namespace issue?

Christopher A. Craig com-nospam at ccraig.org
Thu Jun 21 21:23:12 CEST 2001


Michael Powe <michael+gnus at trollope.org> writes:

> >>> def GetNum2():	
> ... 	AC = raw_input("Area Code: ")
> ... 	PN = raw_input("Phone Number: ")
> ...	if not PN : PN = '000-0000'
> ...	if not AC : AC = '503'
> ...	if len(PN) < 8 and not string.find(PN,'-'):
> ...		Ph = PN[:3] + '-' + PN[3:]
> ...	return Ph

  string.find(PN, '-') 
succeeds (since PN contains a '-'), so 
  len(PN)<8 and not string.find(PN,'-') 
returns false, meaning that
  Ph = PN[:3] + '-' + PN[3:]
is never executed, and Ph is not defined when the return statement is
reached.

So, yes, it is because of the conditional, but no it has nothing to do
with namespaces.  (unlike in C or C++, in Python not all blocks get
their own namespaces, only functions, modules, and classes (and
probably something I forgot))

Also, yes, raw_input returns a string.

-- 
Christopher A. Craig <com-nospam at ccraig.org>
Q: What's the difference between Bell Labs and the Boy Scouts of America
A: The Boy Scouts have adult supervision



More information about the Python-list mailing list