Reputation: 1
new to python. Just started a rigging class that is starting to get into scripting. I found a practice for python and I am having trouble with an error.
import maya.cmds as cmds
stockPath = "C:\Users\Dryan\Desktop\table.csv"
f = open(stockPath)
data = f.read()
f.close()
print data
This is the error I get.
> # Error: line 1: IOError: file <maya console> line 4: 22 #
Again this is just a practice to get the file of number to print in the script editor. Thank you for any help.
Upvotes: 0
Views: 5144
Reputation: 371
As joojaa said, try to avoid using backslashes when you can. I try to always convert any incoming path to a forward slashes version, and just before outputting it I normalize it using os.path.normpath.
clean_path = any_path_i_have_to_deal_with.replace("\\", "/")
# do stuff with it
# (concat, XML save, assign to a node attribute...)
print os.path.normpath(clean_path) # back to the OS version
Upvotes: 0
Reputation: 12208
The likeliest problem is that you're using backslashes in your file name, so they get interpreted as control characters. The IO error is because the filename is mangled.
try
stockPath = "C:\\Users\\Dryan\\Desktop\\table.csv" # double slashes to get single slashes in the string
or
stockPath = "C:/Users/Dryan/Desktop/table.csv" # it's more python-y to always use right slashes.
Upvotes: 3