[Tutor] filtering within a function.

D-Man dsh8290@rit.edu
Mon, 12 Mar 2001 21:54:35 -0500


On Mon, Mar 12, 2001 at 06:02:56PM -0500, Tesla Coil wrote:
| On 12 Mar 2001, Remco Gerlich replied:
| > And why would you eliminate importing string
| > when it has a perfectly fine definition of
| > uppercase?!
| 
| Currently have "import string" in the cipher
| module, and "import cipher, string" will load
| cipher, string and cipher.string--and all that
| cipher has ended up using is string.uppercase.  

How is this a problem?  If I understand correctly you have:

### cipher.py
import string

### here.py (I don't know what you named this module ;-)
import cipher , string

# now there exists 2 paths to string
print string
print cipher.string

## but I don't see a problem with it, just use 'string' instead of
'cipher.string'


| I could simply 'from string import uppercase'
| but uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
| doesn't amount to that much more typing, and
| 
| >>> from string import uppercase
| >>> len(uppercase) == 26
| 0
| >>> len(uppercase)
| 56
| 
| ...could prove The Wrong Thing.

Maybe.  Are you using some interesting locales or something?

Here:

Python 2.0 (#18, Oct 31 2000, 13:55:49) [C] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> import string
>>> len( string.uppercase )
26
>>> print string.uppercase
ABCDEFGHIJKLMNOPQRSTUVWXYZ
>>>


-D