homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zach.ware
Recipients Ramchandra Apte, eric.smith, joncle, mark.dickinson, rhettinger, skrah, terry.reedy, zach.ware
Date 2012年08月23日.18:11:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1345745520.63.0.880371492256.issue15136@psf.upfronthosting.co.za>
In-reply-to
Content
I came across this issue and thought it might be within my means to attempt a patch, so here's the first step towards one. I liked Terry's suggestion of implementing __format__ using .as_decimal, so that's what I'm working towards with this.
The first part is (or seems to be, I am pretty new at this and may well have missed something obvious :-)) pretty easy. The attached patch is pretty self-explanatory, I think. I figure if the user wants something specific from their fraction-as-a-decimal, they're probably working with other decimals already and will be able to supply a context. Otherwise, if they just want to see a decimal representation, they'll probably be fine with the default context and don't have to worry about it.
The __format__ part, though, seems kind of daunting. For one thing, Decimal's implementation looks pretty hairy and scary from my perspective; duplicating it for Fraction would be quite a feat. For another, the standard format spec doesn't seem to me to cleanly apply to fractional representations--what should be filled, how should alignment work, how would width be divided up, what exactly does precision mean?
I've had a thought, though; what if Fraction.__format__ simply looks for a 'D' at the end of format_spec? If it's found, just return format(self.as_decimal(), format_spec[:-1]. Otherwise, format using to-be-determined rules specific to fractions, including rules for, say, mixed fractions or denominator of a certain size.
Thoughts?
History
Date User Action Args
2012年08月23日 18:12:00zach.waresetrecipients: + zach.ware, rhettinger, terry.reedy, mark.dickinson, eric.smith, skrah, joncle, Ramchandra Apte
2012年08月23日 18:12:00zach.waresetmessageid: <1345745520.63.0.880371492256.issue15136@psf.upfronthosting.co.za>
2012年08月23日 18:12:00zach.warelinkissue15136 messages
2012年08月23日 18:11:59zach.warecreate

AltStyle によって変換されたページ (->オリジナル) /