Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV File not found
#1
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
Reply
#2
with open('/path/Program.txt', 'r') as in_file: # Python will handle / acording to the operating system
    # do something
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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'
Reply
#4
Replace 'path' with directory path to the file.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
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
Reply
#6
(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))
Reply
#7
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...
Reply
#8
You define, but don't use, p. You need to incorporate it into the open call.
Reply
#9
Sorry but where do I add the p?
Reply
#10
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Absolute paths in subprocess - file not found kittyticker 4 501 Jan-28-2024, 10:37 PM
Last Post: kittyticker
  file open "file not found error" shanoger 8 1,165 Dec-14-2023, 08:03 AM
Last Post: shanoger
  File not found error saisankalpj 10 3,883 Jul-04-2022, 07:57 AM
Last Post: saisankalpj
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,559 Nov-23-2020, 05:15 PM
Last Post: cananb
  File not found error Ads 5 3,288 Mar-15-2020, 01:56 PM
Last Post: saqib1066
  modify line in file if pattern found in list. kttan 1 2,233 Dec-10-2018, 08:45 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020