Python window keep giving error message from last operation

2584
3
12-13-2012 11:36 AM
GarethMann
New Contributor III
I am brand new to Python as of today. I cannot believe that ESRI is replacing VBA with full intellisense for this silly DOS window thing.

Anyway, if I run this code in the Python window in ArcMap:

def happyBirthday(person):
    print("Happy Birthday " + person + ".")

happyBirthday('emily')


It runs fine. But then when I run this code:

import arcpy, os
def prinnames(sPath);
import arcpy, os
 folderPath = sPath
      for filename in os.listdir(folderPath):
   fullpath = os.path.join(folderPath, filename)
   if os.path.isfile(fullpath):
    basename, extension = os.path.splitext(fullpath)
    if extension.lower() == ".mxd":
     mxd = arcpy.mapping.MapDocument(fullpath)
     print(mxd.title)
prinnames("C:\Gareth\mystuff")


I get this error:

Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 2)

But then, when I try to go back and paste the exact same code back into the window that ran before (The "Happy Birthday" test code), it won't run, instead it gives me the exact same error it had before (Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 2))

So why is it doing this?
Tags (2)
0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Gareth,

What version of ArcGIS (including Service Packs) are you running?  I was unable to reproduce this using ArcGIS 10.1 SP1.
0 Kudos
MathewCoyle
Frequent Contributor
I am brand new to Python as of today. I cannot believe that ESRI is replacing VBA with full intellisense for this silly DOS window thing.

Anyway, if I run this code in the Python window in ArcMap:

def happyBirthday(person):
    print("Happy Birthday " + person + ".")

happyBirthday('emily')


It runs fine. But then when I run this code:

import arcpy, os
def prinnames(sPath);
import arcpy, os
 folderPath = sPath
      for filename in os.listdir(folderPath):
   fullpath = os.path.join(folderPath, filename)
   if os.path.isfile(fullpath):
    basename, extension = os.path.splitext(fullpath)
    if extension.lower() == ".mxd":
     mxd = arcpy.mapping.MapDocument(fullpath)
     print(mxd.title)
prinnames("C:\Gareth\mystuff")


I get this error:

Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 2)

But then, when I try to go back and paste the exact same code back into the window that ran before (The "Happy Birthday" test code), it won't run, instead it gives me the exact same error it had before (Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 2))

So why is it doing this?


Looks like you are using a semi-colon instead of a colon in your first line. Not sure why it won't run the previous code afterwards.

def prinnames(sPath);
0 Kudos
GarethMann
New Contributor III
Thanks for the prompt responses guys.

I am using ArcMap 10.0, not sure which service pack. All of a sudden the problem I was having went away. Not sure why, and thanks mzcoyle, that was in fact the problem with my code, so it is now fixed.

Next time that problem occurs I will post here again and maybe include a screen shot.
0 Kudos