ANN: Urwid 0.9.1 - Console UI Library

2006-03-09 Thread Ian Ward
Announcing Urwid 0.9.1
--

Urwid home page:
  http://excess.org/urwid/

Tarball:
  http://excess.org/urwid/urwid-0.9.1.tar.gz


About this release:
===

This release includes high resolution UTF-8 support for the BarGraph and
ProgressBar widgets, improved support for threading with raw_display and
a couple bug fixes.


New in this release:


  - BarGraph and ProgressBar can now display data more accurately by using
the UTF-8 vertical and horizontal eighth characters.  This behavior
will be enabled when the UTF-8 encoding is detected and smoothed
attributes are passed to the BarGraph or ProgressBar constructors.

  - New get_encoding_mode() function to determine how Urwid will treat
raw string data.

  - New raw_display.signal_init() and raw_display.signal_restore() methods
that may be overridden by threaded applications that need to call
signal.signal(..) from their main thread.

  - Fixed a bug that prevented the use of UTF-8 strings in text markup.

  - Removed some forgotten asserts that broke 8-bit and CJK input.


About Urwid
===

Urwid is a console UI library for Python. It features fluid interface
resizing, UTF-8 support, multiple text layouts, simple attribute markup,
powerful scrolling list boxes and flexible interface design.

Urwid is released under the GNU LGPL.


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

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


My OSDC.il Python Talks

2006-03-09 Thread Miki Tebeka
Hello All,

Last week I gave three Python talks at OSDC.il (http://osdc.org.il/).

If you are truly bored you can find the talks and demo source code at 
http://one.fsphost.com/tebeka/OSDC/

Bye.
--

Miki Tebeka [EMAIL PROTECTED]
http://one.fsphost.com/tebeka/
The only difference between children and adults is the price of the toys
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: processing the genetic code with python?

2006-03-09 Thread Tim Roberts
David E. Konerding DSD staff [EMAIL PROTECTED] wrote:

I don't really understand precisely what you're trying to do.  

First off, those aren't base pairs, they're bases.  Only when you have 
double-stranded
DNA (or RNA, or some other oddball cases) would they be base pairs.

Isn't that just a standard way to write DNA pairs?  After all, every a is
paired with a t, and every c is paired with a g, so it is redundant
to specify both ends of the pair.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Weekly Python Patch/Bug Summary

2006-03-09 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  386 open ( +4) /  3089 closed (+10) /  3475 total (+14)
Bugs:  889 open ( +9) /  5636 closed (+12) /  6525 total (+21)
RFE :  212 open ( +1) /   201 closed ( +0) /   413 total ( +1)

New / Reopened Patches
__

db4.4 support for bsddb  (2006-03-02)
CLOSED http://python.org/sf/1441660  opened by  Jérome Laheurte

Faster list comprehensions  (2006-03-03)
CLOSED http://python.org/sf/1442442  opened by  Collin Winter

Add support for the If-Modified-Since header  (2006-03-03)
   http://python.org/sf/1442867  opened by  Shannon -jj Behrens

PyLong_FromString optimization  (2006-03-04)
   http://python.org/sf/1442927  opened by  Alan McIntyre

Incremental codecs for CJKCodecs  (2006-03-05)
   http://python.org/sf/1443155  opened by  Hye-Shik Chang

Remove bad PREDICT in ceval.c  (2006-03-04)
   http://python.org/sf/1443159  opened by  Collin Winter

gc.get_count() and other changes  (2006-03-05)
CLOSED http://python.org/sf/1443865  opened by  Barry A. Warsaw

email/charset.py convert() patch  (2006-03-06)
   http://python.org/sf/1443875  opened by  Tokio Kikuchi

Various minor fixes for NULL checks, etc.  (2006-03-06)
   http://python.org/sf/1444030  opened by  Hye-Shik Chang

Make itertools.tee participate in GC  (2006-03-06)
   http://python.org/sf/1444398  opened by  Thomas Wouters

kwdargs for compile/__import__  (2006-03-07)
   http://python.org/sf/1444529  opened by  Thomas Wouters

New with semantics  (2006-03-08)
   http://python.org/sf/1445739  opened by  Guido van Rossum

Patches Closed
__

db4.4 support for bsddb  (2006-03-02)
   http://python.org/sf/1441660  closed by  nnorwitz

Inconsistency in os' function naming  (2006-03-01)
   http://python.org/sf/1440928  closed by  gvanrossum

PEP 357 --- adding nb_index  (2006-02-21)
   http://python.org/sf/1436368  closed by  gvanrossum

Faster list comprehensions  (2006-03-03)
   http://python.org/sf/1442442  closed by  nnorwitz

The email package needs an application type  (2006-02-04)
   http://python.org/sf/1424065  closed by  bwarsaw

Size of time_t changed to 64 bits in MSVC++ 2005 CRT  (2006-02-24)
   http://python.org/sf/1437769  closed by  loewis

gc.get_count() and other changes  (2006-03-05)
   http://python.org/sf/1443865  closed by  bwarsaw

StreamReader.readline with size reading multiple lines  (2005-12-13)
   http://python.org/sf/1379332  closed by  doerwalter

Make property use the getter's __doc__ if no doc argument  (2006-02-18)
   http://python.org/sf/1434038  closed by  gbrandl

New / Reopened Bugs
___

yet another svn head compiler change  (2006-03-02)
   http://python.org/sf/1441486  opened by  Michael Hudson

socket read() can cause MemoryError in Windows  (2006-03-02)
   http://python.org/sf/1441530  opened by  taukki

Omission in docs for urllib2.urlopen()  (2006-03-02)
   http://python.org/sf/1441864  opened by  Kent Johnson

A (treaded) Python crash only on dual core machines  (2006-03-02)
CLOSED http://python.org/sf/1441884  opened by  Robert Kiendl

Multiple simultaneous sendtos on AF_UNIX socket broken.  (2006-03-02)
   http://python.org/sf/1441984  opened by  Brian Brunswick

Traceback in pydoc  (2006-03-02)
CLOSED http://python.org/sf/1442012  opened by  Thomas Heller

IDLE shell window gets very slow when displaying long lines  (2006-03-03)
   http://python.org/sf/1442493  opened by  Heiko Selber

os.listdir doesn't release GIL  (2006-02-15)
CLOSED http://python.org/sf/1432525  reopened by  gvanrossum

docs for os.statvfs miss f_bsize parameter  (2006-03-03)
CLOSED http://python.org/sf/1442767  opened by  Chris Cogdon

handling comments with markupbase and HTMLParser  (2006-03-03)
   http://python.org/sf/1442874  opened by  Daniel

Bad Coroutine link  (2006-03-04)
CLOSED http://python.org/sf/1442937  opened by  Paddy McCarthy

Pickle protocol 2 fails on private slots.  (2006-03-05)
   http://python.org/sf/1443328  opened by  Daniele Varrazzo

locale.getpreferredencoding() dies when setlocale fails  (2006-03-05)
   http://python.org/sf/1443504  opened by  Catherine Devlin

email 3.0+ stops parsing headers prematurely  (2006-03-05)
   http://python.org/sf/1443866  opened by  Mark Sapiro

os.open() Documentation  (2006-03-06)
   http://python.org/sf/1444104  opened by  Thomas Guettler

subprocess test cases fail with noexec-mounted /tmp  (2006-03-06)
   http://python.org/sf/108  opened by  Wummel

Pointer freed twice in Py_InitializeEx()  (2006-03-07)
   http://python.org/sf/1444893  opened by  athorp

getpass.getpass queries on STDOUT not STERR (*nix)  (2006-03-07)
   http://python.org/sf/1445068  opened by  Jon Lasser

embedding Python causes memory leaks  (2006-03-08)
   http://python.org/sf/1445210  opened by  Andrew Trevorrow

install fails on hard link  (2006-03-08)
   

Re: It is fun.the result of str.lower(str())

2006-03-09 Thread Tim Roberts
Sullivan WxPyQtKinter [EMAIL PROTECTED] wrote:

Guess what would be the result of these functions:

str.lower('ASFA')
str.join(str(),['1','1','1'])
str.join('a','b')

If you guess them correctly, please explain.

Can you tell us what you expected these to do?  It might help future
questioners.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Threading.Lock() question

2006-03-09 Thread Alvin A. Delagon
I have a multithreaded application that spawns threads which query a 
database server. During stress test I encountered some threads failing 
due lost connection errors and sometimes the actual script itself dies 
due to a Segmentation Fault. I realized that it might be a deadlock 
situation so I applied a lock mechanism but after another stress test, 
some threads are still failing. Here's a rough sketch of my script:

class Process(threading.Thread):
def __init__(self,lock,query)
   self.lock = lock
   self.query = query
   threading.Thread.__init__(self)
def run(self):
   ''' Some data processing code here '''
   self.lock.acquire()
   result = cursor.execute(query)
   self.lock.release()

class Send(Request__POA.Send):
   def push(self,query,...some args here):
  lock = threading.Lock()
  Process(lock,query).start()

db = MySQL().connect()
cursor = db.make_cursor()

The class Send is being called by a CORBA client. The script is actually 
a CORBA server which in the future would serve a high traffic of 
requests. Is my usage is locking correct or am I doing something stupid 
in the code? Thanks is advance!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cgi problem

2006-03-09 Thread Tim Roberts
Paul Rubin http://[EMAIL PROTECTED] wrote:

Thomas Guettler [EMAIL PROTECTED] writes:
  back to the originating url, i.e. I want the cgi to send a 302 redirect.

 I have this setup for a small script (for bigger things I use quixote)...

Thanks.  It looks like you've written your cgi completely from
scratch.  I was hoping to use the cgi module, which has some
convenient features for reading the query parameters and POST content.

Yes, but the CGI module doesn't write anything, so the advice of writing a
Location: header still applies.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cgi problem

2006-03-09 Thread Paul Rubin
Tim Roberts [EMAIL PROTECTED] writes:
 Yes, but the CGI module doesn't write anything, so the advice of writing a
 Location: header still applies.

Aha, it's coming from CGIHTTPServer.py:CGIHTTPRequestHandler.run_cgi()
where it says

self.send_response(200, Script output follows)

I got the two modules confused.  This still leaves me with the same
basic problem, how to suppress the sending of that header.

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


Re: Bidirectional communication over unix socket (named pipe)

2006-03-09 Thread Ross Ridge

Donn Cave wrote:
 The other part of the problem remains, as I don't know
 how to get data to actually go both ways.

The problem here is that datagram sockets don't send data from one
process to another, they send data from one address to another.  In
this case, the client isn't able to receive data through it's socket
because the socket isn't bound any address.  Calling connect() on the
datagram socket doesn't give the socket an address to receive data
with, just a default address to send data to.  Since the server's
socket is the only socket bound to /tmp/mysock it's the only the only
process that can receive datagrams sent to that address.  That includes
any datagrams the server itself sends to the address.

You need multiple Unix domain address so each process has an address it
can receive data with, and an address other than it's own that it can
send data to.

  Ross Ridge

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


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread bruno at modulix
Brian Elmegaard wrote:
 bruno at modulix [EMAIL PROTECTED] writes:
 
 
Now how you could do it the OO way (QD, not really tested):
 
 
 Something goes wrong in my 2.3 

So it's time to move to 2.4x !-)

What is going wrong exactly ?

 when I change the syntax to
 _add_instance=classmethod(_add_instance).

 If I understand this correctly the class is keeping track of the
 instances of itself.

Yeps.

 The class is extendible and has all the needed
 methods. This means that any global lists can be
 avoided. 

Yeps too. This is called encapsulation.

But this also means you only have one list of instances - which may or
may not be ok for what you're trying to do. Note that there are possible
workarounds, like using a dict of lists:

class Foo(object):
  _instance_lists = {}

  def __init__(self, x, list_id):
self.x = x # no, you won't avoid it
self._add_instance(self, list_id)

  @classmethod
  def _add_instance(cls, instance, list_id):
 cls._instance_lists.setdefault(list_id, []).append(instance)

  @classmethod
  def get_instances(cls, list_id):
return cls._instance_lists[list_id].[:]

  # now you need to add the list_id parameter to all others classmethods

Also, if you intend to use such a solution (with or without multiple
lists), you may want to add a classmethod to delete instances from the
list(s).



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


implementation of complex type

2006-03-09 Thread Russ
I tried the following:

 x = complex(4)
 y = x
 y *= 2
 print x, y
(4+0j) (8+0j)

But when I tried the same thing with my own class in place of
complex above, I found that both x and y were doubled. I'd like to
make my class behave like the complex class. Can someone tell me the
trick? Also, where can I find the code for for the complex class? I
hope it's written in Python! Thanks.

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


Re: Learning different languages

2006-03-09 Thread Christoph Hess

Harry George [EMAIL PROTECTED] wrote:

 gene tani [EMAIL PROTECTED] writes:

 Rich wrote:
  Hi,
 
  (this is a probably a bit OT here, but comp.lang seems rather
  desolated, so I'm not sure I would get an answer there. And right now
  I'm in the middle of learning Python anyway so...)
 
  Anyway, my question is: what experience you people have with working
  with different languages at the same time?

 http://www.infoworld.com/article/06/02/22/75452_09OPstrategic_1.html


 re the article:

 To say Java and Python could use the same libraries misses a) dynamic
 programming in python and b) the re-invent-the-wheel ethos of the whole
 Java world.

Jon Udell talks about Javascript not about Java. 


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


Re: Threading.Lock() question

2006-03-09 Thread Alvin A. Delagon
I think I just found out my problem. How stupid of me, I should've 
created an instance of lock in the class Process instead of class Send. 
Good Heaven's python's threading rocks! I stress tested the server 
script having two clients sending requests on a while 1 loop without 
even a time.sleep() and yet it still runs! ^_^

class Process(threading.Thread):
   lock = threading.Lock() # Lock instance should be placed here
   def __init__(self,query)
  self.query = query
  threading.Thread.__init__(self)
   def run(self):
  ''' Some data processing code here '''
  Process.lock.acquire()
  cursor.execute(query)
  Process.lock.release()

class Send(Request__POA.Send):
   def push(self,query,...some args here):
  Process(query).start()

db = MySQL().connect()
cursor = db.make_cursor()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: implementation of complex type

2006-03-09 Thread Mikael Olofsson
Russ wrote:
x = complex(4)
y = x
y *= 2
print x, y
 
 (4+0j) (8+0j)
 
 But when I tried the same thing with my own class in place of
 complex above, I found that both x and y were doubled. I'd like to
 make my class behave like the complex class. Can someone tell me the
 trick? Also, where can I find the code for for the complex class? I
 hope it's written in Python! Thanks.

Have your __imul__ and such return new objects, and not perform in-place 
modification if you do not want x and y to refer to the same object 
after y*=2.

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


accesibility of the namespace

2006-03-09 Thread Petr Jakes
In my code I have relatively wide dictionary definition (about 100
rows).

I would like to put it in to the different file (module) because of the
main code readability (say the name of the file will be
my_dictionary.py)

In the dictionary I have strings formatted using % operator like:
lcd={2:Your credit= %3d % (credit)}

While I am trying to import my_dictionary in to the main code, I am
getting:

exception unhandled NameError
name credit is not defined

How can I organize my code so the credit variable will be visible
in the my_dictionary namespace?

Thanks

Petr Jakes

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


Python Evangelism

2006-03-09 Thread Steve Holden
I've been thinking (and blogging) about python evangelism since PyCon, 
as a result of which I created a squidoo lens:

   http://www.squidoo.com/pythonlogy

Imagine my surprise at discovering that this has gone up in rank (by 
number of views) from # 442,000 or so to #153! Clearly there's some 
mileage in marketing Python, and I'd like to keep the buzz going if it 
means more people will adopt the language.

Any suggestions for improvement?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Re: New python.org website

2006-03-09 Thread Doug Bromley
I much prefer the look and feel of the potential Ruby websites being developed at the moment. The Python site is very corporate and academic which could put many early adopters off. I'm sure you've all heard accusations that Python doesn't have the marketing drive of Ruby. Perhaps this is an example where we could do with taking a leaf out of Ruby's book? (
http://redhanded.hobix.com/redesign2005/)-Doug Bromleyblog.straw-dogs.co.uk
On 8 Mar 2006 14:20:29 -0800, Kay Schluehr [EMAIL PROTECTED] wrote:
Michael Tobis wrote:  No one  of the complainers and negativists do claim that they could do it much  better. Indeed, I do not have to be able to write a particular program to
 notice it has bugs. On the other hand, (since I think the design, while not brilliant, is good) fixing the logo is something that can be achieved without too much fuss.
  But I think at times it might be usefull to consult  professional aid. In the case of the logo design, I am not sure I agree. I think the twisted logo 
http://saph.twistedmatrix.com/blog/archives/twisted.png and the PyCon logo 
http://mirrors.ccs.neu.edu/Python/pub/old-www/pics/pycon-logo.gif were probably not designed by professional designers but rather by people who appreciate Python, and yet do have more appeal to the
 community and the outside world alike. If we are going to use a snake motif, we should use snakes that look like snakes.Maybe its time for me to abandone this discussion. If you and othersfeel quite well represented by a pasty and wordy snake than go for it.
I do neither feel embraced nor bitten by it. And I don't just mean thelogo. We can do an awfull lot of comparisons with pages that failed butthis doesn't bring forth anything.This evening we talked at the Hofbraeuhaus at Munich about Michelangelo
whose sixtine chapel images where once overpainted because his figuresappeared naked as god created them. But maybe he was wrong and hiscustomer, the pope, was right and they were actually born with a leaf
covered their pubic hairs? The pope had to take responsibility and hadto appease possible and real critics. We can assume he was far frombeing an idiot but a serious man - a politician. As a serious person
myself I'm always a little splitted between Michelangelo and the pope.My own idealism expects Michelangelo doing such outstanding things thatit is beyond anything. Nothing could be better than having the uptights
as the most severe enemies. What a fun! But as it seems my politicalparty is guided by ordinary indifferent humans as well and Michelangelomay be as much attracted by it as I am by e.g. the german socialdemocratic party? So I should track back and rethink the professional
aid which might be not what I'm really looking for. Guido feels a deepjoy about the resonance between Python and an programmer and artist -Juergen Scheible - who likes the language, feels inspired by it and
creates a little artwork for Nokia 60s. So there is some inversion inthe right direction. Suddenly Python appears a bit distorted withinanother context and it becomes sexy again. Should we talk about Apple
next ... ?--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Threading.Lock() question

2006-03-09 Thread Alvin A. Delagon
@ Dennis

Thanks for the quick heads up! You're right! I noticed the bug on my 
script just after sending out my question. Yes, I'm using MySQLdb but I 
did a wrapper for it to further simplify my script that why the sample 
script I wrote is a little bit different. Thanks again! Python rules!!! ^_^
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: implementation of complex type

2006-03-09 Thread Juho Schultz
Russ wrote:
 I tried the following:
 
 
x = complex(4)
y = x
y *= 2
print x, y
 
 (4+0j) (8+0j)
 
 But when I tried the same thing with my own class in place of
 complex above, I found that both x and y were doubled. I'd like to
 make my class behave like the complex class. Can someone tell me the
 trick? Also, where can I find the code for for the complex class? I
 hope it's written in Python! Thanks.
 

This is like the difference of tuples and lists.

Your own class is mutable.
y=x # Names x and y are now bound to the same object.
y*=2 # change the object bound to names x and y.

Builtin complex is immutable, so you can not manipulate the contents.
y*=2 # creates a new object (value = 2*y), binds it to name y.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to dervie from an instance object?

2006-03-09 Thread reinsn
Hi,

I am currently working with ZopeX3. Because python doesn't include
concept of interfaces, those were defined by the module zope.interface.

So interfaces were defined like:

class IMyInterface(zope.interface.Interface):
   .


I have looked into the module zope.interface and found, that
zope.interface.Interface is an object instance and no class object! But
how does this work? How can I derive from an object instance?

I mean is something like this possible in Python?

class X: pass

x = X()

class Y (x):
  .


Thanks for the replies in advance!

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


Re: Python Evangelism

2006-03-09 Thread Just
In article [EMAIL PROTECTED],
 Steve Holden [EMAIL PROTECTED] wrote:

 I've been thinking (and blogging) about python evangelism since PyCon, 
 as a result of which I created a squidoo lens:
 
http://www.squidoo.com/pythonlogy
 
 Imagine my surprise at discovering that this has gone up in rank (by 
 number of views) from # 442,000 or so to #153! Clearly there's some 
 mileage in marketing Python, and I'd like to keep the buzz going if it 
 means more people will adopt the language.
 
 Any suggestions for improvement?

Yeah, the URL:

 http://www.squidoo.com/pythonology

:)

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


embedding Python: how to avoid memory leaks?

2006-03-09 Thread Andrew Trevorrow
No response to my last message, so I'll try a different tack...

Does anyone know of, or even better, has anyone here written a
C++ application for Mac/Windows that allows users to run Python
scripts from within the app?  Not just once, but many times in
a single session, and without leaking memory.  Preferably an
open source app so I can see how it's done.

Our app (http://golly.sourceforge.net/) currently uses calls
like these every time a user decides to run a script:

   Py_Initialize();
   PyRun_SimpleString(execfile('foo.py'));
   Py_Finalize();

But even if foo.py is *empty* the above calls result in a memory
leak of about 12K on Mac OS 10.3.9 (using Python 2.3) and about
11K on Windows 2000 (using Python 2.4.2).  I wouldn't mind if
there was a one-off cost due to calling Py_Initialize the very
first time, but we see leaks every time a script is executed.

I've tried calling Py_Initialize just once (at app startup)
and Py_Finalize once on exit, but that doesn't really solve
anything.  It avoids leaks when using trivial scripts (like
an empty .py file!) but we want to run some rather complicated
scripts that consume lots of memory, so we need a reliable way
to release that memory.  I was surprised to discover that
Py_Finalize doesn't always do that.

Is there some magic Python code that can restore memory usage
to what it was before each execfile call?  Something like
PostScript's save and restore.

I've been struggling with this problem for about a week now.
Having been seduced by Python's power and beauty I'd hate to
have to abandon it and switch to Perl or some other crappy
scripting language!  Please help...

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


Re: generators shared among threads

2006-03-09 Thread jess . austin
Bryan,

You'll get the same result without the lock.  I'm not sure what this
indicates.  It may show that the contention on the lock and the race
condition on i aren't always problems.  It may show that generators, at
least in CPython 2.4, provide thread safety for free.  It does seem to
disprove my statement that, the yield leaves the lock locked.

More than that, I don't know.  When threading is involved, different
runs of the same code can yield different results.  Can we be sure that
each thread starts where the last one left off?  Why wouldn't a thread
just start where it had left off before?  Of course, this case would
have the potential for problems that Alex talked about earlier.  Why
would a generator object be any more reentrant than a function object?
Because it has a gi_frame attribute?  Would generators be thread-safe
only in CPython?

I started the discussion with simpler versions of these same questions.
 I'm convinced that using Queue is safe, but now I'm not convinced that
just using a generator is not safe.

cheers,
Jess

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


Re: license preamble template

2006-03-09 Thread Alan Mackenzie
Xah Lee [EMAIL PROTECTED] wrote on 4 Mar 2006 10:21:11 -0800:
 I noticed, that in just about all emacs programs on the web (elisp
 code), it comes with this template text as its preamble:

[  ]

 ;; This program is distributed in the hope that it will be useful, but
 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 ;; General Public License for more details.

[  ]

 Concerned parties and the FSF foundation, please remove the middle
 section of this template. That section is mainly for lawyers, for
 programers to protect themselves in the context of modern society's law
 system. Legally speaking, that section is redundant because it is in
 the GNU General Public License itself.

That section is there to draw people's attention to the lack of a
warranty, to cause them to contrast it with the warranty offered by
non-free software, which typically is restricted to replacing the
distribution CD if it can't be read.

 The effect of that section in a license summary is fueling the habit
 and sanction of irresponsible programing we see all around us.

My impression is that irresponsible programming tends to come with a
guarantee to replace the distribution CD if it can't be read.

 In place of that section, i'd propose replacing it with the following
 gist:

 ??This program is distributed in the hope that it will be useful. The
 author(s) has responsibly produced it, and will take reasonable
 responsibilities with regards to the program's intended purpose and
 workability. For legal aspects of WARRANTY, please see the GNU General
 Public License for more details.??

Nah, that's too defensive and wooly.  If you get an Email from a stranger
that says checked virus-free by , would you believe that?  No?
Then why would you believe a programmer who feels he has to assert he has
done his work responsibly, whatever that might mean?  It's legally
dubious, and wouldn't inspire any confidence whatsoever.  Responsibility
is shown by actions and results, not promises.

[  ]

Xah

-- 
Alan Mackenzie (Munich, Germany)
Email: [EMAIL PROTECTED]; to decode, wherever there is a repeated letter
(like aa), remove half of them (leaving, say, a).

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


Re: Python Evangelism

2006-03-09 Thread Gerard Flanagan
Steve Holden wrote:
 I've been thinking (and blogging) about python evangelism since PyCon,
 as a result of which I created a squidoo lens:

http://www.squidoo.com/pythonlogy

 Imagine my surprise at discovering that this has gone up in rank (by
 number of views) from # 442,000 or so to #153! Clearly there's some
 mileage in marketing Python, and I'd like to keep the buzz going if it
 means more people will adopt the language.

 Any suggestions for improvement?


 '-nology' not '-nlogy' in the link.

I like the 'What's Happening on Planet Python' section - I find the
planetpython.org gives too much of an intro to the pages it links to. A
line or too, as in the lens site,  would be preferable in my view.
Just a thought - would a similar section be suitable for 'python.org'
main page?

Gerard

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


Re: Python Evangelism

2006-03-09 Thread Doug Bromley
Python is in desperate need of marketing and I don't think its new site will help it.The Ruby community has a fanaticism we could learn from and its going some way to 'converting' me. The community is alive, growing, shouting from the roof tops while the Python community seems to sit in its ivory towers conducting research and corporate development in 'forward-thinking' companies such as Google.
I can see Ruby overtaking Python if we don't ALL do something about it.On 9 Mar 2006 02:43:53 -0800, Gerard Flanagan 
[EMAIL PROTECTED] wrote:Steve Holden wrote: I've been thinking (and blogging) about python evangelism since PyCon,
 as a result of which I created a squidoo lens:http://www.squidoo.com/pythonlogy Imagine my surprise at discovering that this has gone up in rank (by
 number of views) from # 442,000 or so to #153! Clearly there's some mileage in marketing Python, and I'd like to keep the buzz going if it means more people will adopt the language. Any suggestions for improvement?
 '-nology' not '-nlogy' in the link.I like the 'What's Happening on Planet Python' section - I find theplanetpython.org gives too much of an intro to the pages it links to. A
line or too, as in the lens site,would be preferable in my view.Just a thought - would a similar section be suitable for 'python.org'main page?Gerard--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
bruno at modulix [EMAIL PROTECTED] writes:

 So it's time to move to 2.4x !-)

I guess so.


 What is going wrong exactly ?

  def _add_instance(cls, instance):
  _add_instance=classmethod(_add_instance)
  cls._instances.append(instance)

gives me:
d:/DTU/80494 $ python.exe ooo.py 
Traceback (most recent call last):
  File ooo.py, line 36, in ?
Foo(value)
  File ooo.py, line 6, in __init__
self._add_instance(self)
  File ooo.py, line 9, in _add_instance
_add_instance=classmethod(_add_instance)
UnboundLocalError: local variable '_add_instance' referenced before assignment
d:/DTU/80494 $ 

 Yeps too. This is called encapsulation.

Interesting. 

 Also, if you intend to use such a solution (with or without multiple
 lists), you may want to add a classmethod to delete instances from the
 list(s).

I will have to study classmethods.

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: implementation of complex type

2006-03-09 Thread Steven D'Aprano
On Thu, 09 Mar 2006 01:15:57 -0800, Russ wrote:

 I tried the following:
 
 x = complex(4)
 y = x
 y *= 2
 print x, y
 (4+0j) (8+0j)
 
 But when I tried the same thing with my own class in place of
 complex above, I found that both x and y were doubled. I'd like to
 make my class behave like the complex class. Can someone tell me the
 trick? Also, where can I find the code for for the complex class? I
 hope it's written in Python! Thanks.

Or, to put it another way:

Here's some code that works!

Now, I've written some *other* code, which has a bug in it. Who'd like to
guess what the bug is?

Why don't you show us your complex class?

Also, why are you re-inventing the wheel? Is it just to learn the
language? Or because you want to add extra functionality? Or just NIH
Syndrome? If it is a learning exercise, they I applaud you; if it is to
add extra functionality, there is a better way.



-- 
Steven.

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


[OT] .DS_Store files (was Re: Removing .DS_Store files from mac folders)

2006-03-09 Thread Dan Sommers
On Thu, 09 Mar 2006 17:19:15 +1300,
Greg Ewing [EMAIL PROTECTED] wrote:

 I don't think that deleting the .DS_Store files is the
 right approach to this, for various reasons:

[ ... ]

 * It might not even work, since the .DS_Store could
   get re-created in between your purge and creating
   the tarball.

 It would be better to just avoid putting the .DS_Store
 files in the tarball. For example, collect the pathnames
 of all the .DS_Store files and give them as an exclusion
 list to tar.

If these are both true, then *new* .DS_Store files could
be created after I've made the list and before I've made
the tarball.

Regards,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
I wish people would die in alphabetical order. -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RAD tutorials and tools for GUI development with Python?

2006-03-09 Thread Ravi Teja
 Interesting link, but the focus there seems to be encoperating Python into 
 Delphi apps in Windows. My focus is more getting Delphi like GUI building, 
 but coding python on Linux.


According to the web site
http://mmm-experts.com/VersionHistory.aspx?ProductId=3
it supports Lazarus, which is a Delphi clone that runs on most
platforms on Linux. I can vouch for Lazarus as a fine tool.
I think I used WINE in the past successfully with Delphi apps with
embedded Python on Linux.

Delphi quality integrated GUI builders are not available to any dynamic
language yet. But if you prefer a pure Python approach libglade and Qt
Designer are the paths of least resistance for Linux currently.

(I am adding this to the group. Let's keep the on-topic discussions
here so that others may offer better suggestions)

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


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
James Stroud [EMAIL PROTECTED] writes:

 You should look into __cmp__ and other magic methods. This is probably
 the type of functionality you seem to be after.

Good example, I need to look at the magic methods.
What I want is to get the value of another variable in C. Would I need to
use __repr__ and get the id from it to find xx of the instance with
maximum x? 

class C:
   def __init__(self, x):
 self.x = x
 self.xx = x*x

sees = [C(x) for x in (4,7,1,3,0,9,2)]  # random-ish ints
print max(sees)

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding Python: how to avoid memory leaks?

2006-03-09 Thread Torsten Bronger
Hallöchen!

Andrew Trevorrow [EMAIL PROTECTED] writes:

 [...]

 [...]  Not just once, but many times in a single session, and
 without leaking memory.  Preferably an open source app so I can
 see how it's done.

 Our app (http://golly.sourceforge.net/) currently uses calls
 like these every time a user decides to run a script:

Py_Initialize();
PyRun_SimpleString(execfile('foo.py'));

Does PyRun_AnyFile show the same effect?  That's the way I'm about
to go.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New python.org website

2006-03-09 Thread Nicola Musatti

Michael Tobis wrote:
[...]
 On the other hand, (since I think the design, while not brilliant, is
 good) fixing the logo is something that can be achieved without too
 much fuss.

The obviously perfect logo would be Kaa's face:
http://disney.go.com/vault/archives/villains/kaa/kaa.html

After all even my two and a half year old kids know that Kaa is *the*
python. However I suspect it would take a lot of money to license that.
[...]
 Finally, I disagree that the current logo is better than the neutral
 but consistently used php logo or the very clever java coffee mug logo,
 and notably the Ruby on Rails logo, which is first rate.

The Java logo has the problem that it is not universal: in Italy for
instance the name Java has no connection with coffee.

Cheers,
Nicola Musatti

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


Re: accesibility of the namespace

2006-03-09 Thread Steven D'Aprano
On Thu, 09 Mar 2006 01:42:55 -0800, Petr Jakes wrote:

 In my code I have relatively wide dictionary definition (about 100
 rows).
 
 I would like to put it in to the different file (module) because of the
 main code readability (say the name of the file will be
 my_dictionary.py)
 
 In the dictionary I have strings formatted using % operator like:
 lcd={2:Your credit= %3d % (credit)}

The values in the dictionary (e.g. Your credit= 9.99, or whatever value
credit actually has) are fixed at creation. I assume that means that
credit etc. are also fixed values.


 While I am trying to import my_dictionary in to the main code, I am
 getting:
 
 exception unhandled NameError
 name credit is not defined
 
 How can I organize my code so the credit variable will be visible
 in the my_dictionary namespace?

Put it in the same module as my_dictionary.

E.g. 

# Module my_dictionary.py
# which I hope will have a more sensible name before being used
# for production-code
credit = 27
foo = 15
lcd = {2: Your credit= %3d % credit}

On the other hand, if credit is a calculated value, this might not be
an easy thing to do. In that case, you can do this:


# Module calculatevalues.py
credit = some_function()
foo = some_other_function()

# Module my_dictionary.py
import calculatevalues
lcd = {2: Your credit= %3d % calculatevalues.credit}



On the third hand, if the strings from the dictionary are supposed to be
changed at run-time (which sounds more sensible to me) then do this:

# Module my_dictionary.py
lcd = {2: Your credit= %3d}


# main program
import my_dictionary
... lots of code here
credit = 27
... more code
print lcd[2] % credit




-- 
Steven.

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


Re: advice on this little script

2006-03-09 Thread Kent Johnson
Alex Martelli wrote:
 John Salerno [EMAIL PROTECTED] wrote:
...
 
I think the 'from time import sleep' looks cleaner, because I'm only 
taking what I need (is an import any more expensive than this from?),
but I also feel like the 'time.sleep' syntax is much more 
self-describing and better to read than just 'sleep'.

So what do you guys think between these two choices?

I use both fairly interchangeably. When I just need one or two things 
from the module, or if I am going to use something a lot, I use from xx 
import yy.
 
 
 I only use the 'from' statement to import specific modules from a
 package, never to import specific objects (functions, classes, or
 whatever) from a module. It scales much better: when reading a long
 module, I _know_ that any barename X always refers to a local,
 nested-scope, or global name, never to something snatched from
 who-recalls-what module -- in the latter case I'll never see a barename,
 but always somemodule.X, and searching for '... import somemodule' will
 immediately tell me where somemodule was coming from (should I need to
 be reminded of that information).

If you use from xx import yy, searching for yy will show you its 
provenance as well.

 From xx import * is evil because it does hide the provenance of names. 
It can also give unexpected results - if xx contains from zz import *, 
then all of the names from zz will also be imported into the module 
importing xx!

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


Re: Learning different languages

2006-03-09 Thread Frithiof Andreas Jensen

Terry Hancock [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Tuesday 07 March 2006 04:44 pm, Rich wrote:

 I've been trying to get my kids to learn a little Python for some
 time, but it hasn't been too easy for them yet.  Then, out of the
 blue, they want to learn Lua.

 Why?

 Simple -- Lua is the extension language for Enigma. So they want to
 make new game levels ergo, they must use Lua.  Motivation matters
 more than ease, IMHO. :-)

 We realized recently that while teaching kids to program is hard,
 teaching them to *hack* is easy. Once they learn to hack game
 levels, they will learn, from the level designers, basics about
 scripting and then programming, and they'll start to ask how
 can I make this easier?


Hacking is The Way - I learned Z80 assembly language to cheat in Space
Invaders on a Microbee conputer ;-). You can teach them some methods that
make their hacking easier, like debuggers, script tools and all that.

Maybe a Pyhton tool to simplify/generate skeleton code could be a devious
way of getting Python involved?

My son is quite proficient in using a collection of quite hairy build tools
because he likes to build levels for Counter Strike Source. He has no
interest in computers what so ever.


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


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Steven D'Aprano
On Thu, 09 Mar 2006 12:24:05 +0100, Brian Elmegaard wrote:

 James Stroud [EMAIL PROTECTED] writes:
 
 You should look into __cmp__ and other magic methods. This is probably
 the type of functionality you seem to be after.
 
 Good example, I need to look at the magic methods.
 What I want is to get the value of another variable in C. Would I need to
 use __repr__ and get the id from it to find xx of the instance with
 maximum x? 
 
 class C:
def __init__(self, x):
  self.x = x
  self.xx = x*x
 
 sees = [C(x) for x in (4,7,1,3,0,9,2)]  # random-ish ints
 print max(sees)


Can you explain more carefully what you are trying to do? If you want the
square of the maximum value, just do this:

max(4,7,1,3,0,9,2)**2


__repr__ is *not* the way to get the ID of a general object:

 repr(4)
'4'

For some objects, the default representation includes the ID as part of
the representation string, but that's not the way to get the ID. The way
to do that is with the id() function.

Right, now that you've learnt how to get the ID of an object, scrub it
from your mind. You won't need it. You can't use it. It isn't the way to
do whatever you are trying to do, whatever it is that you are trying to
do. These aren't the droids you are looking for.

[The above paragraph is always true, except for the exceptions when it is
not true. You will know when you need id(). If you only *think* you need
id(), you don't need it.]

Seriously though, you can't generally work backwards to see where an
object came from (which list, which dictionary, whatever). In general,
objects do not know what references there are to that object. If your
algorithm relies on object X knowing that it is the 5th item of list L,
then you must either store that information yourself somewhere, and
maintain it, or you must change your algorithm. 



-- 
Steven.

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


Alternative style sheets - Re: New python.org website

2006-03-09 Thread Magnus Lycka
Phoe6 wrote:
 beta.python.org evolved  very nice and noticed today the new python.org
 website going live. There is a change in the look n feel, wherein it
 looks more official and maximum possible information about python is
 now directly accessible from the home page itself.  Kudoes to the
 design team.

I also feel this is a big improvement.

I know that a web site like this needs constant nurturing, so
I hope that it's been developed in such as way that it will
be easier to maintain it and to involve more contributors.

Concerning style sheets, it's pretty trivial to make several
style sheets and let people use the one they like best.

If we enable that, it should also be simple to see from the
web site statistics which style sheet people prefer. Then we
can use the most popular style sheet as the default!

Since people have different tastes, different screens with
various resolutions and colors etc, darker or lighter rooms,
might want different styles for on-screen viewing and on paper
etc, I think it would be a good idea to have several styes
even if there is no ambivalence concerning what look we want.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accesibility of the namespace

2006-03-09 Thread Petr Jakes
Thanks Steven,
credit is mentioned to be a calculated value  changed at run-time and
your third hand suggestion is exactly what I was looking for.

Petr Jakes

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


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Steven D'Aprano
On Thu, 09 Mar 2006 11:54:11 +0100, Brian Elmegaard wrote:

 What is going wrong exactly ?
 
   def _add_instance(cls, instance):
   _add_instance=classmethod(_add_instance)
   cls._instances.append(instance)
 
 gives me:
 d:/DTU/80494 $ python.exe ooo.py 
 Traceback (most recent call last):
   File ooo.py, line 36, in ?
 Foo(value)
   File ooo.py, line 6, in __init__
 self._add_instance(self)
   File ooo.py, line 9, in _add_instance
 _add_instance=classmethod(_add_instance)
 UnboundLocalError: local variable '_add_instance' referenced before assignment

This isn't a bug in version 2.3. It is a bug in your code.  Follow the
code at runtime when you call the method:

Calling x._add_instance(foo) calls the _add_instance method with arguments
x.__class__ and foo. The first instruction that gets executed is:

_add_instance=classmethod(_add_instance)

but _add_instance doesn't exist inside the method's local scope, so you
get an UnboundLocalError exception.

What you probably think you want is something like this:

class Foo:
_instances = []

def _add_instance(cls, instance):
cls._instances.append(instance)

_add_instances = classmethod(_add_instances)


I say think you want because I don't know what problem you are trying to
solve with this messy, self-referential, piece of code. If you could
explain what your goal is, there is probably a better way of reaching it.


-- 
Steven.

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


Re: [OT] .DS_Store files (was Re: Removing .DS_Store files from mac folders)

2006-03-09 Thread Eric Deveaud
Dan Sommers wrote:
  If these are both true, then *new* .DS_Store files could
  be created after I've made the list and before I've made
  the tarball.


not python related, but in order to creater the tarball without the .DS_Store
files why don't you use the --exclude=PATTERN option from tar ??

Eric

-- 
  CM: Faut-il nommer un modérateur suppléant à Christophe Wolfhugel ?
  MG: Faudrait savoir ce qu'il en pense ? Va-t-il répondre : « Rien » ?
  CW: Non.
   -+- in: Guide du Cabaliste Usenet - Euh... Non, rien. -+-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about slicing with a step length

2006-03-09 Thread André

Terry Reedy wrote:
  John Salerno wrote:
  Given:
   numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
   can someone explain to me why
   numbers[10:0:-2] results in [10, 8, 6, 4, 2]?

 It appears that s[i:j:-1] is s[(j+1):(i+1)] .reverse()'ed.  For 'numbers',
 this is 10, 9, 8, 7, 6, 5, 4, 3, 2].  Then take every other item.  Why the
 +1?  Don't know and not my intuitive expectation.  I just know that
 extended slicing was developed for and until recently pretty much
 restricted to numeric (now numpy).

It's not simply +1.
 a = range(10)
 a[9:0:-2]
[9, 7, 5, 3, 1]

 a[10:0:-2]
[9, 7, 5, 3, 1]

 a[11:0:-2]
[9, 7, 5, 3, 1]

 a[42:0:-2]
[9, 7, 5, 3, 1]

 Steven D'Aprano
  I think the documentation is misleading/incomplete when
  it comes to negative strides for extended slices.

 and Andre Agreed! also, and you three aren't the only ones.  Maybe some
 day I will read the source, think about it more, and post a suggested
 revision for comment  ... or maybe someone will beat me to it.

I, myself, think that the slicing behaviour is broken in this case.
From the little I understand (without looking at the source),
adjustment on the boundaries of the slicing request (the first 2
numbers) is done first, to make them positive and, I believe, ensure
that they do not extend beyond the boundaries of the sequence.  Then,
the actual stepping through is performed.

In my (most likely not-well informed enough opinion), the behaviour
should be the following:
from [i: j: k],
if k  0 and j = i : return []
if k 0 and j = i : return []
otherwise, build the following list of numbers:
i, i+k, i+2*k,
until i +n*k = j (if k0; use = if k0)
where the last number is excluded, i.e.
[0: 2: 1] = list(0, 1)
*Then*, exclude from the list just built any negative numbers, or any
number greater than the length of the sequence to be sliced.

So, [10:0:-2] would yield the following list of numbers
[10, 8, 6, 4, 2] before trimming;  applying this to
range(10), would end up with result in trimming 10 from the list
built.
Thus, we are looking at indices [8, 6, 4, 2] of range(10), which happen
to be the numbers [8, 6, 4, 2] in this case.  We should end up with
the same list if we ask for [42:0:-2].   This is not the observed
behaviour,
as we get [9, 7, 5, 3, 1].
If we ask Python to do
 a[0:10:2]
we get
[0, 2, 4, 6, 8]
which is correct.  It seems to me that the following (pseudo-code, not
valid Python)
a[2:10:2] == a[8:0:-2].reversed()
should be true, just like
a[1:10:1] == a[9:0:-1].reversed()
is true.

I *suspect* that boundary adjustments are performed first before
creating a sequence of indices, so that there is less trimming (as
described above) for the sake of efficiency ... and that this is not
done properly.

Then again, perhaps I simply don't understand what slices are supposed
to do

André

 
 Terry Jan Reedy

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


Re: grayscale pixel based graphics with pygame

2006-03-09 Thread Brian L. Troutwine
Thank you, but that wasn't quite what I was looking for. I do admit,
however, that my post wasn't very clear (writting while exceptionally
tired is not a very clever thing to do.) As Terry mentioned below this
should be a question for the pygame mailing lists, so I'll take it
there.

Thanks again though.

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


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
Steven D'Aprano [EMAIL PROTECTED] writes:

 Can you explain more carefully what you are trying to do? If you want the
 square of the maximum value, just do this:

I want to get the value of another attribute of the instance with
maximum x. 

I know I could do it like you suggest for the case with x*x, but the
other attribute does not depend on x.

 [The above paragraph is always true, except for the exceptions when it is
 not true. You will know when you need id(). If you only *think* you need
 id(), you don't need it.]

:-)

 algorithm relies on object X knowing that it is the 5th item of list L,
 then you must either store that information yourself somewhere, and
 maintain it, or you must change your algorithm. 

OK, I think this is the answer I was looking for.

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: grayscale pixel based graphics with pygame

2006-03-09 Thread Brian L. Troutwine
Geez, I apologize for my post being so vague. I was terribly tired when
I wrote that, and should have known better than to post.

I was not aware of the pygame mailing list. I will take this question
there.

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


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
Steven D'Aprano [EMAIL PROTECTED] writes:

 What you probably think you want is something like this:

Thanks, that made it run.
Now I need to study what classmethods are.

 I say think you want because I don't know what problem you are trying to
 solve with this messy, self-referential, piece of code. If you could
 explain what your goal is, there is probably a better way of reaching it.

Probably, this was just an example posted to show me how to add all
the instances to the class.

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Inter-module globals

2006-03-09 Thread Anton81
Hi,

I want to use globals that are immediately visible in all modules. My
attempts to use global haven't worked. Suggestions?

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


Re: Inter-module globals

2006-03-09 Thread Jorge Godoy
Anton81 [EMAIL PROTECTED] writes:

 I want to use globals that are immediately visible in all modules. My
 attempts to use global haven't worked. Suggestions?

Use a module and a class variables for that.  Import your module and
read/update class variables as you need them.


-- 
Jorge Godoy  [EMAIL PROTECTED]

Quidquid latine dictum sit, altum sonatur.
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: embedding Python: how to avoid memory leaks?

2006-03-09 Thread Andrew Trevorrow
  Our app (http://golly.sourceforge.net/) currently uses calls
  like these every time a user decides to run a script:
 
 Py_Initialize();
 PyRun_SimpleString(execfile('foo.py'));
 
 Does PyRun_AnyFile show the same effect?  That's the way I'm about
 to go.

I couldn't get the PyRun_*File* calls to work on Windows, presumably
because of the FILE* problem mentioned in the docs.

I'll be very surprised if it makes any difference to the memory
leak problem.  Let me know how you get on!

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


Re: implementation of complex type

2006-03-09 Thread cfbolz
Hi!

Russ wrote:
 I tried the following:

  x = complex(4)
  y = x
  y *= 2
  print x, y
 (4+0j) (8+0j)

 But when I tried the same thing with my own class in place of
 complex above, I found that both x and y were doubled. I'd like to
 make my class behave like the complex class. Can someone tell me the
 trick? Also, where can I find the code for for the complex class? I
 hope it's written in Python! Thanks.

In CPython it is actually written in C, implemented in the
Objects/complexobject.c file. See for example:

http://svn.python.org/view/python/trunk/Objects/complexobject.c?rev=42596view=markup

In PyPy it is indeed a pure Python implementation right now:

http://codespeak.net/svn/pypy/dist/pypy/module/__builtin__/app_complex.py

Cheers,

Carl Friedrich Bolz

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


Re: cgi problem

2006-03-09 Thread Kent Johnson
Paul Rubin wrote:
 Tim Roberts [EMAIL PROTECTED] writes:
 
Yes, but the CGI module doesn't write anything, so the advice of writing a
Location: header still applies.
 
 
 Aha, it's coming from CGIHTTPServer.py:CGIHTTPRequestHandler.run_cgi()
 where it says
 
 self.send_response(200, Script output follows)
 
 I got the two modules confused.  This still leaves me with the same
 basic problem, how to suppress the sending of that header.

Ah, now I get it. This does look like a bug in CGIHTTPServer to me. As 
you note, it hardcodes the 200 status response. The CGI spec says that 
the CGI program can use the Status: header to tell the server what 
status code to send but CGIHTTPServer doesn't do that.

ISTM the spec requires the server to buffer and interpret the HTTP 
headers from the CGI so the Status header can be set based on the CGI 
response.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread bruno at modulix
Steven D'Aprano wrote:
(snip)

 I say think you want because I don't know what problem you are trying to
 solve with this messy, self-referential, piece of code.

This messy piece of code is mine, thanks !-)

And it's not self-referential - it introduces a references cycle
(class object - instances - class object), which may or may not be a
problem.

 If you could
 explain what your goal is, 

He did (more or less), please read the original post.

 there is probably a better way of reaching it.

Probably, yes.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread bruno at modulix
Brian Elmegaard wrote:
 bruno at modulix [EMAIL PROTECTED] writes:
 
 
So it's time to move to 2.4x !-)
 
 
 I guess so.
 
 
 
What is going wrong exactly ?
 
 
   def _add_instance(cls, instance):
   _add_instance=classmethod(_add_instance)
   cls._instances.append(instance)

You want

def _add_instance(cls, instance):
  cls._instances.append(instance)

_add_instance=classmethod(_add_instance)


(snip)

Also, if you intend to use such a solution (with or without multiple
lists), you may want to add a classmethod to delete instances from the
list(s).
 
 
 I will have to study classmethods.

May I suggest that you first learn the language syntax and basics ?-)

FWIW, a classmethod is a method that get the class object as first
argument (instance methods get a reference to the instance).


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to dervie from an instance object?

2006-03-09 Thread bruno at modulix
reinsn wrote:
 Hi,
 
 I am currently working with ZopeX3. Because python doesn't include
 concept of interfaces,

It does, but implicitly. The interface of an object is the set of
messages it understands.

 those were defined by the module zope.interface.
 
 So interfaces were defined like:
 
 class IMyInterface(zope.interface.Interface):
.
 
 I have looked into the module zope.interface and found, that
 zope.interface.Interface is an object instance and no class object! But
 how does this work? How can I derive from an object instance?

Python classes *are* objects - instances of their metaclass.

 I mean is something like this possible in Python?
 
 class X: pass
 
 x = X()
 
 class Y (x):
   .

Not directly. Google for Python +metaclass.



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New python.org website

2006-03-09 Thread Magnus Lycka
Nicola Musatti wrote:
 The obviously perfect logo would be Kaa's face:
 http://disney.go.com/vault/archives/villains/kaa/kaa.html

The Soviet version is better, and I think most of the
Maugli movies are made before 1973, which means that
they aren't copyrighted outside the former Soviet Union.
(Disclaimer: IANAL)

I'm not sure either version really works as a logo though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding Python: how to avoid memory leaks?

2006-03-09 Thread Martin v. Löwis
Andrew Trevorrow wrote:
 Our app (http://golly.sourceforge.net/) currently uses calls
 like these every time a user decides to run a script:
 
Py_Initialize();
PyRun_SimpleString(execfile('foo.py'));
Py_Finalize();
 
 But even if foo.py is *empty* the above calls result in a memory
 leak of about 12K on Mac OS 10.3.9 (using Python 2.3) and about
 11K on Windows 2000 (using Python 2.4.2).

I could reproduce a memory leak with the code

#include Python.h
int main()
{
  while(1){
Py_Initialize();
PyRun_SimpleString(execfile('foo.py'));
Py_Finalize();
  }
}

However, I could not reproduce a memory leak with the code

#include Python.h
int main()
{
  Py_Initialize();
  while(1){
PyRun_SimpleString(execfile('foo.py'));
  }
  Py_Finalize();
}

So I recommend you do Py_Initialize only once. It is well-known
that initializing the Python interpreter allocates memory that
can never be freed, e.g. global variables in extension modules
(there just isn't any API to tell all the modules to release their
memory). So a cycle of Py_Initialize/Py_Finalize will certainly
leak.

OTOH, PyRun_SimpleString shouldn't leak, and didn't when I
tried it.

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


Re: accesibility of the namespace

2006-03-09 Thread Petr Jakes
Ops. My keyboard (fingers) was faster than my mind :(
So
There is more than one run-time changed variable in the dictionary
and not all strings in the dictionary are formatted using % operator.
Example:
lcd={
2:{2:((Enter you choice),(Your kredit= %3d % (kredit)))},
4:{2:((Your choice: %2s % (keyboard)),(%-20s % (actKeyboard)))}}

I do not know which variable(s) to use for the % operator in the time
of the call of the value (% formatted string) from the dictionary.

This is also the reason why the variable names are stored in the
dictionary with the strings.

Any other suggestions?
Thanks
Petr Jakes

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


Re: embedding Python: how to avoid memory leaks?

2006-03-09 Thread Torsten Bronger
Hallöchen!

[EMAIL PROTECTED] (Andrew Trevorrow) writes:

 [...]

 I couldn't get the PyRun_*File* calls to work on Windows, presumably
 because of the FILE* problem mentioned in the docs.

Which compiler do you use?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inter-module globals

2006-03-09 Thread Schüle Daniel
Anton81 wrote:
 Hi,
 
 I want to use globals that are immediately visible in all modules. My
 attempts to use global haven't worked. Suggestions?
 
 Anton

I think a dictionary would work here
as well as list but not strings and int's

# module1
settings = {
release : 1.0,
blabla  : None,
}

# module2
import module1 as settings
print settings.settings[release]
settings.settings[blabla] = True


# module3
import module1 as settings
settings.settings[blabla] = False

Regards

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


Re: accesibility of the namespace

2006-03-09 Thread Mikael Olofsson
Petr Jakes wrote:
 Ops. My keyboard (fingers) was faster than my mind :(
 So
 There is more than one run-time changed variable in the dictionary
 and not all strings in the dictionary are formatted using % operator.
 Example:
 lcd={
 2:{2:((Enter you choice),(Your kredit= %3d % (kredit)))},
 4:{2:((Your choice: %2s % (keyboard)),(%-20s % (actKeyboard)))}}
 
 I do not know which variable(s) to use for the % operator in the time
 of the call of the value (% formatted string) from the dictionary.
 
 This is also the reason why the variable names are stored in the
 dictionary with the strings.
 
 Any other suggestions?

So, use something like

  lcd={
2:{2:(Enter you choice,Your kredit= %(kredit)3d)},
4:{2:(Your choice: %(keyboard)2s ,%(actKeyboard)-20s)}}
  kredit = 7
  keyboard = 'aa'
  actKeyboard = 7654
  lcd[2][2][-1] % vars()
'Your kredit=   7'
  lcd[2][2][0] % vars()
'Enter you choice'
  lcd[4][2][0] % vars()
'Your choice: aa'
  lcd[4][2][1] % vars()
'7654'
 

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


Re: Python Evangelism

2006-03-09 Thread Steve Holden
Doug Bromley wrote:
 Python is in desperate need of marketing and I don't think its new site 
 will help it.
 The Ruby community has a fanaticism we could learn from and its going 
 some way to 'converting' me.  The community is alive, growing, shouting 
 from the roof tops while the Python community seems to sit in its ivory 
 towers conducting research and corporate development in 
 'forward-thinking' companies such as Google.
 
OK, and this post will improve the situation how, exactly?

 I can see Ruby overtaking Python if we don't ALL do something about it.
 
Indeed. Hence http://www.squidoo.com/pythonology

And your contribution is ... yet another post about how we all need to 
*do* something? On the other hand, you could just roll up your sleeves 
and start doing something :-)

Your take on Python is likely unique: start telling people why *you* use it.

regards
  Steve

 On 9 Mar 2006 02:43:53 -0800, *Gerard Flanagan*  [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:
 
 Steve Holden wrote:
   I've been thinking (and blogging) about python evangelism since
 PyCon,
   as a result of which I created a squidoo lens:
  
  http://www.squidoo.com/pythonlogy
  
   Imagine my surprise at discovering that this has gone up in rank (by
   number of views) from # 442,000 or so to #153! Clearly there's some
   mileage in marketing Python, and I'd like to keep the buzz going
 if it
   means more people will adopt the language.
  
   Any suggestions for improvement?
  
 
 '-nology' not '-nlogy' in the link.
 
 I like the 'What's Happening on Planet Python' section - I find the
 planetpython.org http://planetpython.org gives too much of an
 intro to the pages it links to. A
 line or too, as in the lens site,  would be preferable in my view.
 Just a thought - would a similar section be suitable for 'python.org
 http://python.org'
 main page?
 
 Gerard

By the way, the apparent increase in rank was somewhat bogus given that 
there appear to be fewer than 20,000 lenses at present :-)
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Re: Python Evangelism

2006-03-09 Thread Fredrik Lundh
Doug Bromley wrote:

 I can see Ruby overtaking Python if we don't ALL do something about it.

on the other hand, people have posted I can see XXX overtaking Python if we
don't ALL do something about it NOW messages for as long as I've been using
Python.

the best thing I've seen in the recent argh! this is the end threads that 
have been
popping up here and there is this advice from an anonymous ruby user, from a
comment on guido's blog:

My advice for you Pythonistas: First, chill; the mind works better when
relaxed. Second, look around and count your blessings; Python is every-
where. Third, just work on something you find interesting and fun.

have you used Python to work on something fun and interesting today?  if not, 
what's
your excuse? ;-)

/F 



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


Re: why no block comments in Python?

2006-03-09 Thread Benji York
Terry Hancock wrote:
 I'm thinking this might be a use-case for the new support for
 doctests in a separate file.

Having doctests in their own file is (IMHO) a majorly under appreciated 
feature of doctest.  The ability to do either nice user (as in 
developer) docs with known good examples or well documented 
not-meant-for-documentation unit/functional/integration tests is terrific.
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


String functions: what's the difference?

2006-03-09 Thread Harro de Jong
(absolute beginner here, sorry if this seems basic)

Section 7.10 of 'How to Think Like a Computer Scientist' contains this 
discussion of string.find and other string functions: 

(quote)
We can use these constants and find to classify characters. For example, if
find(lowercase, ch) returns a value other than -1, then ch must be lowercase:

def isLower(ch):
return string.find(string.lowercase, ch) != -1

Alternatively, we can take advantage of the in operator, which determines
whether a character appears in a string:
def isLower(ch):
return ch in string.lowercase

As yet another alternative, we can use the comparison operator:
def isLower(ch):
return 'a' = ch = 'z'
If ch is between a and z, it must be a lowercase letter.

As an exercise, discuss which version of isLower you think will be
fastest. Can you think of other reasons besides speed to prefer one
or the other?

(end quote)

I've tried all three, but the function is so small (test a single letter) I 
can't measure the difference. I'm using time.time() to see how long it takes to 
execute the function. 
I could use a loop to increase execution time, but then I might be measuring 
mostly overhead. 

I'd expect the third option to be the fastest (involves looking up 3 values, 
where the others have to iterate through a-z), but am I right? 
And reasons to prefer one? a-z doesn't contain all lowercase letters (it omits 
acents and symbols), but other than that? 


-- 
Harro de Jong
remove the extra Xs from xmsnet to mail me
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Evangelism

2006-03-09 Thread rtilley
Steve Holden wrote:
 Doug Bromley wrote:
 I can see Ruby overtaking Python if we don't ALL do something about it.

I think it's the name. Python. Let's change it to something nicer. Think 
about it... if you found a Ruby, you'd pick it up and put it in your 
pocket. If you ran across a Python, you'd run away.

Gems is nice too. Compare that to Cheese Shop... who came up with that 
:) Do you want a pretty gem stone or a smelly slice of cheese? I mean 
that in a literal sense. I don't think Python is smelly at all, but it 
certainly has chosen some slimy, smelly bad names for itself!

Psychology is important. Just as important as good design. I think this 
fact doesn't sink in to the Python community.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get a page's html code via a proxy

2006-03-09 Thread JuHui
who can help me?
please give me a sample code. thanks a lot.

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


Re: encoding problem

2006-03-09 Thread Martin v. Löwis
Yves Glodt wrote:
 It seems in general I have trouble with special characters...
 What is the python way to deal with éàè öäü etc...
 
 print 'é' fails here,
 print u'é' as well :-(
 
 How am I supposed to print non-ascii characters the correct way?

The second form should be used, but not in interactive mode.
In a Python script, make sure you properly declare the encoding
of your script, e.g.

# -*- coding: iso-8859-1 -*-
print u'é'

That should work. If not, give us your Python version, operating
system name, and mode of operation.

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


Re: String functions: what's the difference?

2006-03-09 Thread Martin v. Löwis
Harro de Jong wrote:
 I've tried all three, but the function is so small (test a single letter) I 
 can't measure the difference. I'm using time.time() to see how long it takes 
 to 
 execute the function. 
 I could use a loop to increase execution time, but then I might be measuring 
 mostly overhead. 

Still, this is what you should do. Try the timeit.py module; it does the
loop for you. Surprisingly, one of the faster ways to do a loop is

nones = [None]*1000

start timer
for x in nones:
  action
stop timer

This is fast because no Python integers are created to implement the
loop.

 I'd expect the third option to be the fastest (involves looking up 3 values, 
 where the others have to iterate through a-z), but am I right? 

Just measure it for yourself. I just did, and the third option indeed
came out fastest, with the in operator only slightly slower.

 And reasons to prefer one? 

For what purpose? To find out whether a letter is lower-case?

Just use the .islower() method on the character for that.

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


First script, please comment and advise

2006-03-09 Thread Pedro Graca
I'm sure this isn't very pythonic; comments and advice appreciated


def curious(text):
 Return the words in input text scrambled except for the first and 
last letter. 
new_text = 
word = 
for ch in text:
if ch in abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:
word = word + ch
else:
new_text = new_text + scramble(word)
word = 
new_text = new_text + ch
return new_text

def scramble(word):
 scramble word 
from random import randint

if len(word)  4:
return word
new_word = word[0]

### transform curious into ['u', 'r', 'i', 'o', 'u']
letters = []
for ch in word:
letters.append(ch)
del letters[0:1]
del letters[-1]

### why doesn't range(len(letters) - 1, 0, -1) work?
for i in range(len(letters) - 1, -1, -1):
j = randint(0, i)
new_word = new_word + letters[j]
del letters[j]
return new_word + word[-1]

print curious(curious.__doc__)


-- 
If you're posting through Google read http://cfaj.freeshell.org/google
-- 
http://mail.python.org/mailman/listinfo/python-list


opensource prayer

2006-03-09 Thread gen_tricomi
I and my opensource brothers/sisters are one. all i have is thiers.
therefore i will keep my source code open for them. we are free and
will remain free because freedom is the goal of evolution. OM OM OM
REPEAT THIS TO YOUR SELF AS OFTEN AS POSSIBLE AS REGULARLY AS POSSIBLE
TO STRENGHTEN OUR COMMUNITY.

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


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
bruno at modulix [EMAIL PROTECTED] writes:

 May I suggest that you first learn the language syntax and basics ?-)

I'll try

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get a page's html code via a proxy

2006-03-09 Thread Fredrik Lundh
JuHui wrote:

 who can help me?

did you check the documentation ?  a quick look in the library index
might have helped you find this page

http://docs.python.org/lib/module-urllib.html

(search for proxy on that page to learn how urllib handles proxies)

 please give me a sample code.

import urllib
urllib.urlretrieve(someurl, filename)

hope this helps!

/F 



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


Re: encoding problem

2006-03-09 Thread Scott David Daniels
Yves Glodt wrote:
 It seems in general I have trouble with special characters...
 What is the python way to deal with éàè öäü etc...
 
 print 'é' fails here,
This should probably stay true.

 print u'é' as well :-(
This is an issue with how your output is connected.
What OS, what code page, what application?
I'm using Win2K, Python 2.4.2
Using Idle, I can do:
print u'élève'
And get what I expect
I can also do:
print repr(u'élève')
which gives me:
 u'\xe9l\xe8ve'
and:
 print u'\xe9l\xe8ve'
Also shows me élève.


With cmd.exe (the command line):
 c:\ python
  print u'\xe9l\xe8ve'
shows me élève, but I can't type in:
  print u'lve'
is what I get when I paste in the print u'élève' (beeps during paste).
What do you get if you put in:
  print repr('élève')

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning different languages

2006-03-09 Thread gene tani

Harry George wrote:

 re the OP:

 I find I have to concentrate on one language for a while (several
 programs) to ramp up on the syntax, semantics, idioms, and libraries.
 Then I'm safe to wander off and learn other languages.  When it comes
 time to do a project, I use one main language unless it really is a
 bad match, in which case I write in one of the others.  My one
 language has variously been over the years Pascal, Modula-2, Modula-3,
 perl, and Python.  Even though I've written substantially in COBOL,
 FORTRAN, Lisp, Prolog, and Java, I wouldn't use these for a default
 language.


this raises a few issues: how do you keep the syntax of python and
javascript, or python and C clear?  At a base level, some combination
of IDE code completion, reference websites (the activestate docs
package for python is fantastically easy to search), Oreilly nutshell
/other books, and quick references / other visual aids.  At the next
level, Udell talks about making different languages work similarly if
you need to move functionality between them.

the other is it's hard to avoid having to read, e.g. perl if you're
working in a UNIX shop, lisp if you pick emacs, java/C# if you want to
read about design patterns, javascript, etc. etc.  After a while, the
read-only ability segues into some ability to modify others' code,
which segues into writing code.

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


Re: Python Evangelism

2006-03-09 Thread Doug Bromley
A defector!Release the hounds!Burn the scum!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: First script, please comment and advise

2006-03-09 Thread Just
In article [EMAIL PROTECTED],
 Pedro Graca [EMAIL PROTECTED] wrote:

 I'm sure this isn't very pythonic; comments and advice appreciated
 
 
 def curious(text):
  Return the words in input text scrambled except for the first and 
 last letter. 
 new_text = 
 word = 
 for ch in text:
 if ch in abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:
 word = word + ch
 else:
 new_text = new_text + scramble(word)
 word = 
 new_text = new_text + ch
 return new_text
 
 def scramble(word):
  scramble word 
 from random import randint
 
 if len(word)  4:
 return word
 new_word = word[0]
 
 ### transform curious into ['u', 'r', 'i', 'o', 'u']
 letters = []
 for ch in word:
 letters.append(ch)
 del letters[0:1]
 del letters[-1]
 
 ### why doesn't range(len(letters) - 1, 0, -1) work?
 for i in range(len(letters) - 1, -1, -1):
 j = randint(0, i)
 new_word = new_word + letters[j]
 del letters[j]
 return new_word + word[-1]
 
 print curious(curious.__doc__)

def curious(text):
 Return the words in input text scrambled except for the
first and last letter. 
new_text = 
word = 
for ch in text:
if ch.isalpha():
word += ch
else:
new_text += scramble(word)
word = 
new_text += ch
new_text += scramble(word)
return new_text

def scramble(word):
 scramble word 
from random import shuffle
if len(word)  4:
return word
letters = list(word[1:-1])
shuffle(letters)
return word[0] + .join(letters) + word[-1]

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


Re: advice on this little script

2006-03-09 Thread Grant Edwards
On 2006-03-09, John Salerno [EMAIL PROTECTED] wrote:
 Grant Edwards wrote:
 On 2006-03-09, John Salerno [EMAIL PROTECTED] wrote:
 
 from time import sleep

 minutes = input('Enter the number of minutes to wait: ')

 for x in range(minutes):
 sleep(1.0)
 minutes -= 1
 print minutes, 'minutes remaining.'
 
 for x in range(minutes,0,-1):
 sleep(60.0)
 print minutes, 'minutes remaining'

   print x, 'minutes remaining'

Doh!   

-- 
Grant Edwards   grante Yow!  Now KEN is having
  at   a MENTAL CRISIS beacuse
   visi.comhis R.V. PAYMENTS are
   OVER-DUE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Evangelism

2006-03-09 Thread Dale Strickland-Clark
rtilley wrote:

 Psychology is important. Just as important as good design. I think this
 fact doesn't sink in to the Python community.

You speak of fluff and ribbons and glitter.

I think most people here are less concerned with psychology and more
interested in pychology.
-- 
Dale Strickland-Clark
Riverhall Systems www.riverhall.co.uk
We're recruiting. See the web site for details.

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


Re: String functions: what's the difference?

2006-03-09 Thread gry
First, don't appologize for asking questions.  You read, you thought,
and you tested.  That's more than many people on this list do.  Bravo!

One suggestion: when asking questions here it's a good idea to always
briefly mention which version of python and what platform (linux,
windows, etc) you're using.  It helps us answer your questions more
effectively.

For testing performance the timeit module is great.  Try something
like:
  python -mtimeit -s 'import string;from myfile import isLower'
isLower('x')

You didn't mention the test data, i.e. the character you're feeding to
isLower.
It might make a difference if the character is near the beginning or
end of the range.

As to reasons to prefer one or another implementation, one *very*
important question is which one is clearer?.  It may sound like a
minor thing, but when I'm accosted first thing in the
morning(pre-coffee) about a nasty urgent bug and sit down to pore over
code and face string.find(string.lowercase, ch) != -1, I'm not happy.

Have fun with python!
-- George Young

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


Re: Python Evangelism

2006-03-09 Thread Dale Strickland-Clark
Steve Holden wrote:

 Any suggestions for improvement?
 
 regards
   Steve
Get rid of the scarey face?

  :-)
-- 
Dale Strickland-Clark
Riverhall Systems www.riverhall.co.uk
We're recruiting. See the web site for details.

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


Re: Python Evangelism

2006-03-09 Thread Andrew Gwozdziewycz
On 3/9/06, rtilley [EMAIL PROTECTED] wrote:

  Doug Bromley wrote:
  I can see Ruby overtaking Python if we don't ALL do something about it.

 I think it's the name. Python. Let's change it to something nicer. Think
 about it... if you found a Ruby, you'd pick it up and put it in your
 pocket. If you ran across a Python, you'd run away.

Woah, are you actually serious? What would changing the name of language you're
trying to market do for the marketing campaign? New to the YAMMA language? Check
out all these other Python tutorials to get started. I don't think
it's the name, I think the
major problem is people saying, What can we do to market it? and not
actually doing
anything, as Steven just said. Work on something. Create something popular. Heck
promote django or some other framework. Work on some new innovative technology
in python! Just choose python and recommend it to others. Word of mouth, Quality
projects and not claiming we need new marketing strategies _IS_ the
best marketing
strategy.

 Gems is nice too. Compare that to Cheese Shop... who came up with that
 :) Do you want a pretty gem stone or a smelly slice of cheese? I mean
 that in a literal sense. I don't think Python is smelly at all, but it
 certainly has chosen some slimy, smelly bad names for itself!

While I agree, that gem is nice and python needs a new standard
package management
system, maybe that's your contribution! Build it! Make it awesome!

 Psychology is important. Just as important as good design. I think this
 fact doesn't sink in to the Python community.

Pyschology _is_ important, but not in this case. Make good products
and they will
come. Python has a ton of good projects and a ton of users. What we
don't have is
ruby on rails and the web 2.0 crowd, and I say, who the hell cares? We
have everything
else.

--
Andrew Gwozdziewycz [EMAIL PROTECTED]
http://ihadagreatview.org
http://plasticandroid.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python debugging question

2006-03-09 Thread Harry George
[EMAIL PROTECTED] writes:

 I am a python newbie. I have writen some 500 lines of code. There are 4
 classes and in all 5 files.
 
 Now, I am trying to run the program. I am getting wrong values for the
 simulation results.
 Is there any debugging facilities in python which would let me go step
 by step and check the values of the variables at every step. I have
 done something like this in MS Visual Stdio 6.0 sometime back.
 
 For python, I am using SPE.
 
 what is a good way of debugging such large and iterative programs ? Any
 tips.
 
 Every help is appreciated.
 
 Thanks
 
If you use my mkpythonproj:
http://www.seanet.com/~hgg9140/comp/index.html#L006
then you will have a test suite and a debug ftn ready to go.

For a brand new project, where you are exploring and don't know what
the test cases might be, you can just do the debug calls. Once you
know where you are headed (or if you got rqmts at the start) then
crank up some test cases and run that testsuite everytime you add a
few lines of code.

Start exploring or testing at the hello, world level, and gradually
add functionality (tests and code) as you go.  This is MUCH easier
than writing a lot of code and then trying to debug it.  You only need
to understand a few lines at a time.

In tens of thousands of lines of python code, I think I've used a
debugger (pdb) maybe once.  We have some apps here that are one-off
quick hacks and others that are multi-person, multi-year efforts.
They all live by their test suites.

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Evangelism

2006-03-09 Thread rtilley
Dale Strickland-Clark wrote:
 rtilley wrote:
 
 
Psychology is important. Just as important as good design. I think this
fact doesn't sink in to the Python community.
 
 
 You speak of fluff and ribbons and glitter.

Yes, I know. Great products, ideas and methods have lost mind share to 
lesser things (not that Ruby is inferior to Python or vice versa) 
because they lack fluff, ribbons and glitter :)

I hope Python gets more fluff... it already has lost of great technical 
merit :)
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: CherryPy-2.2.0-rc1 released

2006-03-09 Thread remi
Hello everyone,

I'm happy to announce that the first release candidate for
CherryPy-2.2.0 is now available.

This release includes various bugfixes, a new benchmarking tool and
improved WSGI support.

Check out this great post from Christian Wyglendowski to see how you
can run multiple WSGI-CherryPy apps using other tools like wsgutils or
Paste (or do the opposite: run a PyBloxsom or MoinMoin WSGI app within
CherryPy):

http://blog.dowski.com/2006/03/08/cherrypy-and-wsgi-can-play-nice/

Christian has also put together a great screencast showing how to run
CherryPy and interact with it directly from the prompt:

http://blog.dowski.com/2006/03/05/cherrypy-and-the-interactive-interpreter/


***
About CherryPy:

CherryPy is a pythonic, lightweight and straightforward (no
dependencies) web development framework.

Here is a sample Hello, World in CherryPy:

# import cherrypy
# class HelloWorld:
# @cherrypy.expose
# def index(self):
# yield htmlbody
# yield Hello world!
# yield /body/html
# cherrypy.root = HelloWorld()
# cherrypy.server.start()


Details and downloads for the 2.2.0-rc1 release are available from the
CherryPy website:

http://www.cherrypy.org


Remi.

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


Re: is there any overheard with try/except statements?

2006-03-09 Thread John Salerno
Alex Martelli wrote:


 In general, it's more frequent for EAFP to be handier and more solid,
 and performance may well not matter -- but if you find yourself trying
 to squeeze every last drop of performance from a region of your code
 that profiling has shown to be a bottleneck, module timeit can help!

Thanks Alex, great information. I learn way too much new information 
every day on this newsgroup.  ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Michael
Brian Elmegaard wrote:
...
 The code that runs:
 
 class Foo:
 def __init__(self,x):
 self.x=x
 
 y=[]
 y.append(Foo(10.0))
 y.append(Foo(110.0))
 y.append(Foo(60.0))
 
 ys=[]
 y_max=0.0
 y_min=0.0
 
 for s in y:
 ys.extend([s.x])
 y_max=max(s.x,y_max)
 y_min=min(s.x,y_min)
 
 yz=[]
 for i in range(len(ys)-1):
 yz.append(ys[i+1]-ys[i])
 
 What I hoped I could do:
...
 yz=[y[:-1].x-y[1:].x]

Based on the code that runs, you want* this:

[(y[x+1].x-y[x].x) for x in range(len(y)-1) ]

FWIW, - does not work across lists. You could use map if you wanted, but
personally I prefer the explicit loop which you wanted to not use:

 yz=[]
 for i in range(len(ys)-1):
 yz.append(ys[i+1]-ys[i])

Since personally I find that a lot clearer than:

map(float.__sub__, [X.x for X in y[1:]], [X.x for X in y[:-1] ])

Regards,


Michael.

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


A bit OT: Python prompts display as nested mail quotes in Thunderbird

2006-03-09 Thread Joel Hedlund
Hi

Sorry to bother you with my OT problems, but my newsgroup reader (Thunderbird) 
displays explicitly written python prompts as triple nested mail quotes (with 
lines in alternating colors in the margins). That's pretty tiresome to look at 
in a python newsgroup. Therefore, I'm looking for a way to display messages 
from this newsgroup *In Plain Text*.

I tried View  Message Body As  Plain Text but that did nothing. 

I'm not sure what to search for so I didn't get far neither with Google or the 
Mozilla Thunderbird FAQ or newsgroup.

Has anyone else encountered/solved this problem? Should I get another newsgroup 
reader? In that case, which? I'm running Thunderbird 1.0.7 on Ubuntulinux 5.10.

Thank you for your time,
Joel Hedlund
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice on this little script

2006-03-09 Thread John Salerno
Steve Holden wrote:

 You might also want to synchronize to a caesium clock, but the guy is 
 timing his laundry, for Pete's sake! Can we agree your approach, while 
 theoretically sound, might be a little over-complicated for a first 
 application?

LOL. Thanks, I was about to fall out of my chair!  :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New python.org website

2006-03-09 Thread msoulier
I don't mind the logo or the colour scheme, but I do mind the first
paragraph in bolded text. What, you figure the readers can't figure out
how to find What is Python? by themselves?

Bold should be used sparingly. This is serious overuse.

Otherwise, I like it.

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


Re: advice on this little script

2006-03-09 Thread John Salerno
Alex Martelli wrote:

 I only use the 'from' statement to import specific modules from a
 package, never to import specific objects (functions, classes, or
 whatever) from a module.

I like that. So in my case I'd use 'import time' (which I actually 
already changed last night). I think especially right now, while I'm new 
to Python, it helps me to see 'time.sleep' instead of just 'sleep', so I 
can begin to associate certain functions with their proper modules.

Not to mention, like you said, that importing specific pieces like 
functions tends to look a little messy in the code when they aren't 
qualified.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get a page's html code via a proxy

2006-03-09 Thread JuHui
thank you! I am not good at it.

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


Re: advice on this little script

2006-03-09 Thread Alex Martelli
Kent Johnson [EMAIL PROTECTED] wrote:
   ...
 If you use from xx import yy, searching for yy will show you its 
 provenance as well.

But when seeing the barename yy, it gives no clue whether the module
you're reading used 'from xx import yy' or defined yy in any other way
(localy, globally, or in any intermediate scope).

'from' has many other disadvantages, such as working badly with reload
_except_ when used specifically to import a module.


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


Re: Python Evangelism

2006-03-09 Thread Felipe Almeida Lessa
Em Qui, 2006-03-09 às 09:51 +, Steve Holden escreveu:
 I've been thinking (and blogging) about python evangelism since PyCon, 
 as a result of which I created a squidoo lens:
 
http://www.squidoo.com/pythonlogy
 
 Imagine my surprise at discovering that this has gone up in rank (by 
 number of views) from # 442,000 or so to #153! Clearly there's some 
 mileage in marketing Python, and I'd like to keep the buzz going if it 
 means more people will adopt the language.
 
 Any suggestions for improvement?

Why don't you mention ReportLab there? I never saw a better library for
creating PDFs in *any* language. For creating crude reports it may be a
little more difficult than things like JasperReports, but for custom
reports full of different forms of data presentations and such, like I'm
doing now (and I plant to post later on ReportLab's samples page) it
just rocks!

Just my two cents,
Felipe.

-- 
Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas.

  -- Sun Tzu, em A arte da guerra

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

Re: First script, please comment and advise

2006-03-09 Thread bearophileHUGS
My version is similar to Just one:

from random import shuffle

def scramble_text(text):
Return the words in input text string scrambled
except for the first and last letter.
def scramble_word(word):
if len(word)  4: return word
core = list(word[1:-1])
shuffle(core)
return word[0] + .join(core) + word[-1]

return  .join(map(scramble_word, text.split()))

print scramble_text(scramble_text.__doc__)

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


Hashtables in pyhton ...

2006-03-09 Thread Konrad Mühler
Hi,

are there predefinded chances to use hashtables in python? How can I use 
Hashtable in python? Or do I have to implement this on my own?

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


Re: why no block comments in Python?

2006-03-09 Thread msoulier
 (and if you don't, you can quickly comment out regions by putting them
 inside a triple-quoted string.)

Although that will use up memory, as opposed to a comment.

Still, it's simple enough in an editor like Vim or Emacs to highlight a
region, and define a macro to add/remove #s. Any Python IDE should
certainly have this capability.

Mike

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


Re: why no block comments in Python?

2006-03-09 Thread Roy Smith
msoulier [EMAIL PROTECTED] wrote:
 (and if you don't, you can quickly comment out regions by putting them
 inside a triple-quoted string.)

Although that will use up memory, as opposed to a comment.

I can't imagine a realistic scenario where the amount of memory wasted
by triple-quoting out code could possibly be significant.

I'll also repeat what I said before -- good software engineering
practice demands that you remove dead code completely.  Commenting
something out for a quick test during development is OK, but once it
reaches the production stage, get rid of it.  It'll still live in your
revision control system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why no block comments in Python?

2006-03-09 Thread Peter Otten
msoulier wrote:

 (and if you don't, you can quickly comment out regions by putting them
 inside a triple-quoted string.)
 
 Although that will use up memory, as opposed to a comment.
 
Doesn't seem so:

 def f():
... docstring
... another string
... a = 42
... yet another string
...
 f.func_code.co_consts
('docstring', 42, None)


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


Re: Hashtables in pyhton ...

2006-03-09 Thread Max M
Konrad Mühler wrote:
 Hi,
 
 are there predefinded chances to use hashtables in python? How can I use 
 Hashtable in python? Or do I have to implement this on my own?


  a_hash_is_a_dict = {'key':'value'}
  a_hash_is_a_dict['key2'] = 'value 2'
  a_hash_is_a_dict['key']
'value'

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice on this little script

2006-03-09 Thread Alex Martelli
John Salerno [EMAIL PROTECTED] wrote:

 Alex Martelli wrote:
 
  I only use the 'from' statement to import specific modules from a
  package, never to import specific objects (functions, classes, or
  whatever) from a module.
 
 I like that. So in my case I'd use 'import time' (which I actually 
 already changed last night). I think especially right now, while I'm new
 to Python, it helps me to see 'time.sleep' instead of just 'sleep', so I
 can begin to associate certain functions with their proper modules.

I'm hardly new to Python, yet it keeps helping me too;-).


 Not to mention, like you said, that importing specific pieces like 
 functions tends to look a little messy in the code when they aren't 
 qualified.

I wouldn't call it messy, but rather potentially confusing in a large
module with many imports -- in the middle of the module,

a = b(c)

always gives the strong impression that b and cc are local or global (or
from an intermediate lexical scope), while

a = X.b(Y.c)

contains hints suggesting otherwise (if I had no clue what X and Y were
at this point, I'd _first_ check if they were imported modules, while it
would be my last resort in the former snippet regarding b and c).


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


  1   2   3   >