Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread Steve Holden
kanchy kang wrote:
> many people write test cases with python scripts.
> in these test scripts, there are many validation statements,
> for example, in unittest, failUnless(a == b),(a/b may be stringType or 
> intType...)
> 
> during running test scripts, if there is one exception raised from 
> failUnless, i still do not know a =?, b= ?... i have to add one statment 
> "print a" or "print b" again...
> 
> as i know, there are many validation statements if using python as one 
> test tool...
> i think my suggestion or requirement may benefit users greatly...
> 
A test framework will contain many tests for equality that have nothing 
to do with the tests themselves. So the real answer to this problem is 
to have the tests be more explicit when they need to be. A testEqual(a, 
b) test function would seem to be a more sensible approach than radical 
surgery on the interpreter. The function can then print its arguments if 
they turn out to be unequal.

Otherwise there would have to be some *very* selective mechanism to 
decide when the comparison arguments were printed out.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [Numpy-discussion] algorithm, optimization, or other problem?

2006-02-21 Thread Nadav Horesh
You may get a significant boost by replacing the line:
  w=w+ eta * (y*x - y**2*w)
with
  w *= 1.0 - eta*y*y
  w += eta*y*x

I ran a test on a similar expression and got 5 fold speed increase.
The dot() function runs faster if you compile with dotblas.

  Nadav.


-Original Message-
From:   [EMAIL PROTECTED] on behalf of Bruce Southey
Sent:   Tue 21-Feb-06 17:15
To: Brian Blais
Cc: python-list@python.org; [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject:Re: [Numpy-discussion] algorithm, optimization, or other 
problem?
Hi,
In the current version, note that Y is scalar so replace the squaring
(Y**2) with Y*Y as you do in the dohebb function.  On my system
without blas etc removing the squaring removes a few seconds (16.28 to
12.4). It did not seem to help factorizing Y.

Also, eta and tau are constants so define them only once as scalars
outside the loops and do the division outside the loop. It only saves
about 0.2 seconds but these add up.

The inner loop probably can be vectorized because it is just vector
operations on a matrix. You are just computing over the ith dimension
of X.  I think that you could be able to find the matrix version on
the net.

Regards
Bruce



On 2/21/06, Brian Blais <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to translate some Matlab/mex code to Python, for doing neural
> simulations.  This application is definitely computing-time limited, and I 
> need to
> optimize at least one inner loop of the code, or perhaps even rethink the 
> algorithm.
>The procedure is very simple, after initializing any variables:
>
> 1) select a random input vector, which I will call "x".  right now I have it 
> as an
> array, and I choose columns from that array randomly.  in other cases, I may 
> need to
> take an image, select a patch, and then make that a column vector.
>
> 2) calculate an output value, which is the dot product of the "x" and a weight
> vector, "w", so
>
> y=dot(x,w)
>
> 3) modify the weight vector based on a matrix equation, like:
>
> w=w+ eta * (y*x - y**2*w)
>^
>|
>+ learning rate constant
>
> 4) repeat steps 1-3 many times
>
> I've organized it like:
>
> for e in 100:   # outer loop
>  for i in 1000:  # inner loop
>  (steps 1-3)
>
>  display things.
>
> so that the bulk of the computation is in the inner loop, and is amenable to
> converting to a faster language.  This is my issue:
>
> straight python, in the example posted below for 25 inner-loop steps, 
> takes 20
> seconds for each outer-loop step.  I tried Pyrex, which should work very fast 
> on such
> a problem, takes about 8.5 seconds per outer-loop step.  The same code as a 
> C-mex
> file in matlab takes 1.5 seconds per outer-loop step.
>
> Given the huge difference between the Pyrex and the Mex, I feel that there is
> something I am doing wrong, because the C-code for both should run comparably.
> Perhaps the approach is wrong?  I'm willing to take any suggestions!  I don't 
> mind
> coding some in C, but the Python API seemed a bit challenging to me.
>
> One note: I am using the Numeric package, not numpy, only because I want to 
> be able
> to use the Enthought version for Windows.  I develop on Linux, and haven't 
> had a
> chance to see if I can compile numpy using the Enthought Python for Windows.
>
> If there is anything else anyone needs to know, I'll post it.  I put the main 
> script,
> and a dohebb.pyx code below.
>
>
> thanks!
>
> Brian Blais
>
> --
> -
>
>  [EMAIL PROTECTED]
>  http://web.bryant.edu/~bblais
>
>
>
>
> # Main script:
>
> from dohebb import *
> import pylab as p
> from Numeric import *
> from RandomArray import *
> import time
>
> x=random((100,1000))# 1000 input vectors
>
> numpats=x.shape[0]
> w=random((numpats,1));
>
> th=random((1,1))
>
> params={}
> params['eta']=0.001;
> params['tau']=100.0;
> old_mx=0;
> for e in range(100):
>
>  rnd=randint(0,numpats,25)
>  t1=time.time()
>  if 0:  # straight python
>  for i in range(len(rnd)):
>  pat=rnd[i]
>  xx=reshape(x[:,pat],(1,-1))
>  y=matrixmultiply(xx,w)
>  w=w+params['eta']*(y*transpose(xx)-y**2*w);
>  th=th+(1.0/params['tau'])*(y**2-th);
>  else: # pyrex
>  dohebb(params,w,th,x,rnd)
>  print time.time()-t1
>
>
> p.plot(w,'o-')
> p.xlabel('weights')
> p.show()
>
>
> #=
>
> # dohebb.pyx
>
> cdef extern from "Numeric/arrayobject.h":
>
>struct PyArray_Descr:
>  int type_num, elsize
>  char type
>
>ctypedef class Numeric.ArrayType [object PyArrayObject]:
>  cdef char *data
>  cdef int nd
>  cdef int *dimensions, *strides
>  cdef object base
>  cdef PyArray_Descr *descr
>  cdef int flags
>
>
> def dohebb(params,ArrayType w,ArrayTyp

Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread kanchy kang

Thank you for your suggestions!



From: Steve Holden <[EMAIL PROTECTED]>
To: kanchy kang <[EMAIL PROTECTED]>
CC: python-list@python.org
Subject: Re: May i customize basic operator (such as 1==3)?
Date: Wed, 22 Feb 2006 01:44:26 -0500

kanchy kang wrote:

many people write test cases with python scripts.
in these test scripts, there are many validation statements,
for example, in unittest, failUnless(a == b),(a/b may be stringType or 
intType...)


during running test scripts, if there is one exception raised from 
failUnless, i still do not know a =?, b= ?... i have to add one statment 
"print a" or "print b" again...


as i know, there are many validation statements if using python as one 
test tool...

i think my suggestion or requirement may benefit users greatly...

A test framework will contain many tests for equality that have nothing to 
do with the tests themselves. So the real answer to this problem is to have 
the tests be more explicit when they need to be. A testEqual(a, b) test 
function would seem to be a more sensible approach than radical surgery on 
the interpreter. The function can then print its arguments if they turn out 
to be unequal.


Otherwise there would have to be some *very* selective mechanism to decide 
when the comparison arguments were printed out.


regards
 Steve
--
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/


_
FREE pop-up blocking with the new MSN Toolbar – get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


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

Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread kanchy kang
__eq__ method can resolve this problem only for class object.
what can i do in the following case?

a = somefuction(...) #a is stringType

a == "1234"?

my simple requirement is:
in some validation statments, such as, failUnless(a == "1234")
if the result is true, it's OK. otherwise, it prints a automatically.

also, i know we can implement failUnless(...) to satisfy this,
failUnless(a == b, a, b)

but i think, if we can override "==" for any type, it will make things 
conveniently...

regards!


>From: Casey Hawthorne <[EMAIL PROTECTED]>
>To: python-list@python.org
>Subject: Re: May i customize basic operator (such as 1==3)?
>Date: Wed, 22 Feb 2006 04:06:34 GMT
>
>I believe you are asking for a side effect from the "==" operator.
>
>Add print statements to the __eq__ method.
>
>"kanchy kang" <[EMAIL PROTECTED]> wrote:
>
> >Hi,all
> >as we know, we can override the operator of one object(for example 
>__eq__).
> >my question is, how to override the basic operator?
> >for example,
> >
> >for any object comparison operator(including litterals),
> >for example,
> >a = "123"
> >b = "321"
> >
> >the boolean equation a == b,
> >i need override "==" operator like this:
> >first display a and b
> >
> >then return real boolean result (a == b).
> >
> >thanks!
> >
> >
> >---
> >Best regards,
> >kangzz
> >
> >mailto:[EMAIL PROTECTED]
> >Tel : 021-65407754
> >MP: 13916928084
> >
> >_
> >Express yourself instantly with MSN Messenger! Download today - it's 
>FREE!
> >http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>--
>Regards,
>Casey
>--
>http://mail.python.org/mailman/listinfo/python-list

_
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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


Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread Robert Kern
kanchy kang wrote:
> many people write test cases with python scripts.
> in these test scripts, there are many validation statements,
> for example, in unittest, failUnless(a == b),(a/b may be stringType or
> intType...)
> 
> during running test scripts, if there is one exception raised from
> failUnless, i still do not know a =?, b= ?... i have to add one statment
> "print a" or "print b" again...
> 
> as i know, there are many validation statements if using python as one
> test tool...

So why don't you just do something like this:

  self.failUnless(a == b, "%s != %s" % (a,b))

As a bonus, that will only print something if the test fails rather than spewing
out a whole bunch of text that's irrelevant when the tests pass.

> i think my suggestion or requirement may benefit users greatly...

Python will never grow the ability to modify methods on the builtin types. We've
discussed several times before, and you can search the archives of this list if
you want more information why this is so.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Pyserial never read

2006-02-21 Thread Nick Craig-Wood
Peter Hansen <[EMAIL PROTECTED]> wrote:
>  Nick Craig-Wood wrote:
> > luca72 <[EMAIL PROTECTED]> wrote:
> > 
> >> Thanks for your help, but it don't solve the problem.
> >> I receive only the echo and full stop.
> > 
> > Try swapping pins 2 and 3 in the lead.
> 
>  Anything's possible, but given that in his original post he says it 
>  works when he uses Delphi, it seems unlikely making a change to the 
>  hardware is necessary.

Sorry missed that bit!

Pyserial works very well in my experience (under linux).

Serial ports are generally a pain though ;-)

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


Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread kanchy kang

many people write test cases with python scripts.
in these test scripts, there are many validation statements,
for example, in unittest, failUnless(a == b),(a/b may be stringType or 
intType...)


during running test scripts, if there is one exception raised from 
failUnless, i still do not know a =?, b= ?... i have to add one statment 
"print a" or "print b" again...


as i know, there are many validation statements if using python as one test 
tool...

i think my suggestion or requirement may benefit users greatly...

best regards!



From: Steve Holden <[EMAIL PROTECTED]>
To: python-list@python.org
Subject: Re: May i customize basic operator (such as 1==3)?
Date: Tue, 21 Feb 2006 23:29:30 -0500

kanchy kang wrote:
> Hi,all
> as we know, we can override the operator of one object(for example 
__eq__).

> my question is, how to override the basic operator?
> for example,
>
> for any object comparison operator(including litterals),
> for example,
> a = "123"
> b = "321"
>
> the boolean equation a == b,
> i need override "==" operator like this:
> first display a and b
>
> then return real boolean result (a == b).
>
> thanks!

This isn't going to be possible without modifying the Python
interpreter, as the operators are implemented as methods of objects, and
the built-in objects are programmed in C and not in Python.

regards
  Steve
--
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


_
FREE pop-up blocking with the new MSN Toolbar – get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


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

Re: a little more help with python server-side scripting

2006-02-21 Thread Steve Holden
John Salerno wrote:
> Steve Holden wrote:
> 
> 
>>If the script ran, you will now know waht version of Apaceh you're 
>>running with!
> 
> 
> Well, the script did seem to run, but I'm still not sure if this is what 
> I'm ultimately after. This allows me to run Python script files, which 
> is good, but what I really want to do is write bits of Python code in my 
> HTML files (as a means to include headers and footers, for example). So 
> these bits of Python code will basically be like a PHP include() 
> function that calls another HTML file which contains the header/footer 
> HTML to insert into the calling file. This type of situation doesn't 
> involve calling external Python scripts.
> 
> Maybe I can just try this also and see if it works, but I don't know the 
> code to use to write such an include statement. What would the 
> equivalent of this be in Python:
> 
> 
> 
> Thanks.

There are various ways you can do this, each of which depends on having 
a particular framework in place. Since your web service provider tells 
you that mod_python is available it's likely that you'll be able to use 
PSP (one of several beasts known as "Python Server Pages").

This is briefly described (for a flavor of the technology) in

   http://www.python.org/pycon/dc2004/papers/14/

by the author of mod_python. If you like what you see then take a look 
at the full mod_python documentation, at

   http://www.modpython.org/live/current/doc-html/

Note that purists might suggest this isn't the best way to use Python on 
the web. If it gets you where you want to be, feel free to ignore them :-)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: a little more help with python server-side scripting

2006-02-21 Thread John Salerno
Steve Holden wrote:

> If the script ran, you will now know waht version of Apaceh you're 
> running with!

Well, the script did seem to run, but I'm still not sure if this is what 
I'm ultimately after. This allows me to run Python script files, which 
is good, but what I really want to do is write bits of Python code in my 
HTML files (as a means to include headers and footers, for example). So 
these bits of Python code will basically be like a PHP include() 
function that calls another HTML file which contains the header/footer 
HTML to insert into the calling file. This type of situation doesn't 
involve calling external Python scripts.

Maybe I can just try this also and see if it works, but I don't know the 
code to use to write such an include statement. What would the 
equivalent of this be in Python:



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


Re: a little more help with python server-side scripting

2006-02-21 Thread John Salerno
Steve Holden wrote:

>> Where does this line go? Just at the top as well?
> 
> Nope. I presume you can log in to your web server using ssh or telnet or 
> similar. In which case you do so. Then use the commands
> 
> cd {wherever}/cgi-bin
> chmod +x test.py
> 
> to make the script executable, and therefore recognised as a proper 
> script by Apache.

I'm afraid I still don't understand. I guess this step isn't necessary, 
since the script seemed to run anyway, but I'd like to know this anyway. 
The way I log into my server space is by an FTP program, so I don't see 
an occasion to actually *type* in any kind of commands.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little more help with python server-side scripting

2006-02-21 Thread Steve Holden
John Salerno wrote:
> Steve Holden wrote:
> 
> 
>>Fortunately they've given you the information you need to run CGI
>>scripts. Try installing this script in your cgi-bin directory as test.py 
>>(you may have to set it executable):
> 
> 
> Thank you! I desperately needed to test it, and that seemed to work. I 
> didn't have to make it executable though. I wonder why?

Probably because the cgi-bin directory is specially marked to contain 
executables. If you drop the script in another directory you will almost 
certainly just see the source of the script. Making it executable 
*might* cause it to run, but that would depend on exactly how your 
server is configured.

Certainly my sites all have a line like

ScriptAlias /cgi-bin/ "c:/apache/cgi-bin/"

in the httpd.conf file. ScriptAlias tells Apache that the files in the 
directory are scripts. The first argument is the address in web-space, 
the second the address on disk.

You'll find you can affect *some* configuration items by creating files 
called .htaccess in your web content directories, but that's a ways down 
the road yet.

If the script ran, you will now know waht version of Apaceh you're 
running with!

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: What are COM-enabled applications?

2006-02-21 Thread Ravi Teja
COM is Windows only. (Actually there is DCOM for Linux, but that's
another story).

Read about it here.
http://en.wikipedia.org/wiki/Component_object_model

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


Re: Basic coin flipper program - logical error help

2006-02-21 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> John Zenger wrote:
> > Also, with the functional programming tools of map, filter, and lambda,
> > this code can be reduced to just six lines:
> >
> > import random
> >
> > flips = map(lambda x: random.randrange(2), xrange(100))
> > heads = len(filter(lambda x: x is 0, flips))
> > tails = len(filter(lambda x: x is not 0, flips))
>
> Or a filter/map/lambda free way:
>
> heads = sum(random.randrange(2) for x in xrange(100))
> tails = 100 - heads
>
sort, then groupby.


import itertools
import random
h,t = [len(list(g)) for k,g in itertools.groupby(sorted([random.randrange(2)
for i in xrange(100)]))]
print h,t



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


Re: Basic coin flipper program - logical error help

2006-02-21 Thread bonono

John Zenger wrote:
> Also, with the functional programming tools of map, filter, and lambda,
> this code can be reduced to just six lines:
>
> import random
>
> flips = map(lambda x: random.randrange(2), xrange(100))
> heads = len(filter(lambda x: x is 0, flips))
> tails = len(filter(lambda x: x is not 0, flips))

Or a filter/map/lambda free way:

heads = sum(random.randrange(2) for x in xrange(100))
tails = 100 - heads

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


Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread Steve Holden
kanchy kang wrote:
> Hi,all
> as we know, we can override the operator of one object(for example __eq__).
> my question is, how to override the basic operator?
> for example,
> 
> for any object comparison operator(including litterals),
> for example,
> a = "123"
> b = "321"
> 
> the boolean equation a == b,
> i need override "==" operator like this:
> first display a and b
> 
> then return real boolean result (a == b).
> 
> thanks!

This isn't going to be possible without modifying the Python 
interpreter, as the operators are implemented as methods of objects, and 
the built-in objects are programmed in C and not in Python.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: a little more help with python server-side scripting

2006-02-21 Thread Steve Holden
John Salerno wrote:
> Ben Cartwright wrote:
> 
> 
>>>The script can be given a executable mode, or permission, using the
>>>chmod command:
>>>
>>>  $ chmod +x myscript.py
>>
>>And this answers your second.  Your host needs to know the path to your
>>script so they can use chmod to make it executable.
> 
> 
> Where does this line go? Just at the top as well?

Nope. I presume you can log in to your web server using ssh or telnet or 
similar. In which case you do so. Then use the commands

cd {wherever}/cgi-bin
chmod +x test.py

to make the script executable, and therefore recognised as a proper 
script by Apache.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: a little more help with python server-side scripting

2006-02-21 Thread John Salerno
Steve Holden wrote:

> Fortunately they've given you the information you need to run CGI
> scripts. Try installing this script in your cgi-bin directory as test.py 
> (you may have to set it executable):

Thank you! I desperately needed to test it, and that seemed to work. I 
didn't have to make it executable though. I wonder why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little more help with python server-side scripting

2006-02-21 Thread John Salerno
Ben Cartwright wrote:

>> The script can be given a executable mode, or permission, using the
>> chmod command:
>>
>>   $ chmod +x myscript.py
> 
> And this answers your second.  Your host needs to know the path to your
> script so they can use chmod to make it executable.

Where does this line go? Just at the top as well?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread Robert Kern
Casey Hawthorne wrote:
> I believe you are asking for a side effect from the "==" operator.
> 
> Add print statements to the __eq__ method.

The things is, he wants to make those modifications to builtin types, which he
can't do.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: May i customize basic operator (such as 1==3)?

2006-02-21 Thread Casey Hawthorne
I believe you are asking for a side effect from the "==" operator.

Add print statements to the __eq__ method.

"kanchy kang" <[EMAIL PROTECTED]> wrote:

>Hi,all
>as we know, we can override the operator of one object(for example __eq__).
>my question is, how to override the basic operator?
>for example,
>
>for any object comparison operator(including litterals),
>for example,
>a = "123"
>b = "321"
>
>the boolean equation a == b,
>i need override "==" operator like this:
>first display a and b
>
>then return real boolean result (a == b).
>
>thanks!
>
>
>---
>Best regards,
>kangzz
>
>mailto:[EMAIL PROTECTED]
>Tel : 021-65407754
>MP: 13916928084
>
>_
>Express yourself instantly with MSN Messenger! Download today - it's FREE! 
>http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
--
Regards,
Casey
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little more help with python server-side scripting

2006-02-21 Thread Steve Holden
John Salerno wrote:
> I contacted my domain host about how Python is implemented on their 
> server, and got this response:
> 
> ---
> Hello John,
> 
> Please be informed that the implementation of python in our server is 
> through mod_python integration with the apache.
> 
> These are the steps needed for you to be able to run .py script directly 
> from browser for your webpage:
> 
> 1. Please use the below mentioned path for python:
> #!/usr/bin/env python
> 
> Furthermore, update us with the script path, so that we can set the 
> appropriate ownership and permissions of the script on the server.
> 
> If you require any further assistance, feel free to contact us.
> ---
> 
> Unfortunately, I don't completely understand what it is I need to do 
> now. Where do I put the path they mentioned? And what do they mean by my 
> script path?

Don't worry, it looks as though they don't completely understand either :-)

Fortunately they've given you the information you need to run CGI
scripts. Try installing this script in your cgi-bin directory as test.py 
(you may have to set it executable):

#!/usr/bin/env python
#
import os
print "Content-Type: text/plain"
print
for t in os.environ.items():
 print "%s=%s" % t

If it runs when you access http://yourdomain/cgi-bin/test.py it looks 
like you're good to go!

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


What are COM-enabled applications?

2006-02-21 Thread Tempo
As the subject of this post suggests, I have one question; what are
COM-enabled applications? I believe Microsoft Word is one of these
apps, but what else? Is a web browser, Paint, Solitare, games, etc? I'm
not sure if it varies from operating system to operating system, but I
am talking about COM applications in Windows. Thanks for any and all of
your help and time.

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


May i customize basic operator (such as 1==3)?

2006-02-21 Thread kanchy kang
Hi,all
as we know, we can override the operator of one object(for example __eq__).
my question is, how to override the basic operator?
for example,

for any object comparison operator(including litterals),
for example,
a = "123"
b = "321"

the boolean equation a == b,
i need override "==" operator like this:
first display a and b

then return real boolean result (a == b).

thanks!


---
Best regards,
kangzz

mailto:[EMAIL PROTECTED]
Tel : 021-65407754
MP: 13916928084

_
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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


Weekly Python Patch/Bug Summary

2006-02-21 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  385 open (-14) /  3067 closed (+25) /  3452 total (+11)
Bugs:  864 open (-59) /  5621 closed (+68) /  6485 total ( +9)
RFE :  211 open ( +2) /   200 closed ( +2) /   411 total ( +4)

New / Reopened Patches
__

GNU uses double-dashes not single  (2006-02-16)
   http://python.org/sf/1433148  opened by  splitscreen

restrict codec lookup to encodings package  (2006-02-16)
CLOSED http://python.org/sf/1433198  reopened by  lemburg

restrict codec lookup to encodings package  (2006-02-16)
CLOSED http://python.org/sf/1433198  opened by  Guido van Rossum

add on_missing() and default_factory to dict  (2006-02-17)
   http://python.org/sf/1433928  opened by  Guido van Rossum

CHM file contains proprietary link format  (2006-02-18)
   http://python.org/sf/1434298  opened by  Alexander Schremmer

Patch to support lots of file descriptors  (2006-02-19)
   http://python.org/sf/1434657  opened by  Sven Berkvens-Matthijsse

Add copy() method to zlib's compress and decompress objects  (2006-02-20)
   http://python.org/sf/1435422  opened by  Chris AtLee

PEP 343 with statement  (2006-02-21)
   http://python.org/sf/1435715  opened by  mbland

Incremental codecs  (2006-02-21)
   http://python.org/sf/1436130  opened by  Walter Dörwald

fix inplace assignment for immutable sequences  (2006-02-21)
   http://python.org/sf/1436226  opened by  Georg Brandl

Patches Closed
__

GNU uses double-dashes not single  (2006-02-16)
   http://python.org/sf/1433166  deleted by  gvanrossum

restrict codec lookup to encodings package  (2006-02-16)
   http://python.org/sf/1433198  closed by  lemburg

restrict codec lookup to encodings package  (2006-02-16)
   http://python.org/sf/1433198  closed by  lemburg

use computed goto's in ceval loop  (2006-01-18)
   http://python.org/sf/1408710  closed by  loewis

have SimpleHTTPServer return last-modified headers  (2006-01-28)
   http://python.org/sf/1417555  closed by  birkenfeld

Feed style codec API  (2005-01-12)
   http://python.org/sf/1101097  closed by  lemburg

chunk.py can't handle >2GB chunks  (2005-12-05)
   http://python.org/sf/1373643  closed by  birkenfeld

Fix of bug 1366000  (2005-11-30)
   http://python.org/sf/1370147  closed by  birkenfeld

Optional second argument for startfile  (2005-12-29)
   http://python.org/sf/1393157  closed by  birkenfeld

Clairify docs on reference stealing  (2006-01-26)
   http://python.org/sf/1415507  closed by  birkenfeld

urllib proxy_bypass broken  (2006-02-07)
   http://python.org/sf/1426648  closed by  birkenfeld

Speed up EnumKey call  (2004-06-22)
   http://python.org/sf/977553  closed by  birkenfeld

[PATCH] Bug #1351707  (2005-11-10)
   http://python.org/sf/1352711  closed by  birkenfeld

fileinput patch for bug #1336582  (2005-10-25)
   http://python.org/sf/1337756  closed by  birkenfeld

Fix for int(string, base) wrong answers  (2005-10-22)
   http://python.org/sf/1334979  closed by  birkenfeld

[PATCH] 100x optimization for ngettext  (2005-11-06)
   http://python.org/sf/1349274  closed by  birkenfeld

commands.getstatusoutput()  (2005-11-02)
   http://python.org/sf/1346211  closed by  birkenfeld

two fileinput enhancements (fileno, openhook)  (2005-06-05)
   http://python.org/sf/1215184  closed by  birkenfeld

mode argument for fileinput class  (2005-05-31)
   http://python.org/sf/1212287  closed by  birkenfeld

do not add directory of sys.argv[0] into sys.path  (2004-05-02)
   http://python.org/sf/946373  closed by  gbrandl

prefix and exec_prefix as root dir bug  (2004-04-08)
   http://python.org/sf/931938  closed by  gbrandl

New / Reopened Bugs
___

optparse docs double-dash confusion  (2006-02-16)
   http://python.org/sf/1432838  opened by  John Veness

Logging hangs thread after detaching a StreamHandler's termi  (2006-02-13)
CLOSED http://python.org/sf/1431253  reopened by  yangzhang

os.path.expandvars sometimes doesn't expand $HOSTNAME  (2006-02-17)
CLOSED http://python.org/sf/1433667  opened by  Doug Fort

normalize function in minidom unlinks empty child nodes  (2006-02-17)
   http://python.org/sf/1433694  opened by  RomanKliotzkin

string parameter to ioctl not null terminated, includes fix  (2006-02-17)
   http://python.org/sf/1433877  opened by  Quentin Barnes

pointer aliasing causes core dump, with workaround  (2006-02-17)
   http://python.org/sf/1433886  opened by  Quentin Barnes

Python crash on __init__/__getattr__/__setattr__ interaction  (2004-04-26)
CLOSED http://python.org/sf/942706  reopened by  hhas

Crash when decoding UTF8  (2006-02-20)
CLOSED http://python.org/sf/1435487  opened by  Viktor Ferenczi

CGIHTTPServer doesn't handle path names with embeded space  (2006-02-21)
   http://python.org/sf/1436206  opened by  Richard Coupland

Bugs Closed
___

Logging hangs thread af

Re: Python vs. Lisp -- please explain

2006-02-21 Thread Peter Mayne
Torsten Bronger wrote:
> 
> My definiton would be that an interpreted language has in its
> typical implementation an interpreting layer necessary for typical
> hardware.  Of couse, now we could discuss what is "typical",
> however, in practice one would know it, I think.  In case of Python:
> CPython and all important modern processors.

In a previous century, I used something called UCSD Pascal, which at the 
time was a typical implementation of Pascal. It ran on (amongst other 
things) an Apple ][, which at the time was typical hardware. It worked 
by compiling Pascal source to bytecode (called p-code), and interpreting 
the p-code. So, in practice, one would know that Pascal was an 
interpreted language.

Later on, I used a typical implementation called VAX Pascal: a compiler 
reduced Pascal source to VAX object code. In practice, Pascal was not an 
interpreted language. Of course, more than one of the VAXen we had did 
not implement the entire VAX instruction set, and some instructions were 
emulated, or interpreted, if you will, by other VAX instructions. So, in 
practice, some of the Pascal was interpreted.

And, as someone in this thread has pointed out, it is likely that your 
important modern (x86) processor is not natively executing your x86 
code, and indeed meets your definition of having "in its typical 
implementation an interpreting layer necessary for typical hardware".

Another example: is Java the bytecode, which is compiled from Java the 
language, interpreted or not? Even when the HotSpot JIT cuts in? Or when 
a native Java processor is used? Or when your Java program is compiled 
with GCJ (if GCJ does what I think it does)? Does this make Java an 
interpreted language or not?

Personally, in practice I don't care, so don't ask me. Ponder on getting 
angels to dance on the head of a pin before you worry about whether the 
dance can be interpreted or not.

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


Re: Basic coin flipper program - logical error help

2006-02-21 Thread John Zenger
wes weston wrote:
>Looping is easier with:
> for x in range(100):
>if random.randint(0,1) == 0:
>   heads += 1
>else:
>   tails += 1

Also, with the functional programming tools of map, filter, and lambda, 
this code can be reduced to just six lines:

import random

flips = map(lambda x: random.randrange(2), xrange(100))
heads = len(filter(lambda x: x is 0, flips))
tails = len(filter(lambda x: x is not 0, flips))

print "The coin landed on heads", heads, "times."
print "The coin landed on tails", tails, "times."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little more help with python server-side scripting

2006-02-21 Thread Ben Cartwright
John Salerno wrote:
> I contacted my domain host about how Python is implemented on their
> server, and got this response:
>
> ---
> Hello John,
>
> Please be informed that the implementation of python in our server is
> through mod_python integration with the apache.
>
> These are the steps needed for you to be able to run .py script directly
> from browser for your webpage:
>
> 1. Please use the below mentioned path for python:
> #!/usr/bin/env python
>
> Furthermore, update us with the script path, so that we can set the
> appropriate ownership and permissions of the script on the server.
>
> If you require any further assistance, feel free to contact us.
> ---
>
> Unfortunately, I don't completely understand what it is I need to do
> now. Where do I put the path they mentioned? And what do they mean by my
> script path?


The Python tutorial should fill in the blanks
(http://www.python.org/doc/tut/node4.html):
> 2.2.2 Executable Python Scripts
>
> On BSD'ish Unix systems, Python scripts can be made directly executable,
> like shell scripts, by putting the line
>
>   #! /usr/bin/env python
>
> (assuming that the interpreter is on the user's PATH) at the beginning
> of the script and giving the file an executable mode. The "#!" must be
> the first two characters of the file. On some platforms, this first line
> must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or
> Windows ("\r\n") line ending. Note that the hash, or pound, character,
> "#", is used to start a comment in Python.

This answers your first question.  Put the #! bit at the top of your
.py script.  This way the web server will know how to run the script.

> The script can be given a executable mode, or permission, using the
> chmod command:
>
>   $ chmod +x myscript.py

And this answers your second.  Your host needs to know the path to your
script so they can use chmod to make it executable.

--Ben

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


Re: odt -> pdf

2006-02-21 Thread Colin J. Williams
Katja Suess wrote:
> Hi
> Cause Google didn't find the Info I was trying to find her my post.
> Is PyUNO still _the_ Tool to create PDFs out of OpenOffice docs (odt, 
> not swx) ?
> Do other tools exist?
> Do you prefer generatingp PDFs using the XML-Strukture of odt files?
> Regards,
> Katja
> 
OpenOffice.org 2.0 gives you an Export to pdf capability.

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


Re: number ranges

2006-02-21 Thread Colin J. Williams
Alex Martelli wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>...
> 
>>>Reread the part I quoted above: at least some of the proponents of this
>>>syntax appear to be totally ignorant of 30 years of literature and
>>>practice of programming, "it will be tough to convince" them that closed
>>>intervals are a terrible mistake and semi-open ones the only way to go.
>>
>>I intellectually understand that semi-open intervals 
>>are the only way to go. But reading the words, the part 
>>of my brain that speaks English cries out for a closed 
>>interval. Bad brain.
> 
> 
> Human brain -- it's harder for non-native-speakers like me to judge the
> associations of certain English words in a native speaker's brain.
> 
> 
>>Given the overwhelming benefit of semi-closed 
>>intervals, I wish to amend my proposal to follow Alex's 
>>suggestions, namely:
>>
>>for i in (1 to 10 by 3):
>> print i
>>
>>should print 1 4 7.
> 
> 
> But that would be an "attractive nuisance" to many other native speakers
> like you, who would instinctively think of a closed interval.  Maybe
> 'upto' rather than 'to', as somebody else suggested, would ease that.
> 
> 
>>That would make (a to b by c) equivalent to 
>>range(a,b,c) except that it returns an iterator rather 
>>than a list. Hmmm... putting it that way, the new 
>>syntax actually costs 1 keystroke, or saves 1 if you 
>>put spaces after the commas in the range expression. 
>>Does it add enough clarity and ease of understanding to 
>>justify two new keywords?
> 
> 
> No, of course not.  And if we use upto, we'll need a downto as well, a
> third keyword, for loops with negative step.  range should return an
> iterator in Python 3.0 (maybe in 2010?-) and xrange will then go away,
> so the only issue is whether syntax sugar for it is SO badly needed as
> to justify 2/3 new keywords.
> 
> 
>>>whines about it); Python is clearly much better off if such people run
>>>away to Ruby, with its (expletive deleted) a..b AND a...b syntaxes just
>>>to ensure maximum confusion;-).
>>
>>Ruby uses both .. and ...? Now I'm frightened.
> 
> 
> I _like_ Ruby, mostly, but yes, it has both a..b AND a...b, one of them
> to indicate a semi-open interval and the other to indicate a closed one
> (I believe the three dots are for the semi-open, but it could be the
> other way 'round) -- I don't remember how it indicates a step. I do
> think this is a wart (lack of visual or mnemonic distinction), though
> I'm sure Ruby enthusiasts would not agree.
> 
> 
> Alex
http://www.ruby-doc.org/docs/ProgrammingRuby/
It seems that .. and ... are Range class constructors.

Range.new(a, b, exclusive= True) is equivalent to Python's range(a, b) 
i.e. Ruby's  a...b

There appears to be no provision for a stride.

Ruby's choice between .. and ... seems a little perverse.  I would 
expect '...' to deliver a little more than '..'.

I guess one could consider Python's range() as a constructor for the 
List class.

Steven D'Aprano suggested that 1 to 10 by 3 should create an iterator.
What are the benefits of this as compared with a Python List?

Could we not have 1 ... 10 ... 3 to mean the same thing and then there 
would be no need for extra reserved words?

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


Re: Python vs. Lisp -- please explain

2006-02-21 Thread Carl Friedrich Bolz
Chris Mellon wrote:
[snip]
> I don't think it does, though. Firstly, as a definition it relies on
> the environment the application will be running under and therefore
> can't be considered to describe just a language. Secondly, by that
> definition Java is an interpreted language which is at odds with the
> common definition.
> 
> I've encountered a C scripting environment that works by using GCC to
> compile each line as it is encountered, doing some magic to keep a
> working compilation environment around.
> 
> Interpreted? Compiled?
>

There is also the wonderful C interpreter cint:

http://root.cern.ch/root/Cint.html

so obviously C must be an interpreted language :-)

Cheers,

Carl Friedrich Bolz

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


Re: Basic coin flipper program - logical error help

2006-02-21 Thread DannyB
Thanks everyone for your insight.

I'm coming from C++ - I'm used to formatting code with {} instead of
whitespaces.

@Larry - this isn't my homework :P  I'm actually taking a VB.NET class
in school.

I was teaching myself C++ but decided to scale back to Python.  I've
heard it was a bit easier to understand and it cuts your development
time by at least 50% (I've heard 90%).

Logically I can figure things out - its the formatting of the logic in
Python that is messing me up.  I'll get it soon enough =)

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


ANN: Extended Python debugger 0.12

2006-02-21 Thread R. Bernstein
This third release of an improved debugger also probably about as
great as the last release.

Download from
http://sourceforge.net/project/showfiles.php?group_id=61395&package_id=175827

On-line documentation is at
http://bashdb.sourceforge.net/pydb/pydb/lib/index.html

Along with this release is a version of ddd (3.3.12-test3) that
interfaces with this debugger. Get that at:
http://sourceforge.net/project/showfiles.php?group_id=61395&package_id=65341

- - - - - - 
>From the NEWS file.

* Add gdb commands: 
- "cd" command
- "display", "undisplay"
- help subcommands for "show", "info", and "set"
- info: "display", "line" "source" and "program"
- "pwd" command
- "return" (early exit from a function)
- "shell" command
- Extend "info line" to allow a function name.

* Use inspect module. Argument parameters and values are now shown.

* Break out debugger into more files 

* File location reporting changed. Is now like mdb, bashdb, or (or perldb)

* Changes to make more compatible with ddd.

* Doc fixes, add more GNU Emacs debugger commands

* "clear" command now accepts a function name

* Bugfixes:
  - allow debugged program to mangle sys.argv (we save our own copy)



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


Re: deriving from float or int

2006-02-21 Thread Robert Kern
gene tani wrote:
> Russ wrote:
> 
>>Does it ever make sense to derive a class from a basic type such as
>>float or int? Suppose, for example, that I want to create a class for
>>physical scalars with units. I thought about deriving from float, then
>>adding the units. I played around with it a bit, but it doesn't seem to
>>work very well. Am I missing something here? Thanks.
> 
> you could look at how sciPy does it:
> http://starship.python.net/~hinsen/ScientificPython/

ScientificPython != SciPy

ScientificPython's unit package does not subclass from floats since it tries to
be agnostic about the kind of value you can assign a unit to.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


a little more help with python server-side scripting

2006-02-21 Thread John Salerno
I contacted my domain host about how Python is implemented on their 
server, and got this response:

---
Hello John,

Please be informed that the implementation of python in our server is 
through mod_python integration with the apache.

These are the steps needed for you to be able to run .py script directly 
from browser for your webpage:

1. Please use the below mentioned path for python:
#!/usr/bin/env python

Furthermore, update us with the script path, so that we can set the 
appropriate ownership and permissions of the script on the server.

If you require any further assistance, feel free to contact us.
---

Unfortunately, I don't completely understand what it is I need to do 
now. Where do I put the path they mentioned? And what do they mean by my 
script path?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic coin flipper program - logical error help

2006-02-21 Thread Martin P. Hellwig
DannyB wrote:
 > I'm just learning Python.

So am I :-)

 > I've created a simple coin flipper program -
 > here is the code:
 >
 > [source]
 > #Coin flipper
 > import random
 >
 > heads = 0
 > tails = 0
 > counter = 0
 >
 > coin = random.randrange(2)
 >
 > while (counter < 100):
 > if (coin == 0):
 > heads += 1
 > counter += 1
 > else:
 > tails += 1
 > counter += 1
 >
 > coin = random.randrange(2)

This line is you logic error because it's not part of your while loop 
the coin variables get the result of random.randrange(2) assigned only 
one time (before the loop).

 >
 >
 > print "\nThe coin landed on heads", heads, "times."
 > print "\nThe coin landed on tails", tails, "times."
 > [/source]
 >
 > << anyway.>>>
 >
 > The program runs - however - it will give me 100 heads OR 100 tails.
 > Can someone spot the logic error?
 >
 > Thanks
 >
 > ~Dan
 >

You could changed the program to this it works too and is just as 
readable (IMHO):

#Coin flipper
import random

heads = 0
tails = 0
counter = 0
# removed random line
while (counter < 100):
 if random.randrange(2):# put random here
 heads += 1
 counter += 1
 else:
 tails += 1
 counter += 1
# removed random line
print "\nThe coin landed on heads", heads, "times."
print "\nThe coin landed on tails", tails, "times."

Take my advice with caution I'm also new to this :-)

Btw, it is possible that the coins lands on it side if not catched with 
the hand (yes I have seen it happen) ;-)

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


Re: Basic coin flipper program - logical error help

2006-02-21 Thread wes weston
DannyB wrote:
> I'm just learning Python.  I've created a simple coin flipper program -
> here is the code:
> 
> [source]
> #Coin flipper
> import random
> 
> heads = 0
> tails = 0
> counter = 0
> 
> coin = random.randrange(2)
> 
> while (counter < 100):
> if (coin == 0):
> heads += 1
> counter += 1
> else:
> tails += 1
> counter += 1
> 
> coin = random.randrange(2)
> 
> 
> print "\nThe coin landed on heads", heads, "times."
> print "\nThe coin landed on tails", tails, "times."
> [/source]
> 
> << anyway.>>>
> 
> The program runs - however - it will give me 100 heads OR 100 tails.
> Can someone spot the logic error?  
> 
> Thanks
> 
> ~Dan
> 

Dan,
Looping is easier with:
for x in range(100):
if random.randint(0,1) == 0:
   heads += 1
else:
   tails += 1

Inside the loop you need to "flip" on each pass.
You're "flipping" once before the start of the loop now.
wes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic coin flipper program - logical error help

2006-02-21 Thread Larry Bates
DannyB wrote:
> I'm just learning Python.  I've created a simple coin flipper program -
> here is the code:
> 
> [source]
> #Coin flipper
> import random
> 
> heads = 0
> tails = 0
> counter = 0
> 
> coin = random.randrange(2)
> 
> while (counter < 100):
> if (coin == 0):
> heads += 1
> counter += 1
> else:
> tails += 1
> counter += 1
> 
> coin = random.randrange(2)
> 
> 
> print "\nThe coin landed on heads", heads, "times."
> print "\nThe coin landed on tails", tails, "times."
> [/source]
> 
> << anyway.>>>
> 
> The program runs - however - it will give me 100 heads OR 100 tails.
> Can someone spot the logic error?  
> 
> Thanks
> 
> ~Dan
> 
Looks an awful lot like your homework, but I'll give you a clue.
You need to get the your coin tosses inside your loop.  Otherwise
you only toss the coin once and then loop 100 times with the
same value.

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


Re: Basic coin flipper program - logical error help

2006-02-21 Thread Claudio Grondi
DannyB wrote:
> I'm just learning Python.  I've created a simple coin flipper program -
> here is the code:
> 
> [source]
> #Coin flipper
> import random
> 
> heads = 0
> tails = 0
> counter = 0
> 
> while (counter < 100):

  coin = random.randrange(2)

Claudio

> if (coin == 0):
> heads += 1
> counter += 1
> else:
> tails += 1
> counter += 1
> 
> coin = random.randrange(2)
> 
> 
> print "\nThe coin landed on heads", heads, "times."
> print "\nThe coin landed on tails", tails, "times."
> [/source]
> 
> << anyway.>>>
> 
> The program runs - however - it will give me 100 heads OR 100 tails.
> Can someone spot the logic error?  
> 
> Thanks
> 
> ~Dan
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: deriving from float or int

2006-02-21 Thread gene tani

Russ wrote:
> Does it ever make sense to derive a class from a basic type such as
> float or int? Suppose, for example, that I want to create a class for
> physical scalars with units. I thought about deriving from float, then
> adding the units. I played around with it a bit, but it doesn't seem to
> work very well. Am I missing something here? Thanks.

you could look at how sciPy does it:
http://starship.python.net/~hinsen/ScientificPython/

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


Re: Basic coin flipper program - logical error help

2006-02-21 Thread John McMonagle
On Tue, 2006-02-21 at 16:14 -0800, DannyB wrote:
> I'm just learning Python.  I've created a simple coin flipper program -
> here is the code:
> 
> [source]
> #Coin flipper
> import random
> 
> heads = 0
> tails = 0
> counter = 0
> 
> coin = random.randrange(2)
> 
> while (counter < 100):
> if (coin == 0):
> heads += 1
> counter += 1
> else:
> tails += 1
> counter += 1
> 
> coin = random.randrange(2)
> 
> 
> print "\nThe coin landed on heads", heads, "times."
> print "\nThe coin landed on tails", tails, "times."
> [/source]
> 
> << anyway.>>>
> 
> The program runs - however - it will give me 100 heads OR 100 tails.
> Can someone spot the logic error?  

Yes.  Put coin = random.randrange(2) inside the while loop.

import random

heads = 0
tails = 0
counter = 0

coin = random.randrange(2)

while (counter < 100):
if (coin == 0):
heads += 1
counter += 1
else:
tails += 1
counter += 1

coin = random.randrange(2)

print "\nThe coin landed on heads", heads, "times."
print "\nThe coin landed on tails", tails, "times."


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Re: Video.

2006-02-21 Thread Dr. Pastor
Many thanks to you All.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: deriving from float or int

2006-02-21 Thread Terry Hancock
On Tue, 21 Feb 2006 15:01:22 -0600
Robert Kern <[EMAIL PROTECTED]> wrote:
> http://www.python.org/2.2.3/descrintro.html#__new__

Curiously, __new__ does not appear in the index of
the Python 2.3 language reference!

It is fixed in Python 2.4, though -- I just checked.

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

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


Basic coin flipper program - logical error help

2006-02-21 Thread DannyB
I'm just learning Python.  I've created a simple coin flipper program -
here is the code:

[source]
#Coin flipper
import random

heads = 0
tails = 0
counter = 0

coin = random.randrange(2)

while (counter < 100):
if (coin == 0):
heads += 1
counter += 1
else:
tails += 1
counter += 1

coin = random.randrange(2)


print "\nThe coin landed on heads", heads, "times."
print "\nThe coin landed on tails", tails, "times."
[/source]

<<>>

The program runs - however - it will give me 100 heads OR 100 tails.
Can someone spot the logic error?  

Thanks

~Dan

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


Re: interpreting the fractional portion of time.clock() vs time.time() measurements

2006-02-21 Thread Peter Hansen
john peter wrote:
>  
> let's say i'm taking timing measurements in Windows XP
>  
> t1 = time.clock()
> ...
> t2 = time.clock()
>  
> t3 = t2 - t1 = say, 0.018
> what is the unit of measurement for t3? is it correct to say that t3 = 
> 18 milliseconds? microseconds?
>  
> what if the timing function used for t1 and t2 was time.time()? is it 
> still correct to
> say that t3 = 18 milliseconds? i kinda know that in Windows, 
> time.clock() has
> higher resolution than time.time().  all i need is millisecond 
> resolution. which
> of these functions would be easier to translate into millisecond units 
> of measurement?

Both return seconds.  As the docs say (I believe), however, time.clock() 
is higher resolution, so you should prefer it on Windows for short 
intervals (where short is defined as well under 24 hours).

I imagine you already know how to convert seconds into milliseconds...

-Peter

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


Re: Video.

2006-02-21 Thread Peter Hansen
Sybren Stuvel wrote:
> Dr. Pastor enlightened us with:
> 
>>What environment,library,product should I import or study to
>>manipulate cameras, video, fire-wire, avi files?
> 
> 
> That depends on what you want with it. Without more information I'd
> say "transcode"

Presumably this, found easily by typing that exact word into Google: 
http://www.transcoding.org/cgi-bin/transcode


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


redirecting to a content page

2006-02-21 Thread Shreyas
I am a new user writing some scripts to store data entered via a
browser into a database.  I have several content pages, and one
"processing" page.  A content page often has a form like this:



...

And the processing page goes like this:

form = cgi.FieldStorage()
## do some work, put data into the db

The thing is, processing.py doesn't have any content that I want to
display to the user.  I would ideally like processing.py to seamlessly
send the user back to the content page that it came from, perhaps with
some parameter tweaks.

Instead, I am having to write intermediate steps like this into
processing.py:

Return to the page you came
from.

Please let me know if there's a way to do this, or if my general
approach (having such a processing page) is off.

Thanks,

Shreyas

- I did try searching for this in the archive but am not even entirely
sure what it is called...

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


With pyMinGW

2006-02-21 Thread bearophileHUGS
To use Pyrex, SWIG and the like on a Win2K I have followed this way:

http://jove.prohosting.com/iwave/ipython/pyMinGW.html

I already had MinGW 3.4.2, so I have decompressed the Python 2.4.2
sources, I have merged in the pyMinGW patch, and I have run the global
compilation with:

make -f python24.mak all

It has compiled most things, but not zlibmodule.c
It has stopped the compilation with:

c:\..\bin\dllwrap.exe: no export definition file provided.
Creating one, but that may not be what you want
make[1]: Leaving directory `/.../PyminGW/Python-2.4.2/MinGW'
make -f zlib.mak
make[1]: Entering directory `/.../PyminGW/Python-2.4.2/MinGW'
gcc.exe -c ../Modules/zlibmodule.c -o ../Modules/zlibmodule.o
-I"../Include" -I"../Pc" -I"../../../d
ist/zlib-1.2.3"  -Wall -s -DNDEBUG -D_USRDLL -O2
../Modules/zlibmodule.c:8:18: zlib.h: No such file or directory
../Modules/zlibmodule.c:66: error: syntax error before "z_stream"

... etc etc.

Anyway, probably 98% was compiled and this Python works, I have tried
the standard tests and most of them pass.
Then I have downloaded the pyMinGW Extensions V. 0.0.6.6, so zip and
other things now work.

The link to the Tcl-Tkinter extension doesn't work (the free site
hosting the file doesn't accept this file format anymore), so I cannot
use Tkinter.

I have decompressed SWIG and put it in a temporary Path.

I have then tried a basic SWIG example, (called example) coming from
this obsolete but probably still interesting page:
http://sebsauvage.net/python/mingw.html

But I have had problems durign the module creation:

C:\...\PyminGW\Python-2.4.2\MinGW>python setup.py build -cmingw32
running build
running build_ext
building 'example' extension
swigging example.i to example_wrap.c
C:\...\PyminGW\swigwin-1.3.28\swig.exe -python -o example_wrap.c
example.i
creating build
creating build\temp.win32-2.4
creating build\temp.win32-2.4\Release
C:\..\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\python24\include
-Ic:\pytho
n24\PC -c example_wrap.c -o build\temp.win32-2.4\Release\example_wrap.o
example_wrap.c: In function `My_variable_set':
example_wrap.c:2550: error: `My_variable' undeclared (first use in this
function)

... ecc.


So I have had 3 problems, maybe some of you can suggest me how to solve
some of them.

(Can the standard Python site accept to distribuite an installer with
MinGW-compiled Python + minGW + SWIG for people using Windows that want
such system prebuilt? Maybe me or another person can assemble it).

Thank you,
bearophile

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


Re: Module question

2006-02-21 Thread Gary Herron
Tuvas wrote:

>Could I just do this then?
>
>from foo import x?
>  
>
Yes, you can do it that way.  (f you have your modules importing each 
other in a circular fashion, then this can cause trouble as x may not be 
defined yet, so best to avoid that case.)

>One more question now that I've tried this. In my main function, I have
>alot of init code. I don't want this code to be re-ran when the second
>module imports the first. Is there any way around this? Thanks!
>
>  
>
It won't be run twice.  Module import is a two phase thing:

1.  Read/compile the module and run it, creating a module object.  (This 
is done only once -- the first time a module is  imported.)

2. Bind values in the importing code to the module or its attributes.  
(This is done every time a module is imported.)

So... Your init code will be executed once -- in phase 1, no matter how 
many times an import causes phase two to be performed.

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


Re: Video.

2006-02-21 Thread SPE - Stani's Python Editor
- pymedia: http://www.pymedia.org/
- pyvideo: http://www.geocities.com/rtrocca/python/ (use avisynth)
- videocapture: http://videocapture.sourceforge.net/

If you are on Mac, you probably have access to everything by pyobjc.

Good luck,
Stani
--
http://pythonide.stani.be

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


interpreting the fractional portion of time.clock() vs time.time() measurements

2006-02-21 Thread john peter
   let's say i'm taking timing measurements in Windows XP     t1 = time.clock()  ...  t2 = time.clock()     t3 = t2 - t1 = say, 0.018what is the unit of measurement for t3? is it correct to say that t3 = 18 milliseconds? microseconds?   what if the timing function used for t1 and t2 was time.time()? is it still correct to  say that t3 = 18 milliseconds? i kinda know that in Windows, time.clock() has  higher resolution than time.time().  all i need is millisecond resolution. which  of these functions would be easier to translate into millisecond units of measurement?  __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter Event Binding Double-click

2006-02-21 Thread James Stroud
Tuvas wrote:
> I am trying to execute a function with a tkinter event binding double
> click. With 2 mouse clicks done quickly, the function should happen,
> otherwise, it should not. However, I am noticing that the time that the
> event binding of a double-click is quite long, on the order of a second
> or so. I am double-clicking twice in a second, and the function is
> being executed 3 times, and not just 2. I want to know, is this
> controlled by the OS, or by Tkinter? And if by tkinter, is there a way
> to change it, and how so? Thanks!
> 

You might need to provide more info and some relevant code. I bind to 
double click all of the time and it works fine.

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


RE: Python vs. Lisp -- please explain

2006-02-21 Thread Delaney, Timothy (Tim)
Terry Reedy wrote:

>>> The the compiler is built into the VM as opposed to a separate tool
>>> (like Java) is just an implementation issue.

That was me, not Paul - careful with the attributions. Otherwise Paul
might think you were trying to ascribe some awful, inaccurate statement
to him ;)

> The presence of the exec statement and the eval function (which is
> used by the input statement) requires the runtime presence of the
> parser-compiler. Removing the latter disables the former features. 
> This is legitimite when not needed or when space is tight, but the
> result is no longer a full implementation.

True - but there's no reason that exec and eval couldn't hand off to a
python compiler to do the work. Failure to distribute the compiler would
mean then that exec and eval wouldn't work - but everything else would.

It's similar to why some projects need the JDK rather than the JRE -
they have to be able to compile things on the fly.

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


Re: Module question

2006-02-21 Thread Tuvas
Most of these are indeed independed of Tkinter, except for a status
report message that is often sent in response. I' have a few small
files already that do this, however, I would ike to be able to put
several that do in fact need to post status messages as well. There are
about 2400 lines of code in the main module right now, and about 1000
in smaller modules, but I would like to move some more, the problem is,
most of the function in my tkinter function use somehow the master tk()
variable. I don't know if there's any way around it or not, just trying
to find a way. Mine is a somewhat unusual program wherein that the
majority of the funcionality is in fact as a GUI, it mostly runs
programs from other mediums, it controls an external device, so there
isn't much in the line of real gruntwork that the program does. Thanks
for the help!

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


Re: Exiting os.spawnv's subroutine

2006-02-21 Thread IamIan
My code is below. As a single script there is no pause at the end of
the processing as there is with using os.spawnv... I am using the
P_WAIT value, and wonder if it is responsible for the extra time at the
end of each iteration. Could it take longer for the processing to be
"successful" when run under os.spawnv? Is there a way to manually send
a "success" exit code back to os.spawnv, rather than waiting for it?
Thanks.

Main script:
# Import subprocess modules
import os, sys, win32com.client

# Define arguments for subprocess
pyPath = "C:\\Python21\\python.exe"
contourScript = "C:\\Ian\\Python scripts\\subProcess2.py"
workspace = "D:\\GIS\\Test"

# Get a list of IMG files in the workspace for Contouring
filenames = os.listdir(workspace)
filenames = [filename.lower()
for filename in filenames
if (filename[-4:].lower() == ".img" and filename[0:2] != "h_" )]
for filename in filenames:

# Define filenames
print "Filename is " + filename
inImg = workspace + "\\" + filename
outContour50 = workspace + "\\contour50_" + filename[:-4] + ".shp"
outContour100 = workspace + "\\contour100_" + filename[:-4] +
".shp"
outContour200 = workspace + "\\contour200_" + filename[:-4] +
".shp"
outContour500 = workspace + "\\contour500_" + filename[:-4] +
".shp"

# Create parameter list
parameterList = []

# First parameter is the name of the Python executable
parameterList.append('python.exe')

# Second parameter is the full path of the Python script
parameterList.append(contourScript)

# The following parameters are the arguments for the Batch script
parameterList.append(inImg)
parameterList.append(outContour50)
parameterList.append(outContour100)
parameterList.append(outContour200)
parameterList.append(outContour500)

# Run subprocess
os.spawnv(os.P_WAIT, pyPath, parameterList)

print "All done!"


Secondary script:
# Import system modules
import sys, win32com.client

# Create the geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

# Confirm license availability
print "ArcInfo license is " + str(gp.CheckProduct("ArcInfo"))
gp.SetProduct("ArcInfo")
gp.CheckOutExtension("Spatial")

# Set arguments to be passed to main script
inImg = sys.argv[1]
outContour50 = sys.argv[2]
outContour100 = sys.argv[3]
outContour200 = sys.argv[4]
outContour500 = sys.argv[5]

badImgList = []

try:
# For each IMG file, contour at 50, 100, and 200 meter intervals
gp.Contour_sa(inImg, outContour50, "50", "0", "1")
print "Successfully contoured at 50 meter interval!"

gp.Contour_sa(inImg, outContour100, "100", "0", "1")
print "Successfully contoured at 100 meter interval!"

gp.Contour_sa(inImg, outContour200, "200", "0", "1")
print "Successfully contoured at 200 meter interval!"

gp.Contour_sa(inImg, outContour500, "500", "0", "1")
print "Successfully contoured at 500 meter interval!"
except:
badImgList.append(filename)
print filename + " is no good! It's been added to the list!"

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


Re: Video.

2006-02-21 Thread Dr. Pastor
Thank you Sybren.
Where is it?
Regards.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: deriving from float or int

2006-02-21 Thread Sybren Stuvel
Russ enlightened us with:
> The problem is that when I derive a new class from float, the darn
> thing won't let me create a constructor that accepts more than one
> argument.

Use __new__, not __init__. It's the function that's called when a new
immutable object is created.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Video.

2006-02-21 Thread Sybren Stuvel
Dr. Pastor enlightened us with:
> What environment,library,product should I import or study to
> manipulate cameras, video, fire-wire, avi files?

That depends on what you want with it. Without more information I'd
say "transcode"

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module question

2006-02-21 Thread Kent Johnson
Tuvas wrote:
> I know this is probably a very simple question, but I am building a
> program that is now at about 2400 lines of code in the main module. I
> need to break it up, however, there are certain variables that I would
> like to use among all of them, namely the TKinter background. It's
> build using tkinter, so, to do anything useful requires having the
> master=Tk() variable portable in every interface. I can't just pass
> this variable, the real way to do it is to have a global variable. How
> can I do this? Thanks!

You don't say what the program does, but try to identify code that does 
the actual work and put it in separate modules that implement a data 
model or business logic for the program. These modules should be 
independent of Tkinter.

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


Re: Jython Pythonpath question

2006-02-21 Thread Kent Johnson
Mark Fink wrote:
> Hi there,
> 
> I have a source file FailFixture.py in the folder
> D:\AUT_TEST\workspace\JyFIT\testutil. Now I want to import the file
> with "import testutil.FailFixture". Unfortunately I could not figure
> out how to set this up. I am convinced that
> "D:\AUT_TEST\workspace\JyFIT" should be included in the pythonpath but
> it does not work. Nor does it work to include this path in the java
> classpath. Any idea whats wrong?

Do you have a file D:\AUT_TEST\workspace\JyFIT\testutil\__init__.py ?

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


Re: Module question

2006-02-21 Thread Tuvas
Could I just do this then?

from foo import x?

One more question now that I've tried this. In my main function, I have
alot of init code. I don't want this code to be re-ran when the second
module imports the first. Is there any way around this? Thanks!

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


Video.

2006-02-21 Thread Dr. Pastor
Dear All:
(I am a 100% beginner in Python.)
What environment,library,product should I
import or study to manipulate cameras, video,
fire-wire, avi files?
Thanks you for any guidance.

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


Re: Module question

2006-02-21 Thread Mikalai
Tuvas wrote:
> I know this is probably a very simple question, but I am building a
> program that is now at about 2400 lines of code in the main module. I
> need to break it up, however, there are certain variables that I would
> like to use among all of them, namely the TKinter background. It's
> build using tkinter, so, to do anything useful requires having the
> master=Tk() variable portable in every interface. I can't just pass
> this variable, the real way to do it is to have a global variable. How
> can I do this? Thanks!

I will write an example with comments:

# say, this is a file/module foo
x = 1 # this is our variable
# end of module foo
--
# other module, where x is needed
import foo
foo.x  # here you have it
# end
--

It is all simple, but you need to have proper hierarchical import-ing.
You are splitting a file, which has a hierarchical order (count lines),
so writting proper importing is possible at least in principle.

Mikalai

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


Re: Python vs. Lisp -- please explain

2006-02-21 Thread Steven D'Aprano
On Tue, 21 Feb 2006 09:46:27 -0800, Donn Cave wrote:

> In article <[EMAIL PROTECTED]>,
>  Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> ...
>> Hey Donn, here is a compiled program for the PowerPC, 
>> or an ARM processor, or one of IBM's Big Iron 
>> mainframes. Or even a Commodore 64. What do you think 
>> the chances are that you can execute it on your 
>> x86-compatible PC? It's compiled, it should just 
>> work!!! Right?
>> 
>> No of course not. If your CPU can't interpret the 
>> machine code correctly, the fact that the code is 
>> compiled makes NO difference at all.

[snip for brevity]

> Sure, all this is true, except for the term "interpreter."
> You would surely not use the word that way, unless you
> just didn't want to communicate.

Do you honestly believe that the CPU doesn't have to interpret the machine
code, or are you just deliberately playing silly buggers with language?

In modern CPUs, there is an intermediate layer of micro-code between the
machine code your C compiler generates and the actual instructions
executed in hardware. But even if we limit ourselves to obsolete hardware
without micro-code, I ask you think about what an interpreter does, and
what the CPU does, in the most general way possible.

Both take a stream of instructions. Both have to take each instruction,
and execute it. In both cases the link between the instruction and the
effect is indirect: for example, the machine code 0101 on the 
Zilog Z80 processor causes the CPU to decrement the B processor register.
In assembly language this would be written as DEC B. There is absolutely
nothing fundamental about the byte value 5 that inherently means
"decrement B processor register".

In other words, machine language is a language, just like it says, and
like all languages, it must be interpreted.

> Your paragraph above that starts with "No of course not",
> even omits a point that everyone understands, you can in
> fact expect a .py file will work independent of machine
> architecture - like any interpreted language.

Amazing. In your previous post you were telling everybody how the
*disadvantage* of interpreted programs is that they won't run unless the
interpreter is present, and in this post you are telling us that
interpreted languages will just work. What happened to the requirement for
an interpreter?

Let's see you run that Python program on a Zilog Z80 without a Python
interpreter. Can't be done. No interpreter, whether in hardware or
software, and the program won't run, whether in source code or byte code
or machine code.

If I allow that the machines have an interpreter, perhaps you'll return
the favour and install an interpreter for machine language (often called
an emulator). Now your compiled C or Lisp code also will run independent
of machine architecture.

In order to force "interpreted language" and "compiled language" into two
distinct categories, rather than just two overlapping extremes of a single
unified category, you have to ignore reality. You ignore interpreted
languages that are compiled, you ignore the reality of how machine code is
used in the CPU, you ignore the existence of emulators, and you ignore
virtual machines.


> We all know
> what native code compilation buys you and what it doesn't.

Did you fail to learn *anything* from my parable of interpreted Lisp on a
Macintosh II running faster than compiled Lisp running on a Mac II fitted
with a Lisp processor?


-- 
Steven

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


Module question

2006-02-21 Thread Tuvas
I know this is probably a very simple question, but I am building a
program that is now at about 2400 lines of code in the main module. I
need to break it up, however, there are certain variables that I would
like to use among all of them, namely the TKinter background. It's
build using tkinter, so, to do anything useful requires having the
master=Tk() variable portable in every interface. I can't just pass
this variable, the real way to do it is to have a global variable. How
can I do this? Thanks!

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


Re: number ranges

2006-02-21 Thread Tim Hochberg

[Lots of proposals snipped]

90% of my gripes with range disappeared with the addition of enumerate. 
However, if there's going to be another round of range literal proposals 
I might as well throw out what seems (to me anyway) like the only 
halfway obvious choice in the context of Python.

1. a:b:c is equivalent to slice(a,b,c) with the usual rules that missing 
values are mapped to None: Parentheses would be required where this 
construct would otherwise be ambiguous.

2. slice(a,b,c) grows an __iter__ method that returns a generator that 
produces an appropriate sequence of integers. This is easy to define for 
positive steps, but tricky for negative steps (more on that in a second).

Thus:

for i in (1::2): print i,
=> 1 3 5 ...

and

for i in (:10:3): print i,
=> 0 3 6 9


The tricky part is deciding what to with negative steps when the start 
is undefined. It's tempting to use 0 as the start, but I think -1 is 
actually better if slightly odd. The reason is that I think the 
following invariant should hold.

newlist = []
for i in someslice:
 try:
 newlist.append(origlist[i])
 except IndexError:
 break
assert(newlist == origlist[slice])

For that to work out, you want:

for i in (::-2): print i,
=> -1 -3 -5 ...

etc. I realize that this is quite similar to the rejected PEP 204 
syntax, but the addition of generators has reduced many of the problems 
that that PEP had.

I have no great need for range literals, but it seems that if there were 
to be one, one that fit together with the existing syntax would be 
better than making up something new.

-tim






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


Re: jython socket sendall

2006-02-21 Thread Mark Fink
I used send instead. This should work.
-Mark

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


Re: Python vs. Lisp -- please explain

2006-02-21 Thread Pietro Campesato
> As they say, case is the difference between "I helped my
> Uncle Jack off a horse" and "I helped my uncle jack off a horse."

Hahaha!... never heard of that though

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


Re: why does close() fail miserably on popen with exit code -1 ?!

2006-02-21 Thread Atanas Banov
Jeffrey Schwab wrote:
> _PyPclose returns the exit status of the popened process (the popenee?),
> or -1 on error.  Of course, if the status is supposed to be -1, there's
> some confusion.

yes, that's what i thought the root of the problem is.

> In the snippet of code below (from Modules/posixmodule.c), result has
> been initialized to the output of fclose, which in your case is 0.  The
> comment is particularly handy.
>
...
>   /* Indicate failure - this will cause the file object
>* to raise an I/O error and translate the last
>* error code from errno.  We do have a problem with
>* last errors that overlap the normal errno table,
>* but that's a consistent problem with the file object.
>*/

the piece you quoted is from the unix #ifdef part, i think. there is
another version of the pypclose for windows below that.

in any event i think such behaviour is a bug - just because in unix
exit codes are limited to 0..255 (and returned multiplied by 256)
doesnt mean other OSes should suffer because of design flow in
_PyPclose, right?

throwing an IOError "no error" doesnt help.

is there a bug database for python where i can check if this was
discussed?

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


Jython Pythonpath question

2006-02-21 Thread Mark Fink
Hi there,

I have a source file FailFixture.py in the folder
D:\AUT_TEST\workspace\JyFIT\testutil. Now I want to import the file
with "import testutil.FailFixture". Unfortunately I could not figure
out how to set this up. I am convinced that
"D:\AUT_TEST\workspace\JyFIT" should be included in the pythonpath but
it does not work. Nor does it work to include this path in the java
classpath. Any idea whats wrong?

I experiented a little at the Jython prompt:

D:\AUT_TEST>java -Dpython.home=D:\AUT_TEST\Jython21
-Dpython.path=D:\AUT_TEST\workspace\JyFIT -classpath
D:\AUT_TEST\Jython21\jython.jar;D:\AUT_TEST\JavaLib\log4j-1.2.13.jar;D:\AUT_TEST\workspace\JyFIT
org.python.util.jython

Jython 2.1 on java1.5.0_06 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import testutil.FailFixture
Traceback (innermost last):
  File "", line 1, in ?
ImportError: No module named FailFixture
>>> ^Z

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


Re: Zope/Plone - Is it the right solution?

2006-02-21 Thread Bruno Desthuilliers
kbperry a écrit :
> Well,
> I guess our main goal in this class is to improve usability and user
> experiences at the site.
> 
> While we want to improve our site visually and make it more usable to
> the prospective students, the site needs to be easily updated.  I don't
> think that I am looking for a wiki.

Don't overlook this solution. A wiki can be made good-looking, and you 
just can't beat it when it comes to ease of use for non-technical 
persons (and for technical persons too...). Modern wikis like MoinMoin 
or the Wiki part of Trac are also very extensibles.

For the record, for our own extranet, we're actually switching from CPS 
(a very-close-to-Plone CMF) to... Trac - there's not even a subversion 
repository around, but we use the Wiki/Ticket/Roadmap combo to manage 
our current projects.

Now Plone is a pretty good CMS for Portal-like sites, so it may be what 
you're looking for...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number ranges

2006-02-21 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes:
> > for i in (1 to 10 by 3):
> >  print i
> > 
> > should print 1 4 7.
> 
> But that would be an "attractive nuisance" to many other native speakers
> like you, who would instinctively think of a closed interval.  Maybe
> 'upto' rather than 'to', as somebody else suggested, would ease that.

I don't think "upto" is any better.  Any distinction that might exist
between "to" and "upto" doesn't jump out at me.

I notice that Haskell uses closed intervals: [1..5] means [1,2,3,4,5].
Is that an error by Haskell's designers?  One possibility is that those
intervals don't actually get used in ways likely to cause one-off errors.
I haven't used Haskell enough to have any sense of this.

Here's something ugly but explicit, somewhat Haskell-inspired:

   (1 .. )# infinite generator, like Haskell
   (1 .. < 10)   # semi-closed interval: 1,2,3...,9
   (1 .. <= 10)  # closed interval: 1,2,3...,10
   (1,4 .. < 10)  # semi-closed: 1,4,7
   (1,4, .. <= 10)  # closed: 1,4,7,10

This would be horrible for Python though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: deriving from float or int

2006-02-21 Thread Robert Kern
Russ wrote:
> The problem is that when I derive a new class from float, the darn
> thing won't let me create a constructor that accepts more than one
> argument. I need two arguments: one for the numerical value and one for
> the units. But when I try to give the constructor two arguments, I get
> this when I call the constructor:
> 
> TypeError: float() takes at most 1 argument (2 given)
> 
> In other words, python doesn't seem to want to let me "extend" the
> float type. I don't understand the reason for that, but I assume there
> is a reason.

http://www.python.org/2.2.3/descrintro.html#__new__

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: deriving from float or int

2006-02-21 Thread Russ
The problem is that when I derive a new class from float, the darn
thing won't let me create a constructor that accepts more than one
argument. I need two arguments: one for the numerical value and one for
the units. But when I try to give the constructor two arguments, I get
this when I call the constructor:

TypeError: float() takes at most 1 argument (2 given)

In other words, python doesn't seem to want to let me "extend" the
float type. I don't understand the reason for that, but I assume there
is a reason.

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


Tkinter Event Binding Double-click

2006-02-21 Thread Tuvas
I am trying to execute a function with a tkinter event binding double
click. With 2 mouse clicks done quickly, the function should happen,
otherwise, it should not. However, I am noticing that the time that the
event binding of a double-click is quite long, on the order of a second
or so. I am double-clicking twice in a second, and the function is
being executed 3 times, and not just 2. I want to know, is this
controlled by the OS, or by Tkinter? And if by tkinter, is there a way
to change it, and how so? Thanks!

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


Re: In need of a virtual filesystem / archive

2006-02-21 Thread Enigma Curry
Thanks for all the suggestions!

I realized a few minutes after I posted that a database would work.. I
just wasn't in that "mode" of thinking when I posted.

PyTables also looks very interesting, especially because apparently I
can read a file in the archive like a normal python file, ie one line
at a time.

Could I do the same using SQL? I'm assuming I would get the whole file
back when I did my SELECT statement. I guess I could chunk the file out
and store it in multiple rows, but that sounds complicated.

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


Re: That's really high-level: bits of beautiful python

2006-02-21 Thread Rocco Moretti
Max wrote:

> But today we were discussing the problem of running externally-provided 
> code (e.g. add-on modules). Neither of us knew how to do it in C, though 
> I suggested using DLLs. However, I quickly installed python on his 
> laptop and coded this:
> 
> exec "import %s as ext_mod" % raw_input("Module: ")
> ext_mod.do()

Be careful with this - its fine for developer only use, but I'd avoid it 
in production code. You leave the possibility for hackers to try to 
import the module named 'os; os.system('rm -rf /'); import', or other 
such deviousness.

Probably a better version:

ext_mod_name = raw_input("Module: ")
ext_mod = __import__(ext_mod_name, globals(), locals(), ['__dict__'])
ext_mod.do()

But granted, it's less cool than the original.

P.S. The ", globals(), locals(), ['__dict__']" is there so that the 
proper thing is done when you provide the code with a dotted module name.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-21 Thread Steve Holden
Chris Mellon wrote:
[...]
> Torstens definition isn't useful for quantifying a difference between
> interpeted and compiled - it's a rough sort of feel-test. It's like
> how much of a naked body you can expose before before it changes from
> art to pornography - it's not something that is easily quantified.
> 
[...]

Possibly, but if your aim is exposing as much flesh as possible without 
being labeled pornography I think I'd conclude you were in the 
pornography business from the start, albeit masquerading as an "art dealer".

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Mutable numbers

2006-02-21 Thread Magnus Lycka
Suresh Jeevanandam wrote:
> # I am new to python.
[...]
> In any application most of the operation is numerical. So, i think, we 
> should get a good speed advantage with the availability of mutable 
> numbers. What do you think ?

If you are new to Python, I think you should try to learn how to
use it well, and rest assured that the smart people who have been
working on it for 15 years have done a pretty good job at making
it perform well, with respect to the basic design decisions.

Runtime performance has never been the prime goal for Python. It's
always been more important with clarity, easy of use and programmer
productivity. CPUs get faster and faster, but programmers don't get
smarter and smarter...

Still, it's quite possible to write very capable programs in Python.
For intense number crunching, it's often helpful to use some good
library written in C though, whether it's NumPy or some cryptographic
library.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No

2006-02-21 Thread Gaz
Aye, but the file is in MY drive, not the server. Perhaps  thats the
issue? I bet it's so... how should i deal with it? Perhaps should be a
script that uploads the files to the server and then emails it... i
believed this was handled using the root in my PC, but now i see this
is not correct.

Now i need a script for uploading the files from MY pc and then use the
sendmail thingie. Any tips about that script?

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


Re: Zope/Plone - Is it the right solution?

2006-02-21 Thread kbperry
Rene and Tim,
Thanks for the help!  I am glad that I didn't rule out Plone yet
because I was able to download and install quickly.  My "site" was up
and running very quickly.

For this class we are more focused on the HCI/usability stuff than we
are the coding.  I have plenty of other classes that focus on the
coding.  I am hoping that we could build an extension or two using
python (if needed), and I would like to completely redesign the main
"skin," but other than that I need the CMS tool so Plone looks like a
great fit.

I tried installing Zope last night, but when I did, I couldn't find out
how to even start it for about an hour after searching.  I was worried
that if I went the Plone/Zope route, then I would need to know both.
It looks like Plone just makes Zope much easier to work with.

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


Re: No

2006-02-21 Thread Steve Holden
Fredrik Lundh wrote:
> "Gaz" wrote:
> 
> 
>>OSError: [Errno 2] No such file or directory: 'c:/'
>>  args = (2, 'No such file or directory')
>>  errno = 2
>>  filename = 'c:/'
>>  strerror = 'No such file or directory'
>>
>>Crazy... and if i use c:\, i get a 500 error.
> 
> 
> that's probably because "c:\" is a syntax error:
> 
> 
"c:\"
> 
>   File "", line 1
> "c:\"
> ^
> SyntaxError: EOL while scanning single-quoted string
> 
> but since you're getting a "500 error" instead, it sure sounds like you
> forgot to tell us *how* you're running your scripts... (server, platform,
> python version, etc).
> 
The 500 error's almost certainly because the script is failing before it 
emits anything on standard output (I'm presuming that the syntax error 
will appear on standard error, without having checked ...).

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: editor for Python on Linux

2006-02-21 Thread Szabolcs Nagy
pida is a great ide as well:
http://pida.vm.bytemark.co.uk/projects/pida

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


Re: message

2006-02-21 Thread Steve Holden
Nina Almaguer wrote:
> Hi,
> We are a web integration firm in Reston, VA and would like to post the 
> following developer position (I have already joined the group).
>  
>  
> 
> When you begin your career at Siteworx, you’ll be part of a rapidly 
> growing software and services company. In fact, you have probably 
> visited some of our web applications and sites already – many are for 
> companies with household names. It’s this kind of success that creates 
> exceptional opportunities for ambitious people. If you’re looking for a 
> place where you can perform your best, consider the following position 
> in our Reston, Virginia headquarters:
> 
>  
> 
> Software Developer
> 
>  
> 
> You will develop Internet applications in teams from Siteworx 
> specifications. You will work closely with many Senior Developers to 
> improve your knowledge and technical prowess.  Siteworx has very high 
> standards and understands that very few people are qualified to do what 
> we do upon hiring, however, the position requires a BA/BS in a technical 
> field and 1+ years experience (internships applicable) in software 
> development.  Fluency with three or more of following is necessary: 
> XHTML, CSS, C/C++, Javascript, Java, Python, XSLT.  A background in 
> Object Oriented Programming is necessary and familiarity with Zope is a 
> major plus.
> 
Nina:

See http://www.python.org/Jobs-howto.html

for how to get this on the python.org web site.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: RSA in python

2006-02-21 Thread Heikki Toivonen
Abhisek Datta wrote:
> -BEGIN RSA PUBLIC KEY-
> MIGJAoGBALxi3tGXlSwRgn7/Km6mTSge+5ijQgIn3GvnZOeYyOo1DkubVtTaFj26
> GWtJo43MEe1a5UlWKJEOpbKVCr4AASfFj8YmmRewH4SXdZ+w1Bad8amyzL2h8F7J
> wJojOnocSs6xDE7o86CpZRUlojBefanMdCpu074QFktE63OD1zBBAgMBAAE=
> -END RSA PUBLIC KEY-
> 
> Traceback (most recent call last):
[...]
> M2Crypto.RSA.RSAError: no start line

The files in M2Crypto tests directory don't have any files that have
"BEGIN RSA PUBLIC KEY" in them - haven't checked if this is legal or not.

However, plain OpenSSL does not like that file either:

$ openssl rsa -in rsa_heikki.pem -pubin
3440:error:0906D06C:PEM routines:PEM_read_bio:no
startline:pem_lib.c:644:Expecting: PUBLIC KEY

$ openssl rsa -in rsa_heikki.pem -check
2140:error:0906D06C:PEM routines:PEM_read_bio:no
startline:pem_lib.c:644:Expecting: ANY PRIVATE KEY

If I take out the "RSA " part from the delimiter lines I get:

$ openssl rsa -in rsa_heikki2.pem -pubin
unable to load Public Key
3124:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong
tag:tasn_dec.c:
1282:
3124:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1
error:ta
sn_dec.c:374:Type=X509_ALGOR
3124:error:0D08303A:asn1 encoding
routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 e
rror:tasn_dec.c:743:Field=algor, Type=X509_PUBKEY
3124:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:pem_oth.c:83:

$ openssl rsa -in rsa_heikki2.pem -check
unable to load Private Key
2304:error:0906D06C:PEM routines:PEM_read_bio:no start
line:pem_lib.c:644:Expect
ing: ANY PRIVATE KEY


My suggestion would be to ask on the openssl-users list.

-- 
  Heikki Toivonen




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

Re: warning for google api users

2006-02-21 Thread Doug Bromley
Producing a SERPS scraper for Google would be very easy and possible in about 10-15 lines of code.  However, its against the Google terms of service and if they decide to bite you for breaching them then you'll be in trouble.  Its also a reason you'll not likely find one that trumpets its existence very much as the site promoting it would probably be taken off the Google index - severely effecting visitors.
On 2/21/06, Gabriel B. <[EMAIL PROTECTED]> wrote:
the google webservices (aka google API) is not even close for any kindof real use yetif you search for the same term 10 times, you get 3 mixed totals. 2mixed result order. and one or two "502 bad gateway"
i did an extensive match agains the API and the regular searchservice. the most average set of results:results 1-10; total: 373000results 11-20; total: 151000results 21-30; total: 151000results 31-40; total: 373000
results 41-50; total: 373000results 51-60; total: 373000results 61-70; total: 151000( 502 bad gateway. retry)results 71-80; total: 373000results 81-90; total: 151000( 502 bad gateway. retry)
results 91-100; total: 373000on the regular google search, total:  2,050,000 (for every page, ofcourse)besides that, the first and third result on the regular google search,does not apear in the 100 results from the API in this query, but this
is not average, more like 1 chance in 10 :-/So, no matter how much google insists that this parrot is sleeping,it's simply dead.now, what i presume that is happening, is that they have a dozen of
machine pools, and each one has a broken snapshot of the productionindex (probably they have some process to import the index and or itexplode in some point or they simply kill it after some time). andthey obviously don't run that process very often.
Now... anyone has some implementation of pygoogle.py that scraps theregular html service instead of using SOAP? :)Gabriel B.--http://mail.python.org/mailman/listinfo/python-list

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

Re: Zope 3?? How do you start it on Windows?

2006-02-21 Thread kbperry
Many good points!  Thx Matt.

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


Re: algorithm, optimization, or other problem?

2006-02-21 Thread Jesus Rivero (Neurogeek)
Hello,

If the parameters that are received by functions in order to calculate
weights, th's and dot's products , are equal to each other in different
cycles (and i bet more than often they will) i suggest you replace those
functions with memoizable functions. That also would ease work inside
the loop. Take into account other suggestions people have made and
review memoization in Python.


Regards.

Jesus (Neurogeek)







Bas wrote:

>Hi,
>
>as the others have already said, move all the invariants out of the
>loop. It is also not useful to randomly draw a vector out of random
>array. Some other small things:
>
>for i in range(len(x)): do something with x[i]
>should probably be replaced by
>for xi in x: do something with xi
>this saves an array index operation, don't know if this works for a
>numeric array
>
>You use the y**2 twice. A good compiler might notice this, but Python
>is interpreted...
>
>use += instead of + for w, the calculation can be done in place, this
>might save the creation of a new array/variable
>
>I am not sure what you are doing with x, bit it seems that you are
>transposing it a few times to many. Mightbe you can declare x as the
>transpose of what you do now, thereby saving the transpose in the loop?
>
>so my guess (not tested):
>
>x=random((1000,100))# 1000 input vectors,  declared differently
>for xx in x:
> y=dot(xx,w)
> y2 = y*y
> w+=ETA*(y*xx-y2*w);
> th+= INV_TAU*(y2-th); 
>
>
>Hope it helps,
>Bas
>
>  
>

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


Re: Augmented assignment

2006-02-21 Thread gene tani

Terry Hancock wrote:
> On Tue, 21 Feb 2006 10:55:42 +0530
> Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:

> Seriously,
> I think they are usually equivalent internally,
> at least for immutable objects.
>

yah, but when you do augmented assigns on lists, or mix immutable an
dmutable:

http://zephyrfalcon.org/labs/python_pitfalls.html

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


warning for google api users

2006-02-21 Thread Gabriel B.
the google webservices (aka google API) is not even close for any kind
of real use yet

if you search for the same term 10 times, you get 3 mixed totals. 2
mixed result order. and one or two "502 bad gateway"

i did an extensive match agains the API and the regular search
service. the most average set of results:

results 1-10; total: 373000
results 11-20; total: 151000
results 21-30; total: 151000
results 31-40; total: 373000
results 41-50; total: 373000
results 51-60; total: 373000
results 61-70; total: 151000
( 502 bad gateway. retry)
results 71-80; total: 373000
results 81-90; total: 151000
( 502 bad gateway. retry)
results 91-100; total: 373000

on the regular google search, total:  2,050,000 (for every page, of
course)

besides that, the first and third result on the regular google search,
does not apear in the 100 results from the API in this query, but this
is not average, more like 1 chance in 10 :-/

So, no matter how much google insists that this parrot is sleeping,
it's simply dead.


now, what i presume that is happening, is that they have a dozen of
machine pools, and each one has a broken snapshot of the production
index (probably they have some process to import the index and or it
explode in some point or they simply kill it after some time). and
they obviously don't run that process very often.

Now... anyone has some implementation of pygoogle.py that scraps the
regular html service instead of using SOAP? :)

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


That's really high-level: bits of beautiful python

2006-02-21 Thread Max
I have a friend who has been programming in C for many years, and he is 
a great fan of the language. However, he (and I) are about to start a 
python course, and he has been asking me a lot of questions. He often 
responds to my answers with "Urgh! Object-orientation!" and suchlike.

But today we were discussing the problem of running externally-provided 
code (e.g. add-on modules). Neither of us knew how to do it in C, though 
I suggested using DLLs. However, I quickly installed python on his 
laptop and coded this:

exec "import %s as ext_mod" % raw_input("Module: ")
ext_mod.do()

And created to sample modules with do() functions to demonstrate. He was 
impressed ("That's really high-level" were his words).

I was just thinking perhaps we should create some kind of collection of 
bits of "impressive" code like this.

He also liked 99 Bottles in one line:

print '\n'.join(["%d bottles of beer on the wall." % i for i in 
range(100,0,-1)])

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


Re: Zope 3?? How do you start it on Windows?

2006-02-21 Thread Magnus Lycka
kbperry wrote:
> Cool thx Matt.  I did finally figure it out, but barely.  Why would you
> want to download and install Zope without creating an instance?  It
> seems kind of dumb to me.

This is a quite normal separation. I think you will find the same
thing among both database systems and various web tool kits. Some
database systems do create an instance on installation, but that's
because those database systems need one main systems database per
install to adminster the other databases. Whether it's Oracle, Zope
or Django, you can have many instances running in one installation.

I installed Trac yesterday. It worked just the same way.

In settings with more than just a few developers, it's quite normal
that system admins install software products such as Zope, while
software developers create Zope instances. Why on earth would you
force the sysadmin to make a Zope instance? He doesn't need one!
The developer probably doesn't have root access, and it isn't his
job to install third party s/w.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Little tool - but very big size... :-(

2006-02-21 Thread Peter Hansen
Larry Bates wrote:
> Since the target is Windows only, consider using win32gui
> (part of Mark Hammonds win32 extensions) calls to use
> native Windows controls.  That way you can eliminate
> wxWindows altogether.  If all you need is a file dialog,
> it isn't very difficult.

A good point, and one the developer of Venster thought of as well, since 
he's already done much of this work (and without even requiring 
win32gui, as he went through the lighter-weight ctypes). 
http://venster.sourceforge.net/htdocs/index.html

(I haven't tried using this myself, but there's an 800K example of a 
Windows GUI app included on that page for download.)

-Peter

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


Re: Writing my own typing monitor program for RSI sufferers...

2006-02-21 Thread samslists
Well, this is the one part that I have no idea how to doas far as I
can tell the information simply is not in /proc.  I need a different
method to discover when someone is typing.  That's what I came to the
list for, to get a clue as to how to do that.

Certainly someone has an idea how to detect typing on a usb keyboard
under pythonsome external library must exist?

Thanks

p.s. Diez...I'll read that over, and will look forward to seeing what
you come up with.  Please email me to let me know..I suspect that
your approach will require kernel modifications I don't want to go
down that path.  I'd be okay with it once, cut the last thing I want to
do is repatch my ubuntu kernel every time there was a security fix.

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


Re: Augmented assignment

2006-02-21 Thread Terry Hancock
On Tue, 21 Feb 2006 10:55:42 +0530
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
>   Is there any gain in performance because of
>   augmented assignments.
> 
>   x += 1  vs x = x+1

Yep. I perform better when I only type names once.
Especially if they are long:

length_of_object_I_must_describe_very_carefully += 1

vs

length_of_object_I_must_describe_very_carefully = 
length_of_object_I_must_describe_very_carefully + 1

Oh, you mean performance of the computer? ;-)

But Python is all about optimizing the
performance of programmers, not computers!

Seriously,
I think they are usually equivalent internally,
at least for immutable objects.

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

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


Re: Is there a way to build python without 'posixmodule' ?

2006-02-21 Thread Ross Ridge

mrstephengross wrote:
> I'm working on building python 2.4.2 with the mingw compiler (on
> cygwin).

Try following the instructions on the pyMinGW site:

http://jove.prohosting.com/iwave/ipython/pyMinGW.html

 Ross Ridge

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


Re: Multiple assignment and the expression on the right side

2006-02-21 Thread Terry Hancock
On Tue, 21 Feb 2006 10:53:21 +0530
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
>   I read in "Python in a Nutshell" that when we have
>   multiple assignments 
> made on a single line, it is equivalent to have those many
> simple  assignments and that the right side is evaluated
> once for each  assignment. [The wordings are mine. I am
> not sure if this is what he  intended].

>  >>> c = d = e = x()

AFAIK, this is equivalent to this:

e = x()
d = e
c = d

So, in fact, what you say is true, but these, of course will
not evaluate x multiple times.

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

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


Re: Little tool - but very big size... :-(

2006-02-21 Thread BJ in Texas
[EMAIL PROTECTED] wrote:
|| 11MB is seldom a concern for today's machine.
||

A good windows/microsoft attitude.. :-)


-- 
"Last week, I stated this woman was the ugliest woman I had ever
seen. I have since been visited by her sister, and now wish to
withdraw that statement." -- Mark Twain


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


Re: Zope/Plone - Is it the right solution?

2006-02-21 Thread Tim Williams (gmail)
On 21 Feb 2006 08:00:03 -0800, Michele Simionato <[EMAIL PROTECTED]> wrote:
For easy of use nothing beats CherryPy, but I am not sure how stable itis.
If CherryPy is of interest then don't discount Karrigell,  it has
a smaller learning curve and appears stable.   Overall I
found it quicker to become productive than with CP.    

see   http://quentel.python-hosting.com/wiki/index.pih  and  http://karrigell.sourceforge.net/

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

Re: html parser , unexpected '<' char in declaration

2006-02-21 Thread Jesus Rivero (Neurogeek)
Oopss!

You are totally right guys, i did miss the closing '>' thinking about
maybe errors in the use of ' or ".

Jesus

Tim Roberts wrote:

>"Jesus Rivero - (Neurogeek)" <[EMAIL PROTECTED]> wrote:
>  
>
>>hmmm, that's kind of different issue then.
>>
>>I can guess, from the error you pasted earlier, that the problem shown
>>is due to the fact Python is interpreting a "<" as an expression and not
>>as a char. review your code or try to figure out the exact input you're
>>receving within the mta.
>>
>>
>
>Well, Jesus, you are 0 for 2.  Sakcee pointed out what the exact problem
>was in his original message.  The HTML he is being given is ill-formed; the
> tag
>which it thinks is inside the 
>  
>
>>>well probabbly I should explain more.  this is part of an email . after
>>>the mta delivers the email, it is stored in a local dir.
>>>After that the email is being parsed by the parser inside an web based
>>>imap client at display time.
>>>
>>>I dont think I have the choice of rewriting the message!? and I dont
>>>want to reject the message alltogether.
>>>
>>>I can either 1-fix the incoming html by tidying it up
>>>or 2- strip only plain text out and dispaly that you have spam, 3 - or
>>>ignore that mal-formatted tag and display the rest
>>>  
>>>
>
>If this is happening with more than one message, you could check for it
>rather easily with a regular expression, or even just ''.find, and then
>either insert a closing '>' or delete everything up to the  before
>parsing it.
>  
>

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


Re: Zope/Plone - Is it the right solution?

2006-02-21 Thread Tim Parkin
Fredrik Lundh wrote:
> "kbperry" wrote:
>>I am currently a student, and for our HCI class project we are
>>redeveloping our CS website.  I attend a very large university (around
>>30,000 students), and the CS site will need to be updated by many
>>people that don't have technical skills (like clerical staff).
>>
>>The biggest problem with the current site is that not enough people
>>have access to update it.  Since I love python, these seemed like
>>viable solutions.
>>
>>1)  Is Zope/Plone overkill for this type of project?
>>
>>2)  Why use Plone vs. straight up Zope?
>>
>>3)  Is there a way to get over the steep learning curves (that I have
>>read about)?
> 
> do you want to build a web application, use a ready-made CMS, or is the goal 
> to
> easily get lots of information on to the (intra)web ?
> 
> if the latter, a modern wiki with good access control could be worth 
> investigating:
> 
> http://moinmoin.wikiwikiweb.de/
> http://moinmoin.wikiwikiweb.de/HelpOnAccessControlLists
> 
> (for performance, you may want to run the wiki behind mod_proxy)
> 
> if you want a ready-made content management system, pick Plone.

I'd heartily agree with Fredrik on this.. If you just want to manage a
set of interlinked documents (i.e. content oriented web pages) then a
wiki will get you going and contributors updating stuff faster than
pretty much anything going.

Plone will give you more structure (allow you to create your own types
of conten or object e.g. courses, buildings, whatever) with more effort
and more maintenance.

Rolling your own with any framework out there will inevitably give you
the most flexibility (you can do pretty much what you want) traded off
against a lot larger investment in time at the start and ongoing.

If you want it to be a project, there isn't much to get your teeth into
in creating a wiki based site (you can write you own modules and
plug-ins I suppose). Plone/Zope3 would challenge you more and you'd have
a chance to learn some different approaches to common cs problems.

If I were to recommend based on you wanting a project, I'd say zope3. If
it's based on getting some content up and editable quickly then I'd say
wiki. If you're aiming for a structured website to handle some of the
typical course info (handling events, rooms, dates, etc) I'd recommend
plone.

Tim Parkin

p.s. The steep learning curve should only be if you want to do something
to 'extend' the plone/zope system. As long as you are happy with the
defaults for common components you shouldn't have too much to learn.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >