summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-12-26 13:10:50 (GMT)
committerGuido van Rossum <guido@python.org>1991-12-26 13:10:50 (GMT)
commit4a3a41f1bb1bdb753fc456d671389521a0c371b2 (patch)
tree6358906fdecd6e8914ea76c8356a0922efef2fe3 /Lib
parent8fd7eee6dbd7d32d1941c5eb9d6c5a2517bec99c (diff)
downloadcpython-4a3a41f1bb1bdb753fc456d671389521a0c371b2.zip
cpython-4a3a41f1bb1bdb753fc456d671389521a0c371b2.tar.gz
cpython-4a3a41f1bb1bdb753fc456d671389521a0c371b2.tar.bz2
Use 'global' instead of struct kludge.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/tempfile.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index f4a9d4b..a571f41 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -11,11 +11,9 @@ tempdir = '/usr/tmp'
template = '@'
-# Kludge to hold mutable state
+# Counter for generating unique names
-class Struct: pass
-G = Struct()
-G.i = 0
+counter = 0
# User-callable function
@@ -24,9 +22,10 @@ G.i = 0
# XXX By all means, avoid a mess with four different functions like C...
def mktemp():
+ global counter
while 1:
- G.i = G.i+1
- file = tempdir +'/'+ template + `posix.getpid()` +'.'+ `G.i`
+ counter = counter+1
+ file = tempdir+'/'+template+`posix.getpid()`+'.'+`counter`
if not path.exists(file):
break
return file