[Tutor] Tutor digest, Vol 1 #537 - 13 msgs

Kalle Svensson kalle@gnupung.net
Fri, 19 Jan 2001 14:05:55 +0100


--wac7ysb48OaltWcw
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez Sharriff Aina:

> >>> from os import *
> >>> test1 =3D open('junk.txt', 'w')
> Traceback (innermost last):
>   File "<pyshell#1>", line 1, in ?
>     test1 =3D open('junk.txt', 'w')
> TypeError: an integer is required
> >>>=20
>=20
> the sytax is fine, I =B4ve tried it out several times. I=B4ve noticed tha=
t this
> prooblem starts when I import the OS module, witrhout it, the sytax is ok=
ay

The problem is that you use from os import *, and os contains a function
named open.  Check it out:
http://www.python.org/doc/current/lib/os-fd-ops.html

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.

HTH,
  Kalle
--=20
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

--wac7ysb48OaltWcw
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6aDuzdNeA1787sd0RAt72AJ4jkT4tpL6kodKy5G9a5Ku3Y73rJACfS1yN
HuZwDvdp6vw3MsEbZLsdvyU=
=33JZ
-----END PGP SIGNATURE-----

--wac7ysb48OaltWcw--