]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use 'global' instead of struct kludge.
authorGuido van Rossum <guido@python.org>
Thu, 26 Dec 1991 13:10:50 +0000 (13:10 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 26 Dec 1991 13:10:50 +0000 (13:10 +0000)
Lib/tempfile.py

index f4a9d4bdeb921f07060b97f747edcefb0dbe374a..a571f413ffa62c4270d7777934d9d4dcf9eb7cfa 100644 (file)
@@ -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