1
I have a txt with some information. txt follows the following pattern:
1 - Beginning of the block
2 - Information
3 - Description of line 2
So for example
190845 3890580235203895 0329045832854880328 58908349058340534859 hjdfhgjdfhg dgfdgdf
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN
120845 3890580235203895 0329045832854880328 58908349058340534859 hjdfhgjdfhg dgfdgdf
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN
What I need is to separate the blocks into different variables knowing that they start at 1 and end at the next incidence of 1. The example above would be:
a = '190845 3890580235203895 0329045832854880328 58908349058340534859 hjdfhgjdfhg dgfdgdf
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN'
b = '120845 3890580235203895 0329045832854880328 58908349058340534859 hjdfhgjdfhg dgfdgdf
22343 34234234 324234 324234234 234234 342324989856475959596
3SHDSHFUHDSFUHSDUFHSHDFUDSFDSTTJKKHGHJMNMNBN'
I tried to do it by matching while
+ readline
+ startswith
, but I couldn’t
Can appear the value 1 anywhere on the line, inside the information, or always 1 will represent the beginning of the block?
– Woss
Hello Anderson! How long ! So, 1 can appear anywhere in the file, but the 1 that represents the beginning of the block will always be at position 1 of the line
– Lucas Torres
i had tried line.startswith("1"), but to manipulate the whole block became unviable
– Lucas Torres
Thus what did you do? I think with regular expression you can make a better solution, but I can not think of anything at this time.
– Woss
@Andersoncarloswoss your tip helped a lot !!
– Lucas Torres