I’m not sure if I’m just going about it wrong or if there is a bug, but I’m trying to append data into a new dataset, but I’m getting the following error whenever I try to run .append() on it. Any Ideas?
Huh, AFAIK python’s list append() takes 1 arg…
Yeah I just noticed I was missing my square braces around my data I was appending. Error is confusing, but it seems to work now.
You can also do newData.extend(["test","test"])
Python background/internals lesson:
newData.append() is calling the append
function on newData
, which is an instance of the list
class, which in pseudocode looks something like:
class list(object):
def append(self, item):
<add an item to internal data storage>
So it’s saying it needs 2 arguments because it does - self
, and item
- it’s just that self
is automatically passed when you call it on an object reference.
As @jpark pointed out, if you want to add multiple items in one call, just use extend
.
2 Likes