Ignore:
Timestamp:
10/01/21 23:40:49 (3 years ago)
Author:
Maciej Komosinski
Message:

Cosmetic/minor improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/frams-test-props.py

    r1151 r1158  
     1"""An example of iterating through the properties of an ExtValue object and printing their characteristics."""
     2
    13import frams
    24import sys
     
    46frams.init(*(sys.argv[1:]))
    57
    6 def printSingleProperty(v,p):
    7         print('  %s "%s" type="%s" flags=%d group=%d help="%s"' % (v._propId(p),v._propName(p),v._propType(p),v._propFlags(p),v._propGroup(p),v._propHelp(p)))
     8
     9def printSingleProperty(v, p):
     10        print(' * %s "%s" type="%s" flags=%d group=%d help="%s"' % (v._propId(p), v._propName(p), v._propType(p), v._propFlags(p), v._propGroup(p), v._propHelp(p)))
    811
    912
    1013def printFramsProperties(v):
    11         N=v._propCount()
    12         G=v._groupCount()
    13         if G<2:
    14                
    15                 #no groups, simply iterate all props
    16                
    17                 print("'%s' has %d properties" % (v._class(),v._propCount()))
     14        N = v._propCount()
     15        G = v._groupCount()
     16        print("======================= '%s' has %d properties in %d group(s). =======================" % (v._class(), N, G))
     17        if G < 2:
     18                # No groups, simply iterate all properties
    1819                for p in range(v._propCount()):
    19                         printSingleProperty(v,p)
    20                
     20                        printSingleProperty(v, p)
    2121        else:
    22                
    23                 #iterate through groups and iterate all props in a group.
    24                 #why the distinction?
    25                 #first, just to show there are two ways. there is always at least one
    26                 #group so you can always get all props by iterating the group.
    27                 #second, groups actually do not exist as collections. iterating in
    28                 #groups works by checking all properties on each iteration and
    29                 #testing which one is the m-th property of the group.
    30                 #these inefficient _memberCount() and _groupMember() are provided
    31                 #for the sake of completeness but don't use them without good reason ;-)
    32                
    33                 print("'%s' has %d properties in %d group(s)" % (v._class(),v._propCount(),v._groupCount()))
     22                # Iterate through groups and iterate all props in a group.
     23                # Why the distinction?
     24                # First, just to show there are two ways. There is always at least one
     25                # group so you can always get all properties by iterating the group.
     26                # Second, groups actually do not exist as collections. Iterating in
     27                # groups works by checking all properties on each iteration and
     28                # testing which one is the m-th property of the group!
     29                # So these inefficient _memberCount() and _groupMember() are provided
     30                # for the sake of completeness, but don't use them without a good reason ;-)
    3431                for g in range(G):
    35                         print('\n=========== Group #%d: %s ==========' % (g,v._groupName(g)))
     32                        print('\n------------------- Group #%d: %s -------------------' % (g, v._groupName(g)))
    3633                        for m in range(v._memberCount(g)):
    37                                 p=v._groupMember(g,m)
    38                                 printSingleProperty(v,p)
    39                         print('========================\n')
    40 
    41 
     34                                p = v._groupMember(g, m)
     35                                printSingleProperty(v, p)
     36        print('\n\n')
    4237
    4338
    4439printFramsProperties(frams.World)
    45                
    46 printFramsProperties(frams.GenePools[0].add('X'))
     40
     41printFramsProperties(frams.GenePools[0].add('X'))  # add('X') returns a Genotype object
Note: See TracChangeset for help on using the changeset viewer.