How to return the function result instead of the function syntax of a variable?

zll_0091
New Contributor III

Hi,

I'm trying to get the certain value of my variable in the for loop but it's returning the syntax instead of the value. Also, is it possible to covert this value to an integer? Thanks

zll_0091_0-1723013056629.png

 

szymon_dybczak
Esteemed Contributor III

Hi @zll_0091 ,

Could you provide more code? What's inside dsfd variable? What's your expected outcome?

Hi Slash,

dsfd is just dbutils.fs.ls of my source path.

Output: [Column<'substring(process_run_key=661962868/, 16, 26)'>]

Expected Output: [661962868]

I just want to get the integer of that specific folder.

szymon_dybczak
Esteemed Contributor III

So, in my opinion you're doing it wrong. The dbutils.fs.ls will return python list. You're using substring function from pyspark.sql.functions which is not needed in this case.
As an example, I created dsfd variable with following content

Slash_1-1723023091145.png

Then I can iterate over this list in the following way. Let's say that I only need path from dbutils.fs.ls output:

 

for row in dsfd:
    print(row.path)