Accessing overridden __builtin__s?

garyjefferson123 at garyjefferson123 at
Tue Mar 14 06:28:06 CET 2006

I'm having a scoping problem.  I have a module called SpecialFile,
which defines:

def open(fname, mode):
  return SpecialFile(fname, mode)

class SpecialFile:

  def __init__(self, fname, mode):
    self.f = open(fname, mode)

The problem, if it isn't obvioius, is that the open() call in __init__
no longer refers to the builtin open(), but to the module open().  So,
if I do:

f =, mode)

I get infinite recursion.

How do I tell my class that I want to refer to the __builtin__ open(),
and not the one defined in the module?


More information about the Python-list mailing list