469,963 Members | 1,971 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

question about shadowing built-in names

I understand that if you reassign a built-in name to your own variable,
such as:

str = 'hello'

then you lose the use of the built-in (in this case str()), but is this
also the case in terms of imported names? For example:

import MySQLdb

db = connect(blah blooh blee)
cursor = db.cursor()

Now, in the above, did I reassign the value of the cursor method, or is
this different?

Actually, now that I think about it, that's not exactly the same because
cursor is a method of a connection object, not simply a function. So I
suppose my real question is, does the 'shadowing' of built-in names also
happen when you import other names, whether they are functions,
methods or whatever else they could be?

Thanks.
May 23 '06 #1
1 2165
Dennis Lee Bieber wrote:
import MySQLdb

db = connect(blah blooh blee)
Actually, the above has already failed <G> Should be
MySQLdb.connect...


Heh heh, yeah, I totally meant to do that on purpose. ;)

Well, if you have a habit of doing
from module import *
and later rebind one of the imported names...


I see. So doing a regular import <name> statement keeps the namespace
confined to that module, right? So I would be able to create my own
variable with the same name as a name in the imported module, and this
wouldn't be a problem as long as I didn't import with *?
May 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Arthur J. O'Dwyer | last post: by
10 posts views Thread by deko | last post: by
18 posts views Thread by No Such Luck | last post: by
2 posts views Thread by Zoury | last post: by
3 posts views Thread by Nick Stansbury | last post: by
5 posts views Thread by iwdu15 | last post: by
1 post views Thread by mitsura | last post: by
3 posts views Thread by Cartoper | last post: by
9 posts views Thread by Alexander Dong Back Kim | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.