Are you sure that the right comparison operator is invoked? Python2 [1] will happily compare anything [2]. Even if it does not make sense. I noticed this on a nother project where I'm using boost-python. Try printing int(bal1) > int(bal2), for example. Or check bal1.__lt__ and bal1.__class__.__lt__ if you notice something strange.
[1] see http://docs.python.org/3/whatsnew/3.0.html "The ordering comparison operators (<, <=, >=, >) raise a TypeError exception when the operands don’t have a meaningful natural ordering. Thus, expressions like 1 < '', 0 > None or len <= len are no longer valid, and e.g. None < None raises TypeError instead of returning False. A corollary is that sorting a heterogeneous list no longer makes sense – all the elements must be comparable to each other. Note that this does not apply to the == and != operators: objects of different incomparable types always compare unequal to each other." [2]: class A(object): pass class B(object): pass a = A(); b = B() a > b # => False (on my system) On Thu, Aug 15, 2013 at 2:09 AM, Zack Williams <[email protected]> wrote: > Just an FYI, if you're using the ledger python interface, balance > objects compare the opposite of the sign. > > Given this input: > > -- > 2013-01-01 Items for One > Customer:One:Items $100 > Accounts:Checking > > 2013-01-02 Items for Two > Customer:Two:Items $40 > Accounts:Checking > -- > and this code: > > > -- > import ledger > > journal = ledger.read_journal("py_acc_re_test.lgr") > comms = ledger.commodities > usd = comms.find_or_create('$') > > def balance_posts_subaccts(account, start_d=None, end_d=None): > total = ledger.Balance() > for post in account.posts(): > if start_d and post.date < start_d: > continue > if end_d and post.date > end_d: > continue > total += post.amount > for subacct in account.accounts(): > total += balance_posts_subaccts(subacct, start_d, end_d) > return total > > def balance_re_subaccts(top_account, match_account, start_d=None, end_d=None): > total = ledger.Balance() > for subacct in top_account.accounts(): > if subacct.name == match_account: > total += balance_posts_subaccts(subacct, start_d, end_d) > else: > total += balance_re_subaccts(subacct,match_account,start_d,end_d) > return total > > account = journal.find_account_re("") > > bal1 = balance_re_subaccts(account,"One") > bal2 = balance_re_subaccts(account,"Two") > > print "bal1 = %s" % bal1.value(usd) > print "bal2 = %s" % bal2.value(usd) > > if bal1 > bal2: > print "bal1 is more" > else: > print "bal2 is more" > --- > > The output is: > -- > bal1 = $100 > bal2 = $40 > bal2 is more > -- > > I'm assuming there's some reversed comparison operator in there somewhere. > > Thanks, > Zack > > -- > > --- > You received this message because you are subscribed to the Google Groups > "Ledger" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. -- --- You received this message because you are subscribed to the Google Groups "Ledger" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
