Re: wxStyledTextCtrl problem ?

2004-11-29 Thread Jean Brouwers


If you are running GTK+ try using

self.Editor.SetSTCFocus(True)

in addition to or instead of SetFocus().  Plus maybe

wx.CallAfter(self.Editor.EnsureCaretVisible)

It solved the 'dissapearing caret' problem for our application.


/Jean Brouwers



In article
<[EMAIL PROTECTED]>,
Paul Robson <[EMAIL PROTECTED]> wrote:

> I have a wierd thing with a little editor app I'm writing.
> 
> I'm using wxStyledTextCtrl ; the wrapper for Scintilla. When I create the
> frame in wxPython, I use self.Editor.SetFocus() to put the focus initially
> on the editor.
> 
> This works fine.
> 
> Odd thing is though, switching back and forwards between applications
> alternately hides and reappears the caret.
> 
> Hit Alt-Tab twice and it disappears
> Hit Alt-Tab twice and it comes back.
> 
> It still works fine - there's just no caret. I've tried various things in
> EVT_ACTIVATE including Moving the Caret on screen, and forcing it to be
> visible - they are being called but it makes no difference.
> 
> Any ideas ?
>
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: TestGen 0.05 C/C++ Test Generator Released

2004-11-29 Thread Dan Gass
TestGen 0.05 is now available and contains significant enhancements.

What's New
--

Significant Enhancements/Changes
1) added manipc.py, a generic C/C++ source manipulator that can be used for
   function/method isolation and stubbing for the purposes of unit testing
   with any test framework, including CppUnit.
2) although not new (but neglected in first anouncement) this package also
   includes doxit.py which is used to automatically insert Doxygen comment
   templates into source code.
   
Minor Enhancements/Changes
1) C/C++ stubber has index checks to prevent storage array overflows
2) added a lot of comments to the example test scripts.
3) moved all example source files into examples/source subdirectory and moved
   defaultConfig.py to the examples subdirectory.

Bug Fixes
1) corrected undefined name problem in C/C++ source manipulator 
removefunction().
2) unit test stubber didn't recognize #include of .hpp files (or any include
   where extension is greater than one character. 
3) python unit test target - fixed so syntax error doesn't occur when no test 
   cases.


What's TestGen
--

TestGen is a Python package for software testing.  The package currently 
contains targets for unit testing C/C++.  Future releases will support 
integration testing of C/C++ systems as well as functional testing using 
Python targets. 

- requires Python2.2 or later (it was developed on Python2.3 with some
  testing/verification performed with 2.2)
- Python API for specification of test case setup, inputs and outputs
  (Python's power and flexibility can be used to generate test cases)
- generates "C/C++" test code per test specifications, compiles, links,
  runs, and evaluates the results
- provides access to C++ protected and private variables and methods
- function/method stubbing (for satisfying external linkages or testing
  interfaces to them)
- function/method remove/copy (for isolating code under test
  to reduce external linkage requirements)
- "on the fly" code under test manipulation capability (useful for
  making temporary code modifications to make it testable)
- convenient "C" random number function library (useful when iterating
  the test to get better coverage)
- easy file output comparison and base lining
- test expectations independently verified for successful completion.
- batch facility available for running multiple test scripts (batch
  tests may be nested in that they may execute other batch tests)
- GNU and Microsoft compilers supported (customizable for others)

TestGen also includes "by products" that fall outside the main purpose
of TestGen but are related or depend on TestGen (IOW, great tools
that I don't want to create independent projects for yet):

- manipc.py -- source code manipulator for isolating/stubbing
  functions and methods for test purposes.  This can be used with any
  test framework including CppUnit.
- doxit.py -- inserts Doxygen comment templates into source code for
  the file header as well as structures, enums, classes, functions, 
  methods, and defines.  Does not insert templates where templates
  already exist.  Prepopulates certain fields such as function name,
  parameters, and return type in the template automatically.
- config.py -- flexible configuration file reader (a less up to date
  version is also available at http://sourceforge.net/projects/config-py/.
- HtmlDiff -- class that creates an HTML table showing a side by side 
  comparison of two versions of a text (is being included in Python2.4).

License
---

The vast majority of TestGen is released under the GNU General Public
License with the small remainder released under the MIT License.  All
modules should be clearly marked, if not please let me know.

Download


Downloads are available at the following address under the "Files" link:
https://sourceforge.net/projects/testgen/

Feedback


Feedback and comments (both positive and negative) are very welcome.  
Besides allowing me to improve this package, it also lets me know how 
worth while my time is spent making updates to this package publically
available.  Email addresses will be respected of course.

Documentation is always a challenge to keep accurate and complete.  If 
you struggle with any part of it, let me know.  Better yet if you can 
contribute, even something as small as a clarification, that would be 
greatly appreciated.
  
You may contact the author at dan.gass at gmail.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxStyledTextCtrl problem ?

2004-11-29 Thread Jean Brouwers

Here is the recent thread about this particular problem:



/Jean Brouwers


In article <[EMAIL PROTECTED]>,
Jean Brouwers <[EMAIL PROTECTED]> wrote:

> If you are running GTK+ try using
> 
> self.Editor.SetSTCFocus(True)
> 
> in addition to or instead of SetFocus().  Plus maybe
> 
> wx.CallAfter(self.Editor.EnsureCaretVisible)
> 
> It solved the 'dissapearing caret' problem for our application.
> 
> 
> /Jean Brouwers
> 
> 
> 
> In article
> <[EMAIL PROTECTED]>,
> Paul Robson <[EMAIL PROTECTED]> wrote:
> 
> > I have a wierd thing with a little editor app I'm writing.
> > 
> > I'm using wxStyledTextCtrl ; the wrapper for Scintilla. When I create the
> > frame in wxPython, I use self.Editor.SetFocus() to put the focus initially
> > on the editor.
> > 
> > This works fine.
> > 
> > Odd thing is though, switching back and forwards between applications
> > alternately hides and reappears the caret.
> > 
> > Hit Alt-Tab twice and it disappears
> > Hit Alt-Tab twice and it comes back.
> > 
> > It still works fine - there's just no caret. I've tried various things in
> > EVT_ACTIVATE including Moving the Caret on screen, and forcing it to be
> > visible - they are being called but it makes no difference.
> > 
> > Any ideas ?
> >
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: deleting os files

2004-11-29 Thread John Aherne
Kent Johnson <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> John Aherne wrote:
> > Unfortunately, when it comes to delete, I get a permission error. And
> > yes, when I run the program and try to delete the file from the
> > command prompt, I get a permission error.
> > 
> > As far as I can tell, I assume the file is being kept open in the
> > DictReader call. But I can't work out how I can close the file -
> > .close comand also returns an error. I was assuming that on the return
> > from the call the file would be closed - mistakenly I now think.
>  
> > locallist = [(x) for x in os.listdir(localdir) if   
> > os.path.getsize(os.path.join(localdir, x)) > 0] # upload all local
> > files
> > localfiles = fnmatch.filter(locallist, '*.OUT')
> > for localname in localfiles:  
> >localpath = os.path.join(localdir, localname) 
> >if localname[-3:] == 'OUT':
> > csv_file = file(localpath)
> > reader = csv.DictReader(csv_file,['phone', 'msg', 'PZ', 'MP'])
> > for row in reader:
> > phone = row['phone']
> > msg = row['msg']
> > 
> > print time.ctime(time.time()),' uploading', msg,  'to',
> > phone
> 
>  csv_file.close() # after you finish reading the rows
> 
> Kent

Thanks for the responses.

I had tried the csv_file.close() but was getting an exception in my
try/except block.

I reckon I'm doing this wrong or in the wrong place. So I'll try
reworking the code and see where I get.

At least I can forget about the DictReader class. It's my code I need
to look at.

Thanks

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


Re: Newbie MySQLdb / MySQL version problem, I think

2004-11-29 Thread alastair
Hi,

I'm using MySQLdb with mysql 4.1 and I've seen this too - to get
around it go to the following link:

http://dev.mysql.com/doc/mysql/en/Old_client.html

Hope this helps,

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


Re: Protecting Python source

2004-11-29 Thread Armin Steinhoff
Alan Sheehan wrote:
Hi pythonistas,
I am looking for methods of deploying applications with end users so
that the python code is tamper proof. What are my options ?
I understand I can supply .pyc or .pyo files but they can easily be
reverse engineered I am told.
Is it possible to load the scripts from zip files where the zip files
are password protected ?
Any other ideas ?
Use Pyrex in order to convert the critical parts to C modules ...
Regards
  Armin

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


Re: Psycopg2 mirror availability

2004-11-29 Thread Gerhard Haering
On Sun, Nov 28, 2004 at 10:06:20PM +, Andrew James wrote:
> Gerhard,
> What's your public key? Your messages are all showing up as having an
> invalid signature!

The key should be on the keyservers now.

-- Gerhard


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help on creating a HTML by python

2004-11-29 Thread Gert-Jan den Besten
sepgy writes:
Can anyone help me to use a python to create an HTML photo gallery
generator. When it's finished, it will be able find all the picture
files (i.e. .jpg, .gif. .png files) in any given folder on the
computer, automatically create smaller thumbnails for each image, and
then generate a complete HTML file that displays a clickable image
gallery. When viewed in a web browser, the HTML file will display the
thumbnails in a neatly formatted table, and if you click on one of the
thumbnails the full-size image will appear.
Thanks

Your script is meant to create something like this? 
http://home.hccnet.nl/gj.den.besten/20040822_maasbommel/html/overzicht_01.html

A few months ago I wrote this script to get familiarized with Python. It 
has a few disadvantages:
* It is not written in English (in Dutch actually).
* Written using a procedural/modular programming style.
  No classes are used, so it is not very "Pythonic"
* Written to meet my needs to get pictures published on my website.
* No GUI.

When I get rid of the first two disadvantages, I will publish the 
sourcecodes on my website. It will be GPL'ed.

So far, I tested it on Linux and WinNT and it seems to work fine. It 
uses the "Python Imaging Library" instead of "ImageMagick". Using PIL 
gives it a better performance.

There is another option:
http://info.linspire.com/lphoto/
This is an Open Source application, built using Python. If you can get 
the source, this may be your best choice.

Gert-Jan
--
 Homepage:
   http://www.GJdenBesten.nl
--
http://mail.python.org/mailman/listinfo/python-list


website hosting

2004-11-29 Thread [EMAIL PROTECTED]
Here is the link to the web hosting company that I use for my 3 sites.

http://frontpage-web-hosting.org/


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


Re: Building web graphics with Python

2004-11-29 Thread Peter Maas
Steven Feil schrieb:
I am wondering if there is a light weight Python library for producing
web graphics on-the-fly. There is a C-language library called gd that
can be used in a CGI program to produce gif images.  The Library can
be used to produce graphics images that are dynamically generated.  I
was wondering if there is something similar for Python.
You can create a Python wrapper for gd with SWIG or Pyrex. PIL (Python
Imging Library) and Piddle are native Python solutions.
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building web graphics with Python

2004-11-29 Thread Gerhard Haering
On Mon, Nov 29, 2004 at 10:35:00AM +0100, Peter Maas wrote:
> Steven Feil schrieb:
> >I am wondering if there is a light weight Python library for producing
> >web graphics on-the-fly. There is a C-language library called gd that
> >can be used in a CGI program to produce gif images.  The Library can
> >be used to produce graphics images that are dynamically generated.  I
> >was wondering if there is something similar for Python.
> 
> You can create a Python wrapper for gd with SWIG or Pyrex. PIL (Python
> Imging Library) and Piddle are native Python solutions.

No need to reimplement a gd wrapper:

http://dmoz.org/Computers/Programming/Languages/Python/Modules/Graphics/
http://newcenturycomputers.net/projects/gdmodule.html

-- Gerhard


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: SysLogHandler is drivin me nuts PEBCAC

2004-11-29 Thread michael
Vinay Sajip <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> michael wrote:
> > Yep it was incomplete heres the complete config as it has to be
> > 
> [config file snipped]
> 
> The complete file looks OK.

Thx. with this file it is working. The syslogd configuration under AIX was 
buggy.

regards

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


Re: Building web graphics with Python

2004-11-29 Thread Fredrik Lundh
Steven Feil wrote:

>I am wondering if there is a light weight Python library for producing
> web graphics on-the-fly. There is a C-language library called gd that
> can be used in a CGI program to produce gif images.  The Library can
> be used to produce graphics images that are dynamically generated.  I
> was wondering if there is something similar for Python.

here's one such library:

http://www.pythonware.com/products/pil/index.htm

if you insist on using GD itself, use the gdmodule:

http://newcenturycomputers.net/projects/gdmodule.html

 



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


Re: Newbie MySQLdb / MySQL version problem, I think

2004-11-29 Thread Leon
new version MySQL use new Password encode .
you can use ¡upassword()¡v(modify user table)¡Ato change new password encode 
to old password..

good luck ^^

---by Leon--
"Dave Merrill" <[EMAIL PROTECTED]> ¼¶¼g©ó¶l¥ó·s»D:[EMAIL PROTECTED]
> Sorry for the newbness... Win2K, Python 2.3.3, MySQL 4.1.7. Downloaded and
> extracted MySQL-python-1.0.0.win32-py2.3.zip. Put the whole extracted
> directory into C:\Program Files\Python23\Lib\site-packages\ and renamed it
> to "MySQLdb.
>
> MySQLdb.__version__ returns '1.0.0', so I think it's installed ok.
>
> However, I still can't connect, and I just want to confirm my guess on 
> what
> the problem is, which is that MySQLdb doesn't yet support MySQL 4.1. I'd
> hoped that all that meant was that it wouldn't support any of 4.1's new
> features, but it appears this combination may be completely 
> non-functional.
> Test and results below.
>
> Has anyone else tried this?
>
> Thanks,
>
> Dave Merrill
>
>
> TEST CODE (from http://www.kitebird.com/articles/pydbapi.html):
> --
> import MySQLdb
> conn = MySQLdb.connect (host = "localhost",
>   user = "test_user",
>   passwd = "secret",
>   db = "test_db")
> cursor = conn.cursor ()
> cursor.execute ("SELECT VERSION()")
> row = cursor.fetchone ()
> print "server version:", row[0]
> cursor.close ()
> conn.close ()
> --
>
> RESULT:
> --
> Traceback (most recent call last):
>  File "C:\PROGRA~1\PYTHON23\Lib\site-packages\sm\scriptutils.py", line 49,
> in run
>exec codeObject in mainDict
>  File "", line 9, in ?
>  File "C:\PROGRA~1\PYTHON23\lib\site-packages\MySQLdb\__init__.py", line
> 64, in Connect
>return apply(Connection, args, kwargs)
>  File "C:\PROGRA~1\PYTHON23\lib\site-packages\MySQLdb\connections.py", 
> line
> 116, in __init__
>self._make_connection(args, kwargs2)
>  File "C:\PROGRA~1\PYTHON23\lib\site-packages\MySQLdb\connections.py", 
> line
> 41, in _make_connection
>apply(super(ConnectionBase, self).__init__, args, kwargs)
> OperationalError: (1251, 'Client does not support authentication protocol
> requested by server; consider upgrading MySQL client')
> --
>
>
>
> 


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


Re: Protecting Python source

2004-11-29 Thread Peter Maas
RCS schrieb:
I am looking for methods of deploying applications with end users so
that the python code is tamper proof. What are my options ?

An interesting question is, what makes your source code so innovative as 
to mandate this tamper proof thing?
I can think of 3 reasons to prevent tampering:
- You need money and want to sell your software on a "per seat" basis.
- You don't want customers to fiddle with your code and then innocently
  call for support and demand "bug fixes" for free.
- Your customer demands closed source because the code contains trade
  secrets.
Protecting source has nothing to do with innovation. It's about making
money.
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Python Design Patterns

2004-11-29 Thread Tony Ha
Hello

I am learning Python for in the pass ten months, and have brought a few 
books about Python. Most of them are good books by its only right, and all 
of them only teach you how to write Python programs using Python syntax and 
Python ways, but no one single Python book explicitly teaches you on how to 
analyst your application, and structure your programmes in a way, so that, 
it is easy to maintain, easily to reuse, (i.e. use loosely couple), and 
easily to extend or add new features (programming to Interface instead of 
Implementation) without introduce bugs into your existing working codes.

I recently brought a book called "Head First Design Patterns" published by 
O'reilly. This book is simply a gem. It shows you how to use and apply 
Design Patterns to analyst and structure your code, so that, the programs 
can be easy maintains, reuse, modify and extend. (It is the books I have 
been looking for a long time while I am learning Python, but cannot find 
one). The only caveat about this book is that the authors use Java (not 
Python) in the examples.

I wonder, can any Python guru out there translate the Java examples in the 
book into Python examples, or write a similar book in Python, perhaps 
called "Head First Design Patterns in Python". I think, this will be a 
great addition to Python books, and a great benefit to Python community.

P.S. I am not sure is this the right news group to post this request.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help on creating a HTML by python

2004-11-29 Thread M.E.Farmer
[EMAIL PROTECTED] (sepgy) wrote in message 
> Can anyone help me to use a python to create an HTML photo gallery
> generator. When it's finished, it will be able find all the picture
> files (i.e. .jpg, .gif. .png files) in any given folder on the
> computer, automatically create smaller thumbnails for each image, and
> then generate a complete HTML file that displays a clickable image
> gallery. When viewed in a web browser, the HTML file will display the
> thumbnails in a neatly formatted table, and if you click on one of the
> thumbnails the full-size image will appear.

Hello, 
You want to look at this:
 http://www.uselesspython.com/thumbnail.py
I also did this very thing when i first started learning Python.
Found it quite educational and learned much in the process.
Here was my try at 'improving it':
 http://bellsouthpwp.net/m/e/mefjr75/python/Thumbz.py
You can see my dumb newbie code , of course that was two years ago ;)
There are others out there too try thumbnail.py in a Google search sometime 
;) 
> Thanks
your welcome ...
HTH, 
   M.E.Farmer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to drop all thread ??

2004-11-29 Thread Diez B. Roggisch
Leon wrote:

> if class A(
> use threading,thread module
> ) to produce 100 thread,how to drop its (100 thread) when its running

By exiting. There is no other way to stop a thread by force. Of course you
can write a run()-method like this:


def run(self):
while self.running_condition:
# do something
pass

If that running-condition is queried often enough, you can stop the thread
by setting it to false.

-- 
Regards,

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


error import _bsddb module

2004-11-29 Thread Falko Zurell
Hi Newsgroup,
I installed a python 2.3.4 on my linux box and some Berkeley DB version 
(4.2.21 and 4.1.25). Then I installed also the BSDDB3 package for python 
linked against the given older version of DB.
The I tried to run a program (Current Servers cadmin) which makes 
oviously use of bsddb but this program keeps failing with this message:

>./cadmin --help
Traceback (most recent call last):
  File "./cadmin", line 40, in ?
import channel
  File "/opt/init/local/apps/current-1.4.4/share/current/channel.py", 
line 10, in ?
import bsddb
  File 
"/opt/init/local/apps/python-2.3.4/lib/python2.3/bsddb/__init__.py", 
line 40, in ?
import _bsddb
ImportError: No module named _bsddb
[ 01:02 ] [EMAIL PROTECTED]/opt/init/local/apps/current-1.4.4/sbin:

Has anyone an idea how I can fix this?
Thanks
Falko
--
http://mail.python.org/mailman/listinfo/python-list


Re: protocols, inheritance and polymorphism

2004-11-29 Thread Dirk Thierbach
Dirk Thierbach <[EMAIL PROTECTED]> wrote:
> Donn Cave <[EMAIL PROTECTED]> wrote:
>> Quoth Jacek Generowicz <[EMAIL PROTECTED]>:

>>> Specifically, dynamic polymorphism is impossible without dynamic
>>> typing.

> I haven't heard the term "dynamic typing" in this context, 

Sorry, that should have been "dynamic polymorphism".

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


Load module on IRIX 6

2004-11-29 Thread Roland Van Praag
Dear All,

I try to prepare a new module named  using python 1.5 on IRIX6. The
shared library created is named igg.so and contains the initializarion
routine initigg. I call in this routine Py_InitModule giving as first
argument "igg". Whe I try to import this module, I always have the message :
SystemError: _PyImport_FixupExtension: module igg not loaded. The same
example is running well on windows and DEC alpha but I never succeed on
Silicon workstation. I try with python 1.5 and 2.3.
Thanks for your help
Roland




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


Re: Newbie MySQLdb / MySQL version problem, I think

2004-11-29 Thread Tim Williams
"Dave Merrill" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Sorry for the newbness... Win2K, Python 2.3.3, MySQL 4.1.7. Downloaded and
> extracted MySQL-python-1.0.0.win32-py2.3.zip. Put the whole extracted
> directory into C:\Program Files\Python23\Lib\site-packages\ and renamed it
> to "MySQLdb.
> 
> MySQLdb.__version__ returns '1.0.0', so I think it's installed ok.
> 
> However, I still can't connect, and I just want to confirm my guess on what
> the problem is, which is that MySQLdb doesn't yet support MySQL 4.1. I'd
> hoped that all that meant was that it wouldn't support any of 4.1's new
> features, but it appears this combination may be completely non-functional.
> Test and results below.
> 
> Has anyone else tried this?
> 
> Thanks,
> 
> Dave Merrill
> 
> 
> TEST CODE (from http://www.kitebird.com/articles/pydbapi.html):
> --
> import MySQLdb
> conn = MySQLdb.connect (host = "localhost",
>user = "test_user",
>passwd = "secret",
>db = "test_db")
> cursor = conn.cursor ()
> cursor.execute ("SELECT VERSION()")
> row = cursor.fetchone ()
> print "server version:", row[0]
> cursor.close ()
> conn.close ()
> --
> 
> RESULT:
> --
> Traceback (most recent call last):
>   File "C:\PROGRA~1\PYTHON23\Lib\site-packages\sm\scriptutils.py", line 49,
> in run
> exec codeObject in mainDict
>   File "", line 9, in ?
>   File "C:\PROGRA~1\PYTHON23\lib\site-packages\MySQLdb\__init__.py", line
> 64, in Connect
> return apply(Connection, args, kwargs)
>   File "C:\PROGRA~1\PYTHON23\lib\site-packages\MySQLdb\connections.py", line
> 116, in __init__
> self._make_connection(args, kwargs2)
>   File "C:\PROGRA~1\PYTHON23\lib\site-packages\MySQLdb\connections.py", line
> 41, in _make_connection
> apply(super(ConnectionBase, self).__init__, args, kwargs)
> OperationalError: (1251, 'Client does not support authentication protocol
> requested by server; consider upgrading MySQL client')
> --


I had a similar problem and found this thread:

http://groups.google.com/groups?hl=en&lr=&selm=mailman.5325.1098460353.5135.python-list%40python.org

I changed the user's password using OLD_PASSWORD() and now it works
for me.

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


Re: wxStyledTextCtrl problem ?

2004-11-29 Thread Paul Robson
On Sun, 28 Nov 2004 23:43:32 -0800, Josiah Carlson wrote:

> I don't know why the problem you are having happens, but I would just
> make a call to self.Editor.SetFocus() on an EVT_ACTIVATE event.

Tried that, it doesn't work :(

Or to be precise, it works every other time :)

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


Re: wxStyledTextCtrl problem ?

2004-11-29 Thread Paul Robson
On Mon, 29 Nov 2004 08:10:18 +, Jean Brouwers wrote:

> If you are running GTK+ try using
> 
> self.Editor.SetSTCFocus(True)
> 
> in addition to or instead of SetFocus().  Plus maybe
> 
> wx.CallAfter(self.Editor.EnsureCaretVisible)
> 
> It solved the 'dissapearing caret' problem for our application.

Thanks - that worked perfectly !

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


Re: wxPython: how to update a panel content/layout according to a variable content

2004-11-29 Thread Lo?c Mah?
Thanks for the answer.

I will try the method you talked about.

For the moment, I am creating a new sizer and new panel
and call the SetSizer(...) and SetAutoLayout(...)
but this is not satisfying me.

Loïc


"F. GEIGER" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> wxWindow has Update and Refresh methods. You can override the one of your
> wxPanel, where you can call all its children to update/refresh themselves.
> wxPanel's update could be triggered by a timer event, mouse event  or
> whatever.
> 
> I do such things preferably in timers owned by the widgets themselves.
> 
> HTH
> Franz GEIGER
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Closing files

2004-11-29 Thread Daniel Dittmar
Henrik Holm wrote:
I have recently started playing around with Python.  Some of the things
I have done have involved reading files.  The way I do this is along the
lines of
  f = file('file.txt')
  lines = f.readlines()
  f.close()
I have noticed that it is possible to do this in one line:
  lines = file('file.txt').readlines()
My question is: does the file get closed if I do the reading in this
manner?
The file gets closed in CPython because file objects are closed when the 
last reference to them gets deleted. (I guess when the .readlines () 
returns)

When you use Jython or IronPython, the file will be closed sometime 
later when the file object gets garbage collected. This can lead to 
problems becaause the process might run out of file handles before the 
garbage collection and file locks are held a lot longer.

This led to two camps.
One camp thinks that the correct way would be
f = file('file.txt')
try:
lines = f.readlines()
finally:
f.close()
The other camp thinks that reference counting should be implemented in 
all Python implementations.

And then there are a lot of people who think that changing all the 
readlines one liner would be quite easy should the need of a Jython port 
arrive, so why bother about it now?

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


PyQt on a Server

2004-11-29 Thread Bob Parnes
I have an application importing qt on a linux server and am missing 
something in trying to run it from a workstation via nfs. The 
workstation has the server /usr directory mounted to its own /usr 
directory, so it can access the necessary files. The error I get is

Traceback (most recent call last):
  File "/demo/revenues.py", line 24, in ?
from qt import *
  File "/usr/lib/python2.3/site-packages/qt.py", line 24, in ?
import libsip
ImportError: libXrender.so.1: cannot open shared object file: 
  No such file or directory

I can see the file in /usr/X11R6/lib. So maybe there is a path variable
that qt.py uses and that has to be set on the workstation. If so, I don't 
know how to find it. Thanks for any help.

Bob

-- 
Bob Parnes
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt on a Server

2004-11-29 Thread Phil Thompson
This is likely to be a Qt/X setup problem - PyQt doesn't explicitly call
Xrender.

Does your workstation /etc/ld.so.conf contain a line for /usr/X11R6/lib?

Phil

> I have an application importing qt on a linux server and am missing
> something in trying to run it from a workstation via nfs. The
> workstation has the server /usr directory mounted to its own /usr
> directory, so it can access the necessary files. The error I get is
>
> Traceback (most recent call last):
>   File "/demo/revenues.py", line 24, in ?
> from qt import *
>   File "/usr/lib/python2.3/site-packages/qt.py", line 24, in ?
> import libsip
> ImportError: libXrender.so.1: cannot open shared object file:
>   No such file or directory
>
> I can see the file in /usr/X11R6/lib. So maybe there is a path variable
> that qt.py uses and that has to be set on the workstation. If so, I don't
> know how to find it. Thanks for any help.
>
> Bob
>
> --
> Bob Parnes
> [EMAIL PROTECTED]

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


Re: Closing files

2004-11-29 Thread Timo Virkkala
Daniel Dittmar wrote:
And then there are a lot of people who think that changing all the 
readlines one liner would be quite easy should the need of a Jython port 
arrive, so why bother about it now?
The problem with this approach is, when the time for the Jython port 
arrives, do you remember to do it?

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


Re: network programming without goto (refactoring)

2004-11-29 Thread Sibylle Koczian
Nick Coghlan schrieb:
Roy Smith wrote:
 Jeff Shannon <[EMAIL PROTECTED]> wrote:
In Python, exceptions use 'raise', not 'throw'...
Doh!  I guess it shows that I've been doing a lot of C++ lately :-)
Heh. I'm working on a Python test harness that uses a C++ hardware 
interface module. I keep writing raise on the C++ side and throw on the 
Python side.

Isn't "throw something" a much more aggressive act than "raise 
something", and might that help? But English isn't my native language so 
I may be quite wrong.

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Protecting Python source

2004-11-29 Thread Craig Ringer
On Mon, 2004-11-29 at 18:04, Peter Maas wrote:

> I can think of 3 reasons to prevent tampering:
> 
> - You need money and want to sell your software on a "per seat" basis.

If you mean that you therefore must add built-in copy-protection, then
sure. Users will always get around it if they really want to, so
tamper-resistance is probably closer to the truth, but it'll slow them
down.

On the other hand, one can license software per-seat quite effectively
without software enforcement, or with only informative software
enforcement ("By the way, you appear to be over your seat count."). In
many cases this is good enough - the user can always crack / steal your
software, tamper resistant or not (witness: the games industry), and
code without copy protection is a LOT friendly.

For example, my employer currently relies on software that has a dongle.
The software manufacturer has gone out of business, so if that dongle
dies we're in trouble, as development of a replacement is moving slowly.
In future, if we're given the choice between a product that's superior
in price or functionality but has opressive copy protection and one
that's more limited or more expensive, but has no software enforcement
of copy protection, we'll buy the inferior or overpriced one.

We're quite capable of monitoring our own license compliance. Those who
aren't are also generally quite capable of 'fixing' the software, tamper
resistant or not, so I really don't see the point.

> - You don't want customers to fiddle with your code and then innocently
>call for support and demand "bug fixes" for free.

There, what you really want is tamper-evident code not tamper-proof
code. That's quite a bit more practical IMO, and may be a good place to
look at digital signing.

> - Your customer demands closed source because the code contains trade
>secrets.

My understanding is that that's never guaranteed safe, no? Or are
restrictions against reverse engineering now commonly enforcable?

--
Craig Ringer

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


Re: how to drop all thread ??

2004-11-29 Thread Peter Hansen
Diez B. Roggisch wrote:
Leon wrote:

if class A(
use threading,thread module
) to produce 100 thread,how to drop its (100 thread) when its running

By exiting. There is no other way to stop a thread by force. 
Note that even trying to exit won't work, if the threads are not
marked as "daemon" threads...  Only by calling .setDaemon(True) on
the threads before they are started will you be able to terminate
them all just by exiting.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt on a Server

2004-11-29 Thread Jerry Sievers
Bob Parnes <[EMAIL PROTECTED]> writes:

> I have an application importing qt on a linux server and am missing 
> something in trying to run it from a workstation via nfs. The 
> workstation has the server /usr directory mounted to its own /usr 
> directory, so it can access the necessary files. The error I get is
> 
> Traceback (most recent call last):
>   File "/demo/revenues.py", line 24, in ?
> from qt import *
>   File "/usr/lib/python2.3/site-packages/qt.py", line 24, in ?
> import libsip
> ImportError: libXrender.so.1: cannot open shared object file: 
>   No such file or directory
> 
> I can see the file in /usr/X11R6/lib. So maybe there is a path variable
> that qt.py uses and that has to be set on the workstation. If so, I don't 
> know how to find it. Thanks for any help.


LD_LIBRARY_PATH=/usr/X11R6/lib

or if the LD_LIBRARY_PATH exists already, append to it;

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/X11R6/lib

then

export LD_LIBRARY_PATH

Now try running your Python script and see if this helps.  If so, read
about ld.config and add that lib to the standard config on the
workstation if you plan on having that NFS mount all the time.

You might also check to insure that the lib that you are "seeing" is
actually a file and not a symlink to nowhere and that the file has
appropriate perms for a shared lib r-x is typical.

HTH

> 
> Bob
> 
> -- 
> Bob Parnes
> [EMAIL PROTECTED]

-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Closing files

2004-11-29 Thread Daniel Dittmar
Timo Virkkala wrote:
Daniel Dittmar wrote:
And then there are a lot of people who think that changing all the 
readlines one liner would be quite easy should the need of a Jython 
port arrive, so why bother about it now?
The problem with this approach is, when the time for the Jython port 
arrives, do you remember to do it?
If you can write a unit test now that would fail using Jython, then 
you're going to be reminded quickly.

And perhaps there will be changes to Python
- that make the oppen().readlines () version work in fully garbage 
collected environments; like closing the inner file handle when the end 
of the file is reached
- that suggest a different solution; like declarations on local 
variables that say "call destructor when object goes out of scope"

Then, having more complicated code today doesn't buy you anything.
Daniel
--
http://mail.python.org/mailman/listinfo/python-list


[OT] Re: SysLogHandler is drivin me nuts PEBCAC

2004-11-29 Thread Jan Dries
Slightly OT, but regarding the title, shouldn't it be PEBKAC, since it's 
keyboard and not ceyboard?

Regards,
Jan
michael wrote:
Vinay Sajip <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
michael wrote:
Yep it was incomplete heres the complete config as it has to be
[config file snipped]
The complete file looks OK.

Thx. with this file it is working. The syslogd configuration under AIX was 
buggy.
regards
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie MySQLdb / MySQL version problem, I think

2004-11-29 Thread Dave Merrill
Thanks Allastair, Leon, Tim, anyone else I missed. Bingo, that was it.

I didn't even try looking at mysql.com, duh. In my defense (;-), I'd already
spent a bunch of time in incompatible version hell with other things, so I
was (too) ready to think it either wouldn't work period, or I'd borked it up
somehow. Bless the problems you can fix, easily, even...

Dave Merrill


> I'm using MySQLdb with mysql 4.1 and I've seen this too - to get
> around it go to the following link:
>
> http://dev.mysql.com/doc/mysql/en/Old_client.html


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


Parallel Python on PowerMac?

2004-11-29 Thread Wolfgang Keller
Hello,

as I might get a dual-G5 PowerMac someday in the not to distant future, I
was wondering what options are available for making Python benefit from the
second CPU? Running two interpreters and using Pyro would not be the most
efficient (and easiest) way, I guess?

TIA,

Best regards

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


knowing a file's own name

2004-11-29 Thread Scott Frankel
I'm looking for a way to identify a filename remotely.  Put differently,
is there a way a file can get its own name from its globals()?
doit.py calls exec() on a second py script, tpairs.py, to obtain a dict 
of the
globals in tpairs.py.  How can I add the filename, "tpairs.py," to the 
resulting dict?
i.e.:

# - - - - - - - - - - - - - - - -
# -- tpairs.py
# - - - - - - - - - - - - - - - -
this  = "this"
that  = "that"
gdict = globals()
# - - - - - - - - - - - - - - - -
# -- doit.py
# - - - - - - - - - - - - - - - -
#!/usr/bin/env python
theFile = "./tpairs.py"
theDict = {}
execfile(theFile, theDict)
# somehow add theFile to gdict, i.e.:
# gdict['theFile'] = theFile
Thanks in advance!
Scott
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to drop all thread ??

2004-11-29 Thread Andrew Koenig
This reply is off topic but I couldn't resist:

The best way to get rid of thread is to adopt a kitten.

In fact, one of my cats is named Snobol because she is such a good string 
manipulator.


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


date diff calc

2004-11-29 Thread tertius
Hi,
Is there a more pythonic way to write or do a date difference 
calculation? I have as input two date fields in the form '-MM-DD'

TIA
Terius

from datetime import date
bdl = '2004-11-25'.split('-')
edl = '2004-11-30'.split('-')
bd = date(int(bdl[0]),  int(bdl[1]),  int(bdl[2]))
ed = date(int(edl[0]),  int(edl[1]),  int(edl[2]))
print ed , '-', bd , '=', (ed-bd).days
--
http://mail.python.org/mailman/listinfo/python-list


Re: knowing a file's own name

2004-11-29 Thread Fredrik Lundh
Scott Frankel wrote:

> I'm looking for a way to identify a filename remotely.  Put differently,
> is there a way a file can get its own name from its globals()?
>
> doit.py calls exec() on a second py script, tpairs.py, to obtain a dict of 
> the globals in 
> tpairs.py.  How can I add the filename, "tpairs.py,"
> to the resulting dict?
> i.e.:
>
> # - - - - - - - - - - - - - - - -
> # -- tpairs.py
> # - - - - - - - - - - - - - - - -
> this  = "this"
> that  = "that"
> gdict = globals()
>
> # - - - - - - - - - - - - - - - -
> # -- doit.py
> # - - - - - - - - - - - - - - - -
> #!/usr/bin/env python
>
> theFile = "./tpairs.py"
> theDict = {}
> execfile(theFile, theDict)
>
> # somehow add theFile to gdict, i.e.:
> # gdict['theFile'] = theFile

given your example,

gdict['theFile'] = theFile

does in fact do what you want.

if you want "tpairs.py" to know it's own name, you could add it to
theDict *before* you call execfile:

# doit.py
theDict = {"__file__": theFile}
execfile(theFile, theDict)

# in tpairs.py
gdict["theFile"] = __file__

but why you want a script to access its own globals via a dictionary is
more than I can figure out...

 



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


Re: C API PyErr_Clear vs PyObject_HasAttrString

2004-11-29 Thread Andrew MacIntyre
On Sun, 28 Nov 2004, Robin Becker wrote:

> > I had a look at the source (from a CVS checkout this morning), and the
> > only thing that looks like a source of such trouble would be an extension
> > class with a tp_getattr implementation.
>
> It is such a beast, but the exciting test case looks like
>
> #
> import _test
> g=_test.gstate()
>
> for a in ('strokeColor','strokeColor'):
>   try:
>   setattr(g,a,(1,2,3))
>   print 'Wrong handling of bad '+a
>   except ValueError:
>   pass
> #
>
> so the tp_getattr slot isn't being used.

Referring to the original C code you posted, PyObject_HasAttrString() will
call the tp_getattr routine, clearing any exceptions raised as it returns.

-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


unicode in doctests

2004-11-29 Thread Bjorn Tillenius
I'm trying to combine documentation and testing, by using DocFileSuite
from Python 2.4. But the problem is that I need to write non-ascii
characters in the test, and I can't get it to work. I haven't found a
way to specify which encoding the file is in, so it gets decoded to
unicode.

Anyone know if it's possible at all to use non-ascii character in a
DocFileSuite?

For example, this fails:

>>> foo = u'föö'
u'föö'

BTW, I know that I can use \-notation, but since the test will serve as
documentation as well, I don't want to use it.

Regards,

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


Question on sorting

2004-11-29 Thread Lad
Hi,
I have a file of records of 4 fields each.
Each field is separated by a semicolon. That is

Filed1;Ffield2;Field3;Field4

But there may be also empty records such as

(only semicolons).

For sorting I used
#
lines = file('Config.txt').readlines()# a file I want to sort
lines.sort()
ff=open('ConfigSorted.txt','w')# sorted file
ff.writelines(lines)
ff.close()
###
It was sorted but empty records were first. I need them to be last(at
the end of the file). How can I do that?

Thanks for help
Lad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: date diff calc

2004-11-29 Thread Diez B. Roggisch
> bdl = '2004-11-25'.split('-')
> edl = '2004-11-30'.split('-')
> bd = date(int(bdl[0]),  int(bdl[1]),  int(bdl[2]))
> ed = date(int(edl[0]),  int(edl[1]),  int(edl[2]))

using time.strptime and datetime.date.fromtimestamp is surely the better
alternative, as it lets specify you the format by a string.

> print ed , '-', bd , '=', (ed-bd).days

I can't imagine what could possibly be easier than subtracting two dates -
in fact, most times one has to jump through much more hoops to achieve
these results, e.g. in java.

-- 
Regards,

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


Re: [OT] Re: SysLogHandler is drivin me nuts PEBCAC

2004-11-29 Thread Lloyd Zusman
Jan Dries <[EMAIL PROTECTED]> writes:

> Slightly OT, but regarding the title, shouldn't it be PEBKAC, since it's
> keyboard and not ceyboard?

Your computer didn't come with a ceyboard?  :)

-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.

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


Re: date diff calc

2004-11-29 Thread tertius
Diez B. Roggisch wrote:
 >
I can't imagine what could possibly be easier than subtracting two dates -
in fact, most times one has to jump through much more hoops to achieve
these results, e.g. in java.
I'll try that.
Thanks,
T
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on sorting

2004-11-29 Thread wes weston
Lad wrote:
Hi,
I have a file of records of 4 fields each.
Each field is separated by a semicolon. That is
Filed1;Ffield2;Field3;Field4
But there may be also empty records such as

(only semicolons).
For sorting I used
#
lines = file('Config.txt').readlines()# a file I want to sort
lines.sort()
ff=open('ConfigSorted.txt','w')# sorted file
ff.writelines(lines)
ff.close()
###
It was sorted but empty records were first. I need them to be last(at
the end of the file). How can I do that?
Thanks for help
Lad
Lad,
   The sort call can have a function name as an arg. You
could do:
def mycompare(s1,s2):
#return -1 to put s1's at front; 1 to put s1's at back; 0 for a tie
#if s1=="" and s2<>"": return 1
lines.sort(mycompare)
wes
--
http://mail.python.org/mailman/listinfo/python-list


pdb with emacs

2004-11-29 Thread Yuri Shtil
Hi,

I am trying to learn python and use the gud/pdb from emacs. The
functionality that I am used to under gud/gdb and gud/perldb is missing, or
I don't know how to make it work.
Specifically: when I start pdb on a script file, the source does not show in
an another window as it does with perldb and gdb. If I bring it up in an
another window,
the ^X SPC set a break, but the subsequent gud-next commands do not move the
execution cursor in the source file window.

Any help will be greatly appreciated.


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


Re: Parallel Python on PowerMac?

2004-11-29 Thread Alan Kennedy
[Wolfgang Keller]
> as I might get a dual-G5 PowerMac someday in the not to distant
> future, I was wondering what options are available for making Python
> benefit from the second CPU? Running two interpreters and using Pyro
> would not be the most efficient (and easiest) way, I guess?
Qualifier: obviously efficiency is relative to the application.
But I would venture to say that, *in the general case*, the "most 
efficient" way to benefit from a second cpu, both in terms of coding 
time and execution efficiency, is to use either jython on a suitable jvm 
or ironpython on mono (when it catches up with the .net CLR in efficiency).

I say "most efficient in execution efficiency" because all of the 
de/serialization involved with communicating between two independent 
cpython interpreters, using something like pyro, would outweigh whatever 
performance advantage cpython might have over jython or ironpython. This 
becomes more pronounced as you add more and more processors into the 
picture.

I say "most efficient in coding time" because cpython would require you 
to specially write code for inter-interpreter communications, and 
possibly restructure your application accordingly, whereas jython and 
ironpython won't: the same interpreter can have threads on multiple 
processors, all executing simultaneously.

Although, iff your prospective machine supports System V IPC, you might 
want to check out PoSH.

http://poshmodule.sourceforge.net
running-to-find-my-flame-retardant-suit-ly'yrs
--
alan kennedy
--
email alan:  http://xhaus.com/contact/alan
--
http://mail.python.org/mailman/listinfo/python-list


Re: date diff calc

2004-11-29 Thread Skip Montanaro

tertius> Is there a more pythonic way to write or do a date difference
tertius> calculation? I have as input two date fields in the form
tertius> '-MM-DD'

How about:

import datetime
import time

bd = "2004-11-25"
ed = "2004-11-30"

start = datetime.date.fromtimestamp(time.strptime("%Y-%m-%d", bd))
end = datetime.date.fromtimestamp(time.strptime("%Y-%m-%d", ed))

print ed , '-', bd , '=', (end-start).days

I think that for completeness' sake it would be nice if datetime exposed a
fromstring method which accepted a string representing a date and a format
specifier, e.g.:

start = datetime.date.fromstring("%Y-%m-%d", "2004-11-25")
end = datetime.date.fromstring("%Y-%m-%d", "2004-11-30")

(Maybe it should be called "strptime", since that's the call it's saving.)

The datetime.date object already exposes a strftime method for generating a
formatted string output and will create date objects from both time.time()
output (fromtimestamp) and "proleptic Gregorian ordinal"s (fromordinal).
Looking at the datetime module docs, it's not at all obvious to me that the
latter would be used all that often.  I think inputs from strings would be
much more common.

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


Re: Protecting Python source

2004-11-29 Thread Peter Maas
Craig Ringer schrieb:
On Mon, 2004-11-29 at 18:04, Peter Maas wrote:

I can think of 3 reasons to prevent tampering:
[...]
My understanding is that that's never guaranteed safe, no? Or are
restrictions against reverse engineering now commonly enforcable?
It's not guaranteed but if protection works in 99.9% of all instal-
lations it makes sense, at least if you are not producing highly
visible software like Windows.
Reverse engineering may be possible but in most cases it is a huge
effort. Think of the samba project which builds Windows server
software by analyzing network packets and this is probably easier
than to analyze machine code.
If the "reverse engineering" argument boils down to "protecting source
doesn't make sense" then why does Microsoft try so hard to  protect
its sources?
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: Protecting Python source

2004-11-29 Thread Grant Edwards
On 2004-11-29, Peter Maas <[EMAIL PROTECTED]> wrote:

> If the "reverse engineering" argument boils down to "protecting source
> doesn't make sense" then why does Microsoft try so hard to  protect
> its sources?

To avoid embarassment.

-- 
Grant Edwards   grante Yow!  Why don't you
  at   ever enter and CONTESTS,
   visi.comMarvin?? Don't you know
   your own ZIPCODE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A lock that times out but doesn't poll

2004-11-29 Thread Jive

"Peter Hansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jive wrote:
> > Oh, there will be no bugs.
>
> ??  What kind of a statement is that?

Humorous?  Imagine Carl Spackler in Caddy Shack saying, "Oh, there will be
no money."

> Seriously, why are you so confident about that?  Even if
> the code were trivial, we're talking *threads* here...
>

Two reasons:

1) I just know I can do it.  Argue with *that* logic!

B) Writing bug-free code is quite possible when the job is well-defined and
"from scratch."
It's when you have to modify a mess that it gets tricky.

I think a lot of programmers would be capable of writing bug-free code if
they just knew
it was possible and believed they could do it.  My programmers submit very
few bugs.

I've made some bugs in my day, but the odds are with me on this one.

But enough about me...  Read any good books lately?




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


Re: Parallel Python on PowerMac?

2004-11-29 Thread Wolfgang Keller
Hello,

and thanks for your reply.

> But I would venture to say that, *in the general case*, the "most 
> efficient" way to benefit from a second cpu, both in terms of coding 
> time and execution efficiency, is to use either jython

*cough* *choke*

Err, no, sorry, not for me.

> Although, iff your prospective machine supports System V IPC,

No clue whether MacOS X does so. Afaik it's basically a FreeBSD based on
Mach (from CMU) with a proprietary layer above.

> you might want to check out PoSH.

Where's the binary installer for MacOS X?

Not having to use compilers and linkers and makefiles and the like was one
of the major reasons which made Python interesting for me...

Best regards,

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


httplib question

2004-11-29 Thread Laszlo Zsolt Nagy
Hello,

This is from the docs, from section 11.6.1 (HTTPConnection Objects)

HTTPConnection instances have the following methods: 
request( method, url[, body[, headers]])
[.]
The headers argument should be a mapping of extra HTTP headers to send with the 
request.


AFAIK the only standard mapping type is the dictionary type.
I'm trying to do this:

>>> import httplib
>>> AGENT_MSIE = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET 
>>> CLR 1.1.4322)"
>>> HOST   = "www.google.com"
>>> URL= "http://"+HOST+"/";
>>> headers = {}
>>> headers["User-Agent"] = AGENT_MSIE
>>> conn = httplib.HTTPConnection(HOST)
>>> conn.request("HEAD", URL, headers)
Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python23\lib\httplib.py", line 718, in request
self._send_request(method, url, body, headers)
  File "C:\Python23\lib\httplib.py", line 742, in _send_request
self.send(body)
  File "C:\Python23\lib\httplib.py", line 576, in send
self.sock.sendall(str)
  File "", line 1, in sendall
TypeError: sendall() argument 1 must be string or read-only buffer, not dict

What should I pass instead of a dict?
  

-- 
Best regards,
 Laszlo  

mailto:[EMAIL PROTECTED]
web: http://designasign.biz



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


Re[2]: httplib question

2004-11-29 Thread Laszlo Zsolt Nagy
Hello Stuart,

Monday, November 29, 2004, 8:59:57 PM, you wrote:

> Laszlo,

> The "request" method call expects a "body" parameter that defaults to None
> as the 3rd method parameter.  You will either need to pass in an empty
> string as the body parameter, or assign the headers property by named
> assignment. Python interprets your call as passing the dictionary into the
> body parameter.

> Stuart
I'm a real Lama. :-)


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


Re: Operator Overloading

2004-11-29 Thread Bengt Richter
On 25 Nov 2004 06:35:23 -0800, [EMAIL PROTECTED] (Sebastien Boisgerault) wrote:

>Peter Maas <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
>> Sebastien Boisgerault schrieb:
>> > I wonder if the following quotation from the Python Reference Manual 
>> > (release 2.3.3) about operator overloading is true :
>> > 
>> > "For example, if a class defines a method named __getitem__(), and x
>> > is an instance of this class, then x[i] is equivalent to
>> > x.__getitem__(i)"
>>  [...]
>> from Numeric import *
>> a = array([0.5])
>> a[0]
>> > 
>> > 0.5
>> > 
>> > but
>> > 
>> > 
>> a.__getitem__(0)
>> > 
>> > Traceback (most recent call last):
>> >   File "", line 1, in ?
>> > AttributeError: __getitem__
>> 
>> The quotation above is true. Short form:
>> 
>> IF __getitem__ in dict THEN [] works.
>
>Not exactly the same assertion: 
>replace "__getitem__ in dict" by "__getitem__ in the class dict" 
>and more importantly "[] works" by "[] and __getitem__" are *equivalent*.
>
>Here, "__getitem__" does belongs to type(a).__dict__,
>so "[]" and "__getitem__" should work exactly the same 
>according to the reference, but they don't.
>
>> [...]
>> but this is not what the Python Reference Manual says. Im not a
>> Numeric expert but AFAIK Numeric arrays are basically C arrays
>> having [] intrinsically so there's no need no deliver it via
>> __getitem__.
>
>I would buy your argument if I couldn't find the "__getitem__" method.
>But it does exist ! Except that it is hidden is the class __dict__ and
>apparently cannot be recovered from the instance.__getitem__ call ...
> 
>Thanks for your help,
>
>SB
I believe the new style classes require looking for a descriptor (which
includes functions, which become bound methods via their descriptor nature)
with the attribute name given, before grabbing something from the instance dict.
Otherwise instance attributes would always shadow corresponding method or 
property
names, and those things wouldn't work, or would work as in the old style 
classes.

Therefore looking for __getitem__ is a little trickier than it might seem.
It has to work like any other name, so a.__getitem__ can't be treated 
differently from a.foo.

So as you noticed, the first place to look is in type(a).__dict__ (which is
also an attribute lookup BTW, with name '__dict__' which could be a descriptor
too, but we'll ignore that for the moment. See further below for that).

Consider that given

 >>> import Numeric
 >>> a = Numeric.array([0.5])
 >>> a
 array([ 0.5])

this

 >>> a[0]
 0.5

produces the same result as this

 >>> type(a).__dict__['__getitem__'].__get__(a, type(a)).__call__(0)
 0.5

So what happens when we look for type(a).__dict__? '__dict__' is just a name,
so we have to look for a method or property in the chain of base classes.
The buck presumably stops at some base class descriptor named __dict__, if any,
and that descriptor, if present, determines what you get. The chain of search
for type(a).__dict__ presumably starts looking in type(type(a)).__dict__, but

 >>> type(type(a))
 

is already at the end of the chain.

 >>> type(type(a)).__dict__
 

Remember, we're going to look _in_ the __dict__, not _for_ it here ;-)

But this has already been processed through the attribute magic, so to see
what '__dict__' is without that processing, we use the proxy to look it up:

 >>> type(type(a)).__dict__['__dict__']
 

Which is a descriptor if it has a __get__ method:
 >>> type(type(a)).__dict__['__dict__'].__get__
 

Sure enough, so we pass type(a) and its type to that, and get back 
type(a).__dict__ the long way:

 >>> type(type(a)).__dict__['__dict__'].__get__(type(a), type(type(a)))
 

now we can look for __getitem__ in that:
 >>> type(type(a)).__dict__['__dict__'].__get__(type(a), 
 >>> type(type(a)))['__getitem__']
 

Which being the function of a method, should have a descriptor's __get__ 
method, by which
to become a bound method:

 >>> type(type(a)).__dict__['__dict__'].__get__(type(a), 
 >>> type(type(a)))['__getitem__'].__get__
 

So we pass it the instance and its type:
 >>> type(type(a)).__dict__['__dict__'].__get__(type(a), 
 >>> type(type(a)))['__getitem__'].__get__(a, type(a))
 

Which should have a __call__ method if it's callable:
 >>> type(type(a)).__dict__['__dict__'].__get__(type(a), 
 >>> type(type(a)))['__getitem__'].__get__(
 a, 
type(a)).__call__
 

Which we can call with the index
 >>> type(type(a)).__dict__['__dict__'].__get__(type(a), 
 >>> type(type(a)))['__getitem__'].__get__(
 a, 
type(a)).__call__(0)
 0.5

Fortunately, we don't normally have to think about all that when we write

 >>> a[0]
 0.5

;-)

Caveat: this is not based on reading the code internals, so I could be 
misinterpreting surface
appearances, but at least it ought to be clear that a[0] involves a lot of 
dynamic decisions that
might 

Re: Protecting Python source

2004-11-29 Thread Dave Reed
On Monday 29 November 2004 14:13, Grant Edwards wrote:
> On 2004-11-29, Peter Maas <[EMAIL PROTECTED]> wrote:
> 
> > If the "reverse engineering" argument boils down to "protecting 
source
> > doesn't make sense" then why does Microsoft try so hard to  protect
> > its sources?
> 
> To avoid embarassment.

+1 QOTW

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


Re: date diff calc

2004-11-29 Thread Rick Holbert
Here's how to do it as a one-liner:

python -c "import datetime; import time; print 'Only %d days until
Christmas' %  (datetime.date(2004, 12, 25) -
datetime.date.fromtimestamp(time.time())).days"

Here's a slightly shorter way of doing it:

python -c "import time; print 'Only %f more days until Christmas' % 
(float(time.mktime(time.strptime('2004-12-25', '%Y-%m-%d')) -
time.time()) / 86400)"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Building web graphics with Python

2004-11-29 Thread Larry Bates
ReportLab Graphics module can produce graphics
and then save into many formats via Python Imaging
Library (PIL).
Larry Bates

Steven Feil wrote:
I am wondering if there is a light weight Python library for producing
web graphics on-the-fly. There is a C-language library called gd that
can be used in a CGI program to produce gif images.  The Library can
be used to produce graphics images that are dynamically generated.  I
was wondering if there is something similar for Python.
--
http://mail.python.org/mailman/listinfo/python-list


POSH on PowerMac? (was: Parallel Python on PowerMac?)

2004-11-29 Thread Wolfgang Keller
>> Although, iff your prospective machine supports System V IPC,
> 
> No clue whether MacOS X does so.

[EMAIL PROTECTED]&! Read before you post. According to "Mac OS X for UNIX Users"
there's a compatibility library included in Mac OS X that does so.

Now who's got a the tools and the know-how to port this thing to the Mac?

TIA,

Best regards,

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


Python UPS / FedEx Shipping Module

2004-11-29 Thread Gabriel Cooper
Is there an existing UPS and FedEx capable shipping (as in, price 
quotes) module out there? I have UPS working but now I need FedEx and 
was curious whether I'd be reinventing the wheel. ;) Web searches didn't 
reveal anything particularly interesting.

Also, anyone know what happened to the "payment" sourceforge.net 
project? it was only a few python files on CVS of connecting to various 
online stores, but it seems to be deleted now. I had to update it to 
work with newer python libraries, and wanted to contribute my changes 
back to it but in the mean time it disappeared from sourceforge!

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


slicing, mapping types, ellipsis etc.

2004-11-29 Thread Jerry Sievers
Fellow Pythonists;

I am totally puzzled on the use of slicing on mapping types and
especially unsure on use of the Ellipsis... and slicing syntax that
has two or more groups seperated by comma.

I am referring to (from the manual);

 Slice objects
Slice objects are used to represent slices when extended
  slice syntax is used. This is a slice using two colons, or multiple
  slices or ellipses separated by commas, e.g., a[i:j:step], a[i:j,
  k:l], or a[..., i:j]. They are also created by the built-in slice()
  function.

A quick example on how this is used and/or pointer to more reading is
greatly appreciated.

Thanks


-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Random number generation from functions

2004-11-29 Thread drs
Is there any way to generate random numbers based on arbitrary real valued
functions? I am looking for something like random.gauss() but with natural
log and exponential functions.

thanks,

-d


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


Re: how to drop all thread ??

2004-11-29 Thread Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.
Hi !

The best method, it is the suicide (of the threads).




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


Re: asynchat and threading

2004-11-29 Thread Eric S. Johansson
Anthony Baxter wrote:
twisted is too large to go into the python core as is - in addition, there's a 
mismatch between Python's release cycle speed and twisted's release
cycle speed (although the current delayed-until-who-knows-when Twisted
2.0 might be a harbinger of twisted slowing down to Python's speed )
It's possible that in the future a small core of twisted could end up in the
stdlib - this topic's come up a couple of times on the twisted list (most 
recently, a couple of months ago).

I wonder if the asyncore docs couldn't grow a 'See also' that points at twisted,
though...
this points to an important issue that should be addressed at some point 
which is the ability to quickly and easily, on the level of rpm or 
apt-get, import external frameworks.  I have a body of code which counts 
on smtpd.py and pop3d.py.  I have modified both and just created new 
versions to sit within my application.  Easy integration.

If I was to count on twisted, I would have another fetch fest collecting 
all the pieces as well as increasing the complexity of building my 
application.

If I could simply do: py-get twisted
and have all of the dependencies resolved, it would be wonderful.  as a 
prototype, I would suggest wrapping apt-get with a python envelope which 
 automatically invokes apt-get with a python specific configuration 
file for .pydeb files as well as a private repository and database etc.. 
 Since apt-get exists for almost every version of Linux and should be 
portable to other platforms, this distribution method should be 
relatively distribution portable.

One can also handle upgrades of the core image of Python and ancillary 
packages as well by leaving a breadcrumb file indicating which packaging 
system is native and the package currently installed. <<- idea needs work

yea? nay?
---eric
--
http://mail.python.org/mailman/listinfo/python-list


PIL 1.1.4 paste PNG's with transparency problem

2004-11-29 Thread Caleb Hattingh
Here's hoping effbot is around :)
I have a really simple situation where I have 2 png images, and open them  
so:

'>>> iconBallImage =  
Image.open('sampleTextures/iconBall.png').resize(DimensionSize)
'>>> iconShieldImage =  
Image.open('sampleTextures/iconShield.png').resize(DimensionSize)

The 2nd image has an alpha channel with transparency.  The first one also  
has an alpha channel, but is fully opaque.  Then I paste the second image  
into the first image:

'>>> iconBallImage.paste(iconShieldImage, (10,10))
Then I save:
'>>> iconBallImage.save('sampleTextures/output.png')
When I view "output.png" in the Gimp, I see that the transparent bits in  
the second image appear as a grey-crosshatching pattern.  There is an  
alpha channel in the new image, but I expected to see that bits of the  
original first image would peer through the transparent bits of the  
original second image.

I fully expect I am doing something wrong here, I just don't know what.
Thanks
Caleb
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel Python on PowerMac?

2004-11-29 Thread Robert Kern
Alan Kennedy wrote:
Although, iff your prospective machine supports System V IPC, you might 
want to check out PoSH.

http://poshmodule.sourceforge.net
It uses inline assembly, so that's a no-go on the PPC unless someone 
ports the assembly code.

--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: slicing, mapping types, ellipsis etc.

2004-11-29 Thread Caleb Hattingh
I'm going to assume the following is self-explanatory - type the commands  
in yourself.

'>>> a = 'hello my name is caleb'
'>>> b = a.split()
'>>> b
['hello', 'my', 'name', 'is', 'caleb']
'>>> b[0]
'hello'
'>>> b[1]
'my'
'>>> b[0:1]
['hello']
'>>> b[0:2]
['hello', 'my']
'>>> b[-1]
'caleb'
'>>> b[:-2]
['hello', 'my', 'name']
'>>> b[2:-2]
['name']
'>>>
thx
Caleb

On 29 Nov 2004 15:49:30 -0500, Jerry Sievers <[EMAIL PROTECTED]>  
wrote:

 Slice objects
Slice objects are used to represent slices when  
extended
  slice syntax is used. This is a slice using two colons, or  
multiple
  slices or ellipses separated by commas, e.g., a[i:j:step],  
a[i:j,
  k:l], or a[..., i:j]. They are also created by the built-in  
slice()
  function.

A quick example on how this is used and/or pointer to more reading is
greatly appreciated.
Thanks

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


Re: asynchat and threading

2004-11-29 Thread Caleb Hattingh
I heartily support something like this, but alas I have not the time to  
help out with it.  I like the Enthought python distribution because it  
installs several packages in one shot.  A pity there isn't a similar thing  
for python addons in Linux (or is there?).

Something apt-get-like would be cool.  Was there talk of having the python  
package index support something like this at some stage?

If I could simply do: py-get twisted
and have all of the dependencies resolved, it would be wonderful.  as a  
prototype, I would suggest wrapping apt-get with a python envelope which  
  automatically invokes apt-get with a python specific configuration  
file for .pydeb files as well as a private repository and database etc..  
  Since apt-get exists for almost every version of Linux and should be  
portable to other platforms, this distribution method should be  
relatively distribution portable.

One can also handle upgrades of the core image of Python and ancillary  
packages as well by leaving a breadcrumb file indicating which packaging  
system is native and the package currently installed. <<- idea needs work

yea? nay?
---eric
--
http://mail.python.org/mailman/listinfo/python-list


using os

2004-11-29 Thread Juliano Freitas
how can i get just the directories in other directorie without a files
using the os module in Python??


Juliano



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


Re: The use of :

2004-11-29 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, bruno modulix wrote:

> 
> In fact, from a purely technical POV, the ':' could have been omitted 
> from the Python syntax, since indentation does the whole job of defining 
> blocks. It's only here for readability AFAIK.
> 

The ':' serves as a very good hint to "python aware" text editors to
automagically indent the next line after hitting return.

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


Re: slicing, mapping types, ellipsis etc.

2004-11-29 Thread Jerry Sievers
"Caleb Hattingh" <[EMAIL PROTECTED]> writes:

> I'm going to assume the following is self-explanatory - type the commands  
> in yourself.

[snip]

Yes, it certainly is self-explanatory.  And, I appreciate your
response.

However, my question pertains to advanced use of the slicing features
which I have found to be not totally explained in the docs.

The use of [start:stop:step] on sequence types is NOT unclear to me at
all.

I'd like to know;

1. what the Ellipsis object or ... syntax is used for
2. what a slice [..., j:k:l] does
3. how slices are applied to object of mapping types

Thank you

-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/

-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using os

2004-11-29 Thread Jeffrey Froman
Juliano Freitas wrote:

> how can i get just the directories in other directorie without a files
> using the os module in Python??

You can test using os.path.isdir, for example:

>>> import os
>>> [x for x in os.listdir('.') if os.path.isdir(x)]  


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


Re: using os

2004-11-29 Thread Jean Brouwers

Check the os.walk() and os.path.walk() functions.  More details and
some examples are at

  

resp.

  


/Jean Brouwers



In article <[EMAIL PROTECTED]>,
Juliano Freitas <[EMAIL PROTECTED]> wrote:

> how can i get just the directories in other directorie without a files
> using the os module in Python??
> 
> 
> Juliano
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter manual question

2004-11-29 Thread Sean McIlroy
The 'Canvas Methods' section of the online Intro to Tkinter
(http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm)
refers (without explanation) to something called "bbox". What is this?
TIA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asynchat and threading

2004-11-29 Thread Jp Calderone
On Mon, 29 Nov 2004 16:05:14 -0500, "Eric S. Johansson" <[EMAIL PROTECTED]> 
wrote:
> If I could simply do: py-get twisted
> and have all of the dependencies resolved, it would be wonderful.  as a 
> prototype, I would suggest wrapping apt-get with a python envelope which 
>   automatically invokes apt-get with a python specific configuration 
> file for .pydeb files as well as a private repository and database etc.. 
>   Since apt-get exists for almost every version of Linux and should be 
> portable to other platforms, this distribution method should be 
> relatively distribution portable.
> 
> One can also handle upgrades of the core image of Python and ancillary 
> packages as well by leaving a breadcrumb file indicating which packaging 
> system is native and the package currently installed. <<- idea needs work
> 
> yea? nay?
> 

  Why not use apt-get?

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


Re: Help on creating a HTML by python

2004-11-29 Thread Jarek Zgoda
sepgy wrote:
Can anyone help me to use a python to create an HTML photo gallery
generator. When it's finished, it will be able find all the picture
files (i.e. .jpg, .gif. .png files) in any given folder on the
computer, automatically create smaller thumbnails for each image, and
then generate a complete HTML file that displays a clickable image
gallery. When viewed in a web browser, the HTML file will display the
thumbnails in a neatly formatted table, and if you click on one of the
thumbnails the full-size image will appear.
Once I had similar idea -- I planned to use PIL for generating 
thumbnails and some templating/transformation library for generating 
HTML. It all ended up with HTMLTemplate 
(http://freespace.virgin.net/hamish.sanderson/htmltemplate.html), as it 
is simple and compact.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Anybody using Arch?

2004-11-29 Thread Gustavo Córdova Avila
Does anybody have an Arch archive with the current python source I could 
slurp it from?

Thanks in advance :-)
--
Gustavo Córdova Avila <[EMAIL PROTECTED]> 

*Tel:* +52 (81) 8130-1919 ext. 127
Integraciones del Norte, S.A. de C.V.
Padua #6047, Colonia Satélite Acueducto
Monterrey, Nuevo León, México.


signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: using os

2004-11-29 Thread Jerry Sievers
Juliano Freitas <[EMAIL PROTECTED]> writes:

> how can i get just the directories in other directorie without a
> files using the os module in Python??

If there's a command for listing only dirs, I've not stumbled on it.

Here's a one-liner using filter and lambda;

from os import listdir
from os.path import isdir

dir = '/tmp/'

onlyDirs = filter(lambda entry: isdir(dir + entry), listdir(dir))

HTH


-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode question

2004-11-29 Thread Bengt Richter
On Tue, 23 Nov 2004 20:37:04 +0100, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= 
<[EMAIL PROTECTED]> wrote:

>Steve Holden wrote:
>> Am I the only person who found it scary that Bengt could apparently 
>> casually drop on a polynomial the would decode to " Löwis"?
Well, don't give me too much credit, though I admit enjoying a little unearned
flattered-ego buzz ;-) But it's not a big deal if you had recently implemented
an automatic lambda-printer-outer to solve for a polynomial function f such that
f(0)==k0, f(1)==k1, .. f(n)==kn. For a single number k0 that will be lambda x: 
k0
and for two numbers k0, k1 will be lambda x: k0 + x*(k1-k0) etc. It's a matter 
of
solving some simultaneous equations for the coefficient values, which I had done
in response to a previous thread. For that, I happened to have had some 
experience
from the '60s writing variations on an equation solver (back when we 
congratulated
ourselves on getting all (software-implemented) floating point ops other than 
divide
to execute in under a millisecond ;-) Here I was using an exact decimal module 
I happened
to have (also built in response to previous thread discussion ;-), so I didn't 
even have
to look for maximum abs pivot elements in the matrix for this one. And it 
didn't have to be fast.
So it was kind of a fun exercise. But anyway, it was all ready to go at this 
point, so
all I had to was do was run coeffsx.py with the character ord values as args on 
the command line.
The opportunity to use it in a fun way to fake casual wizardry was just dumb 
luck ;-)

>
>I'm not scared, but honored, of course.
>
A bit late responding, but I couldn't think of a clever followup to that ;-)
But Just to play fair,

print ''.join([chr((lambda x: (
-6244372133*x**31 +3013910052086*x**30 -695396351572920*x**29
+102105752307741620*x**28 -10715303804974659632*x**27 
+855734314951919397204*x**26
-54067713339116101354860*x**25 +2774121296568607137441900*x**24
-117725625258165396333623970*x**23 +4187405270602160539007125440*x**22
-126060225187601954901807327900*x**21 +3234908736910295469078183101700*x**20
-71121878980966418114205095297640*x**19 
+1344268902923717571167117226451980*x**18
-21886601404074660751245403749948900*x**17 
+307180698948793841846368910776059300*x**16
-3714719218772170154406066269371644945*x**15 
+38641327091060849304069885597725238090*x**14
-344757809926306996671359721670334393500*x**13 
+2627069115710241704477921121071756668600*x**12
-16998869426095431823754237370045113150352*x**11 
+92697362475995606001274610327169882407584*x**10
-421837211162827653880286870838716820642880*x**9 
+1581695033356657201434736494281105646218880*x**8
-4805817748883837636614530805204695373091328*x**7 
+11572394080794032785251889126742747327087616*x**6
-2141782094441901308037452513456003159040*x**5 
+29141767437911436346798089144038222112768000*x**4
-2718608642882609434610843144764478140416*x**3 
+1533994355659295223664305312404777140224*x**2
-388225373807829537910251710026682204160*x 
+23023948231698183889631576064000)
/274094621805930760590852096000
)(x)) for x in xrange(32)])

Not-ready-to-be-mythologized-though-plenty-flatterable-ly y'rs

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


Re: tkinter manual question

2004-11-29 Thread Richard Townsend
On 29 Nov 2004 13:58:05 -0800, Sean McIlroy wrote:

> The 'Canvas Methods' section of the online Intro to Tkinter
> (http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm)
> refers (without explanation) to something called "bbox". What is this?
> TIA

Do you mean this section ?

bbox(items) => tuple, bbox() => tuple

Returns the bounding box for the given items. If the specifier is
omitted, the bounding box for all items are returned. Note that the
bounding box is approximate and may differ a few pixels from the real
value.


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


Re: slicing, mapping types, ellipsis etc.

2004-11-29 Thread Steven Bethard
Jerry Sievers wrote:
1. what the Ellipsis object or ... syntax is used for
2. what a slice [..., j:k:l] does
My understanding is that the Ellipsis object is intended primarily for 
Numeric/numarray use.  Take a look at:

http://stsdas.stsci.edu/numarray/numarray-1.1.html/node26.html
3. how slices are applied to object of mapping types
The short answer is that they aren't.  Slices aren't hashable, so dicts 
can't handle them:

>>> d = {}
>>> d = {1:'a', 2:'b'}
>>> d[1:2]
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unhashable type
>>> hash(slice(1, 2))
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unhashable type
You can, however handle them if you write your own mapping type:
>>> class M(object):
... def __getitem__(self, x):
... if isinstance(x, slice):
... return x.start, x.stop, x.step
... else:
... return x
...
>>>
>>> m = M()
>>> m[1]
1
>>> m[1:2]
(1, 2, None)
Hope this helps!
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Question of Optionparse

2004-11-29 Thread Pekka Niiranen
Hi,
How can I STOP Optionparse to process boolean
value as parameter. See this:
>>> parser = optparse.OptionParser()
>>> parser.add_option("-x",dest='xxx', action="store_true",help="xxx")
>>> parser.add_option("-r",dest='root',help="directory",type="string")
>>> args = ["-r", "d:", "-x"]
>>> parser.parse_args(args)
(, [])
Last line is correct: boolean 'xxx' gets set 'True'
and parameter 'root' to 'd:'
However when value is NOT given for '-r' but '-x' exists:
>>> args = ["-r", "-x"]
>>> parser.parse_args(args)
(, [])
This is BS: I expected 'root' to be None and 'xxx' to be 'True'.
How can I make it so?
Another question: Is there a way to store options
directly into user defined dictionary without assignment
like this:
my_environment_values = {}
(options, args) = parser.parse_args()
environment_values["xxx"] = options.xxx
-pekka-
--
http://mail.python.org/mailman/listinfo/python-list


Re: slicing, mapping types, ellipsis etc.

2004-11-29 Thread Scott David Daniels
Jerry Sievers wrote:
I'd like to know;
1. what the Ellipsis object or ... syntax is used for
Use the Numeric (or numarray) package to really see these in use.
Otherwise, you mostly get to implement it yourself.
> 2. what a slice [..., j:k:l] does
Again, see numeric.  Essentially, select parts of a matrix (or higher
dimensional array) based on a stride in the last dimension.
3. how slices are applied to object of mapping types
One way to investigate this interactively:
class CheckOut(object):
def __init__(self, name=None):
self.name = name or str(self)
def __getitem__(self, *args, **kwargs):
print '%s._gi_(*%r, **%r):' % (self.name, args, kwargs),
return input()
>>> c = CheckOut('a')
>>> b = c[1, ...]
c.gi(*(1, Ellipsis), **{}): self.name * 7
>>> b
'aaa'
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: using os

2004-11-29 Thread Jeremy Jones




Jerry Sievers wrote:

  Juliano Freitas <[EMAIL PROTECTED]> writes:

  
  
how can i get just the directories in other directorie without a
files using the os module in Python??

  
  
If there's a command for listing only dirs, I've not stumbled on it.

Here's a one-liner using filter and lambda;

from os import listdir
from os.path import isdir

dir = '/tmp/'

 entry: isdir(dir + entry), listdir(dir))

HTH


  

Or using list comprehensions:

>>> [f for f in os.listdir('/tmp') if
os.path.isdir(os.path.join('/tmp', f))]
['gconfd-root', '.X11-unix', '.ICE-unix', '.mozilla', '.font-unix']

Just as a side note, and just preference, but I typically (almost
always) prefer using os.path.join() rather than using the "+" operator
to put a path together.


Jeremy Jones


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

Numeric: 'where' function conditions

2004-11-29 Thread Jorl Shefner
Could anyone tell me the efficient way to do this?   Extracting values 
from an array for a single condition (say all values greater than 'x') 
using 'where' and 'compress' is simple enough.  

>>> from Numeric import arange,where,compress
>>> data= arange(10)
>>> data= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> mask= where((data > 3),1,0)
>>> result= compress(mask,data)
>>> result
array([4, 5, 6, 7, 8, 9])

But, 'where' doesn't appear to allow for multiple conditions in one 
statement.  For instance, I'd like to do something like:

mask= where((3 < data <= 7),1,0)

but, this won't work.

So, the best I could come up with was this more complicated process that 
requires 2 separate masks and an extra temporary array.

>>> mask1= where((data > 3),data,0)
>>> mask1
array([0, 0, 0, 0, 4, 5, 6, 7, 8, 9])
>>> mask2= where((mask1<= 7),mask1,0)
>>> mask2
array([0, 0, 0, 0, 4, 5, 6, 7, 0, 0])
>>> r= compress(mask2,data)
>>> r
array([4, 5, 6, 7])

Is there a more concise way?

Thanks,

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


Re: tkinter manual question

2004-11-29 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Sean McIlroy <[EMAIL PROTECTED]> wrote:
>The 'Canvas Methods' section of the online Intro to Tkinter
>(http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm)
>refers (without explanation) to something called "bbox". What is this?
>TIA

"bounding box"

http://downloads.openchannelsoftware.com/WebWinds/rel4/files/BoundingBox.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numeric: 'where' function conditions

2004-11-29 Thread Robert Kern
Jorl Shefner wrote:
Could anyone tell me the efficient way to do this?   Extracting values 
from an array for a single condition (say all values greater than 'x') 
using 'where' and 'compress' is simple enough.  


from Numeric import arange,where,compress
data= arange(10)
data= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
mask= where((data > 3),1,0)
result= compress(mask,data)
result
array([4, 5, 6, 7, 8, 9])
But, 'where' doesn't appear to allow for multiple conditions in one 
statement.  For instance, I'd like to do something like:

mask= where((3 < data <= 7),1,0)
but, this won't work.
Right. "3 < data" creates an array of 0s and 1s where the condition is 
false and true, respectively. You don't need where() at all.

Try
mask = logical_and(3 < data, data <= 7)
--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


pre-PEP generic objects

2004-11-29 Thread Steven Bethard
I promised I'd put together a PEP for a 'generic object' data type for 
Python 2.5 that allows one to replace __getitem__ style access with 
dotted-attribute style access (without declaring another class).  Any 
comments would be appreciated!

Thanks!
Steve
--
Title: Generic Object Data Type
Version: $Revision: 1.0 $
Last-Modified: $Date: 2004/11/29 16:00:00 $
Author: Steven Bethard <[EMAIL PROTECTED]>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 29-Nov-2004
Python-Version: 2.5
Post-History: 29-Nov-2004
Abstract

This PEP proposes a standard library addition to support the simple
creation of 'generic' objects which can be given named attributes
without the need to declare a class. Such attribute-value mappings are
intended to complement the name-value mappings provided by Python's
builtin dict objects.
Motivation
==
Python's dict objects provide a simple way of creating anonymous
name-value mappings. These mappings use the __getitem__ protocol to
access the value associated with a name, so that code generally appears
like::
mapping['name']
Occasionally, a programmer may decide that dotted-attribute style access
is more appropriate to the domain than __getitem__ style access, and
that their mapping should be accessed like::
mapping.name
Currently, if a Python programmer makes this design decision, they are
forced to declare a new class, and then build instances of this class.
When no methods are to be associated with the attribute-value mappings,
declaring a new class can be overkill.  This PEP proposes adding a
simple type to the standard library that can be used to build such
attribute-value mappings.
Providing such a type allows the Python programmer to determine which
type of mapping is most appropriate to their domain and apply this
choice with minimal effort.  Some of the suggested uses include:
Returning Named Results
---
It is often appropriate for a function that returns multiple items to
give names to the different items returned.  The type suggested in this
PEP provides a simple means of doing this that allows the returned
values to be accessed in the usual attribute-style access::
>>> def f(x):
... return Bunch(double=2*x, squared=x**2)
...
>>> y = f(10)
>>> y.double
20
>>> y.squared
100
Representing Hierarchical Data
--
The type suggested in this PEP also allows a simple means of
representing hierarchical data that allows attribute-style access::
>>> x = Bunch(spam=Bunch(rabbit=1, badger=[2, 3, 4]), ham='neewom')
>>> x.spam.badger
[2, 3, 4]
>>> x.ham
'neewom'
Rationale
=
As Bunch objects are intended primarily to replace simple classes,
simple Bunch construction was a primary concern.  As such, the Bunch
constructor supports creation from keyword arguments, dicts, and
sequences of (attribute, value) pairs::
>>> Bunch(eggs=1, spam=2, ham=3)
Bunch(eggs=1, ham=3, spam=2)
>>> Bunch({'eggs':1, 'spam':2, 'ham':3})
Bunch(eggs=1, ham=3, spam=2)
>>> Bunch([('eggs',1), ('spam',2), ('ham',3)])
Bunch(eggs=1, ham=3, spam=2)
To allow attribute-value mappings to be easily combined, the update
method of Bunch objects supports similar arguments.
If Bunch objects are used to represent hierarchical data, comparison of
such objects becomes a concern.  For this reason, Bunch objects support
object equality::
>>> x = Bunch(parrot=Bunch(lumberjack=True, spam=42), peng='shrub')
>>> y = Bunch(peng='shrub', parrot=Bunch(spam=42, lumberjack=True))
>>> z = Bunch(parrot=Bunch(lumberjack=True), peng='shrub')
>>> x == y
True
>>> x == z
False
Additionally, to allow users of the Bunch type to convert other
hierarchical data into Bunch objects, a frommapping classmethod is
supported.  This can be used, for example, to convert an XML DOM tree
into a tree of nested Bunch objects::
>>> import xml.dom.minidom
>>> def getitems(element):
... if not isinstance(element, xml.dom.minidom.Element):
... raise TypeError('items only retrievable from Elements')
... if element.attributes:
... for key, value in element.attributes.items():
... yield key, value
... children = {}
... for child in element.childNodes:
... if child.nodeType == xml.dom.minidom.Node.TEXT_NODE:
... text_list = children.setdefault('text', [])
... text_list.append(child.nodeValue)
... else:
... children.setdefault(child.nodeName, []).append(
... Bunch.frommapping(child, getitems=getitems))
... for name, child_list in children.items():
... yield name, child_list
...
>>> doc = xml.dom.minidom.parseString("""\
... 
...   
... a text 1
... 
...  b text 
... a text 

Re: slicing, mapping types, ellipsis etc.

2004-11-29 Thread Bengt Richter
On 29 Nov 2004 16:45:52 -0500, Jerry Sievers <[EMAIL PROTECTED]> wrote:

>"Caleb Hattingh" <[EMAIL PROTECTED]> writes:
>
>> I'm going to assume the following is self-explanatory - type the commands  
>> in yourself.
>
>[snip]
>
>Yes, it certainly is self-explanatory.  And, I appreciate your
>response.
>
>However, my question pertains to advanced use of the slicing features
>which I have found to be not totally explained in the docs.
>
>The use of [start:stop:step] on sequence types is NOT unclear to me at
>all.
>
>I'd like to know;
>
>1. what the Ellipsis object or ... syntax is used for
>2. what a slice [..., j:k:l] does
>3. how slices are applied to object of mapping types
>
 >>> class C(object):
 ... def __getitem__(self, i): print i; return None
 ...
 >>> c=C()
 >>> c[1]
 1
 >>> c[1:2]
 slice(1, 2, None)
 >>> c[1:2:3]
 slice(1, 2, 3)
 >>> c[:2:3]
 slice(None, 2, 3)
 >>> c[::3]
 slice(None, None, 3)
 >>> c[::]
 slice(None, None, None)
 >>> c[1,::]
 (1, slice(None, None, None))
 >>> c[1,...,::]
 (1, Ellipsis, slice(None, None, None))
 >>> c[1, 2, ..., 3:4]
 (1, 2, Ellipsis, slice(3, 4, None))
 >>> c[...]
 Ellipsis

An object implementing __getitem__ (and/or __setitem__) will be passed arguments
as above and is free to use them in any way that makes sense to it's author.
Making sense to the users of the author's software is another thing ;-)

AFAIK Ellipsis is just a special builtin object that can be used as a handy
standard place holder in the get/setitem context. But any other builtin
could be passed also, e.g., 

 >>> c[1,2,abs,3]
 (1, 2, , 3)

so AFAIK it's just that an Ellipsis reference is generated when you use ... in 
the
getitem context. The compiler generates a reference to the built-in constant, so
you can make a test for it for your object's logic, e.g.

 >>> class C(object):
 ... def __getitem__(self, i):
 ... if i is Ellipsis or isinstance(i, tuple) and Ellipsis in i:
 ... print 'got ... in the index arg %r'%(i,)
 ... else:
 ... print 'did not get ... in the index arg %r'%(i,)
 ...
 >>> c=C()
 >>> c[1,2]
 did not get ... in the index arg (1, 2)
 >>> c[::]
 did not get ... in the index arg slice(None, None, None)
 >>> c[::, ...]
 got ... in the index arg (slice(None, None, None), Ellipsis)
 >>> c[...]
 got ... in the index arg Ellipsis
 >>> c[Ellipsis]
 got ... in the index arg Ellipsis

But interestingly, compare the appearance of Ellipsis in the disassembly
of foo and bar (LOAD_GLOBAL vs LOAD_CONST). The global you can shadow or
rebind, but the const is apparently known by the compiler, and it is arranged
that they both refer to the same object by default, so the 'is' test succeeds.

 >>> class C(object):
 ... def __getitem__(self, i): return i
 ... def foo(self): return self[...]
 ... def bar(self): return self.foo() is Ellipsis
 ...
 >>> c= C()
 >>> c[...] is Ellipsis
 True
 >>> c.foo() is Ellipsis
 True
 >>> c.bar()
 True
 >>> import dis
 >>> dis.dis(C)
 Disassembly of __getitem__:
   2   0 LOAD_FAST1 (i)
   3 RETURN_VALUE

 Disassembly of bar:
   4   0 LOAD_FAST0 (self)
   3 LOAD_ATTR1 (foo)
   6 CALL_FUNCTION0
   9 LOAD_GLOBAL  2 (Ellipsis)
  12 COMPARE_OP   8 (is)
  15 RETURN_VALUE

 Disassembly of foo:
   3   0 LOAD_FAST0 (self)
   3 LOAD_CONST   1 (Ellipsis)
   6 BINARY_SUBSCR
   7 RETURN_VALUE

HTH

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


python API wrapper for C++ API

2004-11-29 Thread Mark Doberenz



I'm fairly new at 
Python, but I've got a project I really want to do.
 
I'm working with a 
real-time 3D program called Deep Creator, and it has a C++ API written for 
it.  I'm wondering what it would take to create a Python wrapper that would 
allow me to write Python programs that would call the C++ 
API.
 
The main issue I'm 
running into is that I need to create a DLL that I load as a plugin into Deep 
Creator.  I then will specify a python program inside Deep Creator that I 
want to run, and the DLL plugin will be the link between the python program and 
Deep Creator.
 
I'd really 
appreciate any ideas or issues that people see with this set 
up.
 
Thanks,
Mark
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: knowing a file's own name

2004-11-29 Thread Scott Frankel
Thanks for the responses!
I'd forgotten about using the sys module:
import sys
filename = sys.argv[0]
Using "__file__" also works.
Thanks
Scott
On Nov 29, 2004, at 9:37 AM, Scott Frankel wrote:
I'm looking for a way to identify a filename remotely.  Put 
differently,
is there a way a file can get its own name from its globals()?

doit.py calls exec() on a second py script, tpairs.py, to obtain a 
dict of the
globals in tpairs.py.  How can I add the filename, "tpairs.py," to the 
resulting dict?
i.e.:

# - - - - - - - - - - - - - - - -
# -- tpairs.py
# - - - - - - - - - - - - - - - -
this  = "this"
that  = "that"
gdict = globals()
# - - - - - - - - - - - - - - - -
# -- doit.py
# - - - - - - - - - - - - - - - -
#!/usr/bin/env python
theFile = "./tpairs.py"
theDict = {}
execfile(theFile, theDict)
# somehow add theFile to gdict, i.e.:
# gdict['theFile'] = theFile
Thanks in advance!
Scott
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 14, Issue 377

2004-11-29 Thread Jamie Saker
On Mon, 29 Nov 2004 16:05:14 -0500, "Eric S. Johansson" <[EMAIL PROTECTED]> 
wrote:
> If I could simply do: py-get twisted

or how about 'emerge twisted'

works fine for me! When twisted2 comes out, emerge world will catch it for me 
too. Check out Gentoo at http://www.gentoo.org for more info, or on IRC at 
#gentoo 

Jamie Saker
"Gentoo bumper sticker: I'd rather be compiling!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Random number generation from functions

2004-11-29 Thread Bengt Richter
On Mon, 29 Nov 2004 20:51:50 GMT, "drs" <[EMAIL PROTECTED]> wrote:

>Is there any way to generate random numbers based on arbitrary real valued
>functions? I am looking for something like random.gauss() but with natural
>log and exponential functions.
>
>thanks,
Don't know what you mean. This kind of thing?
(the 1-random... is to make the random numbers in (0,1] instead of [0,1))

 >>> import random
 >>> import math
 >>> math.log(1.0-random.uniform(0,1))
 -0.90030288455841156
 >>> math.log(1.0-random.uniform(0,1))
 -0.261249141864835
 >>> math.log(1.0-random.uniform(0,1))
 -0.99694366818547997

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


documentation for PyArg_ParseTupleAndKeywords

2004-11-29 Thread Steven Bethard
I'm just starting to play around with the Python source.  (Specifically, 
I'm looking at adding a key argument to max/min like sorted has.)  Can 
anyone direct me to the documentation on how 
PyArg_ParseTupleAndKeywords, etc. work?  In particular, I can't figure 
out how the format arg to vgetargskeywords should be specified...

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


Re: A lock that times out but doesn't poll

2004-11-29 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Jive <[EMAIL PROTECTED]> wrote:
.
.
.
>B) Writing bug-free code is quite possible when the job is well-defined and
>"from scratch."
.
.
.
?  !?  Who has "well-defined" jobs?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 14, Issue 377

2004-11-29 Thread Jamie Saker
On Mon, 29 Nov 2004 16:05:14 -0500, "Eric S. Johansson" <[EMAIL PROTECTED]> 
wrote:
> If I could simply do: py-get twisted

And I forgot to mention, the Gentoo 'emerge' tool is actually written in 
Python, so in a sense, your py-get is already there in Gentoo.

From the header of /usr/bin/python:

#!/usr/bin/python -O
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-src/portage/bin/emerge,v 1.347 2004/10/21 
20:54:38 carpaski Exp $

Gentoo is a rather enjoyable distro for Python work. Most Python packages are 
an emerge away: twisted, zope (including zope3), bsddb, mysql & postgresql 
interfaces, python-ldap, pyparsing and many others. 

A few to make Gentoo more enjoyable:

1. standardize on a kernel (e.g. I use hardened-dev-sources for servers and 
gentoo-dev-sources for workstations - all 2.6 kernels,) This simplifies 
maintenance and opens up distcc for you (which will be handy if you have a 
few systems that will be running Gentoo and want to speed up source builds). 
You'll need a common kernel and gcc version in order to not have distcc 
issues.

2. read up on USE= flags. It simplifies dependencies significantly, but you 
want to make sure you're using it to its fullest, not leaving out important 
options or including everything and the kitchen sink. For instance, if you're 
not using ipv6, don't bother - including this in your USE= statement will 
slow down source builds significantly for no benefit (not to mention some 
bloat and potentially some security issues for unmonitored capabilities e.g. 
enabling samba USE without discretion).

3. set your ACCEPT_KEYWORDS = 'x86' (assuming intel/x86) to back off minor 
version builds. of course, if you need bleeding edge packages, you may have 
to use ~x86. x86 is the "stable" setting. 

4. for help, forums.gentoo.org is useful (though the search engine is rather 
lacking imho)

Having started with two 5.25's in 1993, I've been a die-hard user of SLS, 
Slackware, Redhat, Debian and now Gentoo. You'll hear plenty of distro war 
stuff and certainly every tool has its pros/cons. For python, if you haven't 
given Gentoo a look, check it out...

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


Re: Number of colors in an image

2004-11-29 Thread David Bolen
Christos "TZOTZIOY" Georgiou <[EMAIL PROTECTED]> writes:

> A set seems more appropriate in this case:
> 
> color_count = len(set(izip(r, g, b))) # untested code

Well, while potentially premature optimization, I was trying for
performance in this case.  In Python 2.3, the sets module is coded in
Python, and just wraps a dictionary, and when handed an iterable, ends
up looping (in Python) with individual dictionary key assignments.
Although I didn't specifically test sets, when I did a loop like that
myself, it was 5-6 times slower than directly building the dictionary.

That might change in 2.4 with the built-in set - it's still a wrapper
around dict but knows it's just directly setting items to a true value
so can avoid dealing with the tuples that dict does (not to mention I
don't have to build the extra tuple).

Although I expect the direct support in PIL 1.1.5 that Fredrik posted
about will be best.

> >For a greyscale, or single banded image, it should be faster just to
> >use the built-in PIL "histogram" method and take the length of the
> >resulting list.
> 
> More like the count of non-zero elements in the histogram; I believe the
> length of the resulting list will be constant (ie 256).

Oops, definitely yes.

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


  1   2   >