Wie kann ich das Komma aus einer Python-Zeichenfolge wie Foo, bar
entfernen? Ich habe 'Foo, bar'.strip(',')
ausprobiert, aber es hat nicht funktioniert.
Verwenden Sie die replace
-Methode von Zeichenfolgen, nicht strip
:
s = s.replace(',','')
Ein Beispiel:
>>> s = 'Foo, bar'
>>> s.replace(',',' ')
'Foo bar'
>>> s.replace(',','')
'Foo bar'
>>> s.strip(',') # clears the ','s at the start and end of the string which there are none
'Foo, bar'
>>> s.strip(',') == s
True
unicode('foo,bar').translate(dict([[ord(char), u''] for char in u',']))
Dadurch werden alle Kommas aus dem Text entfernt und links ausgerichtet.
for row in inputfile:
place = row['your_row_number_here].strip(', ')