re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-13 Thread Devin Jeanpierre
Hey Pythonistas,

Consider the regular expression "$*". Compilation fails with the
exception, "sre_constants.error: nothing to repeat".

Consider the regular expression "(?=$)*". As far as I know it is
equivalent. It does not fail to compile.

Why the inconsistency? What's going on here?

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


Re: how to tell a method is classmethod or static method or instance method

2012-02-13 Thread Zheng Li

I can get "method1" of class "Test" by
a = getattr(Test, "method1")

and I also want know how to invoke it
a() or  a(Test())



BTW:
I don't see what the problem is if I ask a question just because I am curious 
about it.


On 2012/02/13, at 16:23, Cameron Simpson wrote:

> On 13Feb2012 15:59, Zheng Li  wrote:
> | how to tell a method is class method or static method or instance method?
> 
> Maybe a better question is:
>  under what circumstances do you need to figure this out? 
> 
> I'm actually quite serious here. Please outline what circumstances cause
> you to want to ask and answer this question.
> 
> Cheers,
> -- 
> Cameron Simpson  DoD#743
> http://www.cskk.ezoshosting.com/cs/
> 
> Reason #173 to fear technology:
> 
>o   o   o   o   o   o  
>   ^|\ ^|^ v|^ v|v |/v |X|  \|  |
>/\  >\ /<   >\ /<   >\ /<   >\
> 
>o>  o   o   o   o   o   o   o
>\   x<\> <)>  |\
>   /<   >\ /<   >\ /<   >\  >>  L
> 
> Mr. email does the Macarena.

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Chris Angelico
On Tue, Feb 14, 2012 at 11:39 AM, Rick Johnson
 wrote:
> # Py>=3.0
> py> sum(earner.get_income(2012) for earner in earners2012) /
> len(earners2012)
> average_income
>
> Once you exceed that amount you are robbing your fellow man. How can
> you justify making more than your fair share UNLESS someone offers
> their work load to YOU? You can't. You are living in excess. And for
> those who think the average_income is too small, well then, it's time
> to implement population control!

My equation looks something like this:

# Brain >= 0,1
brain> Your contribution to society / Society's contribution to you

This value should be able to exceed 1.0 across the board. In fact, if
it doesn't, then as a society we're moving backward.

Rick, what's YOUR ratio?

Oh wait, you mightn't be able to run that code. You may need to
download an upgraded brain.

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Michael Torrie
On 02/13/2012 05:39 PM, Rick Johnson wrote:
> Why? Do you need the services of a professional software developer?

Do you have some to offer?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Ian Kelly
[Reply sent off-list, partly because this is way off-topic, but also
because python-list rejected my response as spam]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Rick Johnson
On Feb 13, 3:46 pm, Michael Torrie  wrote:
> On 02/13/2012 09:01 AM, Rick Johnson wrote:
>
> > Look, i hate super rich, arrogant people just as much i hate selfish
> > people.
>
> But wait, Rick.  You are a man of contradictions.  We all are, but you
> seem to bluster on and on more about it than most.  Firstly, to *hate*
> anyone, super-rich, arrogant, or not, _is_ selfish by definition.

Not necessarily. But i will admit that i did not choose my words
correctly.

I don't "hate" people simply BECAUSE they are rich. Just like i don't
hate people simply because they are poor. However i DO hate what the
super rich people BECOME. They become blind to their own position in
the universe and instead start to believe the universe revolves around
them. When their daily lives are consumed with vanity, and they lose
all appreciation for the value of money. Yes, they have become
something NOT to aspire to.

But how much is too much?

Good question, and the answer is ALWAYS subjective isn't it? A child
might think $20 dollars is a lot of money. A homeless person might
think someone who has a new model car is rich and not struggling. Same
goes in the opposite direction. A rich man might choose suicide over
life if confronted with the possibility of surviving on $40,000 a
year. However, as we know, many folks survive on much less than that
-- some even pretend to be happy!

Can there be a specific amount wherein if you exceed that amount THEN
you are living in excess? I believe there is a specific amount,
however it is constantly changing depending on the current state of
employment and wages. My equation looks like:

# Py>=3.0
py> sum(earner.get_income(2012) for earner in earners2012) /
len(earners2012)
average_income

Once you exceed that amount you are robbing your fellow man. How can
you justify making more than your fair share UNLESS someone offers
their work load to YOU? You can't. You are living in excess. And for
those who think the average_income is too small, well then, it's time
to implement population control!

The fact is, we have far too many people living beyond their needs. We
have people buying houses they can't afford and then blaming the bank
for some how "tricking" them. They don't have the scruples to accept
the blame!

Take a look around man. The world is in death throes. World wide
economic collapse is upon us. And how did we get here? Entitlements:
which is just another manifestation of selfishness. Look at Greece.
Look at Europe. America YOU are next!

> Put in another way, health care should only go to those
> that can afford to pay for the insurance or care, and not the
> free-loaders.

Yes. Healthcare is a luxury available only to those who can afford it.
If you can't afford healthcare, then visit a REAL charity hospital
(not one subsidized by taxpayers!). A real charity is subsidized by
caring folks who want to help their fellow man -- even if to only
extend his suffering a few more days, months, or years.

> Thus a "super rich" person
> should be commended as he will be able to afford health care without
> burdening anyone else in society.

"commend" is a strong word. I don't think paying your debts requires a
pat on the back. If you have children, then you are required to raise
them, you don't get brownie points for raising your children, it's
your job! Same for debts.

> Does your hatred for super-rich,
> arrogant, people mean that you believe there is an acceptable dollar
> value for the wealth a person should morally be able to amass?

see above equation for enlightenment ^^^

> What do you do for your career?  Are you a professional
> software developer?

Why? Do you need the services of a professional software developer?

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Steven D'Aprano
On Mon, 13 Feb 2012 13:01:05 -0800, Rick Johnson wrote:

> Healthy people do not need healthcare very often

Healthy people don't need healthcase AT ALL.

By definition, once you need healthcare, you are no longer healthy.

Your faith in the magic of "immune system" is touching, but one wonders 
how "immune system" will save people who have been hit by a car.


Rick, isn't it time for you to go back to forking Python so that the 
adoring silent majority who agrees with you can abandon this cesspool of 
inefficient Python code and use your awesome new version? Please don't 
disappoint your millions of fans!


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


Re: Change os.makedirs to handle existing directory

2012-02-13 Thread Andrew Berg
On 2/13/2012 4:59 PM, Wanderer wrote:
> I think wanting to create a directory if one doesn't exist or do
> nothing if it does exist and just use the existing directory is a
> fairly normal programming need. Apparently this is somewhat
> complicated in Python. 
There are new exceptions in 3.3, one of which is for exactly this.

http://docs.python.org/dev/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy
http://docs.python.org/dev/library/exceptions.html#FileExistsError

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatic Type Conversion to String

2012-02-13 Thread Bruce Eckel
I'm willing to subclass str, but when I tried it before it became a little 
confusing -- I think mostly because anytime I assigned to self it seemed like 
it converted the whole object to a str rather than a Path. I suspect I don't 
know the proper idiom for doing this -- any hints? Thanks ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Change os.makedirs to handle existing directory

2012-02-13 Thread Tim Delaney
On 14 February 2012 09:59, Wanderer  wrote:

> I think wanting to create a directory if one doesn't exist or do
> nothing if it does exist and just use the existing directory is a
> fairly normal programming need. Apparently this is somewhat
> complicated in Python.
> ...
> IMHO, os.makedirs should do this for you with something like
>
> os.makedirs(dirName, exist = False)
>
> and have makedirs silence the error the 'right' way whatever that is,
> without turning it into an exercise for the user.


Added in 3.2:
http://docs.python.org/py3k/library/os.html?highlight=makedirs#os.makedirs

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


Change os.makedirs to handle existing directory

2012-02-13 Thread Wanderer
I think wanting to create a directory if one doesn't exist or do
nothing if it does exist and just use the existing directory is a
fairly normal programming need. Apparently this is somewhat
complicated in Python. If you use

if not os.path.exists(dirName):
os.makedirs(dirName)

you create a race condition. If you use try:

try:
os.makedirs(dirName)
except OSError:
pass

Now you're silencing too many errors, so you need to select which
errors to silence. You can check to see if the directory already
exists and assume that the directory already existing is the cause of
the error.

try:
os.makedirs(dirName)
except OSError:
if os.path.exists(dirName):
# We are nearly safe
pass
else:
# There was an error on creation, so make sure we know about
it
raise

or check the error type:

try:
os.makedirs(dirName)
except OSError, e:
if e.errno != errno.EEXIST:
raise


IMHO, os.makedirs should do this for you with something like

os.makedirs(dirName, exist = False)

and have makedirs silence the error the 'right' way whatever that is,
without turning it into an exercise for the user.








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


Re: M2crypto

2012-02-13 Thread zigi
Ok, thanks.


On 13 Lut, 23:27, geremy condra  wrote:
> On Mon, Feb 13, 2012 at 12:37 AM, zigi  wrote:
> > Hello,
> > this is must be testing time to crypt files, using just M2crypto :-)
> > I know this is a strange use of the library, but such is the will of
> > the management.
>
> I take it you mean that you're benchmarking file encryption
> performance using M2Crypto? If your only goal is to do exactly that
> then go for it, but otherwise you're probably using the wrong tool for
> the job.
>
> Geremy Condra
>
>
>
>
>
>
>
> > On 13 Lut, 01:28, geremy condra  wrote:
> >> On Sun, Feb 12, 2012 at 4:00 PM, Mel Wilson  wrote:
> >> > zigi wrote:
>
> >> >> Hello,
> >> >> M2crypto
>
> >> >> __init__(self, alg, key, iv, op, key_as_bytes=0, d='md5',
> >> >> salt='12345678', i=1, padding=1)
>
> >> >> I wont write app, using M2crypto and I can not understand what are the
> >> >> arguments:
> >> >> key, iv, op, salt ?
> >> >> What they do ?
>
> >> > I assume you're reading in 
> >> > about M2Crypto.EVP.Cipher.
>
> >> > Epydoc claims another victim.
>
> >> > I'm having a lot of trouble finding documentation.  The obvious OpenSSL
> >> > pages are kind of thin, too.  You might see some useful code in the EVP 
> >> > unit
> >> > tests m2crypto/tests/test_evp.py in the m2crypto installation.
>
> >> Not intending to be rude, but being perfectly serious: as a general
> >> rule, if you don't know what an IV is you're probably getting yourself
> >> into a lot of trouble working with low-level crypto libraries.
>
> >> Two suggestions:
>
> >> 1. Describe what you're trying to do- I'll be able to help more if I
> >> know what you're actually going for.
>
> >> 2. Try keyczar. It's not perfect, but it's a lot easier to get right.
>
> >> Geremy Condra
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list

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


Re: M2crypto

2012-02-13 Thread geremy condra
On Mon, Feb 13, 2012 at 12:37 AM, zigi  wrote:
> Hello,
> this is must be testing time to crypt files, using just M2crypto :-)
> I know this is a strange use of the library, but such is the will of
> the management.

I take it you mean that you're benchmarking file encryption
performance using M2Crypto? If your only goal is to do exactly that
then go for it, but otherwise you're probably using the wrong tool for
the job.

Geremy Condra

> On 13 Lut, 01:28, geremy condra  wrote:
>> On Sun, Feb 12, 2012 at 4:00 PM, Mel Wilson  wrote:
>> > zigi wrote:
>>
>> >> Hello,
>> >> M2crypto
>>
>> >> __init__(self, alg, key, iv, op, key_as_bytes=0, d='md5',
>> >> salt='12345678', i=1, padding=1)
>>
>> >> I wont write app, using M2crypto and I can not understand what are the
>> >> arguments:
>> >> key, iv, op, salt ?
>> >> What they do ?
>>
>> > I assume you're reading in 
>> > about M2Crypto.EVP.Cipher.
>>
>> > Epydoc claims another victim.
>>
>> > I'm having a lot of trouble finding documentation.  The obvious OpenSSL
>> > pages are kind of thin, too.  You might see some useful code in the EVP 
>> > unit
>> > tests m2crypto/tests/test_evp.py in the m2crypto installation.
>>
>> Not intending to be rude, but being perfectly serious: as a general
>> rule, if you don't know what an IV is you're probably getting yourself
>> into a lot of trouble working with low-level crypto libraries.
>>
>> Two suggestions:
>>
>> 1. Describe what you're trying to do- I'll be able to help more if I
>> know what you're actually going for.
>>
>> 2. Try keyczar. It's not perfect, but it's a lot easier to get right.
>>
>> Geremy Condra
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatic Type Conversion to String

2012-02-13 Thread Chris Rebert
On Mon, Feb 13, 2012 at 2:01 PM, Bruce Eckel  wrote:
> I'm creating a class to encapsulate OS paths, to reduce the visual
> noise and typing from the os.path methods. I've got the class and nose
> tests below, and everything works except the last test which I've
> prefixed with XXX:
>
>    def XXXtest_should_work(self):
>        """
>        Produces:
>        open(self.p2, 'w').write('')
>        TypeError: coercing to Unicode: need string or buffer, Path
> found
>        """
>        open(self.p2, 'w').write('')
>        assert self.p2
>
> Note that I *have* a __str__(self) method to perform automatic
> conversion to string, and I've commented out the __unicode__(self)
> method because it wasn't getting called. The problem appears to be
> that open() does not seem to be calling __str__ on its first argument,
> but instead it appears to want a basestring and this doesn't
> automatically call __str__.

Right. Python is strongly-typed, so it requires a genuine str here (as
opposed to just something that's stringifyable) and doesn't do an
coercion call to str() for you. Just like how str.join() doesn't
automatically call str() on the elements of the list you give it. This
is to prevent silliness like trying to open() e.g. a dict. Your
alternatives are:
- Learn to live with having to write open(str(path_obj))
- Add a .open() method to Path, and use that instead of the open()
built-in function
- Have Path subclass `str` or `unicode`

> I'm trying to write the Path class so I can just hand a Path object
> to, for example, open() and have it produce the path string.

Impossible, short of subclassing `str` or `unicode`.

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


Automatic Type Conversion to String

2012-02-13 Thread Bruce Eckel
I'm creating a class to encapsulate OS paths, to reduce the visual
noise and typing from the os.path methods. I've got the class and nose
tests below, and everything works except the last test which I've
prefixed with XXX:

def XXXtest_should_work(self):
"""
Produces:
open(self.p2, 'w').write('')
TypeError: coercing to Unicode: need string or buffer, Path
found
"""
open(self.p2, 'w').write('')
assert self.p2

Note that I *have* a __str__(self) method to perform automatic
conversion to string, and I've commented out the __unicode__(self)
method because it wasn't getting called. The problem appears to be
that open() does not seem to be calling __str__ on its first argument,
but instead it appears to want a basestring and this doesn't
automatically call __str__.

I'm trying to write the Path class so I can just hand a Path object
to, for example, open() and have it produce the path string.

Thanks for any insights.
--- Class and tests, put in file path.py


import os, os.path

class Path(object):
def __init__(self, *args):
"""
Each of *args is a piece of a path. Assemble them together.
"""
if len(args) == 0:
self.path = os.path.abspath('.')
else:
self.path = str(args[0]) # str() so you can add Path
objects
if self.path.endswith(':'):
self.path = os.path.join(self.path, os.sep)
for a in args[1:]:
self.path = os.path.join(self.path, str(a))
def __add__(self, other):
return Path(os.path.join(self.path, other))
def __iadd__(self, other): # path += path
self.path = os.path.join(self.path, other)
return self # Allows chaining
def __str__(self):
return self.path
# def __repr__(self):
# assert not self.path, "__repr__"
# return os.path.join(self.path)
# def __unicode__(self):
# assert not self.path, "__unicode__"
# print "Unicode called %s" % self.path
# return os.path.join(self.path)
def __nonzero__(self):
"""
Boolean test: does this path exist?
So you can say "if path:"
"""
return bool(os.path.exists(self.path))

"""
Nose tests. To run, you must first install nose:
pip install nose
Then:
nosetests path.py
"""
def test_platform():
"First draft tests are Windows-based"
import platform
assert platform.system() == 'Windows'

class test_paths():
def setUp(self):
self.paths = [
("C:\\"),
("C:\\", "Users", "Bruce Eckel", "Downloads",
"AtomicScala.zip"),
("C:\\", "Users", "Bruce Eckel", "Dropbox",
"AtomicScala"),
]
self.p1 = Path(self.paths[0])
self.s1 = os.path.join(self.paths[0], "\\")
self.p2 = Path(*self.paths[1])
self.s2 = os.path.join(*self.paths[1])
self.p3 = Path(*self.paths[2])
self.s3 = os.path.join(*self.paths[2])
self.p4 = self.p3 + "TestFile1.tmp"
self.s4 = os.path.join(self.s3, "TestFile1.tmp")
self.p5 = self.p3 + "TestFile2.tmp"
self.s5 = os.path.join(self.s3, "TestFile2.tmp")
self.p6 = Path("foo") + "bar" + "baz"

def test1(self):
"Root directory"
print self.p1
print self.s1
assert str(self.p1) == self.s1

def test2(self):
"Full path to file"
print "p2", self.p2
print "s2", self.s2
assert str(self.p2) == self.s2

def test3(self):
"Directory"
assert str(self.p3) == self.s3

def test4(self):
"Plus operator"
assert str(self.p4) == self.s4

def test5(self):
"Another temp file"
assert str(self.p5) == self.s5

def test6(self):
"Chained operator +"
assert str(self.p6) == r"foo\bar\baz"

def test7(self):
"Operator +="
self.p6 += "bingo"
assert str(self.p6) == r"foo\bar\baz\bingo"

def test8(self):
"Create a Path from a Path"
p = Path(self.p3)
assert p.path == self.s3

class test_existence:
"""
Test for directory and path existence
"""
def setUp(self):
base = Path("C:", "Users", "Bruce Eckel", "Downloads")
self.p1 = base + "TestFile1.tmp"
self.p2 = base + "TestFile2.tmp"
self.p3 = base + "TestFile3.tmp"

def test_basestring(self):
print type(self.p1)
assert isinstance(self.p1.path, basestring)

def test1(self):
"p1 existence"
open(self.p1.path, 'w').write('')
assert self.p1

def test2(self):
"p2 existence"
open(self.p2.path, 'w').write('')
assert self.p2

def test3(self):
"p3 existence"
assert not self.p3

def XXXtest_should_work(self):
"""
Produces:
open(self.p2, 'w').write('')
TypeError: coercing to Unicode: need st

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Michael Torrie
On 02/13/2012 09:01 AM, Rick Johnson wrote:
> Look, i hate super rich, arrogant people just as much i hate selfish
> people. 

But wait, Rick.  You are a man of contradictions.  We all are, but you
seem to bluster on and on more about it than most.  Firstly, to *hate*
anyone, super-rich, arrogant, or not, _is_ selfish by definition.  Also,
while I accept that you do not see yourself as arrogant, there are
others on this list, who are not particularly arrogant, who read your
posts as occasionally being extremely arrogant.  For example, your post
mocking people for using English in ways that you do not personally
approve.  Maybe this is just an artifact of the limitations of the
written word.

Now to the second contradiction.  You said that one way to fix health
care costs would be to deny it to anyone who could not afford health
care insurance.  Put in another way, health care should only go to those
that can afford to pay for the insurance or care, and not the
free-loaders.  Is that not what you said?  Thus a "super rich" person
should be commended as he will be able to afford health care without
burdening anyone else in society.  Does your hatred for super-rich,
arrogant, people mean that you believe there is an acceptable dollar
value for the wealth a person should morally be able to amass?

All of this reminds me that I've always wanted to ask you something.
After reading your many posts over the last couple of years, I am
curious.  What do you do for your career?  Are you a professional
software developer?

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Mark Lawrence

On 13/02/2012 21:01, Rick Johnson wrote:


Healthy people do not need healthcare very often, and in the rare
cases when they do, they don't bog down the system because their
bodies are strong. Why are their bodies strong? Because healthy people
eat correctly, healthy people exercise, therefore, healthy people have
correctly functioning immune systems -- of course quality genes always
help!


Please explain why previously healthy people get struck down with Common 
Fatigue Syndrome amongst other things.


--
Cheers.

Mark Lawrence.

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Chris Angelico
Rick, you are either...

On Tue, Feb 14, 2012 at 8:01 AM, Rick Johnson
 wrote:
> I can however tell you that what DOES matter is the continued
> improvement of the base gene pool. Yes, this improvement comes at a
> cost; the cost of the individual. Those with quality genes will reap
> the rewards, likewise, those with crap genes will not.

... a Nazi/Fascist/Commie mutant traitor, or...

> But go on falsely believing your little puny life matters. Go on
> believing in your worn out traditions and selfish languages and
> cultures. Go on believing that humans will be inhabiting this rock in
> the next 1000 years, or this universe in the next 10,000 -- because
> the enlightened few will have transcended into the mind hive and your @
> $$ will be glued to Terra firma forever!

... the Borg. I'm not sure which is worse.

Hmm, I think I just godwinned this thread. But at least I could couple
it with a Paranoia reference.

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


Re: frozendict

2012-02-13 Thread John Nagle

On 2/10/2012 9:52 PM, 8 Dihedral wrote:

在 2012年2月11日星期六UTC+8上午2时57分34秒,John Nagle写道:

On 2/10/2012 10:14 AM, Nathan Rice wrote:

Lets also not forget that knowing an object is immutable lets you do a
lot of optimizations; it can be inlined, it is safe to convert to a
contiguous block of memory and stuff in cache, etc.  If you know the
input to a function is guaranteed to be frozen you can just go crazy.
Being able to freeze(anyobject) seems like a pretty clear win.
Whether or not it is pythonic is debatable.  I'd argue if the meaning
of pythonic in some context is limiting, we should consider updating
the term rather than being dogmatic.


  A real justification for the ability to make anything immutable is
to make it safely shareable between threads.  If it's immutable, it
doesn't have to be locked for access.  Mozilla's new "Rust"
language takes advantage of this.  Take a look at Rust's concurrency
semantics.  They've made some progress.

John Nagl



Lets model the system as an asynchronous set of objects with multiple threads
performing operatons on objects as in the above.


   I'd argue for a concurrency system where everything is either 
immutable, unshared, synchronized, or owned by a synchronized object.

This eliminates almost all explicit locking.

   Python's use of immutability has potential in that direction, but
Python doesn't do anything with that concept.

John Nagle

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Rick Johnson
On Feb 13, 12:38 pm, Ian Kelly  wrote:
> I hate being suckered in by trolls, but this paragraph demands a response.
>
> On Mon, Feb 13, 2012 at 9:01 AM, Rick Johnson
>
>  wrote:
> > You are born with rights. Life, Liberty, and the pursuit of happiness.
> > Healthcare care is NOT a right, healthcare is a privileged.
>
> If you deprive a person of access to healthcare, and they die, then
> you have deprived them of life and thus violated the very rights that
> you just stated they had. And finally the "pursuit of happiness". Notice the 
> wording here: "pursuit". You have a right to PURSUE happiness, not a right to 
> steal it. Also, you are guaranteed happiness, only the right to purse your 
> version of happiness -- so long as that version does not interfere with 
> others rights.

You have a right to life, NOT a right to unnaturally extend your
lifetime by stealing the fruits of other people's labor (in this case:
money). You have a right to be free, but NOT to quell the freedom of
others so that YOU may benefit (in this case: taxation).

Healthy people do not need healthcare very often, and in the rare
cases when they do, they don't bog down the system because their
bodies are strong. Why are their bodies strong? Because healthy people
eat correctly, healthy people exercise, therefore, healthy people have
correctly functioning immune systems -- of course quality genes always
help!

> In any case, taking that phrase from the Declaration of Independence
> and holding it out as an exhaustive list of rights is moronic.  First,
> because it's not even a legal document -- it's only a statement of
> high-minded classical liberalism, albeit a historically important and
> influential one.  Second, because it actually states "We hold these
> truths to be self-evident, that all men are created equal, that they
> are endowed by their Creator with certain unalienable Rights, that
> **AMONG** these are Life, Liberty and the pursuit of Happiness."  The
> phrasing obviously implies that there are other human rights besides
> the three examples listed.  After all, the purpose of the document was
> not to enumerate all human rights, but to air a list of grievances
> against King George and assert the right to revolt against him.



> Incidentally, "not being required to pay taxes" is not something that
> the founding fathers would have considered a human right, taxation
> being necessary to support government and representative government
> (at least according to the Declaration of Independence) being
> necessary to secure those rights.

I never stated that taxation violated anyone's "human rights". And i
personally believe that "some" amount of taxation is a necessary in a
democratic society. How else would the government pay the bills? Rule
of law, infrastructure, national security (just to name a few) are all
subjects that the government must handle for the sake of society as a
whole.

HOWEVER, healthcare is not a concern of the greater society, but only
the individual -- with the exception of contagious disease of course,
which effects us all! Cardiovascular diseases, cancers, cirrhosis,
kidney failure, stroke, diabetes, etc..., are NOT contagious but
continue to be a drain on healthcare costs. In fact, most of these
problems are the results of an unhealthy lifestyle.

Listen, I have no objection to folks living an unhealthy lifestyle. I
say, if that's what makes you happy, GO FOR IT!. However, i'll be
damned if i am going to subsidize their healthcare because now they
are dying and can't afford the medical bills.

Likewise if someone gets hit by a bus... was the person j-walking? If
so, too bad. Ride a motorcycle without a helmet and get a concussion,
too bad. Drink and drive and then end up in a coma, too bad! You play
with fire and you get burned! You kick a bear in the ass and you get
eaten. You stick your head in a crocodiles mouth and you suffer the
consequences! You are not fit to survive in this universe. You were
given fear for a reason. You were given pain for a reason. Those who
refuse to learn are culled from the herd.

> > Procreation should be a
> > privilege, however sadly for our collective evolution, it's seems to
> > be a right :(
>
> There is a word for the philosophy that procreation should be a
> privilege reserved for those with good genes: eugenics.

No, the word is evolution; which means: "survival of the fittest".

Listen, i will be the first to admit that evolution is VERY unfair to
those among us who have a poor gene pool. Poor genes are not our
fault. We did not get to CHOOSE our genes, or our parents, or our
country of origin, or etc, etc, etc! But these ARE the cards we were
dealt as individuals of a species. That last sentence is VERY
important: "individuals of a species". We like to think that our
individual lives matter in the greater scheme of things, but i can
assure you we don't matter.

Anyone who has studied animal behavior knows that only the strongest
males are allowed to mate. 

(Rebooting) Python Usage Statistics

2012-02-13 Thread Eric Snow
The original topic got side-tracked pretty quickly (surprise,
surprise).  However, I think the question is valuable enough that it's
worth broaching again.  Notably, the first time around I did get a
meaningful response (thanks Stefan!).  If you do feel like diverging
from the topic of gathering usage statistics, please at least change
the subject.  

I've also started a wiki page:

  http://wiki.python.org/moin/usage_stats

Feel free to add to it.

--

Does anyone have (or know of) accurate totals and percentages on how
Python is used?  I'm particularly interested in the following
groupings:

- new development vs. stable code-bases
- categories (web, scripts, "big data", computation, etc.)
- "bare metal" vs. on top of some framework
- regional usage

I'm thinking about this partly because of a discussion on python-ideas
about [some U-word related topic ].  All the rhetoric, anecdotal
evidence, and use-cases there have little meaning to me, in regards to
Python as a whole, without an understanding of who is actually
affected.

For instance, if frameworks (like django and numpy) could completely
hide the arguable challenges of [some feature] in Python 3--and most
projects were built on top of frameworks--then general efforts for
making [some feature] easier in Python 3 should go toward helping
framework writers.

Such usage numbers help us know where efforts could be focused in
general to make Python more powerful and easier to use where it's
already used extensively.  They can show us the areas that Python
isn't used much, thus exposing a targeted opportunity to change that.

Realistically, it's not entirely feasible to compile such information
at a comprehensive level, but even generally accurate numbers would be
a valuable resource.  If the numbers aren't out there, what would some
good approaches to discovering them?  Thanks!

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Chris Angelico
On Tue, Feb 14, 2012 at 5:38 AM, Ian Kelly  wrote:
> "... Rights, that
> **AMONG** these are Life, Liberty and the pursuit of Happiness."

AMONG our rights are such elements as Life, Liberty, the Pursuit of
Happiness, and an almost fanatical devotion to the Founding
Fathers I'll come in again.

(Does that drag this back on topic? Almost? Vain attempt to at least
look like it's on topic?)

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


Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Waylan Limberg
On Mon, Feb 13, 2012 at 3:16 PM, Arnaud Delobelle  wrote:
>> Strangely it was working fine the other day. Then while debugging a
>> script it suddenly started do this and now does this for every script
>
> How were you debugging?

I think I may have been attempting to use pipes to redirect stdin
and/or stdout when the problem first presented itself.  Unfortunately,
once I closed the window, I lost whatever pipe combination I had
tried.

It just occurred to me that I was unsure if I had been doing that pipe
correctly, and that maybe I overwrote python.exe. Sure enough, the
modify date on that file indicated I overwrote it. A re-install has
resolved the problem.

It's just a little embarrassing that I didn't think of that until now,
but the fact that everything else seems to work was throwing me off.
Of course, everything else was running `pythonw.exe` not `python.exe`.

Anyway, thanks for the pointer Arnaud.

-- 

\X/ /-\ `/ |_ /-\ |\|
Waylan Limberg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Arnaud Delobelle
On 13 February 2012 19:50, waylan  wrote:
> When I try running any Python Script on the command line with Python
> 3.2 I get this weird behavior. The cursor dances around the command
> line window and nothing ever happens. Pressing Ctr+C does nothing.
> When I close the window (mouse click on X in top right corner), an
> error dialog appears asking me to "force" it to close.

I'm not a Windows user, so I can't be of assistance but it may help
others if you explained how you installed Python 3.2 on your computer.
 Also have you tried reinstalling it?

> Strangely it was working fine the other day. Then while debugging a
> script it suddenly started do this and now does this for every script

How were you debugging?

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


Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread waylan
When I try running any Python Script on the command line with Python
3.2 I get this weird behavior. The cursor dances around the command
line window and nothing ever happens. Pressing Ctr+C does nothing.
When I close the window (mouse click on X in top right corner), an
error dialog appears asking me to "force" it to close.

See a short (26 sec) video of it here: https://vimeo.com/36491748

Also, the printer suddenly starts printing multiple copies of the
contents of the command line window - which has wasted much paper.

Strangely it was working fine the other day. Then while debugging a
script it suddenly started do this and now does this for every script
I've run in Python 3.2. Multiple system reboots had no effect.
I also have Python 2.5 & 2.7 installed and they work fine.

Even the most basic script results in this behavior:

if __name__ == "__main__":
print("Hello, World!")

In an attempt to check the exact version of Python, even this causes
the strange behavior:

c:\Python32\python.exe -V

I'm on Windows XP if that matters. IDLE (which works fine) tells me
I'm on Python 3.2.2

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


Python barcode scanner was RE:

2012-02-13 Thread Prasad, Ramit
From: roncy thomas
Sent: Monday, February 13, 2012 1:16 PM
To: python-list@python.org
Subject: 

I'm doing a miniproject on electronics voting system.I require help for 
creating a code in python for coverting the barcode into binary digits.Or 
atleast an algorithm for the same..please Help..Reply to this mail id.

Kindly help me.
===

One of these should help: 
http://stackoverflow.com/questions/4434959/usb-barcode-scanner-research
http://zbar.sourceforge.net/

Please include a descriptive subject next time.


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2012-02-13 Thread roncy thomas

I'm doing a miniproject on electronics voting system.I require help 
for creating a code in python for coverting the barcode into binary digits.Or 
atleast an algorithm for the same..please Help..Reply to this mail id.

Kindly help me.

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


Re: package extension problem

2012-02-13 Thread Terry Reedy

On 2/13/2012 12:58 PM, Miki Tebeka wrote:

import new_pandas as np df =
np.DataFrame({'A':[1,2,3],'B':[4,5,6]}) col_A = df['A']

I'm not familiar with pandas, but my *guess* will be that you'll need
to override __getitem__ in the new DataFrame.


This is essentially the same problem that if you, for instance, subclass
int as myint, you need to override (wrap) *every* method to get them to 
return myints instead of ints.


class myint(int):
...
def __add__(self, other): return myint(self+other)


In the OP's case, if the original class is in python, one might be able 
to just change the __class__ attribute. But I would make sure to have a 
good set of tests in any case.


--
Terry Jan Reedy

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Ian Kelly
I hate being suckered in by trolls, but this paragraph demands a response.

On Mon, Feb 13, 2012 at 9:01 AM, Rick Johnson
 wrote:
> You are born with rights. Life, Liberty, and the pursuit of happiness.
> Healthcare care is NOT a right, healthcare is a privileged.

If you deprive a person of access to healthcare, and they die, then
you have deprived them of life and thus violated the very rights that
you just stated they had.

In any case, taking that phrase from the Declaration of Independence
and holding it out as an exhaustive list of rights is moronic.  First,
because it's not even a legal document -- it's only a statement of
high-minded classical liberalism, albeit a historically important and
influential one.  Second, because it actually states "We hold these
truths to be self-evident, that all men are created equal, that they
are endowed by their Creator with certain unalienable Rights, that
**AMONG** these are Life, Liberty and the pursuit of Happiness."  The
phrasing obviously implies that there are other human rights besides
the three examples listed.  After all, the purpose of the document was
not to enumerate all human rights, but to air a list of grievances
against King George and assert the right to revolt against him.

Incidentally, "not being required to pay taxes" is not something that
the founding fathers would have considered a human right, taxation
being necessary to support government and representative government
(at least according to the Declaration of Independence) being
necessary to secure those rights.

> Procreation should be a
> privilege, however sadly for our collective evolution, it's seems to
> be a right :(

There is a word for the philosophy that procreation should be a
privilege reserved for those with good genes: eugenics.  Welcome to
fascism, Rick.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: package extension problem

2012-02-13 Thread Peter Otten
Fabrizio Pollastri wrote:

> Ok. To be more clear, consider the real python package Pandas.
> 
> This package defines a Series class and a DataFrame class.
> The DataFrame is a matrix that can have columns of
> different type.
> 
> If I write
> 
> import pandas as pd
> df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
> 
> a data frame with two cols named A and B is created.
> 
> If I write
> 
> col_A = df['A']
> 
> the returned col_A is an instance of Series.
> 
> Now , let suppose that I want to extend some functionality of pandas
> by adding new methods to both Series and DataFrame classes.
> 
> One way to do this is to redefine this classes in a new package
> (new_pandas) as follow
> 
> import pandas as pd
> 
> class Series(pd.Series):
>   ...
>   add new methods
>   ...
> 
> class DataFrame(pd.DataFrame):
>   ...
>   add new methods
>   ...
> 
> When I use the new package as a pandas substitute and write
> 
> import new_pandas as np
> df = np.DataFrame({'A':[1,2,3],'B':[4,5,6]})
> col_A = df['A']
> 
> col_A is an instance of the original pandas and not of the new pandas,
> losing all the added functionality.

A quick look into the pandas source reveals that the following might work:

# untested
class DataFrame(pd.DataFrame):
@property
def _constructor(self):
return DataFrame # your class
# your new methods


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


Re: Python usage numbers

2012-02-13 Thread Andrew Berg
On 2/12/2012 10:19 PM, Ben Finney wrote:
> If it helps, ASCII art *is* UTF-8 art. So it will be the same in UTF-8.
As will non-ASCII text art:

   /l、
 ゙(゚、 。 7
  l、゙ ~ヽ
  じしf_, )ノ

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: package extension problem

2012-02-13 Thread Jerry Hill
On Sun, Feb 12, 2012 at 1:46 PM, Fabrizio Pollastri wrote:

> Hello,
>
> I wish to extend the functionality of an existing python package by
> creating
> a new package that redefines the relevant classes of the old package. Each
> new class inherits the equivalent old class and adds new methods.
> ...

There is a way to solve this problem without redefining in the new package
> all the
> methods of the old package that return old classes?
>

The general answer is no.  If you want the methods of your subclass to
behave differently, in any way, from the same methods in the superclass,
then you must write new code that defines the behavior that you want.

Sometimes people write their classes so they automatically play nicely when
subclassed, and sometimes they don't.  In general, it's impossible to
always do the right thing when you don't know what particular behavior a
subclass might need to override, so a lot of times people don't bother to
write their classes to check for subclasses being passed in, etc.

Since you haven't actually shown us any code, that's about all I can tell
you.

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


Re: package extension problem

2012-02-13 Thread Miki Tebeka
> import new_pandas as np 
> df = np.DataFrame({'A':[1,2,3],'B':[4,5,6]}) 
> col_A = df['A']
I'm not familiar with pandas, but my *guess* will be that you'll need to 
override __getitem__ in the new DataFrame.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: package extension problem

2012-02-13 Thread Fabrizio Pollastri

Ok. To be more clear, consider the real python package Pandas.

This package defines a Series class and a DataFrame class.
The DataFrame is a matrix that can have columns of
different type.

If I write

import pandas as pd
df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})

a data frame with two cols named A and B is created.

If I write

col_A = df['A']

the returned col_A is an instance of Series.

Now , let suppose that I want to extend some functionality of pandas
by adding new methods to both Series and DataFrame classes.

One way to do this is to redefine this classes in a new package
(new_pandas) as follow

import pandas as pd

class Series(pd.Series):
 ...
 add new methods
 ...

class DataFrame(pd.DataFrame):
 ...
 add new methods
 ...

When I use the new package as a pandas substitute and write

import new_pandas as np
df = np.DataFrame({'A':[1,2,3],'B':[4,5,6]})
col_A = df['A']

col_A is an instance of the original pandas and not of the new pandas, 
losing all the added functionality.



Fabrizio











Now, how can I add new methods to extend the functionality of pandas 
classes Series and DataFrame


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


Re: package extension problem

2012-02-13 Thread Miki Tebeka
> B[some_hash] still returns an instance of the old class A, while I want 
an instance of the new class A. 
I don't understand this sentence. How does B[some_hash] related to A?

I've tried the below and it seems to work. Can you paste some code to help us 
understand more?

-- old.py --
class A:
pass

-- new.py __
import old
class A(old.A):
pass

-- main.py --
import new
a = new.A()
a.__class__ # Shows new.A
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XSLT to Python script conversion?

2012-02-13 Thread Mike C. Fletcher

On 12-02-13 06:20 AM, Matej Cepl wrote:

Hi,

I am getting more and more discouraged from using XSLT for a 
transformation from one XML scheme to another one. Does anybody could 
share any experience with porting moderately complicated XSLT 
stylesheet 
(https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl) 
into a Python script using ElementTree's interparse or perhaps xml.sax?


Any tools for this? Speed differences (currently I am using xsltproc)? 
Any thoughts?


Thank you,

Matěj
I wound up rewriting the Docbook to XSL transformation for PyOpenGL's 
docs in Python using lxml.etree and Kid (now reworked to use Genshi).  
However, that was a fairly direct translation, it has only a handful of 
strategies for transforming nodes from docbook to xhtml.  That said, it 
took our processing time down from 
so-long-I-just-didn't-want-to-work-on-the-docs down to 
regenerate-whenever-I-make-a-trivial-change.


http://bazaar.launchpad.net/~mcfletch/pyopengl/directdocs/files 



Is the repository where the project lives.  It *also* does a lot of 
other processing, but the generate.py, model.py and 
templates/section.kid files are all you need to look at to understand 
the docbook processing.


HTH,
Mike

--

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Rick Johnson
On Feb 13, 10:12 am, Steven D'Aprano  wrote:
> On Mon, 13 Feb 2012 08:01:59 -0800, Rick Johnson wrote:
> > Evolution knows how to handle degenerates.
>
> And yet here you still are.

Embrace the perfection of evolution, and both our needs shall be met!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Steven D'Aprano
On Mon, 13 Feb 2012 08:01:59 -0800, Rick Johnson wrote:

> Evolution knows how to handle degenerates.

And yet here you still are.


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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Rick Johnson
On Feb 13, 2:05 am, Steven D'Aprano  wrote:
> On Sun, 12 Feb 2012 20:48:54 -0800, Rick Johnson wrote:
> > Do you think that cost of healthcare is the problem? Do you think the
> > cost of healthcare insurance is the problem? NO! The problem is people
> > expect entitlements.
>
> Entitlements? I work hard and pay my taxes. I *earned* that healthcare
> that [gentlemen] like you call an entitlement. Damn straight it's an
> entitlement -- I paid for it, I earned it, I'm entitled to it,

And just how much healthcare dollars are you entitled to exactly? Can
you put your entitlement into some form of monetary value?

And how can we ever make a system like this fair? If someone works for
30 years and pays a 30% tax rate and another works for 2 years and
pays 15%, then how do we delegate the fair share? The answer is you
can't delegate fairness in a system like this. The system of "i pay
taxes therfore i deserve a free heart transplant" is broken!

And don't forget, your tax dollars are not just for coving the cost of
healthcare. What about infrastructure, social security, welfare,
military, government bail-outs, bribe money to rouge states, earmarks,
bridges to nowhere, and and even planting trees on the main highways?
These things cost money you know!

How about instead of enriching the government by increasing taxes YOU
just live within your means? If you can afford healthcare, great! If
not, too bad.

>  and if you
> try to steal if from me, expect a fight.

Steal what from you... you're stealing from everyone else! You're
expecting ME to cover YOUR healthcare. What's next? I should
supplement your income so you can you buy a summer home?

What about folks who gorge on sugar, saturated fats, and salt all
their lives with no regard for their own health? What happens when
they develop diabetes, heart disease, and cancer? Do you think the
measly little amount of taxes they payed (IF THEY PAYED AT ALL!) will
cover a heart transplant or cancer treatments? Who will pay when they
cannot?

What about the idiots who smoke cigarettes, drink alcohol, and/or
abuse drugs (prescription or otherwise). Should your tax dollars cover
these medical expenses? Who will pay when they cannot?

What about people who are too lazy to cook their children healthy
meals and instead rely on fast food and soda? What happens when those
same kids become morbidly obese? Why are we not charging these idiots
with child abuse? Who will pay when they cannot?

*Selfish Sam blubbers:* "I pay taxes, so the government needs to
subsidize my unhealthy lifestyle!"

But where does the "government money" come from Sam?
Sam: Taxes?
Very good Sam, and WHO pays taxes?
Sam: Citizens?
You're very smart Sam. And what do think will happen when the
government needs more money?
Sam: They will increase taxes?
Good boy Sam! Here is a treat. Now run along and fetch the newspaper.

Taxes are tranny. And you WANT to give them an excuse to increase
taxes! We are doomed!

> Socialised healthcare is a win-win system:

Sure, for the degenerates!

> - the working class wins, because they get healthcare at a much cheaper
> rate than they could otherwise afford

Healthcare is expensive. Do you want a minimum wage doctor curing your
ills? And the frivolous lawsuits are not bringing the costs down
either.

> - bosses win, because they have reduced absenteeism, lower training costs
> to replace workers who die, and fewer epidemics that threaten their own
> families

BS! With free healthcare, those who would have allowed their immune
system fight off the flu, now take off from work, visit a local
clinic, and get pumped full of antibiotics so they can create a new
strain of antibiotic resistant flu virus! Thanks free healthcare!

> - Wall Street wins, because productivity is increased due to better health

Oh yes, and wall street is the hope of the future. Thank god they are
winning. Thank god they are healthy enough to rob us for another day.
Thank god!

> - pharmaceutical companies win, because even though their profits on
> individual items are reduced, their increased sales more than make up for
> it

This is the same thing that happened to the funiture industry. They
call it the "Assembly Line". I don't know how you feel, but i think
mass produced furniture sucks a big fat Python!

> - doctors win, because they spend more time getting paid to deal with
> patients and less unproductive time on dealing with insurance companies

Doctors have minions for those tasks. Do you actually believe doctors
are on the phone with insurance companies? They are at the freaking
golf course!

> - the economy wins, because fewer people are bankrupted by simple medical
> procedures

It sucks that medical can be so expensive, and i am all for reducing
the costs. However, we cannot implement a system that rewards the
slothful degenerates of society on the backs of the hard working.
Evolution knows how to handle degenerates.

> The only loss is for the insurers, who have to get an honest job. So why

Re: Removing items from a list

2012-02-13 Thread Thomas Philips
I could indeed have addressed this problem with a list comprehension.
It escaped me at the time because the larger problem I was trying to
solve included removing data from a dictionary:

months =
sorted(list(dataDict.keys()))  #Sort
months in ascending order

for mth in
reversed(months):#Remove
months with inadequate data
if len(dataDict[mth]) < minItems:
   months.remove(mth)
   del dataDict[mth]

There's more than one way to solve this problem, and, with the benefit
of hindsight, my solution was sloppy, but thanks to the help I
received, I was able to get my code working correctly. Cleaning up is
the next phase!

Thanks, all.

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


ANN: eGenix pyOpenSSL Distribution 0.13.0-1.0.0g

2012-02-13 Thread eGenix Team: M.-A. Lemburg

ANNOUNCING

   eGenix.com pyOpenSSL Distribution

 Version 0.13.0-1.0.0g


 An easy-to-install and easy-to-use distribution
 of the pyOpenSSL Python interface for OpenSSL -
available for Windows, Mac OS X and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.0-1.0.0g-1.html


INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python.

It comes with an easy-to-use installer that includes the most recent
OpenSSL library versions in pre-compiled form, making your application
independent of OS provided OpenSSL libraries:

http://www.egenix.com/products/python/pyOpenSSL/

pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS-
aware network applications as well as certificate management tools:

https://launchpad.net/pyopenssl/

OpenSSL is an open-source implementation of the SSL/TLS protocol:

http://www.openssl.org/


NEWS

This new release of the eGenix.com pyOpenSSL Distribution updates the
included pyOpenSSL version to 0.13.0 and the included OpenSSL version
to 1.0.0g.

Main new features in pyOpenSSL sine 0.10.0
--

 * pyOpenSSL 0.11 fixes a few bugs related to error processing;
   see https://launchpad.net/pyopenssl/+announcement/7128

 * pyOpenSSL 0.12 fixes interaction with memoryviews, adds TLS
   callbacks and x509 extension introspection;
   see https://launchpad.net/pyopenssl/+announcement/8151

 * pyOpenSSL 0.13 adds OpenSSL 1.0 support (which eGenix
   contributed) and a few new APIs;
   see https://lists.launchpad.net/pyopenssl-users/msg8.html

Please see Jean-Paul Calderone's above announcements for more details.

New features in OpenSSL 1.0.0g since 1.0.0a
---

OpenSSL 1.0.0g fixes several vulnerabilities relative to 1.0.0a:

http://openssl.org/news/vulnerabilities.html

and includes a number of stability enhancements as well as extra
protection against attacks:

http://openssl.org/news/changelog.html

New features in the eGenix pyOpenSSL Distribution
-

 * Updated the pyOpenSSL license information from LGPL to
   Apache License 2.0.

 * Added support for Python 2.7 on all platforms.

 * Added documentation for automatic download of egg distributions
   using compatible tools such as easy_install and zc.buildout.

As always, we provide binaries that include both pyOpenSSL and the
necessary OpenSSL libraries for all supported platforms:
Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64.

We've also added egg-file distribution versions of our eGenix.com
pyOpenSSL Distribution for Windows, Linux and Mac OS X to the
available download options. These make setups using e.g. zc.buildout
and other egg-file based installers a lot easier.


DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/pyOpenSSL/


UPGRADING

Before installing this version of pyOpenSSL, please make sure that
you uninstall any previously installed pyOpenSSL version. Otherwise,
you could end up not using the included OpenSSL libs.

___
SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.


MORE INFORMATION

For more information about the eGenix pyOpenSSL Distributon, licensing
and download instructions, please visit our web-site or write to
sa...@egenix.com.

Enjoy,

-- 
Marc-Andre Lemburg
eGenix.com

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


::: Try our new mxODBC.Connect Python Database Interface for free ! 


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

Re: XSLT to Python script conversion?

2012-02-13 Thread Stefan Behnel
Matej Cepl, 13.02.2012 12:20:
> I am getting more and more discouraged from using XSLT for a transformation
> from one XML scheme to another one.

Could you explain what it is that discourages you about it? That would
allow us to come up with better alternatives for your specific problem.


> Does anybody could share any experience
> with porting moderately complicated XSLT stylesheet
> (https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl)
> into a Python script using ElementTree's interparse or perhaps xml.sax?
> 
> Any tools for this? Speed differences (currently I am using xsltproc)? Any
> thoughts?

You could try switching to lxml. It would at least allow you to do a part
of the processing in Python and only use XSLT when it seems more
appropriate and/or easier.

Stefan

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


Re: Read-only attribute in module

2012-02-13 Thread mloskot

Terry Reedy wrote
> 
> On 2/10/2012 6:11 AM, mloskot wrote:
>> The intent of xyz.flag is that it is a value set by the module
>> internally.
>> xyz is a module wrapping a C library.
>> The C library defines concept of a global flag set by the C functions at
>> some events,
>> so user can check value of this flag.
>> I can provide access to it with function: xyz.get_flag()
> 
> If the value of the flag can change during a run, I would do that. 
> Otherwise, you have to make sure the local copy keeps in sync. Users 
> might also think that it is a true constant that they could read once.
> 
> I understand that you might be concerned that one person in a 
> multi-programmer project might decide to rebind xyz.flag and mess up 
> everyone else. I think the real solution might be an option to freeze an 
> entire module.
> 

Terry,

Thanks for your really helpful notes.

Best regards,


-
-- 
Mateusz Loskot
http://mateusz.loskot.net
--
View this message in context: 
http://python.6.n6.nabble.com/Read-only-attribute-in-module-tp4378950p4464760.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


XSLT to Python script conversion?

2012-02-13 Thread Matej Cepl

Hi,

I am getting more and more discouraged from using XSLT for a 
transformation from one XML scheme to another one. Does anybody could 
share any experience with porting moderately complicated XSLT stylesheet 
(https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl) 
into a Python script using ElementTree's interparse or perhaps xml.sax?


Any tools for this? Speed differences (currently I am using xsltproc)? 
Any thoughts?


Thank you,

Matěj
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Sarge, a library wrapping the subprocess module, has been released.

2012-02-13 Thread Vinay Sajip
On Feb 13, 7:08 am, Anh Hai Trinh  wrote:
> > Objection! Does the defense REALLY expect this court to believe that
> > he can testify as to how MOST members of the Python community would or
> > would not favor bash over Python? And IF they do in fact prefer bash,
> > is this display of haughty arrogance nothing more than a hastily
> > stuffed straw-man presented to protect his own ego?
>
> Double objection! Relevance. The point is that the OP created another 
> language that is neither Python nor Bash.
>

Triple objection! I think Rick's point was only that he didn't think
you were expressing the views of "most" people, which sort of came
across in your post.

To say I've created "another language" is misleading - it's just a
subset of Bash syntax, so you can do things like "echo foo; echo bar",
use "&&", "||" etc. (I used the Bash man page as my guide when
designing the parser.)

As an experiment on Windows, in a virtualenv, with GnuWin32 installed
on the path:

(venv) C:\temp>python
ActivePython 2.6.6.17 (ActiveState Software Inc.) based on
Python 2.6.6 (r266:84292, Nov 24 2010, 09:16:51) [MSC v.1500 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from extproc import sh
>>> sh('echo foo; echo bar')
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\temp\venv\lib\site-packages\extproc.py", line 412, in sh
f = Sh(cmd, fd=fd, e=e, cd=cd).capture(1).stdout
  File "C:\temp\venv\lib\site-packages\extproc.py", line 202, in
capture
p = subprocess.Popen(self.cmd, cwd=self.cd, env=self.env,
stdin=self.fd[0],
stdout=self.fd[1], stderr=self.fd[2])
  File "C:\Python26\Lib\subprocess.py", line 623, in __init__
errread, errwrite)
  File "C:\Python26\Lib\subprocess.py", line 833, in _execute_child
startupinfo)
WindowsError: [Error 3] The system cannot find the path specified

>>> from sarge import capture_stdout
>>> capture_stdout('echo foo; echo bar').stdout.text
u'foo\r\nbar\r\n'
>>>

That's all from a single interactive session. So as you can see, my
use cases are a little different to yours, which in turn makes a
different approach reasonable.

> My respectful opinion is that the OP's approach is fundamentally flawed. 
> There are many platform-specific issues when forking and threading are fused. 
> My benign intent was to warn others about unsolved problems and 
> scratching-your-head situations.
>
> Obviously, the OP can always choose to continue his direction at his own 
> discretion.

I think you were right to bring up the forking+threading issue, but I
have addressed the points you made in this thread - please feel free
to respond to the points I made about the Linux Programming Blog
article. I've updated the sarge docs to point to that article, and
I've added a section on API stability to highlight the fact that the
library is in alpha status and that API changes may be needed based on
feedback.

I'm not being blasé about the issue - it's just that I don't want to
be too timid, either. Python does not proscribe using subprocess and
threads together, and the issues you mention could easily occur even
without the use of sarge. You might say that sarge makes it more
likely that the issues will surface - but it'll only do that if you
pass "a & b & c & d" to sarge, and not otherwise.

The other use of threads by sarge - to read output streams from child
processes - is no different from the stdlib usage of threads in
subprocess.Popen.communicate().

Possibly Rick was objecting to the tone of your comments, but I
generally disregard any tone that seems confrontational when the
benefit of the doubt can be given - on the Internet, you can never
take for granted, and have to make allowances for, the language style
of your interlocutor ... I think you meant well when you responded,
and I have taken your posts in that spirit.

Regards,

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


Re: ANN: Sarge, a library wrapping the subprocess module, has been released.

2012-02-13 Thread Vinay Sajip
On Feb 13, 3:57 am, Anh Hai Trinh  wrote:

>
> I don't disagree with it. But the solution is really easy, just call 'sh' and 
> pass it a string!
>
> >>> from extproc import sh
> >>> n = int(sh(“ls /etc –1 | wc –l”))
>
> No parser needed written!
>
> Yes there is a danger of argument parsing and globs and all that. But people 
> are aware of it. With string parsing, ambiguity is always there. Even when 
> you have a BNF grammar, people easily make mistakes.

You're missing a few points:

* The parser is *already* written, so there's no point worrying about
saving any effort.
* Your solution is to pass shell=True, which as you point out, can
lead to shell injection problems. To say "people are aware of it" is
glossing over it a bit - how come you don't say that when it comes to
locking+forking? ;-)
* I'm aiming to offer cross-platform functionality across Windows and
Posix. Your approach will require a lower common denominator, since
the Windows shell (cmd.exe) is not as flexible as Bash. For example -
no "echo foo; echo bar"; no "a && b" or "a || b" - these are not
supported by cmd.exe.
* Your comment about people making mistakes applies just as much if
someone passes a string with a Bash syntax error, to Bash, via your
sh() function. After all, Bash contains a parser, too. For instance:

>>> from extproc import sh
>>> sh('ls >>> abc')
/bin/sh: Syntax error: redirection unexpected
''

If you're saying there might be bugs in the parser, that's something
else - I'll address those as and when they turn up.

Regards,

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


Re: how to tell a method is classmethod or static method or instance method

2012-02-13 Thread 88888 Dihedral
在 2012年2月13日星期一UTC+8下午4时03分24秒,Steven D'Aprano写道:
> On Mon, 13 Feb 2012 15:59:27 +0900, Zheng Li wrote:
> 
> > how to tell a method is class method or static method or instance
> > method?
> 
> That's a good question, with a subtle answer that depends on exactly what 
> you mean by the question. If you mean the object you get back from 
> ordinary attribute access like "instance.method", then you do this:
> 
> >>> class K(object):
> ... @classmethod
> ... def cmethod(cls):
> ... pass
> ... @staticmethod
> ... def smethod():
> ... pass
> ... def method(self):
> ... pass
> ... 
> >>> k = K()
> >>> type(k.smethod)
> 
> 
> So static methods are just functions, and both class methods and instance 
> methods share the same underlying type:
> 
> >>> type(k.method)
> 
> >>> type(k.cmethod)
> 
> 
> 
> But if you dig deeper, you learn that all methods are actually 
> descriptors:
> 
> >>> type(K.__dict__['cmethod'])
> 
> >>> type(K.__dict__['smethod'])
> 
> >>> type(K.__dict__['method'])
> 
> 
> (Functions are descriptors too.)
> 
> This is deep magic in Python, but if you want to learn more about it, you 
> can read this:
> 
> http://users.rcn.com/python/download/Descriptor.htm
> 
> 
> And I'll take this opportunity to plug my dualmethod descriptor:
> 
> http://code.activestate.com/recipes/577030-dualmethod-descriptor/
> 
> 
> 
> -- 
> Steven

The methods of an object can be well organized
to avoid redundant checks of operations 
desired to be performed on the object.

Also an object's methods should be factored to be easy to be maintained
 and to provide debugging and error information for the programmer to track
the operations related to the hardware, the OS, and the sofware design
issues. 




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


Re: M2crypto

2012-02-13 Thread zigi
Hello,
this is must be testing time to crypt files, using just M2crypto :-)
I know this is a strange use of the library, but such is the will of
the management.




On 13 Lut, 01:28, geremy condra  wrote:
> On Sun, Feb 12, 2012 at 4:00 PM, Mel Wilson  wrote:
> > zigi wrote:
>
> >> Hello,
> >> M2crypto
>
> >> __init__(self, alg, key, iv, op, key_as_bytes=0, d='md5',
> >> salt='12345678', i=1, padding=1)
>
> >> I wont write app, using M2crypto and I can not understand what are the
> >> arguments:
> >> key, iv, op, salt ?
> >> What they do ?
>
> > I assume you're reading in 
> > about M2Crypto.EVP.Cipher.
>
> > Epydoc claims another victim.
>
> > I'm having a lot of trouble finding documentation.  The obvious OpenSSL
> > pages are kind of thin, too.  You might see some useful code in the EVP unit
> > tests m2crypto/tests/test_evp.py in the m2crypto installation.
>
> Not intending to be rude, but being perfectly serious: as a general
> rule, if you don't know what an IV is you're probably getting yourself
> into a lot of trouble working with low-level crypto libraries.
>
> Two suggestions:
>
> 1. Describe what you're trying to do- I'll be able to help more if I
> know what you're actually going for.
>
> 2. Try keyczar. It's not perfect, but it's a lot easier to get right.
>
> Geremy Condra

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


OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Steven D'Aprano
On Sun, 12 Feb 2012 20:48:54 -0800, Rick Johnson wrote:

> Do you think that cost of healthcare is the problem? Do you think the
> cost of healthcare insurance is the problem? NO! The problem is people
> expect entitlements.

Entitlements? I work hard and pay my taxes. I *earned* that healthcare 
that trolls like you call an entitlement. Damn straight it's an 
entitlement -- I paid for it, I earned it, I'm entitled to it, and if you 
try to steal if from me, expect a fight.

Socialised healthcare is a win-win system:

- the working class wins, because they get healthcare at a much cheaper 
rate than they could otherwise afford

- bosses win, because they have reduced absenteeism, lower training costs 
to replace workers who die, and fewer epidemics that threaten their own 
families

- Wall Street wins, because productivity is increased due to better health

- pharmaceutical companies win, because even though their profits on 
individual items are reduced, their increased sales more than make up for 
it

- doctors win, because they spend more time getting paid to deal with 
patients and less unproductive time on dealing with insurance companies

- the economy wins, because fewer people are bankrupted by simple medical 
procedures

The only loss is for the insurers, who have to get an honest job. So why 
on earth is anyone against socialised healthcare when it provably works 
better than the US system?

Simple. To a certain mind, "win-win" is not a good thing, it is a bad 
thing. "Win-win" implies that you might have to share the pie instead of 
eating it all yourself, and to that sort of person, anything less than 
ALL the pie might as well be nothing at all. What's the point of being 
wealthy and powerful without having hungry, sick peons to lord over? How 
will you know you have won unless others lose?

The inefficiencies (economic and moral) of the US private healthcare 
system are not a bug, they are a feature. It is part of the war the 1% of 
the 1% have been waging on the rest of society for the last 40 years.


> You are only born with one
> guarantee; you will die, guaranteed! Any questions?

Yes. Why haven't you moved to a libertarian paradise like Somalia yet? 
You'd like it there. There are two sorts of people: those who can afford 
their own private militia, and victims.


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


Re: how to tell a method is classmethod or static method or instance method

2012-02-13 Thread Steven D'Aprano
On Mon, 13 Feb 2012 15:59:27 +0900, Zheng Li wrote:

> how to tell a method is class method or static method or instance
> method?

That's a good question, with a subtle answer that depends on exactly what 
you mean by the question. If you mean the object you get back from 
ordinary attribute access like "instance.method", then you do this:

>>> class K(object):
... @classmethod
... def cmethod(cls):
... pass
... @staticmethod
... def smethod():
... pass
... def method(self):
... pass
... 
>>> k = K()
>>> type(k.smethod)


So static methods are just functions, and both class methods and instance 
methods share the same underlying type:

>>> type(k.method)

>>> type(k.cmethod)



But if you dig deeper, you learn that all methods are actually 
descriptors:

>>> type(K.__dict__['cmethod'])

>>> type(K.__dict__['smethod'])

>>> type(K.__dict__['method'])


(Functions are descriptors too.)

This is deep magic in Python, but if you want to learn more about it, you 
can read this:

http://users.rcn.com/python/download/Descriptor.htm


And I'll take this opportunity to plug my dualmethod descriptor:

http://code.activestate.com/recipes/577030-dualmethod-descriptor/



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