Function

1044
9
Jump to solution
04-12-2021 10:39 PM
Mick
by
New Contributor

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?

 

 

0 Kudos
1 Solution

Accepted Solutions
JeffK
by MVP Regular Contributor
MVP Regular Contributor

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 

 

 

 

View solution in original post

9 Replies
DanPatterson
MVP Esteemed Contributor

....


... sort of retired...
0 Kudos
Mick
by
New Contributor

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.

0 Kudos
DanPatterson
MVP Esteemed Contributor

...

 

 


... sort of retired...
0 Kudos
Mick
by
New Contributor

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.

0 Kudos
DanPatterson
MVP Esteemed Contributor

..


... sort of retired...
0 Kudos
Mick
by
New Contributor

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. 

0 Kudos
DanPatterson
MVP Esteemed Contributor

.


... sort of retired...
0 Kudos
Mick
by
New Contributor

 

 

 

 

 

0 Kudos
JeffK
by MVP Regular Contributor
MVP Regular Contributor

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