[Tutor] puzzled by main()

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Aug 20 09:47:16 CEST 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:


for any given n.

If you have more questions on this, please feel free to ask.  Also, take a
look at the first two sections of:


The official tutorial has a good example with the "fibonacci numbers
module" that's similar in spirit to what you're doing with a
number-spelling module.

Good luck!

More information about the Tutor mailing list