[Tutor] Converting from a single module to a package

Tim Johnson tim at johnsons-web.com
Sat Aug 6 01:22:47 CEST 2011


* Christopher King <g.nius.ck at gmail.com> [110805 12:03]:
> To make a package, you make a folder named what you want to name the
> package, for example: virus_toolkit. Then you make a file in it called
> __init__.py. This is what you import if you import the virus_toolkit. You
> usually put documentation and general functions in this I believe (I'm not
> 100% sure on package etiquette.) Then you put various modules inside the
> folder, such as brute force, worms, and Trojan_horse. Then you can do from
> virus_toolkit import worms, and such, or if you want to unleash a full out
> attack and import them all, do from virus_toolkit import *.
> 
 Thanks Christopher. Your take on the issue is pretty much the same
 as mine. However, my question is really how to make the transition
 from a single module to a package with the least amount of code
 changes. I'm guessing that I'm going to have to bite the bullet on
 this one. Example:

 # current way
 import tlib as std
 ....
 std.htmlButton(*arglist)

 # New way, after transition 
 import tlib as std
 std.html.button(*arglist)
 #OR 
 import html from tlib
 html.button(*arglist)
 #...
 oh well. Probably best to leave the original as is, for backwards
 compatibility.

 cheers
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com


More information about the Tutor mailing list