From 723f4078a3b2dc299a5864c7e59a77d428ff6a66 Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Tue, 17 Apr 2007 20:14:26 -0700 Subject: [PATCH] pyutil: fileutil.open_or_create() --- src/allmydata/util/fileutil.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index ddb111ea..25ad9761 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -178,3 +178,9 @@ def remove_if_possible(f): remove(f) except: pass + +def open_or_create(fname, binarymode=True): + try: + return open(fname, binarymode and "r+b" or "r+") + except EnvironmentError: + return open(fname, binarymode and "w+b" or "w+") -- 2.45.2