[Tutor] Re: IOError exception handling

Derrick 'dman' Hudson dman@dman.ddts.net
Thu, 22 Aug 2002 22:21:31 -0400


--gr/z0/N6AeWAPJVB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jul 28, 2002 at 04:33:22PM -0700, Allyn Weaks wrote:
| Python 2.1 until I can get 2.2.1 installed properly (linux 7.1), but

Linux is only at version 2.5.<something> if you follow Linus'
development work.

| Can one get a more detailed error back than IOError?  I'm counting
| lines in files that may or may not exist, and if one doesn't exist, I
| can set the number of lines to zero and continue with the rest.  But,
| if the file can't be opened because of any other problem, such as a
| permission error, I want it to bail with whatever error message is
| appropriate (preferably without handling each and every case.)

Use os.path.exists() to first query the existance of a file.  Then
only attempt to open it if it exists.

HTH,
-D

--=20
The crucible for silver and the furnace for gold,
but the Lord tests the heart.
        Proverbs 17:3
=20
http://dman.ddts.net/~dman/

--gr/z0/N6AeWAPJVB
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj1lnCsACgkQO8l8XBKTpRRg2wCfRy/wIes+B9ceTpJQjYqV9Kjw
SxcAoJCBRk7NbrKLoz5zC0dXSOCTGrop
=xXxN
-----END PGP SIGNATURE-----

--gr/z0/N6AeWAPJVB--