Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Marc 'BlackJack' Rintsch
On Sat, 23 Feb 2008 17:19:47 -0800, thebjorn wrote:

> On Feb 23, 6:18 pm, Paul Hankin <[EMAIL PROTECTED]> wrote:
>
>> IMO Jason's solution of testing containment in a generator is better
>> (more readable).
>> if element[0] not in (x[0] for x in a):
>> a.append(element)
> 
> It may be more readable (although that's debatable), but it always
> traverses the entire list.

The ``not in`` stops if the element is found.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Using lambda [was Re: Article of interest: Python pros/cons for the enterprise]

2008-02-23 Thread Steven D'Aprano
On Sat, 23 Feb 2008 19:35:30 -0800, Jeff Schwab wrote:

> Every time somebody uses
> lambda here, they seem to get a bunch "why are you using lambda?"
> responses.

Not from me.

I even use "named anonymous functions" *cough* by assigning lambda 
functions to names:

foo = lambda x: x+1



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


Re: asynchronous alarm

2008-02-23 Thread Paul Rubin
Alan Isaac <[EMAIL PROTECTED]> writes:
> while True:
> sys.stdout.write('\a')
> sys.stdout.flush()
> time.sleep(0.5)
> 
> I want to add code to allow me to turn off this alarm and then
> interact with the program in its new state (which the alarm alerts
> me to).
> 
> Question: how best to do this mostly simply in a console application
> and in a Tkinter application?

You'd usually use another thread to tell the loop when to exit,
or run the loop itself in another thread:

import sys,time
from threading import Event, Thread

def f(event):
   while not event.isSet():
   sys.stdout.write('\a')
   sys.stdout.flush()
   time.sleep(0.5)

a = Event()
Thread(target=f, args=(a,)).start()
raw_input('hit return when done: ')
a.set()

see the docs for the threading module, to make sense of this.
-- 
http://mail.python.org/mailman/listinfo/python-list


asynchronous alarm

2008-02-23 Thread Alan Isaac
Goal: turn off an audible alarm without
terminating the program.  For example,
suppose a console program is running::

while True:
sys.stdout.write('\a')
sys.stdout.flush()
time.sleep(0.5)

I want to add code to allow me to turn off
this alarm and then interact with the
program in its new state (which the alarm
alerts me to).

Question: how best to do this mostly simply
in a console application and in a Tkinter application?

I realize this must be a standard problem so that there
is a good standard answer.  Here are some naive solutions
that occured to me.

Solution C1 (console): poll keyboard inside the loop.
E.g., http://effbot.org/librarybook/msvcrt.htm>
Problem: no platform independent way to do this?

Solution C2 (console): handle KeyboardInterrupt.
An ugly hack. But works fine.

Solution C3 (console): start alarm in one thread
and wait for raw_input.  (Should that be in another
thread?  It does not seem to matter.)
This seems plausible, but I know nothing about threads
except that nonprogrammers tend to make mistakes
with them, so I hesitate.

Solution G1 (gui): start alarm in a thread but
include a test for a variable that can be set
by a button push?  (Sounds plausible etc.)

Solution G2 (gui): start alarm but
somehow let Tkinter listen for an event
without programming any threads. Possible??

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


Re: Official IRC channel for Python?

2008-02-23 Thread Paul Rubin
Paul Rudin <[EMAIL PROTECTED]> writes:
> You can't join #python on freenode without identifying with nickserv
> first.

Oh, interesting and annoying.  I don't know if I've noticed that before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Official IRC channel for Python?

2008-02-23 Thread Paul Rudin
Paul Rubin  writes:

> "Manu Hack" <[EMAIL PROTECTED]> writes:
>> > Really? maybe I'm been blocked from it...
>> >  thanks.
>> 
>> Maybe you need your nick name to be recognized.  You need to register
>> your nickname somewhere.
>
> On freenode, you need to register your nick in order to send private
> messages, but you can join a channel with an unregistered nick.  If
> the nick is registered to someone else, you get a message saying to
> identify (which in this situation actually means change nicks, since
> you presumably don't have the password to identify as the other
> person).
>

You can't join #python on freenode without identifying with nickserv
first.

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


Re: Official IRC channel for Python?

2008-02-23 Thread Manu Hack
On 23 Feb 2008 22:21:59 -0800, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Manu Hack" <[EMAIL PROTECTED]> writes:
>  > > Really? maybe I'm been blocked from it...
>  > >  thanks.
>  >
>
> > Maybe you need your nick name to be recognized.  You need to register
>  > your nickname somewhere.
>
>  On freenode, you need to register your nick in order to send private
>  messages, but you can join a channel with an unregistered nick.  If
>  the nick is registered to someone else, you get a message saying to
>  identify (which in this situation actually means change nicks, since
>  you presumably don't have the password to identify as the other
>  person).
>
>  Manu, what happens when you try to join?  What happens if you change
>  nicks?  Can you connect to freenode at all?  Can you join other
>  channels?
>  --

For most of the channels there is not problem joining.  Only the
python channel I need to use message nickserv to identify in order to
join.  I'm not very into the irc thing so after the first time I
register the nickname and then I don't seem to remember  where I
registered.

LIke if I run /join python in irssi it gives  #python You need to be
identified to join that channel

so I need to run /msg nickserv identify my_password

and then I can join #python by running /join python.

Manu

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


Re: Seeing "locals()" from imported function

2008-02-23 Thread 7stud
On Feb 23, 11:41 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On Feb 23, 10:06 pm, "Luis M. González" <[EMAIL PROTECTED]> wrote:
>
>
>
> > I apologize for this very basic question, but I can't understand how
> > this works...
> > I want to import a function from module B into my main script A, so
> > this function can see and use the locals from A.
>
> > For example:
>
> > def auto():
> >     urls = ['/', 'index']
> >     for k,v in __main__.locals().items():         #  these "locals"
> > are the ones of the main script
> >             if isinstance(v,type) and k != 'index':
> >                     urls.append('/%s' %k)
> >                     urls.append(k)
> >     return tuple(urls)
>
> > Of course this doesn't work...
>
> > Any hint?
>
> Yes, define your functions so that they get all the input they need
> from the arguments that are passed in.

For instance:

#file1.py:
def auto(a_list):
for elmt in a_list:
print elmt

#file2.py:
import file1

file1.auto(whatever)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seeing "locals()" from imported function

2008-02-23 Thread 7stud
On Feb 23, 10:06 pm, "Luis M. González" <[EMAIL PROTECTED]> wrote:
> I apologize for this very basic question, but I can't understand how
> this works...
> I want to import a function from module B into my main script A, so
> this function can see and use the locals from A.
>

> For example:
>
> def auto():
>     urls = ['/', 'index']
>     for k,v in __main__.locals().items():         #  these "locals"
> are the ones of the main script
>             if isinstance(v,type) and k != 'index':
>                     urls.append('/%s' %k)
>                     urls.append(k)
>     return tuple(urls)
>
> Of course this doesn't work...
>
> Any hint?
>

Yes, define your functions so that they get all the input they need
from the arguments that are passed in.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Official IRC channel for Python?

2008-02-23 Thread Paul Rubin
"Manu Hack" <[EMAIL PROTECTED]> writes:
> > Really? maybe I'm been blocked from it...
> >  thanks.
> 
> Maybe you need your nick name to be recognized.  You need to register
> your nickname somewhere.

On freenode, you need to register your nick in order to send private
messages, but you can join a channel with an unregistered nick.  If
the nick is registered to someone else, you get a message saying to
identify (which in this situation actually means change nicks, since
you presumably don't have the password to identify as the other
person).

Manu, what happens when you try to join?  What happens if you change
nicks?  Can you connect to freenode at all?  Can you join other
channels?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Official IRC channel for Python?

2008-02-23 Thread Manu Hack
On Sun, Feb 24, 2008 at 12:16 AM, js <[EMAIL PROTECTED]> wrote:
> Really? maybe I'm been blocked from it...
>  thanks.

Maybe you need your nick name to be recognized.  You need to register
your nickname somewhere.

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


Re: Official IRC channel for Python?

2008-02-23 Thread js
No. Actually, i'm very new to IRC.

On Sun, Feb 24, 2008 at 2:55 PM, Steve Holden <[EMAIL PROTECTED]> wrote:
> js wrote:
>  > Really? maybe I'm been blocked from it...
>  > thanks.
>  >
>  Currently 479 users. Have you been blocked from many channels?
>
>  regards
>   Steve
>  --
>  Steve Holden+1 571 484 6266   +1 800 494 3119
>  Holden Web LLC  http://www.holdenweb.com/
>
>  --
>
>
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-23 Thread Steve Holden
Tamer Higazi wrote:
> Hi!
> My brother is dreaming and dying for python and swear that it is the
> ultimate killer application language.
> 
> I am coding Webapplication in PHP5 and ask myself if for python are:
> 
> - application frameworks like: "Zend Framework" and ezComponents
> - What is the Zope Applikation Server? Is it also a Webserver like the
> Apache or Tomcat Webserver?
> 
You can write web servers completely in Python. There are many such, and 
  there are also a number of web frameworks, the two best-known  being 
TurboGears and Django.

> - Is there a way of Round Tripp engineering based on UML XMI Files to
> generate python files (with it's dependencies) 
> 
I'll let the UML users answer this one, but UML is certainly supported, 
and quite a few commercial tools are starting to support Python.

> - Let us assume, I want to write a Web application in Python (what I did
> now in PHP5) and want to distribute my work under commercial usage.
> 
> Can I encrypt my work and generate Licence Files for Customers who would
> purchase my End-Sollution like with:
> 
> - Zend Encoder
> - IonCube
> - SourceGuardian
> 
> ???
> 
> I just ask, because I have finished a product and will encrpyt it with
> the Ioncube encoder based on PHP5.
> 
The Python world doesn't invest greatly in source encryption, so you may 
not get many helpful suggestions. I am sure, however, that you will get 
a few people suggesting your code is rather less likely to need 
protection (and be worthy of it) than you think.

> for answering all my Questions, I would thank you guys very much.
> 
regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
> > languages should be a red flag in a design review, and a factor in
> > determining product liability if a program misbehaves.
> 
> Your product gets the benefit of the doubt if it was written in
> Python, but not if written in C?  What if the Python interpreter
> screws up?

The Python interpreter has been run in production for over a decade
modulo comparatively small incremental changes, heavily reviewed and
tested by multiple people, between versions.  It's likely to be more
reliable than any one-off C program of comparable size.  Further, for
a C application, the analogous situation to the Python interpreter
screwing up would be the C compiler screwing up (generating wrong
code).  They have that possibility in common.  But for the C
application, the screwup can be in two places (the compiler or the
application) while Python limits it to one place.  The principle here
is to minimize the size of the so-called trusted codebase.

Either way, the ongoing effort (PyPy) to write Python in Python will
probably improve Python's reliability.

> In the first place, you're not distinguishing C from C++.  I know you
> think they're the same.  They're not.  Python's array bounds checking
> is done in C, as is the case for traditional OS kernels.  C++, like
> Python, offers you container types that "smell" like arrays, but do
> safety checking under the hood; 

Not as long as you can have pointers to those objects that contain
naked memory addresses which can be invalid.

> Buffer overflows are the result of developers deliberately
> choosing not to use bounds-checking.

Yes, the most common way that choice is expressed is by choosing to
code in C or C++ in the first place.

> to enable that access. Even then you're trusting the hardware
> developers to check for invalid indexes (bus errors and seg faults).
> Should we outlaw computer hardware, too?

Again, the concept is "best practices" which is an engineering term,
not a mathematical one.  Best practices are not infallible, they're
just the best normal practices observed in real-world projects of
similar scope.

> "Best practices," though, is usually just what managers say when
> they mean "what everybody else is doing."  

No really, among other things it includes following standards that
are designed by people who know what they're doing.  That actually
means something.  

> The idea is that if you're a manager who sticks to "best practices,"
> then if everything goes to hell, the problem can't be linked
> specifically to you.

That is a very valuable aspect.  If I'm writing an encryption program,
best practice is to use a standard algorithm like AES instead of
concocting my own algorithm.  If something does turn out to be wrong
wtih AES that makes my program fail, I'm very glad to be able to point
to the rigorous standardization process that AES went through and say
that I made the best choice I could with available information.  If
for some reason I think there's an 0.002% chance that something is
wrong with AES but only an 0.001% chance that something is wrong with
my home-cooked algorithm, AES is still the obvious choice.

Same thing with internet applications, I'm much better off writing in
a type-safe language than relying on the intricacies of my unique
application code to behave properly in a language without type-safety.

> The only way to keep them from writing code that will blow up
> at run-time is to impose formal verification of their program, every
> time they change it; that's what the C++ static type system lets you
> do, in a limited and easily subverted way. 

Why not get rid of the limitations and easy subversions?  And I can't
agree that using a basic type like "int x[10];" is somehow a
subversion.  Subversion means you have to go to some lengths to break
the type safety.

> Even if you could somehow remove every feature open to potential
> abuse, and thereby dodo-proof the language, the result would be a
> slow, weak, ugly language that non-dodos would not want to use.  But
> hey, at least it would still be "best practice."

Enforcing type safety is certainly an enormous step towards
dodo-proofing a language, it hugely helps the reliability of real
programs, and is one of the reasons Python and Java are displacing C++.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Official IRC channel for Python?

2008-02-23 Thread Steve Holden
js wrote:
> Really? maybe I'm been blocked from it...
> thanks.
> 
Currently 479 users. Have you been blocked from many channels?

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

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


PHP Developer highly interested in Python (web development) with some open questions...

2008-02-23 Thread Tamer Higazi
Hi!
My brother is dreaming and dying for python and swear that it is the
ultimate killer application language.

I am coding Webapplication in PHP5 and ask myself if for python are:

- application frameworks like: "Zend Framework" and ezComponents
- What is the Zope Applikation Server? Is it also a Webserver like the
Apache or Tomcat Webserver?

- Is there a way of Round Tripp engineering based on UML XMI Files to
generate python files (with it's dependencies) 

- Let us assume, I want to write a Web application in Python (what I did
now in PHP5) and want to distribute my work under commercial usage.

Can I encrypt my work and generate Licence Files for Customers who would
purchase my End-Sollution like with:

- Zend Encoder
- IonCube
- SourceGuardian

???

I just ask, because I have finished a product and will encrpyt it with
the Ioncube encoder based on PHP5.

for answering all my Questions, I would thank you guys very much.



Tamer Higazi

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


Re: Official IRC channel for Python?

2008-02-23 Thread js
Really? maybe I'm been blocked from it...
thanks.

On 23 Feb 2008 20:37:42 -0800, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> js <[EMAIL PROTECTED]> writes:
>  > I tried #python irc.freenode.net
>
>  That has always worked for me.
>
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Paul Rubin wrote:
> Jeff Schwab <[EMAIL PROTECTED]> writes:
>>> there's actually a published book specifically about C++ pitfalls.
>> Mercy, a whole book?
> 
> http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?EAN=9780201179286
> 
>>> C and C++ should practically be outlawed at this point.
>> On what grounds?  "I don't approve of the programming language you're
>> using.  Cease and desist.  Nyah!"
> 
> Well, "outlawed" of course is a figure of speech; however use of those
> languages should be a red flag in a design review, and a factor in
> determining product liability if a program misbehaves.

Your product gets the benefit of the doubt if it was written in Python, 
but not if written in C?  What if the Python interpreter screws up?


> Think of all
> the buffer overflow exploits against Microsoft Windows programs that
> couldn't have happened if Microsoft had used safer languages.  There
> was clearly a failure to use best engineering practices.

In the first place, you're not distinguishing C from C++.  I know you 
think they're the same.  They're not.  Python's array bounds checking is 
done in C, as is the case for traditional OS kernels.  C++, like Python, 
offers you container types that "smell" like arrays, but do safety 
checking under the hood; the C++ bounds checks, unlike the Python 
checks, are done in-language.  If C++ were marketed like Java, people 
might advertise that the C++ standard containers are "pure C++," or that 
"C++ is written in C++".

Secondly, you're going to have a hard time writing an operating system 
kernel without fixed-size buffers.  You have to read data in chunks of 
some size.  It's fine to say that buffer access should be checked to 
make sure indexes should be in range, but somebody actually has to write 
the code to do the checking, and then programmers have to use it. 
Buffer overflows are the result of developers deliberately choosing not 
to use bounds-checking.

In Python, somebody could still define a monolithic array, use different 
parts of it to represent different things, and then "oops" lose track of 
their index, thereby overwriting one part of the array with data that 
should have stayed in the other part.  If you're thinking "Yeah, they 
*could*, but only a dodo would do that, and it's not Python's fault that 
the programmer did something bone-headed," then you're beginning to get 
the picture.  If you somehow wrote an OS kernel in Python, and the 
above-mentioned bone-headedness took place, then there would be no 
"lower level" to save your OS from having a dangerous security hole. 
Even if the hardware supported checked access for large quantities of 
arbitrarily sized arrays, somebody would have to enable that access. 
Even then you're trusting the hardware developers to check for invalid 
indexes (bus errors and seg faults).  Should we outlaw computer 
hardware, too?

Thirdly, you mentioned a "failure to use best engineering practices." 
If you mean there was a failure to design and implement a bug-free 
operating system, then by Jiminy, you're right.  "Best practices," 
though, is usually just what managers say when they mean "what everybody 
else is doing."  The idea is that if you're a manager who sticks to 
"best practices," then if everything goes to hell, the problem can't be 
linked specifically to you.

Server-side Python is now, at this very moment, becoming acceptable as 
"best practice."  It's no better or worse for this; it's just that a lot 
more uninspired, uncreative programmers are about to start using it.  Do 
not underestimate their ability to make any programming language look 
bad.  If you make it fool-proof, they'll build a better fool.  The only 
way to keep them from writing code that will blow up at run-time is to 
impose formal verification of their program, every time they change it; 
that's what the C++ static type system lets you do, in a limited and 
easily subverted way.  Even if you could somehow remove every feature 
open to potential abuse, and thereby dodo-proof the language, the result 
would be a slow, weak, ugly language that non-dodos would not want to 
use.  But hey, at least it would still be "best practice."
-- 
http://mail.python.org/mailman/listinfo/python-list


Seeing "locals()" from imported function

2008-02-23 Thread Luis M. González
I apologize for this very basic question, but I can't understand how
this works...
I want to import a function from module B into my main script A, so
this function can see and use the locals from A.

For example:

def auto():
urls = ['/', 'index']
for k,v in __main__.locals().items(): #  these "locals"
are the ones of the main script
if isinstance(v,type) and k != 'index':
urls.append('/%s' %k)
urls.append(k)
return tuple(urls)

Of course this doesn't work...

Any hint?

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


PHP Developer highly interested in Python (web development) with some open questions...

2008-02-23 Thread Tamer Higazi
Hi!
My brother is dreaming and dying for python and swear that it is the
ultimate killer application language.

I am coding Webapplication in PHP5 and ask myself if for python are:

- application frameworks like: "Zend Framework" and ezComponents
- What is the Zope Applikation Server? Is it also a Webserver like the
Apache or Tomcat Webserver?

- Is there a way of Round Tripp engineering based on UML XMI Files to
generate python files (with it's dependencies) 

- Let us assume, I want to write a Web application in Python (what I did
now in PHP5) and want to distribute my work under commercial usage.

Can I encrypt my work and generate Licence Files for Customers who would
purchase my End-Sollution like with:

- Zend Encoder
- IonCube
- SourceGuardian

???

I just ask, because I have finished a product and will encrpyt it with
the Ioncube encoder based on PHP5.

for answering all my Questions, I would thank you guys very much



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


Re: Official IRC channel for Python?

2008-02-23 Thread Paul Rubin
js <[EMAIL PROTECTED]> writes:
> I tried #python irc.freenode.net

That has always worked for me.

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
> > there's actually a published book specifically about C++ pitfalls.
> 
> Mercy, a whole book?

http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?EAN=9780201179286

> > C and C++ should practically be outlawed at this point.
> 
> On what grounds?  "I don't approve of the programming language you're
> using.  Cease and desist.  Nyah!"

Well, "outlawed" of course is a figure of speech; however use of those
languages should be a red flag in a design review, and a factor in
determining product liability if a program misbehaves.  Think of all
the buffer overflow exploits against Microsoft Windows programs that
couldn't have happened if Microsoft had used safer languages.  There
was clearly a failure to use best engineering practices.
-- 
http://mail.python.org/mailman/listinfo/python-list


Official IRC channel for Python?

2008-02-23 Thread js
Howdy,

I was wondering if there's official IRC channel for Python.
I tried #python irc.freenode.net and irc.openproject.net with no luck.

Could you please give me some suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-23 Thread zaley
On Feb 24, 6:48 am, Ricardo Aráoz <[EMAIL PROTECTED]> wrote:
> Lie wrote:
> > On Feb 23, 4:02 pm, zaley <[EMAIL PROTECTED]> wrote:
> >> On Feb 22, 11:06 pm, "Jesper"  wrote:
>
> >>> Give PyScripter fromhttp://www.mmm-experts.com/atry
> >>> It is for Windows, though it is written in Delphi and not in C/C++
> >>> /Jesper
> >>> "zaley" <[EMAIL PROTECTED]> skrev i en meddelelsenews:[EMAIL PROTECTED]
> >>> Of course, python scripts debugger
> >>> On 2ÔÂ22ÈÕ, ÏÂÎç3ʱ22·Ö, zaley <[EMAIL PROTECTED]> wrote:
>  My project need a simple scripts debugger . I hope I can find
>  something instructive
>  Stefan Behnel дµÀ£º
> > zaley wrote:
> >> Is there a open souce IDE writen by C( C++) or partly writen by C( C+
> >> +)?
> > Tons of them. What do you want to do with it?
> > Stefan- Hide quoted text -
> >>> - Show quoted text -
> >> But PyScripter is not a open source project
>
> > Am I correct to say that the reason why you wanted an open source C++
> > IDE is because you wanted the freedom to modify your own programming
> > environment?
> >From the "About" window in PyScripter :
>
> """
> A freeware, open source Python scripter integrated
> development environment created with the ambition to bring to
> the Python community the quality and functionality available in
> commercial IDEs available for other languages.
> """
>
> So I think we could say PyScripter IS an open source project.- Hide quoted 
> text -
>
> - Show quoted text -

Really, what I want to do is that scripts can be executed step by
step .
I know By "Py_Runstring"  clauses  in main function can executed by
step .
But I can't know how to step into a function and how to step in a
function.
So I hope I can find something helpful in open source IDE for python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
>  def mkadder(n):
>  return lambda x: x + n
> 
> I have gotten the impression that this was somehow inferior in Python
> though, at least in terms of performance.  Every time somebody uses
> lambda here, they seem to get a bunch "why are you using lambda?"
> responses.  If I am grossly mistake, please just enlighten me.

There are some Python users who object to lambda on stylistic
grounds, and would rather that you say

   def mkdadder(n):
  def adder(x, n):
 return x + n
  return adder

Those same users tend to object to higher-order functions (preferring
listcomps or genexps).  It seems to me though that Python is moving
more towards HOF-oriented styles because of the utility of HOF's over
iterators (look at itertools).  That might make its learning curve
steeper for beginners; I don't have a good sense of this.

> I note from your other posts that you seem to have a strong Lisp
> bent. Lisp programmer and Smalltalk programmers stand out in the
> crowd.  I first noted this when somebody found a while-loop offensive,
> on the grounds that recursion was somehow a more natural way to
> implement looping.  It can take a while to convince somebody like that
> they different idioms work best in different languages.

Well, the saying is "to iterate is human; to recurse, divine" ;-).
Scheme has while-loops but they are just syntax sugar for recursion.
-- 
http://mail.python.org/mailman/listinfo/python-list


python-list@python.org

2008-02-23 Thread castironpi
On Feb 23, 7:47 pm, [EMAIL PROTECTED] wrote:
> On Feb 23, 6:19 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Feb 23, 2:03 pm, [EMAIL PROTECTED] wrote:
>
> > > 1) [EMAIL PROTECTED]
>
> > > @synchronized
> > > def function( arg ):
> > >    behavior()
>
> > > Synchronized prevents usage from more than one caller at once: look up
> > > the function in a hash, acquire its lock, and call.
>
> > > def synchronized( func ):
> > >    def presynch( *ar, **kwar ):
> > >       with _synchlock:
> > >          lock= _synchhash.setdefault( func, allocate_lock() )
> > >          with lock:
> > >             return func( *ar, **kwar )
> > >    return presynch
>
> > No need for a global _synchhash, just hang the function lock on the
> > function itself:
>
> > def synch(f):
> >     f._synchLock = Lock()
> >     def synchedFn(*args, **kwargs):
> >         with f._synchLock:
> >             f(*args, **kwargs)
> >     return synchedFn
>
> > You might also look at the PythonDecoratorLibrary page of the Python
> > wiki, there is a synchronization decorator there that allows the
> > function caller to specify its own lock object (in case a single lock
> > should be shared across multiple functions).
>
> > -- Paul- Hide quoted text -
>
> > - Show quoted text -
>
> Why not just:
>
> def synched( f ):
>    l= Lock()
>    def presynched( *a, **kwa ):
>       with l:
>           return f( *a, **kwa )
>
> It's not like the lock is ever used anywhere else.  Besides, if it is,
> isn't the correct spelling:
>
> class Asynched:
>    def __init__( self, func ):
>       self.func, self.lock= func, Lock()
>    def __call__( self, *a, **kwa ):
>       return self.func( *a, **kwa )
>
> and
>
> def synched( func ):
>    return Asynched( func )
>
> or even
>
> synched= Asynched
>
> ?- Hide quoted text -
>
> - Show quoted text -

So, you live around here?  Where'd you park? ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter: Missing the last piece of the puzzle

2008-02-23 Thread Simon Forman
On Feb 23, 9:00 am, [EMAIL PROTECTED] wrote:
> I have a simple editor built into my visual parser. It has a File menu
> with
> typical New, Open, Save, Save As ... options. I now know how to set
> the options [en/dis]abled and how to check the Text widget's modified
> flag.
>
> Now I want to [en/dis]able those options. Can I ask the text to notify
> me when the modified flag changes?

yes! check out http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/464635

HTH,
~Simon

> Can I set the statuses when the
> user clicks File, before the options are displayed? Do I need to
> create
> a checker on an independent thread that looks at the flag every few
> millis?
>
> (Tkinter deserves more respect. I've got a good-looking application
> growing quickly.)


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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Paul Rubin wrote:
> Jeff Schwab <[EMAIL PROTECTED]> writes:
>> One great thing about C is that
>> a programmer can realistically hope to know the entire language
>> definition; maybe Guido would like the same to be true of Python.
> 
> C is horrendously complicated, with zillions of obscure traps.  C++ is
> even worse;

Who feeds you this stuff?


> there's actually a published book specifically about C++
> pitfalls.

Mercy, a whole book?

My current favorite book of language-specific pitfalls:

 http://www.javapuzzlers.com/

Wait a few years.  A Python Puzzlers book will surely be on the shelves 
eventually.  Here are some of the top results when Googling "python 
pitfalls:"

 http://zephyrfalcon.org/labs/python_pitfalls.html
 http://evanjones.ca/python-pitfall-scope.html

Maybe C++ needs better pub.  The guy who wrote the first of those 
articles says elswhere on his web site:

 "My Python pitfalls article seems to be a popular read. It's
 written from a somewhat negative viewpoint: things that can go
 wrong. (Of course, that's useful; you're never going to do these
 things wrong again. Right? ;-) To counter-balance this, I think
 there should an article with a more positive viewpoint as well.
 So I was wondering, if I could collect 10 "anti-pitfalls"; parts
 of the Python language that are especially clever, elegant and
 intuitive."


Good luck with that.  Once language Y comes along, there will be a 
million reasons people believe that language X was downright unusable.


> Python is underspecified but freer of weird hazards in
> practice.
> 
> C and C++ should practically be outlawed at this point.  

On what grounds?  "I don't approve of the programming language you're 
using.  Cease and desist.  Nyah!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Paul Rubin wrote:
> Jeff Schwab <[EMAIL PROTECTED]> writes:
>> So to use the Perl example: If you want to sort a list using some
>> arbitrary snippet of code as the comparison function, you can write:
>>  sort { code to compare $a and $b } @elements
> 
> Yes, you can do that in Python, using a lambda expression, a named
> function, or whatever.

You can indeed.  I think you can also use this to do the other stuff you 
would expect, e.g. return locally defined code snippets to define closures:

 def mkadder(n):
 return lambda x: x + n

I have gotten the impression that this was somehow inferior in Python 
though, at least in terms of performance.  Every time somebody uses 
lambda here, they seem to get a bunch "why are you using lambda?" 
responses.  If I am grossly mistake, please just enlighten me.


>> What language do you have in mind, in which lambda is more basic than
>> named definitions?  Are you coming from a functional language
>> background?
> 
> All languages that I know of with lambda, treat it as more basic than
> named definitions, e.g. the Lisp family (not sure if those count as
> functional languages) in addition to functional languages like Haskell.

I note from your other posts that you seem to have a strong Lisp bent. 
Lisp programmer and Smalltalk programmers stand out in the crowd.  I 
first noted this when somebody found a while-loop offensive, on the 
grounds that recursion was somehow a more natural way to implement 
looping.  It can take a while to convince somebody like that they 
different idioms work best in different languages.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Hyphenation module PyHyphen-0.3 released

2008-02-23 Thread Ryan Ginstrom
> On Behalf Of Max Erickson
> the easy way to do this might be to find(in your mingw /lib 
> directory) and copy or rename libmsvcr71.a and libmsvcr71d.a 
> into libmsvcrt.a and libmsvcrtd.a (backing up the originals 
> if desired). If the MingW you have installed doesn't provide 
> the appropriate runtime, you would have to track that down.

Here's another way. Go to /MinGW/lib/gcc/mingw32/3.4.2/spec, and modify the
libgcc directive as follows:

*libgcc:
%{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcr71

Regards,
Ryan Ginstrom

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Matthew Woodcraft wrote:
> Jeff Schwab  <[EMAIL PROTECTED]> wrote:
>> Matthew Woodcraft wrote:
>>> Jeff Schwab  <[EMAIL PROTECTED]> wrote:
 The most traditional, easiest way to open a file in C++ is to use an 
 fstream object, so the file is guaranteed to be closed when the fstream 
 goes out of scope.
>  
>>> Out of interest, what is the usual way to manage errors that the
>>> operating system reports when it closes the file?
> 
>> By default, the fstream object just sets its "failbit," which you can 
>> check manually by calling my_stream.fail().  If you want anything 
>> particular to take place on failure to close a stream, you either have 
>> to call close manually, or you need a dedicated object whose destructor 
>> will deal with it.
> 
>> Alternatively, you can tell the fstream ahead of time that you want 
>> exceptions thrown if particular actions fail.  There's a convention that 
>> destructors don't ever throw exceptions, though, so it would be unusual 
>> to request an exception when close() fails.
> 
> I see. Then, unless you don't care about data loss passing silently,
> this 'most traditional' way to open a file is unsuitable for files
> opened for writing.

No, why would you think so?  If you want something special to happen 
when the close() fails (as you indeed would if you were writing 
important data), you have to say somehow that you want your special code 
called.  What syntax would you like to see?  Here's what the C++ would 
look like, supposing you have a type LoggingCloser that calls close and 
logs any failure:

 void f(std::string file_name) {
 std::ofstream out(file_name.c_str()); // [1]
 LoggingCloser closer(out);

 // ... your work code here ...
 }

The closer's destructor is guaranteed to be called before the file 
stream's.  That gives it a chance to call close manually, and keeps the 
error-handling code separate from the rest of the program logic. 
Compare the following Python equivalent, assuming we've replaced Logging 
Closer's constructor and destructor with __enter__ and __exit__ definitions:

 def f(file_name):
with file(file_name, 'w') as out:
 with LoggingCloser(out) as closer:
 // ... your work code here ...

In this case, the Python with-statement is not too bad, because you only 
have two constructor/destructor pairs.  For each new pair, though, it 
seems like you need an extra level of nesting (and therefore 
indentation).  Of course, it may just be that I don't yet know how to 
use the with-statement effectively.

[1] That c_str() kludge is usually the primary complaint about using 
ofstream.  It has been fixed in the new draft standard, which will 
become official in 2009.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
> So to use the Perl example: If you want to sort a list using some
> arbitrary snippet of code as the comparison function, you can write:
>  sort { code to compare $a and $b } @elements

Yes, you can do that in Python, using a lambda expression, a named
function, or whatever.  

> What language do you have in mind, in which lambda is more basic than
> named definitions?  Are you coming from a functional language
> background?

All languages that I know of with lambda, treat it as more basic than
named definitions, e.g. the Lisp family (not sure if those count as
functional languages) in addition to functional languages like Haskell.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
> One great thing about C is that
> a programmer can realistically hope to know the entire language
> definition; maybe Guido would like the same to be true of Python.

C is horrendously complicated, with zillions of obscure traps.  C++ is
even worse; there's actually a published book specifically about C++
pitfalls.  Python is underspecified but freer of weird hazards in
practice.

C and C++ should practically be outlawed at this point.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hyphenation module PyHyphen-0.3 released

2008-02-23 Thread Max Erickson
thebjorn <[EMAIL PROTECTED]> wrote:
>   Visual Studio 2003 was not found on this system. If you have
>   Cygwin 
> installed,
>   you can try compiling with MingW32, by passing "-c mingw32" to
> setup.py.
> -- bjorn

You need to convince MingW to use the correct VS runtime. Cribbing 
from:

http://www.develer.com/oss/GccWinBinaries

the easy way to do this might be to find(in your mingw /lib directory) 
and copy or rename libmsvcr71.a and libmsvcr71d.a into libmsvcrt.a and 
libmsvcrtd.a (backing up the originals if desired). If the MingW you 
have installed doesn't provide the appropriate runtime, you would have 
to track that down.

The MingW/GCC package from the linked page provides a utility to do 
this, but it is a tossup/up to you if the version of GCC provided is 
suitable for 'production' use.


max

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Paul Rubin wrote:
> "Terry Reedy" <[EMAIL PROTECTED]> writes:
>> | Yes, this seems to be the Python way:  For each popular feature of some
>> | other language, create a less flexible Python feature that achieves the
>> | same effect in the most common cases (e.g. lambda to imitate function
>> | literals, or recursive assignment to allow x = y = z).
>>
>> This is a rather acute observation.  Another example is generators versus 
>> full coroutines (or continuations).  Guido is content to capture 80% of the 
>> practical use cases of a feature.  He never intended Python to be a 100% 
>> replace-everything language.
> 
> I don't understand the lambda example due to not being sure what Jeff
> means by "function literals".  But in other languages, lambda is the
> basic primitive, and "def" or equivalent is syntax sugar.

Sorry, I didn't know what else to call them except "lambdas."  I meant 
the bare code blocks you can use in Perl, or what Java tries to achieve 
via anonymous inner classes.  So to use the Perl example:  If you want 
to sort a list using some arbitrary snippet of code as the comparison 
function, you can write:

 sort { code to compare $a and $b } @elements

This isn't really "native" in C++ either:

 http://www.boost.org/doc/html/lambda.html

What language do you have in mind, in which lambda is more basic than 
named definitions?  Are you coming from a functional language background?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Terry Reedy wrote:
> "Jeff Schwab" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> [snip discussion of 'with' statements]
> 
> | Yes, this seems to be the Python way:  For each popular feature of some
> | other language, create a less flexible Python feature that achieves the
> | same effect in the most common cases (e.g. lambda to imitate function
> | literals, or recursive assignment to allow x = y = z).
> 
> This is a rather acute observation.  Another example is generators versus 
> full coroutines (or continuations).  Guido is content to capture 80% of the 
> practical use cases of a feature.  He never intended Python to be a 100% 
> replace-everything language.

I think the idea is to balance power on one hand, against complexity and 
potential confusion on the other.  One great thing about C is that a 
programmer can realistically hope to know the entire language 
definition; maybe Guido would like the same to be true of Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread thebjorn
On Feb 24, 2:24 am, Paul Rubin  wrote:
> thebjorn <[EMAIL PROTECTED]> writes:
> > If the lists are long enough to care, either rewrite use a set-based
> > solution if the items are hashable, or keep the elements sorted and
> > rewrite to use the bisect module if the elements can be ordered.
>
> Well, you want a tree data structure to have fast insertions to
> remember what items have already been seen.  There's been a bunch
> of proposals for an ordered dict type that works like this.
>
> Some day...

Amen!  .. *sigh*...
-- 
http://mail.python.org/mailman/listinfo/python-list


python-list@python.org

2008-02-23 Thread castironpi
On Feb 23, 6:19 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Feb 23, 2:03 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
>
>
> > 1) [EMAIL PROTECTED]
>
> > @synchronized
> > def function( arg ):
> >    behavior()
>
> > Synchronized prevents usage from more than one caller at once: look up
> > the function in a hash, acquire its lock, and call.
>
> > def synchronized( func ):
> >    def presynch( *ar, **kwar ):
> >       with _synchlock:
> >          lock= _synchhash.setdefault( func, allocate_lock() )
> >          with lock:
> >             return func( *ar, **kwar )
> >    return presynch
>
> No need for a global _synchhash, just hang the function lock on the
> function itself:
>
> def synch(f):
>     f._synchLock = Lock()
>     def synchedFn(*args, **kwargs):
>         with f._synchLock:
>             f(*args, **kwargs)
>     return synchedFn
>
> You might also look at the PythonDecoratorLibrary page of the Python
> wiki, there is a synchronization decorator there that allows the
> function caller to specify its own lock object (in case a single lock
> should be shared across multiple functions).
>
> -- Paul- Hide quoted text -
>
> - Show quoted text -

Why not just:

def synched( f ):
   l= Lock()
   def presynched( *a, **kwa ):
  with l:
  return f( *a, **kwa )

It's not like the lock is ever used anywhere else.  Besides, if it is,
isn't the correct spelling:

class Asynched:
   def __init__( self, func ):
  self.func, self.lock= func, Lock()
   def __call__( self, *a, **kwa ):
  return self.func( *a, **kwa )

and

def synched( func ):
   return Asynched( func )

or even

synched= Asynched

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


Re: can't set attributes of built-in/extension type

2008-02-23 Thread Steve Holden
Steve Holden wrote:
> Neal Becker wrote:
>> Steve Holden wrote:
>>
>>> Neal Becker wrote:
 Steve Holden wrote:

> Neal Becker wrote:
>> 7stud wrote:
>>
>>> On Feb 21, 11:19 am, Neal Becker <[EMAIL PROTECTED]> wrote:
 I'm working on a simple extension.  Following the classic 'noddy'
 example.

 In [15]: cmplx_int32
 Out[15]: 

 Now I want to add an attribute to this type.  More precisely, I want
 a class attribute.

 cmplx_int32.test = 0
 ---
 TypeError Traceback (most recent call
 last)

 /home/nbecker/numpy/ in ()

 TypeError: can't set attributes of built-in/extension
 type 'numpy.cmplx_int32'

 What am I missing?
>>> class Dog(object):
>>> def __setattr__(self, attr, val):
>>> print "TypeError: can't set attributes of built-in/extension"
>>> print "type 'Dog.cmplx_int32'"
>>>
>>> d = Dog()
>>> d.test = 0
>>>
>>> --output:--
>>> TypeError: can't set attributes of built-in/extension
>>> type 'Dog.cmplx_int32'
>> Not quite, I'm setting a class attribute, not an attribute on an
>> instance.
>>
> Quite. The problem is that extension types' attributes are determined by
> the layout of the object's slots and forever fixed in the C code that
> implements them: the slots can't be extended, so there's no way to add
> attributes. This is an efficiency feature: it would be *extremely* slow
> to look up the basic types' attributes using late-binding (it would also
> change the nature of the language somewhat, making it more like Ruby or
> Self).
>
> So the reason you can't do what you want to is the same reason why you
> can't add attribute to the built-in types (which are, of course, clearly
> mentioned in the error message).
>
>  >>> object.anyoldname = "You lose!"
> Traceback (most recent call last):
>File "", line 1, in 
> TypeError: can't set attributes of built-in/extension type 'object'
>  >>>
>
> If you look in typeobject.c you'll find this error message occurs when
> the object's type isn't a PyHeapTypeObject (in other words, if it's one
> of the built-in or extension types).
>
 Thanks, but I'm a bit confused.  After reading in my "Python in a
 Nutshell", I found that if after calling PyReady on my type object, if I
 use PyDict_SetItemString (my_type_obj.tp_dict,)

 That seems to work fine (which isn't exactly what it said in the Nutshell
 book, but close).

>> I wanted to add an attribute to my type.
>> Specifically, my type object is a static cmplx_int32_scalar_obj.
>>
>> After calling PyType_Ready (&cmplx_int32_scalar_obj), then I did
>> PyDict_SetItemString (cmplx_int32_scalar_obj.tp_dict, "dtype", 
>> (PyObject*)d1);
>>
>> Now my type has the property:
>> cmplx_int32.dtype
>> dtype('cmplx_int32')
>>
>> Now, I do see that I still can't set it:
>>
>> cmplx_int32.dtype = 2
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> TypeError: can't set attributes of built-in/extension type 
>> 'numpy.cmplx_int32'
>>
>> In this case, I don't need to.
>>
>> But I still don't know why I can have a python class and set class or 
>> instance
>> attributes as I like, but this type acts differently.  What would I need to 
>> do if I did want to allow arbitrary attributes to be set/added to my type?
>>
> I believe it's because PyType_Ready(), among its many other duties,
> calls mro_internal() on the type. It seems obvious that one would want
> to optimize the MRO by not allowing modifications. Yet in C it is
> possible, as you point out, to do so. Hmm ...
> 
> I'll let you know if I come to any conclusion - a query to python-dev
> would probably get an answer, but surely someone on this list knows already?
> 
> [Left this as a draft for a while to mull it over].
> 
> After further consideration I have concluded (without further scrutiny 
> of the source) that it's because the method slots in C-implemented types 
> are pointers to C functions not to Python functions. Would this make sense?
> 
Just to close this one off, Neal wrote to python-dev and got the 
following reply from Guido himself.

> On Sat, Feb 23, 2008 at 4:55 PM, Neal Becker <[EMAIL PROTECTED]> wrote:
>> There is some discussion on this subject, archived here:
>>  http://permalink.gmane.org/gmane.comp.python.general/560661
>>
>>  I wonder if anyone could shed some light on this subject?
>>
>>  (Or, help me understand, what is the difference between a type that I create
>>  using python C api and a python class?)
> 
> This is prohibited intentionally to prevent accidental fatal changes
> to built-in types (fatal to parts of the code that you never though
> of). Also, 

Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Paul Rubin
thebjorn <[EMAIL PROTECTED]> writes:
> If the lists are long enough to care, either rewrite use a set-based
> solution if the items are hashable, or keep the elements sorted and
> rewrite to use the bisect module if the elements can be ordered.

Well, you want a tree data structure to have fast insertions to
remember what items have already been seen.  There's been a bunch
of proposals for an ordered dict type that works like this.

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Hrvoje Niksic
"Terry Reedy" <[EMAIL PROTECTED]> writes:

> "Jeff Schwab" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> [snip discussion of 'with' statements]
>
> | Yes, this seems to be the Python way:  For each popular feature of some
> | other language, create a less flexible Python feature that achieves the
> | same effect in the most common cases (e.g. lambda to imitate function
> | literals, or recursive assignment to allow x = y = z).
>
> This is a rather acute observation.  Another example is generators versus 
> full coroutines (or continuations).

Another example that comes to mind is "with" statement versus a macro
system that allowed one to define custom statements based on
try...finally.  contextlib.contextmanager implements an even more
specific subset of this functionality.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread thebjorn
On Feb 23, 6:18 pm, Paul Hankin <[EMAIL PROTECTED]> wrote:
> On Feb 22, 7:01 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
> > On Feb 22, 12:54 pm, Paul Rubin  wrote:
>
> > > Paul Rubin  writes:
> > > > if any(x==element[0] for x in a):
> > > >   a.append(element)
>
> > > Should say:
>
> > >  if any(x[0]==element[0] for x in a):
> > > a.append(element)
>
> > I think you have this backwards.  Should be:
>
> >  if not any(x[0]==element[0] for x in a):
> > a.append(element)
>
> IMO Jason's solution of testing containment in a generator is better
> (more readable).
> if element[0] not in (x[0] for x in a):
> a.append(element)
>
> --
> Paul Hankin

It may be more readable (although that's debatable), but it always
traverses the entire list.

If the list is short I'd use either the traditional "for/else" or the
newer "if all(...)":

if all(x[0] != element[0] for x in a):
a.append(element)

which allows for short-circuit evaluation -- I generally try to stay
away from negating any() and all() because the logic often gets
convoluted.

If the lists are long enough to care, either rewrite use a set-based
solution if the items are hashable, or keep the elements sorted and
rewrite to use the bisect module if the elements can be ordered.

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
"Terry Reedy" <[EMAIL PROTECTED]> writes:
> | Yes, this seems to be the Python way:  For each popular feature of some
> | other language, create a less flexible Python feature that achieves the
> | same effect in the most common cases (e.g. lambda to imitate function
> | literals, or recursive assignment to allow x = y = z).
> 
> This is a rather acute observation.  Another example is generators versus 
> full coroutines (or continuations).  Guido is content to capture 80% of the 
> practical use cases of a feature.  He never intended Python to be a 100% 
> replace-everything language.

I don't understand the lambda example due to not being sure what Jeff
means by "function literals".  But in other languages, lambda is the
basic primitive, and "def" or equivalent is syntax sugar.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Terry Reedy

"Jeff Schwab" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
[snip discussion of 'with' statements]

| Yes, this seems to be the Python way:  For each popular feature of some
| other language, create a less flexible Python feature that achieves the
| same effect in the most common cases (e.g. lambda to imitate function
| literals, or recursive assignment to allow x = y = z).

This is a rather acute observation.  Another example is generators versus 
full coroutines (or continuations).  Guido is content to capture 80% of the 
practical use cases of a feature.  He never intended Python to be a 100% 
replace-everything language.

tjr



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


Re: Hyphenation module PyHyphen-0.3 released

2008-02-23 Thread thebjorn
On Feb 23, 8:35 pm, "Dr. leo" <[EMAIL PROTECTED]> wrote:
> I am pleased to share with you the great features of the latest version.
> Large parts of the sources were completely rewritten. Also, they are now
> reasonably documented.
>
> Just go tohttp://pypi.python.org/pypi/PyHyphen/0.3
>
> I was tempted to classify it as Beta. Indeed I am not aware of any bugs, but
> I haven't spent very much time for testing, just ran some word lists...
>
> Any feedback is greatly appreciated. Especially I would be interested in
> experiences under Windows. I can only test it under Linux.
>
> If there were a good soul to send me a DLL for Windows
> ([EMAIL PROTECTED]) , this would be terrific.
>
> Bests
>
> Leo

Looks interesting, and I'd love to provide a .pyd file, however I'm
running into some problems :-(   I've got VS 2005 on this machine and
setup-tools is complaining about my Python being built with VS 2003.
(I know what the problem is with intermingling runtime libraries, yet
I can't downgrade my VS version...)  I got a message that I could try
using mingw32, so a quick download and the build step seemed to finish
without any problems:

  C:\work\PyHyphen-0.3>python setup.py build -c mingw32
  running build
  running build_py
  running build_ext
  running build_scripts
  creating build\scripts-2.5
  copying example.py -> build\scripts-2.5

(I ran build_ext first, which is why there's so little output.) I
copied the dictionary into build\lib.win32-2.5\dict and was able to
import the library without getting any errors and run the example from
http://pypi.python.org/pypi/PyHyphen/0.3 (from the build directory).
I'm stuck at trying to install the package though...:

  C:\work\PyHyphen-0.3>python setup.py install
  running install
  running build
  running build_py
  running build_ext
  error: Python was built with Visual Studio 2003;
  extensions must be built with a compiler than can generate
compatible binaries.
  Visual Studio 2003 was not found on this system. If you have Cygwin
installed,
  you can try compiling with MingW32, by passing "-c mingw32" to
setup.py.

  C:\work\PyHyphen-0.3>python setup.py install -c mingw32
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2
[cmd2_opts] ...]
 or: setup.py --help [cmd1 cmd2 ...]
 or: setup.py --help-commands
 or: setup.py cmd --help

  error: invalid command 'mingw32'

I don't know if I'm just doing it wrong, or if I can't use extensions
compiled with mingw32 with the standard distribution Python
executable?

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


Re: bus error/segfault from PyArg_ParseTuple in initproc with incorrect arg number

2008-02-23 Thread Andrew MacIntyre
Miles Lubin wrote:
> I am using PyArg_ParseTuple to parse the arguments (ignoring the keyword 
> arguments) to my initproc for a type I define.
> It seems that something goes wrong inside PyArg_ParseTuple when it gets 
> the wrong number of arguments (my format string is "OO");
> if the function isn't given exactly two arguments, I get a bus error on 
> OS X and a segfault on Linux.
> If two arguments are given, the code runs as expected.
> This does not occur when using PyArg_ParseTuple in a normal method.
> Am I not using PyArg_ParseTuple correctly?
> 
> Here's the relevant code:
> PyObject *a, *b;
> if (!PyArg_ParseTuple(args, "OO", &a, &b))
>   return -1;
> 
> The segfault occurs on this line, not on any line after.

I have seen bus errors on FreeBSD when python runs out of stack space.

-- 
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return value of an assignment statement?

2008-02-23 Thread Terry Reedy

"Tim Roberts" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
|
| >On Fri, 22 Feb 2008 11:00:17 -0800, Aahz wrote:
| >
| >> It's just too convenient to be able to write
| >>
| >> L += ['foo']
| >>
| >> without rebinding L.
| >
| >But ``+=`` does rebind.
|
| Usually, but there's an exception for lists, which a specific
| implementation for += that calls "append".  Or do I misunderstand you?

There is no exception at the compiler level, and indeed, cannot be, because 
in general, the compiler *does not know* the types of either target or 
augment.

target += augment

is compiled, in effect, as

compute target and load target_object
compute and load augment_object
call target_object.__iadd__(augment_object)
store return_object at target

 In the list case, the rebinding is to the *same* object! --
because list.__iadd(l1,l2)__  returns l1 extended with l2 rather than a new 
list l1+l2, as the specification allows.

Augmented (inplace) assignment is still assignment (binding).

| C:\tmp>python
| Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on
| win32
| Type "help", "copyright", "credits" or "license" for more information.
| >>> L = [1,2,3]
| >>> id(L)
| 10351000
| >>> L += [4]
| >>> id(L)
| 10351000

L has been rebound to the same object, hence same id.  Unfortunately, such 
rebinding is only visible (that I can think of) when it fails:

>>> t=([],)
>>> t[0]+=[1]

Traceback (most recent call last):
  File "", line 1, in -toplevel-
t[0]+=[1]
TypeError: object does not support item assignment
>>> t
([1],)

The list comprising t[0] is extended by its __iadd__ method.  The exception 
arises due to the subsequent attempted rebinding to t[0] (see dis output 
below), which is, of course, not permissible.

>>> t[0].extend([2])
>>> t
([1, 2],)

Extension without attempted illegal rebinding raises no error.

CPython specifics:

>>> from dis import dis

>>> def fi(i): i+=1; return i
>>> dis(fi)
  1   0 LOAD_FAST0 (i)
  3 LOAD_CONST   1 (1)
  6 INPLACE_ADD
  7 STORE_FAST   0 (i)
 10 LOAD_FAST0 (i)
 13 RETURN_VALUE

>>> def fl(l): l += [1]; return l
>>> dis(fl)
  1   0 LOAD_FAST0 (l)
  3 LOAD_CONST   1 (1)
  6 BUILD_LIST   1
  9 INPLACE_ADD
 10 STORE_FAST   0 (l)
 13 LOAD_FAST0 (l)
 16 RETURN_VALUE

Treating the VM stack as a Python list, INPLACE_ADD executes
something like

stack[-2] = stack[-2].__iadd__(stack[-1])
stack.pop() # leaving returned object on top of stack

Terry Jan Reedy






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


python-list@python.org

2008-02-23 Thread Paul McGuire
On Feb 23, 2:03 pm, [EMAIL PROTECTED] wrote:
>
> 1) [EMAIL PROTECTED]
>
> @synchronized
> def function( arg ):
>    behavior()
>
> Synchronized prevents usage from more than one caller at once: look up
> the function in a hash, acquire its lock, and call.
>
> def synchronized( func ):
>    def presynch( *ar, **kwar ):
>       with _synchlock:
>          lock= _synchhash.setdefault( func, allocate_lock() )
>          with lock:
>             return func( *ar, **kwar )
>    return presynch
>

No need for a global _synchhash, just hang the function lock on the
function itself:

def synch(f):
f._synchLock = Lock()
def synchedFn(*args, **kwargs):
with f._synchLock:
f(*args, **kwargs)
return synchedFn

You might also look at the PythonDecoratorLibrary page of the Python
wiki, there is a synchronization decorator there that allows the
function caller to specify its own lock object (in case a single lock
should be shared across multiple functions).

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
Nicola Musatti <[EMAIL PROTECTED]> writes:
> >>>a = [f(x) + g(y) for x,y in izip(m1, m2) if h(x,y).frob() == 7]
> [...]
> > There you replace one line of code with 40+ lines to get around the
> > absence of GC.  Sounds bug-prone among other things.
> 
> Come on, you didn't define f, g, izip, h or frob either. It's more
> like 5 to one. Furthermore your code is more compact due to the
> existence of list comprehensions, not because of GC. Had you written a
> loop the difference would be smaller.


No I don't need a loop if I don't use the listcomp.  I could say

  a = map(lambda x,y: f(x)+g(y), ifilter(lambda x,y: h(x,y).frob==7,
   izip(m1, m2)))

the listcomp is basically syntax sugar for that.

The issue here is that Python is simply more expressive than C++,
which doesn't support creation of higher order functions like that.
However, one of the consequences of programming in this style is
you allocate a lot of temporary objects which best managed by GC.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
>   some_class().method()
> The method body could create an external reference to the instance of
> some_class, such that the instance would not be reclaimed at the end of
> the statement.

Yes.  Therefore there is no way to predict if the object will be be
freed, without intimate knowledge of the semantics of the class and
method.  

> It's not "my" scheme.  I got it from Martelli.

Well, he's a very wise and knowledgable Pythonista, so I hope he's
using the "with" statement by now.

> This is a special case of the reference count being 1, then
> immediately dropping to zero.  It is simple and convenient.  The
> approach is, as you rightly point out, not extensible to more
> complicated situations in Python, because the reference counting
> ceases to be trivial.

It's not trivial even in the simplest case, like the one you cited
of opening a file.  Maybe you've shadows the "open" function to
keep a cache of file contents or something.

> The point is that once you tie object lifetimes to scope, rather than
> unpredictable garbage collection, you can predict with perfect ease
> and comfort exactly where the objects are created and destroyed.

Sure, fine, Python does that with the "with" statement and C++ does
it with class destructors on automatic variables.  The old kludge of 

  some_class().method()

creates an instance of some_class but does NOT tie it to a scope,
for the reasons we've discussed.  

> That's true of the current language.  I don't have enough experience
> with "with" yet to know whether it's a realistic solution to the
> issue. IMO, they are at least preferable to Java-style
> finally-clauses, but probably not a replacement for C++-style RAII.

It is a more general version of what C++ does, as I understand it.
-- 
http://mail.python.org/mailman/listinfo/python-list


looking for open source simulink clone in python

2008-02-23 Thread [EMAIL PROTECTED]
Does anyone know of something like this? I've searched to no avail.
GNUradio companion is promising but tied to gnuradio.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Matthew Woodcraft
Jeff Schwab  <[EMAIL PROTECTED]> wrote:
>Matthew Woodcraft wrote:
>> Jeff Schwab  <[EMAIL PROTECTED]> wrote:
>>> The most traditional, easiest way to open a file in C++ is to use an 
>>> fstream object, so the file is guaranteed to be closed when the fstream 
>>> goes out of scope.
 
>> Out of interest, what is the usual way to manage errors that the
>> operating system reports when it closes the file?

> By default, the fstream object just sets its "failbit," which you can 
> check manually by calling my_stream.fail().  If you want anything 
> particular to take place on failure to close a stream, you either have 
> to call close manually, or you need a dedicated object whose destructor 
> will deal with it.

> Alternatively, you can tell the fstream ahead of time that you want 
> exceptions thrown if particular actions fail.  There's a convention that 
> destructors don't ever throw exceptions, though, so it would be unusual 
> to request an exception when close() fails.

I see. Then, unless you don't care about data loss passing silently,
this 'most traditional' way to open a file is unsuitable for files
opened for writing.

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


Re: Python camping in Argentina

2008-02-23 Thread Terry Reedy

"Facundo Batista" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Looks like a great event.

|And of course, we lunched and dinner all together, played games,

What is the hexagon board game?

And, is the one woman I saw in the group photo a programmer?
(I am trying to entice my daughter!)

tjr




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


Python camping in Argentina

2008-02-23 Thread Facundo Batista
Hi!

This post is to tell you about a Python event we had the last weekend.

It was a Python camping, in Los Cocos, Córdoba, Argentina. More than
20 Python developers, some experienced, some new ones, joined together
in a center where we made a lot of activities during four whole days:

- We had a mini python bug day, closing 4 or 5 issues, but more
important, two new developers know how the full process is.

- Worked heavily on a PyAr project, CDPedia, that aims to release a
part of the wikipedia (spanish pages, for example, ;) ) to be queried
off line, distributable in a CD. The project, when finished, will give
you the way to construct these CDs or DVDs with the subselection of
the wikipedia that you want, with installers for different operating
systems, full text searches, and everything, :)

- Made a framework for handling Scenes, Layers, sprites movements, and
menues in pyglet, thinking in PyWeek.

- Worked with behaviour trees and perceptrons, for AI modeling (yes,
with Python).

- Made a translation of Trac to spanish, aiming to include it in a
Trac branch that will handle localizations.

- Had a Python Argentina formal meeting.

- Worked on a Rubick cube game in pyglet.

And of course, we lunched and dinner all together, played games,
climbed a mountain (carrying the Python Argentina flag to the top, see
the photos), and have a lot, lot of fun.

All the photos, here:
http://www.flickr.com/photos/[EMAIL PROTECTED]/sets/72157603938876036/

Regards,

-- 
.Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Matthew Woodcraft wrote:
> Jeff Schwab  <[EMAIL PROTECTED]> wrote:
>> The most traditional, easiest way to open a file in C++ is to use an 
>> fstream object, so the file is guaranteed to be closed when the fstream 
>> goes out of scope.
> 
> Out of interest, what is the usual way to manage errors that the
> operating system reports when it closes the file?

By default, the fstream object just sets its "failbit," which you can 
check manually by calling my_stream.fail().  If you want anything 
particular to take place on failure to close a stream, you either have 
to call close manually, or you need a dedicated object whose destructor 
will deal with it.

Alternatively, you can tell the fstream ahead of time that you want 
exceptions thrown if particular actions fail.  There's a convention that 
destructors don't ever throw exceptions, though, so it would be unusual 
to request an exception when close() fails.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return value of an assignment statement?

2008-02-23 Thread Tim Roberts
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

>On Fri, 22 Feb 2008 11:00:17 -0800, Aahz wrote:
>
>> It's just too convenient to be able to write
>> 
>> L += ['foo']
>> 
>> without rebinding L.
>
>But ``+=`` does rebind.

Usually, but there's an exception for lists, which a specific
implementation for += that calls "append".  Or do I misunderstand you?

C:\tmp>python
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> L = [1,2,3]
>>> id(L)
10351000
>>> L += [4]
>>> id(L)
10351000
>>>
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Matthew Woodcraft
Jeff Schwab  <[EMAIL PROTECTED]> wrote:
> The most traditional, easiest way to open a file in C++ is to use an 
> fstream object, so the file is guaranteed to be closed when the fstream 
> goes out of scope.

Out of interest, what is the usual way to manage errors that the
operating system reports when it closes the file?

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


Re: ILeo (IPython-Leo bridge); a marriage made in heaven?

2008-02-23 Thread Ville Vainio
On Feb 23, 10:54 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote:

> Are you part of Leo? This smells like a marketing scheme to me.

Yes, Edward is part of Leo and I am part of IPython. In fact, most of
my income comes from selling IPython T-shirts at the local flea market
and I therefore have to resort to shady operations like this to pump
up my fading income. Hey, it pays the bills!

Seriously, though; this *is* cool stuff. I have an updated version of
the document here: http://vvtools.googlecode.com/files/ILeo_doc.txt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-23 Thread Ricardo Aráoz
Lie wrote:
> On Feb 23, 4:02 pm, zaley <[EMAIL PROTECTED]> wrote:
>> On Feb 22, 11:06 pm, "Jesper"  wrote:
>>
>>
>>
>>> Give PyScripter fromhttp://www.mmm-experts.com/atry
>>> It is for Windows, though it is written in Delphi and not in C/C++
>>> /Jesper
>>> "zaley" <[EMAIL PROTECTED]> skrev i en meddelelsenews:[EMAIL PROTECTED]
>>> Of course, python scripts debugger
>>> On 2ÔÂ22ÈÕ, ÏÂÎç3ʱ22·Ö, zaley <[EMAIL PROTECTED]> wrote:
 My project need a simple scripts debugger . I hope I can find
 something instructive
 Stefan Behnel дµÀ£º
> zaley wrote:
>> Is there a open souce IDE writen by C( C++) or partly writen by C( C+
>> +)?
> Tons of them. What do you want to do with it?
> Stefan- Hide quoted text -
>>> - Show quoted text -
>> But PyScripter is not a open source project
> 
> Am I correct to say that the reason why you wanted an open source C++
> IDE is because you wanted the freedom to modify your own programming
> environment?

>From the "About" window in PyScripter :
"""
A freeware, open source Python scripter integrated
development environment created with the ambition to bring to
the Python community the quality and functionality available in
commercial IDEs available for other languages.
"""

So I think we could say PyScripter IS an open source project.

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


Re: Globals or objects?

2008-02-23 Thread Steven D'Aprano
On Sat, 23 Feb 2008 08:16:44 -0500, Steve Holden wrote:

> Steven D'Aprano wrote:
>> On Fri, 22 Feb 2008 18:53:54 +, tinnews wrote:
>> 
> But you're not comparing what the OP posted.  He was comparing a
> global with an object with a single variable inside it.  Either
> would work with the y = spam(arg) example above.
 What do you mean by "an object with a single variable inside it"? I
 don't understand what that is supposed to mean, or why you think it
 is the same as a global. Do you mean a Singleton?

 If so, then the answer is simple: using a Singleton argument instead
 of a global is better, because with a global you are stuck to always
 using the global (at least until you can re-write the code), but with
 the Singleton argument, you may be enlightened and *not* use a
 Singleton.

>>> But if you stop using the Singleton the code no longer does the same
>>> as it would with a global does it?
>> 
>> That's a *good* thing, not a problem. The whole idea is to get away
>> from the bad behaviour of globals, not find some other way to implement
>> it.
>> 
> I think that advocation of a global singleton is not really solving the
> problem. Not the problem I perceive, anyway. From your comments it's
> difficult to see whether we share the same perceptions, so let me
> elucidate.

Thanks for the details. I do agree with you. It wasn't me that suggested 
that the OP create a global singleton, or that using such a beast was a 
good plan. I hope that my response that [paraphrasing] a global singleton 
was good because it lets the developer STOP using a global singleton can 
be seen in context of tinnews badgering me again and again to explain why 
using a global singleton is better than an old-style global variable. 
That's not a position I would take.

[...]
> After all, some things *have* to be global for our programs to make any
> sense at all, unless you want to adopt a truly functional style that has
> never appealed to me. I like my programs to have state.

Some things are global, yes, but very few of them need to be "global 
variables" in the sense we're discussing. Actually, in the sense of the 
OP's example, I don't believe anything *needs* to be a global variable, 
unless it's a deliberate design choice (e.g. a global flag controlling 
some aspect of program behaviour, which I see as a legitimate if 
restrictive choice).


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


python-list@python.org

2008-02-23 Thread castironpi
Corrections.

Typographical error in the implementation of #1.

def synchronized( func ):
   def presynch( *ar, **kwar ):
  with _synchlock:
 lock= _synchhash.setdefault( func, allocate_lock() )
  with lock:
 return func( *ar, **kwar )
   return presynch

On footnote #4, one might need a vector of jump addresses, one for
each context in which the word might be modified.  Yes, this involves
a miniature "many small" design in actual hardware memory, and
definitely opens some doors to faster processing.  As such, it may not
be the best "first" structural element in paralell off-loading, but
it's a good one.  And yes, it's specialty RAM, for which RAM may not
even be the right place.  If a few KB of it is enough, just bump it up
next to the cache, which may make for shorter cycles on the jump-back
later.  You probably don't want to be setting the instruction pointer
from a KB's worth of addresses, so there's probably an extra cycle
involved in setting the jump register, halting the IP, and signalling
a jump.  Interrupts may be suited too.  Does the OS need to provide an
API before a compiler can make use of it?

On #4, the signatures func( self, locks ) vs. func( locks, self ) is
open: just if you sometimes want locks to be the second parameter, and
other times the first, as for non-class-member functions, there will
be two methods, or a parameter to signal the difference.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Rhamphoryncus
On Feb 23, 11:39 am, Nicola Musatti <[EMAIL PROTECTED]> wrote:
> Paul Rubin wrote:
> > Nicola Musatti <[EMAIL PROTECTED]> writes:
> >>>a = [f(x) + g(y) for x,y in izip(m1, m2) if h(x,y).frob() == 7]
> [...]
> > There you replace one line of code with 40+ lines to get around the
> > absence of GC.  Sounds bug-prone among other things.
>
> Come on, you didn't define f, g, izip, h or frob either. It's more like
> 5 to one. Furthermore your code is more compact due to the existence of
> list comprehensions, not because of GC. Had you written a loop the
> difference would be smaller.

So here's three versions, for comparison:


a = [f(x) + g(y) for x,y in izip(m1, m2) if h(x,y).frob() == 7]


a = []
for x, y in izip(m1, m2):
if h(x, y).frob() == 7:
a.append(f(x) + g(y))


std::vector a;
for (std::someiterable::iterator i = izip(m1, m2); !
i.finished(); ++i) {
if (h(i->first, i->second).frob() == 7)
a.push_back(f(i->first) + g(i->second));
}

Although the the benefits of static typing can be argued, surely you
can see the clarity tradeoffs that you make for it?

Some notes:
* izip() takes two iterables as input and returns an iterator, using
only O(1) memory at any given time.  Your original version got this
wrong.
* I fudged the "!i.finished()" as I couldn't find an appropriate
official version in time for this post
* The iterator can't sanely be copied, so it probably needs to use
refcounting internally.  Oops, that's GC...
* Whoever decided to keep C's i++ syntax for iterators should be shot
* x and y aren't named.  They could be extracted, but it's just enough
effort that it's probably not worth it in C++.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a open souce IDE writen by C( C++) or partly writen by C( C++)?

2008-02-23 Thread Lie
On Feb 23, 4:02 pm, zaley <[EMAIL PROTECTED]> wrote:
> On Feb 22, 11:06 pm, "Jesper"  wrote:
>
>
>
> > Give PyScripter fromhttp://www.mmm-experts.com/atry
>
> > It is for Windows, though it is written in Delphi and not in C/C++
>
> > /Jesper
>
> > "zaley" <[EMAIL PROTECTED]> skrev i en meddelelsenews:[EMAIL PROTECTED]
> > Of course, python scripts debugger
>
> > On 2ÔÂ22ÈÕ, ÏÂÎç3ʱ22·Ö, zaley <[EMAIL PROTECTED]> wrote:
>
> > > My project need a simple scripts debugger . I hope I can find
> > > something instructive
>
> > > Stefan Behnel дµÀ£º
>
> > > > zaley wrote:
> > > > > Is there a open souce IDE writen by C( C++) or partly writen by C( C+
> > > > > +)?
>
> > > > Tons of them. What do you want to do with it?
>
> > > > Stefan- Hide quoted text -
>
> > - Show quoted text -
>
> But PyScripter is not a open source project

Am I correct to say that the reason why you wanted an open source C++
IDE is because you wanted the freedom to modify your own programming
environment?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: graphing/plotting with python and interface builder

2008-02-23 Thread Jacob Davis
I found SM2DGraphView, but I guess that I am too much of a newbie with  
interface builder and pyobjc to figure out how to get SM2DGraphView to  
work.  Are there any good tutorials (or better yet, examples) of how  
to get SM2DGraphView to work?

I don't know pyobjc well at all.

Thanks

Jake


On Feb 23, 2008, at 5:54 AM, Diez B. Roggisch wrote:

> Jacob Davis schrieb:
>> Hi.
>>
>> I am developing for mac and using Xcode and Interface Builder 3.0.  I
>> can make a simple application, but I am having a hard time trying to
>> figure out a good way to create a graph or plot for a class project.
>>
>> Does anybody have any tips on where to get started, or on how to do  
>> this?
>>
>> I have searched far for several days now, but I don't know if I am on
>> the right track.  Any help is much appreciated.
>
> I use
>
> http://developer.snowmintcs.com/frameworks/sm2dgraphview/index.html
>
>
> under 10.4. I don't see why it shouldn't work under 10.5. I assume you
> use pyobjc? I had to use the signature-decorator to make the
> SM2DGraphDataSource-category work - but I'm not sure if pyobjc 2.0
> changes anything in that respect.
>
>
> Diez
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Replacing 'if __name__ == __main__' with decorator (was: Double underscores -- ugly?)

2008-02-23 Thread castironpi
> @mainmethod
> def main(...)
>
> and like this:
>
> @mainmethod(parser=myparser)
> def main(...)
>
> then you cannot use that decorator for a function that expects or
> allows a function as its first argument? Because how and

If it's called with only one non-keyword parameter, then the language
might have done it; if not, guaranteed not.  (More succintly, if it's
not, the language didn't.)

So, to get:
> @mainmethod
> def main(...)
you'll have to check the parameter counts, and you can never invoke
with just one callable parameter, pretty easy; bulky; your choice
between:

@mainmethod()
def main(...)

Note: 'Non-keyword' -and- callable!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Carl Banks wrote:
> On Feb 23, 6:40 am, Jeff Schwab <[EMAIL PROTECTED]> wrote:
>> Recently, I've had a few replies in tones that imply I'm on the brink of
>> entering several kill-files, mostly because I express disagreement with
>> a few closely held beliefs of some other c.l.p posters.
> 
> A bit of advice:
> 
> Python and C++ have almost no common ground in terms of what the
> priorties of the language are.

Producing software of measurable quality.  Increasing developer 
productivity.  Providing in-language support for formal design and 
development processes.  I think the languages approach the same 
high-level goals, just from very different angles.


> So, if you're a big proponent of the
> language features of C++, you really ought to expect lots of
> disagreement over just about anything you opine.
> 
> P.S. I've had much sharper disagreements with some Pythonistas over
> aspects of Python.  None of them are in my killfile.

Good to know. :)


>> One of the things that's supposed to be great about Python is the user
>> community, and in many ways, that community is wonderful; for example,
>> both new and experienced users can quickly get a variety of solutions to
>> any given coding issue, just by asking for help.
> 
> They say that about every small language community.

I'm not sure Python qualifies as a small community anymore.

Language-based communities that continue to support free thought and 
open conversation over time are much more rare.  The worst case scenario 
is (apologies in advance) the Lisp-style consensus: This language is 
just the best tool for every job, period.


>> In other ways, though, the Python community is just blindingly ignorant,
>> arrogant, and argumentative.
> 
> You're not exactly riding the humble bus there yourself, chief.
> Saying things like (in so many words), "I'm just here because C++
> doesn't have good runtime libraries", doesn't come off too well.

That's not how I feel, and I never meant to imply anything like it. 
Things I like about Python:

- No separate compilation step during development
- Emphasis on design-for-test
- Extensibility from other languages
- Clean syntax
- Portability
- Mainstream use and support
- Excellent documentation
- Large standard library
- Progress by design, rather than ad hoc "improvements"
- Design decisions value "useful" over "neat-o"
- Support for data-as-code (or code-as-data)


>> and I am starting to become
>> really concerned about the clarity of mind of the Python community,
>> because I hope to rely on it.
> 
> I think your expectations for the Python community are unreasonable.

Maybe.


> My advice to you, if you want a good relationship with the Python
> community, would be to keep the comparisons with C++ out of it as much
> as possible.  Understand that a lot--a lot--of people are going to say
> bad things about C++ and various features that C++ implements.  If you
> try to defend C++ every time that happens, you won't last long here.

Thanks.  I do value my sanity, and would like to preserve what's left of it.
-- 
http://mail.python.org/mailman/listinfo/python-list


python-list@python.org

2008-02-23 Thread castironpi
To whoso has a serious interest in multi-threading:

What advanced thread techniques does Python support?

1)  @synchronized

@synchronized
def function( arg ):
   behavior()

Synchronized prevents usage from more than one caller at once: look up
the function in a hash, acquire its lock, and call.

def synchronized( func ):
   def presynch( *ar, **kwar ):
  with _synchlock:
 lock= _synchhash.setdefault( func, allocate_lock() )
 with lock:
return func( *ar, **kwar )
   return presynch

2)  trylock:

trylock.acquire() returns False if the thread that currently owns it
is currently blocking on a lock that the calling thread currently
owns.  with trylock: instead throws an exception.  Implementation
pending.  If a timeout is specified, returns one of three values:
Success, Failure, and Deadlock.

3)  upon_acquiring( lockA, lockB )( function, *ar, **kwar )

upon_acquiring spawns new thread upon acquiring locks A and B.
Optional UponAcquirer( *locks ) instance can guarantee they are always
acquired in the same order, similar to the strategy of acquiring locks
in order of ID, but does not rely on the implementation detail of
having them.  Just acquire them in the order with which the instance
was initialized.

The similar construction:

while 1:
   lockA.acq()
   lockB.acq()

Is likewise efficient (non-polling), except in the corner case of
small numbers of locks and large numbers of free-acquire pairs, such
as in large numbers of lock clients, spec. threads.

4)  @with_lockarg

with_lockarg wraps an acquisition call, as in 2 or 3, and passes a
lock group to the function as a first parameter: yes, even
supersceding object instance parameters.

def function( locks, self, *ar, **kwar ):
   behavior_in_lock()
   locks.release()
   more_behavior()

function is called with the locks already held, so sadly though, with
locks: idiom is not applicable.

5)  groupjoin

for j in range( len( strats ) ):
  for k in range( j+ 1, len( strats ) ):
branch:
  i.matches[ j,k ]= Match( strats[j], strats[k] )
#Match instances may not be initialized until...
joinallthese()

This ideal may be implemented in current syntax as follows:

thg= ThreadGroup()
for j in range( len( strats ) ):
  for k in range( j+ 1, len( strats ) ):
@thg.branch( freeze( i ), freeze( j ) )
def anonfunc( i, j ):
  i.matches[ j,k ]= Match( strats[j], strats[k] )
#Match instances may not be initialized until...
thg.groupjoin()

Footnotes:

2: trylock actually checks a graph for cyclicity, not merely if the
individual callee is already waiting for the caller.
3: upon_acquiring as usual, a parameter can be passed to indicate to
the framework to preserve calling order, rather than allowing with
lockC to run prior to a series of threads which only use lockA and
lockB.
4: x87 hardware supports memory block pairs and cache pairs, which set
a reverse-bus bit upon truth of rudimentary comparisons, alleviating
the instruction stack of checking them every time through a loop;
merely jump to address when match completes.  Fortunately, the blender
doubles as a circuit-board printer after hours, so production can
begin at once.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ILeo (IPython-Leo bridge); a marriage made in heaven?

2008-02-23 Thread Ricardo Aráoz
Edward K Ream wrote:
>> Here is something cool that will rock your world (ok, excuse the slight 
>> hyperbole):
> 
> Many thanks for this posting, Ville.  It is indeed very cool:
> 
> - It shows how Leo can be used *now* as an IPython notebook.
> 
> - It expands the notion of what is possible with Leo/IPython/Python scripts.
> 
> Your ideas are destined to be of great importance to both the IPython and 
> Leo communities.
> I shall continue this discussion at:
> 
> http://groups.google.com/group/leo-editor/browse_thread/thread/3747a122f913cd7f
> 
> Edward
> 
> Edward K. Ream   email:  [EMAIL PROTECTED]
> Leo: http://webpages.charter.net/edreamleo/front.html
> 
> 
> 

Are you part of Leo? This smells like a marketing scheme to me.





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


Hyphenation module PyHyphen-0.3 released

2008-02-23 Thread Dr. leo
I am pleased to share with you the great features of the latest version.
Large parts of the sources were completely rewritten. Also, they are now
reasonably documented.

Just go to
http://pypi.python.org/pypi/PyHyphen/0.3

I was tempted to classify it as Beta. Indeed I am not aware of any bugs, but
I haven't spent very much time for testing, just ran some word lists...

Any feedback is greatly appreciated. Especially I would be interested in
experiences under Windows. I can only test it under Linux.

If there were a good soul to send me a DLL for Windows
([EMAIL PROTECTED]) , this would be terrific.

Bests

Leo


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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Nicola Musatti
Paul Rubin wrote:
> Nicola Musatti <[EMAIL PROTECTED]> writes:
>>>a = [f(x) + g(y) for x,y in izip(m1, m2) if h(x,y).frob() == 7]
[...]
> There you replace one line of code with 40+ lines to get around the
> absence of GC.  Sounds bug-prone among other things.

Come on, you didn't define f, g, izip, h or frob either. It's more like 
5 to one. Furthermore your code is more compact due to the existence of 
list comprehensions, not because of GC. Had you written a loop the 
difference would be smaller.

>> int f(int n) { return n * 2; }
>> int g(int n) { return ( n * 2 ) + 1; }
> 
> That is not a reasonable translation, since you've assumed the output
> of f and g are integers that don't need to be dynamically allocated.
> Maybe in the Python example, f and g and x and y are all bignums or
> matrices or something like that.

In my example I return a map by value just to show that it can be 
generalized to more complex data types. This is not C: in C++ you can go 
a long way without allocating dynamic memory explicitly. In my example 
std::map and std::vector do it for me.

Cheers,
Nicola Musatti
-- 
Nicola.Musatti  gmail  com
Home: http://nicola.musatti.googlepages.com/home
Blog: http://wthwdik.wordpress.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: graphing/plotting with python and interface builder

2008-02-23 Thread Jacob Davis
Thanks for the reply.

I have wxPython installed and have used it.  with wx I have just been  
using the wx.lib.plot module and the graphing is fine (although in  
other posts I note some focus issues).

I have been looking at moving to using interface builder 3.0 and  
building Cocoa apps because for a bigger project it might be faster  
and better code.

I only want to make plots that show data... but I need to refresh the  
plot at every step.  with wx.lib.plot, i just draw it again  
(performance is not too big of an issue).  No user interaction is  
needed.

I will check out Chaco.  Like I said, I know how to use wx.lib.plot,  
so if there is a way that I can use the graphs created there that  
would be great... although I suspect that wx.lib.plot requires a frame  
as a parent, which I would not want to use since .nib files (from  
interface builder) would handle the gui side with PyObjC (a language  
which I don't know).

Thanks

Jake

On Feb 22, 2008, at 10:30 PM, Peter Wang wrote:

> On Feb 22, 10:08 pm, Jacob Davis <[EMAIL PROTECTED]> wrote:
>> Hi.
>>
>> I am developing for mac and using Xcode and Interface Builder 3.0.  I
>> can make a simple application, but I am having a hard time trying to
>> figure out a good way to create a graph orplotfor a class project.
>>
>> Does anybody have any tips on where to get started, or on how to do
>> this?
>>
>> I have searched far for several days now, but I don't know if I am on
>> the right track.  Any help is much appreciated.
>>
>> Thanks,
>> Jake
>
>
> Jake, are you using any python-specific GUI libraries like wxPython,
> Qt, or Tk?  The Chaco plotting toolkit (http://code.enthought.com/
> chaco)  supports several different mechanisms for rendering on OS X;
> the default is to render via Quartz, but this requires wx or Qt.  I am
> also currently working on a (somewhat experimental) pure OpenGL
> backend, which doesn't require wxPython or Qt, just an active OpenGL
> context.
>
> Do you want to generate a fairly static plot, or do you want the user
> to be able to interact with it in some way?
>
>
> -Peter
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Nicola Musatti
Marc 'BlackJack' Rintsch wrote:
[...]
> Or are used to think of OOP as a graph of objects that are communicating
> with each other.  In the value type style you are "talking" to copies of
> objects all the time which I find a bit confusing because *I* have to keep
> track of which maybe not so identical twin brother of an object I'm
> talking at each point.

But C++ gives you both; you use values for things that have equality but 
not identity and (smart) pointers for the opposite case.

> Also it seems odd to me to copy large collections around instead of
> passing references.  Your `izip()` creates a quite small `map` -- what
> about big ones.  With mutable objects!?

True, and in a serious application I'd probably pass the map by 
reference into the function. Still, it's rather likely that these copies 
are optimized away by the compiler; this is what VC++ does, for instance.

Cheers,
Nicola Musatti
-- 
Nicola.Musatti  gmail  com
Home: http://nicola.musatti.googlepages.com/home
Blog: http://wthwdik.wordpress.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The big shots

2008-02-23 Thread Ricardo Aráoz
Dotan Cohen wrote:
> On 20/02/2008, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>  It's a bad sign.  If you aren't keeping your thoughts to yourself, and
>>  thrashing about the world for a peer, a social network, a support
>>  group, or a community, then you missed the day in grammar school when
>>  they were handing out smiles.  But they're not handing them out
>>  anymore.
> 
> You talk in analogies. I don't understand them. I do not know Spanish,
> and maybe if I knew both Spanish and your local customs, I would
> understand your analogies. But as a Hebrew-speaking middle easterner,
> I don't.
> 

I am a native Spanish speaker and I don't understand him either. It
is not cultural.


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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Carl Banks
On Feb 23, 6:40 am, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> Recently, I've had a few replies in tones that imply I'm on the brink of
> entering several kill-files, mostly because I express disagreement with
> a few closely held beliefs of some other c.l.p posters.

A bit of advice:

Python and C++ have almost no common ground in terms of what the
priorties of the language are.  So, if you're a big proponent of the
language features of C++, you really ought to expect lots of
disagreement over just about anything you opine.

P.S. I've had much sharper disagreements with some Pythonistas over
aspects of Python.  None of them are in my killfile.


> One of the things that's supposed to be great about Python is the user
> community, and in many ways, that community is wonderful; for example,
> both new and experienced users can quickly get a variety of solutions to
> any given coding issue, just by asking for help.

They say that about every small language community.


> In other ways, though, the Python community is just blindingly ignorant,
> arrogant, and argumentative.

You're not exactly riding the humble bus there yourself, chief.
Saying things like (in so many words), "I'm just here because C++
doesn't have good runtime libraries", doesn't come off too well.


> and I am starting to become
> really concerned about the clarity of mind of the Python community,
> because I hope to rely on it.

I think your expectations for the Python community are unreasonable.

My advice to you, if you want a good relationship with the Python
community, would be to keep the comparisons with C++ out of it as much
as possible.  Understand that a lot--a lot--of people are going to say
bad things about C++ and various features that C++ implements.  If you
try to defend C++ every time that happens, you won't last long here.


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


Re: Return value of an assignment statement?

2008-02-23 Thread John Henry
On Feb 23, 2:59 am, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> Dennis Lee Bieber wrote:
> > On Fri, 22 Feb 2008 11:23:27 -0800, Jeff Schwab <[EMAIL PROTECTED]>
> > declaimed the following in comp.lang.python:
>
> >> I'm about through with this discussion, but FWIW, this is a real gotcha
> >> for me and many others.  This is a case where Python does not do what
> >> many programmers expect, and it at least takes some getting used-to.
>
> >As opposed to the twice monthly shocked newbie discovering that a
> > mutable as a function default doesn't reset on the next invocation?
>
> >In that aspect, it all comes down to the difference between mutables
> > and immutables in Python.
>
> You know what's illuminating the discussion?  Everybody thinks they
> understand this issue, but the explanations are contradictory.  It seems
> like half the folks think this is an issue of mutability vs.
> immutability, and the other half believe that has nothing to do with it.

You mean like this:  :=)

def invoke_some_fct(parent):
   y = parent.x
   try:
  y += [ 'world' ]
   except:
  y += ( 'world', )
   print y, parent.x

class abc:
   def __init__(self):
  self.x=[ 'hello' ]
  invoke_some_fct(self)
  print self.x
  self.x=( 'hello', )
  invoke_some_fct(self)
  print self.x

hw = abc()
-- 
http://mail.python.org/mailman/listinfo/python-list


Web tutorial temporarily moved

2008-02-23 Thread learn2program
My programming tutorial web site has been dead this past week.
This is just to say that I have copied the English version to a
temporary mirror:

http://uk.geocities.com/[EMAIL PROTECTED]/

Normal service will hopefully be resumed soon.

Just in case anyone was wondering where it had gone! :-)

Alan Gauld
Author of the Learn to Proram web site
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Handling locked db tables...

2008-02-23 Thread M.-A. Lemburg
On 2008-02-20 17:19, breal wrote:
> On Feb 20, 8:05 am, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote:
>> On 2008-02-20 16:24, breal wrote:
>>
>>> I have a db table that holds a list of ports.  There is a column
>>> in_use that is used as a flag for whether the port is currently in
>>> use.  When choosing a port the table is read and the first available
>>> port with in_use = 0 is used, updated to in_use = 1, used, then
>>> updated to in_use = 0.  I am using MySQLdb and want to make sure I am
>>> locking the table when doing reads, writes, updates since there will
>>> be several instances of my program looking for available ports
>>> simultaneously.
>>> When I run a "lock table mytable read" I can do all of my
>>> transactions.  But, when another cursor then tries to do the read I
>>> get an error unless the first process has been completed... unlocking
>>> the tables.  How is this handled generally?
>> This is normal database locking behavior. If you do an update to
>> a table from one process, the updated row is locked until the
>> transaction is committed.
>>
>> If another process wants to access that row (even if only indirectly,
>> e.g. a select that does a query which includes the data from the locked
>> row), that process reports a database lock or times out until the
>> lock is removed by the first process.
>>
>> The reason is simple: you don't want the second process to report
>> wrong data, since there's still a chance the first process might
>> roll back the transaction.
>>
>> Most modern database allow row-level locking. I'm not sure whether
>> MySQL supports this. SQLite, for example, only support table locking.
>
> Marc-Andre,
> 
> Thanks for the reply.  I understand that this is normal locking
> behavior.  What I am looking for is a standard method to either loop
> the query until the table is unlocked, or put the query into some sort
> of queue.  Basically my queries work like this.
> 
> Request comes in
> 
> PART I:
> LOCK TABLE port_usage READ;
> SELECT * FROM port_usage WHERE in_use = 0;
> Get available port
> UPDATE port_usage SET in_use = 1 WHERE port = available_port;
> UNLOCK TABLES;
> 
> send request to available port and do some stuff until finished with
> port
> 
> PART II:
> LOCK TABLE port_usage READ
> UPDATE port_usage SET in_use = 0 WHERE port = available_port;
> UNLOCK TABLES;
> 
> Several of these *may* be happening simultaneously so when a second
> request comes in, and the first one has the table locked, I want to
> have the PART I sql still work.  Any suggestions here?

Ok, so you want to use the table to manage locks on a resource.

This is tricky, since the SELECT and UPDATE operations do not
happen atomically. Also a READ lock won't help, what you need
is a WRITE lock. Note that the UPDATE causes an implicit
WRITE lock on the row you updated which persists until the end
of the transaction.

The way I usually approach this, is to mark the row for usage
using an indicator that's unique to the process/thread requesting the
resource. In a second query, I fetch the marked resource via the
indicator.

When freeing the resource, I update the row, again using the
indicator and also clear the indicator from the row.

All this is done on an auto-commit connection, so that no locking
takes place. Works great.

-- 
Marc-Andre Lemburg
eGenix.com

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


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


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


Re: Return value of an assignment statement?

2008-02-23 Thread Jeff Schwab
Arnaud Delobelle wrote:
> On Feb 23, 3:44 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote:
>>  actions = (
>>  ('some_string', do_something),
>>  ('other_string', do_other_thing))
>>
>>  def find_action(pattern):
>>  for string, action in actions:
>>  m = pattern.match(string)
>>  if m:
>>  return action
>>  return do_default_thing
>>
>>  find_action(re.compile('some pattern'))()
> 
> You don't need to pass the pattern, just pass the match function:
> 
> def find_action(match, actions=actions, default_action=None):
> for string, action in actions:
> if match(string):
> return action
> return default_action
> 
> find_action(re.compile('some pattern').match)()

That's cool. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Paul Hankin
On Feb 22, 7:01 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Feb 22, 12:54 pm, Paul Rubin  wrote:
>
> > Paul Rubin  writes:
> > >     if any(x==element[0] for x in a):
> > >       a.append(element)
>
> > Should say:
>
> >      if any(x[0]==element[0] for x in a):
> >         a.append(element)
>
> I think you have this backwards.  Should be:
>
>      if not any(x[0]==element[0] for x in a):
>         a.append(element)

IMO Jason's solution of testing containment in a generator is better
(more readable).
if element[0] not in (x[0] for x in a):
a.append(element)

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


Re: Return value of an assignment statement?

2008-02-23 Thread Arnaud Delobelle
On Feb 23, 3:44 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote:
>
>      actions = (
>              ('some_string', do_something),
>              ('other_string', do_other_thing))
>
>      def find_action(pattern):
>          for string, action in actions:
>              m = pattern.match(string)
>              if m:
>                  return action
>          return do_default_thing
>
>      find_action(re.compile('some pattern'))()

You don't need to pass the pattern, just pass the match function:

def find_action(match, actions=actions, default_action=None):
for string, action in actions:
if match(string):
return action
return default_action

find_action(re.compile('some pattern').match)()

--
Arnaud

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


Tkinter: Missing the last piece of the puzzle

2008-02-23 Thread MartinRinehart
I have a simple editor built into my visual parser. It has a File menu
with
typical New, Open, Save, Save As ... options. I now know how to set
the options [en/dis]abled and how to check the Text widget's modified
flag.

Now I want to [en/dis]able those options. Can I ask the text to notify
me when the modified flag changes? Can I set the statuses when the
user clicks File, before the options are displayed? Do I need to
create
a checker on an independent thread that looks at the flag every few
millis?

(Tkinter deserves more respect. I've got a good-looking application
growing quickly.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return value of an assignment statement?

2008-02-23 Thread Paddy
On 21 Feb, 23:33, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> > What you can't do (that I really miss) is have a tree of assign-and-test
> > expressions:
>
> > import re
> > pat = re.compile('some pattern')
>
> > if m = pat.match(some_string):
> > do_something(m)
> > else if m = pat.match(other_string):
> > do_other_thing(m)
> > else:
> > do_default_thing()
>
> What you want is:
>
> for astring, afunc in ((some_string, do_something), (other_string,
> do_other_thing)):
> m = pat.match(astring)
> if m:
> afunc(m)
> break
> else:
> do_default_thing()

The Bruno transform? :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Paul Rubin wrote:
> Jeff Schwab <[EMAIL PROTECTED]> writes:
>> The most traditional, easiest way to open a file in C++ is to use an
>> fstream object, so the file is guaranteed to be closed when the
>> fstream goes out of scope.  
> 
> Python has this too, except it's using a special type of scope
> created by the "with" statement.

Yes, this seems to be the Python way:  For each popular feature of some
other language, create a less flexible Python feature that achieves the
same effect in the most common cases (e.g. lambda to imitate function
literals, or recursive assignment to allow x = y = z).


>> CPython offers a similar feature, since
>> you can create a temporary object whose reference count will become
>> zero at the end of the statement where it is defined:
> 
>>  $ echo world >hello
>>  $ python
>>  >>> file('hello').read()
>>  'world\n'
> 
> CPython does not guarantee that the reference count will become zero
> at the end of the statement.  It only happens to work that way in your
> example, because the file.read operation doesn't make any new
> references to the file object anywhere.

It doesn't "happen" to work that way in the example; it works that way
by design.  I see what you're saying, though, and it is a good point.
Given a statements of the form:

some_class().method()

The method body could create an external reference to the instance of
some_class, such that the instance would not be reclaimed at the end of
the statement.


> Other code might well do
> something different, especially in a complex multi-statement scope.
> Your scheme's

It's not "my" scheme.  I got it from Martelli.


> determinism relies on the programmer accurately keeping
> track of reference counts in their head, which is precisely what
> automatic resource management is supposed to avoid.

This is a special case of the reference count being 1, then immediately 
dropping to zero.  It is simple and convenient.  The approach is, as you 
rightly point out, not extensible to more complicated situations in 
Python, because the reference counting ceases to be trivial.

The point is that once you tie object lifetimes to scope, rather than 
unpredictable garbage collection, you can predict with perfect ease and 
comfort exactly where the objects are created and destroyed.  If you can 
then request that arbitrary actions be taken automatically when those 
events happen, you can pair up resource acquisitions and releases very 
easily.  Each resource has an "owner" object whose constructor acquires, 
and whose destructor releases.  The resources are released in the 
reverse order, which is almost always exactly what you want.

Suppose you are using objects that have to be closed when you have 
finished with them.  You would associate this concept with a type:

 class Closer:
 def __init__(self, closable):
 self.closable = closable)
 def __del__(self):
 self.closable.close()

The C++-style paradigm would then let you do this:

 def my_func(a, b, c):
 a_closer = Closer(a)
 b_closer = Closer(b)
 c_closer = Closer(c)

# ... arbitrary code ...

If an exception gets thrown, the objects get closed.  If you return 
normally, the objects get closed.  This is what "with" is supposed to 
replace, except that it only seems to cover the trivial case of a 
single, all-in-one cleanup func.  That's only a direct replacement for a 
single constructor/destructor pair, unless you're willing to have an 
additional, nested with-statement for each resource.

Now suppose there is an object type whose instances need to be 
"released" rather than "closed;" i.e., they have a release() method, but 
no close() method.  No problem:  You have the Closer class get its 
action indirectly from a mapping of types to close-actions.  Whenever 
you have a type whose instances require some kind of cleanup action, you 
add an entry to the mapping.

 class Closer:
actions = TypeActionMap()

 # ...

 def __del__(self):
 actions[type(self.closable)](self.closable)

The mapping is not quite as simple as a dict, because of inheritance. 
This is what function overloads and C++ template specializations are 
meant to achieve.  Similar functionality could be implemented in Python 
via pure Python mapping types, represented above by TypeActionMap.


> If you want
> reliable destruction it's better to set it up explicitly, using
> "with".

That's true of the current language.  I don't have enough experience 
with "with" yet to know whether it's a realistic solution to the issue. 
  IMO, they are at least preferable to Java-style finally-clauses, but 
probably not a replacement for C++-style RAII.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Boris Ozegovic
TeroV wrote:

> It isn't list comprehension, it is generator expression 
> http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generator_expressions

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


integrating python with owl

2008-02-23 Thread Noorhan Abbas
Hello,
I have developed an ontology using protege owl and  I wonder if you can help me 
get any documentation on how to integrate it with python.

Thank you very much,
Noorhan.


  __
Sent from Yahoo! Mail.
A Smarter Inbox. http://uk.docs.yahoo.com/nowyoucan.html-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Return value of an assignment statement?

2008-02-23 Thread Jeff Schwab
Jeff Schwab wrote:
> mrstephengross wrote:
>> Hi all. In C, an assignment statement returns the value assigned. For
>> instance:
>>
>>   int x
>>   int y = (x = 3)
>>
>> In the above example, (x=3) returns 3, which is assigned to y.
>>
>> In python, as far as I can tell, assignment statements don't return
>> anything:
>>
>>   y = (x = 3)
>>
>> The above example generates a SyntaxError.
>>
>> Is this correct? I just want to make sure I've understood the
>> semantics.
> 
> Yes, but there is valid syntax for the common case you mentioned:
> 
> y = x = 3
> 
> What you can't do (that I really miss) is have a tree of assign-and-test 
> expressions:
> 
> import re
> pat = re.compile('some pattern')
> 
> if m = pat.match(some_string):
> do_something(m)
> else if m = pat.match(other_string):
> do_other_thing(m)
> else:
> do_default_thing()


This is apparently section 1.9 of the Python Cookbook:

http://www.oreilly.com/catalog/pythoncook2/toc.html

Martelli suggests something similar to the "thigamabob" technique I use 
(he calls it DataHolder).  It's really more like the "xmatch" posted by 
Paul Rubin.

Martelli also says, though, that if you need this, you're not thinking 
Pythonically.  I don't know what the Pythonic alternative is.  The 
iterating-over-pairs approach suggested by Bruno is the only alternative 
I've seen.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return value of an assignment statement?

2008-02-23 Thread Jeff Schwab
[EMAIL PROTECTED] wrote:
>> What you can't do (that I really miss) is have a tree of assign-and-test
>> expressions:
>>
>> import re
>> pat = re.compile('some pattern')
>>
>> if m = pat.match(some_string):
>> do_something(m)
>> else if m = pat.match(other_string):
>> do_other_thing(m)
>> else:
>> do_default_thing()
> 
> What you want is:
> 
> for astring, afunc in ((some_string, do_something), (other_string,
> do_other_thing)):
> m = pat.match(astring)
> if m:
> afunc(m)
> break
> else:
> do_default_thing()

That looks like the first realistic alternative I've seen.  I find the 
flow a little hard to follow, but I think that's mostly just because I'm 
not accustomed to the syntax.

Your approach fits in my head a little more comfortably if none of the 
lines are longer than eighty columns, if the for-loop isn't given an 
else-clause (which still looks to my untrained eye like it should match 
the preceding if), and if the break-statement is replaced with a 
return-statement:

 actions = (
 ('some_string', do_something),
 ('other_string', do_other_thing))

 def find_action(pattern):
 for string, action in actions:
 m = pattern.match(string)
 if m:
 return action
 return do_default_thing

 find_action(re.compile('some pattern'))()
-- 
http://mail.python.org/mailman/listinfo/python-list


Prophet Muhammad the last Messenger in the Bible

2008-02-23 Thread dawa-dawa

Prophet Muhammad the last Messenger in the Bible
http://www.islamhouse.com/p/51913
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread TeroV
Boris Ozegovic wrote:
> Paul Rubin wrote:
> 
>>  if any(x[0]==element[0] for x in a): 
> 
> How come this list comprehension isn't in [] brackets?

It isn't list comprehension, it is generator expression 
http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generator_expressions

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


Re: Odd behaviour of *.pth files and Apache

2008-02-23 Thread D'Arcy J.M. Cain
On Thu, 21 Feb 2008 13:55:25 -0500
"D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote:
> I tried searching the archives for information on this but nothing
> seemed to be germane.  I am running Python sripts as CGI under Apache
> and I have a .pth file in site-packages that includes directory that
> has another .pth in it.  Sometimes it picks up the paths in the
> second .pth and sometimes it does not.  It always seems to work if I am
> working in a location not in the ServerRoot but if I use the main site
> it does not pick up the directories in the included .pth.

I have more information now.  It seems that it recurses the .pth files
it finds in PYTHONPATH but not for directories found in the .pth files
in site-packages.  Is this expected behaviour?  The documentation
suggests that it should pick up both.

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


Re: Getting stdout from other processes

2008-02-23 Thread Matthias Vogelgesang
Hi,

Miki wrote:
> The current "official" module to use is subprocess (pipe =
> Popen([client], stdout=PIPE))
> However if the client is sending data, reading from the pipe.stdout
> will block the server.
> If you *need* to wait, then you can use pipe.wait(), otherwise do as
> Diez suggested and have a thread
> read the client output and propagate it to the main loop (maybe using
> Queue.Queue)

Thanks both of you for your explanations. In fact, it did the trick.

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


Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Boris Ozegovic
Paul Rubin wrote:

>  if any(x[0]==element[0] for x in a): 

How come this list comprehension isn't in [] brackets?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ILeo (IPython-Leo bridge); a marriage made in heaven?

2008-02-23 Thread Edward K Ream
> Here is something cool that will rock your world (ok, excuse the slight 
> hyperbole):

Many thanks for this posting, Ville.  It is indeed very cool:

- It shows how Leo can be used *now* as an IPython notebook.

- It expands the notion of what is possible with Leo/IPython/Python scripts.

Your ideas are destined to be of great importance to both the IPython and 
Leo communities.
I shall continue this discussion at:

http://groups.google.com/group/leo-editor/browse_thread/thread/3747a122f913cd7f

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: graphing/plotting with python and interface builder

2008-02-23 Thread Diez B. Roggisch
Jacob Davis schrieb:
> Hi.
> 
> I am developing for mac and using Xcode and Interface Builder 3.0.  I 
> can make a simple application, but I am having a hard time trying to 
> figure out a good way to create a graph or plot for a class project.
> 
> Does anybody have any tips on where to get started, or on how to do this?
> 
> I have searched far for several days now, but I don't know if I am on 
> the right track.  Any help is much appreciated.

I use

http://developer.snowmintcs.com/frameworks/sm2dgraphview/index.html


under 10.4. I don't see why it shouldn't work under 10.5. I assume you 
use pyobjc? I had to use the signature-decorator to make the 
SM2DGraphDataSource-category work - but I'm not sure if pyobjc 2.0 
changes anything in that respect.


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


Re: can't set attributes of built-in/extension type

2008-02-23 Thread Steve Holden
Neal Becker wrote:
> Steve Holden wrote:
> 
>> Neal Becker wrote:
>>> Steve Holden wrote:
>>>
 Neal Becker wrote:
> 7stud wrote:
>
>> On Feb 21, 11:19 am, Neal Becker <[EMAIL PROTECTED]> wrote:
>>> I'm working on a simple extension.  Following the classic 'noddy'
>>> example.
>>>
>>> In [15]: cmplx_int32
>>> Out[15]: 
>>>
>>> Now I want to add an attribute to this type.  More precisely, I want
>>> a class attribute.
>>>
>>> cmplx_int32.test = 0
>>> ---
>>> TypeError Traceback (most recent call
>>> last)
>>>
>>> /home/nbecker/numpy/ in ()
>>>
>>> TypeError: can't set attributes of built-in/extension
>>> type 'numpy.cmplx_int32'
>>>
>>> What am I missing?
>> class Dog(object):
>> def __setattr__(self, attr, val):
>> print "TypeError: can't set attributes of built-in/extension"
>> print "type 'Dog.cmplx_int32'"
>>
>> d = Dog()
>> d.test = 0
>>
>> --output:--
>> TypeError: can't set attributes of built-in/extension
>> type 'Dog.cmplx_int32'
> Not quite, I'm setting a class attribute, not an attribute on an
> instance.
>
 Quite. The problem is that extension types' attributes are determined by
 the layout of the object's slots and forever fixed in the C code that
 implements them: the slots can't be extended, so there's no way to add
 attributes. This is an efficiency feature: it would be *extremely* slow
 to look up the basic types' attributes using late-binding (it would also
 change the nature of the language somewhat, making it more like Ruby or
 Self).

 So the reason you can't do what you want to is the same reason why you
 can't add attribute to the built-in types (which are, of course, clearly
 mentioned in the error message).

  >>> object.anyoldname = "You lose!"
 Traceback (most recent call last):
File "", line 1, in 
 TypeError: can't set attributes of built-in/extension type 'object'
  >>>

 If you look in typeobject.c you'll find this error message occurs when
 the object's type isn't a PyHeapTypeObject (in other words, if it's one
 of the built-in or extension types).

>>> Thanks, but I'm a bit confused.  After reading in my "Python in a
>>> Nutshell", I found that if after calling PyReady on my type object, if I
>>> use PyDict_SetItemString (my_type_obj.tp_dict,)
>>>
>>> That seems to work fine (which isn't exactly what it said in the Nutshell
>>> book, but close).
>>>
> 
> I wanted to add an attribute to my type.
> Specifically, my type object is a static cmplx_int32_scalar_obj.
> 
> After calling PyType_Ready (&cmplx_int32_scalar_obj), then I did
> PyDict_SetItemString (cmplx_int32_scalar_obj.tp_dict, "dtype", (PyObject*)d1);
> 
> Now my type has the property:
> cmplx_int32.dtype
> dtype('cmplx_int32')
> 
> Now, I do see that I still can't set it:
> 
> cmplx_int32.dtype = 2
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: can't set attributes of built-in/extension type 'numpy.cmplx_int32'
> 
> In this case, I don't need to.
> 
> But I still don't know why I can have a python class and set class or instance
> attributes as I like, but this type acts differently.  What would I need to 
> do if I did want to allow arbitrary attributes to be set/added to my type?
> 
I believe it's because PyType_Ready(), among its many other duties,
calls mro_internal() on the type. It seems obvious that one would want
to optimize the MRO by not allowing modifications. Yet in C it is
possible, as you point out, to do so. Hmm ...

I'll let you know if I come to any conclusion - a query to python-dev
would probably get an answer, but surely someone on this list knows already?

[Left this as a draft for a while to mull it over].

After further consideration I have concluded (without further scrutiny 
of the source) that it's because the method slots in C-implemented types 
are pointers to C functions not to Python functions. Would this make sense?

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

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


Re: Return value of an assignment statement?

2008-02-23 Thread Steve Holden
Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> Personally, I think the confusion of augmented assignments is not worth 
>> the benefit of saving typing a couple of characters. I think Guido's 
>> first decision, to leave += etc out of the language, was the right 
>> decision.
> 
> It quite helpful to be able to say
> 
>   foo['bar'+lookup(baz)][blob(a)+frob(b)] += 1
> 
> without having to split it into separate statements to avoid repeating
> the function calls and their possible side effects.

And that was the reason for eventually including them. I remember being 
very surprised when I learned that rebinding was possible at the option 
of the implementing object, but of course rebinding is inevitable when 
you have immutable objects that implement augmented assignments.

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

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


Re: n00b with urllib2: How to make it handle cookie automatically?

2008-02-23 Thread Steve Holden
7stud wrote:
> On Feb 21, 11:50 pm, est <[EMAIL PROTECTED]> wrote:
>> class SmartRequest():
>>
> 
> You should always define a class like this:
> 
> class SmartRequest(object):
> 
> 
> unless you know of a specific reason not to.
> 
> 
It's much easier, though, just to put

__metaclass__ = type

at the start of any module where you want exlusively new-style objects. 
And I do agree that you should use exclusively new-style objects without 
a good reason for not doing, though thanks to Guido's hard work it 
mostly doesn't matter.

$ cat test94.py
__metaclass__ = type

class Rhubarb:
 pass

rhubarb = Rhubarb()

print type(Rhubarb)
print type(rhubarb)


$ python test94.py



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

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


Re: Globals or objects?

2008-02-23 Thread Steve Holden
Steven D'Aprano wrote:
> On Fri, 22 Feb 2008 18:53:54 +, tinnews wrote:
> 
 But you're not comparing what the OP posted.  He was comparing a
 global with an object with a single variable inside it.  Either would
 work with the y = spam(arg) example above.
>>> What do you mean by "an object with a single variable inside it"? I
>>> don't understand what that is supposed to mean, or why you think it is
>>> the same as a global. Do you mean a Singleton?
>>>
>>> If so, then the answer is simple: using a Singleton argument instead of
>>> a global is better, because with a global you are stuck to always using
>>> the global (at least until you can re-write the code), but with the
>>> Singleton argument, you may be enlightened and *not* use a Singleton.
>>>
>> But if you stop using the Singleton the code no longer does the same as
>> it would with a global does it?
> 
> That's a *good* thing, not a problem. The whole idea is to get away from 
> the bad behaviour of globals, not find some other way to implement it.
> 
I think that advocation of a global singleton is not really solving the 
problem. Not the problem I perceive, anyway. From your comments it's 
difficult to see whether we share the same perceptions, so let me elucidate.

The issue I have with globals is primarily that use of a global 
introduces a tight coupling between a function and its environment, 
since any environment that uses the function has to provide the global.

It's true that a global singleton is a half-way step to a solution of 
the problem because it portends the true solution, which also solves the 
problem of multiple counts. That solution, of course, is to have the 
"function" become a method of some counter object, which can then be 
used to count many things.

In other words (untested, so ignore the many Holden types that this will 
inevitably incur):


bad.py:

counter = 0

def count(n):
 global counter
 counter += n

justasbadifnotworse.py:

class bunch: pass;

counter = bunch()
bunch.count = 0

def count(n):
 counter.count += n

better.py:

class Counter:
 def __init__(self):
 self.count = 0

counter1 = Counter()
counter2 = Counter()

def count(n, counter):
 counter.count += n

best.py:

class Counter:
 def __init__(self):
 self.count = 0
 def count(self, n):
 self.count += n


Now the names I have chosen are pejorative, but this is typically the 
development you see in someone's programming style as they slowly (or 
not slowly) start to understand the value of the object-oriented approach.

Unfortunately this sometimes goes too far, and people end up writing 
"monster objects", with dozens of methods and lots of instance variables 
used to communicate between them. With that style of programming the 
instance variables introduce the same tight coupling between the methods 
that globals do in a less object-oriented style, and the code becomes 
just as difficult to understand. Only now there can be multiple 
instances of the badly-written function!

Sometimes this is inevitable, but good programming style is about trying 
to strike the right balance between contexts. It is truly possible to 
write good and bad programs in any language you like, and rules like 
"globals are bad" need to be taken in context just like any other rule.

After all, some things *have* to be global for our programs to make any 
sense at all, unless you want to adopt a truly functional style that has 
never appealed to me. I like my programs to have state.

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

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Jeff Schwab
Ryan Ginstrom wrote:
>> On Behalf Of Jeff Schwab
>> When I see this silliness again and again, it really breaks 
>> my heart
> 
> If you allow your heart to be broken by others' opinions, you're setting
> yourself up for a lot of disappointment IMHO.

It's not so much their opinions, as the fact that their opinions 
strongly influence their work.  But you're probably right, anyway.


> I personally used C++ for about 90% of my code for 10 years. During that
> time, I was chugging the C++ Kool-Aid so hard I almost peed myself.> I still
> think that C++ is a beautiful language, but I have also come to think that
> starting a program with C++ is a premature optimization. 

I'm not much of a Kool Aid drinker. :)  I just tend to find, when I 
develop anything non-trivial in a language other than C++, that I wish I 
had used C++, because it would have allowed me to enforce design 
semantics more efficiently.  Optimization has nothing to do with it; I'm 
a firm believer in profiling before you optimize.


> I think that very few Python programmers today started with Python. Most of
> them came to Python for a reason. 

For several reasons, even!
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Ryan Ginstrom
> On Behalf Of Jeff Schwab
> When I see this silliness again and again, it really breaks 
> my heart

If you allow your heart to be broken by others' opinions, you're setting
yourself up for a lot of disappointment IMHO.

I personally used C++ for about 90% of my code for 10 years. During that
time, I was chugging the C++ Kool-Aid so hard I almost peed myself. I still
think that C++ is a beautiful language, but I have also come to think that
starting a program with C++ is a premature optimization. 

I think that very few Python programmers today started with Python. Most of
them came to Python for a reason. 

Regards,
Ryan Ginstrom

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


  1   2   >