source: framspy/frams-test-props.py @ 1189

Last change on this file since 1189 was 1162, checked in by Maciej Komosinski, 2 years ago

Cosmetic

  • Property svn:eol-style set to native
File size: 1.7 KB
RevLine 
[1162]1"""An advanced example of iterating through the properties of an ExtValue object and printing their characteristics.
2This example may be useful for some developers, but it is not needed for a regular usage of Framsticks (i.e. simulation and evolution)."""
[1158]3
[1151]4import frams
5import sys
6
7frams.init(*(sys.argv[1:]))
8
9
[1158]10def printSingleProperty(v, p):
11        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)))
[1151]12
[1158]13
[1151]14def printFramsProperties(v):
[1158]15        N = v._propCount()
16        G = v._groupCount()
17        print("======================= '%s' has %d properties in %d group(s). =======================" % (v._class(), N, G))
18        if G < 2:
19                # No groups, simply iterate all properties
[1151]20                for p in range(v._propCount()):
[1158]21                        printSingleProperty(v, p)
[1151]22        else:
[1158]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 properties 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                # So these inefficient _memberCount() and _groupMember() are provided
31                # for the sake of completeness, but don't use them without a good reason ;-)
[1151]32                for g in range(G):
[1158]33                        print('\n------------------- Group #%d: %s -------------------' % (g, v._groupName(g)))
[1151]34                        for m in range(v._memberCount(g)):
[1158]35                                p = v._groupMember(g, m)
36                                printSingleProperty(v, p)
37        print('\n\n')
[1151]38
39
[1158]40printFramsProperties(frams.World)
[1151]41
[1158]42printFramsProperties(frams.GenePools[0].add('X'))  # add('X') returns a Genotype object
Note: See TracBrowser for help on using the repository browser.