Trouble with 'Python for Everyone' course

2524
3
Jump to solution
04-18-2014 09:51 AM
JoshuaHouston
New Contributor
Hi, I'm doing the 'Python for Everyone' course from ESRI http://training.esri.com/Courses/PythEveryone10_1/player.cfm and my script isn't working.

It says that
path = r"C:\Student\PythEveryone10_1\Creating Scripts\BismarckUpd.txt" file = open(path, 'w')
will create and open a text file, however, when I run the script I get these errors returned:

"Traceback (most recent call last):
File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "C:\Student\PythEveryone10_1\CreatingScripts\BismarckShapefiles.py", line 11, in <module>
file = open(path, 'w')
IOError: [Errno 2] No such file or directory: 'C:\\Student\\PythEveryone10_1\\Creating Scripts\\BismarckUpd.txt'
"

Here is the whole script.
#Assign variables to the shapefiles park = "nd_park520.shp" school = "ND_schools454.shp" sewer = "nd_sew454.shp"  #Create a list of shapefile variables shapeList = [park, school, sewer]  #Create and open new text file for updated shapefiles path = r"C:\Student\PythEveryone10_1\Creating Scripts\BismarckUpd.txt" file = open(path, 'w')  #Update the names of the shapefiles in shapefile list for shp in shapeList:     print shp     shp = shp.replace("nd", "ND")     print shp     file.write(shp +"\n")  file.close()


If you could help me understand what I'm doing wrong or where something went wrong I'd appreciate it, thank you.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DouglasSands
Occasional Contributor II

IOError: [Errno 2] No such file or directory: 'C:\\Student\\PythEveryone10_1\\Creating Scripts\\BismarckUpd.txt'



This is the key here. The file doesn't exist in that location. Try browsing to that file location and look for the file called BismarckUpd.txt. If it isn't there, then there is no way for python to open it.

Since you are opening it in 'w' (write) mode, then I'd assume that the file path is the part that is incorrect. If the folders all existed, then python would have created an empty .txt file with the name BismarkUpd.txt in that folder.

- Doug

View solution in original post

3 Replies
DouglasSands
Occasional Contributor II

IOError: [Errno 2] No such file or directory: 'C:\\Student\\PythEveryone10_1\\Creating Scripts\\BismarckUpd.txt'



This is the key here. The file doesn't exist in that location. Try browsing to that file location and look for the file called BismarckUpd.txt. If it isn't there, then there is no way for python to open it.

Since you are opening it in 'w' (write) mode, then I'd assume that the file path is the part that is incorrect. If the folders all existed, then python would have created an empty .txt file with the name BismarkUpd.txt in that folder.

- Doug
JoshuaHouston
New Contributor
This is the key here. The file doesn't exist in that location. Try browsing to that file location and look for the file called BismarckUpd.txt. If it isn't there, then there is no way for python to open it.

Since you are opening it in 'w' (write) mode, then I'd assume that the file path is the part that is incorrect. If the folders all existed, then python would have created an empty .txt file with the name BismarkUpd.txt in that folder.

- Doug


Thank you, Doug!  You were correct about my path! I had a typo. 😮
0 Kudos
SarfarazKhan
New Contributor

You can try this Python course and it will definitely help you.

0 Kudos