[Tutor] Tutor digest, Vol 1 #537 - 13 msgs
Fri, 19 Jan 2001 18:07:47 -0800 (PST)
> > >>> from os import *
> > >>> test1 = open('junk.txt', 'w')
> > Traceback (innermost last):
> > File "<pyshell#1>", line 1, in ?
> > test1 = open('junk.txt', 'w')
> > TypeError: an integer is required
> The problem is that you use from os import *, and os contains a function
> named open. Check it out:
> The solution is: Don't do that. Use import os, not from os import *.
> Very generally, don't use from ... import * at all, or at least only when
> you are absolutely, positively sure that it's safe.
As a clarification, doing:
from os import open as osopen
would prevent the naming conflict. It's unfortunate that they have the
same name, but Python lets us rename functions if we really need to. This
only works with Python 2.0 though.