Re: Question to python C API

2009-04-17 Thread alex23
On Apr 17, 4:22 pm, Andreas Otto  wrote:
>         Question 1: Why you wall it "Pyrex" package ?

>From the first paragraph on the Cython site: "Cython is based on the
well-known Pyrex, but supports more cutting edge functionality and
optimizations."

> >python ./setup.py install
>
> Traceback (most recent call last):
>   File "./setup.py", line 5, in 
>     from Cython.Compiler.Version import version
>   File "/home/dev1usr/src/Cython-0.11.1/Cython/__init__.py", line 2, in
> 
>     from Shadow import *
> ImportError: No module named Shadow

Did you unpack the Cython archive correctly? Is there a Shadow.py in
your src/Cython-0.11.1/Cython/ folder?

>   4. than I try the second part from INSTALL.txt
> (2) If you prefer not to modify your Python
>     installation, arrange for the directory
>     containing this file (INSTALL.txt) to be in
>     your PYTHONPATH. On unix, also put the bin
>     directory on your PATH.
>
> Traceback (most recent call last):
>   File "setup.py", line 3, in 
>     from Cython.Distutils import build_ext
> ImportError: No module named Cython.Distutils

Did you follow the 2nd set of instructions & modify both your
PYTHONPATH & PATH env vars? Have you confirmed they're correct? This
is the sort of error I'd expect if those weren't set up properly.

>   7. a little bit to much errors for the first step, isn't it ?

Yes, however none of these happened when I just installed Cython to
the XP, OSX & Ubuntu boxen I'm working on, so this isn't usual
behaviour.

What is your setup? What OS?
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyGUI 2.0.1

2009-04-17 Thread Thomas Heller
greg schrieb:
> Suraj Barkale wrote:
> 
>> I installed this and tried out the tests on Python 2.6.1 and Windows XP
>> SP3. Following are my observations.
> 
> Thanks, I'll look into these.
> 
>> Test 33-mouse-events.py:
>> 1. mouse-enter and mouse-leave events are not reported.
> 
> That's actually expected on Windows -- I couldn't find
> any way of implementing these.

Maybe this can help:

http://blogs.msdn.com/oldnewthing/archive/2003/10/13/55279.aspx

>> Test 37-image-cursor.py:
>> 1. Mouse pointer hotspot is in the middle of the image.
> 
> That's okay too, it's meant to be there.
> 


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


script question

2009-04-17 Thread Stefano

I have a script like this

myscript.py

   def func01()
   def func02()
   def func03()
   
   def funcnn()

How can i execute my func in the code ?

import myscript
for i in range(1,n):
   myscript.func??

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


Re: script question

2009-04-17 Thread Chris Rebert
On Fri, Apr 17, 2009 at 12:00 AM, Stefano  wrote:
> I have a script like this
>
> myscript.py
>
>   def func01()
>   def func02()
>   def func03()
>   
>   def funcnn()
>
> How can i execute my func in the code ?
>
> import myscript
> for i in range(1,n):
>   myscript.func??
getattr(myscript, "func"+str(n))() #disregarding zero-padding

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


Re: Create standalone Windows program with simple graphics?

2009-04-17 Thread Paul Rudin
Poster28  writes:


> I'd like to program and compile a simple graphics program (showing something
> like a chess board, some numbers and buttons, mouse support) ...

2d or 3d graphics? You could start by looking at pygame and pyopengl.

> ... and provide it as a standalone binary for Windows users.

py2exe, althought this is a bit of a PITA. I'd get your game working
first and worry about this aspect of the project last.



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


Re: script question

2009-04-17 Thread Peter Otten
Stefano wrote:

> I have a script like this
> 
> myscript.py
> 
> def func01()
> def func02()
> def func03()
> 
> def funcnn()
> 
> How can i execute my func in the code ?
> 
> import myscript
> for i in range(1,n):
  getattr(myscript, "func%02d" % i)()

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


Re: script question

2009-04-17 Thread alex23
On Apr 17, 5:00 pm, "Stefano"  wrote:
> How can i execute my func in the code ?
>
> import myscript
> for i in range(1,n):
>     myscript.func??


for i in range(1,n):
getattr(myscript, 'func%d' % i)()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-17 Thread Ken Seehart

[email protected] wrote:

Hi,

I am C++ guy for the most part and don't know much of Python, so,
please, bear with me if I am asking errrm..idiotic question.

Old rexec module provided kinda 'secure' execution environment. I am
not looking for security at this point. What I need an execution
environment which almost like rexec, but is non-secure.
  What I want is:
  separate global dictionary,
  separate list of imported modules,
  separate sys.path
  (optionaly) separate __builtins__

I might be able to get away without my own builtins, but the rest I
need.

If  it's any help, I plan to use it to execute embedded Python scripts
from C++.

Thanks,

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

  


As far as I know, you can't make multiple instances of the python 
environment from within python, but there is an easier way to get what 
you want, given that this is an embedding situation.


See: http://wingware.com/psupport/python-manual/1.5/api/initialization.html

You can use Py_NewInterpreter() to create multiple instances of python, 
which should give you the desired effect (though I have not tried this).


- Ken

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


Re: How to access C structures

2009-04-17 Thread Stefan Behnel
Chris Helck wrote:
> I have a couple dozen C structures that define binary file records. I
> need to read the file and access the records. I need to do this very
> efficiantly.
>
> I am aware of the Python struct class, but the C structures contain
> arrays of nested structures and I'm not sure if Python struct can handle
> it. I am willing to give up portability for speed.

No need to trade, you can have both. You can implement it in Cython, a
Python-like language that supports direct interaction with C code and C
data types. It will compile to a fast C extension that you can import and
use from Python.

http://cython.org

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


JSON Template: Minimal but powerful templating language implemented in Python and 3 other languages

2009-04-17 Thread Andy Chu
I'm looking for some feedback based on real usage.  There have been a
few small features added here and there since it was made public 3
weeks ago, but more comments are appreciated.

A big selling point is that it's implemented in JavaScript too, so you
can use the same templates on the client and the server.  There's a
Java version too and a PHP version (in progress).

Right now it's just a single Python module which you can download and
try out, but I'll make an official release soon.

http://code.google.com/p/json-template/

There's a good deal of documentation on the site, but this article
explains it well:

http://json-template.googlecode.com/svn/trunk/doc/Introducing-JSON-Template.html

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


Re: Question to python C API

2009-04-17 Thread Andreas Otto
alex23 wrote:

> On Apr 17, 4:22 pm, Andreas Otto  wrote:
>> Question 1: Why you wall it "Pyrex" package ?
> 
> From the first paragraph on the Cython site: "Cython is based on the
> well-known Pyrex, but supports more cutting edge functionality and
> optimizations."
> 
>> >python ./setup.py install
>>
>> Traceback (most recent call last):
>> File "./setup.py", line 5, in 
>> from Cython.Compiler.Version import version
>> File "/home/dev1usr/src/Cython-0.11.1/Cython/__init__.py", line 2, in
>> 
>> from Shadow import *
>> ImportError: No module named Shadow
> 
> Did you unpack the Cython archive correctly? Is there a Shadow.py in
> your src/Cython-0.11.1/Cython/ folder?

yes

> 
>> 4. than I try the second part from INSTALL.txt
>> (2) If you prefer not to modify your Python
>> installation, arrange for the directory
>> containing this file (INSTALL.txt) to be in
>> your PYTHONPATH. On unix, also put the bin
>> directory on your PATH.
>>
>> Traceback (most recent call last):
>> File "setup.py", line 3, in 
>> from Cython.Distutils import build_ext
>> ImportError: No module named Cython.Distutils
> 
> Did you follow the 2nd set of instructions & modify both your
> PYTHONPATH & PATH env vars? Have you confirmed they're correct? This
> is the sort of error I'd expect if those weren't set up properly.

I put the the "Cython-0.11.1" into the PATH and don't modify the
PYTHONPATH

the INSTALL.txt say: On unix, *also* put the bin directory on your PATH

but I think I found the reason I have to set the PYTHONPATH to this
directory *and* setup the PATH. I understand *also* as something like "or"

but now the following error happen:


> PYTHONPATH=~/ext/x86_64-suse-linux/thread/bin/Cython-0.11.1/
PATH=$PATH:~/ext/x86_64-suse-linux/thread/bin/Cython-0.11.1/
python ./setup.py build_ext --inplace
Traceback (most recent call last):
  File "./setup.py", line 3, in 
from Cython.Distutils import build_ext
 
File 
"/home/dev1usr/ext/x86_64-suse-linux/thread/bin/Cython-0.11.1/Cython/__init__.py",
line 2, in 
from Shadow import *
ImportError: No module named Shadow


> 
>> 7. a little bit to much errors for the first step, isn't it ?
> 
> Yes, however none of these happened when I just installed Cython to
> the XP, OSX & Ubuntu boxen I'm working on, so this isn't usual
> behaviour.
> 
> What is your setup? What OS?

SuSE 10.3, I have compiled python on my own and install it in:
~/ext/x86_64-suse-linux/thread


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


Re: Question to python C API

2009-04-17 Thread Andreas Otto
Andreas Otto wrote:

> alex23 wrote:
>> Did you unpack the Cython archive correctly? Is there a Shadow.py in
>> your src/Cython-0.11.1/Cython/ folder?
> 
> yes

dev1...@linux02:~/ext/x86_64-suse-linux/thread/bin/Cython-0.11.1> ls -al
Cython/Shadow.py
-rw-r--r-- 1 dev1usr users 4130  3. Apr 10:52 Cython/Shadow.py


mfg

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


Re: JSON Template: Minimal but powerful templating language implemented in Python and 3 other languages

2009-04-17 Thread Paul Rubin
Andy Chu  writes:
> I'm looking for some feedback based on real usage.  There have been a
> few small features added here and there since it was made public 3
> weeks ago, but more comments are appreciated.

It looks cute, but very limited, and lacking in documentation unless I
wasn't looking in the right places.  I like the declarative approach
but I think to really make it interesting, you have to supply more of
the machinery found in functional programming languages.  As one
simple example, I don't see how to extend your sample template (the
song list) to number the items on the list, e.g.

  1. Sounds Like Thunder
  2. Their Hooves Carve Craters in the Earth

where the numbers 1 and 2 are generated by the template.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Man Bites Python

2009-04-17 Thread Vito De Tullio
Mikael Olofsson wrote:

> I don't think the guy in question finds it that funny.

I don't think the python in question finds it that funny.

-- 
By ZeD

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


Re: Accessing a parse tree

2009-04-17 Thread Clarendon
Thank you very much for this information. It seems to point me to the
right direction. However, I do not fully understand the flatten
function and its output. Some indices seem to be inaccurate. I tried
to find this function at nltk.tree.Tree.flatten, but it returns a
flattened tree, not a tuple.

So your flatten function must be a different one, and it's not one of
the builtins, either. Could you tell me where I can find the
documentation about this flatten function?
--
http://mail.python.org/mailman/listinfo/python-list


Re: get text from rogramms runn by subprocess.Popen immediatetly

2009-04-17 Thread Piet van Oostrum
> Rüdiger Ranft <[email protected]> (RR) wrote:

>RR> Hi all,
>RR> I need to call some programms and catch their stdout and stderr streams.
>RR> While the Popen class from subprocess handles the call, I get the
>RR> results of the programm not until the programm finishes. Since the
>RR> output of the programm is used to generate a progress indicator, I need
>RR> a way to acces the values written to stdout/stderr as fast as possible.

>RR> print p.stderr.read()

Use p.stderr.readline() or p.stderr.read(1) in a loop.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] large db question about no joins

2009-04-17 Thread Martin P. Hellwig

Daniel Fetchinson wrote:


Well, I gave the concrete example of zoo/cage/animal/leg because this
*is* the business logic. I need to know for example the total number
of animals, this is pretty understandable if you have a zoo. Or you
mean that I should give another example?


It might be the business logic but not the process. 
http://en.wikipedia.org/wiki/Business_process



Using the business process I could probably
narrow down the scope quite a bit like, 



No, I'd like to have the exact number at any given time.

Fair enough, but this is then the *exact* scope you like to answer me in.





Let's say I need to implement this on the google app engine, so I
can't make too many choices on my own. On the GAE, how would I do
this?
All other data modeling (e.g. EAV, relational, object orientated) will 
result in a structure requiring extra calculation when doing the query 
(and thus according your requirement isn't acceptable).


So I need to store the data in such a way that it is accessible before 
the query with the minimal amount of processing.


Thus the only thing left is writing a subroutine in my code which 
recalculates the amount of legs when there is a change in it and store 
it just as a pair value:

amount_of_legs = Positive Integer

The thing with bogus requirements for an imaginary example is that the 
solution is imaginary bogus too, leaving little room for applicability 
in the real world.


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


Re: Choose: class with static methods or module with functions

2009-04-17 Thread Dan Sommers
On Thu, 16 Apr 2009 09:55:40 -0700, bearophileHUGS wrote:

> But there can be a situation where you want to keep functions even
> closer, for example because in a module you have two classes and two
> groups of functions related to each class. In such situation
> staticmethods seem better.

In order not to guess in the face of ambiguity, I propose that you handle 
that case ("two classes and two groups of functions related to each 
class") by splitting that module into two modules.  One module would 
contain one of the classes and its related functions; the other module 
would contain the other class and its related functions.

Unless, of course, you mean that you have two groups of functions, each 
of which are related to *both* classes, in which case I'd still prefer 
module-level functions to staticmethods, but I'm old enough that I only 
speak Object Oriented as a Second Language.

Dan

-- 
Dan Sommers   A death spiral goes clock-
   wise north of the equator.
Atoms are not things. -- Werner Heisenberg  -- Dilbert's PHB

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


Re: [Python-Dev] RELEASED Python 2.6.2

2009-04-17 Thread Piet van Oostrum
> Barry Warsaw  (BW) wrote:

>BW> On behalf of the Python community, I'm happy to announce the  availability
>BW> of Python 2.6.2.  This is the latest production-ready  version in the
>BW> Python 2.6 series.  Dozens of issues have been fixed  since Python 2.6.1
>BW> was released back in December.  Please see the NEWS  file for all the gory
>BW> details.

>BW> http://www.python.org/download/releases/2.6.2/NEWS.txt

>BW> For more information on Python 2.6 in general, please see

>BW>  http://docs.python.org/dev/whatsnew/2.6.html

>BW> Source tarballs, Windows installers, and (soon) Mac OS X disk images  can
>BW> be downloaded from the Python 2.6.2 page:

>BW> http://www.python.org/download/releases/2.6.2/

Maybe a link to the MacOSX image can also be added to
http://www.python.org/download 
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: script question

2009-04-17 Thread Piet van Oostrum
> "Stefano"  (S) wrote:

>S> I have a script like this
>S> myscript.py

>S>def func01()
>S>def func02()
>S>def func03()
>S>
>S>def funcnn()

>S> How can i execute my func in the code ?

>S> import myscript
>S> for i in range(1,n):
>S>myscript.func??

Others have suggested getattr. I think a cleaner (more pythonic) way
would be: 

funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()

Or myscript.funclist[i]() from another module.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: script question

2009-04-17 Thread Marco Mariani

Piet van Oostrum wrote:


funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()

Or myscript.funclist[i]() from another module.


Ehm, calling a bazillion things in the right order should be a 
responsibility of the myscript module anyway.


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


QT , Wxwidgets are not just UI framework ?

2009-04-17 Thread Deep_Feelings
qt include many libraries : network , threading,database ..etc while
Wxwidgets seem similar but with less scope

my question is : does these frameworks replace python's (or any other
language for that matter) built-in libraries ? or python does not
include that sort of libraries ?

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


Re: binary file compare...

2009-04-17 Thread Nigel Rantor

Adam Olsen wrote:

On Apr 16, 11:15 am, SpreadTooThin  wrote:

And yes he is right CRCs hashing all have a probability of saying that
the files are identical when in fact they are not.


Here's the bottom line.  It is either:

A) Several hundred years of mathematics and cryptography are wrong.
The birthday problem as described is incorrect, so a collision is far
more likely than 42 trillion trillion to 1.  You are simply the first
person to have noticed it.

B) Your software was buggy, or possibly the input was maliciously
produced.  Or, a really tiny chance that your particular files
contained a pattern that provoked bad behaviour from MD5.

Finding a specific limitation of the algorithm is one thing.  Claiming
that the math is fundamentally wrong is quite another.


You are confusing yourself about probabilities young man.

Just becasue something is extremely unlikely does not mean it can't 
happen on the first attempt.


This is true *no matter how big the numbers are*.

If you persist in making these ridiculous claims that people *cannot* 
have found collisions then as I said, that's up to you, but I'm not 
going to employ you to do anything except make tea.


Thanks,

  Nigel

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


Re: QT , Wxwidgets are not just UI framework ?

2009-04-17 Thread Diez B. Roggisch
Deep_Feelings wrote:

> qt include many libraries : network , threading,database ..etc while
> Wxwidgets seem similar but with less scope
> 
> my question is : does these frameworks replace python's (or any other
> language for that matter) built-in libraries ? or python does not
> include that sort of libraries ?

Some it includes, others it doesn't. And they come with different features.

While python comes with a lot of included batteries, for some things you
need a more powerful generator - that's where 3rd-party-libraries come into
play.

There are plenty of discussions about which GUI-toolkit is the best - google
this group.

However, mostly people agree that Qt is the most powerful, but often was
debunked because of it's licensing. This has changed to the much more
liberal LGPL for Qt4.5.

Now it might be though that you'd still need to buy a license from Phil
Thompson for his excellent PyQt-wrapping - but I'd personally say it's more
worth than it actually costs given the power of Qt.

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


Re: Non-secure execution environment

2009-04-17 Thread Aaron Brady
On Apr 17, 1:47 am, [email protected] wrote:
> Hi,
>
> I am C++ guy for the most part and don't know much of Python, so,
> please, bear with me if I am asking errrm..idiotic question.
>
> Old rexec module provided kinda 'secure' execution environment. I am
> not looking for security at this point. What I need an execution
> environment which almost like rexec, but is non-secure.
>   What I want is:
>   separate global dictionary,
>   separate list of imported modules,
>   separate sys.path
>   (optionaly) separate __builtins__
>
> I might be able to get away without my own builtins, but the rest I
> need.
>
> If  it's any help, I plan to use it to execute embedded Python scripts
> from C++.
>
> Thanks,
>
> Gennadiy

It depends what you mean by secure environment.  One option is to
create a subprocess, to just limit access your variables.  Another is
to compile and examine their code yourself, and prohibit things like
access to the file class, the os module, etc.

I once had some success with removing the Lib folder, leaving only
certain exceptions, but you need a custom 2nd install for that.

In general, there's no good way.  Python was designed to free your
mind, not tie your hands.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Man Bites Python

2009-04-17 Thread Aaron Brady
On Apr 17, 3:33 am, Vito De Tullio  wrote:
> Mikael Olofsson wrote:
> > I don't think the guy in question finds it that funny.
>
> I don't think the python in question finds it that funny.
>
> --
> By ZeD

Man bites python.
Python bites dog.
Dog bites man.

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


how to know the importing file name from an imported file?

2009-04-17 Thread Visco Shaun
Hi

Is there a way to know the name of the script(say A), which is importing
a module(say B), from B?
ie in above situation i should be able to get name 'A' through some way
in B, when A contains an 'import B' statement.
-- 
Thanks & Regards
visco

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


Re: binary file compare...

2009-04-17 Thread Nigel Rantor

Adam Olsen wrote:

On Apr 16, 4:27 pm, "Rhodri James" 
wrote:

On Thu, 16 Apr 2009 10:44:06 +0100, Adam Olsen  wrote:

On Apr 16, 3:16 am, Nigel Rantor  wrote:

Okay, before I tell you about the empirical, real-world evidence I have
could you please accept that hashes collide and that no matter how many
samples you use the probability of finding two files that do collide is
small but not zero.

I'm afraid you will need to back up your claims with real files.

So that would be a "no" then.  If the implementation of dicts in Python,
say, were to assert as you are that the hashes aren't going to collide,
then I'd have to walk away from it.  There's no point in using something
that guarantees a non-zero chance of corrupting your data.


Python's hash is only 32 bits on a 32-bit box, so even 2**16 keys (or
65 thousand) will give you a decent chance of a collision.  In
contrast MD5 needs 2**64, and a *good* hash needs 2**128 (SHA-256) or
2**256 (SHA-512).  The two are at totally different extremes.


I'm just going to go ahead and take the above as an admission by you 
that the chance of collision is non-zero, and that if we accept that 
fact you cannot rely on a hash function to tell you if two files are 
identical.


Thanks.


There is *always* a non-zero chance of corruption, due to software
bugs, hardware defects, or even operator error.  It is only in that
broader context that you can realize just how minuscule the risk is.


Please explain why you're dragging the notion of corruption into this 
when it seems to be beside the point?



Can you explain to me why you justify great lengths of paranoia, when
the risk is so much lower?


Because in the real world, where I work, in practical, real, factual 
terms I have seen it happen. Not once. Not twice. But many, many times.



Why are you advocating a solution to the OP's problem that is more
computationally expensive than a simple byte-by-byte comparison and
doesn't guarantee to give the correct answer?


For single, one-off comparison I have no problem with a byte-by-byte
comparison.  There's a decent chance the files won't be in the OS's
cache anyway, so disk IO will be your bottleneck.

>

Only if you're doing multiple comparisons is a hash database
justified.  Even then, if you expect matching files to be fairly rare
I won't lose any sleep if you're paranoid and do a byte-by-byte
comparison anyway.  New vulnerabilities are found, and if you don't
update promptly there is a small (but significant) chance of a
malicious file leading to collision.


If I have a number of files then I would certainly use a hash as a quick 
test, but if two files hash to the same value I still have to go compare 
them. Hashing in this case saves time doing a comparison for each file 
but it doesn't obviate the need to do a byte-by-byte comparison to see 
if the files that hash to the same value are actually the same.



That's not my concern though.  What I'm responding to is Nigel
Rantor's grossly incorrect statements about probability.  The chance
of collision, in our life time, is *insignificant*.


Please tell me which statements? That the chance of two files hashing to 
the same value is non-zero? You admit as much above.


Also, please remember I gave you a way of verifying what I said, go 
crawl the web for images, pages, whatever, build a hash DB and tell me 
how long it takes you to find a collision using MD5 (which is the hash I 
was talking about when I told you I had real-world, experience to back 
up the theoretical claim that collisions occur.


Regards,

  Nigel

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


Re: Accessing a parse tree

2009-04-17 Thread Aaron Brady
On Apr 17, 4:03 am, Clarendon  wrote:
> Thank you very much for this information. It seems to point me to the
> right direction. However, I do not fully understand the flatten
> function and its output. Some indices seem to be inaccurate. I tried
> to find this function at nltk.tree.Tree.flatten, but it returns a
> flattened tree, not a tuple.
>
> So your flatten function must be a different one, and it's not one of
> the builtins, either. Could you tell me where I can find the
> documentation about this flatten function?

No, it is a different one.  I don't even have it.  We'd have to write
it.

The indices weren't included in the flattened tree, but if you're
writing it, it can.

0: ( 'ROOT', None, , None --no parent--, 0 )
1: ( 'S', None, , 0 --parent is 'ROOT'--, 1 )
2: ( 'NP', None, , 1 --parent is 'S'--, 2 )
3: ( 'PRP', 'I', , 2 --parent is 'NP'--, 3 )
4: ( 'VP', None, , 1 --parent is 'S', 2 )
5: ( 'VBD', 'came', , 4 --parent is 'VP'--, 2 )

I screwed up the 'depth' field on #5.  It should be:
5: ( 'VBD', 'came', , 4 --parent is 'VP'--, **3** )

Otherwise I'm not sure what you mean by 'indices seem to be
inaccurate'.  I'm still not completely sure though.  After all, I did
it by hand, not by program.

If your package comes with a flatten function, it would be a good
place to start.  Flatten functions can get hairy.  What is its code,
and what is its output?

Here's an example:

>>> a= [ 'p', [ [ 'q', 'r' ], 's', 't' ], 'u' ]
>>> a
['p', [['q', 'r'], 's', 't'], 'u']
>>> def flatten( x ):
... for y in x:
... if isinstance( y, list ):
... for z in flatten( y ):
... yield z
... else:
... yield y
...
>>> list( flatten( a ) )
['p', 'q', 'r', 's', 't', 'u']
--
http://mail.python.org/mailman/listinfo/python-list


Re: binary file compare...

2009-04-17 Thread Tim Wintle
On Thu, 2009-04-16 at 21:44 -0700, Adam Olsen wrote:
> The Wayback Machine has 150 billion pages, so 2**37.  Google's index
> is a bit larger at over a trillion pages, so 2**40.  A little closer
> than I'd like, but that's still 56294995000 to 1 odds of having
> *any* collisions between *any* of the files.  Step up to SHA-256 and
> it becomes 1915619400 to
> 1.  Sadly, I can't even give you the odds for SHA-512, Qalculate
> considers that too close to infinite to display. :)

That might be true as long as your data is completely uniformly
distributed. For the example you give there's:

a) a high chance that there's "" near the top

b) a non-uniform distribution of individual words within the text.

c) a non-unifom distribution of all n-grams within the text (as there is
in natural language)

So it's very far from uniformly distributed. Just about the only
situation where I could imagine that holding would be where you are
hashing uniformly random data for the sake of testing the hash.


I believe the point being made is that comparing hash values is a
probabilistic algorithm anyway, which is fine if you're ok with that,
but for mission critical software it's crazy.

Tim Wintle

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


Re: how to know the importing file name from an imported file?

2009-04-17 Thread Peter Otten
Visco Shaun wrote:

> Is there a way to know the name of the script(say A), which is importing
> a module(say B), from B?
> ie in above situation i should be able to get name 'A' through some way
> in B, when A contains an 'import B' statement.

While

import sys
print "I'm imported by %r" % sys._getframe(1).f_globals["__name__"]

will sometimes work this is a bad idea. What are you trying to achieve?
--
http://mail.python.org/mailman/listinfo/python-list


Re: compiler package vs parser

2009-04-17 Thread Robin Becker

Kay Schluehr wrote:

On 16 Apr., 11:41, Robin Becker  wrote:


Is the compiler package actually supposed to be equivalent to the parser module?


No. The parser module creates a concrete parse tree ( CST ) whereas
the compiler package transforms this CST into an AST for subsequent
computations. In more recent versions those CST -> AST transformations
are performed by the runtime and the Python compiler uses those
internally produced ASTs. The Python 2.6 API to ASTs is the ast module.

..

OK having digested most of what Kay said (my simple engineer's brain being 
rather stretched at the best of times) I would like to rephrase my question.


Is it intended that the compile package be able to create the same code as the 
normal parser chain. I think I understand now that the compiler used internally 
is now exposed in various ways as built in modules.


The example I gave earlier seems to indicate that the compiler package may not 
be creating the same final bytecode at least using the compilation approach that 
I used (cbased on the compiler package itself).


If I have messed that up then there should be some easy fix, otherwise if 
pycodegen is somehow not getting the semantics of the the variables i,j correct 
is there some way I can fix that.


I realize that I probably ought to be trying this out with the newer ast stuff, 
but currently I am supporting code back to 2.3 and there's not much hope of 
doing it right there without using the compiler package.


My analysis of the problem is that in

 start p.py
def func(D):
for k in D:
exec '%s=D[%r]' % (k,k)
print i, j, k
print locals()
print i, j, k

if __name__=='__main__':
func(dict(i=1,j=33))
 end p.py

the compiler package ends up treating i & j as global, whereas the modern 
analysis doesn't (and doesn't say they're definitely local either). Looking at 
the code in Python/compile.c the compile_nameop code seems to check for scopes 
FREE, CELL, LOCAL, GLOBAL_IMPLICIT & GLOBAL_EXPLICIT whereas 
pycodegen.CodeGenerator._nameOp seems not to know about GLOBAL_IMPLICIT/EXPLICIT 
but has only a single GLOBAL scope.

--
Robin Becker

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


how to know the importing file name from an imported file?

2009-04-17 Thread R. David Murray
Visco Shaun  wrote:
> Hi
> 
> Is there a way to know the name of the script(say A), which is importing
> a module(say B), from B?
> ie in above situation i should be able to get name 'A' through some way
> in B, when A contains an 'import B' statement.

Suppose module C imports module B as well?

So, no, not in any useful way.

--
R. David Murray http://www.bitdance.com

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


sys.setcheckinterval() never gets updated second time. Bug?

2009-04-17 Thread k3xji
Hi all,

Yesterday I opened a thread for this issue where I was calling
sys.setcheckinterval() with sys.maxint and then try to set it to a
lower value but did not succeed with that. Here it is:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/fc01a6470245a704/f80733445ce30a36#f80733445ce30a36

I think we might have a bug or a undocumented intention.

Here is the related code in Python/ceval.c, line number 833 Python
2.6.2 source code:

if (--_Py_Ticker < 0) {
if (*next_instr == SETUP_FINALLY) {
/* Make the last opcode before
   a try: finally: block uninterruptable. */
goto fast_next_opcode;
}
_Py_Ticker = _Py_CheckInterval;
tstate->tick_counter++;

>From what I understand is this, when you call sys.setcheckinterval()
with some value, _Py_Ticker volatile variable is not updated until
next context-switch. As in our example we set _Py_CheckInterval to
sys.maxint() then the thread starts ticking and even we set
checkinterval to a lower value, it is never updated as it waits for
the next context switch. Of course, if you do a blocking call, context
switch occurs and you think everything is fine, but as _Py_Ticker gets
never to "0" every thread starts running till finding a blocking call
which, in turn results in uncontrolled thread scheduling behavior.

As far as I understand, setcheckinterval() never designed to handle
such big values like sys.maxint to simulate unpreemtable behavior. If
the case is so, I think in any way we should document it somewhere.

Comments?

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


Re: Help improve program for parsing simple rules

2009-04-17 Thread pruebauno
On Apr 16, 3:59 pm, Aaron Brady  wrote:
> On Apr 16, 10:57 am, [email protected] wrote:
>
> > Another interesting task for those that are looking for some
> > interesting problem:
> > I inherited some rule system that checks for programmers program
> > outputs that to be ported: given some simple rules and the values it
> > has to determine if the program is still working correctly and give
> > the details of what the values are. If you have a better idea of how
> > to do this kind of parsing please chime in. I am using tokenize but
> > that might be more complex than it needs to be. This is what I have
> > come up so far:
>
> > rules=[
> >          '( A - B ) = 0',
> >          '(A + B + C + D + E + F + G + H + I) = J',
> >          '(A + B + C + D + E + F + G + H) = I',
> >          '(A + B + C + D + E + F) = G',
> >          '(A + B + C + D + E) = (F + G + H + I + J)',
> >          '(A + B + C + D + E) = (F + G + H + I)',
> >          '(A + B + C + D + E) = F',
> >          '(A + B + C + D) = (E + F + G + H)',
> >          '(A + B + C) = (D + E + F)',
> >          '(A + B) = (C + D + E + F)',
> >          '(A + B) = (C + D)',
> >          '(A + B) = (C - D + E - F - G + H + I + J)',
> >          '(A + B) = C',
> >          '(A + B) = 0',
> >          '(A+B+C+D+E) = (F+G+H+I+J)',
> >          '(A+B+C+D) = (E+F+G+H)',
> >          '(A+B+C+D)=(E+F+G+H)',
> >          '(A+B+C)=(D+E+F)',
> >          '(A+B)=(C+D)',
> >          '(A+B)=C',
> >          '(A-B)=C',
> >          '(A/(B+C))',
> >          '(G + H) = I',
> >          '-0.99 LE ((A+B+C)-(D+E+F+G)) LE 0.99',
> >          '-0.99 LE (A-(B+C)) LE 0.99',
> >          '-1000.00 LE A LE 0.00',
> snip
> > def main():
> >     for cur_rule in rules[20:26]:
> >         tokens=get_tokens(cur_rule)
> >         normal=replace_comps(tokens,COMP_REPLACERS)
> >         subst=replace_names(normal,vars_)
> >         groups=split_seccions(subst,COMP_REPLACERS.values())
> >         rep=all_seccions(groups)
> >         rep_out=''.join(x[0]+x[1] for x in rep)
> >         calc=calc_seccions(rep)
> >         calc_out=''.join(x[0]+x[1] for x in calc)
> >         deltas=calc_deltas(calc)
> >         result=eval(calc_out,{},{})
>
> snip
>
> You are using 'eval' which isn't safe if its inputs are dangerous.  If
> you are controlling the inputs, you might be interested in the
> optional arguments to 'eval'.
>
> >>> a= '-1000.00 < A < 0.00'
> >>> eval( a, { 'A': -100 } )
> True
> >>> eval( a, { 'A': -1000 } )
>
> False
>
> The syntax is slightly different for Python 2.  For the replacement of
> 'LE', I assume you require spaces on both sides.
>
> >>> a= '-1000.00 LE A LE 0.00'
> >>> b= a.replace( ' LE ', ' <= ' )
> >>> b
>
> '-1000.00 <= A <= 0.00'>>> eval( b, { 'A': -1000 } )
> True
> >>> eval( b, { 'A': -1001 } )
>
> False
>
> If you need something more flexible, the 'ast' module gives you more
> options.  The string has to be a valid Python module to start with.
>
> FYI, have you checked order of precedence in your custom rule set to
> match Python's?

I know about evals implication of safety. Rules are defined by the
programmers so I don't worry too much about it at this point. They
should know better than messing up their application server. Unless
there is some easier way to do it I am willing to take the risk.
Precedence is standard math, we can always add some extra parenthesis
to the rules, I don't thing the old system would mind.

I thought about using eval with a locals dictionary, but they want
output of the intermediate values. I want to avoid the situation where
the intermediate output does not match what eval is doing.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] large db question about no joins

2009-04-17 Thread andrew cooke

on the more general point about exactly how to handle large data sets, i
found this article interesting -
http://highscalability.com/unorthodox-approach-database-design-coming-shard

andrew

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


Re: how to know the importing file name from an imported file?

2009-04-17 Thread Duncan Booth
Visco Shaun  wrote:

> Hi
> 
> Is there a way to know the name of the script(say A), which is importing
> a module(say B), from B?
> ie in above situation i should be able to get name 'A' through some way
> in B, when A contains an 'import B' statement.

The script always runs in module __main__, so when running a script form a 
file you just need to look at the __main__.__file__ attribute. Of course 
your module could also be imported from an interactive session with no 
script so you'll want to protected against that:

import __main__
print getattr(__main__, "__file__", "not running a script")

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


Re: Help improve program for parsing simple rules

2009-04-17 Thread pruebauno
On Apr 16, 9:29 pm, John Machin  wrote:
> On Apr 17, 1:57 am, [email protected] wrote:
>
> > COMP_REPLACERS={'LT':'<', 'GT':'>', 'LE':'<=', 'GE':'>=', '=':'==',
> > '=>':'=>', '=<':'=<'}
>
> What do the '=>' and '=<' represent? Why are you replacing each by
> itself?

because of this:
groups=split_seccions(subst,COMP_REPLACERS.values())

I didn't want to create a separate variable. Those are dubious anyway,
I haven't seen one in all of our current rules and it generates a
syntax error in Python so I took them out:

COMP_REPLACERS={'LT':'<', 'GT':'>', 'LE':'<=', 'GE':'>=', '=':'=='}

And before somebody else points it out. This line:

(TOK.NUMBER,str(vars_.get(x[1],x[1]))) if x[0]==TOK.NAME

should really be:

(TOK.NUMBER,str(vars_[x[1]])) if (x[0]==TOK.NAME and x[1] in vars_)
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] RELEASED Python 2.6.2

2009-04-17 Thread Barry Warsaw

On Apr 17, 2009, at 5:42 AM, Piet van Oostrum wrote:


Maybe a link to the MacOSX image can also be added to
http://www.python.org/download


Done.
-Barry



PGP.sig
Description: This is a digitally signed message part
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to know the importing file name from an imported file?

2009-04-17 Thread Dave Angel

Visco Shaun wrote:

Hi

Is there a way to know the name of the script(say A), which is importing
a module(say B), from B?
ie in above situation i should be able to get name 'A' through some way
in B, when A contains an 'import B' statement.
  


The full path to the script is stored in sys.argv[0]

Of course the script may not import B directly, so it may not have such 
an import statement.  If you're not looking for the script, but for the 
particular module that imports you, I don't know of a way. Naturally, 
it'd be a list of modules, not a single one.


Why not have the A module invoke a function in B, giving its own name?


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


Re: Accessing a parse tree

2009-04-17 Thread John Machin

On 17/04/2009 7:32 PM, Clarendon wrote:

Dear John Machin


I presume that you replied to me instead of the list accidentally.



So sorry about the typo. It should be: "the program should *see* that
the designated *words* are..."

"a long way" has two parentheses to the left -- (VP (DT -- before it
hits a separate group -- VBD came).


Like I said, the parentheses are an artifact of one particular visual 
representation of the parse tree. Your effort at clarification has 
introduced new unexplained terminology ("separate group"). BTW if you 
plan to persist with parentheses, you might at least display the tree in 
a somewhat more consistent fashion, discovering in the process that you 
are two parentheses short:

(ROOT
(S
(NP
(PRP I)
)
(VP
(VBD came)
(NP
(DT a)
(JJ long)
(NN way)
)
(PP
(IN in)
(S
(VP
(VBG changing)
(NP
(PRP$ my)
(NN habit)
)
)
)
)
)
Now look at this:
ROOT
S
NP
PRP I
VP
VBD came
NP
DT a
JJ long
NN way
PP
IN in
etc etc
No parentheses, and no loss of information.

In fact if you keep the parentheses and lose all whitespace except a 
space between each node-type an a terminal word, you'll see that the 
parenthesis notation is just one way of serialising the tree.


You have a tree structure, with the parsed information built on top of 
the words (terminals). A very quick flip through the NLTK tutorial gave 
me the impression that it would be highly unlikely not to have all you 
need -- and a bazillion other things, which is probably why you can't 
find what you want :-) I certainly saw having parents mentioned as an option


Suggestions:
1. Get a pencil and a piece of paper, write "ROOT" at the top in the 
centre, and write "I came a long way in .." spaced across the 
bottom. Fill in the parse tree.
2. Express your requirement in terms of moving around the tree, 
following pointers to parent, left/elder sibling (if any), right/younger 
sibling (if any), and children. E.g. the 3 parse nodes for "a long way" 
are "DT JJ NN" and their parent is "NP". NP's left sibling is a VBD node 
("came") and its right sibling is a PP ("in .")

3. Then have another look at the NLTK docs
4. Ask questions on the NLTK mailing list.

HTH,
John

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


Re: Unpreempted behavior with sys.setcheckinterval

2009-04-17 Thread Aahz
In article ,
k3xji   wrote:
>
>I want unpreempted behavior for some application and do some testing
>as below. Well the unpreemption behavior is working fine with
>sys.setcheckinterval(sys.maxint). However, when I set the interval to
>a lower value, the thread does not being preempted anymore, it runs
>until it is finished. 

I'm sorry, I think English is not your primary language, and I can't
quite understand what you mean here.  Please rephrase.

Note that sys.setcheckinterval() is *not* designed to force threads to
run to completion, only to allow you to change the time chunk for a
thread to process, and if anything goes through the GIL, the thread may
yield.  To force a thread to be the only thread running, you need to use
some kind of locking.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


OpenGL win32 Python

2009-04-17 Thread gintare statkute
 Hello,

i found an example for OpenGL in windows.
It is incredibly helpful, but how to rewrite it to be useful in Python.

 How to give address of pfd in Python?:
iFormat = ChoosePixelFormat( hDC, &pfd );
SetPixelFormat( hDC, iFormat, &pfd );

I found syntax for sizeof and pfd:

#! /usr/include/pyhton2.4 python
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
import win32api
import sizeof
pfd=Gdi.PIXELFORMATDESCRIPTOR()
ZeroMemory( pfd, ctypes.sizeof( pfd ) )

regards,
Gintare Statkute

p.s. whole code which i want to use in Python:
http://www.nullterminator.net/opengl32.html
only the addresses and pointer are not clear (marked in red above)


void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;

// get the device context (DC)
*hDC = GetDC( hWnd );

// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
  PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( *hDC, &pfd );
SetPixelFormat( *hDC, iFormat, &pfd );

// create and enable the render context (RC)
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}

void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}
--
http://mail.python.org/mailman/listinfo/python-list


Re: compiler package vs parser

2009-04-17 Thread Aahz
In article ,
Robin Becker   wrote:
>
>My analysis of the problem is that in
>
> start p.py
>def func(D):
> for k in D:
> exec '%s=D[%r]' % (k,k)
> print i, j, k
> print locals()
> print i, j, k
>
>if __name__=='__main__':
> func(dict(i=1,j=33))
> end p.py
>
>the compiler package ends up treating i & j as global, whereas the
>modern analysis doesn't (and doesn't say they're definitely local
>either). Looking at the code in Python/compile.c the compile_nameop
>code seems to check for scopes FREE, CELL, LOCAL, GLOBAL_IMPLICIT &
>GLOBAL_EXPLICIT whereas pycodegen.CodeGenerator._nameOp seems not to
>know about GLOBAL_IMPLICIT/EXPLICIT but has only a single GLOBAL scope.

At this point, given the lack of response from people who actually know
the compiler internals, I think it's fair of you to try going to
python-dev -- normally questions like this are off-topic, and if someone
complains, I'll take the blame.  ;-)
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to know the importing file name from an imported file?

2009-04-17 Thread John Machin
On Apr 17, 9:17 pm, Visco Shaun  wrote:
> Hi
>
> Is there a way to know the name of the script(say A), which is importing
> a module(say B), from B?
> ie in above situation i should be able to get name 'A' through some way
> in B, when A contains an 'import B' statement.

I find it difficult to imagine a sensible use case for a module
wanting to know which other module/script imported it. Functions/
methods should *not* contain "logic" like "I'm being imported by the
xyzzy script so I'll do something subtly different". Alternative
behaviours should be invoked explicitly through args in the APIs, not
through nasty manholes/trapdoors.

BTW "imported by" is not 100% identical to "called from".

Note: It's a frequent requirement to find the path to the originating
script, in the case that some resource files are located in the same
directory. Is that what you want? That path will be in sys.argv[0]

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


Re: OpenGL win32 Python

2009-04-17 Thread Maxim Khitrov
On Fri, Apr 17, 2009 at 9:27 AM, gintare statkute  wrote:
> Hello,
>
> i found an example for OpenGL in windows.
> It is incredibly helpful, but how to rewrite it to be useful in Python.
>
> How to give address of pfd in Python?:
> iFormat = ChoosePixelFormat( hDC, &pfd );
> SetPixelFormat( hDC, iFormat, &pfd );

Take a look at ctypes.byref and ctypes.pointer. Post the results if
you get it to work :)

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


Registering Cron using CronTab

2009-04-17 Thread gurcharan . saini
Hi

I'm developing a Django application which is running on Apache. We
need to add crontab from the Python script and we are using Python
CronTab package  for
this.

I'm stuck with the issue - if we execute the code from Apache the
crontab is not getting updated, while it get updated if we run it from
Django in-built webserver.

Does anyone have any idea why this is happening.

I'm on Ubuntu.

Thanks

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


Re: compiler package vs parser

2009-04-17 Thread Scott David Daniels

Robin Becker wrote:
  If I have messed that up then there should be some easy fix, otherwise 
if pycodegen is somehow not getting the semantics of the the variables 
i,j correct is there some way I can fix that


def func(D):
for k in D:
exec '%s=D[%r]' % (k,k)
print i, j, k
print locals()
print i, j, k

if __name__=='__main__':
func(dict(i=1,j=33))
 end p.py

the compiler package ends up treating i & j as global, whereas the 
modern analysis doesn't (and doesn't say they're definitely local 
either).


If they are not definitely local, they are non-local.  Locals are
determined at function definition time, not function execution time.
So, your expectations about what the exec statement can do above are
mistaken.  You may try to work your way around it, but, IMHO, you
will not succeed.  If the code above were to work as you wish, every
access to every non-local in code that contains an "exec" would have
to check a "new locals" dictionary just in case the exec added a local.
Think about what this code would have to do:
> i = j = 42
> def func(D):
> print i, j, k
> for k in D:
> exec '%s=D[%r]' % (k,k)
> print i, j, k

--Scott David Daniels
[email protected]

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


Re: Registering Cron using CronTab

2009-04-17 Thread Philip Semanchuk


On Apr 17, 2009, at 9:51 AM, [email protected] wrote:


Hi

I'm developing a Django application which is running on Apache. We
need to add crontab from the Python script and we are using Python
CronTab package  for
this.

I'm stuck with the issue - if we execute the code from Apache the
crontab is not getting updated, while it get updated if we run it from
Django in-built webserver.


Sure sounds like a permissions problem to me.


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


Re: script question

2009-04-17 Thread Aahz
In article , Piet van Oostrum   wrote:
>
>Others have suggested getattr. I think a cleaner (more pythonic) way
>would be: 
>
>funclist = [func01, func02, func03, ... ]
>for i in range(1,n):
>funclist[i]()

Go to all that trouble, you might as well make it easier:

for func in funclist:
func()
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: QT , Wxwidgets are not just UI framework ?

2009-04-17 Thread Deep_Feelings
On Apr 17, 1:52 pm, "Diez B. Roggisch"  wrote:
> Deep_Feelings wrote:
> > qt include many libraries : network , threading,database ..etc while
> > Wxwidgets seem similar but with less scope
>
> > my question is : does these frameworks replace python's (or any other
> > language for that matter) built-in libraries ? or python does not
> > include that sort of libraries ?
>
> Some it includes, others it doesn't. And they come with different features.
>
> While python comes with a lot of included batteries, for some things you
> need a more powerful generator - that's where 3rd-party-libraries come into
> play.
>
> There are plenty of discussions about which GUI-toolkit is the best - google
> this group.
>
> However, mostly people agree that Qt is the most powerful, but often was
> debunked because of it's licensing. This has changed to the much more
> liberal LGPL for Qt4.5.
>
> Now it might be though that you'd still need to buy a license from Phil
> Thompson for his excellent PyQt-wrapping - but I'd personally say it's more
> worth than it actually costs given the power of Qt.
>
> Diez

thank you

considering that wxwidget is open source and free do you think that QT
lisencing is worth it ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Man Bites Python

2009-04-17 Thread Dotan Cohen
> Man bites python.
> Python bites dog.
> Dog bites man.
>

This beats rock paper scissors by a long shot.

Python: Index finger extended
Man: Index and middle fingers extended, thumb between them
Dog: Four main fingers extended and slightly curved, thumb touches tip
of middle finger

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
--
http://mail.python.org/mailman/listinfo/python-list


Re: script question

2009-04-17 Thread Scott David Daniels

Marco Mariani wrote:

Piet van Oostrum wrote:


funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()

Or myscript.funclist[i]() from another module.


Ehm, calling a bazillion things in the right order should be a 
responsibility of the myscript module anyway.



For example, you could do it like:

myscript.py:
funclist = []

def _included(function):
funclist.append(function)
return function

@_included
def func01():
...

@_included
def func02():
...

def call_all():
for function in funclist:
function()

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


Language detection with python

2009-04-17 Thread S.Selvam
Hi all,

I am trying for language detection in python.I just need to check whether
the input text is english or not.

1)I tried nltk's stopwords and compared with input text,but only with little
success.

2)Used oice.langdet for language detection,which uses bi-gram approach.It is
also inefficient.

I need a best way to detect english text .

I welcome your suggestions ...
-- 
Yours,
S.Selvam
--
http://mail.python.org/mailman/listinfo/python-list


ANN: doit 0.2.0 released

2009-04-17 Thread Eduardo Schettino
doit comes from the idea of bringing the power of build-tools to
execute any kind of task. It will keep track of dependencies between
“tasks” and execute them only when necessary. It was designed to be
easy to use and “get out of your way”.

check the new website http://python-doit.sourceforge.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: script question

2009-04-17 Thread gitulyar
On Apr 17, 5:23 pm, Scott David Daniels  wrote:
> Marco Mariani wrote:
> > Piet van Oostrum wrote:
>
> >> funclist = [func01, func02, func03, ... ]
> >> for i in range(1,n):
> >>     funclist[i]()
>
> >> Or myscript.funclist[i]() from another module.
>
> > Ehm, calling a bazillion things in the right order should be a
> > responsibility of the myscript module anyway.
>
> For example, you could do it like:
>
> myscript.py:
>      funclist = []
>
>      def _included(function):
>          funclist.append(function)
>          return function
>
>     �...@_included
>      def func01():
>          ...
>
>     �...@_included
>      def func02():
>          ...
>
>      def call_all():
>          for function in funclist:
>              function()
>
> --Scott David Daniels
> [email protected]

This code does the same as '__all__' should, but anyway it's
the ugly way, because you have to edit '__all__' every time
you add/remove new functions to your module and if '__all__'
is absent your code won't work.

As for me the best solution is to use 'dir()':

for func in dir(myscript):
if match(func):
getattr(myscript, func)()
--
http://mail.python.org/mailman/listinfo/python-list


Re: script question

2009-04-17 Thread Peter Pearson
On 17 Apr 2009 07:03:18 -0700, Aahz  wrote:
> In article , Piet van Oostrum wrote:
>>
>>funclist = [func01, func02, func03, ... ]
>>for i in range(1,n):
>>funclist[i]()
>
> Go to all that trouble, you might as well make it easier:
>
> for func in funclist:
> func()

Yes.  Especially because func01 gets called, this way.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: compiler package vs parser

2009-04-17 Thread Gabriel Genellina
En Fri, 17 Apr 2009 10:55:46 -0300, Scott David Daniels  
 escribió:



Robin Becker wrote:


def func(D):
for k in D:
exec '%s=D[%r]' % (k,k)
print i, j, k
print locals()
print i, j, k
 if __name__=='__main__':
func(dict(i=1,j=33))
 end p.py
 the compiler package ends up treating i & j as global, whereas the  
modern analysis doesn't (and doesn't say they're definitely local  
either).


If they are not definitely local, they are non-local.  Locals are
determined at function definition time, not function execution time.
So, your expectations about what the exec statement can do above are
mistaken.  You may try to work your way around it, but, IMHO, you
will not succeed.  If the code above were to work as you wish, every
access to every non-local in code that contains an "exec" would have
to check a "new locals" dictionary just in case the exec added a local.


And that's what happens. In absence of an exec statement, locals are  
optimized: the compiler knows exactly how many of them exist, and its  
names, just by static code analysis. But when the function contains an  
exec statement (or an "import *" statement) this is not possible anymore,  
and the compiler has to switch to another strategy and generate code using  
a less-optimized approach. Unknown variables are accessed using  
LOAD_NAME/STORE_NAME (require a name lookup) instead of the normal  
LOAD_FAST/STORE_FAST for local variables and LOAD_GLOBAL/STORE_GLOBAL for  
global ones.



Think about what this code would have to do:
 > i = j = 42
 > def func(D):
 > print i, j, k
 > for k in D:
 > exec '%s=D[%r]' % (k,k)
 > print i, j, k


I don't completely understand what you wanted to show, but try this:

py> i = j = 42
py> def f():
...   print i, j
...   exec "k=1"
...   print i, j, k
...   exec "i=5"
...   print i, j, k
...
py> f()
42 42
42 42 1
5 42 1
py> i
42
py> j
42
py> k
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'k' is not defined

Note that i starts as a global name and after the exec "i=5" it becomes a  
local variable; and k is always a local variable even if there is no  
explicit assignment to it (except in the exec).


--
Gabriel Genellina

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


Re: [OT] large db question about no joins

2009-04-17 Thread Daniel Fetchinson
>> Well, I gave the concrete example of zoo/cage/animal/leg because this
>> *is* the business logic. I need to know for example the total number
>> of animals, this is pretty understandable if you have a zoo. Or you
>> mean that I should give another example?
>
> It might be the business logic but not the process.
> http://en.wikipedia.org/wiki/Business_process
>
>>> Using the business process I could probably
>>> narrow down the scope quite a bit like,
> 
>> No, I'd like to have the exact number at any given time.
> Fair enough, but this is then the *exact* scope you like to answer me in.
>>
> 
>> Let's say I need to implement this on the google app engine, so I
>> can't make too many choices on my own. On the GAE, how would I do
>> this?
> All other data modeling (e.g. EAV, relational, object orientated) will
> result in a structure requiring extra calculation when doing the query
> (and thus according your requirement isn't acceptable).
>
> So I need to store the data in such a way that it is accessible before
> the query with the minimal amount of processing.
>
> Thus the only thing left is writing a subroutine in my code which
> recalculates the amount of legs when there is a change in it and store
> it just as a pair value:
> amount_of_legs = Positive Integer

Actually, this is a pretty good idea! In my case there are not so many
writes, but tons of reads. So doing this is actually absolutely
feasible.

> The thing with bogus requirements for an imaginary example is that the
> solution is imaginary bogus too, leaving little room for applicability
> in the real world.

It's not so bogus I think. But here is another example, even more
concrete, maybe that will show more clearly what I'm talking about,
sorry if I was not clear enough: let's say you have a music store and
you have cd's in the store.

In an relational database setting you would have a table for artists,
a table for cd's and a table for songs and a table for comments where
people can comment on songs. All of this with obvious foreign keys.
Now you want to display on your website the total number of cd's, the
total number of songs and the total number of comments because that
looks very cool on top of every page: 1242342 cd's and 134242342342
songs and 284284728347284728 comments!

Okay, so you need to issue a query with joins in your relational db.
Or in another query, you want to select all comments of an artist,
meaning all comments that were comments on a song belonging to cd's of
a given artist. This would also involve joins.

How would I do these queries if I can't have joins or in other words
how would I lay out my data storage?

Thanks by the way for your help and replies,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Language detection with python

2009-04-17 Thread Jeremiah Dodds
On Fri, Apr 17, 2009 at 3:19 PM, S.Selvam  wrote:

> Hi all,
>
> I am trying for language detection in python.I just need to check whether
> the input text is english or not.
>
> 1)I tried nltk's stopwords and compared with input text,but only with
> little success.
>
> 2)Used oice.langdet for language detection,which uses bi-gram approach.It
> is also inefficient.
>
> I need a best way to detect english text .
>
> I welcome your suggestions ...
> --
> Yours,
> S.Selvam
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

I don't know anything about language detection, but my first attempt would
be something like:

Grab the first N words (space-separated) from whatever file you're trying to
check
Find out what percentage of them, if any, are in some dictionary file, say
/usr/share/dict/american-english on Ubuntu linux.

If there's a high percentage of words found, it's more than likely english.

Or, perhaps checking for some commonly used words in english that only
appear in english. I'm not aware of any examples off the top of my head, as
I only know one language, but I'm sure there are some common english words
that are mostly unique to the language.
--
http://mail.python.org/mailman/listinfo/python-list


Re: QT , Wxwidgets are not just UI framework ?

2009-04-17 Thread Diez B. Roggisch
Deep_Feelings wrote:

> On Apr 17, 1:52 pm, "Diez B. Roggisch"  wrote:
>> Deep_Feelings wrote:
>> > qt include many libraries : network , threading,database ..etc while
>> > Wxwidgets seem similar but with less scope
>>
>> > my question is : does these frameworks replace python's (or any other
>> > language for that matter) built-in libraries ? or python does not
>> > include that sort of libraries ?
>>
>> Some it includes, others it doesn't. And they come with different
>> features.
>>
>> While python comes with a lot of included batteries, for some things you
>> need a more powerful generator - that's where 3rd-party-libraries come
>> into play.
>>
>> There are plenty of discussions about which GUI-toolkit is the best -
>> google this group.
>>
>> However, mostly people agree that Qt is the most powerful, but often was
>> debunked because of it's licensing. This has changed to the much more
>> liberal LGPL for Qt4.5.
>>
>> Now it might be though that you'd still need to buy a license from Phil
>> Thompson for his excellent PyQt-wrapping - but I'd personally say it's
>> more worth than it actually costs given the power of Qt.
>>
>> Diez
> 
> thank you
> 
> considering that wxwidget is open source and free do you think that QT
> lisencing is worth it ?

What do you think I wrote the following sentence for?

"""
Now it might be though that you'd still need to buy a license from Phil
Thompson for his excellent PyQt-wrapping - but I'd personally say it's
more worth than it actually costs given the power of Qt.
"""

Diez

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


Re: script question

2009-04-17 Thread D'Arcy J.M. Cain
On 17 Apr 2009 07:03:18 -0700
[email protected] (Aahz) wrote:
> Go to all that trouble, you might as well make it easier:
> 
> for func in funclist:
> func()

And if you need the return values:

retlist = [func() for func in funclist]

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help improve program for parsing simple rules

2009-04-17 Thread Paul McGuire
On Apr 16, 10:57 am, [email protected] wrote:
> Another interesting task for those that are looking for some
> interesting problem:
> I inherited some rule system that checks for programmers program
> outputs that to be ported: given some simple rules and the values it
> has to determine if the program is still working correctly and give
> the details of what the values are. If you have a better idea of how
> to do this kind of parsing please chime in. I am using tokenize but
> that might be more complex than it needs to be. This is what I have
> come up so far:

I've been meaning to expand on pyparsing's simpleArith.py example for
a while, to include the evaluation of the parsed tokens.  Here is the
online version, http://pyparsing.wikispaces.com/file/view/eval_arith.py,
it will be included in version 1.5.2 (coming shortly).  I took the
liberty of including your rule set as a list of embedded test cases.

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


Inheriting dictionary attributes and manipulate them in subclasses

2009-04-17 Thread Dominik Ruf
Hi,

I just stumbled upon the following behaviour.
>>> class base():
...   dic = {'1':'1', '2':'2'}
...
>>> class child1(base):
...   def __init__(self):
... self.dic.update({'1':'2'})
...
>>> class child2(base):
...   pass
...
>>> c1 = child1()
>>> c2 = child2()
>>>
>>> print c1.dic
{'1': '2', '2': '2'}
>>> print c2.dic
{'1': '2', '2': '2'}

This is not what I have excepted.
Although I know the solution to get what I want...
>>> class base():
...   def __init__(self):
... self.dic = {'1':'1', '2':'2'}
...
>>> class child1(base):
...   def __init__(self):
... base.__init__(self)
... self.dic.update({'1':'2'})
...
>>> class child2(base):
...   pass
...
>>> c1 = child1()
>>> c2 = child2()
>>>
>>> print c1.dic
{'1': '2', '2': '2'}
>>> print c2.dic
{'1': '1', '2': '2'}

... I wonder if there is a special reason for the behaviour in the
first example.
Shouldn't the first example behave like the second?

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


Re: Help improve program for parsing simple rules

2009-04-17 Thread John Machin
On Apr 18, 1:26 am, Paul McGuire  wrote:
> On Apr 16, 10:57 am, [email protected] wrote:
>
> > Another interesting task for those that are looking for some
> > interesting problem:
> > I inherited some rule system that checks for programmers program
> > outputs that to be ported: given some simple rules and the values it
> > has to determine if the program is still working correctly and give
> > the details of what the values are. If you have a better idea of how
> > to do this kind of parsing please chime in. I am using tokenize but
> > that might be more complex than it needs to be. This is what I have
> > come up so far:
>
> I've been meaning to expand on pyparsing's simpleArith.py example for
> a while, to include the evaluation of the parsed tokens.  Here is the
> online version,http://pyparsing.wikispaces.com/file/view/eval_arith.py,
> it will be included in version 1.5.2 (coming shortly).  I took the
> liberty of including your rule set as a list of embedded test cases.

Hi Paul,

I don't see how it can handle the chained relop in the last two
testcases e. g. '0.00 LE A LE 4.00' -- unless relops are chained by
default in your parser.

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


Re: Inheriting dictionary attributes and manipulate them in subclasses

2009-04-17 Thread Diez B. Roggisch
Dominik Ruf wrote:

> Hi,
> 
> I just stumbled upon the following behaviour.
 class base():
> ...   dic = {'1':'1', '2':'2'}
> ...
 class child1(base):
> ...   def __init__(self):
> ... self.dic.update({'1':'2'})
> ...
 class child2(base):
> ...   pass
> ...
 c1 = child1()
 c2 = child2()

 print c1.dic
> {'1': '2', '2': '2'}
 print c2.dic
> {'1': '2', '2': '2'}
> 
> This is not what I have excepted.
> Although I know the solution to get what I want...
 class base():
> ...   def __init__(self):
> ... self.dic = {'1':'1', '2':'2'}
> ...
 class child1(base):
> ...   def __init__(self):
> ... base.__init__(self)
> ... self.dic.update({'1':'2'})
> ...
 class child2(base):
> ...   pass
> ...
 c1 = child1()
 c2 = child2()

 print c1.dic
> {'1': '2', '2': '2'}
 print c2.dic
> {'1': '1', '2': '2'}
> 
> ... I wonder if there is a special reason for the behaviour in the
> first example.
> Shouldn't the first example behave like the second?

No, because you are creating *classvariables* when declaring things like
this:

class Foo(object):
   bar = {}

If these are mutable, changing them will change them for *all* instances.

OTOH, when assigning to an instance, this will create an
*instance*-variable. Which is what

self.some_name = some_value

does.

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


Re: binary file compare...

2009-04-17 Thread norseman

Adam Olsen wrote:

On Apr 16, 11:15 am, SpreadTooThin  wrote:

And yes he is right CRCs hashing all have a probability of saying that
the files are identical when in fact they are not.


Here's the bottom line.  It is either:

A) Several hundred years of mathematics and cryptography are wrong.
The birthday problem as described is incorrect, so a collision is far
more likely than 42 trillion trillion to 1.  You are simply the first
person to have noticed it.

B) Your software was buggy, or possibly the input was maliciously
produced.  Or, a really tiny chance that your particular files
contained a pattern that provoked bad behaviour from MD5.

Finding a specific limitation of the algorithm is one thing.  Claiming
that the math is fundamentally wrong is quite another.
--
http://mail.python.org/mailman/listinfo/python-list



Spending a lifetime in applied math has taught me:
1) All applied math is finite.
2) Any algorithm failing to handle all contingencies is flawed.

The meaning of 1) is that it is limited in what it can actually do.
The meaning of 2) is that the designer missed or left out something.

Neither should be taken as bad. Both need to be accepted 'as 'is' and 
the decision to use (when,where,conditions) based on the probability of 
non-failure.



"...a pattern that provoked bad behavior... " does mean the algorithm is 
incomplete and may be fundamentally wrong. Underscore "is" and "may".


The more complicated the math the harder it is to keep a higher form of 
math from checking (or improperly displacing) a lower one.  Which, of 
course, breaks the rules.  Commonly called improper thinking. A number 
of math teasers make use of that.




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


Re: binary file compare...

2009-04-17 Thread SpreadTooThin
On Apr 17, 4:54 am, Nigel Rantor  wrote:
> Adam Olsen wrote:
> > On Apr 16, 11:15 am, SpreadTooThin  wrote:
> >> And yes he is right CRCs hashing all have a probability of saying that
> >> the files are identical when in fact they are not.
>
> > Here's the bottom line.  It is either:
>
> > A) Several hundred years of mathematics and cryptography are wrong.
> > The birthday problem as described is incorrect, so a collision is far
> > more likely than 42 trillion trillion to 1.  You are simply the first
> > person to have noticed it.
>
> > B) Your software was buggy, or possibly the input was maliciously
> > produced.  Or, a really tiny chance that your particular files
> > contained a pattern that provoked bad behaviour from MD5.
>
> > Finding a specific limitation of the algorithm is one thing.  Claiming
> > that the math is fundamentally wrong is quite another.
>
> You are confusing yourself about probabilities young man.
>
> Just becasue something is extremely unlikely does not mean it can't
> happen on the first attempt.
>
> This is true *no matter how big the numbers are*.
>
> If you persist in making these ridiculous claims that people *cannot*
> have found collisions then as I said, that's up to you, but I'm not
> going to employ you to do anything except make tea.
>
> Thanks,
>
>    Nigel

You know this is just insane.  I'd be satisfied with a CRC16 or
something in the situation i'm in.
I have two large files, one local and one remote.  Transferring every
byte across the internet to be sure that the two files are identical
is just not feasible.  If two servers one on one side and the other on
the other side both calculate the CRCs and transmit the CRCs for
comparison I'm happy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing a parse tree

2009-04-17 Thread Aaron Brady
On Apr 17, 8:22 am, John Machin  wrote:
> On 17/04/2009 7:32 PM, Clarendon wrote:
>
> > Dear John Machin
>
> I presume that you replied to me instead of the list accidentally.
>
>
>
> > So sorry about the typo. It should be: "the program should *see* that
> > the designated *words* are..."
>
> > "a long way" has two parentheses to the left -- (VP (DT -- before it
> > hits a separate group -- VBD came).
>
snip
> need -- and a bazillion other things, which is probably why you can't
> find what you want :-) I certainly saw having parents mentioned as an option

Is it opt-in or opt-out?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-17 Thread rogeeff
On Apr 17, 7:06 am, Aaron Brady  wrote:
> On Apr 17, 1:47 am, [email protected] wrote:
>
>
>
> > Hi,
>
> > I am C++ guy for the most part and don't know much of Python, so,
> > please, bear with me if I am asking errrm..idiotic question.
>
> > Old rexec module provided kinda 'secure' execution environment. I am
> > not looking for security at this point. What I need an execution
> > environment which almost like rexec, but is non-secure.
> >   What I want is:
> >   separate global dictionary,
> >   separate list of imported modules,
> >   separate sys.path
> >   (optionaly) separate __builtins__
>
> > I might be able to get away without my own builtins, but the rest I
> > need.
>
> > If  it's any help, I plan to use it to execute embedded Python scripts
> > from C++.
>
> > Thanks,
>
> > Gennadiy
>
> It depends what you mean by secure environment.  One option is to
> create a subprocess, to just limit access your variables.  Another is
> to compile and examine their code yourself, and prohibit things like
> access to the file class, the os module, etc.

I actually need *non-secure* execution environment. I just want
several independent ones.

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


Re: get text from rogramms runn by subprocess.Popen immediatetly

2009-04-17 Thread Aaron Brady
On Apr 16, 8:02 am, Rüdiger Ranft <[email protected]> wrote:
> Diez B. Roggisch schrieb:
>
> > Rüdiger Ranft schrieb:
> >> Hi all,
>
> >> I need to call some programms and catch their stdout and stderr streams.
> >> While the Popen class from subprocess handles the call, I get the
> >> results of the programm not until the programm finishes. Since the
> >> output of the programm is used to generate a progress indicator, I need
> >> a way to acces the values written to stdout/stderr as fast as possible.
snip

FWIR from what I recall, you have to create and open read and write
file descriptors using the 'msvcrt.get_osfhandle' function, and pass
them to the subprocess on the command line.  Or you can pass the
handles.  Then you get a communication channel that is not STDIN.

I have no idea why the designers did this.  I've submitted a patch,
and received 0 attention on it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-17 Thread Aaron Brady
On Apr 17, 11:19 am, [email protected] wrote:
> On Apr 17, 7:06 am, Aaron Brady  wrote:
snip
> > It depends what you mean by secure environment.  One option is to
> > create a subprocess, to just limit access your variables.  Another is
> > to compile and examine their code yourself, and prohibit things like
> > access to the file class, the os module, etc.
>
> I actually need *non-secure* execution environment. I just want
> several independent ones.
>
> Gennadiy

Oh.  Ken gave you a good answer then.  You can also check out the
'subprocess' and 'multiprocessing' modules.  Any closer?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-17 Thread rogeeff
On Apr 17, 3:16 am, Ken Seehart  wrote:
> [email protected] wrote:
> > Hi,
>
> > I am C++ guy for the most part and don't know much of Python, so,
> > please, bear with me if I am asking errrm..idiotic question.
>
> > Old rexec module provided kinda 'secure' execution environment. I am
> > not looking for security at this point. What I need an execution
> > environment which almost like rexec, but is non-secure.
> >   What I want is:
> >   separate global dictionary,
> >   separate list of imported modules,
> >   separate sys.path
> >   (optionaly) separate __builtins__

> As far as I know, you can't make multiple instances of the python
> environment from within python,

How about rexec? It's almost there. It just enforces some restrictions
I do not need. The problem as I see it is that I need custom import
operator to maintain separate "imported modules" list. The custom
import required separate __builtins__ dictionary and that cause the
Python C implementation to choke on access to the restricted
attributes.

Would I be able to have custom import without updating builtins, I'd
get what I need. But I do not know how to achieve this.

> but there is an easier way to get what
> you want, given that this is an embedding situation.

> See:http://wingware.com/psupport/python-manual/1.5/api/initialization.html

I am using Python 2.4, if it's matter

> You can use Py_NewInterpreter() to create multiple instances of python,
> which should give you the desired effect (though I have not tried this).

What do I do with pointer generated by this function? How do I execute
anything inside this interpreter?

Also I am not sure how will this work with Boost.Python I am
employing.

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


Re: Suggestions wanted on Tkinter problem

2009-04-17 Thread norseman

Dave Angel wrote:

norseman wrote:
One 
suggested I change the subject line - OK

I also replaced the [TAB]s since I noticed the Emailer seems
to get very confused with them.



Problem:
Using Python 2.5.2 and Tkinter ??? (came with system)
List made and for loop in use
lst=[ ("S", "Single"), .]

for mode, text 
c = Radiobuton(.
c.pack()

At this point the program runs, but I cannot control gray-out of a
specific Radiobutton.

If I:

counter=0
for mode, text 
c[counter] = Radiobuton(specified_frame,..
c[counter].pack()
counter += 1
.
.
blockUseOf= $varSetElsewhere
c[blockUseOf].config(state = strSetElsewhere)

Program crashes on Radiobutton line.

There are a number of Frames containing Radiobuttons in the program.
The individual lists are long enough no one in their right mind wants to
hand code such repetition and then try to maintain it. Not even with a
code generator. (Number and organization will change over time.)
How do I set things to be able to control any given Radiobutton from
elsewhere in the program and still use the for-loop loader?


Steve






Try posting as text.  The html tags in the message are distracting.

I don't know tkinter, but I can see a problem with your code.  You're 
using the [] operators on c, but you never initialize c.  Of course, you 
have a tiny fragment of code, and we're supposed to guess the rest.  But 
normally, when you build a list, you start with:

mylist = []
for     in :
   c =  new widget
   mylist.append(c)

Now, c is just temporary, but mylist contains reference to all the 
widgets.  So later on, you can use  mylist[42] to get button# 42.


A separate problem is that mylist should be a member of a class derived 
from the frame widget, or something like that.  So if this code is part 
of an __init__ method of a class, there are a few "self" items needed.


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


===
I don't use HTML!  I re-checked the file I sent and it is plain text.
I have no idea where the file you received has been, but sorry for 
problem because Yes, they are distracting from my own experiences.


"... if code is part of an __init__..."  No. It's for Global control.

I have tried every combination I could dream up -- except the (now) 
obvious one.  Being too close to the problem is just that - too close.


Problem solved - Thank you very much.


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


Re: script question

2009-04-17 Thread Scott David Daniels

gitulyar wrote:

On Apr 17, 5:23 pm, Scott David Daniels  wrote:

Marco Mariani wrote:

Piet van Oostrum wrote:

funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()
Or myscript.funclist[i]() from another module.

...
For example, you could do it like:
 funclist = []
 def _included(function):
 funclist.append(function)
 return function

 @_included
 def func01():
 ...
 def call_all():
 for function in funclist:
 function()

--Scott David Daniels
[email protected]


This code does the same as '__all__' should, but anyway it's
the ugly way, because you have to edit '__all__' every time
you add/remove new functions to your module and if '__all__'
is absent your code won't work.

As for me the best solution is to use 'dir()':

for func in dir(myscript):
if match(func):
getattr(myscript, func)()


Well, I prefer that the names of the functions not matter, (that
renaming a function not change the behavior of a program).  And if
you are not going by name, how do you refactor the functions that
you do want to call (and lift common behavior to a function).
It really does come down to style, and I like to avoid using
function names as the way to discover functions.  I put up with
the naming convention for testing, but I don't like it.  The only
excuse I see is that there are often a huge number of tests, and
there _is_ a convention for such names as defined by the xUnit style.
If we were starting from scratch now, I'd argue for a @test decorator.

--Scott David Daniels
[email protected]

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


cPickle and subclassing lists?

2009-04-17 Thread Reckoner
I have a large class that is a child of list. I need to pickle it, but
it's not working. For example, I have reduced it to the following:

class Mylist(list):
def __init__(self,x=[]):
list.__init__(self,x)

and I cannot even get this to pickle right.

>> w=Mylist([1,2,3])
>> dumps(w)

PicklingError: Can't pickle : attribute lookup
__main__.p fa
iled


I'm using python 2.5 on win32.

any help appreciated.



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


Re: Help improve program for parsing simple rules

2009-04-17 Thread Paul McGuire
On Apr 17, 10:43 am, John Machin  wrote:
>
> I don't see how it can handle the chained relop in the last two
> testcases e. g. '0.00 LE A LE 4.00' -- unless relops are chained by
> default in your parser.
>

John -

First of all, to respect precedence of operations, higher level
precedences are parsed and grouped first.  If you left off the parse
actions and just printed out the parse tree created by the example
(using asList()), for "A + B * C" you would get ['A', '+', [ 'B', '*',
'C' ]].  If you expand that test case to "A + B * C + D", you would
get ['A', '+', [ 'B', '*', 'C' ], '+', 'D' ].  This is counter to the
conventional infix parser that would create [['A', '+', [ 'B', '*',
'C' ]], '+', 'D' ], in which binary operators typicaly return
'operand' 'operator' 'operand' triples, and either operand might be a
nested parse tree.

As it happens, when using pyparsing's operatorPrecedence helper, *all*
binary operators at the same precedence level are actually parsed in a
single chain.

This is why you see this logic in EvalAddOp.eval:

def eval(self):
sum = self.value[0].eval()
for op,val in operatorOperands(self.value[1:]):
if op == '+':
sum += val.eval()
if op == '-':
sum -= val.eval()
return sum

operatorOperands is a little generator that returns operator-operand
pairs, beginning at the second (that is, the "1th") token in the
list.  You can't just do the simple evaluation of "operand1 operator
operand2", you have to build up the sum by first evaluating operand1,
and then iterating over the operator-operand pairs in the rest of the
list.  Same thing for the muliplication operators.

For the comparison operators, things are a little more involved.
"operand1 operator1 operand2 operator2 operand3" (as in "0.00 LE A LE
4.00") has to evaluate as

op1 operator1 op2 AND op2 operator2 op3

So EvalComparisonOp's eval method looks like:

def eval(self):
val1 = self.value[0].eval()
ret = True
for op,val in operatorOperands(self.value[1:]):
fn = EvalComparisonOp.opMap[op]
val2 = val.eval()
ret = ret and fn(val1,val2)
val1 = val2
return ret

The first term is evaluated and stored in val1.  Then each
comparisonop-operand pair is extracted, the operand is eval()'ed and
stored in val2, and the comparison method that is mapped to the
comparisonop is called using val1 and val2.  Then, to move on to do
the next comparison, val2 is stored into val1, and the we iterate to
the next comparison-operand pair.  In fact, not only does this handle
"0.00 LE A LE 4.00", but it could also evaluate "0.00 LE A LE 4.00 LE
E > D".  (I see that I should actually do some short-circuiting here -
if ret is false after calling fn(val1,val2), I should just break out
at that point.  I'll have that fixed in the online version shortly.)

-- Paul

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


unpythonic use of property()?

2009-04-17 Thread J Kenneth King

Consider:

code:


class MyInterface(object):

def __get_id(self):
return self.__id

id = property(fget=__get_id)

def __init__(self, id, foo):
self.__id = id
self.foo = foo


class MyInterface2(object):

def __init__(self, id, foo):
self._id = id
self.foo = foo

@property
def id(self):
return self._id



The situation is that an API to an external resource must enforce
consistency with the resource's expectations of data (ie: ID's must be
immutable).

The Python docs clearly show the use of the property() decorator in both
the example classes shown here. Both ensure that an assignment to the
class objects' 'id' attribute will raise an AttributeError
exception. Both will satisfy the requirements.

I assume we all know what the implementation differences are between the
two examples here. What I am curious about is what use case would the
MyInterface example have? My guess is that it's added protection for
attribute names on objects generated from factories or generators. I'd
like a more concrete explanation from someone who has encountered a
scenario where it was required.

I was recently informed that it was 'unpythonic' and have since been a
little confused by the term. I've heard it bandied about before but
never paid much attention. What is 'unpythonic'? What about this example
is unpythonic?
--
http://mail.python.org/mailman/listinfo/python-list


Re: QT , Wxwidgets are not just UI framework ?

2009-04-17 Thread Phil Thompson
On Fri, 17 Apr 2009 07:04:40 -0700 (PDT), Deep_Feelings
 wrote:
> On Apr 17, 1:52 pm, "Diez B. Roggisch"  wrote:
>> Deep_Feelings wrote:
>> > qt include many libraries : network , threading,database ..etc while
>> > Wxwidgets seem similar but with less scope
>>
>> > my question is : does these frameworks replace python's (or any other
>> > language for that matter) built-in libraries ? or python does not
>> > include that sort of libraries ?
>>
>> Some it includes, others it doesn't. And they come with different
>> features.
>>
>> While python comes with a lot of included batteries, for some things you
>> need a more powerful generator - that's where 3rd-party-libraries come
>> into
>> play.
>>
>> There are plenty of discussions about which GUI-toolkit is the best -
>> google
>> this group.
>>
>> However, mostly people agree that Qt is the most powerful, but often was
>> debunked because of it's licensing. This has changed to the much more
>> liberal LGPL for Qt4.5.
>>
>> Now it might be though that you'd still need to buy a license from Phil
>> Thompson for his excellent PyQt-wrapping - but I'd personally say it's
>> more
>> worth than it actually costs given the power of Qt.
>>
>> Diez
> 
> thank you
> 
> considering that wxwidget is open source and free do you think that QT
> lisencing is worth it ?

wxWidgets, Qt and PyQt are all open source and free - just not the same
open source license.

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


Re: cPickle and subclassing lists?

2009-04-17 Thread Peter Otten
Reckoner wrote:

> I have a large class that is a child of list. I need to pickle it, but
> it's not working. For example, I have reduced it to the following:
> 
> class Mylist(list):
> def __init__(self,x=[]):
> list.__init__(self,x)
> 
> and I cannot even get this to pickle right.
> 
>>> w=Mylist([1,2,3])
>>> dumps(w)
> 
> PicklingError: Can't pickle : attribute lookup
> __main__.p fa
> iled
> 
> 
> I'm using python 2.5 on win32.
> 
> any help appreciated.

This error occurs when you try to pickle a class that cannot be found by its
name:

>>> from cPickle import dumps
>>> class p: pass
...
>>> a = p
>>> del p
>>> dumps(a)
Traceback (most recent call last):
  File "", line 1, in 
cPickle.PicklingError: Can't pickle __main__.p: attribute lookup __main__.p
failed

I don't see how this error could be triggered by the code you give above.
Please try it again in a fresh interpreter.

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


Re: compiler package vs parser

2009-04-17 Thread Kay Schluehr
> I realize that I probably ought to be trying this out with the newer ast 
> stuff,
> but currently I am supporting code back to 2.3 and there's not much hope of
> doing it right there without using the compiler package.

You might consider using the *builtin* parser module and forget about
the compiler package if it is broken ( I take your word that it is )
or modern ast representations which aren't really necessary for Python
anyway.

>>> import parser
>>> tree = parser.suite("def foo():\n print 42}\n")
>>> code = tree.compile()
>>> exec code
>>> foo()
42

This is also not 100% reliable ( at least not for all statements in
all Python versions ) but it uses the internal parser/compiler and not
a standard library compiler package that might not be that well
maintained.
--
http://mail.python.org/mailman/listinfo/python-list


Re: cPickle and subclassing lists?

2009-04-17 Thread Reckoner
On Apr 17, 10:42 am, Peter Otten <[email protected]> wrote:
> Reckoner wrote:
> > I have a large class that is a child of list. I need to pickle it, but
> > it's not working. For example, I have reduced it to the following:
>
> > class Mylist(list):
> > def __init__(self,x=[]):
> > list.__init__(self,x)
>
> > and I cannot even get this to pickle right.
>
> >>> w=Mylist([1,2,3])
> >>> dumps(w)
>
> > PicklingError: Can't pickle : attribute lookup
> > __main__.p fa
> > iled
>
> > I'm using python 2.5 on win32.
>
> > any help appreciated.
>
> This error occurs when you try to pickle a class that cannot be found by its
> name:
>
> >>> from cPickle import dumps
> >>> class p: pass
> ...
> >>> a = p
> >>> del p
> >>> dumps(a)
>
> Traceback (most recent call last):
>   File "", line 1, in 
> cPickle.PicklingError: Can't pickle __main__.p: attribute lookup __main__.p
> failed
>
> I don't see how this error could be triggered by the code you give above.
> Please try it again in a fresh interpreter.
>
> Peter

sorry. here it is:

PicklingError: Can't pickle : attribute
lookup __main__.Mylist failed


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


Re: [Python-Dev] RELEASED Python 2.6.2

2009-04-17 Thread Russell Owen

On Apr 16, 2009, at 11:17 PM, Ronald Oussoren wrote:


On 16 Apr, 2009, at 20:58, Russell Owen wrote:

I installed the Mac binary on my Intel 10.5.6 system and it works,  
except it still uses Apple's system Tcl/Tk 8.4.7 instead of my  
ActiveState 8.4.19 (which is in /Library/Frameworks where one would  
expect).


That's very string. I had ActiveState 8.4 installed (whatever was  
current about a month ago).


I agree. (For what it's worth, you probably have Tcl/Tk 8.4.19 -- a  
version I've found to be very robust. 8.4.19 was released awhile ago  
and is probably the last version of 8.4 we will see, since all  
development is happening on 8.5 now).


Could you try a simple experiment (assuming you still have ActiveState  
Tcl/Tk installed): run python from the command line and enter these  
commands:

import Tkinter
root = Tkinter.Tk()

Then go to the application that comes up and select About Tcl/Tk...  
(in the Python menu) and see what version it reports. When I run with  
the Mac binary of 2.6.2 it reports 8.4.7 (Apple's built-in python).  
When I build python 2.6.2 from source it reports 8.4.19 (my  
ActiveState Tclc/Tk).


Just out of curiosity: which 3rd party Tcl/Tk did you have  
installed when you made the installer? Perhaps if it was 8.5 that  
would explain it. If so I may try updating my Tcl/Tk -- I've been  
wanting some of the bug fixes in 8.5 anyway.


Tcl 8.5 won't happen in 2.6, and might not happen in 2.7 either.   
Tkinter needs to work with the system version of Tcl, which is some  
version of 8.4,  Tkinter will not work when the major release of Tcl  
is different than during the compile. That makes it rather hard to  
support both 8.4 and 8.5 in the same installer.


Perfect. I agree.

-- Russell

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


Re: script question

2009-04-17 Thread python
Scott,

Newbie question (and I'm not the OP): What are your thoughts on having
your decorator add an attribute to the functions vs. placing the
functions in a global variable?

def _included(f):
f._included = True
return f

I tried experimenting with this technique, but could not find a way to
use dir() to discover all my functions with an _included attribute.

The following convoluted comprehension works to execute functions with
an _included attribute when a list of function names is available.

[ eval(x)() for x in [ 'func01', 'func02', 'func03' ] if getattr(
eval(x), '_included', False ) ]

However, I can't figure out a way to replace my list of hard-coded
function names with the output from the dir() command.

Thank you for your thoughts,

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


Re: cPickle and subclassing lists?

2009-04-17 Thread Peter Otten
Reckoner wrote:

> On Apr 17, 10:42 am, Peter Otten <[email protected]> wrote:
>> Reckoner wrote:
>> > I have a large class that is a child of list. I need to pickle it, but
>> > it's not working. For example, I have reduced it to the following:
>>
>> > class Mylist(list):
>> > def __init__(self,x=[]):
>> > list.__init__(self,x)
>>
>> > and I cannot even get this to pickle right.
>>
>> >>> w=Mylist([1,2,3])
>> >>> dumps(w)
>>
>> > PicklingError: Can't pickle : attribute lookup
>> > __main__.p fa
>> > iled
>>
>> > I'm using python 2.5 on win32.
>>
>> > any help appreciated.
>>
>> This error occurs when you try to pickle a class that cannot be found by
>> its name:
>>
>> >>> from cPickle import dumps
>> >>> class p: pass
>> ...
>> >>> a = p
>> >>> del p
>> >>> dumps(a)
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> cPickle.PicklingError: Can't pickle __main__.p: attribute lookup
>> __main__.p failed
>>
>> I don't see how this error could be triggered by the code you give above.
>> Please try it again in a fresh interpreter.
>>
>> Peter
> 
> sorry. here it is:
> 
> PicklingError: Can't pickle : attribute
> lookup __main__.Mylist failed

Please post the complete script that provoked the error.
Does the error occur when you run it from the command line?

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


Re: cPickle and subclassing lists?

2009-04-17 Thread Piet van Oostrum
> Reckoner  (R) wrote:

>R> I have a large class that is a child of list. I need to pickle it, but
>R> it's not working. For example, I have reduced it to the following:

>R> class Mylist(list):
>R> def __init__(self,x=[]):
>R> list.__init__(self,x)

>R> and I cannot even get this to pickle right.

 w=Mylist([1,2,3])
 dumps(w)

>R> PicklingError: Can't pickle : attribute lookup
>R> __main__.p fa
>R> iled

Where does the 'p' come from?
What is w.__class__ ?

>R> I'm using python 2.5 on win32.

No problem with 2.6.2 on Mac OS X.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help improve program for parsing simple rules

2009-04-17 Thread Aaron Brady
On Apr 17, 7:37 am, [email protected] wrote:
> On Apr 16, 3:59 pm, Aaron Brady  wrote:
>
>
>
> > On Apr 16, 10:57 am, [email protected] wrote:
>
> > > Another interesting task for those that are looking for some
> > > interesting problem:
> > > I inherited some rule system that checks for programmers program
> > > outputs that to be ported: given some simple rules and the values it
> > > has to determine if the program is still working correctly and give
> > > the details of what the values are. If you have a better idea of how
> > > to do this kind of parsing please chime in. I am using tokenize but
> > > that might be more complex than it needs to be. This is what I have
> > > come up so far:
>
snip
> > > def main():
> > >     for cur_rule in rules[20:26]:
> > >         tokens=get_tokens(cur_rule)
> > >         normal=replace_comps(tokens,COMP_REPLACERS)
> > >         subst=replace_names(normal,vars_)
> > >         groups=split_seccions(subst,COMP_REPLACERS.values())
> > >         rep=all_seccions(groups)
> > >         rep_out=''.join(x[0]+x[1] for x in rep)
> > >         calc=calc_seccions(rep)
> > >         calc_out=''.join(x[0]+x[1] for x in calc)
> > >         deltas=calc_deltas(calc)
> > >         result=eval(calc_out,{},{})
>
> > snip
>
snip
> > >>> a= '-1000.00 < A < 0.00'
> > >>> eval( a, { 'A': -100 } )
snip
> > >>> a= '-1000.00 LE A LE 0.00'
> > >>> b= a.replace( ' LE ', ' <= ' )
snip
>
> I know about evals implication of safety. Rules are defined by the
> programmers so I don't worry too much about it at this point. They
> should know better than messing up their application server. Unless
> there is some easier way to do it I am willing to take the risk.
> Precedence is standard math, we can always add some extra parenthesis
> to the rules, I don't thing the old system would mind.
>
> I thought about using eval with a locals dictionary, but they want
> output of the intermediate values. I want to avoid the situation where
> the intermediate output does not match what eval is doing.

I take you to need the operands to the individual comparison
operators; that is, each side of each comparison.  There might be a
way using abstract syntax trees.  Or, a basic 're' split can simplify
it.

>>> import re
>>> a= '-1000.00 LE A LE 0.00'
>>> b= re.split( r'\s(LT|GT|LE|GE|=|<|>|<=|>=)\s', a )
>>> b
['-1000.00', 'LE', 'A', 'LE', '0.00']
>>> COMP_REPLACERS={'LT':'<', 'GT':'>', 'LE':'<=', 'GE':'>=', '=':'=='}
>>> c= [ COMP_REPLACERS.get( x, x ) for x in b ]
>>> c
['-1000.00', '<=', 'A', '<=', '0.00']
>>> vars_={'A': 0, 'B': 1.1, 'C': 2.2, 'D': 3.3, 'E': 4.4, 'F': 5.5, 'G':
... 6.6, 'H':7.7, 'I':8.8, 'J':9.9}
>>> d= [ str( vars_.get( x, x ) ) for x in c ]
>>> d
['-1000.00', '<=', '0', '<=', '0.00']
>>> eval( ''.join( d ) )
True

The 'dict.get( x, x )' expression returns the value of the entry for
x, or x itself if it is not present.

No promises.  I didn't think it all the way through.
--
http://mail.python.org/mailman/listinfo/python-list


Re: binary file compare...

2009-04-17 Thread Adam Olsen
On Apr 17, 5:30 am, Tim Wintle  wrote:
> On Thu, 2009-04-16 at 21:44 -0700, Adam Olsen wrote:
> > The Wayback Machine has 150 billion pages, so 2**37.  Google's index
> > is a bit larger at over a trillion pages, so 2**40.  A little closer
> > than I'd like, but that's still 56294995000 to 1 odds of having
> > *any* collisions between *any* of the files.  Step up to SHA-256 and
> > it becomes 1915619400 to
> > 1.  Sadly, I can't even give you the odds for SHA-512, Qalculate
> > considers that too close to infinite to display. :)
>
> That might be true as long as your data is completely uniformly
> distributed. For the example you give there's:
>
> a) a high chance that there's "" near the top
>
> b) a non-uniform distribution of individual words within the text.
>
> c) a non-unifom distribution of all n-grams within the text (as there is
> in natural language)
>
> So it's very far from uniformly distributed. Just about the only
> situation where I could imagine that holding would be where you are
> hashing uniformly random data for the sake of testing the hash.
>
> I believe the point being made is that comparing hash values is a
> probabilistic algorithm anyway, which is fine if you're ok with that,
> but for mission critical software it's crazy.

Actually, *cryptographic* hashes handle that just fine.  Even for
files with just a 1 bit change the output is totally different.  This
is known as the Avalanche Effect.  Otherwise they'd be vulnerable to
attacks.

Which isn't to say you couldn't *construct* a pattern that it would be
vulnerable to.  Figuring that out is pretty much the whole point of
attacking a cryptographic hash.  MD5 has significant vulnerabilities
by now, and other will in the future.  That's just a risk you need to
manage.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help improve program for parsing simple rules

2009-04-17 Thread Aaron Brady
On Apr 17, 12:15 pm, Paul McGuire  wrote:
> On Apr 17, 10:43 am, John Machin  wrote:
snip
> not only does this handle
> "0.00 LE A LE 4.00", but it could also evaluate "0.00 LE A LE 4.00 LE
> E > D".  (I see that I should actually do some short-circuiting here -
> if ret is false after calling fn(val1,val2), I should just break out
> at that point.  I'll have that fixed in the online version shortly.)

Hi, not to offend; I don't know your background.  One thing I like
about Python is it and the docs are careful about short-circuiting
conditions.  ISTR that C left some of those details up to the compiler
at one point.

>>> def f():
... print( 'in f' )
... return 10
...
>>> 0>> 0http://mail.python.org/mailman/listinfo/python-list


can't install new modules after updating python

2009-04-17 Thread lie
I've updated from python 2.5 to 2.6 on my Slackware 12.2, by compiling
the 2.6 source. When I try to use slapt-get to install a new module
for python, it installs in the old version, and I can't use it. How
can I fix this? Should I go back to 2.5?
--
http://mail.python.org/mailman/listinfo/python-list


Re: binary file compare...

2009-04-17 Thread Adam Olsen
On Apr 17, 9:59 am, norseman  wrote:
> The more complicated the math the harder it is to keep a higher form of
> math from checking (or improperly displacing) a lower one.  Which, of
> course, breaks the rules.  Commonly called improper thinking. A number
> of math teasers make use of that.

Of course, designing a hash is hard.  That's why the *recommended*
ones get so many years of peer review and attempted attacks first.

I'd love of Nigel provided evidence that MD5 was broken, I really
would.  It'd be quite interesting to investigate, assuming malicious
content can be ruled out.  Of course even he doesn't think that.  He
claims that his 42 trillion trillion to 1 odds happened not just once,
but multiple times.
--
http://mail.python.org/mailman/listinfo/python-list


ANN: ConfigObj 4.6.0 and Validate 1.0.0 released

2009-04-17 Thread Fuzzyman
Finally a fresh release ConfigObj and Validate.

* ConfigObj Home page: http://www.voidspace.org.uk/python/configobj.html
* Validate Home page: http://www.voidspace.org.uk/python/validate.html

**ConfigObj** is a simple to use but powerful Python library for the
reading and writing of configuration (ini) files. Through **Validate**
it integrates a config file validation and type conversion system.

Features of ConfigObj include:

* Nested sections (subsections), to any level
* List values
* Multiple line values
* Full Unicode support
* String interpolation (substitution)
* Integrated with a powerful validation system

- including automatic type checking/conversion
- and allowing default values
- repeated sections

* All comments in the file are preserved
* The order of keys/sections is preserved
* Powerful ``unrepr`` mode for storing/retrieving Python data-types

Release 4.6.0 fixes bugs and adds new features, particularly making
configspec handling more flexible.

Full details on the changes can be found at:
http://www.voidspace.org.uk/python/weblog/arch_d7_2009_04_11.shtml#e1078

The changelog for ConfigObj 4.6.0 is:

* Pickling of ConfigObj instances now supported (thanks to Christian
Heimes)
* Hashes in confgspecs are now allowed (see note below)
* Replaced use of hasattr (which can swallow exceptions) with getattr
* ``__many__`` in configspecs can refer to scalars (ordinary values)
as well as sections
* You can use ``___many___`` (three underscores!) where you want to
use ``__many__`` as well
* You can now have normal sections inside configspec sections that use
``__many__``
* You can now create an empty ConfigObj with a configspec,
programmatically set values and then validate
* A section that was supplied as a value (or vice-versa) in the actual
config file would cause an exception during validation (the config
file is still broken of course, but it is now handled gracefully)
* Added ``as_list`` method
* Removed the deprecated ``istrue``, ``encode`` and ``decode`` methods
* Running test_configobj.py now also runs the doctests in the
configobj module
* Through the use of validate 1.0.0 ConfigObj can now validate multi-
line values

As the public API for Validate is stable, and there are no outstanding
issues or feature requests, I've bumped the version number to 1.0.0.
The full change log is:

* BUGFIX: can now handle multiline strings
* Addition of 'force_list' validation option
--
http://mail.python.org/mailman/listinfo/python-list


Re: binary file compare...

2009-04-17 Thread Adam Olsen
On Apr 17, 9:59 am, SpreadTooThin  wrote:
> You know this is just insane.  I'd be satisfied with a CRC16 or
> something in the situation i'm in.
> I have two large files, one local and one remote.  Transferring every
> byte across the internet to be sure that the two files are identical
> is just not feasible.  If two servers one on one side and the other on
> the other side both calculate the CRCs and transmit the CRCs for
> comparison I'm happy.

Definitely use a hash, ignore Nigel.  SHA-256 or SHA-512.  Or, if you
might need to update one of the files, look at rsync.  Rsync still
uses MD4 and MD5 (optionally!), but they're fine in a trusted
environment.
--
http://mail.python.org/mailman/listinfo/python-list


Re: need to start a new project , can python do all that ?

2009-04-17 Thread Hyuga
On Apr 15, 10:54 am, Deep_Feelings  wrote:
> On Apr 15, 4:05 pm, Tim Rowe  wrote:
>
>
>
> > 2009/4/15 Deep_Feelings :
>
> > > I want to start programming a new program (electronic health care
> > > center) in python and before start learning python i wanna make sure
> > > that python does have all the features i need to accomplish this
> > > project so i wanna ask you does python able to support these
> > > features :
>
> > > 1- cross platform (windows + linux)
> > > 2- mysql database access
> > > 3- 2D graphs (curves)
> > > 4- support of international languages
> > > 5- can access a scanner and input pictures from it.
>
> > > and possibly be able to import data from labratory machines (such as
> > > CBC machines) to automatically register patient investigations result
> > > into the system (not mandatory)
>
> > What are the safety and security requirements? If you're handling
> > patient investigation results then there are certainly security issues
> > because of patient confidentiality, and there may be safety issues
> > (could a software fault contribute to a patient receiving incorrect
> > treatment, or failing to receive necessary treatment?)
>
> > You almost certainly need to contact the appropriate regulatory
> > authority to check whether they have any requirements for languages in
> > such applications (and for specific development processes), or you
> > could find yourself either with an application you can't use or a very
> > big lawsuit and possibly jail if it goes wrong.
>

> thank you so much ,rest assured that the code will me tested very well
> (in real world situation) before using it.

I'm not too assured... What are the actual requirements for this
software?  Is this intended for real world use in health care?  I'm
not too comfortable with a single individual with apparently limited
experience in Python developing something like that.  Not that it's
any of my business...or for all I know it may be!  You might as well
have started this post "I want to start programming a new program (air
traffic control system) in python and before start learning python..."
--
http://mail.python.org/mailman/listinfo/python-list


question about xrange performance

2009-04-17 Thread _wolf
lately i realized a slow running portion of my application, and a
quick profiling nourished the suspicion that, of all things, calls to
`xrange().__contains__` (`x in b` where `b = xrange(L,H)`) is the
culprit. to avoid any other influences, i wrote this test script with
class `xxrange` being a poor man’s `xrange` replacement:



class xxrange( object ):
  def __init__( self, start, stop ):
self.start  = start
self.stop   = stop
  def __contains__( self, x ):
return ( x == int( x ) ) and self.start <= x < self.stop

import cProfile
from random import randint
test_integers = [ randint 0, 5000 ) for i in xrange( 8000 ) ]
test_range_a  = xxrange( 1, 2 )
test_range_b  = xrange(  1, 2 )

def a():
  print test_range_a.__class__.__name__
  for x in test_integers:
x in test_range_a

def b():
  print test_range_b.__class__.__name__
  for x in test_integers:
x in test_range_b

cProfile.run('a()')
cProfile.run('b()')


now this is the output, surprise:


xxrange
 8003 function calls in 0.026 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno
(function)
10.0000.0000.0260.026 :1()
10.0120.0120.0260.026 xrange-profiler.py:18(a)
 80000.0140.0000.0140.000 xrange-profiler.py:9
(__contains__)
10.0000.0000.0000.000 {method 'disable' of
'_lsprof.Profiler' objects}


xrange
 3 function calls in 4.675 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno
(function)
10.0000.0004.6754.675 :1()
14.6754.6754.6754.675 xrange-profiler.py:23(b)
10.0000.0000.0000.000 {method 'disable' of
'_lsprof.Profiler' objects}


can it be that a simple diy-class outperforms a python built-in by a
factor of 180? is there something i have done the wrong way?
omissions, oversights? do other people get similar figures?

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


Re: Lambda alternative?

2009-04-17 Thread J. Cliff Dyer
On Thu, 2009-04-16 at 13:33 +0200, Hrvoje Niksic wrote:
> mousemeat  writes:
> 
> > Correct me if i am wrong, but i can pickle an object that contains a
> > bound method (it's own bound method).
> 
> No, you can't:
> 
> >>> import cPickle as p
> >>> p.dumps([])
> '(l.'
> >>> p.dumps([].append)
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: expected string or Unicode object, NoneType found

Yes he can.  mousemeat stated that he could pickle an object that
*contains* a bound method, not that he could pickle the method itself.

That said, you can make an instance method out of a lambda, just as well
as any named function, and you can pickle that object, too:

Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cPickle as p
>>> class Foo(object):
... a = lambda self, x: x+1
>>> foo.a(1)
2
>>> type(foo.a)

>>> p.dumps(foo)
'ccopy_reg\n_reconstructor\np1\n(c__main__\nFoo\np2\nc__builtin__
\nobject\np3\nNtRp4\n.'

Cheers,
Cliff


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


Re: [OT] large db question about no joins

2009-04-17 Thread J. Cliff Dyer
On Thu, 2009-04-16 at 14:11 -0700, John Fabiani wrote:
> Daniel Fetchinson wrote:
> 
> > Hi folks, I've come across many times the claim that 'joins are bad'
> > for large databases because they don't scale
> 
> IMO that's bull...

OK.  That makes four legs so far

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

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


Re: question about xrange performance

2009-04-17 Thread MRAB

_wolf wrote:

lately i realized a slow running portion of my application, and a
quick profiling nourished the suspicion that, of all things, calls to
`xrange().__contains__` (`x in b` where `b = xrange(L,H)`) is the
culprit. to avoid any other influences, i wrote this test script with
class `xxrange` being a poor man’s `xrange` replacement:



class xxrange( object ):
  def __init__( self, start, stop ):
self.start  = start
self.stop   = stop
  def __contains__( self, x ):
return ( x == int( x ) ) and self.start <= x < self.stop

import cProfile
from random import randint
test_integers = [ randint 0, 5000 ) for i in xrange( 8000 ) ]
test_range_a  = xxrange( 1, 2 )
test_range_b  = xrange(  1, 2 )

def a():
  print test_range_a.__class__.__name__
  for x in test_integers:
x in test_range_a

def b():
  print test_range_b.__class__.__name__
  for x in test_integers:
x in test_range_b

cProfile.run('a()')
cProfile.run('b()')


now this is the output, surprise:


xxrange
 8003 function calls in 0.026 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno
(function)
10.0000.0000.0260.026 :1()
10.0120.0120.0260.026 xrange-profiler.py:18(a)
 80000.0140.0000.0140.000 xrange-profiler.py:9
(__contains__)
10.0000.0000.0000.000 {method 'disable' of
'_lsprof.Profiler' objects}


xrange
 3 function calls in 4.675 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno
(function)
10.0000.0004.6754.675 :1()
14.6754.6754.6754.675 xrange-profiler.py:23(b)
10.0000.0000.0000.000 {method 'disable' of
'_lsprof.Profiler' objects}


can it be that a simple diy-class outperforms a python built-in by a
factor of 180? is there something i have done the wrong way?
omissions, oversights? do other people get similar figures?


xrange() returns an xrange object, which generates its values on demand.
It doesn't have a __contains__ method, so 'in' uses its iterator, making
the xrange object yield each value until either the desired value is
produced or there are no more values.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda alternative?

2009-04-17 Thread Aaron Brady
On Apr 17, 1:43 pm, "J. Cliff Dyer"  wrote:
> On Thu, 2009-04-16 at 13:33 +0200, Hrvoje Niksic wrote:
> > mousemeat  writes:
>
> > > Correct me if i am wrong, but i can pickle an object that contains a
> > > bound method (it's own bound method).
>
> > No, you can't:
>
> > >>> import cPickle as p
> > >>> p.dumps([])
> > '(l.'
> > >>> p.dumps([].append)
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > TypeError: expected string or Unicode object, NoneType found
>
> Yes he can.  mousemeat stated that he could pickle an object that
> *contains* a bound method, not that he could pickle the method itself.
>
> That said, you can make an instance method out of a lambda, just as well
> as any named function, and you can pickle that object, too:
snip

'Contains' here is ambiguous.  If the object contains a bound method,
that is, if a bound method is in its dictionary, you can't.

>>> import pickle as p
>>> class A: pass
...
>>> a= A()
>>> class A:
... def f( self ): print( 'f' )
...
>>> a= A()
>>> class B: pass
...
>>> b= B()
>>> b.f= a.f
>>> b.f()
f
>>> p.dumps( b )
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Programs\Python30\lib\pickle.py", line 1329, in dumps
Pickler(f, protocol).dump(obj)
_pickle.PicklingError: Can't pickle : attribute
lookup
builtins.method failed

In this example, 'b' contains a bound method, 'a.f'.  However, for
other definitions of 'contains', such as if 'b' is an instance of a
class that contains methods, you can.  But in that case, the method is
not in 'b.__dict__'.

>>> b.__dict__
{'f': >}

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


Re: Help improve program for parsing simple rules

2009-04-17 Thread Paul McGuire
On Apr 17, 1:26 pm, Aaron Brady  wrote:
> Hi, not to offend; I don't know your background.  

Courtesy on Usenet!!!  I'm going to go buy a lottery ticket!

Not to worry, I'm a big boy.  People have even called my baby ugly,
and I manage to keep my blood pressure under control.

> One thing I like
> about Python is it and the docs are careful about short-circuiting
> conditions.  ISTR that C left some of those details up to the compiler
> at one point.
>
> >>> def f():
>
> ...     print( 'in f' )
> ...     return 10
> ...>>> 0
> in f
> True>>> 0
> in f
> in f
> True
>
> Therefore, if op{n} has side effects, 'op1 operator1 op2 AND op2
> operator2 op3' is not equivalent to 'op1 optor1 op2 optor2 op3'.

Interesting point, but I don't remember that "A < B < C" is valid C
syntax, are you perhaps thinking of a different language?

By luck, my implementation of EvalComparisonOp.eval does in fact
capture the post-eval value of op2, so that if its evaluation caused
any side effects, they would not be repeated.

-- Paul

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


  1   2   >