Re: Picking a license

2010-05-08 Thread Paul Rubin
Patrick Maupin  writes:
> I certainly agree that RMS's language is couched in religious rhetoric.

I would say political movement rhetoric.  He's not religious.  He uses
the word "spiritual" sometimes but has made it clear he doesn't mean
that in a religious sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 14:27:32 -0700, dasacc22 wrote:

> U presume entirely to much. I have a preprocessor that normalizes
> documents while performing other more complex operations.  Theres
> nothing buggy about what im doing

I didn't *presume* anything, I took your example code and ran it and 
discovered that it didn't do what you said it was doing.


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


Re: Kindly show me a better way to do it

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 14:06:33 -0700, Oltmans wrote:

> On May 9, 1:53 am, superpollo  wrote:
> 
>> add = lambda a,b: a+b
>> for i in reduce(add,a):
>>      print i
> 
> This is very neat. Thank you. Sounds like magic to me. Can you please
> explain how does that work? Many thanks again.

Don't use this except for small lists, it is very inefficient and will be 
slow for large lists. It is a Shlemiel The Painter algorithm:

http://www.joelonsoftware.com/articles/fog000319.html


The most idiomatic solution is a simple, straightforward nested iteration:

for sublist in a:
for item in sublist:
do_something_with(item)

Say that there are 10 sublists with 10 items each. Then nested iteration 
will iterate 100 times in total. The solution with reduce will iterate:

10+10  # add the first sublist and the second sublist
20+10  # add the third sublist
30+10  # add the fourth sublist
40+10  # and so on... 
50+10
60+10
70+10
80+10
90+10  # add the last sublist
100  # and now iterate over the combined list

or 640 times in total.  If there are 100 sublists of 10 items each, the 
performance is even worse: 51,490 for the reduce solution, versus 1000 
for the nested iteration.

Admittedly those iterations will be in fast C code instead of slow Python 
code, which is why you might not notice the difference at first, but 
you're still doing a lot of unnecessary work which takes time. How much 
time? Python makes it easy to find out.

>>> from timeit import Timer
>>> setup = "data = [range(10) for i in range(10)]"
>>> t1 = Timer("""for sublist in data:
... for item in sublist:
... pass""", setup)
>>> t2 = Timer("""for item in reduce(lambda x,y: x+y, data):
... pass""", setup)
>>>
>>> min(t1.repeat(number=10))
0.94107985496520996
>>> min(t2.repeat(number=10))
1.7509880065917969

So for ten sublists of ten items each, the solution using reduce is 
nearly twice as slow as the nested iteration. If we make the number of 
lists ten times larger, the nested for-loop solution takes ten times 
longer, as you would expect:

>>> setup = "data = [range(10) for i in range(100)]"
>>> t1 = Timer("""for sublist in data:
... for item in sublist:
... pass""", setup)
>>> min(t1.repeat(number=10))
10.349304914474487


But the reduce solution slows down by a factor of thirty-two rather than 
ten:

>>> t2 = Timer("""for item in reduce(lambda x,y: x+y, data):
... pass""", setup)
>>> min(t2.repeat(number=10))
58.116463184356689


If we were to increase the number of sublists further, the reduce 
solution will perform even more badly.



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


Re: Picking a license

2010-05-08 Thread Patrick Maupin
On May 9, 12:19 am, Steven D'Aprano  wrote:
> On Sat, 08 May 2010 16:39:33 -0700, Carl Banks wrote:
> > GPL is about fighting a holy war against commercial software.
>
> Much GPL software *is* commercial software. Given that you're so badly
> misinformed about the GPL that you think it can't be commercial, why
> should we pay any attention to your opinions about it?

I think, when Carl wrote "commercial" he meant what many others,
including RMS, would call "proprietary."  And, although many people
who use the GPL license may not be fighting the holy war, the original
author of the license certainly is.  When asked how he sees
proprietary software businesses making a profit when more and more
software is free, RMS replied "That's unethical, they shouldn't be
making any money. I hope to see all proprietary software wiped out.
That's what I aim for. That would be a World in which our freedom is
respected. A proprietary program is a program that is not free. That
is to say, a program that does respect the user's essential rights.
That's evil. A proprietary program is part of a predatory scheme where
people who don't value their freedom are drawn into giving it up in
order to gain some kind of practical convenience."

And while I agree somewhat with RMS when the subject is certain
proprietary companies that try really hard to lock in users and lock
up their data, I don't view all proprietary software as evil, and I
certainly agree that RMS's language is couched in religious rhetoric.

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


Re: Picking a license

2010-05-08 Thread Paul Rubin
Patrick Maupin  writes:
> hybrid models that the GPL doesn't support.  See, for example, Apple's
> support of BSD, Webkit, and LLVM.  Apple is not a "do no evil"
> corporation, and their contributions back to these packages are driven
> far more by hard-nosed business decisions than by any expectation of
> community goodwill.

That is true.  They've also supported GPL projects.  I think they just
don't want to be in the business of selling those sorts of products.
They're making too much money selling iphones and laptops to want such a
distraction.  Things were different with G++.  The company that
developed it would have liked to go into the compiler business with it,
but it wasn't an option, so they released under GPL.

Linus has said similar things have happened with Linux, but I don't know
details.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kindly show me a better way to do it

2010-05-08 Thread Lie Ryan
On 05/09/10 07:09, Günther Dietrich wrote:
> 
> Why not this way?
> 
 a = [[1,2,3,4], [5,6,7,8]]
 for i in a:
>  for j in i:
>  print(j)
>  
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 
> Too simple?

IMHO that's more complex due to the nested loop, though I would
personally do it as:

a = [ [1,2,3,4], [5,6,7,8] ]
from itertools import chain
for i in chain.from_iterable(a):
print i

so it won't choke when 'a' is an infinite stream of iterables.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 16:39:33 -0700, Carl Banks wrote:

> GPL is about fighting a holy war against commercial software.


Much GPL software *is* commercial software. Given that you're so badly 
misinformed about the GPL that you think it can't be commercial, why 
should we pay any attention to your opinions about it?



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


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 13:46:59 -0700, Mark Dickinson wrote:

>> However, s[:-len(t)] should be both faster and correct.
> 
> Unless len(t) == 0, surely?

Doh! The hazards of insufficient testing. Thanks for catching that.



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


Re: Picking a license

2010-05-08 Thread Patrick Maupin
On May 8, 11:36 pm, Paul Rubin  wrote:
> a...@pythoncraft.com (Aahz) writes:
> > What does your argument claim about Apache?
>
> No idea.  I don't have the impression the developer communities are
> really similar, and Apache httpd doesn't have all that many developers
> compared with something like Linux (I don't know what happens if you add
> all the sister projects like Lucene).
>
> I do know that the GPL has gotten companies to release major GCC
> improvements that they would have preferred to make proprietary if
> they'd had the option.  That includes G++.

Absolutely, and as Aahz acknowledges, RMS was a pioneer in introducing
people to the concept of free software.  But fast forward to today,
and as ESR points out, the FOSS development model is so superior for
many classes of software that proprietary companies contribute to free
software even when they don't have to, and are working hard to support
hybrid models that the GPL doesn't support.  See, for example, Apple's
support of BSD, Webkit, and LLVM.  Apple is not a "do no evil"
corporation, and their contributions back to these packages are driven
far more by hard-nosed business decisions than by any expectation of
community goodwill.

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


Re: Picking a license

2010-05-08 Thread Patrick Maupin
On May 8, 11:29 pm, Paul Rubin  wrote:

> No it doesn't (not like the above).  You, the licensee under the GPL,
> can make those combinations and use them as much as you want on your own
> computers.  You just can't distribute the resulting derivative to other
> people.  With proprietary software you can't redistribute the software
> to other people from day zero (or even use more copies within your own
> company than you've paid for), regardless of whether you've combined it
> with anything.  And since you usually don't get the source code, it's
> awfully hard to make derived combinatoins.

But the point is that a lot of small developers who are writing
software don't need to distribute any software other than software
they wrote themselves.  Their customers will have Oracle/Microsoft/IBM/
CA/whatever licenses already.  Companies like Oracle support various
APIs that allow custom software to be connected to their software, so
if Carl is writing stuff to support Oracle, he can just distribute his
software to the customer, and let the customer link it himself.

Now when Carl's software links to GPLed software, it gets
interesting.  Although it's probably a legal overreach, the FSF often
attempts to claim that software like Carl's, *by itself*, must be
licensed under the GPL, simply because it can link to GPLed software,
even if it doesn't actually contain any GPLed software.  (Whether it's
a legal overreach or not, it's the position of the FSF, and of a lot
of authors who use the GPL, so morally it's probably best to follow
their wishes.)

The end result is that Carl can deliver software to his customer that
lets the customer link Oracle and Microsoft software together, for
example, but is prohibited from delivering software that lets the
customer link GPLed code to Oracle code, because the FSF considers
that software that would do that is a "derived work" and that Carl is
making a distribution when he gives it to his customer, and he is not
allowed to distribute GPLed code that links to proprietary Oracle
code.

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


Re: [ANN] Leipzig Python User Group - Meeting, May 11, 2010, 08:00pm

2010-05-08 Thread Eric Stechmann


On May 7, 2010, at 11:00 AM, Stefan Schwarzer wrote:


=== Leipzig Python User Group ===

We will meet on Tuesday, May 11, 8:00 pm at the training
center of Python Academy in Leipzig, Germany
( http://www.python-academy.com/center/find.html ).

Julian Moritz will give a talk about CouchDB.

Food and soft drinks are provided. Please send a short
confirmation mail to i...@python-academy.de, so we can prepare
appropriately.

Everybody who uses Python, plans to do so or is interested in
learning more about the language is encouraged to participate.

While the meeting language will be mainly German, we will provide
English translation if needed.

Current information about the meetings are at
http://www.python-academy.com/user-group .

Stefan


== Leipzig Python User Group ===

Wir treffen uns am Dienstag, 11.05.2010 um 20:00 Uhr
im Schulungszentrum der Python Academy in Leipzig
( http://www.python-academy.de/Schulungszentrum/anfahrt.html ).

Julian Moritz hält einen Vortrag über CouchDB.

Für das leibliche Wohl wird gesorgt. Eine Anmeldung unter
i...@python-academy.de wäre nett, damit wir genug Essen
besorgen können.

Willkommen ist jeder, der Interesse an Python hat, die Sprache
bereits nutzt oder nutzen möchte.

Aktuelle Informationen zu den Treffen sind unter
http://www.python-academy.de/User-Group zu finden.

Viele Grüße
Stefan















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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


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


Re: Cross-platform file paths

2010-05-08 Thread Wolfgang Rohdewald
On Sonntag 09 Mai 2010, Tim Roberts wrote:
> No.  On Linux, you need to mount the share in some empty
> directory (using mount or smbmount), then read the files from
> that directory.

actually the mount directory does not have to be empty - whatever
it contains is invisible while someting is mounted in it. But
of course using an empty directory gets you less surprises.

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


Openings at Aspire Systems, Chennai. (Product Dev. Company)

2010-05-08 Thread Nathas
Hi All,

Please find below the openings at Aspire Systems, Chennai (www.aspiresys.com)

1. Testing - Selenium, TestComplete, RFT, Manual - SSE and Engineers - 2 + years

2. Java, Swings - Project Leader Position – 5+ years

3. Java, J2EE – Enngineer, SSE, Tech Arch – 2+ Yrs

4. .NET - SSE and Tech Architect – 3+ years

5. Silverlight, Sharepoint - Engineer, SSE – 2+ yrs

6. PHP, Python, RoR, Great Plains - Engineer, SSE – 2+ yrs
 
7. UI Developer - 2+ years

8. Sales - Sr. Exe. – 3+ yrs

Kindly circulate with your friends and do forward your / your friend's resume 
to the below email id.

nagarajan.gane...@aspiresys.com


Thanks,
Nagarajan.


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


Re: Picking a license

2010-05-08 Thread Paul Rubin
a...@pythoncraft.com (Aahz) writes:
> What does your argument claim about Apache?

No idea.  I don't have the impression the developer communities are
really similar, and Apache httpd doesn't have all that many developers
compared with something like Linux (I don't know what happens if you add
all the sister projects like Lucene).

I do know that the GPL has gotten companies to release major GCC
improvements that they would have preferred to make proprietary if
they'd had the option.  That includes G++.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Paul Rubin
Carl Banks  writes:
> If a commercial developer has a EULA that prevents users from
> combining their tools with tools from (say) their competitors, 

Do you mean something like a EULA that stops you from buying a copy of
Oracle and combining it with tools from IBM on the computer that you
install Oracle on?  Those EULAs exist but are not remotely comparable to
the GPL.

> The GPL does exactly that,

No it doesn't (not like the above).  You, the licensee under the GPL,
can make those combinations and use them as much as you want on your own
computers.  You just can't distribute the resulting derivative to other
people.  With proprietary software you can't redistribute the software
to other people from day zero (or even use more copies within your own
company than you've paid for), regardless of whether you've combined it
with anything.  And since you usually don't get the source code, it's
awfully hard to make derived combinatoins.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread dasacc22
On May 8, 2:46 pm, Steven D'Aprano  wrote:
> On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote:
> > On 8 Mai, 20:46, Steven D'Aprano 
> > wrote:
>
> >> def get_leading_whitespace(s):
> >>     t = s.lstrip()
> >>     return s[:len(s)-len(t)]
>
> >> >>> c = get_leading_whitespace(a)
> >> >>> assert c == leading_whitespace
>
> >> Unless your strings are very large, this is likely to be faster than
> >> any other pure-Python solution you can come up with.
>
> > Returning s[:-1 - len(t)] is faster.
>
> I'm sure it is. Unfortunately, it's also incorrect.
>
> >>> z = "*abcde"
> >>> z[:-1-5]
> ''
> >>> z[:len(z)-5]
>
> '*'
>
> However, s[:-len(t)] should be both faster and correct.
>
> --
> Steven

This is without a doubt faster and simpler then any solution thus far.
Thank you for this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Aahz
In article <7xtyqhu5sg@ruckus.brouhaha.com>,
Paul Rubin   wrote:
>
>I don't know if it counts as a moral hazard but some programmers simply
>don't want to do proprietary product development for free.  That's why
>Linux (GPL) has far more developers (and consequentially far more
>functionality and more users) than the free versions of BSD, and GCC
>(GPL) has far more developers than Python.

What does your argument claim about Apache?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Carl Banks
On May 8, 7:58 pm, Paul Rubin  wrote:
> Carl Banks  writes:
> > People who esteem their users give them freedom to use software
> > however they see fit, including combining it with proprietary
> > software.
>
> Huh  That makes no sense at all.  Why should a standard like that be
> expected from free software developers, when it isn't expected from the
> makers of the proprietary software who you're proposing deserve to rake
> in big bucks from locking up other people's work that they didn't pay
> for?

Same thing's true commercial software, Sparky.

If a commercial developer has a EULA that prevents users from
combining their tools with tools from (say) their competitors, they
would be very much disrespecting their users.  The GPL does exactly
that, and people who release GPL software disrespect their users just
as much as a commercial entity that requires you not to use competing
products.

But for some reason when someone and inflicts the disrespect of the
GPL on the community they're considered folk heroes.  Bah.


> I've got no problem writing stuff for inclusion in proprietary products.
> But I do that as a professional, which means I expect to get paid for
> it.  And I think you have the "esteem" issue backwards.  Users who
> esteem developers who write and share software for community benefit,
> should not whine and pout that the largesse doesn't extend as far as
> inviting monopolistic corporations to lock it away from further sharing.

In your petty jealous zeal to prevent megacorporations from profiting
off free software, you prevent guys like me from doing useful,
community-focused things like writing extensions for commercial
software that uses GPL-licensed code.  The GPL drives a wedge between
commercial and free software, making it difficult for the two to
coexist.  That is far more detrimental to open source community than
the benefits of making a monopolistic corporation do a little extra
work to avoid having their codebase tainted by GPL.


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


Re: Picking a license

2010-05-08 Thread Paul Rubin
Martin wrote:
>>> I fail to see what is morally wrong with it. When I ,as the author,
>>> share my work to the public, I should have made peace with the fact
>>> that I, for all intends and purposes, lost control over its use.

Robert Kern  writes:
> Martin is not saying that you *ought* to release your code under a
> liberal license. He is only saying that he does not believe he is
> inviting moral hazard when *he* decides to release *his* code under a
> liberal license. He was responding to Steven who was claiming
> otherwise.

As I read it, he is saying that when someone releases free software,
they have "for all intends and purposes lost control over its use", so
they "should have made peace with the fact" and surrender gracefully.
I'm asking why he doesn't think Microsoft has lost control the same way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread dasacc22
On May 8, 5:18 pm, Patrick Maupin  wrote:
> On May 8, 1:16 pm, dasacc22  wrote:
>
>
>
>
>
> > On May 8, 12:59 pm, Patrick Maupin  wrote:
>
> > > On May 8, 12:19 pm, dasacc22  wrote:
>
> > > > Hi
>
> > > > This is a simple question. I'm looking for the fastest way to
> > > > calculate the leading whitespace (as a string, ie '    ').
>
> > > > Here are some different methods I have tried so far
> > > > --- solution 1
>
> > > > a = '    some content\n'
> > > > b = a.strip()
> > > > c = ' '*(len(a)-len(b))
>
> > > > --- solution 2
>
> > > > a = '    some content\n'
> > > > b = a.strip()
> > > > c = a.partition(b[0])[0]
>
> > > > --- solution 3
>
> > > > def get_leading_whitespace(s):
> > > >     def _get():
> > > >         for x in s:
> > > >             if x != ' ':
> > > >                 break
> > > >             yield x
> > > >     return ''.join(_get())
>
> > > > ---
>
> > > > Solution 1 seems to be about as fast as solution 2 except in certain
> > > > circumstances where the value of b has already been determined for
> > > > other purposes. Solution 3 is slower due to the function overhead.
>
> > > > Curious to see what other types of solutions people might have.
>
> > > > Thanks,
> > > > Daniel
>
> > > Well, you could try a solution using re, but that's probably only
> > > likely to be faster if you can use it on multiple concatenated lines.
> > > I usually use something like your solution #1.  One thing to be aware
> > > of, though, is that strip() with no parameters will strip *any*
> > > whitespace, not just spaces, so the implicit assumption in your code
> > > that what you have stripped is spaces may not be justified (depending
> > > on the source data).  OTOH, depending on how you use that whitespace
> > > information, it may not really matter.  But if it does matter, you can
> > > use strip(' ')
>
> > > If speed is really an issue for you, you could also investigate
> > > mxtexttools, but, like re, it might perform better if the source
> > > consists of several batched lines.
>
> > > Regards,
> > > Pat
>
> > Hi,
>
> > thanks for the info. Using .strip() to remove all whitespace in
> > solution 1 is a must. If you only stripped ' ' spaces then line
> > endings would get counted in the len() call and when multiplied
> > against ' ', would produce an inaccurate result. Regex is
> > significantly slower for my purposes but ive never heard of
> > mxtexttools. Even if it proves slow its spurred my curiousity as to
> > what functionality it provides (on an unrelated note)
>
> Could you reorganize your code to do multiple lines at a time?  That
> might make regex competitive.
>
> Regards,
> Pat

I have tried this already, the problem here is that it's not a trivial
matter. Iterating over each line is unavoidable, and I found that
using various python builtins to perform string operations (like say
the wonderful partition builtin) during each iteration works 3 fold
faster then regexing the entire document with various needs. Another
issue is having to keep a line count and when iterating over regex
matches and counting lines, it doesn't scale nearly as well as a
straight python solution using builtins to process the information.

At the heart of this here, determining the leading white-space is a
trivial matter. I have much more complex problems to deal with. I was
much more interested in seeing what kind of solutions ppl would come
up with to such a problem, and perhaps uncover something new in python
that I can apply to a more complex problem. What spurred the thought
was this piece written up by guido concerning "what's the best way to
convert a list of integers into a string". It's a simple question
where concepts are introduced that can lead to solving more complex
problems.

http://www.python.org/doc/essays/list2str.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing superclass methods from subclass

2010-05-08 Thread Chris Rebert
> On May 8, 7:05 pm, Chris Rebert  wrote:
>> On Sat, May 8, 2010 at 4:50 PM, ben  wrote:
>> > Why doesn't this work:
>>
>> > class C1:
>> >    def f1(self):
>> >        print("f1")
>>
>> > class C2(C1):
>> >    f1()
>>
>> > It throws this error:
>>
>> > Traceback (most recent call last):
>> >  File "./c1.py", line 7, in 
>> >    class C2(C1):
>> >  File "./c1.py", line 8, in C2
>> >    f1()
>> > NameError: name 'f1' is not defined
>>
>> > f1() is an attribute of class C1, C2 inherits C1, so why can't it see
>> > it?
>>
>> The way classes work in Python, C2 isn't actually created until after
>> its body suite has been executed, so that's why Python can't find f1.
>>
>> Additionally, it makes no sense to call an *instance* method such as
>> f1() in a class context. Or in Java-speak: you can't call a non-static
>> method in a static context.
On Sat, May 8, 2010 at 8:24 PM, ben  wrote:
> Ok, thanks for the info.
>
> What would be a better way to do this?  What I'm trying to do is treat
> things in a reasonable OOP manner (all fairly new to me, esp. in
> Python).  Here's a made-up example with a little more context.  Let's
> say you're making a drawing program that can draw various shapes.  So
> in the interest of not repeating oneself, I want a class Shape that
> handles everything that shapes have, such as a color, and a location.
> Then I can subclass Shape to create Square, which has code specific to
> drawing a square (e.g. 4 equal sides).  So, like this:
>
> class Shape:
>
>x = 0
>y = 0
>
>def setColor(self,color):
>self.color = color
>
>def setLocation(self,x,y):
>self.x = x
>self.y = y
>
>def getLocation(self):
>return [self.x,self.y]
>
> class Square(Shape):
>
>size = 0
>
>def __init__(self,size):
>self.size = size
>
>def draw(self):
>location = getLocation()
># code to draw shape from location[0],location[1] at size size
># etc...
>
> It seems to me that you would want the location code handled in the
> Shape class so that I'm not rewriting it for Circle, Triangle, etc.,
> but I'm not allowed to call any of those methods from the subclass.  I
> must be thinking of this in the wrong way.  Help?

Your code suggests you need to read a tutorial on Python's
object-oriented features. The relevant part of Python's official
tutorial is http://docs.python.org/tutorial/classes.html

For starters, Python is not Java and getters/setters are not usually
necessary nor Pythonic; see
http://dirtsimple.org/2004/12/python-is-not-java.html
Secondly, Python does not have instance variable declarations; doing
`x = 0` at the class-level creates a static/class variable, it *does
not* declare an instance variable.
Thirdly, to call an instance method such as getLocation, you need to
specify the receiver, i.e. `self.getLocation()`, not merely
`getLocation()`

Here is how I would rewrite your example:

class Shape(object):
def __init__(self, x=0, y=0):
self.x = x
self.y = y

@property
def location(self):
return (self.x, self.y)

@location.setter
def location(self, val):
   self.x, self.y = val

class Square(Shape):
   def __init__(self,size):
   super(Square, self).__init__()
   self.size = size

   def draw(self):
   x, y = self.location
   # code to draw shape from location[0],location[1] at size size
   # etc...


This uses some minor magic involving property(), see
http://docs.python.org/library/functions.html#property for how that
works.

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


Re: Picking a license

2010-05-08 Thread Robert Kern

On 2010-05-08 22:12 , Paul Rubin wrote:

Steven D'Aprano  writes:

For the record, I've published software under an MIT licence because I
judged the cost of the moral hazard introduced by encouraging freeloaders
to be less than the benefits of having a more permissive licence that
encourages freeloading and therefore attracts more users. For other
software, I might judge that the cost/benefit ratio falls in a different
place, and hence choose the GPL.


I don't know if it counts as a moral hazard but some programmers simply
don't want to do proprietary product development for free.  That's why
Linux (GPL) has far more developers (and consequentially far more
functionality and more users) than the free versions of BSD, and GCC
(GPL) has far more developers than Python.


Post hoc ergo propter hoc? Show me some controlled studies demonstrating that 
this is actually the causative agent in these cases, then maybe I'll believe you.


--
Robert Kern

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

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


Re: Picking a license

2010-05-08 Thread Robert Kern

On 2010-05-08 22:03 , Paul Rubin wrote:

"Martin P. Hellwig"  writes:

I fail to see what is morally wrong with it. When I ,as the author,
share my work to the public, I should have made peace with the fact
that I, for all intends and purposes, lost control over its use.


Does the same thing apply to Microsoft?  If I get a copy of MS Office,
do you think I should be able to incorporate its code into my own
products for repackaging and sale any way that I want, without their
having any say?  If not, why should Microsoft be entitled to do that
with software that -I- write?


Martin is not saying that you *ought* to release your code under a liberal 
license. He is only saying that he does not believe he is inviting moral hazard 
when *he* decides to release *his* code under a liberal license. He was 
responding to Steven who was claiming otherwise.



Is there something in the water making
people think these inequitable things?


Is there something in the water making people think that every statement of 
opinion about how one licenses one's own code is actually an opinion about how 
everyone should license their code?



If Microsoft's licenses are
morally respectable then so is the GPL.


Martin is not saying that the GPL is not morally respectable.

--
Robert Kern

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

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


A more general solution

2010-05-08 Thread 3Jane
You could interpret [[1,2,3,4],[5,6,7,8]] as a tree and
your task as traversal of its leaves. All solutions before
would not work with trees with bigger height.

Here is how to traverse such trees recursively:

def eventualPrint(x):
for v in x:
if isinstance(v, list): eventualPrint(x)
else: print(v)

Then eventualPrint(a) does the job. This would
only cope with lists as proper nodes. More
general tests than isinstance() could be tried,

hasattr(x, 'getitem')

would match all sequence types for example.
Also "for v in x:" should perhaps tested for
exceptions. Optimal directives for both
alternatives depend on the scope of the code's
purpose.

As often the price for generality is performance
here.

Good luck, Joost
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing superclass methods from subclass

2010-05-08 Thread ben
Ok, thanks for the info.

What would be a better way to do this?  What I'm trying to do is treat
things in a reasonable OOP manner (all fairly new to me, esp. in
Python).  Here's a made-up example with a little more context.  Let's
say you're making a drawing program that can draw various shapes.  So
in the interest of not repeating oneself, I want a class Shape that
handles everything that shapes have, such as a color, and a location.
Then I can subclass Shape to create Square, which has code specific to
drawing a square (e.g. 4 equal sides).  So, like this:

class Shape:

x = 0
y = 0

def setColor(self,color):
self.color = color

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

def getLocation(self):
return [self.x,self.y]

class Square(Shape):

size = 0

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

def draw(self):
location = getLocation()
# code to draw shape from location[0],location[1] at size size
# etc...

It seems to me that you would want the location code handled in the
Shape class so that I'm not rewriting it for Circle, Triangle, etc.,
but I'm not allowed to call any of those methods from the subclass.  I
must be thinking of this in the wrong way.  Help?

thanks!



On May 8, 7:05 pm, Chris Rebert  wrote:
> On Sat, May 8, 2010 at 4:50 PM, ben  wrote:
> > Why doesn't this work:
>
> > class C1:
> >    def f1(self):
> >        print("f1")
>
> > class C2(C1):
> >    f1()
>
> > It throws this error:
>
> > Traceback (most recent call last):
> >  File "./c1.py", line 7, in 
> >    class C2(C1):
> >  File "./c1.py", line 8, in C2
> >    f1()
> > NameError: name 'f1' is not defined
>
> > f1() is an attribute of class C1, C2 inherits C1, so why can't it see
> > it?
>
> The way classes work in Python, C2 isn't actually created until after
> its body suite has been executed, so that's why Python can't find f1.
>
> Additionally, it makes no sense to call an *instance* method such as
> f1() in a class context. Or in Java-speak: you can't call a non-static
> method in a static context.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

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


Re: Picking a license

2010-05-08 Thread Paul Rubin
Steven D'Aprano  writes:
> For the record, I've published software under an MIT licence because I 
> judged the cost of the moral hazard introduced by encouraging freeloaders 
> to be less than the benefits of having a more permissive licence that 
> encourages freeloading and therefore attracts more users. For other 
> software, I might judge that the cost/benefit ratio falls in a different 
> place, and hence choose the GPL.

I don't know if it counts as a moral hazard but some programmers simply
don't want to do proprietary product development for free.  That's why
Linux (GPL) has far more developers (and consequentially far more
functionality and more users) than the free versions of BSD, and GCC
(GPL) has far more developers than Python.  Of course the BSD license
did allow Bill Gates and Steve Jobs to become billionaires off the work
off the developers who actually wrote the Berkeley code and are now
struggling to make their rent.  But at least those developers can be
proud that the Microsoft and Apple DRM empires benefited so much from
their efforts.  THAT's a level of self-sacrifice that I can do without.

Note, "permissive license" is a Microsoft propaganda term from what I
can tell.  "Forbidding forbidden" is how I like to think of the GPL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Paul Rubin
"Martin P. Hellwig"  writes:
> I fail to see what is morally wrong with it. When I ,as the author,
> share my work to the public, I should have made peace with the fact
> that I, for all intends and purposes, lost control over its use.

Does the same thing apply to Microsoft?  If I get a copy of MS Office,
do you think I should be able to incorporate its code into my own
products for repackaging and sale any way that I want, without their
having any say?  If not, why should Microsoft be entitled to do that
with software that -I- write?  Is there something in the water making
people think these inequitable things?  If Microsoft's licenses are
morally respectable then so is the GPL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Paul Rubin
Carl Banks  writes:
> People who esteem their users give them freedom to use software
> however they see fit, including combining it with proprietary
> software.

Huh  That makes no sense at all.  Why should a standard like that be
expected from free software developers, when it isn't expected from the
makers of the proprietary software who you're proposing deserve to rake
in big bucks from locking up other people's work that they didn't pay
for?

I've got no problem writing stuff for inclusion in proprietary products.
But I do that as a professional, which means I expect to get paid for
it.  And I think you have the "esteem" issue backwards.  Users who
esteem developers who write and share software for community benefit,
should not whine and pout that the largesse doesn't extend as far as
inviting monopolistic corporations to lock it away from further sharing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform file paths

2010-05-08 Thread Tim Roberts
utabintarbo  wrote:
>
>Until now, I have used the UNC under Windows (XP) to allow my program
>to access files located on a Samba-equipped *nix box (eg.
>os.path.normpath(r"\\serverFQDN\sharename\dir\filename")). When I try
>to open this file under Linux (Red Hat 5), I get a file not found
>error.
>
>Is there a cross-platform method for accessing files on a network
>share using Python 2.X?

No.  On Linux, you need to mount the share in some empty directory (using
mount or smbmount), then read the files from that directory.

It's kind of odd to use a Windows network protocol to access a Linux file
system from another Linux machine.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Patrick Maupin
On May 8, 8:41 pm, Ben Finney  wrote:
> Patrick Maupin  writes:
> > On May 8, 2:38 pm, Steven D'Aprano  > cybersource.com.au> wrote:
> > > Which brings us back full circle to Ben's position, which you took
> > > exception to.
>
> […]
>
> > To me, the clear implication of the blanket statement that you have to
> > use the GPL if you care at all about users is that anybody who doesn't
> > use the GPL is uncaring.  I think that's a silly attitude […]
>
> Fortunately, neither that silly blanket statement nor its implication
> are represented in any of my messages in this thread.

Hmm, I must have misunderstood this:

"Unless you place such a low value the freedom of your users that
you'd allow proprietary derivatives of your work to remove the
freedoms you've taken care to grant, then you should choose a copyleft
license like the GPL."

To me, placing "such a low value on the freedom of [my] users" sounds
like I'm ready to consign them to slavery or something, so I certainly
originally viewed this as a "blanket" (e.g. unqualified)
"statement" (well, that should be obvious) that I have to use the GPL
"if [I] care at all about [my] users".

> I hope that helps.

Well, perhaps you meant less by your wording of "a low value on the
freedom" than could be read into it, just as Aahz and I meant less by
"forced" than you apparently read into that.  I think we all have more
or less accurate understandings of the differences between GPL and
permissive licenses, but only disagree somewhat on how important the
various features are, and at the end of the day we all come to some
reasonably nuanced view of how to proceed with our projects.

One thing I realized that I didn't cover in my earlier posts is that I
think that for a lot of library-type projects, LGPL v2.1 is a really
fine license, offering a great balance of competing interests.  I view
the new licensing on QT from Nokia (commercial, GPL v3, or LGPL v2.1)
as a good example of a balanced strategy.

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


Re: Picking a license

2010-05-08 Thread Ben Finney
a...@pythoncraft.com (Aahz) writes:

> In article ,
> Carl Banks   wrote:
> >
> >GPL is about fighting a holy war against commercial software.
>
> And really, that's a Good Thing. We wouldn't have Python, to some
> extent, were it not for Stallman and his crusade. That doesn't mean we
> should slavishly worship him, though.

+1.

-- 
 \ “A child of five could understand this. Fetch me a child of |
  `\  five.” —Groucho Marx |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Ben Finney
Patrick Maupin  writes:

> On May 8, 2:38 pm, Steven D'Aprano  cybersource.com.au> wrote:
> > Which brings us back full circle to Ben's position, which you took
> > exception to.
[…]

> To me, the clear implication of the blanket statement that you have to
> use the GPL if you care at all about users is that anybody who doesn't
> use the GPL is uncaring.  I think that's a silly attitude […]

Fortunately, neither that silly blanket statement nor its implication
are represented in any of my messages in this thread.

I hope that helps.

-- 
 \ “I've always wanted to be somebody, but I see now that I should |
  `\   have been more specific.” —Jane Wagner, via Lily Tomlin |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Aahz
In article ,
Carl Banks   wrote:
>
>GPL is about fighting a holy war against commercial software.

And really, that's a Good Thing.  We wouldn't have Python, to some
extent, were it not for Stallman and his crusade.  That doesn't mean we
should slavishly worship him, though.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing superclass methods from subclass

2010-05-08 Thread MRAB

ben wrote:

Why doesn't this work:

class C1:
def f1(self):
print("f1")

class C2(C1):
f1()


It throws this error:

Traceback (most recent call last):
  File "./c1.py", line 7, in 
class C2(C1):
  File "./c1.py", line 8, in C2
f1()
NameError: name 'f1' is not defined


f1() is an attribute of class C1, C2 inherits C1, so why can't it see
it?


Name lookup works differently from some other languages. You need to be
explicit and tell it where 'f1' is defined:

C1.f1()

However, that will raise a different exception. I don't know what you're
trying to do.
--
http://mail.python.org/mailman/listinfo/python-list


Re: accessing superclass methods from subclass

2010-05-08 Thread Chris Rebert
On Sat, May 8, 2010 at 4:50 PM, ben  wrote:
> Why doesn't this work:
>
> class C1:
>    def f1(self):
>        print("f1")
>
> class C2(C1):
>    f1()
>
>
> It throws this error:
>
> Traceback (most recent call last):
>  File "./c1.py", line 7, in 
>    class C2(C1):
>  File "./c1.py", line 8, in C2
>    f1()
> NameError: name 'f1' is not defined
>
>
> f1() is an attribute of class C1, C2 inherits C1, so why can't it see
> it?

The way classes work in Python, C2 isn't actually created until after
its body suite has been executed, so that's why Python can't find f1.

Additionally, it makes no sense to call an *instance* method such as
f1() in a class context. Or in Java-speak: you can't call a non-static
method in a static context.

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


accessing superclass methods from subclass

2010-05-08 Thread ben
Why doesn't this work:

class C1:
def f1(self):
print("f1")

class C2(C1):
f1()


It throws this error:

Traceback (most recent call last):
  File "./c1.py", line 7, in 
class C2(C1):
  File "./c1.py", line 8, in C2
f1()
NameError: name 'f1' is not defined


f1() is an attribute of class C1, C2 inherits C1, so why can't it see
it?

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


Re: Picking a license

2010-05-08 Thread Carl Banks
On May 6, 4:56 pm, Ben Finney  wrote:
> a...@pythoncraft.com (Aahz) writes:
> > In article <4be05d75.7030...@msn.com>,
> > Rouslan Korneychuk   wrote:
>
> > >The only question I have now is what about licensing? Is that
> > >something I need to worry about? Should I go with LGPL, MIT, or
> > >something else?
>
> > Which license you use depends partly on your political philosophy.
>
> Yes.
>
> Unless you place such a low value the freedom of your users that you'd
> allow proprietary derivatives of your work to remove the freedoms you've
> taken care to grant, then you should choose a copyleft license like the
> GPL.

GPL is about fighting a holy war against commercial software.

People who esteem their users give them freedom to use software
however they see fit, including combining it with proprietary
software.

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


Re: how to play a sound file repeatedly in loop

2010-05-08 Thread MRAB

varnikat t wrote:


How to run sound file repeatedly in loop ?

When I do this, it does nothing and terminates:

import pygst
pygst.require("0.10")
import gst, gtk


n=0

while n<10:
player = gst.element_factory_make("playbin2", "player")
player.set_property("uri", "file:/home/varnika/hello.ogg")
player.set_state(gst.STATE_PLAYING)
n=n+1


It's not doing nothing, it's repeatedly making a player, starting it,
and then on the next iteration making another player and starting it.

The line:

player.set_state(gst.STATE_PLAYING)

doesn't wait until the sound file has finished before returning.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Kindly show me a better way to do it

2010-05-08 Thread Nathan Rice
itertools is also written in c, so if you're working with a big nested list
is long it will be a lot faster.

On Sat, May 8, 2010 at 5:40 PM, Tycho Andersen  wrote:

> On Sat, May 8, 2010 at 4:09 PM, Günther Dietrich
>  wrote:
> [snip]
> > Too simple?
>
> No, not at all. I really only intended to point the OP to itertools,
> because it does lots of useful things exactly like this one.
>
> \t
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Patrick Maupin
On May 8, 1:16 pm, dasacc22  wrote:
> On May 8, 12:59 pm, Patrick Maupin  wrote:
>
>
>
> > On May 8, 12:19 pm, dasacc22  wrote:
>
> > > Hi
>
> > > This is a simple question. I'm looking for the fastest way to
> > > calculate the leading whitespace (as a string, ie '    ').
>
> > > Here are some different methods I have tried so far
> > > --- solution 1
>
> > > a = '    some content\n'
> > > b = a.strip()
> > > c = ' '*(len(a)-len(b))
>
> > > --- solution 2
>
> > > a = '    some content\n'
> > > b = a.strip()
> > > c = a.partition(b[0])[0]
>
> > > --- solution 3
>
> > > def get_leading_whitespace(s):
> > >     def _get():
> > >         for x in s:
> > >             if x != ' ':
> > >                 break
> > >             yield x
> > >     return ''.join(_get())
>
> > > ---
>
> > > Solution 1 seems to be about as fast as solution 2 except in certain
> > > circumstances where the value of b has already been determined for
> > > other purposes. Solution 3 is slower due to the function overhead.
>
> > > Curious to see what other types of solutions people might have.
>
> > > Thanks,
> > > Daniel
>
> > Well, you could try a solution using re, but that's probably only
> > likely to be faster if you can use it on multiple concatenated lines.
> > I usually use something like your solution #1.  One thing to be aware
> > of, though, is that strip() with no parameters will strip *any*
> > whitespace, not just spaces, so the implicit assumption in your code
> > that what you have stripped is spaces may not be justified (depending
> > on the source data).  OTOH, depending on how you use that whitespace
> > information, it may not really matter.  But if it does matter, you can
> > use strip(' ')
>
> > If speed is really an issue for you, you could also investigate
> > mxtexttools, but, like re, it might perform better if the source
> > consists of several batched lines.
>
> > Regards,
> > Pat
>
> Hi,
>
> thanks for the info. Using .strip() to remove all whitespace in
> solution 1 is a must. If you only stripped ' ' spaces then line
> endings would get counted in the len() call and when multiplied
> against ' ', would produce an inaccurate result. Regex is
> significantly slower for my purposes but ive never heard of
> mxtexttools. Even if it proves slow its spurred my curiousity as to
> what functionality it provides (on an unrelated note)

Could you reorganize your code to do multiple lines at a time?  That
might make regex competitive.

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


Re: Kindly show me a better way to do it

2010-05-08 Thread Tycho Andersen
On Sat, May 8, 2010 at 4:09 PM, Günther Dietrich
 wrote:
[snip]
> Too simple?

No, not at all. I really only intended to point the OP to itertools,
because it does lots of useful things exactly like this one.

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


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread dasacc22
U presume entirely to much. I have a preprocessor that normalizes
documents while performing other more complex operations.  Theres
nothing buggy about what im doing

On May 8, 1:46 pm, Steven D'Aprano  wrote:
> On Sat, 08 May 2010 10:19:16 -0700, dasacc22 wrote:
> > Hi
>
> > This is a simple question. I'm looking for the fastest way to calculate
> > the leading whitespace (as a string, ie '    ').
>
> Is calculating the amount of leading whitespace really the bottleneck in
> your application? If not, then trying to shave off microseconds from
> something which is a trivial part of your app is almost certainly a waste
> of your time.
>
> [...]
>
> > a = '    some content\n'
> > b = a.strip()
> > c = ' '*(len(a)-len(b))
>
> I take it that you haven't actually tested this code for correctness,
> because it's buggy. Let's test it:
>
> >>> leading_whitespace = " "*2 + "\t"*2
> >>> a = leading_whitespace + "some non-whitespace text\n"
> >>> b = a.strip()
> >>> c = " "*(len(a)-len(b))
> >>> assert c == leading_whitespace
>
> Traceback (most recent call last):
>   File "", line 1, in 
> AssertionError
>
> Not only doesn't it get the whitespace right, but it doesn't even get the
> *amount* of whitespace right:
>
> >>> assert len(c) == len(leading_whitespace)
>
> Traceback (most recent call last):
>   File "", line 1, in 
> AssertionError
>
> It doesn't even work correctly if you limit "whitespace" to mean spaces
> and nothing else! It's simply wrong in every possible way.
>
> This is why people say that premature optimization is the root of all
> (programming) evil. Instead of wasting time and energy trying to optimise
> code, you should make it correct first.
>
> Your solutions 2 and 3 are also buggy. And solution 3 can be easily re-
> written to be more straightforward. Instead of the complicated:
>
> > def get_leading_whitespace(s):
> >     def _get():
> >         for x in s:
> >             if x != ' ':
> >                 break
> >             yield x
> >     return ''.join(_get())
>
> try this version:
>
> def get_leading_whitespace(s):
>     accumulator = []
>     for c in s:
>         if c in ' \t\v\f\r\n':
>             accumulator.append(c)
>         else:
>             break
>     return ''.join(accumulator)
>
> Once you're sure this is correct, then you can optimise it:
>
> def get_leading_whitespace(s):
>     t = s.lstrip()
>     return s[:len(s)-len(t)]
>
> >>> c = get_leading_whitespace(a)
> >>> assert c == leading_whitespace
>
> Unless your strings are very large, this is likely to be faster than any
> other pure-Python solution you can come up with.
>
> --
> Steven

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


Re: Kindly show me a better way to do it

2010-05-08 Thread Günther Dietrich
Tycho Andersen  wrote:

>On Sat, May 8, 2010 at 3:41 PM, Oltmans  wrote:
>> Hi, I've a list that looks like following
>>
>> a = [ [1,2,3,4], [5,6,7,8] ]
>>
>> Currently, I'm iterating through it like
>>
>> for i in [k for k in a]:
>>        for a in i:
>>                print a
>>
>> but I was wondering if there is a shorter, more elegant way to do it?
>
>How about itertools? In python 2.6:
>
 a = [ [1,2,3,4], [5,6,7,8] ]
 from itertools import chain
 for i in chain(*a):
>... print i
>...
>1
>2
>3
>4
>5
>6
>7
>8


Why not this way?

>>> a = [[1,2,3,4], [5,6,7,8]]
>>> for i in a:
... for j in i:
... print(j)
... 
1
2
3
4
5
6
7
8

Too simple?



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kindly show me a better way to do it

2010-05-08 Thread superpollo

Oltmans ha scritto:

On May 9, 1:53 am, superpollo  wrote:


add = lambda a,b: a+b
for i in reduce(add,a):
 print i


This is very neat. Thank you. Sounds like magic to me. Can you please
explain how does that work? Many thanks again.



here:

http://tinyurl.com/3xp

and here:

http://tinyurl.com/39kdge5

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


Re: Kindly show me a better way to do it

2010-05-08 Thread Oltmans
On May 9, 1:53 am, superpollo  wrote:

> add = lambda a,b: a+b
> for i in reduce(add,a):
>      print i

This is very neat. Thank you. Sounds like magic to me. Can you please
explain how does that work? Many thanks again.

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


Re: Kindly show me a better way to do it

2010-05-08 Thread Tycho Andersen
On Sat, May 8, 2010 at 3:41 PM, Oltmans  wrote:
> Hi, I've a list that looks like following
>
> a = [ [1,2,3,4], [5,6,7,8] ]
>
> Currently, I'm iterating through it like
>
> for i in [k for k in a]:
>        for a in i:
>                print a
>
> but I was wondering if there is a shorter, more elegant way to do it?

How about itertools? In python 2.6:

>>> a = [ [1,2,3,4], [5,6,7,8] ]
>>> from itertools import chain
>>> for i in chain(*a):
... print i
...
1
2
3
4
5
6
7
8
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kindly show me a better way to do it

2010-05-08 Thread Alain Ketterlin
Oltmans  writes:

> a = [ [1,2,3,4], [5,6,7,8] ]
>
> Currently, I'm iterating through it like
>
> for i in [k for k in a]:
>   for a in i:
>   print a

I would prefer:

for i in a:
for v in i:
print v

i.e., not messing with a and avoiding an additional list.

> but I was wondering if there is a shorter, more elegant way to do it?

I can't see any, but if you need to save space, you may use

for v in (e for l in a for e in l):
...

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


Re: Kindly show me a better way to do it

2010-05-08 Thread superpollo

superpollo ha scritto:

Oltmans ha scritto:

Hi, I've a list that looks like following

a = [ [1,2,3,4], [5,6,7,8] ]

Currently, I'm iterating through it like

for i in [k for k in a]:
for a in i:


i think you used te a identifier for two meanings...


print a

but I was wondering if there is a shorter, more elegant way to do it?



add = lambda a,b: a+b


or:

from operator import add



for i in reduce(add,a):
print i

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


Re: Kindly show me a better way to do it

2010-05-08 Thread Chris Rebert
On Sat, May 8, 2010 at 1:41 PM, Oltmans  wrote:
> Hi, I've a list that looks like following
>
> a = [ [1,2,3,4], [5,6,7,8] ]
>
> Currently, I'm iterating through it like
>
> for i in [k for k in a]:
>        for a in i:
>                print a
>
> but I was wondering if there is a shorter, more elegant way to do it?

Just use a different variable name besides `a` in the nested loop so
you don't have to make the copy of `a`. I arbitrarily chose `b`:

for i in a:
for b in i:
print b

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


Re: Kindly show me a better way to do it

2010-05-08 Thread superpollo

Oltmans ha scritto:

Hi, I've a list that looks like following

a = [ [1,2,3,4], [5,6,7,8] ]

Currently, I'm iterating through it like

for i in [k for k in a]:
for a in i:


i think you used te a identifier for two meanings...


print a

but I was wondering if there is a shorter, more elegant way to do it?



add = lambda a,b: a+b
for i in reduce(add,a):
print i
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Mark Dickinson
On May 8, 8:46 pm, Steven D'Aprano  wrote:
> On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote:
> > On 8 Mai, 20:46, Steven D'Aprano 
> > wrote:
>
> >> def get_leading_whitespace(s):
> >>     t = s.lstrip()
> >>     return s[:len(s)-len(t)]
>
> >> >>> c = get_leading_whitespace(a)
> >> >>> assert c == leading_whitespace
>
> >> Unless your strings are very large, this is likely to be faster than
> >> any other pure-Python solution you can come up with.
>
> > Returning s[:-1 - len(t)] is faster.
>
> I'm sure it is. Unfortunately, it's also incorrect.
>
> >>> z = "*abcde"
> >>> z[:-1-5]
> ''
> >>> z[:len(z)-5]
>
> '*'
>
> However, s[:-len(t)] should be both faster and correct.

Unless len(t) == 0, surely?

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


Kindly show me a better way to do it

2010-05-08 Thread Oltmans
Hi, I've a list that looks like following

a = [ [1,2,3,4], [5,6,7,8] ]

Currently, I'm iterating through it like

for i in [k for k in a]:
for a in i:
print a

but I was wondering if there is a shorter, more elegant way to do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ConfigParser.get() defaults?

2010-05-08 Thread Tim Chase

On 05/08/2010 01:58 PM, Steven D'Aprano wrote:

If your patch doesn't attract the interest of a Python-Dev
developer, you might need to give them a prod occasionally.
Their time for reviewing bugs and patches is always in short
supply.


- where (or to whom) to I submit the patch (and possibly
tests)


Submit the patch and tests to the bug tracker at
http://bugs.python.org/


Okay -- a good first stop, and vastly more helpful than the 
non-reply I got regarding my optparse patch.



- any tests needed/expected?  run how?  internal as an "if
__name__ == '__main__'" block, or an external test suite?


Look at the tests in (e.g.) /usr/local/lib/python2.6/test/ for
an idea of what you should do.


I poked in my Debian analogue (/usr/bin/lib/python2.6/test/) but 
the tests there seemed a bit...um...lacking?  There was nothing 
testing ConfigParser at all, just three high-level test modules. 
 Granted, I could create some tests that exercise my code, and 
perhaps some that should have been there in the first place, but 
that's a big jump from merely adding a couple tests (non)existing 
ConfigParser tests.



Because this is a new feature, and 2.5 (and 2.6?) are in bug fix only
mode, you should probably aim for 2.7 or 3.2 as the ideal. Patches
written against 2.6 or 3.1 are probably good enough though.


Okay, I've submitted the patch to dev.python.org in the hopes 
something comes of it, even if it's 2.7 or 3.2



That's what I thought you meant. Forking is the right term in this case
(you are forking the ConfigParser module, not all of Python), and I still
say it is overkill. Generally speaking, when a module doesn't do what you
want, and modifying it isn't an option, there are five things you can do.
In order of decreasing desirability:

(1) Write a small wrapper function to tweak the behaviour.

(2) Sub-class the class to gain new behaviour.

(3) Monkey-patch the module at runtime.

(4) Fork the module and modify that.

(5) Re-write the whole thing from scratch.


I'd say the ordering of your #3 and #4 are more ambiguous -- if 
I'm distributing/deploying a project and my monkey-patching gets 
broken (there's a reason monkey-patching feels dirty) by some 
python lib upgrade external to my control, then I & my code look 
bad.  If I freeze a modified/locally-forked library module, it 
continues to work regardless of the environment.  Maybe that's an 
indicator that I did a bad job of monkey patching, but I prefer 
to prevent breakage where I can.


-tkc


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


Re: Picking a license

2010-05-08 Thread Patrick Maupin
On May 8, 2:38 pm, Steven D'Aprano  wrote:



> I don't think you understand what a moral hazard is. Under no
> circumstances is it a moral hazard to say "If you do X, I will do Y" --
> in this case, "If you obey these restrictions on redistribution, I'll
> licence this copyrighted work to you". Perhaps you should check the
> definition before arguing further that the GPL imposes a moral hazard on
> anyone:
>
> http://en.wikipedia.org/wiki/Moral_hazard

Well, definition is a tricky thing.  Note that the wikipedia article
is disputed.  One definition of moral hazard is "The tendency of a
person or entity that is imperfectly monitored to engage in
undesirable behavior."  Under this definition, Linksys apparently
thought that the imperfect monitoring would let it get away with GPL
violations.  Certainly, even if Linksys as a corporation wasn't trying
to get away with anything, their employees were improperly monitored,
and getting a product out was more important than any potential
copyright violation at the time (which shows there was a moral hazard
their employees took advantage of under either the definition I gave
or the wikipedia definition.)  There are probably other companies (or
employees of those companies) getting away with GPL violations right
now -- certainly the risk of discovery if you just use a small portion
of GPL code and don't distribute your source must be very small.
There are certainly fewer companies getting away with MIT license
violations, simply because the license is so much harder to violate.

> > If I expect nothing in return, if it's
> > a gift, then the likelihood of moral hazard is significantly reduced.
> > Unless you are somehow suggesting that I owe my user's customers
> > anything (which suggestion, btw, is frequently made in veiled terms, and
> > always pisses me off), there is no other moral hazard produced by me
> > choosing a permissive license for my code.
>
> No, you don't *owe* them anything, but this brings us back to Ben's
> original post. If you care about the freedoms of Cisco's customers as
> much as you care about the freedoms of Cisco, then that's a good reason
> to grant those customers the same rights as you granted Cisco.

But I *do* grant them the same rights -- they can come to my site and
download my software!!!

> And let's not forget self-interest -- if you care about *your own
> freedoms*, then it is in your own self-interest to encourage others to
> use open licences rather than closed ones. The MIT licence merely
> encourages openness by example, while the GPL makes it a legal
> requirement.

But I *do* care about my own freedom.  I thought I made that crystal
clear.  If I produce something under the MIT license, it's because I
want to give it away with no strings.  If I produce something under
the GPL (that's not merely a small addendum to a preexisting project),
it's probably going to be because I think it's pretty valuable stuff,
maybe even valuable enough I might be able to make some money with
it.  If I'm going to use any prebuilt components, those *can't* be
licensed under the GPL if I want to deliver the final package under
the MIT license. Even if I'm using the GPL for my valuable software,
my monetization options are more limited if I use a third party
component that is licensed under the GPL, because I now don't have the
viable option of dual-licensing.  So, that gets back to my argument
about what I like to see in a package I use, and how I license things
according to what I would like see.  For me, the golden rule dictates
that when I give a gift of software, I release it under a permissive
license.  I realize that others see this differently.

> Which brings us back full circle to Ben's position, which you took
> exception to. If the global freedoms granted by the GPL are sufficiently
> important to you, then you should use the GPL. If you have other factors
> which are more important, then choose another licence. Why you considered
> this controversial enough to require sarcastic comments about the
> untrustworthiness of Guido and the PSF, I don't know.

To me, the clear implication of the blanket statement that you have to
use the GPL if you care at all about users is that anybody who doesn't
use the GPL is uncaring.  I think that's a silly attitude, and will
always use any tool at hand, including sarcasm, to point out when
other people try to impose their own narrow sense of morality on
others by painting what I perceive to be perfectly normal, moral,
decent, and legal behavior as somehow detrimental to the well-being of
the species (honestly -- ebola???)

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


[ANN] Pyspread 0.1.1 released

2010-05-08 Thread Martin Manns
Pyspread 0.1.1 released
===

I am pleased to announce the new release 0.1.1 of pyspread.

 
About: 
--

Pyspread is a cross-platform Python spreadsheet application. 
It is based on and written in the programming language Python.

Instead of spreadsheet formulas, Python expressions are entered into
the spreadsheet cells. Each expression returns a Python object that can
be accessed from other cells. These objects can represent anything
including lists or matrices.

Pyspread runs on Linux and *nix platforms with GTK support as well as
on Windows (XP and Vista tested). On Mac OS X, some icons are too small
but the application basically works.


Homepage


http://pyspread.sourceforge.net


Changes to 0.1
--

 * Grid is faster.
 * Copying only partly filled cells works now.
 * Cells that get attributes but no string no longer display None.

Enjoy

Martin

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


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote:

> On 8 Mai, 20:46, Steven D'Aprano 
> wrote:
> 
>> def get_leading_whitespace(s):
>>     t = s.lstrip()
>>     return s[:len(s)-len(t)]
>>
>> >>> c = get_leading_whitespace(a)
>> >>> assert c == leading_whitespace
>>
>> Unless your strings are very large, this is likely to be faster than
>> any other pure-Python solution you can come up with.
> 
> Returning s[:-1 - len(t)] is faster.


I'm sure it is. Unfortunately, it's also incorrect.


>>> z = "*abcde"
>>> z[:-1-5]
''
>>> z[:len(z)-5]
'*'


However, s[:-len(t)] should be both faster and correct.


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


Re: Need help with my 1st python program

2010-05-08 Thread Vincent Davis
I think what is not clear by what is being said is that you have passed in
pressure and not 'pressure'. The first is undefined, pressure = 1 would
define it. Where as 'pressure' is a string type.

On Sat, May 8, 2010 at 1:35 PM, Walter Brameld IV <
wb4remove_this_t...@wbrameld4.name> wrote:

> Dave Luzius wrote:
>
>> On Sat, 08 May 2010 19:02:42 +, Steven D'Aprano wrote:
>>
>>  On Sat, 08 May 2010 18:52:33 +, Dave Luzius wrote:
>>>
>>>  Pleaser help me with this. Here's a copy of the program, but it keeps
 calling for me to define pressure.

>>> That's because you haven't defined pressure.
>>>
>>> When Python tells you there is a bug in your program, it is almost
>>> always correct.
>>>
>>>
>>>  # A small program to fetch local barometer reading   from weather.com #
 and convert the value from   metric to imperial. # My first attempt at
 Python.
 #
 import urllib

 # next line does the fetching
 urllib.urlopen("http://xoap.weather.com/weather/local/USMI0060";,
 pressure)

>>> What is pressure? It is an undefined name. Where does pressure get its
>>> value from?
>>>
>>
>> Pressure is a term for barometric pressure, and is understood by Conky,
>> which this program is designed to work with, and is understood by
>> weather.com. But the value it passes to conky is metric, and I want it to
>> display in imperial.
>>
>> What should I do
>>
>
> You're passing in the value of pressure as the 'data' parameter to
> urllib.urlopen.  So...what is the value of pressure?  You haven't assigned
> any value to it before calling urlopen.  Therein lies the problem.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog  |
LinkedIn
-- 
http://mail.python.org/mailman/listinfo/python-list


how to play a sound file repeatedly in loop

2010-05-08 Thread varnikat t
How to run sound file repeatedly in loop ?

When I do this, it does nothing and terminates:

import pygst
pygst.require("0.10")
import gst, gtk


n=0

while n<10:
player = gst.element_factory_make("playbin2", "player")
player.set_property("uri", "file:/home/varnika/hello.ogg")
player.set_state(gst.STATE_PLAYING)
n=n+1

Regards
Varnika Tewari
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with my 1st python program

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 19:13:12 +, Dave Luzius wrote:

>> What is pressure? It is an undefined name. Where does pressure get its
>> value from?
> 
> Pressure is a term for barometric pressure, and is understood by Conky,
> which this program is designed to work with, and is understood by
> weather.com. But the value it passes to conky is metric, and I want it
> to display in imperial.

I know what pressure is in English. What is it in your program? When the 
Python compiler sees the word "pressure", what do you expect it to do?


> What should I do

Perhaps you should start with a few simple tutorials and introductions to 
programming before tackling this program.


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


Re: Need help with my 1st python program

2010-05-08 Thread Benjamin Kaplan
On Sat, May 8, 2010 at 3:13 PM, Dave Luzius  wrote:

>
> Pressure is a term for barometric pressure, and is understood by Conky,
> which this program is designed to work with, and is understood by
> weather.com. But the value it passes to conky is metric, and I want it to
> display in imperial.
>
> What should I do
> --

Don't tell us what pressure is. Tell Python.

>>> urllib.urlopen("http://xoap.weather.com/weather/local/USMI0060";, pressure)

What do you think this line does? Because it does absolutely nothing.
Assuming pressure is defined It creates a file-like object connected
to that URL. But because that file-like object is never assigned to
anything, it's reference count drops to 0 and it's immediately closed
and deleted.

You have to
1) Assign the file-like object to some name.
2) Read the data from the file-like object
3) convert the string you read from the file-like object into a float
4) use the float to do math

Python is succinct, but it isn't magic. Just like every other
programming language, it can't guess what you want it to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 10:14:18 -0700, Patrick Maupin wrote:

> On May 8, 3:37 am, Steven D'Aprano  cybersource.com.au> wrote:
>> On Fri, 07 May 2010 23:40:22 -0700, Patrick Maupin wrote:
>> > Personally, I believe that if anything is false and misleading, it is
>> > the attempt to try to completely change the discussion from MIT vs.
>> > GPL to GPL vs. no license (and thus very few rights for the software
>> > users), after first trying to imply that people who distribute
>> > software under permissive licenses (that give the user *more* rights
>> > than the GPL) are somehow creating a some sort of moral hazard that
>> > might adversely affect their users
>>
>> If encouraging third parties to take open source code and lock it up
>> behind proprietary, closed licences *isn't* a moral hazard, then I
>> don't know what one is.
> 
> For a start, there is a difference between "encouraging" and "allowing".

Finely parsed semantics with a meaningless difference when applied to
what I said in the context of comparing GPL vs. more permissive licenses.


>  But in point of fact, you have it exactly backwards. Putting the code
> out there and making it a tort to republish it under a closed license
> creates a moral hazard -- a trap that many companies including
> Linksys/Cisco have fallen into.  

What? That's crazy talk. You think Linksys and Cisco don't have people 
capable of reading licences? What sort of two-bit organisation do you 
think they are?

They have lawyers, they have people whose job it is to make sure that 
they don't infringe other people's copyright. They wouldn't use software 
copyrighted by Microsoft without making sure they were legally licenced. 
One can only wonder why they thought they didn't need to treat the GPL 
with an equal amount of respect.

Since you raised the analogy of a restaurant giving away freebies, if a 
restaurant stuck a sign on the door saying "Free softdrink with every 
burger", and some Cisco engineer walked in the door and started loading 
up a trolley with cans of drink from the fridge ("they're free, right?"), 
would you argue that this was the restaurant's fault for creating a moral 
hazard?

I don't think you understand what a moral hazard is. Under no 
circumstances is it a moral hazard to say "If you do X, I will do Y" -- 
in this case, "If you obey these restrictions on redistribution, I'll 
licence this copyrighted work to you". Perhaps you should check the 
definition before arguing further that the GPL imposes a moral hazard on 
anyone:

http://en.wikipedia.org/wiki/Moral_hazard


> If I expect nothing in return, if it's
> a gift, then the likelihood of moral hazard is significantly reduced. 
> Unless you are somehow suggesting that I owe my user's customers
> anything (which suggestion, btw, is frequently made in veiled terms, and
> always pisses me off), there is no other moral hazard produced by me
> choosing a permissive license for my code.

No, you don't *owe* them anything, but this brings us back to Ben's 
original post. If you care about the freedoms of Cisco's customers as 
much as you care about the freedoms of Cisco, then that's a good reason 
to grant those customers the same rights as you granted Cisco.

And let's not forget self-interest -- if you care about *your own 
freedoms*, then it is in your own self-interest to encourage others to 
use open licences rather than closed ones. The MIT licence merely 
encourages openness by example, while the GPL makes it a legal 
requirement.

Which brings us back full circle to Ben's position, which you took 
exception to. If the global freedoms granted by the GPL are sufficiently 
important to you, then you should use the GPL. If you have other factors 
which are more important, then choose another licence. Why you considered 
this controversial enough to require sarcastic comments about the 
untrustworthiness of Guido and the PSF, I don't know.



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


Re: Need help with my 1st python program

2010-05-08 Thread Walter Brameld IV

Dave Luzius wrote:

On Sat, 08 May 2010 19:02:42 +, Steven D'Aprano wrote:


On Sat, 08 May 2010 18:52:33 +, Dave Luzius wrote:


Pleaser help me with this. Here's a copy of the program, but it keeps
calling for me to define pressure.

That's because you haven't defined pressure.

When Python tells you there is a bug in your program, it is almost
always correct.



# A small program to fetch local barometer reading   from weather.com #
and convert the value from   metric to imperial. # My first attempt at
Python.
#
import urllib

# next line does the fetching
urllib.urlopen("http://xoap.weather.com/weather/local/USMI0060";,
pressure)

What is pressure? It is an undefined name. Where does pressure get its
value from?


Pressure is a term for barometric pressure, and is understood by Conky, 
which this program is designed to work with, and is understood by 
weather.com. But the value it passes to conky is metric, and I want it to 
display in imperial.


What should I do


You're passing in the value of pressure as the 'data' parameter to 
urllib.urlopen.  So...what is the value of pressure?  You haven't 
assigned any value to it before calling urlopen.  Therein lies the problem.

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


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Wolfram Hinderer
On 8 Mai, 20:46, Steven D'Aprano  wrote:

> def get_leading_whitespace(s):
>     t = s.lstrip()
>     return s[:len(s)-len(t)]
>
> >>> c = get_leading_whitespace(a)
> >>> assert c == leading_whitespace
>
> Unless your strings are very large, this is likely to be faster than any
> other pure-Python solution you can come up with.

Returning s[:-1 - len(t)] is faster.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with my 1st python program

2010-05-08 Thread Dave Luzius
On Sat, 08 May 2010 19:02:42 +, Steven D'Aprano wrote:

> On Sat, 08 May 2010 18:52:33 +, Dave Luzius wrote:
> 
>> Pleaser help me with this. Here's a copy of the program, but it keeps
>> calling for me to define pressure.
> 
> That's because you haven't defined pressure.
> 
> When Python tells you there is a bug in your program, it is almost
> always correct.
> 
> 
>> # A small program to fetch local barometer reading   from weather.com #
>> and convert the value from   metric to imperial. # My first attempt at
>> Python.
>> #
>> import urllib
>> 
>> # next line does the fetching
>> urllib.urlopen("http://xoap.weather.com/weather/local/USMI0060";,
>> pressure)
> 
> What is pressure? It is an undefined name. Where does pressure get its
> value from?

Pressure is a term for barometric pressure, and is understood by Conky, 
which this program is designed to work with, and is understood by 
weather.com. But the value it passes to conky is metric, and I want it to 
display in imperial.

What should I do
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with my 1st python program

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 18:52:33 +, Dave Luzius wrote:

> Pleaser help me with this. Here's a copy of the program, but it keeps
> calling for me to define pressure.

That's because you haven't defined pressure.

When Python tells you there is a bug in your program, it is almost always 
correct.


> # A small program to fetch local barometer reading   from weather.com 
> # and convert the value from   metric to imperial.
> # My first attempt at Python.
> #
> import urllib
> 
> # next line does the fetching
> urllib.urlopen("http://xoap.weather.com/weather/local/USMI0060";,
> pressure)

What is pressure? It is an undefined name. Where does pressure get its 
value from?





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


Re: ConfigParser.get() defaults?

2010-05-08 Thread Steven D'Aprano
On Fri, 07 May 2010 20:46:47 -0500, Tim Chase wrote:

> On 05/07/2010 07:56 PM, Steven D'Aprano wrote:
>> On Fri, 07 May 2010 15:05:53 -0500, Tim Chase wrote:
>>> With a normal dictionary, I can specify a default fallback value in
>>> the event the requested key isn't present:
>> [...]
>>> However, with the ConfigParser object, there doesn't seem to be any
>>> way to do a similar
>>
>> Sounds like a nice feature to have. When you submit a patch (*grin*),
> 
> I'm game to create and provide a patch, though I've had no success in
> the past trying to push tweaks into the Python Core (adding a subclass
> of optparse.HelpFormatter that respects newlines for text-wrapping).


If your patch doesn't attract the interest of a Python-Dev developer, you 
might need to give them a prod occasionally. Their time for reviewing 
bugs and patches is always in short supply.


 
> But if there's a straightforward way to do this, I'd love to patch the
> file and submit the deltas.  I just need to know
> 
> - what sort of patch (unified diff, context diff, ed)
> 
> - against which version?  I'm currently running the 2.5 that Debian
> Testing defaults to, though I have 2.6 available through my repository.
> 
> - any tests needed/expected?  run how?  internal as an "if __name__ ==
> '__main__'" block, or an external test suite?
> 
> - where (or to whom) to I submit the patch (and possibly tests)

Submit the patch and tests to the bug tracker at http://bugs.python.org/

Look at the tests in (e.g.) /usr/local/lib/python2.6/test/ for an idea of 
what you should do.

Because this is a new feature, and 2.5 (and 2.6?) are in bug fix only 
mode, you should probably aim for 2.7 or 3.2 as the ideal. Patches 
written against 2.6 or 3.1 are probably good enough though.

And you want a unified diff.

See also: http://www.python.org/dev/patches/



>> please make sure the caller can specify what to do on missing section
>> and missing option independently.
> 
> Could you detail what you envision here?  For my use case, it's that the
> option doesn't exist, whether because there's no section, or there's a
> section but no option.  Either way, something failed and I want a
> default value back.  I don't have a mental model of what you expect in
> the "section exists but no option" that would behave differently from
> the "section doesn't exist" case.
> 
> Do you also have suggestions for how it should interact with the weird
> [DEFAULT] section oddities (that don't really seem to default the way I
> expect them to)?
> 
> Perhaps the two interrelate?

I haven't really given it any detailed thought, but what I was thinking 
was something like:

config.set_missing_section("FOO")
config.set_missing_value("missing")

Then if you ask for the value of key 'x' in section BAR, and BAR doesn't 
exist, then 'x' is looked up in FOO instead; if 'x' doesn't exist there 
either, then "missing" is returned. If section BAR *does* exist, but 'x' 
doesn't, then "missing" is also returned.


 
>>> I've thumbed through the source to ConfigParser.py but don't see any
>>> indication that it's possible to do what I'd like short of wrapping
>>> all my cp.get*() calls in try/except blocks or creating a forked
>>> version of ConfigParser.py locally.  Is there anything I'm missing, or
>>> a better workaround to this?
>>
>> Don't fork the source code, that's ridiculously overkill. Subclass
>> ConfigParser and add the required functionality.
> 
> Sorry for such loaded terms -- my "forking" suggestion wasn't intended
> to be Python, the Tim Version(tm), but rather, "copy the ConfigParser.py
> into my project directory, make the edits I need/want, and have it
> available to my project" (something similar to what I did for one of my
> projects copying in the python2.6 zipfile.py to my python2.4 code-base
> to supersede the standard 2.4 library's zipfile.py).

That's what I thought you meant. Forking is the right term in this case 
(you are forking the ConfigParser module, not all of Python), and I still 
say it is overkill. Generally speaking, when a module doesn't do what you 
want, and modifying it isn't an option, there are five things you can do. 
In order of decreasing desirability:

(1) Write a small wrapper function to tweak the behaviour.

(2) Sub-class the class to gain new behaviour.

(3) Monkey-patch the module at runtime.

(4) Fork the module and modify that.

(5) Re-write the whole thing from scratch.




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


[RELEASED] Python 2.7 beta 2

2010-05-08 Thread Benjamin Peterson
On behalf of the Python development team, I'm elated to announce the second beta
release of Python 2.7.

Python 2.7 is scheduled (by Guido and Python-dev) to be the last major version
in the 2.x series.  2.7 will have an extended period of bugfix maintenance.

2.7 includes many features that were first released in Python 3.1.  The faster
io module, the new nested with statement syntax, improved float repr, set
literals, dictionary views, and the memoryview object have been backported from
3.1. Other features include an ordered dictionary implementation, unittests
improvements, a new sysconfig module, and support for ttk Tile in Tkinter.  For
a more extensive list of changes in 2.7, see
http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python
distribution.

To download Python 2.7 visit:

 http://www.python.org/download/releases/2.7/

While this is a development release and is thus not suitable for production use,
we encourage Python application and library developers to test the release with
their code and report any bugs they encounter to:

 http://bugs.python.org/

2.7 documentation can be found at:

 http://docs.python.org/2.7/


Enjoy!

--
Benjamin Peterson
2.7 Release Manager
benjamin at python.org
(on behalf of the entire python-dev team and 2.7's contributors)
-- 
http://mail.python.org/mailman/listinfo/python-list


Need help with my 1st python program

2010-05-08 Thread Dave Luzius
Pleaser help me with this. Here's a copy of the program, but it keeps 
calling for me to define pressure.

# A small program to fetch local barometer reading   from weather.com   
# and convert the value from   metric to 
imperial.  
# My first attempt at Python.   
#
import urllib

# next line does the fetching
urllib.urlopen("http://xoap.weather.com/weather/local/USMI0060";, pressure)

# next line does the conversion to imperial
imppress = 0.029875 * float(pressure)

  # next line shows the results.  
print imppress

as you can see, I'm stuck on what should be relatively simple.
TIA, Dave
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 10:08:08 -0400, Alex Hall wrote:

> Hi all,
> I am sorry if this is the second message about this you get; I typed
> this and hit send (on gmail website) but I got a 404 error, so I am not
> sure if the previous message made it out or not. Anyway, I have about
> fifteen vars in a function which have to be global. Is there a faster
> and more space-efficient way of doing this than putting each var on its
> own line; that is, fifteen "global varName" declarations? Thanks.

global google, for_, global_, variables, considered, harmful



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


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 10:19:16 -0700, dasacc22 wrote:

> Hi
> 
> This is a simple question. I'm looking for the fastest way to calculate
> the leading whitespace (as a string, ie '').

Is calculating the amount of leading whitespace really the bottleneck in 
your application? If not, then trying to shave off microseconds from 
something which is a trivial part of your app is almost certainly a waste 
of your time.


[...]
> a = 'some content\n'
> b = a.strip()
> c = ' '*(len(a)-len(b))


I take it that you haven't actually tested this code for correctness, 
because it's buggy. Let's test it:

>>> leading_whitespace = " "*2 + "\t"*2
>>> a = leading_whitespace + "some non-whitespace text\n"
>>> b = a.strip()
>>> c = " "*(len(a)-len(b))
>>> assert c == leading_whitespace
Traceback (most recent call last):
  File "", line 1, in 
AssertionError


Not only doesn't it get the whitespace right, but it doesn't even get the 
*amount* of whitespace right:

>>> assert len(c) == len(leading_whitespace)
Traceback (most recent call last):
  File "", line 1, in 
AssertionError

It doesn't even work correctly if you limit "whitespace" to mean spaces 
and nothing else! It's simply wrong in every possible way.

This is why people say that premature optimization is the root of all 
(programming) evil. Instead of wasting time and energy trying to optimise 
code, you should make it correct first.

Your solutions 2 and 3 are also buggy. And solution 3 can be easily re-
written to be more straightforward. Instead of the complicated:

> def get_leading_whitespace(s):
> def _get():
> for x in s:
> if x != ' ':
> break
> yield x
> return ''.join(_get())

try this version:

def get_leading_whitespace(s):
accumulator = []
for c in s:
if c in ' \t\v\f\r\n':
accumulator.append(c)
else:
break
return ''.join(accumulator)

Once you're sure this is correct, then you can optimise it:

def get_leading_whitespace(s):
t = s.lstrip()
return s[:len(s)-len(t)]

>>> c = get_leading_whitespace(a)
>>> assert c == leading_whitespace
>>>

Unless your strings are very large, this is likely to be faster than any 
other pure-Python solution you can come up with.


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


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread dasacc22
On May 8, 12:59 pm, Patrick Maupin  wrote:
> On May 8, 12:19 pm, dasacc22  wrote:
>
>
>
>
>
> > Hi
>
> > This is a simple question. I'm looking for the fastest way to
> > calculate the leading whitespace (as a string, ie '    ').
>
> > Here are some different methods I have tried so far
> > --- solution 1
>
> > a = '    some content\n'
> > b = a.strip()
> > c = ' '*(len(a)-len(b))
>
> > --- solution 2
>
> > a = '    some content\n'
> > b = a.strip()
> > c = a.partition(b[0])[0]
>
> > --- solution 3
>
> > def get_leading_whitespace(s):
> >     def _get():
> >         for x in s:
> >             if x != ' ':
> >                 break
> >             yield x
> >     return ''.join(_get())
>
> > ---
>
> > Solution 1 seems to be about as fast as solution 2 except in certain
> > circumstances where the value of b has already been determined for
> > other purposes. Solution 3 is slower due to the function overhead.
>
> > Curious to see what other types of solutions people might have.
>
> > Thanks,
> > Daniel
>
> Well, you could try a solution using re, but that's probably only
> likely to be faster if you can use it on multiple concatenated lines.
> I usually use something like your solution #1.  One thing to be aware
> of, though, is that strip() with no parameters will strip *any*
> whitespace, not just spaces, so the implicit assumption in your code
> that what you have stripped is spaces may not be justified (depending
> on the source data).  OTOH, depending on how you use that whitespace
> information, it may not really matter.  But if it does matter, you can
> use strip(' ')
>
> If speed is really an issue for you, you could also investigate
> mxtexttools, but, like re, it might perform better if the source
> consists of several batched lines.
>
> Regards,
> Pat

Hi,

thanks for the info. Using .strip() to remove all whitespace in
solution 1 is a must. If you only stripped ' ' spaces then line
endings would get counted in the len() call and when multiplied
against ' ', would produce an inaccurate result. Regex is
significantly slower for my purposes but ive never heard of
mxtexttools. Even if it proves slow its spurred my curiousity as to
what functionality it provides (on an unrelated note)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Patrick Maupin
On May 8, 12:19 pm, dasacc22  wrote:
> Hi
>
> This is a simple question. I'm looking for the fastest way to
> calculate the leading whitespace (as a string, ie '    ').
>
> Here are some different methods I have tried so far
> --- solution 1
>
> a = '    some content\n'
> b = a.strip()
> c = ' '*(len(a)-len(b))
>
> --- solution 2
>
> a = '    some content\n'
> b = a.strip()
> c = a.partition(b[0])[0]
>
> --- solution 3
>
> def get_leading_whitespace(s):
>     def _get():
>         for x in s:
>             if x != ' ':
>                 break
>             yield x
>     return ''.join(_get())
>
> ---
>
> Solution 1 seems to be about as fast as solution 2 except in certain
> circumstances where the value of b has already been determined for
> other purposes. Solution 3 is slower due to the function overhead.
>
> Curious to see what other types of solutions people might have.
>
> Thanks,
> Daniel

Well, you could try a solution using re, but that's probably only
likely to be faster if you can use it on multiple concatenated lines.
I usually use something like your solution #1.  One thing to be aware
of, though, is that strip() with no parameters will strip *any*
whitespace, not just spaces, so the implicit assumption in your code
that what you have stripped is spaces may not be justified (depending
on the source data).  OTOH, depending on how you use that whitespace
information, it may not really matter.  But if it does matter, you can
use strip(' ')

If speed is really an issue for you, you could also investigate
mxtexttools, but, like re, it might perform better if the source
consists of several batched lines.

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


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Daniel Skinner
sorry, my mistake it runs faster (looking at the wrong line of code). But
the first two solutions are still faster.

On Sat, May 8, 2010 at 12:48 PM, Daniel Skinner  wrote:

> That solution actually runs slower then the generator method.
>
>
> On Sat, May 8, 2010 at 12:33 PM, Shashank Singh <
> shashank.sunny.si...@gmail.com> wrote:
>
>>
>>
>> On Sat, May 8, 2010 at 10:49 PM, dasacc22  wrote:
>>
>>> Hi
>>>
>>> This is a simple question. I'm looking for the fastest way to
>>> calculate the leading whitespace (as a string, ie '').
>>>
>>> Here are some different methods I have tried so far
>>> --- solution 1
>>>
>>> a = 'some content\n'
>>> b = a.strip()
>>> c = ' '*(len(a)-len(b))
>>>
>>
>> use lstrip if you want to remove leading whitespaces only.
>> strip removes trailing white spaces too
>>
>>>
>>> --- solution 2
>>>
>>> a = 'some content\n'
>>> b = a.strip()
>>> c = a.partition(b[0])[0]
>>>
>>> --- solution 3
>>>
>>> def get_leading_whitespace(s):
>>>def _get():
>>>for x in s:
>>>if x != ' ':
>>>break
>>>yield x
>>>return ''.join(_get())
>>>
>>
>> why do you need a generator (and as you mentioned the extra function call
>> overheads)?
>>
>> How about this?
>>
>> def get_leading_whitespaces(s):
>> count = 0
>> for c in s:
>> if c != ' ': break
>> count += 1
>> return ' ' * count
>>
>>
>>>
>>> ---
>>>
>>> Solution 1 seems to be about as fast as solution 2 except in certain
>>> circumstances where the value of b has already been determined for
>>> other purposes. Solution 3 is slower due to the function overhead.
>>>
>>> Curious to see what other types of solutions people might have.
>>>
>>> Thanks,
>>> Daniel
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>>
>> --
>> Regards
>> Shashank Singh
>> Senior Undergraduate, Department of Computer Science and Engineering
>> Indian Institute of Technology Bombay
>> shashank.sunny.si...@gmail.com
>> http://www.cse.iitb.ac.in/~shashanksingh
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Daniel Skinner
That solution actually runs slower then the generator method.

On Sat, May 8, 2010 at 12:33 PM, Shashank Singh <
shashank.sunny.si...@gmail.com> wrote:

>
>
> On Sat, May 8, 2010 at 10:49 PM, dasacc22  wrote:
>
>> Hi
>>
>> This is a simple question. I'm looking for the fastest way to
>> calculate the leading whitespace (as a string, ie '').
>>
>> Here are some different methods I have tried so far
>> --- solution 1
>>
>> a = 'some content\n'
>> b = a.strip()
>> c = ' '*(len(a)-len(b))
>>
>
> use lstrip if you want to remove leading whitespaces only.
> strip removes trailing white spaces too
>
>>
>> --- solution 2
>>
>> a = 'some content\n'
>> b = a.strip()
>> c = a.partition(b[0])[0]
>>
>> --- solution 3
>>
>> def get_leading_whitespace(s):
>>def _get():
>>for x in s:
>>if x != ' ':
>>break
>>yield x
>>return ''.join(_get())
>>
>
> why do you need a generator (and as you mentioned the extra function call
> overheads)?
>
> How about this?
>
> def get_leading_whitespaces(s):
> count = 0
> for c in s:
> if c != ' ': break
> count += 1
> return ' ' * count
>
>
>>
>> ---
>>
>> Solution 1 seems to be about as fast as solution 2 except in certain
>> circumstances where the value of b has already been determined for
>> other purposes. Solution 3 is slower due to the function overhead.
>>
>> Curious to see what other types of solutions people might have.
>>
>> Thanks,
>> Daniel
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> Regards
> Shashank Singh
> Senior Undergraduate, Department of Computer Science and Engineering
> Indian Institute of Technology Bombay
> shashank.sunny.si...@gmail.com
> http://www.cse.iitb.ac.in/~shashanksingh
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Shashank Singh
On Sat, May 8, 2010 at 10:49 PM, dasacc22  wrote:

> Hi
>
> This is a simple question. I'm looking for the fastest way to
> calculate the leading whitespace (as a string, ie '').
>
> Here are some different methods I have tried so far
> --- solution 1
>
> a = 'some content\n'
> b = a.strip()
> c = ' '*(len(a)-len(b))
>

use lstrip if you want to remove leading whitespaces only.
strip removes trailing white spaces too

>
> --- solution 2
>
> a = 'some content\n'
> b = a.strip()
> c = a.partition(b[0])[0]
>
> --- solution 3
>
> def get_leading_whitespace(s):
>def _get():
>for x in s:
>if x != ' ':
>break
>yield x
>return ''.join(_get())
>

why do you need a generator (and as you mentioned the extra function call
overheads)?

How about this?

def get_leading_whitespaces(s):
count = 0
for c in s:
if c != ' ': break
count += 1
return ' ' * count


>
> ---
>
> Solution 1 seems to be about as fast as solution 2 except in certain
> circumstances where the value of b has already been determined for
> other purposes. Solution 3 is slower due to the function overhead.
>
> Curious to see what other types of solutions people might have.
>
> Thanks,
> Daniel
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards
Shashank Singh
Senior Undergraduate, Department of Computer Science and Engineering
Indian Institute of Technology Bombay
shashank.sunny.si...@gmail.com
http://www.cse.iitb.ac.in/~shashanksingh
-- 
http://mail.python.org/mailman/listinfo/python-list


Fastest way to calculate leading whitespace

2010-05-08 Thread dasacc22
Hi

This is a simple question. I'm looking for the fastest way to
calculate the leading whitespace (as a string, ie '').

Here are some different methods I have tried so far
--- solution 1

a = 'some content\n'
b = a.strip()
c = ' '*(len(a)-len(b))

--- solution 2

a = 'some content\n'
b = a.strip()
c = a.partition(b[0])[0]

--- solution 3

def get_leading_whitespace(s):
def _get():
for x in s:
if x != ' ':
break
yield x
return ''.join(_get())

---

Solution 1 seems to be about as fast as solution 2 except in certain
circumstances where the value of b has already been determined for
other purposes. Solution 3 is slower due to the function overhead.

Curious to see what other types of solutions people might have.

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


Re: Picking a license

2010-05-08 Thread Patrick Maupin
On May 8, 3:37 am, Steven D'Aprano  wrote:
> On Fri, 07 May 2010 23:40:22 -0700, Patrick Maupin wrote:
> > Personally, I believe that if anything is false and misleading, it is
> > the attempt to try to completely change the discussion from MIT vs. GPL
> > to GPL vs. no license (and thus very few rights for the software users),
> > after first trying to imply that people who distribute software under
> > permissive licenses (that give the user *more* rights than the GPL) are
> > somehow creating a some sort of moral hazard that might adversely affect
> > their users
>
> If encouraging third parties to take open source code and lock it up
> behind proprietary, closed licences *isn't* a moral hazard, then I don't
> know what one is.

For a start, there is a difference between "encouraging" and
"allowing".  But in point of fact, you have it exactly backwards.
Putting the code out there and making it a tort to republish it under
a closed license creates a moral hazard -- a trap that many companies
including Linksys/Cisco have fallen into.  If I expect nothing in
return, if it's a gift, then the likelihood of moral hazard is
significantly reduced.  Unless you are somehow suggesting that I owe
my user's customers anything (which suggestion, btw, is frequently
made in veiled terms, and always pisses me off), there is no other
moral hazard produced by me choosing a permissive license for my code.

> > So which is it?  GPL good because a user can do more with the software
> > than if he had no license, or MIT bad because a user can do more with
> > the software than if it were licensed under GPL?
>
> Good or bad isn't just a matter of which gives you more freedoms, they're
> also a matter of *what* freedoms they give. Weaponized ebola would allow
> you to kill hundreds of millions of people in a matter of a few weeks,
> but it takes a very special sort of mind to consider that the freedom to
> bring about the extinction of the human race a "good".

You're missing the context where Mr. Finney keeps changing what he's
arguing about.  I agree completely that different licenses are valid
for different expectations, and said as much in my first post on this
subject.  But it's extremely silly to compare weaponized ebola to
publishing free software, unless you want to give ammunition to those
amoral profiteers who claim that it is so dangerous for hackers to
give out source code at all that doing so should be criminalized.

> I consider the freedom granted by the MIT licence for my users to take my
> source code and lock it up behind restrictive licences (and therefore
> *not* grant equivalent freedoms to their users in turn) to be a bad, not
> a good. But in some cases it is a cost worth paying, primarily because
> not all people who use MIT-licenced software go on to re-publish it under
> a restrictive licence, but nevertheless won't consider the GPL (possibly
> due to misunderstandings, confusion or political interference).

"Political interference" is certainly the main reason that I won't use
the GPL, but it is probably not the same politics you are thinking
of.  When I seriously consider investing in learning a piece of
software so that I can make it part of my "toolbox," a major
consideration is how well it plays with the other tools in my toolbox,
and exactly which construction jobs I can use it on.  RMS has managed
to create a scenario where the GPL not only doesn't play nicely with
some other licenses, but now doesn't even always play nicely with
itself -- some people who liked GPL v2 but weren't willing to cede
control of their future licensing terms to the FSF now have GPL v2
code that can't be linked to GPL v3 code.

So, when a package is GPL licensed, for me it can create more
contemplation about whether the package is worth dealing with or not.
If the package is large, well-maintained, and standalone, and I'm just
planning on being a user, the fact that it's GPL-licensed is not at
all a negative.  If I'm looking at two roughly equivalent programming
toolkits, I will take the BSD/MIT one any day, because I know that
when I learn it, I "own" it to the extent that I can use it on
anything I want in any fashion in the future.

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


Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Jon Clements
On 8 May, 16:03, Alex Hall  wrote:
> On 5/8/10, Jon Clements  wrote:
>
> > On 8 May, 15:08, Alex Hall  wrote:
> >> Hi all,
> >> I am sorry if this is the second message about this you get; I typed
> >> this and hit send (on gmail website) but I got a 404 error, so I am
> >> not sure if the previous message made it out or not.
> >> Anyway, I have about fifteen vars in a function which have to be
> >> global. Is there a faster and more space-efficient way of doing this
> >> than putting each var on its own line; that is, fifteen "global
> >> varName" declarations? Thanks.
>
> >> --
> >> Have a great day,
> >> Alex (msg sent from GMail website)
> >> mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> > About 15 that *need* to be global; smells bad to me. However, you can
> > amend a function's .func_globals attribute.
>
> How do you do this exactly?> Just wouldn't be going there myself. Why do you 
> have this many? What's your
> > use case?
>
> They are in a "setOptions" function in config.py, which reads from an
> ini file and sets up all options for the program. All other files then
> can read these options. For example, anyone else can import config,
> then, if they are rounding a number, they can know how many places to
> round to by looking at config.rnd. I have everything in a function
> instead of being initialized upon importing since I offer a function
> to reload the ini file if the user changes something. Eventually I
> will have a gui for setting options, and that gui, to save options,
> will write an ini file then call setOptions so all options are then
> reset according to the newly created ini. If I do not make everything
> in setOptions global, no other file seems able to read it; I get an
> exception the first time another file tries to access a setting.
> Thanks.
>
>
>
> > Jon.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap

Umm, okay at least now we know the context.

Similar to what James suggested just have a dict object in your config
module called 'settings' or something and access that. I still prefer
the "giveth rather than taketh" approach though. But heck, if it
works, who cares?

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


Re: ActivePython - how to configure portable framework?

2010-05-08 Thread Sridhar
Copy all the files in the ZIP to your USB stick and run 
INSTALLDIR\python.exe


-srid

On 5/7/2010 3:24 AM, balzer wrote:
I downloaded ActivePython-2.6.5.12-win32-x86.zip, it contains two 
folders and 3 files:


SystemFolder
INSTALLDIR
sh2.py
install.bat
_install.py

Anyone know how to configure this Python environment  as "portable 
application" to work with it without installation, to set a 
fully-functional Python environment that executes entirely from hard 
drive (or USB stick) without leaving no registry entries, no mess with 
windows system files, etc on machine it's run on.


I created folder "Python",  what files I should copy inside?

thanks.


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


Re: shortcut for large amount of global var declarations?

2010-05-08 Thread James Mills
On Sun, May 9, 2010 at 12:08 AM, Alex Hall  wrote:
> Hi all,
> I am sorry if this is the second message about this you get; I typed
> this and hit send (on gmail website) but I got a 404 error, so I am
> not sure if the previous message made it out or not.
> Anyway, I have about fifteen vars in a function which have to be
> global. Is there a faster and more space-efficient way of doing this
> than putting each var on its own line; that is, fifteen "global
> varName" declarations? Thanks.

Using "globals" (global variables) is generally considered bad practise.

Consider instead using a class/object. You could for example
have a "config" object that is shared by other modules.

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


Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Alex Hall
On 5/8/10, Jon Clements  wrote:
> On 8 May, 15:08, Alex Hall  wrote:
>> Hi all,
>> I am sorry if this is the second message about this you get; I typed
>> this and hit send (on gmail website) but I got a 404 error, so I am
>> not sure if the previous message made it out or not.
>> Anyway, I have about fifteen vars in a function which have to be
>> global. Is there a faster and more space-efficient way of doing this
>> than putting each var on its own line; that is, fifteen "global
>> varName" declarations? Thanks.
>>
>> --
>> Have a great day,
>> Alex (msg sent from GMail website)
>> mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> About 15 that *need* to be global; smells bad to me. However, you can
> amend a function's .func_globals attribute.
How do you do this exactly?
> Just wouldn't be going there myself. Why do you have this many? What's your
> use case?
They are in a "setOptions" function in config.py, which reads from an
ini file and sets up all options for the program. All other files then
can read these options. For example, anyone else can import config,
then, if they are rounding a number, they can know how many places to
round to by looking at config.rnd. I have everything in a function
instead of being initialized upon importing since I offer a function
to reload the ini file if the user changes something. Eventually I
will have a gui for setting options, and that gui, to save options,
will write an ini file then call setOptions so all options are then
reset according to the newly created ini. If I do not make everything
in setOptions global, no other file seems able to read it; I get an
exception the first time another file tries to access a setting.
Thanks.
>
> Jon.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows - select.select, timeout and KeyboardInterrupt

2010-05-08 Thread Giampaolo Rodolà
2010/5/8 Antoine Pitrou :
> On Sat, 8 May 2010 13:47:53 +0200
> Giampaolo Rodolà  wrote:
>>
>> Assuming loop() function does something like this:
>>
>>      ...
>>      select.select(r, w, e, timeout)
>>      scheduler()  # checks for scheduled calls to be fired
>>      ...
>>
>> ...imagine a case where there's a connection (aka a dispatcher
>> instance) which does not receive or send any data *and* a scheduled
>> call which is supposed to be fired after, say, 5 seconds.
>> The entire loop would hang on select.select() which won't return for
>> 30 seconds because the socket is not ready for reading and/or writing
>> resulting in scheduler() be called too late.
>
> Well, obviously you have to change the timeout based on the delay for
> the next scheduled call. If your patch doesn't do that, it probably
> needs fixing :)
>
> Regards
>
> Antoine.

No it doesn't and I didn't consider this solution at the time.
Thanks. =)


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


Re: Picking a license

2010-05-08 Thread Aahz
In article <4be522ac$0$27798$c3e8...@news.astraweb.com>,
Steven D'Aprano   wrote:
>
>For the record, I've published software under an MIT licence because I 
>judged the cost of the moral hazard introduced by encouraging freeloaders 
>to be less than the benefits of having a more permissive licence that 
>encourages freeloading and therefore attracts more users. For other 
>software, I might judge that the cost/benefit ratio falls in a different 
>place, and hence choose the GPL.

Well, yes, which is more-or-less what I posted in the first place.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Jon Clements
On 8 May, 15:08, Alex Hall  wrote:
> Hi all,
> I am sorry if this is the second message about this you get; I typed
> this and hit send (on gmail website) but I got a 404 error, so I am
> not sure if the previous message made it out or not.
> Anyway, I have about fifteen vars in a function which have to be
> global. Is there a faster and more space-efficient way of doing this
> than putting each var on its own line; that is, fifteen "global
> varName" declarations? Thanks.
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap

About 15 that *need* to be global; smells bad to me. However, you can
amend a function's .func_globals attribute. Just wouldn't be going
there myself. Why do you have this many? What's your use case?

Jon.

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


Re: shortcut for large amount of global var declarations?

2010-05-08 Thread MRAB

Alex Hall wrote:

Hi all,
I am sorry if this is the second message about this you get; I typed
this and hit send (on gmail website) but I got a 404 error, so I am
not sure if the previous message made it out or not.
Anyway, I have about fifteen vars in a function which have to be
global. Is there a faster and more space-efficient way of doing this
than putting each var on its own line; that is, fifteen "global
varName" declarations? Thanks.


'global' will accept multiple names:

def foo():
global a, b, c
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: fast regex

2010-05-08 Thread MRAB

Bryan wrote:

Tim Chase wrote:

James wrote:

[Tim had written:]

If the keys in your word_list are more than just words, then the
regexp may not find them all, and thus not replace them all.  In
that case you may have to resort to my 2nd regexp which builds
the 5k branch regexp from your actual dictionary keys:


 r = re.compile(r'\b(%s)\b' % (
   '|'.join(re.escape(s) for s in words_list.keys())
   ),
   re.IGNORECASE)

This method on the above dictionary (modified)

   d = {
 'hello': 'goodbye',
 'world': 'python',
 'stuff with spaces?': 'tadah!',
 }

would create a regexp of

   \b(about|world|stuff\ with\ spaces\?)\b



There's a subtle issue of the order of the keywords. Pythons
(ir)regular expressions do not strictly guarantee to find the longest
match. For example,

re.findall(r'\b(about|about\-faced)\b',
'does about-faced match?')

returns ['about'], which is the first complete match, not the longest.
Sorting the keywords into longest-first order avoids the problem.



This has considerable performance implications as len(word_list)
grows, unless you can figure a way to determine that some
replacements are more probable than others and push them to the
front of this regexp, but that's more complex and requires
knowledge of your word-list.


There is another method which is to factor out common prefixes, so the
re module's search-and-backtrack engine never has a choice of multiple
paths. Instead of:

\b(abolished|abolition)\b

we'd use:

\b(aboli(shed|tion)\b

The RE-generator is of course more complex than Tim's one-liner, but I
happen to have code, which I'll include below. It's probably academic,
as I'd agree with Tim that his first solution is the better candidate
at this point.

With my giant prefix-combined RE's, I can re.compile one with 4000
words randomly chosen from a Unix words file, but 5000 results in
"regular expression code size limit exceeded". Tim's version which
doesn't combine prefixes tops out a little lower. This is on 32-bit
Windows, standard distribution. One could, of course, build multiple
smaller RE's, but that starts to suck.


There's an alternative regex module at:

http://bugs.python.org/issue2636

and also at:

http://pypi.python.org/pypi/regex/0.1.2010414

It looks for common prefixes and suffixes internally and can handle much
larger regexes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python is cool!!

2010-05-08 Thread lkcl
On Mar 25, 3:01 pm, Bruno Desthuilliers  wrote:
> Jose Manuel a écrit :
>
> > I have been learning Python, and it is amazing  I am using the
> > tutorial that comes with the official distribution.
>
> > At the end my goal is to develop applied mathematic in engineering
> > applications to be published on the Web, specially on app. oriented to
> > simulations and control systems, I was about to start learning Java
> > but I found Python which seems easier to learn that Java.
>
> Python is indeed quite lightweight when compared to Java. But it has
> it's share of non-obvious features, dark corners, gotchas, and plain
> warts too.

 good god. it does?? :) that's news to me, bruno! where? i haven't
found _any_ of those things - it's aaalll been blindingly obvious
and... ok maybe not metaclasses i alllmost grok those :)

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


Re: fast regex

2010-05-08 Thread Bryan
Tim Chase wrote:
> James wrote:
> > [Tim had written:]
> If the keys in your word_list are more than just words, then the
> regexp may not find them all, and thus not replace them all.  In
> that case you may have to resort to my 2nd regexp which builds
> the 5k branch regexp from your actual dictionary keys:
>
> >>  r = re.compile(r'\b(%s)\b' % (
> >>    '|'.join(re.escape(s) for s in words_list.keys())
> >>    ),
> >>    re.IGNORECASE)
>
> This method on the above dictionary (modified)
>
>    d = {
>      'hello': 'goodbye',
>      'world': 'python',
>      'stuff with spaces?': 'tadah!',
>      }
>
> would create a regexp of
>
>    \b(about|world|stuff\ with\ spaces\?)\b


There's a subtle issue of the order of the keywords. Pythons
(ir)regular expressions do not strictly guarantee to find the longest
match. For example,

re.findall(r'\b(about|about\-faced)\b',
'does about-faced match?')

returns ['about'], which is the first complete match, not the longest.
Sorting the keywords into longest-first order avoids the problem.


> This has considerable performance implications as len(word_list)
> grows, unless you can figure a way to determine that some
> replacements are more probable than others and push them to the
> front of this regexp, but that's more complex and requires
> knowledge of your word-list.

There is another method which is to factor out common prefixes, so the
re module's search-and-backtrack engine never has a choice of multiple
paths. Instead of:

\b(abolished|abolition)\b

we'd use:

\b(aboli(shed|tion)\b

The RE-generator is of course more complex than Tim's one-liner, but I
happen to have code, which I'll include below. It's probably academic,
as I'd agree with Tim that his first solution is the better candidate
at this point.

With my giant prefix-combined RE's, I can re.compile one with 4000
words randomly chosen from a Unix words file, but 5000 results in
"regular expression code size limit exceeded". Tim's version which
doesn't combine prefixes tops out a little lower. This is on 32-bit
Windows, standard distribution. One could, of course, build multiple
smaller RE's, but that starts to suck.

-Bryan Olson


from random import sample
import re


def build_big_re(str_list):
 """ Build a non-backtracking regular expression
matching any of the words in str_list.
 """

 def trie_insert(table, str):
 if str:
 submap = table.setdefault(str[0], {})
 trie_insert(submap, str[1:])
 else:
 table[""] = {}

 def sequentialize(table, lst):
 if table:
 keys = table.keys()
 keys.sort(key=len, reverse=True)
 lst.append('(?:')
 seperator = ''
 for key in keys:
 lst.append(seperator + re.escape(key))
 submap = table[key]
 while len(submap) == 1:
 key = submap.keys()[0]
 submap = submap[key]
 lst.append(re.escape(key))
 sequentialize(submap, lst)
 seperator = '|'
 lst.append(')')

 table = {}
 for str in str_list:
 trie_insert(table, str)
 lst = [r'\b']
 sequentialize(table, lst)
 lst.append(r'\b')
 re_str = "".join(lst)
 # print "RE is: '%s'\n" % re_str
 return re.compile(re_str, re.IGNORECASE)



def simple_re(str_list):
str_list = sorted(str_list, key=len, reverse=True)
re_str = r'\b(%s)\b' % (
 '|'.join(re.escape(s) for s in str_list))
# print "RE is", re_str
return re.compile(re_str, re.IGNORECASE)



def testy():

words_file = r'/usr/share/dict/words' # Common Unix
# words_file = r'C:\z\wordlist.txt' # Just my box

nkeywords = 3500

from random import sample
with open(words_file, 'r') as f:
allwords = [w.strip() for w in f.readlines()]
keywords = sample(allwords, nkeywords)
bigtext = ' '.join(allwords)

print 'Building simple RE...'
simpre = simple_re(keywords)
print 'Run simple re...'
z1 = simpre.findall(bigtext)
print 'Done.\n'

print 'Building complex RE...'
compre = build_big_re(keywords)
print 'Run complex re...'
z2 = compre.findall(bigtext)
print 'Done.'

assert z1 == z2

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


shortcut for large amount of global var declarations?

2010-05-08 Thread Alex Hall
Hi all,
I am sorry if this is the second message about this you get; I typed
this and hit send (on gmail website) but I got a 404 error, so I am
not sure if the previous message made it out or not.
Anyway, I have about fifteen vars in a function which have to be
global. Is there a faster and more space-efficient way of doing this
than putting each var on its own line; that is, fifteen "global
varName" declarations? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows - select.select, timeout and KeyboardInterrupt

2010-05-08 Thread exarkun

On 11:47 am, g.rod...@gmail.com wrote:

2010/5/7 Antoine Pitrou :

Le Fri, 07 May 2010 21:55:15 +0200, Giampaolo Rodol� a �crit�:
Of course, but 30 seconds look a little bit too much to me, also 
because
(I might be wrong here) I noticed that a smaller timeout seems to 
result

in better performances.


That's probably bogus.


Probably, I'll try to write a benchmark script and see what happens.

Plus, if scheduled callbacks are ever gonna be added to asyncore we
would be forced to lower the default timeout anyway in order to have 
a

decent reactivity.


Why?


Assuming loop() function does something like this:

...
select.select(r, w, e, timeout)
scheduler()  # checks for scheduled calls to be fired
...

...imagine a case where there's a connection (aka a dispatcher
instance) which does not receive or send any data *and* a scheduled
call which is supposed to be fired after, say, 5 seconds.
The entire loop would hang on select.select() which won't return for
30 seconds because the socket is not ready for reading and/or writing
resulting in scheduler() be called too late.


This would be an intensely lame way to implement support for scheduled 
callbacks.  Try this trivial modification instead, to make it awesome:


   ...
   select.select(r, w, e, scheduler.time_until_next_call())
   scheduler.run()
   ...

(Or maybe just use Twisted. ;)

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


Re: Windows - select.select, timeout and KeyboardInterrupt

2010-05-08 Thread exarkun

On 07:48 am, l...@geek-central.gen.new_zealand wrote:

In message ,
exar...@twistedmatrix.com wrote:
This is a good example of why it's a bad idea to use select on 
Windows.

Instead, use WaitForMultipleObjects.


How are you supposed to write portable code, then?


With WaitForMultipleObjects on Windows, epoll on Linux, kqueue on BSD, 
event completion on Solaris, etc...


Sound like more work than using select() everywhere?  Yea, a bit.  But 
not once you abstract it away from your actual application code.  After 
all, it's not like these *do* different things.  They all do the same 
thing (basically) - differently.


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


Re: Windows - select.select, timeout and KeyboardInterrupt

2010-05-08 Thread Antoine Pitrou
On Sat, 8 May 2010 13:47:53 +0200
Giampaolo Rodolà  wrote:
> 
> Assuming loop() function does something like this:
> 
>  ...
>  select.select(r, w, e, timeout)
>  scheduler()  # checks for scheduled calls to be fired
>  ...
> 
> ...imagine a case where there's a connection (aka a dispatcher
> instance) which does not receive or send any data *and* a scheduled
> call which is supposed to be fired after, say, 5 seconds.
> The entire loop would hang on select.select() which won't return for
> 30 seconds because the socket is not ready for reading and/or writing
> resulting in scheduler() be called too late.

Well, obviously you have to change the timeout based on the delay for
the next scheduled call. If your patch doesn't do that, it probably
needs fixing :)

Regards

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


[PATCH] Re: ConfigParser.get() defaults?

2010-05-08 Thread Tim Chase

On 05/07/2010 07:56 PM, Steven D'Aprano wrote:

On Fri, 07 May 2010 15:05:53 -0500, Tim Chase wrote:

With a normal dictionary, I can specify a default fallback value in the
event the requested key isn't present:

[...]

However, with the ConfigParser object, there doesn't seem to be any way
to do a similar


Sounds like a nice feature to have. When you submit a patch (*grin*),


I'm game to create and provide a patch,


Attached is my initial patch against 2.6's ConfigParser.py to 
work in some defaults (though it should also apply fairly cleanly 
against 2.5).


It doesn't differentiate between missing sections and missing 
options, as both cases are the same in my use:  the user didn't 
provide a setting, so I want to specify a default without lots of 
try/except wrapping.


For the type-specific get[int/float/boolean]() functions, it also 
provides an optional parameter to raise the ValueError or just 
return the default if it's provided-but-bogus (it may also yell 
at you if your default creates a ValueError).


My distributed ConfigParser.py didn't seem to have any tests, so 
I didn't include any; but would be glad to write a few if they'd 
be integrated into the standard core testing.


Is this the sort of things that should also be sent to 
python-dev, or are the powers-that-be lurking sufficiently on 
this list to see this patch fly?


-tkc



diff -r eea32b421d4c -r 79cb9fc14932 ConfigParser.py
--- a/ConfigParser.py   Sat May 08 07:15:52 2010 -0500
+++ b/ConfigParser.py   Sat May 08 07:55:48 2010 -0500
@@ -304,21 +304,30 @@
 filename = ''
 self._read(fp, filename)
 
-def get(self, section, option):
+def get(self, section, option, default=None):
 opt = self.optionxform(option)
 if section not in self._sections:
 if section != DEFAULTSECT:
-raise NoSectionError(section)
+if default is None:
+raise NoSectionError(section)
+else:
+return default
 if opt in self._defaults:
 return self._defaults[opt]
 else:
-raise NoOptionError(option, section)
+if default is None:
+raise NoOptionError(option, section)
+else:
+return default
 elif opt in self._sections[section]:
 return self._sections[section][opt]
 elif opt in self._defaults:
 return self._defaults[opt]
 else:
-raise NoOptionError(option, section)
+if default is None:
+raise NoOptionError(option, section)
+else:
+return default
 
 def items(self, section):
 try:
@@ -333,22 +342,44 @@
 del d["__name__"]
 return d.items()
 
-def _get(self, section, conv, option):
-return conv(self.get(section, option))
+def _get(self, section, conv, option, default=None, raise_on_bad=False):
+v = self.get(section, option, default=default)
+try:
+return conv(v)
+except ValueError:
+if raise_on_bad:
+raise
+else:
+return default
 
-def getint(self, section, option):
-return self._get(section, int, option)
+def getint(self, section, option,
+default=None,
+raise_on_bad=False
+):
+return self._get(section, int, option,
+default=default,
+raise_on_bad=raise_on_bad
+)
 
-def getfloat(self, section, option):
-return self._get(section, float, option)
+def getfloat(self, section, option,
+default=None,
+raise_on_bad=False
+):
+return self._get(section, float, option,
+default=default,
+raise_on_bad=raise_on_bad
+)
 
 _boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
'0': False, 'no': False, 'false': False, 'off': False}
 
-def getboolean(self, section, option):
-v = self.get(section, option)
+def getboolean(self, section, option, default=None, raise_on_bad=False):
+v = self.get(section, option, default=default)
 if v.lower() not in self._boolean_states:
-raise ValueError, 'Not a boolean: %s' % v
+if default is None or raise_on_bad:
+raise ValueError, 'Not a boolean: %s' % v
+else:
+return default
 return self._boolean_states[v.lower()]
 
 def optionxform(self, optionstr):
@@ -512,7 +543,7 @@
 
 class ConfigParser(RawConfigParser):
 
-def get(self, section, option, raw=False, vars=None):
+def get(self, section, option, raw=False, vars=None, default=None):
 """Get an option value for a given section.
 
 All % interpolations are expanded in the return values, based on the
@@ -528,7 +559,10 

Re: py3 tkinter acceps bytes. why?

2010-05-08 Thread Martin v. Loewis
Matthias Kievernagel wrote:
> Me:
>>> If I don't want bytes to get passed to tkinter
>>> I just have to raise an exception in AsObj, no?
>>> Or is it even sufficient to just remove the bytes case?
> Martin v. Loewis  wrote:
>> But why would you want that? There are commands which legitimately
>> return bytes, e.g. the file and network io libraries of Tcl (not that
>> you would usually want to use them in Python, but Tkinter is actually
>> Tclinter, and should support all Tcl commands).
> 
> I'm just looking for a reliable error message when I pass
> something to GUI functions which is not fit for display,
> i.e. not a string. If bytes pass unnoticed,
> I'll sooner or later have a surprise.
> Just to make sure I decode all bytes (coming from a socket)
> before I pass them on to the GUI.

I see. I think it's just not possible to provide such a check,
given Tcl's (non-existent) type system.

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


Re: Cross-platform file paths

2010-05-08 Thread News123
Hi TIA,

utabintarbo wrote:
> Until now, I have used the UNC under Windows (XP) to allow my program
> to access files located on a Samba-equipped *nix box (eg.
> os.path.normpath(r"\\serverFQDN\sharename\dir\filename")). When I try
> to open this file under Linux (Red Hat 5), I get a file not found
> error.
> 
> Is there a cross-platform method for accessing files on a network
> share using Python 2.X?
> 

Up to my knowledge there is now path name under linux, which gives you
access to samba shares without mounting then.


Perhaps there's some special user space file system drivers providing
that functionality, but I don't expect it to be standard linux behaviour.

What is your linux distribution?

I would suggest to change the subject line to something like:

"accessing samba shares from a linux host without mounting them"

or  "cross-platform liibrary to access samba shares"

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


Re: Windows - select.select, timeout and KeyboardInterrupt

2010-05-08 Thread Giampaolo Rodolà
2010/5/7 Antoine Pitrou :
> Le Fri, 07 May 2010 21:55:15 +0200, Giampaolo Rodolà a écrit :
>> Of course, but 30 seconds look a little bit too much to me, also because
>> (I might be wrong here) I noticed that a smaller timeout seems to result
>> in better performances.
>
> That's probably bogus.

Probably, I'll try to write a benchmark script and see what happens.

>> Plus, if scheduled callbacks are ever gonna be added to asyncore we
>> would be forced to lower the default timeout anyway in order to have a
>> decent reactivity.
>
> Why?

Assuming loop() function does something like this:

 ...
 select.select(r, w, e, timeout)
 scheduler()  # checks for scheduled calls to be fired
 ...

...imagine a case where there's a connection (aka a dispatcher
instance) which does not receive or send any data *and* a scheduled
call which is supposed to be fired after, say, 5 seconds.
The entire loop would hang on select.select() which won't return for
30 seconds because the socket is not ready for reading and/or writing
resulting in scheduler() be called too late.


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


Re: Picking a license

2010-05-08 Thread Martin P. Hellwig

On 05/08/10 09:37, Steven D'Aprano wrote:


If encouraging third parties to take open source code and lock it up
behind proprietary, closed licences *isn't* a moral hazard, then I don't
know what one is.


I fail to see what is morally wrong with it. When I ,as the author, 
share my work to the public, I should have made peace with the fact that 
I, for all intends and purposes, lost control over its use. And that is 
rightfully so; who am I to say: "Yeah you can use it but only once in a 
blue moon when Jupiter aligns with Mars and a solar eclipse reaches its 
high on Greenwich at noon exactly."


But just for argument sake say that you can put restrictions on the use, 
who is going to enforce these restrictions? The author/Police/special 
interest groups?


Anyway I usually put stuff under the MIT/BSD license, but when I can I 
use the beerware license (http://people.freebsd.org/~phk/) and I fully 
agree with PHK's reasoning.


--
mph


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


Re: Picking a license

2010-05-08 Thread Steven D'Aprano
On Fri, 07 May 2010 23:40:22 -0700, Patrick Maupin wrote:

> Personally, I believe that if anything is false and misleading, it is
> the attempt to try to completely change the discussion from MIT vs. GPL
> to GPL vs. no license (and thus very few rights for the software users),
> after first trying to imply that people who distribute software under
> permissive licenses (that give the user *more* rights than the GPL) are
> somehow creating a some sort of moral hazard that might adversely affect
> their users

If encouraging third parties to take open source code and lock it up 
behind proprietary, closed licences *isn't* a moral hazard, then I don't 
know what one is.

For the record, I've published software under an MIT licence because I 
judged the cost of the moral hazard introduced by encouraging freeloaders 
to be less than the benefits of having a more permissive licence that 
encourages freeloading and therefore attracts more users. For other 
software, I might judge that the cost/benefit ratio falls in a different 
place, and hence choose the GPL.


> So which is it?  GPL good because a user can do more with the software
> than if he had no license, or MIT bad because a user can do more with
> the software than if it were licensed under GPL?

Good or bad isn't just a matter of which gives you more freedoms, they're 
also a matter of *what* freedoms they give. Weaponized ebola would allow 
you to kill hundreds of millions of people in a matter of a few weeks, 
but it takes a very special sort of mind to consider that the freedom to 
bring about the extinction of the human race a "good".

I consider the freedom granted by the MIT licence for my users to take my 
source code and lock it up behind restrictive licences (and therefore 
*not* grant equivalent freedoms to their users in turn) to be a bad, not 
a good. But in some cases it is a cost worth paying, primarily because 
not all people who use MIT-licenced software go on to re-publish it under 
a restrictive licence, but nevertheless won't consider the GPL (possibly 
due to misunderstandings, confusion or political interference).



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


Re: Windows - select.select, timeout and KeyboardInterrupt

2010-05-08 Thread Lawrence D'Oliveiro
In message , 
exar...@twistedmatrix.com wrote:

> This is a good example of why it's a bad idea to use select on Windows.
> Instead, use WaitForMultipleObjects.

How are you supposed to write portable code, then?
-- 
http://mail.python.org/mailman/listinfo/python-list