[Tutor] Equivalent of a Subroutine in Python?
Deirdre Saoirse
deirdre@deirdre.net
Thu, 1 Feb 2001 11:15:35 -0800 (PST)
As this is really a tutor question, I'm cutting the extra parts and
re-posting the meat to the Tutor list (list mom's prerogative):
(And yes, I'd rather responses went to the list; others are struggling
with the same kinds of things and NOT posting...)
On Thu, 1 Feb 2001, Seelinger, Bruce wrote:
> I wanted to use values obtained in subroutines or functions as you are
> allowed in DCL. For example, one subroutine determines the hardware
> type of unit based on data imported from a file. Once that subroutine
> determines the hardware type, it is assigned to a variable (hw_type)
> and is used by other subroutines for purposes unique to that hardware
> type. I think the underlying issue is the my logic and design will
> need to be modified to adhere to Python's rules.
In calling a function, you can pass one or more parameters to it. Unlike
may other languages, you can also return multiple parameters.
def readFile(fname):
... do some stuff...
hw_type = (something from the file)
hw_info = (something else from the file)
return hw_type, hw_info
def main():
hw_type, hw_info = readFile("foo")
There's also more complex structures; see:
http://www.python.org/doc/current/tut/node7.html#SECTION007400000000000000000
_Deirdre