Re: Pipe in the "return" statement

2011-07-27 Thread Thomas 'PointedEars' Lahn
Ethan Furman wrote:

> Billy Mays wrote:
>> On 07/25/2011 10:16 AM, Archard Lias wrote:
>>> On Jul 25, 2:03 pm, Ian Collins  wrote:
 On 07/26/11 12:00 AM, Archard Lias wrote:
> Still I dont get how I am supposed to understand the pipe and its
> task/ idea/influece on control flow, of:
> return|
> ??

 It's simply a bitwise OR.
>>>
>>> Yes, but how does it get determined, which one actually gets returned?
>> The return statement returns a single value from a function context. The
>> pipe operator takes 2 values and bitwise ORs* them together.  That
>> result is then returned to the caller.
> Just for completeness, if the actual line had been
> 
> return  or 
> 
> then Python would compute , and if its boolean value was
> True would return the computation of , otherwise it would
> compute  and return that.  When 'or' is used, the first
> truthy* item is return, or the last falsey* item if none evaluate to True.

Hence "*bitwise* OR" (as Billy wrote), _not_ logical OR (as you wrote), 
probably.
 
-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-27 Thread OKB (not okblacke)
Thomas 'PointedEars' Lahn wrote:
>  Automatic word-wrap, where available, really is not a solution; it
> is a bad workaround to a problem caused by the original author of
> the source code that can be easily avoided by them taking more care
> while coding. 

I think exactly the opposite.  The source file should reflect the 
semantic organization of the code, without extraneous concessions to 
visual display (like "lining things up" with spaces or splitting long 
lines with hard newlines).  The editor should present the code nicely.  
People already argue for this general mindset when they say that "any 
good edit will let you set the tab width", etc.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming Python for Absolute Beginners

2011-07-27 Thread harrismh777

Billy Mays wrote:


No one cares and don't spam the list.


   ... ouch, now I feel really bad... has someone not had their coffee 
this morning?






kind regards,

--
m harris

FSF  ...free as in freedom/
http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm
--
http://mail.python.org/mailman/listinfo/python-list


Seeking an example on using Queue to update variable while threading

2011-07-27 Thread Danny Wong (dannwong)
Hi Python experts,
I'm trying to use a dict structure to store and update information from 
X number of threads. How do I share this dict structure between threads? I 
heard of using a queue, but I'm not familiar with how it works. Does anyone 
have an example of using a queue to store variables/dicts between threads?

Thanks

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


Re: Programming Python for Absolute Beginners

2011-07-27 Thread Billy Mays

On 7/27/2011 11:50 PM, harrismh777 wrote:





No one cares and don't spam the list.
--
http://mail.python.org/mailman/listinfo/python-list


Programming Python for Absolute Beginners

2011-07-27 Thread harrismh777

Greetings folks,

   Well, we're back from a 3985 mile road trip around the Southeastern 
U.S. ending back in Minnesota--- dragging a trailer--- spent somewhere 
close to a month visiting battle fields honoring the CSA dead from that 
little skirmish between the states 1861-1865... found my great great 
grandpa's tomb (he served with the Smyth Dragoons 8th Virginia Cavalry 
Co A...  did Chancellorsville, and Gettysburg, and D.C quite a trip. 
  so what?


   So what??? I feel like I own major stock shares in British Petroleum!

   No, seriously, in the evenings I worked my way through the 3rd 
edition of the book, "Python Programming for the Absolute Beginner": 
quiet cool evenings with a starlit sky... my notebook... and python game 
programming;  what more could I want?


http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002/ref=tmm_pap_title_0

Author: Michael Dawson

   Most of the campgrounds we visited had free wifi in on the grounds, 
and there was peace and quite for evaluating a fantastic book. What 
makes this book different is that it is project oriented rather than 
reference oriented. He teaches programming in Python by teaching the 
reader how to construct some simpler games using the Python tools.


   I used the public library copy for the trip... but I picked up my 
own copy since getting back, and I'm gonna set my kids down with this 
text as a fun educational motivator.  I'll let you know...



--
m harris

FSF  ...free as in freedom/
http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread harrismh777

Steven D'Aprano wrote:

On Thu, 28 Jul 2011 08:34 am rantingrick wrote:


>  WRONG! When in doubt be consistent! There should be one AND ONLY ONE
>  obvious way to do it! When we have multiple ways of doing the same
>  thing we induce an overhead into our work flows. Instead we need to
>  follow the zen; in other words, BE CONSISTENT!

Oh, and you were doing so good there for all of one day.

Back to the kill-file with you.



... nah, don't kill file rantingrick. Every anarchy needs at least one 
ranter--- not to mention some of ricks rants are riotous wry humor... 
and also, he's a funny guy. And then every so often... and its really 
more often than you might want to admit... he contributes something 
really beautiful like his best list of commands (I printed it off) !


I stopped kill-filing folks a long time ago because every time I thought 
I needed to do that, I'd miss something important... so I listen to 
everyone... every person has a story... rantingrick's are better than most.


But I fully understand that no person can tell another person what to 
do... especially with their kill file some-rants--> /dev/null



:)


--
m harris

FSF  ...free as in freedom/
http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread Steven D'Aprano
On Thu, 28 Jul 2011 08:34 am rantingrick wrote:

> WRONG! When in doubt be consistent! There should be one AND ONLY ONE
> obvious way to do it! When we have multiple ways of doing the same
> thing we induce an overhead into our work flows. Instead we need to
> follow the zen; in other words, BE CONSISTENT!

Oh, and you were doing so good there for all of one day.

Back to the kill-file with you.



-- 
Steven

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


PyImport_ImportModule bug in ver 3.1.2?

2011-07-27 Thread 健安 王
Hi:
My Python version is 3.1.2.
I am programming embedding c with python in windows.
When I imported urllib.request  in my test py file,
PyImport_ImportModule always return NULL.
But I imported re or cmd ,they work fine.
I found urllib is folder, and request seems to be submodule.
I don't know how to import it. I confirmed myutil.py and application
are in same folder.
Could you give me some advice?
Thank you.

myutil.py

import sys
import urllib.request


CRLF = '\r\n'

def addValue(oper1,oper2):
  return (oper1 + oper2);


def ConnectURL(url):
  try:
req = urllib.request.urlopen(url)
response = req.read()
req.close()
return (req.getcode(),req.geturl())

  except BaseException as exp:
sys.stdout.write(exp)


native code:



int APIENTRY _tWinMain(HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPTSTRlpCmdLine,
   int   nCmdShow)
{
PyObject* pPyUtil   = NULL;
PyObject* pPypfn= NULL;
PyObject* pPyArgs   = NULL;
PyObject* pPyRet= NULL;
int nRet= 0;
int nValue  = 0;


Py_Initialize();
PyImport_ImportModule("sys");   // ok
PyImport_ImportModule("csv");   // ok

PyImport_ImportModule("urllib");// ok

pPyUtil = PyImport_ImportModule("myutil"); // failed ,
if(pPyUtil != NULL)
{

Py_DECREF(pPyUtil);
}
Py_Finalize();



return 0;
}


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


Re: How should I document exceptions thrown by a method?

2011-07-27 Thread Chris Torek
>Arcadio  writes:
>> I have a Settings class that is used to hold application settings. A
>> Settings object initializes itself from a ConfigParser that gets
>> passed in as an argument to the constructor.

In article <87oc0fpg9o@benfinney.id.au>
Ben Finney   wrote:
>So the caller is aware of, and takes responsibility for, the
>ConfigParser instance.

>> If a setting isn't found in whatever the ConfigParser is reading
>> settings from, the ConfigParser's get() method will raise an
>> exception. Should I just say that clients of my Settings class should
>> be prepared to catch exceptions thrown by ConfigParser? Do I even have
>> to mention that as it might be just implied?
>
>In this case IMO it is implied that one might get exceptions from the
>object one passes as an argument to a callable.

Yes.  But on the other hand:

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
...

:-)

I would suggest that in this case, too, "explicit is better than
implicit": the documentation should say "will invoke x.get() and
therefore propagate any exception that x.get() might raise".

>> Or should Setting's constructor catch any exceptions raised by the
>> ConfigParser and "convert it" to a Settings- specific exception class
>> that I then document?
>
>Please, no. Since the ConfigParser object was created and passed in by
>the calling code, the calling code needs to know about the exceptions
>from that object.

In *some* cases (probably not applicable here), one finds a good
reason to transform one exception to another.  In this case I agree
with Ben Finney though, and so does "import this":

...
Simple is better than complex.
...

Letting exceptions flow upward unchanged is (usually) simpler,
hence "better".
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread Andrew Berg
On 2011.07.27 08:34 PM, Cameron Simpson wrote:
> I think when he releases Python4000 we'll all fall behind.
That is, if he ever does release RickPy4000. ;)

-- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread Cameron Simpson
On 28Jul2011 02:06, Thomas Jollans  wrote:
| On 28/07/11 00:34, rantingrick wrote:
| > [ snip rant ]
| 
| To be clear, the code is more what you'd call "guidelines" than actual
| rules. Welcome aboard the Black Pearl, Mister Ranting!

I think when he releases Python4000 we'll all fall behind.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

I think... Therefore I ride.  I ride... Therefore I am.
- Mark Pope 
-- 
http://mail.python.org/mailman/listinfo/python-list


PyCon Australia 2011: Registration Back Online

2011-07-27 Thread Ryan Kelly


Hi Everyone,


After a brief hiatus, registrations for PyCon Australia 2011 are back
online!  We have extended some registration deadlines to compensate
for the outage.

PyCon Australia is Australia's only conference dedicated exclusively to
the Python programming language, and will be held at the Sydney Masonic
Center over the weekend of August 20 and 21. See below for more
information and updates on:

 1. Registration Back Online
 2. Call for Volunteers
 3. Convore Group
 4. Thanks to our Sponsors
 
Please pass this message on to those you feel may be interested.

 

Registration Back Online


Registrations are back online after a brief PayPal outage:

http://pycon-au.org/reg


Our apologies to those inconvenienced.  PayPal put a temporary lock on 
our account while they were reviewing our status as a non-profit.  Many
thanks to the hard-working folks at Linux Australia for following up with
all the necessary paperwork.

To compensate for the outage we have adjusted some of our registration
deadlines.  The new dates are:

  1st August:   T-Shirt order finalised
  8th August:   Special dietary needs finalised
  15th August:  Last chance to get tickets!

Remember, registrations must close on Monday the 15th of August, and we will
not be accepting registrations at the door.

So don't delay, register now at:

http://pycon-au.org/reg



Call for Volunteers
===

A community conference such as PyCon just can't run without the work of
many generous volunteers.  If you're interested in helping out, please 
send us an email at:

pycon-...@pycon-au.org


We're currently looking for people to help with the following:

  * Session Staff
(see http://pycon-au.org/2011/helping/session_staff/)

  * Bag Packers
(Friday afternoon; also just general setup of the venue)

  * Registration Desk



Convore Group
=

We've set up a group on Convore for anyone wanting to chat about the 
conference:

https://convore.com/pycon-au-2011/


There are already some good tips from Sydney-siders who know the area
around the venue.  If you have any more, please share!

Don't forget, you can also follow us on Twitter for the latest updates:

https://twitter.com/pyconau
https://twitter.com/#!/search/pyconau



Thanks to our Sponsors
==


Thanks once again to the following companies for their continuing support 
of Python and for helping to make PyCon Australia 2011 a reality:


Gold:  Google  
Gold:  ComOps  
 
Silver:  Anchor
Silver:  Enthought 
Silver:  Python Software Foundation
Silver:  WingWare  
Silver:  Arclight  
Silver:  Bitbucket by Atlassian
Silver:  Microsoft 


Thanks also to Linux Australia, who provide the overarching legal and
organisational structure for PyCon Australia.
 



Ryan Kelly
PyCon Australia 2011


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


pysvn merge

2011-07-27 Thread mud
I have started using your pysvn module and find it very useful.

I trying to doing a pysvn.Client.merge which is working well, but I am
would like to cater for conflicts. I would like to by default accept
“theirs-full” version, but I can’t figure out how to do it.

Svn command line merge has a option called –-accept theirs-full (as
you already know), and I was trying to use pysvn.Client.merge’s
merge_options. But there is no documentation on the accepted merge
options or how to use it. I have tried merge_options=[‘—-accept theirs-
full’] and merge_options=[‘--accept’, ‘theirs-full’] but no luck.

I get the following error: “Error parsing diff options: Bad character
specified on command line”

I then looked at using the “resolve” method but the only method there
is “resolved” which does not resolve the confict.

I am using pysvn version 1.7.2.0.

Could you please let me know how do I go about resolving the conflicts
using pysvn, if anybody of you know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I access IDLE in Win7

2011-07-27 Thread W. eWatson
In the mean time, I punted and re-installed. It's still not quite right. 
I uninstalled it. I was asked during install if I wanted to remove 
c:\Python25. It was still there and had several folders (Lib, Scripts) 
and files (fishe.py, RemovePIL.exe, junk.py). I said yes. It installed 
2.5.2.


Edit with IDLE still fails, as does a simple py file like junk.py (has 
five lines of simple math). That is executing junk.py or trying to get 
it into IDLE doesn't work.


For junk.py, I tried Open With->Choose default program. I selected 
idle.pyw. When I tried the new default for getting to IDLE, it 
complained it was not a valid 32-bit app. That's very strange.


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


Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread Thomas Jollans
On 28/07/11 00:34, rantingrick wrote:
> I believe the current Python style guide is inconsistent. The author
> again allowed hie emotion to get in the way of logic.

If you think that logic can be the foundation of a style [guide], then
you have a very curious idea of what "logic" means.

> [ snip rant ]

To be clear, the code is more what you'd call "guidelines" than actual
rules. Welcome aboard the Black Pearl, Mister Ranting!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Fall in love with bpython

2011-07-27 Thread Karim

On 07/28/2011 01:32 AM, Walter Prins wrote:

Hi Karim

On 28 July 2011 00:04, Karim > wrote:


On 07/27/2011 12:34 AM, Alan Gauld wrote:

Karim wrote:

I use bpython interpreter. This is a very good interactive
CLI.


I had never heard of it and had to google for it.
It appears to be a curses based CLI for *nix and MacOS


Ah Windows user.


Thanks for mentioning bpython -- I had also not heard of it but it 
duly installed on my ubuntu box from the repositories!  I've browsed 
the code -- it uses ncurses to do the screen IO.  You can always read 
the code, but, as you intimated, unless you're pretty familiar with 
somewhat large codebases and ncurses it might not be that much use to 
you just yet. ... Still, it might be worth having a look at the 
source... :)


http://hg.bpython-interpreter.org/bpython/src/bcd836c859aa/bpython/

Walter


Hi,

I am using ubuntu too.
I used to write large API but in fact I did not know curses and I wanted 
to see in the code
where the keywords are 'injected' to try with my own grammar. I still 
have to study the details.
But it seems that the keywords are imported dynamically from 
__builtins__ module. Don't know yet

how to configure or modify it.

Thanks for your advice
Regards
Karim



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


Re: How do I access IDLE in Win7

2011-07-27 Thread Thomas Jollans
On 27/07/11 23:26, W. eWatson wrote:
> I cannot copy from the cmd window. It ends with [errorno 13] Permission
> denied to c:||Users\\Wayne\\idlerc\\recent-files.lst'
> 

Yes you can. Right-click to bring up a menu with a "select" or "copy"
option (IIRC)

As for the error, see if there is file
/users/wayne/idlerc/recent-files.lst
And if there is, delete it. Or even delete the whole folder «idlerc».
IDLE should be able to cope with it not being there at all: it wouldn't
be there the first time IDLE is started by a user.

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


Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread Andrew Berg
On 2011.07.27 05:34 PM, rantingrick wrote:
>> --
>> Use 4 spaces per indentation level.
>> --
> 
> This should be the only acceptable indention level allowed by the
> interpreter. All other indention should cast plagues of syntax errors
> on the unrighteous.
> 
>> --
>> For really old code that you don't want to mess up, you
>> can continue to use 8-space tabs.
>> --
> 
> NO! You should convert the code to 4 space tabs and move into the 21st
> century. Stop living in the past. We must move forward... kicking and
> screaming if necessary.
It wasn't too long ago you were calling for tabs. It's even funnier
since this whole message is about inconsistencies.

-- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings show as brackets with a 'u'.

2011-07-27 Thread goldtech

> Rick gave you some good advice, perhaps worth re-reading. What you need
> are investigative skills, and not just bits of data.


Totally agree. beginning to see what's going on. I'm not specifically
accessing the list element with n (vs. n[0]). Printing n uses repr
which gives the unicode "tag".  Something akin to this...thanks for
showing what i need to read up on...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Fall in love with bpython

2011-07-27 Thread Walter Prins
Hi Karim

On 28 July 2011 00:04, Karim  wrote:

> On 07/27/2011 12:34 AM, Alan Gauld wrote:
>
>> Karim wrote:
>>
>>  I use bpython interpreter. This is a very good interactive CLI.
>>>
>>
>> I had never heard of it and had to google for it.
>> It appears to be a curses based CLI for *nix and MacOS
>>
>
> Ah Windows user.


Thanks for mentioning bpython -- I had also not heard of it but it duly
installed on my ubuntu box from the repositories!  I've browsed the code --
it uses ncurses to do the screen IO.  You can always read the code, but, as
you intimated, unless you're pretty familiar with somewhat large codebases
and ncurses it might not be that much use to you just yet. ... Still, it
might be worth having a look at the source... :)

http://hg.bpython-interpreter.org/bpython/src/bcd836c859aa/bpython/

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


Re: PEP 8 and extraneous whitespace

2011-07-27 Thread Thomas 'PointedEars' Lahn
Chris Rebert wrote:

> John Gordon wrote:
>> Neil Cerutti writes:
>>> You can fit much more code per unit of horizontal space with a
>>> proportionally spaced font. As a result, that issue, while valid,
>>> is significantly reduced.
>>
>> Is it?  I assume one major reason for the 80-character limit is to help
>> the poor sod who will eventually get stuck working with your code on an
>> 80-column fixed width terminal window.
> 
> What environments with that limitation are still in common use?

TTYs are present on Unices and compatible OSes everywhere today (even more 
so as Python is evolving into a more powerful replacement for Bourne-shell 
based shell command languages), and there are sophisticated graphic-mode 
IDEs (not IDLE) where you want to have more than the source code column 
visible at the same time.

Having too long code lines is detrimental to readability there, because even 
though you can scroll, horizontal scrolling is a PITA.  Automatic word-wrap, 
where available, really is not a solution; it is a bad workaround to a 
problem caused by the original author of the source code that can be easily 
avoided by them taking more care while coding.

> It's not the '70s anymore; I think we can safely increase the max
> column width a bit.

You're wrong.  It is not only an issue of output device/window, but also 
simply of readability.  In particular, humans have difficulties reading text 
that is larger than about 60 characters, both due to constrainted view angle 
and increased eye movement from the end of one line to the beginning of the 
next one (the greater that distance, the harder to keep track of the text).  
One can learn from the newspaper and pocketbook publishers how easily 
readable text should be formatted (but one must not overdo as some of them 
do).
 
-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fall in love with bpython

2011-07-27 Thread Karim

On 07/28/2011 12:31 AM, Michael Poeltl wrote:

hi,

have you heard abut ipython? maybe that's helpful for you?
http://ipython.scipy.org/moin/python


Hello Michael,

Yes I saw some article where Ipython and Bpython CLI integrations was 
made in Django.


Thanks for the link I will evaluate it as well.

Cheers
Karim


Michael
* Karim  [2011-07-27 23:46]:


Hello,

I use bpython interpreter. This is a very good interactive CLI.
I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...

Is there a tool where I can plug all my grammary commands line
a sort of generic box with completion, highlights, etc...

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



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


Re: can I use element tree for handling special characters in xml text?

2011-07-27 Thread Thomas 'PointedEars' Lahn
hackingKK wrote:

> I have been waiting a lot to ask this question and I did ask some days
> back but probably could not put it the proper way.

You still can't.  

But to spare everyone yet another try:

> I want to know how I can safely include special characters like & or >
> in xml text?

(I don't know what you want to know, so don't ask me that.)

You need CDATA sections for this.  That is not a Python problem.

You should get a real name.

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fall in love with bpython

2011-07-27 Thread Karim

On 07/27/2011 12:34 AM, Alan Gauld wrote:

Karim wrote:


I use bpython interpreter. This is a very good interactive CLI.


I had never heard of it and had to google for it.
It appears to be a curses based CLI for *nix and MacOS


Ah Windows user.




I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...


Why not read the bpython source to see what they used?
Thats the big advantage of open source - its open!
(Although they don't make the source explicitly available,
I'm assuming the tar file contains the source- it might
even be in Python!)

They use pygments to parse the source as you type.
That would be worth investigating too...



Yes I saw mainly pygments which is an OpenSource project...
But, I must admit. I will spend 6 months before understanding this.
Rhahaaa... This level is high! I saw too cmd2 which is fully compatible 
and inherit from cmd.

But not quite as fun!

The main module cli.py is 1700 lignes and the architecture is not very 
well documented.

We will see If I can make any progress during the next month.

Thanks Alan

PS: Are you still making some hiking in the higlands. Beautiful photos I 
have seen on your web site!


Cheers
Alan



HTH,

Alan G.


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


PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread rantingrick

I believe the current Python style guide is inconsistent. The author
again allowed hie emotion to get in the way of logic. I will be
posting blocks of text from the PEP8 and commenting below them.

> --
> One of Guido's key insights is that code is read much more
> often than it is written.  The guidelines provided here
> are intended to improve the readability of code and make
> it consistent across the wide spectrum of Python code.  As
> PEP 20 [6] says, "Readability counts".
> --

Yes but this guide itself is contradictory Mr Van Rossum.

> --
> A style guide is about consistency.  Consistency with this
> style guide is important.  Consistency within a project is
> more important. Consistency within one module or function
> is most important.
> --

Hmm, Yes. And CONSISTENCY within a style guide that promotes
CONSISTENCY should trump them all! However as we'll see shortly
"CONSISTENCY" has been sacrificed at the alter of fluffy feelings and
multi-style-ism.

> --
> But most importantly: know when to be inconsistent --
> sometimes the style guide just doesn't apply.  When in
> doubt, use your best judgment.
> --

WRONG! When in doubt be consistent! There should be one AND ONLY ONE
obvious way to do it! When we have multiple ways of doing the same
thing we induce an overhead into our work flows. Instead we need to
follow the zen; in other words, BE CONSISTENT!

> --
> Look at other examples and
> decide what looks best.  And don't hesitate to ask!
> --

NO, NO! Follow the community standards. NEVER make up your own. We
cannot keep propagating multiplicity or else we will drown in it! We
cannot have people making up syntax for iterations can we? Likewise we
cannot allow people to make up styles.

> --
> Two good reasons to break a particular rule:
>
> (1) When applying the rule would make the code less
> readable, even for someone who is used to reading code
> that follows the rules.
>
> (2) To be consistent with surrounding code that also
> breaks it (maybe for historic reasons) -- although this is
> also an opportunity to clean up someone else's mess (in
> true XP style).
> --

Number two is the ONLY reason why ANYONE should not follow the style
guide to a "T"! However, code of this style should be shamed by the
community.

> --
> Use 4 spaces per indentation level.
> --

This should be the only acceptable indention level allowed by the
interpreter. All other indention should cast plagues of syntax errors
on the unrighteous.

> --
> For really old code that you don't want to mess up, you
> can continue to use 8-space tabs.
> --

NO! You should convert the code to 4 space tabs and move into the 21st
century. Stop living in the past. We must move forward... kicking and
screaming if necessary.

> --
> Tabs or Spaces?
>
> Never mix tabs and spaces.
>
> The most popular way of indenting Python is with spaces
> only.  The second-most popular way is with tabs only.
> Code indented with a mixture of tabs and spaces should be
> converted to using spaces exclusively.  When invoking the
> Python command line interpreter with the -t option, it
> issues warnings about code that illegally mixes tabs and
> spaces.  When using -tt these warnings become errors.
> These options are highly recommended!
> --

Here is another missed opportunity to force compliance of a style
convention. Mixing tabs and spaces should throw syntax errors! Is it
too much to ask that people at least choose one over the other? Sheez,
are we that afraid of offending them? Are these people emotional
basket cases riving with suicidal tendencies? *rolls-eyes* If they are
then the Python style guide is the LEAST of their problems.

> --
> Blank Lines
>
> Separate top-level function and class definitions with two
> blank lines.
>
> Method definitions inside a class are separated by a
> single blank line.
> --

This should be the law. Unfortunately many stdlib modules do not
follow this suggestion. In Python4000 i'm making it a syntax error to
include ANY blank lin

Re: Fall in love with bpython

2011-07-27 Thread Alan Gauld

Karim wrote:


I use bpython interpreter. This is a very good interactive CLI.


I had never heard of it and had to google for it.
It appears to be a curses based CLI for *nix and MacOS



I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...


Why not read the bpython source to see what they used?
Thats the big advantage of open source - its open!
(Although they don't make the source explicitly available,
I'm assuming the tar file contains the source- it might
even be in Python!)

They use pygments to parse the source as you type.
That would be worth investigating too...


HTH,

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


Re: shlex parsing

2011-07-27 Thread Karim

On 07/28/2011 12:11 AM, Dan Stromberg wrote:


You could probably use a recursive descent parser with the standard 
library.


But if your management is OK with pyparsing, that might be easier, and 
a bit more clear as well.


Yes, I thought to use str method partition in a recursive way but using 
pyParsing still be easer.


Thanks
Cheers



On Wed, Jul 27, 2011 at 2:08 PM, Karim > wrote:



Thank you Dan for answering.

I ended with this and gave up with shlex:

split = ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR',
'-option3', 'TAG']

procedure_found = False
result  = []

for token in split:
if not token.startswith('[') and not token.endswith(']') and
not procedure_found:
result.append(token)
elif token.startswith('['):
procedure_found = True
_token = token
elif token.endswith(']'):
procedure_found = False
_token += ' ' + token
result.append(_token)
else:
_token += ' ' + token

print split
print result

which gives the desired values:

['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR',
'-option3', 'TAG']
['-option1', '[get_rule A1 B2]', '-option2', '$VAR', '-option3',
'TAG']


Sure pyParsing seems to be pretty simple but my constraint is to use
standard lib (at maximum). To bad it is not part of python
standard libs.
On the other hand, I will have to regroup expression like
'-option1 $VAL == $CONSTRAINT'
in ['-option1', '$VAL == $CONSTRAINT'].

So it seems that I have no others choicse and have to use a parser
like pyParsing.

Regards
Karim


On 07/27/2011 10:44 PM, Dan Stromberg wrote:


I've not used the shlex module, but this feels more like an issue
to address with a parser than for a lexical analyzer - or perhaps
even both, since you're splitting on whitespace sometimes, and
matching square brackets sometimes.

I've used pyparsing for stuff a bit similar to this.

Or here's a list:
http://wiki.python.org/moin/LanguageParsing

On Wed, Jul 27, 2011 at 12:30 PM, Karim mailto:karim.liat...@free.fr>> wrote:


Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR',
'-option3',  'TAG']

Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes',
'whitespace', etc...

But I make 'choux blanc'.

If somebody has complex experiences with  this module I am in.

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








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


Re: shlex parsing

2011-07-27 Thread Dan Stromberg
You could probably use a recursive descent parser with the standard library.

But if your management is OK with pyparsing, that might be easier, and a bit
more clear as well.

On Wed, Jul 27, 2011 at 2:08 PM, Karim  wrote:

> **
>
> Thank you Dan for answering.
>
> I ended with this and gave up with shlex:
>
> split = ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR',
> '-option3', 'TAG']
>
> procedure_found = False
> result  = []
>
> for token in split:
> if not token.startswith('[') and not token.endswith(']') and not
> procedure_found:
> result.append(token)
> elif token.startswith('['):
> procedure_found = True
> _token = token
> elif token.endswith(']'):
> procedure_found = False
> _token += ' ' + token
> result.append(_token)
> else:
> _token += ' ' + token
>
> print split
> print result
>
> which gives the desired values:
>
> ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', '-option3',
> 'TAG']
> ['-option1', '[get_rule A1 B2]', '-option2', '$VAR', '-option3', 'TAG']
>
>
> Sure pyParsing seems to be pretty simple but my constraint is to use
> standard lib (at maximum). To bad it is not part of python standard libs.
> On the other hand, I will have to regroup expression like '-option1 $VAL ==
> $CONSTRAINT'
> in ['-option1', '$VAL == $CONSTRAINT'].
>
> So it seems that I have no others choicse and have to use a parser like
> pyParsing.
>
> Regards
> Karim
>
>
> On 07/27/2011 10:44 PM, Dan Stromberg wrote:
>
>
> I've not used the shlex module, but this feels more like an issue to
> address with a parser than for a lexical analyzer - or perhaps even both,
> since you're splitting on whitespace sometimes, and matching square brackets
> sometimes.
>
> I've used pyparsing for stuff a bit similar to this.
>
> Or here's a list:
> http://wiki.python.org/moin/LanguageParsing
>
>  On Wed, Jul 27, 2011 at 12:30 PM, Karim  wrote:
>
>>
>> Hello All,
>>
>> I would like to parse this TCL command line with shlex:
>>
>> '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'
>>
>> And I want to get the splitted list:
>>
>> ['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',  'TAG']
>>
>> Then I will gather in tuple 2 by 2 the arguments.
>>
>> I tried to the shlec properties attributes 'quotes', 'whitespace', etc...
>>
>> But I make 'choux blanc'.
>>
>> If somebody has complex experiences with  this module I am in.
>>
>> Cheers
>> Karim
>>  --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Fall in love with bpython

2011-07-27 Thread Karim



Hello,

I use bpython interpreter. This is a very good interactive CLI.
I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...

Is there a tool where I can plug all my grammary commands line
a sort of generic box with completion, highlights, etc...

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


Re: How do I access IDLE in Win7

2011-07-27 Thread W. eWatson

On 7/27/2011 12:53 PM, Jerry Hill wrote:

On Wed, Jul 27, 2011 at 3:34 PM, W. eWatson  wrote:

On 7/27/2011 9:48 AM, Jerry Hill wrote:

So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\
(or where ever you installed python)?  If not, it sounds to me like
your python installation is screwed up.  I would re-install.


Yes, I have both. Neither shows anything on the monitor when I double click
them.


Oh, I guess I misunderstood.  Go ahead and open that cmd.exe window
back up.  Please run the following and report back the results.  In
the cmd.exe window run:

assoc .py
assoc .pyw
ftype Python.File
ftype Python.NoConFile


.py=Python.File
.pyw=Python.NoConFile
Python.File="C:\Python25\python.exe" "%1" %*
Python.File="C:\Python25\python.exe" "%1" %*
Python.NoConFile="C:\Python25\pythonw.exe" "%1" %*



Those four commands should show us how the python file associations
are set up on your computer.

Then, let's try to run idle and capture whatever error message is
popping up.  I don't think you've mentioned what version of python you
have installed.  The following is for 2.6, since that's what I have
installed here, but it should work on any other version if you swap in
your installation directory for the 2.6 one below.  Still in your
cmd.exe window, run the following:

c:\Python26\python.exe C:\Python26\Lib\idlelib\idle.py
I cannot copy from the cmd window. It ends with [errorno 13] Permission 
denied to c:||Users\\Wayne\\idlerc\\recent-files.lst'


recent-files.lst !!! weird


If you get an exception, please copy and paste the details for us.  If
that works and opens idle, please try running this:

C:\Python26\Lib\idlelib\idle.py

Based on the behavior you've described so far, that ought to fail, and
hopefully give some sort of message or exception for us to diagnose.

PS: If you're just trying to get things working, and don't care what
might be wrong, I would recommend just re-installing python.  That
ought to clean up all the file associations and set things up properly
for you.  That's likely the quickest way to just get things working.


Yep, I'm thinking about it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How should I document exceptions thrown by a method?

2011-07-27 Thread Ben Finney
Arcadio  writes:

> I have a Settings class that is used to hold application settings. A
> Settings object initializes itself from a ConfigParser that gets
> passed in as an argument to the constructor.

So the caller is aware of, and takes responsibility for, the
ConfigParser instance.

> If a setting isn't found in whatever the ConfigParser is reading
> settings from, the ConfigParser's get() method will raise an
> exception. Should I just say that clients of my Settings class should
> be prepared to catch exceptions thrown by ConfigParser? Do I even have
> to mention that as it might be just implied?

In this case IMO it is implied that one might get exceptions from the
object one passes as an argument to a callable.

> Or should Setting's constructor catch any exceptions raised by the
> ConfigParser and "convert it" to a Settings- specific exception class
> that I then document?

Please, no. Since the ConfigParser object was created and passed in by
the calling code, the calling code needs to know about the exceptions
from that object.

-- 
 \ “My girlfriend has a queen sized bed; I have a court jester |
  `\   sized bed. It's red and green and has bells on it, and the ends |
_o__) curl up.” —Steven Wright |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shlex parsing

2011-07-27 Thread Karim


Thank you Dan for answering.

I ended with this and gave up with shlex:

split = ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', 
'-option3', 'TAG']


procedure_found = False
result  = []

for token in split:
if not token.startswith('[') and not token.endswith(']') and not 
procedure_found:

result.append(token)
elif token.startswith('['):
procedure_found = True
_token = token
elif token.endswith(']'):
procedure_found = False
_token += ' ' + token
result.append(_token)
else:
_token += ' ' + token

print split
print result

which gives the desired values:

['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', '-option3', 
'TAG']

['-option1', '[get_rule A1 B2]', '-option2', '$VAR', '-option3', 'TAG']


Sure pyParsing seems to be pretty simple but my constraint is to use
standard lib (at maximum). To bad it is not part of python standard libs.
On the other hand, I will have to regroup expression like '-option1 $VAL 
== $CONSTRAINT'

in ['-option1', '$VAL == $CONSTRAINT'].

So it seems that I have no others choicse and have to use a parser like 
pyParsing.


Regards
Karim

On 07/27/2011 10:44 PM, Dan Stromberg wrote:


I've not used the shlex module, but this feels more like an issue to 
address with a parser than for a lexical analyzer - or perhaps even 
both, since you're splitting on whitespace sometimes, and matching 
square brackets sometimes.


I've used pyparsing for stuff a bit similar to this.

Or here's a list:
http://wiki.python.org/moin/LanguageParsing

On Wed, Jul 27, 2011 at 12:30 PM, Karim > wrote:



Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',
 'TAG']

Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes', 'whitespace',
etc...

But I make 'choux blanc'.

If somebody has complex experiences with  this module I am in.

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





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


TestFixtures 1.11.0 Released!

2011-07-27 Thread Chris Withers

Hi All,

I'm happy to announce a new release of TestFixtures with the following 
changes:


- testfixtures' compare function now does rich comparison of dicts and 
their subclasses, showing which keys matches, were missing or differed 
between the two objects being compared.


- A decorator of ShouldRaise called should_raise is now included:

http://packages.python.org/testfixtures/exceptions.html#the-should-raise-wrapper-function

The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


http://www.simplistix.co.uk/software/python/testfixtures

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: shlex parsing

2011-07-27 Thread Dan Stromberg
I've not used the shlex module, but this feels more like an issue to address
with a parser than for a lexical analyzer - or perhaps even both, since
you're splitting on whitespace sometimes, and matching square brackets
sometimes.

I've used pyparsing for stuff a bit similar to this.

Or here's a list:
http://wiki.python.org/moin/LanguageParsing

On Wed, Jul 27, 2011 at 12:30 PM, Karim  wrote:

>
> Hello All,
>
> I would like to parse this TCL command line with shlex:
>
> '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'
>
> And I want to get the splitted list:
>
> ['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',  'TAG']
>
> Then I will gather in tuple 2 by 2 the arguments.
>
> I tried to the shlec properties attributes 'quotes', 'whitespace', etc...
>
> But I make 'choux blanc'.
>
> If somebody has complex experiences with  this module I am in.
>
> Cheers
> Karim
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Suggestions on writing a sh <--> python Howto/Tutorial

2011-07-27 Thread Robert Laing
I've been tinkering around learning traditional Unix shell programming
and python at the same time. I set myself the following exercise which
I found quite educational. I first wrote a shell CGI script to read
the man pages on my web hosting service's computer via  a browser like
so:

http:///rtfm.cgi?page=&man=

Where page= is optional since one does not often need it. The shell
script that did the trick looks so:

#!/bin/sh
MAN=$(echo $QUERY_STRING | sed -n "s/^.*man=\([^&]*\).*$/\1/p")
PAGE=$(echo $QUERY_STRING | sed -n "s/^.*page=\([^&]*\).*$/\1/p")
echo "Content-type: text/html; charset=utf-8"
echo ""
gunzip < $(man --path $PAGE $MAN) | groff -Thtml -mandoc

That last line with the < redirect and pipe to groff is not purely
illustrative since while the Linux distro on my laptap has a version
of man that understands -Thtml, the one on my hosting company's server
does not (making the above quite a valuable script).

Now I managed to write a rtfm.py script that does the same thus:

#!/usr/local/bin/python3.2
import os, urllib.parse, gzip, subprocess
QUERY_STRING=os.environ['QUERY_STRING']
MAN=urllib.parse.parse_qs(QUERY_STRING)['man'][0]
try:
PAGE=urllib.parse.parse_qs(QUERY_STRING)['page'][0]
except (KeyError):
PAGE=''
manfile = subprocess.getoutput("man --path "+PAGE+" "+MAN)
p1 = subprocess.Popen(["gunzip","--to-stdout",manfile],
stdout=subprocess.PIPE)
p2 = subprocess.Popen(["groff", "-Thtml", "-mandoc"], stdin=p1.stdout,
  stdout=subprocess.PIPE, universal_newlines=True)
p1.stdout.close()
print("Content-type: text/html; charset=utf-8\n")
print(p2.communicate()[0])

Figuring I needed to add 'universal_newlines=True' to get rid of all
the '\n's took me quite a while.

I'm now modifying this to use python's gzip library rather than
calling gunzip as a subprocess, but so far produce gibberish since
f=gzip.open(manfile) insists on flagging the text output as binary
data which confuses groff. That, however, is not the issue here.

The point is, I thought it would be worthwhile writing a Howto/
Tutorial on doing shell script type programming with python, and
thought I'd start a thread for suggestions on tricks from the gurus
out there.

PS: lets avoid any ideological fights about bash vs python. From my
side, I found the bash version of the above quicker and easier to
write, but would hate to expand it into a bigger program, whereas
python got my mind buzzing with ideas on features to add.



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


Re: How do I access IDLE in Win7

2011-07-27 Thread Jerry Hill
On Wed, Jul 27, 2011 at 3:34 PM, W. eWatson  wrote:
> On 7/27/2011 9:48 AM, Jerry Hill wrote:
>> So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\
>> (or where ever you installed python)?  If not, it sounds to me like
>> your python installation is screwed up.  I would re-install.
>
> Yes, I have both. Neither shows anything on the monitor when I double click
> them.

Oh, I guess I misunderstood.  Go ahead and open that cmd.exe window
back up.  Please run the following and report back the results.  In
the cmd.exe window run:

assoc .py
assoc .pyw
ftype Python.File
ftype Python.NoConFile

Those four commands should show us how the python file associations
are set up on your computer.

Then, let's try to run idle and capture whatever error message is
popping up.  I don't think you've mentioned what version of python you
have installed.  The following is for 2.6, since that's what I have
installed here, but it should work on any other version if you swap in
your installation directory for the 2.6 one below.  Still in your
cmd.exe window, run the following:

c:\Python26\python.exe C:\Python26\Lib\idlelib\idle.py

If you get an exception, please copy and paste the details for us.  If
that works and opens idle, please try running this:

C:\Python26\Lib\idlelib\idle.py

Based on the behavior you've described so far, that ought to fail, and
hopefully give some sort of message or exception for us to diagnose.

PS: If you're just trying to get things working, and don't care what
might be wrong, I would recommend just re-installing python.  That
ought to clean up all the file associations and set things up properly
for you.  That's likely the quickest way to just get things working.

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


How should I document exceptions thrown by a method?

2011-07-27 Thread Arcadio
I use Doxygen to document my source code, and I'm wondering how
exceptions thrown by a method of a class should be documented in the
following example.

I have a Settings class that is used to hold application settings.  A
Settings object initializes itself from a ConfigParser that gets
passed in as an argument to the constructor.  If a setting isn't found
in whatever the ConfigParser is reading settings from, the
ConfigParser's get() method will raise an exception.  Should I just
say that clients of my Settings class should be prepared to catch
exceptions thrown by ConfigParser?  Do I even have to mention that as
it might be just implied?  Or should Setting's constructor catch any
exceptions raised by the ConfigParser and "convert it" to a Settings-
specific exception class that I then document?

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


Re: How do I access IDLE in Win7

2011-07-27 Thread W. eWatson

On 7/27/2011 9:48 AM, Jerry Hill wrote:

On Wed, Jul 27, 2011 at 12:28 PM, W. eWatson  wrote:

If I run cmd.exe and work my way down to  .../idlelib, I find nothing but
idle.bat. strange. Hidden?  I can get into line mode by using python.exe.
That is, I can type in print "abc", and get a result.


So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\
(or where ever you installed python)?  If not, it sounds to me like
your python installation is screwed up.  I would re-install.

Jerry
Yes, I have both. Neither shows anything on the monitor when I double 
click them.

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


shlex parsing

2011-07-27 Thread Karim


Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',  'TAG']

Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes', 'whitespace', etc...

But I make 'choux blanc'.

If somebody has complex experiences with  this module I am in.

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


Re: Only Bytecode, No .py Files

2011-07-27 Thread harrismh777

Christian Heimes wrote:

Now the test.py has the same mtime as test.pyc and Python won't
recompile the .pyc file from the .py file as long as the magic header
(168686339) is correct.



~very cool.



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


Re: Maximize already running tkinter program on invocation

2011-07-27 Thread Francesco Bochicchio
On 27 Lug, 10:18, Steven Kauffmann  wrote:
> Hi all,
>
> I have written a small GUI application in python 3.x using the tkinter
> module. Program is running fine, but multiple instances of the program
> can now be created. I would like to reduce the number of instances of
> the program to only 1 instance. I know that this is possible by using
> a singleton class. This way it's possible to check if the program is
> already running or not.
>
> When I invoke the program and it detects that the program is already
> running, is it then possible to maximize the already running program?
>
> I can find a lot of examples about singleton classes in python on the
> web, but nothing about showing the already running application when 1
> instance of the program already exists. Is there a way to realize this
> in python?
>
> I'm now doing the development on a linux machine, but the final
> program should work on Windows.
>
> Cheers,
>
>
The multiprocesing  module could help you in making sure that two
instances of the same program are not started ( for instance using
multiprocessing.Queue) as well as to signal the already running
instance that it sould maximize its window ( for instance using
multiprocessing.Queue ). Just make sure that what you use is supoorted
on your target operating system(s).

However, the integration of any form of inter-process communication
with Tkinter main loop is going to be tricky ...


Ciao
-
FB

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


Re: How do I access IDLE in Win7

2011-07-27 Thread Jerry Hill
On Wed, Jul 27, 2011 at 12:28 PM, W. eWatson  wrote:
> If I run cmd.exe and work my way down to  .../idlelib, I find nothing but
> idle.bat. strange. Hidden?  I can get into line mode by using python.exe.
> That is, I can type in print "abc", and get a result.

So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\
(or where ever you installed python)?  If not, it sounds to me like
your python installation is screwed up.  I would re-install.

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


Re: How do I access IDLE in Win7

2011-07-27 Thread W. eWatson

On 7/27/2011 8:38 AM, rantingrick wrote:

On Jul 27, 10:06 am, "W. eWatson"  wrote:

It's been many months since I played with Python, and have forgotten how
to bring up IDLE. If I simply click on a py file, I see what may be a
dos window appear and quickly disappear.


"Double-clicking" a [py|pyw] file in windows will auto run the file
(considering you have not changed the association). So if you're
trying to edit the file you'll want to try something else.


If I right-click on the file,
and select IDLE, the same thing happens.


You mean "Right-Click ->  Send-To-IDLE"?
A right-click gives me two choices. Edit with IDLE or Open With. The 
first produces nothing, or something so quick that I do not see it. The 
second gives me a choice of python.exe, Notepad, or Choose Default 
Program. None of these are helpful.





If I go directly to All
Programs, the same thing happens when I select IDLE.


You mean "Start_Menu ->  All_Programs ->  PythonX.X ->  IDLE_(Python
GUI)"? Yes typically that is how you'd run IDLE form a winders box.

Yes, that's what I do, but again the result is essentially nothing.


If you want to edit a python script then first open an editor and then
navigate to the file. There is also a "RightClick ->  Open-with-IDLE"
option also but i prefer to navigate from my editor.

Edit with IDLE as above. Doesn't work. No editor appears.


However it sounds like you may be experiencing a bug (or configuration
issue). Can you capture the "dos" error with the print screen button
and post it here? You'll have to be quick to catch it!

Way too fast.


Also try to run IDLE from this path:
...\PythonXX\Lib\idlelib {double click PyShell.py}

It stays up for about 1/2 second.

If I run cmd.exe and work my way down to  .../idlelib, I find nothing 
but idle.bat. strange. Hidden?  I can get into line mode by using 
python.exe. That is, I can type in print "abc", and get a result.


Baffling.

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


Re: How can I make a program automatically run once per day?

2011-07-27 Thread John Salerno
On Jul 27, 7:58 am, Billy Mays
<81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com> wrote:
> On 07/27/2011 08:35 AM, Chris Angelico wrote:
>
>
>
>
>
>
>
>
>
> > On Wed, Jul 27, 2011 at 10:27 PM, Dave Angel  wrote:
> >> As Chris pointed out, you probably aren't getting the script's directory
> >> right.  After all, how can the scheduler guess where you put it?  The
> >> obvious answer is to use a full path for the script's filename.  Another
> >> alternative is to fill in the current directory in the appropriate field of
> >> the scheduler's entry.
>
> > I would prefer setting the current directory, as that allows the
> > script to find any data files it needs, but either works.
>
> >> I find it useful to only add batch files to the scheduler.  Those batch
> >> files can do any setup and cleanup necessary.  In this case, the batch file
> >> might simply set the current directory to the location of the script.
>
> > And that is an excellent idea. Definitely recommended.
>
> > ChrisA
>
> If it hasn't been mentioned already:
>
> import time
>
> while True:
>      t1 = time.time()
>
>      #your code here
>
>      t2 = time.time()
>      time.sleep( 86400 - (t2 - t1) )
>
> This doesn't take into account leap seconds, but it doesn't depend on a
> task scheduler.  It is also independent of the time your code takes to
> execute.
>
> This is simpler, but it might drift slightly over time.
>
> --
> Bill

Well, I specified the full path name but it still doesn't seem to
work. A DOS prompt flashes for about a second that says "taskeng.exe"
in the title bar, but the script itself still isn't being run.

I don't know about batch files but I'll read up on them and see if
that will be a better solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I access IDLE in Win7

2011-07-27 Thread rantingrick
On Jul 27, 10:06 am, "W. eWatson"  wrote:
> It's been many months since I played with Python, and have forgotten how
> to bring up IDLE. If I simply click on a py file, I see what may be a
> dos window appear and quickly disappear.

"Double-clicking" a [py|pyw] file in windows will auto run the file
(considering you have not changed the association). So if you're
trying to edit the file you'll want to try something else.

> If I right-click on the file,
> and select IDLE, the same thing happens.

You mean "Right-Click -> Send-To-IDLE"?

> If I go directly to All
> Programs, the same thing happens when I select IDLE.

You mean "Start_Menu -> All_Programs -> PythonX.X -> IDLE_(Python
GUI)"? Yes typically that is how you'd run IDLE form a winders box.

If you want to edit a python script then first open an editor and then
navigate to the file. There is also a "RightClick -> Open-with-IDLE"
option also but i prefer to navigate from my editor.

However it sounds like you may be experiencing a bug (or configuration
issue). Can you capture the "dos" error with the print screen button
and post it here? You'll have to be quick to catch it!

Also try to run IDLE from this path:
...\PythonXX\Lib\idlelib {double click PyShell.py}
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I access IDLE in Win7

2011-07-27 Thread W. eWatson
It's been many months since I played with Python, and have forgotten how 
to bring up IDLE. If I simply click on a py file, I see what may be a 
dos window appear and quickly disappear. If I right-click on the file, 
and select IDLE, the same thing happens. If I go directly to All 
Programs, the same thing happens when I select IDLE.

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


Re: Only Bytecode, No .py Files

2011-07-27 Thread Thomas Rachel

Am 27.07.2011 14:18 schrieb John Roth:


Two comments. First, your trace isn't showing attempts to open .py
files, it's showing attempts to open the Curses library in the bash
directory.


Of course. My goal was to show that the OP's "problem" is not a python 
one, but occurs all over several programs.



> Maybe you also have a problem with the .py files,

Why should I?


> It's also not showing the program that's causing the failing open.

It is irrelevant, IMO.

It just shows that it seems to be common, even for the bin loader, to 
search for libraries to be linked to by trying to open them from several 
places. So every program call must be full of "failures" shown by the 
"audit program".




Second, the audit program is an idiot. There are lots of programs
which use the "easier to ask forgiveness" pattern and test for the
existence of optional files by trying to open them. This may be what
Bash is doing.


ACK. That is exactly what I wanted to show. (With the difference that 
this is probably nt the bash, but the linux loader trying to link a .so, 
but for the problem, it doesn't make any difference.)



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


Re: How can I make a program automatically run once per day?

2011-07-27 Thread Billy Mays

On 07/27/2011 08:35 AM, Chris Angelico wrote:

On Wed, Jul 27, 2011 at 10:27 PM, Dave Angel  wrote:

As Chris pointed out, you probably aren't getting the script's directory
right.  After all, how can the scheduler guess where you put it?  The
obvious answer is to use a full path for the script's filename.  Another
alternative is to fill in the current directory in the appropriate field of
the scheduler's entry.


I would prefer setting the current directory, as that allows the
script to find any data files it needs, but either works.


I find it useful to only add batch files to the scheduler.  Those batch
files can do any setup and cleanup necessary.  In this case, the batch file
might simply set the current directory to the location of the script.


And that is an excellent idea. Definitely recommended.

ChrisA


If it hasn't been mentioned already:

import time

while True:
t1 = time.time()

#your code here

t2 = time.time()
time.sleep( 86400 - (t2 - t1) )



This doesn't take into account leap seconds, but it doesn't depend on a 
task scheduler.  It is also independent of the time your code takes to 
execute.


This is simpler, but it might drift slightly over time.

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


Re: How can I make a program automatically run once per day?

2011-07-27 Thread Chris Angelico
On Wed, Jul 27, 2011 at 10:27 PM, Dave Angel  wrote:
> As Chris pointed out, you probably aren't getting the script's directory
> right.  After all, how can the scheduler guess where you put it?  The
> obvious answer is to use a full path for the script's filename.  Another
> alternative is to fill in the current directory in the appropriate field of
> the scheduler's entry.

I would prefer setting the current directory, as that allows the
script to find any data files it needs, but either works.

> I find it useful to only add batch files to the scheduler.  Those batch
> files can do any setup and cleanup necessary.  In this case, the batch file
> might simply set the current directory to the location of the script.

And that is an excellent idea. Definitely recommended.

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


Re: How can I make a program automatically run once per day?

2011-07-27 Thread Dave Angel

On 01/-10/-28163 02:59 PM, John Salerno wrote:

On Jul 26, 9:22 pm, Andrew Berg  wrote:

On 2011.07.26 08:05 PM,JohnSalernowrote:>  Hmm, okay I'm finally trying Task 
Scheduler, but how do I set it to

run a Python script? It seems to not work, I suppose because it's
running the script but doesn't know how to find Python to run it
properly.

Tell it to run the Python interpreter and pass the script as an argument.

--
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB

Thank you. I changed it as suggested so that now it runs C:
\Python32\python.exe extract_songs.py but it still isn't working. A
DOS prompt flashes real quick as it runs, but when I check the output
file that is supposed to be written to, nothing new has been added.
I'm not sure what the problem is now. I know the script itself works
because I just ran it manually and the output was fine.

As Chris pointed out, you probably aren't getting the script's directory 
right.  After all, how can the scheduler guess where you put it?  The 
obvious answer is to use a full path for the script's filename.  Another 
alternative is to fill in the current directory in the appropriate field 
of the scheduler's entry.


I find it useful to only add batch files to the scheduler.  Those batch 
files can do any setup and cleanup necessary.  In this case, the batch 
file might simply set the current directory to the location of the 
script. But it can also pause at the end, so you can read the console 
before it disappears.   Or it could create another file, so you could 
check the timestamp to figure out when it was triggered.


DaveA

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


Re: Only Bytecode, No .py Files

2011-07-27 Thread John Roth
On Jul 27, 1:10 am, Thomas Rachel  wrote:
> Am 26.07.2011 17:19 schrieb Eldon Ziegler:
>
> > Is there a way to have the Python processor look only for bytecode
> > files, not .py files? We are seeing huge numbers of Linux audit messages
> > on production system on which only bytecode files are stored. The audit
> > subsystem is recording each open failure.
>
> Is that really a problem? AFAIK there are many failing open() calls on
> the start of every program.
>
> E.g.
>
> open("/lib/bash/4.1/tls/i686/sse2/libncurses.so.5", O_RDONLY) = -1
> ENOENT (No such file or directory)
> stat64("/lib/bash/4.1/tls/i686/sse2", 0xbfd3a350) = -1 ENOENT (No such
> file or directory)
> open("/lib/bash/4.1/tls/i686/libncurses.so.5", O_RDONLY) = -1 ENOENT (No
> such file or directory)
> stat64("/lib/bash/4.1/tls/i686", 0xbfd3a350) = -1 ENOENT (No such file
> or directory)
> open("/lib/bash/4.1/tls/sse2/libncurses.so.5", O_RDONLY) = -1 ENOENT (No
> such file or directory)
> stat64("/lib/bash/4.1/tls/sse2", 0xbfd3a350) = -1 ENOENT (No such file
> or directory)
> open("/lib/bash/4.1/tls/libncurses.so.5", O_RDONLY) = -1 ENOENT (No such
> file or directory)
> stat64("/lib/bash/4.1/tls", 0xbfd3a350) = -1 ENOENT (No such file or
> directory)
> open("/lib/bash/4.1/i686/sse2/libncurses.so.5", O_RDONLY) = -1 ENOENT
> (No such file or directory)
> stat64("/lib/bash/4.1/i686/sse2", 0xbfd3a350) = -1 ENOENT (No such file
> or directory)
> open("/lib/bash/4.1/i686/libncurses.so.5", O_RDONLY) = -1 ENOENT (No
> such file or directory)
> stat64("/lib/bash/4.1/i686", 0xbfd3a350) = -1 ENOENT (No such file or
> directory)
> open("/lib/bash/4.1/sse2/libncurses.so.5", O_RDONLY) = -1 ENOENT (No
> such file or directory)
> stat64("/lib/bash/4.1/sse2", 0xbfd3a350) = -1 ENOENT (No such file or
> directory)
> open("/lib/bash/4.1/libncurses.so.5", O_RDONLY) = -1 ENOENT (No such
> file or directory)
> stat64("/lib/bash/4.1", 0xbfd3a350)     = -1 ENOENT (No such file or
> directory)
> open("/lib/libncurses.so.5", O_RDONLY)  = 3
>
> is a part of what happens if I start the MySQL client,
>
> Even starting the bash results in
>
> open("/lib/bash/4.1/tls/i686/sse2/libreadline.so.6", O_RDONLY) = -1
> ENOENT (No such file or directory)
> stat64("/lib/bash/4.1/tls/i686/sse2", 0xbfe0c4d0) = -1 ENOENT (No such
> file or directory)
> open("/lib/bash/4.1/tls/i686/libreadline.so.6", O_RDONLY) = -1 ENOENT
> (No such file or directory)
> stat64("/lib/bash/4.1/tls/i686", 0xbfe0c4d0) = -1 ENOENT (No such file
> or directory)
> open("/lib/bash/4.1/tls/sse2/libreadline.so.6", O_RDONLY) = -1 ENOENT
> (No such file or directory)
> stat64("/lib/bash/4.1/tls/sse2", 0xbfe0c4d0) = -1 ENOENT (No such file
> or directory)
> open("/lib/bash/4.1/tls/libreadline.so.6", O_RDONLY) = -1 ENOENT (No
> such file or directory)
> stat64("/lib/bash/4.1/tls", 0xbfe0c4d0) = -1 ENOENT (No such file or
> directory)
> open("/lib/bash/4.1/i686/sse2/libreadline.so.6", O_RDONLY) = -1 ENOENT
> (No such file or directory)
> stat64("/lib/bash/4.1/i686/sse2", 0xbfe0c4d0) = -1 ENOENT (No such file
> or directory)
> open("/lib/bash/4.1/i686/libreadline.so.6", O_RDONLY) = -1 ENOENT (No
> such file or directory)
> stat64("/lib/bash/4.1/i686", 0xbfe0c4d0) = -1 ENOENT (No such file or
> directory)
> open("/lib/bash/4.1/sse2/libreadline.so.6", O_RDONLY) = -1 ENOENT (No
> such file or directory)
> stat64("/lib/bash/4.1/sse2", 0xbfe0c4d0) = -1 ENOENT (No such file or
> directory)
> open("/lib/bash/4.1/libreadline.so.6", O_RDONLY) = -1 ENOENT (No such
> file or directory)
> stat64("/lib/bash/4.1", 0xbfe0c4d0)     = -1 ENOENT (No such file or
> directory)
> open("/etc/ld.so.cache", O_RDONLY)      = 3
>
> So can it really be such a huge problem?
>
> Thomas

Two comments. First, your trace isn't showing attempts to open .py
files, it's showing attempts to open the Curses library in the bash
directory. Maybe you also have a problem with the .py files, but it
isn't documented in this trace. It's also not showing the program
that's causing the failing open.

Second, the audit program is an idiot. There are lots of programs
which use the "easier to ask forgiveness" pattern and test for the
existence of optional files by trying to open them. This may be what
Bash is doing.

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


Re: Maximize already running tkinter program on invocation

2011-07-27 Thread Peter Otten
Steven Kauffmann wrote:

> I have written a small GUI application in python 3.x using the tkinter
> module. Program is running fine, but multiple instances of the program
> can now be created. I would like to reduce the number of instances of
> the program to only 1 instance. I know that this is possible by using
> a singleton class. This way it's possible to check if the program is
> already running or not.
> 
> When I invoke the program and it detects that the program is already
> running, is it then possible to maximize the already running program?
> 
> I can find a lot of examples about singleton classes in python on the
> web, but nothing about showing the already running application when 1
> instance of the program already exists. Is there a way to realize this
> in python?
> 
> I'm now doing the development on a linux machine, but the final
> program should work on Windows.

The singleton pattern will help you ensure that you can create only one 
instance of the class per process, it doesn't limit the number of processes 
running the same program.

I think a generic way to inform a process about an already running instance 
of the program is to occupy a previously agreed-upon resource like a file or 
socket. The Python cookbook has a few recipes, e. g. 

http://code.activestate.com/recipes/576891/

but the details are tricky to get right and I cannot vouch for the sanity of 
the one I linked.


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


Re: can I use element tree for handling special characters in xml text?

2011-07-27 Thread Stefan Behnel

hackingKK, 27.07.2011 13:16:

I have been waiting a lot to ask this question and I did ask some days back
but probably could not put it the proper way.


I assume you missed the answer you got?



I want to know how I can safely include special characters like & or > in
xml text?
For example I store a small xml file containing list of organisations.
Many names have an "&" in the name as in brian & turner.
so the xml noad will be  brian & turner 
But I know this won't work directly.


Yes it does. There's nothing you have to do, just put in the text and 
ElementTree will handle it.




my code naturally fails when I try to insert such data.


You may want to show us your code then. Please provide a code snippet that 
shows the problem and present the output you get as well as the output you 
expected.


Stefan

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


can I use element tree for handling special characters in xml text?

2011-07-27 Thread hackingKK

Hello all.
I have been waiting a lot to ask this question and I did ask some days 
back but probably could not put it the proper way.
I want to know how I can safely include special characters like & or > 
in xml text?

For example I store a small xml file containing list of organisations.
Many   names have an "&"  in the name as in brian & turner.
so the xml noad will be  brian & turner 
But I know this won't work directly.
my code naturally fails when I try to insert such data.
Can any one suggest the right way of parsing this kind  of strings and 
treat & like characters as part of the literal string?

Hope my question is clear this time.
Happy hacking.
Krishnakant.

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


PyImport_ImportModule bug in 3.1.2

2011-07-27 Thread bob . wang
Hi:
My Python version is 3.1.2.
I am programming embedding c with python in windows.
When I imported urllib.request  in my test py file,
PyImport_ImportModule always return NULL.
But I imported re or cmd ,they work fine.
I found urllib is folder, and request seems to be submodule.
I don't know how to import it. I confirmed myutil.py and application
are in same folder.
Could you give me some advice?
Thank you.

myutil.py

import sys
import urllib.request 


CRLF = '\r\n'

def addValue(oper1,oper2):
  return (oper1 + oper2);


def ConnectURL(url):
  try:
req = urllib.request.urlopen(url)
response = req.read()
req.close()
return (req.getcode(),req.geturl()) 

  except BaseException as exp:
sys.stdout.write(exp) 


native code:



int APIENTRY _tWinMain(HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPTSTRlpCmdLine,
   int   nCmdShow)
{
PyObject* pPyUtil   = NULL;
PyObject* pPypfn= NULL;
PyObject* pPyArgs   = NULL;
PyObject* pPyRet= NULL;
int nRet= 0;
int nValue  = 0;


Py_Initialize();
PyImport_ImportModule("sys");   // ok
PyImport_ImportModule("csv");   // ok
 
PyImport_ImportModule("urllib");// ok

pPyUtil = PyImport_ImportModule("myutil"); // failed , 
if(pPyUtil != NULL)
{

Py_DECREF(pPyUtil);
}
Py_Finalize();



return 0;
}




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


Re: Only Bytecode, No .py Files

2011-07-27 Thread Christian Heimes
Am 27.07.2011 03:32, schrieb harrismh777:
> Christian Heimes wrote:
>> The first four bytes of a pyc file contain the magic header. It must
>> match the magic of the current Python version. The next four bytes
>> contain the pyc_mtime. It must match the mtime of the corresponding .py
>> files as returned by fstat().st_mtime. If the magic doesn't match or the
>> mtime header doesn't match the mtime of the .py file, the pyc is ignored.
> 
> ... so recompile is required to fix.

It's not required, you can fake a .py file with a trick:

>>> import os, struct, datetime

First get the magic and mtime from the pyc file

>>> with open("test.pyc", "rb") as f:
... header = f.read(8)
...
>>> magic, mtime = struct.unpack("ii", header)
>>> magic, mtime
(168686339, 1311717735)

Verify it's a good date

>>> datetime.datetime.fromtimestamp(mtime)
datetime.datetime(2011, 7, 27, 0, 2, 15)

Now create an empty test.py

>>> open("test.py", "w").close()

Set its mtime

>>> os.utime("test.py", (mtime, mtime))

Now the test.py has the same mtime as test.pyc and Python won't
recompile the .pyc file from the .py file as long as the magic header
(168686339) is correct.

Christian

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


Re: Validating Entry in tkinter

2011-07-27 Thread Giacomo Boffi
Saul Spatz  writes:

> In tcl/tk an Entry widget can be set to validate its contents with
> the validate option. [...]  Can one do something like this in
> tkinter?

i read the thread and nobody mentioned the python mega widget (Pmw)
toolkit, from whose docs i quote the following

Pmw.EntryField() - entry widget with validation

[...]

Validation is performed early, at each keystroke or other event
which modifies the text. However, if partially valid text is
permitted, the validity of the entered text can be checked just
before it is to be used, which is a form of late validation.

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


Re: How can I make a program automatically run once per day?

2011-07-27 Thread baloan
On Jul 14, 7:00 pm, monkeys paw  wrote:
> On 7/9/2011 10:01 PM, John Salerno wrote:
>
> > Thanks everyone! I probably should have said something like "Python,
> > if possible and efficient, otherwise any other method" ! :)
>
> > I'll look into the Task Scheduler. Thanks again!
>
> You could use the below code. time.sleep(# seconds in a day)
> where i == 30 would run once a day for a month
>
> import time
> i=0
> while (1):
>         print 'hello'
>         time.sleep(2)   # Change this to number of seconds in a day
>         if (i == 3):    # make this 30 for a month
>                 break
>         i = i + 1

This looks like a bad idea to me: to make it work throughout the year
you need to adjust for daylight savings start and end; this is where a
day does not have 24 hours - and, of course, daylight savings depends
on country settings of your host system...

Andreas
bal...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Maximize already running tkinter program on invocation

2011-07-27 Thread Steven Kauffmann
Hi all,

I have written a small GUI application in python 3.x using the tkinter
module. Program is running fine, but multiple instances of the program
can now be created. I would like to reduce the number of instances of
the program to only 1 instance. I know that this is possible by using
a singleton class. This way it's possible to check if the program is
already running or not.

When I invoke the program and it detects that the program is already
running, is it then possible to maximize the already running program?

I can find a lot of examples about singleton classes in python on the
web, but nothing about showing the already running application when 1
instance of the program already exists. Is there a way to realize this
in python?

I'm now doing the development on a linux machine, but the final
program should work on Windows.

Cheers,

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


Re: Only Bytecode, No .py Files

2011-07-27 Thread Thomas Rachel

Am 26.07.2011 17:19 schrieb Eldon Ziegler:

Is there a way to have the Python processor look only for bytecode
files, not .py files? We are seeing huge numbers of Linux audit messages
on production system on which only bytecode files are stored. The audit
subsystem is recording each open failure.


Is that really a problem? AFAIK there are many failing open() calls on 
the start of every program.


E.g.

open("/lib/bash/4.1/tls/i686/sse2/libncurses.so.5", O_RDONLY) = -1 
ENOENT (No such file or directory)
stat64("/lib/bash/4.1/tls/i686/sse2", 0xbfd3a350) = -1 ENOENT (No such 
file or directory)
open("/lib/bash/4.1/tls/i686/libncurses.so.5", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/lib/bash/4.1/tls/i686", 0xbfd3a350) = -1 ENOENT (No such file 
or directory)
open("/lib/bash/4.1/tls/sse2/libncurses.so.5", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/lib/bash/4.1/tls/sse2", 0xbfd3a350) = -1 ENOENT (No such file 
or directory)
open("/lib/bash/4.1/tls/libncurses.so.5", O_RDONLY) = -1 ENOENT (No such 
file or directory)
stat64("/lib/bash/4.1/tls", 0xbfd3a350) = -1 ENOENT (No such file or 
directory)
open("/lib/bash/4.1/i686/sse2/libncurses.so.5", O_RDONLY) = -1 ENOENT 
(No such file or directory)
stat64("/lib/bash/4.1/i686/sse2", 0xbfd3a350) = -1 ENOENT (No such file 
or directory)
open("/lib/bash/4.1/i686/libncurses.so.5", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/lib/bash/4.1/i686", 0xbfd3a350) = -1 ENOENT (No such file or 
directory)
open("/lib/bash/4.1/sse2/libncurses.so.5", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/lib/bash/4.1/sse2", 0xbfd3a350) = -1 ENOENT (No such file or 
directory)
open("/lib/bash/4.1/libncurses.so.5", O_RDONLY) = -1 ENOENT (No such 
file or directory)
stat64("/lib/bash/4.1", 0xbfd3a350) = -1 ENOENT (No such file or 
directory)

open("/lib/libncurses.so.5", O_RDONLY)  = 3

is a part of what happens if I start the MySQL client,

Even starting the bash results in

open("/lib/bash/4.1/tls/i686/sse2/libreadline.so.6", O_RDONLY) = -1 
ENOENT (No such file or directory)
stat64("/lib/bash/4.1/tls/i686/sse2", 0xbfe0c4d0) = -1 ENOENT (No such 
file or directory)
open("/lib/bash/4.1/tls/i686/libreadline.so.6", O_RDONLY) = -1 ENOENT 
(No such file or directory)
stat64("/lib/bash/4.1/tls/i686", 0xbfe0c4d0) = -1 ENOENT (No such file 
or directory)
open("/lib/bash/4.1/tls/sse2/libreadline.so.6", O_RDONLY) = -1 ENOENT 
(No such file or directory)
stat64("/lib/bash/4.1/tls/sse2", 0xbfe0c4d0) = -1 ENOENT (No such file 
or directory)
open("/lib/bash/4.1/tls/libreadline.so.6", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/lib/bash/4.1/tls", 0xbfe0c4d0) = -1 ENOENT (No such file or 
directory)
open("/lib/bash/4.1/i686/sse2/libreadline.so.6", O_RDONLY) = -1 ENOENT 
(No such file or directory)
stat64("/lib/bash/4.1/i686/sse2", 0xbfe0c4d0) = -1 ENOENT (No such file 
or directory)
open("/lib/bash/4.1/i686/libreadline.so.6", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/lib/bash/4.1/i686", 0xbfe0c4d0) = -1 ENOENT (No such file or 
directory)
open("/lib/bash/4.1/sse2/libreadline.so.6", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/lib/bash/4.1/sse2", 0xbfe0c4d0) = -1 ENOENT (No such file or 
directory)
open("/lib/bash/4.1/libreadline.so.6", O_RDONLY) = -1 ENOENT (No such 
file or directory)
stat64("/lib/bash/4.1", 0xbfe0c4d0) = -1 ENOENT (No such file or 
directory)

open("/etc/ld.so.cache", O_RDONLY)  = 3

So can it really be such a huge problem?


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


Re: seeking an example on C extension works in python 3.1.x or above

2011-07-27 Thread Stefan Behnel

Terry Reedy, 27.07.2011 04:58:

On 7/26/2011 8:06 PM, llwaeva...@gmail.com wrote:

I have been searching the example on C extension that works in python
3.1.x


All the stdlib modules written in C. These are extension modules that come
with Python. There are perhaps a hundred more on PyPI.


Or hundreds.

337 x C
http://pypi.python.org/pypi?:action=browse&c=181

115 x C++
http://pypi.python.org/pypi?:action=browse&c=183

39 x Cython
http://pypi.python.org/pypi?:action=browse&c=536

And that only includes those that properly state their implementation 
language (but I assume that's the large majority).


I also (biasedly) second Dan's recommendation of using Cython instead of C, 
as that substantially reduces the chance of producing portability problems 
in the first place. It also substantially lowers the barrier of having to 
learn much about CPython's C-API and the inner workings and differences of 
CPython versions (at least at the C level).


In case the question was about porting existing C code (the OP wasn't clear 
here), it's sometimes even faster to rewrite the code (or at least the glue 
code) in Cython than to port it to CPython 3.x. And the investment is a 
rather good bargain for reducing the future maintenance cost.


Stefan

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