Re: IDE Question

2008-10-15 Thread Dick Moores

Have you seen Kelie Feng's video introducing the terrific and free
IDE, Ulipad? http://www.rcblue.com/u3/
Get Ulipad 3.9 from http://code.google.com/p/ulipad/downloads/list
svn for the latest revision http://ulipad.googlecode.com/svn/trunk/
Mailing list for Ulipad: http://groups-beta.google.com/group/ulipad

Dick Moores 


--
http://mail.python.org/mailman/listinfo/python-list


Conflict between msvcrt and Tkinter?

2008-06-18 Thread Dick Moores

Win XP, Python 2.5.1

I'm having trouble using msvcrt.getch() in a program that also uses a 
graphics module which itself imports Tkinter. Is this to be expected?


Thanks,

Dick Moores

--
http://mail.python.org/mailman/listinfo/python-list


Re: Books for programmers

2008-06-04 Thread Dick Moores
Do not neglect the 2008 book, Object-Oriented Programming in 
Python, by Goldwasser and Letscher.

http://www.prenhall.com/goldwasser/
http://www.bestbookdeal.com/book/compare/0136150314/

Dick Moores

--
http://mail.python.org/mailman/listinfo/python-list


Re: A video introducing Ulipad, an IDE mainly for Python

2008-05-30 Thread Dick Moores

At 07:57 AM 5/30/2008, David C. Ullrich wrote:

In article [EMAIL PROTECTED],
 Dick Moores [EMAIL PROTECTED] wrote:

 I've been using Ulipad, a free IDE mainly for Python, and written in
 wxPython, for a couple of years, and think it's terrific. Now another
 user, Kelie Feng, has made an 8-minute video showing it off. The
 visual clarity of the video is remarkable. You can download it
 (Introducing_Ulipad_2008-05-22.avi), and a codec (tscc.exe) that may
 be necessary for your player, from http://www.rcblue.com/u3/.

I skipped the video and tried Ulipad. Looks very interesting.

The documentation I got is mostly in Chinese. Is there an
English version somewhere?


F1 will open UliPad Documentations. Check out the HowTo's and the 
FAQ. And subscribe to the Ulipad list at Google Groups 
(http://groups.google.com/group/ulipad). The main developer, 
Limodou, is in Beijing, but he's very quick in answering questions 
posed to the list.


Dick Moores

--
http://mail.python.org/mailman/listinfo/python-list


A video introducing Ulipad, an IDE mainly for Python

2008-05-28 Thread Dick Moores
I've been using Ulipad, a free IDE mainly for Python, and written in 
wxPython, for a couple of years, and think it's terrific. Now another 
user, Kelie Feng, has made an 8-minute video showing it off. The 
visual clarity of the video is remarkable. You can download it 
(Introducing_Ulipad_2008-05-22.avi), and a codec (tscc.exe) that may 
be necessary for your player, from http://www.rcblue.com/u3/.


Dick Moores

--
http://mail.python.org/mailman/listinfo/python-list


Re: A video introducing Ulipad, an IDE mainly for Python

2008-05-28 Thread Dick Moores


Date: Wed, 28 May 2008 11:29:59 -0400
From: Sean Azelton [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] A video introducing Ulipad, an IDE mainly for Python

For those looking for the codec and not running Windows, you can find
it here for Mac OS X as well

http://www.techsmith.com/download/codecs.asp

--
http://mail.python.org/mailman/listinfo/python-list


r' question

2008-05-17 Thread Dick Moores


Win XP, Python 2.5.1
I have a text file of phone numbers, which I'd like to search with a
regex. 
This script works fine:
import re
fstr = \sjoe\s
regex = ^.* + fstr + .*$
p = re.compile(regex, re.I)
f = open('phone.txt', 'r')
for line in f.readlines():
 if p.search(line):
 print
p.search(line).group()
f.close()
But this one, with a different 3rd line, doesn't:
import re
fstr = \sjoe\s
regex = r'^.* + fstr + .*$'
p = re.compile(regex, re.I)
f = open('phone.txt', 'r')
for line in f.readlines():
 if p.search(line):
 print
p.search(line).group()
f.close()
Is there no way to get it to work?
Thanks,
Dick Moores


--
http://mail.python.org/mailman/listinfo/python-list

Re: r' question

2008-05-17 Thread Dick Moores

At 10:17 PM 5/17/2008, Gabriel Genellina wrote:

En Sat, 17 May 2008 23:37:16 -0300, Dick Moores [EMAIL PROTECTED] escribió:

 I have a text file of phone numbers, which I'd like to search with a regex.

 fstr = \sjoe\s
 regex = ^.* + fstr + .*$

 fstr = \sjoe\s
 regex = r'^.* + fstr + .*$'

The r... is a signal to the parser - meaning 
don't interpret the escape characters here. 
Note that the r is OUTSIDE the quotes. In your 
example, the escape characters are in fstr, so 
it should be written as r\sjoe\s


However, (please refer back to my original post) 
I want to keep the fstr, ultimately to be the 
string entered by the user who knows a bit about 
regex, but not how to use r'  ' . Or 
alternatively, not assume any knowledge of regex, 
but build in some options, such as ignoring/not 
ignoring case, searching on just a string, or on 
a word. So I want to know how to build the user's 
fstr into regex. I apologize for not making this clear.


Now, if you want the lines that contain the 
word joe surrounded by space, just use:


import re
regex = r\sjoe\s
p = re.compile(regex, re.I)
f = open('phone.txt', 'r')
for line in f:
 m = p.search(line)
 if m:
 print m.group()
f.close()

A file is its own line iterator (no need for 
readlines). And since you're iterating over 
lines, the regex doesn't have to test for it ^ and $.


Yes, that works. Thanks.

Dick Moores 


--
http://mail.python.org/mailman/listinfo/python-list


IDLE gripe and question

2008-04-22 Thread Dick Moores

I have IDLE 1.2.1, on Win XP, Python 2.5.1.

The first time I use File | Open to open a script, the Open dialogue 
box always opens at E:\Python25\Lib\idlelib. Most of the scripts I 
want to access are in E:\PythonWork. There doesn't seem to be a way 
to change the default folder to E:\PythonWork, but is there?


Thanks,

Dick Moores

   
UliPad The Python Editor: http://code.google.com/p/ulipad/ 


--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE gripe and question

2008-04-22 Thread Dick Moores

At 09:30 PM 4/22/2008, Mensanator wrote:

First, find the shortcut that lauches IDLE.

On my Vista system it's in
C:\Program Data\Microsoft\Windows\Start Menu\Programs\Python 2.5

XP will be different, I think there're start menu directories under
each user and a default one.

Anyway, once you have the shortcut (mine was named IDLE (Python GUI)),
right-click and select Properties.

There's a property attribute labeled Start In.
Set that to the directory where your scripts are.
The menu Open will now default to that directory.


Yes! That did it.

Thanks!

Dick Moores


   
UliPad The Python Editor: http://code.google.com/p/ulipad/ 


--
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread Dick Moores
At 11:03 PM 1/11/2008, Landon wrote:
Hi, I'm a freshman in college and I'm going to be taking an intro to
programming course next semester which mainly uses Python, so I
thought it might be a good time to pick up Python beyond the scope of
the class as well. The text book for this class is Python for the
Absolute Beginner or something similar to that name.

I was wondering if anyone had any opinions on what other titles I
could look into since this one seems from a glance at reviews to be
teaching mainly through game programming (a topic I'm not too
interested in) or if this one is a quality book by itself.

Yes, it's a quality book, IMO.

I hope by now you've gotten over your dislike for online tutorials. 
Please take a look at these 3:
Hands-On Python http://www.cs.luc.edu/~anh/python/hands-on/
How to Think Like a (Python) Programmer 
http://www.greenteapress.com/thinkpython/
Alan Gauld's Learning to Program (heavy emphasis on Python) 
http://www.freenetpages.co.uk/hp/alan.gauld

Also, do take advantage of the VERY helpful Tutor mailing list. 
http://mail.python.org/mailman/listinfo/tutor.

Dick Moores

--
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble getting loop to break

2007-11-25 Thread Dick Moores
At 01:32 PM 11/20/2007, Fredrik Johansson wrote:
On Nov 20, 2007 10:00 PM, Dick Moores [EMAIL PROTECTED] wrote:
  And also with the amazing Chudnovsky algorithm for pi. See
  http://python.pastebin.com/f4410f3dc

Nice! I'd like to suggest two improvements for speed.

First, the Chudnovsky algorithm uses lots of factorials, and it's
rather inefficient to call mpmath's factorial function from scratch
each time. You could instead write a custom factorial function that
only uses multiplications and caches results, something like this:

cached_factorials = [mpf(1)]

def f(n):
 n = int(n)
 if n  len(cached_factorials):
 return cached_factorials[n]
 p = cached_factorials[-1]
 for i in range(len(cached_factorials), n+1):
 p *= i
 cached_factorials.append(p)
 return p

(In some future version of mpmath, the factorial function might be
optimized so that you won't have to do this.)

Second, to avoid unnecessary work, factor out the fractional power of
640320 that occurs in each term. That is, change the denom = line to

 denom = (f(3*k) * ((f(k))**3) * (640320**(3*k)))

and then multiply it back in at the end:

 print 1/(12*sum/640320**(mpf(3)/2))

With these changes, the time to compute 1,000 digits drops to only 
0.05 seconds!

Further improvements are possible.

Fredrik

Fredrik,

I'm afraid I'm just too dumb to see how to use your first suggestion 
of cached_factorials. Where do I put it and def()? Could you show me, 
even on-line, what to do? http://py77.python.pastebin.com/f48e4151c 
You (or anyone) can submit an amendment to my code using the textbox.

I did make the denom change, and see that it does improve the speed a bit.

Thanks,

Dick




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble getting loop to break

2007-11-25 Thread Dick Moores
At 03:26 AM 11/25/2007, Fredrik Johansson wrote:
On Nov 25, 2007 9:00 AM, Dick Moores [EMAIL PROTECTED] wrote:
  Fredrik,
 
  I'm afraid I'm just too dumb to see how to use your first suggestion
  of cached_factorials. Where do I put it and def()? Could you show me,
  even on-line, what to do? http://py77.python.pastebin.com/f48e4151c
  You (or anyone) can submit an amendment to my code using the textbox.
 
  I did make the denom change, and see that it does improve the speed a bit.

I edited the pastebin code, see: http://py77.python.pastebin.com/m6b2b34b7

Fredrik

Wow. your f() is ingenious, Frederik. Thanks very much.

Any more tricks up your sleeve? You did say a post or so ago, 
Further improvements are possible.

Dick



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble getting loop to break

2007-11-20 Thread Dick Moores
At 12:45 AM 11/20/2007, Dennis Lee Bieber wrote:
On Mon, 19 Nov 2007 23:41:02 -0800, Dick Moores [EMAIL PROTECTED]
declaimed the following in comp.lang.python:

  a way to get it to break where I want it to, i.e., when the sum
  equals the limit as closely as the precision allows?
 

   if sum = limit:

 Well, since it ISN'T a case of testing for an absolute equivalence
with floats...

 Perhaps putting a print sum, limit before that point would reveal
what type of values you are encountering.

If you run the program you'll see exactly that, if I understand you 
correctly. http://python.pastebin.com/f2f06fd76 shows the full 
output for a precision of 50 and x == 5.

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble getting loop to break

2007-11-20 Thread Dick Moores
At 03:53 AM 11/20/2007, Fredrik Johansson wrote:
On Nov 20, 2007 8:41 AM, Dick Moores [EMAIL PROTECTED] wrote:
  I'm writing a demo of the infinite series
 
  x**0/0! + x**1/1! + x**2/2! + x**3/3! + ...   = e**x   (x is non-negative)
 
  It works OK for many x, but for many the loop doesn't break. Is there
  a way to get it to break where I want it to, i.e., when the sum
  equals the limit as closely as the precision allows?
 
  Here's what I have:
 
  === series_xToN_OverFactorialN.py ==
  #!/usr/bin/env python
  #coding=utf-8
  # series_xToN_OverFactorialN.py  limit is e**x   from p.63 in The
  Pleasures of Pi,e
  from mpmath import mpf, e, exp, factorial
  import math
  import time
  precision = 100
  mpf.dps = precision
  n = mpf(0)
  x = mpf(raw_input(Enter a non-negative int or float: ))
  term = 1
  sum = 0
  limit = e**x
  k = 0
  while True:
   k += 1
   term = x**n/factorial(n)
   sum += term
   print  sum = %s k = %d % (sum, k)
   print exp(%s) = %s % (x, exp(x))
   print   e**%s = %s % (x, e**x)
   print
   if sum = limit:
   print math.e**%s = %f % (x, math.e**x)
   print last term = %s % term
   break
   time.sleep(0.2)
   n += 1
 
  
  Output for x == mpf(123.45):
  sum =
  
 410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942
  k = 427
  exp(123.45) =
  
 410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942
 e**123.45 =
  
 410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942
  
  
 
  This is also on the web at http://python.pastebin.com/f1a5b9e03.
 
  Examples of problem x's: 10, 20, 30, 40, 100, 101
  Examples of OK x's: 0.2, 5, 10.1, 11, 33.3, 123.45
 
  Thanks,
 
  Dick Moores

Hi,

Checking that sum = e**x will generally not work, because e**x might
have been rounded up while the sum might repeatedly be rounding down.
If this happens, no matter how many terms you add, the sum will never
reach the limit (one of the curses of finite-precision arithmetic).

One solution is to use directed rounding. First compute the limit with
downward rounding:

mpf.round_down()
limit = e**x
mpf.round_default()

Then compute every term in the sum with upward rounding:

mpf.round_down()
fac = factorial(n)
mpf.round_up()
term = x**n / fac
sum += term

(Note that the factorial should be rounded down to obtain upward
rounding in the term, since you're taking its reciprocal.)

This should guarantee that the sum eventually exceeds the limit.

As a simpler, less rigorous alternative, instead of checking if sum =
limit, check (for example) whether

 abs(sum - limit) / limit = mpf(10)**(-precision+3)

i.e., if the sum is within 3 digits of the limit. This is the usual
way to test for numerical equality of floating-point numbers.

I tried out both ways, and found that the second one best suited my 
purposes. Please see the 2 highlighted lines in 
http://python.pastebin.com/fcc23b10
Note that to break the loop I found that this does the job:

if abs(sum - limit) / limit = mpf(10)**(-precision+1):#  I 
changed your +3 to +1
 break

Fredrik, thanks VERY much for your terrific instruction!

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble getting loop to break

2007-11-20 Thread Dick Moores
At 10:42 AM 11/20/2007, [EMAIL PROTECTED] wrote:
Instead of comparing sum to the known value of e**x, why not test
for convergence?  I.e., if sum == last_sum: break.  Seems like that
would be more robust (you don't need to know the answer to computer
the answer), since it seems like it should converge.

Yes! And believe it or not I did that before seeing your post. Works 
well. See http://python.pastebin.com/f7c37186a

And also with the amazing Chudnovsky algorithm for pi. See 
http://python.pastebin.com/f4410f3dc

Thanks,

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Trouble getting loop to break

2007-11-19 Thread Dick Moores
I'm writing a demo of the infinite series

x**0/0! + x**1/1! + x**2/2! + x**3/3! + ...   = e**x   (x is non-negative)

It works OK for many x, but for many the loop doesn't break. Is there 
a way to get it to break where I want it to, i.e., when the sum 
equals the limit as closely as the precision allows?

Here's what I have:

=== series_xToN_OverFactorialN.py ==
#!/usr/bin/env python
#coding=utf-8
# series_xToN_OverFactorialN.py  limit is e**x   from p.63 in The 
Pleasures of Pi,e
from mpmath import mpf, e, exp, factorial
import math
import time
precision = 100
mpf.dps = precision
n = mpf(0)
x = mpf(raw_input(Enter a non-negative int or float: ))
term = 1
sum = 0
limit = e**x
k = 0
while True:
 k += 1
 term = x**n/factorial(n)
 sum += term
 print  sum = %s k = %d % (sum, k)
 print exp(%s) = %s % (x, exp(x))
 print   e**%s = %s % (x, e**x)
 print
 if sum = limit:
 print math.e**%s = %f % (x, math.e**x)
 print last term = %s % term
 break
 time.sleep(0.2)
 n += 1


Output for x == mpf(123.45):
sum = 
410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942
 
k = 427
exp(123.45) = 
410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942
   e**123.45 = 
410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942



This is also on the web at http://python.pastebin.com/f1a5b9e03.

Examples of problem x's: 10, 20, 30, 40, 100, 101
Examples of OK x's: 0.2, 5, 10.1, 11, 33.3, 123.45

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Help with sympy, please

2007-11-18 Thread Dick Moores
from __future__ import division
Here's what I'm trying to do, but using sympy:
=
from math import e
n = 1
prod = 1
k = 0
while k  1000:
 k += 1
 term = (e**(1.0/n))/(e**(1.0/(n+1)))
 prod *= term
 n += 2
print prod, term

Output:
1.99950018746 1.0025013  (the limit is 2)



from sympy import *
from sympy import Rational as R
from sympy.numerics import *

prec = 50
Float.setdps(prec)
e = evalf(E)
n = 1
k = 0
prod = evalf(R(1,1))
while k  1000:
 k += 1
 n = evalf(R(n,1))
 term = (e**(1/n))/(e**(1/(n+1)))
 prod *= term
 n += 2
print prod, term
===

This gets:
Traceback (most recent call last):
   File E:\PythonWork\Untitled 5.py, line 20, in module
 term = (e**(1/n))/(e**(1/(n+1)))
TypeError: unsupported operand type(s) for /: 'int' and 'Float'

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with sympy, please

2007-11-18 Thread Dick Moores
At 03:42 PM 11/18/2007, Dennis Lee Bieber wrote:
On Sun, 18 Nov 2007 13:02:01 -0800, Dick Moores [EMAIL PROTECTED]
declaimed the following in comp.lang.python:

 
  This gets:
  Traceback (most recent call last):
 File E:\PythonWork\Untitled 5.py, line 20, in module
   term = (e**(1/n))/(e**(1/(n+1)))
  TypeError: unsupported operand type(s) for /: 'int' and 'Float'
 
 Seems self-explanatory... try using 1.0 rather than 1

term = (e**(1.0/n))/(e**(1.0/(n+1)))
TypeError: unsupported operand type(s) for /: 'float' and 'Float'

Dick 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with sympy, please

2007-11-18 Thread Dick Moores
At 04:26 PM 11/18/2007, Fredrik Johansson wrote:
On Nov 19, 2007 1:05 AM, Dick Moores [EMAIL PROTECTED] wrote:
Hi Dick, I recognize you from python-list, where you had a question
about mpmath.

Your code still won't work if you convert the numbers to Floats
because the Float type in sympy.numerics does not implement ** for
fractional numbers. You could use the exp function in
sympy.numerics.functions instead to compute e**x.

Thanks, Fredrik, but I get the same error using either exp or power:

from __future__ import division
from sympy import *
from sympy import Rational as R
from sympy.numerics import *
from sympy.numerics.functions import power, exp

prec = 50
Float.setdps(prec)
e = evalf(E)
n = 1
m = n + 1
k = 0
n = evalf(R(n,1))
m = evalf(R(m,1))
prod = evalf(R(1,1))
prec = 50
Float.setdps(prec)
e = evalf(E)
n = 1
k = 0
prod = evalf(R(1,1))
while k  1000:
  k += 1
  n = evalf(R(n,1))
  term = (exp(1/n))/(exp(1/(n+1)))
  prod *= term
  n += 2
print prod, term
=
term = (exp(1/n))/(exp(1/(n+1)))
TypeError: unsupported operand type(s) for /: 'int' and 'Float'

And also if I use sympy.numerics.functions.power in that line, as
term = power(e,(1/n))/power(e,(1/(n+1)))

I get:

term = power(e,(1/n))/power(e,(1/(n+1)))
TypeError: unsupported operand type(s) for /: 'int' and 'Float'

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with sympy, please

2007-11-18 Thread Dick Moores
At 04:26 PM 11/18/2007, Fredrik Johansson wrote:

Basically, sympy.numerics is an old version of mpmath. The
sympy.numerics module is not very well integrated in SymPy, slower
than mpmath, and has a couple bugs that have subsequently been fixed
in mpmath. In sympycore (http://code.google.com/p/sympycore/), we're
using the latest version of mpmath and integrating it directly into
the symbolic engine; it will be much more robust and user-friendly. It
will hopefully not be long until we merge the improvements we've done
in the sympycore project with the main SymPy branch.

Fredrik

OK, I tried mpmath again, and to my surprise, it went well!

===
#!/usr/bin/env python
#coding=utf-8
from mpmath import *
mpf.dps = 50
n = 1
k = 0
prod = mpf(1)
while k  10:
 k += 1
 term = exp(1.0/n)/exp(1.0/(n+1))
 prod *= term
 n += 2
print prod, term
==
Output:
1.95187499635016028080844735182389158683797 
1.00250001250004074790133889386806610626172

Thanks,

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with sympy, please

2007-11-18 Thread Dick Moores
At 05:24 PM 11/18/2007, Fredrik Johansson wrote:
On Nov 19, 2007 2:03 AM, Dick Moores [EMAIL PROTECTED] wrote:
  At 04:26 PM 11/18/2007, Fredrik Johansson wrote:
  On Nov 19, 2007 1:05 AM, Dick Moores [EMAIL PROTECTED] wrote:
  Hi Dick, I recognize you from python-list, where you had a question
  about mpmath.
  
  Your code still won't work if you convert the numbers to Floats
  because the Float type in sympy.numerics does not implement ** for
  fractional numbers. You could use the exp function in
  sympy.numerics.functions instead to compute e**x.
 
  Thanks, Fredrik, but I get the same error using either exp or power:
  
  from __future__ import division
  from sympy import *
  from sympy import Rational as R
  from sympy.numerics import *
  from sympy.numerics.functions import power, exp
 
  prec = 50
  Float.setdps(prec)
  e = evalf(E)
  n = 1
  m = n + 1
  k = 0
  n = evalf(R(n,1))
  m = evalf(R(m,1))
  prod = evalf(R(1,1))
  prec = 50
  Float.setdps(prec)
  e = evalf(E)
  n = 1
  k = 0
  prod = evalf(R(1,1))
  while k  1000:
k += 1
n = evalf(R(n,1))
term = (exp(1/n))/(exp(1/(n+1)))
prod *= term
n += 2
  print prod, term
  =
  term = (exp(1/n))/(exp(1/(n+1)))
  TypeError: unsupported operand type(s) for /: 'int' and 'Float'
 
  And also if I use sympy.numerics.functions.power in that line, as
  term = power(e,(1/n))/power(e,(1/(n+1)))
 
  I get:
 
  term = power(e,(1/n))/power(e,(1/(n+1)))
  TypeError: unsupported operand type(s) for /: 'int' and 'Float'

Try not using from __future__ import division.

Didn't help.


Also,

  n = evalf(R(n,1))

won't work, because the arguments to Rational must be ints.

But both n and 1 are ints, aren't they?

Anyway, you've by now seen my new success with mpmath. I'll abandon 
syspy for the time being.

Dick

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with sympy, please

2007-11-18 Thread Dick Moores
At 05:33 PM 11/18/2007, Fredrik Johansson wrote:
On Nov 19, 2007 2:23 AM, Dick Moores [EMAIL PROTECTED] wrote:
  OK, I tried mpmath again, and to my surprise, it went well!
 
  ===
  #!/usr/bin/env python
  #coding=utf-8
  from mpmath import *
  mpf.dps = 50
  n = 1
  k = 0
  prod = mpf(1)
  while k  10:
   k += 1
   term = exp(1.0/n)/exp(1.0/(n+1))
   prod *= term
   n += 2
  print prod, term
  ==
  Output:
  1.95187499635016028080844735182389158683797
  1.00250001250004074790133889386806610626172

You're getting slightly wrong results, though, because 1.0/n and
1.0/(n+1) just performs regular float division with ~16-digit
precision when n is a Python int. You should convert either 1.0 or n
to an mpf before dividing.

Ah, yes. That was my original mistake with using mpmath. How's this?:

=
#!/usr/bin/env python
#coding=utf-8
import psyco
psyco.full()
from mpmath import *
mpf.dps = 50
n = mpf(1)
k = 0
prod = mpf(1)
while k  10:
 k += 1
 term = exp(1.0/n)/exp(1.0/(n+1))
 prod *= term
 n += 2
print prod, term
===
Output:
1.95187499635415917971337956346129920295869 
1.00250001250009375062500416669401059407666

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


mpmath puzzle

2007-11-13 Thread Dick Moores
For 1234 ** 10.9, why the wrong result from mpmath.power()?


#!/usr/bin/env python
#coding=utf-8
from mpmath import *

mpf.dps = 32

x = mpf(1234)
y = mpf(10.9)

print power(x,y)
print 4.9583278648155041477415234438717e+33 # from Windows calculator


output:
4.9583278648155166864966558721921e+33
4.9583278648155041477415234438717e+33


(Code is also at http://python.pastebin.com/m72a277b8)

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
Windows XP Pro, Python 2.5.1

import msvcrt
while True:
 if msvcrt.kbhit():
 key = msvcrt.getch()
 if key == 'Enter'
 do something

Is there a way to catch the pressing of the 'Enter' key?

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 04:29 AM 10/29/2007, Filip Wasilewski wrote:
On Oct 29, 11:26 am, Dick Moores [EMAIL PROTECTED] wrote:
  Windows XP Pro, Python 2.5.1
 
  import msvcrt
  while True:
   if msvcrt.kbhit():
   key = msvcrt.getch()
   if key == 'Enter'
   do something
 
  Is there a way to catch the pressing of the 'Enter' key?

Yes there is. Just open the Python shell and see what is being
returned by `getch` or `getche` functions when you press Enter:

  import msvcrt
  msvcrt.getch()
'\r'

Terrific! Thanks.

Also try to avoid `busy waiting` and calling msvcrt.kbhit in a loop
without a sleep statement.
I don't know your case but probably this
should be enough:

while True:
 if msvcrt.getch() == '\r':

I tried it and find that without the msvcrt.kbhit the first key I hit 
doesn't do anything. I have to hit that key again, or another key.

Dick

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 09:53 AM 10/29/2007, Dick Moores wrote:
At 09:26 AM 10/29/2007, Gabriel Genellina wrote:
 On 29 oct, 09:23, Dick Moores [EMAIL PROTECTED] wrote:
 
   while True:
if msvcrt.getch() == '\r':
  
   I tried it and find that without the msvcrt.kbhit the first key I hit
   doesn't do anything. I have to hit that key again, or another key.
 
 I'd say there is a logic error in your program then; keys don't do
 anything by themselves.
 Try posting a small sample, telling what you get and what you expect.

Huh. Works now.

import msvcrt
while True:
  key = msvcrt.getch()
  if key == 'h':
  print 'Hello'
  if key == 'b':
  print 'Bye'
  if key == '\r': # 'Enter' key
  break

Dick

But here's a case where it seems I do need the

if msvcrt.kbhit() line

=
#!/usr/bin/env python
#coding=utf-8
import time
import msvcrt
timeNow = time.time()
oldTimeNow = timeNow
while True:
 if msvcrt.kbhit():
 key = msvcrt.getch()
 if key == 'h':
 print 'Hello'
 if key == 'b':
 print 'Bye'
 if key == '\r': # Enter key
 break
 timeNow = time.time()
 if timeNow - oldTimeNow  5:
 print 5 seconds passed
 oldTimeNow = timeNow
==

Without that line:
==
#!/usr/bin/env python
#coding=utf-8
import time
import msvcrt
timeNow = time.time()
oldTimeNow = timeNow
while True:
 #if msvcrt.kbhit():
 key = msvcrt.getch()
 if key == 'h':
 print 'Hello'
 if key == 'b':
 print 'Bye'
 if key == '\r': # Enter key
 break
 timeNow = time.time()
 if timeNow - oldTimeNow  5:
 print 5 seconds passed
 oldTimeNow = timeNow


Without that line the 5 seconds passed report is printed ONLY after 
a b or an h, not what I want.

Dick

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 09:26 AM 10/29/2007, Gabriel Genellina wrote:
On 29 oct, 09:23, Dick Moores [EMAIL PROTECTED] wrote:

  while True:
   if msvcrt.getch() == '\r':
 
  I tried it and find that without the msvcrt.kbhit the first key I hit
  doesn't do anything. I have to hit that key again, or another key.

I'd say there is a logic error in your program then; keys don't do
anything by themselves.
Try posting a small sample, telling what you get and what you expect.

Huh. Works now.

import msvcrt
while True:
 key = msvcrt.getch()
 if key == 'h':
 print 'Hello'
 if key == 'b':
 print 'Bye'
 if key == '\r': # 'Enter' key
 break

Dick 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
Reposting, deleting the [Possible SPAM] from the Subject: header.

At 03:23 PM 10/29/2007, Gabriel Genellina wrote:
 En Mon, 29 Oct 2007 14:39:49 -0300, Dick Moores [EMAIL PROTECTED] escribió:
 
   But here's a case where it seems I do need the
  
   if msvcrt.kbhit() line
 
 At least add a small sleep() call inside the loop, to be nice to other
 running processes:
 
   =
   #!/usr/bin/env python
   #coding=utf-8
   import time
   import msvcrt
   timeNow = time.time()
   oldTimeNow = timeNow
   while True:
if msvcrt.kbhit():
key = msvcrt.getch()
if key == 'h':
print 'Hello'
if key == 'b':
print 'Bye'
if key == '\r': # Enter key
break
  else:
  time.sleep(0.1)
timeNow = time.time()
if timeNow - oldTimeNow  5:
print 5 seconds passed
oldTimeNow = timeNow
   =

Yes, that makes a major difference in the CPU
usage percentage on my computer. In fact I can't
even tell that there is anything going on other
than the usual behind-the-scenes XP stuff. CPU
usage stays right around 0% or 6%, with an
occasional 6% and a very occasional 15%.
Interestingly, sleep(0.001) makes as big a
difference as your sleep(0.1), but sleep(0.0001) bumps it up to a steady 100%!

Thanks,

Dick 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Possible SPAM] Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 03:23 PM 10/29/2007, Gabriel Genellina wrote:
En Mon, 29 Oct 2007 14:39:49 -0300, Dick Moores [EMAIL PROTECTED] escribió:

  But here's a case where it seems I do need the
 
  if msvcrt.kbhit() line

At least add a small sleep() call inside the loop, to be nice to other
running processes:

  =
  #!/usr/bin/env python
  #coding=utf-8
  import time
  import msvcrt
  timeNow = time.time()
  oldTimeNow = timeNow
  while True:
   if msvcrt.kbhit():
   key = msvcrt.getch()
   if key == 'h':
   print 'Hello'
   if key == 'b':
   print 'Bye'
   if key == '\r': # Enter key
   break
 else:
 time.sleep(0.1)
   timeNow = time.time()
   if timeNow - oldTimeNow  5:
   print 5 seconds passed
   oldTimeNow = timeNow
  =

Yes, that makes a major difference in the CPU 
usage percentage on my computer. In fact I can't 
even tell that there is anything going on other 
than the usual behind-the-scenes XP stuff. CPU 
usage stays right around 0% or 6%, with an 
occasional 6% and a very occasional 15%. 
Interestingly, sleep(0.001) makes as big a 
difference as your sleep(0.1), but sleep(0.0001) bumps it up to a steady 100%!

Thanks,

Dick 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 06:34 PM 10/29/2007, Gabriel Genellina wrote:
En Mon, 29 Oct 2007 21:22:36 -0300, Dick Moores [EMAIL PROTECTED] escribió:

  At 03:23 PM 10/29/2007, Gabriel Genellina wrote:
  En Mon, 29 Oct 2007 14:39:49 -0300, Dick Moores [EMAIL PROTECTED]
  escribió:
 
 
  At least add a small sleep() call inside the loop, to be nice to other
  running processes:
 
 
  Yes, that makes a major difference in the CPU
  usage percentage on my computer. In fact I can't
  even tell that there is anything going on other
  than the usual behind-the-scenes XP stuff. CPU
  usage stays right around 0% or 6%, with an
  occasional 6% and a very occasional 15%.
  Interestingly, sleep(0.001) makes as big a
  difference as your sleep(0.1), but sleep(0.0001) bumps it up to a steady
  100%!

The underlying function in Windows is Sleep (or SleepEx) which takes an
argument in milliseconds. 0.0001s = 0.1ms and it's rounded to 0. Sleep(0)
has very specific semantics - for a single threaded program, it does
nothing, so your code is effectively a busy loop taking 100% CPU.

Ah, useful information. Thank you. Where'd you learn that?

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Top Programming Languages of 2013

2007-10-07 Thread Dick Moores
http://www.redcanary.ca/view/top-programming

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Where's the Starship's crew?

2007-10-05 Thread Dick Moores
http://starship.python.net/crew/index.html

I didn't check on all of them, but the only one I found was Mark 
Hammond http://starship.python.net/crew/mhammond/.

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where's the Starship's crew?

2007-10-05 Thread Dick Moores
At 04:54 AM 10/5/2007, Thomas Heller wrote:
Dick Moores schrieb:
  http://starship.python.net/crew/index.html
 
  I didn't check on all of them, but the only one I found was Mark
  Hammond http://starship.python.net/crew/mhammond/.
 
  Dick Moores
 

There are more. Think of it as a game you have to solve.

Yeah, a mind numbing game!

http://starship.python.net/crew/ewalstad/ Eric Walstad
http://starship.python.net/crew/piers/ Piers Lauder
http://starship.python.net/crew/jae/ -- http://zhar.net/  John Eikenberry
http://starship.python.net/crew/mwh/
http://starship.python.net/crew/manus/ Manus Hand
http://starship.python.net/crew/bhoel/ Berthold Höllmann
http://starship.python.net/crew/marduk/ (Server Error)
http://starship.python.net/crew/schorsch/
http://starship.python.net/crew/dni/ David Niergarth
http://starship.python.net/crew/jcooley/ James Cooley
http://starship.python.net/crew/sdrees/ Stefan Drees
http://starship.python.net/crew/jwt/ Jim Tittsler
http://starship.python.net/crew/theller/ Thomas Heller
http://starship.python.net/crew/gherman/ Dinu Gherman
http://starship.python.net/crew/mhammond/ Mark Hammond
http://starship.python.net/crew/atuining/
http://starship.python.net/crew/hooft/ Rob W.W. Hooft
http://starship.python.net/crew/lemburg/ -- http://www.egenix.com/
http://starship.python.net/crew/goodger/ David Goodger
http://starship.python.net/crew/mmuller/ Mike Muller
http://starship.python.net/crew/skippy/ same as 
http://starship.python.net/crew/mhammond/ Mark Hammond

BTW How could I have done this with Python script?

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed of Python

2007-09-11 Thread Dick Moores
At 09:42 AM 9/7/2007, wang frank wrote:
Are there any way to speed it up?

How about psyco?

Dick Moores
XP, Python 2.5.1, editor is Ulipad


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 'REPL' style IDE

2007-08-22 Thread Dick Moores
At 10:50 AM 8/20/2007, beginner wrote:
Hi Everyone,

I am using the Wing IDE. It works great when developing applications,
but the workflow is like Visual Studio -- after you execute it or
debug it, the python script ends.

What I want is an interactive interpreting environment. I want the IDE
to execute a boot script to initialize my environment and create some
basic data objects. And then I want to be able to type in command on
the command line using these objects. The IDLE that comes with Python
does this, but compared with Wing, it does not have a lot of the
convenient features.

I am wondering if there is anything more powerful than IDLE that can
do this.

Are you sure you can't do this with Wing? Have you asked support, 
[EMAIL PROTECTED]?

Dick Moores



==
   Bagdad Weather
http://weather.yahoo.com/forecast/IZXX0008_f.html 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-22 Thread Dick Moores
At 06:55 AM 8/21/2007, limodou wrote:
On 8/21/07, king kikapu [EMAIL PROTECTED] wrote:
  On Aug 21, 12:00 pm, Joel Andres Granados [EMAIL PROTECTED]
  wrote:
   Hello list:
  
   I have tried various times to use an IDE for python put have always been
   disapointed.
 
 
  I have also tried a lot of them (IDEs) in the last year. I was finally
  happy with Eclipse/Pydev but i was always wanted a more true IDE for
  Python.
  I think i found it in Eric4 http://www.die-offenbachs.de/eric/index.html
  You can download from here 
 http://www.riverbankcomputing.co.uk/pyqt/download.php
  (binary installer for Windows that contains Eric and PyQt)
  and have a look at it!
 
Maybe someone can try UliPad, I just release 3.7 version a few days before.

I'm a longtime, very satisfied Ulipad user, and heartily recommend 
Ulipad. http://code.google.com/p/ulipad/.

Limodou, although sometimes busy with other projects, is very 
responsive to requests for help with Ulilpad, and very open to 
suggestions for new features. He's Chinese, in Beijing, so is on 
Beijing time, but during his day he seems to check his mail often. 
(Gmail users can see when he's using his Gmail account.) If you do 
become a Ulipad user, I strongly suggest you subscribe to the Ulipad 
list at Google Groups, http://groups.google.com/group/ulipad.

Dick Moores
XP, Python 2.5, editor is Ulipad



--
I like python!
UliPad The Python Editor: http://code.google.com/p/ulipad/
My Blog: http://www.donews.net/limodou
--
http://mail.python.org/mailman/listinfo/python-list

==
   Bagdad Weather
http://weather.yahoo.com/forecast/IZXX0008_f.html 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hot subject: a good python editor and/or IDE?

2007-08-19 Thread Dick Moores
At 02:47 AM 8/19/2007, Sébastien wrote:
Hi folks,

I am currently using Eclipse+PyDev when developping Python projects but
I lack a fast, simple editor for tiny bit of scripts. So here is my
question: what is, for you, the current best ( but still kind of light!
) Python editor/IDE ? A tiny precision, I am on Ubuntu so I am looking
for a linux compatible editor.

I thought Ulipad WAS linux-compatible. Isn't it?

Dick Moores
XP, Python 2.5, editor is Ulipad



==
   Bagdad Weather
http://weather.yahoo.com/forecast/IZXX0008_f.html  

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-19 Thread Dick Moores
At 08:30 AM 8/16/2007, special_dragonfly wrote:
Hello,

I need to return the date yesterday in the form DDMM. I looked through
the modules: time, datetime and calendar but can't find anything that leaps
out at me.

The problem I'm having is that although I can use time.localtime and get a
tuple of the year, month, day and so forth, I don't believe I can just minus
1 from the day, because I don't think it's cyclic, also, I can't see the
date being linked in with the month.

So is there any way of getting yesterdays date?

The question has already been well-answered, but since I've found 
using the datetime module to be tough going, I was wondering if 
either of these would be easier to understand and use:
1. http://www.egenix.com/products/python/mxBase/mxDateTime/
I see that mxDateTime comes with a 55-page manual as a PDF.

2. http://labix.org/python-dateutil

Dick Moores




-- 
http://mail.python.org/mailman/listinfo/python-list


Opinions about this new Python book?

2007-08-14 Thread Dick Moores
I'd appreciate opinions about this new Python book.

Title: Python Power!: The Comprehensive Guide
Author:  Matt Telles
Publisher:  Course Technology
Pub. Date:  Jul 27, 2007
Edition:  1st edition
Binding:  Paperback
Pages:  508
ISBN:  1598631586
List Price:  34.99 USD

The book on the publisher's website: http://tinyurl.com/2dkhzg

And at BestBookDeal.com:
 http://www.bestbookdeal.com/book/compare/1598631586

Thanks,

Dick Moores 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Opinions about this new Python book?

2007-08-14 Thread Dick Moores
At 05:57 AM 8/14/2007, [EMAIL PROTECTED] wrote:
On Aug 14, 7:05 am, Dick Moores [EMAIL PROTECTED] wrote:
  I'd appreciate opinions about this new Python book.
 
  Title: Python Power!: The Comprehensive Guide
  Author:  Matt Telles
  Publisher:  Course Technology
  Pub. Date:  Jul 27, 2007
  Edition:  1st edition
  Binding:  Paperback
  Pages:  508
  ISBN:  1598631586
  List Price:  34.99 USD
 
  The book on the publisher's website: http://tinyurl.com/2dkhzg
 
  And at BestBookDeal.com:
  http://www.bestbookdeal.com/book/compare/1598631586
 
  Thanks,
 
  Dick Moores

I just got this book over the weekend. I'll start reading/skimming
through it this week and hopefully remember to get back to you.

Thanks!

  By the
way, why do you want to know?

If the experts like it, I'll buy it.

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Binary, Hex, and Decimal string conversions

2007-08-13 Thread Dick Moores


At 07:35 AM 8/13/2007, Robert Dailey wrote:
Just curious Dick, why are you
making your own to_base method? Doesn't the source I provided in my
earlier email give you all that you need? I was hoping my source might be
useful to a few people, even though it's pretty trivial code.

I didn't roll my own. I just preferred n to
number. I greatly appreciated your code!
Dick

On 8/12/07, Dick Moores
[EMAIL PROTECTED] wrote:


At 07:04 PM 8/12/2007, Michael Bentley wrote:

On Aug 12, 2007, at 6:28 PM, Dick Moores wrote:



n = 12

base = 36

print to_base(n, base)

== 

This seems to work fine for n = base, but not for n 
base. For

example, the code shown returns c. Is my
indentation wrong, or

the code? It seems to me that the code should work for the
general 

case, not just for n = base.



Isn't 'c' the correct answer?

Yes, of course. Stupid of me.

Dick


--


http://mail.python.org/mailman/listinfo/python-list




-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Puzzled by is

2007-08-12 Thread Dick Moores
On 8/12/07, Ben Finney [EMAIL PROTECTED] wrote:

 Dick Moores [EMAIL PROTECTED] writes:

  At 06:13 PM 8/9/2007, Ben Finney wrote:
  it's entirely left to the language implementation which
  optimisation trade-offs to make, and the language user (that's you
  and I) should *not* expect any particular behaviour to hold between
  different implementations.
 
  I'm not clear on the meaning of implementations here.  Would 2.5
  for Windows, Mac, Linux all be different implementations? Would Iron
  Python be another? ActivePython?

 For the purpose of the above statement, you should consider even the
 same Python on two different machines to be different
 implementations. As a programmer writing Python code, you should not
 expect any implementation-dependent behaviour to operate in any
 particular way.


So would a programmer EVER use is in a script?

Dick
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Puzzled by is

2007-08-12 Thread Dick Moores
At 08:23 AM 8/12/2007, Steve Holden wrote:
Dick Moores wrote:
  So would a programmer EVER use is in a script?

Sure. For example, the canonical test for None uses

  x is None

because there is only ever one instance of type Nonetype, so it's the
fastest test. Generally speaking you use is to test for identity (do
these two expressions reference the same object) rather than equality
(do these two expressions evaluate to equivalent objects).

Off the top of your head, could you or others give me as many 
examples as you can think of?

Thanks again,

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzled by is

2007-08-12 Thread Dick Moores
At 09:59 AM 8/12/2007, Steve Holden wrote:
Dick Moores wrote:
  At 08:23 AM 8/12/2007, Steve Holden wrote:
  Dick Moores wrote:
  So would a programmer EVER use is in a script?
  Sure. For example, the canonical test for None uses
 
   x is None
 
  because there is only ever one instance of type Nonetype, so it's the
  fastest test. Generally speaking you use is to test for identity (do
  these two expressions reference the same object) rather than equality
  (do these two expressions evaluate to equivalent objects).
 
  Off the top of your head, could you or others give me as many
  examples as you can think of?
 
Occasionally it's necessary to test for a specific type (though in
Python this is usually bad practice). Since types are also singletons
the best way to do this is (e.g.):

  type(x) is type([]) # test specifically for a list

If you want to know whether you have been told to write to standard
output, one possible test is

  if f is not sys.stdout

Similarly, of course, you can test for the other standard IO channels.

The imputil module contains the test

  if importer is not self

to determine whether a reload() should be performed in the context of
the current package.

When you need to establish a specific sentinel value that can never be
provided by an outside caller it's normal to create an instance of
object (the simplest possible thing you can create in a Python program)
and test for that instance, as in

  sentinel = object()
  ...
  if value is sentinel:

You can test whether a class is new-style as opposed to old-style, which
can help to unify old-style and new-style objects:

class MetaProperty(type):
  def __new__(cls, name, bases, dct):
  if bases[0] is object: # allow us to create class Property
  return type.__new__(cls, name, bases, dct)
  return property(dct.get('get'), dct.get('set'),
  dct.get('delete'), dct.get('__doc__'))

  def __init__(cls, name, bases, dct):
  if bases[0] is object:
  return type.__init__(cls, name, bases, dct)


That gets you started ...

Sure does. Thanks very much, Steve.

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


A dumb question about a class

2007-08-12 Thread Dick Moores
I'm still trying to understand classes. I've made some progress, I 
think, but I don't understand how to use this one. How do I call it, 
or any of its functions? It's from the Cookbook, at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523048.

Thanks,

Dick Moores

=
class PrimeList:
def __init__(self, initial=0):
self.primelist = [2,3]
self.primelookup = [0,0,1,1]
self.max_prime = 3
self.grow_primelist(initial)

def grow_primelist(self,number):
newprimes = []
while self.max_prime = number:
next = self.nextprime()
newprimes.append(next)
self.max_prime = next
size_difference = self.max_prime - 
len(self.primelookup) + 1
self.primelookup.extend([0] * size_difference)
for i in newprimes:
self.primelookup[i]=1

def contains(self,number):
if number  2:
return 0
if number  len(self.primelookup) - 1:
self.grow_primelist(number)
return self.primelookup[number]
return self.primelookup[number]

def nextprime(self):
i = self.max_prime + 2
while 1:
isprime = True
for prime in self.primelist:
if i % prime == 0:
isprime = False
i += 2
break
if isprime:
self.primelist.append(i)
return(i)
==

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A dumb question about a class

2007-08-12 Thread Dick Moores
At 03:09 PM 8/12/2007, Steven Bethard wrote:

Here's how I'd write the recipe::

  import itertools

  def iter_primes():
  # an iterator of all numbers between 2 and +infinity
  numbers = itertools.count(2)

  # generate primes forever
  while True:

  # get the first number from the iterator (always a prime)
  prime = numbers.next()
  yield prime

  # remove all numbers from the (infinite) iterator that are
  # divisible by the prime we just generated
  numbers = itertools.ifilter(prime.__rmod__, numbers)


  class PrimeList(object):
  def __init__(self):
  # infinite iterator of primes
  self._prime_iter = iter_primes()

  # the last prime we've seen
  self._last_prime = None

  # all primes seen so far
  self._prime_set = set()

  # add the first prime (so that _last_prime is set)
  self._add_prime()

  def __contains__(self, n):
  # add primes to the list until we exceed n
  while n  self._last_prime:
  self._add_prime()

  # return True if n is one of our primes
  return n in self._prime_set

  def _add_prime(self):
  # take a prime off the iterator and update the prime set
  self._last_prime = self._prime_iter.next()
  self._prime_set.add(self._last_prime)

I'm afraid my next question is How do I run this?

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A dumb question about a class

2007-08-12 Thread Dick Moores
At 03:35 PM 8/12/2007, Steven Bethard wrote:
Note that if you just want to iterate over all the primes, there's no
need for the class at all.  Simply write::

  for prime in iter_primes():

Even if I want to test only 1 integer, or want the list of primes in 
a certain interval, I don't need the class at all:


import itertools

def iter_primes():
 # an iterator of all numbers between 2 and +infinity
 numbers = itertools.count(2)


 # generate primes forever
 while True:


 # get the first number from the iterator (always a prime)
 prime = numbers.next()
 yield prime


 # remove all numbers from the (infinite) iterator that are
 # divisible by the prime we just generated
 numbers = itertools.ifilter(prime.__rmod__, numbers)

def listPrimes(n,m):
 
 Returns the list of primes in closed interval [n,m]
 
 primes = []
 for prime in iter_primes():
 if prime  m:
 return primes
 if n = prime = m:
 primes.append(prime)


Thanks for your help. I didn't learn much about classes, but 
appreciated your iter_primes() a lot!

Dick Moores 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Binary, Hex, and Decimal string conversions

2007-08-12 Thread Dick Moores


At 04:20 PM 8/12/2007, Robert Dailey wrote:
Well, I decided to implement my
own way of doing this. I've attached the source. You're all welcome
:)
On 8/12/07, Michael Bentley

[EMAIL PROTECTED] wrote:


Hi Robert,

On Aug 11, 2007, at 3:59 PM, Robert Dailey wrote:

Hi, I was wondering if there is a built in module that supports
conversion in any direction between Binary, Hex, and Decimal strings?
Thanks. 

Shouldn't be too hard to build one. Here's a little incantation
to convert from base 10 to another base:

import string

def to_base(number, base):

'converts base 10 integer to another base'

number = int(number)

base = int(base)

if base  2 or base  36:

raise ValueError, Base must be between 2 and 36 

if not number:

return 0

symbols = string.digits + string.lowercase[:26]

answer = []

while number:

number, remainder = divmod(number, base)

answer.append(symbols[remainder]) 

return ''.join(reversed(answer))

I've tried to figure out the correct indentation for this, and came up
with

import string
def to_base(n, base):
 'converts base 10 integer to another base, up thru
base 36'
 n = int(n)
 base = int(base) 
 if base  2 or base  36:
 raise ValueError, Base
must be between 2 and 36 
 if not n:
 return 0
 symbols = string.digits + string.lowercase[:26] 
 answer = []
 while n:
 n, remainder = divmod(n,
base)

answer.append(symbols[remainder]) 
 return ''.join(reversed(answer))
n = 12
base = 36
print to_base(n, base)
==
This seems to work fine for n = base, but not for n  base. For
example, the code shown returns c. Is my indentation wrong,
or the code? It seems to me that the code should work for the general
case, not just for n = base.
Dick Moores


How 'bout you hack a from_base function and email it back to me?
(hint: type 'help(int)' in the python interpreter).

Peace,

Michael

---

Let the wookie win.



Content-Type: text/plain; name=baseconv.py
Content-Disposition: attachment; filename=baseconv.py
X-Attachment-Id: f_f5a5roa4

-- 

http://mail.python.org/mailman/listinfo/python-list



-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Binary, Hex, and Decimal string conversions

2007-08-12 Thread Dick Moores
At 07:04 PM 8/12/2007, Michael Bentley wrote:

On Aug 12, 2007, at 6:28 PM, Dick Moores wrote:

n = 12
base = 36
print to_base(n, base)
==
This seems to work fine for n = base, but not for n  base. For 
example, the code shown returns c. Is my indentation wrong, or 
the code? It seems to me that the code should work for the general 
case, not just for n = base.

Isn't 'c' the correct answer?

Yes, of course. Stupid of me.

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzled by is

2007-08-10 Thread Dick Moores
At 06:13 PM 8/9/2007, Ben Finney wrote:
Content-Transfer-Encoding: base64Grzegorz 
Słodkowicz [EMAIL PROTECTED]  [EMAIL PROTECTED] 
theorisation but I'd rather expect the interpreter
  simply not to create a second tuple while there already is an
  identical one.

Others have already said that it's an implementation optimisation,
which seems to partly answer your question.

It's important to also realise that the language is *deliberately*
non-committal on whether any given value will have this behaviour;
that is, it's entirely left to the language implementation which
optimisation trade-offs to make, and the language user (that's you and
I) should *not* expect any particular behaviour to hold between
different implementations.

I'm not clear on the meaning of implementations 
here.  Would 2.5 for Windows, Mac, Linux all be 
different implementations? Would Iron Python be another? ActivePython?

Thanks,

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Puzzled by is

2007-08-09 Thread Dick Moores
  () is ()
True
  (1,) is (1,)
False

Why?

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzled by is

2007-08-09 Thread Dick Moores
At 10:46 AM 8/9/2007, Bill Scherer wrote:
Dick Moores wrote:
() is ()
  True
(1,) is (1,)
  False
 
  Why?
 

  a = ()
  b = ()
  c = (1,)
  d = (1,)
  a is b
True
  c is d
False
  id(a)
3086553132
  id(b)
3086553132
  id(c)
3086411340
  id(d)
3086390892


There is only one empty tuple.
Does that clear it up for you?

But isn't that the same as saying, That's just the reality of 
Python; it is what it is.? I want to know why there is only one 
empty tuple, but more than one (1,).

Also,
  [] is []
False

Dick  

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the one python book

2007-08-08 Thread Dick Moores
At 10:22 AM 8/5/2007, vasudevram wrote:
  On Aug 4, 7:23 am, dhr [EMAIL PROTECTED] wrote:
 
   newbie question:
 
   Is there a 'KR type of Python book? The book that you'd better have on
   your shelf if you are going into Python?
 

Python in a Nutshell, the Python Cookbook and Programming Python are
all very good, IMO. Programming Python comes with a CD of all the
source code in the book (at least the 2nd edition did, as well as
Python language - this can save you some time keying in the examples.
Of course, many of the O'Reilly books (and all 3 of these are from
O'Reilly) have links to downloadable source code from them. Just
Google for the name of the book, then in the results, hit the
appropriate link to the O'Reilly site for the book, and look down the
page for the link to the examples' source.

Or (for Programming Python):

http://www.oreilly.com/catalog/python2/
http://www.oreilly.com/catalog/python3/

No CD with 3rd edition, but here are the examples: 
http://examples.oreilly.com/python3/

Dick Moores

==
   Bagdad Weather
http://weather.yahoo.com/forecast/IZXX0008_f.html 

-- 
http://mail.python.org/mailman/listinfo/python-list


WinPdb?

2007-08-08 Thread Dick Moores


The only debugging I've done so far is to put in print statements where I
want to see what's happening. But it's often through a glass
darkly.
However, I just discovered that my excellent (IMO) Python editor, Ulipad,
comes with WinPdb, and I'm thinking it's about time I learned how to use
a debugger. 
But first, could I get some reviews here of WinPdb before I invest a lot
of time in learning it? I've found a couple links to tutorials on the
WinPdb website
(
http://www.digitalpeers.com/pythondebugger/, where you'll also
notice that version 1.2.0 came out August 6 (the latest svn revision of
Ulipad already has it:

http://ulipad.googlecode.com/svn/ (Ulipad's developer, Limodou,
is very responsive). 
Thanks,
Dick Moores

==

Bagdad Weather

http://weather.yahoo.com/forecast/IZXX0008_f.html


-- 
http://mail.python.org/mailman/listinfo/python-list

Re: OOP in Python book?

2007-07-28 Thread Dick Moores
At 01:27 PM 7/28/2007, Dennis Lee Bieber wrote:
On Fri, 27 Jul 2007 16:27:57 -0700, Dick Moores [EMAIL PROTECTED]
declaimed the following in comp.lang.python:


  Well, the publisher is Prentice Hall, The world's leading
  educational publisher. Textbooks are typically expensive.
 

 Yeah... But at that price it should have hard-covers!

Should have, but look at this popular Cultural Anthropology text 
(paperback): http://tinyurl.com/38ec5s. List price is $120.95 USD. 
(BTW I just bought the 6th edition online for about $10.)

Then there's Calculus: Single Variable (Paperback) 
http://tinyurl.com/2lqw9c List price $123.95 USD.

And so it goes.

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP in Python book?

2007-07-27 Thread Dick Moores
At 08:41 AM 7/27/2007, Bill wrote:
Does anyone out there have any information about this book. It's
listed on Amazon to be published in November of this year. A simple
Google search (1st page only) doesn't show anything useful, and I
can't find a reference on the web sites of the authors. Neither of the
authors appears to be heavily into OOP theory, just some CS areas that
I don't understand.

I'm particularly interested in why this book is worth the $100 tag
that Amazon shows.

Well, the publisher is Prentice Hall, The world's leading 
educational publisher. Textbooks are typically expensive.

Here's the Amazon link: 
http://www.amazon.com/Object-Oriented-Programming-Python-Michael-Goldwasser/dp/0136150314

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for a wxPython GUI builder

2007-06-15 Thread Dick Moores
How about SPE?

Any others?

And which ones do people
actually use? Commercial or Freeware.

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with following python code

2007-06-11 Thread Dick Moores
At 09:52 PM 6/11/2007, Dan Hipschman wrote:
On Tue, Jun 12, 2007 at 04:25:31AM -, why? wrote:
  I've been having problem with the following code. It's supposed to
  print the prime numbers  between 10 and 100. But i'm not getting any
  output, i.e. i guess the outer 'for' loop is being traversed only
  once. I would be greatful if you could help me out. Thanx!
   f=1
   for i in range(10,100):
  ... for j in range(2,i):
  ... if i%j==0:
  ... f=0
  ... break
  ... else: continue
  ... if f==1:
  ... print i,
  ...

Move f=1 inside the outer loop:

for i in range(10,100):
 f=1
 for j in range(2,i):
 if i%j==0:
 f=0
 break
 else: continue
 if f==1:
 print i,

It gets set to 0 in the first iteration and never has another chance to
be set to 1 after that.

And of course the inner loop does too much work. Try:

for i in range(10,100):
 f=1
 max = int(i**.5 + 1)
 for j in range(2,max):
 if i%j==0:
 f=0
 break
 else: continue
 if f==1:
 print i,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: preferred windows text editor?

2007-05-10 Thread Dick Moores
At 11:06 AM 5/9/2007, T. Crane wrote:
Right now I'm using Notepad++.  What are other people using?

Ulipad.

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Welch essential for learning Tkinter well?

2007-04-07 Thread Dick Moores
At 10:36 AM 4/6/2007, Russell E. Owen wrote:
In article [EMAIL PROTECTED],
  Kevin Walzer [EMAIL PROTECTED] wrote:

  James Stroud wrote:
  This begs the
   question, is anyone truly an expert in Tkinter?
 
  Frederick Lundh is, if anyone is.
 
  http://www.pythonware.com/library/tkinter/introduction/index.htm (outdated)
  http://effbot.org/tkinterbook/ (new but incomplete)

I agree that this is an excellent resource.

I find Welch's book and the on-line tcl/tk help very helpful for Tkinter
programming--especially some of the more obscure details. But to use
either of these resources comfortably you must learn the basics of
Tkinter first (including understanding the simple mapping between
Tkinter and Tcl/Tk).

Where can I get this mapping spelled out?

For learning the basics of Tkinter I suggest the links that Kevin listed
above and/or Alex Martelli's Python in a Nutshell (an excellent
reference in any case).

Although owning the 2nd ed. of Python is a Nutshell, I hadn't 
thought of looking into it for Tkinker. There's a whole chapter, 
Tkinter GUIs (46 pages!).

  Grayson's book is another reasonable alternative
(and includes enough reference material to keep you from having to refer
to the tcl/tk documentation very often).

One web tutorial that looks good to me is Thinking in Tkinter, by 
Stephen Ferg (http://www.ferg.org/thinking_in_tkinter/index.html).

My thanks to all who responded.

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
I accidentally stumbled across the Turtle Graphics module (turtle.py) 
the other day and have been having some fun with it.

Now I'm wondering if there is a way to build into a script the saving 
of each window just before it is cleared. For example, here are a 
couple that I've saved by screen capture:
http://www.rcblue.com/Misc/RandomTriangles.jpg
http://www.rcblue.com/Misc/RandomTriangles2.jpg

They were produced by this script:

=
# randomTriangles.py

import turtle as T
from random import *

def twoRndN(low=0, high=1):
 
 generate two random floats x, y in the range [low, high) such that x = y
 
 x, y = uniform(low, high), uniform(low, high)
 if x = y:
 return x, y
 else:
 return y, x

T.setup(width=1000, height=700, startx=0, starty=0)
T.title(Random Triangles with random R,G,B)

colorRange = all
if colorRange == random:
 lowR, highR = twoRndN()
 lowG, highG = twoRndN()
 lowB, highB = twoRndN()

count = 0
for n in range(300):
 wdth = randrange(0,7,3)
 T.width(wdth)
 T.speed(fastest)
 if colorRange == dark:
 R = uniform(.1, .5)
 G = uniform(.1, .5)
 B = uniform(.1, .5)
 elif colorRange == pastel:
 R = uniform(.5, .9)
 G = uniform(.5, .9)
 B = uniform(.5, .9)
 elif colorRange == all:
 R = uniform(0, 1)
 G = uniform(0, 1)
 B = uniform(0, 1)
 # set RGB for one color of your choice
 elif colorRange == manual:
 R = .45
 G = .2
 B = .2
 elif colorRange == random:
 R = uniform(lowR, highR)
 G = uniform(lowG, highG)
 B = uniform(lowB, highB)

 T.color(R,G,B)
 T.begin_fill()
 # 2 connected lines will fill as a triangle
 for x in range(2):
 coord = (randint(-500,500), randint(-350,350))
 T.goto(coord)
 T.end_fill()

 count += 1
 if count  5:
 clr = randint(0,5)
 if clr == 0:
 T.clear()
 count = 0
T.done()
==
(The docs for Turtle graphics for Tk are at 
http://www.python.org/doc/2.5/lib/module-turtle.html)

But how could I have saved them automatically?

The script as shown will clear (T.clear() -- the 3rd line from the 
bottom) the window after producing 6 to maybe 15 superimposed 
triangles, so clearing will take place maybe 30 times. How can I save 
as images each of the 30 windows just before they are cleared?

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Welch essential for learning Tkinter well?

2007-04-07 Thread Dick Moores
At 03:43 AM 4/7/2007, James Stroud wrote:
Dick Moores wrote:
  At 10:36 AM 4/6/2007, Russell E. Owen wrote:
  I find Welch's book and the on-line tcl/tk help very helpful for Tkinter
  programming--especially some of the more obscure details. But to use
  either of these resources comfortably you must learn the basics of
  Tkinter first (including understanding the simple mapping between
  Tkinter and Tcl/Tk).
 
  Where can I get this mapping spelled out?

Grayson Appendix A. $25 pdf--well worth it in your time.

Terrific! Thank you.

Dick

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
At 06:50 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu=B3a?= wrote:
Dick Moores wrote:
  I accidentally stumbled across the Turtle Graphics module (turtle.py)
  the other day and have been having some fun with it.
 
  Now I'm wondering if there is a way to build into a script the saving of
  each window just before it is cleared. For example, here are a couple
  that I've saved by screen capture:
  http://www.rcblue.com/Misc/RandomTriangles.jpg
  http://www.rcblue.com/Misc/RandomTriangles2.jpg

Turtle module uses Tk canvas element to draw graphics ('_canvas'
attribute). I've written module, that exports canvas graphics to SVG
file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
for you.

I afraid I'm totally unfamiliar with SVG. Would it be possible for 
you or someone else on the list to show how to use your module to 
export the simple product of this simple script to an SVG file?

===
import turtle as T
from random import randint
T.setup(width=1000, height=700, startx=0, starty=0)
T.color(1, .5, .5)
T.begin_fill()
# 2 connected lines will fill as a triangle
for x in range(2):
 coord = (randint(-500,500), randint(-350,350))
 T.goto(coord)
T.end_fill()

T.done()


Thanks,

Dick Moores
Win XP Pro SP2
Python 2.5
Python IDE: Ulipad 3.6


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
At 08:48 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu=B3a?= wrote:
Dick Moores wrote:
  Turtle module uses Tk canvas element to draw graphics ('_canvas'
  attribute). I've written module, that exports canvas graphics to SVG
  file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
  for you.
 
  I afraid I'm totally unfamiliar with SVG. Would it be possible for you
  or someone else on the list to show how to use your module to export the
  simple product of this simple script to an SVG file?
 
  ===
  import turtle as T
import canvasvg
  from random import randint
  T.setup(width=1000, height=700, startx=0, starty=0)
  T.color(1, .5, .5)
  T.begin_fill()
  # 2 connected lines will fill as a triangle
  for x in range(2):
  coord = (randint(-500,500), randint(-350,350))
  T.goto(coord)
  T.end_fill()

canvasvg.saveall(image.svg, T._canvas)

  T.done()
  

OK, thanks, now I've got

===
?xml version=1.0 ?!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 
1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'svg 
height=246.000 viewBox=8.000 338.000 504.000 246.000 
width=504.000 xmlns=http://www.w3.org/2000/svg;line fill=none 
stroke=#ff8080 stroke-linecap=round x1=500.0 x2=20.0 
y1=350.0 y2=426.0/line fill=none stroke=#ff8080 
stroke-linecap=round x1=20.0 x2=368.0 y1=426.0 
y2=569.0/line fill=none stroke=#ff8080 stroke-linecap=round 
x1=360.0 x2=368.0 y1=569.0 y2=569.0/polygon fill=#ff8080 
points=368.0 569.0 358.0 572.0 360.0 569.0 358.0 566.0/polygon 
fill=#ff8080 fill-rule=evenodd points=500.0,350.0 20.0,426.0 
368.0,569.0 stroke-linejoin=round//svg


What do I do to see this?

Dick

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
At 09:31 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu=B3a?= wrote:
Dick Moores wrote:
  What do I do to see this?

For example Opera 9 and Firefox 1.5+ are able to view SVG files;
there is a free plugin for IrfanView.

Ha. I had tried it with Firefox 2 already, but I stupidly changed the 
extension to HTM first. I'll also get the IrfanView plugin.

Thanks for all the help, and especially for your canvasvg.py module.

Dick


-- 
http://mail.python.org/mailman/listinfo/python-list


Welch essential for learning Tkinter well?

2007-04-05 Thread Dick Moores
In a couple of places recently I've seen Brent Welch's _Practical 
Programming in Tcl  Tk_ (http://tinyurl.com/ynlk8b) recommended 
for learning Tkinter well.

So a couple of questions:

1) Is it really good for learning Tkinter, even though it doesn't 
mention Tkinter at all (in the 4th edition at least)?

2) If it is good for learning Tkinter, can I get by with a cheaper, 
used copy of the 3rd edition?

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE question

2007-03-27 Thread Dick Moores
At 01:39 AM 3/27/2007, alain wrote:
Hi,

Could someone tell me how to uninstall SPE under windows?

Well, mine is in E:\Python25\Lib\site-packages\_spe, so I'd try 
deleting that folder.

Dick Moores 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE question

2007-03-27 Thread Dick Moores
At 03:37 AM 3/27/2007, [EMAIL PROTECTED] wrote:
On Mar 27, 11:39 am, alain [EMAIL PROTECTED] wrote:
  Hi,
 
  Could someone tell me how to uninstall SPE under windows?
 
  Alain

Dunno about SPE, but most Python modules I've installed can
be uninstalled from control panel/add remove programs.

SPE doesn't show up on my win XP add/remove programs list.

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Weekly Python Patch/Bug Summary

2007-03-17 Thread Dick Moores


May I ask a dumb question here? It isn't clear to me what to do with
these patches. For most of them there is something like, Committed
as r54386 and r54387. I'm familiar with updating the editor Ulipad
to the latest revision, using software such as TortoiseSVN and RapidSVN.
Is that what is meant? And if so, what's the URL of the trunk?
Thanks,
Dick Moores




-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Weekly Python Patch/Bug Summary

2007-03-17 Thread Dick Moores
At 01:32 AM 3/17/2007, Terry Reedy wrote:

Dick Moores [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
| May I ask a dumb question here? It isn't clear to me what to do with
these patches. For most of them there is something like, Committed as
r54386 and r54387. I'm familiar with updating the editor Ulipad to the
latest revision, using software such as TortoiseSVN and RapidSVN. Is that
what is meant? And if so, what's the URL of the trunk?
-

Yes, those are svn revision numbers.  Start at svn.python.org.

I thought I'd give 
http://svn.python.org/projects/python/branches/release25-maint/ 
(the latest release (plus bug fixes) of Python) a try. I first backed 
up my Python25 folder (I'm using Win XP). Then with Python 25 open I 
opened the Explorer context menu for the folder and then the 
TortoiseSVN sub-menu. There doesn't seem to have a menu item that 
will enable me to update. I tried Export... and entered 
http://svn.python.org/projects/python/branches/release25-maint/ as 
URL of repository, but that choice seems to expect the Python25 
folder to be empty. Can you tell me what to do to just update?

Dick 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-13 Thread Dick Moores
At 06:38 AM 3/10/2007, Steven D'Aprano wrote:
On Sat, 10 Mar 2007 02:32:21 -0800, Dick Moores wrote:

  So why not just repeatedly call a function to generate lists of
  length N of random integers within the appropriate range (the closed
  interval [1,M-N-1]), and return the first list the sum of which is M?
  I don't understand what all the discussion is about. Time is not one
  of the constraints.

Time is always a constraint. The sun will expand and destroy the Earth in
a couple of billion years, it would be nice to have a solutions before
then...

*wink*

Seriously, almost all programming problems have two implicit constraints:
it must run as fast as practical, using as little computer resources (e.g.
memory) as practical. Naturally those two constraints are usually in
opposition, which leads to compromise algorithms that run fast enough
without using too much memory.

OK, points well-taken.

The problem posed by the OP is Given two positive integers, N and M 
with N  M, I have to generate N
positive integers such that sum(N)=M. No more constraints.

But let's say there is one more constraint--that for each n of the N 
positive integers, there must be an equal chance for n to be any of 
the integers between 1 and M-N+1, inclusive. Thus for M == 50 and N 
== 5, the generated list of 5 should be as likely to be [1,46,1,1,1] 
as [10,10,10,10,10] or [14, 2, 7, 1, 26].

Wouldn't sumRndInt() be THE solution?:
=
def sumRndInt(M, N):
 import random
 while True:
 lst = []
 for x in range(N):
 n = random.randint(1,M-N+1)
 lst.append(n)
 if sum(lst) == M:
 return lst

if __name__ == '__main__':

 N = 5
 M = 50

 lst = sumRndInt(M, N)

 print N is %d, M is %d, lst is %s, sum(lst) is %d % (N, M, 
lst, sum(lst))
==

I hope I don't seem querulous--I really want to know.

Thanks,

Dick Moores



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-13 Thread Dick Moores
At 02:52 AM 3/13/2007, Duncan Booth wrote:
Dick Moores [EMAIL PROTECTED] wrote:

  But let's say there is one more constraint--that for each n of the N
  positive integers, there must be an equal chance for n to be any of
  the integers between 1 and M-N+1, inclusive. Thus for M == 50 and N
 == 5, the generated list of 5 should be as likely to be [1,46,1,1,1]
  as [10,10,10,10,10] or [14, 2, 7, 1, 26].

I don't think what you wrote actually works. Any combination including a 46
must also have four 1s, so the digit 1 has to be at least 4 times as likely
to appear as the digit 46, and probably a lot more likely than that.

Yes, I see you're right. Thanks.

On the other hand, making sure that each combination occurs equally often
(as your example might imply) is doable but still leaves the question
whether the order of the numbers matters: are [1,46,1,1,1] and [1,1,46,1,1]
the same or different combinations?

If the added constraint is instead that the probability of generating 
a given list of length N be the same as that of generating any other 
list of length N, then I believe my function does the job. Of course, 
[1,46,1,1,1] and [1,1,46,1,1], as Python lists, are distinct. I ran 
this test for M == 8 and N == 4:
==
def sumRndInt(M, N):
 import random
 while True:
 lst = []
 for x in range(N):
 n = random.randint(1,M-N+1)
 lst.append(n)
 if sum(lst) == M:
 return lst

A = []
B = []
for x in range(10):
 lst = sumRndInt(8,4)
 if lst not in A:
 A.append(lst)
 B.append(1)
 else:
 i = A.index(lst)
 B[i] += 1

A.sort()
print A
print B
print len(A), len(B)
===
a typical run produced:
[[1, 1, 1, 5], [1, 1, 2, 4], [1, 1, 3, 3], [1, 1, 4, 2], [1, 1, 5, 
1], [1, 2, 1, 4], [1, 2, 2, 3], [1, 2, 3, 2], [1, 2, 4, 1], [1, 3, 1, 
3], [1, 3, 2, 2], [1, 3, 3, 1], [1, 4, 1, 2], [1, 4, 2, 1], [1, 5, 1, 
1], [2, 1, 1, 4], [2, 1, 2, 3], [2, 1, 3, 2], [2, 1, 4, 1], [2, 2, 1, 
3], [2, 2, 2, 2], [2, 2, 3, 1], [2, 3, 1, 2], [2, 3, 2, 1], [2, 4, 1, 
1], [3, 1, 1, 3], [3, 1, 2, 2], [3, 1, 3, 1], [3, 2, 1, 2], [3, 2, 2, 
1], [3, 3, 1, 1], [4, 1, 1, 2], [4, 1, 2, 1], [4, 2, 1, 1], [5, 1, 1, 1]]

[2929, 2847, 2806, 2873, 2887, 2856, 2854, 2825, 2847, 2926, 2927, 
2816, 2816, 2861, 2919, 2820, 2890, 2848, 2898, 2883, 2820, 2820, 
2829, 2883, 2873, 2874, 2891, 2884, 2837, 2853, 2759, 2761, 2766, 2947, 2875]

35 35

Dick Moores




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-13 Thread Dick Moores
At 06:59 AM 3/13/2007, Anton Vredegoor wrote:
Dick Moores wrote:

  If the added constraint is instead that the probability of generating
  a given list of length N be the same as that of generating any other
  list of length N, then I believe my function does the job. Of course,
  [1,46,1,1,1] and [1,1,46,1,1], as Python lists, are distinct. I ran
  this test for M == 8 and N == 4:

Yes, I believe your function is OK. But the 'fencepost' method posted
earlier in this thread also does this and it's faster AND it's only two
line of code ...

Yes, I tested that after posting mine. Paul Rubin's fencepost method 
is about 14 times faster than mine for the same M == 8 and N == 4!  :(

  A = []
  B = []
  for x in range(10):
   lst = sumRndInt(8,4)
   if lst not in A:
   A.append(lst)
   B.append(1)
   else:
   i = A.index(lst)
   B[i] += 1
 
  A.sort()

Doesn't sorting break the correspondence between A and B?

Yes, but I thought that it would be easier to see that all the 
permutations are represented. It seemed clear enough that with larger 
num, all counts would approach num/35..

  Also, a more
pythonic way to count would be to convert the lst into a tuple and then
do something with a dictionary. Dictionaries have faster lookup. For
example:

T = tuple(lst)
D[T] = D.get(T,0) + 1

in the loop in order to count the occurrences.

Sorry, I don't understand this. Could you spell it out for me by 
rewriting my above test to use it? Thanks!

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-13 Thread Dick Moores
At 05:47 PM 3/10/2007, Paul Rubin wrote:

The fencepost method still seems to be simplest:

 t = sorted(random.sample(xrange(1,50), 4))
 print [(j-i) for i,j in zip([0]+t, t+[50])]

=
M = 50
N = 4
def sumRndIntRubin(M, N):
 import random
 t = sorted(random.sample(xrange(1,M), N-1))
 lst = [(j-i) for i,j in zip([0]+t, t+[M])]

 print t
 print t + [M]
 print [0] + t
 print lst
 print sum(lst)

sumRndIntRubin(M, N)

[6, 20, 31]
[6, 20, 31, 50]
[0, 6, 20, 31]
[6, 14, 11, 19]
50

I understand what zip() and random.sample() are doing, and the above 
helps me get inside the fencepost method, but I don't understand WHY 
it works, or how in the world anyone could have devised it. It is 
truly magical to me!

BTW I did see this in this thread, Suppose you have a fixed 
telegraph pole at N and a fixed telegraph pole at M, and you're given 
5 more telegraph poles... (Gerard Flanagan), but even now I can't 
take it anywhere. I guess I'm just a dim bulb. (I thought I was a 
fairly smart guy until I took up Python.)

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-13 Thread Dick Moores
At 06:20 PM 3/13/2007, Paul Rubin wrote:
Dick Moores [EMAIL PROTECTED] writes:
  I understand what zip() and random.sample() are doing, and the above
  helps me get inside the fencepost method, but I don't understand WHY
  it works, or how in the world anyone could have devised it. It is
  truly magical to me!

It's Gerald Flanagan's telegraph pole method that you quoted (I
misremembered it as fencepost):

 Suppose you have a fixed telegraph pole at N and a fixed telegraph
 pole at M, and you're given 5 more telegraph poles... (Gerard Flanagan),

Consider this diagram for the numbers from 1 to 50:

   |--|

The vertical bar at the left represents 0 and the vertical bar
at the right represents 51.  The fifty dashes represent 1,2,3...50.
You can also view the fifty dashes as a line segment of length 50.

The fencepost method is to simply chop the line segment into smaller
pieces.  You do that by choosing some random points inside the segment:

  import random
  random.sample(xrange(1,50), 4)
 [49, 37, 22, 5]

so mark those points with plus signs (let's see if I got this right)
and label the points from left to right, calling them p0,p1,p2,p3:

 |++--+---+-|
  p0   p1 p2  p3

So the length of the leftmost small segment is p0-0, the length of the
second segment is p1-p0, the third is p2-p1, the fourth is p3-p2, and
the fifth is 50-p3.  So those lengths are the numbers you want.

The zip thing was just a way to avoid using messy subscripts to
compute the lengths.  Another way to do it is (untested):

t2 = [0] + t + [50]
lst = [(t2[i] - t2[i-1]) for i in xrange(1, len(t2))]

Works fine!

I'm not sure which is better from a Python stylistic perspective.

I'm not sure, but I think if you had written it this way at first, I 
would have understood it.  But I'm glad to have learned the zip way!

Using zip that way is fairly natural in Haskell, which I've been
fooling around with lately.  All you're doing is subtracting adjacent
elements by making two versions of the list, one of them shifted over
one place, then subtracting element by element, instead of jumping
around inside a single list, with more ways to make off-by-one errors.
It looked more symmetrical in the Python code so I did it that way.

Thank you, thank you! You've made it very clear up to this point. 
I'll worry about the Haskell approach later, much later. ;)

Dick Moores

FWIW, the actual Haskell approach would translate to something more like:

from itertools import chain, izip
lst = [(j-i) for i,j in izip(chain([0],t), chain(t,[50]))]

which avoids making the intermediate zipped list.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-10 Thread Dick Moores
At 07:17 AM 3/9/2007, cesco wrote:
On Mar 9, 3:51 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
  cesco [EMAIL PROTECTED] writes:
   I have to generate a list of N random numbers (integer) whose sum is
   equal to M. If, for example, I have to generate 5 random numbers whose
   sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
   simple pattern or function in Python to accomplish that?
 
  Erm, yes, lots of ways, there are probably further constraints on the
  problem, such as the size of the integers, how the lists are supposed
  to be distributed, etc.  Can you be more specific?  Is this for an
  application?  If it's a homework problem, that's fine, but it's better
  in that case for respondents to suggest hints rather than full solutions.

Given two positive integers, N and M with N  M, I have to generate N
positive integers such that sum(N)=M. No more constraints.

So why not just repeatedly call a function to generate lists of 
length N of random integers within the appropriate range (the closed 
interval [1,M-N-1]), and return the first list the sum of which is M? 
I don't understand what all the discussion is about. Time is not one 
of the constraints.

Dick Moores 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: favourite editor

2007-02-12 Thread Dick Moores
At 08:41 PM 2/10/2007, azrael wrote:
Since i'm new on this forum, and first time meeting a python comunity,
i wanted to ask you for your python editors.

Im looking for some good python editor, with integrated run function,
without having to set it up manualy like komodo.
I found the pyscripter, and it has all i need, but it's unsatble.
bloated. it crashes when i close an yplication window run by python
from pyscripter. please. tell me a good one with buil in run (-very
important) and nice gui. if possible to suport projects, code
highlighting, code completition, class browser, python comand line
(), traceback.

UliPad. http://wiki.woodpecker.org.cn/moin/UliPad

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode is confusing me

2007-02-10 Thread Dick Moores
As per p. 188 of Python for Dummies, I've created a sitecustomize.py
in  my site-packages directory:


# sitecustomize.py  (see p.188 of Python for Dummies)
import sys
sys.setdefaultencoding('utf-8')
===

With that in place, at the interactive prompt this goes well:
===
 import sys
 sys.getdefaultencoding()
'utf-8'
 a = [u'\u91cd', u'\u8981', u'\u6027']
for x in range(3):
. . .   print a[x],
. . .
重 要 性

===
The 3 CJK characters are printed very nicely.

However, when I put the last 3 lines of that code in a script,


a = [u'\u91cd', u'\u8981', u'\u6027']
for x in range(3):
print a[x]
===

and redirect the output to a text file, I get
Traceback (most recent call last):
  File E:\Python25\dev\Untitled1.py, line 3, in ?
print a[x]
UnicodeEncodeError: 'ascii' codec can't encode character u'\u91cd' in
position 0: ordinal not in range(128)

I thought maybe it would help if I made the first line,
# -*- coding: utf-8 -*-

but that made no difference. Got the same error.

Can someone help me understand what's going on?

Thanks,

Dick Moores
-- 
my configuration:
Win XP Pro SP2
Python 2.5
wxPython 2.8.1.1 Unicode
Python IDE: Ulipad 3.6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode is confusing me

2007-02-10 Thread Dick Moores
I'm the OP, and answering my own question. I received excellent advice
from the developer of Ulipad, Limodou.

On 2/10/07, Dick Moores [EMAIL PROTECTED] wrote:

 
 a = [u'\u91cd', u'\u8981', u'\u6027']
 for x in range(3):
 print a[x]
 ===

The script should be
===
# -*- coding: utf-8 -*-
a = [u'\u91cd', u'\u8981', u'\u6027']
for x in range(3):
   print a[x].encode('utf-8'),

When output is redirected to a text file, this give a very pretty
重 要 性

Also, it turns out that I didn't need that sitecustomize.py .

-- 
my configuration:
Win XP Pro SP2
Python 2.5
wxPython 2.8.1.1 Unicode
Python IDE: Ulipad 3.6
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.5 Quick Reference

2007-02-03 Thread Dick Moores
http://rgruet.free.fr/PQR25/PQR2.5.html
Is this reliable? (Looks good to me, but...)

Thanks,

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5 Quick Reference

2007-02-03 Thread Dick Moores
At 04:02 AM 2/3/2007, Robin Becker wrote:
Dick Moores wrote:
  http://rgruet.free.fr/PQR25/PQR2.5.html
  Is this reliable? (Looks good to me, but...)
 
.

I really like these for a good overview

So it looks accurate?

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Definitions of editor and IDE?

2007-02-03 Thread Dick Moores


Are there generally accepted definitions of editor and
IDE. Is there a clear-cut distinction between them? I've been
looking at the lists of each at python.org,

http://wiki.python.org/moin/PythonEditors and

http://wiki.python.org/moin/IntegratedDevelopmentEnvironments.
Many programs are on both lists: Komodo, Eclipse, jedit, SPE, Wing IDE,
UliPad, etc.
Dick Moores



-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What happened to SPE?

2007-01-11 Thread Dick Moores
At 07:43 AM 1/11/2007, Paulo Pinto wrote:
does anyone know what happened to SPE?

It seems that the address http://pythonide.stani.be
is no longer valid. :(

I'd suggest subscribing to the Python-spe-users list, 
https://lists.berlios.de/mailman/listinfo/python-spe-users, or 
reading the archive there.

Dick Moores



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for the Perfect Editor

2006-09-14 Thread Dick Moores
At 08:54 PM 9/13/2006, Jay wrote:
I, too, am a hardcore fan of jEdit.  It's nice to finally see some user
support on this forum.  :-)

I'm trying out jEdit and UliPad. I got UliPad going right away and 
I'm very pleased with it, but could I jump in here with a basic jEdit 
question? How do you run a script?

And one more. On the menus, the font is clear and large, but the 
equivalent key combinations are written so small they are very 
difficult for me to read. Is there a way to configure them to be 
slightly larger? (I'd ask on the jEdit support forum, but it doesn't 
seem to be very active.)

Thanks,

Dick Moores




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for the Perfect Editor

2006-09-14 Thread Dick Moores
At 08:51 AM 9/14/2006, stu wrote:

Dick Moores wrote:
  I'm trying out jEdit and UliPad. I got UliPad going right away and
  I'm very pleased with it, but could I jump in here with a basic jEdit
  question? How do you run a script?
 
  And one more. On the menus, the font is clear and large, but the
  equivalent key combinations are written so small they are very
  difficult for me to read. Is there a way to configure them to be
  slightly larger? (I'd ask on the jEdit support forum, but it doesn't
  seem to be very active.)
 

to change jedits fonts, under utilities menu choose global options

select appearance, this has font options for menus + other fields
text area has the editing text font (I use dialogeinput for menus and
such and
andale mono for the text area...)

I afraid I still don't see how to use larger fonts for the problem I 
mentioned. I mean the tiny fonts used, for example, to the right of 
File | New, where it says, I'm guessing, C+n.

to run a script.. you can 'dock' jython in the sides of the editor or
bottom, and import from the buffer or load it.. or fire jython up from
the plugin menu

Doesn't sound easy. With UliPad (or IDLE, for that matter) just hit F5.

there is also a colour scheme plugin that gives you colour defaults if
you want it to look lke emacs or jbuilder or idea etc etc etc

jedit is pretty rich with its plugins.

Thanks,

Dick



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for the Perfect Editor

2006-09-10 Thread Dick Moores
At 02:15 PM 9/10/2006, Kent Johnson wrote:
Dick Moores wrote:
  At 01:10 PM 9/8/2006, Doug Stell wrote:
  Try www.TextPad.com. I've used it for years and love it. It
  understands many programming language constructs and can be taught to
  understand python so that things show up in color.
 
  Any tips on how to teach TextPad to understand python?
Download and install the Python syntax highlighting definition from the
TextPad website.

Thanks very much, Kent. I've been using TextPad for 10 years and 
never considered using it for Python.

I downloaded Python (7) from 
http://www.textpad.com/add-ons/synn2t.html and put the file 
PythonV2.4.syn in C:\Program Files\TextPad 4\system .

I make a tool to run the front window in Python. Here are the values
from the preferences window for the tool:

Command: C:\Python24\python.exe
Parameters: -u $File
Init fldr: $FileDir

regex to match output:
^.*([^]+), *line ([0-9]+)

with File: 1, Line: 2

After fumbling around, I believe I've made the tool, using your 
values, except I used E:\Python24\python.exe instead of 
C:\Python24\python.exe .

I also associated .py with TextPad. I'm now able to open a Python 
script with TextPad, and execute it with  Ctrl+4.

However, no syntax highlighting is showing up. so I must have done 
something wrong. Do I have to do something other than put 
PythonV2.4.syn in C:\Program Files\TextPad 4\system ?

Also, why do you use TextPad instead of IDLE?

Thanks,

Dick Moores


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for the Perfect Editor

2006-09-10 Thread Dick Moores
At 06:30 PM 9/10/2006, Kent Johnson wrote:
Dick Moores wrote:

  I downloaded Python (7) from
  http://www.textpad.com/add-ons/synn2t.html and put the file
  PythonV2.4.syn in C:\Program Files\TextPad 4\system .
 
  However, no syntax highlighting is showing up. so I must have done
  something wrong. Do I have to do something other than put
  PythonV2.4.syn in C:\Program Files\TextPad 4\system ?

One more step - make a new Document Class for Python (in the prefs).
Associate it with *.py, turn on syntax highlighting and select the
syntax file you downloaded.

OK. Done.

  Also, why do you use TextPad instead of IDLE?

You're kidding, right?

No. Tell me, please. Macros? Comparing files? What else?

Dick



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for the Perfect Editor

2006-09-09 Thread Dick Moores
At 01:10 PM 9/8/2006, Doug Stell wrote:
Try www.TextPad.com. I've used it for years and love it. It
understands many programming language constructs and can be taught to
understand python so that things show up in color.

Any tips on how to teach TextPad to understand python?

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Need Python for Linux (Suse 10.1)

2006-08-31 Thread Dick Moores


I've got a friend interested in trying out Python. I sent him to

http://www.python.org/download/linux/ but he's uncertain as to what
to download. He's rather get a new download than use what was on his Suse
disk. His box is an x86.
Any chance
Python
2.4.3 compressed source tarball would be suitable for him?
Advice for him, please.
Thanks,
Dick Moores




-- 
http://mail.python.org/mailman/listinfo/python-list

Programming Python, 3rd ed.??

2006-01-02 Thread Dick Moores
Several months ago I saw an item on the O'Reilly site to the effect that 
the 3rd. ed. of Programming Python was in the works. I made a note to 
myself to check back in January. I just did, but could find nothing at 
all about a 3rd. edition. Anyone know?

Thanks,

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Python and Tkinter Programming

2005-10-08 Thread Dick Moores
DaveInSidney wrote at 15:55 10/8/2005:
Check out BestBookBuys:
http://www.bestwebbuys.com/Python_and_Tkinter_Programming-ISBN_1884777813.html?isrc=b-search

Or even better, BestBookDeal.com:
http://www.bestbookdeal.com/book/compare/1884777813

Dick Moores

-- 
http://mail.python.org/mailman/listinfo/python-list


[Tutor] New Python book

2005-10-05 Thread Dick Moores
Magnus Lie Hetland's new book, _Beginning Python: From Novice to
Professional_ was published by Apress on Sept. 26 (in the U.S.). My copy 
arrived in the mail a couple of days ago. Very much worth a look, IMHO. 
But what do the experts here think?

http://www.bestbookdeal.com/book/compare/159059519X

Dick Moores
[EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


New Python book

2005-10-05 Thread Dick Moores
(Sorry, my previous post should not have had Tutor in the subject header.)

Magnus Lie Hetland's new book, _Beginning Python: From Novice to
Professional_ was published by Apress on Sept. 26 (in the U.S.). My copy
arrived in the mail a couple of days ago. Very much worth a look, IMHO.
But what do the experts here think?

http://www.bestbookdeal.com/book/compare/159059519X

Dick Moores
[EMAIL PROTECTED]


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compute pi to base 12 using Python?

2005-04-17 Thread Dick Moores
Tim Roberts wrote at 22:05 4/16/2005:
Dick Moores [EMAIL PROTECTED] wrote:

# Reading/writing Python source often gives me the impression of
# reading/writing a poem!
# Layout, indentation, rythm, I like the look and feel!

# What does this tiny program do? It is not a sonnet, even not a
# pi-sonnet, but it surely produces Pi!

It sure does. When I ran it my jaw dropped. I had 7,947 CORRECT digits in
2 minutes 0 seconds (by my stopwatch)!
How do you know?  I think the 7,912th digit is wrong.
;)
I suppose you're joshing, Tim, but I really did check by using my trusty

def compareSequences(seq1, seq2):

find first index at which two sequences differ

if s1 == s2:
print Sequences are identical
return None
if len(seq1) = len(seq2):
shorterOrEqualSequence = seq2
else:
shorterOrEqualSequence = seq1
for index in range(len(shorterOrEqualSequence)):
if seq1[index] != seq2[index]:
print sequences first differ at index, index
print s1 at that index is, s1[index]
print s2 at that index is, s2[index]
break
if index == len(shorterOrEqualSequence)-1:
print sequences are identical thru end of shorter sequence at 
index, index
==

I got the correct pi from 
http://www.ballandclaw.com/upi/pi.5.html. By inspection of the text 
file I copied this to (removing the 3. of 3.1), the 7,912th digit is 
2 (I'm using Textpad). If you begin with 31, which what the speedy 
script does, the 7,912th digit is 6.

Now, I've shown you mine. Show me yours. ;-)
Dick 

--
http://mail.python.org/mailman/listinfo/python-list


Re: Compute pi to base 12 using Python?

2005-04-17 Thread Dick Moores
M.E.Farmer wrote at 23:18 4/14/2005:
 Using the GNU bc utility:
 
$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation,
Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale = 3000# number of output places wanted
obase = 12  # output base
print 4 * a(1)  # pi = 4*arctan(1)
Wow! this got me the 3003 (changed from 3000) digits of pi to base 12 in 
60.8 secs. No, I didn't count them yet, nor am I sure they're correct. 
But I'd bet on them..

Could someone remind me how to get the output of bc -l into a text file 
on Windows? (I've tried employing   pi3003.txt in various ways) OR, 
how to copy and paste from the command line window, or whatever that 
window is called? (Sorry for the OT question.)

BTW I found a nice set of SCO UNIX man pages at http://www.rt.com/man/.
Dick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compute pi to base 12 using Python?

2005-04-17 Thread Dick Moores
Roel Schroeven wrote at 01:45 4/17/2005:
Dick Moores wrote:
M.E.Farmer wrote at 23:18 4/14/2005:
 Using the GNU bc utility:
 
$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation,
Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale = 3000# number of output places wanted
obase = 12  # output base
print 4 * a(1)  # pi = 4*arctan(1)
Wow! this got me the 3003 (changed from 3000) digits of pi to base 12 
in 60.8 secs. No, I didn't count them yet, nor am I sure they're 
correct. But I'd bet on them..
Could someone remind me how to get the output of bc -l into a text file 
on Windows? (I've tried employing   pi3003.txt in various ways) OR, 
how to copy and paste from the command line window, or whatever that 
window is called? (Sorry for the OT question.)
Works for me (using the Cygwin version though) when I do
C:\cygwin\bin\bc -l  pi12.txt
But how or when do you enter the lines
scale = 3000
obase = 12
print 4 * a(1)
Otherwise, to copy from the command prompt window: open the system menu
(icon in the top left corner of the window) and choose Edit-Mark. Then
select what you want to copy and press Enter or choose Edit-Copy in the
system menu.
Thanks! You've just relieved years of frustration.
Dick 

--
http://mail.python.org/mailman/listinfo/python-list


Re: Compute pi to base 12 using Python?

2005-04-17 Thread Dick Moores
Bengt Richter wrote at 02:26 4/17/2005:
Could someone remind me how to get the output of bc -l into a text file
on Windows? (I've tried employing   pi3003.txt in various ways) OR,
how to copy and paste from the command line window, or whatever that
window is called? (Sorry for the OT question.)
To copy from the command window to the clipboard:
1. Scroll top of desired stuff to make it visible near top
2. Hold down Alt
3. Tap Space Bar
4. Release Alt
5. Tap e
6. Tap k
7. Use mouse or arrow keys to place cursor on top left corner of desired box
8. Hold down Shift
9. Use arrow keys or mouse-with-left-button-pressed to go to bottom 
right character of desired box
9a. If the bottom is out of sight, keep holding  shift down and pretend 
you can cursor down below bottom.
the attempt should make the screen scroll up and select more 
desired material. If you overshoot, don't panic,
just keep holding down shift and use arrows (the are slower) or 
mouse-with-left-button-still-down to move to
desired bottom right corner.
10. Release mouse button if using that
11. Release Shift
12. Press Enter
That should copy to the clipboard and make the selection box revert to 
normal display.

Pasting from clipboard is up to you. Pasting into the command window 
from clipboard
is 2-5 above, and Tap p
Thanks for showing me another way. But Roel Schroeven's
to copy from the command prompt window: open the system menu
(icon in the top left corner of the window) and choose Edit-Mark. Then
select what you want to copy and press Enter or choose Edit-Copy in the
system menu.
seems to be easier.

PS. Redirecting with  from a script whose interpreter was started by 
windows extension association
doesn't work on some version of windows. To be safe, invoke the 
interpreter explicitly, e.g.,
python myscript.py [whatever args here]  pi3003.txt
Thanks very much for this.
What kind of args could I use here?
Dick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compute pi to base 12 using Python?

2005-04-17 Thread Dick Moores
Paul Rubin wrote at 02:35 4/17/2005:
Dick Moores [EMAIL PROTECTED] writes:
 C:\cygwin\bin\bc -l  pi12.txt

 But how or when do you enter the lines

 scale = 3000
 obase = 12
 print 4 * a(1)
You could put them into a file, say pi.bc.  Then run
  bc -l pi.bc
OK, now that I've got Textpad trained to open .bc files, I'm thinking of 
things to store in them. I'm sure I'll want to put in some remarks as 
well. What should I use to mark the remarks. #, //, or what?

The bc man page at http://www.rt.com/man/bc.1.html is tough. Any 
suggestion for more easily understandable help?

And finally (maybe), is it possible to employ bc within a Python script?
Thanks,
Dick

--
http://mail.python.org/mailman/listinfo/python-list


Re: Compute pi to base 12 using Python?

2005-04-15 Thread Dick Moores
M.E.Farmer wrote at 23:18 4/14/2005:
Nice collection of unix tools, Cygwin not needed.
http://unxutils.sourceforge.net/
Thank you!
But a question. I've download both UnxUtils.zip and UnxUpdates.zip. I'm 
planning to put the contents of UnxUtils.zip in a directory and then move 
the contents of UnxUpdates.zip, which has many of the same filenames, to 
the same directory. Should I just let Windows replace the old files with 
the updated ones?

This seems obvious, but I wanted to make sure.
I'm using Win XP Pro.
Thanks,
Dick Moores

--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >