Re: pygame.Rect question

2012-04-09 Thread Pekka Karjalainen
On Mon, Apr 9, 2012 at 3:29 AM, Dave Angel  wrote:
> I don't know about pygame, but almost everywhere in the standard
> library, ranges are closed at the begin and open at the end.  For
> example, if you have range(30, 50), there are 20 items, numbered 30
> through 49.  I expect the same will be true for rect.right() and
> rect.bottom().

Your expectation is correct. I'll just point out the part in the
Pygame docs that spells this out.

http://www.pygame.org/docs/ref/rect.html

"The area covered by a Rect does not include the right- and
bottom-most edge of pixels. If one Rect's bottom border is another
Rect's top border (i.e., rect1.bottom=rect2.top), the two meet exactly
on the screen but do not overlap, and rect1.colliderect(rect2) returns
false."

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


Re: New Python chess module

2005-09-30 Thread Pekka Karjalainen
> Its still rough around the edges and not fully tested. I'll eventualy 
> release a more polished version and possibly put it on Sourceforge. In 
> the meantime I would be grateful for any feedback..

Somebody ought to comment this in more detail...

I have one minor point. It looks like your test whether the location is on
the board is needlessly complex. Python understands multiple comparisons
like in mathematical notation, and not like in e.g. C language. This
snippet shows what I mean:

>>> [x for x in range(10) if 2http://www.python.org/doc/2.4.2/ref/comparisons.html

-- 
Pekka Henrik Karjalainen
who still occasionally writes if (test): because of all the C
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Not defined

2005-10-01 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>, Rob wrote:
>Forgive me please if this is not the proper place for this ?  I am trying to 
>keep an active brain :)

Seems proper to me :)

You can see what you've just imported by using the built-in
dir() function. Here's an example from my PyWin window:

>>> dir()
['__builtins__', '__doc__', '__name__', 'pywin']
>>> from math import *
>>> dir ()
['__builtins__', '__doc__', '__name__', 'acos', 'asin', 'atan', 'atan2',
'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod',
'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'pywin',
'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']
>>> 

Note that the first time I use dir() it lists just four items. After from
math import * it lists all the stuff I got from the math module in
addition.

How does your dir() look after the import statement?

-- 
Pekka Henrik Karjalainen

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


Re: Not defined

2005-10-01 Thread Pekka Karjalainen
I looked around a bit and found the answer. At least the change I
recommend below worked for me.

In article <[EMAIL PROTECTED]>, Rob wrote:
>When trying the basic tutorial for cgkit I always seem to get a not defined 
>error as follows.
>
>Pythonwin GUI
>
 from cgkit import *

This is "from cgkit.all import *" in the tutorial here:

http://cgkit.sourceforge.net/doc2/node6.html

It seems the tutorial you are using is out of date vis-a-vis the version
of cgkit you use.

-- 
Pekka Henrik Karjalainen

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


Re: Favorite non-python language trick?

2005-07-01 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>, Joseph Garvin wrote:
>I'm curious -- what is everyone's favorite trick from a non-python 
>language? And -- why isn't it in Python?
>

  Being able to use my native language without a hitch when naming my
variables &c. Java allows that because it supports almost any Unicode
character in its identifiers. With Python I occasionally have to stop and
think: "I can't name it that. What's better?"

  Not everyone always writes their programs in English. Once you get used
to Java's naming possibilities, it's plain annoying to go back, even if
it's just a couple of letters that're lacking in my case.

-- 
Pekka Karjalainen - Oulu, Finland

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


Graphics files & Python

2005-07-28 Thread Pekka Karjalainen
  How can I create image files and animations with Python?

  I will clarify a bit. This is a question of recreational programming. I 
have already made some animated gifs from Julia sets using Python and some 
external programs. I hit upon a quick solution of writing ppm image files 
(it's a simple text based format) and using ppmtogif to make gifs out of 
them, then using gifsicle (free program found on the web) to join them 
into animated gif files.

  You can see some of my results in: 

  <http://www.student.oulu.fi/~pkarjala/animaatiot.html>

  That's a small file that links to large (0.8 meg or so) files. They are 
a bit bland at the moment, but I might get around to improving the things 
later :-)

  This seems to work well enough for the modest goals that I have -- I 
just want to make a few beautiful fractal images and animations, and learn 
a bit more about Python while tinkering along.

  However, I might as well ask. Are there other good options for creating
images and animations using Python? As it is, I build my data into an
array representing the bitmap and the value of each pixel, and then write
it into a temp file in ppm format. It's a little slow, but it still runs
fast enough for me at the moment. I have no intention of writing a major
new fractal exploring software after all, so I'm not worried about
execution time, I'm worried about my own programmer's time (which I want
to save for other things).

  Any suggestions?

-- 
Pekka Karjalainen - Oulu, Finland
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graphics files & Python

2005-07-30 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>, Terry Reedy wrote:
>Besides the other responses, you might also check out the pygame site where 
>there once were some tutorial examples of manipulating bitmaps with 
>Numerical Python to get various effects.
>
  I'll keep this in mind too. Thanks to both for helpful replies.

-- 
Pekka Karjalainen - Oulu, Finland

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


Tail recursion Re: list of polynomial functions

2006-06-20 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>, 
Matteo wrote:
>This last approach could, at least theoretically, create an arbitrarily
>long list of polys, without overflowing any kind of stack. In practice,
>python does not seem to perform tail recursion optimizations, and conks
>out after makepolys(997) on my machine.
>

You can find out the conking-out limit and change it, within reason.

>>> import sys
>>> help (sys.getrecursionlimit)
[...]
>>> help (sys.setrecursionlimit)
[...]

Here is a recipe for tail recursion optimization at ASPN:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691

Python doesn't do any kind of tail recursion optimization by default
because Guido has decided it shouldn't (at least so far). I'm sure it has
been discussed in detail in Python development forums & lists, but I
don't know those details.

This Google search is a start, but it gives too many hits for me to shift
through now:

http://www.google.fi/search?q=site%3Apython.org+tail+recursion

Pka


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


help() on stdout.closed

2006-06-21 Thread Pekka Karjalainen
Python 2.4.1 (#1, May 16 2005, 15:19:29)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sys import stdout
>>> help (stdout.closed) 

If I do this, it gives me help on the bool object. Also:

>>> stdout.closed.__doc__
'bool(x) -> bool\n\nReturns True when the argument x is true, False 
otherwise.\nThe builtins True and False are the only two instances of the 
class bool.\nThe class bool is a subclass of the class int, and cannot be 
subclassed.'

What's going on here? Other docstrings in sys.stdout work fine.

Pekka (uses 2.4.3 on another comp)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help() on stdout.closed

2006-06-21 Thread Pekka Karjalainen
On 2006-06-21, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> have you tried things like
[...]

I have now. I'm not sure what the results are supposed to tell me, but I 
am not going to press the issue.

Suppose I had no idea what sys.stdout.closed was and wanted to find out. 
Where would I look it up?

Pekka


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


Re: Remarkable results with psyco and sieve of Eratosthenes

2006-11-30 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>,
Steve Bergman wrote:
>BTW, can this code be made any more efficient?

>def primes():
>primes=[3]
>for x in xrange(5,1000,2):
>maxfact = int(math.sqrt(x))
>flag=True
>for y in primes:
>if y > maxfact:
>break
[...]

You can omit the call to math.sqrt if you test this instead.

y*y > x

in place of if y > maxfact: .

Pka

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


Re: alternate language

2006-12-11 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>, Aahz wrote:
>In article <[EMAIL PROTECTED]>,
>Grant Edwards  <[EMAIL PROTECTED]> wrote:
>>On 2006-12-11, Aahz <[EMAIL PROTECTED]> wrote:
>>>
>>> Um...  I think the original poster is saying that he already knows Python
>>> and wants to learn another language.  He particularly wants opinions from
>>> other people who have learned these languages *after* learning Python.
>>
>>There are people who learn another language after learning Python??
>
>Heh.  Taking your post more seriously than it deserves, don't you think
>someone ought to learn at least SQL if they don't already know it when
>they learn Python?
>-- 
>Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/
>
>Member of the Groucho Marx Fan Club  

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


Re: alternate language

2006-12-11 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>, Pekka Karjalainen wrote:


Sorry, I messed up the attribution when editing and decided not to
post. Accidentally did post an empty message anyway.

I was going to recommend Haskell for the original poster too, and I wanted
to answer that I did indeed (start to) learn another language after
Python. Haskell is mind-expanding after all. I'm not sure which directions
mine has expanded, because I have so much difficulty with slrn today, but
never mind.

I won't repeat the Haskell recommendation I typed up and then deleted. If
you look at what people say about it you either want to try it or not.

Pka

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


Re: merits of Lisp vs Python

2006-12-12 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>, Paul Rubin wrote:
>Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:
>> So there seems to be something macro-like for Haskell.
>
>I think that's some kind of proposed or experimental Haskell feature,
>not in the current standard, but I'm not sure.  I'm barely even a
>newbie with Haskell.

It's called Template Haskell.

http://www.haskell.org/th/

"Template Haskell is an extension to Haskell 98 that allows you to do
type-safe compile-time meta-programming, with Haskell both as the
manipulating language and the language being manipulated."

There is an experimental implementation in new versions of GHC.

Follow-ups set to comp.lang.haskell in case anyone wants to discuss it. I
claim no understanding of it yet. Better figure out ordinary Haskell
first...

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


Wxpython demo crashes

2005-06-07 Thread Pekka Karjalainen
I'm using WinXP (Finnish), Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC
v.1310 32 bit (Intel)] on win32 and wxPython 2.6.0.1.

When I go to the Process and Events section in the wxDemo and run the
Process demo, bad things can happen. It crashes. I think the crash is
caused by characters outside the basic ASCII range, but I haven't tested
it in detail.

This is reproducible on my system:

Start Wxdemo. Go to Process and Events and choose Process item. 
Choose Demo tab, and click Execute so the child process starts.
Enter the single character <ä> into the text input and click send. 

Result: Up pops "The program has performed an illegal operation and will
be shut down". (Or however that goes in English.) And it is shut down.

The character in the angle brackets is a with an umlaut, which you can
get with the alt-code 132.

Does this happen to anyone else? Can I give more useful details?

I haven't run into other problems with wxpython. It's great in fact. I'm
finally seeing some point in learning GUI programming myself :-)

-- 
 Pekka Henrik Karjalainen -+- Oulu, Finland

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


Re: Wxpython demo crashes

2005-06-08 Thread Pekka Karjalainen
In article <[EMAIL PROTECTED]>,
Greg Krohn wrote:
> Do you have the unicode version of wxPython?
> 
> http://prdownloads.sourceforge.net/wxpython/wxPython2.6-win32-unicode-2.6.1.0-py24.exe

  I think I do, because it shows the Unicode demo correctly, and I recall 
that I specifically chose that from the download section. I'm not at the 
right computer ATM, however, so I will have to check this later to be 
sure.

-- 
 Pekka Henrik Karjalainen -+- Oulu, Finland
-- 
http://mail.python.org/mailman/listinfo/python-list