Search code examples
pythonstringtranslate

expected buffer object error on string.translate - python 2.6


I´d appreciate some help for a python novice, I´m trying to delete some characters from a string, like this, for example:

string1 = "100.000"
deleteList = [",", "."]
string1.translate(None, deleteList)

 print string1

but I get a TypeError: expected a character buffer object

Why do I get this error, which argument does it refer to? and where can i find help on this. I'm using python 2.6 on windows.


Solution

  • The docs for string.translate says

    S.translate(table [,deletechars]) -> string
    

    which suggests that deletechars should be a string of characters, instead of a list of characters:

    string1 = "100.000"
    string1=string1.translate(None, ',.')
    print (string1)
    # 100000