Python issue in workflow
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I have been searching for a solution for this issue everywhere and cannot find an answer.
In my workflow, I am passing 2 files (full paths and file names) to a Python Tool as First One and Second One, and then I want to move 3 tabs from First One to Second One, replacing the tabs with that name in Second One.
I am getting AlteryxEngine not defined, and I have tried all the below to get the engine function:
From ayx import Alteryx
engine = Alteryx.get_engine()
Or
From ayx import Alteryx
engine = Alteryx.engine()
Or
From ayx import Package
engine = Package.Engine
I am using this code:
from ayx import Alteryx
import pandas as pd
from openpyxl import load_workbook
import os
engine = Alteryx.get_engine()
# Get file paths from workflow variables
first_file = AlteryxEngine.WorkflowVariables["First One"]
second_file = AlteryxEngine.WorkflowVariables["Second One"]
# Define the sheet names to move
sheets_to_move = ["3E Load File", "Excel Format", "Detail"]
# Read the specified sheets from the first file
sheets_data = pd.read_excel(first_file, sheet_name=sheets_to_move, engine="openpyxl")
# Check if the second file exists
if os.path.exists(second_file):
# Load existing workbook
writer = pd.ExcelWriter(second_file, engine="openpyxl", mode="a",
if_sheet_exists="replace")
else:
# Create a new workbook
writer = pd.ExcelWriter(second_file, engine="openpyxl")
# Write each sheet to the second file
for sheet_name, df in sheets_data.items():
df.to_excel(writer, sheet_name=sheet_name, index=False)
# Save changes
writer.close()
Any Python whizzes see what change(s) I need to make?
Solved! Go to Solution.
- Labels:
- Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
instead of trying to use the engine to get the variables (file names) read them into a dataframe:
import pandas as pd
import openpyxl
from ayx import Alteryx
# Read Alteryx columns
df_in = Alteryx.read("#1")
# Extract Excel file FullPath from the workflow thats in the dataframe now
first_file = df_in["First One"].iloc[0] # Get the first file path
second_file = df_in["Second One"].iloc[0] # Get the second file path
print(f"Source file: {first_file}")
print(f"Destination file: {second_file}")
from there you should be able to use the rest of your code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@kwildais correct. the Alteryx Engine has no relevance here --- check out:
https://help.alteryx.com/current/en/designer/tools/developer/python-tool.html#idp382359
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Doh! Should've known that. Grazie!
