Re: How is memory managed in python?

2010-07-19 Thread Chris Rebert
On Mon, Jul 19, 2010 at 6:30 PM, Vishal Rana  wrote:
> Hi,
> In my web application (Django) I call a function for some request which
> loads like 500 MB data from the database uses it to do some calculation and
> stores the output in disk. I just wonder even after this request is served
> the apache / python process is still shows using that 500 MB, why is it so?
> Can't I release that memory?

http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm

There are multiple layers of memory allocation involved. To avoid
thrashing+fragmentation and to improve efficiency, free memory is not
always immediately returned to the operating system. Example: If your
problem involved calling your 500MB function twice, free-ing after the
first call and then immediately re-allocating another 500MB of memory
for the second call would waste time.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Different python versions confusion under Windows Vista x64

2010-07-19 Thread Edward Diener

On 7/19/2010 5:45 PM, Edward Diener wrote:

On 7/19/2010 9:15 AM, Alf P. Steinbach /Usenet wrote:

* Edward Diener, on 19.07.2010 14:53:

In Windows Vista x64 I have installed python 2.6 64-bit version and
python 3.1 64-bit version to separate folders. Within the command
interpreter I add python 2.6 to the PATH.

In the command interpreter, When I type python somescript.py with an

import sys
print (sys.version)

in the script, it shows:

3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)]

In the command interpreter if I type 'python' I see:

Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit
(AMD64)] on win32

Does anybody have any ideas why this is happening ?


At a guess your description of what's happening is not entirely accurate.

Although it could be, since Windows moves in mysterious ways.

Please try the following commands in sequence, with no other commands:

python -V
echo %path%
ftype python.file
python somescript.py

Then right-click the command interpreter's title bar to get edit menu.
/Mark/ the text of your commands and results. Then /copy/ it to the
clipboard (note: you can't use [Ctrl C] here, use the edit menu or just
press Enter). Then post the commands and results here, /paste/ them into
your message (e.g. [Ctrl V]).

And then, if you haven't already figured it out, somebody probably will.
:-)


I figured out the cause. One of the Python scripts started with:

#!Path/to/Python31Executable

which evidently caused python 3.1 to be called to run that script. I am
not sure that script was run via an 'import' statement, as opposed to a
'python someScript.py' within another script, but I suspect the latter.


No, this is incorrect. The cause had nothing to do with the above. It 
was because .py files were associated with the 3.1 version of Python, no 
Python folder was in the PATH, and a Pyhton script invoked python 
passing it a .py file. So even though the initial command specified the 
2.6 version of Python on a script, subsequent scripts were run using 
Python 3.1.


I since changed the association of .py files to the 2.6 version of 
Python and everything works correctly.

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


Re: How to pass the shell in Python

2010-07-19 Thread MRAB

Ranjith Kumar wrote:

Hi Folks,
 Can anyone tell me how to run shell commands using python script.


Use the 'subprocess' module.
--
http://mail.python.org/mailman/listinfo/python-list


How to pass the shell in Python

2010-07-19 Thread Ranjith Kumar
Hi Folks,
 Can anyone tell me how to run shell commands using python script.

-- 
Cheers
Ranjith,

http://ranjith10z.wordpress.com
-- 
http://mail.python.org/mailman/listinfo/python-list


How is memory managed in python?

2010-07-19 Thread Vishal Rana
Hi,

In my web application (Django) I call a function for some request which
loads like 500 MB data from the database uses it to do some calculation and
stores the output in disk. I just wonder even after this request is served
the apache / python process is still shows using that 500 MB, why is it so?
Can't I release that memory?

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


Re: Accumulate function in python

2010-07-19 Thread Joel Goldstick

Peter Otten wrote:

dhruvbird wrote:


  I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
  And would like to compute the cumulative sum of all the integers
from index zero into another array. So for the array above, I should
get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
  What is the best way (or pythonic way) to get this.


Homework?


def cumulative_sum(values, start=0):

... for v in values:
... start += v
... yield start
...

list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]))

[0, 1, 3, 4, 5, 5, 5, 7, 10]

Peter


nice! Peter

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


Re: Different python versions confusion under Windows Vista x64

2010-07-19 Thread Edward Diener

On 7/19/2010 9:15 AM, Alf P. Steinbach /Usenet wrote:

* Edward Diener, on 19.07.2010 14:53:

In Windows Vista x64 I have installed python 2.6 64-bit version and
python 3.1 64-bit version to separate folders. Within the command
interpreter I add python 2.6 to the PATH.

In the command interpreter, When I type python somescript.py with an

import sys
print (sys.version)

in the script, it shows:

3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)]

In the command interpreter if I type 'python' I see:

Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit
(AMD64)] on win32

Does anybody have any ideas why this is happening ?


At a guess your description of what's happening is not entirely accurate.

Although it could be, since Windows moves in mysterious ways.

Please try the following commands in sequence, with no other commands:

python -V
echo %path%
ftype python.file
python somescript.py

Then right-click the command interpreter's title bar to get edit menu.
/Mark/ the text of your commands and results. Then /copy/ it to the
clipboard (note: you can't use [Ctrl C] here, use the edit menu or just
press Enter). Then post the commands and results here, /paste/ them into
your message (e.g. [Ctrl V]).

And then, if you haven't already figured it out, somebody probably will.
:-)


I figured out the cause. One of the Python scripts started with:

#!Path/to/Python31Executable

which evidently caused python 3.1 to be called to run that script. I am 
not sure that script was run via an 'import' statement, as opposed to a 
'python someScript.py' within another script, but I suspect the latter.

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


Re: parmiko problem

2010-07-19 Thread George Trojan

George Trojan wrote:
I have a problem with connecting to a host without specifying password 
(but with ssh keys configured correctly. That is


[tina src]$ sftp alice
Connecting to alice...
sftp>

works, but the code

import paramiko
paramiko.util.log_to_file('/tmp/paramiko')
t = paramiko.Transport(('alice', 22))
t.connect(username='gtrojan') # , password='a-passwd'])
sftp = paramiko.SFTPClient.from_transport(t)
sftp.close()
t.close()

results in the following output in /tmp/paramiko:

DEB [20100719-19:58:22.497] thr=1   paramiko.transport: starting thread 
(client mode): 0xb81e1150L
INF [20100719-19:58:22.501] thr=1   paramiko.transport: Connected 
(version 2.0, client OpenSSH_4.3)
DEB [20100719-19:58:22.502] thr=1   paramiko.transport: kex 
algos:['diffie-hellman-group-exchange-sha1', 
'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server 
key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 
'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 
'aes192-cbc', 'aes256-cbc', 'rijndael-...@lysator.liu.se', 'aes128-ctr', 
'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', 
'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 
'aes192-cbc', 'aes256-cbc', 'rijndael-...@lysator.liu.se', 'aes128-ctr', 
'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', 
'hmac-ripemd160', 'hmac-ripemd...@openssh.com', 'hmac-sha1-96', 
'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', 
'hmac-ripemd...@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client 
compress:['none', 'z...@openssh.com'] server compress:['none', 
'z...@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEB [20100719-19:58:22.502] thr=1   paramiko.transport: Ciphers agreed: 
local=aes128-ctr, remote=aes128-ctr
DEB [20100719-19:58:22.502] thr=1   paramiko.transport: using kex 
diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local 
aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; 
compression: local none, remote none
DEB [20100719-19:58:22.571] thr=1   paramiko.transport: Switch to new 
keys ...
DEB [20100719-19:58:22.578] thr=2   paramiko.transport: [chan 1] Max 
packet in: 34816 bytes
WAR [20100719-19:58:22.611] thr=1   paramiko.transport: Oops, unhandled 
type 3
DEB [20100719-20:00:22.502] thr=1   paramiko.transport: EOF in transport 
thread


and a traceback in the terminal:

Traceback (most recent call last):
  File "./try.py", line 18, in 
sftp = paramiko.SFTPClient.from_transport(t)
  File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 102, 
in from_transport
  File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 655, 
in open_session
  File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 745, 
in open_channel

EOFError

When the remove the comment on the connect() line and specify password 
the code works fine. Is this a bug, or I am missing something? I am 
running Python 2.6.3 on Centos 5.4.


George


Thanks for listening;-) Found my problem - has to pass private key to 
connect():


paramiko.util.log_to_file('/tmp/paramiko')
t = paramiko.Transport(('alice', 22))
path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa')
key = paramiko.DSSKey.from_private_key_file(path)
t.connect(username='gtrojan', pkey=key)
sftp = paramiko.SFTPClient.from_transport(t)
print sftp.listdir()
sftp.close()
t.close()
--
http://mail.python.org/mailman/listinfo/python-list


parmiko problem

2010-07-19 Thread George Trojan
I have a problem with connecting to a host without specifying password 
(but with ssh keys configured correctly. That is


[tina src]$ sftp alice
Connecting to alice...
sftp>

works, but the code

import paramiko
paramiko.util.log_to_file('/tmp/paramiko')
t = paramiko.Transport(('alice', 22))
t.connect(username='gtrojan') # , password='a-passwd'])
sftp = paramiko.SFTPClient.from_transport(t)
sftp.close()
t.close()

results in the following output in /tmp/paramiko:

DEB [20100719-19:58:22.497] thr=1   paramiko.transport: starting thread 
(client mode): 0xb81e1150L
INF [20100719-19:58:22.501] thr=1   paramiko.transport: Connected 
(version 2.0, client OpenSSH_4.3)
DEB [20100719-19:58:22.502] thr=1   paramiko.transport: kex 
algos:['diffie-hellman-group-exchange-sha1', 
'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server 
key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 
'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 
'aes192-cbc', 'aes256-cbc', 'rijndael-...@lysator.liu.se', 'aes128-ctr', 
'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', 
'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 
'aes192-cbc', 'aes256-cbc', 'rijndael-...@lysator.liu.se', 'aes128-ctr', 
'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', 
'hmac-ripemd160', 'hmac-ripemd...@openssh.com', 'hmac-sha1-96', 
'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', 
'hmac-ripemd...@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client 
compress:['none', 'z...@openssh.com'] server compress:['none', 
'z...@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEB [20100719-19:58:22.502] thr=1   paramiko.transport: Ciphers agreed: 
local=aes128-ctr, remote=aes128-ctr
DEB [20100719-19:58:22.502] thr=1   paramiko.transport: using kex 
diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local 
aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; 
compression: local none, remote none
DEB [20100719-19:58:22.571] thr=1   paramiko.transport: Switch to new 
keys ...
DEB [20100719-19:58:22.578] thr=2   paramiko.transport: [chan 1] Max 
packet in: 34816 bytes
WAR [20100719-19:58:22.611] thr=1   paramiko.transport: Oops, unhandled 
type 3
DEB [20100719-20:00:22.502] thr=1   paramiko.transport: EOF in transport 
thread


and a traceback in the terminal:

Traceback (most recent call last):
  File "./try.py", line 18, in 
sftp = paramiko.SFTPClient.from_transport(t)
  File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 
102, in from_transport
  File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 655, 
in open_session
  File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 745, 
in open_channel

EOFError

When the remove the comment on the connect() line and specify password 
the code works fine. Is this a bug, or I am missing something? I am 
running Python 2.6.3 on Centos 5.4.


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


ANN: PiCloud's Python Platform is now open to the Public!

2010-07-19 Thread Ken Elkabany
After 5 months in private beta, PiCloud, a cloud computing platform for the
Python Programming Language, is now open to the general public. PiCloud enables
Python users to leverage the power of an on-demand, high performance, and
auto scaling compute cluster with as few as two lines of code! No server
management necessary. All new users receive 5 free compute hours of
computation. You can find out more here: http://www.picloud.com

Full service description:
PiCloud is a cloud computing platform that integrates into the Python
Programming Language. It enables you to leverage the compute power of Amazon
Web Services without having to manage, maintain, or configure virtual
servers.

PiCloud integrates seamlessly into your existing code base through a custom
Python library, cloud. To offload the execution of a function to the cloud,
all you must do is pass your desired function into the cloud library.
PiCloud will then run the function on its high-performance and
automatically-scaling cluster. We quickly scale our server capacity to meet
your computational needs, and only charge you for the resources you actually
consume. Getting on the cloud has never been this easy!

PiCloud improves the full cycle of software development and deployment.
Functions that are run on PiCloud have their resource usage monitored,
performance analyzed, and errors traced; we further aggregate all your
functions to give you a bird's eye view of your service. Through these
introspective capabilities, PiCloud enables you to develop faster, easier,
and smarter.

Common use cases for our platform:
* Scientific computing
* Simulations
* Video and image encoding
* Statistical analysis of data sets
* Real-time data processing
* Charts and graphs generation

Cheers,

Ken Elkabany
PiCloud, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why is this group being spammed?

2010-07-19 Thread Jia Hu
Hi noboby:

How can you make the current email and name hidden?
On Mon, Jul 19, 2010 at 2:42 PM, Nobody  wrote:

> On Sun, 18 Jul 2010 15:18:59 -0700, sturlamolden wrote:
>
> >> why is this group being spammed?
> >
> > There used to be bots that issued cancel messages against spam, but I
> > don't think they are actively maintained anymore.
>
> Mostly because cancel messages are invariably ignored nowadays.
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython Signal Handler Check for SIGKILL

2010-07-19 Thread Nobody
On Mon, 19 Jul 2010 20:06:16 +0200, Antoine Pitrou wrote:

> So, in short, Python doesn't check SIGKILL by itself. It's just
> forbidden by the underlying C standard library,

Actually, it's forbidden by the kernel. The C library just passes along
the error to Python, which just passes it to the application.

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


Re: how to copy and move file with its attribute?

2010-07-19 Thread Nobody
On Mon, 19 Jul 2010 17:57:31 +0100, MRAB wrote:

>> About this one. I tried the os.system copy. But it seems I cant find the 
>> right syntax.
>> 
>> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))*
>> 
>> This one seems to not working.
>> 
> In what way doesn't it work?
> 
> If the names contain spaces then you need to quote them:
> 
>  os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2))

No, you need to use subprocess.call() instead of os.system().

If you absolutely must use os.system() for some reason, at least quote the
arguments correctly. If you want to know how to do this, look at the
subprocess.py source code (hint: it's not as simple as the above suggests).


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


Re: Accumulate function in python

2010-07-19 Thread Paul Rubin
Brian Victor  writes:
> def running_sum(result, current_value):
> return result + [result[-1]+current_value if result else current_value]
>
> reduce(running_sum, x, [])

That is not really any good because Python lists are actually vectors,
so result+[...] actually copies the whole old list, making your function
take quadratic time.  It would be ok in a FP language where lists were
chains of cons nodes and result+[...] just allocated a single cons.

I think Peter Otten's solution involving a generator is the one most in
the current Python spirit.  It's cleaner (for my tastes) than the ones
that use things like list.append.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pyglet being extremely slow

2010-07-19 Thread Joshua Landau
I've just tried Pyglet on my computer, a lower-end laptop at that, and going
though the Pyglet tutorials I've tried this:

import pyglet


> window = pyglet.window.Window()


> @window.event

def on_key_press(symbol, modifiers):

print 'A key was pressed'


> @window.event

def on_draw():

window.clear()


> pyglet.app.run()


And from a button-press to the print-statement activating takes ~3 seconds.
I mean, yeah so I'm on a slow-ish-medium laptop but... three bloody seconds?
On another one that shows the FPS of the program I'm getting 0 (fps). I
would give you more detail but this has me stumped. Pygame was a decent
performer -- and I'm not even drawing anything.

Yeah, any help? *sigh*

PS: Note that I'm on Ubuntu with a tiling window manager (Awesome).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why is this group being spammed?

2010-07-19 Thread Nobody
On Sun, 18 Jul 2010 15:18:59 -0700, sturlamolden wrote:

>> why is this group being spammed?
> 
> There used to be bots that issued cancel messages against spam, but I
> don't think they are actively maintained anymore.

Mostly because cancel messages are invariably ignored nowadays.

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


Re: CPython Signal Handler Check for SIGKILL

2010-07-19 Thread Scott McCarty
Yes, yes, thank you both. That is exactly what I didn't understand, I knew
it was some how linked to the C library and wasn't exactly being handled or
decided at the Python layer, I just didn't understand the C part good
enough. I have found the CPython source code that checks. I see what you are
saying, it is basically checking for SIG_ERR like the C code and just
setting the RuntimeError which forces an exit, thereby making the python
module respond in a way very similar to the C library.

Here is the CPython code in Modules/signalmodule.c

if (PyOS_setsig(sig_num, func) == SIG_ERR) {
PyErr_SetFromErrno(PyExc_RuntimeError);
return NULL;
}

Second, I would like to apologize, this list is amazing, and I made a stupid
comment on the core developers mailing list this morning because I didn't
understand that this was the right place to post this question.

Thank You
Scott M

On Mon, Jul 19, 2010 at 2:06 PM, Antoine Pitrou  wrote:

>
> Hello,
>
> > I am not asking about the signals, I understand them,
> > I am asking about the registration of the SIGNAL handler and how it knows
> > that you are trying to register SIGKILL, you get an error like this.
> >
> >  ./signal-catcher.py
> > Traceback (most recent call last):
> >   File "./signal-catcher.py", line 22, in 
> > signal.signal(signal.SIGKILL, signal_handler_kill)
> > RuntimeError: (22, 'Invalid argument')
>
> >>> import errno
> >>> errno.errorcode[22]
> 'EINVAL'
>
> EINVAL is the error returned by the standard POSIX signal() function
> when trying to register a handler for SIGKILL. As the signal() man page
> says:
>
> [...]
>   The signals SIGKILL and SIGSTOP cannot be caught or ignored.
> [...]
> ERRORS
>   EINVAL signum is invalid.
>
>
> So, in short, Python doesn't check SIGKILL by itself. It's just
> forbidden by the underlying C standard library, and Python propagates
> the error as a RuntimeError.
>
> Regards
>
> Antoine.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why is this group being spammed?

2010-07-19 Thread Jia Hu
I use Gmail. When I receive spams, I will click "Report Spam". In addition,
I will not empty the spam box of my email immediately. When I receive about
25 spams, I will click "Filter messages like these" to filter all the spams
and let gmail automatically delete them.




On Mon, Jul 19, 2010 at 1:20 PM, John Bokma  wrote:

> "be.krul"  writes:
>
> > why is this group being spammed?
>
> Do you report those spammers?
>
> While Google is extremely lazy with dealing with spammers, if sufficient
> people report them action might be taken. Also make sure to report those
> spammers with their ISP; posts via GG contain the posting IP address.
>
> Even trolls can be hurt, if enough people report them:
> http://www.xahlee.org/Periodic_dosage_dir/t2/harassment.html
>
> --
> John Bokma
> j3b
>
> Hacking & Hiking in Mexico -  http://johnbokma.com/
> http://castleamber.com/ - Perl & Python Development
>  --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mod_python load cx_Oracle error

2010-07-19 Thread Mladen Gogala
On Mon, 19 Jul 2010 09:12:20 -0700, li wang wrote:

> It's quite weird when I import cx_Oracle in python interactive shell, it
> works perfectly.
> but when I import cx_Oracle in a *,py script, handled by
> mod_python.publisher, it keep reportint :
> 
> ImportError: libclntsh.so.10.1: cannot open shared object file: No such
> file or directory
> 
> Can I anyone have a clue what's the matter, any help would be
> appreciated!


That's an Oracle error, it means that you didn't set and export 
LD_LIBRARY_PATH like this:

export LD_LIBRARY_PATH=$ORACLE_HOME/lib


This is how it normally works:
mgog...@nycwxp2622:~$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> 

And this is what happens when I unset the shell variable:
mgog...@nycwxp2622:~$ unset LD_LIBRARY_PATH
mgog...@nycwxp2622:~$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import cx_Oracle
Traceback (most recent call last):
  File "", line 1, in 
ImportError: libclntsh.so.11.1: cannot open shared object file: No such 
file or directory
>>> 


My cx_Oracle is linked against Oracle instant client 11.2 on Ubuntu.




-- 
http://mgogala.byethost5.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fascinating interview by Richard Stallman at KTH on emacs history and internals

2010-07-19 Thread Rui Maciel
Kenneth Tilton wrote:

> What we do not have is any interesting amount of "free as in speech"
> software, because no one uses the GPL.

You appear to be either confused or out of touch with reality.  If that wasn't 
enough, your comment 
becomes a bit more amusing once we check your post's user agent.


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


Re: how to copy and move file with its attribute?

2010-07-19 Thread MRAB

Alban Nona wrote:

Hello Mrab,

Thank you very much for this informations.
Homever, Im still stuck with a problem:

import os
import sys
import threading
import shutil

source= "C://Production//"
dest= "D://Production//"

os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest))


It seems that it wont copy the files

File not found - //Production//
0 File(s) copied

any idea of why its doing this please ?


[snip]
If you're using slashes then there's no need to double them. Also, you
don't need to end the folder names with slashes or backslashes (except
for root folders). That's what it doesn't like, apparently.

source = "C:/Production"
dest = "D:/Production"

os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest))
--
http://mail.python.org/mailman/listinfo/python-list


Re: CPython Signal Handler Check for SIGKILL

2010-07-19 Thread Antoine Pitrou

Hello,

> I am not asking about the signals, I understand them,
> I am asking about the registration of the SIGNAL handler and how it knows
> that you are trying to register SIGKILL, you get an error like this.
> 
>  ./signal-catcher.py
> Traceback (most recent call last):
>   File "./signal-catcher.py", line 22, in 
> signal.signal(signal.SIGKILL, signal_handler_kill)
> RuntimeError: (22, 'Invalid argument')

>>> import errno
>>> errno.errorcode[22]
'EINVAL'

EINVAL is the error returned by the standard POSIX signal() function
when trying to register a handler for SIGKILL. As the signal() man page
says:

[...]
   The signals SIGKILL and SIGSTOP cannot be caught or ignored.
[...]
ERRORS
   EINVAL signum is invalid.


So, in short, Python doesn't check SIGKILL by itself. It's just
forbidden by the underlying C standard library, and Python propagates
the error as a RuntimeError.

Regards

Antoine.


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


Re: CPython Signal Handler Check for SIGKILL

2010-07-19 Thread Thomas Jollans
On 07/19/2010 07:28 PM, Scott McCarty wrote:
> All,  I just want to understand the C/Python piece better because I am
> writing a tutorial on signals and I am using python to demonstrate. I
> thought it would be fun to show that the SIGKILL is never processed, but
> instead python errors out. There is something in Python checking the
> SIGKILL signal handler, while not checking SIGTERM and I can't find the
> Python C code that handles it. When I am writing something like this, I
> like to point out the C code, not just cite the documentation (I did
> find this change in behaviour noted in the Python change log).

You cannot handle SIGKILL. Nothing to do with Python. Let me demonstrate:

0:pts/8:/tmp% cat sig.c
#include 
#include 

void handle_sig(int sig)
{
printf("SIGNAL: %d\n", sig);
}

int main(int argc, char **argv)
{
if (signal(SIGUSR1, handle_sig) == SIG_ERR)
printf("failed to set for USR1\n");
if (signal(SIGTERM, handle_sig) == SIG_ERR)
printf("failed to set for TERM\n");
if (signal(SIGKILL, handle_sig) == SIG_ERR)
printf("failed to set for KILL\n");

for(;;);
}

0:pts/8:/tmp% cc -osig sig.c
0:pts/8:/tmp% ./sig
failed to set for KILL
^C
130:pts/8:/tmp%

> 
> I have searched everywhere (mostly the code and a little google) and I
> cannot understand where the SIGKILL signal gets checked when it is set
> as a handler. I have scoured the Modules/signalmodule.c only to find two
> instances of the RuntimeError exception, but I cannot understand how
> python knows when a handler is set for SIGKILL. I understand that this
> changed in 2.4 and I am not trying to change it, I just really want to
> understand where this happens. I used grep to find SIGKILL and SIGTERM
> to see if I could determine where the critical difference is, but I
> cannot figure it out.
> 
> I have about 2 hours of searching around and I can't figure it out, I
> assume it has to rely on some default behaviour in Unix, but I have no
> idea. I don't see a difference between SIGKILL and SIGTERM in the python
> code, but obviously there is some difference. I understand what the
> difference is in Unix/Linux, I just want to see it in the python code.
> Since python is checking at run time to see what signals handlers are
> added, I know there must be a difference. I am not asking about the
> signals, I understand them, I am asking about the registration of the
> SIGNAL handler and how it knows that you are trying to register SIGKILL,
> you get an error like this.
> 
>  ./signal-catcher.py
> Traceback (most recent call last):
>   File "./signal-catcher.py", line 22, in 
> signal.signal(signal.SIGKILL, signal_handler_kill)
> RuntimeError: (22, 'Invalid argument')
> 
> And the code is very simple, this attempts to register a handler for
> SIGKILL, but python knows and won't let you.
> 
> signal.signal(signal.SIGKILL, signal_handler_kill)
> 
> Please  can someone just point me in the right direction.
> 
> Thank You
> Scott M
> 

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


Re: how to copy and move file with its attribute?

2010-07-19 Thread Alban Nona
Hello Mrab,

Thank you very much for this informations.
Homever, Im still stuck with a problem:

import os
import sys
import threading
import shutil

source= "C://Production//"
dest= "D://Production//"

os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest))


It seems that it wont copy the files

File not found - //Production//
0 File(s) copied

any idea of why its doing this please ?


2010/7/19 MRAB 

> Alban Nona wrote:
>
>> Hello,
>>
>> About this one. I tried the os.system copy. But it seems I cant find the
>> right syntax.
>>
>> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))*
>>
>> This one seems to not working.
>>
>>  In what way doesn't it work?
>
> If the names contain spaces then you need to quote them:
>
>
>os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2))
>
> (It's easier to always quote them.)
>
> If the destination doesn't exist then you need to add the "/i" flag:
>
>os.system('xcopy /s /i "%s" "%s"' % (dirname1, dirname2))
>
>
>  Is there anyway I can do this way:
>>
>> localpath= c:\
>> networkpath=g:\
>>
>> os.system("copy localpath networkpath)
>>
>> I tried many variations, but still not working. Any help will apreciated
>> :/
>>
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accumulate function in python

2010-07-19 Thread Duncan Booth
dhruvbird  wrote:

> On Jul 19, 4:28 pm, Peter Otten <__pete...@web.de> wrote:
>> dhruvbird wrote:
>> >   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
>> >   And would like to compute the cumulative sum of all the integers
>> > from index zero into another array. So for the array above, I should
>> > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
>> >   What is the best way (or pythonic way) to get this.
>>
>> Homework?
> 
> not really :)
> 
> It's just that I was wondering if a built-in function for doing such
> things (which I find myself doing increasingly with an explicit loop)
> exists.
> 
Why would you find yourself doing it more than once? Write it once in a 
function and then just re-use the code.
-- 
http://mail.python.org/mailman/listinfo/python-list


CPython Signal Handler Check for SIGKILL

2010-07-19 Thread Scott McCarty
All,  I just want to understand the C/Python piece better because I am
writing a tutorial on signals and I am using python to demonstrate. I
thought it would be fun to show that the SIGKILL is never processed, but
instead python errors out. There is something in Python checking the SIGKILL
signal handler, while not checking SIGTERM and I can't find the Python C
code that handles it. When I am writing something like this, I like to point
out the C code, not just cite the documentation (I did find this change in
behaviour noted in the Python change log).

I have searched everywhere (mostly the code and a little google) and I
cannot understand where the SIGKILL signal gets checked when it is set as a
handler. I have scoured the Modules/signalmodule.c only to find two
instances of the RuntimeError exception, but I cannot understand how python
knows when a handler is set for SIGKILL. I understand that this changed in
2.4 and I am not trying to change it, I just really want to understand where
this happens. I used grep to find SIGKILL and SIGTERM to see if I could
determine where the critical difference is, but I cannot figure it out.

I have about 2 hours of searching around and I can't figure it out, I assume
it has to rely on some default behaviour in Unix, but I have no idea. I
don't see a difference between SIGKILL and SIGTERM in the python code, but
obviously there is some difference. I understand what the difference is in
Unix/Linux, I just want to see it in the python code. Since python is
checking at run time to see what signals handlers are added, I know there
must be a difference. I am not asking about the signals, I understand them,
I am asking about the registration of the SIGNAL handler and how it knows
that you are trying to register SIGKILL, you get an error like this.

 ./signal-catcher.py
Traceback (most recent call last):
  File "./signal-catcher.py", line 22, in 
signal.signal(signal.SIGKILL, signal_handler_kill)
RuntimeError: (22, 'Invalid argument')

And the code is very simple, this attempts to register a handler for
SIGKILL, but python knows and won't let you.

signal.signal(signal.SIGKILL, signal_handler_kill)

Please  can someone just point me in the right direction.

Thank You
Scott M
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why is this group being spammed?

2010-07-19 Thread John Bokma
"be.krul"  writes:

> why is this group being spammed?

Do you report those spammers?

While Google is extremely lazy with dealing with spammers, if sufficient
people report them action might be taken. Also make sure to report those
spammers with their ISP; posts via GG contain the posting IP address.

Even trolls can be hurt, if enough people report them:
http://www.xahlee.org/Periodic_dosage_dir/t2/harassment.html

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accumulate function in python

2010-07-19 Thread dhruvbird
On Jul 19, 4:28 pm, Peter Otten <__pete...@web.de> wrote:
> dhruvbird wrote:
> >   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
> >   And would like to compute the cumulative sum of all the integers
> > from index zero into another array. So for the array above, I should
> > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
> >   What is the best way (or pythonic way) to get this.
>
> Homework?

not really :)

It's just that I was wondering if a built-in function for doing such
things (which I find myself doing increasingly with an explicit loop)
exists.

Regards,
-Dhruv.

>
> >>> def cumulative_sum(values, start=0):
>
> ...     for v in values:
> ...             start += v
> ...             yield start
> ...>>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]))
>
> [0, 1, 3, 4, 5, 5, 5, 7, 10]
>
> Peter

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


Re: Accumulate function in python

2010-07-19 Thread dhruvbird
On Jul 19, 9:12 pm, Brian Victor  wrote:
> dhruvbird wrote:
> > Hello,
> >   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
> >   And would like to compute the cumulative sum of all the integers
> > from index zero into another array. So for the array above, I should
> > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
> >   What is the best way (or pythonic way) to get this.
>
> Now that Steven's given you the simple, pythonic way, I'll just mention
> the advanced, complicated and obscure way that might be vaguely familiar
> if you're coming from a functional programming background:
>
> x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
> def running_sum(result, current_value):
>     return result + [result[-1]+current_value if result else current_value]
>
> reduce(running_sum, x, [])
>
> Having offered this, I don't recall ever seeing reduce used in real
> python code, and explicit iteration is almost always preferred.

Yes, even I have noticed that reduce is a tad under-used function.

So, I guess no function like "accumulate" below exists in the standard
lib.


def accumulate(proc, seed, seq):
ret = []
for i in seq:
ret.append(proc(seed, i))
return ret

x = [0, 1, 3, 4, 5, 5, 5, 7, 10]
print accumulate(lambda x,y: x+y, 0, x)

My guess is that accumulate can be used in many more scenarios.

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


Re: how to copy and move file with its attribute?

2010-07-19 Thread MRAB

Alban Nona wrote:

Hello,

About this one. I tried the os.system copy. But it seems I cant find the 
right syntax.


*os.system ("xcopy /s %s %s" % (dirname1, dirname2))*

This one seems to not working.


In what way doesn't it work?

If the names contain spaces then you need to quote them:

os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2))

(It's easier to always quote them.)

If the destination doesn't exist then you need to add the "/i" flag:

os.system('xcopy /s /i "%s" "%s"' % (dirname1, dirname2))


Is there anyway I can do this way:

localpath= c:\
networkpath=g:\

os.system("copy localpath networkpath)

I tried many variations, but still not working. Any help will apreciated :/



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


Re: how to copy and move file with its attribute?

2010-07-19 Thread Alban Nona
Hello,

About this one. I tried the os.system copy. But it seems I cant find the
right syntax.

*os.system ("xcopy /s %s %s" % (dirname1, dirname2))*

This one seems to not working.

Is there anyway I can do this way:

localpath= c:\
networkpath=g:\

os.system("copy localpath networkpath)

I tried many variations, but still not working. Any help will apreciated :/

Thanks !


2010/7/19 Vlastimil Brom 

> 2010/7/19 oyster :
> > I mean writeonly, hidden, system and so on attributes
> >
> > I use windows, but if possible, is there any method to do so in a
> > crossplatfrom way?
> >
> > thanks
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
> You may check to see several possibilities
> http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html
> Probably the shutil module might be appropriate for simple usecases.
>
> hth,
>  vbr
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


ANNOUNCING Tahoe, the Least-Authority File System, v1.7.1

2010-07-19 Thread Zooko O'Whielacronx
Folks:

This innovative distributed filesystem is written entirely in Python.
Well, actually we rely on some C/C++ extension code in Python packages
like "zfec" and "pycryptopp" for some mathematical heavy lifting, but
all of the code in the tahoe-lafs package is actually pure Python.

Regards,

Zooko


ANNOUNCING Tahoe, the Least-Authority File System, v1.7.1

The Tahoe-LAFS team is pleased to announce the immediate
availability of version 1.7.1 of Tahoe-LAFS, an extremely
reliable distributed storage system.

Tahoe-LAFS is the first distributed storage system which
offers "provider-independent security"—meaning that not even
the operators of your storage servers can read or alter your
data without your consent. Here is the one-page explanation of
its unique security and fault-tolerance properties:

http://tahoe-lafs.org/source/tahoe/trunk/docs/about.html

Tahoe-LAFS v1.7.1 is the successor to v1.7.0, which was
released June 18, 2010 [1].

v1.7.1 is a stable minor release which adds several bugfixes
and improvements in security, forward-compatibility,
packaging, usability, and portability. See the NEWS file [2]
for details.


WHAT IS IT GOOD FOR?

With Tahoe-LAFS, you distribute your filesystem across
multiple servers, and even if some of the servers are
compromised by by an attacker, the entire filesystem continues
to work correctly, and continues to preserve your privacy and
security. You can easily share specific files and directories
with other people.

In addition to the core storage system itself, volunteers have
built other projects on top of Tahoe-LAFS and have integrated
Tahoe-LAFS with existing systems.

These include frontends for Windows, Macintosh, JavaScript,
iPhone, and Android, and plugins for Hadoop, bzr, mercurial,
duplicity, TiddlyWiki, and more. See the Related Projects page
on the wiki [3].

We believe that strong cryptography, Free and Open Source
Software, erasure coding, and principled engineering practices
make Tahoe-LAFS safer than RAID, removable drive, tape,
on-line backup or "cloud storage" systems.

This software is developed under test-driven development, and
there are no known bugs or security flaws which would
compromise confidentiality or data integrity under recommended
use. (For all currently known issues please see the
known_issues.txt file [4].)


COMPATIBILITY

This release is fully compatible with the version 1 series of
Tahoe-LAFS. Clients from this release can write files and
directories in the format used by clients of all versions back
to v1.0 (which was released March 25, 2008). Clients from this
release can read files and directories produced by clients of
all versions since v1.0. Servers from this release can serve
clients of all versions back to v1.0 and clients from this
release can use servers of all versions back to v1.0.

This is the tenth release in the version 1 series. This series
of Tahoe-LAFS will be actively supported and maintained for
the forseeable future, and future versions of Tahoe-LAFS will
retain the ability to read and write files compatible with
this series.


LICENCE

You may use this package under the GNU General Public License,
version 2 or, at your option, any later version. See the file
"COPYING.GPL" [5] for the terms of the GNU General Public
License, version 2.

You may use this package under the Transitive Grace Period
Public Licence, version 1 or, at your option, any later
version. (The Transitive Grace Period Public Licence has
requirements similar to the GPL except that it allows you to
delay for up to twelve months after you redistribute a derived
work before releasing the source code of your derived work.)
See the file "COPYING.TGPPL.html" [6] for the terms of the
Transitive Grace Period Public Licence, version 1.

(You may choose to use this package under the terms of either
licence, at your option.)


INSTALLATION

Tahoe-LAFS works on Linux, Mac OS X, Windows, Cygwin, Solaris,
*BSD, and probably most other systems. Start with
"docs/quickstart.html" [7].


HACKING AND COMMUNITY

Please join us on the mailing list [8]. Patches are gratefully
accepted -- the RoadMap page [9] shows the next improvements
that we plan to make and CREDITS [10] lists the names of people
who've contributed to the project. The Dev page [11] contains
resources for hackers.


SPONSORSHIP

Tahoe-LAFS was originally developed by Allmydata, Inc., a
provider of commercial backup services. After discontinuing
funding of Tahoe-LAFS R&D in early 2009, they have continued
to provide servers, bandwidth, small personal gifts as tokens
of appreciation, and bug reports. Thank you to Allmydata,
Inc. for their generous and public-spirited support.

Google, Inc. is sponsoring Tahoe-LAFS development as part of
the Google Summer of Code 2010. Google suggested that we
should apply for the Summer of Code program, and when we did
they generously awarded four sponsorships to students from
around the world to hack on Tahoe-LAFS this summer. Thank you
to Google, Inc. for the

mod_python load cx_Oracle error

2010-07-19 Thread li wang
It's quite weird when I import cx_Oracle in python interactive shell,
it works perfectly.
but when I import cx_Oracle in a *,py script, handled by
mod_python.publisher, it keep reportint :

ImportError: libclntsh.so.10.1: cannot open shared object file: No
such file or directory

Can I anyone have a clue what's the matter,
any help would be appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email für Dich

2010-07-19 Thread Deadly Dirk
On Mon, 19 Jul 2010 17:52:56 +0200, Wolfgang Meiners wrote:

> Liebe Kirsten,
> 
> ich liebe dich und freue mich, dass du bald auch Ferien hast.
> 
> Wolfgang


Und die ganze Python gruppe liebt dich auch.


-- 
The missionaries go forth to Christianize the savages - 
as if the savages weren't dangerous enough already.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accumulate function in python

2010-07-19 Thread Brian Victor
dhruvbird wrote:
> Hello,
>   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
>   And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
>   What is the best way (or pythonic way) to get this.

Now that Steven's given you the simple, pythonic way, I'll just mention
the advanced, complicated and obscure way that might be vaguely familiar
if you're coming from a functional programming background:

x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
def running_sum(result, current_value):
return result + [result[-1]+current_value if result else current_value]

reduce(running_sum, x, [])

Having offered this, I don't recall ever seeing reduce used in real
python code, and explicit iteration is almost always preferred.

-- 
Brian

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


Email für Dich

2010-07-19 Thread Wolfgang Meiners
Liebe Kirsten,

ich liebe dich und freue mich, dass du bald auch Ferien hast.

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


Re: Fascinating interview by Richard Stallman at KTH on emacs history and internals

2010-07-19 Thread Pascal J. Bourguignon
Kenneth Tilton  writes:

> What we do not have is any interesting amount of "free as in speech"
> software, because no one uses the GPL.

I do.  So far, I resist to calls to put my software in a less
freedom-promoting license.


Hey everybody!  Switch from MIT or BSD to GPL!  Now!


-- 
__Pascal Bourguignon__ http://www.informatimago.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: decimal.Decimal formatting

2010-07-19 Thread Stefan Krah
pyt...@lists.fastmail.net  wrote:
> I have various decimals which eventually are written to an XML file.
> Requirements indicate a precision of 11. I am currently having some
> 'issues' with Decimal("0"). When using
> quantize(decimal.Decimal("1e-11")) the result is not 0.000, but
> 1e-11.
> 
> Personally I agree 1e-11 is a better notation than 0.000, but I
> currently need the long one. Is there a way to overwrite the switch to
> the scientific notation? Apparently there is a switch in notation
> 'between' 1e-6 and 1e-7.

Try:

>>> format(Decimal("0"), ".11f")
'0.000'


Stefan Krah


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


Re: Accumulate function in python

2010-07-19 Thread Steven D'Aprano
On Mon, 19 Jul 2010 04:18:48 -0700, dhruvbird wrote:

> Hello,
>   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] And would
>   like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]

[pedant]
The above are *lists*, not arrays. Python has arrays, but you have to 
call "import array" to get them.
[/pedant]

>   What is the best way (or pythonic way) to get this.

Others have given you a plethora of advanced, complicated and obscure 
ways to solve this question, but I haven't seen anyone give the simplest 
method (simple as in no tricks or advanced features):

data = [0, 1, 2, 1, 1, 0, 0, 2, 3]
csums = []
for x in data:
if csums:
y = x + csums[-1]
else:
y = x
csums.append(y)


We can save some code with the ternary operator:

data = [0, 1, 2, 1, 1, 0, 0, 2, 3]
csums = []
for x in data:
csums.append((x + csums[-1]) if csums else x)



Here's a version that writes the cumulative sum in place:

data = [0, 1, 2, 1, 1, 0, 0, 2, 3]
for i in range(1, len(data)):
data[i] += data[i-1]



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


ANN: pyTenjin 0.9.0 - very fast and full-featured template engine

2010-07-19 Thread Makoto Kuwata
I released pyTenjin 0.9.0
http://www.kuwata-lab.com/tenjin/
http://pypi.python.org/pypi/Tenjin/

This release contains a lot of enhancements and changes.
Also you should read planned changes in the next release (1.0.0).
See
  http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#planned-changes
for details.


Overview


pyTenjin is very fast and full-featured template engine for Python.

  * Very fast (about 10 times faster than Django template engine)
  * Easy to learn (no need to learn template-original language)
  * Full-featured (nestable layout template, partial template,
preprocessing, ...)
  * Google App Engine supported


Documents
-

  * User's Guide
  http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html
  * Examples
  http://www.kuwata-lab.com/tenjin/pytenjin-examples.html
  * CHANGES
  http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt


Enhancements from 0.8.1
---

  * Performance improved (about 5%).

  * (IMPORTANT!!)
Fragment cache supported.
See
  http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#fragment-cache
for details.

  * (IMPORTANT!!)
include() now takes keyword arguments as local variables.
ex.
  

  * Add new module 'tenjin.gae'.

  * Add 'input' argument to tenjin.Template() to create template
object without file.
ex.
  input = "Hello ${name}"
  t = tenjin.Template(None, input=input)
  html = t.render({'name': 'World'})

  * Add tenjin.Engine.add_template() to add template object explicitly.

  * User's guide (doc/users-guide.html) is rewrited entirely.

  * Add benchmark for Jinja2.


Changes from 0.8.1
--

  * (IMPORTANT!!)
It is strongly recommended to close 'if', 'for', 'while', ... by
corresponding '#endif', '#endfor', '#endwhile', and so on.
See
  http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#planned-changes
for details.

  * (IMPORTANT!!)
Google App Engine support is changed. All you have to do is to call
tenjin.gae.init() at first.
See
  
http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#google-appengine
for details.

  * (IMPORTANT!!)
tenjin.Engine is changed to share a cache storage between engines
by default.
This improves performance of Tenjin but your test scripts may get errors.
If you get errors in your test scripts, clear cache storage for each test.

def setUp(self):
tenjin.Engine.cache.clear()

If you prefer previous behaviour, set tenjin.Engine.cache to None.

## create new MarshalCacheStorage object for each engine
tenjin.Engine.cache = None

  * Now you can set default template class to tenjin.Engine.templateclass.
ex.
  tenjin.Engine.templateclass = MyTemplate

  * 'cache' argument of tenjin.Engine() is changed.
 [old behaviour] if 'cache' is None, cache template object into memory.
 [new behaviour] if 'cache' is None, use default cache storage.

  * Default preamble is changed from "print ''.join(_buf)" to
"print(''.join(_buf))".

  * 'doc/faq.html' is integrated into 'doc/users-guide.html'.

  * All test scripts are changed to import oktest instead of unittest.


Bug fixes
-

  * Fixed to set correct file path of template object which is loaded
from cache.

  * Fixed a bug that 'pytenjin -sbN' didn't trim line number on the last line


Have fun!

--
regards,
makoto kuwata
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accumulate function in python

2010-07-19 Thread Andre Alexander Bell
On 07/19/2010 01:18 PM, dhruvbird wrote:
> Hello,
>   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
>   And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
>   What is the best way (or pythonic way) to get this.
> 
> Regards,
> -Dhruv.

Maybe not pythonic, but straight-forward:

>>> import numpy
>>> numpy.cumsum(x)
array([ 0,  1,  3,  4,  5,  5,  5,  7, 10])

An example with a class

class CumulativeSum(object):
def __init__(self, start=0):
self._current = start
def __call__(self, value):
self._current += value
return self._current

>>> cummulative_sum = CumulativeSum(0)
>>> map(cummulative_sum, x)
[0, 1, 3, 4, 5, 5, 5, 7, 10]

Dirty:

current = 0

def cummulative_sum(value):
global current
current += value
return current

>>> map(cummulative_sum, x)
[0, 1, 3, 4, 5, 5, 5, 7, 10]

Weird:

def cummulative_sum_reducer(x, y):
x.append(x[-1] + y)
return x

>>> reduce(cummulative_sum_reducer, x, [0])
[0, 0, 1, 3, 4, 5, 5, 5, 7, 10]

Cheers


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


Re: [ANN] Lupa 0.6 - Lua in Python

2010-07-19 Thread Fabrizio Milo aka misto
This is very very interesting.

Do you have any direct application of it ?
I know games like World of Warcraft uses Lua as scripting language.

Thanks.

Fabrizio
--
Luck favors the prepared mind. (Pasteur)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Different python versions confusion under Windows Vista x64

2010-07-19 Thread Alf P. Steinbach /Usenet

* Edward Diener, on 19.07.2010 14:53:

In Windows Vista x64 I have installed python 2.6 64-bit version and
python 3.1 64-bit version to separate folders. Within the command
interpreter I add python 2.6 to the PATH.

In the command interpreter, When I type python somescript.py with an

import sys
print (sys.version)

in the script, it shows:

3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)]

In the command interpreter if I type 'python' I see:

Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit
(AMD64)] on win32

Does anybody have any ideas why this is happening ?


At a guess your description of what's happening is not entirely accurate.

Although it could be, since Windows moves in mysterious ways.

Please try the following commands in sequence, with no other commands:

  python -V
  echo %path%
  ftype python.file
  python somescript.py

Then right-click the command interpreter's title bar to get edit menu. /Mark/ 
the text of your commands and results. Then /copy/ it to the clipboard (note: 
you can't use [Ctrl C] here, use the edit menu or just press Enter). Then post 
the commands and results here, /paste/ them into your message (e.g. [Ctrl V]).


And then, if you haven't already figured it out, somebody probably will. :-)


Cheers & hth.,

- Alf

--
blog at http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list


Different python versions confusion under Windows Vista x64

2010-07-19 Thread Edward Diener
In Windows Vista x64 I have installed python 2.6 64-bit version and 
python 3.1 64-bit version to separate folders. Within the command 
interpreter I add python 2.6 to the PATH.


In the command interpreter, When I type python somescript.py with an

import sys
print (sys.version)

in the script, it shows:

3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)]

In the command interpreter if I type 'python' I see:

Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit 
(AMD64)] on win32


Does anybody have any ideas why this is happening ?

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


Re: timing

2010-07-19 Thread Alex A.
You could use pycallgraph module

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


CPython 3.1.1 docs error in noddy3 example?

2010-07-19 Thread Alf P. Steinbach /Usenet
"Extending and Embedding the Python Interpreter" §2.1.2, the noddy3 extension 
module example, uses "S" as format character for string arguments in its call to 
PyArg_ParseTupleAndKeywords.


This causes Noddy to only accept bytes as arguments, instead of strings (format 
"U").


I suspect this is a leftover from Python 2.x, where strings were bytes, and that 
this is a bug?



Cheers,

- Alf

--
blog at http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list


decimal.Decimal formatting

2010-07-19 Thread python
I have various decimals which eventually are written to an XML file.
Requirements indicate a precision of 11. I am currently having some
'issues' with Decimal("0"). When using
quantize(decimal.Decimal("1e-11")) the result is not 0.000, but
1e-11.

Personally I agree 1e-11 is a better notation than 0.000, but I
currently need the long one. Is there a way to overwrite the switch to
the scientific notation? Apparently there is a switch in notation
'between' 1e-6 and 1e-7.

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


Re: Accumulate function in python

2010-07-19 Thread Mick Krippendorf
Am 19.07.2010 13:18, dhruvbird wrote:
> Hello,
>   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
>   And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
>   What is the best way (or pythonic way) to get this.



import copy
import itertools

def acc(items, copy=copy.deepcopy):
items = iter(items)
result = next(items)
yield copy(result)
for item in items:
result += item
yield copy(result)


print list(acc([0, 1, 2, 1, 1, 0, 0, 2, 3]))
print list(itertools.islice(acc(itertools.count()), 10))
print list(acc(['a', 'b', 'c']))
print list(acc([[a], [b], [c]]))



Output:

[0, 1, 3, 4, 5, 5, 5, 7, 10]
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
['a', 'ab', 'abc']
[[a], [a, b], [a, b, c]]


Without copy.deepcopy() the last line would be:

[[a, b, c], [a, b, c], [a, b, c]]


The copy=copy.deepcopy parameter allows for things like this:

>>> print list(acc([[a], [b], [c]], tuple))
[(a,), (a, b), (a, b, c)]


or:

>>> print list(acc([['a'], ['b'], ['f'], ['s'], ['c'], ['g']], max))
['a', 'b', 'f', 's', 's', 's']


or:

>>> data = [[0], [1], [2], [1], [1], [2], [3]]
>>> print list(acc(data, lambda x: float(sum(x)) / float(len(x
[0.0, 0.5, 1.0, 1.0, 1.0, 1.1667, 1.4285714285714286]


Endless possibilities in an endless universe.


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


Re: Accumulate function in python

2010-07-19 Thread Vlastimil Brom
2010/7/19 dhruvbird :
> Hello,
>  I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
>  And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
>  What is the best way (or pythonic way) to get this.
>
> Regards,
> -Dhruv.
> --

Hi,
just a straightworward, naive approach...:

lst_int =  [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
acc_int = 0
output_lst = []
for i in lst_int:
acc_int += i
output_lst.append(acc_int)
print output_lst

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


Re: Accumulate function in python

2010-07-19 Thread Peter Otten
dhruvbird wrote:

>   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
>   And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
>   What is the best way (or pythonic way) to get this.

Homework?

>>> def cumulative_sum(values, start=0):
... for v in values:
... start += v
... yield start
...
>>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]))
[0, 1, 3, 4, 5, 5, 5, 7, 10]

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


Re: Accumulate function in python

2010-07-19 Thread Nitin Pawar
Hi,

you may want to do like this

array=[0,1,2]
sumArray = []

for element in range(0,len(array)):
if element == 0 :
sumArray.append(array[element])
else:
sumArray.append((array[element] + sumArray[element-1]))

and then you can recheck it

Thanks,
nitin

On Mon, Jul 19, 2010 at 4:48 PM, dhruvbird  wrote:

> Hello,
>  I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
>  And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
>  What is the best way (or pythonic way) to get this.
>
> Regards,
> -Dhruv.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: how to copy and move file with its attribute?

2010-07-19 Thread Vlastimil Brom
2010/7/19 oyster :
> I mean writeonly, hidden, system and so on attributes
>
> I use windows, but if possible, is there any method to do so in a
> crossplatfrom way?
>
> thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You may check to see several possibilities
http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html
Probably the shutil module might be appropriate for simple usecases.

hth,
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to copy and move file with its attribute?

2010-07-19 Thread Peter Otten
oyster wrote:

> I mean writeonly, hidden, system and so on attributes
> 
> I use windows, but if possible, is there any method to do so in a
> crossplatfrom way?

I can't check, but shutil.copy2() may do what you want.

Peter

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


Accumulate function in python

2010-07-19 Thread dhruvbird
Hello,
  I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
  And would like to compute the cumulative sum of all the integers
from index zero into another array. So for the array above, I should
get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
  What is the best way (or pythonic way) to get this.

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


how to copy and move file with its attribute?

2010-07-19 Thread oyster
I mean writeonly, hidden, system and so on attributes

I use windows, but if possible, is there any method to do so in a
crossplatfrom way?

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


Re: Difference between import in script and from interpreter

2010-07-19 Thread Jean-Michel Pichavant

Steven D'Aprano wrote:

On Mon, 19 Jul 2010 00:53:56 -0400, Edward Diener wrote:

  

In a python script a:

from xxx.yyy.zzz import aaa

fails with the message:

"ImportError: No module named xxx.yyy.zzz"

but from within the python interpreter the same line succeeds. What
would be the causes of that ?

 From within the python interpreter I have looked at sys.path and
xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am
not sure why this is failing within the python script.



And how is sys.path different when you run it as a script?


  

'' is not in sys.path when running a script.
'' is in sys.path by default within a interpreter.


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


Re: Fascinating interview by Richard Stallman on Russia TV

2010-07-19 Thread geremy condra
On Sun, Jul 18, 2010 at 7:53 AM, David Kastrup  wrote:



>    File: elisp,  Node: Writing Emacs Primitives,  Next: Object Internals,  
> Prev: Memory Usage,  Up: GNU Emacs Internals
>
>    E.5 Writing Emacs Primitives
>    
>
>    Lisp primitives are Lisp functions implemented in C.  The details of
>    interfacing the C function so that Lisp can call it are handled by a few
>    C macros.  The only way to really understand how to write new C code is
>    to read the source, but we can explain some things here.
>
>       An example of a special form is the definition of `or', from
>    `eval.c'.  (An ordinary function would have the same general
>    appearance.)
>
>         DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
>           doc: /* Eval args until one of them yields non-nil, then return that
>         value. The remaining args are not evalled at all.
>         If all args return nil, return nil.
>         usage: (or CONDITIONS ...)  */)
>           (Lisp_Object args)
>         {
>           register Lisp_Object val = Qnil;
>           struct gcpro gcpro1;
>
>           GCPRO1 (args);
>
>           while (CONSP (args))
>             {
>               val = Feval (XCAR (args));
>               if (!NILP (val))
>                 break;
>               args = XCDR (args);
>             }
>
>           UNGCPRO;
>           return val;
>         }
>
>       Let's start with a precise explanation of the arguments to the
>    `DEFUN' macro.  Here is a template for them:
>
>         DEFUN (LNAME, FNAME, SNAME, MIN, MAX, INTERACTIVE, DOC)
>
>    LNAME
>         This is the name of the Lisp symbol to define as the function
>         name; in the example above, it is `or'.
>
>    FNAME
>         This is the C function name for this function.  This is the name
>         that is used in C code for calling the function.  The name is, by
>         convention, `F' prepended to the Lisp name, with all dashes (`-')
>         in the Lisp name changed to underscores.  Thus, to call this
>         function from C code, call `For'.  Remember that the arguments must
>         be of type `Lisp_Object'; various macros and functions for creating
>         values of type `Lisp_Object' are declared in the file `lisp.h'.
>
>    SNAME
>         This is a C variable name to use for a structure that holds the
>         data for the subr object that represents the function in Lisp.
>         This structure conveys the Lisp symbol name to the initialization
>         routine that will create the symbol and store the subr object as
>         its definition.  By convention, this name is always FNAME with `F'
>         replaced with `S'.
>
>    MIN
>         This is the minimum number of arguments that the function
>         requires.  The function `or' allows a minimum of zero arguments.
>
>    MAX
>         This is the maximum number of arguments that the function accepts,
>         if there is a fixed maximum.  Alternatively, it can be `UNEVALLED',
>         indicating a special form that receives unevaluated arguments, or
>         `MANY', indicating an unlimited number of evaluated arguments (the
>         equivalent of `&rest').  Both `UNEVALLED' and `MANY' are macros.
>         If MAX is a number, it may not be less than MIN and it may not be
>         greater than eight.
>
>    INTERACTIVE
>         This is an interactive specification, a string such as might be
>         used as the argument of `interactive' in a Lisp function.  In the
>         case of `or', it is 0 (a null pointer), indicating that `or'
>         cannot be called interactively.  A value of `""' indicates a
>         function that should receive no arguments when called
>         interactively.  If the value begins with a `(', the string is
>         evaluated as a Lisp form.
>
>    DOC
>         This is the documentation string.  It uses C comment syntax rather
>         than C string syntax because comment syntax requires nothing
>         special to include multiple lines.  The `doc:' identifies the
>         comment that follows as the documentation string.  The `/*' and
>         `*/' delimiters that begin and end the comment are not part of the
>         documentation string.
>
>         If the last line of the documentation string begins with the
>         keyword `usage:', the rest of the line is treated as the argument
>         list for documentation purposes.  This way, you can use different
>         argument names in the documentation string from the ones used in
>         the C code.  `usage:' is required if the function has an unlimited
>         number of arguments.
>
>         All the usual rules for documentation strings in Lisp code (*note
>         Documentation Tips::) apply to C code documentation strings too.
>
>       After the call to the `DEFUN' macro, you must write the argument
>    list that every C function must have, including the types for the
>    arguments.  For a function with a fixed maximum number of

Re: Sharing: member type deduction for member pointers (Alf's device?)

2010-07-19 Thread Alf P. Steinbach /Usenet

* Vladimir Jovic, on 19.07.2010 09:41:

Alf P. Steinbach /Usenet wrote:


#include   // PyWeakPtr, PyPtr, PyModule,
PyClass
using namespace progrock;

namespace {
using namespace cppy;

struct Noddy
{
PyPtr   first;
PyPtr   last;
int number;

Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs )
: number( 0 )
{
devsupport::suppressUnusedWarning( pySelf );

PyWeakPtr   pFirstName  = 0;
PyWeakPtr   pLastName   = 0;

static char*kwlist[] = { "first", "last", "number", 0 };

::PyArg_ParseTupleAndKeywords(
args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist,
pointerTo( pFirstName ), pointerTo( pLastName ), &number
)
>> Accept< IsNonZero >()
|| throwX( "Invalid args" );

if( pFirstName != 0 )   { first = pFirstName; }
if( pLastName != 0 ){ last = pLastName; }


Why not initiallize all member variables in the initializer list?


'PyPtr' is a smart pointer with default constructor, so 'first' and 'last' are 
initialized to zero implicitly.


My goal was to emulate the Python 3.1.1 docs' Noddy2 example as closely as 
possible. And that code's assignment of zero to 'first' and 'last' here 
corresponds to default initialization to zero. :-)


Anyway, parsing the Python arguments in the constructor initializer list is 
possible, but would be inefficient to do directly since it would then involve 
parsing the Python arguments three times (once for each data member).


There is at least one way around that problem, namely outfitting a derived class 
with knowledge of the Noddy class' Python-side __init__ arguments.


But I haven't implemented such support, and I don't know if it would do any 
good. As it is Noddy above is self-contained, except for exporting names to the 
Python side. With a derived class doing the argument parsing it would be less 
self-contained, and the machinery for that would add complexity, I think.


So, I strive to make things simple and explicit (KISS: Keep It Simple, Stupid!).

And I strive to not go into orgies of smart templates doing things implicitly...



}

PyPtr name()
{
(first != 0)
|| throwX( ::PyExc_AttributeError, "first" );
(last != 0)
|| throwX( ::PyExc_AttributeError, "last" );


Nice trick. I would still find this more readable :

if ( first != 0 )
{
   throwX( ::PyExc_AttributeError, "first" );
}


Ah, well. :-)

You can read about the rationale here: http://alfps.wordpress.com/2010/07/18/cppx-b-true-or-b-thrown-using-the-throwing-pattern/> 
 --  posted yesterday.


Of course the only reason that those member variables /can/ be 0 is because I'm 
following the doc's progression of examples. The next version in the docs avoid 
the 0 possibility, as I recall. And the simple way of achieving that in cppy 
would be to declare 'first' and 'last' as PyString instead of generic PyPtr...




return (PyString( first ) + L" " + PyString( last )).pyPtr();
}
};

struct NoddyPyClass: PyClass< Noddy >
{
NoddyPyClass( PyModule& m, PyString const& name, PyString
const& doc )
: PyClass< Noddy >( m, name, doc, Exposition()
.method(
L"name",CPPY_GLUE( name ),
L"Return the name, combining the first and last name"
)
.attribute(
L"first",   CPPY_GLUE( first ), L"first name"
)
.attribute(
L"last",CPPY_GLUE( last ),  L"last name"
)
.attribute(
L"number",  CPPY_GLUE( number ),L"noddy number"
)
)
{}
};

class NoddyModule: public PyModule
{
private:
NoddyPyClassnoddyPyClass_;

public:
NoddyModule()
: PyModule(
L"noddy2", L"Example module that creates an extension
type." )
, noddyPyClass_( *this,
L"Noddy", L"A Noddy object has a name and a noddy
number" )



hmmm what is L ?


It's standard C and C++ notation for a wide character literal, where each 
character is of type 'wchar_t' instead of plain 'char'.


Essentially the intent is to hold Unicode UTF16 or UTF32 code points, which is 
how it is in practice, although for political correctness the C and C++ 
standards allow for other wide character encodings (not necessarily Unicode).


It is the only way to /portably/ use national character literals in C++, because 
otherwise the result depends on the source code encoding. E.g.


  sizeof( "æ" )

yields 2 (the character 'æ' plus a zero byte at the end) with source code in 
Windows ANSI Western, and 3 with source code in UTF8, while


  sizeof( L"æ" )/sizeof( wchar_t )

s

Re: Sharing: member type deduction for member pointers (Alf's device?)

2010-07-19 Thread Vladimir Jovic

Alf P. Steinbach /Usenet wrote:

#include   // PyWeakPtr, PyPtr, PyModule, 
PyClass

using namespace progrock;

namespace {
using namespace cppy;

struct Noddy
{
PyPtr   first;
PyPtr   last;
int number;

Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs )
: number( 0 )
{
devsupport::suppressUnusedWarning( pySelf );

PyWeakPtr   pFirstName  = 0;
PyWeakPtr   pLastName   = 0;

static char*kwlist[] = { "first", "last", "number", 0 };

::PyArg_ParseTupleAndKeywords(
args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist,
pointerTo( pFirstName ), pointerTo( pLastName ), &number
)
>> Accept< IsNonZero >()
|| throwX( "Invalid args" );

if( pFirstName != 0 )   { first = pFirstName; }
if( pLastName != 0 ){ last = pLastName; }


Why not initiallize all member variables in the initializer list?



}

PyPtr name()
{
(first != 0)
|| throwX( ::PyExc_AttributeError, "first" );
(last != 0)
|| throwX( ::PyExc_AttributeError, "last" );


Nice trick. I would still find this more readable :

if ( first != 0 )
{
  throwX( ::PyExc_AttributeError, "first" );
}



return (PyString( first ) + L" " + PyString( last )).pyPtr();
}
};

struct NoddyPyClass: PyClass< Noddy >
{
NoddyPyClass( PyModule& m, PyString const& name, PyString const& 
doc )

: PyClass< Noddy >( m, name, doc, Exposition()
.method(
L"name",CPPY_GLUE( name ),
L"Return the name, combining the first and last name"
)
.attribute(
L"first",   CPPY_GLUE( first ), L"first name"
)
.attribute(
L"last",CPPY_GLUE( last ),  L"last name"
)
.attribute(
L"number",  CPPY_GLUE( number ),L"noddy number"
)
)
{}
};

class NoddyModule: public PyModule
{
private:
NoddyPyClassnoddyPyClass_;

public:
NoddyModule()
: PyModule(
L"noddy2", L"Example module that creates an extension 
type." )

, noddyPyClass_( *this,
L"Noddy", L"A Noddy object has a name and a noddy number" )



hmmm what is L ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fascinating interview by Richard Stallman on Russia TV

2010-07-19 Thread Nick Keighley
On 18 July, 09:38, Emmy Noether  wrote:
> On Jul 18, 1:09 am, Nick <3-nos...@temporary-address.org.uk> wrote:
> > Emmy Noether  writes:



> > > In this video, Stall man makes 4 promises to public but stalls on 2nd
> > > of them.
>
> > I have no idea of the rights or wrongs of this case.  But I've found
> > through experience that when someone uses a "witty" misspelling of
> > someone's name, they are almost always the one in the wrong.  
>
> Huh, you forgot that the whole of GNU = Gnu Not Unix

you know someone named GNU? They must have had strange parents...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why is this group being spammed?

2010-07-19 Thread Stephen Hansen
On 7/17/10 10:01 PM, be.krul wrote:
> why is this group being spammed?

Because while God created the Internet, the Devil twisted it by creating
spammers.

What do you expect? Adam just didn't pay enough attention when Eve made
him a waldorf salad; we descendants of Seth have gone and tried to
devour not only the knowledge of good and evil but all knowledge of all
things, most notably breasts.

Of course there'd be a dire consequence for our hubris.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



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


Emacs Time Line, Graphical Chart by Jamie Zawinski - Valuable Resource for Newbies - written: 8-Mar-1999, updated: 29-Oct-2007

2010-07-19 Thread bolega
Many newbies would find this one by Jamie Zawinski, of immense help

http://www.jwz.org/doc/emacs-timeline.html

written: 8-Mar-1999,  updated: 29-Oct-2007

For more detail about the early days, please see Bernie Greenberg's
paper, Multics Emacs: The History, Design and Implementation.

I've drawn lines only where code is shared, not merely ideas.

1976TECMAC and TMACS
a pair of "TECO-macro realtime editors."
by Guy Steele, Dave Moon, Richard Greenblatt,
Charles Frankston, et al.
  |
  |
1976EMACS
by Richard Stallman, Guy Steele,   EINE (EINE Is Not
EMACS)
and Dave Moon. by Dan Weinreb.
Merger of TECMAC and TMACS, plus   for MIT Lisp Machine.
a dynamic loader and Meta-key cmds.First Emacs written in
Lisp.
Ran on ITS and TWENEX (Tops-20)|
written in TECO and PDP 10 assembly.   |
   |
   |
1978Multics Emacs ZWEI (ZWEI Was EINE
Initially)
by Bernie Greenberg.  by Dan Weinreb and Mike
McMahon.
written in MacLisp;|
also used Lisp as its  |
extension language.|
1980 ZMACS (direct descendant
of ZWEI)
 on Symbolics LM-2, LMI
LispM,
 and later, TI Explorer
(1983-1989)
1981   Gosling Emacs   :
   by James Gosling:
   written in C; with "Mocklisp"
   as its extension language.
   /  |
1983  /   |
 /   Unipress Emacs (6-may-83)
/$395 commercial product.
1984   /   Hemlock
  /by Bill Chiles,
 / Rob MacLachlan,
et al.
1985  GNU Emacs 13.0? (20-mar-85)  written in
Spice Lisp
  by Richard Stallman. (CMU Common
Lisp)
  initial public release?  :
 | :
  GNU Emacs 15.10 (11-apr-85)  :
 |
  GNU Emacs 15.34 (07-may-85)
 |
  GNU Emacs 16.56 (15-jul-85)
  (Gosling code expunged
  for copyright reasons)
 |
 |
  GNU Emacs 16.60 (19-sep-85)
  (contained first patches from
  the net, including preliminary
  SYSV support)
 |
 |
  GNU Emacs 17.36 (20-dec-85)
  (included TeX manual; first
  version that worked on SYSV
  out of the box)
 |
 |
1986  GNU Emacs 18.24 beta (02-oct-86)
 |
1987  GNU Emacs 18.41 (22-mar-87)
 |
  GNU Emacs 18.45 (02-jun-87)
 |
  GNU Emacs 18.49 (18-sep-87)
 |   \
 |\
 | \
 |  \
 |   Early work on
Epoch begins (1987)
 |   by Alan M.
Carroll
1988  GNU Emacs 18.50 (13-feb-88)
|
 |
|
  GNU Emacs 18.51 (07-may-88)
|
 |
|
  GNU Emacs 18.52 (01-sep-88)
|
 |Epoch 1.0
(14-dec-88)
 |by Alan M.
Carroll with Simon Kaplan
1989  GNU Emacs 18.53 (24-feb-89)
|
 |   \
|
 |\
|   _
 |
|\
  GNU Emacs 18.54 (26-apr-89)
| \
 |
|  \
  GNU Emacs 18.55 (23-aug-89)
|   \
 ||
|\
 ||
| NEmacs 3.2.1 (15-dec-89)
 ||
| "Nihongo Emacs": a fork
 ||
| with multi-byte Japanese
 ||
| language support.
 ||
| |
 ||   Epoch 2.0
(23-dec-89) |
 ||
| |
 ||
| |
1990 ||   Epoch 3.1
(06-feb-90) |
 ||
| |
 |\
| NEmacs 3.3.1 (3-mar-90)
 | \
| |
 |  \ Epoch 3.2
(11-dec-90) |
 |   \last C

Re: Difference between import in script and from interpreter

2010-07-19 Thread News123
Edward Diener wrote:
> In a python script a:
> 
> from xxx.yyy.zzz import aaa
> 
> fails with the message:
> 
> "ImportError: No module named xxx.yyy.zzz"
> 
> but from within the python interpreter the same line succeeds. What
> would be the causes of that ?
> 
> From within the python interpreter I have looked at sys.path and
> xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am
> not sure why this is failing within the python script.

Probably your problem is, that you call a python script, which is NOT
located in the current working directlory.


if you type python

then imports will be relative to your current working directory

if you execute a script imports will be relative to the scripts location.


no idea in which directory you are when starting python from a windows menu.

you can set
PYTHONPATH to point to the base directory of your project if you want to
be sure to always find your modules
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: rstrip()

2010-07-19 Thread News123
Dennis Lee Bieber wrote:
> On Sun, 18 Jul 2010 17:49:11 +0100, MRAB 
> declaimed the following in gmane.comp.python.general:
> 
>> How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something
> 
>   Not sure what the first would do... unless one is envisioning
> 
>   "abracadabra".strip_str("abra")...
> 
>   For the others... trim_suffix, trim_prefix are more explicit in
> meaning -- after all, someone might ask if there is an *strip_unicode
> too! (or _bytes). That still leaves the question of what the desired
> behavior of
> 
>   "Shanana".trim_suffix("na") 
> 
> is to produce? "Sha" or "Shana"?
> 
> 


What I'd imagine would be stripping of a suffix or the first match in a
list of suffixes exactly once.

TO me this seems the most common use case, though one is surprised how
functions can be used.


Example:

def strip_suffix(str,*suffixes):
for suffix in suffixes:
if str.endswith(suffix):
return str[-len(suffix):]
return str
-- 
http://mail.python.org/mailman/listinfo/python-list