Using Turtle?

976
4
Jump to solution
09-01-2022 10:11 AM
Labels (1)
Davec43
Regular Contributor

I've automated my workflow using Python but I have to use "replace" in the word document and then paste it into the Python terminal. Importing "Turtle" in Python pops open a dialog box in Arc that I can then input what I would use replace with.

import sys
import turtle

def get_user_input(prompt):
    if not sys.stdin:
        sc = turtle.Screen();
        sc.setup(0, 0);
        return turtle.textinput(title='', prompt=prompt);
    return input(str);

AA1 = get_user_input(prompt="Enter text here: ")

BB1 = get_user_input(prompt="Enter text here: ")

CC1 = get_user_input(prompt="Enter text here: ")

arcpy.conversion.ExcelToTable(r"AA1\BB1.xlsx", r"CC1\Table Name", "Sheet Name", 1, '')

 

Except when I run arcpy.conversion.ExcelToTable I end up getting an error:

Traceback (most recent call last):
File "<string>", line 17, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 514, in ExcelToTable
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 511, in ExcelToTable
retval = convertArcObjectToPythonObject(gp.ExcelToTable_conversion(*gp_fixargs((Input_Excel_File, Output_Table, Sheet, field_names_row, cell_range), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Excel File: Dataset AA1\BB1.xlsx does not exist or is not supported
Failed to execute (ExcelToTable).

What am I doing wrong?

0 Kudos
1 Solution

Accepted Solutions
Brian_Wilson
Honored Contributor

Add "import os" near the top and change line 17 to 

xlsx = os.path.join(AA1, BB1 + '.xlsx)
tbl = os.path.join(CC1, "Table Name")
arcpy.conversion.ExcelToTable(xlsx,tbl,"Sheet Name",1,'')

 

View solution in original post

4 Replies
Brian_Wilson
Honored Contributor

Add "import os" near the top and change line 17 to 

xlsx = os.path.join(AA1, BB1 + '.xlsx)
tbl = os.path.join(CC1, "Table Name")
arcpy.conversion.ExcelToTable(xlsx,tbl,"Sheet Name",1,'')

 

Brian_Wilson
Honored Contributor

Your version is just passing strings into the arcpy function. You need to tell the python interpreter to pass the values of the variables (AA1,BB1,CC1) to the function instead. I used the "os.path.join" function to build up complete paths for the files. You could just "add" the strings together, for example with xlsx = AA1 + "\\" + BB1 + ".xlsx" but os.path.join() will figure out all the details like what slash to put in there and if it even needs one. It's "safer". 

You could also combine all three lines into one line if you want. I find breaking things out on several lines helps keep things easier to read and makes things easier to debug.

 

0 Kudos
Brian_Wilson
Honored Contributor

BTW I did not know there was a turtle module for Python, I have to check that out. Thanks for that.

 

0 Kudos
Davec43
Regular Contributor

Thanks for explaining why it wasn't working!

0 Kudos