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)
Solved! Go to Solution.
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
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
No, I want to set the pathway. A better example is given.
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)
I have error "TypeError: 'module' object is not callable"
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)
It works but gives only the first value
To troubleshoot further you will need to attach both Python files to a reply to this message.
Thank you,
Josh
Okay, I have found the issue.
Thank you,
Josh
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