Pass Input file name dynamically to Python SDK
- 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
We need to pass the file path dynamically to the python code, but I'm not getting the correct approach.
I want to give the file path via input text tool in Gallery and pass that into python code and read the file. Could you please help to build it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@dineshbabu2811 I can advise two things.
(1) To pass the file path 'dynamically' to the Python tool, you need to configure the Interface tool on Input Text tool so that user can select folders by themselves.
(2) Delimiter of directory is slash '/' in Python code(C:user/hoge/hogehoge), while it's back slash '\' in Alteryx(C:user\hoge\hogehoge). Usually you need to configure the step to replace \ to / in file path somewhere. I always put the Formula tool with Replace([Filepath], "\", "/") function before loading file path to the Python tool.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@gawaI have replaced the "/" and tried to call the column FilePath in python, its not working.
Please see the attached screenshot and advise me how to call the file based on the user input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
It says...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@dineshbabu2811 --- these are Python issues. FilePath in that case would be a variable. If you want it as a column name it would be 'FilePath' --- make sure you are importing Pandas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@gawa @apathetichell Fixed the issue by using the below code and passing the values dynamically with interface Text tool.
from ayx import Package
import pandas as pd
from ayx import Alteryx
pth= Alteryx.read("#1")
Filename = pth['FilePath'].iloc[0]
Alteryx.write(pth, 1)
df=pd.read_csv(Filename, encoding = 'latin1')
cols=df.head(2)
Alteryx.write(cols, 2)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@dineshbabu2811 you should accept @gawa 's solution - and mine if you're feeling generous.
