How to return the function result instead of the function syntax of a variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 11:44 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 12:51 AM
Hi @zll_0091 ,
Could you provide more code? What's inside dsfd variable? What's your expected outcome?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 01:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 02:33 AM
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
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)