Python 3.4.1脚本语法错误,arcpy&

时间:2015-02-24 21:01:58

标签: python python-3.4

我习惯于在python 2.7中工作,所以有一些新的东西,比如打印功能不同。请原谅我的无知。我对编程也很陌生。

所以这是我的脚本,我不断收到错误,突出显示一些逗号或空格,并说有一个

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

代码:

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 个答案:

答案 0 :(得分:3)

反斜杠(由您作为Windows路径分隔符使用)表示Python字符串中的转义序列。将反斜杠加倍或使用原始字符串文字:

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

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

Windows还在路径中接受转发斜杠,完全避免了这个问题:

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