Contents
Default argument is took the first parametr in all standart types. In case the class (not instance) is used, it is emulated the absent this attribute.
>>> from structures import *
>>> class S(Structure):
... d1 = Decimal
... d2 = Decimal('2.62')
...
>>> s = S()
>>> s.d1
Traceback (most recent call last):
...
AttributeError: d1
>>> s.d2
Decimal('2.62')
>>> s.d1 = '3.14'
>>> s.d1
Decimal('3.14')
Type | func |
---|---|
Integer | int |
Float | float |
Decimal | decimal.Decimal |
Boolean | bool |
Binary | str |
String | unicode |
int is used for casting. It’s used base 10 for strings.
float is used for casting.
decimal.Decimal is used for casting.
bool is used for casting.
str is used for casting.
unicode is used for casting. Value enc is the encoding for casting from str.
Type | func |
---|---|
List | list |
Tuple | tuple |
Set | set |
FrozenSet | frozenset |
Dict | dict |
Defult values are recreated in the mutable containers types (List, Set & Dict) during creating the instance of structure.
>>> from structures import *
>>> l = [1, 2]
>>> class S(Structure):
... ll = List(l)
...
>>> s1 = S()
>>> s1.ll
[1, 2]
>>> assert s1.ll is not l
>>> assert s1.ll == l
>>> s2 = S()
>>> assert s1.ll is not s2.ll
>>> assert s1.ll == s2.ll
list is used for casting.
tuple is used for casting.
set is used for casting.
dict is used for casting.
Value format is time.strftime formating string. If it’s None (default), ISO-like format is used.
It accepts datetime.datetime, datetime.date (setting time as 00:00:00) and strings.
One of next formats is used for parsing strings if format is None:
- YYYY-MM-DD HH:MM:SS.mmmmmm
- YYYY-MM-DDTHH:MM:SS.mmmmmm
- YYYY-MM-DD HH:MM:SS
- YYYY-MM-DDTHH:MM:SS
- YYYY-MM-DD HH:MM
- YYYY-MM-DDTHH:MM
- YYYY-MM-DD
It accepts datetime.date, datetime.datetime (date is took only) and strings.
One of next formats is used for parsing strings if format is None and date is took only:
- YYYY-MM-DD HH:MM:SS.mmmmmm
- YYYY-MM-DDTHH:MM:SS.mmmmmm
- YYYY-MM-DD HH:MM:SS
- YYYY-MM-DDTHH:MM:SS
- YYYY-MM-DD HH:MM
- YYYY-MM-DDTHH:MM
- YYYY-MM-DD
It accepts datetime.time, datetime.datetime (time is took only) and strings.
One of next formats is used for parsing strings if format is None and time is took only:
- YYYY-MM-DD HH:MM:SS.mmmmmm
- YYYY-MM-DDTHH:MM:SS.mmmmmm
- YYYY-MM-DD HH:MM:SS
- YYYY-MM-DDTHH:MM:SS
- YYYY-MM-DD HH:MM
- YYYY-MM-DDTHH:MM
- HH:MM:SS
- HH:MM
Pleace read the structures.types module for detals... It’s realy simple!