Re: Coming from .NET and VB and C

2008-09-04 Thread Simon Brunning
2008/9/3 Dennis Lee Bieber <[EMAIL PROTECTED]>:

>  non-relational DBMS (if any such are still in use),

There certainly are...

>> SO, I'm interested in using my Google App space (free 500MB) to
>> develop a quick database application.  Using Python.  I found "Dive
>> Into Python" which I will be reading shortly.
>>
>So one question: what RDBMs are supported in that space?

... and the Google's BigTable (see
) is one of them.

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


Re: python/xpath question..

2008-09-04 Thread Stefan Behnel
Hi,

you should really read about XPath. There are also newsgroups specifically for
this topic, please use them.


bruce wrote:
> in my python, i'm using the xpath function to iterate/parse some html. i can
> do something like
> 
> s=d.xpath("//tr/td/text()")
> count=len(s)
> 
> and get the number of nodes that have text

That is a wrong assumption. It will give you the number of text nodes, not the
number of elements. They may or may not be the same.


> i can then do something like
> s=d.xpath("//tr/td")
> count2=len(s)
> 
> and get the number of total nodes...
> by subtracting, i can get the number of nodes, without text.. is there an
> easier way??!!

Yes, learn to use XPath, e.g.

  //tr/td[not string()]

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


Re: xml + mmap cross

2008-09-04 Thread Stefan Behnel
castironpi wrote:
> Any interest in pursuing/developing/working together on a mmaped-xml
> class?  Faster, not readable in text editor.

Any hints on what you are talking about?

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


use str as variable name

2008-09-04 Thread Mathieu Prevot
Hi,

I have a program that take a word as argument, and I would like to
link this word to a class variable.

eg.
class foo():
  width = 10
  height = 20

a=foo()
arg='height'
a.__argname__= new_value

rather than :

if arg == 'height':
  a.height = new_value
elif arg == 'width';
  a.width = new_value

Can I do this with python ? How ?

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


Re: use str as variable name

2008-09-04 Thread Chris Rebert
On Thu, Sep 4, 2008 at 12:25 AM, Mathieu Prevot
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a program that take a word as argument, and I would like to
> link this word to a class variable.
>
> eg.
> class foo():

You should subclass 'object', so that should be:
class Foo(object):

>  width = 10
>  height = 20
>
> a=foo()
> arg='height'
> a.__argname__= new_value

You're looking for the setattr() built-in function. In this exact case:
setattr(a, arg, new_value)

This is probably covered in the Python tutorial, please read it.

Regards,
Chris

>
> rather than :
>
> if arg == 'height':
>  a.height = new_value
> elif arg == 'width';
>  a.width = new_value
>
> Can I do this with python ? How ?
>
> Thanks,
> Mathieu
> --
> http://mail.python.org/mailman/listinfo/python-list
>

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: use str as variable name

2008-09-04 Thread Fredrik Lundh

Mathieu Prevot wrote:


I have a program that take a word as argument, and I would like to
link this word to a class variable.

eg.
class foo():
  width = 10
  height = 20

a=foo()
arg='height'
a.__argname__= new_value

rather than :

if arg == 'height':
  a.height = new_value
elif arg == 'width';
  a.width = new_value

Can I do this with python ? How ?


assuming you mean "instance variable" ("a" is an instance of the class 
"foo"), you can use setattr:


a = foo()
arg = 'height'
setattr(a, arg, new_value)



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


Re: use str as variable name

2008-09-04 Thread Gabriel Genellina
En Thu, 04 Sep 2008 04:25:37 -0300, Mathieu Prevot  
<[EMAIL PROTECTED]> escribi�:



I have a program that take a word as argument, and I would like to
link this word to a class variable.

eg.
class foo():
  width = 10
  height = 20

a=foo()
arg='height'
a.__argname__= new_value

rather than :

if arg == 'height':
  a.height = new_value
elif arg == 'width';
  a.width = new_value


You're looking for "setattr":

setattr(a, arg, new_value)

http://docs.python.org/lib/built-in-funcs.html#l2h-66



Can I do this with python ? How ?

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





--
Gabriel Genellina

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

Re: use str as variable name

2008-09-04 Thread Mathieu Prevot
2008/9/4 Chris Rebert <[EMAIL PROTECTED]>:
> On Thu, Sep 4, 2008 at 12:25 AM, Mathieu Prevot
> <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I have a program that take a word as argument, and I would like to
>> link this word to a class variable.
>>
>> eg.
>> class foo():
>
> You should subclass 'object', so that should be:
>class Foo(object):
>
>>  width = 10
>>  height = 20
>>
>> a=foo()
>> arg='height'
>> a.__argname__= new_value
>
> You're looking for the setattr() built-in function. In this exact case:
>setattr(a, arg, new_value)
>
> This is probably covered in the Python tutorial, please read it.
>
> Regards,
> Chris

Indeed.

I'll use:
a.__setattr__(height, new_value)

Thanks to all
Mathieu
--
http://mail.python.org/mailman/listinfo/python-list


Re: use str as variable name

2008-09-04 Thread Fredrik Lundh

Mathieu Prevot wrote:


I'll use:
a.__setattr__(height, new_value)


that's an implementation detail.  please use setattr() instead, like 
everyone else.




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


Re: Late initialization using __getattribute__

2008-09-04 Thread Bruno Desthuilliers

bukzor a écrit :

On Sep 3, 1:02 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:

bukzor a écrit :
(snip)


Thanks for the reply. Just to see it not work, I tried to remove
__getattribute__ from LateInitMixIn, but couldn't get it to work.

??? Sorry, I don't get what you mean...


Since you said __getattribute__ is an attribute of the class, I tried
to run (something to the effect of) delattr(self.__class__,
"__getattribute__"),


Ah, ok. Definitively *not* a thing to do...



but it threw an AttributeError.


You'd have to call it on the mixin class itself, not on a subclass.




My Base class is a C class (_mysql.connection from MySQLdb) that
sometimes segfaults if you try to use it before it's fully
initialized,


... I have used MySQLdb for years on more than a dozen linux
distribs, and never had such a problem. Is this a known bug ? Or is
there something wrong with your setup ?


I'm trying to optimize my number of connections


Connection pooling anyone ? IIRC, this is something that already exists 
in quite a couple libs / frameworks. Is there a reason you try to roll 
your own ?



by not fully
initializing (read: not connecting) my connection until it's used in
some way. Of course the maintainer didn't envision this (mis)use, so
the object sometimes throws bad errors until it's fully initialized.


Ok.


Of course the *correct* way to do this is to be more careful about
when I create connections, but I think I should be able to get this to
work, and it (would be) much easier to do it The Right Way once it
works.


Please pardon me for repeating the same thing over and over, but messing 
with __getattribute__ is certainly not the way to go.



so unfortunately I think I need to use __getattribute__
to do this. I'm doing all this just to make the connection not
actually connect until used.

I may be dumb, but I don't get how this is supposed to solve your
problem. But anyway : there's a known design pattern for what you're
trying to do, that doesn't require mixins nor messing with
__getattribute__ (which, I repeat, is more often than not something you
*don't* want to do). The name of the design pattern is "proxy". I
strongly suggest that you 1/ try to cure the real problem instead of
hacking around and 2/ read about the proxy design pattern.

My 2 cents...


I like the idea of mix-ins, but can't figure out how to make a proxy
work that way.


You mean, "how to use a proxy for lazy initialization" ? Heck, that's 
the exact use case in the GoF.



For a long time I had a proxy class that added five or
six features on top of the MySQLdb package, but it wasn't configurable
enough, and I'm working on splitting each feature into its own MixIn
class.


As an aside, this is working for me pretty well. The "reconnect"
method (inheritied from a "Reconnectable" mixin) uses several of the
object's attributes, so I need to set _inited beforehand so that I
don't get into an infinite __getattribute__ loop. What I'd *really*
like to do is remove __getattribute__ from the object at that point.


You can't. Or, more exactly, all you can do is remove __getattribute__ 
from the mixin class - but then the mixin class won't work anymore. I 
don't mean to be condescendant, but it looks like you don't have a clear 
understanding of Python's object model here - else you wouldn't even 
consider doing such a thing. FWIW, I posted a solution based on the 
__getattr__ hook, which did work - at least for the "specs" implied by 
your code snippet.


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


Re: max(), sum(), next()

2008-09-04 Thread Mensanator
On Sep 4, 1:26 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Wed, 03 Sep 2008 22:20:43 -0700, Mensanator wrote:
> > On Sep 3, 8:30 pm, Steven D'Aprano <[EMAIL PROTECTED]
> > cybersource.com.au> wrote:
> >> On Wed, 03 Sep 2008 16:20:39 -0700, Mensanator wrote:
> >>  sum([])
> >> > 0
>
> >> > is a bug, just as it's a bug in Excel to evaluate blank cells as 0.
> >> > It should return None or throw an exception like sum([None,1]) does.
>
> >> You're wrong, because 99.9% of the time when users leave a blank cell
> >> in Excel, they want it to be treated as zero.
>
> > Then 99.9% of users want the wrong thing.
>
> It is to laugh.
>
> > Microsoft knows that this is a bug
>
> Says you.
>
> > but refuses to fix it to prevent breaking legacy documents (probably
> > dating back to VisiCalc). When graphimg data, a missing value should be
> > interpreted as a hole in the graph
>
> "Graphing data" is not sum(). I don't expect graphing data to result in
> the same result as sum(), why would I expect them to interpret input the
> same way?
>
> > +--+ +--+--+--+-+
>
> Why should the graphing application ignore blanks ("missing data"), but
> sum() treat missing data as an error? That makes no sense at all.

Maybe it's important to know data is missing. You can see
the holes in a graph. You can't see the holes in a sum.

>
> > and not evaluated as 0
>
> > And Microsoft provides a workaround for graphs to make 0's appear as
> > holes. Of course, this will cause legitimate 0 values to disappear, so
> > the workaround is inconsistent.
>
> I'm not aware of any spreadsheet that treats empty cells as zero for the
> purpose of graphing, and I find your claim that Excel can't draw graphs
> with zero in them implausible, but I don't have a copy of Excel to test
> it.

That was a mistake. I made a followup correction, but
you probably didn't see it.

>
> >> Spreadsheet sum() is not the
> >> same as mathematician's sum, which doesn't have a concept of "blank
> >> cells". (But if it did, it would treat them as zero, since that's the
> >> only useful thing and mathematicians are just as much pragmatists as
> >> spreadsheet users.) The Excel code does the right thing, and your
> >> "pure" solution would do the unwanted and unexpected thing and is
> >> therefore buggy.
>
> > Apparently, you don't use databases or make surface contours.
>
> Neither databases nor surface contours are sum(). What possible relevance
> are they to the question of what sum() should do?

Because a sum that includes Nulls isn't valid. If you treated
Nulls as 0, then not only would your sum be wrong, but so
would your count and the average based on those. Now you
can EXPLICITLY tell the database to only consider non-Null
values, which doesn't change the total, but DOES change
the count.

>
> Do you perhaps imagine that there is only "ONE POSSIBLE CORRECT WAY" to
> deal with missing data, and every function and program must deal with it
> the same way?

But that's what sum() is doing now, treating sum([]) the same
as sum([],0). Why isn't sum() defined such that "...if list
is empty, return start, IF SPECIFIED, otherwise raise exception."
Then, instead of "ONE POSSIBLE CORRECT WAY", the user could
specify whether he wants Excel compatible behaviour or
Access compatible behaviour.

>
> > Contour programs REQUIRE that blanks are null, not 0
>
> Lucky for them that null is not 0 then.

No, but blank cells are 0 as far as Excel is concerned.
That behaviour causes nothing but trouble and I am
saddened to see Python emulate such nonsense.

>
> > so that the Kriging
> > algorithm interpolates around the holes rather than return false
> > calculations. Excel's treatment of blank cells is inconsistent with
> > Access' treatment of Nulls and therefore wrong, anyway you slice it.
>
> No no no, you messed that sentence up. What you *really* meant was:
>
> "Access' treatment of Nulls is inconsistent with Excel's treatment of
> blank cells and therefore wrong, anyway you slice it."
>
> No of course not. That would be stupid, just as stupid as your sentence.
> Excel is not Access. They do different things. Why should they
> necessarily interpret data the same way?

Because you want consistent results?

>
> > Maybe you want to say a bug is when it doesn't do what the author
> > intended, but I say if what the intention was is wrong, then a perfect
> > implentation is still a bug because it doesn't do what it's supposed to
> > do.
>
> Who decides what it is supposed to do if not the author?

The author can't change math on a whim.

> You, in your ivory tower who doesn't care a fig for
> what people want the software to do?

True, I could care less what peole want to do...

...as long as they do it consistently.

>
> Bug report: "Software does what users want it to do."
> Fix: "Make the software do something that users don't want."

What the users want doesn't carry any weight with respect
to what the database wants. The user mu

Re: PyGUI as a standard GUI API for Python?

2008-09-04 Thread M.-A. Lemburg
On 2008-09-04 07:49, Kay Schluehr wrote:
> 3) Following the public rumor mill and the latest hype RIA i.e. the
> merge of web- and desktop applications with systems like Adobe AIR,
> JavaFX, Google Gears and MS Silverlight is the future of frontend
> development. With the exception of IronPython and Silverlight, Python
> hasn't even entered this game and no one knows if it ever will.

Actually, it has already and quite some time ago:

http://www.artima.com/weblogs/viewpost.jsp?thread=208528

The recipe is simple: use Python for the business logic, database
interfacing, etc and have it talk to a Flex front-end via XML-RPC
or REST.

As a nice side-effect, this also results in a better separation
between GUI and backend, effectively making the solution future-proof
and easy to adapt to other front-end technologies.

We've been working with this approach for almost a year now and
so far never had to look back.

-- 
Marc-Andre Lemburg
eGenix.com

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


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


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


Re: use str as variable name

2008-09-04 Thread Bruno Desthuilliers

Mathieu Prevot a écrit :

2008/9/4 Chris Rebert <[EMAIL PROTECTED]>:


(snip)


You're looking for the setattr() built-in function. In this exact case:
   setattr(a, arg, new_value)

This is probably covered in the Python tutorial, please read it.

Regards,
Chris


Indeed.

I'll use:
a.__setattr__(height, new_value)


Please don't. Use the generic setattr() function instead. This holds for 
any __magic__ method : they are *implementation* for operators and 
generic functions  - which you can think of as operators with a function 
syntax -, and are not meant to be called directly. You wouldn't write 
something like 2.__add__(3), would you ?


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


CREDIT CARD DEPT

2008-09-04 Thread roseeea
CREDIT CARD DEPT

http://creditcarddept.googlepages.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: use str as variable name

2008-09-04 Thread Nick Craig-Wood
Mathieu Prevot <[EMAIL PROTECTED]> wrote:
>  Hi,
> 
>  I have a program that take a word as argument, and I would like to
>  link this word to a class variable.
> 
>  eg.
>  class foo():
>width = 10
>height = 20
> 
>  a=foo()
>  arg='height'
>  a.__argname__= new_value

Not quite sure what the above is supposed to achieve

>  rather than :
> 
>  if arg == 'height':
>a.height = new_value
>  elif arg == 'width';
>a.width = new_value
> 
>  Can I do this with python ? How ?

setattr(a, arg, new_value)

See: http://docs.python.org/lib/built-in-funcs.html


-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: use str as variable name

2008-09-04 Thread Fredrik Lundh

Bruno Desthuilliers wrote:

> You wouldn't write something like 2.__add__(3), would you ?

Don't give the "it's only OO if I write obj.method(args)" crowd more bad 
ideas, please ;-)


(...as Bruno implies, setattr(), len() et al can be and should be viewed 
as generic functions.  A specific Python implementation may use custom 
code to implement behaviour for a given object; behaviour that's more 
efficient than a full Python-level method call.  For example, in 
CPython, len(L) is about twice as fast as L.__len__() for built-in 
sequences.)




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


Re: PyGUI as a standard GUI API for Python?

2008-09-04 Thread Kay Schluehr
On 4 Sep., 10:31, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote:
> On 2008-09-04 07:49, Kay Schluehr wrote:
>
> > 3) Following the public rumor mill and the latest hype RIA i.e. the
> > merge of web- and desktop applications with systems like Adobe AIR,
> > JavaFX, Google Gears and MS Silverlight is the future of frontend
> > development. With the exception of IronPython and Silverlight, Python
> > hasn't even entered this game and no one knows if it ever will.
>
> Actually, it has already and quite some time ago:
>
> http://www.artima.com/weblogs/viewpost.jsp?thread=208528
>
> The recipe is simple: use Python for the business logic, database
> interfacing, etc and have it talk to a Flex front-end via XML-RPC
> or REST.

Python is still server-side in this scenario and plays no role in UI
definitions. So one doesn't get more than e.g. Django apps that
respond to HTTP requests triggered by JavaScript forms except that
JavaScript+HTML+Browser is replaced by Flex = AS3+MXML+FlashPlayer.
The role of Python is somewhat arbitrary. This could change only if
Python becomes a client side language executed by AVM, V8 etc. like
IronPython in Silverlight.

About separating UI from application logics by assigning functionality
to different general purpose languages I have to admit that I don't
think it is such a great idea ...
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to write verbose scripts

2008-09-04 Thread Steven D'Aprano
On Tue, 02 Sep 2008 13:07:33 -0400, Joe Riopel wrote:

> On Tue, Sep 2, 2008 at 12:55 PM, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
>> Is there a better way of doing this than the way I am going about it?
> 
> Would the logging module help, and just print the output to the stdout
> (or a file) instead?

Thank you to everyone who answered.

As I feared, it seems that there's no really simple way of dealing with 
arbitrary messages at arbitrary parts of my code.

I'm currently playing around with a few ideas, one of which is a 
decorator to print information about function calls. However, what I'd 
like to avoid is having to explicitly call the decorator on every method. 
I guess that there's metaclass trickery I can play. Does anyone have any 
pointers on how I can apply a decorator to every method in a class 
automatically?



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


Re: Numeric literal syntax

2008-09-04 Thread Alexander Schmolck
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Thu, 04 Sep 2008 01:22:22 +0100, Alexander Schmolck wrote:
>
>> It seems to me that the right choice for thousands seperator is the
>> apostrophe. 
>
> You mean the character already used as a string delimiter?

Yup. No ambiguity or problem here; indeed unlike space seperation or '_' it
would work straighforwardly as a syntax extension in pretty much any
programming language I can think as well as end-user output (I think that
writing e.g. 1'000'000 on a website would be perfectly acceptable; unlike
1_000_000).

'as

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


guenstige kredite

2008-09-04 Thread coolkid246
+
+
+
+
+++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA +++
+
+

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


guenstige kredite

2008-09-04 Thread coolkid246
+
+
+
+
+++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA +++
+
+
http://kredite-online-244.info

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


Re: Numeric literal syntax

2008-09-04 Thread Alexander Schmolck
[EMAIL PROTECTED] writes:

> A problem is that '1234' in Python is a string, so using ' in numbers
> looks a bit dangerous to me (and my editor will color those numbers as
> alternated strings, I think).

Yeah, editors, especially those with crummy syntax highlighting (like emacs)
might get it wrong. This should be easy enough to fix though. Indeed unlike
raw and tripplequoted strings which were adopted without major hitches this
new syntax wouldn't have any bearing on what's a valid string.

'as

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


overwrite set behavior

2008-09-04 Thread Michele Petrazzo

Hi all, I want to modify the method that set use for see if there is
already an object inside its obj-list. Something like this:

class foo: pass

bar1 = foo()
bar1.attr = 1

bar2 = foo()
bar2.attr = 1

set( (bar1, bar2), key=lambda o: o.attr)

and, of course, set has only one value.

It's possible?

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


Re: overwrite set behavior

2008-09-04 Thread Wojtek Walczak
On Thu, 04 Sep 2008 11:48:18 +0200, Michele Petrazzo wrote:
> Hi all, I want to modify the method that set use for see if there is
> already an object inside its obj-list. Something like this:
...
> It's possible?

As far as I understand you, you need descriptors:
http://users.rcn.com/python/download/Descriptor.htm


-- 
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
--
http://mail.python.org/mailman/listinfo/python-list


Re: overwrite set behavior

2008-09-04 Thread Marco Bizzarri
Ciao, Michele:

On Thu, Sep 4, 2008 at 11:48 AM, Michele Petrazzo
<[EMAIL PROTECTED]> wrote:
> Hi all, I want to modify the method that set use for see if there is
> already an object inside its obj-list. Something like this:
>
> class foo: pass
>
> bar1 = foo()
> bar1.attr = 1
>
> bar2 = foo()
> bar2.attr = 1
>
> set( (bar1, bar2), key=lambda o: o.attr)
>
> and, of course, set has only one value.
>
> It's possible?
>
> Thanks,
> Michele
> --
> http://mail.python.org/mailman/listinfo/python-list
>

looking at the source, maybe you could create a subclass of Set
redefining the __contains__ method?

Regards
Marco


-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: overwrite set behavior

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 11:58 AM, Wojtek Walczak <[EMAIL PROTECTED]> wrote:
> On Thu, 04 Sep 2008 11:48:18 +0200, Michele Petrazzo wrote:
>> Hi all, I want to modify the method that set use for see if there is
>> already an object inside its obj-list. Something like this:
> ...
>> It's possible?
>
> As far as I understand you, you need descriptors:
> http://users.rcn.com/python/download/Descriptor.htm
>

I know descriptors a litte, Wojtek, but didn't use them often; can you
elaborate a little more on your idea?

> --
> Regards,
> Wojtek Walczak,
> http://tosh.pl/gminick/
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Saluti
Marco
-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Issue warning if no "return" in function?

2008-09-04 Thread Poster28
What would you suggest to check python programs for non-syntax error.
One example I could think of that one might forget to "return" a value from
a function.

How could I check for these and maybe other mistakes?

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


online credit ohne in Landau sofortkredit kredit onl ine vergleich beamtendarlehen ohne schufa handy ohne schufa kredite ohne schufaauskunft kredit vergleich geld kredit ohn e schufa kredit aus der s

2008-09-04 Thread coolkid246
online credit ohne in Landau sofortkredit kredit online vergleich
beamtendarlehen ohne schufa handy ohne schufa kredite ohne
schufaauskunft kredit vergleich geld kredit ohne schufa kredit aus der
schweiz autofinanzierung ohne schufa kreditkarten ohne schufa
guenstiger kredit kredit online zusage kredite arbeitslose

+
+
+
+
+++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA +++
+
+
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
+
+
+
+






















kredite arbeitslose kredit ohne schufa fuer arbeitslose in Bad
Schwalbach
kredite finanzierung eilkredit in Bad Toelz
guenstiger kredit online kredite privat in Stadthagen
kredit ohne schufa ohne vorkosten online kredite guenstig in Borken
sofortkredit schufafrei kredit online beantragen in Bad
kredit ohne schufa fuer arbeitslose schufafreier kredit in Bernkastel
online sofort kredite www kredit ohne schufa in Meppen
kredite fuer arbeitslose ohne schufa online kredit test in Günzburg
sofort kredite online billig kredite in Werdau
arbeitslos kredite finanzierungen online in Bad Windsheim
kredit ohne schufa in kredit arbeitslos in Sigmaringen
kredite online vergleich banken kredit in Kleve
guenstiger kredit ohne schufa eil kredit ohne schufa in Prüm
guenstige kredite ohne schufa online kredit trotz schufa in Traunstein
kredit arbeitslose bonitaet online in Kronach
online kredit forum auch ohne schufa in Gießen
kredite ohne schufa auch fuer arbeitslose kredite ohne schufa auskunft
in Miesbach



- online sofort kredit ohne schufa billig kredit in Barnim
- kredite schufa www kredit ohne schufa in Erding
- sofortkredit online sofortkredit ohne schufa in Verden
- beamtenkredite clp kredit in Rendsburg
- kreditkarte online kredite online ohne schufa in Ulm
- online sofort kredit ohne credit ohne schufa in Aue
- postbank kredit online ohne kredit in Dachau
- kredit trotz negativer schufa kredit arbeitslose in Wesel
- guenstige online kredit online kredite mit sofortzusage in Saarlouis
- raten kredit ratenkredit ohne schufa in Coburg
- privat kredit ohne schufa kredit girokonto in Hoexter
- kredit von privat online kredite in in Neunkirchen
- mit krediten ohne schufa dispo kredit in Arnstadt
- online credit ohne schufa kredit sofort in Hanau







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


Re: Issue warning if no "return" in function?

2008-09-04 Thread Paul McGuire
On Sep 4, 5:05 am, Poster28 <[EMAIL PROTECTED]> wrote:
> What would you suggest to check python programs for non-syntax error.
> One example I could think of that one might forget to "return" a value from
> a function.
>
> How could I check for these and maybe other mistakes?

Check out PyLint (http://www.logilab.org/857) or PyChecker (http://
pychecker.sourceforge.net/).

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


sofort kredit online in Cochem geld kredite bank kre dite Guenstige Kredide online ohne SCHUFA kredit ohne schufa oesterreich beamtendarlehen ohne schufa schweizer kredit ba rkredit online umschuldun

2008-09-04 Thread coolkid246
sofort kredit online in Cochem geld kredite bank kredite Guenstige
Kredide online ohne SCHUFA kredit ohne schufa oesterreich
beamtendarlehen ohne schufa schweizer kredit barkredit online
umschuldung online blitzkredite schweizer kredit online kredite fuer
selbstaendige online kredit trotz bar kredit ohne schufa kredit ohne
schufa selbstaendig auto ohne schufa

+
+
+
+
+++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA +++
+
+
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
http://WWW.KREDITE-ONLINE-244.INFO/
+
+
+
+






















online kredit auch kredite fuer selbststaendige in Frankenberg
sofort kredit ohne schufa fuer kredite sicherheiten in Mittweida
online kredite in schweizer kredite in Lüchow
sofortkredit schufafrei kredit auch ohne schufa in Tuttlingen
www kredite ohne schufa kredit ohne schufa arbeitslose in Aurich
kredit uni postbank kredit online in Aalen
kredite selbstaendige onlinekredit in Ruppin
kredite online berechnen kredite banken in Sulzbach
kredit ohne schufa vergleich Guenstige Kredide online ohne SCHUFA in
Soltau
kredite zinsen kredit ohne schufa auskunft in Offenburg
online credit ohne schufa online kredite ohne schufa in Würzburg
kredit finanzierung onlinekredit in Lippe
kredit selbstaendige kredit arbeitslos in Starnberg
finanzierung online kredite privat in Halberstadt
kredite banken blitzkredite in Lippe
online kredit im schweizer kredit ohne schufa in Künzelsau
kredit ohne schufa selbstaendige kredit selbstaendige in Mühldorf
kredit auskunft dispo kredite in Siegen
kredite fuer arbeitslose ohne schufa online kredit trotz schufa in
Trier



- handyvertrag ohne schufa kredite online in Offenbach
- kredit arbeitslose internet kredit in Coburg
- klein kredit ohne schufa kredit von privat ohne schufa in
Lüdenscheid
- kleinkredite geld kredit in Steinburg
- www online kredite online credit ohne in Bad
- internetkredite kredit schweiz in Pforzheim
- raten kredit beamtenkredite in Siegburg
- kredite online beantragen online kredit ohne in Pasewalk
- kredit online zusage sofort kredit ohne schufa fuer in Heilbronn
- zinsen online online kredit ohne in Kirchheimbolanden
- kredite zinsen online kredit de in Sonneberg
- kredit girokonto bonitaet online in Loebau
- sofortkredit online kredit oesterreich in Schwarzenberg
- kredite privat kredit auch ohne schufa in Hoexter







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


Re: PyGUI as a standard GUI API for Python?

2008-09-04 Thread M.-A. Lemburg
On 2008-09-04 11:14, Kay Schluehr wrote:
> On 4 Sep., 10:31, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote:
>> On 2008-09-04 07:49, Kay Schluehr wrote:
>>
>>> 3) Following the public rumor mill and the latest hype RIA i.e. the
>>> merge of web- and desktop applications with systems like Adobe AIR,
>>> JavaFX, Google Gears and MS Silverlight is the future of frontend
>>> development. With the exception of IronPython and Silverlight, Python
>>> hasn't even entered this game and no one knows if it ever will.
>> Actually, it has already and quite some time ago:
>>
>> http://www.artima.com/weblogs/viewpost.jsp?thread=208528
>>
>> The recipe is simple: use Python for the business logic, database
>> interfacing, etc and have it talk to a Flex front-end via XML-RPC
>> or REST.
> 
> Python is still server-side in this scenario and plays no role in UI
> definitions.

That depends on how you design the application. It is well possible
to have Python drive the GUI by sending the required details to
the Flex front-end via XML (ie. data-driven GUIs).

> So one doesn't get more than e.g. Django apps that
> respond to HTTP requests triggered by JavaScript forms except that
> JavaScript+HTML+Browser is replaced by Flex = AS3+MXML+FlashPlayer.

You really can't compare the Flex stack to an AJAX stack. Flex
has a lot more to offer for GUI programming than AJAX, it also
doesn't suffer from the problems of AJAX having to support several
different sets of browser or library bugs.

We switched from an AJAX approach to a Flex-based approach last year
and never even considered moving back again.

> The role of Python is somewhat arbitrary. This could change only if
> Python becomes a client side language executed by AVM, V8 etc. like
> IronPython in Silverlight.
>
> About separating UI from application logics by assigning functionality
> to different general purpose languages I have to admit that I don't
> think it is such a great idea ...

In my experience, Flex + Python gives you the best of both worlds,
the nice GUI features of Flex and the efficiency of Python for the
business logic.

A long time ago, there was a Python plugin for Netscape
which allowed you to run Python straight in the browser. Perhaps
it's time to revive such an idea... but then you're still missing
out on the GUI part, since you're still stuck with what the
browser has to offer in terms of widget support.

-- 
Marc-Andre Lemburg
eGenix.com

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


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


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


Re: Issue warning if no "return" in function?

2008-09-04 Thread Wojtek Walczak
On Thu, 04 Sep 2008 12:05:45 +0200, Poster28 wrote:
> What would you suggest to check python programs for non-syntax error.
> One example I could think of that one might forget to "return" a value from
> a function.
>
> How could I check for these and maybe other mistakes?

Check pychecker or figleaf:
http://pychecker.sourceforge.net
http://darcs.idyll.org/~t/projects/figleaf/doc/

-- 
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Serial I/O problem with pywin32 ?

2008-09-04 Thread Impotent Verse
On 3 Sep, 16:33, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Xavier schrieb:
>
>
>
> > Hi,
>
> > I try to access to a Bluetooth GPS data-logger with Python. I use
> > pySerial.
>
> > Sending and receiving little messages (~100 char) works fine. However,
> > when I ask the GPS to dump the trails, it returns some Mbytes and here
> > is the problem : in the stream of bytes, I randomly losts chunks of
> > ~100bytes.
>
> > I tried USPP and pyBlueZ instead of pySerial : same problem.
>
> > It doesn't like it is a bufferoverun bug from me because :
> >  - the GPS seems to wait when I do not read the stream,
> >  - there is never more than 200 inWainting() characters,
> >  - my code to test it is quite simple :
>
> >   seriallink = serial.Serial("COM40")
> >   fileName = "data.dump"
> >   out = open(fileName, 'w')
> >   while 1:
> >     c = seriallink.read()
> >     out.write(" %0.2X" % ord(c))
> >     print "*",
> >   out.close()
>
> > (with pyBluez :
> > sock=BluetoothSocket( RFCOMM )
> > sock.connect(("00:0A:...", 1)))
>
> > I tried my program on two different PC with two Bluetooth dongle,
> > (with pySerial, USPP, pyBluez).
> > The same things are :
> >  - windows
> >  - the GPS (which works fine with the dumper program of the
> > constructor)
> >  - pyWin32
>
> > I've found another guy with a similar problem :
> >http://www.generation-nt.com/reponses/rs232-entraide-142097.html
> > He says:
> >  - no problem with little messages
> >  - lost of one byte every hour when receiving a lot of data
>
> > Any known problems with pywin32 and serial I/O when downloading a big
> > stream of data ?
>
>  From my experience with serial lines I'd say: that's the culprit. They
> tend to be rather unreliable, as there is no real protocol ensuring data
> integrity.
>
> You might consider downloading chunks of data if that's somehow
> possible, and re-try failed chunks.
>
> Diez

Could be hardware flow control. See this sometimes on the bluetooth
connections that are using Serial Port Protocol and the hardware flow
control hasn't been physically implemented.

Do you lose data after exactly the same amount of data has been
received?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from .NET and VB and C

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 12:16 AM, Dennis Lee Bieber
<[EMAIL PROTECTED]> wrote:
> On Wed, 3 Sep 2008 09:52:06 -0700 (PDT), ToPostMustJoinGroup22
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
>
>> have no preference with MySQL or SQL, stored procedures or ad-hoc
>> queries.
>>
>Please note: MySQL is specific relational database management system
> (RDBMs), which uses a dialect of structured query language (SQL). SQL by
> itself is just a semi-standardized query language -- and can technically
> be used to access non-relational DBMS (if any such are still in use),
> though the query processor would be a pain to program (map a relational
> join into a hierarchical DBMS schema? ugh).
>
>> SO, I'm interested in using my Google App space (free 500MB) to
>> develop a quick database application.  Using Python.  I found "Dive
>> Into Python" which I will be reading shortly.
>>
>So one question: what RDBMs are supported in that space?

The appearance is not an RDBMS, at least, maybe it is, but under the surface.

Looks more that you've persistent objects with a SQL-like language to
query them.

Regards
Marco


-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: max(), sum(), next()

2008-09-04 Thread Thomas Bellman
Mensanator <[EMAIL PROTECTED]> wrote:

> No, but blank cells are 0 as far as Excel is concerned.
> That behaviour causes nothing but trouble and I am
> saddened to see Python emulate such nonsense.

Then you should feel glad that the Python sum() function *does*
signal an error for the closest equivalent of "blank cells" in
a list:

>>> sum([1, 2, 3, None, 5, 6])
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Summing the elements of an empty list is *not* the same thing as
summing elements of a list where one element is None.


> There are no "empty" boxes. There are only boxes with
> known quantities and those with unknown quantities.
> I hope that's not too ivory tower.

The sum() function in Python requires exactly one box.  That box
can be empty, can contain "known quantities" (numbers, presumably),
or "unknown quantities" (non-numbers, e.g., None).  But you can't
give it zero boxes, or three boxes.


I don't have a strong view of whether sum([]) should return 0 or
raise an error, but please do not mix that question up with what
a sum over empty cells or over NULL values should yield.  They
are very different questions.

As it happens, the SQL sum() function (at least in MySQL; I don't
have any other database easily available, nor any SQL standard to
read) does return NULL for a sum over the empty sequence, so you
could argue that that would be the correct behaviour for the
Python sum() function as well, but you can't argue that because a
sum *involving* a NULL value returns NULL.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"This isn't right.  This isn't even wrong."  !  bellman @ lysator.liu.se
 -- Wolfgang Pauli   !  Make Love -- Nicht Wahr!
--
http://mail.python.org/mailman/listinfo/python-list

cPickle

2008-09-04 Thread gopal mishra
I have 3 objects and want to save in one pickle file. 

I used cPickle to dump 3 objects in a pkl file 

i.e  cPickle.dump(object1, fileobject,  -1) 

 cPickle.dump(object2, fileobject,  -1)

 cPickle.dump(object3, fileobject,  -1)

 

I have changed the 3rd object and  want to save the updated 3rd object in
the pickle file. 

I have to dump all the 3 objects again.

 

Is there any way to dump only the 3rd object in to the pkl file.

 

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

Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Marco Bizzarri
Let's say I've a class a, where I can write:



-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyGUI as a standard GUI API for Python?

2008-09-04 Thread Banibrata Dutta
On Thu, Sep 4, 2008 at 3:45 PM, M.-A. Lemburg <[EMAIL PROTECTED]> wrote:

> On 2008-09-04 11:14, Kay Schluehr wrote:
> > On 4 Sep., 10:31, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote:
> >> On 2008-09-04 07:49, Kay Schluehr wrote:
> >>
> >>> 3) Following the public rumor mill and the latest hype RIA i.e. the
> >>> merge of web- and desktop applications with systems like Adobe AIR,
> >>> JavaFX, Google Gears and MS Silverlight is the future of frontend
> >>> development. With the exception of IronPython and Silverlight, Python
> >>> hasn't even entered this game and no one knows if it ever will.
> >> Actually, it has already and quite some time ago:
> >>
> >> http://www.artima.com/weblogs/viewpost.jsp?thread=208528
> >>
> >> The recipe is simple: use Python for the business logic, database
> >> interfacing, etc and have it talk to a Flex front-end via XML-RPC
> >> or REST.
> >
> > Python is still server-side in this scenario and plays no role in UI
> > definitions.
>
> That depends on how you design the application. It is well possible
> to have Python drive the GUI by sending the required details to
> the Flex front-end via XML (ie. data-driven GUIs).
>
> > So one doesn't get more than e.g. Django apps that
> > respond to HTTP requests triggered by JavaScript forms except that
> > JavaScript+HTML+Browser is replaced by Flex = AS3+MXML+FlashPlayer.
>
> You really can't compare the Flex stack to an AJAX stack. Flex
> has a lot more to offer for GUI programming than AJAX, it also
> doesn't suffer from the problems of AJAX having to support several
> different sets of browser or library bugs.
>
> We switched from an AJAX approach to a Flex-based approach last year
> and never even considered moving back again.


The approach does seem quite impressive, but isn't Flex's platform
neutrality quite over-rated ? I mean after-all, it assumes that Flex is
available for and available on the platform. Flex today is not yet so
ubiquitous as the JRE...

Are there some established best-practices on how to package such
applications -- s.a. shipping with its's own Flex runtime, offer-download if
missing etc. ? What happens if owner of target machine decides to upgrade
their version of Flex, will it impact the application package in anyway, and
render rest of it "non-upgradable" ?

>
>
> > The role of Python is somewhat arbitrary. This could change only if
> > Python becomes a client side language executed by AVM, V8 etc. like
> > IronPython in Silverlight.
> >
> > About separating UI from application logics by assigning functionality
> > to different general purpose languages I have to admit that I don't
> > think it is such a great idea ...
>
> In my experience, Flex + Python gives you the best of both worlds,
> the nice GUI features of Flex and the efficiency of Python for the
> business logic.
>
> A long time ago, there was a Python plugin for Netscape
> which allowed you to run Python straight in the browser. Perhaps
> it's time to revive such an idea... but then you're still missing
> out on the GUI part, since you're still stuck with what the
> browser has to offer in terms of widget support.
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Source  (#1, Sep 04 2008)
> >>> Python/Zope Consulting and Support ...http://www.egenix.com/
> >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
> >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
> 
>
>  Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 
>
>
>   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>   Registered at Amtsgericht Duesseldorf: HRB 46611
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Diez B. Roggisch
Marco Bizzarri wrote:

> Let's say I've a class a, where I can write:

Anticipating this obviously premature posting:

http://dirtsimple.org/2004/12/python-is-not-java.html

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


Re: cPickle

2008-09-04 Thread Gerhard Häring

gopal mishra wrote:

I have 3 objects and want to save in one pickle file.

I used cPickle to dump 3 objects in a pkl file

i.e  cPickle.dump(object1, fileobject,  -1)

 cPickle.dump(object2, fileobject,  -1)

 cPickle.dump(object3, fileobject,  -1)

 

I have changed the 3^rd object and  want to save the updated 3^rd object 
in the pickle file.


I have to dump all the 3 objects again.

Is there any way to dump only the 3^rd object in to the pkl file.


No, there isn't. You could, of course, save each object in its own 
pickle file. Or use an object database like ZODB instead.


-- Gerhard

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


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 1:00 PM, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> Marco Bizzarri wrote:
>
>> Let's say I've a class a, where I can write:
>
> Anticipating this obviously premature posting:
>
> http://dirtsimple.org/2004/12/python-is-not-java.html
>
> Diez
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Ehi, Diez, that was fast :-) !

Thanks for the link, I saw it in the past days and I read it; and I
appreciated it a lot  (actually, it was a door to a new world in
Python, for me). But I'm asking something I feel is a little
different, as you can read in my message, once it is full.

Regards
Marco

-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Marco Bizzarri
Sorry... pressed enter but really didn't want to.

As I said, let's say I have a class

class A:
def __init__(self):
 self.x = None



Python makes the decision to allow the developers to directly access
the attribute "x",  so that they can directly write: "a.x = 1", or
whatever; this has for me the unfortunate side effect that if I write,
for example "a.y = 1", when I really wanted to write "a.x = 1" no one
cares about it, and I'm unable to spot this error until later.

Of course, I know that while I'm fresh, I've a good knowledge of the
code, and anything else, I will be able to avoid such stupid errors;
however, I'm afraid of the times when I'm tired, when I have to put my
hands on the code of someone else, and so on.

Please, understand that I'm not stating that python is wrong... after
all, if it is wrong, I can move to a language like Java, which has a
different approach on it. I'm really very interested in reading past
discussion on it, if they are available.

Regards
Marco



On Thu, Sep 4, 2008 at 12:57 PM, Marco Bizzarri
<[EMAIL PROTECTED]> wrote:
> Let's say I've a class a, where I can write:
>
>
>
> --
> Marco Bizzarri
> http://notenotturne.blogspot.com/
> http://iliveinpisa.blogspot.com/
>



-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: overwrite set behavior

2008-09-04 Thread Diez B. Roggisch
Michele Petrazzo wrote:

> Hi all, I want to modify the method that set use for see if there is
> already an object inside its obj-list. Something like this:
> 
> class foo: pass
> 
> bar1 = foo()
> bar1.attr = 1
> 
> bar2 = foo()
> bar2.attr = 1
> 
> set( (bar1, bar2), key=lambda o: o.attr)
> 
> and, of course, set has only one value.
> 
> It's possible?

Using a decorator/delegate-pattern, yes:

class Foo(object):

   def __init__(self, delegate):
   self.delegate = delegate

   def __hash__(self):
   return hash(self.delegate.attr)

   def __cmp__(self, other):
   return cmp(self.delegate.attr, other.delegate.attr)


set(Foo(a) for a in bar1, bar2)

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


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Diez B. Roggisch
> Of course, I know that while I'm fresh, I've a good knowledge of the
> code, and anything else, I will be able to avoid such stupid errors;
> however, I'm afraid of the times when I'm tired, when I have to put my
> hands on the code of someone else, and so on.
> 
> Please, understand that I'm not stating that python is wrong... after
> all, if it is wrong, I can move to a language like Java, which has a
> different approach on it. I'm really very interested in reading past
> discussion on it, if they are available.

This has not much to do with the question of setters and getters. Because in
your code you could write

def setX(self, x):
self.y = x

def getX(self):
return self.x

So the error occurs in the same way.

What you are essentially asking is: why is python dynamic instead of static? 

Because *that* is what is the difference. In a static language, you need to
declare first what you want to be available, e.g. which variables and
methods are available and such.

Of course then the compiler (or whoever evaluates the static declarations)
can puke on you if you attempt a stunt like the one you describe.

Python (and other languages such as Ruby, Javascript) chose other. They give
you the freedom to add instance variables (or even methods) at will, with
the cost of the occasional error like the above.

OTOH, Java makes me write s much more code that me becoming tired and
doing some stupid mistake (and there are lots of them doable in static
languages as well, otherwise no C/C++ or Java-program would crash)
becomes much more likelyYMMV.

Diez


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


Re: Coming from .NET and VB and C

2008-09-04 Thread Bruno Desthuilliers

Marco Bizzarri a écrit :

On Thu, Sep 4, 2008 at 12:16 AM, Dennis Lee Bieber
<[EMAIL PROTECTED]> wrote:

On Wed, 3 Sep 2008 09:52:06 -0700 (PDT), ToPostMustJoinGroup22
<[EMAIL PROTECTED]> declaimed the following in
comp.lang.python:


have no preference with MySQL or SQL, stored procedures or ad-hoc
queries.


   Please note: MySQL is specific relational database management system
(RDBMs), which uses a dialect of structured query language (SQL). SQL by
itself is just a semi-standardized query language -- and can technically
be used to access non-relational DBMS (if any such are still in use),
though the query processor would be a pain to program (map a relational
join into a hierarchical DBMS schema? ugh).


SO, I'm interested in using my Google App space (free 500MB) to
develop a quick database application.  Using Python.  I found "Dive
Into Python" which I will be reading shortly.


   So one question: what RDBMs are supported in that space?


The appearance is not an RDBMS, at least, maybe it is, but under the surface.


Not AFAIK, cf:
http://en.wikipedia.org/wiki/BigTable

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


Safely move an element into a heap

2008-09-04 Thread Giampaolo Rodola'
Hi,
I wanted to know if does exist a safe way to, given a heap, move an
arbitrary element to the first position of the heap.
Something like:

 >>> heap = [0,3,6,8,10]
 >>> heapq.move_to_first_position(heap, 4)
 >>> heap = [10, 0,3,6,8]


--- Giampaolo
http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from .NET and VB and C

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 1:23 PM, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
>>
>> The appearance is not an RDBMS, at least, maybe it is, but under the
>> surface.
>
> Not AFAIK, cf:
> http://en.wikipedia.org/wiki/BigTable
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thanks for the pointer, Bruno... I wrote from my memory, but there is
some bank of it which need quick replace ;)


-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Safely move an element into a heap

2008-09-04 Thread Alexandru Palade
I'm not sure what you expect as an answer, but if you mean the heap as 
in the data structure, you can not just arbitrarily move one key where 
you want as it will destroy the heap property.



Giampaolo Rodola' wrote:

Hi,
I wanted to know if does exist a safe way to, given a heap, move an
arbitrary element to the first position of the heap.
Something like:

 >>> heap = [0,3,6,8,10]
 >>> heapq.move_to_first_position(heap, 4)
 >>> heap = [10, 0,3,6,8]


--- Giampaolo
http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list

  

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


Re: cPickle

2008-09-04 Thread Maric Michaud
Le Thursday 04 September 2008 13:08:59 Gerhard Häring, vous avez écrit :
> gopal mishra wrote:
> > I have 3 objects and want to save in one pickle file.
> >
> > I used cPickle to dump 3 objects in a pkl file
> >
> > i.e  cPickle.dump(object1, fileobject,  -1)
> >
> >  cPickle.dump(object2, fileobject,  -1)
> >
> >  cPickle.dump(object3, fileobject,  -1)
> >
> >
> >
> > I have changed the 3^rd object and  want to save the updated 3^rd object
> > in the pickle file.
> >
> > I have to dump all the 3 objects again.
> >
> > Is there any way to dump only the 3^rd object in to the pkl file.
>
> No, there isn't. You could, of course, save each object in its own
> pickle file. Or use an object database like ZODB instead.
>

Shelve is another alternative, shipped with python and rather straightforward. 
Shelve as ZODB use pickles of objects but, unlike ZODB, won't need you change 
anything  to your actual classes.

>>>[8]: import shelve

>>>[9]: s = shelve.open('db')

>>>[10]: a, b, c = 5, 4., ("foo", "bar")

>>>[11]: s['a'], s['b'], s['c'] = a, b, c

>>>[12]: s.close()

>>>[13]:
[EMAIL PROTECTED] 13:46:42:~$ file db
db: Berkeley DB (Hash, version 8, native byte-order)
[EMAIL PROTECTED] 13:46:44:~$ ipython

>>>[1]: import shelve

>>>[2]: s = shelve.open('db')

>>>[3]: for name, value in s.items() : print name, value
   ...:
b 4.0
a 5
c ('foo', 'bar')

>>>[5]: del s['b']

>>>[6]: s['c'] += ('baz',)

>>>[7]: s.sync()

>>>[8]:
[EMAIL PROTECTED] 13:48:12:~$ ipython

>>>[1]: import shelve

>>>[2]: s = shelve.open('db')

>>>[3]: for name, value in s.items() : print name, value
   ...:
a 5
c ('foo', 'bar', 'baz')

The sync method may not work on all platform, maybe you'll have to close and 
re-open the db file to write to disk.

-- 
_

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


Re: Safely move an element into a heap

2008-09-04 Thread Giampaolo Rodola'
On 4 Set, 13:49, Alexandru Palade <[EMAIL PROTECTED]>
wrote:
> I'm not sure what you expect as an answer, but if you mean the heap as
> in the data structure, you can not just arbitrarily move one key where
> you want as it will destroy the heap property.
>
>
>
> Giampaolo Rodola' wrote:
> > Hi,
> > I wanted to know if does exist a safe way to, given a heap, move an
> > arbitrary element to the first position of the heap.
> > Something like:
>
> >  >>> heap = [0,3,6,8,10]
> >  >>> heapq.move_to_first_position(heap, 4)
> >  >>> heap = [10, 0,3,6,8]
>
> > --- Giampaolo
> >http://code.google.com/p/pyftpdlib/
> > --
> >http://mail.python.org/mailman/listinfo/python-list- Nascondi testo citato
>
> - Mostra testo citato -

Could I be able to do that if every element I want to move will have
the value of 0 which is the smallest value I can have into my heap?
What I'm trying to do is implementing a timeout: sometimes I want a
given event which was scheduled to happen within X seconds to happen
immediately.


--- Giampaolo
http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list


help in execfile function

2008-09-04 Thread moijes12
Hi

i have 3 python files and i want to execute the files sequentially
using the execfile command.Hence ,i have written the following program


fileList = ["a.py","b.py","c.py"]

for fileName in fileList  :
execfile(fileName)

however,when i try running it,the program keeps calling execfile on
a.py and thus an infinite loop is created.I am running this on Windows
XP.

Please suggest a sloution whereby i can use execfile to execute all
files in fileList.Please tell me where in my program i may have gone
wrong.

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


Re: use str as variable name

2008-09-04 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>Mathieu Prevot a écrit :
>> 2008/9/4 Chris Rebert <[EMAIL PROTECTED]>:
>
>(snip)
>
>>> You're looking for the setattr() built-in function. In this exact case:
>>>setattr(a, arg, new_value)
>>>
>>> This is probably covered in the Python tutorial, please read it.
>>>
>>> Regards,
>>> Chris
>> 
>> Indeed.
>> 
>> I'll use:
>> a.__setattr__(height, new_value)
>
>Please don't. Use the generic setattr() function instead. This holds for 
>any __magic__ method : they are *implementation* for operators and 
>generic functions  - which you can think of as operators with a function 
>syntax -, and are not meant to be called directly. You wouldn't write 
>something like 2.__add__(3), would you ?
>

Along with the good advice the usual suspects have given,
my intuition is that there's an even better implementation
that doesn't setattr() at all.  While it's impossible to
know, of course, because we don't have the original poster's
true requirements, I conjecture that, rather than "to link
this [user-supplied] word to a class variable", what will
serve him best is to regard the user text as an index into
a class dictionary.
--
http://mail.python.org/mailman/listinfo/python-list

Re: help in execfile function

2008-09-04 Thread Steven D'Aprano
On Thu, 04 Sep 2008 05:03:57 -0700, moijes12 wrote:

> Hi
> 
> i have 3 python files and i want to execute the files sequentially using
> the execfile command.Hence ,i have written the following program
> 
> 
> fileList = ["a.py","b.py","c.py"]
> 
> for fileName in fileList  :
> execfile(fileName)
> 
> however,when i try running it,the program keeps calling execfile on a.py
> and thus an infinite loop is created.I am running this on Windows XP.

Change the line "execfile(fileName)" to "print fileName" and you may 
discover that the problem isn't with execfile but with your code.

Then read about modules and import, and you may discover that there is a 
better way than execfile.


(I wish that eval, exec and execfile were hidden in a module where noobs 
couldn't trip over them and decide they are the answer to every problem. 
Sigh.)


> Please suggest a sloution whereby i can use execfile to execute all
> files in fileList.Please tell me where in my program i may have gone
> wrong.

Looking into my crystal ball, I'm guessing that file a.py contains a line 
that says "execfile('a.py')".

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


Re: overwrite set behavior

2008-09-04 Thread Michele Petrazzo

Marco Bizzarri wrote:

looking at the source, maybe you could create a subclass of Set
redefining the __contains__ method?



Made some tries, but __contains__ are never called

>>> class foo(set):
...  def __contains__(self, value):
...   print value
...
>>> a = foo((1,2))
>>>

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


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Bruno Desthuilliers

Marco Bizzarri a écrit :

Sorry... pressed enter but really didn't want to.

As I said, let's say I have a class

class A:
def __init__(self):
 self.x = None



Python makes the decision to allow the developers to directly access
the attribute "x",


So do Java, if you make your attribute public (which would be a big 
error given Java's lack of support for computed attribute, but this is 
another problem).



 so that they can directly write: "a.x = 1", or
whatever; this has for me the unfortunate side effect that if I write,
for example "a.y = 1", when I really wanted to write "a.x = 1" no one
cares about it,


I assume *you* do !-)

But this is barely related to having explicit setters or not - it comes 
from the fact that the default[1] Python's object behaviour is to 
support arbitrary attribute setting.


[1] some objects don't, but this is mostly for optimization reasons.


and I'm unable to spot this error until later.


Not sure, but IIRC tools like pylint or pychecker might be able to warn 
you about this. But anyway :



Of course, I know that while I'm fresh, I've a good knowledge of the
code, and anything else, I will be able to avoid such stupid errors;
however, I'm afraid of the times when I'm tired, when I have to put my
hands on the code of someone else, and so on.


The edit/test cycle in Python is usually fast enough so you should spot 
the problem *pretty* quickly. This is at least what I learned from 8+ 
years of python (and a couple other dynamic languages) programming...


Not to say that problems like the one you mention (or similar problems 
with dynamic typing etc) never happens, nor that they're never painful 
to track down and fix - just that they happen way less often than one 
might fear, and are most of the time really quickly spotted and fixed.



Please, understand that I'm not stating that python is wrong... after
all, if it is wrong, I can move to a language like Java, which has a
different approach on it.


I don't think it's a matter of "right" or "wrong" - mostly a matter of 
tradeoffs and balance. But if you go for static typing and (allegedly) 
provable correctness, you may want to have a look at languages like OCaml.



I'm really very interested in reading past
discussion on it, if they are available.


Well... Most of these "discussions" alas boil down to bondage&discipline 
proponants asserting - against all evidences - that dynamic languages 
are unsafe and unusable for anything else than simple throw-away scripts 
or toy projects, and dynamic proponants arguing - against all evidences 
- that static typing and everything related is just a waste of time 
(FWIW, you might find myself in the first camp until approx year 2k and 
the second for the five or six following years). And sometimes, someone 
a bit more sensible trying to take a more balanced approach to the 
problem, usually to no avail.

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


[ANN] The Python Papers, Volume 3 Issue 2

2008-09-04 Thread [EMAIL PROTECTED]
Hi everyone

After a long wait of nearly 5 month, we are back in business to bring
the latest edition of The Python Papers - Volume 3 Issue 2 (http://
ojs.pythonpapers.org/index.php/tpp/issue/current).

>From this issue onwards, we will be having only 3 issues per year
instead of 4. This is in compliance with our ISSN registration.

What's new
=
1. We have expanded our editorial team with 2 new Associate Editors,
Sarah Mount (from UK) and Guy Kloss from (New Zealand).

2. TPP is now managed using Open Journal System and it can be assessed
at http://ojs.pythonpapers.org/tpp

3. Backporting of previous issues of TPP from Volume 1 Issue 1 is
complete

4. We had "soft-launched" TWO new periodicals - The Python Papers
Monographs (for monograph-length submissions which may include
dissertations, conference proceedings, case studies and advanced-level
lectures) and The Python Papers Source Codes (modeled after ACM
Collected Algorithms and provides a collection of software and source
codes, usually associated with papers published in The Python Papers
and The Python Papers Monograph). They shall be TPPM and TPPSC
respectively.

5. Collectively, TPP, TPPM and TPPSC will be umbrella-ed as The Python
Papers Anthology (TPPA) and managed under the same editorial
committee.

6. Probably the most important development to TPP is that TPP is
currently indexed by a number of services, including Google Scholar
and OAIster, as a result of using Open Journal System.

So, please enjoy our latest edition and we look towards all of your
continued support and contributions.

Thank you.

Cheers
Maurice Ling
Co-Editor-in-Chief, The Python Papers Anthology
--
http://mail.python.org/mailman/listinfo/python-list


Re: use str as variable name

2008-09-04 Thread Mathieu Prevot
2008/9/4 Fredrik Lundh <[EMAIL PROTECTED]>:
> Bruno Desthuilliers wrote:
>
>> You wouldn't write something like 2.__add__(3), would you ?
>
> Don't give the "it's only OO if I write obj.method(args)" crowd more bad
> ideas, please ;-)
>
> (...as Bruno implies, setattr(), len() et al can be and should be viewed as
> generic functions.  A specific Python implementation may use custom code to
> implement behaviour for a given object; behaviour that's more efficient than
> a full Python-level method call.  For example, in CPython, len(L) is about
> twice as fast as L.__len__() for built-in sequences.)

Got it. Thanks :)
Mathieu
--
http://mail.python.org/mailman/listinfo/python-list


Re: overwrite set behavior

2008-09-04 Thread Maric Michaud
Le Thursday 04 September 2008 14:31:23 Michele Petrazzo, vous avez écrit :
> Marco Bizzarri wrote:
> > looking at the source, maybe you could create a subclass of Set
> > redefining the __contains__ method?
>
> Made some tries, but __contains__ are never called
>

No, __contains__ is only called  with "in" operator, not for internal hashing. 
Anyway this solution is bad, you'll need to compare the new element with all 
the set contain, which would result in a O(n) algorithm for adding elements 
to the set in place of the O(1) it use.

The right way to go is one like Diez show you in a previous post.

>  >>> class foo(set):
> ...  def __contains__(self, value):
> ...   print value
> ...
>  >>> a = foo((1,2))
>  >>>



-- 
_

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


Re: The Python Papers, Volume 3 Issue 2

2008-09-04 Thread Samir
On Sep 4, 8:58 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi everyone
>
> After a long wait of nearly 5 month, we are back in business to bring
> the latest edition of The Python Papers - Volume 3 Issue 2 (http://
> ojs.pythonpapers.org/index.php/tpp/issue/current).
>
> From this issue onwards, we will be having only 3 issues per year
> instead of 4. This is in compliance with our ISSN registration.
>
> What's new
> =
> 1. We have expanded our editorial team with 2 new Associate Editors,
> Sarah Mount (from UK) and Guy Kloss from (New Zealand).
>
> 2. TPP is now managed using Open Journal System and it can be assessed
> athttp://ojs.pythonpapers.org/tpp
>
> 3. Backporting of previous issues of TPP from Volume 1 Issue 1 is
> complete
>
> 4. We had "soft-launched" TWO new periodicals - The Python Papers
> Monographs (for monograph-length submissions which may include
> dissertations, conference proceedings, case studies and advanced-level
> lectures) and The Python Papers Source Codes (modeled after ACM
> Collected Algorithms and provides a collection of software and source
> codes, usually associated with papers published in The Python Papers
> and The Python Papers Monograph). They shall be TPPM and TPPSC
> respectively.
>
> 5. Collectively, TPP, TPPM and TPPSC will be umbrella-ed as The Python
> Papers Anthology (TPPA) and managed under the same editorial
> committee.
>
> 6. Probably the most important development to TPP is that TPP is
> currently indexed by a number of services, including Google Scholar
> and OAIster, as a result of using Open Journal System.
>
> So, please enjoy our latest edition and we look towards all of your
> continued support and contributions.
>
> Thank you.
>
> Cheers
> Maurice Ling
> Co-Editor-in-Chief, The Python Papers Anthology

Good to see that the newest edition of the journal is out.  Also, I
believe the correct URL should either be:
http://ojs.pythonpapers.org/
or
http://ojs.pythonpapers.org/index.php/tpp

Thanks for providing this great resource.

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


Re: How to write verbose scripts

2008-09-04 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Tue, 02 Sep 2008 13:07:33 -0400, Joe Riopel wrote:
> 
> > On Tue, Sep 2, 2008 at 12:55 PM, Steven D'Aprano
> > <[EMAIL PROTECTED]> wrote:
> >> Is there a better way of doing this than the way I am going about it?
> > 
> > Would the logging module help, and just print the output to the stdout
> > (or a file) instead?
> 
> Thank you to everyone who answered.
> 
> As I feared, it seems that there's no really simple way of dealing with 
> arbitrary messages at arbitrary parts of my code.

I would think the 'logging' module *is* the simple way to do this. At
least, it's as simple as it could be without leading to massive
re-visiting of the "arbitrary parts of one's code" when later desiring
to change the way the messages are handled.

-- 
 \ “We must become the change we want to see.” —Mahatma Gandhi |
  `\   |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Assalamu'alaikum wr. wb.

2008-09-04 Thread Abdurrahman Wahid
Assalamu'alaikum wr. wb.,

Faith Freedom Indonesia (http://www.indonesia.faithfreedom.org/forum/)
The Amazing Racist: Moslem Mosque (http://13gb.com/videos/923/)
Forum Murtadin Indonesia (http://mantanmuslim.blogspot.com/)

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


Xpath for HTML processing

2008-09-04 Thread Astley Le Jasper
Can anyone suggest something inthat can process an XPath like the
following:

"/html/body/table[2]/tbody/tr/td[5]/table/tbody/tr[3]/td/table[3]/
tbody/tr[5]/td"

Cheers

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


path slashes cleaning

2008-09-04 Thread Mathieu Prevot
Hi,

for scripts that take arguments, I would like to remove the trailing
slash if it's present.

Is there something else than:

a='/usr/local/lib/'
if a[-1] == '/':
  a = list(a)
  a.pop()
  ''.join(a)

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


Re: path slashes cleaning

2008-09-04 Thread Mike Driscoll
On Sep 4, 8:25 am, "Mathieu Prevot" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> for scripts that take arguments, I would like to remove the trailing
> slash if it's present.
>
> Is there something else than:
>
> a='/usr/local/lib/'
> if a[-1] == '/':
>   a = list(a)
>   a.pop()
>   ''.join(a)
>
> Thanks,
> Mathieu

How about this:

if a[-1] == '/':
a = a[:-1]

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


Re: path slashes cleaning

2008-09-04 Thread Mathieu Prevot
2008/9/4 Mathieu Prevot <[EMAIL PROTECTED]>:
> Hi,
>
> for scripts that take arguments, I would like to remove the trailing
> slash if it's present.
>
> Is there something else than:
>
> a='/usr/local/lib/'
> if a[-1] == '/':
>  a = list(a)
>  a.pop()
>  ''.join(a)

A dummy

a.rstrip('/')

Sorry for the noise
Mathieu
--
http://mail.python.org/mailman/listinfo/python-list


Re: path slashes cleaning

2008-09-04 Thread Francesco Guerrieri
On Thu, Sep 4, 2008 at 3:25 PM, Mathieu Prevot <[EMAIL PROTECTED]> wrote:
> Hi,
>
> for scripts that take arguments, I would like to remove the trailing
> slash if it's present.
>
> Is there something else than:
>
> a='/usr/local/lib/'
> if a[-1] == '/':
>  a = list(a)
>  a.pop()
>  ''.join(a)
>
> Thanks,
> Mathieu

a.rstrip('/') does the job.

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


Re: Access to Windows "Add/Remove Programs"?

2008-09-04 Thread Mike Driscoll
On Sep 3, 9:41 pm, Sean DiZazzo <[EMAIL PROTECTED]> wrote:
> On Sep 3, 7:13 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>
>
>
> > En Wed, 03 Sep 2008 21:51:59 -0300, Sean DiZazzo <[EMAIL PROTECTED]>  
> > escribi :
>
> > > I'm trying to find a way to get a list of all the installed programs
> > > on a Windows box via Python.  I thought of a few hacks that might
> > > partially work, and then thought about "Add/Remove Programs"  Seems
> > > like the right way to go.  I looked over the pywin32 docs a bit, but
> > > nothing slapped me in the face.
>
> > > Is there any reliable way to get at that info?
>
> > You may enumerate the entries under this registry key:
> > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
>
> > --
> > Gabriel Genellina
>
> Thank both of you.  Perfect!
>
> ~Sean

I have used both of these methods, but it should be noted that not all
programs register themselves in the registry. The usual suspects are
spyware related. But there are still a few programs that you can just
download and unzip that don't write anything to the registry.

But this does work for probably 99% of programs on Windows.

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


Re: PyGUI as a standard GUI API for Python?

2008-09-04 Thread M.-A. Lemburg
On 2008-09-04 12:57, Banibrata Dutta wrote:
> On Thu, Sep 4, 2008 at 3:45 PM, M.-A. Lemburg <[EMAIL PROTECTED]> wrote:
> 
>> On 2008-09-04 11:14, Kay Schluehr wrote:
>>> On 4 Sep., 10:31, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote:
 On 2008-09-04 07:49, Kay Schluehr wrote:

> 3) Following the public rumor mill and the latest hype RIA i.e. the
> merge of web- and desktop applications with systems like Adobe AIR,
> JavaFX, Google Gears and MS Silverlight is the future of frontend
> development. With the exception of IronPython and Silverlight, Python
> hasn't even entered this game and no one knows if it ever will.
 Actually, it has already and quite some time ago:

 http://www.artima.com/weblogs/viewpost.jsp?thread=208528

 The recipe is simple: use Python for the business logic, database
 interfacing, etc and have it talk to a Flex front-end via XML-RPC
 or REST.
>>> Python is still server-side in this scenario and plays no role in UI
>>> definitions.
>> That depends on how you design the application. It is well possible
>> to have Python drive the GUI by sending the required details to
>> the Flex front-end via XML (ie. data-driven GUIs).
>>
>>> So one doesn't get more than e.g. Django apps that
>>> respond to HTTP requests triggered by JavaScript forms except that
>>> JavaScript+HTML+Browser is replaced by Flex = AS3+MXML+FlashPlayer.
>> You really can't compare the Flex stack to an AJAX stack. Flex
>> has a lot more to offer for GUI programming than AJAX, it also
>> doesn't suffer from the problems of AJAX having to support several
>> different sets of browser or library bugs.
>>
>> We switched from an AJAX approach to a Flex-based approach last year
>> and never even considered moving back again.
> 
> 
> The approach does seem quite impressive, but isn't Flex's platform
> neutrality quite over-rated ? I mean after-all, it assumes that Flex is
> available for and available on the platform. Flex today is not yet so
> ubiquitous as the JRE...

Since Flex is compiled to Flash and runs inside the Flash player, it
is fairly easy to get Flex apps running. You do have to have the
Flash9 player installed and the default minimum is 9.0.115.0 for
Flex builder 3.

> Are there some established best-practices on how to package such
> applications -- s.a. shipping with its's own Flex runtime, offer-download if
> missing etc. ? What happens if owner of target machine decides to upgrade
> their version of Flex, will it impact the application package in anyway, and
> render rest of it "non-upgradable" ?

So far we have not had any such problems, but that could change when
Flash10 starts to ship, of course.

We currently ship the application as a server application. The only
requirement on the client side is having a browser with Flash9
installed. Pointing the browser at the server will then load the
compiled Flex application (as .swf file).

An alternative approach is bundling the client as AIR application
which then runs as stand-alone app on the client side, but we
haven't tried that yet.

>>> The role of Python is somewhat arbitrary. This could change only if
>>> Python becomes a client side language executed by AVM, V8 etc. like
>>> IronPython in Silverlight.
>>>
>>> About separating UI from application logics by assigning functionality
>>> to different general purpose languages I have to admit that I don't
>>> think it is such a great idea ...
>> In my experience, Flex + Python gives you the best of both worlds,
>> the nice GUI features of Flex and the efficiency of Python for the
>> business logic.
>>
>> A long time ago, there was a Python plugin for Netscape
>> which allowed you to run Python straight in the browser. Perhaps
>> it's time to revive such an idea... but then you're still missing
>> out on the GUI part, since you're still stuck with what the
>> browser has to offer in terms of widget support.
>>
>> --
>> Marc-Andre Lemburg
>> eGenix.com
>>
>> Professional Python Services directly from the Source  (#1, Sep 04 2008)
> Python/Zope Consulting and Support ...http://www.egenix.com/
> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
>> 
>>
>>  Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 
>>
>>
>>   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>>D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>>   Registered at Amtsgericht Duesseldorf: HRB 46611
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> 
> 
> 
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Sep 04 2008)
>>> Python/Zope Consulting and Support 

Investments Are Faltering in Chrysler and GMAC

2008-09-04 Thread 9847733785 . man
Mr. Feinberg’s giant investment fund, Cerberus Capital Management, is
racing to salvage multibillion-dollar investments in Chrysler, the
smallest of the Detroit automakers, and GMAC, the financing arm of
General Motors.

But for Cerberus, named after the mythological three-headed dog who
guards the gates of hell, the news keeps getting worse.

On Wednesday, Chrysler, which owns the Jeep and Dodge brands, said its
sales in the United States fell by a third in August — nearly twice
the industry average — as the downturn in the auto business dragged
on. Honda eclipsed Chrysler as the nation’s No. 4 seller of cars, and
Nissan is closing in fast.

The same day, GMAC, in which Cerberus holds a 51 percent stake, said
it was trying to stanch the bleeding from a business that was supposed
to be immune to the ups and downs of the car industry: home mortgage
lending. GMAC and its home loan unit, Residential Capital, announced
that they would dismiss 5,000 employees, or 60 percent of the unit’s
staff, and close all 200 of its retail mortgage branches.

It is quite a comedown for Mr. Feinberg, who founded Cerberus in 1992
with $10 million and was initially hailed as a savior at Chrysler.
Over the years, Cerberus excelled by gaining control of companies in
bankruptcy and nursing them back to financial health.

Now, Mr. Feinberg’s purchase of Chrysler and his deal for GMAC have
knocked Cerberus down a peg.

“Early on, in the Cerberus deal for Chrysler, when it first did these
auto industry investments, the story was about how big and influential
these funds are, that they think they can buy these iconic industrial
companies,” said Colin C. Blaydon, director of the Center for Private
Equity and Entrepreneurship at the Tuck School of Business at
Dartmouth College. “So far, it does not seem to be working out well
for them.”

Chrysler is still recovering from its split a year ago from its German
partner, Daimler, and is undergoing a big revamping under Cerberus.
Top executives at Cerberus have said they are determined to fix the
company and that their $7.4 billion investment will pay off.

A Cerberus spokesman said in a statement on Wednesday that it remained
confident in its management of Chrysler and GMAC. “No one is pleased
with current market conditions,” he said. “However, Cerberus is a
patient investor and not a market timer, and we take a long-term view
of our investments. Our funds are structured accordingly.”

Mr. Feinberg hired Robert L. Nardelli, the former chief executive of
Home Depot, to turn Chrysler around. Their plan hinges on new
offerings beginning in 2010.

Since Cerberus acquired Chrysler, the automaker has been trying to
squeeze out costs. It has announced the elimination of 28,000 jobs and
sold $500 million worth of assets. Last week, Chrysler announced that
it was studying a sale of its Dodge Viper sports car business.

But like its larger competitors, General Motors and Ford Motor,
Chrysler has faced questions over its ability to ride out a downturn
in American auto sales that is expected to stretch through 2009. All
three Detroit automakers have been hit hard by the sharp decline in
sales of pickup trucks, sport utility vehicles and vans that followed
the rise in gas prices this year.

Chrysler, which has released limited financial data since Cerberus
bought it, ended June with $11.7 billion in cash and had earnings
before interest, tax, depreciation and amortization of $1.1 billion in
the first half of the year. But with limited access to financial data,
some analysts are skeptical of its overall health.

The news on Wednesday from GMAC, meantime, underscored that Cerberus
also must contend with the housing slump, which has led to huge losses
at lenders across the spectrum. That includes Residential Capital,
which became one of the nation’s biggest mortgage providers and
plunged into the market for riskier home loans that could not be sold
to Fannie Mae or Freddie Mac, the mortgage finance giants that have
run into trouble themselves. Now, many of those loans are defaulting
as home prices fall and the economy weakens.

This summer, Residential Capital and its bondholders restructured $14
billion in bonds to ease its debt burden. That restructuring and new
loans from GMAC have bought the company time to work out its problems,
but analysts say it may not be enough to save the firm from rising
defaults on mortgages. Residential Capital bonds are trading at about
70 cents on the dollar.

“They have some time,” said Andrew Feltus, a bond fund manager at
Pioneer Investments. But, he added, “This environment is going against
them.”

www.my-quickloans.com/finance
--
http://mail.python.org/mailman/listinfo/python-list


Re: overwrite set behavior

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 3:07 PM, Maric Michaud <[EMAIL PROTECTED]> wrote:
> Le Thursday 04 September 2008 14:31:23 Michele Petrazzo, vous avez écrit :
>> Marco Bizzarri wrote:
>> > looking at the source, maybe you could create a subclass of Set
>> > redefining the __contains__ method?
>>
>> Made some tries, but __contains__ are never called
>>
>
> No, __contains__ is only called  with "in" operator, not for internal hashing.
> Anyway this solution is bad, you'll need to compare the new element with all
> the set contain, which would result in a O(n) algorithm for adding elements
> to the set in place of the O(1) it use.
>

Thanks for the clarification, Maric; I take notices to watch source
more closely next time (( hopefully, before writing a wrong answer )).

Regards
Marco

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



-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 1:19 PM, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

>
> What you are essentially asking is: why is python dynamic instead of static?
>

Most probably you're right. Maybe I will make a trip back to my
university books and take a look at them again :-)

Thanks
Marco

-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 4:39 PM, Marco Bizzarri <[EMAIL PROTECTED]> wrote:
>
> Most probably you're right. Maybe I will make a trip back to my
> university books and take a look at them again :-)
>

Meant: you *are* right. Sorry.

Saluti
Marco

-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 2:43 PM, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:




Well, Bruno, it looks like I've to wider my search in order to read
something about it. Thanks for your suggestions, in any case.

Regards
Marco


-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Python and Cyrillic characters in regular expression

2008-09-04 Thread phasma
Hi, I'm trying extract all alphabetic characters from string.

reg = re.compile('(?u)([\w\s]+)', re.UNICODE)
buf = re.match(string)

But it's doesn't work. If string starts from Cyrillic character, all
works fine. But if string starts from Latin character, match returns
only Latin characters.

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


Re: Numeric literal syntax

2008-09-04 Thread Fredrik Lundh

Alexander Schmolck wrote:


A problem is that '1234' in Python is a string, so using ' in numbers
looks a bit dangerous to me (and my editor will color those numbers as
alternated strings, I think).


Yeah, editors, especially those with crummy syntax highlighting (like emacs)
might get it wrong. This should be easy enough to fix though.


instead of forcing all editor developers to change their Python modes to 
allow you to use a crude emulation of a typographic convention in your 
Python source code, why not ask a few of them to implement the correct 
typographic convention (thin spaces) in their Python mode?




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


Read Binary data

2008-09-04 Thread Mars creature
Hi guys,
  I am trying to read a binary file created by the following matlab
command:
fid=fopen('a.bin','w','b'); fwrite(fid,a,'real*8'); fclose(fid);, and
wondering how to do it in Python. I googled it but still get
confused.
  'b' in fopen is for 'big-endian', 'real*8' in fwrite is for 64bit
float.
 Thank you very much!
Jinbo Wang
--
http://mail.python.org/mailman/listinfo/python-list


Function decorators

2008-09-04 Thread Aigars Aigars
Good day all,

I am learning Python and came up to decorators.

The question is: Why does function FoodList return value None?

The code in attachment.
Thank you,
Aigars

testingVarLogger.py
Description: application/unknown-application-x-python
--
http://mail.python.org/mailman/listinfo/python-list

Re: Function decorators

2008-09-04 Thread Laszlo Nagy

Aigars Aigars wrote:

Good day all,

I am learning Python and came up to decorators.

The question is: Why does function FoodList return value None?

The code in attachment.


Thank you,
Aigars


--
http://mail.python.org/mailman/listinfo/python-list
First of all, you should always inherit from "object" whenever it is 
possible.



Then the answer:  you did not return the result.

Instead of

   self.func(*args, **kwargs)

use this:


   return self.func(*args, **kwargs)

Corrected example attached.

Best,

  Laszlo



class Logger(object):
	def __init__(self, function):
		self.func = function

	def __call__(self, *args, **kwargs):
		print "Function %s called with args = %s, kwargs = %s" % (self.func.__name__, str(args), str(kwargs))
return self.func(*args, **kwargs) # Return is important here!
	
@Logger
def FoodList(a, b, c="spam"):
	text  = "Food is %s, %s, %s" % (a, b, c)
	print text
	return text


if __name__ == "__main__":
	a = FoodList("eggs", "potatoes")
	print a
	
--
http://mail.python.org/mailman/listinfo/python-list

Re: overwrite set behavior

2008-09-04 Thread Wojtek Walczak
On Thu, 4 Sep 2008 12:06:14 +0200, Marco Bizzarri wrote:

>> As far as I understand you, you need descriptors:
>> http://users.rcn.com/python/download/Descriptor.htm

> I know descriptors a litte, Wojtek, but didn't use them often; can you
> elaborate a little more on your idea?

Marco, I think that I misunderstood the OP, but I was thinking
about immutable (or set-once) attributes. Something like this:

---
class SetOnce(object):
   def __init__(self):
  self._attr1 = ""
  self._attr1flag = False

   def setatt(self, x):
  if self._attr1flag:
 raise ValueError("attribute already set")
  self._attr1flag = True
  self._attr1 = x

   def getatt(self):
  return self._attr1

   attr1 = property(getatt, setatt)

a = SetOnce()
a.attr1 = 1
print a.attr1
try:
   a.attr1 = 2
except ValueError:
   print a.attr1
---

$ python immutattr.py
1
1
$

-- 
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function decorators

2008-09-04 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>,
 Aigars Aigars <[EMAIL PROTECTED]> wrote:

> Good day all,

I am learning Python and came up to decorators.

The question 
> is: Why does function FoodList return value None?

Because the function doesn't return anything, and in Python
a function that doesn't explicitly return anything returns None.

>

The code in attachment.


Thanks for not just pasting it into the post, like so:

class Logger:

   def __init__(self, function):

  self.func = function



   def __call__(self, *args, **kwargs):

  print "Function %s called with args = %s, kwargs = %s" % 
(self.func.__name__, str(args), str(kwargs))

self.func(*args, **kwargs)

   

@Logger

def FoodList(a, b, c="spam"):

   text  = "Food is %s, %s, %s" % (a, b, c)

   print text

   return text





if __name__ == "__main__":

   a = FoodList("eggs", "potatoes")

   print a

> Thank you,

> Aigars-
> [Image]

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


Re: Function decorators

2008-09-04 Thread Diez B. Roggisch

Aigars Aigars schrieb:

Good day all,

I am learning Python and came up to decorators.

The question is: Why does function FoodList return value None?

The code in attachment.


Because the __call__ in Logger doesn't return the value of self.func.

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


Re: path slashes cleaning

2008-09-04 Thread Jason Scheirer
On Sep 4, 6:32 am, "Francesco Guerrieri" <[EMAIL PROTECTED]>
wrote:
> On Thu, Sep 4, 2008 at 3:25 PM, Mathieu Prevot <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > for scripts that take arguments, I would like to remove the trailing
> > slash if it's present.
>
> > Is there something else than:
>
> > a='/usr/local/lib/'
> > if a[-1] == '/':
> >  a = list(a)
> >  a.pop()
> >  ''.join(a)
>
> > Thanks,
> > Mathieu
>
> a.rstrip('/') does the job.
>
> bye,
> Francesco

[1]: import os.path
[2]: os.path.normpath('/usr/bin')
'/usr/bin'
[3]: os.path.normpath('/usr/bin/')
'/usr/bin'

And on windows:
[1]: import os.path
[2]: os.path.normpath(r'c:\data')
'c:\\data'
[3]: os.path.normpath('c:\\data\\')
'c:\\data'

Use the functions provided in os.path.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Read Binary data

2008-09-04 Thread Fredrik Lundh

"Mars creature" wrote:


  I am trying to read a binary file created by the following matlab
command:
fid=fopen('a.bin','w','b'); fwrite(fid,a,'real*8'); fclose(fid);, and
wondering how to do it in Python. I googled it but still get
confused.
  'b' in fopen is for 'big-endian', 'real*8' in fwrite is for 64bit
float.



f = open("a.bin", "rb") # read binary data
s = f.read() # read all bytes into a string

import array, sys

a = array.array("f", s) # "f" for float
if sys.byteorder != "big":
   a.byteswap()



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


Re: max(), sum(), next()

2008-09-04 Thread David C. Ullrich
In article 
<[EMAIL PROTECTED]>,
 Mensanator <[EMAIL PROTECTED]> wrote:

> On Sep 3, 2:18 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> > > Empty Python lists [] don't know the type of the items it will
> > > contain, so this sounds strange:
> >
> >  sum([])
> >
> > > 0
> >
> > > Because that [] may be an empty sequence of someobject:
> >
> > You are right in that sum could be used to sum arbitrary objects.
> > However, in 99.99% of the cases, you will be summing numerical values.
> > When adding real numbers, the neutral element is zero. ( X + 0 = X) It
> > is very logical to return zero for empty sequences.
> 
> No it isn't. Nothing is not 0, check with MS-Access, for instance:
> 
> Null + 1 returns Null. Any arithmetic expression involving a
> Null evaluates to Null. Adding something to an unknown returns
> an unknown, as it should.
> 
> It is a logical fallacy to equate unknown with 0.

Which has nothing to do with the "right" value for an
empty sum. If they hear about what you said here in
sci.math they're gonna kick you out - what do you
imagine the universally accepted value of \sum_{j=1}^0 
is?


> For example, the water table elevation in ft above Mean Sea Level
> is WTE = TopOfCasing - DepthToWater.
> 
> TopOfCasing is usually known and constant (until resurveyed).
> But DepthToWater may or may not exist for a given event (well
> may be covered with fire ants, for example).
> 
> Now, if you equate Null with 0, then the WTE calculation says
> the water table elevation is flush with the top of the well,
> falsely implying that the site is underwater.
> 
> And, since this particular site is on the Mississippi River,
> it sometimes IS underwater, but this is NEVER determined by
> water table elevations, which, due to the CORRECT treatment
> of Nulls by Access, never returns FALSE calculations.
> 
> >>> sum([])
> 0
> 
> is a bug, just as it's a bug in Excel to evaluate blank cells
> as 0. It should return None or throw an exception like sum([None,1])
> does.
> 
> >
> > Same way, if we would have a prod() function, it should return one for
> > empty sequences because X*1 = X. The neutral element for this operation
> > is one.
> >
> > Of course this is not good for summing other types of objects. But how
> > clumsy would it be to use
> >
> > sum( L +[0] )
> >
> > or
> >
> > if L:
> > value = sum(L)
> > else:
> > value = 0
> >
> > instead of sum(L).
> >
> > Once again, this is what sum() is used for in most cases, so this
> > behavior is the "expected" one.
> >
> > Another argument to convince you: the sum() function in SQL for empty
> > row sets returns zero in most relational databases.
> >
> > But of course it could have been implemented in a different way... I
> > believe that there have been excessive discussions about this decision,
> > and the current implementation is very good, if not the best.
> >
> > Best,
> >
> > Laszlo

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

Re: max(), sum(), next()

2008-09-04 Thread David C. Ullrich
In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> Empty Python lists [] don't know the type of the items it will
> contain, so this sounds strange:
> 
> >>> sum([])
> 0
> 
> Because that [] may be an empty sequence of someobject:
> 
> >>> sum(s for s in ["a", "b"] if len(s) > 2)
> 0
> 
> In a statically typed language in that situation you may answer the
> initializer value of the type of the items of the list, as I do in the
> sum() in D.
> 
> This sounds like a more correct/clean thing to do:
> 
> >>> max([])
> Traceback (most recent call last):
>   File "", line 1, in 
> ValueError: max() arg is an empty sequence
> 
> So it may be better to make the sum([]) too raise a ValueError,

I don't see why you feel the two should act the same.
At least in mathematics, the sum of the elements of
the empty set _is_ 0, while the maximum element of the
empty set is undefined. 

And both for good reason:

(i) If A and B are disjoint sets we certainly want to
have sum(A union B) = sum(A) + sum(B). This requires
sum(empty set) = 0.

(ii) If A is a subset of B then we should have
max(A) <= max(B). This requires that max(empty set)
be something that's smaller than everything else.
So we give up on that.

> in
> Python 3/3.1 (if this isn't already true). On the other hand often
> enough I have code like this:
> 
> >>> max(fun(x) for x in iterable if predicate(x))
> 
> This may raise the ValueError both if iterable is empty of if the
> predicate on its items is always false, so instead of catching
> exceptions, that I try to avoid, I usually end with a normal loop,
> that's readable and fast:
> 
> max_value = smallvalue
> for x in iterable:
> if predicate(x):
> max_value = max(max_value, fun(x))
> 
> Where running speed matters, I may even replace that max(max_value,
> fun(x)) with a more normal if/else.
> 
> A possible alternative is to add a default to max(), like the next()
> built-in of Python 2.6:
> 
> >>> max((fun(x) for x in iterable if predicate(x)), default=smallvalue)
> 
> This returns smallvalue if there are no items to compute the max of.
> 
> Bye,
> bearophile

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


Re: Read Binary data

2008-09-04 Thread Mars creature
On Sep 4, 12:03 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> "Mars creature" wrote:
> >   I am trying to read a binary file created by the following matlab
> > command:
> > fid=fopen('a.bin','w','b'); fwrite(fid,a,'real*8'); fclose(fid);, and
> > wondering how to do it in Python. I googled it but still get
> > confused.
> >   'b' in fopen is for 'big-endian', 'real*8' in fwrite is for 64bit
> > float.
>
> f = open("a.bin", "rb") # read binary data
> s = f.read() # read all bytes into a string
>
> import array, sys
>
> a = array.array("f", s) # "f" for float
> if sys.byteorder != "big":
> a.byteswap()
>
> 

Thanks Fredrik! I appreciate it!
The only thing is that a = array.array("f", s) should be a =
array.array("d", s) as the data is double precision.
Thanks again!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Late initialization using __getattribute__

2008-09-04 Thread bukzor

> >>> so unfortunately I think I need to use __getattribute__
> >>> to do this. I'm doing all this just to make the connection not
> >>> actually connect until used.
> >> I may be dumb, but I don't get how this is supposed to solve your
> >> problem. But anyway : there's a known design pattern for what you're
> >> trying to do, that doesn't require mixins nor messing with
> >> __getattribute__ (which, I repeat, is more often than not something you
> >> *don't* want to do). The name of the design pattern is "proxy". I
> >> strongly suggest that you 1/ try to cure the real problem instead of
> >> hacking around and 2/ read about the proxy design pattern.
>
> >> My 2 cents...
>
> > I like the idea of mix-ins, but can't figure out how to make a proxy
> > work that way.
>
> You mean, "how to use a proxy for lazy initialization" ? Heck, that's
> the exact use case in the GoF.

I mean, "how to make a MixIn class that uses the proxy pattern". I'd
like to be able to do something like this:

class SuperCursor(FeatureOneMixIn, FeatureTwoMixin, ...,
VanillaCursor): pass

This works with my current implementation. After thinking about it
more, I think I've got such a thing written. I had to use
inspect.getmro and new.classobj to do it, but it works and it honors
the usual mro (as far as I can tell). I've put the code at the bottom
to (try to) maintain readability.


> > For a long time I had a proxy class that added five or
> > six features on top of the MySQLdb package, but it wasn't configurable
> > enough, and I'm working on splitting each feature into its own MixIn
> > class.
>
> > As an aside, this is working for me pretty well. The "reconnect"
> > method (inheritied from a "Reconnectable" mixin) uses several of the
> > object's attributes, so I need to set _inited beforehand so that I
> > don't get into an infinite __getattribute__ loop. What I'd *really*
> > like to do is remove __getattribute__ from the object at that point.
>
> You can't. Or, more exactly, all you can do is remove __getattribute__
> from the mixin class - but then the mixin class won't work anymore. I
> don't mean to be condescendant, but it looks like you don't have a clear
> understanding of Python's object model here - else you wouldn't even
> consider doing such a thing. FWIW, I posted a solution based on the
> __getattr__ hook, which did work - at least for the "specs" implied by
> your code snippet.

My toy example turned out to be not the best representation of the
problem.
The base class has attributes that "exist" but either throw errors or
segfault
if used before reconnect() is called. This means that I need to
capture more than
just the attributes that would throw AttributeError.




#CODE
class Base(object):
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
def __str__(self): return "" %
(self.args, self.kwargs)

class MixIn2(object):
def __str__(self):
return "" % super(MixIn2, self).__str__()

class MixIn1(object):
def __str__(self):
return "" % super(MixIn1, self).__str__()

class ProxyMixIn(object):
def __init__(self, *args, **kwargs):
self.__proxied = None
self.__args = args
self.__kwargs = kwargs
def __getattr__(self, attr):
print "Getting", attr
try: return getattr(self.__proxied, attr)
except AttributeError:
if self.__proxied: raise
else:
from inspect import getmro
mro = getmro(self.__class__)
mro = mro[list(mro).index(ProxyMixIn) + 1:]
print "Proxied mro", mro
from new import classobj
self.__proxied = classobj("Proxied", mro, globals())
(*self.__args, **self.__kwargs)
return getattr(self.__proxied, attr)
def __str__(self):
return "" % super(ProxyMixIn, self).__str__()

class Proxy(MixIn1, ProxyMixIn, MixIn2, Base): pass

def main():
p = Proxy(1,2,3, one=1, two=2)
print p
main()

#OUTPUT##
Getting args
Proxied mro (, , )
Getting kwargs
>>>

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


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread George Sakkis
On Sep 4, 7:09 am, "Marco Bizzarri" <[EMAIL PROTECTED]> wrote:
> Sorry... pressed enter but really didn't want to.
>
> As I said, let's say I have a class
>
> class A:
>     def __init__(self):
>          self.x = None
>
> Python makes the decision to allow the developers to directly access
> the attribute "x",  so that they can directly write: "a.x = 1", or
> whatever; this has for me the unfortunate side effect that if I write,
> for example "a.y = 1", when I really wanted to write "a.x = 1" no one
> cares about it, and I'm unable to spot this error until later.
>
> Of course, I know that while I'm fresh, I've a good knowledge of the
> code, and anything else, I will be able to avoid such stupid errors;
> however, I'm afraid of the times when I'm tired, when I have to put my
> hands on the code of someone else, and so on.

So what happens in Java (or any language for that matter) if there are
indeed two attributes x and y with the same type and you mistype the
one for the other ? Or if you meant to write x-y instead of y-x ?

When coding tired or on someone's else code, stupid errors are the
ones you should worry the least about.

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


Right to left language support

2008-09-04 Thread Gandalf
Most of you probably speaks Latin language,  so you wont understand
the problem.
when I try to write Hebrew in my statictext the last punctuation marks
get mixed up.
does someone have a solution  for this?

this is the code :

text=wx.StaticText(panel3, -1, Hebrew_string, style=wx.ALIGN_RIGHT)

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


Re: Read Binary data

2008-09-04 Thread mblume
Am Thu, 04 Sep 2008 18:03:54 +0200 schrieb Fredrik Lundh:
>
>>   I am trying to read a binary file [...]
> 
> 
> f = open("a.bin", "rb") # read binary data 
> s = f.read() # read all bytes into a string
> 
> import array, sys
> 
> a = array.array("f", s) # "f" for float 
> if sys.byteorder != "big":
> a.byteswap()
> 
For more complicated structures, the struct module may help.

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


Re: Help needed to freeze a script.

2008-09-04 Thread LB
> Did you try py2exe instead offreeze? On the page
>
> http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
>
> there is only one brief mention of numpy packaging troubles,
> suggesting that it might work better. I have used py2exe in the past
> without much trouble.

Unfortunately, I'm working under Linux and py2exe works only for
windows as far as I know.
Do you know if py2exe executable embedding a lot of C extensions -
like numpy and scipy - can ben executed on another computer, with a
different architecture (64bits vs 32 bits) and a different OS ?

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


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Timothy Grant
On Thu, Sep 4, 2008 at 4:09 AM, Marco Bizzarri <[EMAIL PROTECTED]> wrote:
> Sorry... pressed enter but really didn't want to.
>
> As I said, let's say I have a class
>
> class A:
>def __init__(self):
> self.x = None
>
>
>
> Python makes the decision to allow the developers to directly access
> the attribute "x",  so that they can directly write: "a.x = 1", or
> whatever; this has for me the unfortunate side effect that if I write,
> for example "a.y = 1", when I really wanted to write "a.x = 1" no one
> cares about it, and I'm unable to spot this error until later.
>
> Of course, I know that while I'm fresh, I've a good knowledge of the
> code, and anything else, I will be able to avoid such stupid errors;
> however, I'm afraid of the times when I'm tired, when I have to put my
> hands on the code of someone else, and so on.
>
> Please, understand that I'm not stating that python is wrong... after
> all, if it is wrong, I can move to a language like Java, which has a
> different approach on it. I'm really very interested in reading past
> discussion on it, if they are available.
>
> Regards
> Marco

I think the most obvious solution to the problem is effective unit
tests. If you type "a.y =1" and have a test that asserts a.x == 1 then
you would quite quickly discover that you made a typo.


-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: max(), sum(), next()

2008-09-04 Thread Mensanator
On Sep 4, 11:13 am, "David C. Ullrich" <[EMAIL PROTECTED]> wrote:
> In article
> <[EMAIL PROTECTED]>,
>
>
>
>
>
>  Mensanator <[EMAIL PROTECTED]> wrote:
> > On Sep 3, 2:18 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> > > [EMAIL PROTECTED] wrote:
> > > > Empty Python lists [] don't know the type of the items it will
> > > > contain, so this sounds strange:
>
> > >  sum([])
>
> > > > 0
>
> > > > Because that [] may be an empty sequence of someobject:
>
> > > You are right in that sum could be used to sum arbitrary objects.
> > > However, in 99.99% of the cases, you will be summing numerical values.
> > > When adding real numbers, the neutral element is zero. ( X + 0 = X) It
> > > is very logical to return zero for empty sequences.
>
> > No it isn't. Nothing is not 0, check with MS-Access, for instance:
>
> > Null + 1 returns Null. Any arithmetic expression involving a
> > Null evaluates to Null. Adding something to an unknown returns
> > an unknown, as it should.
>
> > It is a logical fallacy to equate unknown with 0.
>
> Which has nothing to do with the "right" value for an
> empty sum.

I'm less concerned about the "right" value than a consistent
value. I'm fairly certain you can't get 0 from a query that
returns no records, so I don't like seeing empty being
treated as 0, even if it means that in set theory because
databases aren't sets.

> If they hear about what you said here in
> sci.math they're gonna kick you out

They usually don't kick me out, just kick me.

> - what do you
> imagine the universally accepted value of \sum_{j=1}^0
> is?

I can't follow your banter, so I'm not sure what it should be.

>
>
>
>
>
> > For example, the water table elevation in ft above Mean Sea Level
> > is WTE = TopOfCasing - DepthToWater.
>
> > TopOfCasing is usually known and constant (until resurveyed).
> > But DepthToWater may or may not exist for a given event (well
> > may be covered with fire ants, for example).
>
> > Now, if you equate Null with 0, then the WTE calculation says
> > the water table elevation is flush with the top of the well,
> > falsely implying that the site is underwater.
>
> > And, since this particular site is on the Mississippi River,
> > it sometimes IS underwater, but this is NEVER determined by
> > water table elevations, which, due to the CORRECT treatment
> > of Nulls by Access, never returns FALSE calculations.
>
> > >>> sum([])
> > 0
>
> > is a bug, just as it's a bug in Excel to evaluate blank cells
> > as 0. It should return None or throw an exception like sum([None,1])
> > does.
>
> > > Same way, if we would have a prod() function, it should return one for
> > > empty sequences because X*1 = X. The neutral element for this operation
> > > is one.
>
> > > Of course this is not good for summing other types of objects. But how
> > > clumsy would it be to use
>
> > > sum( L +[0] )
>
> > > or
>
> > > if L:
> > > value = sum(L)
> > > else:
> > > value = 0
>
> > > instead of sum(L).
>
> > > Once again, this is what sum() is used for in most cases, so this
> > > behavior is the "expected" one.
>
> > > Another argument to convince you: the sum() function in SQL for empty
> > > row sets returns zero in most relational databases.
>
> > > But of course it could have been implemented in a different way... I
> > > believe that there have been excessive discussions about this decision,
> > > and the current implementation is very good, if not the best.
>
> > > Best,
>
> > > Laszlo
>
> --
> David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Cyrillic characters in regular expression

2008-09-04 Thread MRAB
On Sep 4, 3:42 pm, phasma <[EMAIL PROTECTED]> wrote:
> Hi, I'm trying extract all alphabetic characters from string.
>
> reg = re.compile('(?u)([\w\s]+)', re.UNICODE)

You don't need both (?u) and re.UNICODE: they mean the same thing.

This will actually match letters and whitespace.

> buf = re.match(string)
>
> But it's doesn't work. If string starts from Cyrillic character, all
> works fine. But if string starts from Latin character, match returns
> only Latin characters.
>

I'm encoding the Unicode results as UTF-8 in order to print them, but
I'm not having a problem with it otherwise:

Program
===
# -*- coding: utf-8 -*-
import re
reg = re.compile('(?u)([\w\s]+)')

found = reg.match(u"ya я")
print found.group(1).encode("utf-8")

found = reg.match(u"я ya")
print found.group(1).encode("utf-8")

Output
==
ya я
я ya
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python and Cyrillic characters in regular expression

2008-09-04 Thread Fredrik Lundh

phasma wrote:


Hi, I'm trying extract all alphabetic characters from string.

reg = re.compile('(?u)([\w\s]+)', re.UNICODE)
buf = re.match(string)

But it's doesn't work. If string starts from Cyrillic character, all
works fine. But if string starts from Latin character, match returns
only Latin characters.


can you provide a few sample strings that show this behaviour?



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


Re: max(), sum(), next()

2008-09-04 Thread Mensanator
On Sep 4, 2:05 am, Thomas Bellman <[EMAIL PROTECTED]> wrote:
> Mensanator <[EMAIL PROTECTED]> wrote:
> > No, but blank cells are 0 as far as Excel is concerned.
> > That behaviour causes nothing but trouble and I am
> > saddened to see Python emulate such nonsense.
>
> Then you should feel glad that the Python sum() function *does*
> signal an error for the closest equivalent of "blank cells" in
> a list:
>
>     >>> sum([1, 2, 3, None, 5, 6])
>     Traceback (most recent call last):
>       File "", line 1, in 
>     TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Yes, I am in fact happy to see that behaviour.

>
> Summing the elements of an empty list is *not* the same thing as
> summing elements of a list where one element is None.

So,

>>> sum([1, 2, 3, None, 5, 6])
Traceback (most recent call last):
  File "", line 1, in 
sum([1, 2, 3, None, 5, 6])
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

gives me an error.

As does

>>> sum([None, None, None, None, None, None])

Traceback (most recent call last):
  File "", line 1, in 
sum([None, None, None, None, None, None])
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Why then, doesn't

>>> sum([A for A in [None, None, None, None, None, None] if A != None])
0

give me an error?

Ok, it's not a bug.

"This behaviour is by design." - Microsoft Knowledge Base

I don't like it, but I guess I'll just have to live with it.

>
> > There are no "empty" boxes. There are only boxes with
> > known quantities and those with unknown quantities.
> > I hope that's not too ivory tower.
>
> The sum() function in Python requires exactly one box.  That box
> can be empty, can contain "known quantities" (numbers, presumably),
> or "unknown quantities" (non-numbers, e.g., None).  But you can't
> give it zero boxes, or three boxes.
>
> I don't have a strong view of whether sum([]) should return 0 or
> raise an error, but please do not mix that question up with what
> a sum over empty cells or over NULL values should yield.  They
> are very different questions.

Ok, but I don't understand why an empty list is a valid sum
whereas a list containing None is not.

>
> As it happens, the SQL sum() function (at least in MySQL; I don't
> have any other database easily available, nor any SQL standard to
> read) does return NULL for a sum over the empty sequence, so you
> could argue that that would be the correct behaviour for the
> Python sum() function as well, but you can't argue that because a
> sum *involving* a NULL value returns NULL.

I'm not following that. Are you saying a query that returns no
records doesn't have a specific field containg a Null so there
are no Nulls to poison the sum? ...tap...tap...tap. Ok, I can see
that, but you don't get 0 either.

>
> --
> Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
> "This isn't right.  This isn't even wrong."  !  bellman @ lysator.liu.se
>                          -- Wolfgang Pauli   !  Make Love -- Nicht Wahr!

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


Re: Xpath for HTML processing

2008-09-04 Thread Stefan Behnel
Astley Le Jasper wrote:
> Can anyone suggest something inthat can process an XPath like the
> following:
> 
> "/html/body/table[2]/tbody/tr/td[5]/table/tbody/tr[3]/td/table[3]/
> tbody/tr[5]/td"

[skipping the obvious joke answer to your question]

In case you're asking for a tool that can process HTML using XPath, try 
lxml.html.

http://codespeak.net/lxml

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


Re: max(), sum(), next()

2008-09-04 Thread Wojtek Walczak
On Thu, 4 Sep 2008 10:57:35 -0700 (PDT), Mensanator wrote:

> Why then, doesn't
>
 sum([A for A in [None, None, None, None, None, None] if A != None])
> 0
>
> give me an error?

Because "[A for A in [None, None, None, None, None, None] if A != None]"
returns an empty list, and sum([]) doesn't return an error. What did you
expect?


-- 
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Submitting forms over HTTPS with mechanize

2008-09-04 Thread Rex
On Sep 3, 10:17 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> Rex wrote:
> > Hello,
>
> > I am working on an academic research project where I need to log in to
> > a website (www.lexis.com) over HTTPS and execute a bunch of queries to
> > gather a data set. I just discovered the mechanize module, which seems
> > great because it's a high-level tool. However, I can't find any decent
> > documentation for mechanize apart from the docstrings, which are
> > pretty thin. So I just followed some other examples I found online, to
> > produce the following:
>
> > baseurl = 'http://www.lexis.com/'
> > br = mechanize.Browser()
> > br.set_handle_robots(False)
> > br.addheaders = [('User-Agent', 'Firefox')]
> > br.open(baseurl)
> > br.select_form(name="formauth")
> > br["USER_ID"]="my_user_id"
> > br["PASSWORD"]="my_password"
> > result = br.submit()
>
> > This code hangs at br.submit(), and I can't tell what I'm doing wrong.
> > Typically I would inspect the HTTP data with an HTTP debugging proxy
> > (Fiddler), but I guess since this is HTTPS I can't do that. Any
> > glaring errors in my code?
>
> > By the way, does anyone have suggestions for Python modules that I
> > should use instead of mechanize (and that are sufficiently easy)? If
> > mechanize fails, I might try modifying some similar Perl code a friend
> > sent me that logs into lexis.com.
>
> > Thanks so much,
>
> > Rex
>
> I've used mechanize quite successfully but others have suggested 
> Twillhttp://twill.idyll.org/.  It seems to be at least documented.
>
> -Larry

Thanks for the reply, Larry. I ran my code again and it worked; there
was probably some temporary issue with either my computer or the
server that caused it to hang.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python/xpath question..

2008-09-04 Thread Stefan Behnel
Stefan Behnel wrote:
> Yes, learn to use XPath, e.g.
> 
>   //tr/td[not string()]

Oh, well...

   //tr/td[not(string())]

as I said, wrong news group. ;-)

Try something like "gmane.text.xml.xpath.general", for example.

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


  1   2   >