ANN: eGenix mx Base Distribution 3.1.2

2009-01-29 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

eGenix.com mx Base Distribution

   Version 3.1.2 for Python 2.3 - 2.6

   Open Source Python extensions providing
 important and useful services
for Python programmers.

This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.1.2-GA.html



ABOUT

The eGenix.com mx Base Distribution for Python is a collection of
professional quality software tools which enhance Python's usability
in many important areas such as fast text searching, date/time
processing and high speed data types.

The tools have a proven record of being portable across many Unix and
Windows platforms. You can write applications which use the tools on
Windows and then run them on Unix platforms without change due to the
consistent platform independent interfaces.

Contents of the distribution:

 * mxDateTime - Date/Time Library for Python
 * mxTextTools - Fast Text Parsing and Processing Tools for Python
 * mxProxy - Object Access Control for Python
 * mxBeeBase - On-disk B+Tree Based Database Kit for Python
 * mxURL - Flexible URL Data-Type for Python
 * mxUID - Fast Universal Identifiers for Python
 * mxStack - Fast and Memory-Efficient Stack Type for Python
 * mxQueue - Fast and Memory-Efficient Queue Type for Python
 * mxTools - Fast Everyday Helpers for Python

All available packages have proven their stability and usefulness in
many mission critical applications and various commercial settings all
around the world.

For more information, please see the distribution page:

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



NEWS

The 3.1.2 release of the eGenix mx Base Distribution is the latest
release of our open-source Python extensions.

We have fixed a number of small platform issues and added support for
the strptime() function to mxDateTime on Windows. We have also enhanced
the portability of our pre-built Mac OS X binaries.

As always, we are providing pre-built binaries for all supported
platforms, currently: Windows 32-bit, Linux 32-bit, Linux 64-bit,
FreeBSD 32-bit, FreeBSD 64-bit, Mac OS X 32-bit Intel and PPC.

Whether you are using a pre-built package or the source distribution,
installation is a simple "python setup.py install" command in all
cases. The only difference is that the pre-built packages do not
require a compiler to be installed.

For a list of changes, please refer to the eGenix mx Base Distribution
change log at

http://www.egenix.com/products/python/mxBase/changelog.html

and the change logs of the various included Python packages.



DOWNLOADS

The download archives and instructions for installing the packages can
be found on the eGenix mx Base Distribution page:

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



LICENSE

The eGenix mx Base package is distributed under the eGenix.com Public
License 1.1.0 which is an Open Source license similar to the Python
license. You can use the packages in both commercial and non-commercial
settings without fee or charge.

The package comes with full source code



SUPPORT

Commercial support for this product is available from eGenix.com.
Please see

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

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

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


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


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


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


Re: date handling problem

2009-01-29 Thread M.-A. Lemburg
On 2009-01-29 03:38, Gabriel Genellina wrote:
> En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva
>  escribió:
> 
>> I need to parse rss-feeds based on time stamp,But rss-feeds follow
>> different
>> standards of date(IST,EST etc).
>> I dont know,how to standardize this standards.It will be helpful if
>> you can
>> hint me.
> 
> You may find the Olson timezone database useful.
> http://pytz.sourceforge.net/

Or have a look at the date/time parser in mxDateTime:

http://www.egenix.com/products/python/mxBase/mxDateTime/

-- 
Marc-Andre Lemburg
eGenix.com

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


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


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


Re: Sloooooowwwww WSGI restart

2009-01-29 Thread Bruno Desthuilliers

Ron Garret a écrit :
I'm running a WSGI app under apache/mod_wsgi and I've noticed that 
whenever I restart the server after making a code change it takes a very 
long time (like a minute) before the script is active again.  In other 
words, I do an apachectl restart, reload the page in my browser, and one 
minute later it finally comes up.  During this time CPU usage is 
essentially zero.  Loading all the code manually into a python 
interpreter is virtually instantaneous, and all subsequence interactions 
with the app are very fast.


Does anyone have any ideas what might be going on or how to debug this?


Restarting apache (with or without mod_wsgi) can by itself take some time.

Now, if you're running mod_wsgi in daemon mode, you _don't_ have to 
restart apache to reload your code - just touch the wsgi script file and 
you'll be done, ie with:



  WSGIProcessGroup myproject.tld
  WSGIDaemonProcess myproject.tld user=you group=you
  WSGIReloadMechanism Process
  WSGIScriptAlias / /var/www/myproject/apache/myapp.py


you just have to touch myapp.py to force reload the subinterpreter(s).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 64, Issue 644

2009-01-29 Thread M Kumar
is python a pure objected oriented language?

On Thu, Jan 29, 2009 at 2:08 PM,  wrote:

> Send Python-list mailing list submissions to
>[email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>[email protected]
>
> You can reach the person managing the list at
>[email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
>
> Today's Topics:
>
>   1. Re: dicts,instances,containers, slotted instances, et cetera.
>  (Michele Simionato)
>   2. Re: Recommendation for a small web framework like Perl's
>  CGI::Application to run as CGI? (Jeroen Ruigrok van der Werven)
>   3. Re: Profiling Python Apps on Mac? (Robert Kern)
>   4. Re: Results of executing hyperlink in script (Tino Wildenhain)
>   5. Re: I'm a python addict ! ([email protected])
>   6. ANN: eGenix mx Base Distribution 3.1.2
>  (eGenix Team: M.-A. Lemburg)
>
>
> -- Forwarded message --
> From: Michele Simionato 
> To: [email protected]
> Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST)
> Subject: Re: dicts,instances,containers, slotted instances, et cetera.
> On Jan 29, 12:23 am, [email protected] wrote:
>
> > I just find it odd that there's no quick answer on the
> > fastest way in Python to implement a mapping in this context.
>
> A Python dict is as fast as you can get. If that is not enough, your
> only choice is to try something at the C level, which may give the
> desired speedup or not. Good luck!
>
>   Michele Simionato
>
>
>
> -- Forwarded message --
> From: Jeroen Ruigrok van der Werven 
> To: excord80 
> Date: Thu, 29 Jan 2009 07:31:54 +0100
> Subject: Re: Recommendation for a small web framework like Perl's
> CGI::Application to run as CGI?
> -On [20090128 20:36], excord80 ([email protected]) wrote:
> >If that's correct, it would be great if there were a Werkzeug tutorial
> >on deploying it for use with CGI.
>
> There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look
> in the servers directory in the repository.
>
> I'll double check the documentation and expand where necessary.
>
> [1] http://zine.pocoo.org/
>
> --
> Jeroen Ruigrok van der Werven  / asmodai
> イェルーン ラウフロック ヴァン デル ウェルヴェン
> http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
> Earth to earth, ashes to ashes, dust to dust...
>
>
>
> -- Forwarded message --
> From: Robert Kern 
> To: [email protected]
> Date: Thu, 29 Jan 2009 00:47:46 -0600
> Subject: Re: Profiling Python Apps on Mac?
> On 2009-01-28 13:14, RGK wrote:
>
>> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 &
>> wxPython under OSX 10.4)
>>
>> As I make program architecture decisions, it would be nice to be able to
>> profile the choices. Should I add that extra thread? Is this big-assed
>> xml object I just created horribly bloated or kind of ordinary.
>>
>> Is there anything out there I should look into to if I want to see how
>> those things are affecting my app? The closest I have is the widget
>> iStat, but it's a very static low resolution view of what's really going
>> on.
>>
>
> I have a script kernprof.py which provides a few conveniences over the
> builtin cProfile module. One of its modes of operation is to inject a
> decorator into the __builtins__. It will enable the profiler on entry to the
> method and disable it on exit. This lets you localize your profile results
> to just the part of your code that you are interested in. I found this
> especially useful in GUI apps which require user interaction to trigger the
> part of the code you are actually interesting in profiling. You don't want
> the interesting parts of your profile to be obscured by the GUI event loop
> waiting for your input.
>
> You can get it as part of my line_profiler package (which you may also be
> interested in; cProfile profiles function calls, line_profiler profiles
> individual lines).
>
>  http://pypi.python.org/pypi/line_profiler
>
> You can view the profile results interactively with "python -m pstats
> my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install
> kcachegrind on your system:
>
>  http://www.vrplumber.com/programming/runsnakerun/
>  http://pypi.python.org/pypi/pyprof2calltree/1.1.0
>
> I don't recommend using hotshot because it is deprecated and slow to
> postprocess the data dumps. Also, I don't recommend using the plain profile
> module because it slows down your program rather more than cProfile. See the
> Python documentation for an overview of these modules:
>
>  http://docs.python.org/library/profile
>
> --
> 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
>  a

Re: Sloooooowwwww WSGI restart

2009-01-29 Thread Bruno Desthuilliers

Ron Garret a écrit :

In article ,
 Aleksandar Radulovic  wrote:

(snip)

Secondly, why are you restarting apache after code changes? In normal
circumstances, you shouldn't have to do that.


I thought (and experiment confirms) that only the main WSGI app file 
gets reloaded automatically when it changes, not the libraries.


Depends on how you configure mod_wsgi. Read the part about "Process 
Reloading Mechanism" here:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-29 Thread Bruno Desthuilliers

excord80 a écrit :

On Jan 28, 4:57 am, Bruno Desthuilliers  wrote:


What about:http://thraxil.org/code/cgi_app/

(yes, it is a port of CGI::Application, and FWIW it's mentionned on the
CGI::Application's wiki).



Nice find. Thank you. Interesting project. It seems to be only one
fairly short file (perhaps that's all it takes),


It is. And given the intended context (CGI...), it's a GoodThing !-)


and its most recent
release was in 2004. No mailing list.


Nope. But does it need new release or a mailing list ? As you say, it's 
just a pretty simple module. The point is that you are very likely to 
fork it for your own needs anyway - so see it as a good starting point 
for a simple lightweight CGI/mod_python (and why not WSGI) framework.

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


Re: Sloooooowwwww WSGI restart

2009-01-29 Thread Aleksandar Radulovic
Graham,

On Thu, Jan 29, 2009 at 1:16 AM, Graham Dumpleton
 wrote:
> Sorry, you are wrong to assume that an Apache restart is not be
> required.
> If you are using mod_wsgi embedded mode, or mod_python, then a code
> change will always require a full restart of Apache.

I am running several middleware apps I'm working on under mod_python
(simple setup using mod_python.publisher handler) and so far, haven't
had the reason to restart apache at all.

> Thus, the conjecture that Apache/mod_wsgi cannot be used and that
> CherryPy WSGI server or Paster server must be used when developing a
> Python web application is false. If using mod_wsgi then daemon mode

Not sure what (or whom) you're referring to. IMO, developing TG/Pylons/Django
apps is much convinient with embedded web server (cherrypy or paster) as
it is possible to do rapid development without resorting to restarts.

Example with Pylons:
$ paster serve development.ini --reload

This will start a subprocess which monitors file changes.

Regards,
alex.
-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 64, Issue 644

2009-01-29 Thread Chris Rebert
On Thu, Jan 29, 2009 at 1:08 AM, M Kumar  wrote:
> is python a pure objected oriented language?

Firstly:
(A) Replying to Digests rather than individual posts is very discouraged.
(B) The proper way to start a new thread by emailing
[email protected] (as it says in the very header of the digest!),
not by replying to unrelated posts.

And now to your question:
Yes, Python is completely object-oriented in the Smalltalk sense;
everything is an object, there are no "primitive types" or non-object
values, in contrast to, say, Java.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com


> On Thu, Jan 29, 2009 at 2:08 PM,  wrote:
>>
>> Send Python-list mailing list submissions to
>>[email protected]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>http://mail.python.org/mailman/listinfo/python-list
>> or, via email, send a message with subject or body 'help' to
>>[email protected]
>>
>> You can reach the person managing the list at
>>[email protected]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Python-list digest..."
>>
>> Today's Topics:
>>
>>   1. Re: dicts,instances,containers, slotted instances, et cetera.
>>  (Michele Simionato)
>>   2. Re: Recommendation for a small web framework like Perl's
>>  CGI::Application to run as CGI? (Jeroen Ruigrok van der Werven)
>>   3. Re: Profiling Python Apps on Mac? (Robert Kern)
>>   4. Re: Results of executing hyperlink in script (Tino Wildenhain)
>>   5. Re: I'm a python addict ! ([email protected])
>>   6. ANN: eGenix mx Base Distribution 3.1.2
>>  (eGenix Team: M.-A. Lemburg)
>>
>>
>> -- Forwarded message --
>> From: Michele Simionato 
>> To: [email protected]
>> Date: Wed, 28 Jan 2009 22:17:12 -0800 (PST)
>> Subject: Re: dicts,instances,containers, slotted instances, et cetera.
>> On Jan 29, 12:23 am, [email protected] wrote:
>>
>> > I just find it odd that there's no quick answer on the
>> > fastest way in Python to implement a mapping in this context.
>>
>> A Python dict is as fast as you can get. If that is not enough, your
>> only choice is to try something at the C level, which may give the
>> desired speedup or not. Good luck!
>>
>>   Michele Simionato
>>
>>
>>
>> -- Forwarded message --
>> From: Jeroen Ruigrok van der Werven 
>> To: excord80 
>> Date: Thu, 29 Jan 2009 07:31:54 +0100
>> Subject: Re: Recommendation for a small web framework like Perl's
>> CGI::Application to run as CGI?
>> -On [20090128 20:36], excord80 ([email protected]) wrote:
>> >If that's correct, it would be great if there were a Werkzeug tutorial
>> >on deploying it for use with CGI.
>>
>> There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look
>> in the servers directory in the repository.
>>
>> I'll double check the documentation and expand where necessary.
>>
>> [1] http://zine.pocoo.org/
>>
>> --
>> Jeroen Ruigrok van der Werven  / asmodai
>> イェルーン ラウフロック ヴァン デル ウェルヴェン
>> http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
>> Earth to earth, ashes to ashes, dust to dust...
>>
>>
>>
>> -- Forwarded message --
>> From: Robert Kern 
>> To: [email protected]
>> Date: Thu, 29 Jan 2009 00:47:46 -0600
>> Subject: Re: Profiling Python Apps on Mac?
>> On 2009-01-28 13:14, RGK wrote:
>>>
>>> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 &
>>> wxPython under OSX 10.4)
>>>
>>> As I make program architecture decisions, it would be nice to be able to
>>> profile the choices. Should I add that extra thread? Is this big-assed
>>> xml object I just created horribly bloated or kind of ordinary.
>>>
>>> Is there anything out there I should look into to if I want to see how
>>> those things are affecting my app? The closest I have is the widget
>>> iStat, but it's a very static low resolution view of what's really going
>>> on.
>>
>> I have a script kernprof.py which provides a few conveniences over the
>> builtin cProfile module. One of its modes of operation is to inject a
>> decorator into the __builtins__. It will enable the profiler on entry to the
>> method and disable it on exit. This lets you localize your profile results
>> to just the part of your code that you are interested in. I found this
>> especially useful in GUI apps which require user interaction to trigger the
>> part of the code you are actually interesting in profiling. You don't want
>> the interesting parts of your profile to be obscured by the GUI event loop
>> waiting for your input.
>>
>> You can get it as part of my line_profiler package (which you may also be
>> interested in; cProfile profiles function calls, line_profiler profiles
>> individual lines).
>>
>>  http://pypi.python.org/pypi/line_profiler
>>
>> You can view the profile results interactively with "python -m pstats
>> my_script.py.prof", RunSnakeRun, or pyprof2calltree if you man

Re: Why doesn't eval of generator expression work with locals?

2009-01-29 Thread Hendrik van Rooyen
"Gabriel Genellina"  wrote:



>> Seems that it is important *when* those functions are evaluated, but I
>> don't understand *why*...

Because the scope changes - see also the recent thread on exec woes
where towards the end I put in a similar example - funny, it must the 
flux or something - seems to be the season for calling id on locals()
:-)

- Hendrik


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


Re: Why doesn't eval of generator expression work with locals?

2009-01-29 Thread Hendrik van Rooyen
"Gabriel Genellina"  wrote:

En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels
> escribió:
>
>> The reason is that once your created object has its id taken, you
>> must keep a handle on it, otherwise it may get recycled and reused.
>
>It doesn't matter in this case, I think. globals() is always the same
>object and is alive during the whole test. So something having the same
>id() than globals() must be the very same object, and something having a
>different id() than globals() cannot be the same object.
>
>If you like, I can rewrite the example without using id():
>
 L = list(n for n in [globals(),locals()])
 L[0] is L[1]
>True
 L = list(n() for n in [globals,locals])
 L[0] is L[1]
>False
>
>(I *think* this has to do with free variables in the "right side" (after
>the "in" keyword) of a generator expression; they appear to be evaluated
>when the expression is *defined*, not when is is *used*. By contrast, free
>variables in the "left side" appear to be evaluated when the expression is
>used.)
>

Yikes! this is, IMO, far too complicated a way of looking at it.

I think that if you rewrite the "comprehensions" as loops,
you will see what is happening. - in the one case, the locals()
returned is from the outer scope, while in the other the
locals function is called from inside the loop - a different scope,
because there must be *somewhere* where the state is kept to yield
the next value.

If you nest the thing inside something else, then globals() and locals()
won't be the same, but the two locals() will still differ.

I find it very confusing because locals is always the same
function - but what it returns varies depending on where you
call it from. So if you want to pass it around, it's no good
passing the function - you have to pass the returned result,
*called from the scope of interest*.  Subtle stuff.

- Hendrik


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


Re: Exec woes

2009-01-29 Thread Hendrik van Rooyen
 "Rhodri James"  wrote:
To: 
Sent: Thursday, January 29, 2009 6:12 AM
Subject: Re: Exec woes


> On Wed, 28 Jan 2009 07:47:00 -, Hendrik van Rooyen
>  wrote:

> > This is actually not correct - it is the root cause of my trouble.
> > if you write, in a nested scope:
> >
> > exec ( "somestring to execute" in globals(),locals())
> >
> > You get the syntax error, as the interpreter somehow sees it as one,
> > unqualified thing.
>
> Well, no.  Look at the error Python gives you, nested scope or not:
>
> Traceback (most recent call last):
>File "", line 1, in 
> TypeError: exec: arg 1 must be a string, file, or code object
>
> If exec is a function, arg 1 is the boolean expression
>"somestring to execute" in globals()
> which is unlikely to be what you want.  If exec is a statement,
> arg 1 is a tuple of two elements,
>"somestring to execute" in globals()
> and
>locals()
> which is also unlikely to be what you want.  Neither of these are
> giving you a string, file or code object, exactly as the interpreter
> is telling you.

Well, no - I stick by my assertion, about the nested scope:

>>> def rubbish():
 def deep_rubbish():
  exec('BUILD = "somestring"' in globals(),locals())

SyntaxError: unqualified exec is not allowed in function 'deep_rubbish' it is a
nested function (, line 3)
>>>

That is all I was saying - It was the brackets that buggered me,
and adding the globals() and locals() inside the brackets, inside
the nested scope, makes no difference - the interpreter sees it
as an unqualified exec.

Did you actually try it in a nested scope before asserting
"nested scope or not" ?

If you just do, in the outside scope, the thing I did originally:

>>> exec('BUILD = "foobar"')
>>> BUILD
'foobar'
>>>

Then the brackets are ignored, and the defaults kick in.

But this is silly nit picking around the basic error,
which was to treat the thing as a function and putting
the brackets there.

The other bits in the thread, about the scopes and
locals() are far more interesting.

- Hendrik


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


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-29 Thread James Stroud

[email protected] wrote:

I can't port the entire app to be a stored database procedure.


Perhaps I underestimate what you mean by this, but you may want to look 
at pyTables (http://www.pytables.org/moin/HowToUse).



ctypes, maybe. I just find it odd that there's no quick answer on the
fastest way in Python to implement a mapping in this context.


Your explanation of where your prototype is slow is a little unclear. If 
your data is largely numerical, you may want to rethink your 
organization and use a numeric package. I did something similar and saw 
an order of magnitude speed increase by switching from python data types 
to numpy combined with careful tuning of how I managed the data.


You may have to spend more time on this than you would like, but if you 
really put some thought into it and grind at your organization, you can 
 probably get a significant performance increase.


James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA  90095

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


is python Object oriented??

2009-01-29 Thread M Kumar
Object oriented languages doesn't allow execution of  the code without class
objects, what is actually happening when we execute  some piece of code, is
it bound to any class?
Those who have time and consideration can help me

-- 
Regards,

Maneesh KB

Comat Technologies

Bangalore

Mob: 9740-192309



We work with the underprivileged and in rural India. If you are interested
to be a part of it, please mail or call me. I will be happy to share and
inform - http://www.comat.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-01-29 Thread Gary Herron
M Kumar wrote:
> Object oriented languages doesn't allow execution of  the code without
> class objects, what is actually happening when we execute  some piece
> of code, is it bound to any class?
> Those who have time and consideration can help me
>

Python *is* object-oriented, but it is not (as your definition suggests)
object-fascist.  We use objects to great effect in Python, when it is
natural to do so, but the language does not force  it on us. 


Gary Herron


> -- 
> Regards,
>
> Maneesh KB
>
> Comat Technologies
>
> Bangalore
>
> Mob: 9740-192309
>
>
>
> We work with the underprivileged and in rural India. If you are
> interested to be a part of it, please mail or call me. I will be happy
> to share and inform - http://www.comat.com
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>   

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


Re: date handling problem

2009-01-29 Thread S.Selvam Siva
On Thu, Jan 29, 2009 at 2:27 PM, M.-A. Lemburg  wrote:

> On 2009-01-29 03:38, Gabriel Genellina wrote:
> > En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva
> >  escribió:
> >
> >> I need to parse rss-feeds based on time stamp,But rss-feeds follow
> >> different
> >> standards of date(IST,EST etc).
> >> I dont know,how to standardize this standards.It will be helpful if
> >> you can
> >> hint me.
> >
> > You may find the Olson timezone database useful.
> > http://pytz.sourceforge.net/
>
> Or have a look at the date/time parser in mxDateTime:
>
> http://www.egenix.com/products/python/mxBase/mxDateTime/
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Source  (#1, Jan 29 2009)
> >>> Python/Zope Consulting and Support ...http://www.egenix.com/
> >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
> >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
> 
>
> ::: Try our new mxODBC.Connect Python Database Interface for free ! 
>
>
>   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>   Registered at Amtsgericht Duesseldorf: HRB 46611
>   http://www.egenix.com/company/contact/
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thank you all,
  The link was really nice and i will try it out.

-- 
Yours,
S.Selvam
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-01-29 Thread Chris Rebert
On Thu, Jan 29, 2009 at 2:01 AM, M Kumar  wrote:
> Object oriented languages doesn't allow execution of  the code without class
> objects, what is actually happening when we execute  some piece of code, is
> it bound to any class?

That's not really the standard definition of object-oriented (c.f.
Wikipedia), but by your definition (which seems Java/Ruby-centric,
IMHO), Python would not be object-oriented.

In addition to methods, Python has functions, which are not associated
with a class and let you write code in a procedural style, thus
failing your criterion.
Python also has the top-level module scope, in which the code isn't
even part of a method or function at all and thus certainly is not
associated with a class, again not satisfying your criterion.

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


Re: is python Object oriented??

2009-01-29 Thread Bruno Desthuilliers

(answering to the OP)

M Kumar wrote:

Object oriented languages doesn't allow execution of  the code without
class objects,


Chapter and verse, please ?

Nothing in the (very few) "axioms" of OOP mentions "classes". You don't 
need classes to have an OOPL (ever heard about prototype-based languages 
?). OOP is - as the name imply - about *objects*.



what is actually happening when we execute  some piece
of code,


Top-level code ? or the body of a def statement ?


is it bound to any class?


Why should it be ?

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


Re: is python Object oriented??

2009-01-29 Thread Muriel de Souza Godoi
Python offers support for object orientation, but it's not an
object-oriented language.
I mean, you can code a entire program in Python with no classes. So you use
it if you want to.

It's not like java, which you must use a class to code a Hello World, but
Java isn't fully object-oriented, because it doesn't provide support for
multiple inheritance and it has primitive types (multiple interfaces and
wrappers to primitive types doesn't count  :) )

AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe
Simula?), where everything is a class, even the primitive types.

An excellent reference book for that is:
Sebesta, Robert W. (2002): *Concepts of Programming Languages (Fifth
Edition).* Addison-Wesley Publishing

Cheers,

-- 
Muriel de Souza Godoi
State University of Maringá
Brazil
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-01-29 Thread Tino Wildenhain

Muriel de Souza Godoi wrote:
Python offers support for object orientation, but it's not an 
object-oriented language.
I mean, you can code a entire program in Python with no classes. So you 
use it if you want to.


It's not like java, which you must use a class to code a Hello World, 
but Java isn't fully object-oriented, because it doesn't provide support 
for multiple inheritance and it has primitive types (multiple interfaces 
and wrappers to primitive types doesn't count  :) )


AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe 
Simula?), where everything is a class, even the primitive types.


well actually except keywords, everything is an object in python too,
including of course primitive types (if you say so - practically python
does not have them).

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-01-29 Thread MC

Hi!

Il se trouve que Chris Rebert a formulé :

Python has functions, which are not associated
with a class


functions are methods of builtin...





--
@-salutations

Michel Claveau


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


Re: Tkinter w.pack()?

2009-01-29 Thread Steve Holden
W. eWatson wrote:
> r wrote:
>> On Jan 28, 10:12 pm, "W. eWatson"  wrote:
>>> Where in the world is a description of pack() for Tkinter widgets? Is it
>>> some sort of general method for all widgets? I'm looking in a few
>>> docs that
>>> use it without ever saying where it is described. For one,
>>> . In the NM Tech pdf on
>>> Tkinter,
>>> it's not found anywhere. I see Universal methods for widgets, but no
>>> mention
>>> of pack(). package, packed, but no pack.
>>
>> did you try here :)
>> http://effbot.org/tkinterbook/pack.htm
> Thanks. I have the site bookmarked, but it's hard to search. I posted a
> comment to them that they should have it in pdf form.
> 
http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: is python Object oriented??

2009-01-29 Thread Steve Holden
M Kumar wrote:
> Object oriented languages doesn't allow execution of  the code without
> class objects, what is actually happening when we execute  some piece of
> code, is it bound to any class?
> Those who have time and consideration can help me

a) This is a purely theoretical consideration. You asked whether "python
is a pure object oriented language", but this will inevitably lead to
obscure discussions about what you mean rather than what Python is.

b) You seem to believe that a "pure" object oriented language must do
everything using classes. Since many problems are just as easy (or
easier) to solve with a procedural approach, Python takes the view that
it should be easy to provide such solutions as well.

c) import this
The Zen of Python, by Tim Peters

[...] practicality beats purity [...]

We aren't big on purity in the Python world ;-)

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: how to update python on gnu emacs?

2009-01-29 Thread Wang Lei
If you means python-mode, you can add this line to you .emacs:

(setq py-python-command "python3.0")

On 1/29/09, John Seales  wrote:
>
> I've updated to python 2.6. My terminal application finds the new python
> just fine, but my gnu-emacs still is on python 2.3. Does anyone know how I
> can change that?
>
> using x86 powerbook
>
> John Seales
>
> _
> Windows Live™ Hotmail(R)…more than just e-mail.
> http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009


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


Re: Sloooooowwwww WSGI restart

2009-01-29 Thread Graham Dumpleton
On Jan 29, 8:15 pm, Aleksandar Radulovic  wrote:
> Graham,
>
> On Thu, Jan 29, 2009 at 1:16 AM, Graham Dumpleton
>
>  wrote:
> > Sorry, you are wrong to assume that an Apache restart is not be
> > required.
> > If you are usingmod_wsgiembedded mode, or mod_python, then a code
> > change will always require a full restart of Apache.
>
> I am running several middleware apps I'm working on under mod_python
> (simple setup using mod_python.publisher handler) and so far, haven't
> had the reason to restart apache at all.

The automatic module reloading in mod_python when using
mod_python.publisher only applies to the publisher code files or those
imported via the mod_python module importer and which is also a
candidate for reloading.

Basically, any module or package installed on sys.path is not a
candidate for reloading. Thus if you installed your code outside of
your document tree in a directory in sys.path and those code files
were changed, then no automatic reload would occur.

For further information see documentation for import_module() in:

  http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html

In other words, it is not universal that any code change will be
automatically detected and a reload occur. There are also various
caveats on what mod_python module importer does, as it is reloading
modules into an existing process and not restarting the whole process.
If you are not careful, weird things can happen.

> > Thus, the conjecture that Apache/mod_wsgicannot be used and that
> > CherryPy WSGI server or Paster server must be used when developing a
> > Python web application is false. If usingmod_wsgithen daemon mode
>
> Not sure what (or whom) you're referring to.

It was a general statement. There are various people on different
forums and irc channels who keep saying that a full Apache restart is
required with Apache/mod_wsgi when making code changes. Am just
stating for the record that that isn't true.

> IMO, developing TG/Pylons/Django
> apps is much convinient with embedded web server (cherrypy or paster) as
> it is possible to do rapid development without resorting to restarts.

In the case of Django, it uses a single non threaded process, thus is
not an adequate test of either a multithread or multiprocess
environment. Something which Apache/mod_wsgi provides.

CherryPy WSGI server although it provides multithreading doesn't have
a multiprocess option and it itself doesn't have a reload feature but
depends on some layer on top to manage that from what I remember.

So, depends on how closely you want your development environment to
mirror production so that issues are picked up sooner, rather than
only at the point of deployment to a production system when you are
under pressure.

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


Re: how to update python on gnu emacs?

2009-01-29 Thread Wang Lei
Sorry. Mine is python3.0.

Yours maybe is:

(setq py-python-command "python2.6")

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


Re: How to get atexit hooks to run in the presence of execv?

2009-01-29 Thread Mark Wooding
[email protected] (R. Bernstein) writes:

> Recently, I added remote debugging via TCP sockets. (Well, also FIFO's
> as well but closing sockets before restarting is what's of concern.)
>
> I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get
> called. Should it?

I'd consider that to be highly unusual.  Certainly, the C atexit(3)
function is called only in response to a call to exit(3) (possibly
implicitly by returning from main), and not by execve(2) or any of its
little friends.

Your specific problem is to do with file descriptors, so it's probably
best dealt with using the close-on-exec flag:

from fcntl import fcntl, F_GETFD, F_SETFD, F_CLOEXEC

sk = socket(...)
## ...
fcntl(sk.fileno(), F_SETFD,
  fcntl(sk.fileno(), F_GETFD) | FD_CLOEXEC)

Now the socket will be magically closed when you exec.. another program.

Finally, can I urge against TCP sockets in an application like this?
Certainly without adequate authentication, it will simply be insecure
even within a single multiuser host (e.g., using localhost only) -- and
assuming that even a home machine has only a single user is becoming
less realistic.  Unix-domain sockets live in the filesystem, and access
to them is limited using the standard filesystem mechanisms.

If you're expecting inter-host communications (e.g., remote debugging),
it's a good idea to protect the session using TLS or something (much as
I dislike the TLS certification/public-key- distribution model it's way
better than nothing at all).

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


Re: syntax color lang source code in blogs or website

2009-01-29 Thread Lorenzo Bettini

Xah Lee wrote:

For those of you using emacs, here's the elisp code that allows you to
syntax color computer language source code in your blog or website.

http://xahlee.org/emacs/elisp_htmlize.html



may I suggest also this one: http://www.gnu.org/software/src-highlite/

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values

2009-01-29 Thread Duncan Booth
alex  wrote:

> Jon
> Thank you for your answer. I tried it with no success.
> 
> However I tried with
> tst=cdll.LoadLibrary("f:\\scratch\\test2\\footst.dll") instead of
> tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll")
> 
> and it runs now with no error message, I can't figure for now why, but
> it's great! This is motivating for going ahead.
> 
cdll is for importing functions which use the cdecl calling convention 
where the caller must clean up the stack.

windll is for functions that use the stdcall calling convention: the 
function that is called is responsible for cleaning up the stack.

If you were using windll when you should have been using cdll then ctypes 
will have been expecting the library to clean up the stack, and the library 
will have been expecting the caller to do the cleanup, so nobody cleaned up 
the stack.

The error message was telling you that ctypes pushed 4 bytes of argument 
onto the stack which weren't popped off by the caller. If you had been 
using the correct calling convention that would have indicated you had 
passed too many arguments, but as you were using the wrong calling 
convention the message was a bit unclear.


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


Re: is python Object oriented??

2009-01-29 Thread M Kumar
but still I am not clear of the execution of the code, when we write or
execute a piece of python code without defining class, predefined class
attributes are available (not all but __name__ and __doc__ are available).
does it mean anything to this topic. Is it necessory to have __module__,
__dict__ and __bases__ for a class object in python?

On Thu, Jan 29, 2009 at 5:21 PM, Tino Wildenhain  wrote:

> Muriel de Souza Godoi wrote:
>
>> Python offers support for object orientation, but it's not an
>> object-oriented language.
>> I mean, you can code a entire program in Python with no classes. So you
>> use it if you want to.
>>
>> It's not like java, which you must use a class to code a Hello World, but
>> Java isn't fully object-oriented, because it doesn't provide support for
>> multiple inheritance and it has primitive types (multiple interfaces and
>> wrappers to primitive types doesn't count  :) )
>>
>> AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe
>> Simula?), where everything is a class, even the primitive types.
>>
>
> well actually except keywords, everything is an object in python too,
> including of course primitive types (if you say so - practically python
> does not have them).
>
> Regards
> Tino
>



-- 
Regards,

Maneesh KB

Comat Technologies

Bangalore

Mob: 9740-192309



We work with the underprivileged and in rural India. If you are interested
to be a part of it, please mail or call me. I will be happy to share and
inform - http://www.comat.com
--
http://mail.python.org/mailman/listinfo/python-list


is there a shorter way to write this

2009-01-29 Thread garywood
I had a task in a book to pick 5 items from a list of 26 ensuring the items are 
not repeated


import random
list = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z']
word = ' '
a = random.choice(list)
list.remove(a)
b = random.choice(list)
list.remove(b)
c = random.choice(list)
list.remove(c)
d = random.choice(list)
list.remove(d)
e = random.choice(list)
list.remove(e)
word = a + b + c + d + e
print (word)
print(list)

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


Re: is python Object oriented??

2009-01-29 Thread Luis M . González
On Jan 29, 7:21 am, Gary Herron  wrote:
> Python *is* object-oriented, but it is not (as your definition suggests)
> object-fascist.  

I'm a python-nazi.
No python for you!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Terminating a Python program that uses multi-process, multi-threading

2009-01-29 Thread Jesse Noller
On Wed, Jan 28, 2009 at 3:46 PM, akineko  wrote:
> Hello Python experts,
>
> I have a program that uses three processes (invoked by
> multiprocessing) and several threads.
> The program is terminated when ^C is typed (KeyboardInterrupt).
> The main process takes the KeyboardInterrupt Exception and it orderly
> shutdown the program.
>
> It works fine in normal situation.
>
> However, KeyboardInterrupt is not accepted when, for example, the
> program is stuck somewhere due to error in network. I understand that
> the KeyboardInterrupt won't be processed until the program moves out
> from an atomic step in a Python program.
>
> Probably this is partly my fault as I use some blocking statements
> (without timeout) as they should not block the program in normal
> situation.
>
> As the program freezes up, I cannot do anything except killing three
> processes using kill command.
> So, I cannot tell which statement is actually blocking when this
> occurs (and there are many suspects).
>
> Is there any good way to deal with this kind of problem?
> Killing three processes when it hangs is not a fun thing to do.
>
> Any suggestions will be greatly appreciated.
>
> Best regards,
> Aki Niimura
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

See also:
http://jessenoller.com/2009/01/08/multiprocessingpool-and-keyboardinterrupt/

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


Re: is python Object oriented??

2009-01-29 Thread Stephen Hansen
On Thu, Jan 29, 2009 at 5:58 AM, M Kumar  wrote:

> but still I am not clear of the execution of the code, when we write or
> execute a piece of python code without defining class, predefined class
> attributes are available (not all but __name__ and __doc__ are available).
> does it mean anything to this topic. Is it necessory to have __module__,
> __dict__ and __bases__ for a class object in python?


I think there's some confusion on what you're asking; Python enables you to
write object oriented software if you choose to. It also enables you to
write procedural software if you choose to. There's other paradigms it
supports too, to varying degrees. Its a tool that allows you to use it as
you wish, instead of saying that a paradigm is the Right Way to do it.

When you are writing object oriented software, you generally define classes.
Class can inherit from other classes: if they do then the __bases__
attribute is set on the class itself to indicate which classes it inherits
from.

All Python code is within a module -- as a module is simply a file. For
classes, functions and methods, the __module__ attribute simply points to
which module it was defined in.

The __dict__ of a class represents the dictionary of attributes that are
"in" or "on" that class (approximately).

But those are all implementation details. You don't have to set any of them
or worry about any of them generally.

You just:

class MyClass:
def __init__(self, bar):
self.value = bar
def foo(self):
return self.value

You don't have to set any class attributes to work with classes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there a shorter way to write this

2009-01-29 Thread Stephen Hansen
On Thu, Jan 29, 2009 at 6:11 AM, garywood  wrote:

>  I had a task in a book to pick 5 items from a list of 26 ensuring the
> items are not repeated
>
>

If the list is unique of 26 elements is guaranteed to be unique, simply:

   >>> import random
   >>> random.sample(list, 5)
['g', 'y', 'i', 'n', 'x']

If the list isn't unique:

>>> import random
>>> random.sample(set(list), 5)
['r', 'e', 'b', 'k', 'i']

If you want to combine them all into a single word as you do in your
example:

>>> import random
>>> ''.join(random.sample(set(list), 5))
'wmhsq'

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


Re: is there a shorter way to write this

2009-01-29 Thread Vlastimil Brom
2009/1/29 garywood :
> I had a task in a book to pick 5 items from a list of 26 ensuring the items
> are not repeated
>
>
> import random
> list = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
> 'n','o','p','q','r','s','t','u','v','w','x','y','z']
> word = ' '
> a = random.choice(list)
> list.remove(a)
> b = random.choice(list)
> list.remove(b)
> c = random.choice(list)
> list.remove(c)
> d = random.choice(list)
> list.remove(d)
> e = random.choice(list)
> list.remove(e)
> word = a + b + c + d + e
> print (word)
> print(list)
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
There are probably several ways to do that, e.g.:

>>> lst = 
>>> ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
>>> randomized_list = lst[:]
>>> random.shuffle(randomized_list)
>>> randomized_list[:5]
['n', 'p', 'e', 'f', 'y']
>>>

(better not name a variable like a builtin - list)

hth,
  vbr
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there a shorter way to write this

2009-01-29 Thread Stephen Hansen
If the list is unique of 26 elements is guaranteed to be unique, simply:
>

Wow, 6am copy editing of my own posts is terribly ineffective.

"If the list of 26 elements is guaranteed to be unique"
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there a shorter way to write this

2009-01-29 Thread Tim Chase

I had a task in a book to pick 5 items from a list of 26
ensuring the items are not repeated

import random
list = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z']
word = ' '
a = random.choice(list)
list.remove(a)
b = random.choice(list)
list.remove(b)
c = random.choice(list)
list.remove(c)
d = random.choice(list)
list.remove(d)
e = random.choice(list)
list.remove(e)
word = a + b + c + d + e
print (word)
print(list)


If you just need the "word", you can use

 >>> word = "".join(random.sample(string.lowercase, 5))

If you need the "leftovers" too:

 >>> letters = list(string.lowercase)
 >>> random.shuffle(letters)
 >>> word = "".join(letters[:5])
 >>> remainder = letters[5:]
 >>> print word
 hjwnq
 >>> print "".join(letters)
 ebultgydafpmrxszicvko

This assumes that your input dataset is unique (which 
string.lowercase is, but your problem definition doesn't 
guarantee) for your definition of "unique" (are upper/lowercase 
considered "unique" or "the same"?).  If you need unique, you'd 
have to pre-process -- likely with set():


 >>> data = "abcdefghijABCDEFGHIJK"
 >>> input_data = list(set(c.lower() for c in data))
 >>> word = "".join(random.sample(input_data, 5))
 >>> random.shuffle(input_data)
 >>> word = "".join(input_data[:5])
 >>> remainder = "".join(input_data[5:])

-tkc









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


RE: is there a shorter way to write this

2009-01-29 Thread Andreas Tawn
> I had a task in a book to pick 5 items from a list of 26 ensuring the
items are not repeated
>
>
> import random
> list = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
>'n','o','p','q','r','s','t','u','v','w','x','y','z']
> word = ' '
> a = random.choice(list)
> list.remove(a)
> b = random.choice(list)
> list.remove(b)
> c = random.choice(list)
> list.remove(c)
> d = random.choice(list)
> list.remove(d)
> e = random.choice(list)
> list.remove(e)
> word = a + b + c + d + e
> print (word)
> print(list) 
 
Hmm, sounds like homework, but I'll bite.
 
How about...
 
import random, string
indices = range(26)
random.shuffle(indices)
word = "".join([string.ascii_lowercase[i] for i in indices[:5]])
print word
 
Cheers,
 
Drea
 
 
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-01-29 Thread Bruno Desthuilliers

MC a écrit :

Hi!

Il se trouve que Chris Rebert a formulé :

Python has functions, which are not associated
with a class


functions are methods of builtin...


Please check your facts. Python functions are not "methods" of anything 
(and not even necessarily attributes of a module - think about nested 
functions...).


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


Re: is there a shorter way to write this

2009-01-29 Thread Tim Chase

Hmm, sounds like homework, but I'll bite.


The underlying problem does sound like homework, but the OP 
posted a working solution, and was only looking for ways to 
improve it.  So I'm a little more lenient on providing 
alternatives.  It's true that the homework problem may have been 
exactly as posted ("Improve this code"), but that's less likely 
in my estimation.


-tkc




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


py2exe + SQLite problem

2009-01-29 Thread Armin



Hello all,

I have frozen a running application which is using SQLite with py2exe.

When I start the exe file I see in the log file of the exe:

Traceback (most recent call last):
  File "dpconf.py", line 666, in ?
  File "dpconf.py", line 251, in __init__
  File "sqlite\main.pyc", line 255, in execute
_sqlite.DatabaseError: no such table: genslaveopt

The table exist in the database file ... no problem with the plain 
python version.


How can I solve that problem ??

Best Regards

--Armin


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


py2exe + SQLite problem

2009-01-29 Thread Armin



Hello all,

I have frozen a running application which is using SQLite with py2exe.

When I start the exe file I see in the log file of the exe:

Traceback (most recent call last):
  File "dpconf.py", line 666, in ?
  File "dpconf.py", line 251, in __init__
  File "sqlite\main.pyc", line 255, in execute
_sqlite.DatabaseError: no such table: genslaveopt

The table exist in the database file ... no problem with the plain 
python version.


How can I solve that problem ??

Best Regards

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


Get thread pid

2009-01-29 Thread Alejandro
Hi:

I have Python program running under Linux, that create several
threads, and I want to now the corresponding PID of the threads.

In each of the threads I have

def run(self):
pid = os.getpid()
logger.critical('process ID: %s', pid)

However, the reported PID is the father number, not the PID of the new
thread. Is there a way to get the PID of the thread?

To illustrate this further, this is the output of pstree when the PID
of the main Python thread is 9197:

$pstree -p 9197
python(9197)─┬─{python}(9555)
 ├─{python}(9556)
 ├─{python}(9557)
 ├─{python}(9558)
 ├─{python}(9559)
 ├─{python}(9560)
 ├─{python}(9561)
 ├─{python}(9562)
 ├─{python}(9563)
 └─{python}(9564

I want each thread to report its PID number, in this case 9555, 9556,
etc., but with os.getpid() is get 9197.

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


UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2009-01-29 Thread Anjanesh Lekshminarayanan
Im reading a file. But there seems to be some encoding error.

>>> f = open(filename)
>>> data = f.read()
Traceback (most recent call last):
  File "", line 1, in 
data = f.read()
  File "C:\Python30\lib\io.py", line 1724, in read
decoder.decode(self.buffer.read(), final=True))
  File "C:\Python30\lib\io.py", line 1295, in decode
output = self.decoder.decode(input, final=final)
  File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position
10442: character maps to 

The string at position 10442 is something like this :
"query":"0 1»Ý \u2021 0\u201a0 \u2021»Ý","

So what encoding value am I supposed to give ? I tried f =
open(filename, encoding="cp1252") but still same error. I guess
Python3 auto-detects it as cp1252
-- 
Anjanesh Lekshmnarayanan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic methods and lambda functions

2009-01-29 Thread [email protected]
On Jan 28, 11:32 pm, "Gabriel Genellina" 
wrote:
> En Wed, 28 Jan 2009 16:05:39 -0200, [email protected]  
>  escribió:
>
> >   I had the same problem myself.
> >   Mark's detailed explanation really helped me understand.
>
> >   I ended up doing something like:
>
> The code doesn't work as-is, could you please post a working version? Just  
> for the record, so people reading this thread later don't get confused.
>
> --
> Gabriel Genellina

Sure! This works for me:

class A:
  def __init__(self):
names = 'n1', 'n2'
for n in names:
  setattr(self, "get%s" % n, self._createGetter(n))

  def _createGetter(self, n):
def f(): return n
return f

if __name__ == "__main__":
a=A()
print a.getn1()
print a.getn2()
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get atexit hooks to run in the presence of execv?

2009-01-29 Thread R. Bernstein
Mark Wooding  writes:

> [email protected] (R. Bernstein) writes:
>
>> Recently, I added remote debugging via TCP sockets. (Well, also FIFO's
>> as well but closing sockets before restarting is what's of concern.)
>>
>> I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get
>> called. Should it?
>
> I'd consider that to be highly unusual.  Certainly, the C atexit(3)
> function is called only in response to a call to exit(3) (possibly
> implicitly by returning from main), and not by execve(2) or any of its
> little friends.
>
> Your specific problem is to do with file descriptors, so it's probably
> best dealt with using the close-on-exec flag:
>
> from fcntl import fcntl, F_GETFD, F_SETFD, F_CLOEXEC
>
> sk = socket(...)
> ## ...
> fcntl(sk.fileno(), F_SETFD,
>   fcntl(sk.fileno(), F_GETFD) | FD_CLOEXEC)
>
> Now the socket will be magically closed when you exec.. another program.

Thanks for the wealth of information. Alas, somehow I think this begs
the question. I *know* how to arrange in the debugger for it to clean
up after itself. But it's the program being debugged which I have no
control over. And I would like to give it an opportunity to clean up
after itself. 

>
> Finally, can I urge against TCP sockets in an application like this?

By all means, I hope people will offer thoughts, concerns and ideas. 

> Certainly without adequate authentication, it will simply be insecure
> even within a single multiuser host (e.g., using localhost only) -- and
> assuming that even a home machine has only a single user is becoming
> less realistic.  Unix-domain sockets live in the filesystem, and access
> to them is limited using the standard filesystem mechanisms.
>
> If you're expecting inter-host communications (e.g., remote debugging),
> it's a good idea to protect the session using TLS or something (much as
> I dislike the TLS certification/public-key- distribution model it's way
> better than nothing at all).

Well, I also started coding FIFO's as well as TCP sockets, partly
because I could, and partly to try to try to keep the interface
generic. And in the back of my mind, I'd like to add serial devices as
well - I don't see a reason not to.

Initially, I probably won't add authentication or encryption. I'm
having enough of a time trying to get this much working. (cpickling
over sockets seems to still require knowing how many messages were
sent and unpickling each of those, and TCP_NODELAY isn't allowed and
doesn't seem the right thing either.)

However what I really would like to see is authentication and
encription added as an independent plugin layer much as I view whether
one is debugging locally or not. So I don't see this as an issue per
se with TCP sockets.

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


Weird invisible arguments issues with Windows

2009-01-29 Thread Uberman
I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit.

First off, it didn't register the extension for .PY (although it did register
.PYC).

After manually associating the .PY extension with the python.exe executable, I
am now getting some weirdness on the command line.  When I run the following
script, saved as "build.py", by simply entering "build.py -r -d" on the
command line, it produces the output "1":

import sys
if __name__ == "__main__":
print len(sys.argv)

It doesn't see the additional arguments for some reason.  However, if I
execute the script by prefixing it (i.e., "python build.py -r -d"), I get an
output of "3", meaning it sees the additional arguments.

Has anybody else run into this issue?  And perhaps (hopefully) solved it?
--
http://mail.python.org/mailman/listinfo/python-list


persistent TCP connection in python using socketserver

2009-01-29 Thread markobrien85
G'day

I'm currently using socketserver to build a simple XMLSocket (an XML
based protocol used for communication between flash and the outside
world) server. I've got flash establishing a connection, sending a
request and my python server responding. However at this point
socketserver terminates the connection. Which is bad, since i need a
persistent connection so i can push data from the server to the client
without the overhead of polling.

I need to create TCP connection that persists until I explicitly tell
it to terminate, or the connection is terminated on the other end. A
quick look through the socketserver code makes this seem impossible
since it appears to call close after the handle() method.

Is there an even lower level library to be using, or is there some
option I haven't found yet in socketserver.

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


py2exe + data_files

2009-01-29 Thread Armin


Hello,

is there a way to place individual data files into to the standard 
'dist'  directory and not into a subdirectory of 'dist'


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


How does one view the source of function defined in the interpreter?

2009-01-29 Thread mattc
1) It appears that it is possible to view the source of a function
defined in the interpreter; however, I seem to be unable to do it.
Here is the code and resulting error.

>>> def f():
print("hello world")

>>> f

>>> f()
hello world
>>> import inspect
>>> inspect

>>> inspect.getsourcelines(f)
Traceback (most recent call last):
  File "", line 1, in 
inspect.getsourcelines(f)
  File "C:\Python30\lib\inspect.py", line 678, in getsourcelines
lines, lnum = findsource(object)
  File "C:\Python30\lib\inspect.py", line 526, in findsource
raise IOError('could not get source code')
IOError: could not get source code

2) Also, is there a method to inspect f in the form "f.inspect" or
"f.getsource" or "f.dump"?

3) One last thing, is there any documentation for augmenting,
extending, or editing a function in the interpreter once it is
defined?

Yes, I'm new.  Yes, I've spent the obligatory hours searching the web
and use groups. Yes, I'd love to code in Python. Please help. Thank
you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2009-01-29 Thread Benjamin Kaplan
On Thu, Jan 29, 2009 at 11:24 AM, Anjanesh Lekshminarayanan <
[email protected]> wrote:

> Im reading a file. But there seems to be some encoding error.
>
> >>> f = open(filename)
> >>> data = f.read()
> Traceback (most recent call last):
>  File "", line 1, in 
>data = f.read()
>  File "C:\Python30\lib\io.py", line 1724, in read
>decoder.decode(self.buffer.read(), final=True))
>  File "C:\Python30\lib\io.py", line 1295, in decode
>output = self.decoder.decode(input, final=final)
>  File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode
>return codecs.charmap_decode(input,self.errors,decoding_table)[0]
> UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position
> 10442: character maps to 
>
> The string at position 10442 is something like this :
> "query":"0 1Ȉ \u2021 0\u201a0 \u2021Ȉ ","
>
> So what encoding value am I supposed to give ? I tried f =
> open(filename, encoding="cp1252") but still same error. I guess
> Python3 auto-detects it as cp1252


It does auto-detect it as cp1252- look at the files in the traceback and
you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong
encoding, try opening it as utf-8 or latin1 and see if that fixes it.


> --
> Anjanesh Lekshmnarayanan
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter w.pack()?

2009-01-29 Thread W. eWatson

Gabriel Genellina wrote:
En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson  
escribió:



The word pack doesn't exist on the NMT pdf. Maybe there's a newer one?


There is a PDF version of "An Introduction to Tkinter" here:
http://www.pythonware.com/library/

Thanks. I have it but it's an odd one to search on "pack(". There may be 
over 100 reference to pack(. It's probably explained there somewhere, but 
how many times do I want to press the search key? I have it printed out too. 
I guess I need to eyeball it. It's probably faster. Maybe find the section 
(geometry?) where it and others like it are found. There is an index, but 
it's a pitiful one page.


Found in Chapter 34.

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


distutil problem ??

2009-01-29 Thread Armin


Hello,

I have the following setup script for py2exe:

from distutils.core import setup
import py2exe

setup(windows=['dpconf.py'],
data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]]
)

When I create the distribution I got the following err msg:

*** copy data files ***
warning: install_data: setup script did not provide a directory for '' 
-- installing right in 'C:\pyDPCONF.2.3-dev\dist'

error: can't copy '': doesn't exist or not a regular file

Looks a little bit inconsistent ?

--Armin

PS: "." makes also problems
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter w.pack()?

2009-01-29 Thread W. eWatson

r wrote:

On Jan 28, 10:57 pm, "W. eWatson"  wrote:

The word pack doesn't exist on the NMT pdf. Maybe there's a newer one?


Only the grid manager is discussed at NMT. I just like how at NMT the
widget attributes are in a table and then a list the widget methods
follows below that -- much better navigation.

I talked again to John at NMT and he assured me very soon he's going
to make all the updates. It would probably help if you sent him a nice
message of encouragement like -- 'Can you please update the
documentation, i really like the sites layout?' -- but please don't
forget to thank him for all his contributions to the Python community.

I am currently crusading to have all the old Python tuts and
documentation updated(among other crusades). This was my second win
and i hope that more will follow. The python docs out there need a
dusting off and spit shining.

I fully agree with your assessment of their state.

I might not want him to update the NMT. :-) Why would that be. I just had it 
printed. Another $8! I'm kidding, of course.


Not only is it a good layout, I think it's the best layout out there, IMHO. 
I'll contact him. I think one of his other pdf files needs updating too. 
Possibly the one for PIL.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: Weird invisible arguments issues with Windows

2009-01-29 Thread Tim Golden

Uberman wrote:

I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit.

First off, it didn't register the extension for .PY (although it did register
.PYC).

After manually associating the .PY extension with the python.exe executable, I
am now getting some weirdness on the command line.  When I run the following
script, saved as "build.py", by simply entering "build.py -r -d" on the
command line, it produces the output "1":

import sys
if __name__ == "__main__":
print len(sys.argv)

It doesn't see the additional arguments for some reason.  However, if I
execute the script by prefixing it (i.e., "python build.py -r -d"), I get an
output of "3", meaning it sees the additional arguments.

Has anybody else run into this issue?  And perhaps (hopefully) solved it?



What does your association look like? Try ftype; should be something
like this:

H:\>ftype python.file
python.file="C:\Python26\python.exe" "%1" %*

Notice the stuff at the end

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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2009-01-29 Thread Anjanesh Lekshminarayanan
> It does auto-detect it as cp1252- look at the files in the traceback and
> you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong
> encoding, try opening it as utf-8 or latin1 and see if that fixes it.

Thanks a lot ! utf-8 and latin1 were accepted !
--
http://mail.python.org/mailman/listinfo/python-list


Re: Weird invisible arguments issues with Windows

2009-01-29 Thread MRAB

Uberman wrote:

I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit.

First off, it didn't register the extension for .PY (although it did register
.PYC).

After manually associating the .PY extension with the python.exe executable, I
am now getting some weirdness on the command line.  When I run the following
script, saved as "build.py", by simply entering "build.py -r -d" on the
command line, it produces the output "1":

import sys
if __name__ == "__main__":
print len(sys.argv)

It doesn't see the additional arguments for some reason.  However, if I
execute the script by prefixing it (i.e., "python build.py -r -d"), I get an
output of "3", meaning it sees the additional arguments.

Has anybody else run into this issue?  And perhaps (hopefully) solved it?


You might want to check that:

assoc .py

displays:

.py=Python.File

and:

ftype Python.File

displays:

Python.File="C:\Python26\python.exe" "%1" %*

(or something similar).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Weird invisible arguments issues with Windows

2009-01-29 Thread Chris Hulan
On Jan 29, 11:35 am, Uberman  wrote:
> I've installed Python 2.6.1 (AMD64) under Windows Vista Ultimate 64-bit.
>
> First off, it didn't register the extension for .PY (although it did register
> .PYC).
>
> After manually associating the .PY extension with the python.exe executable, I
> am now getting some weirdness on the command line.  When I run the following
> script, saved as "build.py", by simply entering "build.py -r -d" on the
> command line, it produces the output "1":
>
>     import sys
>     if __name__ == "__main__":
>         print len(sys.argv)
>
> It doesn't see the additional arguments for some reason.  However, if I
> execute the script by prefixing it (i.e., "python build.py -r -d"), I get an
> output of "3", meaning it sees the additional arguments.
>
> Has anybody else run into this issue?  And perhaps (hopefully) solved it?

Have seen this in some installs on XP. Indicates the registry entry
that specfies how to
invoke python on a *.py file is not correctly set to pass along the
command line arguments

on my XP system, in the registry under HKEY_CLASSES_ROOT\Applications
\python.exe\shell\open\command
has:
Name (Default)
Type REG_SZ
Data C:\Python23\python.exe "%1" %*

If that '%*' is missing, thats the problem

Cheers
Chris



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


Re: is python Object oriented??

2009-01-29 Thread Michael Torrie
M Kumar wrote:
> but still I am not clear of the execution of the code, when we write or
> execute a piece of python code without defining class, predefined class
> attributes are available (not all but __name__ and __doc__ are available).
> does it mean anything to this topic. Is it necessory to have __module__,
> __dict__ and __bases__ for a class object in python?

I think you're confused as to what object-oriented means.  OO defines
the internals of a language more than a particular programming paradigm.
 Obviously python lets you program in a variety of paradigms, including
procedural and event-driven, but it is all very much object-oriented.
So ignore those that say python doesn't force you to use OOP, when in
fact it's unavoidable.  It's just that you're not forced to place all
your code in class definitions.  You don't need to because your code is
already object-oriented in that you're manipulating objects and their
attributes.

As others have said, Python is an object-oriented language through and
through, closer to Smalltalk in many ways, the grand-daddy of all OO
languages.

It appears that you are only really familiar with Java, and that leads
to a number of interesting misconceptions about OO.  Java's bizarre OO
requires everything to be in a class, which leads many people to believe
this is what OO should be.  In fact Java is a bit odd when it comes to
OO, as there are many things in Java that aren't in fact objects.  For
example, primitives are intrinsic types and are not objects.
Furthermore class definitions are not objects either, at least from the
programmer's pov.  You can't manipulate them by standard means as you
can in Smalltalk and Python.  In Smalltalk and Python a "class" is an
object just as much as an instance of a class is an object which has a
constructor factory method that returns instance objects.  Java also has
very strange ways of doing singleton patterns.  You have to wrap
singletons in class and define them as "static."  I think this was
inherited from C++.

The most basic object in a python script is the module object which
represents the namespace of the current script.  In effect a module
object is a singleton.  It has a few attributes, and you can use it to
look up any of the objects it contains, such as functions, objects
(so-called variables), classes, etc.  Everything in python is an object.
 The statement:

a = 4

defines an integer object "4" and binds a name to it, 'a.'  You can even
check to see what methods the object supports by doing:

>>> dir(4)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
'__floordiv__', '__getattribute__', '__getnewargs__', '__hash__',
'__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__',
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__',
'__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__',
'__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__',
'__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__',
'__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__',
'__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__']

dir(a) would return the same thing.  As you can see, all the operators
that can be performed with a number object are defined.  This little
exercise alone should show you how much more object-oriented Python is
than Java.

Python's OO capabilities are really exposed when you start extending
built-in types, or doing meta programming where you dynamically alter
classes (and instance objects) on the fly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2009-01-29 Thread Benjamin Kaplan
On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan <
[email protected]> wrote:

> > It does auto-detect it as cp1252- look at the files in the traceback and
> > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong
> > encoding, try opening it as utf-8 or latin1 and see if that fixes it.
>
> Thanks a lot ! utf-8 and latin1 were accepted !
> --
>

If you want to read the file as text, find out which encoding it actually
is. In one of those encodings, you'll probably see some nonsense characters.
If you are just looking at the file as a sequence of bytes, open the file in
binary mode rather than text. That way, you'll avoid this issue all together
(just make sure you use byte strings instead of unicode strings).
--
http://mail.python.org/mailman/listinfo/python-list


CUDA

2009-01-29 Thread dg . google . groups
Hi all,

Has anyone managed to get any of the Python CUDA libraries working on
Windows using cygwin? Which one, and was anything special required?

Thanks in advance for any advice.

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


Re: Spam making a comeback??

2009-01-29 Thread skip

r> Seems like the level of spam is increasing in the last week, and
r> today has been bad. How are the spambytes coming along?

Spambayes is doing fine, but it only filters spam for the mailing list.  It
has no effect on the Usenet side of things (comp.lang.python).

-- 
Skip Montanaro - [email protected] - http://smontanaro.dyndns.org/
--
http://mail.python.org/mailman/listinfo/python-list


slicings: 3 questions

2009-01-29 Thread Alan G Isaac

1. I seem not to understand something obvious at
http://docs.python.org/3.0/reference/expressions.html#slicings
(I assume I'm just not reading this right.)
What is an example of a slicing using a "slice_list"?

2. It seems that slice objects and range objects are
awfully similar in many ways.  Is this "appearance only",
or was there any discussion of unifying them?
Curious for insight...

3. Why are slicings not directly listed among the built-in types?
(I know they are discussed here: 
http://docs.python.org/3.0/reference/datamodel.html#types).
What makes them "internal"?
http://docs.python.org/3.0/library/stdtypes.html#internal-objects

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-29 Thread J Kenneth King
excord80  writes:

> I need to make a small, relatively low-traffic site that users can
> create accounts on and log into. Scripts must run as cgi (no
> mod_python or FastCGI is available). Can anyone recommend a small and
> simple web framework for Python, maybe similar to Perl's
> CGI::Application?
>
> Or would it just be better to roll my own?

web.py

pretty simple. lots of deployment options.

ends up building into your own framework as your application grows.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter w.pack()?

2009-01-29 Thread Gabriel Genellina
En Thu, 29 Jan 2009 14:55:13 -0200, W. eWatson   
escribió:

Gabriel Genellina wrote:
En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson  
 escribió:



The word pack doesn't exist on the NMT pdf. Maybe there's a newer one?

 There is a PDF version of "An Introduction to Tkinter" here:
http://www.pythonware.com/library/

Thanks. I have it but it's an odd one to search on "pack(". There may be  
over 100 reference to pack(. It's probably explained there somewhere,  
but how many times do I want to press the search key? I have it printed  
out too. I guess I need to eyeball it. It's probably faster. Maybe find  
the section (geometry?) where it and others like it are found. There is  
an index, but it's a pitiful one page.


Uh? The very first occurence of "pack" is in the Table of Contents, "The  
pack geometry manager". (You may want to improve your search skills :) )


--
Gabriel Genellina

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


Re: slicings: 3 questions

2009-01-29 Thread Chris Rebert
On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac  wrote:
> 1. I seem not to understand something obvious at
> http://docs.python.org/3.0/reference/expressions.html#slicings
> (I assume I'm just not reading this right.)
> What is an example of a slicing using a "slice_list"?

There's nothing in the stdlib that uses it IIRC, but for instance a
matrix package could allow you to do:

a = Matrix(12,12,12) #make a 3D cubic matrix of all 0s
print( a[4,2,6] ) #get an item from the matrix using slice_list syntax
print( a[4][2][6] ) #another way to get the same item

> 2. It seems that slice objects and range objects are
> awfully similar in many ways.  Is this "appearance only",
> or was there any discussion of unifying them?
> Curious for insight...

Wouldn't really be possible, IMHO. True, they both have notions of
start, stop, and step, but slices don't make sense as ranges without
knowing the length of the container. For example, take the slice
`1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However,
since  -2 < 1 (stop < start ) and 1 (the step) is positive, the range
is nonsensical.
You have to replace all the negative indices with calculated positive
indices first in order to have a sensical range(), in this case,
replacing the stop of -2 with len(container)-2.
Also, more fundamentally, Python is liberal in what it allows for the
parts of slices, so unifying slices with ranges would break code. For
example, Python is perfectly happy if I go slice("a",[8],object), none
of which are even numbers.

> 3. Why are slicings not directly listed among the built-in types?
> (I know they are discussed here:
> http://docs.python.org/3.0/reference/datamodel.html#types).
> What makes them "internal"?
> http://docs.python.org/3.0/library/stdtypes.html#internal-objects

Because they're generally only useful in the context of slicing lists
and other containers, and not as a datatype in and of themselves.
Also, the syntax sugar of a[b:c:d] means that you can practically
disregard the existence of slice() objects and just think that there's
special list-slicing syntax, with very little downside.

Cheers,
Chris

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


Re: persistent TCP connection in python using socketserver

2009-01-29 Thread Jean-Paul Calderone

On Thu, 29 Jan 2009 08:38:43 -0800 (PST), [email protected] wrote:

G'day

I'm currently using socketserver to build a simple XMLSocket (an XML
based protocol used for communication between flash and the outside
world) server. I've got flash establishing a connection, sending a
request and my python server responding. However at this point
socketserver terminates the connection. Which is bad, since i need a
persistent connection so i can push data from the server to the client
without the overhead of polling.


If you don't want the connection to close, then don't let the request
complete.  SocketServer implements logic for single request/response
per connection.  You can change this by making your requests take a
really long time (until you're done with the connection) or you can
override the behavior which closes the connection after a response.

Or you could use the socket module, on which the SocketServer module is
based.  Or you could use Twisted, another higher-level package built on
the socket module (mostly).  Actually, I recommend Twisted, since it will
mostly isolate you from boring low-level details and let you implement
whatever high-level behavior you're after (I know that a bunch of people
have used it to communicate with Flash, for example).

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


Re: is python Object oriented??

2009-01-29 Thread Terry Reedy

M Kumar wrote:
Object oriented languages doesn't allow execution of  the code without 
class objects, what is actually happening when we execute  some piece of 
code, is it bound to any class?

Those who have time and consideration can help me


My take..

Python is a language.  Programs written in Python create and manipulate 
information objects.  (But programs are not objects themselves.) So, 
Python is a language for describing object-based information processing.


Every Python object is an instance of some class.  Every class, being an 
object itself, is an instance of some metaclass.  (The 'type' metaclass 
is an instance of itself.)  Every class (in Py3) is also a subclasses of 
the base class 'object'.


I think 'object-orient language' is a somewhat misleading abbreviation 
since 'object-orientedness' is a potential property of the an abstract 
computation system a language works, with rather than a property of a 
language itself.


Terry Jan Reedy

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


Re: How does one view the source of function defined in the interpreter?

2009-01-29 Thread Terry Reedy

mattc wrote:
Once the interpreter reads lines of code, then, as far as the 
interpreter is concerned, they are gone.



3) One last thing, is there any documentation for augmenting,
extending, or editing a function in the interpreter once it is
defined?


Use IDLE, edit code in an edit window, then run.
I generally use the interpreter or IDLE shell window only for 
single-line commands.


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


Re: is python Object oriented??

2009-01-29 Thread Kay Schluehr
On 29 Jan., 11:21, Gary Herron  wrote:

> Python *is* object-oriented, but it is not (as your definition suggests)
> object-fascist.  

I'd put it more mildly. Python is object oriented. The orientation is
there but the fanatism is gone.

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


ImportError in embedded Python Interpreter

2009-01-29 Thread googler . 1 . webmaster
Hi,

i have a problem. I compiled Python and the socket module so I got
this structure. (all on windows)

C:\test\dll_files\python25.dll
C:\test\my_app
C:\test\dll_files\DLLs\
C:\test\dll_files\python.exe

If I run python I get the console and I can call "import socket" which
succeeds. I wrote a small console app which is stored in C:\test\ and
embeddeds the python interpreter. I set the environment variable PATH
so the python DLL files can be load.

But when I want to import in a script the socket module, it fails.
(The interpreter works fine, just importing files in the DLLs folder
fail). Why? When I print out the sys.path I get the same like in the
real python.exe.

What do you think, whats missing?


Thanks a lot. bye :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Spam making a comeback??

2009-01-29 Thread Terry Reedy

[email protected] wrote:

r> Seems like the level of spam is increasing in the last week, and
r> today has been bad. How are the spambytes coming along?

Spambayes is doing fine, but it only filters spam for the mailing list.  It
has no effect on the Usenet side of things (comp.lang.python).


It does, however, affect the gmane.comp.lang.python newsgroup, which is 
very clean now. Thank you.  (And items posted through gmane are 
apparently sent to the mailing list first, and filtered, before being 
added to the mirror.)


tjr


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


ImportError in embedded Python Interpreter

2009-01-29 Thread googler . 1 . webmaster
Hi,

i have a problem. I compiled Python and the socket module so I got
this structure. (all on windows)

C:\test\dll_files\python25.dll
C:\test\my_app
C:\test\dll_files\DLLs\
C:\test\dll_files\python.exe

If I run python.exe I get the console and I can call "import socket"
which
succeeds. I wrote a small console app which is stored in C:\test\ and
embeddeds the python interpreter. I set the environment variable PATH
so the python25.dll can be load.

But when I want to import the socket module in a script, it fails.
(The interpreter works fine, just importing files in the DLLs folder
fail). Why? When I print out the sys.path in my app I get the same
like in the
real python.exe.

What do you think, whats missing?

Thanks a lot. bye :)
--
http://mail.python.org/mailman/listinfo/python-list


receive and react to MIDI input

2009-01-29 Thread elsjaako
Hi all. I want to write an application that reads midi notes and then
does something (specifically, play sound files, but that doesn't
really matter for this question). I'm on windows.

I went on MSDN and tried to get it to work, and I found myself getting
pretty far (considering how little I know about all this), but I
finally got stuck.

I get en error referring to a Null pointer.

What I tried to do is make it run MidiSigReceived every time a signal
is received. I will add the processing as soon as I got this step
working. I do not have my keyboard plugged in, so my computer should
not receive signals. MidiSigReceived is run once though, and only
after that does the error occur.




What I think the problem is is that midiInID has to be of type
HMIDIIN. Somewhere in the relevant .h file, I found:
DECLARE_HANDLE(HMIDIIN);

DECLARE_HANDLE I couldn't find in the headers, so I looked on the
Internet and found:

#ifdef STRICT
typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef
struct name##__ *name
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif


I think this means that the following could be said:

typedef void *HANDLE;
struct HMIDIIN##__ { int unused; }; typedef struct HMIDIIN##__
*HMIDIIN;

but what exactly that means is I think beyond my C abilities. It seems
that a HMIDIIN is a pointer to a structure with one element: unnamed.
My attempts to figure it out didn't change the error at all. I find it
even more confusing considering midiInOpen requires a pointer to such
an object.


The relevant MSDN page:
http://msdn.microsoft.com/en-us/library/ms709430(VS.85).aspx



This is what I have:

#imports

from ctypes import *
from ctypes.wintypes import *

winmm = windll.LoadLibrary("winmm")

#structures and such
MAXPNAMELEN = 32
MMVERSION = UINT
CALLBACK_FUNCTION = 196608 # hex 3
class MIDIOUTCAPS (Structure):
_fields_ = [("wMid",WORD),
("wPid",WORD),
("vDriverVersion",MMVERSION),
("szPname",WCHAR * MAXPNAMELEN),
("dwSupport",DWORD)]

# The next part defines the callback function
CMPFUNC = CFUNCTYPE(None, c_long, UINT, DWORD, DWORD, DWORD)

def MidiSigReceived(a,b,c,d,e):
print a,b,c,d,e

midi_get = CMPFUNC(MidiSigReceived)


midiInID = c_long() #The ID of the Midi connection, so we can close it
again

winmm.midiInOpen(byref(midiInID), # reference to the connection ID
 0, # Midi device to use
 midi_get, # callback function
 0, # instance data
 CALLBACK_FUNCTION) # Callback flag, makes it use the
callback, change it to 0 to remove error

# Close the connection
winmm.midiInClose(midiInID)

Or, as far as I could understand, you could use the HMIDIIN thing:

class MIDIHANDLESTRUCT (Structure):
_fields_ = [("unused",c_long)]

HMIDIIN = POINTER(MIDIHANDLESTRUCT)
midiInID = HMIDIIN()

If anyone could help, I would greatly appreciate it.

Bart de Waal
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sloooooowwwww WSGI restart

2009-01-29 Thread Aleksandar Radulovic
Graham,

On Thu, Jan 29, 2009 at 1:00 PM, Graham Dumpleton
 wrote:

> In other words, it is not universal that any code change will be
> automatically detected and a reload occur. There are also various
> caveats on what mod_python module importer does, as it is reloading
> modules into an existing process and not restarting the whole.
> If you are not careful, weird things can happen.

Considering I'm not changing any of the modules (ie. working only on the
source tree in the project itself which is published by mod_python.publisher)
I haven't seen the need to restart Apache.

There are caveats, of course - but in day-to-day work, I haven't noticed
any difficulties and need to fully restart Apache.

> It was a general statement. There are various people on different
> forums and irc channels who keep saying that a full Apache restart is
> required with Apache/mod_wsgi when making code changes. Am just
> stating for the record that that isn't true.

We agree here. Someone posted a link earlier explaining the settings of
mod_wsgi (maybe it was you) where it's easy to configure it to detect
code changes and reload the code. Hence my questions from the begining
of the thread.

There are custom built code-reloading modules (and techniques) which can
also be used.

> So, depends on how closely you want your development environment to
> mirror production so that issues are picked up sooner, rather than
> only at the point of deployment to a production system when you are
> under pressure.

Ideally, you would want the environments to be as closely related (in terms
of setup) as possible. In my development, i try to keep the integration
environment a mirror of production, but (as mentioned) keep the local (dev)
environment as suitable to my needs as possible.

Continuous integration system would help in deploying the code to integration
for integration testing and final checks before hitting production (which is a
manual process).

Rushing things into production is never a good think(tm). All it needs is a bit
of careful planning, but I'm going way too off-topic here.

Regards,
alex.
-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2009-01-29 Thread Benjamin Peterson
Anjanesh Lekshminarayanan  anjanesh.net> writes:

> 
> > It does auto-detect it as cp1252- look at the files in the traceback and
> > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong
> > encoding, try opening it as utf-8 or latin1 and see if that fixes it.
> 
> Thanks a lot ! utf-8 and latin1 were accepted !

Just so you know, latin-1 can decode any sequence of bytes, so it will always
work even if that's not the "real" encoding.




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


Re: receive and react to MIDI input

2009-01-29 Thread r
On Jan 29, 1:33 pm, elsjaako  wrote:

There is a Python MIDI module, i think it is pyMIDI, have you checked
it out?
--
http://mail.python.org/mailman/listinfo/python-list


Re: slicings: 3 questions

2009-01-29 Thread Alan G Isaac

On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac  wrote:

1. I seem not to understand something obvious at
http://docs.python.org/3.0/reference/expressions.html#slicings
(I assume I'm just not reading this right.)
What is an example of a slicing using a "slice_list"?



On 1/29/2009 1:37 PM Chris Rebert apparently wrote:

There's nothing in the stdlib that uses it IIRC, but for instance a
matrix package could allow you to do:

a = Matrix(12,12,12) #make a 3D cubic matrix of all 0s
print( a[4,2,6] ) #get an item from the matrix using slice_list syntax
print( a[4][2][6] ) #another way to get the same item



Ah sure, I was misreading it.
It is just enabling NumPy style indexing.
I was assuming that it was describing a legitimate
way so slice sequences generally.

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


python 2.6 wininst problem

2009-01-29 Thread timw.google
I just installed Python2.6 on my WinXP box in a non-standard location
(not C:\Python26) since I'm not admin. I used cygwin to create a
module of an extension I wrote, but when I went to execute the
installer, I get a popup error

"This application has failed to start because the application
configuration is incorrect. Reinstalling the application my fix this
problem."

It turns out that the application installs my module on another
machine where python is installed in C:\Python26, but why not in my
installation?

I went and reinstalled python2.5 in a similar nonstandard location
(%USERPROFILE%\Python25) and rebuilt my extension module under that.
The module installer worked just fine, so it seems to be a 2.6 issue.

Do I now have to get the Helpdesk to install Python for me?

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


Re: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values

2009-01-29 Thread alex
Duncan
Thank you for your explanation of the relationship between calling
convention and stack management.
I will try to understand better this topic in the CVF and ctypes
documentation (not so easy).

Regards Alex

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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2009-01-29 Thread John Machin
Benjamin Kaplan  case.edu> writes:

> 
> 
> On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan 
anjanesh.net> wrote:
> > It does auto-detect it as cp1252- look at the files in the traceback and
> > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong
> > encoding, try opening it as utf-8 or latin1 and see if that fixes it.

Benjamin, "auto-detect" has strong connotations of the open() call (with mode
including text and encoding not specified) reading some/all of the file and
trying to guess what the encoding might be -- a futile pursuit and not what the
docs say: 

"""encoding is the name of the encoding used to decode or encode the file. This
should only be used in text mode. The default encoding is platform dependent,
but any encoding supported by Python can be passed. See the codecs module for
the list of supported encodings"""

On my machine [Windows XL SP3] sys.getdefaultencoding() returns 'utf-8'. It
would be interesting to know
(1) what is produced on Anjanesh's machine
(2) how the default encoding is derived (I would have thought I was a prime
candidate for 'cp1252')
(3) whether the 'default encoding' of open() is actually the same as the
'default encoding' of sys.getdefaultencoding() -- one would hope so but the docs
don't say so.

> Thanks a lot ! utf-8 and latin1 were accepted !

Benjamin and Anjanesh, Please understand that
any_random_rubbish.decode('latin1') will be "accepted". This is *not* useful
information to be greeted with thanks and exclamation marks. It is merely a
by-product of the fact that *any* single-byte character set like latin1 that
uses all 256 possible bytes can not fail, by definition; no character "maps to
".

> If you want to read the file as text, find out which encoding it actually is.
In one of those encodings, you'll probably see some nonsense characters. If you
are just looking at the file as a sequence of bytes, open the file in binary
mode rather than text. That way, you'll avoid this issue all together (just make
sure you use byte strings instead of unicode strings).

In fact, inspection of Anjanesh's report:
"""UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position
10442: character maps to  
The string at position 10442 is something like this :
"query":"0 1»Ý \u2021 0\u201a0 \u2021»Ý"," """ 

draws two observations:
(1) there is nothing in the reported string that can be unambiguously identified
as corresponding to "0x9d"
(2) it looks like a small snippet from a Python source file!

Anjanesh, Is it a .py file? If so, is there something like "# encoding: cp1252"
or "# encoding: utf-8" near the start of the file? *Please* tell us what
sys.getdefaultencoding() returns on your machine.

Instead of "something like", please report exactly what is there:

print(ascii(open('the_file', 'rb').read()[10442-20:10442+21]))

Cheers,
John

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


Re: python 2.6 wininst problem

2009-01-29 Thread Martin v. Löwis
> Do I now have to get the Helpdesk to install Python for me?

No, you should wait for Python 2.6.2; this should fix this problem.

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


Re: Weird invisible arguments issues with Windows

2009-01-29 Thread Uberman
Tim Golden wrote:
> What does your association look like? Try ftype; should be something
> like this:
> 
> H:\>ftype python.file
> python.file="C:\Python26\python.exe" "%1" %*


Then, Chris Hulan wrote:
> on my XP system, in the registry under HKEY_CLASSES_ROOT\Applications
> \python.exe\shell\open\command
> has:
> Name (Default)
> Type REG_SZ
> Data C:\Python23\python.exe "%1" %*
>
> If that '%*' is missing, thats the problem


Finally, MRAB scribed:
> You might want to check that:
>
> assoc .py
>
> displays:
>
> .py=Python.File
>
> and:
>
> ftype Python.File
>
> displays:
>
> Python.File="C:\Python26\python.exe" "%1" %*


Thank you for all the replies, guys. :)

You all seem to be pointing at the same thing, and on my system, I show:

C:\Users\Administrator>ftype python.file
python.file="D:\Python26\python.exe" "%1" %*

and

C:\Users\Administrator>assoc .py
.py=Python.File

Which all seems to be correct.  I'm guessing this doesn't bode well...
--
http://mail.python.org/mailman/listinfo/python-list


Re: slicings: 3 questions

2009-01-29 Thread Alan G Isaac

On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac  wrote:

2. It seems that slice objects and range objects are
awfully similar in many ways.  Is this "appearance only",
or was there any discussion of unifying them?
Curious for insight...



On 1/29/2009 1:37 PM Chris Rebert apparently wrote:

Wouldn't really be possible, IMHO. True, they both have notions of
start, stop, and step, but slices don't make sense as ranges without
knowing the length of the container.


Slices seem somewhat more general than ranges.



For example, take the slice
`1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However,
since  -2 < 1 (stop < start ) and 1 (the step) is positive, the range
is nonsensical.


Or rather, it makes sense, but is empty.
But I take your point.

However, I would turn it around slightly and ask:
when is it not the case that
range(*slice(start,stop,step).indices(stop)) != range(stop,start,step)

If there are no interesting cases, then it seems
that range might derive from slice.
Just curious...



You have to replace all the negative indices with calculated positive
indices first in order to have a sensical range(), in this case,
replacing the stop of -2 with len(container)-2.
Also, more fundamentally, Python is liberal in what it allows for the
parts of slices, so unifying slices with ranges would break code. For
example, Python is perfectly happy if I go slice("a",[8],object), none
of which are even numbers.


Ah, this is new in Python 3 I take it?
I was not aware of this.  Use case?

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


Re: ImportError in embedded Python Interpreter

2009-01-29 Thread googler . 1 . webmaster
Hi!

Okay, I checkede Py_Main(...) and called some python code there. There
it works too. So I know whats missing.

sys.environ.. returns nothing.
How can I set the paths with the Python C API?

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


Re: slicings: 3 questions

2009-01-29 Thread Robert Kern

On 2009-01-29 15:33, Alan G Isaac wrote:

On Thu, Jan 29, 2009 at 10:01 AM, Alan G Isaac 
wrote:

2. It seems that slice objects and range objects are
awfully similar in many ways. Is this "appearance only",
or was there any discussion of unifying them?
Curious for insight...



On 1/29/2009 1:37 PM Chris Rebert apparently wrote:

Wouldn't really be possible, IMHO. True, they both have notions of
start, stop, and step, but slices don't make sense as ranges without
knowing the length of the container.


Slices seem somewhat more general than ranges.



For example, take the slice
`1:-2:1`. This is somewhat equivalent to range(1, -2, 1). However,
since -2 < 1 (stop < start ) and 1 (the step) is positive, the range
is nonsensical.


Or rather, it makes sense, but is empty.
But I take your point.

However, I would turn it around slightly and ask:
when is it not the case that
range(*slice(start,stop,step).indices(stop)) != range(stop,start,step)

If there are no interesting cases, then it seems
that range might derive from slice.
Just curious...


It's possible that it *could*, but there's also no real benefit to doing so.


You have to replace all the negative indices with calculated positive
indices first in order to have a sensical range(), in this case,
replacing the stop of -2 with len(container)-2.
Also, more fundamentally, Python is liberal in what it allows for the
parts of slices, so unifying slices with ranges would break code. For
example, Python is perfectly happy if I go slice("a",[8],object), none
of which are even numbers.


Ah, this is new in Python 3 I take it?


No.

Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> slice("a",[8],object)
slice('a', [8], )


I was not aware of this. Use case?


It allows (ab)uses like numpy.mgrid:

>>> mgrid[0:10:11j]
array([  0.,   1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.])

--
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: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values

2009-01-29 Thread member thudfoo
On Thu, Jan 29, 2009 at 1:08 PM, alex  wrote:
> Duncan
> Thank you for your explanation of the relationship between calling
> convention and stack management.
> I will try to understand better this topic in the CVF and ctypes
> documentation (not so easy).
>
> Regards Alex
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

fwiw, ctypes has a mailing list:

https://lists.sourceforge.net/lists/listinfo/ctypes-users
--
http://mail.python.org/mailman/listinfo/python-list


Re: receive and react to MIDI input

2009-01-29 Thread elsjaako
On Jan 29, 9:36 pm, r  wrote:
> On Jan 29, 1:33 pm, elsjaako  wrote:
>
> There is a Python MIDI module, i think it is pyMIDI, have you checked
> it out?

Thank you for the responce. Unfortunately, that package is for OS X
(it doesn't say that clearly on the website). But it might indeed be
worthwhile to mention that I'd be more than happy to use a library, or
a finished product (I asked for that elsewhere, nobody had any good
ideas)

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


Re: Why doesn't eval of generator expression work with locals?

2009-01-29 Thread Gabriel Genellina
En Thu, 29 Jan 2009 05:14:41 -0200, Hendrik van Rooyen  
 escribió:

"Gabriel Genellina"  wrote:
En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels



(I *think* this has to do with free variables in the "right side" (after
the "in" keyword) of a generator expression; they appear to be evaluated
when the expression is *defined*, not when is is *used*. By contrast,  
free
variables in the "left side" appear to be evaluated when the expression  
is

used.)



Yikes! this is, IMO, far too complicated a way of looking at it.


Sure? "Make everything as simple as possible, but not simpler." (att. A.  
Einstein). I cannot find a simpler way to explain it that is still true...



I think that if you rewrite the "comprehensions" as loops,
you will see what is happening. - in the one case, the locals()
returned is from the outer scope, while in the other the
locals function is called from inside the loop - a different scope,
because there must be *somewhere* where the state is kept to yield
the next value.


But a loop doesn't define a new scope (only "def" and "class" used to  
define one; now generator expressions do too). The new scope is not the  
issue, but the fact that the right and left parts of a gen.expr. are  
evaluated at different times. This wasn't obvious to me -- and still  
isn't. If you rewrite the generator expression as a generator function you  
don't get the same behaviour:


print "genexpr"
A = [1,2,3]
B = 1
g = (x+B for x in A)
A = [4,5,6]
B = 10
print list(g)
# output: [11,12,13]
# A is evaluated at the time g is *defined*
# B is evaluated at the time g is *iterated*

print "genfunc"
A = [1,2,3]
B = 1
def f():
  for x in A:
yield x+B
A = [4,5,6]
B = 10
g = f()
A = [7,8,9]
B = 100
print list(g)
# output: [107,108,109]
# A and B are evaluated at the time g is *iterated*

Of course this is clearly stated in the Language Reference "Variables used  
in the generator expression are evaluated lazily in a separate scope when  
the next() method is called for the generator object (in the same fashion  
as for normal generators). However, the in expression of the leftmost for  
clause is immediately evaluated in the current scope..." -- but this  
behaviour is still surprising and not obvious to me. ("not obvious" means  
that things could have been different, choosing this was a design  
decision).


As far as I can tell, this is the only case in Python where parts of the  
same expression are evaluated in different contexts at different times.



I find it very confusing because locals is always the same
function - but what it returns varies depending on where you
call it from. So if you want to pass it around, it's no good
passing the function - you have to pass the returned result,
*called from the scope of interest*.  Subtle stuff.


Yep, the fact that locals() returns a different thing depending on  
when/where you call it, was the initial clue to this issue.


--
Gabriel Genellina

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


parsing text from a file

2009-01-29 Thread Wes James
If I read a windows registry file with a line like this:

"{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program
Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted
Multicast|Edge=FALSE|"

with this code:

f=open('fwrules.reg2.txt')

for s in f:
  if s.find('LANDesk') <0:
print s,


LANDesk is not found.

Also this does not work:

for s in f:
  try:
i=s.index('L')
print s[i:i+7]
 except:
   pass

all it prints is "LAND"

how do I find LANDesk in a string like this.  is the "\\" messing things up?

thx,

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


Re: Why doesn't eval of generator expression work with locals?

2009-01-29 Thread Gabriel Genellina
En Wed, 28 Jan 2009 18:06:01 -0200, Peter Otten <[email protected]>  
escribió:

Gabriel Genellina wrote:


(I think this has to do with free variables in the "right side" (after
the "in" keyword) of a generator expression; they appear to be evaluated
when the expression is *defined*, not when is is *used*. By contrast,  
free
variables in the "left side" appear to be evaluated when the expression  
is

used.)


Indeed, the right side is evaluated in the enclosing namespace and then
passed as an argument to the genexpr:

 >>> dis.dis(compile("(x for y in z)", "nofile", "exec"))
  1   0 LOAD_CONST   0 ( at
0x2b22b2dcf828, file "nofile", line 1>)
  3 MAKE_FUNCTION0
  6 LOAD_NAME0 (z)
  9 GET_ITER
 10 CALL_FUNCTION1
 13 POP_TOP
 14 LOAD_CONST   1 (None)
 17 RETURN_VALUE


Yes, this is explained (in not so much detail) in the Language Reference.  
Now I *know* how it works, but still isn't *obvious* to me.


--
Gabriel Genellina

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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2009-01-29 Thread Benjamin Kaplan
On Thu, Jan 29, 2009 at 4:19 PM, John Machin  wrote:

> Benjamin Kaplan  case.edu> writes:
>
> >
> >
> > On Thu, Jan 29, 2009 at 12:09 PM, Anjanesh Lekshminarayanan 
> anjanesh.net> wrote:
> > > It does auto-detect it as cp1252- look at the files in the traceback
> and
> > > you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong
> > > encoding, try opening it as utf-8 or latin1 and see if that fixes it.
>
> Benjamin, "auto-detect" has strong connotations of the open() call (with
> mode
> including text and encoding not specified) reading some/all of the file and
> trying to guess what the encoding might be -- a futile pursuit and not what
> the
> docs say:
>
> """encoding is the name of the encoding used to decode or encode the file.
> This
> should only be used in text mode. The default encoding is platform
> dependent,
> but any encoding supported by Python can be passed. See the codecs module
> for
> the list of supported encodings"""
>
> On my machine [Windows XL SP3] sys.getdefaultencoding() returns 'utf-8'. It
> would be interesting to know
> (1) what is produced on Anjanesh's machine
> (2) how the default encoding is derived (I would have thought I was a prime
> candidate for 'cp1252')
> (3) whether the 'default encoding' of open() is actually the same as the
> 'default encoding' of sys.getdefaultencoding() -- one would hope so but the
> docs
> don't say so.


First of all, you're right that might be confusing. I was thinking of
auto-detect as in "check the platform and locale and guess what they usually
use". I wasn't thinking of it like the web browsers use it.

I think it uses locale.getpreferredencoding(). On my machine, I get
sys.getpreferredencoding() == 'utf-8' and locale.getdefaultencoding()==
'cp1252'. When I open a file without specifying the encoding, it's cp1252.


>
> > Thanks a lot ! utf-8 and latin1 were accepted !
>
> Benjamin and Anjanesh, Please understand that
> any_random_rubbish.decode('latin1') will be "accepted". This is *not*
> useful
> information to be greeted with thanks and exclamation marks. It is merely a
> by-product of the fact that *any* single-byte character set like latin1
> that
> uses all 256 possible bytes can not fail, by definition; no character "maps
> to
> ".


If you check my response to Anjanesh's comment, I mentioned that he should
either find out which encoding it is in particular or he should open the
file in binary mode. I suggested utf-8 and latin1 because those are the most
likely candidates for his file since cp1252 was already excluded. Looking at
a character map, 0x9d is a control character in latin1, so the page is
probably UTF-8 encoded. Thinking about it now, it could also be MacRoman but
that isn't as common as UTF-8.

>
> > If you want to read the file as text, find out which encoding it actually
> is.
> In one of those encodings, you'll probably see some nonsense characters. If
> you
> are just looking at the file as a sequence of bytes, open the file in
> binary
> mode rather than text. That way, you'll avoid this issue all together (just
> make
> sure you use byte strings instead of unicode strings).
>
> In fact, inspection of Anjanesh's report:
> """UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position
> 10442: character maps to 
> The string at position 10442 is something like this :
> "query":"0 1»Ý \u2021 0\u201a0 \u2021»Ý"," """
>
> draws two observations:
> (1) there is nothing in the reported string that can be unambiguously
> identified
> as corresponding to "0x9d"
> (2) it looks like a small snippet from a Python source file!
>
> Anjanesh, Is it a .py file? If so, is there something like "# encoding:
> cp1252"
> or "# encoding: utf-8" near the start of the file? *Please* tell us what
> sys.getdefaultencoding() returns on your machine.
>
> Instead of "something like", please report exactly what is there:
>
> print(ascii(open('the_file', 'rb').read()[10442-20:10442+21]))
>
> Cheers,
> John
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


verilog like class w/ bitslicing & int/long classtype

2009-01-29 Thread mark . seagoe
I'm trying to make a script environment with datatypes (or classes)
for accessing hardware registers.  At the top level, I would like the
ability to bitwise ops if bit slice brackets are used, but if no
brackets are used, I would like it to write/read the whole value.

For example, if I have something like:

>>> shadow_register = MyRegClass(0xAA)
>>> shadow_register
170
>>> shadow_register[7:4] = 3  # <== changes value to 0x3A
>>> shadow_register
58
>>> shadow_register = 0x89
>>> shadow_register
137
>>> shadow_register[4:1]
4

I have the bitslice part working.  But of course as expected, if I
type
>>> shadow_register
<__main__.boo object at 0x00A130D0>

I wanted to avoid having something like shadow_register.value just
because it's clumsier.  I read about the __new__() class for
overriding the classtype, like:

print 'foo'
class foo(object):
def __new__(*args): return 0

but if I stick in a __init__(self, val): method, then it chokes saying
val is a global name that's not defined.

Now I know that I have to live with the fact that I can't have
>>> shadow_register = 0x89
Because it will get reassigned from my class value to a newly
intialized memory location (int object).  But can I have it read the
value without the .value extension?  Is this even possible?  Maybe
there's a way to override the = operator?  (Go easy on me - I'm a
hardware guy).

Thx,
Mark



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


Re: is python Object oriented??

2009-01-29 Thread Ben Finney
MC  writes:

> Hi!
> 
> Il se trouve que Chris Rebert a formulé :
> > Python has functions, which are not associated with a class
> 
> functions are methods of builtin...

No, because ‘builtin’ is not a class.

-- 
 \  “The shortest distance between two points is under |
  `\  construction.” —Noelie Alito |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: parsing text from a file

2009-01-29 Thread Vlastimil Brom
2009/1/29 Wes James :
> If I read a windows registry file with a line like this:
>
...
>
> with this code:
>
> f=open('fwrules.reg2.txt')
>
> for s in f:
>  if s.find('LANDesk') <0:
>print s,
>
>
> LANDesk is not found.
>
> how do I find LANDesk in a string like this.  is the "\\" messing things up?
...
>
> thx,
>
> -wj
>
Hi,
 if s.find('LANDesk') <0:
is True for a line which doesn't contain "LANDesk"; if you want the
opposite, try
 if s.find('LANDesk') >-1:
hth
  vbr
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyAA for Python2.5

2009-01-29 Thread Rob Williscroft
Kottiyath wrote in news:d86a0c1d-e158-4aa1-a47f-e2149948bdc3
@p2g2000prf.googlegroups.com in comp.lang.python:

> On Jan 29, 1:51 am, Rob Williscroft  wrote:
>> Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8
>> @b38g2000prf.googlegroups.com in comp.lang.python:

>>
>> > I have mingw32-gcc in my path. If I try that too -it fails.
>>
>> > C:\Documents and Settings\Guest\pyAA>python setup.py install -c
>> > "mingw32-gcc"
>> > invalid command name 'mingw32-gcc'
>>
>> All the examples I found via google have the tool name as "mingw32"
>> so try:
>>
>>         python setup.py install -c mingw32

> Thank you Rob.
> The installation went ahead for some more time - but failed showing a
> lot of errors:
>>compile
> running build
> running build_py
> file pyAAc.py (for module pyAAc) not found
> file pyAAc.py (for module pyAAc) not found
> ...
> pyAAc.cpp:5887: error: `EVENT_OBJECT_HELPCHANGE' was not declared in
> this scope
> pyAAc.cpp:5888: error: `EVENT_OBJECT_DEFACTIONCHANGE' was not declared
> in this scope
> pyAAc.cpp:5889: error: `EVENT_OBJECT_ACCELERATORCHANGE' was not
> declared in this scope
> ...
> error: command 'gcc' failed with exit status 1
> 
> I cannot understand why it fails. I have not worked in C till now, so
> I am pretty confused.
> I googled also, but to no avail.
> 

Looks like the package needs some headers that haven't yet been 
ported to to MinGW.

Alas that meands you'll need to build with the Microsoft SDK 
and compiler.

You can get the SDK including a non-optimising compiler from:

http://www.microsoft.com/downloads/details.aspx?FamilyId=9B3A2CA6-3647-
4070-9F41-A333C6B9181D&displaylang=en

or maybe here:

http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-
4969-ACE8-E4C0C0716ADB&displaylang=en

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygccxml xml output file

2009-01-29 Thread Roman
On Jan 24, 3:25 pm, whatazor  wrote:
> Hi all,
> I start to use this module in order to produce xml( and the make other
> things), but differently from gccxml I don't find the variable that
> set the name of the xml output file after the parsing (in gccxml is -
> fxml), so it creates temporary files.
> how can I do an Is there a tutorial that explain with dectails how it
> works?

I suggest you to ask your questions on the following mailing list:
https://lists.sourceforge.net/lists/listinfo/pygccxml-development

As for your question: see
http://www.language-binding.net/pygccxml/apidocs/pygccxml.parser.project_reader-module.html#create_cached_source_fc
documentation.
and
http://www.language-binding.net/pygccxml/apidocs/pygccxml.parser.project_reader.project_reader_t-class.html#read_files

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


Can't understand what python wants from me

2009-01-29 Thread Oleksiy Khilkevich

Hello, everyone,
This may be a totally noob question, but since I am one, so here is it.

I have the following code (not something much of): 
http://paste.debian.net/27204
The current code runs well, but the problem is with input value: 
http://paste.debian.net/27205
Аs you can see, the numbers are ok, but strings and characters cause 
"not defined" error.


I've obviously missing something important, but tutorial says nothing 
about this.


Thank you for your help.



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


Re: Can't understand what python wants from me

2009-01-29 Thread Chris Rebert
On Thu, Jan 29, 2009 at 1:50 PM, Oleksiy Khilkevich
 wrote:
> Hello, everyone,
> This may be a totally noob question, but since I am one, so here is it.
>
> I have the following code (not something much of):
> http://paste.debian.net/27204
> The current code runs well, but the problem is with input value:
> http://paste.debian.net/27205
> Аs you can see, the numbers are ok, but strings and characters cause "not
> defined" error.
>
> I've obviously missing something important, but tutorial says nothing about
> this.

You're using input(). You should be using raw_input(), at least until
everyone switches to Python 3.0 (which confusingly renames raw_input()
to input() because of the exact newbie confusion you're encountering).
raw_input() reads a string from stdin. input() call raw_input() and
then eval()-s the string, hence 'asd' gets interpreted as a variable,
which doesn't exist in your program, hence the error.

For further information, use help() on input and raw_input from the
interactive interpreter REPL.

Cheers,
Chris

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


Re: Can't understand what python wants from me

2009-01-29 Thread Chris Hulan
On Jan 29, 4:50 pm, Oleksiy Khilkevich 
wrote:
> Hello, everyone,
> This may be a totally noob question, but since I am one, so here is it.
>
> I have the following code (not something much 
> of):http://paste.debian.net/27204
> The current code runs well, but the problem is with input 
> value:http://paste.debian.net/27205
> Аs you can see, the numbers are ok, but strings and characters cause
> "not defined" error.
>
> I've obviously missing something important, but tutorial says nothing
> about this.
>
> Thank you for your help.

You want raw_input()

input() expects the string enterd to be Python code, which it evals()
numbers eval to thenmselves

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


  1   2   >