[Tutor] How do you make a module

James A Roush jar@mminternet.com
Tue, 16 Apr 2002 19:31:55 -0700


> -----Original Message-----
> From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
> Sent: Friday, April 12, 2002 3:36 AM
> To: jar@mminternet.com; tutor@python.org
> Subject: RE: [Tutor] How do you make a module
>
>
> > I have several functions that I've written and use in
> > multiple programs.  I
> > would like to put them in a module for easier maintainability.  Could
> > somebody point me to a tutorial that will explain how?
>
> Try the modules chaprter of my tutor(see sig)
>
> > Once it's made, what directory does it go in?
>
> Anywhere thats in your PYTHONPATH value.
> Or anywhere and add that place to your PYTHONPATH....
>
> Alan g.
> Author of the 'Learning to Program' web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>

Thanks Alen.  That's what I needed.  It's nice to know your website is still
online.  I lost track of it when the URL changed.

I'm stumped about how to handle a namespace issue.

In the __main__ program I open a file for output like this:

    DEBUGOUT = open('f:/source/linkextr2/debug_rr.txt', 'w')

and the functions that __main__ calls output logging data to it.  Now that
those functions have been moved to their own module (crawler.py), the
functions have no idea of DEBUGOUT's existence.  My first thought would be
to pass DEBUGOUT to crawl_site(), but crawl_site calls other functions
within the same module and those functions also need to access the DEBUGOUT
file.

Is there a way to make DEBUGOUT created in __main__ available to the other
module (crawler.py)?