Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Reading locally stored XML files in Python (Jupyter) with Alteryx

AgrimNautiyal
6 - Meteoroid

Hi Everyone! This being my first community post, very excited to learn from all your experiences 🙂

 

I wrote a python script to iteratively parse an XML File to an excel table (csv) for further Alteryx analysis. I want to modify my use case to incorporate this parsing logic within a single canvas itself (instead of first running my python script separately and then plugging the resulting csv into my canvas).

I was hoping to achieve this by using the Python tool, but as I understand the tool reads all inputs as a pandas dataframe by default and this causes incompatibility with my parsing script as I make use of the "xml" python library that directly deals with an input XML file.

I was wondering if there was any way in which I can directly read the XML file stored locally, in my Jupyter notebook within Alteryx and replicate my script. 

 

Any suggestions would be greatly appreciated and do let me know in case any further details are required, thank you!

 

 

3 REPLIES 3
danilang
19 - Altair
19 - Altair

hi @AgrimNautiyal 

 

 

The input on the Python tool is optional, so you can use it as the first tool in a stream of tools.  At the end of your script, change it so that instead of writing to a csv, convert the table to a data frame and send it to the Python tool output using Alteryx.write(df,1).  This will make it available for further processing in the workflow.

 

For a bit of added flexibility, you could use a text input to pass in the name of the file to the Python tool.

 

Dan

AgrimNautiyal
6 - Meteoroid

Thanks @danilang

 

Thing is I tried this approach and kept getting an error thrown as - "File not found" which I'm assuming corresponds to the jupyter notebook/python tool not being able to read my XML file stored locally in the same location as the canvas.

 

This got me wondering if reading locally stored files is possible at all through this tool.  If so, could you maybe share an example of how one could read a locally stored file directly with the tool without using an input tool?

 

Thanks,

Agrim

AgrimNautiyal
6 - Meteoroid

@danilang  - never mind: figured out the mistake I was making. Hadn't accounted for the fact that the current working directory of Alteryx is set by default and would point to the workflow constant "Engine Temp Path".

 

Just used the below to temporarily change the file path in the jupyter notebook itself : 

 

import os

os.getcwd() # this shows me the path Alteryx is reading in, initially - no wonder it wasn't able to read in my input file!

os.chdir(target_path) #this changes to the path in which my file is stored in and so it ends up working seamlessly 🙂

 

 

Thanks for your help - Accepting your solution as it pointed me in the right direction 🙂

 

Regards,

Agrim

Labels
Top Solution Authors