Import Issue

Duncan Booth duncan.booth at invalid.invalid
Thu Jun 29 04:17:06 EDT 2006


 wrote:

> Hi All,
> 
>           What is the difference between
>            import string
>               and 
>            from string import *
> 
> Regards,
> Praveen
> 

"import string" is effectively the same as doing:

string = sys.modules['string']

"from string import *" is effectively the same as doing:

ascii_letters=sys.modules['string'].ascii_letters
ascii_lowercase=sys.modules['string'].ascii_lowercase
ascii_uppercase=sys.modules['string'].ascii_uppercase
atof=sys.modules['string'].atof
atof_error=sys.modules['string'].atof_error
atoi=sys.modules['string'].atoi
atoi_error=sys.modules['string'].atoi_error
atol=sys.modules['string'].atol
atol_error=sys.modules['string'].atol_error
capitalize=sys.modules['string'].capitalize
capwords=sys.modules['string'].capwords
center=sys.modules['string'].center
count=sys.modules['string'].count
digits=sys.modules['string'].digits
expandtabs=sys.modules['string'].expandtabs
find=sys.modules['string'].find
hexdigits=sys.modules['string'].hexdigits
index=sys.modules['string'].index
index_error=sys.modules['string'].index_error
join=sys.modules['string'].join
joinfields=sys.modules['string'].joinfields
letters=sys.modules['string'].letters
ljust=sys.modules['string'].ljust
lower=sys.modules['string'].lower
lowercase=sys.modules['string'].lowercase
lstrip=sys.modules['string'].lstrip
maketrans=sys.modules['string'].maketrans
octdigits=sys.modules['string'].octdigits
printable=sys.modules['string'].printable
punctuation=sys.modules['string'].punctuation
replace=sys.modules['string'].replace
rfind=sys.modules['string'].rfind
rindex=sys.modules['string'].rindex
rjust=sys.modules['string'].rjust
rsplit=sys.modules['string'].rsplit
rstrip=sys.modules['string'].rstrip
split=sys.modules['string'].split
splitfields=sys.modules['string'].splitfields
strip=sys.modules['string'].strip
swapcase=sys.modules['string'].swapcase
Template=sys.modules['string'].Template
translate=sys.modules['string'].translate
upper=sys.modules['string'].upper
uppercase=sys.modules['string'].uppercase
whitespace=sys.modules['string'].whitespace
zfill=sys.modules['string'].zfill




More information about the Python-list mailing list