Re: Markov process representation

2006-03-16 Thread Max M
Jack Diederich wrote:
 On Wed, Mar 15, 2006 at 04:50:31PM -0800, Paul Rubin wrote:
 
kpp9c [EMAIL PROTECTED] writes:

self._all_states |= set(key[i] for key in probabilities)
I am running:
Python 2.3 (#1, Sep 13 2003, 00:49:11)

generator comprehensions are new in 2.4.  Try:

   self._all_states |= set([key[i] for key in probabilities])
 
 
 And sets aren't a builtin in 2.3
 
 try:
   set()
 except NameError:
   import sets
   set = sets.Set

nitpick:

try:
 set
except NameError:
 from sets import Set as set

-- 

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: Is it better to use class variables or pass parameters?

2006-03-16 Thread Eric Brunel
On 15 Mar 2006 15:04:19 -0800, Derek Basch [EMAIL PROTECTED] wrote:

 One more question everybody. Say you have a class that performs a
 series of evaluations on several strings of peptides.

Errr..., no? A class does not perform some operations. A class is a  
template for objects. What are your objects? If you had a class Peptide  
for example (I'm guessing here; I'm not exactly fluent in this domain), I  
would have understood. But what you're describing here is not a class;  
it's just a set of functions.

 Heres the class:

 class PeptideEvaluator:

 def evaluate(self, peptide):
 peptide_name = peptide + Rules!
 result1 = self.test1(peptide, peptide_name)
 result2 = self.test2(peptide, peptide_name)
 result3 = self.test3(peptide, peptide_name)

 def test1(self, peptide, peptide_name):
 f = open(peptide_name + .txt, w)
 f.write(peptide)
 f.close()

 def test2(self, peptide, peptide_name):
 f = open(peptide_name + .txt, w)
 f.write(peptide)
 f.close()

 def test3(self, peptide, peptide_name):
 f = open(peptide_name + .txt, w)
 f.write(peptide)
 f.close()

 So, you instantiate a class called PeptideEvaluator and pass in each
 string to its evaluate method. Now you have to repeatedly pass the
 peptide and peptide_name to each function. According to what everyone
 has said declaring them as class variables is bad because they are not
 related to the state of the PeptideEvaluator. How can I avoid having
 to pass the same parameters all over a class? I can';t quite seem to
 wrap my head around this one.

QED: this class has no need at all for attributes, and does not even  
have a constructor. This is usually a strong signal that what you're doing  
is wrong. Just turn this class into a module containing functions. Or put  
these methods into another class (the Peptide class may be a good  
candidate if you have one; evaluating a peptide seems to be an operation  
that you do on peptides).

HTH
-- 
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 The problem I'm trying to solve is.
 There is a 5x5 grid.
 You need to fit 5 queens on the board such that when placed there are
 three spots left that are not threatened by the queen.

when you're done with your homework (?), you can compare it with
Guido's solution:

http://svn.python.org/view/python/trunk/Demo/scripts/queens.py

/F



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


Re: Tried Ruby (or, what Python *really* needs or perldoc!)

2006-03-16 Thread Nick Craig-Wood
Jason Earl [EMAIL PROTECTED] wrote:
  Why don't you instead install the info version of the Python
  documentation on your server.  Then you can do info Python2.3-lib
  and have at it.

I didn't know about that.  Its very good.

Its still not all the documentation for all the installed modules
(a-la perltoc) but it is much better than I thought!

info on its own reveals these possible info packages for python

Python
* Python2.3-api: (python2.3-api).   Python/C 2.3 API Reference Manual
* Python2.3-dist: (python2.3-dist). Distributing Python Modules (2.3)
* Python2.3-ext: (python2.3-ext).   Extending  Embedding Python 2.3
* Python2.3-lib: (python2.3-lib).   Python 2.3 Library Reference
* Python2.3-ref: (python2.3-ref).   Python 2.3 Reference Manual
* Python2.3-tut: (python2.3-tut).   Python 2.3 Tutorial

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


can httplib.HTTPConnection use proxy?

2006-03-16 Thread JuHui
how to use httplib.HTTPConnection with http proxy?

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


can httplib.HTTPConnection use proxy?

2006-03-16 Thread JuHui
how to use httplib.HTTPConnection with http proxy?

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


asyncore/asynchat do not notify connection errors on Wintel?

2006-03-16 Thread Z. Kotzer
I can not get error notifications when an asynchat based client tries to 
connect to a non-responsive address.

To validate the problem I changed lib/test/test_asynchat.py as follows:


class echo_client(asynchat.async_chat):
def __init__(self):
asynchat.async_chat.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect(('10.135.0.2', PORT)) #  Instead of HOST - set 
an address that does not listen to this port
self.set_terminator(\n)
self.buffer = 

#  And added an error handler
def handle_error(self):
print 'ERROR'


Running it prints nothing - handle_error is not called and nothing is raised 
from asyncore.loop().

Debugging it shows that asyncore.connect gets EWOULDBLOCK and returns 
normally (as may be expected), select in asyncore.poll returns nothing 
(including empty e) and the socket remains forever.

Anybody has an experience with this behaviour?

Thanks in advance! 


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


Re: Is it better to use class variables or pass parameters?

2006-03-16 Thread Steve Holden
Derek Basch wrote:
 So, if I am understanding what everyone is saying here. I should do my
 best to distinguish between values that are part of the state of an
 object and values that are more disposable and can change for each
 computation of a value. So if I create an instance of a wallet class
 and the color of the wallet is red. The red value would be ideal as
 a class variable as it is tied to the state of that wallet instance.

Nope. Technically that would be an *instance* variable - each wallet 
instance can have a different colour. [This may be what you mean in 
whcih case please regard this as correcting your language, not your 
thinking. Class variables are available, and are normally single values 
share among all instances of a class.].

 However, if the wallet class contains a function to compute the tax on
 a purchased item, the purchase price would be a good example of a
 passed parameter value. Am I on the right track?
 
Yes, that would be correct.

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: Printable string for 'self'

2006-03-16 Thread Duncan Booth
Michael Tobis wrote:

 I got in some trouble in these parts a few months back for advocating
 some sort of immutable reference, like
 
 fred - C(fred)
 
 where any reassignment of the refernce during the lifetime of the
 referent would raise an exception. This seems to be seen as wrongheaded
 by greater pythonistas than myself.  I don't fully understand *why*
 this is a bad idea, but my intuitive idea that it would be very
 valuable has gone away.
 

 fred = C(fred)
 jim = fred
RebindingError: cannot rebind C object 'fred' to name jim
 def showit(x):
print x


 showit(fred)
RebindingError: cannot rebind C object 'fred' to name x
 fred.amethod()
RebindingError: cannot rebind C object 'fred' to name self
 fred.aclassmethod()
That works!
 sys.getrefcount(fred)
RebindingError: cannot rebind C object 'fred' to name object
 del fred


What were you planning to do with this object exactly that didn't involve 
binding it to any other names during its lifetime?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing PySQLite on OS X 10.4

2006-03-16 Thread Rob Cowie
Cheers. I should have read the installation notes more carefully :)

Rob C

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


Re: Button and Key Event

2006-03-16 Thread lux
Thanks,
I think that the solution for my problem is only to use an
AcceleratorTable.
In this way I can capture the key pressed event
without the button problem

Luca

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


Re: Install Universal Encoding Detector

2006-03-16 Thread Jacob
How do I uninstall?

/Jacob

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


Re: Python Debugger / IDE ??

2006-03-16 Thread Ritesh Raj Sarraf
Can you please point some good documents (need not be Python specific)
on best practices with writing code this way ?

Thanks,
Ritesh

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


Re: comparing huge files

2006-03-16 Thread s99999999s2003
thanks for the reply,
I have used another method to solve my problem. ie
1) get the total count of the first file
2) write this total count to basecnt eg basecnt
3) get another file, get the total count of this file. eg filecnt
4) if filecnt  basecnt, read in the values from file[basecnt:filecnt]
5) if filecnt  basecnt, overwrite original basecnt and start over
again.

basically, the problem domain is i want to get the most current records
from a log file to review after every 3 hours. so this log file will
increase or accumulate.

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


Re: Other languages for PVM

2006-03-16 Thread Diez B. Roggisch
Ravi Teja wrote:

 Yes! But not many.
 
 http://www.livelogix.net/logix/

Interesting.

 
 Logix also allows you to create your own custom languages for Python's
 VM. But for some reason, there does not seem to be much interest in
 it's development. Odd, given that it has great potential.

I can only speculate - but I guess part of this lack of interest stems from
the fact that the PVM evolves around python itself - in contrast to JAVA,
where the JVM-spec is independen from the language itself. So a
PVM-dependend developer has way lesser guarantees that his endeavors will
work on the next generation PVM.

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


Re: recycling internationalized garbage

2006-03-16 Thread Fredrik Lundh
Martin v. Löwis wrote:

 It should be obvious that any 8-bit single-byte character set can
 produce byte sequences that are valid in UTF-8.

 It is certainly possible to interpret UTF-8 data as if they were
 in a specific single-byte encoding. However, the text you then
 obtain is not meaningful in any language of the world.

Except those languages that uses words consisting of runs of accented
letters immediately followed by either undefined characters or odd sym-
bols, and never use accented characters in any other way.

(Given that the freedb spec says that it's okay to mix iso-8859-1 with
utf-8 on a record-by-record level, one might assume that they've de-
cided that the number of bands using such languages is very close to
zero...)

/F 



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

Re: Install Universal Encoding Detector

2006-03-16 Thread Kent Johnson
Jacob wrote:
 How do I uninstall?

Delete the chardet folder from site-packages (Python24\Lib\site-packages 
on Windows, not sure of the exact path on other OS's).

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


Re: mod_python installation

2006-03-16 Thread Kai Schulte
The Debian stable package tree has only libapache2-mod-python2.3 (3.1.3-3). 
You can look at http://packages.debian.org/stable/python/ for a detailed 
list.

If you really want to use python2.4 you can either try to use the ubuntu 
package 
(http://packages.ubuntu.org.cn/breezy/python/libapache2-mod-python2.4) but I 
would not recommend it, since it could break your system.
Or you could search a backport, may be there is one.


Am Montag, 30. Januar 2006 15:21 schrieb Ravi Teja:
 I have Ubuntu which uses the Debian package tree.
 I see libapache2-mod-python2.4 with apt-cache search mod_python
 Perhaps you don't have all the repositories enabled?

Ubuntu uses mostly the debian testing/unstable or even  experimental package 
tree plus its own package tree, so there are a few packages only available to 
Ubuntu.
-- 
http://mail.python.org/mailman/listinfo/python-list


Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread [EMAIL PROTECTED]
The python code below generates a cartesian product subject to any
logical combination of wildcard exclusions. For example, suppose I want
to generate a cartesian product S^n, n=3, of [a,b,c,d] that excludes
'*a*b*' and '*c*d*a*'. See below for details.

CHALLENGE: generate an equivalent in ruby, lisp, haskell, ocaml, or in
a CAS like maple or mathematica.

#---
# Short algorithm description
# using function _genAll the program generates
# cartesian product without sets, which match
# some wildcarts
# Sets generation uses recursion -
# first of all sets will be generated with dimension 1 and than
filtered through wildcarts
# then sets will be generated with dimension 2 and filtered again
# until the required set dimension is reached
# Program avoids explicit generation of some part of CP sets
# if the end of whildcart is asterics (*) and if the first part of
whildcart (without astrics)
# matches current set = then this set will be filtered out and won't
be used in
# higher dimension set generation
# example *,1,*,2,* [1,2] dim = 10
# by dimension 2 only arrays [1,1],[2,1],[2,2] are will be generated
# = array [1,2] won't be used in next recursion levels
#---
# To obtaine result use function
# CPWithoutWC first parameter is a list of any elements
(char,int,string,class exemplar , any type)
# secont param is CP dimension
# other parameters are wildcarts = lists with any values then may
include
# special value ALL - asterics equivalent
#Example of usage: command line
#  import cartesianProduct as cp
#  for i in cp.CPWithoutWC([1,2],3,[1,cp.ALL,2]):
# print i
# [1, 1, 1]
# [1, 2, 1]
# [2, 1, 1]
# [2, 1, 2]
# [2, 2, 1]
# [2, 2, 2]
#  for i in
cp.CPWithoutWC(['a','b'],3,['a',cp.ALL,'b'],['b',cp.ALL,'a']):
# print i
# ['a', 'a', 'a']
# ['a', 'b', 'a']
# ['b', 'a', 'b']
# ['b', 'b', 'b']
#  for i in cp.CPWithoutWC([1,2],3,[1,cp.ALL,2],[2,cp.ALL,1]):
#print i
# [1, 1, 1]
# [1, 2, 1]
# [2, 1, 2]
# [2, 2, 2]
# 
#  for i in cp.CPWithoutWC([1,2],121212,[1,cp.ALL],[2,cp.ALL,1]):
#print i
##  execute immediately
# 
# if You don't want to print cp. before ALL and CPWithoutWC use import
like this:
# from cartesianProduct import ALL,CPWithoutWC
# CPWithoutWC is a python generator. Which means that it returns values

# immediately and generate next in next cycle.
# Program example
#
## from cartesianProduct import ALL,CPWithoutWC
## def main():
## for i in
cp.CPWithoutWC(['a','b'],3,['a',cp.ALL,'b'],['b',cp.ALL,'a']):
## ## do what You want with current value
## .
## ## go back to for statement and generate new
## if __name__ == __main__:
## main()
#

 Using logical combinations of WC:
 1) It's possible to pass on to the function CPWithoutWC
   any number of wildcarts after first two parameters, for example:
   CPWithoutWC([1,2],121212,[1,cp.ALL],[2,cp.ALL,1],...)
   where ... - is any other wildcart's additional function parameters.
   Number of additional WC is not limited.
   Function will filter out all combinations, which match any passed on
WC.
   It's equal to WC1 | WC2 |  , where | is python analog of OR
logical operations.
 2) To use more complex WC combinations follow these steps
   a) First of all create all needed WC
   b) Then use operators |,  and braces () to create combinations
required and then pass it on to function
   CPWithoutWCEx as the third parameter. Don't use or and and
python statement, otherwise program will
   work improper. First two parameters of this function are the same as
of CPWithoutWC function - set of
   elements and CP dimension. An example of what was described above in
command line:
from cartesianProduct import ALL,CPWithoutWC,CPWithoutWCEx,WC
a = WC([ALL,1,ALL])
b = WC([ALL,2,ALL])
c = a  b #filter out all sets which match a and b
for i in CPWithoutWCEx([1,2],3,c) : print i
   [1, 1, 1]
   [2, 2, 2]
# all sets where both 1 and 2 are present will be filtered out
d = a | b
for i in CPWithoutWCEx([1,2],3,d) : print i
# returns nothing
for i in CPWithoutWCEx([1,2,3],3,d) : print i
   [3, 3, 3]
a = WC([2,1,ALL])
b = WC([1,2,ALL])
c = WC([ALL,2])
d = ( a | b )  c
for i in CPWithoutWCEx([1,2],3,d) : print i
   [1, 1, 1]
   [1, 1, 2]
   [1, 2, 1]
   [2, 1, 1]
   [2, 2, 1]
   [2, 2, 2]
# filters out all combinations which start with [1,2] or [2,1]
and end with 2

   Number of WC, which are used to form logical combinations is not
limited.


13.02.2006
a)Two new function - CPWithoutWCEx_L and CPWithoutWC_L are added.
Their interface is the same as of CPWithoutWCEx and CPWithoutWC
accordingly, except that the third parameter is WC list and
they accept strictly three parameters.

As You can see these functions are very simple because
python is quite flexible =
 def s(x,y): 

Re: Is it better to use class variables or pass parameters?

2006-03-16 Thread Terry Hancock
On 15 Mar 2006 15:04:19 -0800
Derek Basch [EMAIL PROTECTED] wrote:
 
 class PeptideEvaluator:
 
 def evaluate(self, peptide):
 [...]
 
 So, you instantiate a class called PeptideEvaluator and
 pass in each string to its evaluate method. Now you have
 to repeatedly pass the peptide and peptide_name to each
 function. According to what everyone has said declaring
 them as class variables is bad because they are not
 related to the state of the PeptideEvaluator. How can I
 avoid having to pass the same parameters all over a class?
 I can';t quite seem to wrap my head around this one.

PeptideEvaluator suggests it's meant to act on some
data object and produce a result object (you're
reinventing functions, using object-oriented machinery?).

A more usual OOP approach is to make an object Peptide
which models the peptide, then put the methods on it.
When you instantiate Peptide you tell it what its sequence
is, and the methods provide your analysis -- you ask the
object itself to give you the results.  Then, of course,
the peptide sequence *IS* a fundamental property of the
object.

If you have to separate this functionality into a separate
object, you should immediately be asking yourself why? Is
there a compelling reason you need *two* objects that have
to communicate over an interface when one will do? 
(Sometimes there are).

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Cheese Shop: some history for the new-comers

2006-03-16 Thread Terry Hancock
On Sun, 12 Mar 2006 11:58:05 -0500
Peter Decker [EMAIL PROTECTED] wrote:
 Of course, you're straying so far from the original
 thought behind this thread, and that is that the Python
 website is using some terms differently than the majority
 of people who will eventually use the site would
 understand them. The number of people who are brilliant
 enough to actually contribute to the development of the
 Python language is miniscule compared to the potential
 number of programmers out there who could adopt Python as
 their language of choice, and thus consider themselves
 'Python developers'.

But the usual distinction (on any project web page) is
User versus Developer.

Who is a user of Python? That would be you, right? It
would be fairly silly to have a page only for people who
have programs written in Python that they use (they're
*your program*'s users, not *python*'s users).

Developer, in context, is clearly one who *develops*
python, not one who *uses* python to develop programs.

I don't see the ambiguity. I would be confused by the
opposite usage.

However, what you are complaining of is similar to the
situation with Zope, where user actually does have a sane
interpretation (basically designer or scripter), while a
developer is someone working on the Zope core. People who
develop using Zope are (still, I think) underrepresented
-- there never was a product developer or component
developer mailing list, I don't think.

In that context, some people use a term like Core
Developer.  It seems a little redundant to me, but perhaps
it would be less ambiguous?

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Cheese Shop: some history for the new-comers

2006-03-16 Thread Terry Hancock
On Tue, 14 Mar 2006 13:22:09 -0700
Steven Bethard [EMAIL PROTECTED] wrote:
 A.M. Kuchling wrote:
  On Sun, 12 Mar 2006 10:25:19 +0100, 
  Fredrik Lundh [EMAIL PROTECTED] wrote:
  and while you're at it, change python-dev to
 developers and  psf to foundation (or use a title
 on that link).
  
  I've changed the PSF link, but am not sure what to do
  about the python-dev link.  As others have noted,
  Developers is ambiguous about whether it's for people
  who develop in Python or who develop Python itself.   
  Core Development?  (Used on both perl.org and tcl.tk,
  so maybe this is the best option.) Development Team?  
 
 +1 on Core Development.  It's still ambiguous, but less
 so.  And I can't  think of anything better. ;)

Since I just said almost that independently on an earlier
thread, I guess that makes me +1 on Core Development (or
Core Developers) myself.

 -- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Tried Ruby (or, what Python *really* needs or perldoc!)

2006-03-16 Thread Terry Hancock
On Wed, 15 Mar 2006 23:10:16 +0100
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 In [EMAIL PROTECTED], Diez B. Roggisch wrote:
 
  Yes, I'm trying to make time to look at the docutils
 code and the  pydoc command to see what's involved.
 Unfortunately, my spare  time is vanishingly close to
 zero right now.
  
  
  You heard of epydoc? http://epydoc.sourceforge.net/
  
  It pretty much does what you say I think - and for my
  personal projects I use it. Maybe we an adopt it as
  standard-tool.
 
 Epydoc seems to be dead and pudge not yet alive:

What leads you to this conclusion?  Works pretty well for
me. Maybe it's just stable?

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


int - str asymmetric

2006-03-16 Thread Schüle Daniel
Hello

what I sometimes miss in Python is the possibility to
switch tha base of a number
for example this is how it's done in Ruby

irb(main):099:0* a = 10.to_s(2)
= 1010
irb(main):100:0 a.to_i(2)
= 10
irb(main):101:0
irb(main):102:0* a = 10.to_s(3)
= 101
irb(main):103:0 a.to_i(3)
= 10

the Python int-Function behaves similar
  int(1010,2)
10
 

however we lack the reverse functionality
the logical

  str(10,2)
Traceback (most recent call last):
   File stdin, line 1, in ?
TypeError: str() takes at most 1 argument (2 given)
 

fails

it would not break anything if str interface would be changed
what do you think?
Is this already proposed or maybe implemented in 2.5?

Regards, Daniel

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


Re: Python compiler

2006-03-16 Thread M�ta-MCI
Hi! Bonjour !

Après, vous pourrez aussi fréquenter le newsgroup :
fr.comp.lang.python
qui a l'avantage d'être en français.

à bientôt.

Michel Claveau




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

Re: MS word document generator

2006-03-16 Thread M�ta-MCI
Hi!

Yes, I have an idea. But... I has no time, actually.
Perhaps in 2 or 3 weeks...  Sorry.

Michel Claveau


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


A Frame-space syntax ? - Re: global, globals(), _global ?

2006-03-16 Thread robert
Alex Martelli wrote:
 robert [EMAIL PROTECTED] wrote:
...

I think its good to leave the default global binding (that is probably
whats Guido doesn't want to give up for good reason)
 
 
 Then, on the principle that there should be preferably only one obvious
 way to do something, we'll never have an _global object as you propose
 (even by any other and much better name;-), because it systematically
 produces TWO equally obvious or unobvious way to access globals.

a path to the globals whould maybe not much different from an alternate 
__dict__ or globals() access. and see below ..

Yet frames could expose their top-dict anyway as a virtual inspection
object (__l/__l_funcname or  __f_stack[-2]) . Or at least writing to
locals() could be defined as writing to the top-frame-locals. 
Sub-Frames could write free there (its a rare  conscious task anyway)
and the Frame itself could read either way.
 
 
 Not sure I entirely understand what you're proposing, but locals access
 must remain compile-time-optimized for crucial practical reasons, so
 writing to locals() just will not work right.

Why will a definite write to _certain_ top local dict consume any extra 
time?
The target can still be directed fix at compile time. See below.

Another ugly possibilties maybe by enriching variable assignment.

Maybe '=' can be enriched like   .= ..= :=  =: ::= =:: xxx-set ... etc.
in order to be an expression with result value and to allow to writing
to certain namspaces.
 
 
 Ugly enough that Guido has never wanted to entertain such possibilities

Maybe a syntax could be applied which is already known for float 
litterals and which seems to be intuitive and compatible to me:

a=1
.a=1 # same
d=5
def f()
 b=1
 .b=1 # same
 print a
 print ..a# same
 ..a += 1 # compile-time known: its the global!
 def g():
 ..b=2# f-local b !
 ..c=3# write a 'free local' into f-locals
 ..d=4
 ...a += 1   # the compiler knows: its global!
 g()
 print b  # local
 print 1 + .c # ok
 print c  # error!, but thats acceptable
 print d  # global
 print .d # local!, but thats acceptable


This syntax shows some kind of self-similarity:
* a dot . always references a definite dict/namespace/obj (or a float)
* a free dot . simply references the top local dictionary (or a float)
* more dots step back through the frame stack
* If no dot is there the usual automatic name space is assumed

No old code would be broken.

As far as I see this would not slow down the interpreter at run time 
(except maybe for the new ..b= intermediate local write's)

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


Re: MS word document generator

2006-03-16 Thread paron
You might also consider OpenOffice, which writes to ODF. That way,
you're working to a standard. You can script OpenOffice in Python
(http://udk.openoffice.org/python/python-bridge.html) . OpenOffice can
save in .doc, and does a pretty good job of making a file that most MS
Word versions will render properly.

According to http://opendocumentfellowship.org/Devel/LibOpenDocument,
there is a Python API in development, but I don't know how far along
they are. ODF isn't too bad to hack, if you need to do that.

Ron

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


Re: Cheese Shop: some history for the new-comers

2006-03-16 Thread Tim Parkin
Terry Hancock wrote:
 On Tue, 14 Mar 2006 13:22:09 -0700
 Steven Bethard [EMAIL PROTECTED] wrote:
 
A.M. Kuchling wrote:

On Sun, 12 Mar 2006 10:25:19 +0100, 
 Fredrik Lundh [EMAIL PROTECTED] wrote:

and while you're at it, change python-dev to

developers and  psf to foundation (or use a title
on that link).

I've changed the PSF link, but am not sure what to do
about the python-dev link.  As others have noted,
Developers is ambiguous about whether it's for people
who develop in Python or who develop Python itself.   
Core Development?  (Used on both perl.org and tcl.tk,
so maybe this is the best option.) Development Team?  

+1 on Core Development.  It's still ambiguous, but less
so.  And I can't  think of anything better. ;)
 
 
 Since I just said almost that independently on an earlier
 thread, I guess that makes me +1 on Core Development (or
 Core Developers) myself.
 
Sold to the man in the blue hat!! It's on the server now...

Tim Parkin

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


Re: asyncore/asynchat do not notify connection errors on Wintel?

2006-03-16 Thread Abdullah Yoldas
Normally when youmake a nonblockingconnect, socket gets EINPROGRESS, later the result of this request will appear after select returns.

I think asyncore/asynchat incorrectly interprets asychronous connects. Reading Steven's book, I did some modifications to asyncore.dispatcher and asynchat.async_chat asbelow to correctly interpret errors like: ECONNREFUSED, ETIMEDOUT, ENETUNREACH, EHOSTUNREACH, ENETDOWN. Then I used my custom base classes. In the code below I only show the approach for this situation. I have other modifications for other problems (infinte recursions etc.) but those are not shown here.


The reason is that when a socket connection makes connect, the descriptor becomes both readable and writable at the same time if there is a problem in connect. However, asyncore polling mechanism gets readable ready and writable ready separately. Therefore, it cannot detect connect errors. If you consider writability as a healthy condition (incorrectly) you would try to write without a connection establishment, this gives some other error but not the actual error, in handle_error().


Full discussion ofnonblocking connects can be found in chapter 16 of the book UNIX Network Programming Volume 1, Third Edition The Sockets Networking API, W. Richard Stevens, Bill Fenner, Andrew M. Rudoff


Here is my approach:

# drive from asyncore.dispatcher:
class base_channel(asyncore.dispatcher):
 
 def handle_read_event(self): if self.accepting: if not self.connected: self.connected = 1 self.handle_accept() elif not self.connected: 
self.handle_connect_event() else: self.handle_read()

 def handle_write_event(self): if not self.connected: self.handle_connect_event() else: self.handle_write()

 def handle_connect_event(self): err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) if err: raise socket.error, (err, os.strerror(err)) self.connected
 = 1 self.handle_connect()

# I mix the above base_channel
class base_chatter(base_channel, asynchat.async_chat):
 def __init__ (self, conn=None):
 base_channel.__init__(self, conn)
 self.ac_in_buffer = '' self.ac_out_buffer = '' self.producer_fifo = asynchat.fifo()

 def handle_close(self): asynchat.async_chat.handle_close(self)
 def handle_read(self): asynchat.async_chat.handle_read(self)
 def handle_write(self): asynchat.async_chat.handle_write(self)
 def readable(self): return asynchat.async_chat.readable(self)
 def writable(self): return asynchat.async_chat.writable(self)
Abdullah Yoldas

On 3/15/06, Z. Kotzer [EMAIL PROTECTED] wrote:
I can not get error notifications when an asynchat based client tries toconnect to a non-responsive address.
To validate the problem I changed lib/test/test_asynchat.py as follows:class echo_client(asynchat.async_chat): def __init__(self): asynchat.async_chat.__init__(self) self.create_socket
(socket.AF_INET, socket.SOCK_STREAM) self.connect(('10.135.0.2', PORT)) #  Instead of HOST - setan address that does not listen to this port
 self.set_terminator(\n) self.buffer =  #  And added an error handler def handle_error(self): print 'ERROR'
Running it prints nothing - handle_error is not called and nothing is raisedfrom asyncore.loop().Debugging it shows that asyncore.connect gets EWOULDBLOCK and returnsnormally (as may be expected), select in 
asyncore.poll returns nothing(including empty e) and the socket remains forever.Anybody has an experience with this behaviour?Thanks in advance!--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: can httplib.HTTPConnection use proxy?

2006-03-16 Thread JuHui
sorry, would you please give a sample code?
I want to use HTTPConnection to get a html page content via a http
proxy.
thanks.

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


bisect and Queue modules in Python 2.4

2006-03-16 Thread SA Trygubenko
Dear All,

Python 2.4 (#1, Mar 22 2005, 21:42:42)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type help, copyright, credits or license for more information.
  import Queue
  q=Queue.Queue()
  type(q.queue)
type 'collections.deque'
 

q.queue used to be a list, and now it is something else?

I was using bisect module to implement min priority queue, as described 
in python library reference (see 
http://www.python.org/doc/2.3.5/lib/bisect-example.html). I have found 
out that in Python 2.4 q.queue does not support insert anymore, which 
breaks bisect. Please help!

Thank you,
Semen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Tomasz Zielonka
[EMAIL PROTECTED] wrote:
 The python code below generates a cartesian product subject to any
 logical combination of wildcard exclusions. For example, suppose I want
 to generate a cartesian product S^n, n=3, of [a,b,c,d] that excludes
 '*a*b*' and '*c*d*a*'. See below for details.

 CHALLENGE: generate an equivalent in ruby, lisp, haskell, ocaml, or in
 a CAS like maple or mathematica.

What is your goal? You want to learn or to cause a flamewar? ;-)

Anyway, I found the problem entertaining, so here you go, here is my
Haskell code. It could be shorter if I didn't care about performance and
wrote in specification style. It's not very efficient either, because it
will generate all lists matching the given patterns.

In GHCi you can test it by:

$ ghci
:l WildCartesian.hs
test

I apologise for the lack of comments.

88888888
module WildCartesian where

import Data.Set (Set)
import qualified Data.Set as Set
import Control.Monad
import Control.Exception (assert)
import Maybe
import List

data Pat a = All | Lit a deriving Show

generateMatching :: (Ord a) = Int - Set a - [Pat a] - [[a]]
generateMatching 0   _[]= [[]]
generateMatching 0   _(_:_) = []
generateMatching len alphabet (Lit x : ps)
| x `Set.member` alphabet =
[ (x : xs) | xs - generateMatching (len - 1) alphabet ps ]
| otherwise =
[ ]
generateMatching len alphabet (All : ps) =
[ (x : xs)
| x - Set.toList alphabet
, xs - unionSorted
(generateMatching (len - 1) alphabet ps)
(generateMatching (len - 1) alphabet (All : ps)) ]
`unionSorted`
generateMatching len alphabet ps
generateMatching _   _[] = []

generateNotMatching :: (Ord a) = [a] - Int - [[Pat a]] - [[a]]
generateNotMatching alphabet len patterns =
generateMatching len alphaSet [All]
`subtractSorted`
foldr unionSorted []
(map (generateMatching len alphaSet .  simplifyPat) patterns)
  where
alphaSet = Set.fromList alphabet

simplifyPat (All : All : ps) = simplifyPat (All : ps)
simplifyPat (p : ps) = p : simplifyPat ps
simplifyPat [] = []

joinSorted :: Ord a = [a] - [a] - [(Maybe a, Maybe a)]
joinSorted (x1:x2:_) _ | assert (x1  x2) False = undefined
joinSorted _ (y1:y2:_) | assert (y1  y2) False = undefined
joinSorted (x:xs) (y:ys) =
case x `compare` y of
LT - (Just x, Nothing) : joinSorted xs (y:ys)
EQ - (Just x, Just y)  : joinSorted xs ys
GT - (Nothing, Just y) : joinSorted (x:xs) ys
joinSorted (x:xs) [] = (Just x, Nothing) : joinSorted xs []
joinSorted [] (y:ys) = (Nothing, Just y) : joinSorted [] ys
joinSorted [] [] = []

unionSorted :: Ord a = [a] - [a] - [a]
unionSorted xs ys = catMaybes (map (uncurry mplus) (joinSorted xs ys))

subtractSorted :: Ord a = [a] - [a] - [a]
subtractSorted xs ys = catMaybes (map f (joinSorted xs ys))
  where
f (Just x, Nothing) = Just x
f _ = Nothing

test = do
t [1,2] 3 [[Lit 1, All, Lit 2]]
t ['a','b'] 3 [[Lit 'a', All, Lit 'b'], [Lit 'b', All, Lit 'a']]
t [1,2] 3 [[Lit 1, All, Lit 2], [Lit 2, All, Lit 1]]
  where
t a b c = do
putStrLn (concat (intersperse   [generateMatching, show a, show b, 
show c]))
mapM_ (putStrLn . (  ++) . show) (generateNotMatching a b c)
88888888

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML)  (Linux || FreeBSD || math)
for work in Warsaw, Poland
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Tomasz Zielonka
Tomasz Zielonka wrote:
 putStrLn (concat (intersperse   [generateMatching, show a, show 
 b, show c]))

Minor correction: it should be generateNotMatching.

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML)  (Linux || FreeBSD || math)
for work in Warsaw, Poland
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bisect and Queue modules in Python 2.4

2006-03-16 Thread Peter Otten
SA Trygubenko wrote:

 q.queue used to be a list, and now it is something else?
 
 I was using bisect module to implement min priority queue, as described
 in python library reference (see
 http://www.python.org/doc/2.3.5/lib/bisect-example.html). I have found
 out that in Python 2.4 q.queue does not support insert anymore, which
 breaks bisect. Please help!

class PriorityQueue(Queue.Queue):
def _put(self, item):
bisect.insort(self.queue, item)
def _init(self, maxsize):
self.maxsize = maxsize
self.queue = []
def _get(self):
return self.queue.pop(0)

or somesuch might work.

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


Re: looking for atomixlib

2006-03-16 Thread Rocco
here you'll find it in svn.
http://trac.defuze.org/browser/oss

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


Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Michael Spencer
Fredrik Lundh wrote:
 [EMAIL PROTECTED] wrote:
 
 The problem I'm trying to solve is.
 There is a 5x5 grid.
 You need to fit 5 queens on the board such that when placed there are
 three spots left that are not threatened by the queen.
 
 when you're done with your homework (?), you can compare it with
 Guido's solution:
 
 http://svn.python.org/view/python/trunk/Demo/scripts/queens.py
 
 /F
 
 
 
Or, Tim Peters' generator-based one:

http://svn.python.org/view/python/trunk/Lib/test/test_generators.py

Michael

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


Python Documentation Standards

2006-03-16 Thread Colin J. Williams
Doc strings provide us with a great opportunity to illuminate our code.

In the example below, __init__ refers us to the class's documentation,
but the class doc doesn't help much.

Are there any guideline which cover such things?

PEP 8 http://www.python.org/doc/peps/pep-0008/ has general advice.
PEP 257 http://www.python.org/doc/peps/pep-0257/ provides more
detailed advice.

list provides a trivial example because it is very well documented
elsewhere but it does provide a template for others.

Colin W.

Colin W.
  list.__init__.__doc__
'x.__init__(...) initializes x; see x.__class__.__doc__ for signature'
  list.__new__.__doc__
'T.__new__(S, ...) - a new object with type S, a subtype of T'
  list.__class__.__doc__
type(object) - the object's type\ntype(name, bases, dict) - a new type
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Tomasz Zielonka
Major correction (missing case):

Tomasz Zielonka wrote:
 generateMatching :: (Ord a) = Int - Set a - [Pat a] - [[a]]
 generateMatching 0   _[]= [[]]
  generateMatching 0   alphabet (All:ps) = generateMatching 0 alphabet ps
 generateMatching 0   _(_:_) = []

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML)  (Linux || FreeBSD || math)
for work in Warsaw, Poland
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python debugging question

2006-03-16 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 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.

If you first write 500 lines of code, and *then* try to run it,
it seems you are using a development approach suitable in the
1960's when running a program meant handing a stack of punch
cards to a computer operator in a white coat, and then getting
the result of the run the next day (if you're lucky).

I was taught to write like this as recently as in the late 80's
when I was in universtity, but today I typically run my code
every ten minutes or so. It's rare that I run the code I work
on less frequently than every thirty minutes.

In my experience, my current way of developing software leads to
higher productivity, better quality and much better predictability
in regards to both development time and software performance and
features. The way to achieve this is to use lots of automated
tests and a development time where you learn to work in small
increments. Martin Fowler's book Refactoring is a good guide
for this, and Python is a very good language to use for this kind
of development.

Perhaps this might be useful?
http://www.thinkware.se/cgi-bin/thinki.cgi/SoftwareTestingWithPython
http://thinkware.se/epc2004test/log.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int - str asymmetric

2006-03-16 Thread Steven Bethard
Schüle Daniel wrote:
 however we lack the reverse functionality
 the logical
 
   str(10,2)
 Traceback (most recent call last):
   File stdin, line 1, in ?
 TypeError: str() takes at most 1 argument (2 given)
  
 
 fails
 
 it would not break anything if str interface would be changed
 what do you think?
 Is this already proposed or maybe implemented in 2.5?

It's been proposed:

http://mail.python.org/pipermail/python-dev/2006-January/059789.html

But it didn't look like there was a resolution.

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


Re: Python Debugger / IDE ??

2006-03-16 Thread Don Taylor
Christoph Zwerschke wrote:
 [EMAIL PROTECTED] wrote:
 
I like the Pyscripter, is there any Linux version or something of it.
 
 
 Sorry, I forgot to mention that there is a snag in it. Since PyScripter 
 is based on Python for Delphi, it is available for Windows only.


Is there a free or low-cost version of Delphi for Windows available 
anywhere?

Pyscripter looks interesting but when I went to the Borland site to find 
out about the cost of Delphi I went into catatonic shock. They can't be 
serious.

Then I read on Wikipedia that On February 8th, 2006, Borland announced 
that it was looking for a buyer for its IDE and Database line of 
products, which included Delphi, to concentrate on its Application 
Lifecycle Management line.

So I guess it is at the end of its life, at least with Borland.  Maybe 
they will FOSS it?  Nah...

Don.

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


Re: Python Documentation Standards

2006-03-16 Thread Steven Bethard
Colin J. Williams wrote:
 Doc strings provide us with a great opportunity to illuminate our code.
 
 In the example below, __init__ refers us to the class's documentation,
 but the class doc doesn't help much.

It doesn't?

  print list.__doc__
list() - new list
list(sequence) - new list initialized from sequence's items

What is it you were hoping to see in constructor documentation?

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


Re: Tried Ruby (or, what Python *really* needs or perldoc!)

2006-03-16 Thread Steve Juranich
[EMAIL PROTECTED] wrote:

 This release is as alpha as alpha gets. It's so alpha it
 actually loops back around to zeta -- but it's a start, and I
 think it's exactly what the Python community needs.

Not to pick nits, but that should actually be ... so alpha that it actually
loops back around to *OMEGA*.

Cheers.

-- 
Steve Juranich
Tucson, AZ
USA

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


Re: A Frame-space syntax ? - Re: global, globals(), _global ?

2006-03-16 Thread Alex Martelli
robert [EMAIL PROTECTED] wrote:
   ...
  Not sure I entirely understand what you're proposing, but locals access
  must remain compile-time-optimized for crucial practical reasons, so
  writing to locals() just will not work right.
 
 Why will a definite write to _certain_ top local dict consume any extra
 time?

Writing to a dict intrinsically takes longer than writing to a fixed
offset into a vector.  locals(), as a dict, is in fact built as a shim
on top of the fixed vector where a function's locals are kept. We're
talking of a difference in timing of over a factor of two, over a
microsecond per local-variable access on my laptop -- the average
function does so much locals-accessing that I would expect it to slow
down proportionally, by a factor of two or so, if locals were actually
kept in a dictionary rather than in a vector.

Try it out by running the same code as a module's main body versus
running it as a function -- see how much the latter approach speeds
things up. Indeed, put the code inside a function is the first
optimization tip to give to any newbie, exactly because a module's
top-level code actually does read/write a dict for each variable access,
while a function's body code does not.

 The target can still be directed fix at compile time. See below.

None of the examples you give below exemplifies writing to
locals() could be defined as writing to the top-frame-locals as you had
proposed in the snippet I was responding to.


  Ugly enough that Guido has never wanted to entertain such possibilities
 
 Maybe a syntax could be applied which is already known for float 
 litterals and which seems to be intuitive and compatible to me:
 
 a=1
 .a=1 # same

Just about exactly this syntax was recently discussed on python-dev and
Guido (and many others) shot it down in no time. Please do take the tiny
trouble to research the python-dev archives, as I already suggested,
before proposing something that's so recently been roundly rejected.

 As far as I see this would not slow down the interpreter at run time 
 (except maybe for the new ..b= intermediate local write's)

Each local access that goes to a dict instead of a fixed vector will
intrinsically and inevitably slow down by 2-3 times. And the fact that
sometimes accessing a local c is the same as accessing .c, and sometimes
it isn't, is something I'm *EXTREMELY* happy to not have to teach,
explain, and justify.


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


Re: bisect and Queue modules in Python 2.4

2006-03-16 Thread Alex Martelli
Peter Otten [EMAIL PROTECTED] wrote:

 SA Trygubenko wrote:
 
  q.queue used to be a list, and now it is something else?
  
  I was using bisect module to implement min priority queue, as described
  in python library reference (see
  http://www.python.org/doc/2.3.5/lib/bisect-example.html). I have found
  out that in Python 2.4 q.queue does not support insert anymore, which
  breaks bisect. Please help!
 
 class PriorityQueue(Queue.Queue):
 def _put(self, item):
 bisect.insort(self.queue, item)
 def _init(self, maxsize):
 self.maxsize = maxsize
 self.queue = []
 def _get(self):
 return self.queue.pop(0)
 
 or somesuch might work.

Yep, it should, but using heapq instead of bisect is, I suspect, way
better -- there's a recipe on the Cookbook for that (Queue+heapq), and
though I (of course;-) prefer the version as edited for the printed
(2nd) edition, the online one can also no doubt be useful.


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


Re: bisect and Queue modules in Python 2.4

2006-03-16 Thread Abdullah Yoldas
I had a similar problem when i was using asynchat.fifo, it had a list in the past now it has a deque. So in order to put something to zeroth location (to be compatible with python 2.3 and python 2.4) I did something like:


class fifo(asynchat.fifo):
 def __init__(self, list=None): asynchat.fifo.__init__(self, list) self.have_deque = hasattr(self.list, 'appendleft')
 def push_front(self, object): if self.have_deque: self.list.appendleft(object) else: self.list.insert(0, object)
Abdullah Yoldas
On 3/16/06, SA Trygubenko [EMAIL PROTECTED] wrote:
Dear All,Python 2.4 (#1, Mar 22 2005, 21:42:42)[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type help, copyright, credits or license for more information. import Queue q=Queue.Queue() type(q.queue)type 'collections.deque
'q.queue used to be a list, and now it is something else?I was using bisect module to implement min priority queue, as describedin python library reference (see
http://www.python.org/doc/2.3.5/lib/bisect-example.html). I have foundout that in Python 2.4 q.queue does not support insert anymore, whichbreaks bisect. Please help!Thank you,Semen
--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Computing correlations with SciPy

2006-03-16 Thread tkpmep
I want to compute the correlation between two sequences X and Y, and
tried using SciPy to do so without success.l Here's what I have, how
can I correct it?

 X = [1, 2, 3, 4, 5]
 Y = [5, 4, 3, 2, 1]
 import scipy
 scipy.corrcoef(X,Y)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File C:\Python24\Lib\site-packages\numpy\lib\function_base.py, line
671, in corrcoef
d = diag(c)
  File C:\Python24\Lib\site-packages\numpy\lib\twodim_base.py, line
80, in diag
raise ValueError, Input must be 1- or 2-d.
ValueError: Input must be 1- or 2-d.
 

Thanks in advance

Thomas Philips

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


Re: Computing correlations with SciPy

2006-03-16 Thread Felipe Almeida Lessa
Em Qui, 2006-03-16 às 07:49 -0800, [EMAIL PROTECTED] escreveu:
 I want to compute the correlation between two sequences X and Y, and
 tried using SciPy to do so without success.l Here's what I have, how
 can I correct it?

$ python2.4
Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type help, copyright, credits or license for more information.
 x = [1,2,3,4,5]
 y = [5,4,3,2,1]
 import scipy
 scipy.corrcoef(x, y)
array([[ 1., -1.],
   [-1.,  1.]])
 # Looks fine for me...


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

Re: Python Documentation Standards

2006-03-16 Thread Duncan Booth
Steven Bethard wrote:

 Colin J. Williams wrote:
 Doc strings provide us with a great opportunity to illuminate our code.
 
 In the example below, __init__ refers us to the class's documentation,
 but the class doc doesn't help much.
 
 It doesn't?
 
  print list.__doc__
 list() - new list
 list(sequence) - new list initialized from sequence's items
 
 What is it you were hoping to see in constructor documentation?
 
 STeVe

How about this?:

   print list.__doc__
  list() - new list
  list(sequence) - new list initialized from sequence's items
  See http://docs.python.org/lib/built-in-funcs.html#l2h-44

although it would be better if the online docs had a more permanent looking 
anchor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't send large messages over SSL socket

2006-03-16 Thread [EMAIL PROTECTED]
Well the first thing to note is that the maximum record length in SSL
is exactly 16384.  SSL/TLS does not preserve message boundaries - it is
up to the application to determine if there are multiple messages in a
single record, or a single message spanning multiple records.  Sounds
like the particular wrapper function is not properly chunking the
message up into multiple records (or just does not support large
messages).

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


Re: Computing correlations with SciPy

2006-03-16 Thread John Hunter
 tkpmep == tkpmep  [EMAIL PROTECTED] writes:

tkpmep I want to compute the correlation between two sequences X
tkpmep and Y, and tried using SciPy to do so without success.l
tkpmep Here's what I have, how can I correct it?

 X = [1, 2, 3, 4, 5] Y = [5, 4, 3, 2, 1] import scipy
 scipy.corrcoef(X,Y)
tkpmep Traceback (most recent call last): File interactive
tkpmep input, line 1, in ?  File
tkpmep C:\Python24\Lib\site-packages\numpy\lib\function_base.py,
tkpmep line 671, in corrcoef d = diag(c) File
tkpmep C:\Python24\Lib\site-packages\numpy\lib\twodim_base.py,
tkpmep line 80, in diag raise ValueError, Input must be 1- or
tkpmep 2-d.  ValueError: Input must be 1- or 2-d.


Hmm, this may be a bug in scipy.  matplotlib also defines a corrcoef
function, which you may want to use until this problem gets sorted out

In [9]: matplotlib.mlab.corrcoef(X,Y)

In [10]: X = [1, 2, 3, 4, 5]

In [11]: Y = [5, 4, 3, 2, 1]

In [12]: matplotlib.mlab.corrcoef(X,Y)
Out[12]:
array([[ 1., -1.],
   [-1.,  1.]])


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


Re: python2.4.2 + win95, import socket dll error

2006-03-16 Thread John Pote
Dennis,
Thanks for the info. Found winsock2.0 on the MS knowledge base site. 
Downloaded, installed (with the y2k upgrade as recommended) and, amazingly, 
all is working. My simple socket server works no problem as does a test http 
client sending data to my web site. This latter program seems a little 
grainy on updating the wxPython GUI compared to my modern XP box and 
slightly older W2K laptop. But its working!

You might like to know:
I tried searching for winsock 2.2,
on MSK base no hits
on google search many hits but the ones I could make out all refered to 
winsock2.2.exe as a variant of the spybot worm.

Thanks for helping solve the problem,

All the best

John Pote


Dennis Lee Bieber [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On Thu, 16 Mar 2006 01:09:24 GMT, John Pote
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:

 Hi all,
 Can someone throw some light on this problem? (is trying to run Python 
 2.4.2
 on an old win95 box a reasonable thing to do?)

 Wasn't Winsock updated between W95 and W98?

 You may have the older winsock 1.1, and all the newer stuff is built
 against (and trying to load) winsock 2.2
 -- 
  == 
[EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG 
   [EMAIL PROTECTED] |   Bestiaria Support Staff   
  == 
Home Page: http://www.dm.net/~wulfraed/
 Overflow Page: http://wlfraed.home.netcom.com/ 


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


what's going on here?

2006-03-16 Thread John Salerno
This might be confusing to explain, because it's a question about an 
example in Beginning Python and I'll try to provide all the info I can.

First off, I'm reading a chapter on using the ReportLab modules to 
create a line graph from a set of data. The first implementation of the 
program uses a hard-coded list as the data source, the second 
implementation pulls the data from a URL. In either case, the data is of 
this format:

# year month predicted high low
200412  34.235.233.2
200501  31.534.528.5
(repeated many times)

In the first implementation, the data was a list of tuples, each tuple 
being one row of the data. So grabbing the data was done like this:

pred = [row[2]-40 for row in data]
high = [row[3]-40 for row in data]
etc...

We can safely ignore the '-40', that was just for positioning. So the 
variable for predicted would grab 34.2, 31.5, etc., high would get 35.2, 
etc. Easy enough.

Now, the second implementation does this:

for line in urlopen(URL).readlines():
if not line.isspace() and not line[0] in COMMENT_CHARS:
data.append(map(float, line.split()))

pred = [row[2] for row in data]
high = [row[3] for row in data]
etc.

(URL is the location of the data file online. The if statement just 
checks for blank lines and lines beginning with certain comment 
characters, so they can be ignored.)

So finally here's my question: If you are using data.append(), doesn't 
that just put all the numbers into one long list? How are the tuples 
still being created in this case so that the list comprehensions still 
work? It seems like there is no longer any 'row' to refer to in data.

The only thing I can think of is that each time through the for loop, a 
new item (tuple or list) is being created in the data list, so that each 
row of data really is being separated as its own element in the larger 
list, but that doesn't seem right.

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


Re: Tried Ruby (or, what Python *really* needs or perldoc!)

2006-03-16 Thread john_sips_tea

Jason Earl wrote:
 msoulier [EMAIL PROTECTED] writes:

  I have found the Python sidebar VERY helpful:
 
  Personally, I can't use local docs on my desktop as they may not be
  the same version of the docs for the Python distro running on the
  server that I'm deploying on. I usually go to python.org and use the
  wayback machine to look at the old docs for the release that I'm on.

 Why don't you instead install the info version of the Python
 documentation on your server.  Then you can do info Python2.3-lib
 and have at it.  If you are hacking in emacs then this is about as
 slick a documentation system as you could ask for, but even if you use
 some other editor info is a much better documentation tool than man.

You know, I'm pretty used to reading man pages. There's only a
few simple keystrokes I need to remember, and the only time I
ever touch info is when a very short man page tells me that the
real docs are in info and I need to look there. At that point, I have
to relearn how to use that info command. Info is complicated. It's
got some concept of nodes being hierarcical, but also they seem
to have some order to them (a la next and previous) as well. No
idea what the connection between those is. Also it's got cross-
references as well as menus -- dunno if they're different or not.
Bah. Why not just use html and browse it with lynx/links/links2/elinks?

I can't understand why we need two separate and distinct doc
formats: man and info. My take: write your docs in some markup
that can produce both man output and html. Done and done.
Seems like two good candidates for that are epytext and
reStructuredText (reST).

  But, if Python would match Perl for docs available on the
  command-line, then I'd have it all at my fingertips. I simply don't
  understand why this is not being done. When I'm coding in C, I use
  the manpages on the remote host so that I know the docs are correct
  for my target. Why can't I do that in Python? It's yet another thing
  that my Perl-using coworkers point out as a Python weakness.

 Python does match (and exceed) Perl for docs available on the command
 line.  Once you get used to using the excellent info-based Python
 documentation using man is downright primitive.

 Jason

I think that may be wishful thinking. When I use the pydoc command,
I mostly get *very* short API docs with *no* example code or tutorial
notes at all.

Contrast that with perldoc which is categorized and complete docs
for the entire language plus tutorials, faqs, ports info, ... I mean,
have a look over at http://perldoc.perl.org/perl.html -- everything
there is at your fingertips from the terminal! And it's written by
folks
like Larry, Dominus, Randal Schwartz, Tom Christiansen, et al. I've
never come across a FLOSS software project with docs as good as
Perl's.

Now, the one big thing we have going for us is that since Python
is a simpler language, so it needs few docs overall anyway. :)

---John
http://www.simisen.com/jmg/cpd/

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


Re: what's going on here?

2006-03-16 Thread Schüle Daniel
[...]

 So finally here's my question: If you are using data.append(), doesn't 
 that just put all the numbers into one long list? 

no, append appends
extend does what you think

How are the tuples
 still being created in this case so that the list comprehensions still 
 work? It seems like there is no longer any 'row' to refer to in data.

why not to fire interpreter to see what happens

  line1 = 1 2 3 4
  line2 = 5 6 7 8
  lst = []
  lst.append(map(float, line1.split()))
  lst
[[1.0, 2.0, 3.0, 4.0]]
  lst.append(map(float, line2.split()))
  lst
[[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0]]
 


hth, Daniel

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


Re: what's going on here?

2006-03-16 Thread Felipe Almeida Lessa
Em Qui, 2006-03-16 às 16:31 +, John Salerno escreveu:
 So finally here's my question: If you are using data.append(), doesn't 
 that just put all the numbers into one long list? How are the tuples 
 still being created in this case so that the list comprehensions still 
 work? It seems like there is no longer any 'row' to refer to in data.

Look the line data.append(map(float, line.split()))

In other words:

# Suppose line is 200412  34.235.233.2
# for our comments

# Creates a list, like [2004, 12, 34.2, 35.2, 33.2]
splitted = line.split() 

# Convert all numbers to floats
numbers = map(float, splitted)

# It could also be
# numbers = [float(x) for x in splitted]

# Append the list to the data
# ReportLab accept both lists and tuples, so it doesn't matter
data.append(numbers)


Hope this clarifies your mind,
Felipe.

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

Executing a DOS program from within Python

2006-03-16 Thread Randy Kreuziger
This is probably a  newbie question but I need a kick start to get going.

I need to run a DOS (sdetable) program from within a Python program.  I'll use 
command line switches so I will not need to interact with the program however 
it would be nice if I could capture its exit code.

Thanks


Randy Kreuziger
(360) 902-2495  Voice
(360) 902-2940 Fax
ArcSDE Administrator
Wash Dept of Fish and Wildlife


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


Re: what's going on here?

2006-03-16 Thread John Salerno
Felipe Almeida Lessa wrote:

 # Suppose line is 200412  34.235.233.2
 # for our comments
 
 # Creates a list, like [2004, 12, 34.2, 35.2, 33.2]
 splitted = line.split() 

Thanks guys! I think what I forgot was that split() returns a list, so 
that's when the 'rows' were being created.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread [EMAIL PROTECTED]
Thank you very much guys!
Just for clarification it wasn't homework, just extra credit  :)

I can't beleive I didn't realize that I didn't clear the GLOBAL
variable  :D

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


Re: email package 4.0a2

2006-03-16 Thread Konrad Hinsen
On Mar 5, 2006, at 22:10, Barry Warsaw wrote:

 I'm happy to announce the release of the email 4.0a2 standalone  
 package.
 This is the latest version of the email package and will be released
 with Python 2.5.  The major changes between this version and email 3.0
 (released with Python 2.4) is:
...

 Note that the old, email version 3 package names are still  
 supported for
 backward compatibility, so you won't have to change existing code.   
 New
 code should use the new names as the old names will go away in Python
 2.6.  Also note that email.mime.application is /not/ provided as
 email.MIMEApplication.

I am a bit worried by annoucements such as this one, so I would like  
to profit from this opportunity to plead for more stability in Python  
development, even though the concrete case (the email module) is not  
a problem for me.

My interpretation of the above paragraph is that it will be  
impossible to write Python code using the email module (and possibly  
other evolving modules) that works with both Python 2.4 and Python  
2.6. As an author of Python code, I therefore have to choose if I  
want to force my users to update their Python installation (knowing  
that this is impossible or at least a major effort for some of them)  
or if I want to prevent early adopters of new versions from using my  
code. I don't like either option.

 From exchanges with users of my code, I conclude that there are  
significant numbers of users of Python 2.2, 2.3, and 2.4 at the  
moment, plus a small number of users of 2.0 and 2.1. From a few cases  
of Python 2.2 users whose situations I know well, I understand that  
updating is not always an option. For example, there is someone whose  
10 PCs are still running SuSE Linux 8.1 (which includes Python 2.2).  
The PhD student who handles system administration (with minimal  
expertise) adopts the wise approach of never breaking a running  
system. In other words, those machines will remain at SuSE 8.1 and  
Python 2.2 until they will be replaced. This leaves users with the  
only option of installing a newer Python in their home directories -  
not exactly a straightforward task for someone who knows little about  
Python and nothing about system administration.

Given the current situation, I expect that when Python 2.6 is  
released, Python 2.4 will still be in common use.

Personally, I would prefer that all compatibility-breaking changes be  
postponed until Python 3K. I'd rather have worry about compatibility  
once than continously.

Konrad.
--
-
Konrad Hinsen
Laboratoire Léon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: [EMAIL PROTECTED]
-


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


Re: Executing a DOS program from within Python

2006-03-16 Thread Gary Herron
Randy Kreuziger wrote:

This is probably a  newbie question but I need a kick start to get going.

I need to run a DOS (sdetable) program from within a Python program.  I'll use 
command line switches so I will not need to interact with the program however 
it would be nice if I could capture its exit code.

Thanks


Randy Kreuziger
(360) 902-2495  Voice
(360) 902-2940 Fax
ArcSDE Administrator
Wash Dept of Fish and Wildlife


  

There has been numerous ways to do this in the past (os.system, 
os.spawn, os.exec, and various operations in popen2), with os.system 
being the easiest and perhaps sufficient for your need.

However, if you are running Python 2.4, the I'd suggest the subprocess 
module, and in particular its convenience function call.

Gary Herron

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


Re: Cheese Shop: some history for the new-comers

2006-03-16 Thread Harald Armin Massa
Tim,

 For most people 'developers' would mean people developing *with* python,
 not developing python.

one of the richest people on earth did define what developers are:

http://www.ntk.net/ballmer/mirrors.html

people developing with something. So, unless we get /F or BDFL to do an
even more astonishing dance proclaiming that people developing Python
are developers, not people developing WITH Python, I guess you are
quite right.

Harald

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread [EMAIL PROTECTED]
Flame war? Absolutely not. My reason is to learn. There are many sites
dedicated to reasonably objective comparisons between languages. Here
are two examples:

http://www.smallscript.org/Language%20Comparison%20Chart.asp
http://www.jvoegele.com/software/langcomp.html

The wildcard exclusion problem is interesting enough to have many
distinct, elegant solutions in as many languages. It would be
interesting to see if they converge to roughly the same solution or if
there are essential differences. And your code is a crash course in
Haskell! Tossing aside the 'flame war' inquiry your code response is my
only goal. I hope many others find the problem and responses as
fascinating as I do.

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


Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Felipe Almeida Lessa
Em Qui, 2006-03-16 às 09:20 +0100, Fredrik Lundh escreveu:
 when you're done with your homework (?), you can compare it with
 Guido's solution:
 
 http://svn.python.org/view/python/trunk/Demo/scripts/queens.py

Just a curiosity. Running the script as the site lists on my computer:

$ time python2.4 /tmp/queens.py -n 12
Found 14200 solutions.

real0m14.177s
user0m13.700s
sys 0m0.042s

Adding a import psyco; psyco.full() clause to the beginning of the
file:

$ time python2.4 /tmp/queens.py -n 12
Found 14200 solutions.

real0m3.250s
user0m3.003s
sys 0m0.012s

At least interesting...

Felipe.

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

Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread [EMAIL PROTECTED]
The point is to submit elegant code that showcases the features of each
language. And the problem is, just to clarify, given a set WC of
wildcards in any logical combination, and if WC(S^n) is the set all s
in S^n that matches the wildcards, then efficiently generate the
complement S^n\WC(S^n). You are free to restate the problem in any
equivalent way.

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Dr.Ruud
[EMAIL PROTECTED] schreef:

 There are many sites
 dedicated to reasonably objective comparisons between languages. Here
 are two examples:
 
 http://www.smallscript.org/Language%20Comparison%20Chart.asp
 http://www.jvoegele.com/software/langcomp.html

  http://shootout.alioth.debian.org/ 

-- 
Affijn, Ruud

Gewoon is een tijger.
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pow (power) function

2006-03-16 Thread Mike Ressler
On Wed, 2006-03-15 at 18:46 -0800, Ben Cartwright wrote:

 Anyway, if you want to see the int vs. float issue in action, try this:
 
from timeit import Timer
Timer('2**2').timeit()
   0.12681011582321844
Timer('2.0**2.0').timeit()
   0.6011743438121
Timer('2.0**2').timeit()
   0.36681835556112219
Timer('2**2.0').timeit()
   0.37949818370600497
 
 As you can see, the int version is much faster than the float version.

I have a counterexample. In the original timeit example, 111**111 was
used. When I run that 

 timeit.Timer(pow(111,111)).timeit()
10.968398094177246
 timeit.Timer(111**111).timeit()
10.04007887840271
 timeit.Timer(111.**111.).timeit()
0.36576294898986816

The pow and ** on integers take 10 seconds, but the float ** takes only
0.36 seconds. (The pow with floats takes ~ 0.7 seconds). Clearly
typecasting to floats is coming in here somewhere. (Python 2.4.1 on
Linux FC4.)

Mike


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


Re: Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations

2006-03-16 Thread Roedy Green
On 15 Mar 2006 22:20:52 -0800, Xah Lee [EMAIL PROTECTED] wrote,
quoted or indirectly quoted someone who said :

e. For example, the in-fix
notation =E2=80=9C(3+(2*5))7=E2=80=9D is written as =E2=80=9C3 2 5 * + 7 =
=E2=80=9D, where the

Not that Mr. Lee has ever shown much interest in feedback, but you
pretty well have stick to vanilla ASCII to get your notation through
unmangled on newsgroups.
-- 
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Queue limitations?

2006-03-16 Thread mateom
I am creating the images by reading from texture memory using
glGetTexImage(). As an experiment, I tried calling glGetTexImage() only
once and letting imagQueue use that same reference over and over, but
the images were all the same.

So, this leads me to believe that the references returned by
glGetTexImage() are to unique buffers, right? ( documentation for
glGetTexImage() doesn't seem to disagree )

Perhaps, as an OpenGL program, something strange is happening with the
references when my producer method goes out of scope. I guess for now I
can be content to just pass immutable types across the thread boundary.

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


Re: Cheese Shop: some history for the new-comers

2006-03-16 Thread Paul Boddie
Harald Armin  Massa wrote:

 one of the richest people on earth did define what developers are:

 http://www.ntk.net/ballmer/mirrors.html

I was wondering when someone would mention the developers, developers,
developers Ballmer song-and-dance incident: clearly, he isn't chanting
about internal Microsoft project teams.

Paul

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


Re: Is Forth for real?

2006-03-16 Thread astrobe

[EMAIL PROTECTED] a écrit :

 rickman wrote:
  The original post seems to be missing, but my answer to the title
  question is, No, Forth is not real.

 Not for real, for Integer.

No, it's for me and you (well, perhaps more for you than for me).
But 4IM is forever mine :)

 Amicalement,
  Astrobe

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Wade Humeniuk
Without much testing.  Common Lisp

Pattern exclusions are made lispy.


(defun all-lists (list length)
   (unless (zerop length)
 (if (= length 1) (mapcar #'list list)
   (loop for elt in list
 nconc
 (mapcar (lambda (rest)
   (cons elt rest))
 (loop for rest on list
   nconc (all-lists rest (1- length

(defun cp-without-wc (source-list rest patterns)
   (let* ((length (length (first patterns)))
  (all-lists (all-lists source-list length)))
 (dolist (pattern patterns)
   (setf all-lists
 (set-difference all-lists
 (mapcar (lambda (insertion)
   (let ((cp (copy-list pattern)))
 (loop for place on cp
   when (eql :any (car place)) do
   (setf (car place) (pop 
insertion)))
 cp))
 (all-lists source-list (count :any 
pattern)))
 :test #'equal)))
 (remove-duplicates all-lists :test #'equal)))

CL-USER 22  (cp-without-wc '(a b) '(a :any b) '(b :any a))
((A A A) (A B A) (B A B) (B B B))

CL-USER 23  (cp-without-wc '(abc xyz) '(abc :any xyz))
((XYZ XYZ XYZ) (XYZ XYZ ABC) (XYZ ABC XYZ) (XYZ ABC ABC) (ABC XYZ ABC) (ABC ABC 
ABC))

CL-USER 24  (cp-without-wc '(a b) '(a :any :any))
((B B B) (B B A) (B A B) (B A A))

CL-USER 25  (cp-without-wc '(a b) '(a :any :any) '(b :any :any))
NIL

CL-USER 26  (cp-without-wc '(a b) '(:any :any b))
((B B A) (B A A) (A B A) (A A A))

CL-USER 27 

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


Re: email package 4.0a2

2006-03-16 Thread Tony Meyer
[Barry Warsaw]
 I'm happy to announce the release of the email 4.0a2 standalone
 package.

[Konrad Hinsen]
 My interpretation of the above paragraph is that it will be
 impossible to write Python code using the email module (and possibly
 other evolving modules) that works with both Python 2.4 and Python
 2.6.

No, that's not correct.

try:
 from email import message
except ImportError:
 # Compat with 2.4 and earlier
 from email import Message as message

(etc)

Note also that 2.5 won't be out until late this year; 2.6 will  
probably be something like mid 2008.  That's a long time after 2.4  
(or 2.3, or 2.2).  If you want to support something like 10 years of  
versions, there will be difficulties doing that.  You can always  
bundle up the email package separately (this is extremely easy),  
however, so that users have email 4.0 and Python 2.2.

=Tony.Meyer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cheese Shop: some history for the new-comers

2006-03-16 Thread Fredrik Lundh
Paul Boddie wrote:

  one of the richest people on earth did define what developers are:
 
  http://www.ntk.net/ballmer/mirrors.html

 I was wondering when someone would mention the developers, developers,
 developers Ballmer song-and-dance incident: clearly, he isn't chanting
 about internal Microsoft project teams.

since when is Microsoft a programming language ?

/F



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


Re: Executing a DOS program from within Python

2006-03-16 Thread iapain
Use os.system and if you wanna get rid of console window use subprocess
as gary said, you could have better options like killing proc if it
hang/stuck using win32api (if you are using windows) else process
timeout.

ret = os.system('sample.exe') # ret will have return code and os.system
execute sample.exe

#using subprocess

import subprocess
process = subprocess.Popen('sample.exe', stdout=subprocess.PIPE)
#you can print error/output using stderr/stdout pipe

Both are easy to implement!
Thanks!!

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread [EMAIL PROTECTED]
What I have in mind is the efficient, enumerated generation of the
complement S^n/WC(S^n). A good program should initialize, generate, and
terminate.

T=cartprodex(S,n,WC); //initialize
for all i in T do
  what you want with i
  test to see if any more
  terminate if not

and it should do this without explicitly generating WC and then
complementing. For example, if the cardinality of S is m, and the WC is
just '*a*b*', with a != b, then EX(S^n):=S^n\WC(S^n) has cardinality
(m-1)^(n-1)*(m+n-1). Specifically, if m=5 and n=10, then |EX|=3670016
while |S^10|=9765625, so that |EX|/|S^10| is about 0.3758. In general
the program should directly generate EX from arbitrary WC. Of course,
in practice the WC should themselves occur in a logically consistent
manner, but let's just assume they're a given.

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


Re: Cheese Shop - BSOL?

2006-03-16 Thread Christos Georgiou
On 11 Mar 2006 03:22:42 -0800, rumours say that Paul Boddie
[EMAIL PROTECTED] might have written:

Tim Churches wrote:

 Would it be possible to rename Cheese Shop as Bright Side of Life?

[Paul]
snip

So should a service for finding Python packages have a distinct
identity? It is possible that a package index could be someone's
principal view of the Python world (I go to Camelot to get... what is
it I get there?), but the things that emerge from such a service
aren't just downloads that have little in common with each other.
Consequently, I don't think a descriptive name, derived from the name
of the technology, is sensibly avoided in this case.

I like the BSOL idea, but in that case what will the package extension be
instead of .egg?  camelot.python.org has the advantage of suggesting an
obvious extension: .graal

So you go to the Camelot to get the graal (or one of them :).  In case this
catches on, I'd like to upload ASAP one of my packages [1] called wholy.

PS Grail was a web browser written in Python (or an attempt at one).


[1] It's mostly useless but I trust wholy.graal will be downloaded by
millions.
-- 
TZOTZIOY, I speak England very best.
Dear Paul,
please stop spamming us.
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Counting nested loop iterations

2006-03-16 Thread Derek Basch
What is the best way to count nested loop iterations? I can only figure
to use an index but that seems kludgy.

index = 0
for animal in zoo:
for color in animal:
index += 1

Thanks,
Derek Basch

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


Python / glade fundamentals

2006-03-16 Thread Doug
Hi all,
Can someone tell me why I do not get a connection between the events and
the functions in the sample below.  GUI window appears OK, just no
connections seem to be made.
I am new to this so may be missing something fundamental. 
Thanks, 
Doug



file pgtest.glade
=

?xml version=1.0 standalone=no? !--*- mode: xml -*--
!DOCTYPE glade-interface SYSTEM http://glade.gnome.org/glade-2.0.dtd;

glade-interface

widget class=GtkWindow id=page
  property name=visibleTrue/property
  property name=eventsGDK_KEY_PRESS_MASK/property
  property name=title translatable=yesPGtestWindow/property
  property name=typeGTK_WINDOW_TOPLEVEL/property
  property name=window_positionGTK_WIN_POS_NONE/property
  property name=modalFalse/property
  property name=default_width640/property
  property name=default_height480/property
  property name=resizableTrue/property
  property name=destroy_with_parentTrue/property
  property name=decoratedTrue/property
  property name=skip_taskbar_hintFalse/property
  property name=skip_pager_hintFalse/property
  property name=type_hintGDK_WINDOW_TYPE_HINT_NORMAL/property
  property name=gravityGDK_GRAVITY_NORTH_WEST/property
  signal name=destroy_event handler=on_page_destroy_event 
last_modification_time=Thu, 16 Mar 2006 12:57:33 GMT/

  child
widget class=GtkDrawingArea id=drawingarea1
  property name=visibleTrue/property
  property name=eventsGDK_KEY_PRESS_MASK/property
  property name=extension_eventsGDK_EXTENSION_EVENTS_ALL/property
  signal name=key_press_event handler=on_drawingarea1_key_press_event 
last_modification_time=Thu, 16 Mar 2006 10:09:36 GMT/
  signal name=destroy_event handler=on_drawingarea1_destroy_event 
last_modification_time=Thu, 16 Mar 2006 13:01:31 GMT/
/widget
  /child
/widget

/glade-interface

file pgtest.py
==
import gtk
import gtk.glade

def on_drawingarea1_key_press(widget):
   print keypress   

xml = gtk.glade.XML('pgtest.glade')
widget = xml.get_widget('drawingarea1')
#print type(xml)

xml.signal_autoconnect({
  on_drawingarea1_key_press_event: on_drawingarea1_key_press,
  on_page_destroy_event:gtk.mainquit
})

gtk.main()


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


Re: OCR question

2006-03-16 Thread Duncan Watson [EMAIL PROTECTED]
Excellent suggestion.  I found it.  I will see what I can do about some
edge detection to crop the images so that gocr has an easier time of
it.

Thanks
-Duncan

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


Re: Counting nested loop iterations

2006-03-16 Thread Fredrik Lundh
Derek Basch wrote:

 What is the best way to count nested loop iterations? I can only figure
 to use an index but that seems kludgy.

 index = 0
 for animal in zoo:
 for color in animal:
 index += 1

what's kludgy with using a counter to count things ?

(the real question here is of course why you need the counter.  what's
the loop doing?  if the code you posted is all you have, you can replace
it with index = sum(len(animal) for animal in zoo), but I assume you want
to do more stuff in there...)

/F



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


accessing attributes when inheriting?

2006-03-16 Thread Peter Bismuti
How do you access attributes of a class when inheriting from it? Can't you 
just say:

self.attribute? 

Help?!
...
#!/usr/bin/python

from Dialog import Dialog
import enscmd

class RatDialog(Dialog):
 def __init__(self,parent = Dialog,name = RatDialog,modal = 0,fl = 0):
 Dialog.__init__(self)
 self.ClipListView.header().setLabel(0,self.__tr(Clips)) ERROR
 self.ClipListView.clear()
 def CloseButton_clicked(self):
 self.close()



from qt import *


class Dialog(QDialog):
 def __init__(self,parent = None,name = None,modal = 0,fl = 0):
 QDialog.__init__(self,parent,name,modal,fl)

 if not name:
 self.setName(Dialog)


 DialogLayout = QGridLayout(self,1,1,11,6,DialogLayout)

 layout14 = QVBoxLayout(None,0,6,layout14)

 layout13 = QHBoxLayout(None,0,6,layout13)

 self.ClipListView = QListView(self,ClipListView)
 self.ClipListView.addColumn(self.__tr(Column 1))
 layout13.addWidget(self.ClipListView)

 self.ClipTextEdit = QTextEdit(self,ClipTextEdit)
 layout13.addWidget(self.ClipTextEdit)
 layout14.addLayout(layout13)

 layout10 = QHBoxLayout(None,0,6,layout10)

 layout9 = QVBoxLayout(None,0,6,layout9)

 layoutWidth = QHBoxLayout(None,0,6,layoutWidth)

 self.WidthLabel = QLabel(self,WidthLabel)
 layoutWidth.addWidget(self.WidthLabel)

 self.WidthLineEdit = QLineEdit(self,WidthLineEdit)
 layoutWidth.addWidget(self.WidthLineEdit)
 layout9.addLayout(layoutWidth)

 layout5 = QVBoxLayout(None,0,6,layout5)

 self.OriginLabel = QLabel(self,OriginLabel)
 self.OriginLabel.setAlignment(QLabel.WordBreak | QLabel.AlignCenter)
 layout5.addWidget(self.OriginLabel)

 layoutX = QHBoxLayout(None,0,6,layoutX)

 self.XLabel = QLabel(self,XLabel)
 layoutX.addWidget(self.XLabel)

 self.XLineEdit = QLineEdit(self,XLineEdit)
 layoutX.addWidget(self.XLineEdit)
 layout5.addLayout(layoutX)

 layoutY = QHBoxLayout(None,0,6,layoutY)

 self.YLabel = QLabel(self,YLabel)
 layoutY.addWidget(self.YLabel)

 self.YLineEdit = QLineEdit(self,YLineEdit)
 layoutY.addWidget(self.YLineEdit)
 layout5.addLayout(layoutY)

 layoutZ = QHBoxLayout(None,0,6,layoutZ)

 self.ZLabel = QLabel(self,ZLabel)
 layoutZ.addWidget(self.ZLabel)

 self.ZLineEdit = QLineEdit(self,ZLineEdit)
 layoutZ.addWidget(self.ZLineEdit)
 layout5.addLayout(layoutZ)
 layout9.addLayout(layout5)
 layout10.addLayout(layout9)

 self.ButtonGroup = QButtonGroup(self,ButtonGroup)

 self.CircleRadioButton = 
QRadioButton(self.ButtonGroup,CircleRadioButton)
 self.CircleRadioButton.setGeometry(QRect(20,50,56,21))

 self.SquareRadioButton = 
QRadioButton(self.ButtonGroup,SquareRadioButton)
 self.SquareRadioButton.setGeometry(QRect(20,20,64,21))
 self.SquareRadioButton.setChecked(1)
 layout10.addWidget(self.ButtonGroup)
 layout14.addLayout(layout10)

 layout11 = QHBoxLayout(None,0,6,layout11)

 self.NewClipButton = QPushButton(self,NewClipButton)
 layout11.addWidget(self.NewClipButton)

 self.DeleteClipButton = QPushButton(self,DeleteClipButton)
 layout11.addWidget(self.DeleteClipButton)

 self.CloseButton = QPushButton(self,CloseButton)
 layout11.addWidget(self.CloseButton)
 layout14.addLayout(layout11)

 DialogLayout.addLayout(layout14,0,0)

 self.languageChange()

 self.resize(QSize(340,427).expandedTo(self.minimumSizeHint()))
 self.clearWState(Qt.WState_Polished)

 
self.connect(self.NewClipButton,SIGNAL(clicked()),self.NewClipButton_clicked)
 
self.connect(self.DeleteClipButton,SIGNAL(clicked()),self.DeleteClipButton_clicked)
 
self.connect(self.CloseButton,SIGNAL(clicked()),self.CloseButton_clicked)


 def languageChange(self):
 self.setCaption(self.__tr(RAT))
 self.ClipListView.header().setLabel(0,self.__tr(Column 1))
 self.ClipListView.clear()
 item = QListViewItem(self.ClipListView,None)
 item.setText(0,self.__tr(New Item))

 self.WidthLabel.setText(self.__tr(bWidth/Radius/b))
 self.OriginLabel.setText(self.__tr(bOrigin/b))
 self.XLabel.setText(self.__tr(bX/b))
 self.YLabel.setText(self.__tr(bY/b))
 self.ZLabel.setText(self.__tr(bZ/b))
 self.ButtonGroup.setTitle(self.__tr(Clip Type))
 self.CircleRadioButton.setText(self.__tr(Circle))
 self.SquareRadioButton.setText(self.__tr(Square))
 self.NewClipButton.setText(self.__tr(New))
 self.DeleteClipButton.setText(self.__tr(Delete))
 self.CloseButton.setText(self.__tr(Close))


 def NewClipButton_clicked(self):
 print Dialog.NewClipButton_clicked(): Not implemented yet

 def DeleteClipButton_clicked(self):
 print Dialog.DeleteClipButton_clicked(): Not implemented yet

 def CloseButton_clicked(self):
 print Dialog.CloseButton_clicked(): Not implemented yet

 def __tr(self,s,c = None):
 return qApp-- Bismuti
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Dialog.ui'
#
# Created: Thu Mar 16 09:42:22 2006
#  by: The PyQt User Interface Compiler (pyuic) 3.13
#
# WARNING! All changes made in this file will be lost!


from qt import 

accessing attributes when inheriting?

2006-03-16 Thread Peter J. Bismuti


How do you access attributes of a class when inheriting from it? Can't you 
just say:

self.attribute?  

Help?!
...
#!/usr/bin/python

from Dialog import Dialog
import enscmd

class RatDialog(Dialog):
def __init__(self,parent = Dialog,name = RatDialog,modal = 0,fl = 0):
Dialog.__init__(self)
self.ClipListView.header().setLabel(0,self.__tr(Clips))   ERROR
self.ClipListView.clear()
def CloseButton_clicked(self):
self.close()



from qt import *


class Dialog(QDialog):
def __init__(self,parent = None,name = None,modal = 0,fl = 0):
QDialog.__init__(self,parent,name,modal,fl)

if not name:
self.setName(Dialog)


DialogLayout = QGridLayout(self,1,1,11,6,DialogLayout)

layout14 = QVBoxLayout(None,0,6,layout14)

layout13 = QHBoxLayout(None,0,6,layout13)

self.ClipListView = QListView(self,ClipListView)
self.ClipListView.addColumn(self.__tr(Column 1))
layout13.addWidget(self.ClipListView)

self.ClipTextEdit = QTextEdit(self,ClipTextEdit)
layout13.addWidget(self.ClipTextEdit)
layout14.addLayout(layout13)

layout10 = QHBoxLayout(None,0,6,layout10)

layout9 = QVBoxLayout(None,0,6,layout9)

layoutWidth = QHBoxLayout(None,0,6,layoutWidth)

self.WidthLabel = QLabel(self,WidthLabel)
layoutWidth.addWidget(self.WidthLabel)

self.WidthLineEdit = QLineEdit(self,WidthLineEdit)
layoutWidth.addWidget(self.WidthLineEdit)
layout9.addLayout(layoutWidth)

layout5 = QVBoxLayout(None,0,6,layout5)

self.OriginLabel = QLabel(self,OriginLabel)
self.OriginLabel.setAlignment(QLabel.WordBreak | QLabel.AlignCenter)
layout5.addWidget(self.OriginLabel)

layoutX = QHBoxLayout(None,0,6,layoutX)

self.XLabel = QLabel(self,XLabel)
layoutX.addWidget(self.XLabel)

self.XLineEdit = QLineEdit(self,XLineEdit)
layoutX.addWidget(self.XLineEdit)
layout5.addLayout(layoutX)

layoutY = QHBoxLayout(None,0,6,layoutY)

self.YLabel = QLabel(self,YLabel)
layoutY.addWidget(self.YLabel)

self.YLineEdit = QLineEdit(self,YLineEdit)
layoutY.addWidget(self.YLineEdit)
layout5.addLayout(layoutY)

layoutZ = QHBoxLayout(None,0,6,layoutZ)

self.ZLabel = QLabel(self,ZLabel)
layoutZ.addWidget(self.ZLabel)

self.ZLineEdit = QLineEdit(self,ZLineEdit)
layoutZ.addWidget(self.ZLineEdit)
layout5.addLayout(layoutZ)
layout9.addLayout(layout5)
layout10.addLayout(layout9)

self.ButtonGroup = QButtonGroup(self,ButtonGroup)

self.CircleRadioButton = 
QRadioButton(self.ButtonGroup,CircleRadioButton)
self.CircleRadioButton.setGeometry(QRect(20,50,56,21))

self.SquareRadioButton = 
QRadioButton(self.ButtonGroup,SquareRadioButton)
self.SquareRadioButton.setGeometry(QRect(20,20,64,21))
self.SquareRadioButton.setChecked(1)
layout10.addWidget(self.ButtonGroup)
layout14.addLayout(layout10)

layout11 = QHBoxLayout(None,0,6,layout11)

self.NewClipButton = QPushButton(self,NewClipButton)
layout11.addWidget(self.NewClipButton)

self.DeleteClipButton = QPushButton(self,DeleteClipButton)
layout11.addWidget(self.DeleteClipButton)

self.CloseButton = QPushButton(self,CloseButton)
layout11.addWidget(self.CloseButton)
layout14.addLayout(layout11)

DialogLayout.addLayout(layout14,0,0)

self.languageChange()

self.resize(QSize(340,427).expandedTo(self.minimumSizeHint()))
self.clearWState(Qt.WState_Polished)


self.connect(self.NewClipButton,SIGNAL(clicked()),self.NewClipButton_clicked)

self.connect(self.DeleteClipButton,SIGNAL(clicked()),self.DeleteClipButton_clicked)

self.connect(self.CloseButton,SIGNAL(clicked()),self.CloseButton_clicked)


def languageChange(self):
self.setCaption(self.__tr(RAT))
self.ClipListView.header().setLabel(0,self.__tr(Column 1))
self.ClipListView.clear()
item = QListViewItem(self.ClipListView,None)
item.setText(0,self.__tr(New Item))

self.WidthLabel.setText(self.__tr(bWidth/Radius/b))
self.OriginLabel.setText(self.__tr(bOrigin/b))
self.XLabel.setText(self.__tr(bX/b))
self.YLabel.setText(self.__tr(bY/b))
self.ZLabel.setText(self.__tr(bZ/b))
self.ButtonGroup.setTitle(self.__tr(Clip Type))
self.CircleRadioButton.setText(self.__tr(Circle))
self.SquareRadioButton.setText(self.__tr(Square))
self.NewClipButton.setText(self.__tr(New))
self.DeleteClipButton.setText(self.__tr(Delete))

Re: Counting nested loop iterations

2006-03-16 Thread Jeffrey Schwab
Derek Basch wrote:
 What is the best way to count nested loop iterations? I can only figure
 to use an index but that seems kludgy.
 
 index = 0
 for animal in zoo:
 for color in animal:
 index += 1

Depending on the types of the containers in question, you could use:

len(zoo) * len(animal)



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


Re: Counting nested loop iterations

2006-03-16 Thread Derek Basch

Fredrik Lundh wrote:

 what's kludgy with using a counter to count things ?

Ohhh, nothing in particular. Just seeing if there is a better way to do
it.

 (the real question here is of course why you need the counter.  what's
 the loop doing?  if the code you posted is all you have, you can replace
 it with index = sum(len(animal) for animal in zoo), but I assume you want
 to do more stuff in there...)

 /F

Yes, I am doing more. Your example assumes that all that animals have
the same amount of colors. Not a bad assumption considering I didn't
say anything about that. Looks like good old counters are they way to
go then.

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


Re: accessing attributes when inheriting?

2006-03-16 Thread James Stroud
Peter J. Bismuti wrote:
 
 How do you access attributes of a class when inheriting from it? Can't you 
 just say:
 
 self.attribute?  
 
 Help?!
 ...
 #!/usr/bin/python
 
 from Dialog import Dialog
 import enscmd
 
 class RatDialog(Dialog):
 def __init__(self,parent = Dialog,name = RatDialog,modal = 0,fl = 0):
 Dialog.__init__(self)
 self.ClipListView.header().setLabel(0,self.__tr(Clips))   ERROR
 self.ClipListView.clear()
 def CloseButton_clicked(self):
 self.close()
 
 
 
 from qt import *
 
 
 class Dialog(QDialog):
 def __init__(self,parent = None,name = None,modal = 0,fl = 0):
 QDialog.__init__(self,parent,name,modal,fl)
 
 if not name:
 self.setName(Dialog)
 
 
 DialogLayout = QGridLayout(self,1,1,11,6,DialogLayout)
 
 layout14 = QVBoxLayout(None,0,6,layout14)
 
 layout13 = QHBoxLayout(None,0,6,layout13)
 
 self.ClipListView = QListView(self,ClipListView)
 self.ClipListView.addColumn(self.__tr(Column 1))
 layout13.addWidget(self.ClipListView)
 
 self.ClipTextEdit = QTextEdit(self,ClipTextEdit)
 layout13.addWidget(self.ClipTextEdit)
 layout14.addLayout(layout13)
 
 layout10 = QHBoxLayout(None,0,6,layout10)
 
 layout9 = QVBoxLayout(None,0,6,layout9)
 
 layoutWidth = QHBoxLayout(None,0,6,layoutWidth)
 
 self.WidthLabel = QLabel(self,WidthLabel)
 layoutWidth.addWidget(self.WidthLabel)
 
 self.WidthLineEdit = QLineEdit(self,WidthLineEdit)
 layoutWidth.addWidget(self.WidthLineEdit)
 layout9.addLayout(layoutWidth)
 
 layout5 = QVBoxLayout(None,0,6,layout5)
 
 self.OriginLabel = QLabel(self,OriginLabel)
 self.OriginLabel.setAlignment(QLabel.WordBreak | QLabel.AlignCenter)
 layout5.addWidget(self.OriginLabel)
 
 layoutX = QHBoxLayout(None,0,6,layoutX)
 
 self.XLabel = QLabel(self,XLabel)
 layoutX.addWidget(self.XLabel)
 
 self.XLineEdit = QLineEdit(self,XLineEdit)
 layoutX.addWidget(self.XLineEdit)
 layout5.addLayout(layoutX)
 
 layoutY = QHBoxLayout(None,0,6,layoutY)
 
 self.YLabel = QLabel(self,YLabel)
 layoutY.addWidget(self.YLabel)
 
 self.YLineEdit = QLineEdit(self,YLineEdit)
 layoutY.addWidget(self.YLineEdit)
 layout5.addLayout(layoutY)
 
 layoutZ = QHBoxLayout(None,0,6,layoutZ)
 
 self.ZLabel = QLabel(self,ZLabel)
 layoutZ.addWidget(self.ZLabel)
 
 self.ZLineEdit = QLineEdit(self,ZLineEdit)
 layoutZ.addWidget(self.ZLineEdit)
 layout5.addLayout(layoutZ)
 layout9.addLayout(layout5)
 layout10.addLayout(layout9)
 
 self.ButtonGroup = QButtonGroup(self,ButtonGroup)
 
 self.CircleRadioButton = 
 QRadioButton(self.ButtonGroup,CircleRadioButton)
 self.CircleRadioButton.setGeometry(QRect(20,50,56,21))
 
 self.SquareRadioButton = 
 QRadioButton(self.ButtonGroup,SquareRadioButton)
 self.SquareRadioButton.setGeometry(QRect(20,20,64,21))
 self.SquareRadioButton.setChecked(1)
 layout10.addWidget(self.ButtonGroup)
 layout14.addLayout(layout10)
 
 layout11 = QHBoxLayout(None,0,6,layout11)
 
 self.NewClipButton = QPushButton(self,NewClipButton)
 layout11.addWidget(self.NewClipButton)
 
 self.DeleteClipButton = QPushButton(self,DeleteClipButton)
 layout11.addWidget(self.DeleteClipButton)
 
 self.CloseButton = QPushButton(self,CloseButton)
 layout11.addWidget(self.CloseButton)
 layout14.addLayout(layout11)
 
 DialogLayout.addLayout(layout14,0,0)
 
 self.languageChange()
 
 self.resize(QSize(340,427).expandedTo(self.minimumSizeHint()))
 self.clearWState(Qt.WState_Polished)
 
 
 self.connect(self.NewClipButton,SIGNAL(clicked()),self.NewClipButton_clicked)
 
 self.connect(self.DeleteClipButton,SIGNAL(clicked()),self.DeleteClipButton_clicked)
 
 self.connect(self.CloseButton,SIGNAL(clicked()),self.CloseButton_clicked)
 
 
 def languageChange(self):
 self.setCaption(self.__tr(RAT))
 self.ClipListView.header().setLabel(0,self.__tr(Column 1))
 self.ClipListView.clear()
 item = QListViewItem(self.ClipListView,None)
 item.setText(0,self.__tr(New Item))
 
 self.WidthLabel.setText(self.__tr(bWidth/Radius/b))
 self.OriginLabel.setText(self.__tr(bOrigin/b))
 self.XLabel.setText(self.__tr(bX/b))
 self.YLabel.setText(self.__tr(bY/b))
 self.ZLabel.setText(self.__tr(bZ/b))
 self.ButtonGroup.setTitle(self.__tr(Clip Type))
 self.CircleRadioButton.setText(self.__tr(Circle))
 

Re: Counting nested loop iterations

2006-03-16 Thread Derek Basch
 Depending on the types of the containers in question, you could use:

   len(zoo) * len(animal)

I think this would give me the total iterations but I wouldn't be able
to get a running count. Correct?

Thanks for the reply,
Derek Basch

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


Binary python extensions with Free Pascal Compiler

2006-03-16 Thread Caleb Hattingh
Hi all

I want to write python extensions with FPC (Free Pascal Compiler,
http://www.freepascal.org).   In Delphi, this is trivially easy due to
the great work of the P4D (Python-for-Delphi, http://mmm-experts.com/)
guys;  however, when aiming for cross-platform binary extensions, that
strategy naturally doesn't work.

FPC has great cross-platform support, and to date I have written
library units that compile to .dlls (on win32) and .so's (on posix),
and then used these via ctypes.  This has worked very well, but for
certain applications I would prefer to create a new python type via
binary extension, rather than a python class with method wrappers
around library calls.  I could just use C, I guess, but I have a large
amount of pascal code that I would like to use, and I would prefer not
to fiddle with a C-binary extension intermediate.

I have explored the python.h header, and as expected, there appears to
be much use of the C standard library.   Using a tool that converts a C
header into an object pascal unit (intended to be the interface to
python.dll) gets me some of the way, but of course, calls to the C
stdlib don't get automatically translated into equivalent pascal-coded
functionality.  I'm afraid I am answering my own question here: is the
only way of getting this working to change all the stdlib calls in my
newly created pascal unit (created from python.h) to matching
functionality in pascal?

If there is another, simpler way I'm just not seeing, I would be glad
to hear it.

Regards
Caleb

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


Re: Counting nested loop iterations

2006-03-16 Thread Caleb Hattingh
Hi Derek

I went for an embarrassingly long time without knowing about
enumerate().  It doesn't directly answer your question about counting
*within* nests, but I am going to tell you this on the off chance you
don't know yet (and apologies if you do):

This:

count = 0
for animal in zoo:
a = animal
anum = count
count = count + 1

IS a kludge, when you have this available to you:

for count, animal in enumerate(zoo):
a = animal
anum = count

I won't say how long it took me to start using list comprehensions :)

regards
Caleb

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


Re: Binary python extensions with Free Pascal Compiler

2006-03-16 Thread Ravi Teja
I posted this a few days ago. According to the website
(http://mmm-experts.com/VersionHistory.aspx?ProductId=3), FPC support
has been added since version 3.29.

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


Re: Counting nested loop iterations

2006-03-16 Thread Kent Johnson
Derek Basch wrote:
 Fredrik Lundh wrote:
(the real question here is of course why you need the counter.  what's
the loop doing?  if the code you posted is all you have, you can replace
it with index = sum(len(animal) for animal in zoo), but I assume you want
to do more stuff in there...)

/F
 
 
 Yes, I am doing more. Your example assumes that all that animals have
 the same amount of colors.

No, it doesn't. Fredrik wrote
index = sum(len(animal) for animal in zoo)

The expression (len(animal) for animal in zoo) yields a sequence of the 
lengths of the individual animals; passing this to sum() gives the total 
count.

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


Re: Binary python extensions with Free Pascal Compiler

2006-03-16 Thread Caleb Hattingh
Well, there it is:

* Added support for Free Pascal Compiler (http://www.freepascal.org/)
and Lazarus Project (http://www.lazarus.freepascal.org/)
Thanks to Michiel du Toit ([EMAIL PROTECTED])

That was easy.   I just saw the new support for D2k6 recently.

thx Ravi
Caleb

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


Re: Other languages for PVM

2006-03-16 Thread Ravi Teja
I did not mean the lack of interest on part of the developer. That was
explained here.
http://www.livelogix.net/logix/future-work.html
His complaints were Efficiency and Security.

I was wondering why the Python community did not show interest in this.
There is tremendous potential in this product. For example, web
frameworks and ORMs are well understood now and people constantly push
for more and more parsimonious representations. Logix makes writing
DSLs trivial with Lisp like ease without all the parentheses. What I am
surprised is why the framework authors did not leverage it yet.

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


Re: Counting nested loop iterations

2006-03-16 Thread Duncan Booth
Derek Basch wrote:

 index = 0
 for animal in zoo:
 for color in animal:
 index += 1
  # assuming there is something more goes here...
 

You could do this, but it kind of depends what the loop *really* looks 
like:

for index, color in enumerate(color
  for animal in zoo
  for color in animal):
# the something more goes here.
pass


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


Re: Python Debugger / IDE ??

2006-03-16 Thread Rowdy
Don Taylor wrote:
 Is there a free or low-cost version of Delphi for Windows available 
 anywhere?
 
snip

There used to be a Delphi 6 Personal Edition that was available free
(for non-commercial use).  You might still find it around somewhere.

Rowdy

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


Re: Counting nested loop iterations

2006-03-16 Thread Carl Banks
Derek Basch wrote:
 What is the best way to count nested loop iterations? I can only figure
 to use an index but that seems kludgy.

 index = 0
 for animal in zoo:
 for color in animal:
 index += 1

I don't know if it's kludgy, but I do prefer to set counters in the for
statement whenever I can.  If I were using 2.4, I might try writing
something like:

for i,(animal,zoo) in enumerate((animal,zoo) for animal in zoo for
color in animal):
pass

or maybe break it down a little for clarity:

aciter = ((animal,zoo) for animal in zoo for color in animal)
for i,(animal,zoo) in enumerate(aciter):
pass

But even the clear version isn't as nearly clear and straightforward as
the nested fors with the counter.  I wouldn't forsake that clarity just
so it isn't kludgy.


Carl Banks

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread funkyj
here is my version of the same.

REPL output:

CL-USER (tests)


set  = (1 2)
n= 3
patterns = ((1 ANY 2))
---
(1 1 1)
(1 2 1)
(2 1 1)
(2 1 2)
(2 2 1)
(2 2 2)


set  = (A B)
n= 3
patterns = ((A ANY B) (B ANY A))
---
(A A A)
(A B A)
(B A B)
(B B B)


set  = (1 2)
n= 3
patterns = ((1 ANY 2) (2 ANY 1))
---
(1 1 1)
(1 2 1)
(2 1 2)
(2 2 2)
NIL
CL-USER

source:

 cartesian products minus wildcard patterns per:

 Newsgroups: comp.lang.lisp, etc...
 Subject: Programming challenge: wildcard exclusion in cartesian
products
 Date: 16 Mar 2006 03:14:23 -0800



(defun show-me (x) (format t ~A~% x))

(defun set^n (fn set n optional acc)
  call `fn' on each permutation of `set' raised to the `n' power
  (if (= n 0)
  (funcall fn (reverse acc))
  (dolist (e set)
(set^n fn set (- n 1) (cons e acc)

;; test set^n by printing and visually inspecting the result
(defun pr-set^n (set n)   (set^n #'show-me set n))

;; curry `set^n' so that `fn' is the only parameter
(defun set^n-gen (set n)
  (lambda (fn) (set^n fn set n)))

(defun mk-matchl-p (pat-list)
  return a function that tests a value against the patterns in
`pat-list'
  (labels ((matchp (pat val)
 (cond ((null pat) t)
   ((or (eq (car pat) (car val))
(eq (car pat) :any))
(matchp (cdr pat) (cdr val))
(lambda (val)
  predicate: return true if val matches any pattern in `pat-list'
  (dolist (p pat-list)
(if (matchp p val)
(return t))

(defun not-fp (f-pred)
  return the complement of predicate `f-pred'
  (lambda (x) (not (funcall f-pred x

;; f-gen is a generator of the form returned by set^n-gen
(defun accumulate-if (f-gen f-pred)
  accumulate values generated by f-gen that satisfy f-pred
  (let (acc)
(funcall f-gen (lambda (x) (if (funcall f-pred x) (push x acc
(nreverse acc)))

;; `pr-set^n-withoutWC' is the lisp equivalent (more or less) of
;; python code:
;;for i in cp.CPWithoutWC(x,y,z): print i
(defun pr-set^n-withoutWC (set n pat-list)
  (format t ~%~%set  = ~A~%n= ~A~%patterns = ~A~%~A~%
  set n pat-list ---)
  (dolist (e (accumulate-if (set^n-gen set n)
(not-fp (mk-matchl-p pat-list
(format t ~A~% e)))

(defun tests ()
  generate test output per the original problem examples
  (pr-set^n-withoutWC '(1 2) 3 '((1 :any 2)))
  (pr-set^n-withoutWC '(a b) 3 '((a :any b) (b :any a)))
  (pr-set^n-withoutWC '(1 2) 3 '((1 :any 2) (2 :any 1

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


Re: Python IDE: great headache....

2006-03-16 Thread Dag Fjeld Edvardsen
 Come to think of it, the only exception is probably that PyScripter
(AFAIK)
 does not provide conditional pause.

Quoting myself :)

But now it does! Conditional breakpoints were introduced in the
new version released on the 14th of March:
http://mmm-experts.com/

  -Dag


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


Re: Counting nested loop iterations

2006-03-16 Thread Derek Basch

Carl Banks wrote:
 But even the clear version isn't as nearly clear and straightforward as
 the nested fors with the counter.  I wouldn't forsake that clarity just
 so it isn't kludgy.


 Carl Banks

Yeah, looks like using the counters is clearer. Thanks for the opinions
everyone!

Derek Basch

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


  1   2   >