2015-02-24 62 views
1

我習慣於在python 2.7中工作,所以出現了一些新的東西,例如print函數不同。所以請原諒我的無知。我對編程也很新穎。Python 3.4.1腳本語法錯誤,arcpy&

因此,這裏是我的腳本,我不斷收到這突出一些逗號或空格錯誤,說有一個

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!") 
+0

我覺得問題是你不逃避文件路徑中的字符,特別是反斜槓。請參閱http://stackoverflow.com/questions/3380484/using-backslash-in-python-not-to-escape。 – sovemp 2015-02-24 21:04:31

回答

3

反斜槓(使用你的Windows路徑分隔符)Python字符串中的信號轉義序列。雙倍的反斜線或使用原始字符串字面量:

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

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

Windows還接受向前斜槓的路徑,避免了問題完全:

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

DOH!就是這樣!謝謝! – user3161018 2015-02-24 21:18:16