Friday, 15 February 2013

python - Tuples and Strings, Problems with splitting a tuple into a string so that it can be split? -



python - Tuples and Strings, Problems with splitting a tuple into a string so that it can be split? -

i have taken csv file , set a tuple, however, need split string within tuple , not know how. can please tell me need prepare it?

my current code is:

import csv open('scallop.csv','ru') scallop: reader=csv.reader(scallop) data=[tuple(line) line in reader] print data[1] beam=raw_input("please input beam specifications search for: ") line in data: #need rewrite data.index(beam,) print line else: print("\nno beam found")

the beam cannot found because attached one, input file formatted this:

('-55', '158.75', '-54.975', '158.775', '*', '1ab073c1|1bb073c1', 'vsat-antenna-1|vsat-antenna-1', 'buc-1|buc-1')

when inputing beam utilize format

1ab021c1

where:

1a satellite, b021 beam followed 3 digit number and c1 channel followed single number.

here script's output:

please input beam specifications search for: 1ab073c1 traceback (most recent phone call last): file "/users/sasha/documents/workspace/roo1/roo2.py", line 17, in <module> data.index(beam,) valueerror: '1ab073c1' not in list

this snippet should work:

for line in data: #need rewrite if any(item item in info if beam in item): print line else: print("no beam found")

this way, check every element of line, , see if of them contain info beam. assume nil strangely formatted contains beam shouldn't match.

python string csv

No comments:

Post a Comment