cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

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

 

3 REPLIES 3

szymon_dybczak
Contributor

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.

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)

 

  

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group