Re: [Python-ideas] Make "is" checks on non-singleton literals errors

2012-10-09 Thread Chris Angelico
On Tue, Oct 9, 2012 at 1:14 PM, Guido van Rossum  wrote:
> Maybe we should do something more drastic and always create a new,
> unique constant whenever a literal occurs as an argument of 'is' or
> 'is not'? Then such code would never work, leading people to examine
> their code more closely. I betcha we have people who could change the
> bytecode compiler easily enough to do that. (I'm not seriously
> proposing this, except as a threat of what we could do if the
> SyntaxWarning is rejected. :-)

That wouldn't guarantee that the code would never work, merely that
the 'is' checks would be never true. Dangerous if the condition is a
guard for an unusual condition. A unit test could of course catch it,
but that assumes that everyone who writes "if x is 0" has tests
probing both branches of that check...

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


Re: Unpaking Tuple

2012-10-09 Thread Jussi Piitulainen
Dave Angel writes:

> On 10/09/2012 02:07 AM, Bob Martin wrote:
> > in 682592 20121008 232126 "Prasad, Ramit" wrote:
[snip mess]
> > How does one unpack this post?  ;-)
> 
> Since that's not the way it arrived here, i have to ask, how do you
> get these posts?  Are you subscribed to individual messages by email
> via python.org?  or are you using google-groups or some other
> indirection?
> 
> In any reasonable mail program, you can see the source of a message.
> Most of the troubles i've seen here have been caused by people
> trying to send html mail to a text-based mailing list.  But in the
> case you quote, the original message came here as text/plain, and
> well formatted.

I see a carriage return rendered as ^M at the end of every line from
Prasad's messages. Other than that, they are well-formatted plain text
for me, too.

I guess Prasad's system sends \r\n instead of \n\r (the DOS line-end)
and \r\n gets interpreted as a stray \r followed by end-of-line.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Blue Screen Python

2012-10-09 Thread mikcec82
Il giorno venerdì 21 settembre 2012 16:04:48 UTC+2, mikcec82 ha scritto:
> Hallo to all,
> 
> 
> 
> I'm using Python 2.7.3 with Windows 7 @ 64 bit
> 
> and an Intel Core i3 -2350M CPU @2.30GHz 2.3GHz.
> 
> 
> 
> Sometimes, when I'm programming in Python on my screen compare this blue 
> screen:
> 
> http://imageshack.us/a/img228/8352/48579647436249494527021.jpg
> 
> 
> 
> Can you help on what is the issue, and how I can solve it?
> 
> 
> 
> If you need more info I'm available.
> 
> 
> 
> Thank you so much,
> 
> Michele

Hi to all,
and thanks for your answers.

I'm not using a buggy library.
Yesterday I have another BSOD...but I was using only "OS" library.

I have also tested memory using memtest, but there wasn't errors.

In my script I open and close an html (in a FOR cycle); could be this the 
problem?

Or is it possible that Python 2.7 is not compatible with Win7?

Thank you very much to you.

Have a good day,
Michele
-- 
http://mail.python.org/mailman/listinfo/python-list


FW: question Python custome events

2012-10-09 Thread Hussain, Mushabbar

Hi,
Is it possible to define an Event which should fire when a value of a variable 
changes? Something like below

self.Bind(wx.EVT_ON_VAL_CHANGE, variable_to_watch, self.Callback)

I need a Text ctrl UI which continuously changes values based on external data 
changes. Unfortunately I could not find events in Python which can be triggered 
when a variable value changes?  Please let me know how this can be achieved?

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


Re: Blue Screen Python

2012-10-09 Thread Philipp Hagemeister
On 10/09/2012 09:37 AM, mikcec82 wrote:
> In my script I open and close an html (in a FOR cycle); could be this the 
> problem?
Unless you're running your Python script as a kernel driver (and you
can't do that accidentally), there is no way that your user-space
program should cause a bluescreen. This is an error in Windows (or one
of the drivers), not in Python or your program.

What you can do is insert your Windows DVD, boot from it, and click Repair.

> Or is it possible that Python 2.7 is not compatible with Win7?
No, even if a user-space program could legitimately cause a bluescreen,
Python 2.7 still works fine one thousands of Win7 machines.

Cheers,

Philipp



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mangled messages (was: Unpaking Tuple)

2012-10-09 Thread Tim Chase
On 10/09/12 02:22, Jussi Piitulainen wrote:
>>> in 682592 20121008 232126 "Prasad, Ramit" wrote:
> [snip mess]
>>> How does one unpack this post?  ;-)
>>
>> Since that's not the way it arrived here, i have to ask, how do you
>> get these posts?
> 
> I see a carriage return rendered as ^M at the end of every line from
> Prasad's messages. Other than that, they are well-formatted plain text
> for me, too.
> 
> I guess Prasad's system sends \r\n instead of \n\r (the DOS line-end)
> and \r\n gets interpreted as a stray \r followed by end-of-line.

Prasad's system is correctly sending the "right" order (DOS
line-ends are CR+LF = \r\n, not the other way around).  However, it
might be that there is no CR+LF on the last line, or that one line
is missing the CR, so your viewer heuristic (vim does this) thinks
it has Unix NL-only line-endings and shows the ^M on all the lines
that have the CR.  All for one stray line without.

Prasad's email came through cleanly here (gmane + Thunderbird).

-tkc




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


pydelicious documentation

2012-10-09 Thread Andres Soto
Does somebody know where I can get the documentation for pydelicious?
The documentation links ("For code documentation 
see doc/pydelicious or doc/dlcs.py.") in 
http://packages.python.org/pydelicious/README.html#id3 
gave me 
404 Not Found


nginx/1.1.19
 
Prof. Dr. Andrés Soto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: + in regular expression

2012-10-09 Thread Duncan Booth
Cameron Simpson  wrote:

>| Because "\s{6}+" 
>| has other meanings in different regex syntaxes and the designers didn't 
>| want confusion?
> 
> I think Python REs are supposed to be Perl compatible; ISTR an opening
> sentence to that effect...
> 
I don't know the full history of how regex engines evolved, but I suspect 
at least part of the answer is that the decisions the Perl developers made 
influenced the other implementations.

Perl's quantifiers allow both '?' and '+' as modifiers on the standard 
quantifiers so clearly you cannot stack those particular quantifiers in 
Perl, therefore quantifiers in general are unstackable.

The only grammars I can find online for regular expressions split out the 
elements and quantifiers the way I did in my previous post. Python's regex 
parser (and I would guess also most of the others in existence) tend more 
to the spaghetti code than following a grammar (_parse is a 238 line 
function). So I think it really is just trying to match existing regular 
expression parsers and any possible grammar is an excuse for why it should 
be the way it is rather than an explanation.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 02:00:04 +1100, Chris Angelico wrote:

> On Tue, Oct 9, 2012 at 1:48 AM, Dave Angel  wrote:
>> import decimal
>> a = decimal.Decimal(4.3)
>> print(a)
>>
>> 5.0996447286321199499070644378662109375
> 
> Ah, the delights of copy-paste :)
> 
>> The Decimal class has the disadvantage that it's tons slower on any
>> modern machine I know of...
> 
> Isn't it true, though, that Python 3.3 has a completely new
> implementation of decimal that largely removes this disadvantage?

Yes. It's blazingly fast: up to 120 times faster than the pure Python 
version, and within an order of magnitude of the speed of binary floats:

[steve@ando ~]$ python3.3 -m timeit -s "x, y = 1001.0, 978.0" 
> "x+y-(x/y)**4"
100 loops, best of 3: 0.509 usec per loop

[steve@ando ~]$ python3.3 -m timeit -s "from decimal import Decimal" 
> -s "x, y = Decimal(1001), Decimal(978)" "x+y-(x/y)**4"
10 loops, best of 3: 3.58 usec per loop


Without hardware support, Decimal will probably never be quite as fast as 
binary floats, but its fast enough for all but the most demanding needs.



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


Re: Insert item before each element of a list

2012-10-09 Thread Duncan Booth
mooremath...@gmail.com wrote:

> What's the best way to accomplish this?  Am I over-complicating it? 
> My gut feeling is there is a better way than the following: 
> 
 import itertools
 x = [1, 2, 3]
 y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
 range(len(x y
> ['insertme', 1, 'insertme', 2, 'insertme', 3]
> 
> I appreciate any and all feedback.
> 

Given the myriad of proposed solutions, I'm surprised nobody has suggested 
good old list slicing:

>>> x = [1,2,3]
>>> y = ['insertme']*(2*len(x))
>>> y[1::2] = x
>>> y
['insertme', 1, 'insertme', 2, 'insertme', 3]

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


Re: pydelicious documentation

2012-10-09 Thread Alec Taylor
Hi Professor Soto,

Not sure what's going on with their servers', but I was able to find
the documentation on their repo:

https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/index.html
https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/HACKING.html
https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/dlcs.html
https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/pydelicious.html

Just save the files locally then open them in your browser.

All the best,

Alec Taylor

On Tue, Oct 9, 2012 at 10:06 PM, Andres Soto  wrote:
> Does somebody know where I can get the documentation for pydelicious?
> The documentation links ("For code documentation see doc/pydelicious or
> doc/dlcs.py.") in http://packages.python.org/pydelicious/README.html#id3
> gave me
>
> 404 Not Found
>
> 
> nginx/1.1.19
>
> Prof. Dr. Andrés Soto
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pydelicious documentation

2012-10-09 Thread Alec Taylor
Actually it seems this project has been official abandoned.

Unofficially use this, was updated only a month ago:
https://github.com/mgan59/python-pinboard

On Tue, Oct 9, 2012 at 10:47 PM, Alec Taylor  wrote:
> Hi Professor Soto,
>
> Not sure what's going on with their servers', but I was able to find
> the documentation on their repo:
>
> https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/index.html
> https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/HACKING.html
> https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/dlcs.html
> https://pydelicious.googlecode.com/svn/trunk/doc/htmlref/pydelicious.html
>
> Just save the files locally then open them in your browser.
>
> All the best,
>
> Alec Taylor
>
> On Tue, Oct 9, 2012 at 10:06 PM, Andres Soto  wrote:
>> Does somebody know where I can get the documentation for pydelicious?
>> The documentation links ("For code documentation see doc/pydelicious or
>> doc/dlcs.py.") in http://packages.python.org/pydelicious/README.html#id3
>> gave me
>>
>> 404 Not Found
>>
>> 
>> nginx/1.1.19
>>
>> Prof. Dr. Andrés Soto
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating a dictionary

2012-10-09 Thread argbsk
below is the text file i have How to create Facility as a key and then assign 
multiple values to it

FACILITY : BACKUP
FAILED BACKUP_BEFORE
FAILED BACKUP_INTERCHANGE
Total : 34
Passed : 32
Failed : 2
Not Run : 0

FACILITY : CDU
Total : 9
Passed : 9
Failed : 0


for example Facility BACKUP is a key & its values are Total Passed, Failed Not 
Run and Facility CDU as a key & its values Total:9,Passed:9,Failed:0 etc...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert item before each element of a list

2012-10-09 Thread Steven D'Aprano
On Mon, 08 Oct 2012 19:34:26 -0700, rusi wrote:

> How about a 2-paren version?
> 
 x = [1,2,3]
 reduce(operator.add,  [['insert', a] for a in x])
> ['insert', 1, 'insert', 2, 'insert', 3]

That works, but all those list additions are going to be slow. It will be 
an O(N**2) algorithm.


If you're going to be frequently interleaving sequences, a helper 
function is a good solution. Here's my muxer:

def mux(*iterables):
"""Muxer which yields items interleaved from each iterator or
sequence argument, stopping when the first one is exhausted.

>>> list( mux([1,2,3], range(10, 15), "ABCD") )
[1, 10, 'A', 2, 11, 'B', 3, 12, 'C']
"""
for i in itertools.izip(*iterables):  # in Python 3 use builtin zip
for item in i:
yield item


Then call it like this:

py> list(mux(itertools.repeat("insert me"), range(5)))
['insert me', 0, 'insert me', 1, 'insert me', 2, 'insert me', 3, 'insert 
me', 4]



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


Re: mangled messages (was: Unpaking Tuple)

2012-10-09 Thread Jussi Piitulainen
Tim Chase writes:
> On 10/09/12 02:22, Jussi Piitulainen wrote:
> >>> in 682592 20121008 232126 "Prasad, Ramit" wrote:
> > [snip mess]
> >>> How does one unpack this post?  ;-)
> >>
> >> Since that's not the way it arrived here, i have to ask, how do you
> >> get these posts?
> > 
> > I see a carriage return rendered as ^M at the end of every line from
> > Prasad's messages. Other than that, they are well-formatted plain text
> > for me, too.
> > 
> > I guess Prasad's system sends \r\n instead of \n\r (the DOS line-end)
> > and \r\n gets interpreted as a stray \r followed by end-of-line.
> 
> Prasad's system is correctly sending the "right" order (DOS
> line-ends are CR+LF = \r\n, not the other way around).

You are right. I managed to confuse myself about the order of the two
characters while staring on a source that says the opposite of what I
said (http://en.wikipedia.org/wiki/Newline).

Doubly sorry about the noise (being both off-topic and incorrect).

> However, it might be that there is no CR+LF on the last line, or
> that one line is missing the CR, so your viewer heuristic (vim does
> this) thinks it has Unix NL-only line-endings and shows the ^M on
> all the lines that have the CR.  All for one stray line without.

That doesn't sound robust. The problem is still quite rare for me.

> Prasad's email came through cleanly here (gmane + Thunderbird).

I'm on Gnus in Emacs, probably a few years out of date.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Blue Screen Python

2012-10-09 Thread mikcec82
Il giorno venerdì 21 settembre 2012 16:04:48 UTC+2, mikcec82 ha scritto:
> Hallo to all,
> 
> 
> 
> I'm using Python 2.7.3 with Windows 7 @ 64 bit
> 
> and an Intel Core i3 -2350M CPU @2.30GHz 2.3GHz.
> 
> 
> 
> Sometimes, when I'm programming in Python on my screen compare this blue 
> screen:
> 
> http://imageshack.us/a/img228/8352/48579647436249494527021.jpg
> 
> 
> 
> Can you help on what is the issue, and how I can solve it?
> 
> 
> 
> If you need more info I'm available.
> 
> 
> 
> Thank you so much,
> 
> Michele

Thank you so much Philipp.
Now I am at work and I can't insert Windows DVD, but as soon as possible I'll 
done as you said and report you if the problem is solved or not.

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


Re: Insert item before each element of a list

2012-10-09 Thread Peter Otten
Duncan Booth wrote:

> mooremath...@gmail.com wrote:
> 
>> What's the best way to accomplish this?  Am I over-complicating it?
>> My gut feeling is there is a better way than the following:
>> 
> import itertools
> x = [1, 2, 3]
> y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
> range(len(x y
>> ['insertme', 1, 'insertme', 2, 'insertme', 3]
>> 
>> I appreciate any and all feedback.
>> 
> 
> Given the myriad of proposed solutions, I'm surprised nobody has suggested
> good old list slicing:

My post on gmane 

http://thread.gmane.org/gmane.comp.python.general/718940/focus=718947

apparently didn't make it through to the list.

 x = [1,2,3]
 y = ['insertme']*(2*len(x))
 y[1::2] = x
 y
> ['insertme', 1, 'insertme', 2, 'insertme', 3]

An advantage of this approach -- it is usually much faster.

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


Re: Creating a dictionary

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote:

> below is the text file i have How to create Facility as a key and then
> assign multiple values to it

To use Facility as a key in a dict:

d = {}
d['Facility'] = 'ham'

Note that keys are case-sensitive, so that 'Facility', 'facility', 
'FACILITY' and 'FaCiLiTy' are all different.

To have multiple values assigned to a key, use a list:

d['Facility'] = ['ham', 'spam', 'cheese', 'eggs']
d['Facility'].append('tomato')



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


Re: Creating a dictionary

2012-10-09 Thread Roy Smith
In article <50741ffe$0$6574$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote:
> 
> > below is the text file i have How to create Facility as a key and then
> > assign multiple values to it
> 
> To use Facility as a key in a dict:
> 
> d = {}
> d['Facility'] = 'ham'
> 
> Note that keys are case-sensitive, so that 'Facility', 'facility', 
> 'FACILITY' and 'FaCiLiTy' are all different.
> 
> To have multiple values assigned to a key, use a list:
> 
> d['Facility'] = ['ham', 'spam', 'cheese', 'eggs']
> d['Facility'].append('tomato')

I think what he really wants to end up with is a dictionary of 
dictionaries:

{'BACKUP': {'Total' : 34,
 'Passed' : 32,
 'Failed' : 2,
 'Not Run' : 0
  },
 'CDU': {}
}

Or, somewhat more work, but a richer solution, create a FacilityData 
class, whose attributes are total, passed, failed, not_run, etc, and 
have instances of FacilityData be the values.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary

2012-10-09 Thread Ulrich Eckhardt

Am 09.10.2012 13:59, schrieb arg...@gmail.com:

below is the text file i have How to create Facility as a key and then assign 
multiple values to it


The value part of a dict element can be any kind of object, like e.g. a 
tuple, namedtuple or even a dict.



Uli

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


RE: Fastest web framework

2012-10-09 Thread Andriy Kornatskyy

How fast python web framework process routing (URL dispatch)?

Here is a benchmark for various web frameworks (bottle, django, flask, pyramid, 
tornado and wheezy.web) running the following routing: static, dynamic, SEO and 
missing... with a trivial 'hello world' application (all routes are pointing to 
the same handler).

http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html

Benchmark is executed in isolated environment using CPython 2.7.

Comments or suggestions are welcome.

Thanks.

Andriy Kornatskyy

> From: andriy.kornats...@live.com
> To: python-list@python.org
> Subject: Fastest web framework
> Date: Sun, 23 Sep 2012 12:19:16 +0300
> 
> 
> I have run recently a benchmark of a trivial 'hello world' application for 
> various python web frameworks (bottle, django, flask, pyramid, web.py, 
> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find 
> it interesting:
> 
> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html
> 
> Comments or suggestions are welcome.
> 
> Thanks.
> 
> Andriy Kornatskyy
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Private methods

2012-10-09 Thread Mark Lawrence

On 09/10/2012 14:24, D.M. Procida wrote:

What exactly is the point of a private method? Why or when would I want
to use one?

Daniele



Hardly a Python question but using a search engine could have got you 
here, and rather faster :) 
http://stackoverflow.com/questions/2620699/why-private-methods-in-the-object-oriented


--
Cheers.

Mark Lawrence.

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


Re: Private methods

2012-10-09 Thread D.M. Procida
Mark Lawrence  wrote:

> On 09/10/2012 14:24, D.M. Procida wrote:
> > What exactly is the point of a private method? Why or when would I want
> > to use one?
> >
> > Daniele
> >
> 
> Hardly a Python question but using a search engine could have got you
> here, and rather faster :) 
>
http://stackoverflow.com/questions/2620699/why-private-methods-in-the-ob
ject-oriented

Thanks. Sometimes I prefer to talk to real people on Usenet than do web
searches. Just my preference.

Anyway, one of the answers on that page explains that public methods are
interfaces to a class, that other things might rely on, and private ones
are for its own internal logic, that other things don't need to care
about.

In Python, using an underscore is simply a convention to note that a
method is private - it doesn't actually hide it from other things -
correct?

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


string contains and special characters

2012-10-09 Thread loial
I am trying to match a string that containing the "<" and ">" characters, using 
the string contains function, but it never seems to find the lines containing 
the string

e.g if mystring.contains("") :

Do I need to escape the characters...and if so how?

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


Re: Private methods

2012-10-09 Thread Demian Brecht

On 12-10-09 06:59 AM, D.M. Procida wrote:

In Python, using an underscore is simply a convention to note that a
method is private - it doesn't actually hide it from other things -
correct?

Daniele



A single underscore semantically means private. A double underscore will 
name mangle the function such that it's only accessible strictly by name 
through the class that it's define in. Note that you *can* still access 
it if you understand how name mangling works. Nothing in Python is truly 
private.


--
Demian Brecht
@demianbrecht
http://demianbrecht.github.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Insert item before each element of a list

2012-10-09 Thread mooremathewl
On Monday, October 8, 2012 10:06:50 PM UTC-4, Roy Smith wrote:
> In article ,
> 

(big snip)

> 
> 
> > y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in 
> > range(len(x
> 
> 
> 
> A statement ending in four close parens is usually going to be pretty 
> 
> difficult to figure out.  This is one where I had to pull out my pencil 
> 
> and start pairing them off manually to figure out how to parse it.


Fair enough.  I admit I was looking for a tricky one-liner, which rarely leads 
to good code...I should know better.

Thanks for all the feedback from everyone.  It's amazing how much Python one 
can learn just asking about a small section of code!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Private methods

2012-10-09 Thread Robert Kern

On 10/9/12 2:59 PM, D.M. Procida wrote:

Mark Lawrence  wrote:


On 09/10/2012 14:24, D.M. Procida wrote:

What exactly is the point of a private method? Why or when would I want
to use one?

Daniele



Hardly a Python question but using a search engine could have got you
here, and rather faster :)


http://stackoverflow.com/questions/2620699/why-private-methods-in-the-ob
ject-oriented

Thanks. Sometimes I prefer to talk to real people on Usenet than do web
searches. Just my preference.


That's understandable, but the real people on Usenet who will answer your 
questions usually prefer that you do a web search first, for a variety of reasons.


  http://www.catb.org/esr/faqs/smart-questions.html#before


Anyway, one of the answers on that page explains that public methods are
interfaces to a class, that other things might rely on, and private ones
are for its own internal logic, that other things don't need to care
about.

In Python, using an underscore is simply a convention to note that a
method is private - it doesn't actually hide it from other things -
correct?


This is correct.

--
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: Unpaking Tuple

2012-10-09 Thread Grant Edwards
On 2012-10-09, Bob Martin  wrote:
> in 682592 20121008 232126 "Prasad, Ramit"  wrote:
>>Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at =
>>03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_=
>>tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tuple) =3D=3D 4 else (my_=
>
> How does one unpack this post?  ;-)

Yea, my newsreader doesn't like those posts either -- though they're
not as bad as what yours displays. Mine just shows "^M" strings all
at the end of every line.

-- 
Grant Edwards   grant.b.edwardsYow! BARBARA STANWYCK makes
  at   me nervous!!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string contains and special characters

2012-10-09 Thread Agon Hajdari
On 10/09/2012 04:02 PM, loial wrote:
> I am trying to match a string that containing the "<" and ">" characters, 
> using the string contains function, but it never seems to find the lines 
> containing the string
> 
> e.g if mystring.contains("") :
> 
> Do I need to escape the characters...and if so how?
> 
if '' in yourstring:
# your code

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


Re: Private methods

2012-10-09 Thread Tim Chase
On 10/09/12 08:59, D.M. Procida wrote:
>> On 09/10/2012 14:24, D.M. Procida wrote:
>>> What exactly is the point of a private method? Why or when would I want
>>> to use one?
> 
> In Python, using an underscore is simply a convention to note that a
> method is private - it doesn't actually hide it from other things -
> correct?

Correct.  You can read the leading underscore as "if you use this,
don't come crying if it breaks on you in a future version because we
changed an internal implementation. We told you so."

-tkc



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


Re: string contains and special characters

2012-10-09 Thread Dave Angel
On 10/09/2012 10:02 AM, loial wrote:
> I am trying to match a string that containing the "<" and ">" characters, 
> using the string contains function, but it never seems to find the lines 
> containing the string
>
> e.g if mystring.contains("") :
>
> Do I need to escape the characters...and if so how?
>

What language are you trying to use, and what version of that language? 
In all the Python versions I know of, that line would simply be a syntax
error.  There's no "contains" method in the str class, use the 'in' keyword.

if  "' in mystring:

No need to escape any ASCII characters except backslash.

-- 

DaveA

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


Re: mangled messages

2012-10-09 Thread Tim Chase
On 10/09/12 07:05, Jussi Piitulainen wrote:
> Tim Chase writes:
>> However, it might be that there is no CR+LF on the last line,
>> or that one line is missing the CR, so your viewer heuristic
>> (vim does this) thinks it has Unix NL-only line-endings and
>> shows the ^M on all the lines that have the CR.  All for one
>> stray line without.
> 
> That doesn't sound robust. The problem is still quite rare for
> me.

Vim's heuristic is that, if *all* the lines end in CR+LF, it's a
DOS-formatted file; otherwise it's a Unix-style (LF) file with
spurious CRs in it (they just happen to come at the end of
most-but-not-all lines).  It works quite robustly, since writing the
file back out will reliably put the CRs back where they were and
leave the non-CR'ed lines as they were with only LF.  Vim makes it
pretty easy to remove the spurious CRs and then change the
file-format from Unix to DOS line-endings and write it out if that's
what you want[1].

-tkc


[1]
:%s/\r$
:set ff=dos
:w

which (1) removes the spurious/inconsistent CRs, (2) tells vim that
newlines should be written as CR+LF when writing and (3) writes the
file back out to disk.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string contains and special characters

2012-10-09 Thread Dave Angel
On 10/09/2012 10:23 AM, Dave Angel wrote:
> On 10/09/2012 10:02 AM, loial wrote:
>> I am trying to match a string that containing the "<" and ">" characters, 
>> using the string contains function, but it never seems to find the lines 
>> containing the string
>>
>> e.g if mystring.contains("") :
>>
>> Do I need to escape the characters...and if so how?
>>
> What language are you trying to use, and what version of that language? 
> In all the Python versions I know of, that line would simply be a syntax

Sorry, I should have said "Attribute" error.

> error.  There's no "contains" method in the str class, use the 'in' keyword.
>
> if  "' in mystring:
>
> No need to escape any ASCII characters except backslash.
>


-- 

DaveA

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


Re: string contains and special characters

2012-10-09 Thread Jerry Hill
On Tue, Oct 9, 2012 at 10:02 AM, loial  wrote:
> I am trying to match a string that containing the "<" and ">" characters, 
> using the string contains function, but it never seems to find the lines 
> containing the string
>
> e.g if mystring.contains("") :
>
> Do I need to escape the characters...and if so how?

Strings don't have a contains() method.  Assuming that mystring is
actually a string, you should be getting a very specific error,
telling you exactly what's wrong with your code (something like
AttributeError: 'str' object has no attribute 'contains').

If that isn't what you're seeing, you'll need to provide the full and
complete text of the error you are getting, and preferably enough of
your code that we can reproduce the issue and help you solve it.

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


Re: string contains and special characters

2012-10-09 Thread Mark Lawrence

On 09/10/2012 15:23, Dave Angel wrote:

On 10/09/2012 10:02 AM, loial wrote:

I am trying to match a string that containing the "<" and ">" characters, using 
the string contains function, but it never seems to find the lines containing the string

e.g if mystring.contains("") :

Do I need to escape the characters...and if so how?



What language are you trying to use, and what version of that language?
In all the Python versions I know of, that line would simply be a syntax
error.  There's no "contains" method in the str class, use the 'in' keyword.


I see you've already corrected youself :)



 if  "' in mystring:

No need to escape any ASCII characters except backslash.



No need to escape anything if raw strings are used.

--
Cheers.

Mark Lawrence.

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


Re: string contains and special characters

2012-10-09 Thread loial
On Tuesday, 9 October 2012 15:19:33 UTC+1, Agon Hajdari wrote:
> On 10/09/2012 04:02 PM, loial wrote: > I am trying to match a string that 
> containing the "<" and ">" characters, using the string contains function, 
> but it never seems to find the lines containing the string > > e.g if 
> mystring.contains("") : > > Do I need to escape the characters...and if 
> so how? > if '' in yourstring: # your code -- Agon Hajdari

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


surprising behaviour of global dictionaries

2012-10-09 Thread Michele Simionato
I have the following module implementing a registry of functions with a 
decorator:

$ cat x.py
registry = {} # global dictionary

def dec(func):
registry[func.__name__] = func
print registry, id(registry)
return func

if __name__ == '__main__':
import xlib
print registry, id(registry)

The library xlib just defines two dummy functions:

$ cat xlib.py
from x import dec

@dec
def f1():
pass

@dec
def f2():
pass

Then I get the following output:

$ python x.py
{'f1': } 27920352
{'f1': , 'f2': } 
27920352
{} 27395472

This is surprising since I would expect to have a single global dictionary, not 
two: how comes the registry inside the ``if __name__ == '__main__'`` block is 
different from the one seen in the library?

This is python 2.7.3 on Ubuntu.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string contains and special characters

2012-10-09 Thread Ulrich Eckhardt

Am 09.10.2012 16:02, schrieb loial:

I am trying to match a string that containing the "<" and ">"
characters, using the string contains function, but it never seems to
find the lines containing the string

e.g if mystring.contains("") :


I can't locate a 'contains' function anywhere, what type is 'mystring'?



Do I need to escape the characters...and if so how?


Maybe. Please provide some example code that unexpectedly fails.


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


Re: surprising behaviour of global dictionaries

2012-10-09 Thread Peter Otten
Michele Simionato wrote:

> I have the following module implementing a registry of functions with a
> decorator:
> 
> $ cat x.py
> registry = {} # global dictionary
> 
> def dec(func):
> registry[func.__name__] = func
> print registry, id(registry)
> return func
> 
> if __name__ == '__main__':
> import xlib
> print registry, id(registry)
> 
> The library xlib just defines two dummy functions:
> 
> $ cat xlib.py
> from x import dec
> 
> @dec
> def f1():
> pass
> 
> @dec
> def f2():
> pass
> 
> Then I get the following output:
> 
> $ python x.py
> {'f1': } 27920352
> {'f1': , 'f2':  {0x7f7bce0cd6e0>} 27920352 } 27395472
> 
> This is surprising since I would expect to have a single global
> dictionary, not two: how comes the registry inside the ``if __name__ ==
> '__main__'`` block is different from the one seen in the library?
> 
> This is python 2.7.3 on Ubuntu.

Welcome to python -- this is a trap every newbie falls into ;)

Seriously, you shouldn't use the main script as a library; it is put into 
the sys.modules cache under the "__main__" key. Subsequent imports under its 
real name will not find that name in the cache and import another instance 
of the module, with puzzling effects, like

$ cat x.py 
import x
class A: pass
a = A()
assert isinstance(a, x.A)

$ python x.py 
Traceback (most recent call last):
  File "x.py", line 4, in 
assert isinstance(a, x.A)
AssertionError
$ 


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


Re: surprising behaviour of global dictionaries

2012-10-09 Thread Michele Simionato
On Tuesday, October 9, 2012 5:24:17 PM UTC+2, Peter Otten wrote:
> Seriously, you shouldn't use the main script as a library; it is put into 
> 
> the sys.modules cache under the "__main__" key. Subsequent imports under its 
> 
> real name will not find that name in the cache and import another instance 
> 
> of the module, with puzzling effects

Actually I usually never use the main script as a library, this is why I never 
experience this puzzling behavior before. But now it is clear, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: surprising behaviour of global dictionaries

2012-10-09 Thread Grant Edwards
On 2012-10-09, Peter Otten <__pete...@web.de> wrote:

> Welcome to python -- this is a trap every newbie falls into ;)
>
> Seriously, you shouldn't use the main script as a library;

There must be something wrong with me.  It never even occurred to me
to try to import a file from within that same file.  I don't think
I've ever even heard of that before...

-- 
Grant Edwards   grant.b.edwardsYow! The Korean War must
  at   have been fun.
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Generating C++ code

2012-10-09 Thread Jean-Michel Pichavant
Greetings,

I'm trying to generate C++ code from an XML file. I'd like to use a template 
engine, which imo produce something readable and maintainable.
My google search about this subject has been quite unsuccessful, I've been 
redirected to template engine specific to html mostly.

Does anybody knows a python template engine for generating C++ code ?

Here's my flow:

XML file -> nice python app -> C++ code

>From what I know I could use Cheetah, a generic template engine. I never used 
>it though, I'm not sure this is what I need.
I'm familiar with jinja2 but I'm not sure I could use it to generate C++ code, 
did anybody try ? (maybe that's a silly question)

Any advice would be appreciated.

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


Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-09 Thread Token Type
Thanks indeed for your tips. Now I understand the difference between tuples and 
dictionaries deeper.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: surprising behaviour of global dictionaries

2012-10-09 Thread Dave Angel
On 10/09/2012 11:36 AM, Michele Simionato wrote:
> On Tuesday, October 9, 2012 5:24:17 PM UTC+2, Peter Otten wrote:
>> Seriously, you shouldn't use the main script as a library; it is put into 
>>
>> the sys.modules cache under the "__main__" key. Subsequent imports under its 
>>
>> real name will not find that name in the cache and import another instance 
>>
>> of the module, with puzzling effects
> Actually I usually never use the main script as a library, this is why I 
> never experience this puzzling behavior before. But now it is clear, thanks.
More generally, you should arrange your imports so that there are no
cycles.  If module/script "a" imports "b", directly or indirectly, "b"
should not try to import "a."  Move the common code to a third place,
and import it from both "a" and from "b".

The other symptoms you can get are more subtle than this one, but just
as surprising.


-- 

DaveA

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


RE: RE: Unpaking Tuple

2012-10-09 Thread Prasad, Ramit
Bob Martin wrote
> in 682592 20121008 232126 "Prasad, Ramit"  wrote:
> >Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at =
> >03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_=
> >tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tuple) =3D=3D 4 else (my_=
> >tuple + (None,)*4)[:4]=0D=0A> >=0D=0A> =0D=0A> Are you sure this works as y=
> >ou expect? I just stumbled over the following:=0D=0A> =0D=0A> $ python=0D=
> >=0A> Python 3=2E2=2E3 (default, Jun 25 2012, 23:10:56)=0D=0A> [GCC 4=2E7=2E=
> >1] on linux2=0D=0A> Type "help", "copyright", "credits" or "license" for mo=
> >re information=2E=0D=0A> >>> split =3D ['foo', 'bar']=0D=0A> >>> head, tail=
> >=3D split if len(split) =3D=3D 2 else split[0], None=0D=0A> >>> head=0D=0A=
> >> ['foo', 'bar']=0D=0A> >>> tail=0D=0A> >>>=0D=0A> =0D=0A> I don't get it! =
> >Could someone help me, please? Why is head not 'foo'=0D=0A> and tail not 'b=
> >ar'?=0D=0A> =0D=0A> Regards,=0D=0A>  Thomas=0D=0A> --=0D=0A=0D=0AI think yo=
> >u just need to wrap the else in parenthesis so the=0D=0Aelse clause is trea=
> >ted as a tuple=2E Without the parenthesis =0D=0AI believe it is grouping th=
> >e code like this=2E=0D=0A=0D=0Ahead, tail =3D (split if len(split) =3D=3D 2=
> >else split[0] ), None=0D=0A=0D=0AYou want:=0D=0Ahead, tail =3D split if le=
> >n(split) =3D=3D 2 else (split[0], None )=0D=0A=0D=0A=0D=0ARamit=0D=0AThis e=
> >mail is confidential and subject to important disclaimers and=0D=0Aconditio=
> >ns including on offers for the purchase or sale of=0D=0Asecurities, accurac=
> >y and completeness of information, viruses,=0D=0Aconfidentiality, legal pri=
> >vilege, and legal entity disclaimers,=0D=0Aavailable at http://www=2Ejpmorg=
> >an=2Ecom/pages/disclosures/email=2E
> 
> How does one unpack this post?  ;-)
> --

Hmm, I am not sure why that happened. For reference: 
http://mail.python.org/pipermail/python-list/2012-October/632603.html
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


Re: FW: question Python custome events

2012-10-09 Thread Ian Kelly
On Tue, Oct 9, 2012 at 2:35 AM, Hussain, Mushabbar
 wrote:
>
>
> Hi,
>
> Is it possible to define an Event which should fire when a value of a
> variable changes? Something like below
>
>
>
> self.Bind(wx.EVT_ON_VAL_CHANGE, variable_to_watch, self.Callback)
>
>
>
> I need a Text ctrl UI which continuously changes values based on external
> data changes. Unfortunately I could not find events in Python which can be
> triggered when a variable value changes?  Please let me know how this can be
> achieved?

Yes, you would need to:

1) encapsulate the variable;

2) define a custom event;

3) set up a wx.EvtHandler for the variable, since it's not itself
associated with a window;

4) bind your callback to the event handler;

5) have the variable setter fire the custom event.

That said, an event is likely not going to be the best way to do this.
 You should instead use the wx.lib.pubsub module, which implements the
observer pattern for you.  This will be cleaner and easier, as you
only need to:

1) encapsulate the variable;

2) subscribe your callback to the update message;

3) have the variable setter publish the update message.

Observers are also conceptually simpler than events.  You can find
information about pubsub at:

http://wiki.wxpython.org/WxLibPubSub

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


Re: surprising behaviour of global dictionaries

2012-10-09 Thread Peter Otten
Grant Edwards wrote:

> On 2012-10-09, Peter Otten <__pete...@web.de> wrote:
> 
>> Welcome to python -- this is a trap every newbie falls into ;)
>>
>> Seriously, you shouldn't use the main script as a library;
> 
> There must be something wrong with me.  It never even occurred to me
> to try to import a file from within that same file.  

It is typically done in two steps: 

(1) Write module x, use it in module y.
(2) For convenience add "if __name__ == '__main__'" and import module y.

Hilarity ensues.

> I don't think I've ever even heard of that before...

As I was poking fun at Michele who really is an expert and likely knows more 
about Python than I do I may have exaggerated a bit ;)

But it does come up, see

"Singleton implementation problems"
http://mail.python.org/pipermail/python-list/2008-July/470770.html

"Dynamically declared shared constant/variable imported twice problem"
http://mail.python.org/pipermail/python-list/2009-May/535619.html

There are more, but I don't know a convenient way to find the posts.
Related problems with reload() or paths into a package occur even more 
frequently.

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


Getting ipython notebook to plot inline

2012-10-09 Thread Frank Franklin
I've just managed to install ipython and get it to run by typing ipython 
notebook --pylab=inline

Now I'm getting the following error when I try to plot something in ipython 
notebook:
AttributeError: 'module' object has no attribute 'FigureCanvas'

I've tried using imports to make this work:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)

But for some reason I still get this error. Anybody else know what's going on 
here? All of the print statements I've done before have worked, and I actually 
got my plots to work when I didn't set --pylab=inline, though they came up in a 
separate window and I want them to stay in the ipython notebook.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating C++ code

2012-10-09 Thread Andrea Crotti

On 10/09/2012 05:00 PM, Jean-Michel Pichavant wrote:

Greetings,

I'm trying to generate C++ code from an XML file. I'd like to use a template 
engine, which imo produce something readable and maintainable.
My google search about this subject has been quite unsuccessful, I've been 
redirected to template engine specific to html mostly.

Does anybody knows a python template engine for generating C++ code ?

Here's my flow:

XML file -> nice python app -> C++ code

 From what I know I could use Cheetah, a generic template engine. I never used 
it though, I'm not sure this is what I need.
I'm familiar with jinja2 but I'm not sure I could use it to generate C++ code, 
did anybody try ? (maybe that's a silly question)

Any advice would be appreciated.

JM


I think you can use anything to generate C++ code, but is it a good idea?
Are you going to produce this code only one time and then maintain it 
manually?


And are you sure that the design that you would get from the XML file 
actually makes sense when

translated in C++?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Generating C++ code

2012-10-09 Thread Etienne Robillard
On Tue, 09 Oct 2012 20:55:48 +0100
Andrea Crotti  wrote:

> On 10/09/2012 05:00 PM, Jean-Michel Pichavant wrote:
> > Greetings,
> >
> > I'm trying to generate C++ code from an XML file. I'd like to use a 
> > template engine, which imo produce something readable and maintainable.
> > My google search about this subject has been quite unsuccessful, I've been 
> > redirected to template engine specific to html mostly.
> >
> > Does anybody knows a python template engine for generating C++ code ?
> >
> > Here's my flow:
> >
> > XML file -> nice python app -> C++ code
> >
> >  From what I know I could use Cheetah, a generic template engine. I never 
> > used it though, I'm not sure this is what I need.
> > I'm familiar with jinja2 but I'm not sure I could use it to generate C++ 
> > code, did anybody try ? (maybe that's a silly question)
> >
> > Any advice would be appreciated.
> >
> > JM
> 
> I think you can use anything to generate C++ code, but is it a good idea?
> Are you going to produce this code only one time and then maintain it 
> manually?
> 
> And are you sure that the design that you would get from the XML file 
> actually makes sense when
> translated in C++?
> -- 
> http://mail.python.org/mailman/listinfo/python-list

You can build nice python app with Cython/Pyrex too if you got sufficient 
knowledge in C/C++ programming
to extend the app in C. :-)

Otherwise that seem like a little counter-productive to produce a python 
template only for generating C stubs when python
is good for many things without requiring advanced C++ skills like memory 
management, etc.
 
HTH,
E
-- 
Etienne Robillard
Green Tea Hackers Club
Fine Software Carpentry For The Rest Of Us!
http://gthc.org/
e...@gthcfoundation.org
-- 
http://mail.python.org/mailman/listinfo/python-list


share with friends

2012-10-09 Thread admin
HotNet1

hi, 

join small social bookmarking and share best links with pepole.

Please share your friends.We are waiting for you. 
thank you 
HotNet1 team 

http://www.hotnet1.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Private methods

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 11:08:13 -0600, Ian Kelly wrote:

> On Tue, Oct 9, 2012 at 8:08 AM, Demian Brecht 
> wrote:
>> A single underscore semantically means private. A double underscore
>> will name mangle the function such that it's only accessible strictly
>> by name through the class that it's define in. Note that you *can*
>> still access it if you understand how name mangling works. Nothing in
>> Python is truly private.
> 
> I tend to view name mangling as being more for avoiding internal
> attribute collisions in complex inheritance structures than for
> designating names as private.

Really? I tend to view name mangling as a waste of time, and complex 
inheritance structures as something to avoid.



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


Re: Private methods

2012-10-09 Thread Demian Brecht

On 12-10-09 04:51 PM, Steven D'Aprano wrote:

Really? I tend to view name mangling as a waste of time, and complex
inheritance structures as something to avoid.


Yep, I've been coming around to this as of late.

--
Demian Brecht
@demianbrecht
http://demianbrecht.github.com
--
http://mail.python.org/mailman/listinfo/python-list


an error in python lib?

2012-10-09 Thread Wenhua Zhao
Hi list,

I just noticed that in /usr/lib/python2.7/threading.py

class _Condition(_Verbose):
...
def _is_owned(self):
# Return True if lock is owned by current_thread.
# This method is called only if __lock doesn't have
_is_owned().
if self.__lock.acquire(0):
self.__lock.release()
return False
else:
return True

The return values seem to be wrong.  They should be swapped:

def _is_owned(self):
if self.__lock.acquire(0):
self.__lock.release()
return True
else:
return False

Or I understood it wrong here?

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


Re: IDLE Crashing in Mac OS 10.8.2 with 2.7.3

2012-10-09 Thread Kevin Walzer

On 10/9/12 11:27 AM, bkee...@gmail.com wrote:

I've tried all the usual suspect of uninstalling and reinstalling IDLE and 
Python 2.7.3, but my IDLE environment always crashes unexpectedly on Mac OS X 
10.8.


Where did you get Python? What version of Tcl/Tk do you have installed? 
Is it the one from ActiveState or the one bundled with OS X?


--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Porting notmm to pep 3333 and mod_wsgi

2012-10-09 Thread Etienne Robillard
Hi,

Has PEP- introduced backward incompatibilities or changes in unicode 
encoding
and decoding or should this updated pep require python 3 to make mod_wsgi 
working with wsgi 1.0 (pep-333)
scripts ? Moreover is it possible to use python 2.7 with mod_wsgi at all 
without the utf-8 
encoding errors? 

Besides theses minor Unicode encoding problems I'm glad to announce 
experimental mod_wsgi support for notmm 
on python 2.7.3. I will also include a sample app into the next notmm release 
as a proof-of-concept for Django-based
projects but so far I haven't found more serious problems following the 
standard documentation in mod_wsgi 3.4... 

Furthermore this newer support for mod_wsgi should allow experimented Django 
developers to use mod_wsgi and Apache as an alternative to FastCGI (and nginx) 
for serving high-performance Django apps compiled into optimized C bindings 
using Cython and notmm! :-)  

Cheers,
Etienne

-- 
Etienne Robillard
Green Tea Hackers Club
Fine Software Carpentry For The Rest Of Us!
http://gthc.org/
e...@gthcfoundation.org

Donations for the notmm project are accepted through Pledgie.com. 
For more info please visit: 
http://pledgie.com/campaigns/16268
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: an error in python lib?

2012-10-09 Thread MRAB

On 2012-10-10 01:32, Wenhua Zhao wrote:

Hi list,

I just noticed that in /usr/lib/python2.7/threading.py

class _Condition(_Verbose):
 ...
 def _is_owned(self):
 # Return True if lock is owned by current_thread.
 # This method is called only if __lock doesn't have
_is_owned().
 if self.__lock.acquire(0):
 self.__lock.release()
 return False
 else:
 return True

The return values seem to be wrong.  They should be swapped:

 def _is_owned(self):
 if self.__lock.acquire(0):
 self.__lock.release()
 return True
 else:
 return False

Or I understood it wrong here?


The .acquire method will return True if the attempt to acquire has been
successful. This can occur only if it is not currently owned.

In pseudocode:

if the attempt to acquire it succeeds:
no-one owed it before, but now I own it
release it
now no-one owns it
return False
else:
someone already owns it
return True

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


communicate with external process via pty

2012-10-09 Thread Tim Arnold
I have an external process, 'tralics' that emits mathml when you feed it 
latex equations. I want to get that mathml into a string.


The problem for me is that tralics wants to talk to a tty and I've never 
done that before; it basically starts its own subshell.


I have the following code which works for simple things. I'm not sure 
this is the best way though: basically I got this from google...


import os,sys
import subprocess
import shlex
import pty
cmd =  'tralics --interactivemath'

(master, slave) = pty.openpty()
p = subprocess.Popen(shlex.split(cmd),close_fds=True,
 stdin=slave,stdout=slave,stderr=slave)

os.read(master,1024)# start the process
os.write(master,'$\sqrt{x}$\n') # feed it an equation
mathml.append(os.read(master,1024)) # get the mathml in a string

os.write(master,'$\sqrt{x}$\n') # feed more equations
mathml.append(os.read(master,1024)) # get the next string


Any suggestions for improvement?
thanks,
--Tim
--
http://mail.python.org/mailman/listinfo/python-list


lxml 3.0 final released - efficient XML and HTML processing with Python

2012-10-09 Thread Stefan Behnel
Hi everyone,

it's been a while since the last stable release series appeared, so I'm
proud to announce the final release of lxml 3.0.

http://lxml.de/

http://pypi.python.org/pypi/lxml/3.0

Changelog: http://lxml.de/changes-3.0.html

In short, lxml is the most feature-rich and easy-to-use library for
processing XML and HTML in the Python language. It's also very fast, in
case you're interested in that. It runs on Python 2.4 - 3.3.

The 3.0 release features initial support for PyPy and a new tree API for
DTDs (by Walter Dörwald), as well as some major cleanups in the code base.
The lxml.cssselect package was moved into a separate PyPI project nicely
extended and maintained by Simon Sapin.

If you are interested in commercial support or customisations for the lxml
package, please contact me directly.

Have fun,

Stefan

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