Re: embarrassing class question

On Oct 22, 5:02 am, Steven D'Aprano <st...@REMOVE-THIS-> wrote:
On Thu, 21 Oct 2010 12:12:34 -0700, Brendan wrote:
Because has "from x import x" the x class from is added to
the namespace.

~Ethan~- Hide quoted text -

- Show quoted text -

So what is usually done to prevent this? (In my case not wanting class x
added to the namespace)
It seems sloppy.

(1) Don't import it in the first place.

(2) Import it with a different name, possibly private:

from module import x as _x

(3) Delete it when you're done:

from module import x
class Y(x):
del x

(4) Don't be so fussy and just accept that importing adds names to the
namespace, as does any other assignment or class or function definition.


I'll take (2) and pass on (4)

Relevant Pages

  • Re: TclOO, classes, inheritance, self methods and variables: a question
    ... TclOO 0.6 or Tcl 8.6.b1 -- will soon try Tcl CVS as well). ...     superclass Parent ... [namespace upvar] is just as good: ... inheritance you're asking for work, ...
  • Re: Easy questions from a python beginner
    ... def swap: ...   raise RuntimeException ... variables in the namespace of the caller. ... This is true in Python 2 and 3. ...
  • Re: closures and dynamic binding
    ...   def f: ... instead maintains access to the namespace providing x. ... This is the dynamic aspect of closures: ...
  • Re: Reverse-engineering C# Classes
    ... ASSUME that the C# language specification rules are already in place. ... exists within the System.Threading namespace. ... to follow the same rules that a compiler does, ...
  • Re: Create task automatically from email
    ... I'm pretty sure the Entry ID's are valid. ... What version of Outlook? ... If you are using NameSpace twice you should instantiate a NameSpace object.. ...    Dim fldCurrent As MAPIFolder ...