miguel olivares varela
klica_sk8 at hotmail.com
Tue Jul 5 18:09:53 EDT 2011
What's date_cdr supposed to be?
It was a mistake it should be date_source
Is your exception handler doing unusual things with sys.exit?
Did you try to run this? When I try to run it, it fails to compile.
it compiles i have no problems with the compilation. The issue is the result 'out.csv', what i want is to save all the modified rows from 'test.csv' into 'out.csv' but i only can save the firs row.
You might want to try opening your output file once and writing to it repeatedly, then close()ing it after all your writes are completed. Or use "with": http://effbot.org/zone/python-with-statement.htm
On Tue, Jul 5, 2011 at 2:25 PM, miguel olivares varela <klica_sk8 at hotmail.com> wrote:
i got a csv file that i need to modify and create a new one, i have no problem to read mi 'test.cvs' which is the source file but when i try to create a new one with the modifications i only got the first row in my 'out.csv' file. I think there is somethng wrong in my loop because i can't put into the rest.
this is my an example of source file:
[here my code:]
dir_cdr = "/tmp"
#loop to find files csv in a directory and read thoses files
for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ):
file_source = open(cdr_files_in, 'r')
reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE)
for data in reader:
firstname = data
lastname = data
date_source = data
phone = data
#Date to epoch
timestamp=int(time.mktime(time.strptime(date_source, "%Y%m%d %H%M%S")))
fout = open("out.csv", "w")
print >>fout, lastname, firstname, timestamp, phone
except csv.Error, e:
sys.exit('file %s, line %d: %s' % (file_source, reader.line_num, e)
Smith John 1296208720 33611111111
Could you help me?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list