Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > All Other Coding Languages
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-04-2006, 07:46 AM   #16 (permalink)
coolman
Registered User
 
Join Date: Mar 2006
Posts: 25
coolman is on a distinguished road
ok i got the code working

Thanks i got it working finally but there one problem if the fields are to far apart in my text file then it dont insert the commas, but if the fields are close to togother den it insert the commas. but most of my text files will alway be far apart so i need some sort function dat need to include the all the white space and bring it close togother but i cant think of anything i been looking up the manual but i dont understand it

Code:
NUM,,,|FIRSTNAME|,SURNAME,|course,| 12400 COOL <to far away>WHATEVER CS 12500 MICHAEL <to far away> OWEN CS 12600 GEOGE FANNY CS 12700 CARMEN LIGHT IT 12800 PET ROOF
so i need to bring the fields close togother as well as inserting the commas,
__________________
coolman is offline   Reply With Quote
Old 05-04-2006, 07:47 AM   #17 (permalink)
coolman
Registered User
 
Join Date: Mar 2006
Posts: 25
coolman is on a distinguished road
got it working fully almost

Thanks i got it working finally but there one problem if the fields are to far apart in my text file then it dont insert the commas, but if the fields are close to togother den it insert the commas. but most of my text files will alway be far apart so i need some sort function dat need to include the all the white space and bring it close togother but i cant think of anything i been looking up the manual but i dont understand it


Code:
NUM,,,|FIRSTNAME|,SURNAME,|course,|
12400 COOL <to far away>WHATEVER CS
12500 MICHAEL <to far away> OWEN CS
12600 GEOGE FANNY CS
12700 CARMEN LIGHT IT
12800 PET ROOF
so i need to bring the fields close togother as well as inserting the commas,
__________________
coolman is offline   Reply With Quote
Old 05-04-2006, 08:15 AM   #18 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,681
redhead is on a distinguished road
You're not sure this has something todo with either <space> or <tab> seperating the items in your lines ?
The code will only transform spaces into commas, it wont do a thing if theres a <tab>, but this can be fixed by telling the compile() to search for ' |\t' ie:
Code:
for line in f.readlines(): returnline.append(re.compile('( |\t)').sub(',', line[0:-1]))
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 05-04-2006, 10:11 AM   #19 (permalink)
coolman
Registered User
 
Join Date: Mar 2006
Posts: 25
coolman is on a distinguished road
its just shows blank

when i ran the code it just shows blank
__________________
coolman is offline   Reply With Quote
Old 05-04-2006, 10:20 AM   #20 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,681
redhead is on a distinguished road
hmm.... thats odd:
Code:
#!/usr/bin/python import re returnline = [] f = open("List", "r") for line in f.readlines(): returnline.append(re.compile('( |\t)').sub(',', line[0:-1])) for item in returnline: print item
Quote:
> ./test.py
NUM,|FIRSTNAME|,SURNAME,|course,|
------------------------------------------
12400,ERIC,RONNEY,CS
------------------------------------------
12500,MICHAEL,OWEN,CS
------------------------------------------
12600,SCOT,MAN,CS
------------------------------------------
12700,GEOGE,YO,IT
------------------------------------------
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 05-04-2006, 10:37 AM   #21 (permalink)
coolman
Registered User
 
Join Date: Mar 2006
Posts: 25
coolman is on a distinguished road
sorry its works

thanks its work fully
__________________
coolman is offline   Reply With Quote
Old 05-11-2006, 05:55 AM   #22 (permalink)
coolman
Registered User
 
Join Date: Mar 2006
Posts: 25
coolman is on a distinguished road
I found an easier way to understand how dis work

but it dont work fully

Code:
def formate(datafile): returnlines = "" currentline = datafile.readline() while currentline: if currentline[0] != ('#'): returnlines+= currentline +'\n' currentline = datafile.readline() return returnlines def listdata(filename): datafile = open(filename, 'r') returnlines = [] for currentline in datafile.readlines(): if not currentline.startswith('#'): returnlines.append(currentline.replace('\n', '').split(',')) currentline = datafile.readline() datafile.close() return returnlines def presentdata(showdata): for item in showdata: print item print '\n'
to exercute the code

>>>datafile = open("StudentList.txt", "r")
>>>eventdata = datafile.readlines()
>>>print eventdata
__________________
coolman is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
file types: reading and writing pre_wreck Standard C, C++ 2 09-26-2005 05:49 AM
.htaccess -- Image Hotlinking Prevention DavH27 HTML / CSS 0 08-27-2004 03:43 AM
.htaccess -- Custom Error Pages v1.1 DavH27 HTML / CSS 0 08-26-2004 04:40 PM
Reading in a file jello Standard C, C++ 4 05-04-2004 07:53 AM
Binary I/O file reading (0x1a trouble) Danish Standard C, C++ 2 05-26-2003 10:02 AM


All times are GMT -8. The time now is 11:58 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle