Simple hack to get $500 to your home.

2010-07-13 Thread easy money
Simple hack to get $500 to your home at http://cashbygetpaypal.tk

Due to high security risks,i have hidden the cheque link in an
image.  in that website on top side above search box, click on image
and enter your name and address where you want to receive your
cheque. please don,t tell to anyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C interpreter in Lisp/scheme/python

2010-07-13 Thread Paul Rubin
bolega  writes:
> I am trying to compare LISP/Scheme/Python for their expressiveness...
> Are there already answers anywhere ?
> How would a gury approach such a project ?

These two articles

http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprt_computer2000.pdf 
http://www.haskell.org/papers/NSWC/jfp.ps 

about language comparisons (Python is in the first but not the second)
might be of interest.

If you want to know how to implement C, there is a pretty good book by
Hanson and Fraser about LCC, called "A Retargetable C Compiler".
Basically a code walkthrough of a small C compiler written in C.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python track at German Zope conference

2010-07-13 Thread Martin v. Loewis
[Das ist im Wesentlichen eine Kopie einer Nachricht, die Dinu an
 die Python-DE-Liste geschickt hat.]

>From September 15 to September 17, 2010, the German Zope conference
(organized by DZUG) takes place in Dresden. It has tracks for Python,
Zope, and Plone. Dinu Gherman and me are organizing the Python
Track, and we are still looking for people interested in presenting
Python related projects or topics. If so, please let us know,
or submit your talk proposal to the conference site.

Also, if you would like to come to the conference if a certain topic was
presented, please let us know.

You'll find more information on the conference at

http://www.zope.de/tagung/Dresden_2010/call-for-papers

Notice that there will be tutorials before the regular tracks, and
sprints afterwards.

Regards,
Martin

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


Re: C interpreter in Lisp/scheme/python

2010-07-13 Thread geremy condra
On Tue, Jul 13, 2010 at 11:01 PM, bolega  wrote:
> On Jun 20, 9:31 pm, Richard Fateman  wrote:
>> Define Macro wrote:
>> > On Jun 13, 7:07 pm, bolega  wrote:
>> >> I am trying to compare LISP/Scheme/Python for their expressiveness.
>>
>> >> For this, I propose a vanilla C interpreter. I have seen a book which
>> >> writes C interpreter in C.
>>
>> >> The criteria would be the small size and high readability of the code.
>>
>> >> Are there already answers anywhere ?
>>
>> Sure.  Lots of texts on compilers provide exercises which, in one way or
>> another suggest how to write an interpreter and perhaps a compiler too
>> for some language.  Anyone taking a course on compilers is likely to
>> have followed such exercises in order to pass the course.  Some
>> instructors are enlightened enough to allow students to pick the
>> implementation language.
>>
>> Ask any such instructor.
>
>
>
> Beware, he does not tell the readers the financial details. This is
> what he wrote to me by email.
>
> 
> I would be willing to meet with you here in Berkeley to educate you on
> these matters at a consulting rate of  $850 per hour, with a minimum
> of 8 hours.
>
> RJF
> 

He's Berkeley's former CS chair and was implementing lisp before
common lisp was a twinkle in anybody's eye. His time is valuable.

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


Re: C interpreter in Lisp/scheme/python

2010-07-13 Thread bolega
On Jun 20, 9:31 pm, Richard Fateman  wrote:
> Define Macro wrote:
> > On Jun 13, 7:07 pm, bolega  wrote:
> >> I am trying to compare LISP/Scheme/Python for their expressiveness.
>
> >> For this, I propose a vanilla C interpreter. I have seen a book which
> >> writes C interpreter in C.
>
> >> The criteria would be the small size and high readability of the code.
>
> >> Are there already answers anywhere ?
>
> Sure.  Lots of texts on compilers provide exercises which, in one way or
> another suggest how to write an interpreter and perhaps a compiler too
> for some language.  Anyone taking a course on compilers is likely to
> have followed such exercises in order to pass the course.  Some
> instructors are enlightened enough to allow students to pick the
> implementation language.
>
> Ask any such instructor.



Beware, he does not tell the readers the financial details. This is
what he wrote to me by email.


I would be willing to meet with you here in Berkeley to educate you on
these matters at a consulting rate of  $850 per hour, with a minimum
of 8 hours.

RJF




> I think you will find that many people use a packaged parser-generator
> which eliminates much of the choice-of-language difference. Do you like
> Bison, Yacc, Antlr, or one of the many parser generators in Lisp,
> python, etc.
>
> My own experience is that in comparing Lisp to C, students end up with
> smaller and better interpreters and compilers, faster.  I don't know
> about python vs C for sure, but I suspect python wins.  As for
> python vs Lisp, I don't know.
>
> RJF

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


Re: python namespace question

2010-07-13 Thread alex23
chad  wrote:
> I could care less about the extra blank line. I guess I was just more
> concerned about the namespace question.

Which is why Steven spent far more time answering that question than
commenting on newline handling.

Now say 'thank you'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: floatref

2010-07-13 Thread Steven D'Aprano
On Wed, 14 Jul 2010 06:50:58 +0200, Alf P. Steinbach /Usenet wrote:

> Possibly you have a point here.

Oh yeah? Don't think you can escape a flame war by agreeing with me!

*wink*



-- 
Steven

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


Re: floatref

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

* Steven D'Aprano, on 14.07.2010 06:31:


Gary did the right thing by pointing out that the simple-sounding term
"points to" is anything but simple, it depends on what you mean by
pointing and pointers.


Possibly you have a point here.


Cheers,

- Alf

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


Re: floatref

2010-07-13 Thread Steven D'Aprano
On Wed, 14 Jul 2010 03:19:36 +0200, Alf P. Steinbach /Usenet wrote:

> Gary Herron wrote:
>> Python does not have pointers, so if I take your wording"y.var and
>> x.var to point to the same value" literally, then the answer is NO
>> Python does not do that.
> 
> This is just a terminological issue. 

"Just"?

If people can't agree on terminology, they can't even understand each 
other, let alone communicate effectively. If I call you a fine fellow 
with a detailed grasp of programming and a helpful manner, but what I 
mean by "fine", "detailed" and "helpful" are different from what you mean 
by them, how can you tell if I've just complimented you or insulted you?

Gary did the right thing by pointing out that the simple-sounding term 
"points to" is anything but simple, it depends on what you mean by 
pointing and pointers.


> Saying "Python does not have
> pointers" is highly misleading in response to the OP's statement. It's
> easy enough to understand what he means. E.g., in the Java language
> specification "pointer" has a suitable meaning. 

And in a Java language forum, that would arguably be the right meaning to 
assume. Possibly even in a Jython forum. But this is neither, it's a 
Python forum, where "Python" is typically understood to be CPython, not 
Jython and certainly not Java, and "pointer" is typically understood to 
mean C or Pascal pointers.

In an English language forum, the correct meaning to use for "cafeteria" 
is a "dining hall", and not "fringe benefit" as it would be in a 
Hungarian forum. Likewise, the correct meaning to use for the word "gift" 
in an English forum is a present or object which is given, and not 
"poison" as a German might assume.


[...]
> You can't represent or usefully think of a C++ member pointer
> as a C or Pascal pointer. It isn't useful on its own. So, considering
> C++ and Java, the general pointer notion is something that refers,
> however obliquely. 

So an integer like 3 counts as a pointer, as you can use it as an index 
into a list, array or other sequence. In that sense, yes, Python has 
pointers, and makes frequent use of them. You can even do pointer 
arithmetic!

I don't think this position is terribly useful. It's possible to be *too* 
generic.


> You chose a specific meaning of "pointer" where the
> OP's statement does not make sense, but presumably the OP is explaining
> his needs in terms of a more general meaning of "pointer"; assuming
> anything else is silly.

The Zen of Python includes:

In the face of ambiguity, refuse the temptation to guess.

Wise words, not just for programming.




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


Re: python namespace question

2010-07-13 Thread Steven D'Aprano
On Tue, 13 Jul 2010 20:52:31 -0700, Chris Rebert wrote:

> The built-ins is the
> namespace of last resort; it's the last one to be consulted when trying
> to resolve a name in Python. You can inspect it via __builtins__

Avoid __builtins__ as it is an implementation detail. The difference 
between __builtins__ and __builtin__ is one of the more confusing corners 
of Python, but the correct one to use is __builtin__.


http://docs.python.org/library/__builtin__.html




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


Re: python namespace question

2010-07-13 Thread Chris Rebert
On Tue, Jul 13, 2010 at 8:03 PM, chad  wrote:
> Given the following code...
>
> #!/usr/bin/python
>
> class cgraph:
>    def printme(self):
>        print "hello\n"
>
> x = cgraph()
> x.printme()
>
>
> Does the function print() exist in the cgraph namespace or the
> printme() one?

Neither. It exists in the built-ins namespace along with the rest of
the built-in functions like len(), zip(), hex(), etc. The built-ins is
the namespace of last resort; it's the last one to be consulted when
trying to resolve a name in Python. You can inspect it via
__builtins__

Also, in your example, print is being used as a statement (i.e. part
of the language syntax), not a function; note the odd lack of
parentheses when "calling" it. print was changed to a regular function
in Python 3.x.

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


Re: python namespace question

2010-07-13 Thread chad
On Jul 13, 8:37 pm, Steven D'Aprano  wrote:
> On Tue, 13 Jul 2010 20:03:14 -0700, chad wrote:
> > Given the following code...
>
> > #!/usr/bin/python
>
> > class cgraph:
> >     def printme(self):
> >         print "hello\n"
>
> > x = cgraph()
> > x.printme()
>
> > Does the function print() exist in the cgraph namespace or the printme()
> > one?
>
> What function print()? You're calling the print STATEMENT. It doesn't
> exist in any namespace, it's a Python keyword like "if", "for", "return",
> and similar.
>
> Note: this changes in Python 3, where print becomes a function like
> len(), chr(), max(), and similar. In Python 3, you would write:
>
> print("hello\n")
>
> and the function lives in the built-in namespace.
>
> BTW, print (both versions) automatically prints a newline at the end of
> the output, so printing "hello\n" will end up with an extra blank line.
> Is that what you wanted?
>


I could care less about the extra blank line. I guess I was just more
concerned about the namespace question.

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


Re: python ldap recursive

2010-07-13 Thread Steven D'Aprano
On Tue, 13 Jul 2010 18:15:58 -0700, tekion wrote:

> Hi,
> I know perl Net::LDAP could do a recursive search call to LDAP.   What I
> am running into with Python LDAP on the search call is that I would l
> have to wait for the search to complete to get the result.  Where as
> with Perl recursive search call,  I would get the result (not the
> completed result) back while the search is still running.  Does any know
> if we have something like this in Python LDAP module?  Thanks.

What Python LDAP module are you using?



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


Re: death of newsgroups (Microsoft closing their newsgroups)

2010-07-13 Thread Steven D'Aprano
On Tue, 13 Jul 2010 23:24:12 -0400, Kenneth Tilton wrote:

> The moral? If you look for the spam, you'll find it.

And if you *don't* look for spam, you can be sure that some goose will 
reply to it and get it past your filters. Thanks for that Kenneth, if 
that is your name and you're not a Xah Lee sock-puppet.

Followups set to a black hole.


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


Re: python namespace question

2010-07-13 Thread Steven D'Aprano
On Tue, 13 Jul 2010 20:03:14 -0700, chad wrote:

> Given the following code...
> 
> #!/usr/bin/python
> 
> class cgraph:
> def printme(self):
> print "hello\n"
> 
> x = cgraph()
> x.printme()
> 
> 
> Does the function print() exist in the cgraph namespace or the printme()
> one?


What function print()? You're calling the print STATEMENT. It doesn't 
exist in any namespace, it's a Python keyword like "if", "for", "return", 
and similar.

Note: this changes in Python 3, where print becomes a function like
len(), chr(), max(), and similar. In Python 3, you would write:

print("hello\n")

and the function lives in the built-in namespace.

BTW, print (both versions) automatically prints a newline at the end of 
the output, so printing "hello\n" will end up with an extra blank line. 
Is that what you wanted?



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


Re: Check if a command is valid

2010-07-13 Thread Shashwat Anand
On Tue, Jul 13, 2010 at 6:59 AM, Kenny Meyer  wrote:

> Hello,
>
> I have to figure out if a string is callable on a Linux system. I'm
> actually doing this:
>
>def is_valid_command(command):
>retcode = 100 # initialize
>if command:
>retcode = subprocess.call(command, shell=True)
>if retcode is 0:
>print "Valid command."
>else:
>print "Looks not so good..."
>
>is_valid_command("ls")
>
> Never mind the code, because this is not the original.
> The side effect of subprocess.call() is that it *actually* executes
> it, but I just need the return code. What are better ways of doing
> this?
>

Check your $PATH. All your system commands lies there. Make a list and save
it. Now just check whether your 'command' lies in the list. However better
is to run the command, but some commands like 'shutdown' won't be good for
this I think.

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


Re: death of newsgroups (Microsoft closing their newsgroups)

2010-07-13 Thread Kenneth Tilton

Xah Lee wrote:

• Death of Newsgroups
  http://xahlee.org/UnixResource_dir/writ2/death_of_newsgroups.html

plain text version follows.

--
Death of Newsgroups

Xah Lee, 2010-07-13

Microsoft is closing down their newsgroups. See:
microsoft.public.windows.powershell.

I use comp.lang.lisp, comp.emacs since about 1999. Have been using
them pretty much on a weekly basis in the past 10 years. Starting
about 2007, the traffic has been increasingly filled with spam, and
the posters are always just the 20 or 30 known faces. I think perhaps
maybe no more than 100 different posters a year. Since this year or
last year, they are some 95% spam.


Forest. Trees. Please note order.

Case in point: twelve weeks ago His Timness mentioned this on 
comp.lang.lisp;


  http://www.math.union.edu/~dpvc/jsMath/

Now we have this, a port of a desktop app to the web:

  http://teamalgebra.com/

It happened fast because http://qooxdoo.org/lets me program the Web 
without bothering with HTML and CSS and browser variation as if I were 
using a framework like GTk.


I learned about qooxdoo... on comp.lang.lisp.

The moral? If you look for the spam, you'll find it.

kt

--
http://www.teamalgebra.com
"The best Algebra tutorial program I have seen... in a class by itself." 
Macworld

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


Re: python namespace question

2010-07-13 Thread Shashwat Anand
On Wed, Jul 14, 2010 at 8:33 AM, chad  wrote:

> Given the following code...
>
> #!/usr/bin/python
>
> class cgraph:
>def printme(self):
>print "hello\n"
>

No need to do print "hello\n", python is not C, print "hello" prints hello
with a newline. Try it on interpretor.


>
> x = cgraph()
> x.printme()
>
>
> Does the function print() exist in the cgraph namespace or the
> printme() one?
>

Where exactly is the print() function here. BTW printme() is in cgraph
namespace.

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


python namespace question

2010-07-13 Thread chad
Given the following code...

#!/usr/bin/python

class cgraph:
def printme(self):
print "hello\n"

x = cgraph()
x.printme()


Does the function print() exist in the cgraph namespace or the
printme() one?
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with executing python interpretetor on special build of win server 2003

2010-07-13 Thread Бажен Ржеутский
Hello. Actual problem in the next, when i trying to execute portable
python on my build then nothing happens, and the error code is 128.
What does mean this code 128?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nicer way to remove prefix of a string if it exists

2010-07-13 Thread Shashwat Anand
On Wed, Jul 14, 2010 at 5:42 AM, MRAB  wrote:

> News123 wrote:
>
>> I wondered about a potentially nicer way of removing a prefix of a
>> string if it exists.
>>
>>
>> Here what I tried so far:
>>
>>
>> def rm1(prefix,txt):
>>if txt.startswith(prefix):
>>return txt[len(prefix):]
>>return txt
>>
>>
>> for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]:
>># method 1 inline
>>prefix = "file://"
>>if f.startswith(prefix):
>>rslt = f[len(prefix):]
>>else
>>rsl = f
>># method 2 as function
>>rslt = rm1('file://',f)
>>
>>
>> Is there any nicer function than above rm1()?
>>
>
> No.
>
>
>  Is there any nicer inline statement rhan my method 1' ?
>>
>>  You could write:
>
>rsl = f[len(prefix):] if f.startswith(prefix) else f
>

Or you can just do split and join, "".join(f.split(prefix, 1)) will do.

>>> prefix = 'file://'
>>> f = 'file:///home/me/data.txt'
>>> "".join(f.split(prefix, 1))
'/home/me/data.txt'
>>> f = 'file:///home/me/data.txtfile://'
>>> "".join(f.split(prefix, 1))
'/home/me/data.txtfile://'
>>> f = '/home/me/data.txt'
>>> "".join(f.split(prefix, 1))
'/home/me/data.txt'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: floatref

2010-07-13 Thread Steven D'Aprano
On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote:

> Hi all,
> 
> I have two objects that should both be able to alter a shared float. So
> i need something like a mutable float object, or a float reference
> object. Does anybody know if something like that exists? I know it's not
> hard to build, but I have a feeling that there should be a standard
> solution to it.


One standard solution would be to wrap the float in a class as an 
attribute. Another is to put it in a list:

myvalue = [3.1415]
pi = myvalue
myvalue[0] = 3.0
assert pi[0] == 3.0

A third standard solution is to create a mutable float using delegation. 
See the MutableStr class in the standard library for hints.


An even better solution is to avoid the idiom of shared state in the 
first place. Whenever people say "I need shared data", the chances are 
very good that they don't *need* it at all, but merely *want* it because 
that's the idiom they're used to.

But if you really need it, you can make it.



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


Re: floatref

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

* Gary Herron, on 14.07.2010 01:26:

On 07/13/2010 03:02 PM, Roald de Vries wrote:

Hi Gary,

On Jul 13, 2010, at 8:54 PM, Gary Herron wrote:

On 07/13/2010 10:26 AM, Roald de Vries wrote:

Hi all,

I have two objects that should both be able to alter a shared float.
So i need something like a mutable float object, or a float reference
object. Does anybody know if something like that exists? I know it's
not hard to build, but I have a feeling that there should be a
standard solution to it.

Roald


Huh? I must be missing something here. Isn't this what you use a
variable for:


Maybe I didn't explain well:

>>> shared_var = 1.0
>>> x.var = shared_var
>>> y.var = shared_var
>>> x.var = 2.0
>>> y.var
1.0

I wanted y.var and x.var to point to the same value, so that always
x.var == y.var. So that the last line becomes:

>>> y.var
2.0

Cheers, Roald


Please keep responses and further discussions on
list.python-l...@python.org
instead of using private emails.


Seconded. I didn't see that posting.



Python does not have pointers, so if I take your wording"y.var and x.var
to point to the same value" literally, then the answer is NO Python does
not do that.


This is just a terminological issue. Saying "Python does not have pointers" is 
highly misleading in response to the OP's statement. It's easy enough to 
understand what he means. E.g., in the Java language specification "pointer" has 
a suitable meaning. And in general, the term "pointer" encompasses far more than 
the concept of a C or Pascal pointer, e.g., in C++ it includes offset-like 
things called member pointers. You can't represent or usefully think of a C++ 
member pointer as a C or Pascal pointer. It isn't useful on its own. So, 
considering C++ and Java, the general pointer notion is something that refers, 
however obliquely. You chose a specific meaning of "pointer" where the OP's 
statement does not make sense, but presumably the OP is explaining his needs in 
terms of a more general meaning of "pointer"; assuming anything else is silly.




However, Python does have references all over the place, so you can
achieve something similar in many ways.

If x and y in your example code are instances of a class, than look into
using a property for x.var and y.var. A property is a thing that looks
like an attribute, (that would be var in x.var and y.var), but which
really executes getter/setter code when accessed. That getter/setter
code would then access/set the value in shared_var:


shared_var = 123

class Thing(object):
def get_var(self):
return shared_var
def set_var(self, v):
global shared_var
shared_var = v

var = property(get_var, set_var)


x = Thing()
y = Thing()

print x.var, y.var # prints: 123 123
x.var = 99
print x.var, y.var # prints: 99 99


This code goes through hoops to /hide/ the fact of the sharing.

Rather, I'd make that as explicit as possible.

Like,

  x = {"sharedVar": 123}
  y = x

The one won't be surprised when changing x["sharedVar"] also changes 
y["sharedVar"].


Cheers & hth.,

- Alf


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


python ldap recursive

2010-07-13 Thread tekion
Hi,
I know perl Net::LDAP could do a recursive search call to LDAP.   What
I am running into with Python LDAP on the search call is that I would
l have to wait for the search to complete to get the result.  Where as
with Perl recursive search call,  I would get the result (not the
completed result) back while the search is still running.  Does any
know if we have something like this in Python LDAP module?  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't python's list append() method return the list itself?

2010-07-13 Thread Aahz
[Original not available on my swerver, responding here]

>On 7/11/10 10:03 PM, Nathan Rice wrote:
>>
>> Yeah, I long ago filed the in place place in the same folder as
>> strings-as-sequences, all() returning True for an empty iterable and any
>> returning True rather than the thing which triggered it.

Because I love to repeat myself:

"...string iteration isn't about treating strings as sequences of strings,
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters
are strings for other good reasons."  --Aahz
http://mail.python.org/pipermail/python-3000/2006-April/000897.html

Do you really want to give up Python's lovely string-slicing
capabilities?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Normal is what cuts off your sixth finger and your tail..."  --Siobhan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errno 9] Bad file descriptor

2010-07-13 Thread Cameron Simpson
On 13Jul2010 05:56, joblack  wrote:
| Thanks for the answers so far. It's not my code I'm just curious how
| that could happen:
| 
| Starting point:
| ...
| self.status['text'] = 'Processing ...'
| try:
| cli_main(argv)
| except Exception, e:
| self.status['text'] = 'Error: ' + str(e)
| return
| ...
| cli_main:
| 
| keypath, inpath, outpath = argv[1:]
| ...
| with open(inpath, 'rb') as inf:
| serializer = PDFSerializer(inf, keypath)
| with open(outpath, 'wb') as outf:
| filenr = outf.fileno()
| serializer.dump(outf)
| return 0
| 
| PDFSerializer.dump:
| 
| def dump(self, outf):
| self.outf = outf
| ...


See that you set serializer.outf to the outf you open in cli_main?
Any attempt to use serializer _after_ exiting the "with open(outpath,
'wb') as outf" will use serializer.outf, but the outf is now closed.
And thus its file descriptor is invalid.

BTW, by catching Exception in the starting point code you prevent
yourself seeing exactly which line throws the error. It is usualy a bad
idea to catch broad things like "Exception". It is normally better to
place try/except around very small pieces of code and to catch very
specific things. That way you know exactly what's going wrong and don't
quietly catch all sorts of unplanned stuff.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

When buying and selling are controlled by legislation, the first things
bought and sold are the legislators. - P.J. O'Rourke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How is Unladen Swallow coming along?

2010-07-13 Thread Dan Stromberg
2010/7/8 Luis M. González 

> On Jul 8, 1:42 pm, John Nagle  wrote:
> > How is Unladen Swallow coming along?  Looking at the site, code is
> > being checked in and issues are being reported, but the last quarterly
> > release was 2009 Q3.  They missed their January 2010 release date
> > for "2009 Q4", so they're now about 6 months behind their project
> > plan.
> >
> > ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan";)
> >
> > John Nagle
>
> Don't be shy.
> Ask this question in Unladen Swallow's google group. They don't bite!


I'm not the O.P., but I was curious too, so I asked on an Unladen Swallow
mailing list.  The response was that progress on Unladen Swallow is still
occurring, and is focused on merging things into the py3k-jit branch of the
official python repo.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nicer way to remove prefix of a string if it exists

2010-07-13 Thread MRAB

News123 wrote:

I wondered about a potentially nicer way of removing a prefix of a
string if it exists.


Here what I tried so far:


def rm1(prefix,txt):
if txt.startswith(prefix):
return txt[len(prefix):]
return txt


for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]:
# method 1 inline
prefix = "file://"
if f.startswith(prefix):
rslt = f[len(prefix):]
else
rsl = f
# method 2 as function
rslt = rm1('file://',f)


Is there any nicer function than above rm1()?


No.


Is there any nicer inline statement rhan my method 1' ?


You could write:

rsl = f[len(prefix):] if f.startswith(prefix) else f

in recent versions of Python, but the function is neater.
--
http://mail.python.org/mailman/listinfo/python-list


Re: nicer way to remove prefix of a string if it exists

2010-07-13 Thread Juan Andres Knebel
Hi, for rm1 I think something like this could work:
def rm1(prefix,txt):
  regular_expresion = re.compile(r''+prefix+'(.*)')
  return re.match(regular_expresion,txt).group(1)



On Tue, Jul 13, 2010 at 8:49 PM, News123  wrote:

> I wondered about a potentially nicer way of removing a prefix of a
> string if it exists.
>
>
> Here what I tried so far:
>
>
> def rm1(prefix,txt):
>if txt.startswith(prefix):
>return txt[len(prefix):]
>return txt
>
>
> for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]:
># method 1 inline
>prefix = "file://"
>if f.startswith(prefix):
>rslt = f[len(prefix):]
>else
>rsl = f
># method 2 as function
>rslt = rm1('file://',f)
>
>
> Is there any nicer function than above rm1()?
> Is there any nicer inline statement rhan my method 1' ?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Juan Andres Knebel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: guia de python 2.6.4 en castellano

2010-07-13 Thread Juan Andres Knebel
Hola, esto tal vez te pueda ayudar, no es para 2.6.4 pero sirve igual.
http://www.espaciolinux.com/2009/01/tutorial-%E2%80%9Cpython-para-todos%E2%80%9D-en-espanol/
Igualmente esto es una lista en ingles, por lo que si necesitas ayuda en
espanol te recomiendo la lista python en dicho idioma
Saludos

2010/7/13 Ruben ruben 

>  buenos dias mi nombre es ruben queria ver si me podian mandar la guia de
> python 2.6.4 en castellano yo baje el programa python pero en ingles y mi
> ingles es muy regular desde ya muchas gracias muy bueno el programa python
> --
> Descubrí un nuevo Hotmail: con más herramientas para una vida más práctica.
> Muy pronto. Ver más 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Juan Andres Knebel
-- 
http://mail.python.org/mailman/listinfo/python-list


nicer way to remove prefix of a string if it exists

2010-07-13 Thread News123
I wondered about a potentially nicer way of removing a prefix of a
string if it exists.


Here what I tried so far:


def rm1(prefix,txt):
if txt.startswith(prefix):
return txt[len(prefix):]
return txt


for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]:
# method 1 inline
prefix = "file://"
if f.startswith(prefix):
rslt = f[len(prefix):]
else
rsl = f
# method 2 as function
rslt = rm1('file://',f)


Is there any nicer function than above rm1()?
Is there any nicer inline statement rhan my method 1' ?

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


Re: floatref

2010-07-13 Thread Gary Herron

On 07/13/2010 03:02 PM, Roald de Vries wrote:

Hi Gary,

On Jul 13, 2010, at 8:54 PM, Gary Herron wrote:

On 07/13/2010 10:26 AM, Roald de Vries wrote:

Hi all,

I have two objects that should both be able to alter a shared float.
So i need something like a mutable float object, or a float reference
object. Does anybody know if something like that exists? I know it's
not hard to build, but I have a feeling that there should be a
standard solution to it.

Roald


Huh? I must be missing something here. Isn't this what you use a
variable for:


Maybe I didn't explain well:

 >>> shared_var = 1.0
 >>> x.var = shared_var
 >>> y.var = shared_var
 >>> x.var = 2.0
 >>> y.var
1.0

I wanted y.var and x.var to point to the same value, so that always
x.var == y.var. So that the last line becomes:

 >>> y.var
2.0

Cheers, Roald


Please keep responses and further discussions on
  list.python-l...@python.org
instead of using private emails.

Python does not have pointers, so if I take your wording"y.var and x.var 
to point to the same value"  literally, then the answer is NO  Python 
does not do that.


However, Python does have references all over the place, so you can 
achieve something similar in many ways.


If x and y in your example code are instances of a class, than look into 
using a property for x.var and y.var.  A property is a thing that looks 
like an attribute, (that would be var in x.var and y.var), but which 
really executes getter/setter code when accessed.  That getter/setter 
code would then access/set the value in shared_var:



shared_var = 123

class Thing(object):
def get_var(self):
return shared_var
def set_var(self, v):
global shared_var
shared_var = v

var = property(get_var, set_var)


x = Thing()
y = Thing()

print x.var, y.var # prints: 123 123
x.var = 99
print x.var, y.var # prints: 99 99


--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418
--
http://mail.python.org/mailman/listinfo/python-list


Re: Errno 9] Bad file descriptor

2010-07-13 Thread joblack
All right I found the web link. It's an improvement to the pdf miner
project (adds pdf dump methods).

http://pastebin.com/P8SWj5YK

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


Re: Cross-platform module that creates directory object with all file attributes

2010-07-13 Thread python
Hi Tim,

> Can't help you with x-platform; but for Windows I can offer my winsys package.

> if f.readonly:
>print f.created_at, f

I like your logical model - that's exactly what I was looking for. 

Thank you for sharing your code.

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


Re: Check if a command is valid

2010-07-13 Thread Kenny Meyer
Chris Rebert (c...@rebertia.com) wrote:
> On Mon, Jul 12, 2010 at 6:29 PM, Kenny Meyer  wrote:
> > Hello,
> >
> > I have to figure out if a string is callable on a Linux system. I'm
> 
> "callable" seems vague. Is a command string with invalid arguments but
> a valid executable "callable"? If no, then there's no general way to
> test "callability" without actually running the command.

I'm glad you pointed that out, because you're right.  I subconciously
meant a file that is in the $PATH.

[snip]
> 
> Well, you're not gonna be able to get the command's return code
> without actually running it (unless perhaps you're referring to a
> return code from the shell itself?).
> 
> > What are better ways of doing this?
> 
> One idea:
> 
> from shlex import split as shell_tokenize
> from subprocess import check_output
> 
> def is_valid_command(command):
> try:
> executable = shell_tokenize(command)[0]
> except (ValueError, IndexError):# invalid shell syntax
> return False
> return bool(check_output(['which', executable]))# on the PATH?
>
I have tried this and found some unexpected issues with Python 2.6 which I
though I should point out:

Firstly, the function `check_output` in the `subprocess` module only comes with
Python 2.7, but I have found a similar function called `check_call` [1] which
seems is similar, but not the same.

[1] http://docs.python.org/library/subprocess.html#subprocess.check_call

The code now looks like this:

from shlex import split as shell_tokenize
from subprocess import check_call, CalledProcessError

def is_valid_command(command):
try:
executable = shell_tokenize(command)[0]
check_call(['which', executable]) # Raises CalledProcessError if

  # something went wrong
return True  
except (ValueError, IndexError, CalledProcessError): # Catch exception if 
there

 # was an error calling the process
return False

The idea with `which` is really great one.

Thanks a lot, for your time and your input.

-- 
Onward and upwards,
Kenny Meyer


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


Re: executing python scripts within wx frames

2010-07-13 Thread Philip Semanchuk


On Jul 13, 2010, at 11:15 AM, Astan Chee wrote:


Hi,
I'm trying to make one of those frames thats similar to the wx  
python demo where a folder is filled with demo wx python scripts and  
there is one main script that opens the other ones in as different  
items in a tree/notebook.
I've gotten most of it figured out except the part where the scripts  
are executed in a wx frame. The difference between what I'm trying  
to do and the wx python demo one is that mine are generic scripts  
that output the results to std out/error (or whatever gets displayed  
in IDLE). Does anyone know how I can do this? Simulate a IDLE or  
python shell in one of the frames thats basically the output of  
whatever script has been selected to run?

It would be better if the solution was platform independent too.


Hi Astan,
The subprocess module allows you to capture the stdin/stdout/stderr of  
a process that you launch. This sounds like what you're looking for.



bye
Philip

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


Re: adodb.NewADOConnection('postgres') returns None

2010-07-13 Thread Thomas Jollans
On 07/13/2010 09:55 PM, micayael wrote:
> Hi.
> 
> I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10
> the adodb and psycopg2 module (sudo apt-get install python-adodb
> python-psycopg2) but when I put this
> 
> import adodb
> print adodb.NewADOConnection('postgres') --> None
> 
> but with
> 
> print adodb.NewADOConnection('mysql') -->
> 


http://packages.ubuntu.com/lucid/python-adodb

Recommends: python-psycopg (Package not available)

If it says it wants psycopg, I wouldn't expect it to work with psycopg2,
which is probably quite different in some way - otherwise it would be
called the same.

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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

2010-07-13 Thread sturlamolden
On 13 Jul, 22:35, "Alf P. Steinbach /Usenet"  wrote:

> Yes, I know Boost.Python in more detail and I've heard of all the rest except
> SIP,


In my opinion, SIP is the easiest way of integrating C++ and Python.
Just ignore the PyQt stuff.

http://www.riverbankcomputing.co.uk/static/Docs/sip4/using.html#a-simple-c-example
http://www.riverbankcomputing.co.uk/software/sip/intro

(SIP 4 can also expose C libraries to Python, not just C++.)


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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

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

* sturlamolden, on 13.07.2010 22:06:

On 13 Jul, 21:39, "Alf P. Steinbach /Usenet"  wrote:


Thanks! It seems that SCXX does those things that I've been planning to do but
haven't got around to (wrapping standard Python types), while what it doesn't do
(abstracting away all those tables etc. and mapping Python calls to C++ calls)
is what I've been working on. Which could be a Very Nice combination except that
I'm assuming Py3, while SCXX seems to be Py2 only. :-(


I'd suggest PyCXX instead. http://cxx.sourceforge.net

SCXX is a tiny wrapper mostly used in scipy.weave to inline C++ in
Python.


Thanks. I looked up your URL, and PyCXX design goals seem to be much like what 
I'm doing, but different in some crucial ways. It's probably great, but it's not 
to my taste.


E.g. the PyCXX String class interface:


explicitString( PyObject *pyob, bool owned = false )
String( const Object &ob )
String()
String( const char *latin1 )
String( const char *latin1, Py_ssize_t size )
String( const std::string &latin1 )
String( const std::string &v, const char *encoding, const char 
*error=NULL )
String( const char *s, const char *encoding, const char *error=NULL )
	String( const char *s, Py_ssize_t len, const char *encoding, const char 
*error=NULL )

String &operator=( const Object &o )
String &operator=( PyObject *p )
String &operator=( const unicodestring &v )
size_type   size() const
size_type   capacity() const
unicodestring   as_unicodestring() const
std::string operator std::string() const
String  encode( const char *encoding, const char *error="strict" )
std::string 	as_std_string( const char *encoding=NULL, const char 
*error="strict" ) const



In C++ the only way to portably specify a string literal with national 
characters, is as a wide string literal. Otherwise the result depends on the 
source code encoding. Yet PyCXX's String does not support wchar_t.


Also, things like the 'owned' option is just asking for trouble.

I chose this example because a Python string wrapper is the only object wrapper 
(apart from a general PyPtr) that I've implemented so far. The PyCXX string 
wrapper fails the design criterions of general usability (including in 
particular lack of wide char support) and safety (in particular the 'owned' 
option). And it's underdocumented, like, what encoding does the operator 
std::string() produce?


The details don't matter though. I'm sure that PyCXX is Very Nice for its 
purpose, as is e.g. Boost.Python (which is Very Very Nice for its purpose). :-)



Cheers, & thanks for the link,

- Alf

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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

2010-07-13 Thread sturlamolden
On 13 Jul, 22:35, "Alf P. Steinbach /Usenet"  wrote:

> In practice, 'extern "C"' matters for the jump tables because for those few
> compilers if any where it really matters (not just the compiler emitting a
> warning like reportedly Sun CC does), different linkage can imply different
> machine code level calling convention.

I see. Just stick to MSVC and GNU and that never happens, just do a C
style cast.

> Yes, I know Boost.Python in more detail and I've heard of all the rest except
> SIP, but then regarding SIP I really don't like QT

You don't have to use Qt to use SIP. It's just a tool to automatically
wrap C++ for Python (like Swig, except designed for C++).


> And as you'd guess if you were not in silly ignoramus assertion-mode, I'm not
> reinventing the wheel.

It seems you are re-inventing PyCXX (or to a lesser extent
Boost.Python).








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


M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem

2010-07-13 Thread Adam Mercer
Hi

I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5
(python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a
and it is failing with the following:

105 :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
106 :info:build swig -python
-I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5
-I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c
SWIG/_m2crypto.i
107 :info:build SWIG/_bio.i:64: Warning 454: Setting a
pointer/reference variable may leak memory.
108 :info:build SWIG/_rand.i:19: Warning 454: Setting a
pointer/reference variable may leak memory.
109 :info:build SWIG/_evp.i:156: Warning 454: Setting a
pointer/reference variable may leak memory.
110 :info:build SWIG/_dh.i:36: Warning 454: Setting a
pointer/reference variable may leak memory.
111 :info:build SWIG/_rsa.i:43: Warning 454: Setting a
pointer/reference variable may leak memory.
112 :info:build SWIG/_dsa.i:31: Warning 454: Setting a
pointer/reference variable may leak memory.
113 :info:build SWIG/_ssl.i:207: Warning 454: Setting a
pointer/reference variable may leak memory.
114 :info:build SWIG/_x509.i:313: Warning 454: Setting a
pointer/reference variable may leak memory.
115 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a
pointer/reference variable may leak memory.
116 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a
pointer/reference variable may leak memory.
117 :info:build SWIG/_util.i:9: Warning 454: Setting a
pointer/reference variable may leak memory.
118 :info:build SWIG/_ec.i:111: Warning 454: Setting a
pointer/reference variable may leak memory.
119 :info:build SWIG/_engine.i:162: Warning 454: Setting a
pointer/reference variable may leak memory.
120 :info:build creating build/temp.macosx-10.6-x86_64-2.5
121 :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG
122 :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd
-fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
-I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5
-I/opt/local/include
-I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG
-c SWIG/_m2crypto_wrap.c -o
build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING
123 :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes':
124 :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets
in passing argument 1 of 'PyString_FromStringAndSize' differ in
signedness
125 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1':
126 :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets
in passing argument 1 of 'PyString_FromStringAndSize' differ in
signedness
127 :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key':
128 :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets
in passing argument 1 of 'PyString_FromStringAndSize' differ in
signedness
129 :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final':
130 :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets
in passing argument 1 of 'PyString_FromStringAndSize' differ in
signedness
131 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der':
132 :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets
in passing argument 1 of 'PyString_FromStringAndSize' differ in
signedness
133 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus':
134 :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not 
used
135 :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not 
used
136 :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt':
137 :info:build SWIG/_m2crypto_wrap.c:: warning: pointer targets
in passing argument 1 of 'PyString_FromStringAndSize' differ in
signedness
138 :info:build SWIG/_m2crypto_wrap.c: At top level:
139 :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',',
';', 'asm' or '__attribute__' before '*' token
140 :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' 
token
141 :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' 
token
142 :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',',
';', 'asm' or '__attribute__' before '*' token
143 :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' 
token
144 :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' 
token
145 :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509':
146 :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets
in passing argument 1 of 'PyString_FromStringAndSize' differ in
signedness
147 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid':
148 :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets
in passing argu

Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

2010-07-13 Thread Dilip
On Jul 13, 2:34 am, "Alf P. Steinbach /Usenet"  wrote:
> Well, we got no further, but I know of three solutions:
>
>    A) Punting: just say that the compiler has to support C++/C function type
>       mingling.
>       -> Perhaps the practical solution, but formally unsafe.
>
>    B) On the script side of things, delegate all calls to single Mother Of All
>       C func downcaller that supplies as extra arg an id of the C++ function.
>       -> Micro-level inefficient but easy to use and formally correct.
>
>    C) Let the user define the C linkage function wrappers via macros.
>       -> Efficient and formally correct but exposes ugly macro names.
>
> I chose (C).

Alf

This may or may not be what you are looking for but the middleware Ice
provides language mapping to enable Python to call into the Ice
libraries which are basically written in C++.  You can take a look at
this: http://www.zeroc.com/icepy.html

However that page may not be very descriptive.  The codebase, though,
is freely downloadable.  You can take a look at it if that will help
although you need to wade around a little bit to figure out what is
where.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hello

2010-07-13 Thread Tim Johnson
On 2010-07-10, Andreas Waldenburger  wrote:
> On Fri, 9 Jul 2010 16:49:20 + (UTC) Grant Edwards
> wrote:
>
>> On 2010-07-09, Dani Valverde  wrote:
>> 
>> > I am new to python and pretty new to programming (I have some
>> > expertise wit R statistical programming language). I am just
>> > starting, so my questions may be a little bit stupid. Can anyone
>> > suggest a good editor for python?
>> 
>> Emacs, Scite (has nice folding), Vim, Eclipse.
>> 
> Great tips for a newbie.
>
> Not.
>
> Well, they might be, but chances are, they are overkill for people new
> to programming and will only alienate them (Scite may be an exception).
> Text editors are an acquired taste.

Emacs and Vim are very difficult to learn. Emacs more so than vim
(even with vim's modal style of editing IMHO). However, to suggest that
either might alienate someone new to programming presupposes some
metric on their ability to learn. Since I am not privy to that metric,
read on:

As linux programmer, I use vim for python, javascript, rebol and adhoc 
system
management and emacs for lispish programmer languages. 

1)Most releases of vim (such as those available from ubuntu 
repositories)
are compiled with the python binary embedded. Thus one could customize
vim using python itself.
2)Emacs is itself a design environment based on the elisp programming
language and both of these.

The time spent on learning either of these could pay off in the long
run, *but it would be a long run*.

Vim and emacs are available for Windows.

  When I programmed in Windows I used two different editors: Pythowin,
obviously coming with the python for windows distribution.
Pythonwin is great and very 'helpful'.

Boxer - a freeware programmer's editor, that has the best balance
of configurability and ease of use of any editor that I have used. 
But it has been years since I used either.

-- 
Tim 
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

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

* sturlamolden, on 13.07.2010 22:03:

On 9 Jul, 17:52, "Alf P. Steinbach /Usenet"  wrote:


For an extension module it seems that Python requires each routine to be defined
as 'extern "C"'.


That is strange. PyMethodDef is just a jump table. So why should
'extern "C"' matter?


Formally because they're incompatible function pointer types.

C++98 standard §7.5/1: "Two function types with different language linkages are 
distinct types even if they are otherwise identical". Add to that §7.5/4 "A 
linkage-specification shall occur only in namespace scope". And add to that 
§14-4 "A template, a template explicit specialization, or a class-template 
partial specialization shall not have C linkage." This means that formally 
correct code that generates callbacks by templating, is ruled out.


In practice, 'extern "C"' matters for the jump tables because for those few 
compilers if any where it really matters (not just the compiler emitting a 
warning like reportedly Sun CC does), different linkage can imply different 
machine code level calling convention. For example, who's responsible for 
cleaning up the stack, the order in which arguments are pushed or which 
registers they're passed in, and so forth. Ignoring such matters your code gets 
into la-la land pretty fast, but, it's a different matter when one /understands/ 
this and places a requirement on the compiler.




Good luck on re-inventing the wheel (you've probably heared about
Swig, SIP, Boost.Python, PyCXX, scipy.weave and Cython...)


Yes, I know Boost.Python in more detail and I've heard of all the rest except 
SIP, but then regarding SIP I really don't like QT (QT makes eminent sense in 
the context of Python, they're both essentially dynamically typed, but that 
means QT is not very nice as C++, plus there is the ugly preprocessor).


And as you'd guess if you were not in silly ignoramus assertion-mode, I'm not 
reinventing the wheel.



Cheers & hth.,

- Alf

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


Re: Check if a command is valid

2010-07-13 Thread Hans Mulder

Chris Rebert wrote:


`where` seems to be a zsh built-in:
$ # I'm in UR bash
$ nonexistent
-bash: nonexistent: command not found
$ where bash
-bash: where: command not found

And not everyone has zsh installed, so...
I don't see why one shouldn't use the standard `which` *nix command instead.


Because `which` ia a C shell script.  It reads your .cshrc, to see which
aliases would be defined if you were to use the C shell, but it doesn't
look at your .bashrc.

You're probably better off using `type`: it knows about built-ins and
shell functions and that sort of stuff:

$ which type
/usr/bin/type
$ type type
type is a shell builtin
$

Guess which answer is more relevant to you .

HTH,

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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

2010-07-13 Thread sturlamolden
On 13 Jul, 21:39, "Alf P. Steinbach /Usenet"  wrote:

> Thanks! It seems that SCXX does those things that I've been planning to do but
> haven't got around to (wrapping standard Python types), while what it doesn't 
> do
> (abstracting away all those tables etc. and mapping Python calls to C++ calls)
> is what I've been working on. Which could be a Very Nice combination except 
> that
> I'm assuming Py3, while SCXX seems to be Py2 only. :-(

I'd suggest PyCXX instead. http://cxx.sourceforge.net

SCXX is a tiny wrapper mostly used in scipy.weave to inline C++ in
Python.



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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

2010-07-13 Thread sturlamolden
On 9 Jul, 17:52, "Alf P. Steinbach /Usenet"  wrote:

> For an extension module it seems that Python requires each routine to be 
> defined
> as 'extern "C"'.

That is strange. PyMethodDef is just a jump table. So why should
'extern "C"' matter?

Good luck on re-inventing the wheel (you've probably heared about
Swig, SIP, Boost.Python, PyCXX, scipy.weave and Cython...)

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


adodb.NewADOConnection('postgres') returns None

2010-07-13 Thread micayael
Hi.

I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10
the adodb and psycopg2 module (sudo apt-get install python-adodb
python-psycopg2) but when I put this

import adodb
print adodb.NewADOConnection('postgres') --> None

but with

print adodb.NewADOConnection('mysql') -->

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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

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

* Jonathan Lee, on 13.07.2010 16:41:

Problem (C) is outside the realm of the C++ standard, since the C++ standard
doesn't support shared libraries, and I've never actually used *nix shared
libraries so I don't /know/...

Is such dynamic initialization guaranteed?



Not guaranteed, though I think there's a combination of dlopen options
and gcc command line parameters that invoke this behavior. See the
second page of

http://www.linuxjournal.com/article/3687

about auto-registration.

Personally, though, it never worked for me :/


Ah, well. :-(  Thanks for the info! OK, I'll just have to replace the 
auto-registration with some C++ magic. For which I think I'll simply /require/ 
that the compiler supports mixing of C and C++ linkage, that is, that ...




#include 

extern "C"
{
typedef int (*Callback)( int );
}

void foo( Callback f ) { std::cout << "foo!" << f( 42 ) << std::endl; }

int a( int ) { return 1; }
extern "C" int b( int ) { return 2; }

int main()
{
foo( a );   // Unholy Mix of C++ and C linkage, formally not OK.
foo( b );   // Should be OK with any compiler.
}



... compiles, and works.


Cheers, & thanks,

- Alf

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


Re: write a .txt file

2010-07-13 Thread MRAB

Jia Hu wrote:



On Tue, Jul 13, 2010 at 3:17 AM, Cameron Simpson > wrote:


On 13Jul2010 02:46, Jia Hu mailto:huji...@gmail.com>> wrote:
| Hi:
|
| Do you mean the following code?
|
| #!/usr/bin/python
| # OS: Ubuntu
| import subprocess
| fileName = open ('final.txt', 'a')
| fileName.write ('%s %s %s \n' % (12,25,9))
|
| fileName.flush()   # add
| fileName.close()  # add

You should not need the .close().
 


Thank you.
 


| desLrr = subprocess.Popen('ls -a >> final.txt', shell=True)  #
change to "ls
| -a"

You're still not waiting for the Popen subprocess to finish before
continuing.

| fileName=open ('final.txt', 'a')

You shouldn't need the open() if you skip the .close()

| fileName.seek(0,2)

If you _do_ do an open(..., "a") then you don't need the seek - append
mode will write at the end for you.

| fileName.write ('%s %s %s \n' % (85,25,12))
| fileName.close()
|
| I run that, the result showed the list of file is located after
the number
| list 85 25 12
| Is that possible that I put the fileName.flush() in a wrong position ?
| I am new to Python and do not quite understand the "flush" concept.

First: please don't top post. Post below the relevant points as I do
above, like a conversation. That way it is clear exactly what each
remark is for.

 


OK, it is a good suggestion. By the way, do you add the pipe "|" or

they are automatically generated ?


Second: "flush" is a general idea used with buffers.

When you .write() to a file the data does not normally go directly to
disc.  This is because a real write to the disc is expensive in time
(the CPU is much much faster than a hard drive).

Also, a OS-level "write", which transfers the data from your program
into
the OS's buffers (where it queues, for eventual writing to the disc)
is _also_ a comparitively expensive operation. So when you .write()
in python (or C using stdio, and in many other languages) the data is
normally kept in a memory buffer inside your program. Only when that
buffer is filled is an OS-level "write" done. In this way, OS calls are
few. This is a performance gain.

So, in your program, when you .write() your first line of numbers
the data has not been handed to the OS at all, and therefore the
"final.txt" file has not seen it. A .flush() call is an explicit request
to empty the buffer, making an OS-level "write" immediately. In your
program, this is necessary to get the data to "final.txt" before the
"echo" or "ls" commands are run.

If you .close() a file, that also empties the buffer. But it also closes
the file! SO you need to re-open it. For your purposes, a .flush() is
enough and leaves the file open for you to continue using it later.

Regarding the .seek(): after the "echo" or "ls" command has run
the file  has grown. Python's "file" object does not know the file has
grown because it was not involved. So a .seek(0 is needed to position
Python's .write() location to the end of the file instead of where it
though things were.

Um. Because you have opened the file in 'a' mode you should not need the
.seek() - an "append" mode file will always write to the end of the
file.

So: your first problem only requires a .flush(), to empty the buffer
before "echo" or "ls" runs. However, you still have not waited for the
"echo" or "ls" to finish - Popen kicks the command off, but it will run
at the same time as your program! Call:

 desLrr.wait()

I initially thought only desLrr.wait() is needed even if without 
fileName.flush() , that is
because the first line of number will transfer to the memory buffer and 
then "echo, ls" is
also kept in the memory buffer and then wait() to make them finish. But 
when I actually did this, 
I find this method is not very correct. The first few words generated 
by "ls" are missing.

When I add  "fileName.flush()" again and got a correct output.
 
Should I always write to the file at one time and then run "flush" or 
"close()" before the next

write to the file (e.g. "echo" or the second line of number) ?
 

Each process will have its own buffers, so the output from "echo" won't
be going into the same buffer as that of your Python script.

Whether you need to close the file depends on whether the open file can
be shared. When I tried it on Windows XP without closing the file I got
an error message saying that it ("echo") couldn't write to the file
because it was open in another process (the Python script).

If the open file can be shared then you just need to ensure that the
script's output is flushed to disk; if the open file can't be shared
then you need to close the file (any output that's still in the buffer
will be flushed automatically when the file is closed).
--
http://mail.python.org/mai

Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

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

* Robert Kern, on 13.07.2010 17:16:

On 7/13/10 2:34 AM, Alf P. Steinbach /Usenet wrote:


PS: You (the reader) may be wondering, why why why Yet Another Python/C++
binding? Well, because I had this great name for it, "pyni", unfortunately
already in use. But cppy is very different from Boost: Boost is large,  cppy is
tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating
argument conversion etc., while with cppy your Python design is exposed to C++
with no enforced arg conversions and such; Boost relies on canned magic,
difficult to subvert when it doesn't do what you want, while with cppy you are
(or, so far, I am) in control; and I suspect that the Boost Python binding,
relying on dynamic registries and stuff, is not all that efficient, while cppy
is as efficient as using the Python C API to create an extension. And besides,
cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-)


Note that Boost is not the only C++ binding out there. You may want to
take a look at the old SCXX library, which appears to be similar in intent:

  http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html

matplotlib uses it heavily, and their included copy may include some
more recent bugfixes and enhancements:

  http://matplotlib.sourceforge.net/


Thanks! It seems that SCXX does those things that I've been planning to do but 
haven't got around to (wrapping standard Python types), while what it doesn't do 
(abstracting away all those tables etc. and mapping Python calls to C++ calls) 
is what I've been working on. Which could be a Very Nice combination except that 
I'm assuming Py3, while SCXX seems to be Py2 only. :-(



Cheers,

- Alf

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


Re: write a .txt file

2010-07-13 Thread Jia Hu
On Tue, Jul 13, 2010 at 3:17 AM, Cameron Simpson  wrote:

> On 13Jul2010 02:46, Jia Hu  wrote:
> | Hi:
> |
> | Do you mean the following code?
> |
> | #!/usr/bin/python
> | # OS: Ubuntu
> | import subprocess
> | fileName = open ('final.txt', 'a')
> | fileName.write ('%s %s %s \n' % (12,25,9))
> |
> | fileName.flush()   # add
> | fileName.close()  # add
>
> You should not need the .close().
>
>
Thank you.


> | desLrr = subprocess.Popen('ls -a >> final.txt', shell=True)  # change to
> "ls
> | -a"
>
> You're still not waiting for the Popen subprocess to finish before
> continuing.
>
> | fileName=open ('final.txt', 'a')
>
> You shouldn't need the open() if you skip the .close()
>
> | fileName.seek(0,2)
>
> If you _do_ do an open(..., "a") then you don't need the seek - append
> mode will write at the end for you.
>
> | fileName.write ('%s %s %s \n' % (85,25,12))
> | fileName.close()
> |
> | I run that, the result showed the list of file is located after the
> number
> | list 85 25 12
> | Is that possible that I put the fileName.flush() in a wrong position ?
> | I am new to Python and do not quite understand the "flush" concept.
>
> First: please don't top post. Post below the relevant points as I do
> above, like a conversation. That way it is clear exactly what each
> remark is for.



> OK, it is a good suggestion. By the way, do you add the pipe "|" or

they are automatically generated ?

>
> Second: "flush" is a general idea used with buffers.
>
> When you .write() to a file the data does not normally go directly to
> disc.  This is because a real write to the disc is expensive in time
> (the CPU is much much faster than a hard drive).
>
> Also, a OS-level "write", which transfers the data from your program into
> the OS's buffers (where it queues, for eventual writing to the disc)
> is _also_ a comparitively expensive operation. So when you .write()
> in python (or C using stdio, and in many other languages) the data is
> normally kept in a memory buffer inside your program. Only when that
> buffer is filled is an OS-level "write" done. In this way, OS calls are
> few. This is a performance gain.
>
> So, in your program, when you .write() your first line of numbers
> the data has not been handed to the OS at all, and therefore the
> "final.txt" file has not seen it. A .flush() call is an explicit request
> to empty the buffer, making an OS-level "write" immediately. In your
> program, this is necessary to get the data to "final.txt" before the
> "echo" or "ls" commands are run.
>
> If you .close() a file, that also empties the buffer. But it also closes
> the file! SO you need to re-open it. For your purposes, a .flush() is
> enough and leaves the file open for you to continue using it later.
>
> Regarding the .seek(): after the "echo" or "ls" command has run
> the file  has grown. Python's "file" object does not know the file has
> grown because it was not involved. So a .seek(0 is needed to position
> Python's .write() location to the end of the file instead of where it
> though things were.
>
> Um. Because you have opened the file in 'a' mode you should not need the
> .seek() - an "append" mode file will always write to the end of the
> file.
>
> So: your first problem only requires a .flush(), to empty the buffer
> before "echo" or "ls" runs. However, you still have not waited for the
> "echo" or "ls" to finish - Popen kicks the command off, but it will run
> at the same time as your program! Call:
>
>  desLrr.wait()

I initially thought only desLrr.wait() is needed even if without
fileName.flush() , that is
because the first line of number will transfer to the memory buffer and then
"echo, ls" is
also kept in the memory buffer and then wait() to make them finish. But when
I actually did this,
I find this method is not very correct. The first few words generated
by "ls" are missing.
When I add  "fileName.flush()" again and got a correct output.

Should I always write to the file at one time and then run "flush" or
"close()" before the next
write to the file (e.g. "echo" or the second line of number) ?

Thank you.



>

to wait for the "echo" or "ls" to finish before continuing!
>

> Cheers,
> --
> Cameron Simpson  DoD#743
> http://www.cskk.ezoshosting.com/cs/
>
> Quick Guide to Resources to break crypto systems of given strength:
> Difficulty Resources required
>  2**0  Pencil and paper
>  2**8  Pencil and paper and a lot of patience
>  2**16 Warez d00d with a Commodore 64
>  2**32 Amateur with an average PC
>  2**40 Smart amateur with a good PC
>  2**56 Network of workstations, custom-built hardware
>  2**64 Thousands of PCs working together for several years
>  2**80 NSA, Microsoft, the Illuminati
>  2**128Cubic kilometers of sci-fi nanotech
>  2**160Dyson spheres
> Eddy L O Jansson and Matthew Skala, from:
> http://hem.passagen.se/eddy1/reveng/cp4/cp4break.html
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: floatref

2010-07-13 Thread Gary Herron

On 07/13/2010 10:26 AM, Roald de Vries wrote:

Hi all,

I have two objects that should both be able to alter a shared float. 
So i need something like a mutable float object, or a float reference 
object. Does anybody know if something like that exists? I know it's 
not hard to build, but I have a feeling that there should be a 
standard solution to it.


Roald


Huh?  I must be missing something here.  Isn't this what you use a 
variable for:


sharedFloat = 123

and later

  sharedFloat = 99

The variable sharedFloat could exit as a global (in some module) or as a 
instance variable in some shared object or anywhere else you want to 
store it.


As a module attribute:

import Shared
Shared.sharedFloat = 123

Or as a class attribute:

class Shared:
  sharedFloat = 0

Shared.sharedFloat = 123

or as an instance attribute:

  class Shared:
def __init__(self):
self.sharedFloat = 0

  sharedObject = Shared()
  sharedObject.sharedFloat = 123



Gary Herron








--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


death of newsgroups (Microsoft closing their newsgroups)

2010-07-13 Thread Xah Lee
• Death of Newsgroups
  http://xahlee.org/UnixResource_dir/writ2/death_of_newsgroups.html

plain text version follows.

--
Death of Newsgroups

Xah Lee, 2010-07-13

Microsoft is closing down their newsgroups. See:
microsoft.public.windows.powershell.

I use comp.lang.lisp, comp.emacs since about 1999. Have been using
them pretty much on a weekly basis in the past 10 years. Starting
about 2007, the traffic has been increasingly filled with spam, and
the posters are always just the 20 or 30 known faces. I think perhaps
maybe no more than 100 different posters a year. Since this year or
last year, they are some 95% spam.

comp.emacs is pretty much just me.

gnu.emacs.help is not much better. It's pretty much the same
developers and the same few elisp coders, with perhaps 1 new face with
once-per-lifetime post every few days. gnu.emacs.help is doing a bit
better because it is connected to fsf's mailing list.

comp.lang.perl.misc is dead few years ago. It's filled with just
snippet of FAQs that's posted by machine. There's perl.beginners since
2002, and it's a moderated group.

The one newsgroup that i use that's still healthy is comp.lang.python.
Part of the reason it's healthy because it's connected to a mailing
list, and python has become a mainstream lang. Though, it is also
infected by a lot spam in late years.

I did a study of language popularity by graphing newsgroup traffic
thru the years. See: Computer Language Popularity Trend. I thought
about updating it now and then, but it's useless if the majority of
posts are machine generated spam.

For vast majority of people who is not a regular user of newsgroups in
the 1990s or earlier, i suppose newsgroup has been dead since perhaps
2002.

It's somewhat sad. Because newsgroup once was the vibrant hotbed for
uncensored information and freespeech, with incidences that spawned
main stream public debate on policies, or change of nations.
(scientology being one famous example, then there's Cindy's Torment
censorship, then i remember also several cases of political dirty
secrets being released in newsgroups ) These days, much of this
happens in the blogs and there's Wikileaks.

  Xah
∑ http://xahlee.org/

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


Re: integer >= 1 == True and integer.0 == False is bad, bad, bad!!!

2010-07-13 Thread Peter Pearson
On 13 Jul 2010 03:16:31 GMT, Steven D'Aprano wrote:
[snip] 
> . . . and we rightly shake our heads at the sheer
> n00b-ness of it. Writing the explicit tests:
>
> if bool(myInt):
>
> or even:
>
> if myInt <> 0:
>
> are firmly in the same category. The only difference is that it is more 
> familiar and therefore comfortable to those who are used to languages 
> that don't have Python's truth-testing rules.

I have been a Python newbie for over 10 years, and would like
to mention that what's clear to Python experts is much less clear
to me.  I think this might matter more than you think, since
clarity-to-the-semicompetent is an important component of
the "activation barrier" that heavily influences market share.

Names are seldom so felicitous as myInt.  In practice, when
trying to read foreign code, I encounter "if x:", and poor
commenting leaves me ignorant of x's type and thus of the
exact meaning of "if x:".  When I see "if x <> 0:", I get
the feeling that x is some kind of number, and the meaning
of the test is pretty clear.

And then when writing code, I usually can't confidently
retrieve the recipe for the boolean interpretation of x from
readily accessible memory, so I will write explicitly what I
mean, and thereby do a favor for the next guy to look at the
code, who is almost always a 10-year Python newbie who needs
all the clues he can get.

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


Re: Python 3 grammar, function parameters

2010-07-13 Thread Junkman
A-ha!  Thank you very much, Chris.  Much appreciated.  :-)

Jay

Chris Rebert wrote:
> On Mon, Jul 12, 2010 at 3:32 PM, Junkman  wrote:
>> Greetings to Python users,
>>
>> I'm trying to parse Python code using the grammar supplied with the
>> documentation set, and have a question on the grammar for function
>> parameters:
>>
>> funcdef: 'def' NAME parameters ['->' test] ':' suite
>> parameters: '(' [typedargslist] ')'
>> typedargslist: ((tfpdef ['=' test] ',')*
>>('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef]
>> | '**' tfpdef)
>>| tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
>> tfpdef: NAME [':' test]
>>
>> >From what I understand, a naked asterisk - i.e. it is not a prefix to an
>> identifier - is not a valid parameter, but the grammar  explicitly
>> allows it by making the  identifier that immediately follows the
>> asterisk optional.
>>
>> Are there cases where naked asterisk is allowed as a function
>> parameter?
> 
> Yes, for keyword-only arguments, a new feature in Python 3.x. See PEP
> 3102 (http://www.python.org/dev/peps/pep-3102/ ).
> A lone asterisk signals that the function does not take extra
> positional arguments. All keyword-only arguments must be declared
> after a lone or normal *-argument.
> 
> Example:
> def compare(a, b, *, key=None):
> 
> compare() does not accept extra positional arguments and has 1
> keyword-only argument (namely, `key`).
> 
> Cheers,
> Chris
> --
> http://blog.rebertia.com
> 

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


guia de python 2.6.4 en castellano

2010-07-13 Thread Ruben ruben

buenos dias mi nombre es ruben queria ver si me podian mandar la guia de python 
2.6.4 en castellano yo baje el programa python pero en ingles y mi ingles es 
muy regular desde ya muchas gracias muy bueno el programa python
 
_
En Hotmail estamos reinventando un nuevo correo. Preparate para lo que se 
viene. Ver más
http://www.nuevohotmail.com-- 
http://mail.python.org/mailman/listinfo/python-list


floatref

2010-07-13 Thread Roald de Vries

Hi all,

I have two objects that should both be able to alter a shared float.  
So i need something like a mutable float object, or a float reference  
object. Does anybody know if something like that exists? I know it's  
not hard to build, but I have a feeling that there should be a  
standard solution to it.


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


Re: round issue

2010-07-13 Thread Emile van Sebille

On 7/13/2010 9:06 AM Robin Becker said...


Anyhow does anyone have a good algorithm for ensuring rounded
percentages do add up to 100%? :) How about grouped percentages ie
ensure the group sums and the groups display correctly in rounded form.


I generally do the calculations in memory then set the
largest to 100 - sum(rounded(others)).  (Same as for
double entry bookkeeping to ensure debits == credits)

Emile



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


Re: Cross-platform module that creates directory object with all file attributes

2010-07-13 Thread Tim Chase

On 07/13/2010 10:56 AM, pyt...@bdurham.com wrote:

Any recommendations for a cross-platform module that creates a
directory object with not only file names, but file attributes as
well?

Use cases:
- Sort files by file size or date last modified
- Filter files by read-only status

I know I can use various standard library functions [1] to
construct such a class, but I'd rather avoid re-inventing the
wheel if at all possible. (I fear that this may be one of those
seemingly easy tasks that starts off simple and ends up taking a
lot more time to implement after real world refactoring).


I think it's sufficiently easy to create a custom solution that 
there's not much value in trying to map file-metadata into a 
wrapper object.  For your examples:


  f = os.path.getmtime
  #f = os.path.getsize
  sorted_by_mtime = sorted(os.listdir('.'), key=f)

or if you need a different location

  sorted_by_mtime = sorted(
os.listdir(loc),
key=lambda fname: f(os.path.join(loc, fname))
)

And for your read-only status:

  files = [fname for fname in os.listdir(loc)
if os.access(os.path.join(loc, fname), os.W_OK)
]

That doesn't mean somebody hasn't done it before, but given how 
easy it is without a wrapper object, it's not something I'd go 
out of my way to find.


-tkc


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


Re: Plot problem.. ?? No sign at all

2010-07-13 Thread Ritchy lelis
On 11 Jul, 13:28, Johan Grönqvist  wrote:
> 2010-07-11 02:12, Ritchy lelis skrev:
>
> > On 7 jul, 08:38, Johan Grönqvist  wrote:
>
> > About the plot draw it's a curve that it's a set of points wich it's
> > the result of the comput of the Vref and Vi together. I don't know if
> > i had to make a break instruction (like in other's languages) after
> > the "If" instructions if i want the else-condition to be executed? ...
> > (do you have some sujestions?)
>
> I would have expected a code structure similar to this:
>
> (NOTE: This is a very inefficient solution, and not the one suggested
> earlier, but it is closer to the code snippet you posted originally, and
> it does produce a plot.)
>
> --
> import numpy as np
> import matplotlib.pyplot as plt
> Vref = np.linspace(1,20, 100)
> Vi = np.linspace(1,10,100)
>
> for ref in Vref: # Loop over Vref and Vi
>      for i in Vi:
>          if  i > ref/4: # Compute V0
>              V0 = 2*i-ref
>          elif (-ref/4) <= ref and ref <= ref/4:
>              V0 = 2*i
>          elif i < -ref/4:
>              V0 = 2*i+ref
>          plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0
> plt.show() # Display the plot in a window
> --
>
> > Anyway i have a picture of a tuturial that i found but in this forum i
> > can't post it. That pic would show what a really want...
>
> Can you give a link?
>
>
>
> > Relatively to the axis, the Vi takes the x-axis and the Vref takes the
> > y-axis.
>
> To me this sound like you want to make a 3D-plot, as there is the
> x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis?
>
>
>
> > As i said, i have a good 2 pic of a doc that has the information about
> > this ADC that i'm developing.
>
> I looked on wikipedia
> , and saw some
> figures. Is any of those similar to what you look for?
>
> I see that they have (Vi - Vref) on the x-axis, and the computed value
> on the y-axis.
>
> Regards
>
> Johan

hi

This is how looks like the flash residue transference function that i
was talking about...

http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif

I'm suposed to obtain a figure like that in my plot.

Somebody help me please.

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


Re: Plot problem.. ?? No sign at all

2010-07-13 Thread Ritchy lelis
On 11 Jul, 17:39, Ritchy lelis  wrote:
> On 11 jul, 13:28, Johan Grönqvist  wrote:
>
>
>
>
>
> > 2010-07-11 02:12, Ritchy lelis skrev:
>
> > > On 7 jul, 08:38, Johan Grönqvist  wrote:
>
> > > About the plot draw it's a curve that it's a set of points wich it's
> > > the result of the comput of the Vref and Vi together. I don't know if
> > > i had to make a break instruction (like in other's languages) after
> > > the "If" instructions if i want the else-condition to be executed? ...
> > > (do you have some sujestions?)
>
> > I would have expected a code structure similar to this:
>
> > (NOTE: This is a very inefficient solution, and not the one suggested
> > earlier, but it is closer to the code snippet you posted originally, and
> > it does produce a plot.)
>
> > --
> > import numpy as np
> > import matplotlib.pyplot as plt
> > Vref = np.linspace(1,20, 100)
> > Vi = np.linspace(1,10,100)
>
> > for ref in Vref: # Loop over Vref and Vi
> >      for i in Vi:
> >          if  i > ref/4: # Compute V0
> >              V0 = 2*i-ref
> >          elif (-ref/4) <= ref and ref <= ref/4:
> >              V0 = 2*i
> >          elif i < -ref/4:
> >              V0 = 2*i+ref
> >          plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0
> > plt.show() # Display the plot in a window
> > --
>
> > > Anyway i have a picture of a tuturial that i found but in this forum i
> > > can't post it. That pic would show what a really want...
>
> > Can you give a link?
>
> > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the
> > > y-axis.
>
> > To me this sound like you want to make a 3D-plot, as there is the
> > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis?
>
> > > As i said, i have a good 2 pic of a doc that has the information about
> > > this ADC that i'm developing.
>
> > I looked on wikipedia
> > , and saw some
> > figures. Is any of those similar to what you look for?
>
> > I see that they have (Vi - Vref) on the x-axis, and the computed value
> > on the y-axis.
>
> > Regards
>
> > Johan
>
> Hi
>
> Yes those fig look's familiar to me but for now the objective its to
> get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC).
>
> I found inhttp://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF
> there are some fig and explanations on page's 9-13. Can you take a
> look there please?
>
> Also you can take a look inhttp://www.maxim-ic.com/app-notes/index.mvp/id/1023
> (I think there it´s more information than the first link i gave you).
>
> I'll be waiting for sujestions.
>
> Thank's- Ocultar texto citado -
>
> - Mostrar texto citado -

hi

This is how looks like the flash residue transference function that i
was talking about...

http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif

I'm suposed to obtain a figure like that in my plot.

Somebody help me please.

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


Re: Plot problem.. ?? No sign at all

2010-07-13 Thread Ritchy lelis
On 11 Jul, 17:39, Ritchy lelis  wrote:
> On 11 jul, 13:28, Johan Grönqvist  wrote:
>
>
>
>
>
> > 2010-07-11 02:12, Ritchy lelis skrev:
>
> > > On 7 jul, 08:38, Johan Grönqvist  wrote:
>
> > > About the plot draw it's a curve that it's a set of points wich it's
> > > the result of the comput of the Vref and Vi together. I don't know if
> > > i had to make a break instruction (like in other's languages) after
> > > the "If" instructions if i want the else-condition to be executed? ...
> > > (do you have some sujestions?)
>
> > I would have expected a code structure similar to this:
>
> > (NOTE: This is a very inefficient solution, and not the one suggested
> > earlier, but it is closer to the code snippet you posted originally, and
> > it does produce a plot.)
>
> > --
> > import numpy as np
> > import matplotlib.pyplot as plt
> > Vref = np.linspace(1,20, 100)
> > Vi = np.linspace(1,10,100)
>
> > for ref in Vref: # Loop over Vref and Vi
> >      for i in Vi:
> >          if  i > ref/4: # Compute V0
> >              V0 = 2*i-ref
> >          elif (-ref/4) <= ref and ref <= ref/4:
> >              V0 = 2*i
> >          elif i < -ref/4:
> >              V0 = 2*i+ref
> >          plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0
> > plt.show() # Display the plot in a window
> > --
>
> > > Anyway i have a picture of a tuturial that i found but in this forum i
> > > can't post it. That pic would show what a really want...
>
> > Can you give a link?
>
> > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the
> > > y-axis.
>
> > To me this sound like you want to make a 3D-plot, as there is the
> > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis?
>
> > > As i said, i have a good 2 pic of a doc that has the information about
> > > this ADC that i'm developing.
>
> > I looked on wikipedia
> > , and saw some
> > figures. Is any of those similar to what you look for?
>
> > I see that they have (Vi - Vref) on the x-axis, and the computed value
> > on the y-axis.
>
> > Regards
>
> > Johan
>
> Hi
>
> Yes those fig look's familiar to me but for now the objective its to
> get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC).
>
> I found inhttp://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF
> there are some fig and explanations on page's 9-13. Can you take a
> look there please?
>
> Also you can take a look inhttp://www.maxim-ic.com/app-notes/index.mvp/id/1023
> (I think there it´s more information than the first link i gave you).
>
> I'll be waiting for sujestions.
>
> Thank's- Ocultar texto citado -
>
> - Mostrar texto citado -

hi

This is how looks like the flash residue transference function that i
was talking about...

http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif

I'm suposed to obtain a figure like that in my plot.

Somebody help me please.

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


Re: round issue

2010-07-13 Thread Robin Becker

On 12/07/2010 19:59, Mark Dickinson wrote:


It does look inconsistent however, and it seems to me rounding and
interpolation should behave similarly.


Agreed.  In this case it's a minor bug that round(-9.85, 1)
produces -9.9 instead of -9.8;  both string formatting
and round should give -9.8.  This bug is fixed in Python
2.7 and in Python 3.x.

Note that in 2.7 there's still a legitimate difference: round
rounds halfway cases away from 0, while string formatting
rounds them to even.  So the following results are correct:

Python 2.7 (r27:82500, Jul 11 2010, 22:38:53)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

round(1.25, 1)

1.3

'%.1f' % 1.25

'1.2'

(1.25 *is* an exact halfway case, since it's exactly
representable as a binary float.)

In Python 3.x, round always does round-half-to-even, so
string formatting and round should agree (and if they don't,
it's definitely a bug: please report it!)

With all this said, asking for *decimal* rounding of
*binary* approximations to *decimal* halfway cases to give
the results you expect is ... optimistic, to say the least.
Use the decimal module if you care about which way
your (almost) halfway cases get rounded.

[I already replied to this earlier through Google groups, but
I'm not sure whether it went through properly.  Apologies
for the duplication, if so.]



yes thanks I saw that, but no problem about the dup. I suspect we might end up 
using some kind of fixed point.


Anyhow does anyone have a good algorithm for ensuring rounded percentages do add 
up to 100%? :) How about grouped percentages ie ensure the group sums and the 
groups display correctly in rounded form.

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


Cross-platform module that creates directory object with all file attributes

2010-07-13 Thread python
Any recommendations for a cross-platform module that creates a
directory object with not only file names, but file attributes as
well?

Use cases:
- Sort files by file size or date last modified
- Filter files by read-only status

I know I can use various standard library functions [1] to
construct such a class, but I'd rather avoid re-inventing the
wheel if at all possible. (I fear that this may be one of those
seemingly easy tasks that starts off simple and ends up taking a
lot more time to implement after real world refactoring).

Malcolm

[1] os.path.getmtime, os.path.getsize, os.W_OK, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lua is faster than Fortran???

2010-07-13 Thread Luis M . González
On Jul 4, 6:09 pm, Stephen Hansen  wrote:
> On 7/4/10 9:21 AM, sturlamolden wrote:
>
> > On 4 Jul, 14:29, David Cournapeau  wrote:
>
> >> Actually, I think the main reason why Lua is much faster than other
> >> dynamic languages is its size. The language is small. You don't list,
> >> dict, tuples, etc...
>
> > They have managed to combine list and dict into one type (table) that
> > does the job of both.
>
> You say "managed" as if it were some technical accomplishment, or that
> the result is able to actually do the job of both: neither of these
> assertions are true.
>
> Have you actually *used* Lua? I quite like the language in certain
> contexts where its appropriate, but if you've actually used it in real
> code and found tables to be at all a substitute for *either*
> dictionaries *or* lists, then I think somehow you've managed to actually
> miss using either data structure in Python to any real extent, somehow.
>
> Lua's tables are at very weak "dictionary-like" and "list-like" objects,
> which indeed have been folded into one. To the detriment of both, at
> least as far as they are an actual useful data structure.
>
> You can't even get the equivalent of len(dict) in it: you have to
> actually brute-force iterate the table and count manually. Even for a
> purely array-like table with onlyn umbered indexes, #table can be
> unreliable: its quite possible through normal list-like operations that
> you perform on it, it can end up with holes where #table will fail.
> Since it is *not* an list internally at *all*, but simply an associative
> array with numbered indexes.
>
> I could go on, and on, and on: but the fundamental *weakness* of Lua'
> data types as data-structures is irrefutable, from its tables to strings
> to numbers: they are incredibly weak on capabilities. You end up writing
> all kinds of "library" functions to just do the normal things that
> should be really easy to do.
>
> Now, of course, there's really good reason why Lua is so simple in these
> ways. Its entirely suitable for Lua as an embedded scripting language to
> keep things very light, so it can be simple and fast. Good for Lua to
> fill this niche superbly. But you can't start saying its simple
> alternatives are at all comparable to Python's extremely rich and
> capable data types.
>
> > And yes there are tuples.
>
> No, there isn't. There's ways to create a tuple-like-thing which kind of
> behaves like a braindead tuple, and functions have a positively bizarre
> capability of returning more then one value (and accepting variable
> values), so there's these points in the language where you have this
> sort of Immutable Sequence, but its opaque until you unwrap it -- and
> then it ceases to be.
>
> That's not the same thing as having an immutable sequence that you can
> store data in at your discretion, with a rich series of capabilities
> that you can leverage.
>
> > There are no classes, but there are closures and other building blocks
> > that can be used to create any object-oriented type system
>
> Not really.
>
> Above, I spoke of tables as data structures, things just storing data.
> But you're right, they are capable of more then that-- but you're
> over-selling just how far that capability goes, by a long shot (and
> underselling just how much work it takes to get it there).
>
> Yes, tables have a limited series of 'hooks' that you can tie into to
> alter their behavior, and through this you can simulate certain higher
> order type systems as defined in other languages. In fact, lots of
> people have done this: there's multiple "classy" libraries out there to
> bring some kind of Class-or-Object-Oriented-Programming to Lua.
>
> They work to varying degrees: but the hooks that Lua provides to tables
> is still significantly lacking to really replace Python's
> comprehensively dynamic object model, without a LOT of wasted cycles.
>
> For example, while you can use __newindex to 'catch' someone setting a
> new 'key' on a table, and and __index to replace or forward the actual
> lookup, you can't actually capture someone trying to set a value to a
> key which already exists. So, you end up having to do a full proxy
> approach, where your table never actually stores anything directly
> (except a reference to another hidden table), and so when someone goes
> to set something you have to set it on the proxied object instead.
> Because you can't let there ever be any real keys on the proxying /
> external table.
>
> So you're able to work around its lack a bit, to simulate something
> /like/ what it means to have __setattr__.
>
> But then you run into problems. There's no way now to iterate over the
> table now, because pairs() will only return your internal hidden keys
> that you're using to point to the proxied table (Although you can get
> around this with some more complexity by hiding said key into a
> closure-- but even then, you still can't iterate over the proxied
> table's keys instead).
>
> So what do you do? Well

executing python scripts within wx frames

2010-07-13 Thread Astan Chee

Hi,
I'm trying to make one of those frames thats similar to the wx python 
demo where a folder is filled with demo wx python scripts and there is 
one main script that opens the other ones in as different items in a 
tree/notebook.
I've gotten most of it figured out except the part where the scripts are 
executed in a wx frame. The difference between what I'm trying to do and 
the wx python demo one is that mine are generic scripts that output the 
results to std out/error (or whatever gets displayed in IDLE). Does 
anyone know how I can do this? Simulate a IDLE or python shell in one of 
the frames thats basically the output of whatever script has been 
selected to run?

It would be better if the solution was platform independent too.
Thanks for any suggestions
--
http://mail.python.org/mailman/listinfo/python-list


Re: Naming Conventions, Where's the Convention Waldo?

2010-07-13 Thread Neil Cerutti
On 2010-07-12, Steven D'Aprano  wrote:
> On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote:
>
>> On Jul 11, 3:03??am, "G??nther Dietrich"  wrote:
>> 
>>> So, it is not a disadvantage that the functions you listed above are
>>> named in this way. In the contrary, it is an advantage, as it keeps
>>> newcomers from using stupid variable names.
>> 
>> "int" for an Integer is stupid?
>> "list" for a List is stupid?
>> "str" for a String is stupid?
>> 
>> What am i missing?
>
> If you're going to use generic names, why type three or four letters when 
> one will do?
>
> i, j, k, m, n, p, q for ints.
> L, a, b, x for lists
> s, t, a, b for strings.
>
> If you don't want to use generic names, then int, list, str are useless 
> because they don't mean anything. You need something like:
>
> count_of_widgets
> list_of_widgets
> description

def map(function, list):
   # etc.

It's a slight annoyance, nothing more.

In the data I deal with, I get annoyed at needing to write
student_id instead of id, but it's not a huge issue. The big
consolation is that Python really doesn't care if I happen to
shadow a builtin name that I've never heard of. I forget, and use
id as a variable all the time, and nothing bad happens to me,
because I don't need the builtin function.

To see a really odd example of a similar name clash, create a tab
separated values file with a header line starting with ID (I get
lots of them in my work), and then open it with Excel (I don't
know which version has the most bizarre error message).

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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

2010-07-13 Thread Robert Kern

On 7/13/10 2:34 AM, Alf P. Steinbach /Usenet wrote:


PS: You (the reader) may be wondering, why why why Yet Another Python/C++
binding? Well, because I had this great name for it, "pyni", unfortunately
already in use. But cppy is very different from Boost: Boost is large, cppy is
tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating
argument conversion etc., while with cppy your Python design is exposed to C++
with no enforced arg conversions and such; Boost relies on canned magic,
difficult to subvert when it doesn't do what you want, while with cppy you are
(or, so far, I am) in control; and I suspect that the Boost Python binding,
relying on dynamic registries and stuff, is not all that efficient, while cppy
is as efficient as using the Python C API to create an extension. And besides,
cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-)


Note that Boost is not the only C++ binding out there. You may want to take a 
look at the old SCXX library, which appears to be similar in intent:


  http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html

matplotlib uses it heavily, and their included copy may include some more recent 
bugfixes and enhancements:


  http://matplotlib.sourceforge.net/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

2010-07-13 Thread Jonathan Lee
> Problem (C) is outside the realm of the C++ standard, since the C++ standard
> doesn't support shared libraries, and I've never actually used *nix shared
> libraries so I don't /know/...
>
> Is such dynamic initialization guaranteed?
>

Not guaranteed, though I think there's a combination of dlopen options
and gcc command line parameters that invoke this behavior. See the
second page of

   http://www.linuxjournal.com/article/3687

about auto-registration.

Personally, though, it never worked for me :/

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


Re: Check if a command is valid

2010-07-13 Thread Chris Rebert
On Tue, Jul 13, 2010 at 4:33 AM, Jean-Michel Pichavant
 wrote:
> Kenny Meyer wrote:
>> I have to figure out if a string is callable on a Linux system. I'm
>> actually doing this:
>>
>>    def is_valid_command(command):
>>        retcode = 100 # initialize
>>        if command:
>>            retcode = subprocess.call(command, shell=True)
>>        if retcode is 0:
>>            print "Valid command."
>>        else:
>>            print "Looks not so good..."
>>
>>    is_valid_command("ls")
>>
>> Never mind the code, because this is not the original.
>> The side effect of subprocess.call() is that it *actually* executes
>> it, but I just need the return code. What are better ways of doing
>> this?
>>
>
> I'm not sure I get exactly what you're searching for but here's something
> that may help.
>
> If you just whant to know if a command (without parameter) is a Linux
> command (either a builtin, alias of file exe) you can use the "where"
> command and inspect its return code, the command is not executed though.
>
>>where ls
> ls is an alias for ls --color=auto -F
> ls is /bin/ls
>>where apt-get
> apt-get is /usr/bin/apt-get
>>where doesnotexists
> doesnotexists not found
> zsh: exit 1

`where` seems to be a zsh built-in:
$ # I'm in UR bash
$ nonexistent
-bash: nonexistent: command not found
$ where bash
-bash: where: command not found

And not everyone has zsh installed, so...
I don't see why one shouldn't use the standard `which` *nix command instead.

Also, in retrospect, my suggestion should probably have checked the
return code rather than the output; more efficient and simple that
way.

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


Re: Errno 9] Bad file descriptor

2010-07-13 Thread joblack
Thanks for the answers so far. It's not my code I'm just curious how
that could happen:

Starting point:
...
self.status['text'] = 'Processing ...'
try:
cli_main(argv)
except Exception, e:
self.status['text'] = 'Error: ' + str(e)
return
...
cli_main:

keypath, inpath, outpath = argv[1:]
...
with open(inpath, 'rb') as inf:
serializer = PDFSerializer(inf, keypath)
with open(outpath, 'wb') as outf:
filenr = outf.fileno()
serializer.dump(outf)
return 0

PDFSerializer.dump:

def dump(self, outf):
self.outf = outf
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help choosing license for new projects

2010-07-13 Thread Ed Keith
--- On Mon, 7/12/10, Jake b  wrote:

> I'm starting a new python code
> project. What license do you suggest? I
> am searching, but I'm not finding a simple comparison of
> licenses. So
> I don't know which to use. Maybe MIT or Apache or LGPL or
> BSD?
> 
> Are there certain licenses to avoid using because of
> interaction
> problems between libraries using GPL2 / GPL3 / MIT / LGPL.
> / BSD with
> my own?

I generally avoid GPL, one of the reasons in interaction with other licenses.

> 
> I want:
> 1] Pretty much let anyone use it. Users do not have to
> include source
> code, as long as I get credit. (which I think normallly is
> a textfile
> with project url + name?)

This rules out GPL.

> 
> 2] (if it matters) I will be using different combinations
> of pyglet,
> pygame, wxPython, etc.

You will need to look at the individual licenses to see is they have iterations 
with other licenses.

> 
> 3] I want the option to use my own code in something
> commercial at a later date.
> 
> Does #3 complicate things, or is fine when including author
> info?

You can always re-license i, as long as you have the copyright to all the code. 
If other people have made contributions you will need to get their permission 
before you can re-license.


> 
> The choices for google code projects are:
>   Apache License 2.0

I do not use it, but it is good.

>   Eclipse license 1.0

I have not read this one, so I can not comment.

>   GPLv2
>   GPLv3

Incomparable with point one.

>   GNU lesser GPL

You would need to decide whether this is comparable with your first 
requirement. 

LGPL requires that users be able to relink with new versions of the library.  
This has always bothered me because relinking without recompiling (even when 
dynamic linking) in C/C++ is a good way to crash a program. But this should not 
be a problem with Python.

>   MIT license

This one is good.

>   Mozilla Public license 1.1

I avoid this one.

>   New BSD License

This one is good.

I personalty like the Boost License, it has very few restrictions. 

I hope this helps,

-EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com





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


Re: Issue with logging.config

2010-07-13 Thread Peter Otten
Joe Hughes wrote:

> I'm doing some work with logging.config and I'm running into an
> interesting situation.  I've run this by python-help, but that didn't help
> so I thought I would send to the list.  Here is the config file
> 
> [loggers]
> keys=root,log,syslog
> 
> [handlers]
> keys=console,log,syslog
> 
> [formatters]
> keys=rootFormat,logFormat,syslogFormat
> 
> [logger_root]
> level=DEBUG
> handlers=console
> 
> [logger_log]
> level=DEBUG
> handlers=log
> qualname=log
> 
> [logger_syslog]
> level=DEBUG
> handlers=syslog
> qualname=syslog
> 
> [handler_console]
> class=StreamHandler
> level=DEBUG
> formatter=rootFormat
> args=(sys.stdout,)
> 
> [handler_log]
> class=handlers.RotatingFileHandler
> level=DEBUG
> formatter=logFormat
> args=('E:\local\Logs\syslog_interface.txt', 'a', 1000, 10)
> propagate=0
> 
> [handler_syslog]
> class=handlers.SysLogHandler
> level=DEBUG
> formatter=syslogFormat
> host=141.232.41.205
> port=handlers.SYSLOG_UDP_PORT
> facility=LOG_LOCAL0
> 
args=(('141.232.41.205',handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_LOCAL0)
> 
> [formatter_rootFormat]
> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
> 
> [formatter_logFormat]
> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
> 
> [formatter_syslogFormat]
> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
> 
> and the python code
> 
> 
> # Imports
> 
> import logging
> import logging.config
> import os
> import re
> from threading import Thread
> 
> 
> # Constants
> 
> CONFIG_FILENAME = 'E:\local\Config\syslog_interface.conf'
> MCU_LIST_FILENAME = 'E:\local\Scada_Devices\mcu.txt'
> 
> 
> # Classes
> 
> 
> 
> # PingIt
> 
> class PingIt(Thread):
> def __init__(self, mcuIP):
> Thread.__init__(self)
> self.ip = mcuIP
> self.status = -1
> 
> def run(self):
> pinging = os.popen("ping -n 2 " + self.ip, 'r')
> 
> while 1:
> line = pinging.readline()
> 
> if not line:
> break
> 
> gotResponse = re.findall(PingIt.lifeline, line)
> 
> if gotResponse:
> self.status = int(gotResponse[0])
> 
> 
> # Main Routine
> 
> #
> # Get the logger configuration information
> #
> logging.config.fileConfig(CONFIG_FILENAME)
> 
> #
> # Check if running from command line and create logger
> #
> if os.environ.get('PROMPT'):
> #
> # create logger for output to stdout
> #
> logger = logging.getLogger('root')
> else:
> #
> # create logger for output to logfile
> #
> logger = logging.getLogger('log')
> 
> #
> # Create logger for syslog output
> #
> syslog = logging.getLogger('syslog')
> 
> #
> # Declare variables
> #
> PingIt.lifeline = re.compile(r"Received = (\d)")
> mcu_dict = {}
> ping_list = []
> status = ("Not responding", "Responded to only 1 ping of 2", "Alive")
> 
> #
> # Open the MCU file
> #
> mcu_file = open(MCU_LIST_FILENAME, 'r')
> 
> #
> # Loop through the contents of the MCU file and ping the IPs
> #
> for mcu in mcu_file:
> #
> # mcu file contents example
> # 192.168.97.227 MCU_HMSTD
> #
> # mcu_info[0] = MCU IP Address
> # mcu_info[1] = MCU Name
> #
> mcu_info = mcu.split()
> mcu_dict[mcu_info[0]] = mcu_info[1]
> current = PingIt(mcu_info[0])
> logger.info("Pinging " + mcu_info[1])
> ping_list.append(current)
> current.start()
> 
> #
> # Loop through ping list and print the response
> #
> for pinged in ping_list:
> pinged.join()
> logger.info("Status - " + mcu_dict[pinged.ip] + " is " +
> status[pinged.status]) syslog.info("Status - " + mcu_dict[pinged.ip] +
> " is " + status[pinged.status])
> 
> This is the output from the code
> 
> 2010-07-06 14:43:58,280 - log - INFO - Status - netboss2 is Not responding
> msg =  <134>2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is
> Not responding
> address =  ('141.232.41.205', 514)
> Traceback (most recent call last):
>   File "C:\Python31\lib\logging\handlers.py", line 786, in emit
> self.socket.sendto(msg, self.address)
> TypeError: sendto() takes exactly 3 arguments (2 given)
> 2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not
> responding
> 
> This is the handlers.py code from the library.  I added the print
> statement to figure out why it is asking for three args but only getting
> two.
> 
> Line 777 of handlers.

Re: multitask http server (single-process multi-connection HTTP server)

2010-07-13 Thread Luke Kenneth Casson Leighton
On Tue, Jul 13, 2010 at 1:30 AM, Tim Wintle  wrote:
> On Mon, 2010-07-12 at 23:28 +, Luke Kenneth Casson Leighton wrote:
>> On Mon, Jul 12, 2010 at 10:13 PM, geremy condra  wrote:
>> > On Mon, Jul 12, 2010 at 4:59 PM, lkcl  wrote:
>> >> there probably exist perfectly good web frameworks that are capable of
>> >> doing this sort of thing: i feel certain that twisted is one of them.
>> >> however, the original author of rtmplite decided to rip twisted out
>> >> and to use multitask.py and i'm one of those strange people that also
>> >> likes the idea of using 900 lines of awesome elegant code rather than
>> >> tens of thousands of constantly-moving-target.
>
> have you seen nagare:
> http://www.nagare.org/

 i have now! :)

 it uses stackless python, which is proobbably where the nonblocking
aspects come from.  going from there...

 
http://stacklessexamples.googlecode.com/svn/trunk/examples/networking/basicWebserver.py

 ah ha!  on the face of it, that does actually look like it achieves
the same sort of thing.

> I've not used it - but from my understanding it might be what you're
> looking for (for the http part at least).

 yes, for the http part: the rest - mmm no.

>> i hate to think how this would be done using any of the standard
>> MixIns.  even if you wrote a special MixIn which did single-instance
>> socket handling, you couldn't use it because the BaseHTTPHandler
>> doesn't "cooperate", it has a while True loop on serving connections
>> until they're closed.
>
> I started working on something like this once (but I still had threads)
> - afraid I can't find the code with it in right now. I think it was
> similar to what you're doing:
>
> at least 2 threads - one accepts requests, the other deals with them.

 ok, that sounds like the problem has moved: requests could still be
received rather than blocked at the TCP level, but they'd still not
actually get processed if the 2nd "dealing with it" thread was in
"serve_forever()" mode.  and because of HTTP Keep-Alives, when
close_connection=1 in the HTTPRequestHandler base class, that would
still be an issue.

 looking at that stackless basic web server example, i believe that
that's actually it: the concept of "tasklets", and that cooperative
scheduling loop:
while time.time() < t + delay:
stackless.schedule()

 multitask.py effectively does the same thing, but using "yield",
which is just amazing.

but... not being funny or anything, but basically i'm done already :)
multitaskhttpd works, it doesn't need stackless, i completed a JSONRPC
service last night, i'll add POST of multi-part forms today, and i
have everything that [GNUmed] will need.

i think convincing the gnumed team to get all their users to install
and use stackless python would be a bit of a hard sell.

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


Re: Check if a command is valid

2010-07-13 Thread Jean-Michel Pichavant

Kenny Meyer wrote:

Hello,

I have to figure out if a string is callable on a Linux system. I'm
actually doing this:

def is_valid_command(command):
retcode = 100 # initialize
if command:
retcode = subprocess.call(command, shell=True)
if retcode is 0:
print "Valid command."
else:
print "Looks not so good..."

is_valid_command("ls")

Never mind the code, because this is not the original.
The side effect of subprocess.call() is that it *actually* executes
it, but I just need the return code. What are better ways of doing
this?
  
I'm not sure I get exactly what you're searching for but here's 
something that may help.


If you just whant to know if a command (without parameter) is a Linux 
command (either a builtin, alias of file exe) you can use the "where" 
command and inspect its return code, the command is not executed though.


>where ls
ls is an alias for ls --color=auto -F
ls is /bin/ls
>where apt-get
apt-get is /usr/bin/apt-get
>where doesnotexists
doesnotexists not found
zsh: exit 1

retcode = subprocess.call(command, shell=True)

becomes

retcode = subprocess.call("where " + command)

JM

NB : this does not work with parameters appened to the command.


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


Calling LabVIEW VI from Python

2010-07-13 Thread Sathish S
Hi ppl,

I'm trying to call the LabVIEW VI's from python. I'm trying to use the Call
method exposed in the LabVIEW activex. this method expects the input values
to be passed as an array of reference. I'm passing a list to it, and I find
that the list is unchanged. Here is my code:

import win32com.client
from win32com.client import gencache
gencache.EnsureModule('{8C8AAA4D-51FE-41DE-85CF-8E6929409012}', 0, 5, 5)
Application =  win32com.client.Dispatch("LabVIEW.Application")


InputNames = ("Cluster","Array","Numeric","Output")

Cluster=("abcd","1")
Array=("1","2.97")
Output=()
Inputs= (Cluster,Array,"5",Output)

Application._FlagAsMethod("GetVIReference")
VirtualInstrument = Application.GetVIReference('C:\Test.vi');
VirtualInstrument._FlagAsMethod("OpenFrontPanel")
VirtualInstrument.OpenFrontPanel(True,3)
VirtualInstrument._FlagAsMethod("Call")
VirtualInstrument.Call(InputNames,Inputs)

print(Output)
print("Output")
VirtualInstrument._FlagAsMethod("GetControlValue")
print(VirtualInstrument.GetControlValue("Output"))
Application._FlagAsMethod("Quit")
Application.Quit();

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


Re: integer >= 1 == True and integer.0 == False is bad, bad, bad!!!

2010-07-13 Thread Jean-Michel Pichavant

Steven D'Aprano wrote:

On Mon, 12 Jul 2010 19:28:28 -0600, Ian Kelly wrote:

  

On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano
 wrote:


I prefere to explicitly write what I want to test:

if myInt <> 0:


I would argue against that. Why do you, the coder, care about the
specific details of treating ints in a boolean context? The int type
itself knows, leave the decision to it.
  

I think you're missing the point.  He's not using ints in a boolean
context.  If it were a boolean context, he would be using bools in the
first place.



Of course he is -- he's branching on an int (a boolean context), and 
explicitly writing out the test as myInt <> 0. In fact, that test could 
just as easily be written as bool(myInt), which has the benefit of being 
even more explicit that you want a bool.


I never use integers as boolean value. There is no need to in python, 
since True and False are available. I use integers only as integers 
(hope you see what i mean, i.e to count a number of...).

Knowing that, the only meaning possible would be

if myInt:

equals to

if myInt is not None:

in other words, if myInt is a meaningful integer.

But this is wrong in python, as "if myInt" means "if myInt <>None and 
myInt <>0" (I experienced bug because of my wrong understanding).
Fine I can live with that. It forces me to write explicitly the 
condition I require, which is a good thing (explicit >> implicit).


JM

PS : you made a typo, myInt <> 0 does not equal to bool(myInt) (when 
myInt is None)



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


Re: Why doesn't python's list append() method return the list itself?

2010-07-13 Thread Gregory Ewing

John Nagle wrote:

Arguably, if a function just does a "return",
it should be an error to try to use its return value.


It's been suggested at least once before that the
default return value for a function should be some
special value that raises an exception if you try
to do anything with it except throw it away.

Unfortunately, the existence of such a value would
cause headaches for things like debuggers that need
to be able to deal with anything at all without
blowing up.

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


Re: simples setup for an wsgi https server in python

2010-07-13 Thread Дамјан Георгиевски
> It seems, that wsgiref.simple_server.make_server can only create an
> http server.
> 
> What I wondered would be how to easiest create an https server, that
> supports wsgi modules

PythonPaste has a WSGI server that supports https
http://pythonpaste.org/modules/httpserver.html#module-paste.httpserver

Werkzeug too
http://werkzeug.pocoo.org/documentation/0.6.2/serving.html#ssl


I'd strongly suggest you to have both of those libraries installed, they 
have a lot of WSGI goodies :)

-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Scarlett Johansson: You always see the glass half-empty.
Woody Allen: No. I see the glass half-full... but of poison.

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


Re: multitask http server (single-process multi-connection HTTP server)

2010-07-13 Thread Tim Wintle
On Mon, 2010-07-12 at 23:28 +, Luke Kenneth Casson Leighton wrote:
> On Mon, Jul 12, 2010 at 10:13 PM, geremy condra  wrote:
> > On Mon, Jul 12, 2010 at 4:59 PM, lkcl  wrote:
> >> there probably exist perfectly good web frameworks that are capable of
> >> doing this sort of thing: i feel certain that twisted is one of them.
> >> however, the original author of rtmplite decided to rip twisted out
> >> and to use multitask.py and i'm one of those strange people that also
> >> likes the idea of using 900 lines of awesome elegant code rather than
> >> tens of thousands of constantly-moving-target.

have you seen nagare:
http://www.nagare.org/

I've not used it - but from my understanding it might be what you're
looking for (for the http part at least).

> i hate to think how this would be done using any of the standard
> MixIns.  even if you wrote a special MixIn which did single-instance
> socket handling, you couldn't use it because the BaseHTTPHandler
> doesn't "cooperate", it has a while True loop on serving connections
> until they're closed.

I started working on something like this once (but I still had threads)
- afraid I can't find the code with it in right now. I think it was
similar to what you're doing:

at least 2 threads - one accepts requests, the other deals with them.

 * overload BaseHTTPServer.process_request so it just adds connections
to a queue.

 * worker threads fetch connections from the queue and starts working on
them. when they want to give up control they raise an exception to
bubble back up, and the connection is re-added to the queue along with
any persistent data.

I seem to remember the annoying bit being having to override
SocketServer.finish_request to use an existing handler.

- you can fairly easily limit that to process a single session at a time
with a shared dictionary or similar.


The reason I was doing it was for work that was cached for a short time,
but took a while on cache misses - If I noticed that another thread was
currently updating the cached version then I raised an exception. (I had
code that unlocked the gil, so multi-threaded made sense)


Tim




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


Re: Worship We Must

2010-07-13 Thread geremy condra
On Tue, Jul 13, 2010 at 1:17 AM, Johannes Kleese  wrote:
> On 13.07.2010 10:00, geremy condra wrote:
>> On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese  wrote:
>>> On 13.07.2010 05:16, nais-saudi wrote:
 The submission of man to His Creator is the essence of Islam.
>>>
>>> The submission of topic-related Bla to His Newsgroup is the essence of
>>> Posting.
>>>
>>> Learn it. Know it. Live it.
>>
>> The submission of replies to trolls and spammers is the essence of the 
>> internet.
>>
>> Live long. And Prosper.
>
> The submission of troll feed to the Internet is the essence of Bla.
>
> Now do the truffle shuffle!

I'm sure you're aware that the shuffle of so-called 'conflict
truffles' is highly illegal, not to mention unethical. I'm shocked you
would advocate it publicly.

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


Re: Worship We Must

2010-07-13 Thread Johannes Kleese
On 13.07.2010 10:00, geremy condra wrote:
> On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese  wrote:
>> On 13.07.2010 05:16, nais-saudi wrote:
>>> The submission of man to His Creator is the essence of Islam.
>>
>> The submission of topic-related Bla to His Newsgroup is the essence of
>> Posting.
>>
>> Learn it. Know it. Live it.
> 
> The submission of replies to trolls and spammers is the essence of the 
> internet.
> 
> Live long. And Prosper.

The submission of troll feed to the Internet is the essence of Bla.

Now do the truffle shuffle!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Worship We Must

2010-07-13 Thread geremy condra
On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese  wrote:
> On 13.07.2010 05:16, nais-saudi wrote:
>> The submission of man to His Creator is the essence of Islam.
>
> The submission of topic-related Bla to His Newsgroup is the essence of
> Posting.
>
> Learn it. Know it. Live it.

The submission of replies to trolls and spammers is the essence of the internet.

Live long. And Prosper.

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


Re: Cpp + Python: static data dynamic initialization in *nix shared lib?

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

* geremy condra, on 09.07.2010 23:43:

On Fri, Jul 9, 2010 at 5:22 PM, Ian Collins  wrote:

On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote:


[Cross-posted comp.lang.python and comp.lang.c++]

I lack experience with shared libraries in *nix and so I need to ask...

This is about "cppy", some support for writing Python extensions in C++
that I just started on (some days ago almost known as "pynis" (not funny
after all)).

For an extension module it seems that Python requires each routine to be
defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern
"C"' and C++ linkage, using a routine declared as 'static' in a class as
a C callback, formally they're two different kinds, and I seem to recall
that /some/ C++ compiler balks at that kind of mixing unless specially
instructed to allow it. Perhaps it was the Sun compiler?


Yes, it will (correctly) issue a warning.

As the is a bit OT, contact me directly and we can work through it.  I have
had similar fun and games adding PHP modules!


I'd appreciate it if you'd either leave this on-list or cc me in on this, as
I'm working through a similar issue.


Well, we got no further, but I know of three solutions:

  A) Punting: just say that the compiler has to support C++/C function type
 mingling.
 -> Perhaps the practical solution, but formally unsafe.

  B) On the script side of things, delegate all calls to single Mother Of All
 C func downcaller that supplies as extra arg an id of the C++ function.
 -> Micro-level inefficient but easy to use and formally correct.

  C) Let the user define the C linkage function wrappers via macros.
 -> Efficient and formally correct but exposes ugly macro names.

I chose (C).

I believe Boost's Python binding uses (A), or perhaps (B).


Cheers,

- Alf

PS: You (the reader) may be wondering, why why why Yet Another Python/C++ 
binding? Well, because I had this great name for it, "pyni", unfortunately 
already in use. But cppy is very different from Boost: Boost is large, cppy is 
tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating 
argument conversion etc., while with cppy your Python design is exposed to C++ 
with no enforced arg conversions and such; Boost relies on canned magic, 
difficult to subvert when it doesn't do what you want, while with cppy you are 
(or, so far, I am) in control; and I suspect that the Boost Python binding, 
relying on dynamic registries and stuff, is not all that efficient, while cppy 
is as efficient as using the Python C API to create an extension. And besides, 
cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-)


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


Re: Worship We Must

2010-07-13 Thread Johannes Kleese
On 13.07.2010 05:16, nais-saudi wrote:
> The submission of man to His Creator is the essence of Islam. 

The submission of topic-related Bla to His Newsgroup is the essence of
Posting.

Learn it. Know it. Live it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write a .txt file

2010-07-13 Thread Cameron Simpson
On 13Jul2010 02:46, Jia Hu  wrote:
| Hi:
| 
| Do you mean the following code?
| 
| #!/usr/bin/python
| # OS: Ubuntu
| import subprocess
| fileName = open ('final.txt', 'a')
| fileName.write ('%s %s %s \n' % (12,25,9))
| 
| fileName.flush()   # add
| fileName.close()  # add

You should not need the .close().

| desLrr = subprocess.Popen('ls -a >> final.txt', shell=True)  # change to "ls
| -a"

You're still not waiting for the Popen subprocess to finish before
continuing.

| fileName=open ('final.txt', 'a')

You shouldn't need the open() if you skip the .close()

| fileName.seek(0,2)

If you _do_ do an open(..., "a") then you don't need the seek - append
mode will write at the end for you.

| fileName.write ('%s %s %s \n' % (85,25,12))
| fileName.close()
| 
| I run that, the result showed the list of file is located after the number
| list 85 25 12
| Is that possible that I put the fileName.flush() in a wrong position ?
| I am new to Python and do not quite understand the "flush" concept.

First: please don't top post. Post below the relevant points as I do
above, like a conversation. That way it is clear exactly what each
remark is for.

Second: "flush" is a general idea used with buffers.

When you .write() to a file the data does not normally go directly to
disc.  This is because a real write to the disc is expensive in time
(the CPU is much much faster than a hard drive).

Also, a OS-level "write", which transfers the data from your program into
the OS's buffers (where it queues, for eventual writing to the disc)
is _also_ a comparitively expensive operation. So when you .write()
in python (or C using stdio, and in many other languages) the data is
normally kept in a memory buffer inside your program. Only when that
buffer is filled is an OS-level "write" done. In this way, OS calls are
few. This is a performance gain.

So, in your program, when you .write() your first line of numbers
the data has not been handed to the OS at all, and therefore the
"final.txt" file has not seen it. A .flush() call is an explicit request
to empty the buffer, making an OS-level "write" immediately. In your
program, this is necessary to get the data to "final.txt" before the
"echo" or "ls" commands are run.

If you .close() a file, that also empties the buffer. But it also closes
the file! SO you need to re-open it. For your purposes, a .flush() is
enough and leaves the file open for you to continue using it later.

Regarding the .seek(): after the "echo" or "ls" command has run
the file  has grown. Python's "file" object does not know the file has
grown because it was not involved. So a .seek(0 is needed to position
Python's .write() location to the end of the file instead of where it
though things were.

Um. Because you have opened the file in 'a' mode you should not need the
.seek() - an "append" mode file will always write to the end of the
file.

So: your first problem only requires a .flush(), to empty the buffer
before "echo" or "ls" runs. However, you still have not waited for the
"echo" or "ls" to finish - Popen kicks the command off, but it will run
at the same time as your program! Call:

  desLrr.wait()

to wait for the "echo" or "ls" to finish before continuing!

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Quick Guide to Resources to break crypto systems of given strength:
Difficulty Resources required
 2**0  Pencil and paper
 2**8  Pencil and paper and a lot of patience
 2**16 Warez d00d with a Commodore 64
 2**32 Amateur with an average PC
 2**40 Smart amateur with a good PC
 2**56 Network of workstations, custom-built hardware
 2**64 Thousands of PCs working together for several years
 2**80 NSA, Microsoft, the Illuminati
 2**128Cubic kilometers of sci-fi nanotech
 2**160Dyson spheres
Eddy L O Jansson and Matthew Skala, from:
http://hem.passagen.se/eddy1/reveng/cp4/cp4break.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errno 9] Bad file descriptor

2010-07-13 Thread Cameron Simpson
On 11Jul2010 17:48, joblack  wrote:
| I get sometimes a
| 
| Errno 9 Bad file descriptor
| 
| the code is too long to show it here but what are the circumstances
| this could happen? A web search showed nothing.
| 
| I have especially the feeling Python 2.6 has some problems with
| Unicode ... and might not find the file. Is that possible?

You get a UNIX "bad file descriptor" error when you try to use an
invalid file descriptor number. The typical occasion is when you open a
file, use it, close it, and then try to continue to use it.

I would suspect you have performed that sequence in some way.

But you should really try to produce a small sequence of code that shows
the error. That way you can post it here, and for extra value you may
reduce it to the point where you realise what you have done wrong, since
the failing code is then small enough for you to examine easily.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

There is a chasm
of carbon and silicon
the software can't bridge
- Haiku Error Messages 
http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html
-- 
http://mail.python.org/mailman/listinfo/python-list