[Tutor] modular programming help

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 8 Feb 2002 10:05:40 -0800 (PST)

On Fri, 8 Feb 2002, Cameron Stoner wrote:

> What I mean is Python uses files (name.py) as modules.  My intro to
> programming teacher in college is telling me that importing a file
> isn't calling a module.  I must be confussed here because I have

Hmmm... yikes.  It might just be that QBasic programmers use different
terminology than Python programmers.

> always understood that modules were external programming things that
> you brought in with the import and then executed with functions from
> it what you wanted done.  Now this is how I use or understand modules
> in Python.

That's how I understand them as well.

> Then there are the functions that return a 0, or a 1.  She says those
> are modules.  Example:
> def name(x):
>     if x >0
>         return 1
>     else:
>         return 0

I've heard this kind of function called a "boolean" function or a
"predicate" --- I've never heard of it being called a "module", but then,
I've never played with Qbasic before.  *grin*

> What is what here.  We're using Qbasic to understand how to do logic,
> but the terminology is tripping me up with Python.  She also said you
> should be able to pass values to modules and have them return values
> to you.  Functions in Python do that so she thought Python used the
> def to create procedures or subroutines.  I don't understand this
> Python idiom I guess.

The way your teacher is using the word "module" is different from the way
that we're using the word "module".  It'll be a little confusing at first,
but try to treat them as separate concepts.

If it's possible, try asking your teacher for reasons why the 0-1
functions are called "modules", and that may help.  I took a look at:


and apparently, in the context of QBasic, the word "subroutine" and
"module" are synonymous.  That's not the case in Python --- in Python, we
have a distinction in mind between those words.

QBasic also makes the distinction between subroutines that return values,
and they call these things "functions".  However, Python doesn't make this
distinction because all Python "functions" always return a value.

Vocabulary often depends on context, even when we deal with programming
languages.  Don't worry too much; you'll be able to flip between them in

Good luck to you.