Why do these two lines of python code fail when I can run them separately with success?

1767
5
12-18-2016 02:49 AM
Arild_MJohannessen
New Contributor II

When I write these two lines in ArcGIS Pro v1.3.1 Python window I get the result shown below the dotted line. However if I run them one at a time I get the anticipated result. What is going on? By the way, the lines are part of a bigger project, and it seems like anything inserted in line 2 yields an error. I don't suspect that the GPX file is corrupted since it runs with success in example 2 below. It also runs with success with the GPXtoFeatures tool in ArcGIS.

arcpy.GPXtoFeatures_conversion("D:\Downloads\TrackLog2.gpx", "in_memory/GPX")
print("HelloWorld")
-----------------------------------------------------------------------------
Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
AttributeError: 'NoneType' object has no attribute 'write'

.

arcpy.GPXtoFeatures_conversion("D:\Downloads\TrackLog2.gpx", "in_memory/GPX")
-----------------------------------------------------------------------------
<Result 'D:\\ArcGIS Projects\\Test\\Test.gdb\\GPX29'>

print("HelloWorld")
-----------------------------------------------------------------------------
HelloWorld

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

try raw formatting your inputs if you are using command line... ie r"your path goes here preferably without spaces"

having paths beginning with 'n', 't' etc raises the possibility of the \n sequence (for example) being treated as an escape character (in this case a new line)

0 Kudos
Arild_MJohannessen
New Contributor II

Same result  Is this a bug in ArcGIS Pro? The code runs in ArcGIS Desktop 10.4. Can anyone try to reproduce the error?

arcpy.GPXtoFeatures_conversion(r"D:\Downloads\TrackLog2.gpx", r"in_memory/GPX")
print(r"HelloWorld")

--------------------------------------------------------------------------------------------------

Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
AttributeError: 'NoneType' object has no attribute 'write'

0 Kudos
DanPatterson_Retired
MVP Emeritus

arcpy was imported I assume? like in the example  GPX To Features—Conversion toolbox | ArcGIS for Desktop 

0 Kudos
Arild_MJohannessen
New Contributor II

No it was not. However, I have now tried with it imported and it gives the same result. However, if I was missing a reference, I shouldn't have had any luck when I run the example on line at a time...Screenshot of the code not working

0 Kudos
DanPatterson_Retired
MVP Emeritus

well the only thing I can test is the 2nd line... which works.

Check for the existence of the file which I presume it is there since the first incarnation works.

Which leaves The in_memory workspace—ArcGIS Pro | ArcGIS for Desktop looks ok on the surface, but there are a whole load of errors associated with it and stuff in PRO Search Result | ArcGIS Desktop 

so that leaves... trying to save it elsewhere.

0 Kudos