newbie help

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Mar 24 18:12:59 EST 2005


In <1111700515.820073.290410 at o13g2000cwo.googlegroups.com>,
ashtonn at gmail.com wrote:

> 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?

Best way to do what?  That could be written as:

  def get_buffer():
      buffer = [None] * 512
      print "Buffer: %s" % buffer
      return buffer

In your code, no matter if index equals 1 or 2, a list with 512 `None`s is
created, printed and then returned.

It would be really better if you describe *what* you want to achieve, not
*how*.  And in words please, not in code snippets.

Ciao,
	Marc 'BlackJack' Rintsch




More information about the Python-list mailing list