Re: Is there a commas-in-between idiom?

2006-11-09 Thread Peter van Kampen
On 2006-11-08, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> At Wednesday 8/11/2006 16:51, Peter van Kampen wrote:
>
>>"""
>>A = B = [] # both names will point to the same list
>>"""
>>
>>I've been bitten by this once or twice in the past, but I have always
>>wondered what it was useful for? Can anybody enlighten me?
>
> As an optimization, inside a method, you can bind an instance 
> attribute and a local name to the same object:
>
>  def some_action(self):
>  self.items = items = []
>  // following many references to self.items,
>  // but using items instead.
>
> Names in the local namespace are resolved at compile time, so using 
> items is a lot faster than looking for "items" inside self's 
> namespace each time it's used.

Nice example.

Thanks,

PterK

-- 
Peter van Kampen
pterk -- at -- datatailors.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a commas-in-between idiom?

2006-11-09 Thread Peter van Kampen
On 2006-11-08, Georg Brandl <[EMAIL PROTECTED]> wrote:
> Peter van Kampen schrieb:
>> On 2006-11-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>>> I've collected a bunch of list pydioms and other notes here:
>>>
>>> http://effbot.org/zone/python-list.htm
>> 
>> """
>> A = B = [] # both names will point to the same list
>> """
>> 
>> I've been bitten by this once or twice in the past, but I have always
>> wondered what it was useful for? Can anybody enlighten me?
>
> Do you never have a situation where you want to assign the same value
> to two variables?

In the sense that I might want two empty lists or maybe 2 ints that
are initialised as 0 (zero). That's what I (incorrectly) thought A = B
= [] did.

> Or are you objecting to the fact that both names point to the same
> object?

I'm not objecting to anything, merely wondering when I could/should
use this idiom. There's a nice example in another response (self.items
= items = [])

> It couldn't be otherwise. Consider:
>
> X = []
> A = B = X
>
> What should this do? Copy "X" and assign one copy to A, one to B?

Ah yes, I see the error in my ways...I skipped the A = B part too
lightly.

Thanks,

PterK


-- 
Peter van Kampen
pterk -- at -- datatailors.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a commas-in-between idiom?

2006-11-08 Thread Peter van Kampen
On 2006-11-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> I've collected a bunch of list pydioms and other notes here:
>
> http://effbot.org/zone/python-list.htm

"""
A = B = [] # both names will point to the same list
"""

I've been bitten by this once or twice in the past, but I have always
wondered what it was useful for? Can anybody enlighten me?

TIA,

PterK

-- 
Peter van Kampen
pterk -- at -- datatailors.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache & Python 500 Error

2005-02-03 Thread Peter van Kampen
On 2005-02-02, Christian <[EMAIL PROTECTED]> wrote:
> Hello,
>
> i have an apache 1.3 server with python on debian. Python works fine but 
>   the scripts wont´t work.
>
> This easy script i want to do on apache:
>
> #!/usr/bin/python
> import os
> os.getcwd()
>
> in apache config i have done this:
>
>
>  AddHandler python-program .py
>  PythonHandler python
>  Order allow,deny
>  Allow from all
>  #PythonDebug On
>
>
> the script is in this directory /var/www/python
>
> but i get an 500 error everytime, with "every" script 

You're confusing mod_python and cgi. And you're cgi isn't written
properly...

Try this to enable cgi for python files:


Options +ExecCGI
AddHandler cgi-script py


Don't forget to restart apache.

A proper cgi-file outputs a header with at least the content-type. A
header is followed by an empty line.

#!/usr/bin/env python

import os

print "Content-type: text/html"
print
print os.getcwd()

--
Peter van Kampen
pterk -- at -- datatailors.com
-- 
http://mail.python.org/mailman/listinfo/python-list