views:

87

answers:

5

this is my main string

"action","employee_id","name"
"absent","pritesh",2010/09/15 00:00:00

so after name coolumn its goes to new line but here i append to list a new line character is added and make it like this way

data_list*** ['"action","employee_id","name"\n"absent","pritesh",2010/09/15 00:00:00\n']

here its append the new line character with absent but actually its a new line strarting but its appended i want to make it like

data_list*** ['"action","employee_id","name","absent","pritesh",2010/09/15 00:00:00']

A: 
def f(word):
    return word.strip()
data_list = map(f, data_list)
Davide Gualano
Surely you meant `map`? :)
badp
Yes, I did :) Edited accordingly :)
Davide Gualano
A: 

replaces = inString.replace("\n", "");

InsertNickHere
+3  A: 

Davide's answer can be written even simpler as:

data_list = [word.strip() for word in data_list]

But I'm not sure it's what you want. Please write some sample in python.

zefciu
with strip you get also rid of the '\r'
Blauohr
A: 

First, you can use strip() to get rid of '\n':

>>> data = line.strip().split(',')

Secondly, you may want to use the csv module to do that:

>>> import csv
>>> f = open("test")
>>> r = csv.reader(f)
>>> print(r.next())
['action', 'employee_id', 'name']
e-satis
A: 

I'd do like that:

in_string.replace('\n', ',', 1).split(',')
kishkin