Skip to content Skip to sidebar Skip to footer

Python Csvwriter Is Creating A Csv File That Doesn't Seem To Exist In My Directory

I'm trying to write to a CSV file using Python. Problem is - it looks like it's writing to some hidden object in memory and never outputting to a file. Here's the code I was trying

Solution 1:

I copied/pasted your code and it worked. I'm using Ubuntu 18.04.2 LTS. After running your code, the file was generated, next, I changed the file name and I executed it again and it also created the file.

It seems that is a Windows problem. Did you check the directory through the terminal? Maybe you will be able to see the file this way.

Solution 2:

Well, I found a workaround... though not a very clean approach.

Since I discovered that it was exporting perfectly fine using the Python console, I just enclosed my data processing in a function (which returns a list of rows) inside of a file called csvautomate.py. Then I went into the console and did the following:

import csvautomate

withopen("output.csv", mode='w', newline="") as f:
    writer = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)

    for row in csvautomate.processdata():
         writer.writerow(row)

And it worked as intended, outputting a correctly formatted file called output.csv.

However this isn't really an ideal solution, so I'm curious if anyone has any other options. Seems when I run files in the cmd using py file.py it doesn't work as intended for some reason. When I use 64-bit python (I'm on Win7 64-bit) I get this file export problem. When I use 32-bit python I get a "python37.dll is missing" error.

Edit: Solved the 'python37.dll is missing" error with 32-bit python by choosing a new install path (just made a folder on my desktop for the time being). Looks like it was probably some kind of permissions issue with the previous location. However, it didn't fix the problem with not writing files.

Post a Comment for "Python Csvwriter Is Creating A Csv File That Doesn't Seem To Exist In My Directory"