Partial 1.0 - Partial classes for Python

2007-02-07 Thread Martin v. Löwis
I'm happy to announce partial 1.0; a module to implement
partial classes in Python. It is available from

http://cheeseshop.python.org/pypi/partial/1.0

A partial class is a fragment of a class definition;
partial classes allow to spread the definition of
a class over several modules. One location serves
as the original definition of the class.

To extend a class original_module.FullClass with
an additional function, one writes

from partial import *
import original_module

class ExtendedClass(partial, original_module.FullClass):
 def additional_method(self, args):
 body
 more_methods

This module is licensed under the Academic Free License v3.0.

Please send comments and feedback to [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


[ANN] DirectPython 0.8

2007-02-07 Thread Heikki Salo
A new version of DirectPython is now available at 
http://directpython.sourceforge.net/

What is it?
---
DirectPython is a C++ extension to the Python programming
language which provides basic access to DirectX (9.0c) API,
including Direct3D, DirectSound, DirectShow and DirectInput.

The full distribution is very easy to install and it includes
many samples and documentation that show the basics of
DirectPython programming. No additional packages are needed.

Whats new in 0.8.0?
--

Too much to mention here. Check the release notes for more 
information. There are some changes which break backwards 
compatibility with 0.7.

Requirements
-
A Windows operating system (98 and up) with Python (2.4/2.5) 
and DirectX 9.0c installed.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Can Parallel Python run on a muti-CPU server ?

2007-02-07 Thread Nick Vatamaniuc
From the www.parallelpython.com , the 'Features' section:

Features:
 *Parallel execution of python code on SMP and clusters
---

PP uses processes, and thus it will take advantage of multiple cores
for a CPU bound task.

-Nick


On Feb 6, 9:13 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 Hi all,

 I'm interested in Parallel Python and I learned from the website of
 Parallel Python
 that it can run on SMP and clusters. But can it run on a our muti-CPU
 server ?
 We are running an origin3800 server with 128 CPUs.

 Thanks.


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


Re: sgmllib bug in Python 2.5, works in 2.4.

2007-02-07 Thread John Nagle
John Nagle wrote:
 (Was prevously posted as a followup to something else by accident.)
 
I'm running a website page through BeautifulSoup.  It parses OK
 with Python 2.4, but Python 2.5 fails with an exception:
 
 Traceback (most recent call last):
File ./sitetruth/InfoSitePage.py, line 268, in httpfetch
  self.pagetree = BeautifulSoup.BeautifulSoup(sitetext) # parse into 
 tree form
File ./sitetruth/BeautifulSoup.py, line 1326, in __init__
  BeautifulStoneSoup.__init__(self, *args, **kwargs)
File ./sitetruth/BeautifulSoup.py, line 973, in __init__
  self._feed()
File ./sitetruth/BeautifulSoup.py, line 998, in _feed
  SGMLParser.feed(self, markup or )
File /usr/lib/python2.5/sgmllib.py, line 99, in feed
  self.goahead(0)
File /usr/lib/python2.5/sgmllib.py, line 133, in goahead
  k = self.parse_starttag(i)
File /usr/lib/python2.5/sgmllib.py, line 291, in parse_starttag
  self.finish_starttag(tag, attrs)
File /usr/lib/python2.5/sgmllib.py, line 340, in finish_starttag
  self.handle_starttag(tag, method, attrs)
File /usr/lib/python2.5/sgmllib.py, line 376, in handle_starttag
  method(attrs)
File ./sitetruth/BeautifulSoup.py, line 1416, in start_meta
  self._feed(self.declaredHTMLEncoding)
File ./sitetruth/BeautifulSoup.py, line 998, in _feed
  SGMLParser.feed(self, markup or )
File /usr/lib/python2.5/sgmllib.py, line 99, in feed
  self.goahead(0)
File /usr/lib/python2.5/sgmllib.py, line 133, in goahead
  k = self.parse_starttag(i)
File /usr/lib/python2.5/sgmllib.py, line 285, in parse_starttag
  self._convert_ref, attrvalue)
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xa7 in position 0: 
 ordinal
 not in range(128)
 
  The code that's failing is in _convert_ref, which is new in 
 Python 2.5.
 That function wasn't present in 2.4.  I think the code is trying to
 handle single quotes inside of double quotes, or something like that.
 
  To replicate, run
 
 http://www.bankofamerica.com
 or
 http://www.gm.com
 
 through BeautifulSoup.
 
 Something about this code doesn't like big companies. Web sites of smaller
 companies are going through OK.
 
 Also reported as a bug:
 
 [ 1651995 ] sgmllib _convert_ref UnicodeDecodeError exception, new in 2.5

Found the problem and updated the bug report with a fix.  But someone
else will have to check it in.

There's a place in SGMLParser where someone assumed that values 0..255
were valid ASCII characters.  But in fact the allowed range is 0..127.
The effect is that Unicode strings containing values between 128 and 255
will blow up SGMLParser.

In fact, you can even make this happen with an ASCII
source file by using an HTML entity which has a Unicode representation
between 128 and 255, (such as sect;), then using something
Unicode-oriented like BeautifulSoup on it.

John Nagle


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


Re: How to prevent from race conditions to share data between many process and thread in python

2007-02-07 Thread Laurent Pointal
mars a écrit :
 I use TurboGears to do some web service. TurboGears use cherrypy. When
 web browser access this site, the cherrypy will call my python
 program. So my program looks like a lib. When web browser access the
 site, the http server will fock a process or gerenate a thread. I need
 share some data or operate some files. How can I prevent from race
 conditions. Is there any way can I lock this.
 Thank you in advance!

See in the cookbook:

http://aspn.activestate.com/ASPN/search?query=lockingx=0y=0section=PYTHONCKBKtype=Subsection

And test/choose one solution...
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252495
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203
...

A+

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


Getting a class name from within main

2007-02-07 Thread bg_ie
Hi,

Lets say I have the following class -

class MyClass:
def __init__(self):
print (__name__.split(.))[-1]

if __name__ == '__main__':
MyClassName = MyClass

I can print the name of the class from within the class scope as seen
above in the init, but is there any way of printing it from within the
main without creating an object of the MyClass type. I need to assign
the name of the class within my script, to a variable in main.

Thanks,

Barry.

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


Re: Python compiled on Windows

2007-02-07 Thread Duncan Booth
Franz Steinhaeusler [EMAIL PROTECTED] wrote:

Yes, people have compiled Python with gcc on windows. I believe it is
slightly slower than the standard release, but I would guess that may
depend on the exact versions of gcc/msc you choose to compare, and the
exact compiler options you choose (or I may even be imagining it
entirely).
 
 I cannot imagine, that there is a decisive difference, especially as
 in gcc, you have also a couple of options.
 
I did a quick comparison running pystone and taking the best of several 
runs:

On one system which had the Windows Python 2.4 distribution and also 
Python 2.4 installed under cygwin:

Windows Python 2.4: 46k
Cygwin Python 2.4: 41k

On another system which has a dual boot setup:

  Windows Python 2.5: 43.7k
Ubuntu Python 2.5: 42.0k

So in the first case there was about a 12% improvement and in the second 
case about 5% improvement using the Windows distribution.

I don't know whether the gap is closing from improvements in gcc or 
whether there is an OS related difference as well. Unfortunately cygwin 
doesn't appear to offer Python 2.5 yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a class name from within main

2007-02-07 Thread Robin Becker
[EMAIL PROTECTED] wrote:
 Hi,
 
 Lets say I have the following class -
 
 class MyClass:
   def __init__(self):
   print (__name__.split(.))[-1]
 
 if __name__ == '__main__':
   MyClassName = MyClass
 
 I can print the name of the class from within the class scope as seen
 above in the init, but is there any way of printing it from within the
 main without creating an object of the MyClass type. I need to assign
 the name of the class within my script, to a variable in main.
 
 Thanks,
 
 Barry.
 

  class A:
... pass
...
  print A.__name__
A
 
-- 
Robin Becker

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


Re: Getting a class name from within main

2007-02-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], bg_ie wrote:

 class MyClass:
   def __init__(self):
   print (__name__.split(.))[-1]
 
 if __name__ == '__main__':
   MyClassName = MyClass
 
 I can print the name of the class from within the class scope as seen
 above in the init, but is there any way of printing it from within the
 main without creating an object of the MyClass type. I need to assign
 the name of the class within my script, to a variable in main.

Yes::

print MyClass.__name__

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python compiled on Windows

2007-02-07 Thread Franz Steinhaeusler
On 7 Feb 2007 09:44:32 GMT, Duncan Booth [EMAIL PROTECTED]
wrote:

Franz Steinhaeusler [EMAIL PROTECTED] wrote:

Yes, people have compiled Python with gcc on windows. I believe it is
slightly slower than the standard release, but I would guess that may
depend on the exact versions of gcc/msc you choose to compare, and the
exact compiler options you choose (or I may even be imagining it
entirely).
 
 I cannot imagine, that there is a decisive difference, especially as
 in gcc, you have also a couple of options.
 
I did a quick comparison running pystone and taking the best of several 
runs:

On one system which had the Windows Python 2.4 distribution and also 
Python 2.4 installed under cygwin:

   Windows Python 2.4: 46k
   Cygwin Python 2.4: 41k

On another system which has a dual boot setup:

  Windows Python 2.5: 43.7k
   Ubuntu Python 2.5: 42.0k

So in the first case there was about a 12% improvement and in the second 
case about 5% improvement using the Windows distribution.

I don't know whether the gap is closing from improvements in gcc or 
whether there is an OS related difference as well. Unfortunately cygwin 
doesn't appear to offer Python 2.5 yet.

Hello Duncan, interesting test, so this little gap
don't care at all (for me).
If the difference would be say 30% or more, than 
that would make a perceptible difference, I think.

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


Re: Watch folder for new file and execute extern program

2007-02-07 Thread Michael Bo

 BTW-It helps us out here if you let us know what platform you
 are running on (e.g. Windows, Linux, Mac, etc.).

 -Larry

Sorry... I'm running on windows XP.
- Michael

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


Re: huge amounts of pure Python code broken by Python 2.5?

2007-02-07 Thread Robin Becker
[EMAIL PROTECTED] wrote:
 John MySQLdb isn't fully supported for Python 2.5 yet, and there's no
 John tested Windows executable available, although there's an untested
 John version from a World of Warcraft guild available.
 
 As Andy Dustman has pointed out a number of times, he doesn't do Windows.
 Someone in the MySQLdb community who does use Windows is going to have to
 fill that void.
..

well I have managed to build both extant versions (MySQL-python-1.2.1_p2  
MySQL-python-1.2.2b2) from source with the aid of Mr Dustman's comments in the 
site.cfg files and a very minor hack to the earlier version. I had to have the 
sources for Mysql available as well, but that probably comes with the 
territory. 
It seems the very latest version won't play well with earlier MySQL so I used 
MySQL-python-1.2.1_p2 as we are still using some 4.0.27 databases.

Given that I used a particular version of MySQL, 5.0.33, to build against I'm 
not certain that my builds are useful for everyone. I copy here the differences 
I had to make to the source to get stuff to build and run against stock win32 
Python-2.5

#MySQL-python-1.2.1_p2
diff -r -c MySQL-python-1.2.1_p2\_mysql.c \tmp\MySQL-python-1.2.1_p2\_mysql.c
*** MySQL-python-1.2.1_p2\_mysql.c  Wed Apr 05 18:55:44 2006
--- \tmp\MySQL-python-1.2.1_p2\_mysql.c Fri Jan 26 14:01:49 2007
***
*** 2767,2772 
--- 2767,2775 
return e;
   }

+ #define QUOTE(X) _QUOTE(X)
+ #define _QUOTE(X) #X
+
   static char _mysql___doc__[] =
   an adaptation of the MySQL C API (mostly)\n\
   \n\
***
*** 2801,2811 

if (!(dict = PyModule_GetDict(module))) goto error;
if (PyDict_SetItemString(dict, version_info,
!  PyRun_String(version_info, Py_eval_input,
   dict, dict)))
goto error;
if (PyDict_SetItemString(dict, __version__,
!  PyString_FromString(__version__)))
goto error;
if (PyDict_SetItemString(dict, connection,
   (PyObject *)_mysql_ConnectionObject_Type))
--- 2804,2814 

if (!(dict = PyModule_GetDict(module))) goto error;
if (PyDict_SetItemString(dict, version_info,
!  PyRun_String(QUOTE(version_info), Py_eval_input,
   dict, dict)))
goto error;
if (PyDict_SetItemString(dict, __version__,
!  PyString_FromString(QUOTE(__version__
goto error;
if (PyDict_SetItemString(dict, connection,
   (PyObject *)_mysql_ConnectionObject_Type))
diff -r -c MySQL-python-1.2.1_p2\site.cfg \tmp\MySQL-python-1.2.1_p2\site.cfg
*** MySQL-python-1.2.1_p2\site.cfg  Sun Apr 02 18:16:50 2006
--- \tmp\MySQL-python-1.2.1_p2\site.cfg Fri Jan 26 13:48:32 2007
***
*** 16,28 

   [compiler]
   #mysql_root: /usr/local/mysql
! #library_dirs: %(mysql_root)s/lib
! #include_dirs: %(mysql_root)s/include
! #libraries: mysqlclient
! # zlib
! # msvcrt
! # libcmt
! # wsock32
! # advapi32
   #extra_compile_args:
! #extra_objects:
--- 16,28 

   [compiler]
   #mysql_root: /usr/local/mysql
! library_dirs: \tmp\mysql-5.0.33\lib_release
! include_dirs: \tmp\mysql-5.0.33\include
! libraries: mysqlclient
!  zlib
!  wsock32
!  advapi32
! #msvcrt
! #libcmt
   #extra_compile_args:
! extra_objects:  /NODEFAULTLIB:MSVCRT

#MySQL-python-1.2.2b2
diff -r -c MySQL-python-1.2.2b2\site.cfg \tmp\MySQL-python-1.2.2b2\site.cfg
*** MySQL-python-1.2.2b2\site.cfg   Wed Apr 05 02:47:02 2006
--- \tmp\MySQL-python-1.2.2b2\site.cfg  Wed Jan 17 15:17:59 2007
***
*** 16,28 

   [compiler]
   #mysql_root: /usr/local/mysql
! #library_dirs: %(mysql_root)s/lib
! #include_dirs: %(mysql_root)s/include
! #libraries: mysqlclient
! # zlib
! # msvcrt
! # libcmt
! # wsock32
! # advapi32
   #extra_compile_args:
! #extra_objects:
--- 16,28 

   [compiler]
   #mysql_root: /usr/local/mysql
! library_dirs: \tmp\mysql-5.0.33\lib_release
! include_dirs: \tmp\mysql-5.0.33\include
! libraries: mysqlclient
!  zlib
!  wsock32
!  advapi32
! #msvcrt
! #libcmt
   #extra_compile_args:
! extra_objects:  /NODEFAULTLIB:MSVCRT


-- 
Robin Becker

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


Built-in datatypes speed

2007-02-07 Thread Maël Benjamin Mettler
Hello Python-List

I hope somebody can help me with this. I spent some time googling for an
answer, but due to the nature of the problem lots of unrelevant stuff
shows up.

Anyway, I reimplemented parts of TigerSearch (
http://www.ims.uni-stuttgart.de/projekte/TIGER/TIGERSearch/ ) in Python.
I am currently writing the paper that goes along with this
reimplementation. Part of the paper deals with the
differences/similarities in the original Java implementation and my
reimplementation. In order to superficially evaluate differences in
speed, I used this paper (
http://www.ubka.uni-karlsruhe.de/cgi-bin/psview?document=ira/2000/5format=1
) as a reference. Now, this is not about speed differences between Java
and Python, mind you, but about the speed built-in datatypes
(dictionaries, lists etc.) run at. As far as I understood it from the
articles and books I read, any method call from these objects run nearly
at C-speed (I use this due to lack of a better term), since these parts
are implemented in C. Now the question is:

a) Is this true?
b) Is there a correct term for C-speed and what is it?

I would greatly appreciate an answer to that, since this has some impact
on the argumentation in the paper.

Thanks,

Maël

PS: For people interested in this reimplementation project: my code will
be published here (
http://www.ling.su.se/dali/downloads/treealigner/index.htm ) as soon as
it is integrated with the GUI and properly tested. The whole thing is
GPLed...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: division by 7 efficiently ???

2007-02-07 Thread Roel Schroeven
[EMAIL PROTECTED] schreef:
 On Feb 6, 4:54 pm, John Machin [EMAIL PROTECTED] wrote:
 Recursive? Bzzzt!
 Might it not be better to halve the interval at each iteration instead
 of calling a random number function? mid = (lo + hi)  1 looks
 permitted and cheap to me. Also you don't run the risk of it taking a
 very high number of iterations to get a result.
 
 I had considered this, but to halve, you need to divide by 2. Using
 random, while potentially increasing the number of iterations, removes
 the dependency of language tricks and division.

It's possible to use Fibonacci numbers instead of halving each time; 
that requires only addition and subtraction. Unfortunately I forgot 
exactly how that works, and I don't have the time to look it up or to 
try to reproduce it now. Maybe later.

AFAIK that method is not commonly used since binary computers are very 
good at dividing numbers by two, but it would be a good method on 
ternary or decimal computers.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: division by 7 efficiently ???

2007-02-07 Thread Roel Schroeven
Roel Schroeven schreef:
 [EMAIL PROTECTED] schreef:
 I had considered this, but to halve, you need to divide by 2. Using
 random, while potentially increasing the number of iterations, removes
 the dependency of language tricks and division.
 
 It's possible to use Fibonacci numbers instead of halving each time; 
 that requires only addition and subtraction. Unfortunately I forgot 
 exactly how that works, and I don't have the time to look it up or to 
 try to reproduce it now. Maybe later.
 
 AFAIK that method is not commonly used since binary computers are very 
 good at dividing numbers by two, but it would be a good method on 
 ternary or decimal computers.

Responding to myself since I found an explanation in the obvious place:

http://en.wikipedia.org/wiki/Fibonacci_search_technique

It is meant for search in ordered arrays though; I don't think it can be 
adapted for searching in mathematic intervals.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Vim search under cursor

2007-02-07 Thread [EMAIL PROTECTED]
Hi, I am using gvim to edit python source files. When I press * or
#, I would want to search for the attribute name under the cursor
and not the entire string.
 For example, If I have os.error and pressing * on top of error
searches for os.error rather than error. How to set this, any Idea?

thanks.
-
Suresh

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


Re: Graphs, bar charts, etc

2007-02-07 Thread [EMAIL PROTECTED]
On Feb 7, 4:46 am, Joshua J. Kugler [EMAIL PROTECTED] wrote:
 Jan Danielsson wrote:
  Hello all,

 I have some data in a postgresql table which I view through a web
  interface (the web interface is written in python -- using mod_python
  under apache 2.2). Now I would like to represent this data as graphs,
  bar charts, etc.

 I know about matplotlib, and it seemed like exactly what I was
  looking for. I tried importing it in my script, but it gave me some
  error about a home directory not being writable. I'm not sure I like the
  idea of it require to be able to write somewhere. Am I using it wrong?

Hi!

Matplotlib saves some stuff into  a configuration dir. Take a look at
the __init__.py file in site-packages/matplotlib (or where your
installation lives). There are several environment variabels checked
where a .matplotlib folder will be created. Try unsetting HOME, than
probably TMP will be used and this should be writable in any case. I
don't know whether the creation of the configuration folder can be
turned off.

Hope that helps! Bernhard

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


mplayer bug or python bug?

2007-02-07 Thread Marco
The following code is my test program for control mplayer.
in movies/ there are about 20 movies, the code plays them in circle,
but mplayer will crash silently after a circle, the sliently means I
can handle popen2 without except, but no movie.

I have no idea about it...
Can you help me?

class SimplePlayer( myobject ):
def __init__(self):
self.debug('simple player init ready')
self.is_open = False
self.wfd = None
self.rfd = None

def play(self, file):
if self.is_open:
self.wfd.write('loadfile %s\n' %(file))
self.wfd.flush()
else:
self.wfd, self.rfd = os.popen2('mplayer -loop 0 -slave
-quiet -ao null %s 2 /dev/null' %(file))
self.is_open = True


##
if __name__ == '__main__':
player = SimplePlayer()
all = os.listdir('movies/')
print all
while True:
for current in all:
print current
player.play('movies/' + current)
time.sleep(3)

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


Re: Python editor

2007-02-07 Thread stani . vsvv
On Feb 6, 11:01 pm, Stef Mientki [EMAIL PROTECTED]
wrote:
 BBands wrote:
  No, no, no, this is not an invitation to the editor wars.

  I have been using José Cláudio Faria's superb 
  Tinn-R,http://www.sciviews.org/Tinn-R/,
  with the R language,http://www.r-project.org/. This editor allows you
  to send code to the R shell for execution. You can easily send a line,
  the selection, the balance after the cursor or the whole script.

In SPE you can use EditExecute in shell (Shift+Ctrl+E). If there is
nothing selected SPE will run the whole script.

Stani


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


outlook bar

2007-02-07 Thread yvesd
Hello,
I'm trying to make an outlook bar like in python but i'm not at all
familiar with ms-outlook and i'm
a bit too weak and in early stage of python learning.
Has somebody already made or seen the code IN TKINTER(/)PMW  for a bar
like that ?

Thanks very much for all help.
Yves

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


ps tkinter

2007-02-07 Thread yvesd
For a bit more help about my previous message (outlook bar)
does anybody know how to reparent or change a widget(button)'s owner
in tkinter ?
here's my code that doesn't work :
def inverse(self):
if (self.texte==top):
self.texte=bottom
btn = self
btn.pack_forget()
btn.configure(parent = self.top, text=self.texte)
btn.pack(side=TOP,fill=X,expand=1)
else:
self.texte=top
btn = self
btn.pack_forget()
btn.configure(parent=self.bottom, text=self.texte)
btn.parent = None
btn.pack(side=BOTTOM,fill=X,expand=1)

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


Re: Vim search under cursor

2007-02-07 Thread Neil Cerutti
On 2007-02-07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi, I am using gvim to edit python source files. When I press * or
 #, I would want to search for the attribute name under the cursor
 and not the entire string.
  For example, If I have os.error and pressing * on top of error
 searches for os.error rather than error. How to set this, any Idea?

It's will to break things, but you can do this by editing the
iskeyword string and adding in the '.'. :h 'iskeyword'.

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


Re: Vim search under cursor

2007-02-07 Thread Wojciech Muła
[EMAIL PROTECTED] wrote:
 Hi, I am using gvim to edit python source files. When I press * or
 #, I would want to search for the attribute name under the cursor
 and not the entire string.
  For example, If I have os.error and pressing * on top of error
 searches for os.error rather than error. How to set this, any Idea?

Press / then Ctrl-R-A then enter -- of course you should recored it
as a macro.

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


Re: Python editor

2007-02-07 Thread Stef Mientki
[EMAIL PROTECTED] wrote:
 On Feb 6, 11:01 pm, Stef Mientki [EMAIL PROTECTED]
 wrote:
 BBands wrote:
 No, no, no, this is not an invitation to the editor wars.
 
 I have been using José Cláudio Faria's superb 
 Tinn-R,http://www.sciviews.org/Tinn-R/,
 with the R language,http://www.r-project.org/. This editor allows you
 to send code to the R shell for execution. You can easily send a line,
 the selection, the balance after the cursor or the whole script.
 
 In SPE you can use EditExecute in shell (Shift+Ctrl+E). If there is
 nothing selected SPE will run the whole script.
 
 Stani
 
 
hi Stani,

it's hard to get your hands on the SPE editor,
bad links, server not available etc.

When you finally got it,
it crashes a lot (at least at my place).

And it's even impossible to get a manual,
to see if there's a course for these crashes ;-)

I read about a free manual with adds,
but I can find it no-where.
And before I pay for the real manual,
I want to see it running for at least 5 minutes ;-)

So despite the potentials of SPE look very good,
I keep myself to PyScripter ;-)

cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python editor

2007-02-07 Thread limodou
Maybe you can try ulipad.

-- 
I like python!
UliPad The Python Editor: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I use __setitem__ method of dict object?

2007-02-07 Thread jeremito
On Feb 6, 5:10 pm, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
 jeremito a écrit :
   On Feb 6, 2:36 pm, Bruno Desthuilliers  [EMAIL PROTECTED] wrote:

  
 (snip)

  Here's an alternative implementation, so you get the idea.
  
  class Xs(dict):

 oops ! I meant:
   class Xs(object):

 of course...

 (snip)

  I guess I just
  need more experience.

 Possibly - but not only. You may want to have a look at the
 FineManual(tm) for all this kind of magic, starting with 
 :http://docs.python.org/ref/specialnames.htmlhttp://docs.python.org/ref/sequence-types.html

 HTH

Thanks again!  Sometimes the problem is simply not knowing where to
find the documentation, or finding the right portion of the
documentation.  Your help has been invaluable.

Jeremy

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


Re: ps tkinter

2007-02-07 Thread Eric Brunel
On Wed, 07 Feb 2007 13:40:33 +0100, yvesd [EMAIL PROTECTED] wrote:

 For a bit more help about my previous message (outlook bar)
 does anybody know how to reparent or change a widget(button)'s owner
 in tkinter ?
 here's my code that doesn't work :
 def inverse(self):
 if (self.texte==top):
 self.texte=bottom
 btn = self
 btn.pack_forget()
 btn.configure(parent = self.top, text=self.texte)
 btn.pack(side=TOP,fill=X,expand=1)
 else:
 self.texte=top
 btn = self
 btn.pack_forget()
 btn.configure(parent=self.bottom, text=self.texte)
 btn.parent = None
 btn.pack(side=BOTTOM,fill=X,expand=1)

Short answer: you can't. At tcl level, the name for the button contains  
the name of its parent, and you basically can't rename a button.

But, having no idea about what you call an outlook bar since I never  
used outlook in my whole life, another solution may exist, not requiring  
to reparent an existing widget. If you only describe exactly what you're  
trying to do, someone may be able to provide far better help.
-- 
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python for web programming

2007-02-07 Thread JStoneGT
Thanks a lot.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Can Parallel Python run on a muti-CPU server ?

2007-02-07 Thread Martin P. Hellwig
[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
 Hi all,

 I'm interested in Parallel Python and I learned from the website of 
 Parallel Python
 that it can run on SMP and clusters. But can it run on a our muti-CPU 
 server ?
 We are running an origin3800 server with 128 CPUs.

 Thanks.
   
 I have tested that at least it could run sum_primes.py on our server.
 
 But it seems Parallel Python just launch one python process for
 each job, and if I let it use 12 CPUs for 8 jobs, Parallel Python
 launches 12 python processes, 4 of which just sleep until all 8 jobs
 are done.

I've just downloaded it ,having a couple of M-CPU machines, it's quite 
interesting. At this moment I think that you should not see it as 
'magical distribution' of your processing pool but more like the way 
threads work. So every function will stay on it's CPU while executing 
and will not use the process power of another CPU if available.

So I guess you have to fine grain your program to take the advantage of 
multiple CPU's, just like you would do if you had 'real' threads.

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


http://www.freeanything4you.com/

2007-02-07 Thread Janak


http://www.freeanything4you.com/

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


Re: outlook bar

2007-02-07 Thread Diez B. Roggisch
yvesd wrote:

 Hello,
 I'm trying to make an outlook bar like in python but i'm not at all
 familiar with ms-outlook and i'm
 a bit too weak and in early stage of python learning.
 Has somebody already made or seen the code IN TKINTER(/)PMW  for a bar
 like that ?

I've not done such a thing, however I investigated the possibility to create
an IE-Bar - and based on that I assume you can't do that in Tkinter at all.
You need native windows controls for that, and some COM-stuff for
registering and interacting. So at least you need the win32-extensions from
Mark Hammond, but maybe quite a bit more.

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


Re: Partial 1.0 - Partial classes for Python

2007-02-07 Thread Thomas Heller
Martin v. Löwis schrieb:
 I'm happy to announce partial 1.0; a module to implement
 partial classes in Python. It is available from
 
 http://cheeseshop.python.org/pypi/partial/1.0
 
 A partial class is a fragment of a class definition;
 partial classes allow to spread the definition of
 a class over several modules. One location serves
 as the original definition of the class.
 
 To extend a class original_module.FullClass with
 an additional function, one writes
 
 from partial import *
 import original_module
 
 class ExtendedClass(partial, original_module.FullClass):
  def additional_method(self, args):
  body
  more_methods
 
 This module is licensed under the Academic Free License v3.0.
 
 Please send comments and feedback to [EMAIL PROTECTED]

Nice idea.  I had to apply this change to make it work, though:

diff -u c:\python25\lib\site-packages\partial-1.0-py2.5.egg\partial.py.orig 
c:\python25\lib\site-packages\partial-1.0-py2.5.egg\partial.py
--- c:\python25\lib\site-packages\partial-1.0-py2.5.egg\partial.py.orig Wed Feb 
07 13:47:55 2007
+++ c:\python25\lib\site-packages\partial-1.0-py2.5.egg\partial.py  Wed Feb 
07 13:47:55 2007
@@ -36,7 +36,7 @@
 continue
 if k in base.__dict__ and not hasattr(v, '__replace'):
 raise TypeError, %s already has %s % (repr(base), k)
-base.__dict__[k] = v
+setattr(base, k, v)
 # Return the original class
 return base

otherwise I get this:

Traceback (most recent call last):
  File stdin, line 1, in module
  File c:\python25\lib\site-packages\partial-1.0-py2.5.egg\partial.py, line 
39, in __new__
base.__dict__[k] = v
TypeError: Error when calling the metaclass bases
'dictproxy' object does not support item assignment


IIUC, wouldn't be 'partial.extend' or something like that be a better name
for the base class?

Thanks,
Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graphs, bar charts, etc

2007-02-07 Thread Sean Davis
On Feb 6, 7:57 am, Jan Danielsson [EMAIL PROTECTED] wrote:
 Hello all,

I have some data in a postgresql table which I view through a web
 interface (the web interface is written in python -- using mod_python
 under apache 2.2). Now I would like to represent this data as graphs,
 bar charts, etc.

I know about matplotlib, and it seemed like exactly what I was
 looking for. I tried importing it in my script, but it gave me some
 error about a home directory not being writable. I'm not sure I like the
 idea of it require to be able to write somewhere. Am I using it wrong?

Is there something else I can use which can produce graphs easily?

 --
 Kind regards,
 Jan Danielsson

You might want to look at RPy (http://rpy.sourceforge.net), an
interface to R (statistical programming environment).

Sean

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


Group Membership in Active Directory Query

2007-02-07 Thread kooch54
I am trying to write a script to simply query the group members in an
active directory group.  I need to use LDAP to make sure I capture any
global  global group nestings that may occur.  I already have a
function that uses WinNT provider to capture this info from NT4 or AD
domains and it works beautifully.  It just doesn't capture global 
global nestings.  I am having great difficulties in getting this to
work on AD though with ldap.  I have a multiple domain tree
environment and need to be able to query groups in different domains.
I want to simply make an ldap connection, bind to it, search for the
group and get it's members.
I do the following for eDirectory and it works great but not in AD.

import ldap
l=ldap.open(1.2.3.4,trace_level = 1)
l.simple_bind_s('cn=username,ou=company','password')
UserRes = UserRes + l.search_s(
o=company,
ldap.SCOPE_SUBTREE, (|'cn=groupname')

If I do the same thing as above but to an AD source it doesn't work.
I run the open and it seems successful, I run the bind using DN, UPN,
or domain name and password and it seems to bind, I run the query and
it says I must complete a successfull bind operation before doing a
query.

Any help is appreciated.

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


Running Application Within Emacs

2007-02-07 Thread rshepard
  My editor is emacs in linux, and I have the python mode enabled. The two
menus -- IM-Python and Python -- allow me to navigate within the loaded
module and open execute buffers, among other things. But, I don't see a way
to run a wxPython application from within the editor as I would from the
command line.

  Is this possible? If so, how?

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


wxPython running other applications or console

2007-02-07 Thread stumblecrab
Is it possible to run another application like vim or a terminal
window from within a wxPython frame?

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


Re: Group Membership in Active Directory Query

2007-02-07 Thread kooch54
On Feb 7, 9:22 am, [EMAIL PROTECTED] wrote:
 I am trying to write a script to simply query the group members in an
 active directory group.  I need to use LDAP to make sure I capture any
 global  global group nestings that may occur.  I already have a
 function that uses WinNT provider to capture this info from NT4 or AD
 domains and it works beautifully.  It just doesn't capture global 
 global nestings.  I am having great difficulties in getting this to
 work on AD though with ldap.  I have a multiple domain tree
 environment and need to be able to query groups in different domains.
 I want to simply make an ldap connection, bind to it, search for the
 group and get it's members.
 I do the following for eDirectory and it works great but not in AD.

 import ldap
 l=ldap.open(1.2.3.4,trace_level = 1)
 l.simple_bind_s('cn=username,ou=company','password')
 UserRes = UserRes + l.search_s(
 o=company,
 ldap.SCOPE_SUBTREE, (|'cn=groupname')

 If I do the same thing as above but to an AD source it doesn't work.
 I run the open and it seems successful, I run the bind using DN, UPN,
 or domain name and password and it seems to bind, I run the query and
 it says I must complete a successfull bind operation before doing a
 query.

 Any help is appreciated.



I found an example in the groups here and attempted it but it failed
as well.  Below is the code I used and the results.

import ldap, ldapurl

proto = 'ldap'
server = 'domaincontroller.domain.company.com'
port = 389

url = ldapurl.LDAPUrl(urlscheme=proto,
  hostport=%s:%s % (server,
  str(port))).initializeUrl()
ldap_obj = ldap.initialize(url)

# !!!password will be on wire in plaintext!!!
ldap_obj = ldap_obj.simple_bind_s('[EMAIL PROTECTED]',
  'password')

base = 'DC=DOMAIN, DC=COMPANY, DC=COM'

scope = ldap.SCOPE_SUBTREE

query = '(objectclass=user)'

res_attrs = ['*']

res = ldap_obj.search_ext_s(base, scope, query, res_attrs)
print res

RESULTS FROM PYTHON SHELL
res=ldap_obj.search_ext_s(base, scope, query, rest_attrs)
AttributeError: 'NoneType' object has no attribute 'search_Ext_s'

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


Re: How can I use __setitem__ method of dict object?

2007-02-07 Thread jeremito
On Feb 7, 8:28 am, jeremito [EMAIL PROTECTED] wrote:
 On Feb 6, 5:10 pm, Bruno Desthuilliers



 [EMAIL PROTECTED] wrote:
  jeremito a écrit :
On Feb 6, 2:36 pm, Bruno Desthuilliers  [EMAIL PROTECTED] wrote:

  (snip)

   Here's an alternative implementation, so you get the idea.

   class Xs(dict):

  oops ! I meant:
class Xs(object):

  of course...

  (snip)

   I guess I just
   need more experience.

  Possibly - but not only. You may want to have a look at the
  FineManual(tm) for all this kind of magic, starting with 
  :http://docs.python.org/ref/specialnames.htmlhttp://docs.python.org/re...

  HTH

 Thanks again!  Sometimes the problem is simply not knowing where to
 find the documentation, or finding the right portion of the
 documentation.  Your help has been invaluable.

 Jeremy

One more question.  I will be asking for the value of cs.xT *many*
(~millions) times.  Therefore I don't want it's value to be calculated
on the fly.  How can I set the value of xT whenever xS, xF, or xG are
changed, but not allow it to be set directly?  From the example given
previously, it seems like it can't be done this way.

Thans,
Jeremy

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


Re: Partial 1.0 - Partial classes for Python

2007-02-07 Thread Carl Banks
On Feb 7, 8:51 am, Thomas Heller [EMAIL PROTECTED] wrote:
 Martin v. Löwis schrieb:

  I'm happy to announce partial 1.0; a module to implement
  partial classes in Python. It is available from

 http://cheeseshop.python.org/pypi/partial/1.0

  A partial class is a fragment of a class definition;
  partial classes allow to spread the definition of
  a class over several modules. One location serves
  as the original definition of the class.

  To extend a class original_module.FullClass with
  an additional function, one writes

  from partial import *
  import original_module

  class ExtendedClass(partial, original_module.FullClass):
   def additional_method(self, args):
   body
   more_methods

  This module is licensed under the Academic Free License v3.0.

  Please send comments and feedback to [EMAIL PROTECTED]

 Nice idea.

Indeed.  I was going to make a post asking for advice on high-level
delegation (basically you have a generic mostly-OO framework, which
the user extends mostly by subclassing, but how do the generic classes
know about the user-extened classes?).  I knew of many solutions, but
all had significant drawbacks.  But this seems like it'd work great,
maybe with a few minor inconveniences but nothing like the icky hacks
I've been using.

Ironic, since I myself posted a very simple example of how to do this
with a class hook here on c.l.python a while back.

But I'll have to review the license and see how it works with what I
have.


Carl Banks

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


python sub interpreter

2007-02-07 Thread Thomas Pollet

Hello,

I want to have a python interpreter shell spawn from a python class member
function.
atm I use exec but I want something more flexible (i.e. syntax checking
while typing)

E.g.:

class blah:

   def start_shell(self):
   import sys
   dbg=self
   str=
   while str != 'exit':
   exec str
   print 'pydbg',
   str=sys.stdin.readline()

etc.

Somebody knows if something like this has been done before or an easy way to
go about this?

Regards,
Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Calling J from Python

2007-02-07 Thread Gosi
On Feb 6, 9:08 pm, [EMAIL PROTECTED] wrote:
 Gosi:

  There are a number of graphics examples, utilities and demos you can
  use in J and combine it with Python.

 Some of those graphic examples are very nice, I have seen a big site
 filled with complex fractals, chaotic attractors, etc.
 Python Zen seems somewhat opposed to part of the J spirit, that's why
 it's not easy to advertise J in this newsgroup. Python is open source,
 and it values readability, it belives that it's better to write more
 and be more readable/debuggable, than to be able to express many
 things with few symbols. APL was an interesting language, powerful
 too, and J looks more keyboard-friendly and it's probably better for
 other things too. K seems even less readable than J to me. Probably J
 has to be compared more to scipy than to Python itself, because they
 share some purposes, the vector/matrix processing. If you need to do
 lot of array processing the syntax of scipy (with the help of
 MatPlotLib too, that's partially copied from MatLab) isn't (may be
 not) high-level enough, the system isn't able to simplify things by
 itself, etc. So in that situation a more functional language may be
 fitter (maybe even F#, but probably there are better languages around
 for that purpose, some modern ones coming from ML family).

 Bye,
 bearophile

Ken Iverson created APL and it ran first time on a computer 1966.
Ken Iverson then corrected several things and made it so different
that he could no longer use the name and the results was J around
1990.

J can be very short and effective.

I like to use J for many things and I think that combining Python and
J is a hell of a good mixture.

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


Re: Partial 1.0 - Partial classes for Python

2007-02-07 Thread Carl Banks
On Feb 7, 10:17 am, Carl Banks [EMAIL PROTECTED] wrote:
 On Feb 7, 8:51 am, Thomas Heller [EMAIL PROTECTED] wrote:



  Martin v. Löwis schrieb:

   I'm happy to announce partial 1.0; a module to implement
   partial classes in Python. It is available from

  http://cheeseshop.python.org/pypi/partial/1.0

   A partial class is a fragment of a class definition;
   partial classes allow to spread the definition of
   a class over several modules. One location serves
   as the original definition of the class.

   To extend a class original_module.FullClass with
   an additional function, one writes

   from partial import *
   import original_module

   class ExtendedClass(partial, original_module.FullClass):
def additional_method(self, args):
body
more_methods

   This module is licensed under the Academic Free License v3.0.

   Please send comments and feedback to [EMAIL PROTECTED]

  Nice idea.

 Indeed.  I was going to make a post asking for advice on high-level
 delegation (basically you have a generic mostly-OO framework, which
 the user extends mostly by subclassing, but how do the generic classes
 know about the user-extened classes?).  I knew of many solutions, but
 all had significant drawbacks.  But this seems like it'd work great,
 maybe with a few minor inconveniences but nothing like the icky hacks
 I've been using.

 Ironic, since I myself posted a very simple example of how to do this
 with a class hook here on c.l.python a while back.

And looking back at that post, I said that using such a hack would be
truly evil.  To every thing there is a season


Carl Banks

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


Re: Calling J from Python

2007-02-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Gosi wrote:

 I like to use J for many things and I think that combining Python and
 J is a hell of a good mixture.

I was able to follow this sentence up to and including the word hell…  :-)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Partial 1.0 - Partial classes for Python

2007-02-07 Thread Michele Simionato
 Martin v. Löwis schrieb:



  I'm happy to announce partial 1.0; a module to implement
  partial classes in Python. It is available from

 http://cheeseshop.python.org/pypi/partial/1.0

  A partial class is a fragment of a class definition;
  partial classes allow to spread the definition of
  a class over several modules. One location serves
  as the original definition of the class.

This looks the same as Ruby classes, right?
I don't like class definitions to be scattered in different files, for
the same reason
I don't like excessive inheritance, it is too easy to get lost when
debugging
code written by somebody else. But probably I am just overreacting due
to my
exposure to Zope ...

 Michele Simionato

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


Socket and array

2007-02-07 Thread JStoneGT
Hello,
 
How to send an array via socket to the other  end?Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Object type check

2007-02-07 Thread king kikapu
Hi to all,

in statically-types languages, let's say C# for example, we use
polymorphism through interfaces. So we define an interface I with
method M and then a class C that implements I interface and write code
for the M method.
So, if we have a function that takes a parameter of type I, we know
before-hand that it will have an M method to call.

But in dynamic languages this is not the case and we can pass whatever
we want to that function. Assuming that someone writes a library in
Python that other programmers will use, what is the correct way to
check inside that function if the parameter passed is of the correct
type, maybe isinstance BIF ?

Thanks in advance!

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


Re: multithreading concept

2007-02-07 Thread sturlamolden
On Feb 7, 2:53 am, S.Mohideen [EMAIL PROTECTED]
wrote:

 Python is praised about - me too. But at one instance it fails. It fails to
 behave as a true multi-threaded application. That means utilizing all the
 CPUs parallely in the SMP efficiently stays as a dream for a Python
 Programmer.

This has been discussed to death before. Win32 threads and pthreads
(which is what Python normally uses, depending on the platform) are
designed to stay idle most of the time. They are therefore not a tool
for utilizing the power of multiple CPUs, but rather make certain kind
of programming tasks easier to program (i.e. non-blocking I/O,
responsive UIs). The GIL is not a problem in this context. If threads
stay idle most of the time, the GIL does not harm.

If you want to utilize the computing power of multiple CPUs, you
should use multiple processes instead of threads. On Python this is
mandatory due to the GIL. In any other language it it highly
recommended. The de-factor standard for parallel multiprocessing (MPI)
uses multiple processes, even on SMPs. Anyone with serious intentions
of using multiple processors for parallel computing should use
multiple processes and fast IPC - not multiple threads, shared memory
and synchronization objects - even if the language is plain C. With
multiple threads, a lot of time is wasted doing context switches and
book keeping for the  thread synchronization. In addition, obscure and
often very difficult to identify bugs are introduced.

There are a Python binding for MPI (mpi4py) and a similar pure Python
project (Parallel Python) that will take care of all these details for
you.


 Discussion threads say its due to GIL - global interpreter lock. But nobody
 has mentioned any alternative to that apart from suggestions like Code it
 in C and POSH (http://poshmodule.sf.net). Is there any other way we can
 make Python programs really multithreaded in real sense.

As mentioned, use MPI or Parallel Python. MPI is by far the more
mature, but Parallel Python could be easier for a pythoneer.
Multithreading has different use.











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


Re: Object type check

2007-02-07 Thread Calvin Spealman
The answer is to do nothing at all. Use the interfaces of the objects
that you expect. Treat them like numbers if you expect them to be, or
stirngs, or iterables. Call methods and access attributes you expect
to be there. If the caller passes sometihng bad, and something doesn't
work, they'll find out about it and consult your documentation to see
what they did wrong. Dont restrict them to particular types. You would
not restrict them to a particular class in C#. Instead, you define the
interfaces simply by how you use the objects. This is called duck
typing (http://en.wikipedia.org/wiki/Duck_typing) which states If it
walks like a duck and it quacks like a duck, it must be a duck. In
the end, isn't that what matters to you? Not the type or defined
interfaces of an object, but that it does what you expect.

On 7 Feb 2007 08:17:55 -0800, king kikapu [EMAIL PROTECTED] wrote:
 Hi to all,

 in statically-types languages, let's say C# for example, we use
 polymorphism through interfaces. So we define an interface I with
 method M and then a class C that implements I interface and write code
 for the M method.
 So, if we have a function that takes a parameter of type I, we know
 before-hand that it will have an M method to call.

 But in dynamic languages this is not the case and we can pass whatever
 we want to that function. Assuming that someone writes a library in
 Python that other programmers will use, what is the correct way to
 check inside that function if the parameter passed is of the correct
 type, maybe isinstance BIF ?

 Thanks in advance!

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



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multithreading concept

2007-02-07 Thread Paul Boddie
On 7 Feb, 02:53, S.Mohideen [EMAIL PROTECTED]
wrote:

 Python is praised about - me too. But at one instance it fails. It fails to
 behave as a true multi-threaded application. That means utilizing all the
 CPUs parallely in the SMP efficiently stays as a dream for a Python
 Programmer.

Take a look at the Python Wiki for information on parallel processing
with Python:

http://wiki.python.org/moin/ParallelProcessing

Pure CPython code may not be able to use more than one CPU merely
through the use of threads (Jython and IronPython are different,
though), but using all the CPUs or cores in an SMP system is not
exactly a mere dream, as many of the projects listed on the above page
demonstrate.

Paul

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


(n)curses or tcl/tk?

2007-02-07 Thread magnate
Hi All,

Just learning Python - my first new language for about 18 years (I'm
not a programmer ...). I'm writing a small utility to manipulate some
text files (for the game VGA Planets, if you're interested: http://
www.phost.de). It's currently working, but it looks a bit ugly with
raw_input and just basic text output.

I have plans to expand the functions of the utility, and I want a
simple GUI frontend. I assumed I'd end up with something that looks a
bit like the Debian installer: a curses-driven thing with simple ascii
boxes and buttons. But reading a bit more about Python makes me think
that support for tcl/tk is much more developed than support for
curses.

So my question is, should I go to the trouble of learning how to make
boxes and stuff using tcl/tk, or just go with ncurses as I imagined?

Which is more portable? The basic idea is that this just runs on the
largest possible variety of systems (er, assuming they have Python
installed, of course). I use Debian mostly, but of course it needs to
run on bog-standard Windows boxes. Does that tilt the balance in
favour of curses or tcl/tk? Or should I just stick with ugly text?

Thanks for all your help,

CC (noob)

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


Re: Partial 1.0 - Partial classes for Python

2007-02-07 Thread Carl Banks
On Feb 7, 10:48 am, Michele Simionato [EMAIL PROTECTED]
wrote:
  Martin v. Löwis schrieb:

   I'm happy to announce partial 1.0; a module to implement
   partial classes in Python. It is available from

  http://cheeseshop.python.org/pypi/partial/1.0

   A partial class is a fragment of a class definition;
   partial classes allow to spread the definition of
   a class over several modules. One location serves
   as the original definition of the class.

 This looks the same as Ruby classes, right?
 I don't like class definitions to be scattered in different files, for
 the same reason
 I don't like excessive inheritance, it is too easy to get lost when
 debugging
 code written by somebody else. But probably I am just overreacting due
 to my
 exposure to Zope ...

The big difference from Ruby is that this can't extend most built-
ins.  Which means that a lot of Ruby horror stories wouldn't apply.


Carl Banks

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


Re: Partial 1.0 - Partial classes for Python

2007-02-07 Thread Thomas Heller
Carl Banks schrieb:
 On Feb 7, 10:17 am, Carl Banks [EMAIL PROTECTED] wrote:
 On Feb 7, 8:51 am, Thomas Heller [EMAIL PROTECTED] wrote:



  Martin v. Löwis schrieb:

   I'm happy to announce partial 1.0; a module to implement
   partial classes in Python. It is available from

  http://cheeseshop.python.org/pypi/partial/1.0

   A partial class is a fragment of a class definition;
   partial classes allow to spread the definition of
   a class over several modules. One location serves
   as the original definition of the class.

   To extend a class original_module.FullClass with
   an additional function, one writes

   from partial import *
   import original_module

   class ExtendedClass(partial, original_module.FullClass):
def additional_method(self, args):
body
more_methods

   This module is licensed under the Academic Free License v3.0.

   Please send comments and feedback to [EMAIL PROTECTED]

  Nice idea.

 Indeed.  I was going to make a post asking for advice on high-level
 delegation (basically you have a generic mostly-OO framework, which
 the user extends mostly by subclassing, but how do the generic classes
 know about the user-extened classes?).  I knew of many solutions, but
 all had significant drawbacks.  But this seems like it'd work great,
 maybe with a few minor inconveniences but nothing like the icky hacks
 I've been using.

 Ironic, since I myself posted a very simple example of how to do this
 with a class hook here on c.l.python a while back.
 
 And looking back at that post, I said that using such a hack would be
 truly evil.  To every thing there is a season

Do you have a pointer to that post?

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


Re: Object type check

2007-02-07 Thread Michele Simionato
On Feb 7, 5:17 pm, king kikapu [EMAIL PROTECTED] wrote:
 Hi to all,

 in statically-types languages, let's say C# for example, we use
 polymorphism through interfaces. So we define an interface I with
 method M and then a class C that implements I interface and write code
 for the M method.
 So, if we have a function that takes a parameter of type I, we know
 before-hand that it will have an M method to call.

 But in dynamic languages this is not the case and we can pass whatever
 we want to that function. Assuming that someone writes a library in
 Python that other programmers will use, what is the correct way to
 check inside that function if the parameter passed is of the correct
 type, maybe isinstance BIF ?

Usually, you don't check anything at all. However, in some cases, it
may make
sense to check that you passed the right object.
For instance if you have the container

class Example(object):
   def __init__(self, innerobj):
  self.innerobj = innerobj
   def amethod(self):
  self.innerobj.amethod()

ex = Example(None)

you will get an error only when calling ex.amethod(). If you are going
to call
ex.amethod() one hour after instantiation, you will get the error too
late.
So, it makes sense to put a check in the __init__ method, something
like

assert hasattr(self.innerobj, 'amethod')

in order to get an error message as soon as possible. Notice that
checking for the existance
of the needed method is better than using isinstance, since it gives
you much more
freedom for innerobj. Do not require more than you need.
HTH,

 Michele Simionato

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


Re: Group Membership in Active Directory Query

2007-02-07 Thread Uwe Hoffmann
[EMAIL PROTECTED] schrieb:
 ldap_obj = ldap_obj.simple_bind_s('[EMAIL PROTECTED]',
   'password')
 

 AttributeError: 'NoneType' object has no attribute 'search_Ext_s'
 

dummy = ldap_obj.simple_bind_s('[EMAIL PROTECTED]',
   'password')
or better simply
ldap_obj.simple_bind_s('[EMAIL PROTECTED]',
   'password')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Object type check

2007-02-07 Thread king kikapu
 Dont restrict them to particular types. You would
 not restrict them to a particular class in C#. Instead, you define the
 interfaces simply by how you use the objects.

Of cource i restrict them to particular types! In C# you cannot pass
something bad
this way because the compiler will just catch it!

I see what you mean by duck typing. So you suggest the do nothing
at all direction,
better document my code so other can see what is expected, right ?

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


Re: Object type check

2007-02-07 Thread Calvin Spealman
On 7 Feb 2007 08:59:12 -0800, king kikapu [EMAIL PROTECTED] wrote:
  Dont restrict them to particular types. You would
  not restrict them to a particular class in C#. Instead, you define the
  interfaces simply by how you use the objects.

 Of cource i restrict them to particular types! In C# you cannot pass
 something bad
 this way because the compiler will just catch it!

No, you restrict the interfaces, in your example, not the classes. It
is the same in python, but the interfaces are implicitly defined by
how you use the objects.

 I see what you mean by duck typing. So you suggest the do nothing
 at all direction,
 better document my code so other can see what is expected, right ?

Yes. Also, remember that this means if you write code to expect a
dictionary, any mapping type that supports the operations and methods
you use will work transparently, allowing your code to be much more
flexible.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Object type check

2007-02-07 Thread Eduardo \EdCrypt\ O. Padoan
 Of cource i restrict them to particular types! In C# you cannot pass
 something bad
 this way because the compiler will just catch it!

And you cant pass something 'good' that immitates another object
interface (a file-like object for example)

 I see what you mean by duck typing. So you suggest the do nothing
 at all direction,
 better document my code so other can see what is expected, right ?

I would add UnitTests to it.
-- 
EduardoOPadoan (eopadoan-altavix::com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Partial 1.0 - Partial classes for Python

2007-02-07 Thread Ziga Seilnacht
Thomas Heller wrote:

 Do you have a pointer to that post?


I think that he was refering to this post:
http://mail.python.org/pipermail/python-list/2006-December/416241.html

If you are interested in various implementations there is also this:
http://mail.python.org/pipermail/python-list/2006-August/396835.html

and a module from PyPy:
http://mail.python.org/pipermail/python-dev/2006-July/067501.html

which was moved to a new location:
https://codespeak.net/viewvc/pypy/dist/pypy/tool/pairtype.py?view=markup

Ziga


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


Re: (n)curses or tcl/tk?

2007-02-07 Thread Maël Benjamin Mettler
As far as I know Windows does not support ncurses natively (using CygWin
probably changes that). So go with Tkinter. Looks crappy but at least it
should run on all major platforms...
 Hi All,

 Just learning Python - my first new language for about 18 years (I'm
 not a programmer ...). I'm writing a small utility to manipulate some
 text files (for the game VGA Planets, if you're interested: http://
 www.phost.de). It's currently working, but it looks a bit ugly with
 raw_input and just basic text output.

 I have plans to expand the functions of the utility, and I want a
 simple GUI frontend. I assumed I'd end up with something that looks a
 bit like the Debian installer: a curses-driven thing with simple ascii
 boxes and buttons. But reading a bit more about Python makes me think
 that support for tcl/tk is much more developed than support for
 curses.

 So my question is, should I go to the trouble of learning how to make
 boxes and stuff using tcl/tk, or just go with ncurses as I imagined?

 Which is more portable? The basic idea is that this just runs on the
 largest possible variety of systems (er, assuming they have Python
 installed, of course). I use Debian mostly, but of course it needs to
 run on bog-standard Windows boxes. Does that tilt the balance in
 favour of curses or tcl/tk? Or should I just stick with ugly text?

 Thanks for all your help,

 CC (noob)

   

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


Re: (n)curses or tcl/tk?

2007-02-07 Thread Thomas Pollet

Hi,

you could try wxpython and the wxglade toolkit for building gui

Regards,
Thomas

On 7 Feb 2007 08:35:41 -0800, magnate [EMAIL PROTECTED] wrote:


Hi All,

Just learning Python - my first new language for about 18 years (I'm
not a programmer ...). I'm writing a small utility to manipulate some
text files (for the game VGA Planets, if you're interested: http://
www.phost.de). It's currently working, but it looks a bit ugly with
raw_input and just basic text output.

I have plans to expand the functions of the utility, and I want a
simple GUI frontend. I assumed I'd end up with something that looks a
bit like the Debian installer: a curses-driven thing with simple ascii
boxes and buttons. But reading a bit more about Python makes me think
that support for tcl/tk is much more developed than support for
curses.

So my question is, should I go to the trouble of learning how to make
boxes and stuff using tcl/tk, or just go with ncurses as I imagined?

Which is more portable? The basic idea is that this just runs on the
largest possible variety of systems (er, assuming they have Python
installed, of course). I use Debian mostly, but of course it needs to
run on bog-standard Windows boxes. Does that tilt the balance in
favour of curses or tcl/tk? Or should I just stick with ugly text?

Thanks for all your help,

CC (noob)

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

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

Re: (n)curses or tcl/tk?

2007-02-07 Thread Ido Yehieli
On Feb 7, 5:35 pm, magnate [EMAIL PROTECTED] wrote:
 So my question is, should I go to the trouble of learning how to make
 boxes and stuff using tcl/tk, or just go with ncurses as I imagined?

If you want to use curses on windows with python you need to install
WCurses first.
Other then that it is very portable.

After you get used to it curses is also quite easy to use, however tk
has a more features.

Depends on what you want to do. I would have used curses in your
position because it is easy to use (although tk is no rocket science
either) and I like apps that can run on a terminal emulator.

Ido.

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


Re: multithreading concept

2007-02-07 Thread John Nagle
sturlamolden wrote:
 On Feb 7, 2:53 am, S.Mohideen [EMAIL PROTECTED]
 wrote:
 This has been discussed to death before. Win32 threads and pthreads
 (which is what Python normally uses, depending on the platform) are
 designed to stay idle most of the time. They are therefore not a tool
 for utilizing the power of multiple CPUs, but rather make certain kind
 of programming tasks easier to program (i.e. non-blocking I/O,
 responsive UIs). 

Multithread compute-bound programs on multiple CPUs are
how you get heavy number-crunching work done on multiprocessors.
Of course, that's not something you use Python for, at least not
until it gets a real compiler.

It's also the direction games are going.  The XBox 360 forced
game developers to go that way, since it's a 3-CPU shared memory
multiprocessor.  That translates directly to multicore desktops
and laptops.

I went to a talk at Stanford last week by one of Intel's
CPU architects, and he said we're going have hundreds of
CPUs per chip reasonably soon.  Python needs to get ready.

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


Re: Socket and array

2007-02-07 Thread Sam
On 07/02/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 How to send an array via socket to the other end?Thanks.

What you want is a serialisation solution - turning objects into a
string format, and vice versa. Python provides a system for this in
its standard library, in the pickle module. Some pseudocode might look
like:

#sender
import pickle
socket_send(pickle.dumps(my_list))

#receiver
import pickle
my_list = pickle.loads(read_all_socket_data())

However, this should only be used if you trust where the data is
coming from; with untrusted data, a more restrictive format (such as
JSON, perhaps, or a similar lightweight notation system if you are
only sending lists) would be a good idea.

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


what is wrong with my python code?

2007-02-07 Thread Dongsheng Ruan
I got feed back saying list object is not callable. But I can't figure out 
what is wrong with my code.

A=[3,5,4,9,6,7]
l=len(A)-1

for i in range(l):
 print A(i) 


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


Re: Running long script in the background

2007-02-07 Thread Jordan
On Feb 6, 8:26 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hello,

 I am trying to write a python cgi that calls a script over ssh, the
 problem is the script takes a very long time to execute so Apache
 makes the CGI time out and I never see any output.  The script is set
 to print a progress report to stdout every 3 seconds but I never see
 any output until the child process is killed.

 Here's what I have in my python script:

 command = ssh -l root %s /scripts/xen/xen-create-win-vps1.sh %s %
 (host, domuname)
 output = os.popen(command)
 for line in output:
print line.strip()

 Here's a copy of the bash script.

 http://watters.ws/script.txt

 I also tried using os.spawnv to run ssh in the background and nothing
 happens.

 Does anybody know a way to make output show in real time?

Just a little note: os.popen has been replaced by the subprocess
module.  ;D

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


Re: what is wrong with my python code?

2007-02-07 Thread Paul Rubin
Dongsheng Ruan [EMAIL PROTECTED] writes:
 for i in range(l):
  print A(i) 

Use square brackets, A[i].

Usually we'd write such a loop like this:

for x in A:
   print x

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


Re: How can I use __setitem__ method of dict object?

2007-02-07 Thread Jussi Salmela
jeremito kirjoitti:
 On Feb 7, 8:28 am, jeremito [EMAIL PROTECTED] wrote:
 On Feb 6, 5:10 pm, Bruno Desthuilliers



 [EMAIL PROTECTED] wrote:
 jeremito a écrit :
   On Feb 6, 2:36 pm, Bruno Desthuilliers  [EMAIL PROTECTED] wrote:
 (snip)
  Here's an alternative implementation, so you get the idea.
  class Xs(dict):
 oops ! I meant:
   class Xs(object):
 of course...
 (snip)
 I guess I just
 need more experience.
 Possibly - but not only. You may want to have a look at the
 FineManual(tm) for all this kind of magic, starting with 
 :http://docs.python.org/ref/specialnames.htmlhttp://docs.python.org/re...
 HTH
 Thanks again!  Sometimes the problem is simply not knowing where to
 find the documentation, or finding the right portion of the
 documentation.  Your help has been invaluable.

 Jeremy
 
 One more question.  I will be asking for the value of cs.xT *many*
 (~millions) times.  Therefore I don't want it's value to be calculated
 on the fly.  How can I set the value of xT whenever xS, xF, or xG are
 changed, but not allow it to be set directly?  From the example given
 previously, it seems like it can't be done this way.
 
 Thans,
 Jeremy
 
I'm certainly no wizard in timing, but here goes:

Using the class definition given to you by Bruno, adding the following 
to the end (and 'import timeit' at the start):

#
lst = timeit.Timer('for i in xrange(10): xx=xs.xT', \
'from __main__ import Xs;xs = Xs()').repeat(100,1000)
lst.sort()
print lst
print 'Average:', sum(lst)/100
#

I get the output:
[0.017246605364648282, 0.01727426251101738, 0.017275659336591698, 
0.017290745052793044, 0.01733264982001903, 0.017347735536220377,

  and so on ...

0.029063749722380933, 0.029163762433493667, 0.029422733894950315, 
0.029790378386079785]
Average: 0.0182474979362

Thus: A 1000 assignments take a little over 18 milliseconds. The largest 
values in the list are probably caused bu GC occurring. But even 30 ms /
1000 iterations i.e. 30 microseconds per fetch seems to be fast enough.

All this depends of course on the computer used. Mine is on the fast 
side, you might test it on your PC.

The correct way of programming is to find a good simple algorithm and 
the data structures needed, to program a clean solution with them and 
then when you've got a correctly operating application and THEN IF you 
need speed try to do something about it.

Premature optimization is the worst evil or something like that is how 
the saying goes.

Hopefully I'm not leading you astray by being a novice in using the 
timeit module.


HTH,
Jussi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is wrong with my python code?

2007-02-07 Thread Pierre GM
On Wednesday 07 February 2007 12:43:34 Dongsheng Ruan wrote:
 I got feed back saying list object is not callable. But I can't figure
 out what is wrong with my code.

 for i in range(l):
  print A(i)

You're calling A, when you want to access one of its elements: use the 
straight brackets [

for i in range(l):
  print A[i]
-- 
http://mail.python.org/mailman/listinfo/python-list


Why doesn't my heapify work?

2007-02-07 Thread Dongsheng Ruan
I want to turn an Array into a heap, but my code just doesn't work: no 
change after execution.

A=[3,5,4,9,6,7]
m=len(A)-1



for i in range(m,1):
t=(i-1)/2
if A[i]A[t]:
A[i],A[t]=A[t],A[i] 


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


Re: multithreading concept

2007-02-07 Thread Steve Holden
John Nagle wrote:
 sturlamolden wrote:
 On Feb 7, 2:53 am, S.Mohideen [EMAIL PROTECTED]
 wrote:
 This has been discussed to death before. Win32 threads and pthreads
 (which is what Python normally uses, depending on the platform) are
 designed to stay idle most of the time. They are therefore not a tool
 for utilizing the power of multiple CPUs, but rather make certain kind
 of programming tasks easier to program (i.e. non-blocking I/O,
 responsive UIs). 
 
 Multithread compute-bound programs on multiple CPUs are
 how you get heavy number-crunching work done on multiprocessors.
 Of course, that's not something you use Python for, at least not
 until it gets a real compiler.
 
 It's also the direction games are going.  The XBox 360 forced
 game developers to go that way, since it's a 3-CPU shared memory
 multiprocessor.  That translates directly to multicore desktops
 and laptops.
 
 I went to a talk at Stanford last week by one of Intel's
 CPU architects, and he said we're going have hundreds of
 CPUs per chip reasonably soon.  Python needs to get ready.
 

Define Python. Does it include you? What does it need to do to get 
ready. How do you plan to help?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOError: [Errno 4] Interrupted system call

2007-02-07 Thread Donn Cave
In article [EMAIL PROTECTED],
 Marco [EMAIL PROTECTED] wrote:

 Hello,every one, I meet a question:
 
 in my old script, I usually use os.popen2() to get info from standard
 unix(LinuX) program like ps,ifconfig...
 
 Now, I write a OO-based programme, I still use os.popen2( check
 whether mplayer still working via ps command ), but some things I got
 the following message:
 
 Traceback (most recent call last):
   File ./mkt.py, line 351, in loop_timeout
 self.process(self.event.get_next())
   File ./mkt.py, line 361, in process
 self.player.play(command[1])
   File ./mkt.py, line 107, in play
 if self.is_playing():
   File ./mkt.py, line 78, in is_playing
 info = rfd.readlines()
 IOError: [Errno 4] Interrupted system call
 
 why? Thank you!

Some signal was evidently delivered to your process, while
you had a slow read in progress (i.e., not from disk.)
The read was interrupted to deliver the signal.

Look for signal handlers in your code and any library functions
you call.  I hope library functions don't have signal handlers,
sounds like a horrible idea to me.  If your code has a signal
handler for SIGCHLD, try to get rid of that - the handler itself
is causing your problem.

OO (Object Oriented?) doesn't have anything to do with the problem,
that I can think of.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't my heapify work?

2007-02-07 Thread Diez B. Roggisch
Dongsheng Ruan wrote:

 I want to turn an Array into a heap, but my code just doesn't work: no
 change after execution.
 
 A=[3,5,4,9,6,7]
 m=len(A)-1
 
 
 
 for i in range(m,1):
 t=(i-1)/2
 if A[i]A[t]:
 A[i],A[t]=A[t],A[i]

First of all, there is the module heapq that will just do it.

And then you seem to misunderstand how the range-function works. range(m, 1)
will always be the empty list. See 

pydoc range

for how it operates.

Overall, your code is very unpythonic, to say the least. I suggest you start
reading the python tutorial first:

http://docs.python.org/tut/

Especially the looping techniques section:

http://docs.python.org/tut/node7.html#SECTION00760

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


Suggestions on Starting Python Project on P2P streaming

2007-02-07 Thread Krypto
I am 3 months old to python and I have done some small projects. I
want to build a Peer to Peer streaming client ..something like
BitTorrent. I know it is daunting but I got to start somewhere. Please
come easy on me.

What I want in my client program is that client software logs on to
some P2P streaming session from a list, connects to several computers
using TCP connection (protocol may vary in future), obtain stream from
other computers and also send stream to others and play the obtained
media stream on to some media playaer like xmms or any music player.


My obstacles...
1.  I have very little experice in network programming . some tips
here are very welcome Please dont come hard on me.

2. I am not sure how stream content is gathered by client and sent to
media player. suggestions welcome.

3. I have not managed this big project so I am not sure about how to
manage the codesuggestions welcome.


This newbiew appreiates your tips. Any comments are welcome.

Thanks

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


Re: Why doesn't my heapify work?

2007-02-07 Thread Ruan
Can't range go from larger to smaller?


Diez B. Roggisch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Dongsheng Ruan wrote:

 I want to turn an Array into a heap, but my code just doesn't work: no
 change after execution.

 A=[3,5,4,9,6,7]
 m=len(A)-1



 for i in range(m,1):
 t=(i-1)/2
 if A[i]A[t]:
 A[i],A[t]=A[t],A[i]

 First of all, there is the module heapq that will just do it.

 And then you seem to misunderstand how the range-function works. range(m, 
 1)
 will always be the empty list. See

 pydoc range

 for how it operates.

 Overall, your code is very unpythonic, to say the least. I suggest you 
 start
 reading the python tutorial first:

 http://docs.python.org/tut/

 Especially the looping techniques section:

 http://docs.python.org/tut/node7.html#SECTION00760

 Diez 


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


Re: Why doesn't my heapify work?

2007-02-07 Thread Ruan
I found out what is wrong.

You must give it a negative step, like range(10,1,-1)

But my code is not good enought for heapify.

I will try again.


Ruan [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Can't range go from larger to smaller?


 Diez B. Roggisch [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 Dongsheng Ruan wrote:

 I want to turn an Array into a heap, but my code just doesn't work: no
 change after execution.

 A=[3,5,4,9,6,7]
 m=len(A)-1



 for i in range(m,1):
 t=(i-1)/2
 if A[i]A[t]:
 A[i],A[t]=A[t],A[i]

 First of all, there is the module heapq that will just do it.

 And then you seem to misunderstand how the range-function works. range(m, 
 1)
 will always be the empty list. See

 pydoc range

 for how it operates.

 Overall, your code is very unpythonic, to say the least. I suggest you 
 start
 reading the python tutorial first:

 http://docs.python.org/tut/

 Especially the looping techniques section:

 http://docs.python.org/tut/node7.html#SECTION00760

 Diez

 


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


Re: Why doesn't my heapify work?

2007-02-07 Thread skip

ruan Can't range go from larger to smaller?

Yes.  Read the doc:

range(...)
range([start,] stop[, step]) - list of integers

Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
These are exactly the valid indices for a list of 4 elements.

To go from larger to smaller you need a negative step size.  Also, note that
the endpoint is never included.  range(10) serves up 0 throu 9.

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


Re: multithreading concept

2007-02-07 Thread sturlamolden
On Feb 7, 6:17 pm, John Nagle [EMAIL PROTECTED] wrote:

 Multithread compute-bound programs on multiple CPUs are
 how you get heavy number-crunching work done on multiprocessors.

In the scientific community, heavy CPU-bound tasks are either
parallelized using MPI and/or written in Fortran 90/95 and
parallelized using an expensive vectorizing compiler.

 Of course, that's not something you use Python for, at least not
 until it gets a real compiler.

That is also not correct:

1. Using Python does not change the complexity of the algorithm. Big-O
is still the same, and Big-O is still the main determinant of
performance.

2. I value my own time more than extra CPU cycles (and so does those
who pay my salary). If Python is to slow, it is less expensive to
compensate by using more CPUs than using a less productive language
like Java or C++.

3. Only isolated bottlenecks really gain from being statically
compiled. These are usually very small parts of the program. They can
be identified with a profiler (intuition usually do not work very well
here) and rewritten in Pyrex, Fortran 95, C or assembly.

4. There is NumPy and SciPy, which can make Python fast enough for
most CPU-bound tasks. http://www.scipy.org/PerformancePython

5. Premature optimization is the root of all evil in computer
science. (Donald Knuth)

6. Pyrex (the compiler you asked for) does actually exist.


C and Fortran compilers can produce efficient code because they know
the type of each variable. We have do a Python compiler that can do
the same thing. It is called 'Pyrex' and extends Python with static
types. Pyrex can therefore produce code that are just as efficient as
hand-tuned C (see the link above). One can take the bad-performing
Python code, add type declarations to the variables that Pyrex needs
to generate efficient code (but all variables need not be declared),
and leave the rest to the compiler. But this is only required for very
small portions of the code. Transforming time-critical Python code to
Pyrex is child's play. First make it work, then make it fast.

At the University of Oslo, the HPC centre has been running Python
courses for its clients. Python does not perform any worse than C or
Fortran, one just has to know (1) how to use it, (2) when to use it,
and (3) when not to use it.

99% of benchmarks showing bad performance with Python is due to
programmers not understanding which operations are expensive in
interpreted languages, and trying to use Python as if it were C++. The
typical example would be code that use a loop instead of using the
built-in function 'map' or a vectorized array expression with NumPy.


 It's also the direction games are going.

I believe that is due to ignorance. Threads are implemented to be in
an idle blocking state 99% of the time.


 The XBox 360 forced
 game developers to go that way, since it's a 3-CPU shared memory
 multiprocessor.  That translates directly to multicore desktops
 and laptops.

MPI works on SMPs.

MPI does not use threads on SMPs because it performs worse than using
multiple processes.







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


Re: Group Membership in Active Directory Query

2007-02-07 Thread kooch54
On Feb 7, 11:56 am, Uwe Hoffmann [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] schrieb:

  ldap_obj = ldap_obj.simple_bind_s('[EMAIL PROTECTED]',
'password')

  AttributeError: 'NoneType' object has no attribute 'search_Ext_s'

 dummy = ldap_obj.simple_bind_s('[EMAIL PROTECTED]',
'password')
 or better simply
 ldap_obj.simple_bind_s('[EMAIL PROTECTED]',
'password')

First and foremost thanks for the feedback.  Although I don't
appreciate the slight dig at me.
dummy = ldap_obj.simple_bind..

I tried your second recommendation of using
 ldap_obj.simple_bind_s('[EMAIL PROTECTED]','password')

Now I get the following error even after the bind operation seems to
complete successfully.
result = func(*args,**kwargs)
OPERATIONS_ERROR: {'info': ': LdapErr: DSID-0C0905FF, comment:
In order to perform this operation a successful bind must be completed
on the connection., data 0, vece', 'desc': 'Operations error'}

Thanks again...

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


distutils: renaming setup.py ok?

2007-02-07 Thread Anastasios Hatzis
I want to distribute Python site-packages. Is it okay to use other setup 
file names than setup.py, which is mentioned in any place I read in the doc?

E.g., setupMySDK.py, setupMyLib.py

It seems that it works with distutils at least - but probably doing so 
has side-effects with other tools which may expect exactly setup.py as 
file name.


Many thanks,
Anastasios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't my heapify work?

2007-02-07 Thread BJörn Lindqvist
You do know about the heapq module?
http://docs.python.org/dev/lib/module-heapq.html

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distutils: renaming setup.py ok?

2007-02-07 Thread Benjamin Niemann
Hello,

Anastasios Hatzis wrote:

 I want to distribute Python site-packages. Is it okay to use other setup
 file names than setup.py, which is mentioned in any place I read in the
 doc?
 
 E.g., setupMySDK.py, setupMyLib.py
 
 It seems that it works with distutils at least - but probably doing so
 has side-effects with other tools which may expect exactly setup.py as
 file name.

I'd say, it's mostly the user who is expecting setup.py as the filename.

Perhaps 'setup.py --install-sdk' and 'setup.py --install-lib' would be more
approriate (which can be done with distutils).

HTH

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Two mappings inverse to each other: f, g = biject()

2007-02-07 Thread Jonathan Fine
[EMAIL PROTECTED] wrote:

A google search for biject.py and bijection.py
produced no hits, so I suspect that this may not
have been done before.
 
 
 There are few (good too) implementations around, but they are called
 bidict or bidirectional dicts. Sometimes I use this implementation,
 with few changes:
 http://www.radlogic.com.au/releases/two_way_dict.py

Thank you for this.  You are quite right, a dictionary
is a particular type of mapping.  A mapping with an
inverse is called (at least by me) a bijection.  Therefore,
as you say, bidict or something similar is correct for
a bijection that is based on dictionaries.

I had a look at the code in radlogic.  There, the
design philosophy is to add 'inverse operations' to
a dictionary.  Thus, it adds a method reversed_items.

In my code, I used a different philosophy, which
comes down to this.  If a mapping is by design a
bijection, then it should have an inverse method
that gives the inverse mapping.  This preserves the
symmetry between a mapping and its inverse.  (The
inverse has an inverse, which is the original mapping.)

Therefore, my semantics comes down to
   f, g = bidict()  # Use the better name.
   assert f = g.inverse
   assert g = f.inverse
and also
   f[a] = b if and only if g[b] = a

By the way, it turns out that a bidict is not what
my application needs.  But I find it an interesting
problem, and time spent on it I do not consider
wasted.

Best regards

Jonathan



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


Re: How can I use __setitem__ method of dict object?

2007-02-07 Thread jeremito
On Feb 7, 12:48 pm, Jussi Salmela [EMAIL PROTECTED] wrote:
 jeremito kirjoitti:

  On Feb 7, 8:28 am, jeremito [EMAIL PROTECTED] wrote:
  On Feb 6, 5:10 pm, Bruno Desthuilliers

  [EMAIL PROTECTED] wrote:
  jeremito a écrit :
On Feb 6, 2:36 pm, Bruno Desthuilliers  [EMAIL PROTECTED] wrote:
  (snip)
   Here's an alternative implementation, so you get the idea.
   class Xs(dict):
  oops ! I meant:
class Xs(object):
  of course...
  (snip)
  I guess I just
  need more experience.
  Possibly - but not only. You may want to have a look at the
  FineManual(tm) for all this kind of magic, starting with 
  :http://docs.python.org/ref/specialnames.htmlhttp://docs.python.org/re...
  HTH
  Thanks again!  Sometimes the problem is simply not knowing where to
  find the documentation, or finding the right portion of the
  documentation.  Your help has been invaluable.

  Jeremy

  One more question.  I will be asking for the value of cs.xT *many*
  (~millions) times.  Therefore I don't want it's value to be calculated
  on the fly.  How can I set the value of xT whenever xS, xF, or xG are
  changed, but not allow it to be set directly?  From the example given
  previously, it seems like it can't be done this way.

  Thans,
  Jeremy

 I'm certainly no wizard in timing, but here goes:

 Using the class definition given to you by Bruno, adding the following
 to the end (and 'import timeit' at the start):

 #
 lst = timeit.Timer('for i in xrange(10): xx=xs.xT', \
 'from __main__ import Xs;xs = Xs()').repeat(100,1000)
 lst.sort()
 print lst
 print 'Average:', sum(lst)/100
 #

 I get the output:
 [0.017246605364648282, 0.01727426251101738, 0.017275659336591698,
 0.017290745052793044, 0.01733264982001903, 0.017347735536220377,

   and so on ...

 0.029063749722380933, 0.029163762433493667, 0.029422733894950315,
 0.029790378386079785]
 Average: 0.0182474979362

 Thus: A 1000 assignments take a little over 18 milliseconds. The largest
 values in the list are probably caused bu GC occurring. But even 30 ms /
 1000 iterations i.e. 30 microseconds per fetch seems to be fast enough.

 All this depends of course on the computer used. Mine is on the fast
 side, you might test it on your PC.

 The correct way of programming is to find a good simple algorithm and
 the data structures needed, to program a clean solution with them and
 then when you've got a correctly operating application and THEN IF you
 need speed try to do something about it.

 Premature optimization is the worst evil or something like that is how
 the saying goes.

 Hopefully I'm not leading you astray by being a novice in using the
 timeit module.

 HTH,
 Jussi

Thank you.  Once again this mailing list has proven most helpful.  I
realize it probably isn't worth my time (or stress) to figure out how
to avoid calculating xT on the fly-at least not yet.

Jeremy

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


Re: Calling J from Python

2007-02-07 Thread Gosi
On Feb 7, 3:46 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 In [EMAIL PROTECTED], Gosi wrote:
  I like to use J for many things and I think that combining Python and
  J is a hell of a good mixture.

 I was able to follow this sentence up to and including the word hell...  :-)

 Ciao,
 Marc 'BlackJack' Rintsch


That is a start.

Hell is also what most example start with as in Hello something
Hell in northern countries is very cold.
Hell in middle east is very hot.
I do not know which is your Hell hot or cold.
Hell o veröld

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


Re: multithreading concept

2007-02-07 Thread Sergei Organov
sturlamolden [EMAIL PROTECTED] writes:
 On Feb 7, 6:17 pm, John Nagle [EMAIL PROTECTED] wrote:
[...]
 MPI does not use threads on SMPs because it performs worse than using
 multiple processes.

I fail to see how threads in general could perform worse than
processes. I do understand that processes are inherently more
safe/secure, but when it comes to speed I really can't imagine why it
could happen that threads perform worse (poor threads implementation and
programming practices aside). Care to give some references?

-- Sergei.

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


Pyserial example program error: win32file.SetupComm reports 'Incorrect function.'

2007-02-07 Thread Ron Jackson
I am using Python 2.5 on Windows XP. I have installed Pyserial and
win32all extensions.

When I try to run the example program scan.py (included below), or any 
other program using pyserial, as soon as it hits the statement:

s = serial.Serial(i)

I get the error:

Traceback (most recent call last):
   File C:\Python25\Doc\PySerial Examples\scan.py, line 26, in module
 for n,s in scan():
   File C:\Python25\Doc\PySerial Examples\scan.py, line 17, in scan
 s = serial.Serial(i)
   File C:\Python25\Lib\site-packages\serial\serialutil.py, line 156,
in __init__
 self.open()
   File C:\Python25\lib\site-packages\serial\serialwin32.py, line 57,
in open
 win32file.SetupComm(self.hComPort, 4096, 4096)
error: (1, 'SetupComm', 'Incorrect function.')

What do I need to do to fix this? Thanks for the help!

   -- Ron


The example program scan.py (from the pyserial examples folder):
---
#!/usr/bin/env python
Scan for serial ports.
Part of pySerial (http://pyserial.sf.net)  (C)2002-2003 [EMAIL PROTECTED]

The scan function of this module tries to open each port number
from 0 to 255 and it builds a list of those ports where this was
successful.


import serial

def scan():
 scan for available ports. return a list of tuples (num, name)
 available = []
 for i in range(256):
 try:
 s = serial.Serial(i)
 available.append( (i, s.portstr))
 s.close()   #explicit close 'cause of delayed GC in java
 except serial.SerialException:
 pass
 return available

if __name__=='__main__':
 print Found ports:
 for n,s in scan():
 print (%d) %s % (n,s)
-- 
http://mail.python.org/mailman/listinfo/python-list


Can somebody give me a python code for this?

2007-02-07 Thread John
Given an array of elements, look at it as a binary tree. Start at the last 
interior node, and downheap it. Then downheap the previous interior node, 
and continue in this fashion, up to the root. 


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


Python new user question - file writeline error

2007-02-07 Thread James
Hello,

I'm a newbie to Python  wondering someone can help me with this...

I have this code:
--
#! /usr/bin/python

import sys

month ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':
8,'SEP':9,'OCT':10,'NOV':11,'DEC':12}
infile=file('TVA-0316','r')
outfile=file('tmp.out','w')

for line in infile:
item = line.split(',')
dob = item[6].split('/')
dob = dob[2]+'-'+str(month[dob[1]])+'-'+dob[0]
lbdt = item[8].split('/')
lbdt = lbdt[2]+'-'+str(month[lbdt[1]])+'-'+lbdt[0]
lbrc = item[10].split('/')
lbrc = lbrc[2]+'-'+str(month[lbrc[1]])+'-'+lbrc[0]
lbrp = item[14].split('/')
lbrp = lbrp[2]+'-'+str(month[lbrp[1]])+'-'+lbrp[0]
item[6] = dob
item[8] = lbdt
item[10]=lbrc
item[14]=lbrp
list = ','.join(item)
outfile.writelines(list)
infile.close
outfile.close
-

And the data file(TVA-0316) looks like this:
-
06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
NOV/2006,V1,,,21/NOV/2006,AST,19,U/L,5,40,,
06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
NOV/2006,V1,,,21/NOV/2006,GGT,34,U/L,11,32,h,
06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
NOV/2006,V1,,,21/NOV/2006,ALT,31,U/L,5,29,h,
06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
NOV/2006,V1,,,21/NOV/2006,ALKP,61,U/L,40,135,,
-

Basically I'm reading in each line and converting all date fields (05/
MAR/1950) to different format (1950-03-05) in order to load into MySQL
table.

I have two issues:
1. the outfile doesn't complete with no error message.  when I check
the last line in the python interpreter, it has read and processed the
last line, but the output file stopped before.
2. Is this the best way to do this in Python?
3. (Out of scope) is there a way to load this CSV file directly into
MySQL data field without converting the format?

Thank you.

James

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


Re: mplayer bug or python bug?

2007-02-07 Thread MRAB
On Feb 7, 11:40 am, Marco [EMAIL PROTECTED] wrote:
 The following code is my test program for control mplayer.
 in movies/ there are about 20 movies, the code plays them in circle,
 but mplayer will crash silently after a circle, the sliently means I
 can handle popen2 without except, but no movie.

 I have no idea about it...
 Can you help me?

 class SimplePlayer( myobject ):
 def __init__(self):
 self.debug('simple player init ready')
 self.is_open = False
 self.wfd = None
 self.rfd = None

 def play(self, file):
 if self.is_open:
 self.wfd.write('loadfile %s\n' %(file))
 self.wfd.flush()
 else:
 self.wfd, self.rfd = os.popen2('mplayer -loop 0 -slave
 -quiet -ao null %s 2 /dev/null' %(file))
 self.is_open = True

 ##
 if __name__ == '__main__':
 player = SimplePlayer()
 all = os.listdir('movies/')
 print all
 while True:
 for current in all:
 print current
 player.play('movies/' + current)
 time.sleep(3)

Just a thought, but is mplayer writing anything to its standard output
or error streams? It may be trying to report an error! While you're
debugging, try redirecting them to logfiles.

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


Re: need help to kill a process

2007-02-07 Thread elrondrules
On Feb 6, 8:24 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Tue, 06 Feb 2007 22:59:40 -0300, [EMAIL PROTECTED] escribió:





  this is my code snip.
  within my python script I have the following commands..

  snip

  import os
  ...
  os.system (cd /home; ./TestTool )
  os.system (cd /usr/; sh run.sh load.xml )

  snip

  I need to kill these 2 process after a particular job is done.. is
  there any way to get the pids of these process and if so how do i
  invoke the kill command through os.system..

  or else is there anyother way to do this...

 If you're using Python=2.4 you could use the subprocess module.

 import subprocess
 child1 = subprocess.Popen([./TestTool], cwd=/home)
 child2 = subprocess.Popen([sh,run.sh,load.xml], cwd=/usr)

 Popen objects have a pid attribute. You don't have to use os.system to  
 kill them; use os.kill instead.
 You'll notice that I leave out the final , because I don't know how to  
 start a background process without using the shell. But I think you can  
 use: bg [pid], afterwards, to get the same result.

 --
 Gabriel Genellina- Hide quoted text -

 - Show quoted text -

thx for the reply
os.kill worked fine for the first process.. for the second one the
kill managed to kill the shell but the application is still running..

is there any other work around for this..

thanks

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


calling python from msc.adams

2007-02-07 Thread boris . smirnov
Hello all,

i need to call python from msc.adams.
the syntax is
mdi -c python exit
I have created a linux script called run_python with this content:
mdi -c python $* exit

then a call this script with a command:

run_python script.py param1 param2  paramN

Everything looks OK, but the problem is that also the last exit
parameter in run_python script is taken as an input into script.py
together with param1 param2  paramN. But I need this exit
parameter not to send to python but to mdi.

Is there anybody who could give me any hint of how to do it?
Thank you very much.
Regards,
Boris

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


Re: Python new user question - file writeline error

2007-02-07 Thread Bruno Desthuilliers
James a écrit :
 Hello,
 
 I'm a newbie to Python  wondering someone can help me with this...
 
 I have this code:
 --
 #! /usr/bin/python
 
 import sys
 
 month ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':
 8,'SEP':9,'OCT':10,'NOV':11,'DEC':12}
 infile=file('TVA-0316','r')
 outfile=file('tmp.out','w')
 
 for line in infile:
 item = line.split(',')

CSV format ?
http://docs.python.org/lib/module-csv.html

 dob = item[6].split('/')
 dob = dob[2]+'-'+str(month[dob[1]])+'-'+dob[0]

Why did you use integers as values in the month dict if it's for using 
them as strings ?

 lbdt = item[8].split('/')
 lbdt = lbdt[2]+'-'+str(month[lbdt[1]])+'-'+lbdt[0]
 lbrc = item[10].split('/')
 lbrc = lbrc[2]+'-'+str(month[lbrc[1]])+'-'+lbrc[0]
 lbrp = item[14].split('/')
 lbrp = lbrp[2]+'-'+str(month[lbrp[1]])+'-'+lbrp[0]

This may help too:
http://docs.python.org/lib/module-datetime.html

 item[6] = dob
 item[8] = lbdt
 item[10]=lbrc
 item[14]=lbrp
 list = ','.join(item)

Better to avoid using builtin types names as identifiers. And FWIW, this 
is *not* a list...

 outfile.writelines(list)

You want file.writeline() or file.write(). And you have to manually add 
the newline.

 infile.close

You're not actually *calling* infile.close - just getting a reference on 
the file.close method. The parens are not optional in Python, they are 
the call operator.

 outfile.close

Idem.

 -
 
 And the data file(TVA-0316) looks like this:
 -
 06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
 NOV/2006,V1,,,21/NOV/2006,AST,19,U/L,5,40,,
 06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
 NOV/2006,V1,,,21/NOV/2006,GGT,34,U/L,11,32,h,
 06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
 NOV/2006,V1,,,21/NOV/2006,ALT,31,U/L,5,29,h,
 06-0588,03,701,03701,046613,JJB,05/MAR/1950,M,20/NOV/2006,08:50,21/
 NOV/2006,V1,,,21/NOV/2006,ALKP,61,U/L,40,135,,
 -
 
 Basically I'm reading in each line and converting all date fields (05/
 MAR/1950) to different format (1950-03-05) in order to load into MySQL
 table.
 
 I have two issues:
 1. the outfile doesn't complete with no error message.  when I check
 the last line in the python interpreter, it has read and processed the
 last line, but the output file stopped before.

Use the csv module and cleanly close your files, then come back if you 
still have problems.

 2. Is this the best way to do this in Python?

Err... What to say... Obviously, no.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me a python code for this?

2007-02-07 Thread Bruno Desthuilliers
John a écrit :
 Given an array of elements, look at it as a binary tree. Start at the last 
 interior node, and downheap it. Then downheap the previous interior node, 
 and continue in this fashion, up to the root. 
 
 
http://www.catb.org/~esr/faqs/smart-questions.html#homework
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distutils: renaming setup.py ok?

2007-02-07 Thread Anastasios Hatzis
Hello

Benjamin Niemann wrote:
 Hello,
 
 Anastasios Hatzis wrote:
 
 I want to distribute Python site-packages. Is it okay to use other setup
 file names than setup.py, which is mentioned in any place I read in the
 doc?

 E.g., setupMySDK.py, setupMyLib.py

 It seems that it works with distutils at least - but probably doing so
 has side-effects with other tools which may expect exactly setup.py as
 file name.
 
 I'd say, it's mostly the user who is expecting setup.py as the filename.
 
 Perhaps 'setup.py --install-sdk' and 'setup.py --install-lib' would be more
 approriate (which can be done with distutils).
 

Thank you for this hint. I think it will help.

Regards,
Anastasios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is wrong with my python code?

2007-02-07 Thread Bruno Desthuilliers
Dongsheng Ruan a écrit :
 I got feed back saying list object is not callable. But I can't figure out 
 what is wrong with my code.
 
 A=[3,5,4,9,6,7]
 l=len(A)-1
 
 for i in range(l):
  print A(i) 
 
The error message is quite clear when you remember that () is the call 
operator. For the subscribe operator, you want [].

And FWIW, Python for loops are smarter than that:


A = [3,5,4,9,6,7]
for i in A:
   print i


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


Re: Python editor

2007-02-07 Thread Stef Mientki
limodou wrote:
 Maybe you can try ulipad.
 
thanks,
although it doesn't look bad,
and it certainly must have been a huge job doing this with Tcl/Tk,
I don't think it can compete with PyScripter,
except on Linux ;-)

succes,
cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multithreading concept

2007-02-07 Thread sturlamolden
On Feb 7, 8:03 pm, Sergei Organov [EMAIL PROTECTED] wrote:

 I fail to see how threads in general could perform worse than
 processes. I do understand that processes are inherently more
 safe/secure, but when it comes to speed I really can't imagine why it
 could happen that threads perform worse (poor threads implementation and
 programming practices aside). Care to give some references?

I believe Nick Maclaren explained that to you (and me) on January 10
and 11 this group. As far as I have understood the issue, it has to do
with poor threads implementations. Look that up on Google groups and
re-read the discussion (or ask Nick Maclaren as he is far more
competent than me).

http://groups.google.com/group/comp.lang.python/browse_frm/thread/332083cdc8bc44b

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


Re: Object type check

2007-02-07 Thread Bruno Desthuilliers
king kikapu a écrit :
 Hi to all,
 
 in statically-types languages, let's say C# for example, we use
 polymorphism through interfaces. So we define an interface I with
 method M and then a class C that implements I interface and write code
 for the M method.
 So, if we have a function that takes a parameter of type I, we know
 before-hand that it will have an M method to call.
 
 But in dynamic languages this is not the case and we can pass whatever
 we want to that function.

Yes. And this is a Good Thing (tm).

 Assuming that someone writes a library in
 Python that other programmers will use, what is the correct way to
 check inside that function if the parameter passed is of the correct
 type, maybe isinstance BIF ?

The correct way in Python is to *not* check.  Just document what kind of
interface you expect, and it's ok. If the people using your code are stupid
and lazy enough to not read the doc, then you can't help .

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

Re: Object type check

2007-02-07 Thread Bruno Desthuilliers
king kikapu a écrit :
Dont restrict them to particular types. You would
not restrict them to a particular class in C#. Instead, you define the
interfaces simply by how you use the objects.
 
 
 Of cource i restrict them to particular types! In C# you cannot pass
 something bad
 this way because the compiler will just catch it!

This won't prevent some stupid to implement the interface with a totally 
different semantic (what about some getter wiping out your hard drive ?).

FWIW, in Python, you can't pass something bad because it will raise an 
exception. Well, to be true, there's *one* gotcha : passing a string 
where a list or tuple is expected may in some occasions yield strange 
results (strings being sequences too).

 I see what you mean by duck typing. So you suggest the do nothing
 at all direction,
 better document my code so other can see what is expected, right ?

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


Re: Can somebody give me a python code for this?

2007-02-07 Thread hg
John wrote:

 Given an array of elements, look at it as a binary tree. Start at the last
 interior node, and downheap it. Then downheap the previous interior node,
 and continue in this fashion, up to the root.

Your teacher ?

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


  1   2   3   >