Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79237 > unrolled thread
| Started by | varun7rs@gmail.com |
|---|---|
| First post | 2014-10-17 01:33 -0700 |
| Last post | 2014-10-17 02:18 -0700 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
Help in using grako for parsing varun7rs@gmail.com - 2014-10-17 01:33 -0700
Re: Help in using grako for parsing Peter Otten <__peter__@web.de> - 2014-10-17 10:57 +0200
Re: Help in using grako for parsing varun7rs@gmail.com - 2014-10-17 02:17 -0700
Re: Help in using grako for parsing varun7rs@gmail.com - 2014-10-17 02:18 -0700
| From | varun7rs@gmail.com |
|---|---|
| Date | 2014-10-17 01:33 -0700 |
| Subject | Help in using grako for parsing |
| Message-ID | <7228e528-c597-4fd3-8620-508361aa0f6b@googlegroups.com> |
Hello, I am trying to parse a file which ahs the below content. I tried using the split function but that wasn't a good programming practice. I had to use it repeatedly to split the line and then read my data. I thought of doing it in a better way which is when I came across grako. But I have no idea whatsoever about the usage of grako in a script. It would be nice if any of you could help me understand the usage of grako. I need to extract the values beside the variables z, f and x. The numbers represent the request ID, virtualNode ID and physical nodeID for x and it varies a bit for f, Thanks a lot z_0 1.000000 x_0_0_1 1.000000 x_0_1_5 1.000000 x_0_2_20 1.000000 x_0_3_21 1.000000 x_0_4_8 1.000000 f_0_0(0,1)_(1,5) 1.000000 f_0_1(1,2)_(5,9) 1.000000 f_0_1(1,2)_(9,20) 1.000000 f_0_2(2,3)_(2,21) 1.000000 f_0_2(3,2)_(2,22) 1.000000 f_0_2(2,3)_(20,22) 1.000000 f_0_3(4,3)_(8,10) 1.000000 f_0_3(3,4)_(0,10) 1.000000 f_0_3(4,3)_(0,14) 1.000000 f_0_3(4,3)_(14,21) 1.000000 z_1 1.000000 x_1_0_16 1.000000 x_1_1_6 1.000000 x_1_2_13 1.000000 x_1_3_0 1.000000 x_1_4_25 1.000000 x_1_5_15 1.000000 x_1_6_19 1.000000 f_1_0(1,0)_(6,16) 1.000000 f_1_1(0,2)_(6,11) 1.000000 f_1_1(0,2)_(11,13) 1.000000 f_1_1(2,0)_(6,16) 1.000000 f_1_2(3,1)_(0,6) 1.000000 f_1_3(2,4)_(13,25) 1.000000 f_1_4(5,4)_(15,25) 1.000000 f_1_5(3,6)_(0,1) 1.000000 f_1_5(3,6)_(1,18) 1.000000 f_1_5(3,6)_(18,19) 1.000000
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-10-17 10:57 +0200 |
| Message-ID | <mailman.14942.1413536278.18130.python-list@python.org> |
| In reply to | #79237 |
varun7rs@gmail.com wrote: > Hello, > I am trying to parse a file which ahs the below content. I tried using the > split function but that wasn't a good programming practice. I had to use > it repeatedly to split the line and then read my data. I thought of doing > it in a better way which is when I came across grako. But I have no idea > whatsoever about the usage of grako in a script. It would be nice if any > of you could help me understand the usage of grako. I need to extract the > values beside the variables z, f and x. The numbers represent the request > ID, virtualNode ID and physical nodeID for x and it varies a bit for f, We know Python, but not necessarily any terminology you throw at us. I didn't respond to your previous post because I had no idea what a .sol file is and what you're up to. As far as I can see no-one did. Now you make it even harder to help you by forcing us to look up "grako" to not (sic!) understand your question... You give sample input below. Perhaps you'll get more/better feedback if you provide a sample of the output you need, too, together with a more elaborate and accessible explanation of how you think you could get there. > z_0 1.000000 > x_0_0_1 1.000000 > x_0_1_5 1.000000 > x_0_2_20 1.000000 > x_0_3_21 1.000000 > x_0_4_8 1.000000 > f_0_0(0,1)_(1,5) 1.000000 > f_0_1(1,2)_(5,9) 1.000000 > f_0_1(1,2)_(9,20) 1.000000 > f_0_2(2,3)_(2,21) 1.000000 > f_0_2(3,2)_(2,22) 1.000000 > f_0_2(2,3)_(20,22) 1.000000 > f_0_3(4,3)_(8,10) 1.000000 > f_0_3(3,4)_(0,10) 1.000000 > f_0_3(4,3)_(0,14) 1.000000 > f_0_3(4,3)_(14,21) 1.000000 > z_1 1.000000 > x_1_0_16 1.000000 > x_1_1_6 1.000000 > x_1_2_13 1.000000 > x_1_3_0 1.000000 > x_1_4_25 1.000000 > x_1_5_15 1.000000 > x_1_6_19 1.000000 > f_1_0(1,0)_(6,16) 1.000000 > f_1_1(0,2)_(6,11) 1.000000 > f_1_1(0,2)_(11,13) 1.000000 > f_1_1(2,0)_(6,16) 1.000000 > f_1_2(3,1)_(0,6) 1.000000 > f_1_3(2,4)_(13,25) 1.000000 > f_1_4(5,4)_(15,25) 1.000000 > f_1_5(3,6)_(0,1) 1.000000 > f_1_5(3,6)_(1,18) 1.000000 > f_1_5(3,6)_(18,19) 1.000000
[toc] | [prev] | [next] | [standalone]
| From | varun7rs@gmail.com |
|---|---|
| Date | 2014-10-17 02:17 -0700 |
| Message-ID | <3fbc4d4d-c992-4ca8-99fc-ec138fce3523@googlegroups.com> |
| In reply to | #79237 |
I'm really sorry for not being clear. I shall explain things in detail from now onwards. Really sorry. The output I would like is <RF schema="RF.xsd" version=""> <VNE> <requests> <request ID="'0'"> <virtualnodes> <virtualnode PhysicalNode_ID="'1'" Request_ID="'0'" VirtualNode_ID="'0'"/><virtualnode PhysicalNode_ID="'5'" Request_ID="'0'" VirtualNode_ID="'1'"/><virtualnode PhysicalNode_ID="'20'" Request_ID="'0'" VirtualNode_ID="'2'"/><virtualnode PhysicalNode_ID="'21'" Request_ID="'0'" VirtualNode_ID="'3'"/><virtualnode PhysicalNode_ID="'8'" Request_ID="'0'" VirtualNode_ID="'4'"/></virtualnodes> <virtualedges> <virtualedge PhysicalEdgeHead_ID="'5'" PhysicalEdgeTail_ID="'1'" Request_ID="'0'" VirtualEdgeHead_ID="'1'" VirtualEdgeTail_ID="'0'"/><virtualedge PhysicalEdgeHead_ID="'9'" PhysicalEdgeTail_ID="'5'" Request_ID="'0'" VirtualEdgeHead_ID="'2'" VirtualEdgeTail_ID="'1'"/><virtualedge PhysicalEdgeHead_ID="'20'" PhysicalEdgeTail_ID="'9'" Request_ID="'0'" VirtualEdgeHead_ID="'2'" VirtualEdgeTail_ID="'1'"/><virtualedge PhysicalEdgeHead_ID="'21'" PhysicalEdgeTail_ID="'2'" Request_ID="'0'" VirtualEdgeHead_ID="'3'" VirtualEdgeTail_ID="'2'"/><virtualedge PhysicalEdgeHead_ID="'22'" PhysicalEdgeTail_ID="'2'" Request_ID="'0'" VirtualEdgeHead_ID="'2'" VirtualEdgeTail_ID="'3'"/><virtualedge PhysicalEdgeHead_ID="'22'" PhysicalEdgeTail_ID="'20'" Request_ID="'0'" VirtualEdgeHead_ID="'3'" VirtualEdgeTail_ID="'2'"/><virtualedge PhysicalEdgeHead_ID="'10'" PhysicalEdgeTail_ID="'8'" Request_ID="'0'" VirtualEdgeHead_ID="'3'" VirtualEdgeTail_ID="'4'"/><virtualedge PhysicalEdgeHead_ID="'10'" PhysicalEdgeTail_ID="'0'" Request_ID="'0'" VirtualEdgeHead_ID="'4'" VirtualEdgeTail_ID="'3'"/><virtualedge PhysicalEdgeHead_ID="'14'" PhysicalEdgeTail_ID="'0'" Request_ID="'0'" VirtualEdgeHead_ID="'3'" VirtualEdgeTail_ID="'4'"/><virtualedge PhysicalEdgeHead_ID="'21'" PhysicalEdgeTail_ID="'14'" Request_ID="'0'" VirtualEdgeHead_ID="'3'" VirtualEdgeTail_ID="'4'"/></virtualedges> In a similar way I have something like this for every request. This is what I intend to get from the input that I had pasted earlier.
[toc] | [prev] | [next] | [standalone]
| From | varun7rs@gmail.com |
|---|---|
| Date | 2014-10-17 02:18 -0700 |
| Message-ID | <92338730-467b-49a5-b235-ca6b9015b089@googlegroups.com> |
| In reply to | #79237 |
Oh damn, it turned out really crappy. I could not format it properly
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web