[Tutor] modular programming help

Cameron Stoner wolf_binary@hotmail.com
Fri, 8 Feb 2002 11:52:55 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_001A_01C1B097.255285C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 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.

You have some file called mod.py as a module.  It has a function in it =
called say printing.  This is what the function looks like:

def printing(x):
    return x

Now to access this function I have to import it.

import mod

Then to use it:

mod.printing("hello")

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

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. =20

A very confussed beginner,
Cameron

------=_NextPart_000_001A_01C1B097.255285C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2712.300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>What I mean is Python uses files =
(name.py) as=20
modules.&nbsp; My intro to programming teacher in college is telling me =
that=20
importing a file isn't calling a module.&nbsp; I must be confussed here =
because=20
I have always understood that modules were external programming things =
that you=20
brought in with the import and then executed with functions from it what =
you=20
wanted done.&nbsp; Now this is how I use or understand modules in=20
Python.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>You have some file called mod.py =
as&nbsp;a=20
module.&nbsp; It has a function in it called say printing.&nbsp; This is =
what=20
the function looks like:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def printing(x):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; return =
x</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Now to access this function I have to =
import=20
it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>import mod</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Then to use it:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>mod.printing("hello")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Then there are the functions that =
return a 0, or a=20
1.&nbsp; She says those are modules.&nbsp; Example:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def name(x):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if x =
&gt;0</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
return=20
1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; else:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
return=20
0</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>What is what here.&nbsp; We're using =
Qbasic to=20
understand how to do logic, but the terminology is tripping me up with=20
Python.&nbsp; She also said you should be able to pass values to modules =
and=20
have them return values to you.&nbsp; Functions in Python do that so she =
thought=20
Python used the def to create procedures or subroutines.&nbsp; I don't=20
understand this Python idiom I guess.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>A very confussed beginner,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron</FONT></DIV></BODY></HTML>

------=_NextPart_000_001A_01C1B097.255285C0--