Python Forum

Full Version: CSV File not found
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
with open('/path/Program.txt', 'r') as in_file: # Python will handle / acording to the operating system
    # do something
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'
Replace 'path' with directory path to the file.
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
(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))
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...
You define, but don't use, p. You need to incorporate it into the open call.
Sorry but where do I add the p?
(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
Pages: 1 2