[Tutor] nested functions

Cameron Stoner wolf_binary@hotmail.com
Tue, 9 Apr 2002 16:06:38 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C1DFE0.87E0A780
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

Is it a good or bad idea to call functions with in functions?  What =
could you do to not have functions calling functions? I have given an =
example of this bellow.

def splitter(sentence):
 import string
 list =3D string.split(sentence, sep=3D" ")
 return list

# Encrypt sentences
def encryptsent(sentence):
 list =3D splitter(sentence) # list is the list of the
      # the words in the sentence
 count_of_sent =3D len(list)
 count =3D count_of_sent - 1 # -1 of count_of_sent to account for =
slicing
 # initialize variables
 x =3D 0
 list_sentence =3D []
=20
 while x <=3D count: # x is the counter of each word to be processed
  word =3D list[x]
  word_encrypted =3D encrypting(word) # encrypt word
 =20
  quashed_word =3D flow(word_encrypted) # mash character encryption
          # together
  list_sentence.append(quashed_word)
 =20
  x =3D x + 1
  message =3D flow(list_sentence)
=20
 return message

Thanks,
Cameron Stoner



------=_NextPart_000_0005_01C1DFE0.87E0A780
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Is it a good or bad idea to call =
functions with in=20
functions?&nbsp; What could you do to not have functions calling =
functions? I=20
have given an example of this bellow.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def splitter(sentence):<BR>&nbsp;import =

string<BR>&nbsp;list =3D string.split(sentence, sep=3D" =
")<BR>&nbsp;return=20
list</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2># Encrypt sentences<BR>def=20
encryptsent(sentence):<BR>&nbsp;list =3D splitter(sentence) # list is =
the list of=20
the<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # the words in the=20
sentence<BR>&nbsp;count_of_sent =3D len(list)<BR>&nbsp;count =3D =
count_of_sent - 1 #=20
-1 of count_of_sent to account for slicing<BR>&nbsp;# initialize=20
variables<BR>&nbsp;x =3D 0<BR>&nbsp;list_sentence =3D =
[]<BR>&nbsp;<BR>&nbsp;while x=20
&lt;=3D count: # x is the counter of each word to be =
processed<BR>&nbsp;&nbsp;word=20
=3D list[x]<BR>&nbsp;&nbsp;word_encrypted =3D encrypting(word) # encrypt =

word<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;quashed_word =3D =
flow(word_encrypted) # mash=20
character =
encryption<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #=20
together<BR>&nbsp;&nbsp;list_sentence.append(quashed_word)<BR>&nbsp;&nbsp=
;<BR>&nbsp;&nbsp;x=20
=3D x + 1<BR>&nbsp;&nbsp;message =3D =
flow(list_sentence)<BR>&nbsp;<BR>&nbsp;return=20
message</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron Stoner</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0005_01C1DFE0.87E0A780--