Re: Project organization and import

2007-03-05 Thread Martin Unsal
On Mar 5, 3:11 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Your own experience *with Python* ?

No, my experience with Visual Basic. ;)

Of course my experience with Python!

Sorry, I can continue writing snarky replies to your snarky comments
but that won't get us anywhere productive. Instead I think the
following really gets to the crux of the issue.

> May I say that the problem here comes from your insistance on putting
> each class in a single module ?

No, it doesn't.

It really doesn't matter how many classes you have in a module; either
you use "from foo import bar", or you are stuck with a file structure
that is isomorphic to your design namespace.

The former breaks reload; the latter breaks large projects.

Martin

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


Re: worker thread catching exceptions and putting them in queue

2007-03-05 Thread Paul Sijben
Stargaming & Diez,

thanks very much!

Stargaming wrote:
> Paul Sijben schrieb:
>> All,
>>
>> in a worker thread setup that communicates via queues is it possible to
>> catch exceptions raised by the worker executed, put them in an object
>> and send them over the queue to another thread where the exception is
>> raised in that scope?
>>
>> considering that an exception is an object I feel it ought to be
>> possible, however I do not see how to go about it.
>>
>> does anyone have a pointer towards the solution?
>>
>> Paul
> 
> You're right, even exceptions are objects in Python. For further
> studies, read http://docs.python.org/lib/module-exceptions.html
> 
> You can catch an exception like this:
> try:
>   worker.do_some_work_that_may_raise_an_exception()
> except Exception, e:
>   # the first argument is the type of error you want to handle
>   # it is Exception here, the baseclass of all computation exceptions
>   # the second argument is the variable (name) where you want to save
>   # the specific exception raised to
>   # it's 'e' here, a common shortcut for exception
>   exception_handler.handle(e)
>   # notice that you can pass e around as you like
> 
> For further information on exceptions and how to handle them, read
> chapter 8 of the tutorial, especially starting from 8.3:
> http://docs.python.org/tut/node10.html#SECTION001030
> 
> P.S. I don't know if what I told still applies to Python 3.0 -- a lot of
> changes are upcoming related to exception raising and handling.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graphviz Python Binding for Python 2.5 on Windows?

2007-03-05 Thread Nick Vatamaniuc
On Mar 5, 5:16 pm, "Alex Li" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I would like to use Python 2.5 on Windows with Graphviz to generate
> graphs.  I used yapgvb but it only requires Python 2.4 (won't work
> with Python 2.5).  Other packages like pydot seems to be unmaintained
> or requires custom building to be used on Windows (pygraphviz), which
> I tried to avoid.  Any suggestions?
>
> Thanks in advance,
> Alex

Alex,
You can always pipe your dot file directly to the dot or neato
executables using the subprocess method then read the output. This way
you don't have to install yapgvb or other adapters and it will work
with Python 2.5. But you will need to compose your dot file as a giant
character buffer...
-Nick V.

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


Re: Project organization and import

2007-03-05 Thread Martin Unsal
On Mar 5, 11:06 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> I never advocated big files with many functional units - just files
> that are "just big enough".

Then we're in total agreement. I'm not sure why you thought my
opinions were the result of baggage from other languages when you
don't seem to actually disagree with me.

> Fewer dependencies between compilation units means a
> faster rebuild-test turnaround.

I know all about incremental builds and I just don't think people use
small compilation units in C++ to make their builds faster. It
certainly never been the reason why I subdivided a source file.

> Sure, but whats your goal here? If you're just testing something as
> you work, then this works fine. If you're testing large changes, that
> affect many modules, then you *need* to reload your world, because you
> want to make sure that what you're testing is clean.

I don't think reload works for anything but trivial scripts. The
moment you use "from foo import bar" reload is broken.

> The semantics of exactly what reload should do are tricky. Pythons
> reload works in a sensible but limited way.

I agree that there is some subtlety there, and I appreciate your
example. However the fact that Python's module system essentially
forces you to use "from foo import *" and that reload is almost
entirely imcompatible with "from foo import *", I would say that
reload is essentially useless.

> That said, nothing prevents you from using "from foo import Foo" if
> Foo is all you need (or need most - you can combine this with import
> foo).

Well "from foo import Foo" is just a special case of "from foo import
*". :) It still breaks reload. It still means you're restarting your
interpreter even to do the most trivial development cycle.

> I wonder what environments you worked in before that actually had a
> reliable and gotcha free version of reload?

I'm perfectly well aware that I'm not going to be able to reload a
widget in the middle of a running GUI app, for example. I'm not
looking for gotcha free, I'll settle for minimally useful.

Here's an analogy. In C, you can do an incremental build and run your
modified application without having to first reboot your computer. In
Python, where reload() is essentially the incremental build process,
and the interpreter is essentially a virtual machine, you guys are
saying that my best option is to just "reboot" the virtual machine to
make sure I have a "clean slate". It may be the path of least
resistance, but to say that it is necessary or inevitable is 1960s
mainframe thinking.

Martin

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


Re: How to Read Bytes from a file

2007-03-05 Thread Hendrik van Rooyen
 "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:


> On Mar 5, 10:51 am, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
> > > "Bart Ogryczak" <[EMAIL PROTECTED]> (BO) wrote:
> > >BO> Any system with 8-bit bytes, which would mean any system made after
> > >BO> 1965. I'm not aware of any Python implementation for UNIVAC, so I
> > >BO> wouldn't worry ;-)
> >
> > 1965? I worked with non-8-byte machines (CDC) until the beginning of the
> > 80's. :=( In fact in that time the institution where Guido worked also had
such
> > a machine, but Python came later.
>
> Right, I should have written 'designed' not 'made'. UNIVACs also have
> been produced until early 1980s. Anyway, I'd call it
> paleoinformatics ;-)

The correct term is: "Data Processing", or DP for short.

- Hendrik

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


Re: How to Read Bytes from a file

2007-03-05 Thread Hendrik van Rooyen
 "Piet van Oostrum" <[EMAIL PROTECTED]> wrote:

> > "Bart Ogryczak" <[EMAIL PROTECTED]> (BO) wrote:
>
> >BO> Any system with 8-bit bytes, which would mean any system made after
> >BO> 1965. I'm not aware of any Python implementation for UNIVAC, so I
> >BO> wouldn't worry ;-)
>
> 1965? I worked with non-8-byte machines (CDC) until the beginning of the
> 80's. :=( In fact in that time the institution where Guido worked also had
such
> a machine, but Python came later.

Those behemoths were EXPENSIVE - so it made a lot of sense to keep using
them until the point that it became obvious even to an accountant that the
maintenance cost was no longer worth it...

Would actually not surprise me if there were still a few around, doing
electricity
accounts or something.

- Hendrik

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


Re: package_data question

2007-03-05 Thread bytecolor
On Mar 5, 3:52 pm, "Goldfish" <[EMAIL PROTECTED]> wrote:
> On Mar 5, 1:56 am, "bytecolor" <[EMAIL PROTECTED]> wrote:

> I have a package along with a samples section. I have both a setup.py
> script along with a MANIFEST.in file to make sure everything gets in.
> You can see both of the files 
> athttps://springpython.python-hosting.com/browser/trunk/samples

http://tinyurl.com/yo3qqo

>
> That is for the samples section. For my main package, I have something
> similar athttps://springpython.python-hosting.com/browser/trunk/src

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


Re: This web site creates a *popup window* => how fetch contents in a script?

2007-03-05 Thread Gabriel Genellina
En Tue, 06 Mar 2007 03:18:23 -0300, [EMAIL PROTECTED]  
<[EMAIL PROTECTED]> escribió:

> The following web page puts a report in a *popup window* by clicking
> the "Generate Report" button
>
> http://moneycentral.msn.com/investor/research/printrep.asp?Symbol=BBBY
>
> How can I grab this pop window page in a python script? (It doesn't
> seem to have a URL!?!)

Of course it has:
http://moneycentral.msn.com/investor/research/sreport.asp?Symbol=BBBY&Y1=1&CR=1&Type=Equity
If your browser don't let you know the actual URL... try a better browser  
:)

-- 
Gabriel Genellina

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


This web site creates a *popup window* => how fetch contents in a script?

2007-03-05 Thread [EMAIL PROTECTED]
The following web page puts a report in a *popup window* by clicking
the "Generate Report" button

http://moneycentral.msn.com/investor/research/printrep.asp?Symbol=BBBY

How can I grab this pop window page in a python script? (It doesn't
seem to have a URL!?!)

chris

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


Re: Project organization and import

2007-03-05 Thread Alex Martelli
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:

> >>I don't reload...  When my investigative tests gets bigger I write a script
> >>and run it with the interpreter.  It is easy since my text editor can call
> >>Python on a buffer (I use Emacs).
> >  
> > That's interesting, is this workflow pretty universal in the Python
> > world?
> 
> I don't know, but that's also mostly how I do work.

My favorite way of working: add a test (or a limited set of tests) for
the new or changed feature, run it, check that it fails, change the
code, rerun the test, check that the test now runs, rerun all tests to
see that nothing broke, add and run more tests to make sure the new code
is excellently covered, rinse, repeat.  Occasionally, to ensure the code
stays clean, stop to refactor, rerunning tests as I go.

I'm also keen on bigger tests (integration tests, as well as system
tests for regressions, acceptance, etc), but of course I don't run those
anywhere as frequently (they're not part of my daily workflow, iterated
multiple times per day -- more like a "nightly run" kind of thing, or
for special occasions such as just before committing into HEAD... I'm
somewhat of a stickler about HEAD *always* passing *all* tests...).

Not exactly TDD, please note -- I tend to start the cycle with a few
tests (not strictly just one), implement some large chunk of the
new/changed stuff, and add "coverage" and "boundary cases" tests towards
the end of the cycle (more often than not I don't need further changes
to satisfy the coverage and boundary-case tests, because of the "large
chunk" thing).  So, a TDD purist would blast me for heresy.

Nevertheless, having tried everything from pure TDD to papertrail-heavy
waterfall (including the "toss the bits over the wall to QA", shudder!)
to typical Chaos Driven Development, in over a quarter century of
experience, this almost-TDD is what works best for me -- in Python, C,
and C++, at least (it's been a long time, if ever, since I did enough
production Java, Haskell, Ruby, SML, assembly, Perl, bash, Fortran,
Cobol, Objective C, Tcl, awk, Scheme, PL/I, Rexx, Forth, Pascal,
Modula-2, or Basic, to be sure that the same approach would work well in
each of these cases, though I have no reason to think otherwise).


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


Re: Graphviz Python Binding for Python 2.5 on Windows?

2007-03-05 Thread Alex Li
Thanks Michel, I will give it a try.

Alex



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


Re: Islam, the Religion of Ease

2007-03-05 Thread ce
On Mar 6, 12:27 pm, [EMAIL PROTECTED] wrote:
> Excuse me!!
> Would you stop for a moment?!
> O...man...Haven't you thought-one day- about yourself ?
> Who has made it?
> Have you seen a design which hasn't a designer ?!
> Have you seen a wonderful,delicate work without a worker ?!
> It's you and the whole universe!..
> Who has made them all ?!!
> You know who ?.. It's "ALLAH",prise be to him.
> Just think for a moment.
> How are you going to be after death ?!
> Can you believe that this exact system of the universe and all of
> these great creation will end in in nothing...just after death!
> Have you thought, for a second, How to save your soul from Allah's
> punishment?!
> Haven't you thought about what is the right religion?!
> Read ... and think deeply before you answer..
> It is religion of Islam.
> It is the religion that Mohammad-peace upon him- the last prophet, had
> been sent by.
> It is the religion that the right Bible- which is not distorted-has
> preached.
> Just have a look at The Bible of (Bernaba).
> Don't be emstional.
> Be rational and judge..
> Just look..listen...compare..and then judge and say your word.
> We advise you visiting 
> :http://www.islam-guide.comhttp://www.thetruereligion.orghttp://www.beconvinced.comhttp://www.plaintruth.orghttp://english.islamway.comhttp://www.todayislam.comhttp://www.prophetmuhammed.orghttp://www.islamtoday.net/english/http://www.islamunveiled.orghttp://www.islamic-knowledge.com

Yah, this has so much to do with python..

python is the language of ease too!

I am muslim too by the way, but i dont' think this is a proper way to
let ppl know about our religion, buddy!

have any other opinion!

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


Re: Python Source Code Beautifier

2007-03-05 Thread Gabriel Genellina
En Mon, 05 Mar 2007 07:07:57 -0300, Alan Franzoni  
<[EMAIL PROTECTED]> escribió:

> Il Sat, 03 Mar 2007 17:34:35 +1300, greg ha scritto:
>
>> This was all discussed at *very* great length many
>> years ago, and the addition of in-place operators
>> to the language was held up for a long time until
>> the present compromise was devised. You might not
>> like it, but it's here to stay.
>
> Sure. I'm not a great programmer and I never thought about asking for  
> such a removal. I'm sure that there're people smarter and more  
> experienced than me out there designing Python, I'm glad I got it and I  
> won't use such
> shortcuts on mutable objects in my own programs.

The problem is that other people -not necesarily "smarter and more  
experienced" than you- may use those features, and perhaps you have to  
read, understand and modify some code written by someone else.
So, you should at least know what "a += b" means, even if you are not  
going to use it.

-- 
Gabriel Genellina

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


Islam, the Religion of Ease

2007-03-05 Thread lovelydiab
Excuse me!!
Would you stop for a moment?!
O...man...Haven't you thought-one day- about yourself ?
Who has made it?
Have you seen a design which hasn't a designer ?!
Have you seen a wonderful,delicate work without a worker ?!
It's you and the whole universe!..
Who has made them all ?!!
You know who ?.. It's "ALLAH",prise be to him.
Just think for a moment.
How are you going to be after death ?!
Can you believe that this exact system of the universe and all of
these great creation will end in in nothing...just after death!
Have you thought, for a second, How to save your soul from Allah's
punishment?!
Haven't you thought about what is the right religion?!
Read ... and think deeply before you answer..
It is religion of Islam.
It is the religion that Mohammad-peace upon him- the last prophet, had
been sent by.
It is the religion that the right Bible- which is not distorted-has
preached.
Just have a look at The Bible of (Bernaba).
Don't be emstional.
Be rational and judge..
Just look..listen...compare..and then judge and say your word.
We advise you visiting :
http://www.islam-guide.com
http://www.thetruereligion.org
http://www.beconvinced.com
http://www.plaintruth.org
http://english.islamway.com
http://www.todayislam.com
http://www.prophetmuhammed.org
http://www.islamtoday.net/english/
http://www.islamunveiled.org
http://www.islamic-knowledge.com

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


Re: CherryPy + Database questions

2007-03-05 Thread [EMAIL PROTECTED]
On Mar 5, 8:44 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Brian Blais wrote:
> > Hello,
>
> > I have more of a conceptual question about the way databases work, in a
> > web
> > framework, but I will be implementing things with CherryPy and SQLAlchemy.
> >  If you make a web form that adds rows to a database, and use sqlite as
> > the engine, is there a danger of a race condition if several users at the
> > same time try to submit the
> > form?  I want a unique row id, and make a unique identifier for the
> > submissions.  Am I in danger of having multiple submissions given the same
> > identifier?
>
> > I know that if I implemented things without a database, but used a flat
> > file or something like it, I would have that possibility, when two
> > processes try to read and update the file at the same time.
>
> > If you want something more specific, I can throw some code together, but I
> > wanted to get an answer before that because it will change the way I
> > develop the code.
>
> Usually, that is exactly what a RDBMS gives you. See the database connector
> module's threadsaftey property to see what exactly you can expect.
>
> Diez

SQLite isn't really a DBMS at all, it's just a library.  According to
their FAQ (http://www.sqlite.org/faq.html#q8) it is only threadsafe as
long as you aren't changing the same DB in separate threads (so no,
not threadsafe at all).

Hope this helps.

--Tim

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


Re: how can I find out the value of an environment variable?

2007-03-05 Thread MonkeeSage
On Mar 5, 8:22 pm, "ken" <[EMAIL PROTECTED]> wrote:
> how can I find out the value of an environment variable in my pythong
> script?
>
> Thank you.

RTFM...

os.getenv
http://docs.python.org/lib/os-procinfo.html

Regards,
Jordan

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


Re: Is every number in a list in a range?

2007-03-05 Thread MonkeeSage
On Mar 5, 9:19 pm, Paul Rubin  wrote:
> OK, I didn't read the question that way.  I thought the person just
> wanted a yes or no answer to whether the list contained any elements
> outside the desired range.  If the purpose is to select the elements
> in the range, then use filter/ifilter or a different listcomp/genexp:
>
>inrange = [x for x in ll if 0<=x<=maxnum]

Well, the OP didn't actually specify what behavior they wanted. I was
just trying to go the with broadest case, with arbitrary values.

Regards,
Jordan

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


Re: Descriptor/Decorator challenge

2007-03-05 Thread George Sakkis
On Mar 5, 2:31 am, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:

> I had an idea but no time to think it through.
> Perhaps the under-under name mangling trick
> can be replaced (in Py3.0) with a suitably designed decorator.
> Your challenge is to write the decorator.
> Any trick in the book (metaclasses, descriptors, etc) is fair game.
>
> Raymond
>
>  how we currently localize method access with name mangling
> --
> class A:
> def __m(self):
> print 'A.__m'
> def am(self):
> self.__m()
>
> class B(A):
> def __m(self):
> print 'B.__m'
> def bm(self):
> self.__m()
>
> m = B()
> m.am() # prints 'A.__m'
> m.bm() # prints 'B.__m'
>
>  how I would like to localize method access with a decorator
> --
> class A:
> @localmethod
> def m(self):
> print 'A.m'
> def am(self):
> self.m()
>
> class B(A):
> @localmethod
> def m(self):
> print 'B.m'
> def bm(self):
> self.m()
>
> m = B()
> m.am() # prints 'A.m'
> m.bm() # prints 'B.m'
>
> -
>
> P.S. Here's a link to the descriptor how-to:
>http://users.rcn.com/python/download/Descriptor.htm

What would the semantics be if m is decorated as local only in A or
only in B ?

George

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


Re: Is every number in a list in a range?

2007-03-05 Thread Paul Rubin
"MonkeeSage" <[EMAIL PROTECTED]> writes:
> If you want to preserve the items after 46, then you can't just bail
> when you see 46. You need to keep looking at the following values and
> comparing them against the boundry conditions. If the the input is
> sequential, then this isn't a problem, as all items above 46 are out
> of rangebut if the input is arbitrary, then you have to look at
> each index individually as you know. So it really comes down to if the
> data set is ordered or arbitrary as to which approach is more
> efficient.

OK, I didn't read the question that way.  I thought the person just
wanted a yes or no answer to whether the list contained any elements
outside the desired range.  If the purpose is to select the elements
in the range, then use filter/ifilter or a different listcomp/genexp:

   inrange = [x for x in ll if 0<=x<=maxnum]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyDSTool now compatible with numpy 1.0.1, scipy 0.5.2 and 64-bit CPUs.

2007-03-05 Thread Rob Clewley
This kind of comment comes up often, so I think it's worth spelling
out a response that will persist on the web and can appear in our FAQ.

I have a different and admittedly limited view of hybrid systems as
part of dynamical systems theory. In principle, I would love to have
time to write an interface to something like Modelica, but PyDSTool
isn't intended as an industrial-scale simulation package: it is
intended for applied dynamical systems research involving small
systems that people want to analyze with tools like bifurcation theory
and parameter estimation. I also want to switch components in and out
of a model with minimum overhead as part of model estimation and
parameter estimation routines that remain an open research area.
Partly for this reason I don't want to start depending on large
external packages, most features of which people may never be needed.
Given my present purposes the overhead of writing an interface is a
demanding sink of my time when basic (essentially prototype) tools
suffice in the short term. That is also why I am not planning a
graphical UI at this time. (The related DsTool and XPP packages
already have GUIs.)

I appreciate the idea of outsourcing to take advantage of good work in
areas such as yours.  I hope to step up to that bar later on as part
of an ongoing research project connected to me, which involves
studying the mechanisms of locomotion in insects. There are other
mechanical simulation packages that I would like to interface to (most
are commercial), but on close inspection it turns out there's a lot of
very technical issues involved -- although at least modelica is open
source! Sorry to be taking a short-term view here (I try to avoid
that), but we're just a couple of guys trying to concentrate on our
day jobs...

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


Re: pop method question

2007-03-05 Thread Gabriel Genellina
En Sat, 03 Mar 2007 19:55:16 -0300, Steven D'Aprano  
<[EMAIL PROTECTED]> escribió:

> I personally don't see that pop has any advantage, especially since the
> most useful example
>
> while some_dict:
> do_something_with(some_dict.pop())
>
> doesn't work. Instead you have to write this:

For such constructs, one can use popitem:

while some_dict:
 do_something_with(some_dict.popitem()[1])

The popitem method is older than pop. I don't like pop either.

-- 
Gabriel Genellina

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


Re: Is every number in a list in a range?

2007-03-05 Thread MonkeeSage
On Mar 5, 9:03 pm, Paul Rubin  wrote:
> Maybe I didn't undrestand the question.  Say maxnum is 30 in your
> example above.  Then as soon as 46 is seen, you can stop checking, I
> thought.

Yes, as long as 29 doesn't follow 46.

inlist = [1, 5, 23, 46, 29, 21]

If you want to preserve the items after 46, then you can't just bail
when you see 46. You need to keep looking at the following values and
comparing them against the boundry conditions. If the the input is
sequential, then this isn't a problem, as all items above 46 are out
of rangebut if the input is arbitrary, then you have to look at
each index individually as you know. So it really comes down to if the
data set is ordered or arbitrary as to which approach is more
efficient.

Regards,
Jordan

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


Re: Is every number in a list in a range?

2007-03-05 Thread Paul Rubin
"MonkeeSage" <[EMAIL PROTECTED]> writes:
> > This genexp is better than a loop because it bails out immediately
> > if it finds an out-of-range x.
> 
> That's true: assuming that input is sequential. But if it's farily
> random (e.g., [10, 20, 12, 46, 202, 5, 102]), then you need a loop/
> list comp. to check each index.


Maybe I didn't undrestand the question.  Say maxnum is 30 in your
example above.  Then as soon as 46 is seen, you can stop checking, I
thought.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is every number in a list in a range?

2007-03-05 Thread MonkeeSage
On Mar 5, 7:24 pm, Paul Rubin  wrote:
> This genexp is better than a loop because it bails out immediately
> if it finds an out-of-range x.

That's true: assuming that input is sequential. But if it's farily
random (e.g., [10, 20, 12, 46, 202, 5, 102]), then you need a loop/
list comp. to check each index.

Regards,
Jordan

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


Re: classes and functions

2007-03-05 Thread Gabriel Genellina
En Sat, 03 Mar 2007 17:04:33 -0300, Arnaud Delobelle  
<[EMAIL PROTECTED]> escribió:

> On Mar 2, 11:01 pm, Nicholas Parsons <[EMAIL PROTECTED]>
> wrote:
>> That is the beauty of using Python.  You have a choice of using
>> classes and traditional OOP techniques or sticking to top level
>> functions.  For short, small scripts it would probably be overkill to
>> use classes.  Yet the programmer still has classes in his tool chest
>> if he/she is writing code that is going to be reused in larger
>> projects.
>
> Exactly the same thing can be said about Lisp, C++, Perl, PHP, and no
> doubt many other languages that I don't know ;)
> (Well I guess C++ programs are not called 'scripts')

A notable exception being Java, even a "Hello world!" program must use a  
class.
And Eiffel, too.

-- 
Gabriel Genellina

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


Re: Python GUI + OpenGL

2007-03-05 Thread David Boddie
On Monday 05 March 2007 18:22, Chris Mellon wrote:

> On 3/5/07, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>> Beside that, I do love the Qt library and would always use it in
>> preference to wx, but this is a general thing and by no means tied to the
>> OpenGL-programming. After all, that actually is done using PyOpenGL
> 
> wx and Qt support OpenGL in essentially the same manner. I believe he
> took from your earlier post that Qt had its own built in OpenGL
> wrapper (and thus didn't rely on PyOpenGL) but to my knowledge that is
> not correct.

Yes, you need PyOpenGL (or any other suitable OpenGL wrapper) to use
OpenGL with PyQt. Qt itself doesn't provide its own API for OpenGL; you
just use the implementation available on your system.

It is possible to get OpenGL-rendered 2D graphics without having
PyOpenGL installed; you just paint on a QGLWidget in the usual way.
However, I suspect that the original poster wanted to render 3D
graphics, so Python bindings to the system's OpenGL library are still
required.

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


how can I find out the value of an environment variable?

2007-03-05 Thread ken
how can I find out the value of an environment variable in my pythong
script?

Thank you.

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


Re: How to Read Bytes from a file

2007-03-05 Thread Gabriel Genellina
En Fri, 02 Mar 2007 08:22:36 -0300, Bart Ogryczak <[EMAIL PROTECTED]>  
escribió:

> On Mar 1, 7:36 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>> Thanks Bart.  That's perfect.  The other suggestion was to precompute
>> count1 for all possible bytes, I guess that's 0-256, right?
>
> 0-255 actually. It'd be worth it, if accessing dictionary with
> precomputed values would be significantly faster then calculating the
> lambda, which I doubt. I suspect it actually might be slower.

Dictionary access is highly optimized in Python. In fact, using a  
precomputed dictionary is about 12 times faster:

py> import timeit
py> count1 = lambda x:  
(x&1)+(x&2>0)+(x&4>0)+(x&8>0)+(x&16>0)+(x&32>0)+(x&64>0)+
(x&128>0)
py> d256 = dict((i, count1(i)) for i in range(256))
py> timeit.Timer("for x in range(256): w = d256[x]", "from __main__ import  
d256"
).repeat(number=1)
[0.54261253874445003, 0.54763468541393934, 0.54499943428564279]
py> timeit.Timer("for x in range(256): w = count1(x)", "from __main__  
import cou
nt1").repeat(number=1)
[6.1867963665773118, 6.1967124313285638, 6.1666287195719178]

-- 
Gabriel Genellina

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


Re: Webserver balance load

2007-03-05 Thread Jeff McNeil

If you're willing to spend some serious dollars, there are also hardware
products out there that do this type of stuff.  We run a few F5 6800 E
systems. I've come to love their iRules feature - a TCL-based event driven
scripting system for network traffic. RAM cache, SSL offload, and so on.
They'll even tunnel thousands of front-end connections through a few HTTP
KeepAlive sessions on the backend.

The downsides to something like that are a) price and b) they use a SNAT
approach so all client source addresses on the web system are that of the
internal local interface on the load balancer (though there are other
approachs if that bothers you - DSR/N-Path, I replace source in the logs
with X-Forwarded-For.split(",")[0]).

There's also mod_proxy + mod_proxy_balancer:
http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html

Note that while all of these systems will provide better load distribution,
they will not provide H/A unless they're configured in a cluster config as a
standalone load balancer is still a single point of failure.

-Jeff

On 3/5/07, Michael <[EMAIL PROTECTED]> wrote:


Johny wrote:

> Can anyone suggest a way how to balance load on Apache server where I
> have Python scripts running?
> For example I have 3 webservers( Apache servers) and I would like to
> sent user's request to one of the three server depending on a load on
> the server.

To be honest, you're best looking at the Linux Virtual Server project.
It's
really cool technology and scales extremely well. You can do things at a
higher level, but LVS does work and scale extremely well. VS-TUN is
particularly useful if you have an unusual network topology.

http://www.linuxvirtualserver.org/


Michael.

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

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

Re: PyQt4: Clickable links in QLabel?

2007-03-05 Thread David Boddie
On Thursday 01 March 2007 09:00, Tina I wrote:

> A short and sweet question: Is it possible to put a clickable link in a
> QLabel that will open in the systems default browser?

Yes.

> I tried to put in some HTML but it did (of course?) simply display the
> code instead of a link. I also tried to set openExternalLinks 'true' but
> then pyuic4 bombed.

Well, that shouldn't happen. :-(

Can you send a bug report to the PyQt mailing list (assuming you're
subscribed to it) with the error message or backtrace that you get
when this happens?

> I see that QLabel does not have a html text format but I'm still hoping
> it's possible. I really need a link on my main window form.

If you enclose the HTML with  and  tags, the HTML should be
displayed properly. Any other matching tags should also work, so you
could use  and  if you want.

Setting the label's openExternalLinks property to True should then
enable what you want. You can try this out by previewing the form in
Qt Designer.

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


Re: Webserver balance load

2007-03-05 Thread Michael
Johny wrote:

> Can anyone suggest a way how to balance load on Apache server where I
> have Python scripts running?
> For example I have 3 webservers( Apache servers) and I would like to
> sent user's request to one of the three server depending on a load on
> the server.

To be honest, you're best looking at the Linux Virtual Server project. It's
really cool technology and scales extremely well. You can do things at a
higher level, but LVS does work and scale extremely well. VS-TUN is
particularly useful if you have an unusual network topology.

http://www.linuxvirtualserver.org/


Michael.

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


Re: Getting stdout from ctypes module

2007-03-05 Thread Gabriel Genellina
En Fri, 02 Mar 2007 07:54:55 -0300, Massi <[EMAIL PROTECTED]> escribió:

> Hi everyone, I have a program which is written in C and interfaced
> with python via
> Ctypes.  The functions I call print stuff out to the console, using
> the usual function printf. I would like to know if it is possible to
> redirect the output of my C module to python. I'm working on windows
> environment. Thanks in advance.

Is it a DLL or a program?
For a program I don't see how you could use ctypes to invoke things - and  
for a DLL it's strange to use printf for output.
If you run it as a program, try the subprocess module.

-- 
Gabriel Genellina

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


Re: Is every number in a list in a range?

2007-03-05 Thread Paul Rubin
"Steven W. Orr" <[EMAIL PROTECTED]> writes:
> I have a list ll of intergers. I want to see if each number in ll is
> within the range of 0..maxnum
> 
> I can write it but I was wondering if there's a better way to do it?

if all(0 <= x <= maxnum for x in ll): ...

This genexp is better than a loop because it bails out immediately
if it finds an out-of-range x.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is every number in a list in a range?

2007-03-05 Thread Matimus
On Mar 5, 1:34 pm, "Matimus" <[EMAIL PROTECTED]> wrote:
> On Mar 5, 11:03 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
>
> > I have a list ll of intergers. I want to see if each number in ll is
> > within the range of 0..maxnum
>
> > I can write it but I was wondering if there's a better way to do it?
>
> > TIA
>
> > --
> > Time flies like the wind. Fruit flies like a banana. Stranger things have  
> > .0.
> > happened but none stranger than this. Does your driver's license say Organ 
> > ..0
> > Donor?Black holes are where God divided by zero. Listen to me! We are all- 
> > 000
> > individuals! What if this weren't a hypothetical question?
> > steveo at syslang.net
>
> I would probably do something using max and min functions like this:
>
> seq = [...] # your list
>
> if min(seq) >= 0 && max(seq) <= MAXNUM:
>  do stuff

OOps... I've been writing too much C++ lately (or too little python).
That should read:

if min(seq) >= 0 and max(seq) <= MAXNUM:
do_stuff()

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


Re: Interface Implementation in Python

2007-03-05 Thread MonkeeSage
On Mar 5, 6:25 pm, [EMAIL PROTECTED] wrote:
> Hi,
>
>  I would like to know the interface concept in Python.How the
> Interface is defined and implemented in Python?.
>
> How to access the interface fromn Client?
>
> Thanks
> PSB

Not sure exactly what you mean, but in python (like most dynamic
languages) an "interface" is simply a behavioral type system. Any
object can implement an interface, based on its signature. For
example; let's say you have a file object which implements read() and
write(). Any other object with a sufficiently similar signature (e.g.,
StringIO), can be said to implement the same interface. An interface
in python is simply a specified behavior, and any object which
implements that behavior can be said to have the same "interface".

HTH,
Jordan

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


Re: Dialog with a process via subprocess.Popen blocks forever

2007-03-05 Thread Gabriel Genellina
En Fri, 02 Mar 2007 14:38:59 -0300, Donn Cave <[EMAIL PROTECTED]>  
escribió:

> In article <[EMAIL PROTECTED]>,
>  "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>
>> On http://docs.python.org/lib/popen2-flow-control.html there are some
>> notes on possible flow control problems you may encounter.
>
> It's a nice summary of one problem, a deadlock due to full pipe
> buffer when reading from two pipes.  The proposed simple solution
> depends too much on the cooperation of the child process to be
> very interesting, though.  The good news is that there is a real
> solution and it isn't terribly complex, you just have to use select()
> and UNIX file descriptor I/O.  The bad news is that while this is
> a real problem, it isn't the one commonly encountered by first
> time users of popen.

More bad news: you can't use select() with file handles on Windows.

>> If you have no control over the child process, it may be safer to use a
>> different thread for reading its output.
>
> Right - `I used threads to solve my problem, and now I have two
> problems.'  It can work for some variations on this problem, but
> not the majority of them.

Any pointers on what kind of problems may happen, and usual solutions for  
them?
On Windows one could use asynchronous I/O, or I/O completion ports, but  
neither of these are available directly from Python. So using a separate  
thread for reading may be the only solution, and I can't see why is it so  
bad. (Apart from buffering on the child process, which you can't control  
anyway).

-- 
Gabriel Genellina

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Adam Atlas
Okay, here's the prototype...

It's meant to be run as a command line program (pass it a directory or
a zip file as an argument). By default it will save the new file to
the argument's base name plus '.pyc'. You can override this with -o.

Obviously it's very much a work in progress... try it out and let me
know the results.

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


Interface Implementation in Python

2007-03-05 Thread p_shakil
Hi,

 I would like to know the interface concept in Python.How the
Interface is defined and implemented in Python?.

How to access the interface fromn Client?

Thanks
PSB

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


persistent fifo queue class

2007-03-05 Thread David Bear
I'm looking to see if there are any examples or prewritting fifo queue
classes. I know this is a broad topic. I'm looking to implement a simple
application where a web server enqueue and pickle using a local socket on
to a 'queue server' -- and then I will have another application dequeue the
pickles again using a local socket.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread MonkeeSage
Stef,

What Adam is talking about has nothing to do with windows or *nix.
He's talking about packing one or more .py files into a single
archive, which can be imported just like the regular .py files. This
means you can distribute a whole bunch of module files/dirs as a
single .pyc file. It just makes it easier to have a single file to
distribute rather than a whole bunch, or a zip that one has to unzip
into a certain directory, &c. So you can have myscript.py +
myscriptfiles.pyc vs. myscript.py + somedepdir/ + someotherdepdir/ +
somedepfile.py...&c.

If you still don't get it, you don't need it.

Regards,
Jordan

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


Re: Graphviz Python Binding for Python 2.5 on Windows?

2007-03-05 Thread M�ta-MCI
Hi!

You can also use/call GraphViz by COM.
It's run OK with P2.3 - 2.4 & 2.5 

@-salutations

Michel Claveau


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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Paul Boddie
Stef Mientki wrote:
>
> As a normal Windows user,
>I'm used to run an install file,
>  and hit just 1 button.
> As a normal Windows programmer,
>I'm used to create a simple Inno-setup file,
>  and my users can behave as a simplistic and happy Windows user.
>
> But I guess the needed complexity is all thanks to NIX ;-)

"Au contraire, as they say in England." - Steve X. Citement

Most UNIX-based (or at least GNU/Linux or BSD-based) Python users are
likely to have Python provided by their vendor together with a
"constellation" of packages. As long as the software they need is
packaged by their distribution, it's a matter of selecting the package
concerned; other packages upon which the desired software depends will
be installed automatically. You don't usually need to click through
some wizard ("next", "I agree", "next", "next", "next", "next",
"next", "finish"), either.

Paul

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


Re: ANN: PyDSTool now compatible with numpy 1.0.1, scipy 0.5.2 and 64-bit CPUs.

2007-03-05 Thread [EMAIL PROTECTED]

On Mar 2, 12:07 pm, "Rob Clewley" <[EMAIL PROTECTED]> wrote:
> Mike,
>
> Yes, that is a pretty fair description of our support for symbolics
> using Python's own inheritance. Our ModelSpec classes provide only an
> elementary form of inheritance, polymorphism and type checking. We
> hope to expand our existing support for hybrid/DAE systems at the
> level of our ModelSpec model-building tools. All ideas and code
> contributions are welcome!

It is a fair amount of work to figure out all the details for trying
to come up with a clean way of describing hybrid DAE systems for
usability, expressiveness, efficiency, etc (based on my 7 year
involvement in the 10 year and counting Modelica effort).  As a user,
what I would find more interesting would be a python implementation
that could import such descriptions and then work with them (rather
than expressing them in Python).  There is a ton of interesting stuff
in the area of UI, symbolic methods, etc. that is completely
independent of the specification side.  It seems to me the
specification stuff bogs down the effort.

By "outsourcing" all the specification stuff you can offload that
burden and then focus on python based tools for introspection,
symbolic manipulation, visualization, graphical model construction,
etc.  I don't know your ultimate goals but it just seems to me you'll
get their faster by co-opting the existing work.  Not only that, if
you interest is in studying complex dynamic systems there is a
mountain of stuff already out there (in the form of fully specified
models) that you can incorporate.

For what it's worth.

> Cheers,
> Rob

--
Mike

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Bruno Desthuilliers
Stef Mientki a écrit :
> Adam Atlas wrote:
> 
>> Ah... heh, sorry, I misread your message as "a much more convenient
>> way" rather than "much more than a convenient way". Anyway, I
>> understand that, and I do indeed find setuptools useful and use it on
>> a regular basis.
>>
>> But my other points still stand. This would be a moot point if
>> setuptools were part of the standard library, but it's not, and I
>> don't see why people should have to bother installing it if they
>> simply want to try a small package. Look at Beautiful Soup, for
>> example. It's distributed as a single .py file, and that's great. With
>> most modules, all I want to do is download them and plop them into my
>> project directory. You can always copy it into site-packages if you
>> want to access it globally, and you can always unzip it if you need to
>> see the source.
>>
>> So I *will* retract my statement that this could be an "alternative"
>> to eggs -- ideally, it would be an addition, since it doesn't break
>> compatibility at all. You could download an egg and rename it to .pyc,
>> and import it like any other module, and at any point later, you could
>> rename it back to .egg and use setuptools to install it if you wish.
>>
> Good point to make these things much easier!
> 
> But possibly I'm the only Windows user here,

I don't think so.

> as I still find these talks all very difficult to understand,
> and I really don't understand why all this complexity is necessary,
> setuptools ? eggs ? zips ? pythonpaths ?
> 
> As a normal Windows user,
>   I'm used to run an install file,
> and hit just 1 button.

As a normal *n*x user, I'm used to run a single command line. Don't even 
have to hit a button !-)

> But I guess the needed complexity is all thanks to NIX ;-)

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Bruno Desthuilliers
Adam Atlas a écrit :
> Ah... heh, sorry, I misread your message as "a much more convenient
> way" rather than "much more than a convenient way".

!-)

(snip)

> But my other points still stand.

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


Re: Is every number in a list in a range?

2007-03-05 Thread Bruno Desthuilliers
MonkeeSage a écrit :
> On Mar 5, 1:03 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> 
>>I have a list ll of intergers. I want to see if each number in ll is
>>within the range of 0..maxnum
> 
> 
> How about:
> 
> maxnum = 100
> inlist = range(90, 120)
> for i in [i for i in inlist if i >= 0 and i <= maxnum]:

   if 0 <= i <= maxnum

> # do something with i, it's in the valid range
> print i

But I guess Steven is able to come up with such a solution by itself !-)

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread MonkeeSage
Adam,

Sounds like a nice idea to me. Pretty ingenious use of the zip/
bytecode headers and all too. Post a message when you release it
please.

Regards,
Jordan

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


Re: Project organization and import

2007-03-05 Thread Bruno Desthuilliers
Martin Unsal a écrit :
> On Mar 5, 9:15 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
(snip)
> There are myriad other benefits of breaking up large files into
> functional units. Integration history, refactoring, reuse, as I
> mentioned. Better clarity of design. Easier communication and
> coordination within a team. What's the down side? What's the advantage
> of big files with many functional units?

What is a "big file" ?

(snip)
> However when I talk about what I think is "wrong" with the Pythonic
> way, obviously that's just my opinion formed by my own experience.

Your own experience *with Python* ? or any close-enough language ? Or 
your experience with C++ ?

(snip)
> Python still takes time to load & "precompile".

compile. To byte-code, FWIW. Not "load & precompile". And - apart from 
the top-level script - only modified modules get recompiled.

> That time is becoming
> significant for me even in a modest sized project;

On what hardware are you working ??? I have my interpreter up and 
running in a couple milliseconds, and my box is a poor athlon xp1200/256.

> I imagine it would
> be pretty awful in a multimillion line project.

I still wait to see a multimillion line project in Python !-)

If you find yourself in this situation, then you there's certainly 
something totally wrong in the way you (and/or your team) design and code.

But anyway - remember that only the modified modules get recompiled.

> No matter how fast it is, I'd rather reload one module than exit my
> interpreter and reload the entire world.

Did you actually *tried* it ?

> This is not a problem for Python as scripting language. This is a real
> problem for Python as world class application development language.

Sorry to have to say so, but this is total bullshit IMHO - which is 
based on working experience.

>>Nobody I know uses reload() for anything more than trivial "as
>>you work" testing in the interpreter. It's not reliable or recommended
>>for anything other than that.
> 
> 
> That too... although I think that's unfortunate. If reload() were
> reliable, would you use it?

I wouldn't. It easier to rerun a simple test script and keep the 
interpreter opened with full state - and you're sure you have the 
correct desired state then.

>>This is
>>still a much faster way than compiling any but the most trivial of
>>C/C++ modules.
>  
> I'm with you there! I love Python and I'd never go back to C/C++. That
> doesn't change my opinion that Python's import mechanism is an
> impediment to developing large projects in the language.

What about basing your opinion on facts ? What about going with the 
language instead of fighting against it ?

> 
>>If you don't like working with explicit namespaces, you've probably
>>chosen the wrong language.
> 
> 
> I never said that. I like foo.Bar(), I just don't like typing
> foo.Foo() and bar.Bar(), which is a waste of space;  syntax without
> semantics.

May I say that the problem here comes from your insistance on putting 
each class in a single module ?

> 
>>I propose that the technique most amenable to source code management
>>is for a single file (or RCS level module, if you have a locking RCS)
>>to have everything that it makes sense to edit or change for a
>>specific feature.
> 
> 
> Oh, I agree completely. I think we're using the exact same criterion.

I really doubt you do. What Chris is talking about is grouping together 
what usually needs to change together.

> A class is a self-contained feature with a well defined interface,

So is a function. Should we put any single function in a separate module 
then ?

> just what you'd want to put in it's own file. (Obviously there are
> trivial classes which don't implement features, and they don't need
> their own files.)
> 
> 
>>You're also placing far too much emphasis on reload. Focus yourself on
>>unit tests and environment scripts instead. These are more reliable
>>and easier to validate than reload() in a shell.
> 
> 
> I think this is the crux of my frustration. I think reload() is
> unreliable and hard to validate because Python's package management is
> broken.

I think the "crux of your frustation" comes from your a priori. Fighting 
against a language can only bring you into frustration. If the language 
don't fit your brain - which is perfectly legitimate - then use another 
one - but don't blame the language for it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is every number in a list in a range?

2007-03-05 Thread MonkeeSage
On Mar 5, 1:03 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> I have a list ll of intergers. I want to see if each number in ll is
> within the range of 0..maxnum

How about:

maxnum = 100
inlist = range(90, 120)
for i in [i for i in inlist if i >= 0 and i <= maxnum]:
# do something with i, it's in the valid range
print i

Regards,
Jordan

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


Re: Is every number in a list in a range?

2007-03-05 Thread bearophileHUGS
Steven W. Orr:
> I have a list ll of intergers. I want to see if each number in ll is
> within the range of 0..maxnum

One possible nice solution (Python V.2.5):

data = [1, 20, 22, 11, 400, 7]
maxnum = 100
print all(0 <= x <= maxnum for x in data)
maxnum = 1000
print all(0 <= x <= maxnum for x in data)

Bye,
bearophile

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


Graphviz Python Binding for Python 2.5 on Windows?

2007-03-05 Thread Alex Li
Hello,

I would like to use Python 2.5 on Windows with Graphviz to generate
graphs.  I used yapgvb but it only requires Python 2.4 (won't work
with Python 2.5).  Other packages like pydot seems to be unmaintained
or requires custom building to be used on Windows (pygraphviz), which
I tried to avoid.  Any suggestions?

Thanks in advance,
Alex

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


Re: Make instance global -- possbile?

2007-03-05 Thread Arnaud Delobelle
On Mar 5, 10:00 pm, [EMAIL PROTECTED] wrote:
> Rather new to OOP in Python...
>
> I'm writing an app where several objects need to access and change the
> state of ONE instance.
>
> I could of course instantiate the instance and then pass it along the
> objects, but that's cumbersome, especially as it would need to be
> "passed through" classes that don't really need it.
>
> I would be happy if I could just instantiate the object in the main
> module and declare it global, but classes are in different modules so
> I guess that won't work.
>
> Have looked a bit into singletons -- is that the way to go?

Put your 'global' stuff into a module and use import?

--
Arnaud

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Stef Mientki
Adam Atlas wrote:
> Ah... heh, sorry, I misread your message as "a much more convenient
> way" rather than "much more than a convenient way". Anyway, I
> understand that, and I do indeed find setuptools useful and use it on
> a regular basis.
> 
> But my other points still stand. This would be a moot point if
> setuptools were part of the standard library, but it's not, and I
> don't see why people should have to bother installing it if they
> simply want to try a small package. Look at Beautiful Soup, for
> example. It's distributed as a single .py file, and that's great. With
> most modules, all I want to do is download them and plop them into my
> project directory. You can always copy it into site-packages if you
> want to access it globally, and you can always unzip it if you need to
> see the source.
> 
> So I *will* retract my statement that this could be an "alternative"
> to eggs -- ideally, it would be an addition, since it doesn't break
> compatibility at all. You could download an egg and rename it to .pyc,
> and import it like any other module, and at any point later, you could
> rename it back to .egg and use setuptools to install it if you wish.
> 
Good point to make these things much easier!

But possibly I'm the only Windows user here,
as I still find these talks all very difficult to understand,
and I really don't understand why all this complexity is necessary,
setuptools ? eggs ? zips ? pythonpaths ?

As a normal Windows user,
   I'm used to run an install file,
 and hit just 1 button.
As a normal Windows programmer,
   I'm used to create a simple Inno-setup file,
 and my users can behave as a simplistic and happy Windows user.

But I guess the needed complexity is all thanks to NIX ;-)

I think I never would have started with Python,
if I didn't bounced into the Enthought-edition.

-- 
cheers,
Stef Mientki
http://pic.flappie.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project organization and import

2007-03-05 Thread Bruno Desthuilliers
Martin Unsal a écrit :
(snip)
> When refactoring, it's much better to move small files around than to
> move chunks of code between large files.

Indeed. But having hundreds or thousands of files each with at most a 
dozen lines of effective code is certainly not an ideal. Remember that 
Python let you tell much more in a few lines than some mainstream 
languages I won't name here.

> 
>>I don't reload...  When my investigative tests gets bigger I write a script
>>and run it with the interpreter.  It is easy since my text editor can call
>>Python on a buffer (I use Emacs).
>  
> That's interesting, is this workflow pretty universal in the Python
> world?

I don't know, but that's also mostly how I do work.

> I guess that seems unfortunate to me, 

So I guess you don't understand what Jorge is talking about.

> one of the big wins for
> interpreted languages is to make the development cycle as short and
> interactive as possible. 

It's pretty short interactive. Emacs Python mode let you fire up a 
subinterpreter and eval either your whole buffer or a class or def block 
or even a single expression - and play with the result in the 
subinterpreter.

> As I see it, the Python way should be to
> reload a file and reinvoke the class directly, not to restart the
> interpreter, load an entire package and then run a test script to set
> up your test conditions again.

^Cc^C! to start a new interpeter
^Cc^Cc to eval the whole module

Since the module takes care of "loading the entire package", you don't 
have to worry about this. And since, once the script eval'd, you still 
have your (interactive) interpreter opened, with all state set, you can 
then explore at will. Try it by yourself. It's by far faster and easier 
than trying to manually keep track of the interpreter state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Make instance global -- possbile?

2007-03-05 Thread erokar

Rather new to OOP in Python...

I'm writing an app where several objects need to access and change the
state of ONE instance.

I could of course instantiate the instance and then pass it along the
objects, but that's cumbersome, especially as it would need to be
"passed through" classes that don't really need it.

I would be happy if I could just instantiate the object in the main
module and declare it global, but classes are in different modules so
I guess that won't work.

Have looked a bit into singletons -- is that the way to go?

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Adam Atlas
Ah... heh, sorry, I misread your message as "a much more convenient
way" rather than "much more than a convenient way". Anyway, I
understand that, and I do indeed find setuptools useful and use it on
a regular basis.

But my other points still stand. This would be a moot point if
setuptools were part of the standard library, but it's not, and I
don't see why people should have to bother installing it if they
simply want to try a small package. Look at Beautiful Soup, for
example. It's distributed as a single .py file, and that's great. With
most modules, all I want to do is download them and plop them into my
project directory. You can always copy it into site-packages if you
want to access it globally, and you can always unzip it if you need to
see the source.

So I *will* retract my statement that this could be an "alternative"
to eggs -- ideally, it would be an addition, since it doesn't break
compatibility at all. You could download an egg and rename it to .pyc,
and import it like any other module, and at any point later, you could
rename it back to .egg and use setuptools to install it if you wish.

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


Re: Project organization and import

2007-03-05 Thread Bruno Desthuilliers
Martin Unsal a écrit :
> On Mar 5, 12:45 am, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> wrote:
> 
>>Remember that you can put code in
>>the __init__.py of a package, and that this code can import sub-
>>packages/modules namespaces, making the package internal organisation
>>transparent to user code
> 
> 
> Sure, but that doesn't solve the problem.
> 
> Say you have a package "widgets" with classes ScrollBar, Form, etc.
> You want the end user to "import widgets" and then invoke
> "widgets.ScrollBar()". As far as I know there are only two ways to do
> this, both seriously flawed: 1) Put all your code in one module
> widgets.py, 2) use "from scrollbar import *" in widgets/__init__.py,
> which is semi-deprecated 

"deprecated" ? Didn't see any mention of this so far. But it's bad form, 
since it makes hard to know where some symbol comes from.

# widgets.__init
from scrollbar import Scrollbar, SomeOtherStuff, some_function, SOME_CONST

> and breaks reload().

> 
>>Also remember that you can "import as", ie:
>>
>>import some_package.some_subpackage.some_module as some_module
> 
> 
> Sure but that doesn't eliminate the unfortunate interaction between
> Python class organization and filesystem heirarchy.

*class* organization ? It's not Java here. Nothing forces you to use 
classes.

> For example, say
> you want to organize the widgets package as follows:
> 
> widgets/scrollbar/*.py
> widgets/form/*.py
> widgets/common/util.py
> 
> Other than messing around with PYTHONPATH, which is horrible, I don't
> see how to import util.py from the widget code.

Some of us still manage to do so without messing with PYTHONPATH.

> 
>>Bad form IMHO. Packages and module names should be all_lower,
>>classnames CamelCased.
> 
> 
> You're still stuck doing foo.Foo() everywhere in your client code,

from foo import Foo

But:
> which is ugly 

It's not ugly, it's informative. At least you know where Foo comes from.

 > and wastes space,

My. Three letters and a dot...

> or using "from foo import *" which is
> broken.

cf above.

> 
>>>but I
>>>believe this is categorically the wrong thing to do in large projects.
>>
>>Oh yes ? Why ?
> 
> 
> For myriad reasons, just one of them being the one I stated -- smaller
> files with one functional unit each

Oh. So you're proposing that each and any single function goes in a 
separate file ?

> are more amenable to source code
> management with multiple developers.

This is not my experience.

> We could discuss this till we're blue in the face but it's beside the
> point. For any given project, architecture, and workflow, the
> developers are going to have a preference for how to organize the code
> structurally into files, directories, packages, etc. The language
> itself should not place constraints on them. The mere fact that it is
> supposedly "Pythonic" to put more functionality in one file indicates
> to me that the Python package system is obstructing some of its users
> who have perfectly good reasons to organize their code differently.

It has never been an issue for me so far.

> 
>>>you're going to want files to contain the smallest
>>>practical functional blocks. I feel pretty confident saying that "put
>>>more stuff in one file" is the wrong answer, even if it is the
>>>Pythonic answer.
>>
>>Is this actually based on working experience ? It seems that there are
>>enough not-trivial Python projects around to prove that it works just
>>fine.
> 
> 
> Yes. I've worked extensively on several projects in several languages
> with multi-million lines of code

I meant, based on working experience *with Python* ? I've still not seen 
a "multi-million" KLOC project in Python - unless of course you include 
all the stdlib and the interpreter itself, and even then I doubt we get 
so far.

> and they invariably have coding
> styles that recommend one functional unit (such as a class), or at
> most a few closely related functional units per file.

Which is what I see in most Python packages I've seen so far. But we may 
not have the same definition for "a few" and "closely related" ?

> In Python, most of the large projects I've looked at use "from foo
> import *" liberally.

I've seen few projects using this. And I wouldn't like having to 
maintain such a project.

> I guess my question boils down to this. Is "from foo import *" really
> deprecated or not?

This syntax is only supposed to be a handy shortcut for quick testing 
and exploration in an interactive session. Using it in production code 
is considered bad form.

> If everyone has to use "from foo import *"

I never did in 7 years.

> despite
> the problems it causes, how do they work around those problems (such
> as reloading)?

Do you often have a need for "reloading" in production code ???

Martin, I'm not saying Python is perfect, but it really feels like 
you're worrying about things that are not problems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Adam Atlas
This could be easily made into a distutils extension (which was my
intention all along, though that's not implemented yet). That's not
the point. This is not intended as a "way to package source code".
It's analogous to bdist, not sdist. The convenience gain is for the
users, not (primarily) the developers, of the package.

To use an Egg, you have to either put it in your sys.path manually or
install setuptools and use it to install the Egg in some global scope.
The advantage of Squisher is that you can take a whole package, squish
it into one .pyc file, and distribute that. Then, anyone who downloads
it can get a simple module file that can be used anywhere a usual .py
file can, without editing sys.path or installing it somewhere.
(Actually, this could be combined with eggs, since they're just ZIP
files. You could use the same file as an egg or as a squished module
simply by changing its extension.)

...Or am I missing something obvious about setuptools that already
does this and making a fool of myself? :)

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


Re: Is every number in a list in a range?

2007-03-05 Thread Matimus
On Mar 5, 11:03 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> I have a list ll of intergers. I want to see if each number in ll is
> within the range of 0..maxnum
>
> I can write it but I was wondering if there's a better way to do it?
>
> TIA
>
> --
> Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
> happened but none stranger than this. Does your driver's license say Organ ..0
> Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
> individuals! What if this weren't a hypothetical question?
> steveo at syslang.net

I would probably do something using max and min functions like this:

seq = [...] # your list

if min(seq) >= 0 && max(seq) <= MAXNUM:
 do stuff

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Bruno Desthuilliers
Adam Atlas a écrit :
(snip)
> If you make a ZIP archive of
> this and run it through Squisher, you'll get a single .pyc file which
> can be imported by any Python installation anywhere just like any
> other module, without requiring users to install any supporting
> mechanisms (like setuptools),

setuptools offers *much* more than a convenient way to package source code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question

2007-03-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> On Mar 5, 9:03 am, Stargaming <[EMAIL PROTECTED]> wrote:
> 
>>Tommy Grav schrieb:
> 
> 
>>For this case, there are list comprehensions (or map, but you shouldn't
>>use it any longer):
> 
> 
> 
> I didn't see anything in the docs about this.  Is map going away or is
> it considered un-Pythonic now?

It's less used since we have list comps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question

2007-03-05 Thread Bruno Desthuilliers
Tommy Grav a écrit :
> Hi list,
> 
>this is somewhat of a newbie question that has irritated me for a  
> while.
> I have a file test.txt:
> 
> 0.3434  0.5322 0.3345
> 1.3435  2.3345 5.3433
> 
> and this script
> lines = open("test.txt","r").readlines()
> for line in lines:
>(xin,yin,zin) = line.split()
>x = float(xin)
>y = float(yin)
>z = float(zin)
> 
> Is there a way to go from line.split() to x,y,z as floats without  
> converting
> each variable individually?

either map() or a list comprehension

import sys
fname = "test.txt"
lines = open(fname,"r")
for numline, line in enumerate(lines):
   try:
 x, y, z = map(float, line.split())
 # or:
 # x, y, z = [float(item) for item in line.split()]
   except (ValueError, IndexError), e:
 err = "Invalid data format in %s line %s : "%s" (%s)" \
   % (fname, numline, line, e)
 print >> sys.stderr, err
 sys.exit(1)
   else:
 # do whatever appropriate here - anyway

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


Is every number in a list in a range?

2007-03-05 Thread Steven W. Orr
I have a list ll of intergers. I want to see if each number in ll is 
within the range of 0..maxnum

I can write it but I was wondering if there's a better way to do it?

TIA

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


ABC with Linux

2007-03-05 Thread Avi Anu
Im tryin to make ABC (a bitorrent client) work under linux. I installed 
everything, that is ABC, wxpython, glib and gtk, and now I get a python error, 
saying it can't find wxpython. Am I supposed to set an environmental variable 
too?

A little learning is a dangerous thing, but we must take that risk because a 
little is as much as our biggest heads can hold. 
George Bernard Shaw
 
-
Check out the all-new Yahoo! Mail beta - Fire up a more powerful email and get 
things done faster.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: New to Python

2007-03-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> I am trying to get a program to add up input from the user to get to
> the number 100 using a loop.  However, I am having some issues.  Here
> is what I have so far.  I know I am just trying to hard, but I am
> stuck.  

Where ?

May I suggest this reading ?
http://www.catb.org/~esr/faqs/smart-questions.html

> Thank you for any help.
> 
> print "We need to count to 100"
> 
> high_number = 100
> total = 0
> 
> number = input("Enter your first number ")

Please re-read *very carefully* the doc for input(). Then switch to 
raw_input() and perform appropriate validation and conversion.

> sum = number + total

don't use 'sum' as an identifier, unless you don't mind shadowing the 
builtin sum() function.

> while sum < high_number:
> print "Not there yet..."
> number = input("Enter another number ")
> 
> print "We are there!!!"

We're not. number won't be automagically added to sum.

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


Any way to determine test success from inside tearDown()?

2007-03-05 Thread Christopher Corbell
This question pertains to PyUnit, esp. unittest.TestCase subclasses.

Does anyone know of a way from within the TestCase tearDown() method
to determine whether the current test succeeded or not?

What I'm after is a specialized clean-up approach for error/failure
cases.

This is somewhat related to some earlier threads in this group about
using fixtures across test invocations.  I'm functionally testing a
system that uses a database.  Successful tests are guaranteed to
restore the system's data fixtures to initial state, but when tests
fail or error-out we want to do a brute-force re-initialization of the
server so downstream tests can continue.  This re-initialization takes
time so we don't want to do it in every tearDown(), just on error/
failure tearDown()'s.

TIA,
Chris

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


Re: Webserver balance load

2007-03-05 Thread Bruno Desthuilliers
Jean-Paul Calderone a écrit :
> On 5 Mar 2007 11:47:15 -0800, Johny <[EMAIL PROTECTED]> wrote:
> 
>> Can anyone suggest a way how to balance load on Apache server where I
>> have Python scripts running?
>> For example I have 3 webservers( Apache servers) and I would like to
>> sent user's request to one of the three server depending on a load on
>> the server.
>> Thank you .
>> L.
>>
> 
> http://pythondirector.sourceforge.net/ might be interesting.

See also pound:
http://www.apsis.ch/pound/

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


Re: Building a dictionary from a tuple of variable length

2007-03-05 Thread Pierre Quentel
Hi,

> Therefore, how do I build the tuple of Falses to reflect the length of my t 
> tuple?

Yet another solution :

d = dict(zip(t,[False]*len(t)))

Pierre

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


Re: package_data question

2007-03-05 Thread Goldfish
On Mar 5, 1:56 am, "bytecolor" <[EMAIL PROTECTED]> wrote:
> I have a simple package. I'm trying to add an examples subdirectory
> with distutils. I'm using Python 2.4 on Linux. My file layout and
> setup.py can be found here:
>
> http://www.deadbeefbabe.org/paste/3870
>
> I've tried using data_files as well, with the same result; examples/
> fig2.3.apt is not added to the tarball.
>
> --
> bytecolor

I have a package along with a samples section. I have both a setup.py
script along with a MANIFEST.in file to make sure everything gets in.
You can see both of the files at 
https://springpython.python-hosting.com/browser/trunk/samples

That is for the samples section. For my main package, I have something
similar at https://springpython.python-hosting.com/browser/trunk/src

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


Re: Using string as file

2007-03-05 Thread Arnaud Delobelle
On Mar 5, 8:13 pm, Florian Lindner <[EMAIL PROTECTED]> wrote:
> Hello,
> I have a function from a library thast expects a file object as argument.
> How can I manage to give the function a string resp. have the text it would
> have written to file object as a string?
>
> Thanks,
>
> Florian

See

http://docs.python.org/lib/module-StringIO.html

--
Arnaud

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


Using string as file

2007-03-05 Thread Florian Lindner
Hello,
I have a function from a library thast expects a file object as argument.
How can I manage to give the function a string resp. have the text it would
have written to file object as a string?

Thanks,

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


Re: How to create pid.lock via python?

2007-03-05 Thread MrJean1
May this works for your case

  .

/Jean Brouwers


On Mar 5, 3:12 am, Marco <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I write a program control a device via RS232, I hope to add some code
> to let the program canNOT be used by other people when one people
> using.
>
> Can you tell me how to create pid.lock file in python?
> Thank you!!
>
> --
> LinuX Power

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


Re: Webserver balance load

2007-03-05 Thread Jean-Paul Calderone
On 5 Mar 2007 11:47:15 -0800, Johny <[EMAIL PROTECTED]> wrote:
>Can anyone suggest a way how to balance load on Apache server where I
>have Python scripts running?
>For example I have 3 webservers( Apache servers) and I would like to
>sent user's request to one of the three server depending on a load on
>the server.
>Thank you .
>L.
>

http://pythondirector.sourceforge.net/ might be interesting.

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


Webserver balance load

2007-03-05 Thread Johny
Can anyone suggest a way how to balance load on Apache server where I
have Python scripts running?
For example I have 3 webservers( Apache servers) and I would like to
sent user's request to one of the three server depending on a load on
the server.
Thank you .
L.

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


Re: Python 2.5, problems reading large ( > 4Gbyes) files on win2k

2007-03-05 Thread Bill Tydeman

On 3/4/07, Paul Duffy <[EMAIL PROTECTED]> wrote:


Bill Tydeman wrote:
> Just curious, but since the file size limitation on NTFS is 4 GB, have
> you confirmed that it isn't some other part of the interaction that is
> causing the problem?   What FS is hosting the files?
I don't think that is correct.  Groovy version of app runs just fine.'




That should have been pre-NTFS (i.e. FAT32) but I have had problems with
files larger than 4GB on NTFS.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: New to Python

2007-03-05 Thread [EMAIL PROTECTED]
On Mar 5, 1:14 pm, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote:
> On Mar 5, 6:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > I am trying to get a program to add up input from the user to get to
> > the number 100 using a loop.  However, I am having some issues.  Here
> > is what I have so far.  I know I am just trying to hard, but I am
> > stuck.  Thank you for any help.
>
> > print "We need to count to 100"
>
> > high_number = 100
> > total = 0
>
> > number = input("Enter your first number ")
> > sum = number + total
> > while sum < high_number:
> > print "Not there yet..."
> > number = input("Enter another number ")
>
> > print "We are there!!!"
>
> There is no need for 'sum' and 'total'. Here's a working version of
> your program.  Look at the differences with your attempt.
>
> --
> print "We need to count to 100"
>
> high_number = 100
>
> total = input("Enter your first number ") # first total is the fist
> number
> while total < high_number:
> print "Not there yet..."
> number = input("Enter another number ")
> total = total + number # Add the new number to the total
>
> print "We are there!!!"
> --
>
> Good luck !
>
> As others have pointed out, 'input' is a function to be careful with.
> You could use answer=raw_input(...) and then convert the result to an
> int by using number=int(answer).
>
> --
> Arnaud- Hide quoted text -
>
> - Show quoted text -


Thanks for the help guys!!!

Before I got a chance to read your answer Arnaud, I came up with the
below.  Seems to work also.  Yours is easier :).

print "We need to count to 100"

high_number = 100
sum = 0

sum += input("Enter your first number ")
print sum
while sum < high_number:
print "Not there yet..."
sum += input("Enter another number ")
print sum

print "We are there!!!"

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


Re: New to Python

2007-03-05 Thread Arnaud Delobelle
On Mar 5, 6:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I am trying to get a program to add up input from the user to get to
> the number 100 using a loop.  However, I am having some issues.  Here
> is what I have so far.  I know I am just trying to hard, but I am
> stuck.  Thank you for any help.
>
> print "We need to count to 100"
>
> high_number = 100
> total = 0
>
> number = input("Enter your first number ")
> sum = number + total
> while sum < high_number:
> print "Not there yet..."
> number = input("Enter another number ")
>
> print "We are there!!!"

There is no need for 'sum' and 'total'. Here's a working version of
your program.  Look at the differences with your attempt.

--
print "We need to count to 100"

high_number = 100

total = input("Enter your first number ") # first total is the fist
number
while total < high_number:
print "Not there yet..."
number = input("Enter another number ")
total = total + number # Add the new number to the total

print "We are there!!!"
--

Good luck !

As others have pointed out, 'input' is a function to be careful with.
You could use answer=raw_input(...) and then convert the result to an
int by using number=int(answer).

--
Arnaud

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


Re: Project organization and import

2007-03-05 Thread Chris Mellon
On 5 Mar 2007 10:31:33 -0800, Martin Unsal <[EMAIL PROTECTED]> wrote:
> On Mar 5, 9:15 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> > That's actually the exact benefit of unit testing, but I don't feel
> > that you've actually made a case that this workflow is error prone.
> > You often have multiple developers working on the same parts of the
> > same module?
>
> Protecting your head is the exact benefit of bike helmets, that
> doesn't mean you should bike more more recklessly just because you're
> wearing a helmet. :)
>
> Doing text merges is more error prone than not doing them. :)
>
> There are myriad other benefits of breaking up large files into
> functional units. Integration history, refactoring, reuse, as I
> mentioned. Better clarity of design. Easier communication and
> coordination within a team. What's the down side? What's the advantage
> of big files with many functional units?
>


I never advocated big files with many functional units - just files
that are "just big enough". You'll know you've broken them down small
enough when you stop having to do text merges every time you commit.

> > If you don't do this, you aren't really testing your changes, you're
> > testing your reload() machinery.
>
> Only because reload() is hard in Python! ;)
>
> > You seem to have a lot of views about
> > what the "Python way" should be and those are at odds with the actual
> > way people work with Python. I'm not (necessarily) saying you're
> > wrong, but you seem to be coming at this from a confrontational
> > standpoint.
>
> When I refer to "Pythonic" all I'm talking about is what I've read
> here and observed in other people's code. I'm here looking for more
> information about how other people work, to see if there are good
> solutions to the problems I see.
>
> However when I talk about what I think is "wrong" with the Pythonic
> way, obviously that's just my opinion formed by my own experience.
>
> > Your claim, for example, that the language shouldn't place constraints
> > on how you manage your modules is questionable. I think it's more
> > likely that you've developed a workflow based around the constraints
> > (and abilities) of other languages and you're now expecting Python to
> > conform to that instead of its own.
>
> I don't think so; I'm observing things that are common to several
> projects in several languages.
>

 languages with similar runtime semantics and perhaps common
ancestry? All languages  place limitations on how you handle modules,
either because they have infrastructure you need to use or because
they lack it and you're left on your own.

> > I wonder if you've ever asked yourself why this is the case. I know
> > from my own experience why it's done in traditional C++/C environments
> > - it's because compiling is slow and breaking things into as many
> > files (with as few interdependencies) as possible speeds up the
> > compilation process.
>
> I don't think that's actually true. Fewer, bigger compilation units
> actually compile faster in C, at least in my experience.
>

If you're doing whole project compilation. When you're working,
though, you want to be able to do incremental compilation (all modern
compilers I know of support this) so you just recompile the files
you've changed (and dependencies) and relink. Support for this is why
we have stuff like precompiled headers, shadow headers like Qt uses,
and why C++ project management advocates single class-per-file
structures. Fewer dependencies between compilation units means a
faster rebuild-test turnaround.

> > Absent this need (which doesn't exist in Python),
>
> Python still takes time to load & "precompile". That time is becoming
> significant for me even in a modest sized project; I imagine it would
> be pretty awful in a multimillion line project.
>
> No matter how fast it is, I'd rather reload one module than exit my
> interpreter and reload the entire world.
>

Sure, but whats your goal here? If you're just testing something as
you work, then this works fine. If you're testing large changes, that
affect many modules, then you *need* to reload your world, because you
want to make sure that what you're testing is clean. I think this
might be related to your desire to have everything in lots of little
files. The more modules you load, the harder it is to track your
dependencies and make sure that the reload is correct.

> This is not a problem for Python as scripting language. This is a real
> problem for Python as world class application development language.
>

Considering that no other "world class application development
language" supports reload even as well as Python does, I'm not sure I
can agree here. A perfect reload might be a nice thing to have, but
lack of it hardly tosses Python (or any language) out of the running.

> > In a package __init__, which exists expressly
> > for the purpose of exposing it's interior namespaces as a single flat
> > one, it makes perfect sense.
>
> OK! That's good info, t

Re: Descriptor/Decorator challenge

2007-03-05 Thread Arnaud Delobelle
On 5 Mar, 14:38, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote:
> On 5 Mar, 07:31, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
>
> > I had an idea but no time to think it through.
> > Perhaps the under-under name mangling trick
> > can be replaced (in Py3.0) with a suitably designed decorator.
> > Your challenge is to write the decorator.
> > Any trick in the book (metaclasses, descriptors, etc) is fair game.
>
> I had some time this lunchtimes and I needed to calm my nerves so I
> took up your challenge :)
> Here is my poor effort.  I'm sure lots of things are wrong with it but
> I'm not sure I'll look at it again.

Well in fact I couldn't help but try to improve it a bit. Objects now
don't need a callerclass attribute, instead all necessary info is
stored in a global __callerclass__. Bits that didn't work now do.

So here is my final attempt, promised. The awkward bits are:
* how to find out where a method is called from
* how to resume method resolution once it has been established a
local method has to be bypassed, as I don't know how to interfere
directly with mro.

Feedback of any form is welcome (though I prefer when it's polite :)


from types import MethodType, FunctionType

class IdDict(object):
def __init__(self):
self.objects = {}
def __getitem__(self, obj):
return self.objects.get(id(obj), None)
def __setitem__(self, obj, callerclass):
self.objects[id(obj)] = callerclass
def __delitem__(self, obj):
del self.objects[id(obj)]

# This stores the information about from what class an object is
calling a method
# It is decoupled from the object, better than previous version
# Maybe that makes it easier to use with threads?
__callerclass__ = IdDict()

# The purpose of this class is to update __callerclass__ just before
and after a method is called
class BoundMethod(object):
def __init__(self, meth, callobj, callerclass):
self.values = meth, callobj, callerclass
def __call__(self, *args, **kwargs):
meth, callobj, callerclass = self.values
if callobj is None and args:
callobj = args[0]
try:
__callerclass__[callobj] = callerclass
return meth(*args, **kwargs)
finally:
del __callerclass__[callobj]

# A 'normal' method decorator is needed as well
class method(object):
def __init__(self, f):
self.f = f
def __get__(self, obj, objtype=None):
return BoundMethod(MethodType(self.f, obj, objtype), obj,
self.defclass)

class LocalMethodError(AttributeError):
pass

# The suggested localmethod decorator
class localmethod(method):
def __get__(self, obj, objtype=None):
callobj = obj or objtype
defclass = self.defclass
if __callerclass__[callobj] is defclass:
return MethodType(self.f, obj, objtype)
else:
# The caller method is from a different class, so look for
the next candidate.
mro = iter((obj and type(obj) or objtype).mro())
for c in mro: # Skip all classes up to the localmethod's
class
if c == defclass: break
name = self.name
for base in mro:
if name in base.__dict__:
try:
return base.__dict__[name].__get__(obj,
objtype)
except LocalMethodError:
continue
raise LocalMethodError, "localmethod '%s' is not accessible
outside object '%s'" % (self.name, self.defclass.__name__)

class Type(type):
def __new__(self, name, bases, attrs):
# decorate all function attributes with 'method'
for attr, val in attrs.items():
if type(val) == FunctionType:
attrs[attr] = method(val)
return type.__new__(self, name, bases, attrs)
def __init__(self, name, bases, attrs):
for attr, val in attrs.iteritems():
# Inform methods of what class they are created in
if isinstance(val, method):
val.defclass = self
# Inform localmethod of their name (in case they have to
be bypassed)
if isinstance(val, localmethod):
val.name = attr

class Object(object):
__metaclass__ = Type

# Here is your example code

class A(Object):
@localmethod
def m(self):
print 'A.m'
def am(self):
self.m()

class B(A):
@localmethod
def m(self):
print 'B.m'
def bm(self):
self.m()

m = B()
m.am() # prints 'A.m'
m.bm() # prints 'B.m'
# Added:
B.am(m)# prints 'A.m'
B.bm(m)# prints 'B.m'
m.m()  # LocalMethodError (which descends from AttributeError)

# Untested beyond this particular example!


--
Arnaud


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


Re: New to Python

2007-03-05 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

> I am trying to get a program to add up input from the user to get
> to the number 100 using a loop.  However, I am having some issues. 

Please, if you have a problem post the exact error symptoms.

> Here is what I have so far.  I know I am just trying to hard, but
> I am stuck.  Thank you for any help.

We can't tell by magic where you are stuck. Please state observed
and expected behaviour.

> print "We need to count to 100"
> 
> high_number = 100
> total = 0
> 
> number = input("Enter your first number ")

(already mentioned: please don't use input)

> sum = number + total

This is a one-time assignment.

> while sum < high_number:
> print "Not there yet..."
> number = input("Enter another number ")
> 
> print "We are there!!!"

"We" won't reach this point since the while condition never becomes
False. See above; "sum" is assigned just one time and will not
change in your while loop. Having the program work as probably
expected requires a "sum += number" inside the while loop.

BTW, what's "total" expected to do? It's also assigned only one
time.

Regards,


Björn

-- 
BOFH excuse #150:

Arcserve crashed the server again.

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


Re: New to Python

2007-03-05 Thread Stargaming
[EMAIL PROTECTED] schrieb:
> I am trying to get a program to add up input from the user to get to
> the number 100 using a loop.  However, I am having some issues.  Here
> is what I have so far.  I know I am just trying to hard, but I am
> stuck.  Thank you for any help.
> 
> print "We need to count to 100"
> 
> high_number = 100
> total = 0
> 
> number = input("Enter your first number ")
> sum = number + total
> while sum < high_number:
> print "Not there yet..."
> number = input("Enter another number ")
> 
> print "We are there!!!"
> 

Just reading the error messages would be a good start. You assign `sum` 
to `number + total` but as I see it there's no `number` so far. You have 
to increment some variable with the user's input. (`sum += input(..)`)
Additionally, `total` and `number` seem pretty redundant. You only need 
two variables, one containing the targeted number, one the current progress.
By the way, input() is considered pretty evil because the user can enter 
arbitrary expressions. It is recommended to use raw_input() (till Python 
3.0), in your case e. g. int(raw_input()) wrapped in a try-except block.
HTH,
Stargaming
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FloatCanvas in a wxpython application.... layout problems

2007-03-05 Thread Chris
On Feb 21, 1:40 pm, "nelson -" <[EMAIL PROTECTED]> wrote:
> Hi all,
>  i'm developing an application that uses Floatcanvas to diplay a
> cartesian plane. how can i embed it into a "complex" layout?

Your best bet is either the floatcanvas list:

http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas

or the wxPython-users list:

http://www.wxpython.org/maillist.php

In this case, putting a FloatCanvas in an app is no different than
putting any wx.Panel in, so the wxPython list would be fine.

-Chris

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


New to Python

2007-03-05 Thread [EMAIL PROTECTED]
I am trying to get a program to add up input from the user to get to
the number 100 using a loop.  However, I am having some issues.  Here
is what I have so far.  I know I am just trying to hard, but I am
stuck.  Thank you for any help.

print "We need to count to 100"

high_number = 100
total = 0

number = input("Enter your first number ")
sum = number + total
while sum < high_number:
print "Not there yet..."
number = input("Enter another number ")

print "We are there!!!"

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


Re: Project organization and import

2007-03-05 Thread Martin Unsal
On Mar 5, 9:15 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> That's actually the exact benefit of unit testing, but I don't feel
> that you've actually made a case that this workflow is error prone.
> You often have multiple developers working on the same parts of the
> same module?

Protecting your head is the exact benefit of bike helmets, that
doesn't mean you should bike more more recklessly just because you're
wearing a helmet. :)

Doing text merges is more error prone than not doing them. :)

There are myriad other benefits of breaking up large files into
functional units. Integration history, refactoring, reuse, as I
mentioned. Better clarity of design. Easier communication and
coordination within a team. What's the down side? What's the advantage
of big files with many functional units?

> If you don't do this, you aren't really testing your changes, you're
> testing your reload() machinery.

Only because reload() is hard in Python! ;)

> You seem to have a lot of views about
> what the "Python way" should be and those are at odds with the actual
> way people work with Python. I'm not (necessarily) saying you're
> wrong, but you seem to be coming at this from a confrontational
> standpoint.

When I refer to "Pythonic" all I'm talking about is what I've read
here and observed in other people's code. I'm here looking for more
information about how other people work, to see if there are good
solutions to the problems I see.

However when I talk about what I think is "wrong" with the Pythonic
way, obviously that's just my opinion formed by my own experience.

> Your claim, for example, that the language shouldn't place constraints
> on how you manage your modules is questionable. I think it's more
> likely that you've developed a workflow based around the constraints
> (and abilities) of other languages and you're now expecting Python to
> conform to that instead of its own.

I don't think so; I'm observing things that are common to several
projects in several languages.

> I wonder if you've ever asked yourself why this is the case. I know
> from my own experience why it's done in traditional C++/C environments
> - it's because compiling is slow and breaking things into as many
> files (with as few interdependencies) as possible speeds up the
> compilation process.

I don't think that's actually true. Fewer, bigger compilation units
actually compile faster in C, at least in my experience.

> Absent this need (which doesn't exist in Python),

Python still takes time to load & "precompile". That time is becoming
significant for me even in a modest sized project; I imagine it would
be pretty awful in a multimillion line project.

No matter how fast it is, I'd rather reload one module than exit my
interpreter and reload the entire world.

This is not a problem for Python as scripting language. This is a real
problem for Python as world class application development language.

> In a package __init__, which exists expressly
> for the purpose of exposing it's interior namespaces as a single flat
> one, it makes perfect sense.

OK! That's good info, thanks.

> Nobody I know uses reload() for anything more than trivial "as
> you work" testing in the interpreter. It's not reliable or recommended
> for anything other than that.

That too... although I think that's unfortunate. If reload() were
reliable, would you use it? Do you think it's inherently unreliable,
that is, it couldn't be fixed without fundamentally breaking the
Python language core?

> This is
> still a much faster way than compiling any but the most trivial of
> C/C++ modules.

I'm with you there! I love Python and I'd never go back to C/C++. That
doesn't change my opinion that Python's import mechanism is an
impediment to developing large projects in the language.

> If you don't like working with explicit namespaces, you've probably
> chosen the wrong language.

I never said that. I like foo.Bar(), I just don't like typing
foo.Foo() and bar.Bar(), which is a waste of space; syntax without
semantics.

> I propose that the technique most amenable to source code management
> is for a single file (or RCS level module, if you have a locking RCS)
> to have everything that it makes sense to edit or change for a
> specific feature.

Oh, I agree completely. I think we're using the exact same criterion.
A class is a self-contained feature with a well defined interface,
just what you'd want to put in it's own file. (Obviously there are
trivial classes which don't implement features, and they don't need
their own files.)

> You're also placing far too much emphasis on reload. Focus yourself on
> unit tests and environment scripts instead. These are more reliable
> and easier to validate than reload() in a shell.

I think this is the crux of my frustration. I think reload() is
unreliable and hard to validate because Python's package management is
broken. I appreciate your suggestion of alternatives and I think I
need to come to terms with the fact that re

Re: Help Deciphering Code

2007-03-05 Thread Terry Reedy

"Bryan Leber" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

I am learning python and I am having to make some changes on an existing
python script. What happens is that one scripts creates an xml document
that looks like this:

>> "IPM2.1/Identity/IdentityWebApp/Source/com/fisc/prioss/dataservice/component/profile
>>>  
>>> ProfileUtil.java".split()

['IPM2.1/Identity/IdentityWebApp/Source/com/fisc/prioss/dataservice/component/profile',
 
'ProfileUtil.java']

If the ' ' were a '/' instead, then the os.path module has a function for 
splitting off the last component, the file name.

Terry Jan Reedy




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


Re: Howto pass exceptions between threads

2007-03-05 Thread John Nagle
Alexander Eisenhuth wrote:
> Hallo Alltogether,
> 
> I've searched in this mailing list, but it seems to me that there is no 
> general approach to pass exceptions from one thread to another.

Very few languages have that.

Actually, it could be made to work for Python, but it would have to
be carefully designed.  Something that raises an exception in another
thread the next time the thread blocks would have relatively sane
semantics.  You couldn't raise an exception on a compute-bound thread,
only at block points (locks, I/O, long system calls.)

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


Re: Mod python - mysql lock

2007-03-05 Thread John Nagle
If you use MySQL 5, you get atomic transactions.  The old
"LOCK" thing is becoming obsolete.  Suggest getting a newer
MySQL and a newer MySQL book.

John Nagle

Jan Danielsson wrote:
> Roopesh wrote:
> 
>>In my mod_python project I am using mysql as the database. There is
>>table card in which unique cards are stored. When a user request comes
>>he has to get a unique card. In this situation I want to use LOCK with
>>which I can prevent other users accessing the table. I tried excuting
>>"LOCK" command of mysql through python code, but it is not locking the
>>database. Any ideas why this isn't working and how can I do the same.
>>
>>//python code
>>sql = "LOCK TABLES card WRITE"
>>cursor.execute(sql)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question

2007-03-05 Thread [EMAIL PROTECTED]
On Mar 5, 9:03 am, Stargaming <[EMAIL PROTECTED]> wrote:
> Tommy Grav schrieb:

>
> For this case, there are list comprehensions (or map, but you shouldn't
> use it any longer):


I didn't see anything in the docs about this.  Is map going away or is
it considered un-Pythonic now?

Josh

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


Re: list-like behaviour of etree.Element

2007-03-05 Thread [EMAIL PROTECTED]
On Mar 5, 1:00 am, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:
> Raymond Hettinger wrote:
> > On Mar 4, 12:48 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> >> The etree.Element (or ElementTree.Element) supports a number of
> >> list-like methods: append, insert, remove. Any special reason why it
> >> doesn't support pop and extend (and maybe count)?
>
> > Those methods would not be hard to add.  Perhaps, submit a feature
> > request to Fredrik Lundh on SourceForge and see what he thinks there
> > is merit in more closely emulating the list API.  Of the methods you
> > listed, the case is probably strongest for extend().
>
> extend() will be in the next release:
>
>http://effbot.org/zone/elementtree-changes-13.htm
>
> (lxml.etree already has it, btw).
>
> not sure I see the point of pop() and count().  a successful feature request
> would need to include some really compelling use cases.
>
> 

Pop could be useful.  I could use it.

I'm working on a story and submission tracker.  It stores everything
in XML and I use a sax parser to build reports.  If I have to update
one bit of data (say, a submission returns a sale) I have to use a
nasty extraction program that returns the submission node AND the rest
of the document (minus that node).  Then I make the changes of the
individual submission, and append it to the end of submissions data
document.  (I don't care about the order of items in the file, since
my reporting methods re-order everything anyway.)

Josh

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


Re: Newbie question

2007-03-05 Thread Larry Bates
Tommy Grav wrote:
> Hi list,
> 
>this is somewhat of a newbie question that has irritated me for a while.
> I have a file test.txt:
> 
> 0.3434  0.5322 0.3345
> 1.3435  2.3345 5.3433
> 
> and this script
> lines = open("test.txt","r").readlines()
> for line in lines:
>(xin,yin,zin) = line.split()
>x = float(xin)
>y = float(yin)
>z = float(zin)
> 
> Is there a way to go from line.split() to x,y,z as floats without
> converting
> each variable individually?
> 
> Cheers
>Tommy


Using a list comprehension you would write this as:

for line in lines:
xin, yin, zin=[float(x) for x in line.split()]

This if course expects your data to be perfect.  If
you want error handling (e.g. less or more than 3 values,
values that cause exception when passed to float, etc.)
you will have to handle that differently.

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


Re: Python object to xml biding

2007-03-05 Thread Stefan Behnel
raf wrote:
> I'm looking for a python to XSD/xml biding library to easy handling
> this very large protocol spec I need to tackle. I've searched google
> quite extensibly and I haven't found anything that properly fits the
> bill... I'm mostly interested at the xml -> python and python->xml
> marshalling/unmarshalling much like jaxb for java.

Consider using lxml.objectify. It's extremely powerful and simple to use at
the same time.

http://codespeak.net/lxml/dev/objectify.html#element-access-through-object-attributes

http://codespeak.net/lxml/

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


Re: Python stock market analysis tools?

2007-03-05 Thread Mudcat
On Mar 5, 7:55 am, "Beliavsky" <[EMAIL PROTECTED]> wrote:

> Yes, and a discussion of investment approaches would be off-topic.
> Unfortunately, newsgroups such as misc.invest.stocks are dominated by
> spam -- the moderated newsgroup misc.invest.financial-plan is better.
>
> Some research says that "mean variance portfolio optimization" can
> give good results. I discussed this in a message
>

I actually checked out some of those newsgroups in trying to find a
tool to use. I think I even posted a question about it. But you're
right in that there's so much spam, and all of the responses I got
were people trying to hock their own wares. Didn't find much in the
way of useful information.


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


Re: Python stock market analysis tools?

2007-03-05 Thread Mudcat

> What kind of tool do you want?  Getting quotes is the easy part:
>
> import urllib
> symbols = 'ibm jpm msft nok'.split()
> quotes = urllib.urlopen( 'http://finance.yahoo.com/d/quotes.csv?s='+
>  '+'.join(symbols) + '&f=l1&e=.csv').read().split()
> print dict(zip(symbols, quotes))
>
> The hard part is raising capital and deciding what to buy, sell, or
> hold.
>
> Raymond

Yeah, I have something that pulls quotes. So the data isn't hard to
get, but I'm not really interested in building the graphs. I was
hoping to find something already built with the common indicators
already built in that I could add my own to.

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


Re: How use XML parsing tools on this one specific URL?

2007-03-05 Thread Stefan Behnel
[EMAIL PROTECTED] schrieb:
> I understand that the web is full of ill-formed XHTML web pages but
> this is Microsoft:
> 
> http://moneycentral.msn.com/companyreport?Symbol=BBBY
> 
> I can't validate it and xml.minidom.dom.parseString won't work on it.

Interestingly, no-one mentioned lxml so far:

http://codespeak.net/lxml
http://codespeak.net/lxml/dev/parsing.html#parsers

Parse it as HTML and then use anything from XPath to XSLT to treat it.

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


Re: Python GUI + OpenGL

2007-03-05 Thread Chris Mellon
On 3/5/07, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> Dag wrote:
>
> > On Fri, 02 Mar 2007 18:30:34 +0100, Diez B. Roggisch <[EMAIL PROTECTED]>
> > wrote:
> >> Achim Domma wrote:
> >>
> >>> Hi,
> >>>
> >>> I'm developing a GUI app in Python/C++ to visualize numerical results.
> >>> Currently I'm using Python 2.4 with wx and PyOpenGLContext, but there
> >>> are no windows binaries for Python 2.5 for quite some time now.
> >>>
> >>> I need a OpenGL context without restrictions and some settings dialogs.
> >>> Is wx + PyOpenGL the way to go? Or could somebody recommend a better set
> >>> of tools/libs?
> >>
> >> PyQt, but then there is the licensing question of course.
> >
> > I'm facing a similar problem.  Would you care to explain why PyQt is
> > better in this particular case.  I've used both PyQt and wx for 'normal'
> > GUI programming (but I'm more familiar with wx) so I know about their
> > difference in general.  But why is PyQt better than wx for working with
> > OpenGL?
>
> I didn't say so. I just pointed out an alternative, as the OP had issues
> with obtaining binary packages for wx + py2.5
>

I believe he was having trouble with binary packages for PyOpenGL,
wxPython has 2.5 binaries and has since it was released.

That said, it's my understanding that the most recent version of
PyOpenGL uses ctypes and no longer requires a windows binary, which is
why they are not provided.

Also, if you're writing a C++/Python app on Windows then you must have
the correct environment to build Python extensions, so even if my
understanding is incorrect, you should be able to build PyOpenGL via
distutils with minimal if any trouble.

> Beside that, I do love the Qt library and would always use it in preference
> to wx, but this is a general thing and by no means tied to the
> OpenGL-programming. After all, that actually is done using PyOpenGL
>

wx and Qt support OpenGL in essentially the same manner. I believe he
took from your earlier post that Qt had its own built in OpenGL
wrapper (and thus didn't rely on PyOpenGL) but to my knowledge that is
not correct.

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


Re: Project organization and import

2007-03-05 Thread Chris Mellon
On 5 Mar 2007 08:32:34 -0800, Martin Unsal <[EMAIL PROTECTED]> wrote:
> Jorge, thanks for your response. I replied earlier but I think my
> response got lost. I'm trying again.
>
> On Mar 4, 5:20 pm, Jorge Godoy <[EMAIL PROTECTED]> wrote:
> > Why?  RCS systems can merge changes.  A RCS system is not a substitute for
> > design or programmers communication.
>
> Text merges are an error-prone process. They can't be eliminated but
> they are best avoided when possible.
>
> When refactoring, it's much better to move small files around than to
> move chunks of code between large files. In the former case your SCM
> system can track integration history, which is a big win.
>
> > Unit tests help being sure that one change doesn't break the project as a
> > whole and for a big project you're surely going to have a lot of those 
> > tests.
>
> But unit tests are never an excuse for error prone workflow. "Oh,
> don't worry, we'll catch that with unit tests" is never something you
> want to say or hear.
>

That's actually the exact benefit of unit testing, but I don't feel
that you've actually made a case that this workflow is error prone.
You often have multiple developers working on the same parts of the
same module?

> > I don't reload...  When my investigative tests gets bigger I write a script
> > and run it with the interpreter.  It is easy since my text editor can call
> > Python on a buffer (I use Emacs).
>
> That's interesting, is this workflow pretty universal in the Python
> world?
>
> I guess that seems unfortunate to me, one of the big wins for
> interpreted languages is to make the development cycle as short and
> interactive as possible. As I see it, the Python way should be to
> reload a file and reinvoke the class directly, not to restart the
> interpreter, load an entire package and then run a test script to set
> up your test conditions again.

If you don't do this, you aren't really testing your changes, you're
testing your reload() machinery. You seem to have a lot of views about
what the "Python way" should be and those are at odds with the actual
way people work with Python. I'm not (necessarily) saying you're
wrong, but you seem to be coming at this from a confrontational
standpoint.

Your claim, for example, that the language shouldn't place constraints
on how you manage your modules is questionable. I think it's more
likely that you've developed a workflow based around the constraints
(and abilities) of other languages and you're now expecting Python to
conform to that instead of its own.

I've copied some of your responses from your earlier post below:

>Yes. I've worked extensively on several projects in several languages
>with multi-million lines of code and they invariably have coding
>styles that recommend one functional unit (such as a class), or at
>most a few closely related functional units per file.

I wonder if you've ever asked yourself why this is the case. I know
from my own experience why it's done in traditional C++/C environments
- it's because compiling is slow and breaking things into as many
files (with as few interdependencies) as possible speeds up the
compilation process. Absent this need (which doesn't exist in Python),
what benefit is there to separating out related functionality into
multiple files? Don't split them up just because you've done so in the
past - know why you did it in the past and if those conditions still
apply. Don't split them up until it makes sense for *this* project,
not the one you did last year or 10 years ago.

>I guess my question boils down to this. Is "from foo import *" really
>deprecated or not? If everyone has to use "from foo import *" despite
>the problems it causes, how do they work around those problems (such
>as reloading)?

from foo import * is a bad idea at a top level because it pollutes
your local namespace. In a package __init__, which exists expressly
for the purpose of exposing it's interior namespaces as a single flat
one, it makes perfect sense. In some cases you don't want to export
everything, which is when __all__ starts to make sense. Clients of a
package (or a module) shouldn't use from foo import * without a good
reason. Nobody I know uses reload() for anything more than trivial "as
you work" testing in the interpreter. It's not reliable or recommended
for anything other than that. It's not hard to restart a shell,
especially if you use ipython (which can save and re-create a session)
or a script thats set up to create your testing environment. This is
still a much faster way than compiling any but the most trivial of
C/C++ modules. In fact, on my system startup time for the interpreter
is roughly the same as the "startup time" of my compiler (that is to
say, the amount of time it takes deciding what its going to compile,
without actually compiling anything).

>You're still stuck doing foo.Foo() everywhere in your client code,
>which is ugly and wastes space, or using "from foo import *" which is
>broken.

If you don

Re: Newbie question

2007-03-05 Thread Stargaming
Tommy Grav schrieb:
> Hi list,
> 
>this is somewhat of a newbie question that has irritated me for a  
> while.
> I have a file test.txt:
> 
> 0.3434  0.5322 0.3345
> 1.3435  2.3345 5.3433
> 
> and this script
> lines = open("test.txt","r").readlines()
> for line in lines:
>(xin,yin,zin) = line.split()
>x = float(xin)
>y = float(yin)
>z = float(zin)
> 
> Is there a way to go from line.split() to x,y,z as floats without  
> converting
> each variable individually?
> 
> Cheers
>Tommy

For this case, there are list comprehensions (or map, but you shouldn't 
use it any longer):

 >>> a = "0.3434  0.5322 0.3345"
 >>> b = a.split()
 >>> map(float, b)
[0.34338, 0.53221, 0.33452]
 >>> [float(x) for x in b]
[0.34338, 0.53221, 0.33452]

I think it should be easy to apply this to your example above.

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


Re: worker thread catching exceptions and putting them in queue

2007-03-05 Thread Stargaming
Paul Sijben schrieb:
> All,
> 
> in a worker thread setup that communicates via queues is it possible to
> catch exceptions raised by the worker executed, put them in an object
> and send them over the queue to another thread where the exception is
> raised in that scope?
> 
> considering that an exception is an object I feel it ought to be
> possible, however I do not see how to go about it.
> 
> does anyone have a pointer towards the solution?
> 
> Paul

You're right, even exceptions are objects in Python. For further 
studies, read http://docs.python.org/lib/module-exceptions.html

You can catch an exception like this:
try:
   worker.do_some_work_that_may_raise_an_exception()
except Exception, e:
   # the first argument is the type of error you want to handle
   # it is Exception here, the baseclass of all computation exceptions
   # the second argument is the variable (name) where you want to save
   # the specific exception raised to
   # it's 'e' here, a common shortcut for exception
   exception_handler.handle(e)
   # notice that you can pass e around as you like

For further information on exceptions and how to handle them, read 
chapter 8 of the tutorial, especially starting from 8.3: 
http://docs.python.org/tut/node10.html#SECTION001030

P.S. I don't know if what I told still applies to Python 3.0 -- a lot of 
changes are upcoming related to exception raising and handling.
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie question

2007-03-05 Thread Tommy Grav
Hi list,

this is somewhat of a newbie question that has irritated me for a  
while.
I have a file test.txt:

0.3434  0.5322 0.3345
1.3435  2.3345 5.3433

and this script
lines = open("test.txt","r").readlines()
for line in lines:
(xin,yin,zin) = line.split()
x = float(xin)
y = float(yin)
z = float(zin)

Is there a way to go from line.split() to x,y,z as floats without  
converting
each variable individually?

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


Re: worker thread catching exceptions and putting them in queue

2007-03-05 Thread Diez B. Roggisch
Paul Sijben wrote:

> All,
> 
> in a worker thread setup that communicates via queues is it possible to
> catch exceptions raised by the worker executed, put them in an object
> and send them over the queue to another thread where the exception is
> raised in that scope?
> 
> considering that an exception is an object I feel it ought to be
> possible, however I do not see how to go about it.
> 
> does anyone have a pointer towards the solution?


Just raise the exception object found in the queue. Only make sure it _is_
an exception, as you can raise everything. So in your queue-putting-code
you might consider discriminating between the two cases, like this:


while True:
   try:
  result = 1, work()
   except:
  result = 2, sys.exc_info()[1]
   queue.put(result)

---
while True:
   kind, result = queue.get()
   if kind == 1:
  do(result)
   elif kind == 2:
  raise result


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


  1   2   >