[Tutor] puzzled by main()

Dick Moores rdm at rcblue.com
Fri Aug 20 12:44:20 CEST 2004


Danny Yoo wrote at 00:47 8/20/2004:


>On Thu, 19 Aug 2004, Dick Moores wrote:
>
> > I wrote intSpell.py for practice with integers, strings and modules. It
> > works fine by itself, but I'd like to figure out how to use it as a
> > module which I can import and use as intSpell(n).
>
>Hi Dick,
>
>Sounds good!  Let's take a look.
>
>
> > Is my use of main() the problem? Or if not, what should I do?
>
>
>One thing to clarify here: a module can provide more than one function to
>the outside world, so Python has no idea that main() is function you mean
>when you say:
>
>###
>import intSpell
>print intSpell.intSpell(42)
>###
>
>With what you have right now, it looks more like:
>
>###
>import intSpell
>print intSpell.main()
>###
>
>which probably isn't what you want.
>
>
>So you have to, well, spell it out to Python.  *grin*  Rename the main()
>function to intSpell().  Also, modify it so it takes in 'n' as a
>parameter.  Otherwise, we won't be able to say:
>
>     intSpell.intSpell(n)
>
>for any given n.

Thanks for clearing that up, Danny. After renaming main() it's working 
fine now with

import intSpell
intSpell.intSpell(n)

Dick Moores 



More information about the Tutor mailing list