Re: [Tutor] Puzzled again

2011-08-03 Thread Richard D. Moores
On Wed, Aug 3, 2011 at 12:10, Peter Otten <__pete...@web.de> wrote: > Richard D. Moores wrote: > >> On Wed, Aug 3, 2011 at 10:11, Peter Otten <__pete...@web.de> wrote: >>> Richard D. Moores wrote: >>> I wrote before that I had pasted the function (convertPath()) from my initial post into

Re: [Tutor] Puzzled again

2011-08-03 Thread Richard D. Moores
On Wed, Aug 3, 2011 at 12:16, Steven D'Aprano wrote: > Richard D. Moores wrote: >> >> I wrote before that I had pasted the function (convertPath()) from my >> initial post into mycalc.py because I had accidentally deleted it from >> mycalc.py. And that there was no problem importing it from mycalc

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
Richard D. Moores wrote: I wrote before that I had pasted the function (convertPath()) from my initial post into mycalc.py because I had accidentally deleted it from mycalc.py. And that there was no problem importing it from mycalc. Well, I was mistaken (for a reason too tedious to go into). Ther

Re: [Tutor] Puzzled again

2011-08-03 Thread Peter Otten
Richard D. Moores wrote: > On Wed, Aug 3, 2011 at 10:11, Peter Otten <__pete...@web.de> wrote: >> Richard D. Moores wrote: >> >>> I wrote before that I had pasted the function (convertPath()) from my >>> initial post into mycalc.py because I had accidentally deleted it from >>> mycalc.py. And that

Re: [Tutor] Puzzled again

2011-08-03 Thread Dave Angel
On 08/03/2011 01:48 PM, Richard D. Moores wrote: On Wed, Aug 3, 2011 at 10:11, Peter Otten<__pete...@web.de> wrote: Dave was close, but Steven hit the nail: the string r"C:\Users\Dick\..." is fine, but when you put it into the docstring it is not a raw string within another string, it becomes

Re: [Tutor] Puzzled again

2011-08-03 Thread Richard D. Moores
On Wed, Aug 3, 2011 at 10:11, Peter Otten <__pete...@web.de> wrote: > Richard D. Moores wrote: > >> I wrote before that I had pasted the function (convertPath()) from my >> initial post into mycalc.py because I had accidentally deleted it from >> mycalc.py. And that there was no problem importing i

Re: [Tutor] Puzzled again

2011-08-03 Thread Peter Otten
Richard D. Moores wrote: > I wrote before that I had pasted the function (convertPath()) from my > initial post into mycalc.py because I had accidentally deleted it from > mycalc.py. And that there was no problem importing it from mycalc. > Well, I was mistaken (for a reason too tedious to go into

Re: [Tutor] Puzzled again

2011-08-03 Thread Richard D. Moores
I wrote before that I had pasted the function (convertPath()) from my initial post into mycalc.py because I had accidentally deleted it from mycalc.py. And that there was no problem importing it from mycalc. Well, I was mistaken (for a reason too tedious to go into). There WAS a problem, the same o

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
Richard D. Moores wrote: But here's a try using the regular command line: C:\Windows\System32>python Python 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. from mycalc import convertPath Traceba

Re: [Tutor] Puzzled again

2011-08-03 Thread Richard D. Moores
Ops! I accidentally erased convertPath() from mycalc.py while trying out various things. It was my only copy of convertPath that had the docstring as posted, so I went to my initial post and copy-and-pasted it into mycalc.py. Now no problem: from Wing's shell: Python 3.2.1 (default, Jul 10 2

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
Steven D'Aprano wrote: Richard D. Moores wrote: Puzzled again. Why the error. Line 36 is the line just above "import os.path". I have many other functions in mycalc.py with examples formatted exactly the same way. def convertPath(path): """ Given a path with backslashes, return that pat

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
Richard D. Moores wrote: Puzzled again. Why the error. Line 36 is the line just above "import os.path". I have many other functions in mycalc.py with examples formatted exactly the same way. def convertPath(path): """ Given a path with backslashes, return that path with forward slashes.

Re: [Tutor] Puzzled again

2011-08-03 Thread Dave Angel
On 08/03/2011 02:07 AM, Richard D. Moores wrote: On Tue, Aug 2, 2011 at 21:59, Dave Angel wrote: When I paste that from your email into a file and run Python 2.7 on it, it behaves fine with no errors. That's in Linux. I should have said that I'm using Wing IDE Professional 4.0.3-1 (rev 2472

Re: [Tutor] Puzzled again

2011-08-02 Thread Andre Engels
On Wed, Aug 3, 2011 at 8:07 AM, Richard D. Moores wrote: > On Tue, Aug 2, 2011 at 21:59, Dave Angel wrote: > > > When I paste that from your email into a file and run Python 2.7 on it, > it > > behaves fine with no errors. That's in Linux. > > I should have said that I'm using Wing IDE Professio

Re: [Tutor] Puzzled again

2011-08-02 Thread Richard D. Moores
On Tue, Aug 2, 2011 at 21:59, Dave Angel wrote: > When I paste that from your email into a file and run Python 2.7 on it, it > behaves fine with no errors.  That's in Linux. I should have said that I'm using Wing IDE Professional 4.0.3-1 (rev 24721), Windows Vista, and Python 3.2.1. > But the e

Re: [Tutor] Puzzled again

2011-08-02 Thread Dave Angel
On 08/02/2011 10:36 PM, Richard D. Moores wrote: Puzzled again. Why the error. Line 36 is the line just above "import os.path". I have many other functions in mycalc.py with examples formatted exactly the same way. def convertPath(path): """ Given a path with backslashes, return that p

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 16:18, Steven D'Aprano wrote: > On Fri, 2 Jul 2010 05:18:00 am Eike Welk wrote: > >> 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. > > It certainly won

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Steven D'Aprano
On Fri, 2 Jul 2010 05:18:00 am Eike Welk wrote: > 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. It certainly won't be once you get to large enough primes! > Therefore you sho

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 12:18, Eike Welk wrote: > Therefore you should probably use the integer division operator: "//" >>> x = 200033 >>> x//2 100016 I can live with THAT error! Thanks, Eike! But I will press on with Mark

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Mark Lawrence
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

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Eike Welk
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

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 09:25, Mark Lawrence 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

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Mark Lawrence
On 01/07/2010 14:11, Richard D. Moores wrote: On Thu, Jul 1, 2010 at 04:57, Steven D'Aprano wrote: On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote: x = 2034 x/2 1017.0 print(x/2) 1e+15 I was expecting, in fact needing, 117 or 1000

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 04:57, Steven D'Aprano wrote: > On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote: >> >>> x = 2034 >> >>> x/2 >> 1017.0 >> >> >>> print(x/2) >> 1e+15 >> >> I was expecting, in fact needing, 117 or >> 117.0 >> >> 1e

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Steven D'Aprano
On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote: > >>> x = 2034 > >>> x/2 > 1017.0 > > >>> print(x/2) > 1e+15 > > I was expecting, in fact needing, 117 or > 117.0 > > 1e+15 is unsatisfactory. Am I forced to use the decimal module? This

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Evert Rol
x = 2034 x/2 > 1017.0 print(x/2) > 1e+15 > > I was expecting, in fact needing, 117 or 117.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

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Shantanoo
without using decimal module: >>> x = 2034 >>> print('%d'%(x/2)) 1017 On Thu, Jul 1, 2010 at 13:56, Richard D. Moores wrote: x = 2034 x/2 > 1017.0 print(x/2) > 1e+15 > > I was expecting, in fact needing, 117 or 1

Re: [Tutor] Puzzled

2008-08-29 Thread Kent Johnson
On Fri, Aug 29, 2008 at 6:15 PM, ammar azif <[EMAIL PROTECTED]> wrote: > Thanks for the explanation. Btw, How can I get the size of python primitive > data types in bytes? Is it defined somewhere in a file that I can look at? Not really. sys.maxint gives the largest int, from which you can infer t

Re: [Tutor] Puzzled

2008-08-29 Thread ammar azif
Thanks for the explanation. Btw, How can I get the size of python primitive data types in bytes? Is it defined somewhere in a file that I can look at? --- On Fri, 8/29/08, Kent Johnson <[EMAIL PROTECTED]> wrote: From: Kent Johnson <[EMAIL PROTECTED]> Subject: Re: [Tutor] Puzzle

Re: [Tutor] Puzzled

2008-08-29 Thread Kent Johnson
On Fri, Aug 29, 2008 at 5:13 PM, ammar azif <[EMAIL PROTECTED]> wrote: > I wrote a python program that used time() function from the time module to > retrieve time in seconds since Epoch. After the value was retrieved which I > checked is a float by using type(), the value was then written into a

Re: [Tutor] Puzzled by print lst.sort()

2006-10-01 Thread Liam Clarke
Dick Moores wrote: > At 01:37 PM 9/30/2006, Shantanoo Mahajan wrote: > >> Maybe following is helpful: >> >> > a=[3,2,1] > b=a[:] > b.sort() > c=sorted(a) > print a,b,c > [3, 2, 1] [1, 2, 3] [1, 2, 3] > > >> Shantanoo >> > > Sorry to be dense,

Re: [Tutor] Puzzled by print lst.sort()

2006-10-01 Thread Dick Moores
At 01:37 PM 9/30/2006, Shantanoo Mahajan wrote: >Maybe following is helpful: > > >>> a=[3,2,1] > >>> b=a[:] > >>> b.sort() > >>> c=sorted(a) > >>> print a,b,c > >>> [3, 2, 1] [1, 2, 3] [1, 2, 3] > >>> > >Shantanoo Sorry to be dense, but I don't see what showing what happens to a copy of list a ad

Re: [Tutor] Puzzled by print lst.sort()

2006-09-30 Thread Shantanoo Mahajan
+++ Dick Moores [30-09-06 10:47 -0700]: | At 05:07 AM 9/30/2006, Liam Clarke wrote: | >Dick Moores wrote: | > > At 03:22 AM 9/30/2006, Liam Clarke wrote: | > >> Dick Moores wrote: | | > >> A Python list sort is destructive, as you can see - it has modified | > >> lst. So, to emphasise that it is d

Re: [Tutor] Puzzled by print lst.sort()

2006-09-30 Thread Dick Moores
At 05:07 AM 9/30/2006, Liam Clarke wrote: >Dick Moores wrote: > > At 03:22 AM 9/30/2006, Liam Clarke wrote: > >> Dick Moores wrote: > >> A Python list sort is destructive, as you can see - it has modified > >> lst. So, to emphasise that it is destructive, it returns None. You'll > >> find this in

Re: [Tutor] Puzzled by print lst.sort()

2006-09-30 Thread Liam Clarke
Dick Moores wrote: > At 03:22 AM 9/30/2006, Liam Clarke wrote: >> Dick Moores wrote: >>> >>> >>> lst = [5,3,7,6,2] >>> >>> lst.sort() >>> >>> lst >>> [2, 3, 5, 6, 7] >>> >>> lst = [5,3,7,6,2] >>> >>> print lst.sort() >>> None >>> >>> lst >>> [2, 3, 5, 6, 7] >>> >>> I'm wondering why "print ls

Re: [Tutor] Puzzled by print lst.sort()

2006-09-30 Thread Liam Clarke
Dick Moores wrote: > At 03:22 AM 9/30/2006, Liam Clarke wrote: >> Dick Moores wrote: >>> >>> >>> lst = [5,3,7,6,2] >>> >>> lst.sort() >>> >>> lst >>> [2, 3, 5, 6, 7] >>> >>> lst = [5,3,7,6,2] >>> >>> print lst.sort() >>> None >>> >>> lst >>> [2, 3, 5, 6, 7] >>> >>> I'm wondering why "print ls

Re: [Tutor] Puzzled by print lst.sort()

2006-09-30 Thread Dick Moores
At 03:22 AM 9/30/2006, Liam Clarke wrote: Dick Moores wrote:  >>> lst = [5,3,7,6,2]  >>> lst.sort()  >>> lst [2, 3, 5, 6, 7]  >>> lst = [5,3,7,6,2]  >>> print lst.sort() None  >>> lst [2, 3, 5, 6, 7] I'm wondering why "print lst.sort()" doesn't print the newly sorted list, but instead prints

Re: [Tutor] Puzzled by print lst.sort()

2006-09-30 Thread Liam Clarke
Dick Moores wrote: >>> lst = [5,3,7,6,2] >>> lst.sort() >>> lst [2, 3, 5, 6, 7] >>> lst = [5,3,7,6,2] >>> print lst.sort() None >>> lst [2, 3, 5, 6, 7] I'm wondering why "print lst.sort()" doesn't print the newly sorted list, but instead prints "None". In fact, the sorting has taken

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Tim Peters
[Tim Peters] >> You would in this case, and that would be wrong. In fp you'd get an >> approximation to the exact n * (1./5 + 1./5**2 + ...) == n/4. (use >> the rule for the sum of an infinite geometric series). For example, >> that way you'd compute that 4! == 24 has 4/4 == 1 trailing zero, >>

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Christian Tschabuschnig
[Tim Peters] > You would in this case, and that would be wrong. In fp you'd get an > approximation to the exact n * (1./5 + 1./5**2 + ...) == n/4. (use > the rule for the sum of an infinite geometric series). For example, > that way you'd compute that 4! == 24 has 4/4 == 1 trailing zero, > inste

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Tim Peters
[Tim Peters] >> For a fun :-) exercise, prove that the number of trailing zeroes in n! >> is the sum, from i = 1 to infinity, of n // 5**i (of course as soon as >> you reach a value of i such that n < 5**i, the quotient is 0 at that i >> and forever after). >> >> In this case, >> >> 100 // 5 + 100

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Christian Tschabuschnig
Tim Peters wrote: > [Dick Moores, computes 100 factorial as > > 9332621544394415268169923885626670049071596826438162146859296389521753229915608941463976156518286253697920827223758251185210916864 > > but worries about all the trailing zeros] > >> Yes, I'm sure you a

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Tim Peters
[Dick Moores, computes 100 factorial as 9332621544394415268169923885626670049071596826438162146859296389521753229915608941463976156518286253697920827223758251185210916864 but worries about all the trailing zeros] > Yes, I'm sure you are. I'd forgotten about all tho

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Dick Moores
At 04:50 PM 8/18/2006, Christian Tschabuschnig wrote: > >> > 9332621544394415268169923885626670049071596826438162146859296389521753229915608941463976156518286253697920827223758251185210916864 > >>> Still not exactly correct! I'm bewildered. > >>> > >> The results look t

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Christian Tschabuschnig
>> 9332621544394415268169923885626670049071596826438162146859296389521753229915608941463976156518286253697920827223758251185210916864 >>> Still not exactly correct! I'm bewildered. >>> >> The results look the same to me >> why do you think they're not correct? >> what is

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Dick Moores
At 04:24 PM 8/18/2006, Luke Paireepinart wrote: >Dick Moores wrote: > > But here's the revised precisionFactorial.py: > > > > > > # 1precisionFactorial.py > > > > import decimal > > > > def d(x): > > return decimal.Decimal(str(x)) > > > > def fact(n): > > product

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Luke Paireepinart
Dick Moores wrote: > At 02:41 PM 8/18/2006, Bob Gailer wrote: > >> Dick Moores wrote: >> >>> As an exercise that I thought would help me understand the decimal >>> module, I've been trying write a script (precisionFactorial.py) >>> that uses a modified fact(n) to compute precise factorial

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Dick Moores
At 02:41 PM 8/18/2006, Bob Gailer wrote: >Dick Moores wrote: >>As an exercise that I thought would help me understand the decimal >>module, I've been trying write a script (precisionFactorial.py) >>that uses a modified fact(n) to compute precise factorials >What do you mean by "precise factorials

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Bob Gailer
Dick Moores wrote: > As an exercise that I thought would help me understand the decimal > module, I've been trying write a script (precisionFactorial.py) that > uses a modified fact(n) to compute precise factorials What do you mean by "precise factorials"? Python's long integer should handle th