0

I am using the csv module to create a file then write to it. However, nothing is being written to the .csv file.

Here is my code:

import csv
with open('eggsandham.csv', 'wb') as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=' ',
                            quotechar='|', quoting=csv.QUOTE_MINIMAL)
    spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
    spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])

Does anyone know why this is happening?

1
  • A more descriptive title would be nice! Commented Apr 24, 2014 at 8:42

2 Answers 2

1

in my case this code is working and writing to a csv file in current directory . Output or file is :

May be try giving absolute path

Spam Spam Spam Spam Spam |Baked Beans| Spam |Lovely Spam| |Wonderful Spam|

Sign up to request clarification or add additional context in comments.

Comments

1

I wrote this code:

>>> with open('/host/rk/Python27/eggsandham.csv', 'wb') as csvfile:
...     spamwriter = csv.writer(csvfile, delimiter = ' ',quotechar = '|', quoting = csv.QUOTE_MINIMAL)
...     spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
...     spamwriter.writerow(['Spam', 'Lovely Spam','Wonderful Spam'])

It produces output like this:

Spam Spam Spam Spam Spam |Baked Beans|
Spam |Lovely Spam| |Wonderful Spam|

in the.csv file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.