newbie help
Kent Johnson
kent37 at tds.net
Thu Mar 24 17:53:12 EST 2005
ashtonn at gmail.com wrote:
> Here it is again.
>
> I did something like this.
> index is passed from the command line.
>
> def __getBuffer( index):
> if index == 1:
> buf1 = [None] * 512
> print "Buffer: %s" % (buf1)
> return buf1
> elif index == 2:
> buf2 = [None] * 512
> print "Buffer: %s" % (buf2)
> return buf2
>
> Is this the best way to do this?
It's still not clear what you are trying to accomplish. The code above will return a new buffer each
time. It is equivalent to
def __getBuffer(index):
buf = [None] * 512
print "Buffer: %s" % (buf)
return buf
If your intent is that __getBuffer(1) always returns the *same* buffer, you need to create the
buffers once. A simple way is this:
buf1 = [None] * 512
buf2 = [None] * 512
def __getBuffer(index):
if index == 1:
print "Buffer: %s" % (buf1)
return buf1
elif index == 2:
print "Buffer: %s" % (buf2)
return buf2
Kent
More information about the Python-list
mailing list