473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to read a csv file from a python script?

Hi all,
I want to read the contents of a csv file thru my python script.
The csv file has say n rows and each row contains some numbers separated by commas. I have to access a specific row and then all the numbers separately. For ex: the csv file is something like this:

1 01,02,05,07,18
2 00.01,04
3 09,20,21

now the first number which is the number of the row will be provided as input thru command line args.
i want to get the numbers following the row number...i.e for row 1 i want to get 01,02,05,07,18 not as one complete line but as separate numbers.
plz help
Mar 22 '07 #1
27 3196
ghostdog74
511 Expert 256MB
Hi all,
I want to read the contents of a csv file thru my python script.
The csv file has say n rows and each row contains some numbers separated by commas. I have to access a specific row and then all the numbers separately. For ex: the csv file is something like this:

1 01,02,05,07,18
2 00.01,04
3 09,20,21

now the first number which is the number of the row will be provided as input thru command line args.
i want to get the numbers following the row number...i.e for row 1 i want to get 01,02,05,07,18 not as one complete line but as separate numbers.
plz help

since your data has a significant blank space just after the row number and nowhere else, you can use split() on blank.
eg
Expand|Select|Wrap|Line Numbers
  1. >>> for line in open("file"):
  2. ...  line = line.strip().split()
  3. ...  print "row:  ", line[0] , line[1:][0].split(",")
  4. ...
  5. row:   1 ['01', '02', '05', '07', '18']
  6. row:   2 ['00.01', '04']
  7. row:   3 ['09', '20', '21']
  8.  
Mar 22 '07 #2
bartonc
6,596 Expert 4TB
Hi all,
I want to read the contents of a csv file thru my python script.
The csv file has say n rows and each row contains some numbers separated by commas. I have to access a specific row and then all the numbers separately. For ex: the csv file is something like this:

1 01,02,05,07,18
2 00.01,04
3 09,20,21

now the first number which is the number of the row will be provided as input thru command line args.
i want to get the numbers following the row number...i.e for row 1 i want to get 01,02,05,07,18 not as one complete line but as separate numbers.
plz help
My friend ghostdog74 has a very good solution if, in fact, rows start with row number and there are NO spaces between entries.
A true csv file would have a format more like:
1st_value, 2nd_value, etc
For such files, the csv module may be a good choice, too.
Mar 22 '07 #3
My friend ghostdog74 has a very good solution if, in fact, rows start with row number and there are NO spaces between entries.
A true csv file would have a format more like:
1st_value, 2nd_value, etc
For such files, the csv module may be a good choice, too.

Actually the situation is little bit different..
there are several rows in the csv file and each row starts with a unique number followed by another set of numbers. as i told in the previous post. I have to access a particular row and the numbers following it.
Mar 22 '07 #4
bvdet
2,851 Expert Mod 2GB
Actually the situation is little bit different..
there are several rows in the csv file and each row starts with a unique number followed by another set of numbers. as i told in the previous post. I have to access a particular row and the numbers following it.
Barton is correct. This is not a true csv file. As long as the data is consistent, this should work:
Expand|Select|Wrap|Line Numbers
  1. '''
  2. 1 01,02,05,07,18
  3. 2 00,01,04
  4. 3 09,20,21
  5. 4 12,34,56,77,88,99
  6. 5 03,05,77,88,54
  7. '''
  8.  
  9. def file_data1(f):
  10.     dd = {}
  11.     for line in f:
  12.         dd[int(line.split()[0])] = [int(i) for i in line.split()[1].split(',')]
  13.     return dd        
  14.  
  15. dd = file_data1(open('your_file').readlines())
  16. for key in dd:
  17.     print '%s = %s' % (key, dd[key])
  18.  
  19. '''
  20. >>> 1 = [1, 2, 5, 7, 18]
  21. 2 = [0, 1, 4]
  22. 3 = [9, 20, 21]
  23. 4 = [12, 34, 56, 77, 88, 99]
  24. 5 = [3, 5, 77, 88, 54]
  25. '''
>>> for i in dd[5]:
... print i,
...
3 5 77 88 54
>>>
Mar 22 '07 #5
ghostdog74
511 Expert 256MB
Actually the situation is little bit different..
there are several rows in the csv file and each row starts with a unique number followed by another set of numbers. as i told in the previous post. I have to access a particular row and the numbers following it.
so you want to get an input from the command line arguments, try something like this
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. choice = sys.argv[1]
  3. for line in open("file"):
  4.      line = line.strip().split()
  5.      if choice == line[0]
  6.           print line[1:][0].split(",")
  7.  
Mar 22 '07 #6
so you want to get an input from the command line arguments, try something like this
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. choice = sys.argv[1]
  3. for line in open("file"):
  4.      line = line.strip().split()
  5.      if choice == line[0]
  6.           print line[1:][0].split(",")
  7.  

Sry but this dint work...it did not print nething!! :(
Mar 23 '07 #7
Barton is correct. This is not a true csv file. As long as the data is consistent, this should work:
Expand|Select|Wrap|Line Numbers
  1. '''
  2. 1 01,02,05,07,18
  3. 2 00,01,04
  4. 3 09,20,21
  5. 4 12,34,56,77,88,99
  6. 5 03,05,77,88,54
  7. '''
  8.  
  9. def file_data1(f):
  10.     dd = {}
  11.     for line in f:
  12.         dd[int(line.split()[0])] = [int(i) for i in line.split()[1].split(',')]
  13.     return dd        
  14.  
  15. dd = file_data1(open('your_file').readlines())
  16. for key in dd:
  17.     print '%s = %s' % (key, dd[key])
  18.  
  19. '''
  20. >>> 1 = [1, 2, 5, 7, 18]
  21. 2 = [0, 1, 4]
  22. 3 = [9, 20, 21]
  23. 4 = [12, 34, 56, 77, 88, 99]
  24. 5 = [3, 5, 77, 88, 54]
  25. '''
>>> for i in dd[5]:
... print i,
...
3 5 77 88 54
>>>

i executed the code but it showed the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 4, in file_data
ValueError: invalid literal for int(): Of
Mar 23 '07 #8
bartonc
6,596 Expert 4TB
i executed the code but it showed the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 4, in file_data
ValueError: invalid literal for int(): Of
It looks like part of the error message is missing...

You'll need to paste a copy of the actual data. BV's code is not the problem.
Mar 23 '07 #9
It looks like part of the error message is missing...

You'll need to paste a copy of the actual data. BV's code is not the problem.

i pasted the entire error message...
the actual csv file somwwhat looks like this:


List Of Individual Patches
1 00;01;
2 00;
3 01;
4 02;
5 00;01;02;
6 01;02;
7 01;02;03;04;05;
8 01;02;03;04;05;06;
9 00;01;02;03;05;
10 01;02;03;05;
11 02;03;05;06;
12 04;
13 01;02;03;05;08;09;
14 00;01;02;03;05;09;
15 00;01;02;03;05;09;10;
16 01;02;03;05;08;09;10;
17 01;02;03;05;08;10;
18 08;
19 00;01;02;03;05;08;09;10;
20 02;03;05;06;08;10;
21 11;
22 12;
23 11;12;
24 00;01;02;03;05;14;


i'll take the leftmost number as input and depending upon tht number..i'll have to get the list of numbers following it.

plz help
Mar 23 '07 #10
bartonc
6,596 Expert 4TB
i pasted the entire error message...
the actual csv file somwwhat looks like this:


List Of Individual Patches
1 00;01;
2 00;
3 01;
4 02;
5 00;01;02;
6 01;02;
7 01;02;03;04;05;
8 01;02;03;04;05;06;
9 00;01;02;03;05;
10 01;02;03;05;
11 02;03;05;06;
12 04;
13 01;02;03;05;08;09;
14 00;01;02;03;05;09;
15 00;01;02;03;05;09;10;
16 01;02;03;05;08;09;10;
17 01;02;03;05;08;10;
18 08;
19 00;01;02;03;05;08;09;10;
20 02;03;05;06;08;10;
21 11;
22 12;
23 11;12;
24 00;01;02;03;05;14;


i'll take the leftmost number as input and depending upon tht number..i'll have to get the list of numbers following it.

plz help
You originally stated that there are commas in your data, so people wrote functions that look for commas:
Expand|Select|Wrap|Line Numbers
  1. def file_data1(f):
  2.     dd = {}
  3.     for line in f:
  4.         dd[int(line.split()[0])] = [int(i) for i in line.split()[1].split(',')]
  5.     return dd        
  6.  
Do you see the comma in the above function? Your data has semi-colun so you need to change that to:
Expand|Select|Wrap|Line Numbers
  1. def file_data1(f):
  2.     dd = {}
  3.     for line in f:
  4.         dd[int(line.split()[0])] = [int(i) for i in line.split()[1].split(';')] # chaned here
  5.     return dd        
  6.  
Thank you, BV, for the original function.
Mar 23 '07 #11
You originally stated that there are commas in your data, so people wrote functions that look for commas:
Expand|Select|Wrap|Line Numbers
  1. def file_data1(f):
  2.     dd = {}
  3.     for line in f:
  4.         dd[int(line.split()[0])] = [int(i) for i in line.split()[1].split(',')]
  5.     return dd        
  6.  
Do you see the comma in the above function? Your data has semi-colun so you need to change that to:
Expand|Select|Wrap|Line Numbers
  1. def file_data1(f):
  2.     dd = {}
  3.     for line in f:
  4.         dd[int(line.split()[0])] = [int(i) for i in line.split()[1].split(';')] # chaned here
  5.     return dd        
  6.  
Thank you, BV, for the original function.

now as soon as i typed the line :

dd = file_data(open('my_file').readlines())

it showed the following error:

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "<stdin>", line 1, in ?
  3.   File "<stdin>", line 4, in file_dat
  4. IndexError: list index out of range
  5.  
Mar 23 '07 #12
ghostdog74
511 Expert 256MB
i pasted the entire error message...
the actual csv file somwwhat looks like this:


List Of Individual Patches
1 00;01;
2 00;
3 01;
4 02;
5 00;01;02;
6 01;02;
7 01;02;03;04;05;
8 01;02;03;04;05;06;
9 00;01;02;03;05;
10 01;02;03;05;
11 02;03;05;06;
12 04;
13 01;02;03;05;08;09;
14 00;01;02;03;05;09;
15 00;01;02;03;05;09;10;
16 01;02;03;05;08;09;10;
17 01;02;03;05;08;10;
18 08;
19 00;01;02;03;05;08;09;10;
20 02;03;05;06;08;10;
21 11;
22 12;
23 11;12;
24 00;01;02;03;05;14;


i'll take the leftmost number as input and depending upon tht number..i'll have to get the list of numbers following it.

plz help
it does work
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. choice = sys.argv[1]
  3. for line in open("file"):
  4.      line = line.strip().split()
  5.      if choice == line[0]:
  6.           print line[1:][0].split(";")
  7.  
output :
Expand|Select|Wrap|Line Numbers
  1. # ./test.py 23
  2. ['11', '12', '']
  3.  
Note that your csv file is now colon separated and not comma separated. So you have to change the split() statement.
Mar 23 '07 #13
now as soon as i typed the line :

dd = file_data(open('my_file').readlines())

it showed the following error:

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "<stdin>", line 1, in ?
  3.   File "<stdin>", line 4, in file_data
  4. ValueError: invalid literal for int(): Of
  5.  
now as soon as i typed the line :

dd = file_data(open('my_file').readlines())

it showed the following error:

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "<stdin>", line 1, in ?
  3.   File "<stdin>", line 4, in file_data
  4. ValueError: invalid literal for int(): Of
  5.  
[/quote]
Mar 23 '07 #14
now as soon as i typed the line :

dd = file_data(open('my_file').readlines())

it showed the following error:

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "<stdin>", line 1, in ?
  3.   File "<stdin>", line 4, in file_dat
  4. IndexError: list index out of range
  5.  

plz ignore the above mentioned error. i had done some mistake in naming the variable. The error is actually the same as before as soon as i type the following line:

dd = file_data(open('my_file').readlines())

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2. File "<stdin>", line 1, in ?
  3. File "<stdin>", line 4, in file_data
  4. ValueError: invalid literal for int(): Of
  5.  
Mar 23 '07 #15
it does work
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. choice = sys.argv[1]
  3. for line in open("file"):
  4.      line = line.strip().split()
  5.      if choice == line[0]:
  6.           print line[1:][0].split(";")
  7.  
output :
Expand|Select|Wrap|Line Numbers
  1. # ./test.py 23
  2. ['11', '12', '']
  3.  
Note that your csv file is now colon separated and not comma separated. So you have to change the split() statement.
it dint work even now. Let me tell u wht i did:

1) created a file new.py
2) Wrote the following code:
Expand|Select|Wrap|Line Numbers
  1. import os
  2. import sys
  3. import csv
  4.  
  5. def main(argv):
  6.  
  7.     choice = sys.argv[1]
  8.     fp = open("c:\pst\pst_modified\log_4_0.csv",'r')
  9.     for line in fp:
  10.      line = line.strip().split()
  11.      if choice == line[0]:
  12.           print line[1:][0].split(";")
  13.  
3)i have python23 installed at my system
4) opened the command prompt
5)Moved to the directory where new.py is placed
6)executed the following command
python new.py '23'

whr am i wrong??
./new.py flasgged an error tht "." is not a valid command.
Mar 23 '07 #16
ghostdog74
511 Expert 256MB
it dint work even now. Let me tell u wht i did:

1) created a file new.py
2) Wrote the following code:
Expand|Select|Wrap|Line Numbers
  1. import os
  2. import sys
  3. import csv
  4.  
  5. def main(argv):
  6.  
  7.     choice = sys.argv[1]
  8.     fp = open("c:\pst\pst_modified\log_4_0.csv",'r')
  9.     for line in fp:
  10.      line = line.strip().split()
  11.      if choice == line[0]:
  12.           print line[1:][0].split(";")
  13.  
3)i have python23 installed at my system
4) opened the command prompt
5)Moved to the directory where new.py is placed
6)executed the following command
python new.py '23'

whr am i wrong??
./new.py flasgged an error tht "." is not a valid command.

try this:

Expand|Select|Wrap|Line Numbers
  1. import os
  2. import sys
  3. import csv ## you are not using this?
  4.  
  5. filepath = os.path.join("C:\\","pst","pst_modified","log_4_0.csv")
  6.  
  7. def main():
  8.     choice = sys.argv[1]    
  9.     for line in open(filepath):
  10.      line = line.strip().split()
  11.      if choice == line[0]:
  12.           print line[1:][0].split(";")
  13.  
  14. main()  ## < --you did not call the main in your last posted script sample.
  15.  
Mar 23 '07 #17
try this:

Expand|Select|Wrap|Line Numbers
  1. import os
  2. import sys
  3. import csv ## you are not using this?
  4.  
  5. filepath = os.path.join("C:\\","pst","pst_modified","log_4_0.csv")
  6.  
  7. def main():
  8.     choice = sys.argv[1]    
  9.     for line in open(filepath):
  10.      line = line.strip().split()
  11.      if choice == line[0]:
  12.           print line[1:][0].split(";")
  13.  
  14. main()  ## < --you did not call the main in your last posted script sample.
  15.  

Hi,
it's still not working....thr's something tht i wud like to tell.
If u put a " print line" statement after
line = line.strip().split()
u'll c that it prints the entire csv file and reaches the end. After tht when u compare choice with line[0] ...the condition does not satisfy becauseline[0] contains the last line of the csv file.
Mar 23 '07 #18
ghostdog74
511 Expert 256MB
Hi,
it's still not working....thr's something tht i wud like to tell.
If u put a " print line" statement after
line = line.strip().split()
u'll c that it prints the entire csv file and reaches the end. After tht when u compare choice with line[0] ...the condition does not satisfy becauseline[0] contains the last line of the csv file.
please try this debugging method:
Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     choice = sys.argv[1]    
  3.     for line in open(filepath):
  4.      line = line.strip().split()
  5.      print line, type(line), line[0], line[1]
  6.      raw_input("Press to continue: " )
  7.      if choice == line[0]:
  8.           print line[1:][0].split(";")
  9. main()
  10.  
please show the output of the above.
Mar 23 '07 #19
please try this debugging method:
Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     choice = sys.argv[1]    
  3.     for line in open(filepath):
  4.      line = line.strip().split()
  5.      print line, type(line), line[0], line[1]
  6.      raw_input("Press to continue: " )
  7.      if choice == line[0]:
  8.           print line[1:][0].split(";")
  9. main()
  10.  
please show the output of the above.

The output of your code is as follows:

Expand|Select|Wrap|Line Numbers
  1. [',List', 'Of', 'Individual', 'Patches'] <type 'list'> ,List Of
  2. Press to continue:
  3. ['1,00;01;'] <type 'list'> 1,00;01;
  4. Traceback (most recent call last):
  5.   File "<stdin>", line 1, in ?
  6.   File "my.py", line 12, in main
  7.     print line, type(line), line[0], line[1]
  8. IndexError: list index out of range
  9.  
Mar 23 '07 #20
ghostdog74
511 Expert 256MB
The output of your code is as follows:

Expand|Select|Wrap|Line Numbers
  1. [',List', 'Of', 'Individual', 'Patches'] <type 'list'> ,List Of
  2. Press to continue:
  3. ['1,00;01;'] <type 'list'> 1,00;01;
  4. Traceback (most recent call last):
  5.   File "<stdin>", line 1, in ?
  6.   File "my.py", line 12, in main
  7.     print line, type(line), line[0], line[1]
  8. IndexError: list index out of range
  9.  
hey...you original sample is like this:
Expand|Select|Wrap|Line Numbers
  1. List Of Individual Patches
  2. 1 00;01;
  3. 2 00;
  4. 3 01;
  5. 4 02;
  6. 5 00;01;02;
  7. 6 01;02;
  8. 7 01;02;03;04;05;
  9. 8 01;02;03;04;05;06;
  10. 9 00;01;02;03;05;
  11. 10 01;02;03;05;
  12. 11 02;03;05;06;
  13. 12 04;
  14. 13 01;02;03;05;08;09;
  15. 14 00;01;02;03;05;09;
  16. 15 00;01;02;03;05;09;10;
  17. 16 01;02;03;05;08;09;10;
  18. 17 01;02;03;05;08;10;
  19. 18 08;
  20. 19 00;01;02;03;05;08;09;10;
  21. 20 02;03;05;06;08;10;
  22. 21 11;
  23. 22 12;
  24. 23 11;12;
  25. 24 00;01;02;03;05;14;
  26.  
so if you have changed your format to like this:
Expand|Select|Wrap|Line Numbers
  1. 1,00;01;
  2. 2,00;
  3. ...
  4. ..
  5.  
then surely it doesn't work. you have to modify the code. i give you a hint on where to change:
Expand|Select|Wrap|Line Numbers
  1. ....
  2.     for line in open(filepath):
  3.      line = line.strip().split()  <---here.
  4. ....
  5.  
Mar 23 '07 #21
hey...you original sample is like this:
Expand|Select|Wrap|Line Numbers
  1. List Of Individual Patches
  2. 1 00;01;
  3. 2 00;
  4. 3 01;
  5. 4 02;
  6. 5 00;01;02;
  7. 6 01;02;
  8. 7 01;02;03;04;05;
  9. 8 01;02;03;04;05;06;
  10. 9 00;01;02;03;05;
  11. 10 01;02;03;05;
  12. 11 02;03;05;06;
  13. 12 04;
  14. 13 01;02;03;05;08;09;
  15. 14 00;01;02;03;05;09;
  16. 15 00;01;02;03;05;09;10;
  17. 16 01;02;03;05;08;09;10;
  18. 17 01;02;03;05;08;10;
  19. 18 08;
  20. 19 00;01;02;03;05;08;09;10;
  21. 20 02;03;05;06;08;10;
  22. 21 11;
  23. 22 12;
  24. 23 11;12;
  25. 24 00;01;02;03;05;14;
  26.  
so if you have changed your format to like this:
Expand|Select|Wrap|Line Numbers
  1. 1,00;01;
  2. 2,00;
  3. ...
  4. ..
  5.  
then surely it doesn't work. you have to modify the code. i give you a hint on where to change:
Expand|Select|Wrap|Line Numbers
  1. ....
  2.     for line in open(filepath):
  3.      line = line.strip().split()  <---here.
  4. ....
  5.  
i haven't changed the format. My csv file is the same as it was before.It's like this only:

List Of Individual Patches
1 00;01;
2 00;
3 01;
4 02;
5 00;01;02;
6 01;02;
7 01;02;03;04;05;
8 01;02;03;04;05;06;
9 00;01;02;03;05;
10 01;02;03;05;
11 02;03;05;06;
12 04;
13 01;02;03;05;08;09;
14 00;01;02;03;05;09;
15 00;01;02;03;05;09;10;
16 01;02;03;05;08;09;10;
17 01;02;03;05;08;10;
18 08;
19 00;01;02;03;05;08;09;10;
20 02;03;05;06;08;10;
21 11;
22 12;
23 11;12;
24 00;01;02;03;05;14;
25 00;01;02;03;05;09;14;
26 00;01;02;03;05;08;09;10;14;
27 00;01;02;03;05;17;
28 00;01;02;03;05;09;17;
29 00;01;02;03;05;08;09;10;17;
30 01;02;03;05;08;09;10;17;
31 00;01;02;03;05;09;18;
32 01;02;03;05;08;09;10;18;

and after executing ur code snippet i got the error message which i posted in the previous post. Dunno in the output where from the comma is coming.
Mar 23 '07 #22
ghostdog74
511 Expert 256MB
look at this error you had previously:
Expand|Select|Wrap|Line Numbers
  1. [',List', 'Of', 'Individual', 'Patches'] <type 'list'> ,List Of
  2. Press to continue:
  3. ['1,00;01;'] <type 'list'> 1,00;01;
  4. Traceback (most recent call last):
  5.   File "<stdin>", line 1, in ?
  6.   File "my.py", line 12, in main
  7.     print line, type(line), line[0], line[1]
  8. IndexError: list index out of range
  9.  
the follwing output line results from "print line, type(line), line[0], line[1]" statement:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. ['1,00;01;'] <type 'list'> 1,00;01;
  3. ...
  4.  
The "line" value is ['1,00;01;'] after the split. This means it did not split at all. Furthermore, line.strip().split() splits on blanks and since your data have a comma now, it does nothing.
notice the "," after the first "1" ?? that's why i deduced that you csv format is different. If otherwise, then i have no idea at all.
Expand|Select|Wrap|Line Numbers
  1. ...
  2. line = line.strip().split(",")
  3. ...
  4.  
Mar 23 '07 #23
look at this error you had previously:
Expand|Select|Wrap|Line Numbers
  1. [',List', 'Of', 'Individual', 'Patches'] <type 'list'> ,List Of
  2. Press to continue:
  3. ['1,00;01;'] <type 'list'> 1,00;01;
  4. Traceback (most recent call last):
  5.   File "<stdin>", line 1, in ?
  6.   File "my.py", line 12, in main
  7.     print line, type(line), line[0], line[1]
  8. IndexError: list index out of range
  9.  
the follwing output line results from "print line, type(line), line[0], line[1]" statement:
Expand|Select|Wrap|Line Numbers
  1.  
  2. ...
  3. ['1,00;01;'] <type 'list'> 1,00;01;
  4. ...
  5.  
The "line" value is ['1,00;01;'] after the split. This means it did not split at all. Furthermore, line.strip().split() splits on blanks and since your data have a comma now, it does nothing.
notice the "," after the first "1" ?? that's why i deduced that you csv format is different. If otherwise, then i have no idea at all.
Expand|Select|Wrap|Line Numbers
  1. ...
  2. line = line.strip().split(",")
  3. ...
  4.  
hey it worked this time.
thanks a ton!! :)
Mar 23 '07 #24
ghostdog74
511 Expert 256MB
hey it worked this time.
thanks a ton!! :)
so it's your csv format after all?
Mar 23 '07 #25
so it's your csv format after all?
dint get ur question.
I just included this line

Expand|Select|Wrap|Line Numbers
  1. line = line.strip().split(",")
  2.  
in place of this
Expand|Select|Wrap|Line Numbers
  1. line = line.strip().split()
  2.  
Mar 23 '07 #26
ghostdog74
511 Expert 256MB
dint get ur question.
I just included this line

Expand|Select|Wrap|Line Numbers
  1. line = line.strip().split(",")
  2.  
in place of this
Expand|Select|Wrap|Line Numbers
  1. line = line.strip().split()
  2.  
if by doing a split on comma and it works, it means your csv file has commas, right? so that's why i ask is your csv format like this instead:
Expand|Select|Wrap|Line Numbers
  1. 1,00;01;
  2. 2,00;
  3. ....
  4. ...
  5.  
if its not, then a split on comma will not work.
Mar 23 '07 #27
if by doing a split on comma and it works, it means your csv file has commas, right? so that's why i ask is your csv format like this instead:
Expand|Select|Wrap|Line Numbers
  1. 1,00;01;
  2. 2,00;
  3. ....
  4. ...
  5.  
if its not, then a split on comma will not work.
ok...now i understood!!
Thanks a lot!!
Mar 23 '07 #28

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Andrew Chalk | last post by:
Is this possible? In my CGI app. I display a web page with a link (anchor). When the link is clicked I want to exectute a python script rather than go to an HTML page. Many thanks.
7
by: Scott Chapman | last post by:
Hi! I'd like a "file" on the Linux box to actually be the input and output of a Python script. Anything written to the file would be sent to a database and anything read from the file would...
4
by: Chuck Amadi | last post by:
Has anyone got a simple python script that will parse a linux mbox and create a large file to view . Cheers Chu
22
by: Brad Tilley | last post by:
Is it possible to write a file open, then read program in C and then call the C program from a Python script like this: for root, files, dirs in os.walk(path) for f in files: try:...
7
by: Pankaj | last post by:
The module which i am creating is like Part A: 1. It does some processing by using python code. 2. The result of this python code execution is written to a text file. ] Part B: 1. I read a...
6
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
4
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application....
4
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages...
1
by: replysonika | last post by:
Hello, I run a Java app with subprocess from Python script. This python script is called from another Python Wrapper. python = subprocess.Popen(, stdout=subprocess.PIPE,...
0
by: Stef le Breton | last post by:
Hi, I need to compile a pyhton tool into an executable as the destination plateform (Solaris, Linux) are not deployed with Python or not all needed modules. I found pyinstaller and follow the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.