Alan Gauld | 1 Jul 02:14 2010

Re: Decorators


"Mary Morris" <marris1031 <at> gmail.com> wrote

> anything.  I need to find out every decorator and make sure it has a
> descriptive name.  I was thinking I could write a simple script 
> which would
> parse through all of the source files and find decorators-maybe by 
> looking
> for the  <at>  symbol?

I would first try a good IDE. I don't have it installed at the moment 
but I
think pydev for Eclipse can find decorator definitions. Combined with
a power search to locate all uses of decorators that might be easier.

Just a thought and I might be remembering wrong. But if you are doing
serious Python coding Eclipse and PyDev are a good combination.

It should also be possible to get GNU tags to handle decoratiors too - 
it
already works with Pythion and vim will work with tags...

In other words don't be too quick to jump to a programming solution,
OS level tools may be a better first step. Especially if you are on 
*nix.

HTH,

--

-- 
Alan Gauld
(Continue reading)

Richard D. Moores | 1 Jul 10:26 2010
Picon

puzzled by Python 3's print()

>>> x = 2000000000000034
>>> x/2
1000000000000017.0
>>> print(x/2)
1e+15

I was expecting, in fact needing, 1000000000000000017 or 1000000000000000017.0

1e+15 is unsatisfactory. Am I forced to use the decimal module?

Dick Moores
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

शंतनू (Shantanoo | 1 Jul 10:41 2010
Picon

Re: puzzled by Python 3's print()

without using decimal module:

>>> x = 2000000000000034
>>> print('%d'%(x/2))
1000000000000017

On Thu, Jul 1, 2010 at 13:56, Richard D. Moores <rdmoores <at> gmail.com> wrote:
>>>> x = 2000000000000034
>>>> x/2
> 1000000000000017.0
>>>> print(x/2)
> 1e+15
>
> I was expecting, in fact needing, 1000000000000000017 or 1000000000000000017.0
>
> 1e+15 is unsatisfactory. Am I forced to use the decimal module?
>
> Dick Moores
> _______________________________________________
> Tutor maillist  -  Tutor <at> python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Evert Rol | 1 Jul 10:45 2010
Picon

Re: puzzled by Python 3's print()

>>>> x = 2000000000000034
>>>> x/2
> 1000000000000017.0
>>>> print(x/2)
> 1e+15
> 
> I was expecting, in fact needing, 1000000000000000017 or 1000000000000000017.0
> 
> 1e+15 is unsatisfactory. Am I forced to use the decimal module?

Can't you use string formatting? Eg:
>>> print("{0:15.0f}".format(x/2))
1000000000000017

print uses __str__()/str(), which I assume was deemed unsatisfactory in Python 2: it's supposed to show a
'simple, nice' representation of anything, while __repr__() (or the repr() function) shows a more exact
representation (or rather, repr() shows an object that can be used to recreate a new identical object:
float(repr(x/2)) gives back the correct float, while float(str(x/2)) wouldn't). 
So they've apparently changed __str__() to make things somewhat more readable. __repr__()/repr() is
what you get with just using x/2 on the command line:

>>> x/2
1000000000000017.0
>>> repr(x/2)
1000000000000017.0

And you could actually use:

>>> print(repr(x/2))
1000000000000017.0
(Continue reading)

Steven D'Aprano | 1 Jul 13:57 2010

Re: puzzled by Python 3's print()

On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote:
> >>> x = 2000000000000034
> >>> x/2
> 1000000000000017.0
>
> >>> print(x/2)
> 1e+15
>
> I was expecting, in fact needing, 1000000000000000017 or
> 1000000000000000017.0
>
> 1e+15 is unsatisfactory. Am I forced to use the decimal module?

This is not an issue with print, this is an issue with floats -- they 
produced a rounded, approximate value when converted to a string. print 
merely prints that string:

>>> x = 1e15 +17
>>> x
1000000000000017.0
>>> print(x)
1e+15
>>> str(x)
'1e+15'

If you want more control over the string conversion, you can do 
something like this:

>>> print(repr(x))
1000000000000017.0
(Continue reading)

Richard D. Moores | 1 Jul 15:11 2010
Picon

Re: puzzled by Python 3's print()

On Thu, Jul 1, 2010 at 04:57, Steven D'Aprano <steve <at> pearwood.info> wrote:
> On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote:
>> >>> x = 2000000000000034
>> >>> x/2
>> 1000000000000017.0
>>
>> >>> print(x/2)
>> 1e+15
>>
>> I was expecting, in fact needing, 1000000000000000017 or
>> 1000000000000000017.0
>>
>> 1e+15 is unsatisfactory. Am I forced to use the decimal module?
>
> This is not an issue with print, this is an issue with floats -- they
> produced a rounded, approximate value when converted to a string. print
> merely prints that string:
>
>>>> x = 1e15 +17
>>>> x
> 1000000000000017.0
>>>> print(x)
> 1e+15
>>>> str(x)
> '1e+15'
>
>
> If you want more control over the string conversion, you can do
> something like this:
>
(Continue reading)

Mark Lawrence | 1 Jul 18:25 2010
Picon

Re: puzzled by Python 3's print()

On 01/07/2010 14:11, Richard D. Moores wrote:
> On Thu, Jul 1, 2010 at 04:57, Steven D'Aprano<steve <at> pearwood.info>  wrote:
>> On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote:
>>>>>> x = 2000000000000034
>>>>>> x/2
>>> 1000000000000017.0
>>>
>>>>>> print(x/2)
>>> 1e+15
>>>
>>> I was expecting, in fact needing, 1000000000000000017 or
>>> 1000000000000000017.0
>>>
>>> 1e+15 is unsatisfactory. Am I forced to use the decimal module?
>>
>> This is not an issue with print, this is an issue with floats -- they
>> produced a rounded, approximate value when converted to a string. print
>> merely prints that string:
>>
>>>>> x = 1e15 +17
>>>>> x
>> 1000000000000017.0
>>>>> print(x)
>> 1e+15
>>>>> str(x)
>> '1e+15'
>>
>>
>> If you want more control over the string conversion, you can do
>> something like this:
(Continue reading)

Richard D. Moores | 1 Jul 18:58 2010
Picon

Re: puzzled by Python 3's print()

On Thu, Jul 1, 2010 at 09:25, Mark Lawrence <breamoreboy <at> yahoo.co.uk> wrote:

> Take a look at section 7.1.3 here.
>
> http://docs.python.org/py3k/library/string.html#string-formatting
>
> This is the recommended way to format strings in Python 3.

Thanks, Mark. Looks good, if cryptic. I don't have time to dig into it
 now, but I will later and report back.

Dick
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Eike Welk | 1 Jul 21:18 2010
Picon
Picon

Re: puzzled by Python 3's print()

Hello Richard!

On Thursday July 1 2010 15:11:21 Richard D. Moores wrote:
> Thanks to yours and others responses, I've learned some things I
> didn't know, but remember, I'm starting with long ints such as

Also note that in Python 3 the "/" (division) operator returns a floating 
point number when you divide integers. This is one of the changes that Python 
3 introduces.

As you are using long integers (and you were previously writing about prime 
numbers) the precision of floating point numbers might not be enough for your 
purposes.

Therefore you should probably use the integer division operator: "//"

The following (edited) snippet from IPython demonstrates "//" and the loss of 
precision when using "/":

...
Python 2.6.2 (r262:71600, Mar 29 2010, 15:30:01)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
...

In [1]: from __future__ import  division

In [2]: a = 1000000000000000000000000000000000000000000000000000000002

(Continue reading)

Mark Lawrence | 1 Jul 23:13 2010
Picon

Re: puzzled by Python 3's print()

On 01/07/2010 20:18, Eike Welk wrote:
> Hello Richard!
>
> On Thursday July 1 2010 15:11:21 Richard D. Moores wrote:
>> Thanks to yours and others responses, I've learned some things I
>> didn't know, but remember, I'm starting with long ints such as
>
> Also note that in Python 3 the "/" (division) operator returns a floating
> point number when you divide integers. This is one of the changes that Python
> 3 introduces.
>
> As you are using long integers (and you were previously writing about prime
> numbers) the precision of floating point numbers might not be enough for your
> purposes.
>
> Therefore you should probably use the integer division operator: "//"
>
>
> The following (edited) snippet from IPython demonstrates "//" and the loss of
> precision when using "/":
>
>
> ...
> Python 2.6.2 (r262:71600, Mar 29 2010, 15:30:01)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 0.10 -- An enhanced Interactive Python.
> ...
>
> In [1]: from __future__ import  division
(Continue reading)


Gmane