[Tutor] A list of input arguments

Mr Gerard Kelly s4027340 at student.uq.edu.au
Tue Jan 13 05:28:30 CET 2009


I have a problem with understanding how lists, strings, tuples, number
types and input arguments all interact with each other.

I have this program, in which I can use the *a structure to input
unlimited arguments.

As an example, if I use three arguments, it looks like this:

def main():
  #Play a chord
  
  pygame.mixer.pre_init(sample_rate, -16, 1) # 44.1kHz, 16-bit signed, mono
  pygame.init()
  play_for(waves(440,550,660), 5000)

In that final line, I would like to be able to define the input
arguments on a different line (I'm hoping to eventually make a Tkinter
entry box), but when I try to do this:

def main():
  #Play a chord
  
  pygame.mixer.pre_init(sample_rate, -16, 1) # 44.1kHz, 16-bit signed, mono
  pygame.init()
  chord=[440,550,660]
  play_for(waves(chord), 5000)

it doesn't work.

It doesn't work with a string or a tuple either.

The problem is that another part of the code needs to take
float(chord[0]), that is convert the first input value into the float
class, and the error message says "TypeError: float() argument must be a
string or a number." This is fine when the elements of *chord are listed
inside the function's parentheses, but it doesn't work if they're listed
outside.

Is there any way to list the input arguments without listing them inside
the function's parentheses?

Thanks.


More information about the Tutor mailing list