question about shadowing built-in names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Salerno

    #1

    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.
  • John Salerno

    #2
    Re: question about shadowing built-in names

    Dennis Lee Bieber wrote:
    [color=blue][color=green]
    >> import MySQLdb
    >>
    >> db = connect(blah blooh blee)[/color]
    >
    > Actually, the above has already failed <G> Should be
    > MySQLdb.connect ...[/color]

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

    [color=blue]
    > Well, if you have a habit of doing
    > from module import *
    > and later rebind one of the imported names...[/color]

    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 *?

    Comment

    Working...