>So what you are saying is, if I enter a unit in feet, you automatically
>change that unit to some base unit (say, metres if you use SI) behind my
>back. So, assuming SI units as the base, if I say:
>print 2*ft + 1*ft
>you're going to give me an answer of 0.9144 metres, instead of the
>expected 3
On Fri, 07 Apr 2006 21:18:23 -0700, Russ wrote:
>> dist = 4 * ft
>> print >> out, dist/ft
>>> 4
>
>>> Note, however, that this requires the user to explicity ask for the
>>> conversion.
>
>>How is this any more explicit and any less safe than:
>
>>dist = 4 * ft
>>print float(dist)
>
>
Let me just revise earlier my reply slightly.
>But in any case, I suspect you do automatically convert units. What do you
>do in this case:
Yes, I do automatically convert units, but I only do correct
conversions. Conversion from any unit other than radian to a
dimensionless float is incorrect, s
> dist = 4 * ft
> print >> out, dist/ft
>> 4
>> Note, however, that this requires the user to explicity ask for the
>> conversion.
>How is this any more explicit and any less safe than:
>dist = 4 * ft
>print float(dist)
Because the former specifies the actual units and the latter does n
On Thu, 06 Apr 2006 17:14:22 -0700, Russ wrote:
>>I suggest another approach: play nice with the rest of Python by allowing
>>people to convert your units into strings and floats. Once they have
>>explicitly done so, it isn't your problem if they want to add 35 metres to
>>18 kilograms and convert
>I'm sorry, your system of units doesn't allow trig functions to operate on
>degrees? I presume you don't allow grads either. What about steradians or
>other arbitrary measures of angle or solid angle?
I should have stated that more clearly. You can enter the value in
degrees, but it will automati
On Thu, 06 Apr 2006 11:05:06 -0700, Russ wrote:
>>Really, your response seems a little bizarre to me, given that __float__
>>is the defined way in which float() gets a value from an instance, and
>>float() is what the % operator calls when it encounters a '%f' in the
>>format string.
>
> My class
>Yeah, how about we read your mind or make wild guesses about why it's
>not acceptable, and about what your requirements really are.
>Really, your response seems a little bizarre to me, given that __float__
>is the defined way in which float() gets a value from an instance, and
>float() is what th
Russ wrote:
> Thanks, but that is not acceptable for my application. Any other ideas?
Yeah, how about we read your mind or make wild guesses about why it's
not acceptable, and about what your requirements really are.
Really, your response seems a little bizarre to me, given that __float__
is th
Thanks, but that is not acceptable for my application. Any other ideas?
I thought I might be able to overload __rmod__, but apparently python
applies the % operator before __rmod__ is even invoked if the left-hand
argument is a string.
--
http://mail.python.org/mailman/listinfo/python-list
Russ wrote:
> I'd like to get output formatting for my own classes that mimics the
> built-in output formatting. For example,
>
>
x = 4.54
print "%4.2f" % x
>
>
> 4.54
>
> In other words, if I substitute a class instance for "x" above, I'd
> like to make the format string apply to an e
I'd like to get output formatting for my own classes that mimics the
built-in output formatting. For example,
>>> x = 4.54
>>> print "%4.2f" % x
4.54
In other words, if I substitute a class instance for "x" above, I'd
like to make the format string apply to an element or elements of the
instance
12 matches
Mail list logo