Re: Immutable object thread-safety

2008-10-27 Thread Gabriel Genellina
En Sun, 26 Oct 2008 23:25:09 -0200, Alcari The Mad  
<[EMAIL PROTECTED]> escribió:



I am confused about which data structure to rely on thread-safety, or
operator in Python?

All of the builtin functions(which are implemented in C, like len()) are
atomic(but assigning their output to a value may not be).


You can't count on the builtins being atomic. len(x) executes  
type(x).__len__ if such method exists, which may execute arbitrary Python  
code, even trigger the garbage collector and run absolutely unrelated  
things.
See this effbot page for discussion [1] - but in general, since the  
language reference doesn't specify whether an operation is atomic or not,  
you should not count on it. Use a lock when required.


[1]  
http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm


--
Gabriel Genellina

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


Re: Improving interpreter startup speed

2008-10-27 Thread David Cournapeau
On Mon, Oct 27, 2008 at 2:36 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> It this a theoretical problem or an actual one, that we might have other
> suggestions for?

Any command line based on python is a real example of that problem.
There are plenty of them.

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


Re: Improving interpreter startup speed

2008-10-27 Thread James Mills
On Mon, Oct 27, 2008 at 3:36 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:
> It this a theoretical problem or an actual one, that we might have other
> suggestions for?

Heaven knows! I hardly think invoking hundreds
and possibly thousands of short-lived python
interpreters to be an optimal solution that may
have spawned this particular thread.

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-27 Thread James Mills
On Mon, Oct 27, 2008 at 5:28 PM, David Cournapeau <[EMAIL PROTECTED]> wrote:
> Any command line based on python is a real example of that problem.
> There are plenty of them.

Yes, but in most cases you are not invoking your
command-line app x times per y units of time.

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-27 Thread Paul Rubin
"James Mills" <[EMAIL PROTECTED]> writes:
> Heaven knows! I hardly think invoking hundreds
> and possibly thousands of short-lived python
> interpreters to be an optimal solution that may
> have spawned this particular thread.

It's not optimal but it is very common (CGI for example).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-27 Thread David Cournapeau
On Mon, Oct 27, 2008 at 4:33 PM, James Mills
<[EMAIL PROTECTED]> wrote:
> Yes, but in most cases you are not invoking your
> command-line app x times per y units of time.

Depends on the tool: build tool and source control tools are example
it matters (specially when you start interfaciing them with IDE or
editors). Having fast command line tools is an important feature of
UNIX, and if you want to insert a python-based tool in a given
pipeline, it can hurt it the pipeline is regularly updated.

cheers,

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


Re: Improving interpreter startup speed

2008-10-27 Thread James Mills
On Mon, Oct 27, 2008 at 5:36 PM, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> It's not optimal but it is very common (CGI for example).

Which is why we (The Python Community)
created WSGI and mod_wsgi. C"mon guys
these "problems" are a bit old and out
dated :)

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-27 Thread Gabriel Genellina
En Sun, 26 Oct 2008 23:52:32 -0200, James Mills  
<[EMAIL PROTECTED]> escribió:



On Mon, Oct 27, 2008 at 4:12 AM, Benjamin Kaplan
<[EMAIL PROTECTED]> wrote:
You must be in a real big hurry if half a second matters that much to  
you.

Maybe if it took 5 seconds for the interpreter to start up, I could
understand having a problem with the start up time.


+1 This thread is stupid and pointless.
Even for a so-called cold startup 0.5s is fast enough!


I don't see the need to be rude.
And I DO care for Python startup time and memory footprint, and others do  
too. Even if it's a stupid thing (for you).


--
Gabriel Genellina

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


Re: Improving interpreter startup speed

2008-10-27 Thread James Mills
On Mon, Oct 27, 2008 at 5:40 PM, David Cournapeau <[EMAIL PROTECTED]> wrote:
> Depends on the tool: build tool and source control tools are example
> it matters (specially when you start interfaciing them with IDE or
> editors). Having fast command line tools is an important feature of
> UNIX, and if you want to insert a python-based tool in a given
> pipeline, it can hurt it the pipeline is regularly updated.

Fair enough. But still:
0.5s old startup is fast enough
0.08s warm startup is fast enough.

Often "fast enough" is "fast enough"

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: @property decorator doesn't raise exceptions

2008-10-27 Thread Peter Otten
Rafe wrote:

> Can anyone explain why this is happening? 

When an attribute error is raised that is an indication that the requested
attribute doesn't exist, and __getattr__() must be called as a fallback.

> I can hack a work-around, 
> but even then I could use some tips on how to raise the 'real'
> exception so debugging isn't guesswork.

Look at the problem again, maybe you can find a solution without
__getattr__() and use only properties.

Otherwise you have to wrap your getter with something like

try:
...
except AttributeError:
raise BuggyProperty, None, original_traceback


If you put that functionality into a decorator you get:

import sys

class BuggyProperty(Exception):
pass

def safe_getter(get):
def safe_get(self):
try:
return get(self)
except AttributeError:
t, e, tb = sys.exc_info()
raise BuggyProperty("AttributeError in getter %s(); "
"giving original traceback"
% get.__name__), None, tb
return property(safe_get)

class A(object):
@safe_getter
def attr(self):
return self.m(3)

def m(self, n):
if n > 0:
return self.m(n-1)
raise AttributeError("it's a bug")

def __getattr__(self, name):
return "<%s>" % name

A().attr

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


Re: Improving interpreter startup speed

2008-10-27 Thread James Mills
On Mon, Oct 27, 2008 at 5:46 PM, Gabriel Genellina
<[EMAIL PROTECTED]> wrote:
>> +1 This thread is stupid and pointless.
>> Even for a so-called cold startup 0.5s is fast enough!
>
> I don't see the need to be rude.
> And I DO care for Python startup time and memory footprint, and others do
> too. Even if it's a stupid thing (for you).

I apologize. I do not see the point comparing Python with
RUby however, or Python with anything else.

So instead of coming up with arbitary problems, why don't
we come up with solutions for "Improving Interpreter Startup Speeds" ?

I have only found that using the -S option speeds it up
significantly, but that's only if you're not using any site
packages and only using the built in libraries.

Can site.py be improved ?

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5.chm problem

2008-10-27 Thread [EMAIL PROTECTED]

This solve the problem:
http://techrepublic.com.com/5208-11183-0.html?forumID=89&threadID=191474

regsvr32 %systemroot%\system32\hhctrl.ocx 
regsvr32 %systemroot%\system32\itss.dll 


[EMAIL PROTECTED]:

Hi!

When I try to open the 2.5 Python help, I got error message:
  "A fájl (mk:@MSITStore:c:\Python25\Doc\Python25.chm) nem nyitható meg."

The english translation is this:
  "Cannot open the file (mk:@MSITStore:c:\Python25\Doc\Python25.chm)"

I not experienced this problem in the Python 2.4 the help.

What is the solution for this problem? I don't wanna use web helps.

Thanks for it:
dd

--




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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-27 Thread Martin v. Löwis
Andy O'Meara wrote:
> On Oct 24, 9:52 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
 A c-level module, on the other hand, can sidestep/release
 the GIL at will, and go on it's merry way and process away.
>>> ...Unless part of the C module execution involves the need do CPU-
>>> bound work on another thread through a different python interpreter,
>>> right?
>> Wrong.
[...]
> 
> So I think the disconnect here is that maybe you're envisioning
> threads being created *in* python.  To be clear, we're talking out
> making threads at the app level and making it a given for the app to
> take its safety in its own hands.

No. Whether or not threads are created by Python or the application
does not matter for my "Wrong" evaluation: in either case, C module
execution can easily side-step/release the GIL.

>>> As far as I can tell, it seems
>>> CPython's current state can't CPU bound parallelization in the same
>>> address space.
>> That's not true.
>>
> 
> Well, when you're talking about large, intricate data structures
> (which include opaque OS object refs that use process-associated
> allocators), even a shared memory region between the child process and
> the parent can't do the job.  Otherwise, please describe in detail how
> I'd get an opaque OS object (e.g. an OS ref that refers to memory-
> resident video) from the child process back to the parent process.

WHAT PARENT PROCESS? "In the same address space", to me, means
"a single process only, not multiple processes, and no parent process
anywhere". If you have just multiple threads, the notion of passing
data from a "child process" back to the "parent process" is
meaningless.

> Again, the big picture that I'm trying to plant here is that there
> really is a serious need for truly independent interpreters/contexts
> in a shared address space.

I understand that this is your mission in this thread. However, why
is that your problem? Why can't you just use the existing (limited)
multiple-interpreters machinery, and solve your problems with that?

> For most
> industry-caliber packages, the expectation and convention (unless
> documented otherwise) is that the app can make as many contexts as its
> wants in whatever threads it wants because the convention is that the
> app is must (a) never use one context's objects in another context,
> and (b) never use a context at the same time from more than one
> thread.  That's all I'm really trying to look at here.

And that's indeed the case for Python, too. The app can make as many
subinterpreters as it wants to, and it must not pass objects from one
subinterpreter to another one, nor should it use a single interpreter
from more than one thread (although that is actually supported by
Python - but it surely won't hurt if you restrict yourself to a single
thread per interpreter).

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


Re: Improving interpreter startup speed

2008-10-27 Thread [EMAIL PROTECTED]

To make faster python, you can do:

1.) Use mod_python, and not cgi.
2.) Use other special python server that remaining in memory, and call 
it from compiled C code. For example, the C code communicate this server 
with pipes, tcp, (or with special files, and the result will come back 
in other file).
You can improve this server when you split threads to python 
subprocesses, and they still alive for X minutes.
You have one control process (py), and this (like the apache) 
communicate the subprocesses, kill them after timeout, and start a new 
if needed.


dd

James Mills írta:

On Mon, Oct 27, 2008 at 5:46 PM, Gabriel Genellina
<[EMAIL PROTECTED]> wrote:

+1 This thread is stupid and pointless.
Even for a so-called cold startup 0.5s is fast enough!

I don't see the need to be rude.
And I DO care for Python startup time and memory footprint, and others do
too. Even if it's a stupid thing (for you).


I apologize. I do not see the point comparing Python with
RUby however, or Python with anything else.

So instead of coming up with arbitary problems, why don't
we come up with solutions for "Improving Interpreter Startup Speeds" ?

I have only found that using the -S option speeds it up
significantly, but that's only if you're not using any site
packages and only using the built in libraries.

Can site.py be improved ?

--JamesMills



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


conversion to and from unicode strings

2008-10-27 Thread abhishek
hello group,
  i want to represent and store a string u'\x00\x07\xa7' as
'\x00\x07\xa7'. any ideas on how to achieve this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: set/dict comp in Py2.6

2008-10-27 Thread Gabriel Genellina
En Sat, 25 Oct 2008 23:44:46 -0200, Benjamin <[EMAIL PROTECTED]>  
escribió:



On Oct 25, 3:13 am, [EMAIL PROTECTED] wrote:

I'd like to know why Python 2.6 doesn't have the syntax to create sets/
dicts of Python 3.0, like:


Because nobody bothered to backport them.


En Sat, 25 Oct 2008 23:47:32 -0200, Benjamin <[EMAIL PROTECTED]>  
escribió:



Because nobody bothered to backport them.


En Mon, 27 Oct 2008 00:17:20 -0200, Benjamin <[EMAIL PROTECTED]>  
escribió:



Because nobody bothered to backport it.


En Mon, 27 Oct 2008 00:19:29 -0200, Benjamin  
<[EMAIL PROTECTED]> escribió:



Because nobody bothered to backport it.


Yeah, we already know... :)

--
Gabriel Genellina

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


Re: conversion to and from unicode strings

2008-10-27 Thread Gerhard Häring

abhishek wrote:

hello group,
  i want to represent and store a string u'\x00\x07\xa7' as
'\x00\x07\xa7'. any ideas on how to achieve this.


You want to store it in the form of the repr() of the string? It is 
possible to use repr() to get a bytestring to store and to use eval() to 
create a unicode string of that bytestring again. But that's just bad.


It's much better to use a encoding that can represent all Unicode 
characters like UTF-8.


>>> s = u'\x00\x07\xa7'
>>> bytestr = s.encode("utf-8")
>>> bytestr
'\x00\x07\xc2\xa7'
>>> out_str = unicode(bytestr, "utf-8")
>>> out_str == s
True

-- Gerhard

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


Do I need a lock here?

2008-10-27 Thread jasiu85
Hey,

Please take a look at the code of the two threads below:

COMMON_DICT = {}

def thread_1():
global COMMON_DICT
local_dict = prepare_dict()
COMMON_DICT = local_dict

def thread_2():
global COMMON_DICT
local_dict = COMMON_DICT
use_dict(local_dict)

Do I need a lock to protect the COMMON_DICT dictionary? AFAIK bytecode
operations are atomic and in each thread there's only one crucial
bytecode op: STORE_NAME in the first thread and LOAD_NAME in the
second one. So I suspect that everything will work just fine. Am I
right?

Regards,

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


Re: Do I need a lock here?

2008-10-27 Thread Diez B. Roggisch

jasiu85 schrieb:

Hey,

Please take a look at the code of the two threads below:

COMMON_DICT = {}

def thread_1():
global COMMON_DICT
local_dict = prepare_dict()
COMMON_DICT = local_dict

def thread_2():
global COMMON_DICT
local_dict = COMMON_DICT
use_dict(local_dict)

Do I need a lock to protect the COMMON_DICT dictionary? AFAIK bytecode
operations are atomic and in each thread there's only one crucial
bytecode op: STORE_NAME in the first thread and LOAD_NAME in the
second one. So I suspect that everything will work just fine. Am I
right?


Depending on what you mean by "right".

The above is not enough to judge what is really happening. But depending 
on the execution order, thread_1 overwrites the reference in COMMON_DICT 
*after* thread_2 has altered it.


But it won't crash or anything. If that's right for you.

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


Re: Cannot build _multiprocessing, math, mmap and readline of Python 2.6 on FreeBSD 4.11 w/ gcc 2.95.4

2008-10-27 Thread M.-A. Lemburg
On 2008-10-25 20:19, Akira Kitada wrote:
> Hi Marc-Andre,
> 
> Thanks for the suggestion.
> I opened a ticket for this issue: http://bugs.python.org/issue4204

Thanks.

> Now I understand the state of the multiprocessing module,
> but it's too bad to see math, mmap and readline modules, that worked
> fine before,
> cannot be built anymore.

The errors you are getting appear to be related to either some
missing header files or a missing symbol definition to enable
these - looking at the ticket, you seem to have resolved all
this already :-)

> As for FreeBSD4, yeah it's really dated and I understand newer FreeBSD should
> make my life easier, but I would rather want Python continue to
> support old system like this
> as long as it's not getting very hard to maintain the clean code base.

Sure, the more platforms the better.

> Thanks,
> 
> On Sat, Oct 25, 2008 at 10:53 PM, M.-A. Lemburg <[EMAIL PROTECTED]> wrote:
>> On 2008-10-25 08:39, Akira Kitada wrote:
>>> Hi list,
>>>
>>> I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed
>>> to build some of the modules.
>>>
>>> """
>>> Failed to find the necessary bits to build these modules:
>>> _bsddb _sqlite3   _tkinter
>>> gdbm   linuxaudiodev  spwd
>>> sunaudiodev
>>> To find the necessary bits, look in setup.py in detect_modules() for
>>> the module's name.
>>>
>>>
>>> Failed to build these modules:
>>> _multiprocessing   math   mmap
>>> readline
>>> """
>>>
>>> Because I don't have Berkeley DB, SQLite3 tk, GDBM installed on the
>>> system and running FreeBSD,
>>> there is no wonder it failed to build  _bsddb, _sqlite3, _tkinter,
>>> gdbm, linuxaudiodev, spwd and sunaudiodev.
>>>
>>> The problem is it failed to build _multiprocessing, math, mmap and readline.
>> Please post a bug report on python.org about these failures.
>>
>> The multiprocessing module is still fairly new and obviously needs
>> more fine tuning for the large set of platforms on which Python
>> can run. However, please also note that FreeBSD4 is a rather old
>> version of that OS. FWIW: Python 2.6 compiles just fine on FreeBSD6.
>>
>> Thanks.
>>
>>> Here are the outputs of each build failure.
>>>
>>> """
>>> building '_multiprocessing' extension
>>> creating 
>>> build/temp.freebsd-4.11-RELEASE-i386-2.6/usr/home/build/dev/Python-2.6/Modules/_multiprocessing
>>> gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
>>> -Wstrict-prototypes -DHAVE_SEM_OPEN=1 -DHAVE_FD_TRANSFER=1
>>> -DHAVE_SEM_TIMEDWAIT=1 -IModules/_multiprocessing -I.
>>> -I/usr/home/build/dev/Python-2.6/./
>>> Include -I. -IInclude -I./Include -I/usr/local/include
>>> -I/usr/home/build/dev/Python-2.6/Include
>>> -I/usr/home/build/dev/Python-2.6 -c
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c
>>> -o b
>>> uild/temp.freebsd-4.11-RELEASE-i386-2.6/usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.o
>>> In file included from
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.h:24,
>>>  from
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c:9:
>>> /usr/include/arpa/inet.h:89: warning: parameter has incomplete type
>>> /usr/include/arpa/inet.h:92: warning: parameter has incomplete type
>>> /usr/include/arpa/inet.h:96: warning: parameter has incomplete type
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c:
>>> In function `multiprocessing_sendfd':
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c:102:
>>> storage size of `dummy_iov' isn't known
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c:102:
>>> warning: unused variable `dummy_iov'
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c:
>>> In function `multiprocessing_recvfd':
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c:137:
>>> storage size of `dummy_iov' isn't known
>>> /usr/home/build/dev/Python-2.6/Modules/_multiprocessing/multiprocessing.c:137:
>>> warning: unused variable `dummy_iov'
>>> """
>>>
>>> """
>>> building 'cmath' extension
>>> gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
>>> -Wstrict-prototypes -I. -I/usr/home/build/dev/Python-2.6/./Include -I.
>>> -IInclude -I./Include -I/usr/local/include
>>> -I/usr/home/build/dev/Python-2.6/I
>>> nclude -I/usr/home/build/dev/Python-2.6 -c
>>> /usr/home/build/dev/Python-2.6/Modules/cmathmodule.c -o
>>> build/temp.freebsd-4.11-RELEASE-i386-2.6/usr/home/build/dev/Python-2.6/Modules/cmathmodule.o
>>> /usr/home/build/dev/Python-2.6/Modules/cmathmodule.c: In function
>>> `special_type':
>>> /usr/home/build/dev/Python-2.6/Modules/cmathmodule.c:79: warning:
>>> implicit declaration of function `copysign'
>>> /usr/home/build/dev/Python-2.6/Modules/cmathmodule.c: In function `c_acos':
>>> /usr/home/build/dev/Python-2.6/Modules/cmathmodule.c:152: warning:
>>> implicit declaration of fun

example for PEP 342

2008-10-27 Thread Severin
Hello,
Is there a simple example demonstrating how to use the Trampoline from PEP
342 (http://www.python.org/dev/peps/pep-0342/)?

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


FTP via web browser

2008-10-27 Thread rodmc
Hi,

I have posted elsewhere about a related topic. But I an curious is it
possible to set up a web form which people select a file for upload
which is then upload it via FTP protocol to the web server - the
entire process must be web based and not require an external FTP
client. The reason for asking is that uploading large files via HTTP
form post is very unreliable beyond say 20MB.

Thanks in advance.

Best,

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


Re: Type feedback tool?

2008-10-27 Thread M.-A. Lemburg
On 2008-10-26 13:54, Martin Vilcans wrote:
> Hi list,
> 
> I'm wondering if there's a tool that can analyze a Python program
> while it runs, and generate a database with the types of arguments and
> return values for each function. In a way it is like a profiler, that
> instead of measuring how often functions are called and how long time
> it takes, it records the type information. So afterwards, when I'm
> reading the code, I can go to the database to see what data type
> parameter "foo" of function "bar" typically has. It would help a lot
> with deciphering old code.
> 
> When I googled this, I learned that this is called "type feedback",
> and is used (?) to give type information to a compiler to help it
> generate fast code. My needs are much more humble. I just want a
> faster way to understand undocumented code with bad naming.

You could try the trace module:

http://www.python.org/doc/2.5.2/lib/module-trace.html

but I'm not sure whether that includes parameter listings.

Or write your own tracing function and then plug it into your
application using sys.settrace():

http://www.python.org/doc/2.5.2/lib/debugger-hooks.html#debugger-hooks

The frame object will have the information you need:

http://www.python.org/doc/2.5.2/ref/types.html#l2h-143

in f_locals.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 27 2008)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Re: FTP via web browser

2008-10-27 Thread Tino Wildenhain

rodmc wrote:

Hi,

I have posted elsewhere about a related topic. But I an curious is it
possible to set up a web form which people select a file for upload
which is then upload it via FTP protocol to the web server - the
entire process must be web based and not require an external FTP
client. The reason for asking is that uploading large files via HTTP
form post is very unreliable beyond say 20MB.


No its not - see for example rapidshare.

You are asking for web browser - so to do anything here
you would have a web server anyway - and the file upload
via form post. No matter if its using ftp or some
local store underneath.

What about Webdav? Most OS have support for it nowadays.

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: conversion to and from unicode strings

2008-10-27 Thread Duncan Booth
abhishek <[EMAIL PROTECTED]> wrote:

> hello group,
>   i want to represent and store a string u'\x00\x07\xa7' as
> '\x00\x07\xa7'. any ideas on how to achieve this.

You can use latin-1 encoding.

>>> u = ''.join(unichr(c) for c in range(256))
>>> [ord(c) for c in u.encode('latin1')] == range(256)
True


-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do I need a lock here?

2008-10-27 Thread Duncan Booth
jasiu85 <[EMAIL PROTECTED]> wrote:

> Hey,
> 
> Please take a look at the code of the two threads below:
> 
> COMMON_DICT = {}
> 
> def thread_1():
> global COMMON_DICT
> local_dict = prepare_dict()
> COMMON_DICT = local_dict
> 
> def thread_2():
> global COMMON_DICT
> local_dict = COMMON_DICT
> use_dict(local_dict)
> 
> Do I need a lock to protect the COMMON_DICT dictionary? AFAIK bytecode
> operations are atomic and in each thread there's only one crucial
> bytecode op: STORE_NAME in the first thread and LOAD_NAME in the
> second one. So I suspect that everything will work just fine. Am I
> right?
> 
Possibly, but without further information it is impossible to tell.

You have one thing wrong though: bytecode operations are not all atomic. 
For example STORE_NAME will remove a reference to the object previously 
stored under a name and that could trigger code in a __del__ method or a 
weak reference callback. That callback code will execute in the same thread 
as the STORE_NAME, but while it is executing you could get a context switch 
to another thread.

None of that will prevent the store working, and it may not be at all 
applicable to your data structures, but in general any operation which can 
release complex objects is not thread safe.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


xchat

2008-10-27 Thread luca72
Hello

i have installed xchat on suse11 i see that there is the possibility
to use python for make some script, i see also that the python
interface is loaded, but when in python i type import xchat i get that
the module don't exist.
where is the module?
I try also to ask in the xchat forum but i get no reply so i try here

Thanks

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


Re: Type feedback tool?

2008-10-27 Thread skip

(Sorry for any repeated recommendations.  I'm offline until Monday morning.
You may well see some of these suggestions in the meanwhile, but so far it
seems you've had no nibbles.)

Martin> I'm wondering if there's a tool that can analyze a Python
Martin> program while it runs, and generate a database with the types of
Martin> arguments and return values for each function. 

Nothing that I'm aware of.  Here are a few ideas though.

1. Modify the source code in question to decorate any functions you're
   interested in, e.g.:

#!/usr/bin/env python

class ZeroDict(dict):
def __getitem__(self, key):
if key not in self:
return 0
return dict.__getitem__(self, key)

_argtypes = ZeroDict()

def note_types(f):
"Decorator that keeps track of counts of arg types for various 
functions."
def _wrapper(*args):
_argtypes[(f,) + tuple([type(a) for a in args])] += 1
return f(*args)
return _wrapper

@note_types
def fib(n):
if n < 0:
raise ValueError, "n < 0"
if n > 1:
return fib(n-1) + fib(n-2)
return 1

@note_types
def fib2(n):
"fib() that guarantees it is dealing with ints."
if n < 0:
raise ValueError, "n < 0"
n = int(n)
if n > 1:
return fib2(n-1) + fib2(n-2)
return 1

if __name__ == "__main__":
print "fib(5) ==", fib(5)
print "fib(4.0) ==", fib(4.0)
print "fib2(5) ==", fib2(5)
print "fib2(4.0) ==", fib2(4.0)
print _argtypes

   You can probably write a source transformation tool to decorate all
   functions (or just use Emacs macros for a 99% solution which takes a lot
   less time).

2. Look at tools like pdb.  You might be able to add a new command to
   decorate a function in much the same way that you might set a breakpoint
   at a given function.

3. Take a look at IDEs with source (like IDLE).  You might be able to coax
   them into decorating functions then display the collected statistics when
   you view the source (maybe display a tooltip with the stats for a
   particular function).

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


Re: xchat

2008-10-27 Thread Tino Wildenhain

Hi,

luca72 wrote:

Hello

i have installed xchat on suse11 i see that there is the possibility
to use python for make some script, i see also that the python
interface is loaded, but when in python i type import xchat i get that
the module don't exist.
where is the module?
I try also to ask in the xchat forum but i get no reply so i try here


try it again from within xchat. See the documentation for the python
console (like a chat to python interpreter)

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Type feedback tool?

2008-10-27 Thread Orestis Markou
I think that rope has something like that; not really sure though.

On Mon, Oct 27, 2008 at 1:41 AM,  <[EMAIL PROTECTED]> wrote:
>
> (Sorry for any repeated recommendations.  I'm offline until Monday morning.
> You may well see some of these suggestions in the meanwhile, but so far it
> seems you've had no nibbles.)
>
>Martin> I'm wondering if there's a tool that can analyze a Python
>Martin> program while it runs, and generate a database with the types of
>Martin> arguments and return values for each function.
>
> Nothing that I'm aware of.  Here are a few ideas though.
>
> 1. Modify the source code in question to decorate any functions you're
>   interested in, e.g.:
>
>#!/usr/bin/env python
>
>class ZeroDict(dict):
>def __getitem__(self, key):
>if key not in self:
>return 0
>return dict.__getitem__(self, key)
>
>_argtypes = ZeroDict()
>
>def note_types(f):
>"Decorator that keeps track of counts of arg types for various 
> functions."
>def _wrapper(*args):
>_argtypes[(f,) + tuple([type(a) for a in args])] += 1
>return f(*args)
>return _wrapper
>
>@note_types
>def fib(n):
>if n < 0:
>raise ValueError, "n < 0"
>if n > 1:
>return fib(n-1) + fib(n-2)
>return 1
>
>@note_types
>def fib2(n):
>"fib() that guarantees it is dealing with ints."
>if n < 0:
>raise ValueError, "n < 0"
>n = int(n)
>if n > 1:
>return fib2(n-1) + fib2(n-2)
>return 1
>
>if __name__ == "__main__":
>print "fib(5) ==", fib(5)
>print "fib(4.0) ==", fib(4.0)
>print "fib2(5) ==", fib2(5)
>print "fib2(4.0) ==", fib2(4.0)
>print _argtypes
>
>   You can probably write a source transformation tool to decorate all
>   functions (or just use Emacs macros for a 99% solution which takes a lot
>   less time).
>
> 2. Look at tools like pdb.  You might be able to add a new command to
>   decorate a function in much the same way that you might set a breakpoint
>   at a given function.
>
> 3. Take a look at IDEs with source (like IDLE).  You might be able to coax
>   them into decorating functions then display the collected statistics when
>   you view the source (maybe display a tooltip with the stats for a
>   particular function).
>
> Skip
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
[EMAIL PROTECTED]
http://orestis.gr
--
http://mail.python.org/mailman/listinfo/python-list


Post easy_install hooks/message

2008-10-27 Thread Orestis Markou
Hello,

I've finally uploaded PySmell [1] to PyPI [2], thanks to a fantastic
contributor which did all the work for me. As I've written in a blog
post [3], I have some trouble distributing some support files,
notably, a vim script.

I am currently using these directives:

data_files = [
('vim', ['pysmell.vim'])
],
include_package_data = True,

and in MANIFEST.in :

include pysmell.vim

This means than when I do python setup.py sdist, I get the pysmell.vim
file, but when the egg is created by easy_install, a vim folder with
the vim script is put inside it. I want to be able to at least prompt
the user with a message saying

To complete installation, do
"cp /path/to/the/pysmell.vim ~/.vim/plugin"

Or something like that. What is the best way to do this? Right now my
instructions read: "Download the sdist and do python setup.py install,
then copy pysmell.vim where it needs to live.". Being able to replace
that with "easy_install pysmell and follow the instructions would be
great".

[1] http://code.google.com/p/pysmell
[2] http://pypi.python.org/pypi/pysmell
[3] http://orestis.gr/blog/2008/10/26/trouble-setuptools/


Many thanks,
Orestis Markou
-- 
[EMAIL PROTECTED]
http://orestis.gr
--
http://mail.python.org/mailman/listinfo/python-list


Re: Triple-quoted strings hath not the Python-nature

2008-10-27 Thread Steven D'Aprano
On Mon, 27 Oct 2008 12:11:34 +1300, Lawrence D'Oliveiro wrote:

> In message <[EMAIL PROTECTED]>, Steven D'Aprano
> wrote:
> 
>> I disagree. Triple-quoted strings are exactly the same as other
>> strings: they capture *exactly* what you put in them ...
> 
> But that conflicts with the use of whitespace for indentation rules.

No it doesn't. Indentation is a token in Python source code. Strings are 
a data type. Syntax rules don't apply to strings because strings are 
data, not syntax.

You wouldn't expect the following string literal to raise a syntax error:

"if Time = Money then ..."

Nor does the string "C++", and the string "1/0" doesn't raise 
ZeroDivisionError. Strings are data, not syntax. Except for the syntactic 
sugar of escape sequences, the contents of strings have no syntax.

(I say content to distinguish it from the delimiters themselves.)

Why should whitespace in string literals be treated as syntactic tokens 
when no other characters are? 


[...]
> In short, if whitespace is significant outside a string, then it
> shouldn't be significant inside. And vice versa.

That's an arbitrary rule that makes no sense at all. It's not just 
arbitrary, it's *stupid*. Why on earth should the string literal

s = """
text
 aligned
  to
 the
   right
 """

raise an IndentationError? Or should it be a SyntaxError?


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


Re: Do I need a lock here?

2008-10-27 Thread Michael Sparks
jasiu85 wrote:

> Do I need a lock to protect the COMMON_DICT dictionary? AFAIK bytecode
> operations are atomic and in each thread there's only one crucial
> bytecode op: STORE_NAME in the first thread and LOAD_NAME in the
> second one. So I suspect that everything will work just fine. Am I
> right?

Will it crash your system? Probably not. Will you end up with correct values
in your dict? Probably not, since you can still end up with race hazards.

If you want to share data that way, you may want to look at Kamaelia's
STM[1] model, which is described on this page:

   * http://www.kamaelia.org/STM

You can created stores - which are /essentially/ (key value) threadsafe
stores which enable you to figure out when things go wrong, so you can do
something about it ! :)

A short example:

from Axon.STM import Store

S = Store() # Shared store (like your COMMON_DICT)

D = S.using("account_one", "account_two", "myaccount")
D["account_one"].set(50)
D["account_two"].set(100)
D.commit()# This will fail if any of the values have changed
S.dump()

D = S.using("account_one", "account_two", "myaccount")
D["myaccount"].set(D["account_one"].value+D["account_two"].value)
D["account_one"].set(0)
D["account_two"].set(0)
D.commit()# This will fail if any of the values have changed
S.dump()

If this looks familiar, it's the same basic idiom as version control. The
nice thing of course, is in this version you don't need to worry about
locks, but just be aware that the .commit() may fail, and you may need to
retry.

Two examples - one using bare threads, one using Kamaelia components are
here:
   * http://kamaelia.googlecode.com/svn/trunk/Code/Python/Axon/Examples/STM/

Crucially whilst the above says "this will fail", the examples in that
directory handle the failures correctly :)

This code is included in the latest Kamaelia release, described here:
   * http://www.kamaelia.org/GetKamaelia

However you can also use the standalone tarball attached to that page.

[1] ie a minimal software transactional memory implementation. The point of
these things really is to allow you to detect when something has gone
wrong (eg and update fails) and to redo the thing that led to the
update. It's conceptually very similar to version control for variables.
I'm tempted to replace "using" with "checkout" to mirror "commit".



Michael.
-- 
http://www.kamaelia.org/GetKamaelia

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


Python-URL! - weekly Python news and links (Oct 27)

2008-10-27 Thread Gabriel Genellina
QOTW:  "But it is the right idea. They just don't know what it means,
because they've been listening to people like you who insist on using
Pascal terminology with a definition unrecognizable to Pascal programmers.
To an ex-Pascal programmer like myself, when you talk about 'call by value
where the value is a reference', it sounds to me as if you are insisting
that cars are ACTUALLY horse and buggies, where the horse is the engine,
why are we inventing new terms like 'automobile', that just confuses
people." - Steven D'Aprano
http://groups.google.com/group/comp.lang.python/msg/4aec48c7875baba6


A long thread about multiprocessing, multithreading, the GIL, and how
Python behaves in a multicore/multiple CPU environment:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9d995e4a1153a1b2/

Using __del__ and atexit to execute code when interpreter shuts down:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/5478e423ae290671/

Several ways to keep a bunch of named constants: into a dictionary, as
class attributes, as module attributes...

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b3a0942650bdabc6/

Handling keyboard input immediately (without waiting for  key):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/70b2f83151373237/

After discovering some corner cases in the set implementation, this
thread is now discussing abstract data types:
http://mail.python.org/pipermail/python-list/2008-October/512865.html
http://mail.python.org/pipermail/python-list/2008-October/512911.html

Using the right algorithm and data structure, the time to compare two
lists can decrease from 10 minutes to only 2-3 secs:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/91b7eae37c5d22e1/

Replacing a method with an arbitrary callable object:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/1bc94ef7a0bc0e5b/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space f

Finding Default Page Name using urllib2

2008-10-27 Thread barrett
Is there a way to find the name of a page you are retrieving using
python.  For example, if I get http://www.cnn.com/ i want to know that
the page is index.html.  I can do this using wget. as seen in the code
below.  Can I do this in python?

Thanks,

$ wget cnn.com
--11:15:25--  http://cnn.com/
   => `index.html'
Resolving cnn.com... 157.166.226.25, 157.166.226.26,
157.166.224.25, ...
Connecting to cnn.com|157.166.226.25|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.cnn.com/ [following]
--11:15:25--  http://www.cnn.com/
   => `index.html'
Resolving www.cnn.com... 157.166.224.25, 157.166.224.26,
157.166.226.25, ...
Reusing existing connection to cnn.com:80.
HTTP request sent, awaiting response... 200 OK
Length: 96,094 (94K) [text/html]

100%[>] 96,09468.15K/s

11:15:28 (67.99 KB/s) - `index.html' saved [96094/96094]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding Default Page Name using urllib2

2008-10-27 Thread Philip Semanchuk


On Oct 27, 2008, at 12:17 PM, barrett wrote:


Is there a way to find the name of a page you are retrieving using
python.  For example, if I get http://www.cnn.com/ i want to know that
the page is index.html.  I can do this using wget. as seen in the code
below.  Can I do this in python?


Hi barrett,
Look into the urllib2 module and specifically HTTPRedirectHandler  
objects.



Good luck
Philip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Linq to Python

2008-10-27 Thread Tim Rowe
2008/9/24 Duncan Booth <[EMAIL PROTECTED]>:


> Python still wins hands down on this example both in verbosity and
> readability:

But AFAICS, the Python version you give creates a temporary. One of
the advantages cited for LINQs functional programming paradigm is that
it specifies what is wanted at a higher level, so the compiler can
decide whether to create temporaries, and can also decide whether to
farm the thing off to multiple processors -- harder if you've
specified in detail /how/ to do the job. Not an issue for little jobs,
but certainly an issue for, for example, a friend who had a daily
database job to do that took over 24 hours to run.

> I haven't yet had occasion to use LINQ in anger yet, so I have no idea
> whether its an idea to love or to hate. I do think it is good that C# has
> effectively sprouted list comprehensions (not to mention anonymous types
> and type inferencing) and I expect there may be some aspects worth looking
> at for Python but I think they are more likely to lead to itertools
> functions than extensions to syntax.

Yes, looking at what LINQ adds to C# (according to
http://msdn.microsoft.com/en-gb/library/bb397909.aspx):
- Implicitly typed variables: Python already has.
- Object and collection initialisers: Not sure whether Python can do
this directly, but it can certainly emulate it with a dictionary.
- Anonymous types: Not sure whether Python can do this directly, but
it can certainly emulate it with a dictionary.
- Extension methods: Python already has.
- Lambda expressions: Python already has.
- Auto-Implemented properties: No, but that's just syntactic sugar to
make declarations more compact.

So all of the language elements that are needed for LINQ are already
in Python; a library should do the trick.

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


Re: Limit between 0 and 100

2008-10-27 Thread Matimus
On Oct 25, 1:42 pm, [EMAIL PROTECTED] wrote:
> Hi. I'm very new to Python, and so this is probably a pretty basic
> question, but I'm lost. I am looking to limit a float value to a
> number between 0 and 100 (the input is a percentage).
>
> I currently have:
>
> integer = int()
> running = True
>
> while running:
>   try:
>     per_period_interest_rate = float(raw_input("Enter per-period
> interest rate, in percent: "))
>     break
>   except ValueError:
>     print "Please re-enter the per-period interest rate as a number
> between 0 and 100."
>
> I also have to make sure it is a number and not letters or anything.
>
> Thanks for the help.
>
> James
>
> P.S. I don't understand a lot of what I have there, I got most of it
> from the beginning tutorials and help sections. I have never
> programmed before, but this is for a school assignment.

You aren't very far off. You are going to need to use 'if' and '<' or
'>' to check for range though.

As in:

if x > 10:
print "x is greater than 10"

OR:

if 10 < x < 20:
   print "x is between 10 and 20"

If you describe exactly what it is that you don't understand, people
here will be willing to help you to understand it. However, you will
find that people here are very unwilling to do your homework for you.

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


Re: Do a Gnuplot of a file in python

2008-10-27 Thread Santix

Thanks a lot because it works with
 g.load("power.p")

But now I have this problem 

gnuplot> load 'power.p'
gnuplot> set terminal postscript enhanced color
gnuplot> set output "spectrum.ps"
gnuplot> plot 
gnuplot> set terminal x11
gnuplot> set output

gnuplot> plot 
  ^
 line 0: function to plot expected

It plots one time and then I want the program to close the plot window and
do another iteration, then show a plot again, close it, another iteration,
etc...
What should I put in the "power.p" code? I've tried to put exit or close but
it doesn't close the plot window.

Thanks and Regards,

Santi.



Gabriel Genellina-7 wrote:
> 
> En Thu, 23 Oct 2008 13:58:20 -0200, Santix <[EMAIL PROTECTED]>  
> escribió:
> 
>> I am doing a python program that save the data in a text file in columns  
>> and
>> I want to do a gnuplot to plot the results.
>> But I want the program in python to show the result with gnuplot.
>> I have tried this:
>>
>> g.load(power.p)
>>
>> but it gives me this error:
>>
>> Traceback (most recent call last):
>>   File "./spectrum_output.py", line 310, in 
>> main_loop(tb)
>>   File "./spectrum_output.py", line 289, in main_loop
>> g.load(power.p)
>> AttributeError: 'file' object has no attribute 'p'
> 
> I don't know gnuplot nor what g.load expects - but probably some lines  
> above that you have something like this:
> power = open(...)
> Try with g.load("power.p") instead.
> 
> -- 
> Gabriel Genellina
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Do-a-Gnuplot-of-a-file-in-python-tp20134007p20191843.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Ordering python sets

2008-10-27 Thread bearophileHUGS
Glenn Linderman:

> how does one create a key that corresponds to ascending integer followed by 
> descending character string?

(Others may have already answered you because Google groups is very
slow.)

>>> seq = [(10, "abb"), (5, "zul"), (5, "hal"), (2, "of")]
>>> sorted(seq, key=lambda (n,s): (-n, s), reverse=True)
[(2, 'of'), (5, 'zul'), (5, 'hal'), (10, 'abb')]

A little harder question is how to create a key that corresponds to
ascending string followed by descending string?

To do that you can sort the data two times, relying on the stable
nature of the Python sort.

Another (silly?) solution may be to invent a "negate" function for
strings too:

>>> strneg = lambda txt: txt.translate(itable)
>>> itable = "".join(chr(i) for i in xrange(255, -1, -1))
>>> pairs = [('al', 'boo'), ('zul', 'ao'), ('al', 'den'), ('zul', 'o')]
>>> sorted(pairs, key=lambda (s1,s2): (s1, strneg(s2)))
[('al', 'den'), ('al', 'boo'), ('zul', 'o'), ('zul', 'ao')]

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Limit between 0 and 100

2008-10-27 Thread bearophileHUGS
(Sorry for the answering delay, Google groups is very slow.)

James:

>P.S. I don't understand a lot of what I have there, I got most of it from the 
>beginning tutorials and help sections. I have never programmed before, but 
>this is for a school assignment.<

You must understand what you do at school, otherwise it's just wasted
time, trust me. If you don't understand what you do, then it's better
to do something else, like fishing, or reading things you do
understand. Doing things like a robot eventually makes your brain
dumb. Do you like to become dumb?

You can't learn to program on the spot, but I suggest you to limit the
things you don't understand as much as possible.

And you can start a Python interpreter and try every single little
small thing you put into your program (and you can look for them into
the python documentation), so you can have an idea of what you are
doing. You may even try to read the notes/things your teacher may have
shown you.

What's float()?
What's raw_input()?
What's the purpose of the 'integer' variable?
What does break means, and what's its purpose there?

Maybe learning what exceptions are now it too much early, so it may be
better to not use that try-except at all, and just let your program
fail and give an error if you don't input something good. This way you
can reduce the things you don't understand. Better to show the teacher
a bare-bones program that you understand a little, than a refined
program that you don't understand at all.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: big objects and avoiding deepcopy?

2008-10-27 Thread bearophileHUGS
Robert Kern:
> This is similar to implementing "Undo" functionality in applications.<

In a quite-high-level language (like Python, but not necessarily in
Python itself) it may become eventually advantageous to add some (even
limited) built-in form of undo. Both to give a simpler way to
implement a undo functionality into user-level programs (that is to
implement the Undo command in a program with GUI), but more
importantly to help the programmer too in some more general
programming tasks.

So it's probably a feature we'll see in the next generation of high-
level languages, among few other features that today are missing in
Python (only sometimes missing for performance reasons).

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary

2008-10-27 Thread Scott David Daniels

Hendrik van Rooyen wrote:

...

You had Compilers!
You had Compiler Vendors!

When I was lad, we had nowt but raw hardware.
We had to sit in cold room, ears deafened by
whine of fan, clicking switches to load our
octal in computer. We just had error light...


You had octal!  We just had oscilloscope traces shifting up and down.
If there wasn't a metal mask over the oscilloscope with marks where
the bits were, we'd have been in a world of hurt.

--Scott David Daniels
[EMAIL PROTECTED]

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


Re: using modules in destructors

2008-10-27 Thread Scott David Daniels

[EMAIL PROTECTED] wrote:

It seems to me that deleting local instances before imported modules
would solve the problem. Is it not possible for the interpreter to get
this right? Or are there cases where this would break stuff.

It seems rather unpythonic for the __del__() method to become
unpredictable at exit.

What would you have different? How would you define the end of a
Python program?  Would all modules and globals remain, and then
darkness?  Would the modules get removed in alphabetical order?


The core of the problem is that there is ((and possibly can be)
no good definition of what happens after SystemExit leaves the
__main__ module.


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


Re: Ordering python sets

2008-10-27 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> Glenn Linderman:
> 
>> how does one create a key that corresponds to ascending integer followed
>> by descending character string?
> 
> (Others may have already answered you because Google groups is very
> slow.)
> 
 seq = [(10, "abb"), (5, "zul"), (5, "hal"), (2, "of")]
 sorted(seq, key=lambda (n,s): (-n, s), reverse=True)
> [(2, 'of'), (5, 'zul'), (5, 'hal'), (10, 'abb')]
> 
> A little harder question is how to create a key that corresponds to
> ascending string followed by descending string?
> 
> To do that you can sort the data two times, relying on the stable
> nature of the Python sort.
> 
> Another (silly?) solution may be to invent a "negate" function for
> strings too:
> 
 strneg = lambda txt: txt.translate(itable)
 itable = "".join(chr(i) for i in xrange(255, -1, -1))
 pairs = [('al', 'boo'), ('zul', 'ao'), ('al', 'den'), ('zul', 'o')]
 sorted(pairs, key=lambda (s1,s2): (s1, strneg(s2)))
> [('al', 'den'), ('al', 'boo'), ('zul', 'o'), ('zul', 'ao')]

Here's a class that can negate arbitrary values:

>>> class Neg(object):
... def __init__(self, value):
... self.value = value
... def __cmp__(self, other):
... return -cmp(self.value, other.value)
...
>>> pairs = [('al', 'boo'), ('zul', 'ao'), ('al', 'den'), ('zul', 'o')]
>>> sorted(pairs, key=lambda (s, t): (s, Neg(t)))
[('al', 'den'), ('al', 'boo'), ('zul', 'o'), ('zul', 'ao')]

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


Re: Improving interpreter startup speed

2008-10-27 Thread Terry Reedy

David Cournapeau wrote:

On Mon, Oct 27, 2008 at 2:36 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:

It this a theoretical problem or an actual one, that we might have other
suggestions for?


Any command line based on python is a real example of that problem.


No it is not.
The specific problem that you wrote and I responded to was

"Not if the startup is the main cost for a command you need to repeat 
many times. "


in a short enough period so that the startup overhead was a significant 
fraction of the total time and therefore a burden.


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


Re: Improving interpreter startup speed

2008-10-27 Thread Terry Reedy

James Mills wrote:

So instead of coming up with arbitary problems, why don't
we come up with solutions for "Improving Interpreter Startup Speeds" ?


The current developers, most of whom use Python daily, are aware that 
faster startup would be better.  2.6 and 3.0 start up quicker because 
the some devs combed through the list of startup imports to see what 
could be removed (or, in one case, I believe, consolidated).  Some were. 
 Anyone who is still itching on this subject can seek further 
improvements and, if successful, submit a patch.


Or, one could check the Python wiki for a StartUpTime page and see if 
one needs to be added or improved/updated with information from the 
PyDev list archives to make it easier for a new developer to get up to 
speed on what has already been done in this area and what might be done.


tjr

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


Re: Finding the instance reference of an object

2008-10-27 Thread Douglas Alan
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> I understand that Python's object and calling semantics are exactly the 
> same as Emerald (and likely other languages as well), and that both 
> Emerald and Python are explicitly based on those of CLU, as described by 
> by Barbara Liskov in 1979:
>
> "In particular it is not call by value because mutations of
> arguments performed by the called routine will be visible to the
> caller. And it is not call by reference because access is not
> given to the variables of the caller, but merely to certain
> objects."

It is quite true that Python's calling semantics are the same as
CLU's, and that CLU called these semantics "call by sharing".  It's
not quite true that CLU invented these calling semantics, however.
They were the calling semantics of Lisp long before CLU existed.  I'm
not sure that Lisp had a name for it, however.  Lisp people tended to
refer to all variable assignment as "binding".

I agree with those who object to calling the Python/CLU/Lisp calling
semantics as either "call by value" or "call by reference", which is
why I've been a bit dismayed over the years that the term "call by
sharing" hasn't caught on.  When this terminology is used, the meaning is
quite unambiguous.

It should be noted that many other mainstream languages now use call
by sharing.  It's not at all the least peculiar to Python.  Such
languages include Java, JavaScript, Ruby, C#, and ActionScript.

|>oug
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.6] print_function and unicode_literals cannot be used at the same time?

2008-10-27 Thread Terry Reedy

Gabriel Genellina wrote:
En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <[EMAIL PROTECTED]> 
escribió:



?? wrote:

Any ideas?
 Code 1:
 from __future__ import print_function, unicode_literals
import sys
print(type('HELLO, WORLD!'), file=sys.stderr)


You have to do each future import in a separate line:

 >>> from __future__ import unicode_literals
 >>> from __future__ import print_function
 >>> print(type(""), file=sys.stderr)



That's a bug, isn't it? The language reference explicitely allows it:
http://docs.python.org/reference/simple_stmts.html#future-statements


Yes, and Benjamin Peterson already submitted a patch because of this thread.
http://bugs.python.org/issue4209

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


redirection of standard output of a Python command to a Python variable

2008-10-27 Thread TP
Hi everybody,

I try to find a quick way to redirect the standard output of a Python
command (for example: print "message") to a python variable "foobar".
Ok, in this simple example, I could do foobar = "message", but in
fact 'print "message"' could be replaced by any Python function writing on
standard output.
I have googled on this subject.
To redirect to a variable, I could use a temporary file:

import sys
saveout = sys.stdout
fsock = open('out.log', 'w')
sys.stdout = fsock
print 'message'
sys.stdout = saveout
fsock.close()
fsock = open('out.log', 'r')
foobar = fsock.read()
fsock.close()
print "foobar= ", foobar

To redirect a system standard output directly to a variable (without
temporary file), I could do:

import os
f = os.popen("ls")
print f.read()
f.close()

But, how can I get the standard output of a Python command (print "message")
directly into a variable?

Thanks

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding Default Page Name using urllib2

2008-10-27 Thread M�ta-MCI (MVP)

Hi!


Can I do this in python?


No.
The "default page" is a property of the web-server ; and it is not 
client side.

Examples :
 for Apache, it's  index.html or index.htm ; but if PHP is installed, 
index.php is also possible.

 for APS, it's  init.htm   (between others possibilites).
 etc.

@-salutations
--
Michel Claveau



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


Re: big objects and avoiding deepcopy?

2008-10-27 Thread Terry Reedy

[EMAIL PROTECTED] wrote:

Robert Kern:

This is similar to implementing "Undo" functionality in applications.<


In a quite-high-level language (like Python, but not necessarily in
Python itself) it may become eventually advantageous to add some (even
limited) built-in form of undo.


Right now, I believe, one could develop an undo module with undolist and 
undodict classes that wrap instance mutations with an append to an 
undoinfo list.


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


Re: Finding the instance reference of an object

2008-10-27 Thread gooberts
On Oct 17, 5:39 pm, Joe Strout <[EMAIL PROTECTED]> wrote:
> On Oct 17, 2008, at 3:19 PM, Grant Edwards wrote:
>
> >> And my real point is that this is exactly the same as in every
> >> other modern language.
>
> > No, it isn't.  In many other languages (C, Pascal, etc.), a
> > "variable" is commonly thought of as a fixed location in memory
> > into which one can put values.  Those values may be references
> > to objects.
>
> Right, though not in languages like C and Pascal that don't HAVE the  
> notion of objects.  We really ought to stop bringing up those  
> dinosaurs and instead compare Python to any modern OOP language.
>
> >  In Python, that's not how it works.  There is no
> > "location in memory" that corresponds to a variable with a
> > particular name the way there is in C or Pascal or Fortran or
> > many other languages.
>
> No?  Is there any way to prove that, without delving into the Python  
> source itself?
>
> If not, then I think you're talking about an internal implementation  
> detail.


I think this "uncontrived" example addresses the C/Python difference
fairly directly (both were tested):
--
C:

struct {int a;} s1, s2;

int main()
{
   s1.a = 1;
   s2 = s1;

   printf("s1.a %d   s2.a %d\n", s1.a, s2.a);
   s1.a = 99;
   printf("s1.a %d   s2.a %d\n", s1.a, s2.a);
}

--
Python:

class mystruct:
pass

s1 = mystruct()
s1.a = 1
s2 = s1

print "s1.a %2d   s2.a %2d" % (s1.a,s2.a)
s1.a = 99
print "s1.a %2d   s2.a %2d" % (s1.a,s2.a)

---
C OUTPUT:
  s1.a  1   s2.a  1
  s1.a 99   s2.a  1

Python OUTPUT:
  s1.a  1   s2.a  1
  s1.a 99   s2.a 99

Note that in C (or C++) the value of s2.a remains unchanged, because
the VALUE of s1 (the contents of the memory where s1 resides) was
COPIED to the memory location of s2, and subsequently, only the VALUE
of s2.a was changed. In Python, s2.a is "changed" (but not really)
because it turns out that s2 is just another name for the object that
s1 pointed to.

So there is no programatically accessible "location in memory" that
corresponds to s1 or s2 in Python. There is only a location in memory
that corresponds to the object that s1 is currently pointing to. In C,
by contrast, there are definite locations in memory that correspond to
both variables s1 and s2, and those locations remain always separate,
distinct and unchanged throughout the execution of the program.

This is not an "implementation detail", it is a fundamental part of
each language. As C was an "improvement" on assembler, the variable
names have always just been aliases for memory locations (or
registers). You can see this in the output of any C/C++ compiler.

In Python, variables are just names/aliases for *references* to
objects, not names for the objects/values themselves. The variable
names themselves do not correspond directly to the objects' memory
locations. While yes, technically, it is true that those reference
values must be stored somewhere in memory, *that* is the
implementation detail. But is is not the *locations* of these
references (i.e., the locations of the Python *variables*) that are
copied around, it is the references themselves (the locations of the
Python *objects*) that are copied.

> > All that exists in Python is a name->object mapping.
>
> And what does that name->object mapping consist of?  At some level,  
> there has to be a memory location that stores the reference to the  
> object, right?

I think this is answered above, but just to drive it home, in Python
the memory locations of the variables themselves (an implementation
detail), which hold the references to the objects, are inaccessible .
In C/C++, by contrast, variable names correspond directly to memory
locations and objects, and you can easily find the addresses of
variables.

In C/C++, if you choose, you may have a variable that is itself a
reference/pointer to some other memory/object. In C, we would say that
the VALUE of that variable is the memory address of another object.
But you can, if you need to, get the address of the pointer variable,
which points to the *address* of the other object.

In Python, a variable is ONLY EVER a reference to an object. You
cannot get the address of a Python variable, only of a Python object.

Hope this clears things up.

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


[no subject]

2008-10-27 Thread janandith jayawardena

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


Simple print to stderr

2008-10-27 Thread RC

By default the print statement sends to stdout
I want to send to stderr

Try

print "my meeage", file=sys.stderr

I got

SyntaxError: invalid syntax


I try

print "my message", sys.stderr

But it still sent to stdout.
What is the syntax?

I wouldn't understand Python's manual





print([object, ...][, sep=' '][, end='n'][, file=sys.stdout])¶

Print object(s) to the stream file, separated by sep and followed by end. 
sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and 
written to the stream, separated by sep and followed by end. Both sep and end 
must be strings; they can also be None, which means to use the default values. 
If no object is given, print() will just write end.

The file argument must be an object with a write(string) method; if it is 
not present or None, sys.stdout will be used.


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


Re: Simple print to stderr

2008-10-27 Thread Matt Nordhoff
RC wrote:
> By default the print statement sends to stdout
> I want to send to stderr
> 
> Try
> 
> print "my meeage", file=sys.stderr
> 
> I got
>> SyntaxError: invalid syntax
> 
> I try
> 
> print "my message", sys.stderr
> 
> But it still sent to stdout.
> What is the syntax?
> 
> I wouldn't understand Python's manual



That's only in Python 3 (or 2.6 with the proper __future__ import).
Before that, print is a statement. You'd do it like this:

print >> sys.stderr, "whatever"

You should look at
,
not Python 3's documentation.
-- 
--
http://mail.python.org/mailman/listinfo/python-list


Re: redirection of standard output of a Python command to a Python variable

2008-10-27 Thread Gabriel Genellina
En Mon, 27 Oct 2008 16:03:45 -0200, TP <[EMAIL PROTECTED]>  
escribió:



Hi everybody,

I try to find a quick way to redirect the standard output of a Python
command (for example: print "message") to a python variable "foobar".
Ok, in this simple example, I could do foobar = "message", but in
fact 'print "message"' could be replaced by any Python function writing  
on

standard output.
I have googled on this subject.
To redirect to a variable, I could use a temporary file:

import sys
saveout = sys.stdout
fsock = open('out.log', 'w')
sys.stdout = fsock
print 'message'
sys.stdout = saveout
fsock.close()
fsock = open('out.log', 'r')
foobar = fsock.read()
fsock.close()
print "foobar= ", foobar


You are close - but instead of using a real file, look at the StringIO  
module [1]


import sys
from cStringIO import StringIO

old_stdout = sys.stdout
sys.stdout = stdout = StringIO()
print 'message'
sys.stdout = old_stdout
foobar = stdout.getvalue()
print "foobar= ", foobar

(In case you start playing with this and make a mistake, you can restore  
the original stdout from sys.__stdout__)


[1] http://docs.python.org/library/stringio.html

--
Gabriel Genellina

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


Re: Finding the instance reference of an object

2008-10-27 Thread Dale Roberts
On Oct 17, 5:39 pm, Joe Strout <[EMAIL PROTECTED]> wrote:
> On Oct 17, 2008, at 3:19 PM, Grant Edwards wrote:
>
> >> And my real point is that this is exactly the same as in every
> >> other modern language.
>
> > No, it isn't.  In many other languages (C, Pascal, etc.), a
> > "variable" is commonly thought of as a fixed location in memory
> > into which one can put values.  Those values may be references
> > to objects.
>
> Right, though not in languages like C and Pascal that don't HAVE the
> notion of objects.  We really ought to stop bringing up those
> dinosaurs and instead compare Python to any modern OOP language.
>
> >  In Python, that's not how it works.  There is no
> > "location in memory" that corresponds to a variable with a
> > particular name the way there is in C or Pascal or Fortran or
> > many other languages.
>
> No?  Is there any way to prove that, without delving into the Python
> source itself?
>
> If not, then I think you're talking about an internal implementation
> detail.


I think this "uncontrived" example addresses the (C/C++)/Python
difference fairly directly.
--
C:

struct {int a;} s1, s2;

int main()
{
   s1.a = 1;
   s2 = s1;

   printf("s1.a %d   s2.a %d\n", s1.a, s2.a);
   s1.a = 99;
   printf("s1.a %d   s2.a %d\n", s1.a, s2.a);
}

--
Python:

class mystruct:
pass

s1 = mystruct()
s1.a = 1
s2 = s1

print "s1.a %2d   s2.a %2d" % (s1.a,s2.a)
s1.a = 99
print "s1.a %2d   s2.a %2d" % (s1.a,s2.a)

---
C OUTPUT:
  s1.a  1   s2.a  1
  s1.a 99   s2.a  1

Python OUTPUT:
  s1.a  1   s2.a  1
  s1.a 99   s2.a 99

Note that in C (or C++) the value of s2.a remains unchanged, because
the VALUE of s1 (the contents of the memory where s1 resides) was
COPIED to the memory location of s2, and subsequently, only the VALUE
of s2.a was changed. In Python, s2.a is "changed" (but not really)
because it turns out that s2 is just another name for the object that
s1 pointed to.

So there is no programatically accessible "location in memory" that
corresponds to s1 or s2 in Python. There is only a location in memory
that corresponds to the object that s1 is currently pointing to. In C,
by contrast, there are definite locations in memory that correspond to
both variables s1 and s2, and those locations remain always separate,
distinct and unchanged throughout the execution of the program.

This is not an "implementation detail", it is a fundamental part of
each language. As C was an "improvement" on assembler, the variable
names have always just been aliases for memory locations (or
registers). You can see this in the output of any C/C++ compiler.

In Python, variables are just names/aliases for *references* to
objects, not names for the objects/values themselves. The variable
names themselves do not correspond directly to the objects' memory
locations. While yes, technically, it is true that those reference
values must be stored somewhere in memory, *that* is the
implementation detail. But is is not the *locations* of these
references (i.e., the locations of the Python *variables*) that are
copied around, it is the references themselves (the locations of the
Python *objects*) that are copied.

> > All that exists in Python is a name->object mapping.
>
> And what does that name->object mapping consist of?  At some level,
> there has to be a memory location that stores the reference to the
> object, right?

I think this is answered above, but just to drive it home, in Python
the memory locations of the variables themselves (an implementation
detail), which hold the references to the objects, are inaccessible .
In C/C++, by contrast, variable names correspond directly to memory
locations and objects, and you can easily find the addresses of
variables, and the addresses do not change, although the values can.

In C/C++, if you choose, you may have a variable that is itself a
reference/pointer to some other memory/object/array. In C, we would
say that the VALUE of that variable is the memory address of another
object. But you can, if you need to, get the address of the pointer
variable, which points to the *address* of the other object.

In Python, a variable is ONLY EVER a reference to an object. You
cannot get the address of a Python variable, only of a Python object.

Hope this clears things up.

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


Re: Finding the instance reference of an object

2008-10-27 Thread Joe Strout

On Oct 27, 2008, at 12:19 PM, [EMAIL PROTECTED] wrote:


I think this "uncontrived" example addresses the C/Python difference
fairly directly (both were tested):


That's correct, but of course, C is a decades-old language barely a  
step above assembler.  For a fair comparison, pick any modern OOP  
language, including the C derivatives (C++, Objective-C, Java), and  
compare a Python object to an object in that language, rather than to  
a struct.



In Python, variables are just names/aliases for *references* to
objects, not names for the objects/values themselves. The variable
names themselves do not correspond directly to the objects' memory
locations.


Exactly!  In C++, this would be like a pointer variable.  In Java, RB,  
or .NET, it's like an object reference.



While yes, technically, it is true that those reference
values must be stored somewhere in memory, *that* is the
implementation detail.


Agreed.  (And this was my point in response to someone arguing that no  
such location exists.)



But is is not the *locations* of these
references (i.e., the locations of the Python *variables*) that are
copied around, it is the references themselves (the locations of the
Python *objects*) that are copied.


Right.  The variables contain object references; these object  
references are copied (not referenced!) when you pass them into a  
function.  That's call by value.  In the case of an assignment, the  
reference is copied.



All that exists in Python is a name->object mapping.


And what does that name->object mapping consist of?  At some level,
there has to be a memory location that stores the reference to the
object, right?


I think this is answered above, but just to drive it home, in Python
the memory locations of the variables themselves (an implementation
detail), which hold the references to the objects, are inaccessible .


Right.  So too in Java, RB, .NET, etc.  Pointers are nasty.  But lack  
of pointers does not change the calling semantics.



In C/C++, by contrast, variable names correspond directly to memory
locations and objects, and you can easily find the addresses of
variables.


Hmm, no, the C++ equivalent of an object reference would be:

 SomeClass* foo;

In fact, many C++ programmers prefer to typedef a pointer to each  
class, since it's the pointer (which is rough equivalent of a  
reference in newer languages) that you almost always want, rather than  
the class itself.  So it would actually be:


 SomeClassPtr foo;

Now, when you do:

 foo2 = foo;

you are copying the object reference from foo to foo2, just as in  
Python.  When you pass it into a function:


 void NiftyMethod(SomeClassPtr arg) {...}
 ...
 NiftyMethod(foo);

You are copying the object reference right onto the call stack.  This  
is pass by value, plain and simple.  And because it is pass by value,  
you know that nothing NiftyMethod does can possibly change the value  
of foo -- that is, can make it point at something else.  (It may well  
change the data that the object it points to contains, if SomeClass  
objects are mutable, but it can't change foo itself.)  This is, again,  
just like Python and every other OOP language.


Call by reference would be this:

 void NiftyMethod2(SomeClassPtr &arg) {...}
 ...
 NiftyMethod2(foo);

Now, arg here is passed by reference (just like a ByRef parameter in  
RB or .NET).  That means that NiftyMethod2 could very well change the  
value that is passed in.  It could actually make foo point to  
something else.


No Python method can do that, because Python arguments are ALWAYS  
passed by value.  There is no call by reference in Python.  Period,  
end of story, nothing to see here.


Cheers,
- Joe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Proposal for thread-safe Tkinter

2008-10-27 Thread Steve Holden
Allen Taylor wrote:
> I was given the task of upgrading a Python/Tkinter GUI application to
> the latest versions of Python and Tk. After a while, I realized that the
> application had not been written in a thread-safe manner. Multiple
> threads would simply use the Tk object directly. The application
> apparently ran fine (i.e., didn't crash!) using older versions of Python
> (2.2) and Tk (8.3), but it started to have serious problems (i.e.,
> crashing) after using the latest versions.
>  
> The problem is that there isn't enough budget to fix the whole
> application. So, I invested a bit of time to develop mtTkinter, a
> thread-safe version of Tkinter. Importing mtTkinter actually modifies
> the original Tkinter in such a way to make it thread-safe, recognizing
> and diverting out-of-thread calls to the Tk object creation thread via a
> queue and an 'after' event. I think it works quite well, requiring
> basically no changes to the application other than to import mtTkinter
> instead of (or in addition to) Tkinter. Even packages that use Tkinter
> (e.g., Pmw) benefit.
>  
> I would like to contribute this module (single file, about 160 lines) to
> the Python community, but I don't know how. I'm new to Python and am not
> initiated in the deep Pythonic developer world. Can someone give me some
> pointers? Many thanks.
>  
You can publish it in the Python package index - see

  http://pypi.python.org/pypi/

If you want to have it considered for inclusion into future versions of
Python then you should post a bug to bugs.python.org wiht your patch as
an attachment and the test of the above mail as a rationale for the change.

Thanks for going to these lengths to contribute!

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Pydev 1.3.24 Released

2008-10-27 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.24 have been released

This is a high-priority release to fix some blocker bugs (that's why
it was released in such a short time from the last release)

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

Code-analysis: Import was not recognized on code-analysis on some specific cases

Release Highlights in Pydev:
--

* Code-completion: when a relative import was used from __init__ and
the imported module used a token from the __init__ in a 'full' way,
pydev did not recognize it
* Debugger: Fixed debugger halting problem
* Debugger and Jython: Debugger working with Jython (itertools and pid
not available)



What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

Aptana
http://aptana.com/python

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


RE: Web crawler on python

2008-10-27 Thread Support Desk


-Original Message-
From: James Mills [mailto:[EMAIL PROTECTED] 
Sent: Sunday, October 26, 2008 5:26 PM
To: sonich
Cc: python-list@python.org
Subject: Re: Web crawler on python

On Mon, Oct 27, 2008 at 6:54 AM, sonich <[EMAIL PROTECTED]> wrote:
> I need simple web crawler,
> I found Ruya, but it's seems not currently maintained.
> Does anybody know good web crawler on python or with python interface?

Simple, but  it works. Extend it all you like.

http://hg.softcircuit.com.au/index.wsgi/projects/pymills/file/330d047ff663/e
xamples/spider.py

$ spider.py --help
Usage: spider.py [options] 

Options:
  --version show program's version number and exit
  -h, --helpshow this help message and exit
  -q, --quiet   Enable quiet mode
  -l, --links   Get links for specified url only
  -d DEPTH, --depth=DEPTH
Maximum depth to traverse

cheers
James

-- 
--
-- "Problems are solved by method"


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


Re: Ordering python sets

2008-10-27 Thread bearophileHUGS
Lie Ryan:

>Oh no, the two dict implementation would work _exactly_ the same from the 
>outside, they are transparently interchangeable. Only the performance 
>characteristic differs because of the different implementation.<

I don't agree with the general idea. If the operations done by your
data structure have different computational complexity, then they are
fit for different usages. When you program you must know what
computational complexity has each of the operations of your data
structyre, otherwise there's no way to know the complexity of your
whole program, so instead of programming you are just become a mage
that tries magical spells and hopes for the better. So I don't accept
so much different data structures to have the same name. That's why
I'll never appreciate the Python list type to be named list instead of
array, despite it supports more or less all the functions you expect
from an abstract list type.

Said that, for a high-level language like Python I can see another
possible solution. To have a type that contains several kinds of data
structures, for example a "dict" that contains a hash implementation,
a red-black tree, etc. Such data structure can use a small part of the
computational power given to it to collect statistics usages of each
object (or each variable, that may contain in succession several
ojects of the same type). Such data structure can then at run time
adapt dynamically, chosing to use the implementation fitter for the
specific usage of each object or variable (the programmer can give
hints of course, or sometimes even coerce the usage a specific
implementation). (such statistics can also be saved on disk to be used
for the successive run of the program, to help them work well from the
start too, and not just after a while). If this capability works well
in practice, then it can solve the problem you were talking about, I
think.

I presume data structures in future high-level languages will be quite
more able to adapt themselves to their usages. Today it's the second
time I talk about future programming languages :-)

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Unpacking byte strings from a file of unknown size

2008-10-27 Thread Mark
Hi;

I'm trying to use the struct.unpack to extract an int, int, char
struct info from a file.  I'm more accustomed to the file.readlines
which works well in a 'for' construct (ending loop after reaching
EOF).

# This does OK at fetching one 10-byte string at a time:
# (4, 4, 2 ascii chars representing hex)
info1, info2, info3 = struct.unpack('http://mail.python.org/mailman/listinfo/python-list


Re: example for PEP 342

2008-10-27 Thread Terry Reedy

Severin wrote:

Hello,

Is there a simple example demonstrating how to use the Trampoline from 
PEP 342 (http://www.python.org/dev/peps/pep-0342/)?


In the examples section toward the end
  3. A simple co-routine scheduler or "trampoline" that lets
   coroutines "call" other coroutines by yielding the coroutine
   they wish to invoke. ...

I did not read if yet to see if it can be further simplified.

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


Converting a time string to a more readable date, time

2008-10-27 Thread Thierry Lam
I have a python time string which has the following value:

1225137896

The above corresponds to 2008/10/27 16:04:56

What can I use to convert 1225137896 to a more readable date, time
format?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python barcode decoding

2008-10-27 Thread Robocop
On Oct 24, 1:24 pm, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> On Oct 24, 12:05 pm, Robocop <[EMAIL PROTECTED]> wrote:
>
> > Does anyone know of any decent (open source or commercial) python
> >barcoderecognition tools or libraries.  I need to read barcodes from
> > pdfs or images, so it will involve some OCR algorithm.  I also only
> > need to read the code 93 symbology, so it doesn't have to be very
> > fancy.  The most important thing to me is that it outputs in some
> > python friendly way, or ideally that it is written in python.  Any
> > tips would be great!
>
> The closest thing I've heard of is the bar code stuff in reportlab.
> This post talks a little about it:
>
> http://mail.python.org/pipermail/python-list/2000-February/024893.html
>
> And here's the official Reportlab site 
> link:http://www.reportlab.org/downloads.html
>
> Mike

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


Re: Python barcode decoding

2008-10-27 Thread Robocop
On Oct 24, 1:24 pm, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> On Oct 24, 12:05 pm,Robocop<[EMAIL PROTECTED]> wrote:
>
> > Does anyone know of any decent (open source or commercial) python
> > barcode recognition tools or libraries.  I need to read barcodes from
> > pdfs or images, so it will involve some OCR algorithm.  I also only
> > need to read the code 93 symbology, so it doesn't have to be very
> > fancy.  The most important thing to me is that it outputs in some
> > python friendly way, or ideally that it is written in python.  Any
> > tips would be great!
>
> The closest thing I've heard of is the bar code stuff in reportlab.
> This post talks a little about it:
>
> http://mail.python.org/pipermail/python-list/2000-February/024893.html
>
> And here's the official Reportlab site 
> link:http://www.reportlab.org/downloads.html
>
> Mike

I appreciate the effort, but that looks to be for generation of
barcodes if i'm not mistaken.  What i'm looking for is a barcode
DECODER, not an ENCODER (i'm currently using the purepostscript
barcode script for generation, very slick stuff), so i'm looking for
something along the lines of some barcode specific OCR libraries.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unpacking byte strings from a file of unknown size

2008-10-27 Thread Steven Clark
On Mon, Oct 27, 2008 at 4:29 PM, Mark <[EMAIL PROTECTED]> wrote:
> Hi;
>
> I'm trying to use the struct.unpack to extract an int, int, char
> struct info from a file.  I'm more accustomed to the file.readlines
> which works well in a 'for' construct (ending loop after reaching
> EOF).
>
> # This does OK at fetching one 10-byte string at a time:
> # (4, 4, 2 ascii chars representing hex)
> info1, info2, info3 = struct.unpack('
> # Now to do the entire file, putting into a loop just gives error:
> # TypeError: 'int' object is not iterable
> for info1, info2, info3 in struct.unpack('
> In trying to shoehorn this into a 'for' loop I've been unsuccessful.
> I also tried other variations that also didn't work but no point
> wasting space.  Using Python 2.5, WinXP
>
> Thx,
> Mark
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I usually do something like:
s = myfile.read(10)
while len(s) == 10:
info1, info2, info3 = struct.unpack('http://mail.python.org/mailman/listinfo/python-list


Re: Converting a time string to a more readable date, time

2008-10-27 Thread Benjamin Kaplan
On Mon, Oct 27, 2008 at 4:45 PM, Thierry Lam <[EMAIL PROTECTED]> wrote:

> I have a python time string which has the following value:
>
> 1225137896
>
> The above corresponds to 2008/10/27 16:04:56
>
> What can I use to convert 1225137896 to a more readable date, time
> format?
> --


>>> from datetime import datetime
>>> d = datetime.fromtimestamp(1225137896)
>>> print d
2008-10-27 16:04:56
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering python sets

2008-10-27 Thread Carl Banks
On Oct 25, 4:58 am, Lie Ryan <[EMAIL PROTECTED]> wrote:
> On Wed, 22 Oct 2008 10:43:35 -0700, bearophileHUGS wrote:
> > Mr.SpOOn:
> >> Is there another convenient structure or shall I use lists and define
> >> the operations I need?
>
> > 
> > As Python becomes accepted for more and more "serious" projects some
> > more data structures can eventually be added to the collections module:
> > - SortedSet, SortedDict: can be based on red-black trees. Require items
> > to be sortable (them being hashable isn't required, but it's probably
> > more safe that they are immutable). - Odict: a dict ordered according to
> > insertion order. - Bidict: a unordered dict that allows O(1) retrieval
> > on both keys and values (that are both unique).
> > - Graph: a directed unsorted data structure like mine may be acceptable
> > too.
> > - Bitset: dynamically re-sizable and efficient in space and time, easy
> > to implement in C.
> > - Chain: simulates a double linked list, but its implementation can be
> > similar to the current Deque but allowing not completely filled blocks
> > in the middle too. (I haven't named it just List because there's a name
> > clash with the list()).
> > - I use all those data structures in Python programs, plus some more,
> > like interval map, trie (and a dawg), persistent dict and persistent
> > list, kd-tree, BK-tree, Fibonacci Heap, a rank & select, a disjoint-
> > set, and maybe more. But those are uncommon enough to be left out of a
> > standard library.
> > - A problem with the Chain data structure is how to represent iterators
> > in Python. I think this is a big problem, that I don't know how to solve
> > yet. A possible solution is to make them owned by the Chain itself, but
> > this makes the code slow down linearly in accord to the number of the
> > iterators. If someone has a solution I'm all ears. 
>
> > Bye,
> > bearophile
>
> 
> Since python is dynamic language, I think it should be possible to do
> something like this:
>
> a = list([1, 2, 3, 4, 5], implementation = 'linkedlist')
> b = dict({'a': 'A'}, implementation = 'binarytree')
> c = dict({'a': 'A'}, implementation = 'binarytree')

-1

This doesn't buy you anything over simply implementing different types
altogether.

a = collections.linkedlist([1,2,3,4,5])
b = collections.btree({'a': 'A'})

In fact, it adds a whole lot of complexity to the built-in types.


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


Re: Linq to Python

2008-10-27 Thread Duncan Booth
"Tim Rowe" <[EMAIL PROTECTED]> wrote:

>> I haven't yet had occasion to use LINQ in anger yet, so I have no
>> idea whether its an idea to love or to hate. I do think it is good
>> that C# has effectively sprouted list comprehensions (not to mention
>> anonymous types and type inferencing) and I expect there may be some
>> aspects worth looking at for Python but I think they are more likely
>> to lead to itertools functions than extensions to syntax.
> 
> Yes, looking at what LINQ adds to C# (according to
> http://msdn.microsoft.com/en-gb/library/bb397909.aspx):
> - Implicitly typed variables: Python already has.
> - Object and collection initialisers: Not sure whether Python can do
> this directly, but it can certainly emulate it with a dictionary.
> - Anonymous types: Not sure whether Python can do this directly, but
> it can certainly emulate it with a dictionary.
> - Extension methods: Python already has.
> - Lambda expressions: Python already has.
> - Auto-Implemented properties: No, but that's just syntactic sugar to
> make declarations more compact.
> 
> So all of the language elements that are needed for LINQ are already
> in Python; a library should do the trick.
> 
Not quite. The C# implementation of lambda expressions has a neat trick 
that is central to LINQ. A lambda expression compiles either to executable 
code, or to an expression tree. If you are filtering some C# sequence 
object then (as with Python lambdas) the LINQ code simply calls the 
compiled lambda expression like any other delegate, but if you are 
filtering a SQL lookup the LINQ code gets an expression syntax tree and 
further compiles it (at runtime) into SQL code to perform the filtering at 
the database level.

Python can't do the compile time matching to vary what it produces 
according to how the lambda is used, but it would be perfectly possible for 
function objects which are compiled from a lambda expression to grow an 
extra attribute that would hold an AST for the expression. That way you 
could write code that took a filter function and, if it had the AST 
attribute available, compiled it to SQL or xpath or whatever else you 
fancied.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-27 Thread Terry Reedy

[EMAIL PROTECTED] wrote:

On Oct 17, 5:39 pm, Joe Strout <[EMAIL PROTECTED]> wrote:

On Oct 17, 2008, at 3:19 PM, Grant Edwards wrote:



No, it isn't.  In many other languages (C, Pascal, etc.), a
"variable" is commonly thought of as a fixed location in memory
into which one can put values.  Those values may be references
to objects.


In particular, memory is a linear sequence of writable cells.  In Turing 
machines, they have no address, and access is by one-at-a-time movement. 
 Subsequently, cells were given count addresses 0, 1, 2, ... .


Right, though not in languages like C and Pascal that don't HAVE the  
notion of objects.  We really ought to stop bringing up those  
dinosaurs and instead compare Python to any modern OOP language.



 In Python, that's not how it works.  There is no
"location in memory" that corresponds to a variable with a
particular name the way there is in C or Pascal or Fortran or
many other languages.

No?  Is there any way to prove that,


The burden of proof is on those who claim a positive.  Grant and I claim 
that there is no pink elephant in the room, and that we have looked 
around pretty thoroughly.  You claim that there is.  Show us what we missed.


Anyway, suppose you read and execute "L123 = [1,2,3]".  You can, I 
presume, perform any list method on that object.  Where is it?  Some 
memory theories say 'distributed, nowhere in particular'.  Others say 
'concentrated, some particular neurons', but certainly nothing like the 
'where' of linear computer memory.  Consider another object s = 'boo'. 
Which has the lower address?


>> without delving into the Python source itself?

Python, the abstract information algorithm language, has no 'source', 
only a specification of syntax and semantics.  The CPython source is the 
source for a particular computer machine implementation.  Any such 
implemetation has to map abstractly locationless objects to particular 
blocks of computer memory without adding extraneous, Python-accessible 
semantics, such as relative position.


If not, then I think you're talking about an internal implementation  
detail.


I think *you* are.  Giving Python objects an integer address is an 
(optional) implementation detail.  Giving them a *fixed* integer address 
is an optional CPython detail that makes certain aspects of the code 
easier but which prevents re-locating garbage collection (which I 
believe Jython does).


Anyone is free to view Python as only a linear-memory computer 
programming language (and, in some respects, as that, inferior to C). 
However, I have also viewed it as an algorithm language and, as a 
beginner (about 10 years ago), quickly dubbed it 'executable pseudocode' 
(and in that respect, much superior to C).


Terry Jan Reedy

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


Re: FTP via web browser

2008-10-27 Thread Diez B. Roggisch

rodmc schrieb:

Hi,

I have posted elsewhere about a related topic. But I an curious is it
possible to set up a web form which people select a file for upload
which is then upload it via FTP protocol to the web server - the
entire process must be web based and not require an external FTP
client. The reason for asking is that uploading large files via HTTP
form post is very unreliable beyond say 20MB.


No, it's not possible.


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


Re: Unpacking byte strings from a file of unknown size

2008-10-27 Thread Gabriel Genellina
En Mon, 27 Oct 2008 19:03:37 -0200, Steven Clark  
<[EMAIL PROTECTED]> escribió:



On Mon, Oct 27, 2008 at 4:29 PM, Mark <[EMAIL PROTECTED]> wrote:

Hi;

I'm trying to use the struct.unpack to extract an int, int, char
struct info from a file.  I'm more accustomed to the file.readlines
which works well in a 'for' construct (ending loop after reaching
EOF).

# This does OK at fetching one 10-byte string at a time:
# (4, 4, 2 ascii chars representing hex)
info1, info2, info3 = struct.unpack('

I usually do something like:
s = myfile.read(10)
while len(s) == 10:
info1, info2, info3 = struct.unpack('

Pretty clear. Another alternative, using a for statement as the OP  
requested (and separating the "read" logic from the "process" part):


def chunked(f, size):
while True:
block = f.read(size)
if not block: break
yield block

for block in chunked(open(filename, 'rb'), 10):
info1, info2, info3 = struct.unpack('(rather unreadable, I admit, if one isn't familiar with partial functions  
and the 2-argument iter variant)


--
Gabriel Genellina

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


Re: Unpacking byte strings from a file of unknown size

2008-10-27 Thread Terry Reedy

Mark wrote:

Hi;

I'm trying to use the struct.unpack to extract an int, int, char
struct info from a file.  I'm more accustomed to the file.readlines
which works well in a 'for' construct (ending loop after reaching
EOF).


You do not need .readlines to iterate through a file by lines.
  for line in f.readlines():pass
is awkward if you have 100million 100 byte lines, whereas
  for line in f: pass
will read one line at a time and process before reading the next.



# This does OK at fetching one 10-byte string at a time:
# (4, 4, 2 ascii chars representing hex)
info1, info2, info3 = struct.unpack('

for loops require an iterator.  Files only come with one.  So either use 
a while loop or define a reusable file-block generator (untested):


def blocks(openfile, n):
  while True:
block = openfile.read(n)
if len(block) == n:
  yield block
else:
  raise StopIteration

Terry Jan Reedy

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


Re: Type feedback tool?

2008-10-27 Thread Martin Vilcans
Thanks everyone for the suggestions. I've implemented a simple
solution using sys.settrace. It's quite nice because it doesn't
require any instrumentation of the code (it works like a debugger that
traps all function calls).

Here's the output I get right now when "profiling" Skip's example code
(but without using decorators):

fib2 (testee.py:8)
1 arguments
  n:  (1)  (23)

main (testee.py:17)
0 arguments

fib (testee.py:1)
1 arguments
  n:  (9)  (15)

This means that fib2 has been called once with a float in the n
parameter, and 23 times with an int, etc.

There's more work to be done to make this a robust tool (which is why
I was hoping there already existed a tool for this). It should handle
varargs and keyword arguments properly, and probably needs to handle
exceptions better. I'll see if I can run it on real code tomorrow and
see if the results are useful.

Martin

On Mon, Oct 27, 2008 at 11:50 AM, M.-A. Lemburg <[EMAIL PROTECTED]> wrote:
> On 2008-10-26 13:54, Martin Vilcans wrote:
>> Hi list,
>>
>> I'm wondering if there's a tool that can analyze a Python program
>> while it runs, and generate a database with the types of arguments and
>> return values for each function. In a way it is like a profiler, that
>> instead of measuring how often functions are called and how long time
>> it takes, it records the type information. So afterwards, when I'm
>> reading the code, I can go to the database to see what data type
>> parameter "foo" of function "bar" typically has. It would help a lot
>> with deciphering old code.
>>
>> When I googled this, I learned that this is called "type feedback",
>> and is used (?) to give type information to a compiler to help it
>> generate fast code. My needs are much more humble. I just want a
>> faster way to understand undocumented code with bad naming.
>
> You could try the trace module:
>
>http://www.python.org/doc/2.5.2/lib/module-trace.html
>
> but I'm not sure whether that includes parameter listings.
>
> Or write your own tracing function and then plug it into your
> application using sys.settrace():
>
>http://www.python.org/doc/2.5.2/lib/debugger-hooks.html#debugger-hooks
>
> The frame object will have the information you need:
>
>http://www.python.org/doc/2.5.2/ref/types.html#l2h-143
>
> in f_locals.
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Source  (#1, Oct 27 2008)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
> 
>
>  Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 
>
>
>   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>   Registered at Amtsgericht Duesseldorf: HRB 46611
>



-- 
[EMAIL PROTECTED]
http://www.librador.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a time string to a more readable date, time

2008-10-27 Thread Scott David Daniels

Thierry Lam wrote:

I have a python time string which has the following value:
1225137896
The above corresponds to 2008/10/27 16:04:56
What can I use to convert 1225137896 to a more readable date, time
format?


(1) Read Smart Questions [you could at least have told us where this
number came from.]
(2) give system name and version and python version info.
And finally (hoping it doesn't reward you too much for skipping steps):
  Look in the time module documents for localtime, gmtime, and strftime.

--Scott David Daniels
[EMAIL PROTECTED]

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


question about the textwrap module

2008-10-27 Thread TP
Hi everybody,

Recently, I have tried to improve the look of the printed text in command
line. For this, I was compelled to remove redundant spaces in strings,
because in my scripts, often the strings are spreading on several lines.

For example, "aaa   bbb" had to be transformed in "aaa bbb".
I have coded some simple functions to do that.

Today, by examining Python documentation, I have found an interesting
module:

http://www.python.org/doc/2.5.2/lib/module-textwrap.html

But, I haven't found any way to do my redundant space deletion with this
module? Am I right?

Thanks

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-27 Thread Steven D'Aprano
On Mon, 27 Oct 2008 13:11:04 -0600, Joe Strout wrote:

> On Oct 27, 2008, at 12:19 PM, [EMAIL PROTECTED] wrote:
> 
>> I think this "uncontrived" example addresses the C/Python difference
>> fairly directly (both were tested):
> 
> That's correct, but of course, C is a decades-old language barely a step
> above assembler.

So what? It's not like C is no longer in common use.

And even if C had disappeared off the landscape, there are millions of 
programmers, including beginning programmers, whose understanding of 
terms CBR and CBV are defined by the behaviour of languages like C and 
Pascal -- even if they haven't learned either language themselves.


> For a fair comparison, pick any modern OOP language,
> including the C derivatives (C++, Objective-C, Java), and compare a
> Python object to an object in that language, rather than to a struct.

But we already know that many such languages use the exact same calling 
convention as Python, so all you would be showing is that languages with 
the same calling convention as Python have the same calling convention as 
Python.

By common usage and technical definition, C is call by value. Argument 
passing in Python does not behave like C. So why insist that Python is 
also call by value?

[snip]

>> While yes, technically, it is true that those reference values must be
>> stored somewhere in memory, *that* is the implementation detail.
> 
> Agreed.  (And this was my point in response to someone arguing that no
> such location exists.)

Obviously any computer which is based on the Von Newman architecture of 
CPU plus memory is going to store the reference *somewhere*. That's a 
detail unimportant at the Python level. But since clockwork or Conway's 
"Life" cellular automata are both Turing complete, it would be possible 
to build a Python implementation where the reference values weren't 
localised to a particular place in memory, but distributed over the 
system. 


>> But is is not the *locations* of these references (i.e., the locations
>> of the Python *variables*) that are copied around, it is the references
>> themselves (the locations of the Python *objects*) that are copied.
> 
> Right.  The variables contain object references; these object references
> are copied (not referenced!) when you pass them into a function.  That's
> call by value.  In the case of an assignment, the reference is copied.

The value of a Python name is the Python object assigned to it, not an 
arbitrary memory location that points to the object. Even you would 
consider it obfuscatory if I executed this code:

x = "Norwegian Blue"

and then insisted that the value of x was "3086179808L, but if I run that 
line of code again it could get another value, and naturally if you run 
it on your computer you're almost certain to get a different value".

By your definition of "value=reference", the above is perfectly correct, 
and utterly, completely pointless, useless and unhelpful. It's rather 
like listing the ingredients of a cake as "Atoms". Technically true, but 
missing the point.



[snip]
> You are copying the object reference right onto the call stack.  This is
> pass by value, plain and simple.

Who *cares* about copying the pointers? That's the WRONG LEVEL. 
Ultimately EVERY programming language that runs on a computer with memory 
is "Copy By Bit Flipping", but it would be useless and unhelpful to tell 
people that every programming language uses the exact same calling 
conventions: "bits are flipped, and that's the end of story".


[snip]
> No Python method can do that, because Python arguments are ALWAYS passed
> by value.  There is no call by reference in Python.

Except that for millions of programmers who have learnt their terminology 
from Pascal and C, that implies that the values -- the data itself, not 
pointers to the data -- are copied. It implies that this can never fail:

x = [1]
y = function(x)
assert x == [1]

but of course it can fail, if function modifies x -- something which CBV 
implies can't happen.



> Period, end of story, nothing to see here.

I think that this entire argument hinges on the poverty of your mental 
toolbox. You have a hammer (call by value) and a screwdriver (call by 
reference) and refuse to accept that there could possibly be any other 
calling model. Hence you force any actual calling model into the 
framework of CBV or CBR, no matter how much violence you have to do to 
simple terms like "value" to make it fit.


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


Re: Porting VB apps to Python for Window / Linux use

2008-10-27 Thread Steven D'Aprano
On Mon, 27 Oct 2008 12:31:06 +1100, Ben Finney wrote:

> Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
> 
>> Software has no market value. Business models that try to assign it one
>> are doomed to fight an uphill battle against market forces.
> 
> +1 QOTW.

-1

That quote confuses the *cost* of duplicating software (which is close 
enough to zero) with the *value* put on the software by the market (the 
users). We can see that, for example, Ben Finney himself puts quite a lot 
of value on software such as emacs. Just recently Ben wrote (paraphrased) 
that he valued emacs because although he wasn't a Lisp programmer, other 
programmers had already produced many fine emacs tools that let him be a 
more productive developer. Now Ben is agreeing with the statement that he 
doesn't value software, that he considers emacs and other such tools mere 
commodities and is indifferent to which he uses, or even whether he uses 
any at all. That's clearly untrue, and I can only imagine it is because 
Ben doesn't understand what it means for a product, service or thing to 
have no market value. No value is not the same as priceless, and I 
imagine Ben would agree that freedom to modify the source code of emacs 
is virtually priceless.

Should distribution costs rise (say, because the Australian government's 
compulsory web censorship plan "accidentally" block all free software -- 
it must be warez if it's free, right?) then would it really be 
inconceivable that people in Australia who valued emacs over (say) 
Microsoft Notepad would be willing to pay for reliable, uncensored copies 
of the software?

Plenty of people pay for free software. Some of them pay with money, some 
of them pay with development effort, some of them with both. Unless my 
memory is playing tricks on me, I believe that Ben himself has purchased 
Ubuntu CDs with real money; and if he hasn't, I can assure you that his 
employer has.

I can only imagine that what Lawrence was trying to say was something on 
the lines of this: open source software reduces the ability of vendors to 
extract monopoly rents from software by turning each software application 
itself into a commodity. It's not just that there are a thousand 
different text editors from a thousand suppliers that Ben could use, but 
that there are a thousand suppliers entitled to distribute emacs itself, 
and competition between those suppliers ensure that the cost of emacs 
approaches the marginal cost of duplication and distribution, which is 
essentially zero.

(The corollary of this is that to avoid such commoditization, software 
vendors need the government to enforce an artificial monopoly on each 
product. That's not necessarily a bad thing, although it often is.)

It's not as snappy as saying that Ben and others like him don't value 
software, but it's more accurate.



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


Re: Finding the instance reference of an object

2008-10-27 Thread Chuckk Hubbard
I'm sorry to say I'm pretty confused by the example, but if you want
something like

bob = module.object()
frank = module.object()
and then to know that bob is bob from a list of instances, you could
instead do something like:

for person in listofnames:
 temp = module.object(person)
 list.append(temp)

where the __init__ function assigns the argument to object.nametag or
something.  This way you can retrieve the name from an index into the
list, or retrieve the index by searching for the name...
-Chuckk

On Thu, Oct 16, 2008 at 5:04 PM, Astley Le Jasper
<[EMAIL PROTECTED]> wrote:
> On 16 Oct, 16:52, Carsten Haese <[EMAIL PROTECTED]> wrote:
>> Astley Le Jasper wrote:
>> > Sorry for the numpty question ...
>>
>> > How do you find the reference name of an object?
>>
>> > So if i have this
>>
>> > bob = modulename.objectname()
>>
>> > how do i find that the name is 'bob'
>>
>> Why do you need to find that? You know that its name is 'bob'.
>>
>> --
>> Carsten Haesehttp://informixdb.sourceforge.net
>
> I'm creating mulitple instances, putting them in a list, iterating
> through the list to send them to some functions where process them
> with some instance specific parameters. Something along the lines of:
>
> bob = someobject()
> harry = someobject()
> fred = someobject()
>
> parameterdict = {'bob':(0,1,2),'harry':(3,4,5),'fred':(6,7,8)}
> people_list = (bob, harry, fred)
>
> for person in people_list:
>  add_parameters(person)
>
> def add_parameters(person)
>  mytuple = parameterdict[??instance.name]
>  person.x = mytuple[0]
>  person.y = mytuple[1]
>  person.z = mytuple[2]
>
> ... alternatively there is probably a very much easier way of doing
> it.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.badmuthahubbard.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: question about the textwrap module

2008-10-27 Thread Gabriel Genellina
En Mon, 27 Oct 2008 20:50:08 -0200, TP <[EMAIL PROTECTED]>  
escribió:



Recently, I have tried to improve the look of the printed text in command
line. For this, I was compelled to remove redundant spaces in strings,
because in my scripts, often the strings are spreading on several lines.

For example, "aaa   bbb" had to be transformed in "aaa bbb".
I have coded some simple functions to do that.

Today, by examining Python documentation, I have found an interesting
module:

http://www.python.org/doc/2.5.2/lib/module-textwrap.html

But, I haven't found any way to do my redundant space deletion with this
module? Am I right?


You may pre-process your text (stripping redundant whitespace) before  
using textwrap:


py> text = 'This  is some \t   text with  multiple\n\n  spaces.'
py> print textwrap.fill(text, width=20)
This  is
some  text with
multiplespaces.
py> import re
py> re.sub(r'\s+', ' ', text)
'This is some text with multiple spaces.'
py> t2 = _
py> print textwrap.fill(t2, width=20)
This is some text
with multiple
spaces.
py>

--
Gabriel Genellina

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


Looking for a pure python Mysql module

2008-10-27 Thread Carl
Does anyone know of a package that can connect and query a mysql server 
that is platform independent and does not need to compile any extra c 
modules (IE a pure python module)?

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


Database specialized in storing directed graphs?

2008-10-27 Thread Carl Banks
I was wondering if anyone had any advice on this.

This is not to study graph theory; I'm using the graph to represent a
problem domain.  The graphs could be arbitrarily large, and could
easily have millions of nodes, and most nodes have a substantial
amount of data associated with them.  Obviously I don't want a whole
such graph in memory at once, so libraries the just deal with in-
memory graphs are out.

I know I could implement this with a relational DB, and I'd be fine
with a library that was built on top of one.  But I'm hoping for
specialzed behavior useful for graphs.

For example, suppose I have a set of nodes called A.  It would be
useful to know if any of these nodes are connected by paths that
include no nodes in A.  I could, of course, do that by reading from
the database and following the paths, but I clearly don't want to do
that.  I would want instead to somehow cache the outside connectedness
relationship between different nodes of A.  But then what happens if
something changes elsewhere.  How is the cache for A notified, and can
it be updated efficiently using graph theorems, rather than
regenerated?

It's very tricky; that's why I hope someone else has done it.

I'm guessing no.


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


Re: Ordering python sets

2008-10-27 Thread greg

On approximately 10/27/2008 10:27 AM, came the following characters from
the keyboard of Peter Otten:


Here's a class that can negate arbitrary values

... def __init__(self, value):
... self.value = value
... def __cmp__(self, other):
... return -cmp(self.value, other.value)


Unfortunately, the __cmp__ method has been eliminated from
3.0 as well, so this won't work as-is. You would need to
override __lt__, __eq__, etc.

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


Re: Finding the instance reference of an object

2008-10-27 Thread greg

Steven D'Aprano wrote:

By common usage and technical definition, C is call by value. Argument 
passing in Python does not behave like C. So why insist that Python is 
also call by value?


Whether it behaves like C is not the test.

Let's look at the definitions of the terms:

(1) Call by value: The actual parameter is an expression. It is
evaluated and the result is assigned to the formal parameter.
Subsequent assignments to the formal parameter do not affect
the actual parameter.

(2) Call by reference: The actual parameter is an lvalue. The
formal parameter becomes an alias for the actual parameter,
so that assigning to the formal parameter has the same
effect as assigning to the actual parameter.

Seems to me that (1) describes exactly how parameter passing
works in Python. So why insist that it's *not* call by value?

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


Re: Finding the instance reference of an object

2008-10-27 Thread Dale Roberts
[I am actually enjoying this discussion, even though it does not address 
the OP's question. It is helping to solidify *my* understanding.]


Joe Strout wrote:

On Oct 27, 2008, at 12:19 PM, [EMAIL PROTECTED] wrote:


I think this "uncontrived" example addresses the C/Python difference
fairly directly (both were tested):


That's correct, but of course, C is a decades-old language barely a step 
above assembler.  For a fair comparison, pick any modern OOP language, 
including the C derivatives (C++, Objective-C, Java), and compare a 
Python object to an object in that language, rather than to a struct.


Okay, sorry, should have had C++ from the start. See my spiffed-up 
example here, where I magically convert to C++ by replacing "struct" 
with "class" and adding the word "public:". Still behaves the same, though.


I added the functions ByVal() and ByRef() to show that when you pass by 
value, the contents of the object cannot be changed. This is not 
possible in Python unless a copy of the object is made (which is what 
C++ does automatically for you in pass-by-value).


In Python, the contents of the object are changed, which is most similar 
to the pass by reference (or by pointer) construct in C++. But, yes, as 
you say, technically:


  passing the object by reference
   == passing the address of the object by value.

But I think that is, to most programmers, a surprising use of the term 
"pass by value".


And note in my example, nowhere do I explicitly take the address of s1. 
The compiler does this for me in the ByRef() case. And nowhere to I make 
a copy of s1. Again, the compiler does this for me in the ByVal() case. 
The calls to ByVal() and ByRef() are identical. You cannot tell from the 
calls which thing is going to happen.


---
class MyClass {public: int a;} s1, s2;

void ByVal(MyClass  obj) {obj.a=42;}
void ByRef(MyClass &obj) {obj.a=43;}

int main()
{
   s1.a = 1;
   s2 = s1;

   printf("s1.a %2d   s2.a %2d\n", s1.a, s2.a);

   s1.a = 99;
   printf("s1.a %2d   s2.a %2d\n", s1.a, s2.a);

   ByVal(s1);
   printf("s1.a %2d\n", s1.a);

   ByRef(s1);
   printf("s1.a %2d\n", s1.a);
}
--
class mystruct:
pass

def ByObject(obj): obj.a=42

s1 = mystruct()
s1.a = 1
s2 = s1

print "s1.a %2d   s2.a %2d" % (s1.a,s2.a)
s1.a = 99
print "s1.a %2d   s2.a %2d" % (s1.a,s2.a)

ByObject(s1)
print "s1.a %2d" % (s1.a)

--
C++ OUTPUT
s1.a  1   s2.a  1
s1.a 99   s2.a  1  # note s2.a does not change when s1.a is modified
s1.a 99# contents of s1.a does not change when passed by val
s1.a 43# it does change when passed by ref

Python OUTPUT
s1.a  1   s2.a  1
s1.a 99   s2.a 99  # s2.a "changes" because it's the same object as s1
s1.a 42# Contents of object does change with function call.

...and in Python, of course, as you say, what you call the "value" of 
s1, the address of the object, id(val), does not change.


>>
>> [skipping lots of stuff we agree on!]
>>

In C/C++, by contrast, variable names correspond directly to memory
locations and objects, and you can easily find the addresses of
variables.


Hmm, no, the C++ equivalent of an object reference would be:

 SomeClass* foo;


Whoah, nonsequitor there. Let's back up. I did not use the word 
"reference", and that is the point. And I am correct that C variable 
names correspond to memory locations (or sometimes CPU registers - 
optimizers can really mangle things). And you can get the addresses of 
the variables themselves using the & operator.


Have a look at my example code again. s1 and s2 ARE OBJECTS THEMSELVES, 
they are not references to objects. You can do this in C++ (not in 
Python). You can pass whole objects, by value (they are copied by the 
compiler), on the stack. And we both understand that you can't do that 
in Python. That is why we differentiate between "pass by reference" and 
"pass by value" in C++, and people generally understand what that means.


> ...

 void NiftyMethod2(SomeClassPtr &arg) {...}
 ...
 NiftyMethod2(foo);

Now, arg here is passed by reference (just like a ByRef parameter in RB 
or .NET).  That means that NiftyMethod2 could very well change the value 
that is passed in.  It could actually make foo point to something else.


No Python method can do that,


Yes, absolutely agreed. A Python method can never change *which* object 
the caller points to, it can only change the *contents* of that object.


But the same is true in C++ as well. In your example, the address of the 
foo variable itself can never be changed. You can change the *value* of 
foo (so it points to a different object), or you can change the contents 
of the object foo points to. foo is a variable with an address which you 
can usually see with a printf("%x", &foo), and that is different from 
the address of the object which you get when you say printf("%x", foo).


The value &foo cannot be changed.

because Python arguments are ALWAYS passed 
by value.  There is no call 

Re: PIL: Getting a two color difference between images

2008-10-27 Thread Kevin D . Smith

On 2008-10-25 12:41:51 -0500, [EMAIL PROTECTED] said:

Kevin D. Smith:
What I want is a two color output image: black where the image wasn't 
different, and white where it was different.<


There are several ways to do that. If speed isn't essential, then you
can create a third blank image of the right size, and then use the
method that iterates on the pixels of an image, and assign p1 != p2 at
every pixel of the third image.

If speed is important you can copy the images into numpy arrays and
then your operation becomes easy.

Maybe there are built-in ways in PIL too, I don't know. You can also
find an intermediate solution, like computing the difference image
with PIL and then binarize it manually.


This last method is what I ended up doing for now.  I use the PIL 
differencing function, then walk through the result of getdata() to 
binarize it.  I was hoping there might be a way to run a filter or 
something that might be faster, but I haven't figured it out.


--
Kevin D. Smith

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


Re: lxml removing tag, keeping text order

2008-10-27 Thread Tim Arnold
"Stefan Behnel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Tim Arnold schrieb:
>> Hi,
>> Using lxml to clean up auto-generated xml to validate against a dtd; I 
>> need
>> to remove an element tag but keep the text in order. For example
>> s0 = '''
>> 
>>first text
>> ladida
>> emphasized text
>> middle text
>> 
>> last text
>>   
>> '''
>>
>> I want to get rid of the  tag but keep everything else as it 
>> is;
>> that is, I need this result:
>>
>> 
>>first text
>> ladida
>> emphasized text
>> middle text
>> 
>> last text
>>   
>> 
>
> There's a drop_tag() method in lxml.html (lxml/html/__init__.py) that does
> what you want. Just copy the code over to your code base and adapt it as 
> needed.
>
> Stefan
Thanks Stefan, I was going crazy with this. That method is going to be quite 
useful for my project and it's good to learn from too; I was making it too 
hard.

thanks,
--Tim Arnold 


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


Re: Finding the instance reference of an object

2008-10-27 Thread Douglas Alan
greg <[EMAIL PROTECTED]> writes:

> Seems to me that (1) describes exactly how parameter passing
> works in Python. So why insist that it's *not* call by value?

Because there's an important distinction to be made, and the
distinction has been written up in the Computer Science literature
since Lisp first starting using the same argument passing semantics as
Python back in 1958.  The semantics are called "call by sharing".

Many mainstream programming languages other than Python now use call
by sharing.  They include Java, JavaScript, Ruby, ActionScript, and C#.

|>oug

P.S. Lisp didn't call it "call by sharing" -- Lisp called it
"binding".  The designers of CLU invented the term "call by sharing"
back in the 70s.  (Or at least I believe they invented the term.  They
certainly did use the term.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: project in python

2008-10-27 Thread alex23
On Oct 26, 2:51 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> The more you spam people with your repetitive postings, the less likely it
> becomes that they are willing to answer you.

In asit's defence, the Google Groups interface has been woefully
broken for the past 3-4 days. If e had posted via it, messages
wouldn't have been visible to em until today at the earliest.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-27 Thread Gabriel Genellina
En Tue, 28 Oct 2008 00:58:10 -0200, greg <[EMAIL PROTECTED]>  
escribió:



Steven D'Aprano wrote:

By common usage and technical definition, C is call by value. Argument  
passing in Python does not behave like C. So why insist that Python is  
also call by value?


Whether it behaves like C is not the test.

Let's look at the definitions of the terms:

(1) Call by value: The actual parameter is an expression. It is
 evaluated and the result is assigned to the formal parameter.
 Subsequent assignments to the formal parameter do not affect
 the actual parameter.

(2) Call by reference: The actual parameter is an lvalue. The
 formal parameter becomes an alias for the actual parameter,
 so that assigning to the formal parameter has the same
 effect as assigning to the actual parameter.

Seems to me that (1) describes exactly how parameter passing
works in Python. So why insist that it's *not* call by value?


Those definitions are only applicable to unstructured, primitive types,  
where the only relevant operations are "get value" and "assign value".
Structured types provide other operations too - like selection (attribute  
get/set in Python). It is unspecified on both definitions above what  
happens in those cases. Other posts in this same thread showed that Python  
behaves similarly to call-by-reference in C++ with regard to data members  
inside a structure (that is, mutable objects *can* be changed, and the  
caller sees the change). Combined with your previous conclusion that  
Python implements call-by-value, one should finally conclude that it can't  
be neither cbv nor cbr - it's a different thing.
The term "call by object" was coined in the late '70s to describe this  
behavior. More info about this ever-recurring topic can be found at  
http://effbot.org/zone/call-by-object.htm


--
Gabriel Genellina

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


Re: Looking for a pure python Mysql module

2008-10-27 Thread James Mills
On Tue, Oct 28, 2008 at 9:41 AM, Carl <[EMAIL PROTECTED]> wrote:
> Does anyone know of a package that can connect and query a mysql server that
> is platform independent and does not need to compile any extra c modules (IE
> a pure python module)?

There was a recent discussion on
this mailing list regarding this very
subject. Search for it.

cheers
James

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: ........ JUNGLE BUNNIES IN ALASKA ..........

2008-10-27 Thread Sydney Gondomer
On Sun, 15 May 2005 22:55:25 -0500, Michel Catudal
<[EMAIL PROTECTED]> wrote:

>Richard Keebler wrote:
>
> 
>
>
>I found the perfect site for assholes like you
>
>http://www.amishrakefight.org/gfy/

Are there any of GOD's frozen chosen beautiful African Americans on
this Alaska forum?

I would like to hear how they feel about living amongst so many
dangerous Caucasoid's. If you can speak up without worrying about
someone coming after you, what is it l like up there?

I have visited 47 states so far. the only ones I haven't seen are the
Dakotas and Alaska. I was thinking about vacationing up there, but
after reading this forum for a couple of days, I think I might have
more fun in the Republic of Panama instead.

So mote it be.





Come join, and participate NOW!!
Everything you ever wanted to know about politics,racism, White Supremacy, and 
religion,
but were afraid to ask! The largest discussion forums on the Internet and 
growing by the nanosecond!!

http://groups.yahoo.com/group/RACE_RACISM_AND_RELIGION_2008/

http://groups.yahoo.com/group/Race_Religion_Politics/

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


Re: Finding the instance reference of an object

2008-10-27 Thread Gabriel Genellina
En Tue, 28 Oct 2008 01:16:04 -0200, Dale Roberts <[EMAIL PROTECTED]>  
escribió:


So, then, what to tell a C++ programmer about how Python passes  
arguments? You say: tell them Python only passes by value. I disagree,  
because I think that would confuse them. Rather than try to map C++  
conventions onto Python, I think it is more useful to just tell them how  
it really works. Maybe a few statements like this:


   All values in Python are objects, from simple integers up to complex
   user-defined classes.

   An assignment in Python binds a variable name to an object. The
   internal "value" of the variable is the memory address of an object,
   and can be seen with id(var), but is rarely needed in practice.

   The "value" that gets passed in a Python function call is the address
   of an object (the id()).

   When making a function call, myfunc(var), the value of id(var) can
   never be changed by the function.

Not sure if these are the best. To get into much more detail, you have  
to start explaining mutable and immutable objects and such.


I don't think the above explanation is desirable, nor needed. Objects in  
Python don't have an "address" - it's just a CPython implementation  
detail. The fact that id() returns that address is just an implementation  
detail too. The calling mechanism should be explained without refering to  
those irrelevant details.


--
Gabriel Genellina

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