Re: Python 2.1 - 2.4 differences

2005-01-30 Thread RPM1

"BOOGIEMAN" <[EMAIL PROTECTED]> wrote ...
> I found some e-book about Python 2.1, I want to print it but just to check
> first if sintax of Python 2.1 is same as 2.4 ? Also does anybody know
where
> can I download any newer Python related e-book, because there isn't any
> published yet in my country.

Take a look at:
http://diveintopython.org



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


Re: Python is slow

2008-05-22 Thread RPM1

Larry Bates wrote:
If your Python program is 
slow, you have almost assuredly approached it with a wrong method or 
algorithm.


I agree for most applications.  There are however times where Python 
just isn't fast enough, and that's usually when people write extension 
modules.


I have yet to see a chess engine written in Python that is competitive 
with even a below average C or C++ chess engine.  The same could be said 
of Java, VB, C#, Pearl, ...


So there ARE some tasks that Python just isn't suited for due to 
performance, but not enough for it to steer anyone away from Python.


I have been working on a chess engine and have found that I prototype in 
Python and then port to the D programming language, (which IS fast). 
For example, one of my routines, (generating pseudo-legal moves -- no 
evaluation), in Python runs at 700,000 moves per second, (using Psyco). 
 Ported to D it runs at 22 million moves per second.


Python's advantage is in the software development and maintenance 
phases.  As long as the runtime phase is fast ENOUGH, Python kicks most 
other languages butts.


Patrick


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


Re: Relationship between GUI and logic?

2008-05-22 Thread RPM1

John Salerno wrote:


Basically, the question is this: can you write the logic behind a 
program (whether it be a game, an email client, a text editor, etc.) 
without having any idea of how you will implement the GUI?


Chess already has at least two solutions that are in widespread use:

Winboard
UCI (Universal Chess Interface)

Basically you write your chess "engine" to speak either Winboard or UCI 
and then you can "run" it in one of the various GUI interfaces, (such as 
Shredder, Fritz, Arena, ...).


See:
http://www.playwitharena.com/

or the comparatively young:
http://pychess.googlepages.com/(which is written in Python)


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


Re: Wrapping C with Python

2008-08-04 Thread RPM1

Anish Chapagain wrote:

Hi!!
I tried wrapping a simple C code suing SWIG to Python, but am having
problem,


I am not too familiar with SWIG, (I have looked at it), but you may want 
to try ctypes in the standard module library.  It's very easy to use.  I 
use it on Windows with gcc but I believe it works fine on Linux too. 
Basically you just compile your C code as a regular C code dll.  ctypes 
then allows you to access the functions in the dll very easily.  I was 
concerned that performance might be an issue but that has turned out not 
to be true.  I'm writing a chess program and the C dll handles the move 
generation so it is getting called a lot. So far it runs at about 
200,000 calls per second.


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


Re: Wrapping C with Python

2008-08-04 Thread RPM1

brad wrote:

RPM1 wrote:
...
Basically you just compile your C code as a regular C code dll.  
ctypes then allows you to access the functions in the dll very easily. 


Does that work with C++ code too or just C?


I believe it does work with C++ although I have not done that.  Here's a 
simple example:


http://wolfprojects.altervista.org/dllforpyinc.php

I bet if you google around you'll find what you need.

Remember there is documentation for ctypes in the Python documentation 
that comes with Python.


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


Re: Wrapping C with Python

2008-08-04 Thread RPM1

Anish Chapagain wrote:

On 4 Aug, 14:14, brad <[EMAIL PROTECTED]> wrote:

RPM1 wrote:

...


Basically you just compile your C code as a regular C code dll.  ctypes
then allows you to access the functions in the dll very easily.

Does that work with C++ code too or just C?


Hi..
I havenot tried..before with dll, is there any help material and for
me my API in C has almost 20 c files, so will it be feasible

anish


It is worth looking into it.  I found ctypes to be very easy.  I had the 
example up and running in minutes.  I have also figured out how to do 
things like return arrays to Python.  It isn't that hard.  I like the 
fact that I don't have to think about reference counting or PyObjects 
etc.  If you are doing simple function calls ctypes is very easy.


My C code looks like C code.  It has no Python stuff at all.  My Python 
code has just a few calls to the ctypes module.  I guess that's one 
thing I like about it is that my C code looks like C code and my Python 
code looks like Python code, (not much spilling over).


I'm sure it's not perfect, but it seems a lot easier than SWIG to me.

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


Re: Is there a faster way to do this?

2008-08-05 Thread RPM1

[EMAIL PROTECTED] wrote:

I have a csv file containing product information that is 700+ MB in
size. I'm trying to go through and pull out unique product ID's only
as there are a lot of multiples. My problem is that I am appending the
ProductID to an array and then searching through that array each time
to see if I've seen the product ID before. So each search takes longer
and longer. I let the script run for 2 hours before killing it and had
only run through less than 1/10 if the file.



I think you need to learn about Python's dictionary data type.
--
http://mail.python.org/mailman/listinfo/python-list