tags:

views:

121

answers:

3

Is there a reson why date can not append to a list?

vdate = str(dates.date)
vdats = vdate.split("")
vdats = vdats[0]
vbalance.append(vdats)

just did not work?

What am I doing wrong?

UPDATE Error message:AttributeError: 'Decimal' object has no attribute 'append'

+1  A: 
vdats=vdate.split("")

You can't split with an empty separator. This will raise a ValueError exception.

interjay
+4  A: 

Update:

I'd say the error you get is pretty self explanatory: vbalance is just not a list. So you cannot append to it.

What is the intention of your code, what do you want to achieve?

It might be, that you want to add to vbalance:

vbalance += int(vdats)

or that you have to create a list beforehand:

l = list()
vdate = str(dates.date)
vdats = vdate.split("")
vdats = vdats[0]
l.append(vdats)

or that you have to declare vbalance differently in your previous code.


Just from what you posted I guess you get a ValueError:

>>> string = "ab cd asd"
>>> print string.split('')

Traceback (most recent call last):
  Line 2, in <module>
    print string.split('')
ValueError: empty separator

Assuming vdate contains a valid string and vbalance contains a list, if you just want to split the string on the whitespaces, use:

vdats = vdate.split()

Otherwise you have to pass which separator you want to use, but obviously, this string cannot be empty.

Documentation: str.split()

Felix Kling
+1  A: 

Clearly vbalance is not a list. Appending to a Decimal is meaningless, so that operation is not supported. Perhaps you meant to add vdats to it instead:

vbalance += vdats
Ignacio Vazquez-Abrams