use of TTable and string attributes in snappy 6.0

Skip to first unread message

chris james

Apr 21, 2021, 1:59:48 PM4/21/21
to SNAP Users Group

We are having an issue with TTable in snappy 6.0.

With  string attributes.

This is what the issue is:
GetStrVal is not working on TTables, returned by a method, when they are outside that method. Other methods to access numeric TTable entries are working. I have added a toy example of this issue below.  Inside of my_reader_method(), all is fine.  Outside of it, not so much.

========= begin code ==============

import snap

## My method to read in TTable.
def my_reader_method(file_name):
    schema = snap.Schema()
    context = snap.TTableContext()

    schema.Add(snap.TStrTAttrPr("Src", snap.atInt))
    schema.Add(snap.TStrTAttrPr("Dst", snap.atInt))
    schema.Add(snap.TStrTAttrPr("weight_1", snap.atStr))
    delimiter = " "

    ttable = snap.TTable.LoadSS(schema, file_name, context, delimiter, snap.TBool(False))  
    # This will work fine
     print(ttable.GetStrVal("weight_1", 0))
     ttable_iter = ttable.BegRI()
     return ttable

#  Script starts here.
ttable = my_reader_method("tests/systemtests/test_23/graph_23.edges")
   # This will error
   print(ttable.GetStrVal("weight_1", 0))
   ttable_iter = ttable.BegRI()
   # This will error

============= end code ====================

Test file:  The example TTable file
0 1 adaf

Invoke the above Python script with SNAP 6.0.0 and Python 3.8.5, and you should see the expected output print from inside the method and observe two errors outside the method.

Thanks much for your help.


Rok Sosic

Apr 21, 2021, 4:51:19 PM4/21/21

Hi Chris,

Thank you, this is an interesting case! The solution is to define 'context' as global in my_reader_method(), add 'global context' at the beginning of this function.

I expect that the reason for the error is that context is required and maintained in the C++ code, but Python garbage collects it, since it is defined locally, and there is no Python link from TTable to context as this structure is local to C++.



You received this message because you are subscribed to the Google Groups "SNAP Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages