Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
解決済み

Pass Input file name dynamically to Python SDK

dineshbabu2811
アステロイド

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.

6件の返信6
gawa
16 - Nebula
16 - Nebula

@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.

 

dineshbabu2811
アステロイド

@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.

 

 

 

gawa
16 - Nebula
16 - Nebula

It says...

image.png

apathetichell
アルタイル

@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.

dineshbabu2811
アステロイド

@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)

apathetichell
アルタイル

@dineshbabu2811 you should accept @gawa 's solution - and mine if you're feeling generous.

ラベル
トップのソリューション投稿者