python - For line in file not working with try/except -


i'm running in issue trying replace pipes commas in text file.

try:     replacement except nameerror:     line in datatable:         newdata = line.replace("|", ",")         output.write(newdata)     print "no commas found in " + tableloc + "." 

the print statement works fine, when try "for line in file" loop itself, works well, i'm not able work how have set above.

any ideas or additional information can provide?

there nothing special exception handler code block. file reading not impaired. else wrong.

i suspect read file , left file pointer @ end of file. if read file object, cannot read again , hope see same data, need rewind file first:

datatable.seek(0) line in datatable:     newdata = line.replace("|", ",")     output.write(newdata) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -