On 13Mar2014 11:22, Ben Finney wrote:
> Cameron Simpson writes:
> > Therefore you need to continue _only_ if you get EEXIST. Otherwise
> > abort.
>
> If you target Python 3.3 or later, you can catch “FileExistsError”
> http://docs.python.org/3/library/exceptions.html#FileExistsError>
> which is
Cameron Simpson writes:
> Therefore you need to continue _only_ if you get EEXIST. Otherwise
> abort.
If you target Python 3.3 or later, you can catch “FileExistsError”
http://docs.python.org/3/library/exceptions.html#FileExistsError>
which is far simpler than messing around with ‘errno’ values.
On 12/03/2014 22:19, Cameron Simpson wrote:
On 12Mar2014 13:29, zoom wrote:
I would like to assure that when writing to a file I do not
overwrite an existing file, but I'm unsure which is the best way to
approach to this problem. As I can see, there are at least two
possibilities:
1. I could u
On 12Mar2014 13:29, zoom wrote:
> I would like to assure that when writing to a file I do not
> overwrite an existing file, but I'm unsure which is the best way to
> approach to this problem. As I can see, there are at least two
> possibilities:
>
> 1. I could use fd = os.open("x", os.O_WRONLY |
On 3/12/2014 5:29 AM, zoom wrote:
2. Alternatively, a unique string could be generated to assure that no
same file exists. I can see one approach to this is to include date and
time in the file name. But this seems to me a bit clumsy, and is not
unique, i.e. it could happen (at least in theory)
On 2014-03-12 13:29, zoom wrote:
> 2. Alternatively, a unique string could be generated to assure that
> no same file exists. I can see one approach to this is to include
> date and time in the file name. But this seems to me a bit clumsy,
> and is not unique, i.e. it could happen (at least in theo
This seems to be an application-level decision. If so, in your
application, why not just check to see if the file exists, and
implement whatever workaround you deem correct for your needs? For
example (to choose a simple, but rather silly, file naming strategy):
fname = "x"
while os.path.exists(fn
Hi!
I would like to assure that when writing to a file I do not overwrite an
existing file, but I'm unsure which is the best way to approach to this
problem. As I can see, there are at least two possibilities:
1. I could use fd = os.open("x", os.O_WRONLY | os.O_CREAT | os.O_EXCL)
which will f