path = r"C:\Student\PythEveryone10_1\Creating Scripts\BismarckUpd.txt" file = open(path, 'w')
#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()
Solved! Go to Solution.
IOError: [Errno 2] No such file or directory: 'C:\\Student\\PythEveryone10_1\\Creating Scripts\\BismarckUpd.txt'
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
You can try this Python course and it will definitely help you.