Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Russ P.
On Dec 1, 11:34 pm, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:
> "Russ P."  wrote:
> > I am surprised to see that Newton is not taken. I urge
> > Guido to take it while it is still available. Sir Isaac
> > certainly deserves the honor.
>
> Does he?  Are you aware of how he treated Hooke?
>
> He was a great technician, but as a person, you would
> not have had him marry your sister.
>
> - 1 on this silly "Newton" idea.
>
> - Hendrik

I neither know nor care much about Newton's personality and social
graces, but I can assure you that he was more than a "technician" (no
offense to technicians).

If you just read the Wikipedia preamble about him you will realize
that he is arguably the greatest scientist who ever lived. Sorry for
the inefficient use of bandwidth, but I just couldn't refrain from
copying it here:

Sir Isaac Newton FRS (pronounced /ˈnjuːtən/) (4 January 1643 – 31
March 1727) [ OS: 25 December 1642 – 20 March 1727][1] was an English
physicist, mathematician, astronomer, natural philosopher, and
alchemist. His treatise Philosophiae Naturalis Principia Mathematica,
published in 1687, described universal gravitation and the three laws
of motion, laying the groundwork for classical mechanics, which
dominated the scientific view of the physical universe for the next
three centuries and is the basis for modern engineering. He showed
that the motions of objects on Earth and of celestial bodies are
governed by the same set of natural laws by demonstrating the
consistency between Kepler's laws of planetary motion and his theory
of gravitation, thus removing the last doubts about heliocentrism and
advancing the scientific revolution.

In mechanics, Newton enunciated the principles of conservation of
momentum and angular momentum. In optics, he invented the reflecting
telescope and developed a theory of colour based on the observation
that a prism decomposes white light into a visible spectrum. He also
formulated an empirical law of cooling and studied the speed of sound.

In mathematics, Newton shares the credit with Gottfried Leibniz for
the development of the calculus. He also demonstrated the generalized
binomial theorem, developed the so-called "Newton's method" for
approximating the zeroes of a function, and contributed to the study
of power series.

In a 2005 poll of the Royal Society of who had the greatest effect on
the history of science, Newton was deemed more influential than Albert
Einstein.[2]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Dotan Cohen
On 01/12/2007, Russ P. <[EMAIL PROTECTED]> wrote:
> > So what dou you think about D language? :) Or F or F#?
>
> I think that one-letter names are even worse for languages than they
> are for variables.

And they are impossible to google.

Update: well, they were when _I_ needed to... I just tried, and both
"C" and "C++" gave relevant results. A few years ago, "C" would not
return anything programming-related, and "C++" returned exactly the
same results as "C". Google has improved (I say that weekly).

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Dotan Cohen
On 02/12/2007, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> "Russ P."  wrote:
>
> > I am surprised to see that Newton is not taken. I urge
> > Guido to take it while it is still available. Sir Isaac
> > certainly deserves the honor.
>
> Does he?  Are you aware of how he treated Hooke?
>
> He was a great technician, but as a person, you would
> not have had him marry your sister.

I'm still convinced that Leibniz _threw_ the apple at Newton's head.

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Dotan Cohen
On 02/12/2007, Russ P. <[EMAIL PROTECTED]> wrote:
> I neither know nor care much about Newton's personality and social
> graces, but I can assure you that he was more than a "technician" (no
> offense to technicians).
>
> If you just read the Wikipedia preamble about him you will realize
> that he is arguably the greatest scientist who ever lived. Sorry for
> the inefficient use of bandwidth, but I just couldn't refrain from
> copying it here:

You might want to read a bit about Archemedes, Gauss, Leonardo, Euler,
and Tesla. Along with Newton, these were some of the most amazing and
talented people that have been recognized. And even though Leonardo
may seem out of place on that particular list, I assure you that he is
not.

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-- 
http://mail.python.org/mailman/listinfo/python-list

i18n a Python app

2007-12-02 Thread Donn Ingle
Hi,
 I have been going spare looking for a tutorial or howto from my pov as a
total beginner to i18n.
 I understand that one must use gettext, but there seems to be no good info
about *how* one uses it.
 What command line utilities does one use to:
1. make a .pot file
2. make a .mo file
 Are there specific Python aspects to the above, or is it all pure Gnu
gettext?

 The docs are not a tutorial and simply list bare functions which does not
provide any insight. I was hoping there'd be some good links or experience
on the list.

\d

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


Re: [OT] minimalist web server

2007-12-02 Thread I V
On Sat, 01 Dec 2007 19:02:41 -0800, Daniel Fetchinson wrote:
> The reason I need this is that my current best strategy to avoid ads in
> web pages is putting all ad server names into /etc/hosts and stick my
> local ip number next to them (127.0.0.1) so every ad request goes to my
> machine. I run apache which has an empty page for 404 errors so I'll

In this case, do you need a webserver at all? If your browser tries to 
access a web server on 127.0.0.1 and there isn't one, won't the result, 
in most cases, be more or less the same as if the server returned a 404?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie - question about lexical scoping

2007-12-02 Thread Hrvoje Niksic
"Matt Barnicle" <[EMAIL PROTECTED]> writes:

>> i have a class dict variable that apparently holds its value across
>> instantiations of new objects..
[...]
> ok, i see...  python has a concept i'm not accustomed to

I don't doubt that Python managed to confuse you here, but in this
case there is nothing really unusual or novel in Python's treatment of
class variables.  Equivalent Java code would behave exactly the same:

class Foo {
static Map bar = new HashMap();
static {
bar.put("baz", "bing");
}
}

Foo a = new Foo();
a.bar.put("baz", "bong");

Foo b = new Foo();
System.out.println(b.bar.get("baz"));
-> "bong"

> so i'm sure what is going on is obvious to experienced python
> programmers...  i'm not really sure how to get around this though.

Simply do what you'd do in any other OO language: assign a fresh value
to each instance in its constructor:

class Foo(object):
def __init__(self):
self.bar = {'baz': 'bing'}

Now each instance of Foo has a separate "bar" attribute dict which can
be mutated without affecting other instances.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyro and sqlite3 problem

2007-12-02 Thread Sébastien Ramage

> Off hand -- ensure that each remote access runs the entire sequence
> of "connect, cursor, execute, fetch, cursor-close, connection-close"
> rather than trying to, say, create a cursor in one access and then use
> that cursor on a second access...
>
> Or maybe create one long-running thread to handle the database
> access and use queue objects to transfer the remote access parameters to
> the database thread, then retrieve from a return queue.
> --

thanks you for answer.
Do you think the first solution will be slow? I think I must use
locking to avoid problem.

The second solution seems better and looks like what I wanted to build
at first time, but maybe an ever opened sqlite database isn't a good
thing ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Bjoern Schliessmann
Russ P. wrote:
> Python is an "acceptable" name, but Newton1 (or Newton3) would be
> a great name. 

Nah, I like Monty and Snakes. Newton already has his name as unit
for kg*m/s^2. :)

Regards,


Björn

-- 
BOFH excuse #74:

You're out of memory

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


Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Steven D'Aprano
On Sat, 01 Dec 2007 23:55:32 -0800, Russ P. wrote:

> I neither know nor care much about Newton's personality and social
> graces, but I can assure you that he was more than a "technician" (no
> offense to technicians).
> 
> If you just read the Wikipedia preamble about him you will realize that
> he is arguably the greatest scientist who ever lived.

"Arguably" is right.

Please, stop with the fanboy squeeing over Newton. Enough is enough. 
Newton has already received far more than his share of honours.

He might have been a great intellectual but he was no scientist. It's 
only by ignoring the vast bulk of his work -- work which Newton himself 
considered *far* more important and interesting than his work on physics 
and mathematics -- that we can even *pretend* he was a scientist.

Newton was arrogant, deceitful, secretive, and hostile to other peoples 
ideas. Arrogance sometimes goes hand in hand with intellectual 
brilliance, and there's no doubt that Newton was brilliant, but the last 
three are especially toxic for good science. His feuds against two of his 
intellectual equals, Leibniz and Hooke, held mathematics and the sciences 
back significantly. They weren't the only two: he feuded with Astronomer 
Royal John Flamsteed, John Locke, and apparently more tradesmen than 
anyone has counted. He held grudges, and did his best to ruin those who 
crossed him.

Historians of science draw a fairly sharp line in the history of what 
used to be called "natural philosophy" (what we now call science). That 
line is clearly drawn *after* Newton: as John Maynard Smith has said, 
Newton was the last and greatest of the magicians, not the first of the 
scientists. He was first and foremost a theologian and politician, an 
alchemist, a religious heretic obsessed with End Times, and (when he 
wasn't being secretive and isolating himself from others) a shameless 
self-promoter unwilling to share the spotlight.

The myth of Newton the scientist is pernicious. Even those who recognise 
his long periods of unproductive work, his wasted years writing about the 
end of the world, his feuds, his secrecy and his unprofessional grudges 
against other natural philosophers, still describe him as a great 
scientist -- despite the fact that Newton's way of working is anathema to 
science. The myth of science being about the lone genius dies hard, 
especially in popular accounts of science. Science is a collaborative 
venture, like Open Source, and it relies on openness and cooperation, two 
traits almost entirely missing in Newton.

There is no doubt that Newton was a great intellect. His influence on 
mechanics (including astronomy) was grand and productive; that on optics 
was mixed, but his alchemical writings have had no influence on modern 
chemistry. Newton's calculus has been virtually put aside in favour of 
Leibniz's terminology and notation. The great bulk of his work, his 
theological writings, had little influence at the time and no lasting 
influence at all.

Newton was lucky to live at a time of great intellectual activity. Had he 
lived thirty years earlier, his secrecy would almost certainly have meant 
that his discoveries, such as they were, would have died with him. Had he 
lived thirty years later, others like Leibniz, Hooke, the Bernoullis, or 
others, would have made his discoveries ahead of him -- perhaps a few 
years or a decade later, but they would have done so, as Leibniz 
independently came up with calculus.

There's no doubt that Newton was a genius and an important figure in the 
history of science, but to describe him as a scientist is to distort both 
the way Newton worked and the way science works. By all means give him 
credit for what he did and what he was, but don't pretend he was 
something that he was not.


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


Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Clement
On Dec 1, 9:51 am, "Dotan Cohen" <[EMAIL PROTECTED]> wrote:
> On 30/11/2007, Gerardo Herzig <[EMAIL PROTECTED]> wrote:
>
> > You will be eaten by the Snake-Ra god tonight!
>
> Wasn't Ra the Sun god?
>
> Dotan Cohen
>
> http://what-is-what.comhttp://gibberish.co.il
> א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
>
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?

use my name : clement programming languge .. nice la.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: i18n a Python app

2007-12-02 Thread Donn Ingle
Another thought, how would one provide translations for doc strings?

class Boo:
 """This class goes Boo!"""

Can one do this, which does not seem likely:
class Boo:
 _( "This class goes Boo!" )


\d

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


Re: How to read strings cantaining escape character from a file and use it as escape sequences?

2007-12-02 Thread Duncan Booth
John Machin <[EMAIL PROTECTED]> wrote:

> Hmmm ... the encode is documented as "Produce a string that is
> suitable as Unicode literal in Python source code", but it *isn't*
> suitable. A Unicode literal is u'blah', this gives just blah. Worse,
> it leaves the caller to nut out how to escape apostrophes and quotes:
> 
 test = u'Python\'\'\'\'\"\"\"\"\u1234\n'
 print repr(test)
> u'Python\'\'\'\'\u1234\n'
 print test.encode('unicode-escape')
> Python\u1234\n

> 
> Why would someone bother writing this codec when repr() does the job
> properly?
> 
I don't know why it was written, but if it helps I can tell you why I have 
had occasion to use it: precisely because it does leave the caller to 'nut 
out how to escape apostrophes and quotes'.

repr() does a good enough job if you just want a Python source string, but 
you can't control whether repr will escape quotes or apostrophes - if the 
string contains an apostrophe and no double-quote then the repr will 
enclose it in double-quotes, otherwise it always uses single quotes.

>>> u'"', u'"\'', u'\'"', u'\''
(u'"', u'"\'', u'\'"', u"'")

If you want to force a particular quoting convention then unicode-escape 
gets you half way there and you can get the rest of the way with a couple 
of replace calls.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] minimalist web server

2007-12-02 Thread Michael Ströder
Paul Rubin wrote:
>> from SimpleHTTPServer import SimpleRequestHandler
>> handler = HTTPServer (('', 8000), SimpleRequestHandler)
> 
> 
> I think you mean SimpleHTTPRequestHandler.  Note that actually reads
> the url path and looks in the file system to get the file of that
> name, which isn't what the OP wanted.

But it's very easy to override the handler method and return the 404 for
each and every request.

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


question involving installation of python applications

2007-12-02 Thread Giancarlo Bassi
Why python interpreter has two copies ?:

so that:

ls -l python*
-rwxr-xr-x  1 root root 2288515 Nov 10 13:41 python
lrwxrwxrwx  1 root root  16 Jul  3 02:06 python-config ->
python2.5-config
-rwxr-xr-x  1 root root 2288515 Nov 22 00:25 python2.3
-rwxr-xr-x  1 root root1424 Jul  3 02:06 python2.5-config

---

If someone wants to keep more python interpreters how
can avoid to superpose them.

Only by renaming ?
Is there reference into documentation ?

I want to keep python 2.3.5 and Zope-2.8-final for FLE3 (future learning 
environment) and install also pychess, requiring pygtk 2.x , (possibly for 
python 2.5.1)

While I managed to install FLE3 , after installing python2.5.1
I didn't success to run again the daemon for running Zope-2.8.

I got somewhat like that:

[EMAIL PROTECTED]:/home/aka-ankku/Zope-2.8.0-final$ bin/zopectl
Traceback (most recent call last):
   File
"/mnt/hd/home/aka-ankku/Zope-2.8.0-final/lib/python/Zope2/Startup/zopectl.py
", line 43, in ?
 import Zope2.Startup
   File
"/mnt/hd/home/aka-ankku/Zope-2.8.0-final/lib/python/Zope2/__init__.py", 
line
60, in ?
 from Zope2.Startup.run import configure
   File
"/mnt/hd/home/aka-ankku/Zope-2.8.0-final/lib/python/Zope2/Startup/__init__.p
y", line 24, in ?
 import ZConfig
   File
"/mnt/hd/home/aka-ankku/Zope-2.8.0-final/lib/python/ZConfig/__init__.py",
line 21, in ?
 from ZConfig.loader import loadConfig, loadConfigFile
   File
"/mnt/hd/home/aka-ankku/Zope-2.8.0-final/lib/python/ZConfig/loader.py", 
line 26, in ?
 import ZConfig.schema
   File
"/mnt/hd/home/aka-ankku/Zope-2.8.0-final/lib/python/ZConfig/schema.py", 
line
44, in ?
 class BaseParser(xml.sax.ContentHandler):
AttributeError: 'module' object has no attribute 'ContentHandler'
--

Why 'module' object has no attribute 'ContentHandler' ?


THX,
GB

---
"I'm no Pawn, I'm Donald Duck ! "
-- Donald in MathMagic Land

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


Re: Gnu/Linux dialogue boxes in python

2007-12-02 Thread Jorgen Grahn
On Fri, 30 Nov 2007 15:55:16 +0200, Donn Ingle <[EMAIL PROTECTED]> wrote:
> Hi,
>  Okay, so I am in the mood to try this: Inform the user about what modules
> the app requires in a graphical dialogue that can vary depending on what
> the system already has installed. (It will fail-to output on cli)
>
> I am running Kubuntu and I seem to have 'kdialog' installed by default (not
> sure if it came as stock.)
>
> What other 'stock' systems are there out there in the wild? Ubuntu? Suse?
> Fedora? Others?

There are countless Unix configurations out there which can run Python.

I run Debian Linux, and I install none of that KDE or Gnome
cra^H^H^Hsoftware.  Apt/dpkg uses some kind of console dialogue program
("newt"?) but that's the only thing I have.

There is no guarantee that even a modern, full-featured Unix
installation contains a dialogue application like you want.

> I would take a stab at wrapping them in python so that I can use the first
> dialogue system found to popup messages for the user.

But why?  Either

(a) your program has a GUI and can display a dialogue box by itself
(b) your program has a GUI but has problems opening even a tiny part
of it (missing modules?), and should output diagnostics on the terminal
(c) your program is console-based, or a daemon or something, and should
not require a GUI to work.

/Jörgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.access() under windows

2007-12-02 Thread Yann Leboulanger
David Tweet wrote:
> To answer indirectly, usually the EAFP (easier to ask forgiveness than
> permission) approach works better for this kind of thing.
> 
> try:
>   f = open('e:\\test\\test', 'a')
>   f.write('abc')
>   f.close()
> except IOError:
>   print "couldn't write test file, continuing..."
> 
> On Dec 1, 2007 1:48 AM, Yann Leboulanger <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> Under Windows XP os.access has a strange behaviour:
>>
>> I create a folder test under e:
>>
>> then os.access('e:\\test', os.W_OK) returns True. Everything's ok.
>>
>> Now I move My Documents to this e:\test folder
>>
>> Then os.access('e:\\test', os.W_OK) returns False !!
>>
>> but this works:
>> f = open('e:\\test\\test', 'a')
>> f.write('abc')
>> f.close()
>>
>> So why os.access returns False ?
>>
>> --
>> Yann
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> 


yep but the test file I try to create to know if I can write there may
be a folder for exemple, and the open() will fail.

So this can be considered as a bug in os module?
-- 
http://mail.python.org/mailman/listinfo/python-list


C++2py

2007-12-02 Thread farsheed
I,m looking for a tool for converting c++ to python. Any Ideas?
TIA.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gnu/Linux dialogue boxes in python

2007-12-02 Thread Donn Ingle
> But why?  Either
> 
> (a) your program has a GUI and can display a dialogue box by itself
> (b) your program has a GUI but has problems opening even a tiny part
> of it (missing modules?), and should output diagnostics on the terminal
> (c) your program is console-based, or a daemon or something, and should
> not require a GUI to work.
> 
I realise those things, and it's the simplest case. 

 I was thinking of  allow a setup.py file to
be double-clicked and have the install start to run. When it comes to the
bit where all the import statements happen, it can popup a stock dialogue
informing the user about what they need to install first.

I was hoping to get a list of the most common, distro-installed scriptable
dialogues. Perhaps I should even look at TK -- I understand it comes
standard with Python?

 Another thing to realize, and I have experienced this first-hand, is that a
bunch of text, no matter how nicely formatted, spewed out of an app in
white on black ( the usual terminal colours ) does *not* invite a user's
attention. To read it is a chore and they usually panic.

\d

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

Re: Code Management

2007-12-02 Thread BlueBird
On Nov 26, 5:07 pm, "Sergio Correia" <[EMAIL PROTECTED]> wrote:
> Bluebird:
>
> If you are using python 2.5, relative imports are no longer an
> issue:http://docs.python.org/whatsnew/pep-328.html

It does not solve my problem, or I missed something:

[EMAIL PROTECTED] /cygdrive/d/work/work/vy-dev/foo $ find . -name '*.py'
./bar/bar.py
./bar/tests/test_bar.py
./bar/tests/test_bar1.py
./bar/tests/__init__.py
./bar/__init__.py
./foo/foo.py
./foo/tests/__init__.py
./foo/__init__.py
./__init__.py

d:\work\work\vy-dev\foo>C:\Python25\python.exe  bar/tests/test_bar.py
d:\work\work\vy-dev\foo
['d:\\work\\work\\vy-dev\\foo\\bar\\tests', 'C:\\Python25\\lib\\site-
packages\\h
gsvn-0.1.4-py2.5.egg', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\
\Python25\\DLL
s', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\
\lib\\lib-
tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages', 'C:\\Python25\
\lib\\sit
e-packages\\win32', 'C:\\Python25\\lib\\site-packages\\win32\\lib', 'C:
\\Python2
5\\lib\\site-packages\\Pythonwin', 'C:\\Python25\\lib\\site-packages\
\wx-2.8-msw
-ansi']
Traceback (most recent call last):
  File "bar/tests/test_bar.py", line 8, in 
from ..bar import bar_f
ValueError: Attempted relative import in non-package

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


Re: X/Linux mouse_event (like in win32api)

2007-12-02 Thread Jorgen Grahn
On Thu, 29 Nov 2007 01:59:20 -0800 (PST), Atila Olah <[EMAIL PROTECTED]> wrote:
> Hello everyone.
> I would like to be able to emit a mouse click on my xgl/compiz
> desktop, like I used to do in Windows:
...
> Is there a way to interact directly with the X server (or with the
> kernel?) to simulate a click? And if it can't be done in Python, where
> should I go?

This is probably best done in Xlib, the lowest-level X11 API.  See the
XSendEvent() call, and feed it to Google for more information.

I think there is a Python interface to Xlib, although I haven't used it.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Witch editor to use!

2007-12-02 Thread Jorgen Grahn
On Fri, 30 Nov 2007 12:50:06 -0800 (PST), rm <[EMAIL PROTECTED]> wrote:
...
> Both Vim and Emacs are hard to learn.  In other words, they will
> require that you spend at least some time studying how they work and
> practicing.  They have a learning curve that is much larger than using
> something simple like NEdit, Gedit, KWrite, etc.  But, they are a lot
> more powerful.

In other words: if there are no features, you don't have to work to
learn them?

I agree that learning to use an editor well is hard work -- but its
well worth it.  It's the primary interface between the programmer and
the computer, and will continue to be so until you are too old to
type.

> One thing that I think favors Vim over Emacs, is that
> Vim seems to be installed by default on almost all Linux distros.

As I understand it, they tend to include a crippled version of vim
with many of the interesting features disabled.  Doesn't help a Python
developer much.  Of course, both Emacs and the full vim are
trivial to install, unless you're the sysadmin's sworn enemy.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++2py

2007-12-02 Thread Diez B. Roggisch
farsheed schrieb:
> I,m looking for a tool for converting c++ to python. Any Ideas?


Python to C++ - that's shedskin. But the other way round, you don't 
stand a chance. The semantics of C++ are so rich - even _if_ somebody 
would try and create a C++2python-converter, the result would be less 
than pythonic if not actually outright unreadable.


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


Re: C++2py

2007-12-02 Thread markacy
On 2 Gru, 15:56, farsheed <[EMAIL PROTECTED]> wrote:
> I,m looking for a tool for converting c++ to python. Any Ideas?
> TIA.

What about SWIG (http://www.swig.org/) or Boost.Python (http://
www.boost.org/libs/python/doc/)? These are not converters, but I hope
this helps you.

Cheers,

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


String formatting with %s

2007-12-02 Thread Donn Ingle
Hi,
 I'm sure I one read somewhere that there is a simple way to set the order
of replacements withing a string *without* using a dictionary.

What I mean is:
>>> s = "%s and %s" % ( "A", "B" )
>>> print s
A and B

Now, is there something quick like:
>>> s = "%s/2 and %s/1" % ( "A", "B" )
>>> print s
B and A

?

I know it can be done with a dict:
d = { "one" : "A", "two" : "B"  }
s = "%(two)s and %(one)s" % d


\d

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


Re: String formatting with %s

2007-12-02 Thread Mel
Donn Ingle wrote:
  > Now, is there something quick like:
 s = "%s/2 and %s/1" % ( "A", "B" )
 print s
> B and A
> 
> ?

GNU glibc printf accepts a format string:

printf ("%2$s and %1$s", "A", "B");

to produce what you want -- but not Python, AFAIK.


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


Re: python newbie - question about lexical scoping

2007-12-02 Thread Bruno Desthuilliers
Matt Barnicle a écrit :
>>>On Dec 1, 4:47 pm, Matt Barnicle <[EMAIL PROTECTED]> wrote:
>>
>>aye yaye aye...  thanks for the pointers in the right direction..  i
>>fiddled around with the code for a while and now i've reduced it to the
>>*real* issue...  i have a class dict variable that apparently holds its
>>value across instantiations of new objects..

If it's a class attribute, it's indeed shared between all instances...

>>  the problem can be
>>illustrated in the following much simpler code:
>>
>class foo():
>>
>>... bar = { 'baz': 'bing' }
(snip)
> ok, i see...  python has a concept i'm not accustomed to which i found
> described here:
> 
> http://zephyrfalcon.org/labs/python_pitfalls.html
> 4. Class attributes vs instance attributes
> 
> so i'm sure what is going on is obvious to experienced python
> programmers...  i'm not really sure how to get around this though.  

It's not a problem:

class Foo(object):
   def __init__(self):
 self.bar = {'baz':'bing'}



>i'll
> need to spend some time on reworking our models code i guess...  i
> inherited this from someone, and what he was trying to do was to set
> default values for objects representing tables (in kind of a simple ORM
> layer) and storing the values in a dict, and when the object is
> instantiated, the table is queried and the default dict values are
> overwritten. 

class Foo(object):
   bar = {'baz':'bing'}
   def __init__(self):
 self.bar = self.bar
-- 
http://mail.python.org/mailman/listinfo/python-list


How can i find a file size on the web ?

2007-12-02 Thread Abandoned
Hi..
Can i find a file size witdhout download?
For example: www.roche.com/rochea_z_sp.pdf
How can i find its size with python ?
I'm sorry for my bad english.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i find a file size on the web ?

2007-12-02 Thread Dan Upton
On Dec 2, 2007 11:55 AM, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> Can i find a file size witdhout download?
> For example: www.roche.com/rochea_z_sp.pdf
> How can i find its size with python ?


When you send an HTTP request, most servers will respond with the
content length.  For instance, if you go to http://web-sniffer.net/,
you can type in the file you want to view and you can see the header
sent and received, and for the example you gave, you'll notice the
HTTP Response Header includes a line

Content-Length: 4054802

That should be the information you're looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++2py

2007-12-02 Thread hdante
On Dec 2, 12:56 pm, farsheed <[EMAIL PROTECTED]> wrote:
> I,m looking for a tool for converting c++ to python. Any Ideas?
> TIA.

 Try this:

 http://www.archaeologyinfo.com/homosapiens.htm

 (note, probably you'll need the PRO-PLUS version)

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


Re: reading raw variables from file

2007-12-02 Thread Martin Blume
"MonkeeSage" schrieb 
> >
> > If I have understood python naming scoping correctly,
> > doing
> >my_var="hello"
> >import stuff
> >print my_var
> > is not the same as
> >my_var="hello"
> >exec open("stuff.py").read()
> >print my_var
> > with stuff.py containing
> >my_var="bye"
> 
> It's not the same...
> 
> from stuff import *
> 
> ...is.
> 
And indeed it is. Thanks.
Martin

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


Re: How can i find a file size on the web ?

2007-12-02 Thread Adonis Vargas
Abandoned wrote:
> Hi..
> Can i find a file size witdhout download?
> For example: www.roche.com/rochea_z_sp.pdf
> How can i find its size with python ?
> I'm sorry for my bad english.

Typically you would just do an HTTP HEAD request in order to get 
information about the file without downloading it, but I tested the 
given site and it does not seem to support the HEAD request. Instead I 
used the GET request and read the headers in which contains information 
regarding the file as well, but opted no to read the data to avoid 
downloading it.

import httplib
connection = httplib.HTTPConnection("www.roche.com")
connection.request("GET", "/rochea_z_sp.pdf")
response = connection.getresponse()
print response.status, response.reason
print "File sie: %s" % response.getheader('content-length')

Also you can do:

import urllib
response = urllib.urlopen("http://www.roche.com/rochea_z_sp.pdf";)
print response.info()

Hope this helps.

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


Re: String formatting with %s

2007-12-02 Thread Donn Ingle
> but not Python, AFAIK
Damn!

\d

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


Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Dotan Cohen
On 02/12/2007, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Sat, 01 Dec 2007 23:55:32 -0800, Russ P. wrote:
>
> > I neither know nor care much about Newton's personality and social
> > graces, but I can assure you that he was more than a "technician" (no
> > offense to technicians).
> >
> > If you just read the Wikipedia preamble about him you will realize that
> > he is arguably the greatest scientist who ever lived.
>
> "Arguably" is right.
>
> Please, stop with the fanboy squeeing over Newton. Enough is enough.
> Newton has already received far more than his share of honours.
>
> He might have been a great intellectual but he was no scientist. It's
> only by ignoring the vast bulk of his work -- work which Newton himself
> considered *far* more important and interesting than his work on physics
> and mathematics -- that we can even *pretend* he was a scientist.

The work of Newton that is ignored is no different than the work of
others that has been ignored (with the notable exception of Gauss). In
studying Leonardo's contributions to science, for instance, one must
ignore his contributions to music, art, and other fields. Shall I go
on about Pythagoras?

> Newton was arrogant, deceitful, secretive, and hostile to other peoples
> ideas. Arrogance sometimes goes hand in hand with intellectual
> brilliance, and there's no doubt that Newton was brilliant, but the last
> three are especially toxic for good science. His feuds against two of his
> intellectual equals, Leibniz and Hooke, held mathematics and the sciences
> back significantly. They weren't the only two: he feuded with Astronomer
> Royal John Flamsteed, John Locke, and apparently more tradesmen than
> anyone has counted. He held grudges, and did his best to ruin those who
> crossed him.
>
> Historians of science draw a fairly sharp line in the history of what
> used to be called "natural philosophy" (what we now call science). That
> line is clearly drawn *after* Newton: as John Maynard Smith has said,
> Newton was the last and greatest of the magicians, not the first of the
> scientists. He was first and foremost a theologian and politician, an
> alchemist, a religious heretic obsessed with End Times, and (when he
> wasn't being secretive and isolating himself from others) a shameless
> self-promoter unwilling to share the spotlight.

Newton was the bridge between science and superstition. Without him,
we would not have science. For that he is notable. He is both magician
and scientist. It was Newton's belief in the occult that led to his
discovery of gravity: the fact that distant objects could influence
one another. Even today, science has a hard time accepting that. And
gravity _still_ has not been incorporated into a theory of everything
/ grand unified theory.

> The myth of Newton the scientist is pernicious. Even those who recognise
> his long periods of unproductive work, his wasted years writing about the
> end of the world, his feuds, his secrecy and his unprofessional grudges
> against other natural philosophers, still describe him as a great
> scientist -- despite the fact that Newton's way of working is anathema to
> science. The myth of science being about the lone genius dies hard,
> especially in popular accounts of science. Science is a collaborative
> venture, like Open Source, and it relies on openness and cooperation, two
> traits almost entirely missing in Newton.
>
> There is no doubt that Newton was a great intellect. His influence on
> mechanics (including astronomy) was grand and productive; that on optics
> was mixed, but his alchemical writings have had no influence on modern
> chemistry. Newton's calculus has been virtually put aside in favour of
> Leibniz's terminology and notation. The great bulk of his work, his
> theological writings, had little influence at the time and no lasting
> influence at all.

Newton's calculus has most certainly _not_ been put aside in favour of
Leibniz's calculus! Leibniz's calculus methods are all but forgotten.
All that remains used today is his notation. We are essentially using
Leibniz's notation with Newton's methods.

> Newton was lucky to live at a time of great intellectual activity. Had he
> lived thirty years earlier, his secrecy would almost certainly have meant
> that his discoveries, such as they were, would have died with him. Had he
> lived thirty years later, others like Leibniz, Hooke, the Bernoullis, or
> others, would have made his discoveries ahead of him -- perhaps a few
> years or a decade later, but they would have done so, as Leibniz
> independently came up with calculus.

If we are already imagining that Newton had lived 30 years earlier,
imagine what he could have done for Kepler. Have you ever tried
proving the 3 Kepler laws _without_ calculus? I've seen it done. And
Kepler wasn't proving his laws, he was devising them from measurements
of the sky. From scratch.

> There's no doubt that Newton was a genius and an important figure in the
> history of scienc

Re: python newbie - question about lexical scoping

2007-12-02 Thread hdante
On Dec 1, 11:31 pm, "Matt Barnicle" <[EMAIL PROTECTED]> wrote:
> >> On Dec 1, 4:47 pm, Matt Barnicle <[EMAIL PROTECTED]> wrote:
> > aye yaye aye...  thanks for the pointers in the right direction..  i
> > fiddled around with the code for a while and now i've reduced it to the
> > *real* issue...  i have a class dict variable that apparently holds its
> > value across instantiations of new objects..  the problem can be
> > illustrated in the following much simpler code:
>
>  class foo():
> > ... bar = { 'baz': 'bing' }
> > ...
>  a = foo()
>  a.bar
> > {'baz': 'bing'}
>  a.bar['baz'] = 'bong'
>  a.bar
> > {'baz': 'bong'}
>  b = foo()
>  b.bar
> > {'baz': 'bong'}
>
> ok, i see...  python has a concept i'm not accustomed to which i found
> described here:
>
> http://zephyrfalcon.org/labs/python_pitfalls.html
> 4. Class attributes vs instance attributes
>
> so i'm sure what is going on is obvious to experienced python
> programmers...  i'm not really sure how to get around this though.  i'll
> need to spend some time on reworking our models code i guess...  i
> inherited this from someone, and what he was trying to do was to set
> default values for objects representing tables (in kind of a simple ORM
> layer) and storing the values in a dict, and when the object is
> instantiated, the table is queried and the default dict values are
> overwritten.  so obviously this method is not going to work as such..
>
> sorry for the misdirection, i didn't quite understand at first..
>
> - m@


A trivial solution:

class foo:
default_bar = { 'baz' : 'bong' }
def __init__(self):
self.bar = self.default_bar.copy()
self.bar['woo'] = 'wee'

 Note: it's not necessary to reimplement an ORM. Try using Django (if
you need a complete solution) or Elixir (just the ORM).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyro and sqlite3 problem

2007-12-02 Thread Sébastien Ramage
I'm trying to build a client/server app
the server use a sqlite3 database to store differents things
the client ask the server to get value or store new entries in the
database.
The problem is that Pyro create a new thread for each client

at first time I create the connection to database at server start and
I would re use the connection for transaction but I get the error.
Maybe I can open/close database for each transaction but maybe it
would be slow ?

Seb


2007/12/1, Sergio Correia <[EMAIL PROTECTED]>:

If you are creating a cursor/connection object, you need to use it
in
the same thread that created it. Otherwise, some weird errors can
happen (as many of this list have said).

If you give us more info about the type of the problem (what are
you
trying to do?) we can help you build a safer app.

Best,
Sergio

PS: When faced with the same error, I just recycled the objects
used
in the I/O operations and the problem was solved. However, that
was
done locally, without using Pyro, so your milleage may vary.

On Dec 1, 2007 4:29 AM, Sébastien Ramage
<[EMAIL PROTECTED]> wrote:
>
> Hi !
>
> I'm trying to build an client/server app based on Pyro and
sqlite3.
> But I have a problem using sqlite3 on the server
>
> I got this error :
>
> sqlite3.ProgrammingError: ('SQLite objects created in a thread
can
> only be used
> in that same thread.The object was created in thread id 240 and
this
> is thread i
> d 4068', 'This error occured remotely (Pyro). Remote traceback
is
> available.')
>
> what can I do to avoid this ?
>
> I'm using Python 2.5.1,Pyro 3.7  under Windows
>
> Sébastien
> --
> http://mail.python.org/mailman/listinfo/python-list
>


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


Re: String formatting with %s

2007-12-02 Thread MRAB
On Dec 2, 1:35 pm, Donn Ingle <[EMAIL PROTECTED]> wrote:
> Hi,
>  I'm sure I one read somewhere that there is a simple way to set the order
> of replacements withing a string *without* using a dictionary.
>
> What I mean is:>>> s = "%s and %s" % ( "A", "B" )
> >>> print s
>
> A and B
>
> Now, is there something quick like:>>> s = "%s/2 and %s/1" % ( "A", "B" )
> >>> print s
>
> B and A
>
> ?
>
> I know it can be done with a dict:
> d = { "one" : "A", "two" : "B"  }
> s = "%(two)s and %(one)s" % d
>
> \d

One quick solution is to write a function for it:

def format(template, values):
import re
# Collect the indexes from the template.
order = map(int, re.findall(r'%\[(\d+)\]', template))
# Remove the indexes from the template.
template = re.sub(r'(?<=%)\[(\d+)\]', '', template)
# Create a tuple containing the values in the correct positions.
values = tuple(values[index] for index in order)
return template % values

>>> format("%[0]s and %[1]s", ("A", "B"))
'A and B'
>>> format("%[1]s and %[0]s", ("A", "B"))
'B and A'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String formatting with %s

2007-12-02 Thread James Matthews
try to import printf using ctypes

On Dec 2, 2007 7:49 PM, MRAB <[EMAIL PROTECTED]> wrote:

> On Dec 2, 1:35 pm, Donn Ingle <[EMAIL PROTECTED]> wrote:
> > Hi,
> >  I'm sure I one read somewhere that there is a simple way to set the
> order
> > of replacements withing a string *without* using a dictionary.
> >
> > What I mean is:>>> s = "%s and %s" % ( "A", "B" )
> > >>> print s
> >
> > A and B
> >
> > Now, is there something quick like:>>> s = "%s/2 and %s/1" % ( "A", "B"
> )
> > >>> print s
> >
> > B and A
> >
> > ?
> >
> > I know it can be done with a dict:
> > d = { "one" : "A", "two" : "B"  }
> > s = "%(two)s and %(one)s" % d
> >
> > \d
>
> One quick solution is to write a function for it:
>
> def format(template, values):
>import re
># Collect the indexes from the template.
>order = map(int, re.findall(r'%\[(\d+)\]', template))
># Remove the indexes from the template.
>template = re.sub(r'(?<=%)\[(\d+)\]', '', template)
># Create a tuple containing the values in the correct positions.
>values = tuple(values[index] for index in order)
>return template % values
>
> >>> format("%[0]s and %[1]s", ("A", "B"))
> 'A and B'
> >>> format("%[1]s and %[0]s", ("A", "B"))
> 'B and A'
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://search.goldwatches.com/?Search=Movado+Watches
http://www.jewelerslounge.com
http://www.goldwatches.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Limit Guessing Algorithm

2007-12-02 Thread [EMAIL PROTECTED]
Hello hello,

I'm looking for a piece of code, preferably in Python, that will do
the following. It will accept a few data points (x,f(x)) of a function
that converges to some finite value when x converges to infinity. I
need the algorithm to guess what that limit is, to whatever precision
it can.

For example, if the input is:

[
[1,8],
[2,7.5],
[3,7.25],
[4,7.125]
]

Then the output will be 7. Or at least something close.

Does anyone know anything like that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie - question about lexical scoping

2007-12-02 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit :
(snip)


> class Foo(object):
>   bar = {'baz':'bing'}
>   def __init__(self):
> self.bar = self.bar

Hem... Should re-read before posting :(

It's of course:

def __init__(self):
   self.bar = self.bar.copy()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Guessing Algorithm

2007-12-02 Thread Roy Smith
In article 
<[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> Hello hello,
> 
> I'm looking for a piece of code, preferably in Python, that will do
> the following. It will accept a few data points (x,f(x)) of a function
> that converges to some finite value when x converges to infinity. I
> need the algorithm to guess what that limit is, to whatever precision
> it can.
> 
> For example, if the input is:
> 
> [
> [1,8],
> [2,7.5],
> [3,7.25],
> [4,7.125]
> ]
> 
> Then the output will be 7. Or at least something close.
> 
> Does anyone know anything like that?

I suggest any introductory calculus or math analysis text.  Perhaps even 
the one your professor assigned you for the course :-)

Look under "limits" in the table of contents.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String formatting with %s

2007-12-02 Thread Tim Chase
>  I'm sure I one read somewhere that there is a simple way to set the order
> of replacements withing a string *without* using a dictionary.
> 
> What I mean is:
 s = "%s and %s" % ( "A", "B" )
 print s
> A and B
> 
> Now, is there something quick like:
 s = "%s/2 and %s/1" % ( "A", "B" )
 print s
> B and A
> 
> ?
> 
> I know it can be done with a dict:
> d = { "one" : "A", "two" : "B"  }
> s = "%(two)s and %(one)s" % d

Well, if you're willing to cheat and use dictionary formatting
where your keys are the number you want (you've gotta have some
syntax for the index notation...why not reuse
dictionary-key/value syntax), you can do something like:

>>> number = lambda x: dict((str(i+1), v) for (i,v) in enumerate(x))
>>> "%(2)s and %(1)s" % number(["A", "B"])
'B and A'

If you don't mind zero-based indices, you can skip the "+1" bit.

-tkc


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


Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread Russ P.

> He might have been a great intellectual but he was no scientist. It's
> only by ignoring the vast bulk of his work -- work which Newton himself
> considered *far* more important and interesting than his work on physics
> and mathematics -- that we can even *pretend* he was a scientist.

The fact that someone studies theology does not mean that he cannot
also be considered a scientist. And if the person who discovered the
inverse-square law of universal gravitation is not a "scientist," I
don't know who is.

At the time, no one else had even made the connection between things
falling on earth and the motion of the stars and planets. Sure, it
seems obvious to you and me, but it was far from obvious then.

In any case, Newton is just one example of a great mathematician/
scientist whose name could be used for a programming language.

Euler was an amazing mathematician (and also a nice guy with a large
family). His name would be great too, except that it's apparently
already taken. I don't know how widely used the Euler language is, but
if it is just some obscure language, then the name could perhaps still
be used. The other problem with Euler is that its pronunciation is not
obvious from the spelling.

Here's another interesting possibility: Pythagoras. It starts off with
the same first four letters as Python. Everyone's heard of the theorem
named after him (although he apparently did not discover it himself).
The main drawback here is that the name is a bit long at ten
characters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Guessing Algorithm

2007-12-02 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > Look under "limits" in the table of contents.
> 
> I'm a third year math undergrad. You probably did not understand my
> question.

I think I understood the question.  It sounds like a numerical methods
homework problem.  Basically you have f(x0), f(x1), etc. and you want
to extrapolate to x=infinity.  Hint: think of a0=1/x0, a1=1/x1, etc.
so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
obvious what to do next.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Guessing Algorithm

2007-12-02 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > I think I understood the question.  It sounds like a numerical methods
> > homework problem.  Basically you have f(x0), f(x1), etc. and you want
> > to extrapolate to x=infinity.  Hint: think of a0=1/x0, a1=1/x1, etc.
> > so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
> > obvious what to do next.
> 
> Well Paul, it's not obvious to me, so if you could explain it I'll be
> grateful.

Basically define g(x) = f(1/x).  So you have this g(a0), g(a1), g(a2), ...
and you can fit a curve through them with your favorite extrapolation
formula (see a numerics book for lots of choices).  Then compute g(0).
-- 
http://mail.python.org/mailman/listinfo/python-list


ANNOUNCE: Spiff Guard 1.9.0

2007-12-02 Thread Samuel
Introduction

Spiff Guard is a library for implementing access lists in Python. It
provides a clean and simple API and was implemented with performance
and security in mind. It was originally inspired by phpGACL (http://
phpgacl.sourceforge.net/), but features an API that is significantly
cleaner and easier to use.

Spiff Guard is free software and distributed under the GNU GPLv2.


Changes since 1.4.0:
-
The bad:
 o This release breaks API, hard.

The good:
 o Spiff Guard is now type-aware. That means that you can create your
   own types and store them in the database; Spiff Guard will create
   an instance of the same type when you retrieve the object later.
 o Sections are now obsolete - instead, just use types as a section.
 o Spiff Guard makes now extensive use of caching.
 o The API is now a lot easier to use - if that is even possible.

Example Code:
--
guard   = Guard(db_connection)
group   = ResourceGroup("My Group")
user= Resource("My User")
website = ResourceGroup("My Website")
view= Action("View")
write   = Action("Edit")
guard.grant(group, view, website)
guard.grant(user,  edit, website)
if guard.has_permission(user, view, website):
print 'Permission granted.'


Dependencies
-
sqlalchemy (http://www.sqlalchemy.org/)


Download
-
Tarball:
http://pypi.python.org/packages/source/S/Spiff%20Guard/Spiff%20Guard-1.9.0.tar.gz#md5=a81ca3f310899ca8471d26ffbb58a83a

SVN:
svn checkout http://spiff.googlecode.com/svn/trunk/libs/Guard/


Links:
---
Documentation: http://spiff.googlecode.com/svn/trunk/libs/Guard/README
Example: http://spiff.googlecode.com/svn/trunk/libs/Guard/tests/DBTest.py
Spiff project page: http://code.google.com/p/spiff/
Mailing list: http://groups.google.com/group/spiff-devel
Bug tracker: http://code.google.com/p/spiff/issues/list
Browse the source: http://spiff.googlecode.com/svn/trunk/libs/Guard/

If you have any questions, please do not hesitate to ask or file a
bug.

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


Re: Limit Guessing Algorithm

2007-12-02 Thread [EMAIL PROTECTED]
On Dec 2, 10:53 pm, Roy Smith <[EMAIL PROTECTED]> wrote:
> In article
> <[EMAIL PROTECTED]>,
>
>
>
>  "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > Hello hello,
>
> > I'm looking for a piece of code, preferably in Python, that will do
> > the following. It will accept a few data points (x,f(x)) of a function
> > that converges to some finite value when x converges to infinity. I
> > need the algorithm to guess what that limit is, to whatever precision
> > it can.
>
> > For example, if the input is:
>
> > [
> > [1,8],
> > [2,7.5],
> > [3,7.25],
> > [4,7.125]
> > ]
>
> > Then the output will be 7. Or at least something close.
>
> > Does anyone know anything like that?
>
> I suggest any introductory calculus or math analysis text.  Perhaps even
> the one your professor assigned you for the course :-)
>
> Look under "limits" in the table of contents.

I'm a third year math undergrad. You probably did not understand my
question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Guessing Algorithm

2007-12-02 Thread [EMAIL PROTECTED]
On Dec 2, 11:50 pm, Paul Rubin  wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > > Look under "limits" in the table of contents.
>
> > I'm a third year math undergrad. You probably did not understand my
> > question.
>
> I think I understood the question.  It sounds like a numerical methods
> homework problem.  Basically you have f(x0), f(x1), etc. and you want
> to extrapolate to x=infinity.  Hint: think of a0=1/x0, a1=1/x1, etc.
> so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
> obvious what to do next.

Well Paul, it's not obvious to me, so if you could explain it I'll be
grateful.

Also, this is not a homework assignment. This is something I need for
some physical simulations I'm writing.

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


Re: Limit Guessing Algorithm

2007-12-02 Thread [EMAIL PROTECTED]
On Dec 3, 12:02 am, Paul Rubin  wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > > I think I understood the question.  It sounds like a numerical methods
> > > homework problem.  Basically you have f(x0), f(x1), etc. and you want
> > > to extrapolate to x=infinity.  Hint: think of a0=1/x0, a1=1/x1, etc.
> > > so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
> > > obvious what to do next.
>
> > Well Paul, it's not obvious to me, so if you could explain it I'll be
> > grateful.
>
> Basically define g(x) = f(1/x).  So you have this g(a0), g(a1), g(a2), ...
> and you can fit a curve through them with your favorite extrapolation
> formula (see a numerics book for lots of choices).  Then compute g(0).

Thank you Paul. This seems to make sense :)
I'll try to implement it.

Best Wishes,
Ram.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Guessing Algorithm

2007-12-02 Thread Roberto Bonvallet
On Dec 2, 5:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> It will accept a few data points (x,f(x)) of a function
> that converges to some finite value when x converges to infinity. I
> need the algorithm to guess what that limit is.

Since there are an infinity of ways to estimate the limit, I suggest
sticking to the simplest one:

def guess_limit(points):
x, y = max(points)
return y

> [
> [1,8],
> [2,7.5],
> [3,7.25],
> [4,7.125]
> ]
> Then the output will be 7. Or at least something close.

For this data set, my function will return 7.125.  Is it close enough?
Finding a better estimation is more a math problem than a Python one.

Best regards,
--
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] minimalist web server

2007-12-02 Thread ghirai

> On Dec 1, 2007 7:02 PM, Daniel Fetchinson <[EMAIL PROTECTED]> wrote:
>> > > I'm looking for the most minimalist web server ever that does nothing
>> > > else than return a fixed static page for every request. Regardless of
>> > > what the request is, it just needs to be an HTTP request to port 80,
>> > > the web server should return always the same html document. What would
>> > > be the best choice for this? The goal is of course to minimize system
>> > > resources in terms of memory, cpu, etc, etc.
>> >
>> > If you're running linux, maybe you want tux.
>> >
>> > publicfile isn't exactly what you describe, but its description might
>> > be of some interest:
>> >
>> > http://cr.yp.to/publicfile.html
>>
>>
>> Thanks, tux looks good, the only problem is that one needs to
>> recompile the kernel which I really don't want to do (so yes, I'm on
>> linux). Publicfile seems to "know" already too much.
>>
>> The reason I need this is that my current best strategy to avoid ads
>> in web pages is putting all ad server names into /etc/hosts and stick
>> my local ip number next to them (127.0.0.1) so every ad request goes
>> to my machine. I run apache which has an empty page for 404 errors so
>> I'll just see that blank page for every ad. Now I guess apache is a
>> pretty heavy weight guy so I'm looking for a lightweight alternative.
>> Lighttpd, nginx and company are all too complex and "know" too much. I
>> even considered just putting netcat into an infinite loop but I'm
>> afraid if there is a security hole in netcat I might be screwed.
>>
>> Maybe now that I outlined a little more why I need this others can
>> come up with more suggestions.
>>

Running this will start a server on port 80 which will serve files in  
the current folder:

import SimpleHTTPServer
import SocketServer
SocketServer.TCPServer(("",80),SimpleHTTPServer.SimpleHTTPRequestHandler).serve_forever()


Regards,
Ghirai.

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


Mod python set cookie for all subdomains

2007-12-02 Thread Abandoned
Hi..
I set cookie from www.domain.com but i'cant read this cookie from
subdomain.domain.com
How can i set cookie for all subdomains ?

My set cookie code is:
cookie = Cookie.Cookie('Login-Data', data)
cookie.expires = time.time() + 992
Cookie.add_cookie(req, cookie)
-- 
http://mail.python.org/mailman/listinfo/python-list


ImageTk.PhotoImage to PIL Image?

2007-12-02 Thread shadowsithe
I can't seem to find a way to convert an Image.Tk PhotoImage to a PIL
Image so that I can use the [tt]save[/tt] function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Guessing Algorithm

2007-12-02 Thread [EMAIL PROTECTED]
On Dec 3, 1:33 am, Roberto Bonvallet <[EMAIL PROTECTED]> wrote:
> On Dec 2, 5:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > It will accept a few data points (x,f(x)) of a function
> > that converges to some finite value when x converges to infinity. I
> > need the algorithm to guess what that limit is.
>
> Since there are an infinity of ways to estimate the limit, I suggest
> sticking to the simplest one:
>
> def guess_limit(points):
> x, y = max(points)
> return y
>
> > [
> > [1,8],
> > [2,7.5],
> > [3,7.25],
> > [4,7.125]
> > ]
> > Then the output will be 7. Or at least something close.
>
> For this data set, my function will return 7.125.  Is it close enough?
> Finding a better estimation is more a math problem than a Python one.
>
> Best regards,
> --
> Roberto Bonvallet

Roberto, your Zen-Python wisdom is irresistible :)
-- 
http://mail.python.org/mailman/listinfo/python-list


converting to and from octal escaped UTF--8

2007-12-02 Thread Michael Goerz
Hi,

I am writing unicode stings into a special text file that requires to
have non-ascii characters as as octal-escaped UTF-8 codes.

For example, the letter "Í" (latin capital I with acute, code point 205)
would come out as "\303\215".

I will also have to read back from the file later on and convert the
escaped characters back into a unicode string.

Does anyone have any suggestions on how to go from "Í" to "\303\215" and
vice versa?

I know I can get the code point by doing
>>> "Í".decode('utf-8').encode('unicode_escape')
but there doesn't seem to be any similar method for getting the octal
escaped version.

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

Re: Mod python set cookie for all subdomains

2007-12-02 Thread Graham Dumpleton
On Dec 3, 11:44 am, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> I set cookie fromwww.domain.combut i'cant read this cookie from
> subdomain.domain.com
> How can i set cookie for all subdomains ?
>
> My set cookie code is:
> cookie = Cookie.Cookie('Login-Data', data)
> cookie.expires = time.time() + 992
> Cookie.add_cookie(req, cookie)

Having created the cookie do:

  cookie.domain = 'domain.com'

Graham

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


Re: "Python" is not a good name, should rename to "Athon"

2007-12-02 Thread greg
Russ P. wrote:

> I am surprised to see that Newton is not taken.

Not for a language, but there is a physics simulation
library called Newton -- which is a more appropriate
use of the name, I think. To me, he's more associated
with physics than mathematics.

If you want a really appropriate name for a programming
language, I'd suggest Babbage. (not for Python, though!)

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


Re: converting to and from octal escaped UTF--8

2007-12-02 Thread Michael Goerz
Michael Goerz wrote:
> Hi,
> 
> I am writing unicode stings into a special text file that requires to
> have non-ascii characters as as octal-escaped UTF-8 codes.
> 
> For example, the letter "Í" (latin capital I with acute, code point 205)
> would come out as "\303\215".
> 
> I will also have to read back from the file later on and convert the
> escaped characters back into a unicode string.
> 
> Does anyone have any suggestions on how to go from "Í" to "\303\215" and
> vice versa?
> 
> I know I can get the code point by doing
 "Í".decode('utf-8').encode('unicode_escape')
> but there doesn't seem to be any similar method for getting the octal
> escaped version.
> 
> Thanks,
> Michael

I've come up with the following solution. It's not very pretty, but it
works (no bugs, I hope). Can anyone think of a better way to do it?

Michael
_

import binascii

def escape(s):
hexstring = binascii.b2a_hex(s)
result = ""
while len(hexstring) > 0:
(hexbyte, hexstring) = (hexstring[:2], hexstring[2:])
octbyte = oct(int(hexbyte, 16)).zfill(3)
result += "\\" + octbyte[-3:]
return result

def unescape(s):
result = ""
while len(s) > 0:
if s[0] == "\\":
(octbyte, s) = (s[1:4], s[4:])
try:
result += chr(int(octbyte, 8))
except ValueError:
result += "\\"
s = octbyte + s
else:
result += s[0]
s = s[1:]
return result

print escape("\303\215")
print unescape('adf\\303\\215adf')
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: converting to and from octal escaped UTF--8

2007-12-02 Thread MonkeeSage
On Dec 2, 8:38 pm, Michael Goerz <[EMAIL PROTECTED]> wrote:
> Michael Goerz wrote:
> > Hi,
>
> > I am writing unicode stings into a special text file that requires to
> > have non-ascii characters as as octal-escaped UTF-8 codes.
>
> > For example, the letter "Í" (latin capital I with acute, code point 205)
> > would come out as "\303\215".
>
> > I will also have to read back from the file later on and convert the
> > escaped characters back into a unicode string.
>
> > Does anyone have any suggestions on how to go from "Í" to "\303\215" and
> > vice versa?
>
> > I know I can get the code point by doing
>  "Í".decode('utf-8').encode('unicode_escape')
> > but there doesn't seem to be any similar method for getting the octal
> > escaped version.
>
> > Thanks,
> > Michael
>
> I've come up with the following solution. It's not very pretty, but it
> works (no bugs, I hope). Can anyone think of a better way to do it?
>
> Michael
> _
>
> import binascii
>
> def escape(s):
> hexstring = binascii.b2a_hex(s)
> result = ""
> while len(hexstring) > 0:
> (hexbyte, hexstring) = (hexstring[:2], hexstring[2:])
> octbyte = oct(int(hexbyte, 16)).zfill(3)
> result += "\\" + octbyte[-3:]
> return result
>
> def unescape(s):
> result = ""
> while len(s) > 0:
> if s[0] == "\\":
> (octbyte, s) = (s[1:4], s[4:])
> try:
> result += chr(int(octbyte, 8))
> except ValueError:
> result += "\\"
> s = octbyte + s
> else:
> result += s[0]
> s = s[1:]
> return result
>
> print escape("\303\215")
> print unescape('adf\\303\\215adf')

Looks like escape() can be a bit simpler...

def escape(s):
  result = []
  for char in s:
result.append("\%o" % ord(char))
  return ''.join(result)

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


Any idea how to open Matlab and run M-files by using Python?

2007-12-02 Thread itcecsa
Hi,

I am implementing a small Python project, what I am going to do is to
open Matlab and run some M-files, and get some output from Matlab
command prompt.

I have no idea how to open Matlab from Python!

Any suggestions would be appriciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] minimalist web server

2007-12-02 Thread Daniel Fetchinson
> > The reason I need this is that my current best strategy to avoid ads in
> > web pages is putting all ad server names into /etc/hosts and stick my
> > local ip number next to them (127.0.0.1) so every ad request goes to my
> > machine. I run apache which has an empty page for 404 errors so I'll
>
> In this case, do you need a webserver at all? If your browser tries to
> access a web server on 127.0.0.1 and there isn't one, won't the result,
> in most cases, be more or less the same as if the server returned a 404?

Not quite, because if the browser doesn't get a response from the
server it will keep trying for a while and will only give up after
that. And then will display a "server not found, blablablabla" message
depending on the browser, which will appear in place of every ad.
That's ugly and it's better to have an empty page.

Concerning the python solutions posted by several guys, they are too
heavyweight compared to a ~ 1-3 hundred lines of C code that one can
obtain from cheetah's source code.
-- 
http://mail.python.org/mailman/listinfo/python-list


audiodev problem

2007-12-02 Thread Shane Geiger
"""
I just used the following Google search to look for some random .aiff
files which I could use to test the code I once found for the audiodev
module.  Unfortunately, the writeframes() call gives me the traceback
below.  Does anyone know what the problem is?  (I would, quite frankly
rather know how to play mp3 or ogg files, but I was wondering whether
there's a problem here that needs to be fixed.)


http://www.google.com/search?q=intitle%3A%22index.of%22+%22parent+directory%22+%22size%22+%22last+modified%22+%22description%22+%5Bsnd%5D+%28aiff%29+-inurl%3A%28jsp%7Cphp%7Chtml%7Caspx%7Chtm%7Ccf%7Cshtml%7Clyrics-realm%7Cmp3-collection%29+-site%3A.info++&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a


player.writeframes(data)  #  this line is causing this problem with
every .aiff file I try:


Traceback (most recent call last):
  File "/tmp/foo.py", line 39, in 
player.writeframes(data)  #  this line is causing this problem with
every .aiff file I try:
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/Audio_mac.py",
line 67, in writeframes
nframes)
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/struct.py",
line 63, in pack
return o.pack(*args)
struct.error: byte format requires -128 <= number <= 127


-

THE AUDIODEV MODULE

[contents]

(Unix only) This module provides sound playing support for Sun and SGI
computers.
Example: Using the audiodev module

# File: audiodev-example-1.py
"""
import audiodev
import aifc

# THIS IS THE ERROR I GET:  struct.error: byte format requires -128 <=
number <= 127

#sound = aifc.open("/Users/shanegeiger/bring.aiff", "r")
#sound = aifc.open("/Users/shanegeiger/gates01.aif", "r")
sound = aifc.open("/Users/shanegeiger/c2.aiff", "r")

player = audiodev.AudioDev()
player.setoutrate(sound.getframerate())
player.setsampwidth(sound.getsampwidth())
player.setnchannels(sound.getnchannels())

bytes_per_frame = sound.getsampwidth() * sound.getnchannels()
bytes_per_second = sound.getframerate() * bytes_per_frame

#print "bytes_per_frame:",bytes_per_frame
#print "bytes_per_second:",bytes_per_second

i = 0
while 1:
print str(i) + " COMPLETED"  # debug
data = sound.readframes(bytes_per_second)
if not data:
break
#print data  # debug
player.writeframes(data)  #  this line is causing this problem with
every .aiff file I try:

i += 1

#import sys; sys.exit()
player.wait()



-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

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


Re: converting to and from octal escaped UTF--8

2007-12-02 Thread Michael Goerz
MonkeeSage wrote:
 > Looks like escape() can be a bit simpler...
> 
> def escape(s):
>   result = []
>   for char in s:
> result.append("\%o" % ord(char))
>   return ''.join(result)
> 
> Regards,
> Jordan
Very neat! Thanks a lot...
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


i need true friends like u

2007-12-02 Thread Barathi

It takes a minute to have a crush on someone,
a hour to like someone, and a day to fall in
love with someone, but it takes a lifetime to
 forget someone (Friend).


http://jayabarathi.50webs.com/


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


Re: converting to and from octal escaped UTF--8

2007-12-02 Thread Michael Spencer
Michael Goerz wrote:
> Hi,
> 
> I am writing unicode stings into a special text file that requires to
> have non-ascii characters as as octal-escaped UTF-8 codes.
> 
> For example, the letter "Í" (latin capital I with acute, code point 205)
> would come out as "\303\215".
> 
> I will also have to read back from the file later on and convert the
> escaped characters back into a unicode string.
> 
> Does anyone have any suggestions on how to go from "Í" to "\303\215" and
> vice versa?
> 
Perhaps something along the lines of:

  >>> def encode(source):
  ... return "".join("\%o" % ord(c) for c in source.encode('utf8'))
  ...
  >>> def decode(encoded):
  ... bytes = "".join(chr(int(c, 8)) for c in encoded.split('\\')[1:])
  ... return bytes.decode('utf8')
  ...
  >>> encode(u"Í")
  '\\303\\215'
  >>> print decode(_)
  Í
  >>>

HTH
Michael

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

Re: String formatting with %s

2007-12-02 Thread Donn
> dictionary-key/value syntax), you can do something like:
> >>> number = lambda x: dict((str(i+1), v) for (i,v) in enumerate(x))
> >>> "%(2)s and %(1)s" % number(["A", "B"])
Whoa - that'll take me a little while to figure out, but it looks intriguing! 
Tah.

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


Re: converting to and from octal escaped UTF--8

2007-12-02 Thread MonkeeSage
On Dec 2, 11:46 pm, Michael Spencer <[EMAIL PROTECTED]> wrote:
> Michael Goerz wrote:
> > Hi,
>
> > I am writing unicode stings into a special text file that requires to
> > have non-ascii characters as as octal-escaped UTF-8 codes.
>
> > For example, the letter "Í" (latin capital I with acute, code point 205)
> > would come out as "\303\215".
>
> > I will also have to read back from the file later on and convert the
> > escaped characters back into a unicode string.
>
> > Does anyone have any suggestions on how to go from "Í" to "\303\215" and
> > vice versa?
>
> Perhaps something along the lines of:
>
>   >>> def encode(source):
>   ... return "".join("\%o" % ord(c) for c in source.encode('utf8'))
>   ...
>   >>> def decode(encoded):
>   ... bytes = "".join(chr(int(c, 8)) for c in encoded.split('\\')[1:])
>   ... return bytes.decode('utf8')
>   ...
>   >>> encode(u"Í")
>   '\\303\\215'
>   >>> print decode(_)
>   Í
>   >>>
>
> HTH
> Michael

Nice one. :) If I might suggest a slight variation to handle cases
where the "encoded" string contains plain text as well as octal
escapes...

def decode(encoded):
  for octc in (c for c in re.findall(r'\\(\d{3})', encoded)):
encoded = encoded.replace(r'\%s' % octc, chr(int(octc, 8)))
  return encoded.decode('utf8')

This way it can handle both "\\141\\144\\146\\303\\215\\141\\144\\146"
as well as "adf\\303\\215adf".

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


Re: converting to and from octal escaped UTF--8

2007-12-02 Thread MonkeeSage
On Dec 3, 1:31 am, MonkeeSage <[EMAIL PROTECTED]> wrote:
> On Dec 2, 11:46 pm, Michael Spencer <[EMAIL PROTECTED]> wrote:
>
>
>
> > Michael Goerz wrote:
> > > Hi,
>
> > > I am writing unicode stings into a special text file that requires to
> > > have non-ascii characters as as octal-escaped UTF-8 codes.
>
> > > For example, the letter "Í" (latin capital I with acute, code point 205)
> > > would come out as "\303\215".
>
> > > I will also have to read back from the file later on and convert the
> > > escaped characters back into a unicode string.
>
> > > Does anyone have any suggestions on how to go from "Í" to "\303\215" and
> > > vice versa?
>
> > Perhaps something along the lines of:
>
> >   >>> def encode(source):
> >   ... return "".join("\%o" % ord(c) for c in source.encode('utf8'))
> >   ...
> >   >>> def decode(encoded):
> >   ... bytes = "".join(chr(int(c, 8)) for c in encoded.split('\\')[1:])
> >   ... return bytes.decode('utf8')
> >   ...
> >   >>> encode(u"Í")
> >   '\\303\\215'
> >   >>> print decode(_)
> >   Í
>
> > HTH
> > Michael
>
> Nice one. :) If I might suggest a slight variation to handle cases
> where the "encoded" string contains plain text as well as octal
> escapes...
>
> def decode(encoded):
>   for octc in (c for c in re.findall(r'\\(\d{3})', encoded)):
> encoded = encoded.replace(r'\%s' % octc, chr(int(octc, 8)))
>   return encoded.decode('utf8')
>
> This way it can handle both "\\141\\144\\146\\303\\215\\141\\144\\146"
> as well as "adf\\303\\215adf".
>
> Regards,
> Jordan

err...

def decode(encoded):
  for octc in re.findall(r'\\(\d{3})', encoded):
encoded = encoded.replace(r'\%s' % octc, chr(int(octc, 8)))
  return encoded.decode('utf8')
-- 
http://mail.python.org/mailman/listinfo/python-list