Python 3.4.1 script syntax error, arcpy &

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

I am used to working in python 2.7 so there was some new things like the print function being different. So excuse my ignorance. I am also pretty new to programming.

So here is my script, I keep getting errors that highlight some commas or spaces and saying there is a

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 16-17: malformed \N character escape 

Code:

import arcpy  print("mosaic to new raster starting!")  env.workspace = "F:\GDAL" arcpy.env.pyramid = "NONE" arcpy.env.rasterStatistics = "NONE" arcpy.env.compression = "JPEG 87" arcpy.env.tileSize = "256 256"  print("Environment set")  RasterInput = "m_3511401_ne_11_1_20130731.jpg;m_3511401_nw_11_1_20130731.jpg;m_3511401_se_11_1_20130731.jpg;m_3511401_sw_11_1_20130731.jpg;"  print("Input set")  arcpy.MosaicToNewRaster_management(RasterInput,"F:\Pro_Projects\NAIP2013\raster.sde","MosaicFile1","","8_BIT_UNSIGNED","","3","LAST","FIRST")  print("mosaic done!") 

回答1:

Backslashes (used by you as Windows path separators) signal escape sequences in Python strings. Double the backslashes or use a raw string literal:

"F:\\Pro_Projects\\NAIP2013\\raster.sde" 

or

r"F:\Pro_Projects\NAIP2013\raster.sde" 

Windows also accepts forward slashes in paths, avoiding the issue altogether:

"F:/Pro_Projects/NAIP2013/raster.sde" 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!