I am currently testing a function. Could you tell me how to make it works and how to use it as a module in another script?
Solved! Go to Solution.
Note that mylist doesn't exist in the external script that you are importing and your IDE should have warned you. Since you used the "import package" method, mylist() should be fully qualified (package.method) Names_Functions.Names_My() when used. Names_My does exist, and is the name of the function in the imported script.
import Names_Functions
my = Names_Functions.Names_My(filePath)
If you used the "from package import method"
from Names_Functions import Names_My
you can just use the name of the function:
my = Names_My(filePath)
If you want to rename the imported module you can do this:
from Names_Functions import Names_My as mylist
my = mylist(filePath)
There are tons of examples on how to use the try/except. A good place to start is the python docs or w3
....
Yes, I have an error "Could not complete". I have checked the list works when I use it not in the module and give a pathway. I guess something wrong with "return" or somewhere where I call the list.
...
Yes, arcmap. I did but had the same error message.
I only would like to check and print the list. I need a workable solution.
..
I would like to use 'try 'and 'except' and check the module. Could you show how I can call this module from another script? The main reason is to use it as a module.
.
Note that mylist doesn't exist in the external script that you are importing and your IDE should have warned you. Since you used the "import package" method, mylist() should be fully qualified (package.method) Names_Functions.Names_My() when used. Names_My does exist, and is the name of the function in the imported script.
import Names_Functions
my = Names_Functions.Names_My(filePath)
If you used the "from package import method"
from Names_Functions import Names_My
you can just use the name of the function:
my = Names_My(filePath)
If you want to rename the imported module you can do this:
from Names_Functions import Names_My as mylist
my = mylist(filePath)
There are tons of examples on how to use the try/except. A good place to start is the python docs or w3