list indices must be integers, not tuple

86 views
Skip to first unread message

josh...@gmail.com

unread,
Nov 5, 2014, 5:52:42 PM11/5/14
to bots...@googlegroups.com
Hello,
Trying to perform my first translation using a fixed format as input. When attempting to run the translation, I get the following error message that references the fixed grammar file:

list indices must be integers, not tuple

The structure is pretty basic and I have compared to plugin examples and everything appears to be correct. Any ideas what may be incorrect? I'm assuming it has to do with the definition of the grammar, itself:

from bots.botsconfig import *

syntax = {
        'charset'                  : 'utf-8',                                           # character set is utf-8
        'checkfixedrecordtooshort' : False,                                             # check if fixed record is to short
        'indented'                 : False,                                             # xml: produced indented output
        'noBOTSID'                 : True
        }

structure =     [
                {ID:'HDR',MIN:1,MAX:99999}                                               # event record
                ]


recorddefs = {                                                                          # 'recorddefs' section
 'HDR':[
        ['BOTSID', 'C', 2, 'AN'],                                                       # BOTSID
        ['Trk-Rec-Type', 'C', (2,2), 'AN']
        ['Trk-Rec-Client-ID', 'C', (3,3), 'AN'],                                                # Client ID
        ['Trk-Rec-Client-Child-ID', 'C', (3,3), 'AN'],                                  # Client brand or sub-client ID
        ['Trk-Rec-Client-Name', 'C', (32,32), 'AN'],                                    # Company name
        ['Trk-Rec-Client-Child-Name', 'C', (32,32), 'AN'],                                      # Company brand or sub-client name
        ['Trk-Rec-Hermes-Barcode-Number', 'C', (25,25), 'AN'],                          # The Hermes barcode number for the parcel (if supplied in the request file)
        ['Trk-Rec-Customer-Reference-1', 'C', (20,20), 'AN'],                           # A unique reference number that you use in your system to identify this parcel
        ['Trk-Rec-Customer-Reference-2', 'C', (20,20), 'AN'],                           # Value Spaces unless advised by Hermes
        ['Trk-Rec-Tracking-Event-ID', 'C', (9,9), 'AN'],                                        # The ID of the tracking event that took place for this parceli
        ['Trk-Rec-Tracking-Event-Date', 'C', (12,12), 'AN'],                            # Date the tracking event was recorded against this parcel
        ['Trk-Rec-Tracking-Event-Additional-Information', 'C', (32,32), 'AN'],          # If available, any additional information relevant to the tracking event which took place
        ['Trk-Rec-Linked-Barcode-Number', 'C', (25,25), 'AN'],                          # Value Spaces unless advised by Hermes
        ['Trk-Rec-Filler-1', 'C', (30,30), 'AN'],                                               # Values Spaces
        ['Trk-Rec-Filler-2', 'C', (20,20), 'AN'],                                               # Values Spaces
     ],
 }

henk-jan ebbers

unread,
Nov 5, 2014, 6:00:02 PM11/5/14
to bots...@googlegroups.com
try this:
['BOTSID', 'C', 2, 'AN'], # BOTSID
['Trk-Rec-Type', 'C', 2, 'AN']
['Trk-Rec-Client-ID', 'C', 3, 'AN'], # Client ID
['Trk-Rec-Client-Child-ID', 'C', 3, 'AN'], # Client brand or sub-client ID
(etc etc)

(changed field length from eg (2,2) -> 2


kind regards,
henk-jan
> --
> You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+u...@googlegroups.com <mailto:botsmail+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

BikeMike

unread,
Nov 6, 2014, 2:22:50 AM11/6/14
to bots...@googlegroups.com
The wiki does indicate this is allowed (min length,max length) although I never use it.
https://code.google.com/p/bots/wiki/GrammarsRecorddefs#For_each_field

BikeMike

unread,
Nov 6, 2014, 3:54:44 AM11/6/14
to bots...@googlegroups.com
It is simply a python syntax error in your grammar; missing a comma at the end of ['Trk-Rec-Type', 'C', (2,2), 'AN']

The definition of field length (2,2) is ok.

henk-jan ebbers

unread,
Nov 6, 2014, 8:01:51 AM11/6/14
to bots...@googlegroups.com
good catch. did not see that one!

(I am a bit surprized this was not a syntax error)

kind regards,
henk-jan

On 11/06/2014 09:54 AM, BikeMike wrote:
> It is simply a python syntax error in your grammar; missing a comma at the end of ['Trk-Rec-Type', 'C', (2,2), 'AN']
>
> The definition of field length (2,2) is ok.
>

josh...@gmail.com

unread,
Nov 7, 2014, 3:53:00 PM11/7/14
to bots...@googlegroups.com
What a silly mistake! I was assuming the grammar would not have compiled properly if there was such a syntactical error.

Thanks.

BikeMike

unread,
Nov 7, 2014, 6:49:00 PM11/7/14
to bots...@googlegroups.com

Correct!

Some editors will allow you to add a "user tool" so you can add a syntax check in the editor (I use EditPlus and have done this). So I just copy/pasted your code in my editor and did a syntax check.

It says line 19 but the actual error is sometimes on a previous line as in this example.



Reply all
Reply to author
Forward
0 new messages