cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1641
Views
5
Helpful
1
Replies

Accessing a a yang list in Python code

Fantolino
Level 1
Level 1

Hi! I’m trying to access in python to the elements of a yang list. The yang model is:

      list Prenotazione {

        key "TempoAtt";

        unique "TempoDis"; 

 

        leaf TempoAtt {

          type string

        }

        …

And the code I’m trying to use is something

       FirstElementKey = service.Prenotazione.????

In order to access the leaf inside le list element with code such as:

    MyData = service.Prenotazione[FirstElementKey].LeafName

 

How can I do? Is it corect to assume the lis is ordered according to the key?

 

 

1 Accepted Solution

Accepted Solutions

jfloresr
Cisco Employee
Cisco Employee

Hi, in service create code, the service object is an instance of the particular service being instantiated at that moment.

 

For example (using your yang model):

 

service.TempoAtt

 

If you want to access data from other service instances use the root object like so:

 

root.services.Prenotazione[FirstElementKey] 

 

BTW root.services.Prenotazione returns an iterator so you can just walk it without needing to know the keys.

For what I have seen yes, the service is ordered by the key. 

View solution in original post

1 Reply 1

jfloresr
Cisco Employee
Cisco Employee

Hi, in service create code, the service object is an instance of the particular service being instantiated at that moment.

 

For example (using your yang model):

 

service.TempoAtt

 

If you want to access data from other service instances use the root object like so:

 

root.services.Prenotazione[FirstElementKey] 

 

BTW root.services.Prenotazione returns an iterator so you can just walk it without needing to know the keys.

For what I have seen yes, the service is ordered by the key.