Support code for AMUSE framework

class amuse.support.core.late(initializer)

An attribute that is set at first access.

The value of the attribute will be determined from the initializer method. The name of the attribute is the same as the name of the initializer method.

A late attribute is comparible with attributes set in the __init__ method. Except the value of the late attribute is determined when first accessed and not when the class is instantiated.

Typical use to define a managed attribute x:

>>> class C(object):
...    @late
...    def x(self):
...        return "i'm late!"
...
>>> c = C()
>>> print c.x
i'm late!
>>> c.x = "overridden"
>>> print c.x
overridden
Parameters:initializer – function to determine the initial value of the property
Returns:a descriptor to determine and set the value on first access
class amuse.support.core.print_out

Efficient way to contruct large strings.

Strings are build up out of parts. Objects of this class store these parts while building the string. Only on request the parts are concatenated into a large string.

Strings and numbers can be added to the print_out. For other objects str(object) is called before adding it to the print_out.

>>> p = print_out()
>>> p + "number of counts : " + 10    
<amuse.support.core.print_out object at 0x...>
>>> print p.string
number of counts : 10

All methods return the print_out instance, so that calls can be chained.

__add__(x)

Add a new part to the print_out.

dedent()

Decrease the indent. The next line will start dedented.

>>> p = print_out()
>>> p + "01" 
<amuse.support.core.print_out object at 0x...>
>>> p.indent().lf() + "2" 
<amuse.support.core.print_out object at 0x...>
>>> p.dedent().lf() + "01" 
<amuse.support.core.print_out object at 0x...>
>>> print p.string
01
  2
01
indent()

Increase the indent. The next and following lines will start indented.

>>> p = print_out()
>>> p + "01" 
<amuse.support.core.print_out object at 0x...>
>>> p.indent().lf() + "2" 
<amuse.support.core.print_out object at 0x...>
>>> p.lf() + "3" 
<amuse.support.core.print_out object at 0x...>
>>> print p.string
01
  2
  3
indent_characters()

The indent characters, by default 2 spaces.

Override this method to change the indent characters.

lf()

Start a new-line

lf_noindent()

Start a new-line

n()

Start a new-line, if the current line is not-empty.

>>> p = print_out()
>>> for i in range(3):
...     p.n() + i 
...
<amuse.support.core.print_out object at 0x...>
<amuse.support.core.print_out object at 0x...>
<amuse.support.core.print_out object at 0x...>
>>> print p.string
0
1
2
string

String version of the print_out.

class amuse.support.core.OrderedDictionary

A dictionary that keeps the keys in the dictionary in order.

Ordered dictionaries are just like regular dictionaries but they remember the order that items were inserted. When iterating over an ordered dictionary, the values are returned in the order their keys were first added.

>>> d = OrderedDictionary()
>>> d["first"] = 0
>>> d["second"] = 1
>>> d["third"] = 2
>>> [x for x in d]
[0, 1, 2]

Previous topic

Currently supported Community Codes

Next topic

Support code for the community code interfaces

This Page