0
#Python code:
import csv # first we need import necessary lib:csv
file=open("dinesh.csv") #prepare a csv file for our example
testWriter = csv.writer(open('dinesh.csv', 'w'), delimiter=' ',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamWriter.writerow(['Test'] * 5 + ['Wow'])

Error:-
<type 'exceptions.IOError'>: invalid mode: w
args = ('invalid mode: w',)
errno = None
filename = None
message = 'invalid mode: w'
strerror = None

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by jice
0

message = 'invalid mode: w'

try 'wb'

Edited by mike_2000_17: Fixed formatting

0

try 'wb'

not working..invalid mode :(

reading from file is workin.... :((

how to xport data to csv file???

0

try this

#Python code:
import csv # first we need import necessary lib:csv
file=open("dinesh.csv", "w") #prepare a csv file for our example
testWriter = csv.writer(file, delimiter=' ',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL)
testWriter.writerow(['Test'] * 5 + ['Wow'])
file.close()
0

I think the error is here (and griboullis solution corrects it)

file=open("dinesh.csv") #prepare a csv file for our example

Here you open the file (in read only mode - the default value)

testWriter = csv.writer(open('dinesh.csv', 'w'), delimiter=' ',

And here, you reopen it when it is not closed... Not good habit ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.