-3

I have the following code to generate a list of tuples:

list_of_tuples = list()

for name in list_of_names:
    temporary_list = [name]
    date = function_that_return_a_list      #like ['2014', '01', '20']
    temporary_list = temporary_list + date
    print temporary_list    #returns the correct list of [name, '2014', '01', '20']
    list_of_tuples.append(temporary_list)     #crashes with the error message "TypeError: append() takes exactly one argument (0 given)"

print flist

The problem seem to be related to that the append and insert functions return None when I try and use them on the date list

avenet
  • 2,894
  • 1
  • 19
  • 26
SLq
  • 125
  • 1
  • 6
  • 1
    What happens when you do: `list_of_tuples.append(tuple(temporary_list))` – RickyA Jan 20 '14 at 12:45
  • 8
    Could you rather provide a runnable [SSCE](http://sscce.org/) that reproduces the problem? – bereal Jan 20 '14 at 12:46
  • 2
    Your code snippet doesn't produce an error for me (when replacing `function_that_return_a_list` with `['2014', '01', '20']`), nor does the error message make sense. Can you a) provide us with the *full* traceback of the exception and b) a code example that actually produces the exception? – Martijn Pieters Jan 20 '14 at 12:47
  • The code you have provided does not produce any error. Please provide a code example... – gravetii Jan 20 '14 at 12:49
  • 2
    @user2856110: *descriptor*? Then you didn't *call* `list()`. – Martijn Pieters Jan 20 '14 at 12:49

1 Answers1

4

You forgot to call the list() type:

list_of_tuples = list()
#    ----------------^ You didn't do this.

Your exception (as posted in the comments) shows that you tried to call .append on the type object instead:

>>> list.append(())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'append' requires a 'list' object but received a 'tuple'
>>> list().append(())

Better use [] to produce an empty list in any case:

list_of_tuples = []
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343