2

I have a script to export DDP extents to tif and when I change

arcpy.mapping.ExportToTIFF(mxd,"tests\BA\BA10k_" + str(ddp.pageRow.PageName) + ".tif",df,9306,9306*ar,1800,True)

to

arcpy.mapping.ExportToTIFF(mxd,"tests\BA\10k\BA10k_" + str(ddp.pageRow.PageName) + ".tif",df,9306,9306*ar,1800,True)

--added "10k" to the directory I get

Exporting page 1 of 760 Traceback (most recent call last): File "P:\2012\183_TownPlanning_Symbology\Working\Raster_Layer_Creation\DDP_GeoTiff_production_BA.py", line 10, in arcpy.mapping.ExportToTIFF(mxd,"tests\BA\10k\BA10k_" + str(ddp.pageRow.PageName) + ".tif",df,9306,9306*ar,1800,True) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1373, in ExportToTIFF layout.exportToTIFF(*args) AttributeError: DataFrameObject: Error in executing ExportToTIFF

Any ideas on why?

  • 1
    Besides what blah238 has mentioned below, even if I have all of those in place, I have had inconsistent results when using directories starting with numbers in arcpy (sometimes its ok, sometimes its not). As a rule now, I only use directories starting with a letter (and append the date on the end). For storage purposes, I copy the files etc afterwards to the folder with the name I want. – Cindy Jayakumar Oct 22 '12 at 5:21
  • 1
    I do not believe there are any limitations with folders starting with numbers. I think file geodatabase tables/feature classes and possibly shapefiles must start with a letter though. – blah238 Oct 22 '12 at 6:47
7

\ is an escape character in Python.

You will need to either:

  • Escape each \ with another \
  • Put an r before the opening quote to denote it as a raw string
  • Change each \ to a /
  • What's confusing is that it did work without the '\\' except if a number was the first character of the directory name. – GeorgeC Oct 22 '12 at 5:49
  • 1
    That's probably because they weren't valid escape sequences and it was falling back to the literal interpretation. \0, \1, \2 .. \7, are octal numbers which are translated into ASCII characters, thus mangling your pathnames. More info here: docs.python.org/reference/lexical_analysis.html#string-literals – blah238 Oct 22 '12 at 6:45
  • Wow, / is an escape character. This explains so much in my day to day amateur programming! – Cody Brown Oct 22 '12 at 19:15
  • 3
    \ is an escape character, / is not. – blah238 Oct 22 '12 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.