module name same as function name


#1

hello,

i am trying to figure out the best way to organise my python script. I have split it into modules. some modules perform a particular function, like ‘subdivide_curves’ or ‘shrinkwrap_curves’ etc. But the enclosed functions or classes i have just named in the same way ‘subdivide_curves’ and ‘shrinkwrap_curves’.

so when i import the modules i have to write:

import dev.rigging.shrinkwrap_curves as shrinkwrap_curves

shrinkwrap_curves.shrinkwrap_curves()

is there a smarter way to organise this, or should i just find a slightly different way of naming the module or function. Im trying to keep things as simple as possible.

thanks alot,
Sam


#2

If you often use one module for one function, you can try:

from dev.rigging.shrinkwrap_curves import shrinkwrap_curves
...
shrinkwrap_curves()

#3

Typically a given module would contain several classes and/or functions. I try to name things so that the class name has meaning when seen with the module name. So using your example I would probably have called the class “Curves”, and I’m guessing I’d also have one called “Geo” or something, so within the code I get

from dev.rigging import shrinkwrap
s_curves = shrinkwrap.Curves()
s_geo = shrinkwrap.Geo()

David


#4

or, if you really have a “do the main thing” function in the module, just give it a generic name; imagine:


from dev.rigging import shrinkwrap_curves
from dev.rigging import build_skeleton

shrinkwrap_curves.execute()
build_skeleton.execute()

…but I really have no problem with echoing the name. there’s a code some people run quite often and it goes “from ngskintools.ui.mainWindow import MainWindow” :slight_smile:


#5

thanks for all your help guys

Sam