File line splitting in Jython -


i trying read file , populate values in db of jython in odi. this, read line 1 one split line on basis of ',' present.

now have line

4jgbb8gb5aa557812,,miss,maria,cruz,,"266 faller drive apt. b", new milford,nj,07646,2015054604,2015054604,20091029,51133,,, n,lessee,"mercedes-benz usa, llc",n,n 

"mercedes-benz usa, llc" field has , within double quotes due gets split 2 fields whereas should considered one. can please tell me how should avoid this.

fields = valuelist.split(',')  

i use splitting valuelist individual line present in file

you can use csv module can take care of quotes:

line = '4jgbb8gb5aa557812,,miss,maria,cruz,,"266 faller drive apt. b",new milford,nj,07646,2015054604,2015054604,20091029,51133,,,n,lessee,"mercedes-benz usa, llc",n,n'  import stringio import csv  f = stringio.stringio(line) reader = csv.reader(f, delimiter=',') row in reader:     print('\n'.join(row)) 

result:

... 266 faller drive apt. b ... lessee mercedes-benz usa, llc ... 

my example uses stringio because test line string in code, can use opened file handler f.

you find more examples @ "module of month": http://pymotw.com/2/csv/index.html#module-csv


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -