[Tutor] Lost in the control flow
Adam Bark
adam.jtm30 at gmail.com
Tue Aug 10 21:56:29 CEST 2010
On 10/08/10 20:39, Eduardo Vieira wrote:
> Hello, list! I'm trying to parse a text file. I'm getting confuse with
> my strategy, and flags or how to use a sequence of ifs or elifs,
> continue, etc. Anyhow, after several experiments this is close to what
> I'd like to get, except, I can't find a way to include all the pin
> numbers (12 number sequence):
>
> Here is my code:
> http://pastebin.com/1ps6WdF4
>
> The example file is this:
> http://pastebin.com/1MZmE4d3
>
>
> Basically, as a initial step, I'd like to transform this:
> 17 600775301465 CAREYON SIGNS& GRAPHICS EXP 5
> 93.00 $0.00 $ 26.77
>
> RED DEER AB T4N1L2
> FUEL SURCHARGE: 2.10
>
>
> GST/HST: 1.44
>
>
>
> 600775301465 18.60
>
> 600775301473 18.60
>
> 600775301481 18.60
>
>
> into this. View the code and file for details, please:
> {'city': 'AB', 'company': 'CAREYON SIGNS& GRAPHICS', 'tracking':
> ['600775301465', '600775301473', '600775301481', ], 'id': '17'}
>
>
> The way the code is working now I only get this:
> {'city': 'AB', 'company': 'CAREYON SIGNS& GRAPHICS', 'tracking':
> ['600775301465', '600775301465'], 'id': '17'}, and a only the ones
> that have multiple pin numbers.
>
> I'd appreciate your help. Thanks.
>
> Eduardo
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
The problem is you don't call make_dict unless there's a "FUEL
SURCHARGE" or multiple pins. Also you don't add the first pin to
mydict["tracking"] unless there's a "FUEL SURCHARGE".
HTH,
Adam.
More information about the Tutor
mailing list