Python Forum
CSV File not found - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: CSV File not found (/thread-7889.html)

Pages: 1 2


CSV File not found - SeanBassett - Jan-28-2018

I am using Python in Blender.
my code can not find the CSV file.
The file is in the same folder as the blender file and this did work when I was using blender Game Render.
But now I need it to work in Blender Render.

When I check the error it has added two folders to the actual path.
Quote:Traceback (most recent call last):
File "C:\Users\Owner\Desktop\Blender\Probot 2\ProbotPositions.blend\Untitled", line 12, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'Program.txt'

The actual location is "C:\Users\Owner\Desktop\Blender\Probot 2"

My code,

import csv

line = 1
column = 2
 
with open('Program.txt', "r") as file:
    mycsv = csv.reader(file)
    mycsv = list(mycsv)
    text = mycsv[line][column]
    print(text)
    rotate=int(text)
How do I point to the CSV File?

Thank you for any help


RE: CSV File not found - wavic - Jan-28-2018

with open('/path/Program.txt', 'r') as in_file: # Python will handle / acording to the operating system
    # do something



RE: CSV File not found - SeanBassett - Jan-28-2018

Thanks, but did not work


Quote:Traceback (most recent call last):
File "C:\Users\Owner\Desktop\Blender\Probot 2\ProbotPositions.blend\Untitled", line 11, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/path/Program.txt'



RE: CSV File not found - wavic - Jan-29-2018

Replace 'path' with directory path to the file.


RE: CSV File not found - SeanBassett - Jan-29-2018

Same error
Quote:location: <unknown location>:-1
Error: File "C:\Users\Owner\Desktop\Blender\Probot 2\ProbotPositions.blend\Untitled", line 17
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

location: <unknown location>:-1



RE: CSV File not found - Gribouillis - Jan-29-2018

(Jan-29-2018, 06:41 AM)SeanBassett Wrote: Error: File "C:\Users\Owner\Desktop\Blender\Probot 2\ProbotPositions.blend\Untitled", line 17
Use a raw string with a leading r
r"C:\Users\Owner\Desktop\Blender\Probot 2\ProbotPositions.blend\Untitled"
Alternatively, use pathlib
from pathlib import Path
p = Path('C:')/'Users'/'Owner'/'Desktop'/'Blender'/'Probot'/'ProbotPositions.blend'/'Untitled'
print(str(p))



RE: CSV File not found - SeanBassett - Jan-29-2018

Thank you for you advice but it still does not work.

from pathlib import Path
p = Path('C:')/'Users'/'Owner'/'Desktop'/'Blender'/'Probot 2'
print(str(p))
import csv

line = 1
column = 2
 
with open('Program.txt', "r") as file:
    mycsv = csv.reader(file)
    mycsv = list(mycsv)
    text = mycsv[line][column]
    print(text)
    rotate=int(text)
Error message

Quote:49.5
C:Users\Owner\Desktop\Blender\Probot 2
Traceback (most recent call last):
File "C:\Users\Owner\Desktop\Blender\Probot 2\ProbotPositions.blend\Untitled", line 21, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'Program.txt'
Error: Python script fail, look in the console for now...



RE: CSV File not found - micseydel - Jan-29-2018

You define, but don't use, p. You need to incorporate it into the open call.


RE: CSV File not found - SeanBassett - Jan-29-2018

Sorry but where do I add the p?


RE: CSV File not found - Gribouillis - Jan-30-2018

(Jan-29-2018, 09:38 PM)SeanBassett Wrote: Sorry but where do I add the p?
If your program is at position C:\ham\spam\eggs\program.txt in the file system, you can write
p = Path('C:')/'ham'/'spam'/'eggs'/'program.txt'
with p.open('r') as file:
    mycsv = csv.reader(file)
    etc