summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-03 19:05:33 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-03 19:06:56 -0400
commitc6d3cce6d5ace51aa48b6d4af0e7149ba79bb1e8 (patch)
tree87f149ddfb1a7ef37ee059aee3454271745c61a5 /python
parent71642d98de7e55b235f45feb8e68199ff3c357aa (diff)
downloadfork-ledger-c6d3cce6d5ace51aa48b6d4af0e7149ba79bb1e8.tar.gz
fork-ledger-c6d3cce6d5ace51aa48b6d4af0e7149ba79bb1e8.tar.bz2
fork-ledger-c6d3cce6d5ace51aa48b6d4af0e7149ba79bb1e8.zip
Added __str__ and __repr__ methods for ledger.Value.
Diffstat (limited to 'python')
-rw-r--r--python/py_value.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/python/py_value.cc b/python/py_value.cc
index 034d3f8f..80952d7d 100644
--- a/python/py_value.cc
+++ b/python/py_value.cc
@@ -54,6 +54,18 @@ boost::optional<value_t> py_value_2(const value_t& amount,
return amount.value(moment, in_terms_of);
}
+string py_print(const value_t& value) {
+ std::ostringstream buf;
+ value.print(buf);
+ return buf.str();
+}
+
+string py_print_relaxed(const value_t& value) {
+ std::ostringstream buf;
+ value.print(buf, true);
+ return buf.str();
+}
+
void py_set_string(value_t& amount, const string& str) {
return amount.set_string(str);
}
@@ -234,6 +246,7 @@ void export_value()
.def("to_boolean", &value_t::to_boolean)
.def("to_long", &value_t::to_long)
+ .def("__int__", &value_t::to_long)
.def("to_datetime", &value_t::to_datetime)
.def("to_date", &value_t::to_date)
.def("to_amount", &value_t::to_amount)
@@ -242,6 +255,9 @@ void export_value()
.def("to_string", &value_t::to_string)
.def("to_sequence", &value_t::to_sequence)
+ .def("__str__", py_print_relaxed)
+ .def("__repr__", py_print)
+
.def("cast", &value_t::cast)
.def("in_place_cast", &value_t::in_place_cast)