web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Power Automate Desktop
Answered

Python script error

(0) ShareShare
ReportReport
Posted on by 4
i would like to get only few columns data from datatable, i have passed the datatable to python 3 script and developed the code to get required fields, but i am getting error to while running it.
Error:  
File "", line 1
    Datatable = 1415140, , SDMT Automations Test Exp JD, Open, Americas (0001)
                         ^
SyntaxError: invalid syntax
 
My Code: 
 
Datatable = %Var_ExcelData%

new_TD = []

for row in Datatable:

    new_row = { 'Job Req ID': row['Job Req ID'], 'Status' = row['Status']}

    new_TD.append(new_row)

print(new_TD)
Categories:
I have the same question (0)
  • Verified answer
    MParikh Profile Picture
    313 Super User 2025 Season 2 on at
    Python script error

    The Python step received a plain string, not a datatable. Python treats it as invalid syntax, so it fails before your loop even runs.

    Two issues appear:
    1. You used %Var_ExcelData% in the Power Automate Desktop Python action, which injects the raw text instead of a table.
    2. Your dictionary syntax is wrong. You used = instead of :.
    Here is the corrected version that works for a datatable passed from Power Automate Desktop.
    Working code
     
     
    # Datatable comes in as a list-of-dictionaries when mapped correctly
    datatable = Var_ExcelData   # remove percent signs
    
    new_TD = []
    
    for row in datatable:
        new_row = {
            'Job Req ID': row['Job Req ID'],
            'Status': row['Status']
        }
        new_TD.append(new_row)
    
    print(new_TD)
    
     
    What need to be fix in Power Automate Desktop
    1. In the Python script action, map your datatable input using Add input,choose type DataTable or List.
      Do not write %Var_ExcelData% inside the Python code.
    2. Power Automate Desktop automatically injects it as a Python object, usually a list of dicts.
    3. Then the loop works without errors.
    What caused your original syntax error
    Your original line:
     
     
    Datatable = %Var_ExcelData%
    gets evaluated as:
     
     
    Datatable = 1415140 , SDMT Automations...
    Python sees:
    • number
    • comma
    • comma
    • text
    • more commas
    This is not valid Python syntax.
    Set the variable in the action input, not by writing %Var_ExcelData% inside the code.
    If you want, I can rewrite the full working PAD Python step with input and output mapping.
  • Suggested answer
    HE-03121232-0 Profile Picture
    4 on at
    Python script error
    yes, please rewrite the full working PAD Python step with input and output mapping.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 544 Moderator

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 482 Super User 2025 Season 2

#3
chiaraalina Profile Picture

chiaraalina 287

Last 30 days Overall leaderboard