Function with two return values

1431
9
Jump to solution
04-16-2021 04:05 AM
Mick
by
New Contributor

Good day, everybody.

I have a function with several return values that I would like to call from another script. However, it does not work. Could you explain how to call the function in the right way? The first example is a little bit wrong. The main idea to set the pathway and work with three values in my another script. However, it works only with the first one.

 

def getPerson(fileFolder):
    #Import arcpy module
    import arcpy

    from arcpy import env
    

      
     #Set workspace
     env.workspace = fileFolder
     name = .....
     age = .....
     country = .....
     return name, age, country

 

 

 

import arcpy, getPerson

filePath = "C:/1.gdb"

name, age, county = getPerson.getPerson(filePath)

 

 

 

0 Kudos
1 Solution

Accepted Solutions
GeoJosh
Esri Regular Contributor

Hi Mick,

The getPerson function does not take any parameters, yet you are passing the variable "filePath" into it. In other words, "filePath" has no local variable to be mapped to within the function.

Also, is getPerson a class method? If not, it's being invoked incorrectly. Try this out:

def getPerson():
    name = "Leona"
    age = 35
    country = "UK"
    return name,age,country
import arcpy, getPerson

filePath = "C:/1.gdb"

name, age, county = getPerson()

 

Thanks,

Josh

View solution in original post

9 Replies
GeoJosh
Esri Regular Contributor

Hi Mick,

The getPerson function does not take any parameters, yet you are passing the variable "filePath" into it. In other words, "filePath" has no local variable to be mapped to within the function.

Also, is getPerson a class method? If not, it's being invoked incorrectly. Try this out:

def getPerson():
    name = "Leona"
    age = 35
    country = "UK"
    return name,age,country
import arcpy, getPerson

filePath = "C:/1.gdb"

name, age, county = getPerson()

 

Thanks,

Josh

Mick
by
New Contributor

No, I want to set the pathway. A better example is given.

0 Kudos
GeoJosh
Esri Regular Contributor

Okay, the second part of my response still stand true. Given your current code sample, it looks like you are calling a class function (class.function(parameters)) but the function definition shows no sign of being a class method. Try invoking the function like this:

import arcpy, getPerson

filePath = "C:/1.gdb"
name, age, county = getPerson(filePath)

 

0 Kudos
Mick
by
New Contributor

I have error "TypeError: 'module' object is not callable"

0 Kudos
GeoJosh
Esri Regular Contributor

Your import statement may be incorrect. Replace <pythonfile> with the name of the Python file that contains the getPerson function.

import arcpy
from <pythonfile> import getPerson

filePath = "C:/1.gdb"
name, age, county = getPerson(filePath)
0 Kudos
Mick
by
New Contributor

It works but gives only the first value

0 Kudos
GeoJosh
Esri Regular Contributor

To troubleshoot further you will need to attach both Python files to a reply to this message.

Thank you,
Josh

0 Kudos
Mick
by
New Contributor

Okay, I have found the issue. 

Thank you,

Josh

0 Kudos
DanPatterson
MVP Esteemed Contributor

Don't edit your original thread. 

You have made 3 edits according to your editing history, making it hard for people to assess people's responses to your questions.

@GeoJosh 's response was correct to your original question.

Post updated code in your responses


... sort of retired...
0 Kudos