python - Organizing data in mix of comma-separated, tab-separated format -


I am a complete newbie in Python, if you can help me then it would be great that my data format is somewhat like this I'm glad if someone can help me.

  Car Trans + 1,4,6,8 aircraft trans + 3,5,79,4,3 train trans - 2,4,6,7 bus trans - 1,3, 4,5,6,7,8   

Out of the comma-separated values, I'm just trying to remove "Event" numbers (2, 4, 6, 8) , 10th, etc.) is presenting it out and the value of the third column on the basis of + or -.

I want to move "Event" numbers with data separated by commas if it is "+", then the number goes to the fourth column and adds that value to 1, then it will be 5th column Keep in If it is "-", then the number holds the value of the fifth column and the value of zero to the fourth column. I know that this is really an explanation of the explanation, but it would be great if someone can give me an idea from where I can start Thanksgiving

  car.1 trans + 4 5 car .2 Trans + 8 9 Plan 1 Trans + 5 6 Plane 2 Trans + 9 10 Plane 3 Trans + 3 4 Train 1 Trans - 3 4 Train 2. Trans - 6 7 Bus .1 Trans - 2 3 Bus 2. Trans - 4 5 simply 3. Trans - 6 7   

edit2: After a lot of searches and help you guys, I have something like that now . It gives me the proper output but my only problem is that I am having trouble giving it the correct name. (I.e. car .1, car.2, car.3, plane 1, plane 2 .... etc) Can anyone give me information about this problem? Import import system string infileName = sys.argv [1] outfileName = sys.argv [2] def getGenes (infile, outfile): infile = open (infileName, "r") outfile = open (outfileName, "w") while 1: line = infil.readline () if not, then line: break wrds = string.split (line) comma = string. split (wrds [3], ",") print (Comma) fivess = comma [1 :: 2] print (fivess) if lin (wrds)> = 2: name = wrds [0] chr = wrds [1] type = wrds [2] print (type) type == "+": for jv in fivess: start = jj stop = string.atoi (jj) + 1 outfile.write ('% s \ t% s \ t% s \ t% s \ t% s \ n'% (name, crr, type, start, stop)) elif type = = "-": for fjess jj: stop = jj start = string.atoi (jj) -1 outfile.write ('% s \ t% s \ t% s \ t% s \ t% s \ n'% (name, crr, type) , Start, stop) getGenes (infileName, outfileName)

Split; Then divide the last item (list of numbers) on a comma, it will give you all bits to do your processing.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -