I'm pretty new to python, but I'm trying to transpose a time field for a set of data I'm working with in ArcMap. I changed the file locations and fields to my needs. However, when I try to run the script in the python window I get the error

Parsing error SyntaxError: invalid syntax (line 1)

It seems like this is an error with importing arcpy, but I believe ArcMap contains ArcPy. Additionally, running just import arcpy in the scripting window works fine.

Here is the Code:

# Name: TransposeFields_Ex_02.py
# Description: Tranpose field names from column headers to values in one column
# Requirements: None

# Import system modules
import arcpy
from arcpy import env

# set workspace
arcpy.env.workspace = "H:\Users\bdf006\Desktop\GIS Review\Pittsburgh Roads\RoadsWithTime.gdb"

# Set local variables
inTable = "Pittsburgh_Roads_Counts"
# Specify fields to transpose
fieldsToTranspose = "1a;2a;3a;4a;5a;6a;7a;8a;9a;10a;11a;12p;1p;2p;3p;4p;5p;6p;7p;8p;9p;10p;11p;12a"
# Set a variable to store output feature class or table
outTable = "Pittsburgh_Roads_Counts_With_Timw"
# Set a variable to store time field name
transposedFieldName = "Transposed_Time"
# Set a variable to store value field name
valueFieldName = "Value"
# Specify attribute fields to be included in the output
attrFields = "Shape;Type"

# Execute TransposeTimeFields
arcpy.TransposeFields_management(inTable, fieldsToTranspose, outTable, transposedFieldName, valueFieldName, attrFields)
  • 1
    I'd add print statements to troubleshoot where the issue occurs. – smiller Apr 20 at 7:04
  • 1
    Remove everything prior to import arcpy – BERA Apr 20 at 7:55
  • 1
    Why do you have from arcpy import env? I would dispense with it. Are you really using ArcGIS 10.0? – PolyGeo Apr 20 at 9:39
  • 2
    I suspect you have a strange line terminator/ escape sequence in the file. If Python complains about line 1, you don't need to provide more than the first non-comment. Line 10 contains a serious error -- The missing raw formatting flag path = r"C:\something" – Vince Apr 20 at 11:23
  • 2
    Line one is your # Name line. Sounds like it errors out before import arcpy. – kShort Apr 20 at 13:47

Your Answer

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

Browse other questions tagged or ask your own question.