Use 'global' instead of struct kludge.

This commit is contained in:
Guido van Rossum 1991-12-26 13:10:50 +00:00
parent 8fd7eee6db
commit 4a3a41f1bb
1 changed files with 5 additions and 6 deletions

View 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