How to force built-in commands over imported.

Mark McEahern marklists at mceahern.com
Wed Sep 4 11:01:27 EDT 2002


[Maurice van de Rijzen]
> There is a built-in commans called open(fileName). There is also a
> open() command in the os-module open which needs more than the fileName.
>   Originally I didn't import the os-module and everything worked fine.
> However, when I imported the os-module I received an error that open
> needed more arguments. How can I force to take the built-in open()
> instead of the open() in the os-module.

How are you importing os.open?  If you do it like this:

  import os
  f1 = os.open(...)
  f2 = open(...)

you can keep the two open methods separate.  However, if you do it like
this:

  from os import open
  ...

you can't.  Unless you do this:

  from os import open as open_from_os
  ...

But then why would you do that?  ;-)

The idea here is namespaces.  Using 'from module import function' is not
recommended unless you know what you're doing.

Also, for what it's worth, you may want to consider using:

  f = file(...)

instead of:

  f = open(...)

since the method name matches the type:

  >>> type(f)
  <type 'file'>

// m

-





More information about the Python-list mailing list