-3
votes

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

1
What happens when you do: list_of_tuples.append(tuple(temporary_list)) - RickyA
Could you rather provide a runnable SSCE that reproduces the problem? - bereal
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♦
The code you have provided does not produce any error. Please provide a code example... - gravetii
@user2856110: descriptor? Then you didn't call list(). - Martijn Pieters♦

1 Answers

4
votes

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 = []