another python style question -- copying a data file
Guy Middleton
guy at obstruction.com
Tue Apr 22 14:45:52 EDT 2003
More information about the Python-list mailing list
Tue Apr 22 14:45:52 EDT 2003
- Previous message (by thread): Installing MySQL-python-0.9.2 on Solaris 2.9
- Next message (by thread): another python style question -- copying a data file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <mailman.1051033654.17248.python-list at python.org>, =?ISO-8859-1?Q?Gerhard_H=E4ring?= <gh at ghaering.de> wrote: > Guy Middleton wrote: > > Ok, here's another style question. > > > > I want to copy a data file, but if the file doesn't already exist, I don't > > care. I do care about any other errors, such as wrong permissions. > > > > I have the following code, is this a typical Python way to do this? > > > > try: > > os.stat(DATAFILE) > > os.system("cp %s %s.new" % (DATAFILE, DATAFILE)) > > except OSError, arg: > > # ENOENT is ok, we didn't do the copy > > # anything else is a problem > > if arg.errno != errno.ENOENT: > > raise > > Here's what I'd do: > > if os.path.exists(DATAFILE): > shutil.copyfile(DATAFILE, "%s.new" % DATAFILE) Aha, I didn't know about shutil. This is obviously better. :-)
- Previous message (by thread): Installing MySQL-python-0.9.2 on Solaris 2.9
- Next message (by thread): another python style question -- copying a data file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list