Re: Embedding Python in C

2007-06-05 Thread mistabean
now then... where's the edit button...?

oh well, double-posting. Problem solved, thanks for pointing out that
I am needing a numeric array built instead of building a normal list/
tuple. For those who are curious, steps to solving:

...
#include "libnumarray.h" /*from numpy*/
...
...
...

void CallSnake(...)
{
...
...
Py_Initialize();
import_libnumarray(); /*badgered me to call this one... where i don't
know*/
...
...
pArray = NA_InputArray(pArgs, tFloat32, NUM_C_ARRAY); /*instead of
making a pArg and calling PyList_SetItem(pArg, 0, pArgs); */

/*Check for NULL on pArray*/

pValue = PyObject_CallFunctionObjArgs(pFunc,pArray,NULL);
/*error checking, cleaning up, Finalizing etc etc*/
}

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


Re: Python Memory Leak using SWIG

2007-06-05 Thread Pierre Sangouard
[EMAIL PROTECTED] wrote:
> Versions:
> Python 2.5.1 (r251:54863, May 14 2007, 10:50:04)
> SWIG Version 1.3.20
>
> Hello I have some code that wraps a C++ library so I may use it in
> python.  The code basically just gets some data and puts it in the
> PyArrayObject* which is returned as a PyObject*.
> I then call it from python like so:
> self.c = __f2.fdct2_wrapper(x,self.nbs,self.nba,self.ac)
>
> I then loop (which pretty much only calls this function) over and
> over.  I put the variable as a self.c hoping the garbage collector
> would know how to delete it after the class goes out of scope.  I also
> tried explicitly deleting the variable (del var) in the loop with no
> success.  In all cases quiet a large memory leak occurs (and grows
> rather quickly).
>
> I believe this is comming from the fact that the thing that is
> returned is a pointer to the data.  So the returning object is a
> pointer.  The python garbage collector then doesn't know how to delete
> this structure and probably (maybe) just deletes the pointer after the
> class goes out of scope.  Leave the data there and causing the memory
> leak issue.  I however doesn't know how to tell python that this
> variable is a pointer and to delete whats going to it.  Or perhaps
> tell SWIG to delete the data, and return the structure some other way?
>
> Here is the c++ wrapping code,  perhaps there is an easy way to fix
> this memory leak (I believe a lot of SWIG people probably do this)
> perhaps some function call from the python? or some special call from
> the SWIG?  Thanks a bunch!
>
> // set up the list output
> PyListObject* out;
> PyArrayObject* output;
> out = (PyListObject*) PyList_New(0);
> npy_intp dims[2];
> int i,j;
>
> for(i=0;i {
> // append a list for this scale
> PyList_Append((PyObject*) out,PyList_New(0));
>
> for(j=0;j {
> // set the dimensions for this scale & angle
> dims[0] = g[i][j].n();
> dims[1] = g[i][j].m();
>
> // make an array for this scale & angle's data
> output = (PyArrayObject*) PyArray_SimpleNewFromData(2, dims,
> PyArray_CDOUBLE,g[i][j]._data);
> Py_INCREF((PyObject*) output);
>
> // append this angle's data to the list for this scale
> PyList_Append(PyList_GetItem((PyObject*) out,i),(PyObject*)
> output);
>
> // zero the CpxNumMat for this scale & angle, hand ownership to
> numpy
> g[i][j]._data = NULL;
> g[i][j]._m = 0;
> g[i][j]._n = 0;
> output->flags = output->flags | NPY_OWNDATA;
> }
> }
>
> return (PyObject*) out;

I think %newobject swig directive is a solution to your problem.

Pierre 


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


Re: magic names in python

2007-06-05 Thread per9000
On 4 Juni, 10:19, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> [...]
>
> Now I'm a little confused.  What does this have to do with magic names?  I
> thought you are talking about names that start and end with two
> underscores (`__magic__`)!?

Indeed I am talking about two things at once - you are right. Since I
have problems with both of these "features" I perhaps do not separate
them very well.

I received lots of nice links to __special__ names in python, thanks.
When it comes to 'dive into python' this is like the fifth time I
heard of it so I really have to get it soon.

Still, I have problems with "magic" functions, similar to magic
numbers: http://en.wikipedia.org/wiki/Magic_number_%28programming%29
f.x. calling all member-functions of a class to close files as
illustrated in a previous post, or PyUnits magic "test*"-names:
http://pyunit.sourceforge.net/pyunit.html#RUNNING_CMD (there are
options here but I fell into the bear-trap of course)

Guessing from your replies this is a general problem/issue/feature and
as I understand it there is no special pythonic recommendations in
this area, right?

Also, I guess that use of magic numbers and magic should be documented
and are thus discovered by RTFM'ing.

Additional comments are welcome, or course.

All your base are belong to us,
Per

--

Per Erik Strandberg
home: www.pererikstrandberg.se
work: www.incf.org
also: www.spongswedencare.se

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


Re: another thread on Python threading

2007-06-05 Thread Josiah Carlson
sturlamolden wrote:
> On Jun 4, 10:11 pm, Josiah Carlson <[EMAIL PROTECTED]>
> wrote:
> 
>>  lock = threading.Lock()
>>
>>  with lock:
>>  #synchronized block!
>>  pass
> 
> True, except that the lock has to be shared among the threads. This
> explicit initiation of an reentrant lock is avoided in a Java
> synchronized block.

You toss the lock creation in the global namespace of the module for 
which you would like to synchronize access.


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


Re: Getting mount stats for filesystems

2007-06-05 Thread Martin v. Löwis
Mitko Haralanov schrieb:
> Hi, I am trying to find a way to figure out whether a certain remote
> filesystem is mounted using tcp vs. udp in Python. I've looked at the
> statvfs call and module but they don't give me anything useful (the
> F_FLAGS field for both a tcp and a udp filesystem is the same.
> 
> I could, of course, get the output of mount and parse that but I would
> prefer something more elegant.

I'm not quite sure what you want to achieve. You are on machine B,
and you want to find out whether a remote file system (on machine A)
is mounted remotely (say, from machine C)?

How do you answer that question with  mount(8)?

Also, what is a tcp filesystem?

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


Re: another thread on Python threading

2007-06-05 Thread Josiah Carlson
sturlamolden wrote:
> On Jun 4, 10:11 pm, Josiah Carlson <[EMAIL PROTECTED]>
> wrote:
> 
>> However, locking isn't just for refcounts, it's to make sure that thread
>> A isn't mangling your object while thread B is traversing it.
> 
> 
>> With
>> object locking (course via the GIL, or fine via object-specific locks),
>> you get the same guarantees, with the problem being that fine-grained
>> locking is about a bazillion times more difficult to verify the lack of
>> deadlocks than a GIL-based approach.
> 
> I think this is just as much a question of what the runtime should
> guarantee. One don't need a guarantee that two threads are not
> mangling the same object simultaneously. Instead, the runtime could
> leave it to the programmer to use explicit locks on the object or
> synchronized blocks to guarantee this for himself.

Why?  Right now we have a language where the only thing that doing silly 
things with threads can get you now is perhaps a deadlock, perhaps 
incorrect execution, or maybe some data corruption if you are working 
with files.  If we forced all thread users to synchronize everything 
themselves, we get an uglier language, and incorrectly written code 
could potentially cause crashes (though all of the earlier drawbacks 
still apply).  In the "safety vs. speed" or "easy vs. fast" arenas, 
Python has already chosen safe and easy rather than fast.  I doubt it is 
going to change any time soon.


>> It was done a while ago.  The results?  On a single-processor machine,
>> Python code ran like 1/4-1/3 the speed of the original runtime.  When
>> using 4+ processors, there were some gains in threaded code, but not
>> substantial at that point.
> 
> I am not surprised. Reference counts are quite efficient, contrary to
> common belief. The problem with reference counts is cyclic references
> involving objects that define a __del__ method. As these objects are
> not eligible for cyclic garbage collection, this can produce resource
> leaks.

There was a discussion about removing __del__ within the last couple 
weeks.  I didn't pay much attention to it (having learned never to use 
__del__), but I believe it involved some sort of weakref-based cleanup.

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


Re: Who uses Python?

2007-06-05 Thread Hongtian
We use Python in our VOIP server. :-)

Python is a very good script language and can be very easy to embed
into our server. It is great!

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


Re: magic names in python

2007-06-05 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, per9000 wrote:

> Still, I have problems with "magic" functions, similar to magic
> numbers: http://en.wikipedia.org/wiki/Magic_number_%28programming%29
> f.x. calling all member-functions of a class to close files as
> illustrated in a previous post, or PyUnits magic "test*"-names:
> http://pyunit.sourceforge.net/pyunit.html#RUNNING_CMD (there are
> options here but I fell into the bear-trap of course)

I don't see much similarity here.  While magic numbers are quite
meaningless on their own, the name prefix carries at least *some*
explanation and therefore is much less magic.  Maybe not even magic at all
in the sense of the Wikipedia article.

> Guessing from your replies this is a general problem/issue/feature and
> as I understand it there is no special pythonic recommendations in
> this area, right?

Except documenting what's going on and not over(ab)using the reflective
and dynamic nature of Python to the point where the source starts to get
unreadable and too magic, AFAIK there's no special "pythonic"
recommendation.  :-)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter - resize tkMessageBox

2007-06-05 Thread Glenn Hutchings
On 4 Jun, 21:29, [EMAIL PROTECTED] wrote:
> Is there a way to resize the width of the "tkMessageBox.askyesno"
> dialog box, so that the text does not wrap to the next line.

You can use the Tk option database, either explicitly or from a file.
For example, to set the wrap length of all dialogs to 10 inches, try
this:

   root = Tk()
   root.option_add("*Dialog.msg.wrapLength", "10i")

Regards,

Glenn

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


want to get free things from microsoft?

2007-06-05 Thread justpratik
visit my site http://justpratik.blogspot.com if u want to win from
microsoft

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


please help a newbie

2007-06-05 Thread Pieter Potgieter

Hi all
I have a binary file of about 600kbytes - I want to break it up in file
chunks of 1085 bytes - every file must have a new file name.
The data is binary video frames (370 frames) - I want to play the data back
into an embedded system frame/file by file.
I am a complete Python newby - but have C/C++ skills.
Please supply/help me with an snippet or example
Thanks
Pieter
-- 
http://mail.python.org/mailman/listinfo/python-list

Please help on Binary file manipulation

2007-06-05 Thread Pieter Potgieter
Hi all
I have a binary file of about 600kbytes - I want to break it up in file
chunks of 1085 bytes - every file must have a new file name.
The data is binary video frames (370 frames) - I want to play the data
back into an embedded system frame/file by file.
I am a complete Python newby - but have C/C++ skills.
Please supply/help me with an snippet or example 
Thanks
Pieter

***
Disclaimer:  The information contained in this communication is confidential 
and may be legally privileged.  
It is intended solely for the use of the individual or entity to whom it is 
addressed and others authorised to receive it.  
Any review, retransmission, dissemination, copying, disclosure or other use of, 
or taking of any action in reliance upon, this information by person or 
entities other then the intended recipient is prohibited.  
If you have received this message in error, please notify the sender 
immediately by e-mail, facsimile or telephone and return and/or destroy the 
original message and all copies from any computer.  

Denel (Pty) Ltd exercises no editorial control over e-mail messages originating 
in the organisation and does not accept any responsibility for either the 
contents of the message or any copyright laws that may have been violated by 
the person sending this message.  
Denel (Pty) Ltd is neither liable for the proper and complete transmission of 
the information contained in this communication nor any delay in its receipt.  
This message should not be copied or used for any purpose other than intended, 
nor should it be disclosed to any other person.
***

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

CFP: 2008 International Workshop on Multi-Core Computing Systems

2007-06-05 Thread Sabri . Pllana
We apologize if you receive multiple copies of this call for papers.

***
2008 International Workshop on Multi-Core Computing Systems
(MuCoCoS'08)
Barcelona, Spain, March 4 - 7, 2008; in conjunction with CISIS'08.

***

Context
---
- The improvement of the processor performance by increasing the clock
rate has reached its technological limits. Increasing the number of
processor cores rather than clock rate can give better performance and
reduce problems like energy consumption, heat dissipation and design
complexity. We are witnessing the emergence of multi-core processors
in all markets from laptops and game consoles to servers and
supercomputers.

Topics of Interest
--
- The topics of the workshop include but are not limited to:
   - multi-core architectures
   - interconnection networks
   - multi-core embedded systems
   - programming languages and models
   - algorithms for multi-core computing systems
   - applications for multi-core systems
   - performance modeling and evaluation of multi-core systems
   - design space exploration
   - resource usage optimization
   - tool-support for multi-core systems
   - compilers, runtime and operating systems

Submission Guidelines
-
- The papers should be prepared using the IEEE CS format (instructions
for LaTex users are available at
),
and no longer than 6 pages. Submitted papers will be carefully
evaluated based on originality, significance to workshop topics,
technical soundness, and presentation quality.
- Submission of the paper implies that should the paper be accepted,
at least one of the authors will register and present the paper at the
workshop. Proceedings of the workshop will be published by IEEE
Computer Society Press. The best papers presented at the workshop will
be selected for publication in an international journal.
- The papers should be submitted electronically via CISIS'08 website


Important Dates
---
- Paper submission deadline: October 10, 2007
- Notification: November 25, 2007
- Registration: December 15, 2007
- Final version of the paper: January 15, 2008
- Workshop: March 4 - 7, 2008

Keynote Speaker
---
- David A. Bader

Head of the Sony-Toshiba-IBM center of competence for the Cell BE
processor.

Workshop Co-chairs
--
- Leonard Barolli
<[EMAIL PROTECTED]>, Fukuoka Institute of Technology, Japan
- Sabri Pllana
<[EMAIL PROTECTED]>, University of Vienna, Austria
- Fatos Xhafa
<[EMAIL PROTECTED]>, Polytechnic University of Catalonia, Spain

Program Committee
-
- David A. Bader, Georgia Institute of Technology, USA
- Leonard Barolli, Fukuoka Institute of Technology, Japan
- Siegfried Benkner, University of Vienna, Austria
- Luca Benini, University of Bologna, Italy
- Rajkumar Buyya, University of Melbourne, Australia
- Michael McCool, University of Waterloo, and RapidMind Inc., Canada
- Lasse Natvig, Norwegian University of Science and Technology, Norway
- Sabri Pllana, University of Vienna, Austria
- Vivek Sarkar, IBM Research, T.J. Watson Research Center, USA
- Thomas Sterling, Caltech and Louisiana State University, USA
- Jesper Larsson Träff, C&C Research labs, NEC Europe Ltd, Germany
- Manolis Vavalis, CERETETH, Greece
- Brian Vinter, University of Copenhagen, Denmark
- Fatos Xhafa, Polytechnic University of Catalonia, Spain
- Hans Zima, University of Vienna, Austria, and JPL/Caltech, USA

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


Re: Who uses Python?

2007-06-05 Thread Maria R
I tend to agree with some earlier poster that if you use Python you
are, in a sense, a programmer :o)

But seriously, we use Python for controlling fully automated logistics
solutions (conveyors and stacker cranes), for generating PLC code etc
etc.

We are also about to start using FactoryCAD (a thingy from UGS to run
on top af AutoCAD) in which we have "intelligent" objects. These
objects have action code and FactoryCAD contains an embedded Python
interpreter. Our mech engineers thus write (although a bit simple but
still..) Python to make things work :o)

We further have generators of mechanical assemblies in SolidEdge. We
use a rule based approach and both the configuration files and the
rule base are in Python. Our Mech engineers maintain that too.

My two cent..


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


Re: magic names in python

2007-06-05 Thread ai
I don't think it is magic. If you think it is magic, can you talk
about what's the better way and how can you implement the functions
without any magic. I can't image a lauguage without special names.
There are some special names even in Lisp. I guess you just hate the
'__'.

On Jun 4, 2:43 pm, per9000 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I recently started working a lot more in python than I have done in
> the past. And I discovered something that totally removed the pretty
> pink clouds of beautifulness that had surrounded my previous python
> experiences: magic names (I felt almost as sad as when I discovered
> the strange pink worms that eat you in nethack, not to mention the
> mind flayers - I really hate them).
>
> I guess all programming languages have magic names to some extent
> (f.x. classes in the "C-family" have constructors that must have the
> same name as the class (foo::foo) instead of foo.__init__).
>
> I just used a search engine a little on this topic and I found no
> comprehensive list of magic names in python.
>
> So my questions:
>  * is there a comprehensive list of magic names in python (so far i
> know of __init__ and __repr__)?
>  * are these lists complete or can magic names be added over time (to
> the python "core")?
>  * are magic names the same in different python versions?
>
> I also tried (selected parts of(?)) the unittest package for use in
> Zope and it seemed functions that I created for my test with the magic
> prefix "test" were magic, other functions were not.
>
> So another question emerges:
>  * is the use of magic names encouraged and/or part of good coding
> practice.
>
> Live long and prosper,
> Per
>
> --
>
> Per Erik Strandberg
> home:www.pererikstrandberg.se
> work:www.incf.org
> also:www.spongswedencare.se


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


html 2 image script or library

2007-06-05 Thread baur79
Hi everyone

can you help me to find script or library for making website (from
url) 2 image (png, jpg no matter).

thanks a lot

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


Re: Please help on Binary file manipulation

2007-06-05 Thread km

Hi,

I assume ur on  a linux/unix box...

pls check the manual for 'split' command in linux/unix
this does ur job

regards,
KM
---
On 6/5/07, Pieter Potgieter <[EMAIL PROTECTED]> wrote:


 Hi all
I have a binary file of about 600kbytes - I want to break it up in file
chunks of 1085 bytes - every file must have a new file name.
The data is binary video frames (370 frames) - I want to play the data
back into an embedded system frame/file by file.
I am a complete Python newby - but have C/C++ skills.
Please supply/help me with an snippet or example
Thanks
Pieter


***

Disclaimer: The information contained in this communication is
confidential and may be legally privileged.

It is intended solely for the use of the individual or entity to whom it
is addressed and others authorised to receive it.

Any review, retransmission, dissemination, copying, disclosure or other
use of, or taking of any action in reliance upon, this information by person
or entities other then the intended recipient is prohibited.

If you have received this message in error, please notify the sender
immediately by e-mail, facsimile or telephone and return and/or destroy the
original message and all copies from any computer.

 Denel (Pty) Ltd exercises no editorial control over e-mail messages
originating in the organisation and does not accept any responsibility for
either the contents of the message or any copyright laws that may have been
violated by the person sending this message.

Denel (Pty) Ltd is neither liable for the proper and complete transmission
of the information contained in this communication nor any delay in its
receipt.

This message should not be copied or used for any purpose other than
intended, nor should it be disclosed to any other person.


***


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

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

Re: Strange behavior in Windows

2007-06-05 Thread Douglas Woodrow
On Mon, 4 Jun 2007 21:34:36, David Stockwell wxp <[EMAIL PROTECTED]> 
wrote
>
>in DOS you can try this to see what your path is:
>
>echo "My path is %PATH%"

or more simply:

,
| C:> path
`
-- 
Doug Woodrow

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


Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-05 Thread ai
I am not a native English speaker. But I totally do not support PEP
3131. If a program is written in English and commented by other
language, I am read it. But if a program is written in other language,
it will be full unreadable by me even it is commented by English. I
think language is just a tool used for intercommunion. The best
situation is all people use only one language.

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


Re: Beginner question: module organisation

2007-06-05 Thread Mail . To . Nathaniel
Thank you for all your help!

I'll study the proposals to chose the one I prefer or to create
something new :) Anyway, this is a perfect start-up for me.

Nathaniel.

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


Re: Who uses Python?

2007-06-05 Thread montyphyton
i use it for text mining, processing large text corpora for scientific
purposes. i'm also working on some neat data mining tools written in
python (called orange, in case someone's interested)

walterbyrd je napisao/la:
> I mean other than sysadmins, programmers, and web-site developers?
>
> I have heard of some DBAs who use a lot of python.
>
> I suppose some scientists. I think python is used in bioinformatics. I
> think some math and physics people use python.
>
> I suppose some people use python to learn "programming" in general.
> Python would do well as a teaching language.
>
> I would think that python would be a good language for data analysis.
>
> Anything else? Finance? Web-analytics? SEO? Digital art?

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


Regression testing with Python

2007-06-05 Thread Almad
Hi,

I'd like to ask how do You resolve "resources" issue when writing
regression tests in Python. When doing functional tests, I have some
resources that might not be available (like database, HTTP server,
Selenium testing proxy) and I'd like then to skip test gracefully (not
either failing nor green status).

Is there a simple way to do this?

Or, how do You build Your Selenium testsuites and integrate them into
main suite?

Thank You,

Almad

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


Re: html 2 image script or library

2007-06-05 Thread Thomas Jollans
"baur79" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> can you help me to find script or library for making website (from
> url) 2 image (png, jpg no matter).

complex business that is, you'll want to look at fully-fledged HTML redering 
engines like Gecko. You might also want to reveal your name (rather common 
on USENET and mailing lists, I gather) and use, to the best of your ability, 
proper English.

Thomas Jollans 


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


Re: magic names in python

2007-06-05 Thread per9000
On 5 Juni, 11:02, ai <[EMAIL PROTECTED]> wrote:
> I don't think it is magic. If you think it is magic, can you talk
> about what's the better way and how can you implement the functions
> without any magic. [...]

Well, in a sense I guess all reserved words can be considered magic,
but in Python you can kill it (AFAIK that is pretty unique to python):
>>> a = int(8)
>>> int = float
>>> b = int(8)
>>> (a, b)
(8, 8.0)

I guess the amount and flavor of the magic is a matter of personal
taste - coming from a C*-background I pretty much like
myClass.myClass() instead of myClass.__init__() - but these are
equivalent and I guess I just have to live with the way python has
__special__ names and print a list of the cases I end up with often to
keep my memory from forgetting them.

> There are some special names even in Lisp. I guess you just hate the
> '__'.

Yes and no. Indeed, I find the overuse of underscores ugly, but I can
accept some use of __special__ functions. AFAIK there must be reserved
words in a programming language - f.x. names of ctors in oo-languages.
The exceptions are perhaps brainf**k and whitespace that has special
chars instead.

Also I find it unfortunate that the name mangling and underscores are
the way to make members "less public". But I can live with that - I
just have to read more python code to get the hang of it.
[:)]-|--<

/Per

--

Per Erik Strandberg
home: www.pererikstrandberg.se
work: www.incf.org
also: www.spongswedencare.se

>
> On Jun 4, 2:43 pm, per9000 <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I recently started working a lot more in python than I have done in
> > the past. And I discovered something that totally removed the pretty
> > pink clouds of beautifulness that had surrounded my previous python
> > experiences: magic names (I felt almost as sad as when I discovered
> > the strange pink worms that eat you in nethack, not to mention the
> > mind flayers - I really hate them).
>
> > I guess all programming languages have magic names to some extent
> > (f.x. classes in the "C-family" have constructors that must have the
> > same name as the class (foo::foo) instead of foo.__init__).
>
> > I just used a search engine a little on this topic and I found no
> > comprehensive list of magic names in python.
>
> > So my questions:
> >  * is there a comprehensive list of magic names in python (so far i
> > know of __init__ and __repr__)?
> >  * are these lists complete or can magic names be added over time (to
> > the python "core")?
> >  * are magic names the same in different python versions?
>
> > I also tried (selected parts of(?)) the unittest package for use in
> > Zope and it seemed functions that I created for my test with the magic
> > prefix "test" were magic, other functions were not.
>
> > So another question emerges:
> >  * is the use of magic names encouraged and/or part of good coding
> > practice.
>
> > Live long and prosper,
> > Per
>
> > --
>
> > Per Erik Strandberg
> > home:www.pererikstrandberg.se
> > work:www.incf.org
> > also:www.spongswedencare.se


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


url encode

2007-06-05 Thread Lee Jones
Hello,

 

I am trying to urlencode a string.  In python the only thing I can see
is the urllib.urlencode().  But this takes a dictionary, and returns
"key=value", which is not what I want.  I only want to url-encode a
string.  Does any one know how to do this in python

Thanks

Lee

 

 

Lee Jones, 

Software Developer
  
SecureTrading Ltd
European Operations Centre
Parc Menai
Bangor
Gwynedd LL57 4BL 
T: 01248 672 028
F: 01248 672 099

www.securetrading.com

 

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

Re: excel library without COM

2007-06-05 Thread John Machin
On Jun 5, 1:04 pm, james_027 <[EMAIL PROTECTED]> wrote:
> On Jun 4, 8:16 pm, John Machin <[EMAIL PROTECTED]> wrote:
>
> > On Jun 4, 3:52 pm, yuce <[EMAIL PROTECTED]> wrote:
>
> > > i think this one works pretty nice:http://www.python.org/pypi/xlrd
>
> > Sure does :-) However the "rd" in "xlrd" is short for "ReaD". As
> > Waldemar suggested, "xlwt" ("wt" as in WriTe) is more like what the OP
> > needs.
>
> > Cheers,
> > John
>
> Thanks to all who have contributed. I have one concern though. Many of
> the module seems to be not active anymore? or updated? It is because
> it really stable and has most of the features needed?
>

xlwt is active, stable enough for heavy use, and will get a public
outing Real Soon Now (after xlrd 0.6.1 final, which is expected Truly
Rooly Real Soon Now).


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


Memory Leak in Python 2.5.1?

2007-06-05 Thread Suresh Kumar

Hi,

I am currently investigating what seems to be a memory leak in python.
(version 2.5.1). I have made python work with a custom memory sub-allocator
(pool). The idea is to  preallocate a pool of memory during initialization
of my application and ensure that Python doesn't make any system mallocs
(similar to max heap setting in java VM). With this arrangement, python
seems to run out of preallocated memory after few iterations of the
following code:

int main(int argc, char *argv[]){
  int i;
  mem_init(300);//Initialize the memory pool with 3M
  for (i=0;i<2000,i++){
 Py_Initialize();
 Sleep(1000);
 Py_Finalize();
  }
}


The above code runs out of memory after 1000 + iterations. To me this looks
like a memory leak, Does anyone out there have any idea whats happening
here?

Regards,
Suresh

--
"Everything of value that people get from religion can be had more honestly,
without presuming anything on insufficient evidence. The rest is
self-deception, set to music."
-- 
http://mail.python.org/mailman/listinfo/python-list

Feature request: New string conversion type to ignore list item

2007-06-05 Thread thomas . pohl
Hi,
let's assume you want to nicely print the content of a list except for
one (or some)
individual item. You could do it like this:

t = ["foo", "skip me", 1, 2, 3]
print("text: %s\nvalues: %i %i %i" % (t[0], t[2], t[3], t[4]))

If there was a conversion type which simply ignores the corresponding
list item
- let's call it "%v" like "void" - things would be much easier:

t = ["foo", "skip me", 1, 2, 3]
print("text: %s\nvalues: %v%i %i %i" % t)

I guess that this new conversion type wouldn't break any existing
code.
What do you think?

Cheers,
Tom

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


Re: Feature request: New string conversion type to ignore list item

2007-06-05 Thread Peter Otten
 [EMAIL PROTECTED] wrote:

> let's assume you want to nicely print the content of a list except for
> one (or some) individual item. You could do it like this:

> t = ["foo", "skip me", 1, 2, 3]
> print("text: %s\nvalues: %i %i %i" % (t[0], t[2], t[3], t[4]))

or like this:

>>> "%s %.s %s" % ("first", "second", "third")
'first  third'

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


mxtextools, py2app, and intel vs. PPC

2007-06-05 Thread Ian A. York

I've been packaging a set of scripts using py2app, and until now the app
that results has run without issues on MacOS10.4, either intel or ppc.  

The latest version made by py2app, however, only runs on intel (on which I 
made the py2app package).  The problem seems to be with eGenix mx base 
package (which is needed for BioPython).  The package when run on PPC gets 
the error "No module named TextTools", although TextTools is included and 
works fine on intel. If I include TextTools specifically in the Resources 
folder within the package, instead I get an error "ImportError: 
Inappropriate file type for dynamic loading".  Again, these errors only 
appeared on the ppc platform, not on intel.

I worked around the problem by including (in the Resources folder) the 
TextTools from a PPC machine, and the package then runs on both machines. 
This isn't a great solution, because I don't always have easy access to a 
PPC machine running MacOS10.4.  

I presume that the problem is that the mx package I have on the Intel 
machine isn't actually a Universal binary, and so the PPC has no access to 
that module.  I've tried installing the mx package from source, and from 
the prebuilt binary, without fixing the problem.

Anyone know if my guess is right, that the mx package isn't coming in as a 
universal?  And if so, if there's a way to force it to be universal, or 
some other simple fix for my problem?

Thanks,

Ian
-- 
Ian York   ([EMAIL PROTECTED])  
"-but as he was a York, I am rather inclined to suppose him a
 very respectable Man." -Jane Austen, The History of England
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who uses Python?

2007-06-05 Thread Maurice LING
[EMAIL PROTECTED] wrote:
> i use it for text mining, processing large text corpora for scientific
> purposes. i'm also working on some neat data mining tools written in
> python (called orange, in case someone's interested)
> 

Hi,

I am very interested with your use of Python. I am into text mining as 
well. Perhaps we can communicate more on this...

I am also interested in your data mining tools, orange... Care to give 
more details.

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


Re: Feature request: New string conversion type to ignore list item

2007-06-05 Thread thomas . pohl
On 5 Jun., 13:12, Peter Otten <[EMAIL PROTECTED]> wrote:

> or like this:
>
> >>> "%s %.s %s" % ("first", "second", "third")
>
> 'first  third'

Hey, that's great, thanks Peter!

Tom

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


Refactoring test units after an extract method

2007-06-05 Thread Virgil Dupras
This is not strictly python related, but it's not strictly TDD related
either. Anyway, here it goes.

There's something that I was never quite sure how to handle with test
units: How to handle the test unit refactoring after a method
extraction.

Let's say that you have a function foo() that does A and B. You have
tests for foo() that check that A and B are executed properly. Then,
you add another function, bar(), that needs to do B, so you add a
third function, baz() that does B and make foo() and bar() call baz().

How to you handle the tests? Copy over the tests you had for foo() and
apply them to bar()? I don't like copy and pasting code. Move the B
related tests to baz()'s tests? Then your tests wouldn't fail if you
stopped calling baz() in foo() and bar().

What I do right now is that I mock baz() and verify that it is called
in foo() and bar(), with the right arguments. Then I move the B
related tests to baz(). It kind of works, but somehow, it doesn't feel
like the ideal solution to me. But then again, it's kind of the same
thing as if baz() was a third party function: You have to mock it to
test foo() and bar() properly without testing the third party code.

What do you people think?

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


how to convert a bitmap file to an array ?

2007-06-05 Thread stef
hello

I can find all kind of procedures to convert an array to a bitmap
(wxPython, PIL),
but I can't find the reverse,
either
   - convert a bitmap to an array
or
  - read a bitmap file to an array

thanks,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Hi, When I do a small program like

from subprocess import Popen
popen = Popen(["ping", "google.com"])
from time import sleep
sleep(100)

start it and kill it, the ping process lives on.
Is there a way to ensure that the ping process is always killed when the 
python process is?
I can't use atexit, as ping then isn't killed when python is killed "in 
the hard way"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to convert a bitmap file to an array ?

2007-06-05 Thread Stefan Sonnenberg-Carstens
stef schrieb:
> hello
>
> I can find all kind of procedures to convert an array to a bitmap
> (wxPython, PIL),
> but I can't find the reverse,
> either
>- convert a bitmap to an array
> or
>   - read a bitmap file to an array
>
> thanks,
> Stef Mientki
>   
Take a look at the "struct" module.
There you fill find pack/unpack, which can do what you need.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: c[:]()

2007-06-05 Thread Steve Holden
Warren Stringer wrote:
> Oops, forgot to cut and paste the point, to this:
>  
>>> - there is no Python error for "you
>>> cannot do this with this object, but you can do it with other objects
>>> of the same type".
>> Yes there is:
>>
>> #
>> def yo(): print "yo"
>> def no(): print blah
>> yo()
>> no()
>>
>> Starting Python debug run ...
>> yo
>> Traceback (most recent call last):...
>> NameError: global name 'blah' is not defined
>> #
> 
> The point is that if the object is ill formed, then you get a traceback
> regardless.  
> 
> But, as this is an addendum to the other post, please read that first. 
> 
> Now, I really am out of here.
> 
Say, who *was* that masked man? ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: subprocess leaves child living

2007-06-05 Thread Stefan Sonnenberg-Carstens
Thomas Dybdahl Ahle schrieb:
> Hi, When I do a small program like
>
> from subprocess import Popen
> popen = Popen(["ping", "google.com"])
> from time import sleep
> sleep(100)
>
> start it and kill it, the ping process lives on.
> Is there a way to ensure that the ping process is always killed when the 
> python process is?
> I can't use atexit, as ping then isn't killed when python is killed "in 
> the hard way"
>   
Calling popen.close() perhaps ?
You basically open a pipe, which spawns a shell and the command is then
started in there.
So, if your program quits, the spawned shell is still alive, only the 
pipe is dead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to convert a bitmap file to an array ?

2007-06-05 Thread Diez B. Roggisch
stef wrote:

> hello
> 
> I can find all kind of procedures to convert an array to a bitmap
> (wxPython, PIL),
> but I can't find the reverse,
> either
>- convert a bitmap to an array
> or
>   - read a bitmap file to an array

Not true for PIL, Image.getdata and Image.putdata are your friends.

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


Re: Embedding Python in C

2007-06-05 Thread Joe Riopel
This seems like a pretty good resource, although I didn't read it all yet:
http://www.ibm.com/developerworks/edu/l-dw-linux-pythonscript-i.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to convert a bitmap file to an array ?

2007-06-05 Thread stef
Stefan Sonnenberg-Carstens wrote:
> stef schrieb:
>> hello
>>
>> I can find all kind of procedures to convert an array to a bitmap
>> (wxPython, PIL),
>> but I can't find the reverse,
>> either
>>- convert a bitmap to an array
>> or
>>   - read a bitmap file to an array
>>
>> thanks,
>> Stef Mientki
>>   
> Take a look at the "struct" module.
> There you fill find pack/unpack, which can do what you need.
thanks Stefan,

but using struct, I need to know how a bitmap file is build,
I don't know that (and I rather don't want to know that ;-)

Any better solutions (I'm a spoiled Delphi user ;-)

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


Re: how to convert a bitmap file to an array ?

2007-06-05 Thread stef
Diez B. Roggisch wrote:
> stef wrote:
>
>   
>> hello
>>
>> I can find all kind of procedures to convert an array to a bitmap
>> (wxPython, PIL),
>> but I can't find the reverse,
>> either
>>- convert a bitmap to an array
>> or
>>   - read a bitmap file to an array
>> 
>
> Not true for PIL, Image.getdata and Image.putdata are your friends.
>
>   
thanks Diez,
I really overlooked that.

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


*args and **kwargs

2007-06-05 Thread JonathanB
Ok, this is probably definitely a newbie question, but I have looked
all over the Python library reference material and tutorials which I
can find online and I cannot find a clear definition of what these are
and more importantly how to use them. From what I can tell from their
use in the examples I've seen, they are for passing a variable number
of arguments to a function (which I need to do in a program I am
working on). But how do you use them? Is there a fixed order in which
the arguments within *arg or **kwarg should be passed or will be
called within a function? I realize this probably involves a long-
winded answer to a very simple and common programming problem, so if
someone has a link to TFM, I'll gladly go RTFM. I just can't find it.

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


Re: *args and **kwargs

2007-06-05 Thread Diez B. Roggisch
JonathanB wrote:

> Ok, this is probably definitely a newbie question, but I have looked
> all over the Python library reference material and tutorials which I
> can find online and I cannot find a clear definition of what these are
> and more importantly how to use them. From what I can tell from their
> use in the examples I've seen, they are for passing a variable number
> of arguments to a function (which I need to do in a program I am
> working on). But how do you use them? Is there a fixed order in which
> the arguments within *arg or **kwarg should be passed or will be
> called within a function? I realize this probably involves a long-
> winded answer to a very simple and common programming problem, so if
> someone has a link to TFM, I'll gladly go RTFM. I just can't find it.

That's because it's in the language reference, not in the library reference.

http://docs.python.org/ref/calls.html

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


Re: *args and **kwargs

2007-06-05 Thread Thomas Jollans
"JonathanB" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Ok, this is probably definitely a newbie question, but I have looked
> all over the Python library reference material and tutorials which I
> can find online and I cannot find a clear definition of what these are
> and more importantly how to use them. From what I can tell from their
> use in the examples I've seen, they are for passing a variable number
> of arguments to a function (which I need to do in a program I am
> working on). But how do you use them? Is there a fixed order in which
> the arguments within *arg or **kwarg should be passed or will be
> called within a function? I realize this probably involves a long-
> winded answer to a very simple and common programming problem, so if
> someone has a link to TFM, I'll gladly go RTFM. I just can't find it.


I hope this example code will help you understand:

>>> def a(*stuff):
 print repr(stuff)

>>> def b(**stuff):
 print repr(stuff)


>>> def c(*args, **kwargs):
 print 'args', repr(args)
 print 'kwargs', repr(kwargs)


>>> a(1,2,3)
(1, 2, 3)
>>> b(hello='world', lingo='python')
{'hello': 'world', 'lingo': 'python'}
>>> c(13,14,thenext=16,afterthat=17)
args (13, 14)
kwargs {'afterthat': 17, 'thenext': 16}
>>> args = [1,2,3,4]
>>> kwargs = {'no-way': 23, 'yet-anotherInvalid.name': 24}
>>> c(*args, **kwargs)
args (1, 2, 3, 4)
kwargs {'no-way': 23, 'yet-anotherInvalid.name': 24}
>>>


(sorry for the messed-up formatting) 


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


Re: *args and **kwargs

2007-06-05 Thread Wildemar Wildenburger
JonathanB wrote:
> Ok, this is probably definitely a newbie question, but I have looked
> all over the Python library reference material and tutorials which I
> can find online and I cannot find a clear definition of what these are
> and more importantly how to use them. From what I can tell from their
> use in the examples I've seen, they are for passing a variable number
> of arguments to a function (which I need to do in a program I am
> working on). But how do you use them? Is there a fixed order in which
> the arguments within *arg or **kwarg should be passed or will be
> called within a function? I realize this probably involves a long-
> winded answer to a very simple and common programming problem, so if
> someone has a link to TFM, I'll gladly go RTFM. I just can't find it.
>
>   
http://www.python.org/doc/faq/programming/#how-can-i-pass-optional-or-keyword-parameters-from-one-function-to-another
(the first hit when you search python.org for *args and **kwargs)

Basically 'args' is a tuple with all the positional arguments, kwargs is 
a dictionary with all the named arguments.
Likewise you can pass a tuple to a function like func(*tuple), or a dict 
like func(**dictionary) or both, where the zuple has to come first.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *args and **kwargs

2007-06-05 Thread JonathanB
> I hope this example code will help you understand:
>>Code Snipped<<
OOH!! That makes perfect sense, thanks!, *args are passed as a turple,
**kwargs are passed as a dictionary. That means **kwargs is probably
what I want.

JonathanB


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


RE: Graph plotting module

2007-06-05 Thread Sells, Fred
www.vpython.org might be overkill, but it was easy to do simple 2d charts.

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Behalf Of Grant Edwards
> Sent: Monday, June 04, 2007 11:23 AM
> To: python-list@python.org
> Subject: Re: Graph plotting module
> 
> 
> On 2007-06-04, Viewer T. <[EMAIL PROTECTED]> wrote:
> 
> > Is there a python module anywhere out there that can plot straight
> > line graphs, curves (quadratic, etc). If anyone knows where I can
> > download one, please let me know.
> 
> gnuplot-py
> matplotlib
> 
> -- 
> Grant Edwards   grante Yow! BARRY 
> ... That was
>   at   the most 
> HEART-WARMING
>visi.comrendition 
> of "I DID IT MY
>WAY" I've 
> ever heard!!
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *Naming Conventions*

2007-06-05 Thread Neil Cerutti
On 2007-06-04, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> Wildemar Wildenburger wrote:
>> While that is true, I guess it is commonplace to use i, j, k
>> and n (maybe others) in constructs like
>> 
>> for i in range(len(data)):
>>do_stuff(data[i])
>> 
>> Or should the good python hacker do that differently? Hope not
>> ;).
>
> Well, yes, I would do:
>
> for item in data:
> do_stuff(item)
>
> or, if using enumerate:
>
> for item_index, item in enumerate(data):
> do_stuff(item_index, item)
>
> I agree with Bruno that i and j should be used only for
> indices, but I'm usually less terse than that.

I find i and j preferable to overly generic terms like "item."

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


Re: Who uses Python?

2007-06-05 Thread Neil Cerutti
On 2007-06-04, walterbyrd <[EMAIL PROTECTED]> wrote:
> I mean other than sysadmins, programmers, and web-site
> developers?

I manage the database application, data integration, and
reporting for a financial aid office, and I use Python every day.
Though I only seldom have to write new programs or update my old
ones.

I use it to shuffle and sort important files around, to convert
reports into formats necessary for various import and export
functions, to reconcile data between database systems, and to
maintain little text databases for various business processes.

The only "programming language" I use more often is Excel
(VLOOKUP and Pivot Tables specifically). Python can replace any
individual Excel application, but I use Excel for a bunch of
one-timers, for which I find it more convenient. Python enters
the picture when I find something that I need to do frequently,
and with similar data inputs and outputs.

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


Re: subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Den Tue, 05 Jun 2007 14:07:44 +0200 skrev Stefan Sonnenberg-Carstens:

> Thomas Dybdahl Ahle schrieb:
>> Hi, When I do a small program like
>>
>> from subprocess import Popen
>> popen = Popen(["ping", "google.com"]) from time import sleep
>> sleep(100)
>>
>> start it and kill it, the ping process lives on. Is there a way to
>> ensure that the ping process is always killed when the python process
>> is?
>> I can't use atexit, as ping then isn't killed when python is killed "in
>> the hard way"
>>   
> Calling popen.close() perhaps ?
> You basically open a pipe, which spawns a shell and the command is then
> started in there.
> So, if your program quits, the spawned shell is still alive, only the
> pipe is dead.

Problem is - I can't do that when I get killed.
Isn't it possible to open processes in such a way like terminals? If I 
kill the terminal, everything open in it will die too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring test units after an extract method

2007-06-05 Thread Steve Howell

--- Virgil Dupras <[EMAIL PROTECTED]>
wrote:

> How to you handle the tests? Copy over the tests you
> had for foo() and
> apply them to bar()? I don't like copy and pasting
> code. Move the B
> related tests to baz()'s tests? Then your tests
> wouldn't fail if you
> stopped calling baz() in foo() and bar().
> 

I recently had an example where class A used class B,
which used class C, which used class D, which used OS
service E, etc.  I had mock versions of B, C, D, and
E.  The overall design of the module was kind of like
a network stack, where each module theoretically only
depended on the services of the module beneath it in
the stack.  

So many of the tests for A used a real B, but a mock
C.

Many of the tests for B used a real C, but a mock D.

Many of the tests for C used a real D, but a mock E.

But I also wanted to test that my abstractions weren't
leaky, e.g. that there weren't some implementation
details of C or lower that broke A.  So certain loops
in my test for A would also plug in a real C.

Finally, some of the test for A would also use a mock
B.

I was able to mostly avoid copy-and-pasting of tests
by taking advantage of Python's dynamic nature. 
Although this is oversimplifying things a bit, you can
do things like this:

for b_is_mocked, c_is_mocked, d_is_mocked in [
 (True, True, True),
 (True, True, False),
 (False, False, False), # etc.
 ]
 # do setup
 test1()
 test2()
 test3()
 test4()







   

Sick sense of humor? Visit Yahoo! TV's 
Comedy with an Edge to see what's on, when. 
http://tv.yahoo.com/collections/222
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedding interactive interpreter

2007-06-05 Thread Ryan K
Hi. I am trying to embed an interactive interpreter in a C++
application. I need to capture the output of int
PyRun_InteractiveOne(FILE *fp, const char *filename). Is redirecting
sys.stdout and sys.stderr after initializing the interpreter the best
way to do this?

Thanks,
Ryan

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


Logging: how to suppress default output when adding handlers?

2007-06-05 Thread Chris Shenton
I am setting up handlers to log DEBUG and above to a rotating file and
ERROR and above to console.  But if any of my code calls a logger
(e.g., logging.error("foo")) before I setup my handlers, the logging
system will create a default logger that *also* emits logs, which I
can't seem to get rid of.  Is there a way I can suppress the creation
of this default logger, or remove it when I 'm setting up my handlers?
Thanks.

Sample code:

  import sys, logging, logging.handlers

  if len(sys.argv) > 1:
  logging.warning("Logging before setting handlers adds unwanted default 
logger")

  logging.getLogger().setLevel(logging.DEBUG)

  console = logging.StreamHandler()
  console.setLevel(logging.ERROR)
  console.setFormatter(logging.Formatter('%(levelname)-8s %(module)s: 
%(message)s'))
  logging.getLogger().addHandler(console)

  filelog = logging.handlers.RotatingFileHandler("/tmp/logtest2.log")
  filelog.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s 
%(module)s: %(message)s'))
  filelog.setLevel(logging.DEBUG)  # NOP since default above is DEBUG, but 
OK
  logging.getLogger().addHandler(filelog)

  logging.debug("TEST debug")
  logging.warning("TEST warning")
  logging.error("TEST error")


Sample runs, first without initial log call (good), then with one
showing the default log messages in the mix (bad); I'm showing the
console and tailing the logfile so they're mixed together but the
timestamp indicates the file logs:

  [EMAIL PROTECTED]:/tmp<103> tail -f /tmp/logtest2.log &

  [EMAIL PROTECTED]:/tmp<118> python /tmp/logtest2.py 
  2007-06-05 09:36:27,234 DEBUGlogtest2: TEST debug
  2007-06-05 09:36:27,234 WARNING  logtest2: TEST warning
  ERRORlogtest2: TEST error
  2007-06-05 09:36:27,239 ERRORlogtest2: TEST error

  [EMAIL PROTECTED]:/tmp<119> python /tmp/logtest2.py  this gives ugly logger
  WARNING:root:Logging before setting handlers adds unwanted default logger
  DEBUG:root:TEST debug
  2007-06-05 09:36:30,069 DEBUGlogtest2: TEST debug
  WARNING:root:TEST warning
  2007-06-05 09:36:30,072 WARNING  logtest2: TEST warning
  ERROR:root:TEST error
  ERRORlogtest2: TEST error
  2007-06-05 09:36:30,073 ERRORlogtest2: TEST error
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess leaves child living

2007-06-05 Thread Rob Wolfe

Thomas Dybdahl Ahle wrote:

> Problem is - I can't do that when I get killed.
> Isn't it possible to open processes in such a way like terminals? If I
> kill the terminal, everything open in it will die too.

On POSIX platform you can use signals and ``os.kill`` function.
Fo example:


import os, signal
from subprocess import Popen
from time import sleep

def handler(signum, frame):
print 'Signal handler called'
raise KeyboardInterrupt

signal.signal(signal.SIGTERM, handler)

try:
popen = Popen(["ping", "google.com"])
try:
sleep(100)
except KeyboardInterrupt:
pass
finally:
if popen.poll() is None:
print "killing process: %d" % popen.pid
os.kill(popen.pid, signal.SIGTERM)


--
HTH,
Rob

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


otsu threshold in python

2007-06-05 Thread azrael
Hy guys.
I'd like to ask you for a favour.
I tried several times to implement the otsu threshold filter in
python. but I failed every time. I found the soucre code i n Java from
the ImageJ project but I never worked in Java and there have been used
some built in Java functions which I don't know how they behave. I
also found the otsu threshold in the ia636 python module and would
like only this filter and don't want to import this library.
Is there anyone who wold like to help me. I need a function that takes
a list of 256 elements as an argument and returns the threshold values
for the threshold according to Otsu.

In addvance, I don't expect someone to do my homework. I really tried
it, I have been googling and didn't find a standalone function. I
wasn't able write a standalone function because I don't understand the
Otsu method. I just know that it works well and that I need it.

If there is no one that wants to help me with this problem, can
someone at least explain me in a detailed way how to implement it.

Thanks

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


Basic Auth for simple web server

2007-06-05 Thread Marco Aloisio
Hi, I'm a Python newbie; 
I have to write a simple webserver, and I need to
implement a basic authentication as specified in the RFC2617. 
I wonder if there is a Python library for doing that.

Thanks!

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


Beginning Python

2007-06-05 Thread abhiee
Hello , I have just begun learning python...and I'm loving it...Just
wanted to ask you that how much time would it take me to learn python
completely and which languages should i learn alongwith python to be a
good professional programmer?...Now i only know C
thanx in advance!

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


Re: Logging: how to suppress default output when adding handlers?

2007-06-05 Thread Vinay Sajip
On Jun 5, 2:44 pm, Chris Shenton <[EMAIL PROTECTED]> wrote:
> I am setting up handlers to log DEBUG and above to a rotating file and
> ERROR and above to console.  But if any of my code calls a logger
> (e.g.,logging.error("foo")) before I setup my handlers, thelogging
> system will create a default logger that *also* emits logs, which I
> can't seem to get rid of.  Is there a way I can suppress the creation
> of this default logger, or remove it when I 'm setting up my handlers?
> Thanks.

The default handler is created because you are calling the convenience
functions of the logging package: logging.error, etc. If you don't
want the default handler to be created, either

(a) Configure the logging system yourself before any logging call is
made (I'm not sure why you're not doing this - it could be done in
your main script before anything else happens) - or
(b) Make calls on a specific named logger, e.g.
logging.getLogger("logtest2").error("foo"), rather than
logging.error("foo") which is for casual/unsophisticated use only.

Regards,

Vinay Sajip

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


Re: *Naming Conventions*

2007-06-05 Thread Michael Hoffman
Neil Cerutti wrote:

> I find i and j preferable to overly generic terms like "item."

Well, I probably wouldn't use "item" in a real example, unless it were 
for a truly generic function designed to act on all sequences.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5.1 broken os.stat module

2007-06-05 Thread Joe Salmeri
> But that perspective is not directly relevant to *your* topic line.  When
> you make a claim that os.stat is 'broken' and bugged, you are making a
> claim about the *programmer* experience -- in particular, experiencing a
> discrepancy between performance and reasonable expectation based on the
> manuals.  Martin and I are both concerned about that particular claim
> (which now appears to be resolved in the negative).

The subject line reflects what *originally* appeared to be the source of the 
problem since a comparison of the results did not match previous Python 
versions.

For other developers that run into this difference (which did not occur 
before) I believe it is benefitial to them to understand why the difference 
is now occurring and why BOTH Python and Windows are displaying CORRECT 
results even though they do NOT match what they display.

For those same developers, I also posted a localtime_windows much which 
allows them to massage the values returned by Python localtime so that they 
match the values that Windows displays if they have the need and/or 
requirement to do so.

Often times in development what "appears" to be the source of the problem 
turns out that it is not the actual problem that is occurring.

It is still beneficial to have that link from what "appears" to be the 
problem to the details of what "actually" is the source of the problem.

For another developer that runs into this difference their most likely 
initial conclusion would be that something in Python 2.5.1 is broke 
especially when they research the changes in Python 2.5.1 and find that 
os.stat was changed.  As a general rule, when something is broke, suspect 
the last thing that you did even if it does not seem like it should be the 
source of the problem.

> Python developers cannot fix that.  Besides which, Python is a
> cross-platform language, originally developed on *nix.

Really, I thought they could fix anything :-)



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


Re: subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Den Tue, 05 Jun 2007 07:06:15 -0700 skrev Rob Wolfe:

> Thomas Dybdahl Ahle wrote:
> 
>> Problem is - I can't do that when I get killed. Isn't it possible to
>> open processes in such a way like terminals? If I kill the terminal,
>> everything open in it will die too.
> 
> On POSIX platform you can use signals and ``os.kill`` function. Fo
> example:
> 
> 
> import os, signal
> from subprocess import Popen
> from time import sleep
> 
> def handler(signum, frame):
> print 'Signal handler called'
> raise KeyboardInterrupt
> 
> signal.signal(signal.SIGTERM, handler)
> 
> try:
> popen = Popen(["ping", "google.com"]) try:
> sleep(100)
> except KeyboardInterrupt:
> pass
> finally:
> if popen.poll() is None:
> print "killing process: %d" % popen.pid os.kill(popen.pid,
> signal.SIGTERM)
> 

But you can't ever catch sigkill.
Isn't there a way to make sure the os kills the childprocess when the 
parrent dies?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *args and **kwargs

2007-06-05 Thread BartlebyScrivener
On Jun 5, 7:31 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> JonathanB wrote:
> > Ok, this is probably definitely a newbie question, but I have looked
> > all over the Python library reference material and tutorials which I
> > can find online and I cannot find a clear definition of what these are
> > and more importantly how to use them.

Also, well maybe op did not check THE tutorial. Or found explanation
too terse. But it's there.

http://docs.python.org/tut/node6.html#SECTION00660

rd




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


Re: Basic Auth for simple web server

2007-06-05 Thread Michele Simionato
On Jun 5, 4:28 pm, Marco Aloisio <[EMAIL PROTECTED]> wrote:
> Hi, I'm a Python newbie;
> I have to write a simple webserver, and I need to
> implement a basic authentication as specified in the RFC2617.
> I wonder if there is a Python library for doing that.
>
> Thanks!
>
> --
> Marco Aloisio


Have a look at paste (http://pythonpaste.org/).

For instance, to enable authentication for user foo, you can do the
following

from paste.auth.basic import AuthBasicHandler

def only_for_foo(env, user, passwd):
return user == 'foo' and passwd = 'bar'

auth_app = AuthBasicHandler(
myapp, 'app realm', only_for_foo)

(where myapp is your WSGI application, of course).


 Michele Simionato

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


RE: Please help on Binary file manipulation

2007-06-05 Thread Looney, James B
Pieter,
I've found when I have questions like this, that thinking about how I'd
do it in C/C++, then searching on some of those key words leads me to a
Python equivalent solution, or at least heading down the right path.
 
In this case, I believe you'll find the "file" module helpfull.  You can
read/seek on a number of bytes.  
 
I don't know how you'd do the playback specifically, but my guess is
you'll use a loop to create new files, so use a similar loop for
playback.
 
-JB
 




From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Pieter Potgieter
Sent: Tuesday, June 05, 2007 2:43 AM
To: python-list@python.org
Subject: Please help on Binary file manipulation


Hi all
I have a binary file of about 600kbytes - I want to break it up
in file chunks of 1085 bytes - every file must have a new file name.
The data is binary video frames (370 frames) - I want to play
the data back into an embedded system frame/file by file.
I am a complete Python newby - but have C/C++ skills.
Please supply/help me with an snippet or example 
Thanks
Pieter



*** 

Disclaimer: The information contained in this communication is
confidential and may be legally privileged. 

It is intended solely for the use of the individual or entity to
whom it is addressed and others authorised to receive it. 

Any review, retransmission, dissemination, copying, disclosure
or other use of, or taking of any action in reliance upon, this
information by person or entities other then the intended recipient is
prohibited. 

If you have received this message in error, please notify the
sender immediately by e-mail, facsimile or telephone and return and/or
destroy the original message and all copies from any computer. 



Denel (Pty) Ltd exercises no editorial control over e-mail
messages originating in the organisation and does not accept any
responsibility for either the contents of the message or any copyright
laws that may have been violated by the person sending this message. 

Denel (Pty) Ltd is neither liable for the proper and complete
transmission of the information contained in this communication nor any
delay in its receipt. 

This message should not be copied or used for any purpose other
than intended, nor should it be disclosed to any other person. 



*** 



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

Re: *Naming Conventions*

2007-06-05 Thread Ninereeds
Google Groups appears to have thrown away my original reply, so sorry
if this appears twice...

On Jun 4, 9:51 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:

> 'i' and 'j' are the canonical names for for loops indices in languages
> that don't support proper iteration over a sequence. Using them for
> the iteration variable of a Python for loop (which is really a
> 'foreach' loop) would be at best confusing.

Without wanting to start a religious war, I disagree.

In practice, I believe most programmers associate those short names
with pretty much any loop

variable, irrespective of data type, based primarily on the simple
fact that it's looping

over a set of values whose meaning is obvious from context. That
declaration is made after

decades of working with other peoples code as well as my own.

Don't believe me? Take a look at some code that uses C++ iterators,
for example, or some C

code that uses pointers as iterators, or some Ada code that loops over
an enumerated type,

etc etc. It won't find you long to realise that 'i' and 'j' are very
common names for those

too.

I've seen 'i' used in "iterations" over lists in Scheme, OCaml and
Haskell, whether done

using tail recursion or list comprehensions or whatever. 'x' is more
common, as with 'x:xs'

patterns used to pick the head 'x' from a list in OCaml or Haskell,
but then 'x' looks

scarily like an ordinate we can't have that ;-)

Anyway, why should 'indexes' always be numeric...

> >   for i in validanswers:
> > if myAnswers.current in myAnswers.validList [i]:
> >   MyOptions['style'] = i
>
> And this is *exactly* what one should not do in Python. If you want a
> generic name here, use 'item' instead.

In this code, 'i' is appears to be just an answer identifier. It is
used to identify for

which answer in the validList you are looking for. It may well even be
a numeric index (or

some other kind of key), from what we can see in the example.

"item" says nothing that "i" does not. If nothing else, you could
always say that 'i' is

short for 'item' or 'id' or whatever.

> since the use of 'self' is mandatoy.

That is true, making 'm' prefixes pointless in Python, but that's what
comes from working

with many different language. You don't always keep them neatly
compartmentalised in your

head. Habits can be very strong, and there is not always any strong
reason to try to break

them. Which is why you will still occasionally see 'm' prefixes in
Python code.

Actually, in *my* Python code you're still more likely to see
'f' (standing for field)

prefixes - a convention I adopted in C++ at a time when I thought 'm'
better suited macros,

and when I'd never yet seen the 'm' for member prefix since most C++
code I'd seen still used

the Hungarian conventions. It's a bad habit that I still haven't fully
broken.

> 1/ parameters names *are* local

As they are in C and C++. Not just in terms of scoping, but in terms
of being local variables

too...

  int factorial (int p)
  {
int l = 1;
while (p > 1)  {  l *= p;  p--;  }
return l;
  }

  def factorial (p) :
l = 1
while p > 1 : l *= p; p -= 1
return l

Updating parameters when you could just as easily update locals is of
course bad style in

either language - and some would say that any updating of parameters
is bad style - but the

point is that C and Python do the same thing.

This example does illustrate another useful fact about the 'l' and 'p'
prefixes - there are

times when the prefix is all you need to specify the whole name, since
there really is

nothing else that can be usefully be said.

> 2/ pythonic methods and functions tends to be short, so you usually
> know which names are params.

Well written functions and methods in any language tend to be short,
but even so, there are

times when a convention that distinguishes the two kinds of names
without needing to think up

distinct names is convenient. I wasn't suggesting that this convention
should be universally

adopted in Python or that it was relevant to Thorstens example even -
but it is common in

many languages (not just C++), and it does sometimes help resolve the

how-can-I-give-these-meaningfully-different-names issue.

> Python has a pretty good support for computed attributes (look for
> 'property'), so you don't need explicit getters/setters.

I may not use Python as my first and only language, but I have been
using it since version

1.4 and I am perfectly aware of properties in Python, as I am in other
languages. I am aware,

for example, that they are relatively new additions to the language,
that they are not used

in a lot of code, and that you still need named getter and setter
functions to redirect the

property access to even if these names are only referred to in the
property definition.

All of which is mostly besides the point. More and more programmers
are multilingual these

days, and scripting languages such as Python are more likely second
languages than first.

Having a hard rule 

Re: Beginning Python

2007-06-05 Thread kyosohma
On Jun 5, 9:29 am, abhiee <[EMAIL PROTECTED]> wrote:
> Hello , I have just begun learning python...and I'm loving it...Just
> wanted to ask you that how much time would it take me to learn python
> completely and which languages should i learn alongwith python to be a
> good professional programmer?...Now i only know C
> thanx in advance!

I think a more accurate question would be "how long does it take to
learn python so I don't have to look stuff up constantly". Knowing any
language completely is nigh impossible unless you designed it
yourself. However, I must say that learning Python so that you can
just start programming well without always going for help is quite
easy. I would think it would take 1-3 months depending on your ability
to suck in information and the amount of time you actually program.

As I understand it, the top languages are still Java and C++, with
COBOL being a major player in insurance/business environments. I would
recommend pretty much any web language as more and more is heading
towards the online world. Thus, Java/Javascript, PHP, Perl, CSS, CGI,
etc are good to know.

Check out this interesting graph on computer language trends:
http://www.cs.berkeley.edu/~flab/languages.html

Mike

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


Re: Beginning Python

2007-06-05 Thread Michael Bentley

On Jun 5, 2007, at 9:29 AM, abhiee wrote:

> Hello , I have just begun learning python...and I'm loving it...Just
> wanted to ask you that how much time would it take me to learn python
> completely and which languages should i learn alongwith python to be a
> good professional programmer?...Now i only know C
> thanx in advance!

How long is a piece of rope?

Seriously, there is no way for anyone to predict how long it will  
take you to learn something.  In this case, that something (Python)  
is a moving target -- there are a few things I use daily that weren't  
even part of the language when I started.

I do believe that it takes about three years to get reasonably  
competent at anything.  And about ten years to get really good at it.  
And probably another ten years to be a master (I'm only guessing  
though -- because I haven't been doing anything for twenty years  
yet).  Of course, by my metrics I guess even Guido wouldn't be a  
master at Python so perhaps I'm full of crap :-)

Hope this helps,
Michael

---
"I use tuples simply because of their mellifluous appellation." -- 
Neil Cerutti



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


Re: otsu threshold in python

2007-06-05 Thread Hyuga
On Jun 5, 10:19 am, azrael <[EMAIL PROTECTED]> wrote:
> Hy guys.
> I'd like to ask you for a favour.
> I tried several times to implement the otsu threshold filter in
> python. but I failed every time. I found the soucre code i n Java from
> the ImageJ project but I never worked in Java and there have been used
> some built in Java functions which I don't know how they behave. I
> also found the otsu threshold in the ia636 python module and would
> like only this filter and don't want to import this library.
> Is there anyone who wold like to help me. I need a function that takes
> a list of 256 elements as an argument and returns the threshold values
> for the threshold according to Otsu.
>
> In addvance, I don't expect someone to do my homework. I really tried
> it, I have been googling and didn't find a standalone function. I
> wasn't able write a standalone function because I don't understand the
> Otsu method. I just know that it works well and that I need it.
>
> If there is no one that wants to help me with this problem, can
> someone at least explain me in a detailed way how to implement it.
>
> Thanks

What is the whole assignment meant to accomplish?  Is the assignment
to implement the Otsu method?  If so, you shouldn't be trying to find
library functions.  Or is it just something you need for some larger
task?

I would ask exactly what problems you're running into, but:
> it, I have been googling and didn't find a standalone function. I
> wasn't able write a standalone function because I don't understand the
> Otsu method. I just know that it works well and that I need it.

How do you know you need it?  Did you learn about this in class?  And
if so, are you expected to understand it?
I've never even heard of it, but I googled it, and found the fourth
hit pretty good: 
http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MORSE/threshold.pdf
This gives a reasonable explanation.  I couldn't tell you *exactly*
why it works, but it's understandable enough from that that I can see
that it should work, and to see how to implement it.

Not to mention that the above PDF basically *gives* you the
implementation for free (just make sure not to miss the recurrence
relations at the end of the section on the Otsu method, or else you'll
be screwing yourself).

So give that a look and see if it helps.

Hyuga

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


Sending cookies with python. When download with python

2007-06-05 Thread moishyyehuda
I need to download files off a password protected website. So if I try
to download files off the site with python I will be blocked. Is there
anyway to send cookies with python. So I will be authenticated.

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


Tkinter, tkMessagebox and overrideredirect

2007-06-05 Thread marcoberi
Hi everybody.

I have this code snippet that shows a window without a titlebar (using
overrideredirect) and two buttons on it: one quits and the other one
brings up a simple tkMessageBox.
On Windows (any flavour) the tkMessagebox brings up over the
underlying window.
On Linux (apparently any flavour) the tkMessagebox brings up under the
underlying window.
You can drag the popup window near the main window to discover if it's
over or under it.
Obviously I would like to show a popup that is over the main window!
Before asking I tried, I read, I googled, I pulled my hair off, but no
avail...
Any hints?
Thanks a lot for your time.
Ciao.
Marco.

import tkMessageBox
from Tkinter import *

class App():
def __init__(self):
self.root = Tk()
self.root.overrideredirect(1)
self.frame = Frame(self.root, width=320, height=200,
   borderwidth=5, relief=RAISED)
self.frame.pack_propagate(False)
self.frame.pack()
self.bQuit = Button(self.frame, text="Quit",
command=self.root.quit)
self.bQuit.pack(pady=20)
self.bHello = Button(self.frame, text="Hello",
command=self.hello)
self.bHello.pack(pady=20)

def hello(self):
tkMessageBox.showinfo("Popup", "Hello!")

app = App()
app.root.mainloop()

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


Re: itertools.groupby

2007-06-05 Thread [EMAIL PROTECTED]
On May 27, 7:50 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> The groupby itertool came-out in Py2.4 and has had remarkable
> success (people seem to get what it does and like using it, and
> there have been no bug reports or reports of usability problems).

With due respect, I disagree.  Bug ID #1212077 is either a bug report
or a report of a usability problem, depending on your point of view.
You may disagree on whether or not this is a problem that needs to be
be fixed, but it *is* a report.

http://sourceforge.net/tracker/index.php?func=detail&aid=1212077&group_id=5470&atid=105470


I think the semantics of the itertools groupby are too tricky for
naive users--I find them confusing myself, and I've been using Python
for quite a while.  I still hope that Python will someday gain a
groupby function suitable for ordinary use.  Until that happens, I
recommend the following cookbook entry:

# from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259173

class groupby(dict):
def __init__(self, seq, key=lambda x:x):
for value in seq:
k = key(value)
self.setdefault(k, []).append(value)
__iter__ = dict.iteritems


Mike

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


Re: Who uses Python?

2007-06-05 Thread walterbyrd
On Jun 5, 3:01 am, Maria R <[EMAIL PROTECTED]> wrote:
> I tend to agree with some earlier poster that if you use Python you
> are, in a sense, a programmer :o)
>

Yes, in a sense. But, in another sense, that is sort of like saying
that people who post on message boards are "writers."

I should have been more clear, when I posted "programmers" I meant
"professional programmers" i.e. people who develop software
applications for a living.

I am getting the idea that most python "programmers" use python more
like a tool, rather than as their primary specialization. In other
words, python is usually not the primary specialization. I think this
is different than other languages, such as Java, or even PHP. Few
python users are specifically "python programmers" rather, they are
data analysts, scientists, etc. who use python in the same way that
some might use excel - as a tool.

 BTW: I am seriously impressed with the stuff that many here are doing
with python. And I would like to thank those who responded to my
post.

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


Re: Who uses Python?

2007-06-05 Thread [EMAIL PROTECTED]
walterbyrd wrote:
> On Jun 5, 3:01 am, Maria R <[EMAIL PROTECTED]> wrote:
> > I tend to agree with some earlier poster that if you use Python you
> > are, in a sense, a programmer :o)
> >
>
> Yes, in a sense. But, in another sense, that is sort of like saying
> that people who post on message boards are "writers."
>
> I should have been more clear, when I posted "programmers" I meant
> "professional programmers" i.e. people who develop software
> applications for a living.
>
> I am getting the idea that most python "programmers" use python more
> like a tool, rather than as their primary specialization. In other
> words, python is usually not the primary specialization. I think this
> is different than other languages, such as Java, or even PHP.

Good professional programmers don't have a single language.  That's
true even of Java programmers.  PHP is an odd case; there are good PHP
programmers, but there's also a large group of people who aren't
really trained as programmers at all (despite writing PHP for a
living) for whom it's the only language they kind-of know.  The same
thing exists in other languages, but in my experience it's a fair bit
more common in the PHP world.

> Few python users are specifically "python programmers" rather, they are
> data analysts, scientists, etc. who use python in the same way that

FWIW, the majority of my paid work day is spent developing Python code
(or doing ancillary work common to all software projects--gathering
requirements, design, testing, etc), and it's the 3rd job in a row
(going back to 1999) where I've done a significant amount of Python
coding for work.  The prior two also involved a fair amount of C,
Java, and Perl as well.

I wouldn't call myself specifically a "Python programmer", but I
wouldn't have called myself specifically a "C programmer" 10 years
ago--and when I'm hiring, it's much more important to me to find a
good programmer than to find a programmer who knows Python (or
whatever other system is in use).  Programming as a skill is largely
independent of any single language, but that's not a Python-centric
statement.

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


Re: itertools.groupby

2007-06-05 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> On May 27, 7:50 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> > The groupby itertool came-out in Py2.4 and has had remarkable
> > success (people seem to get what it does and like using it, and
> > there have been no bug reports or reports of usability problems).
>
> With due respect, I disagree.  Bug ID #1212077 is either a bug report
> or a report of a usability problem, depending on your point of view.
> You may disagree on whether or not this is a problem that needs to be
> be fixed, but it *is* a report.
>
> http://sourceforge.net/tracker/index.php?func=detail&aid=1212077&group_id=5470&atid=105470
>
>
> I think the semantics of the itertools groupby are too tricky for
> naive users

Itertools isn't targeted primarily at naive users.  It can be useful
to them, but it's really there to allow sophisticated work on
iterables without reading them all in at once (indeed, it works
properly on infinite iterables).  That's pretty much _the_ defining
characteristic of itertools

Anyone who's doing that knows you can't do infinite lookahead, so you
can't do a sort or a group-by over the entire data set.  IOW, for
anyone who would be looking to use itertools for what it's designed
for, the kind of operation you specify below would be very unexpected.

>--I find them confusing myself, and I've been using Python
> for quite a while.  I still hope that Python will someday gain a
> groupby function suitable for ordinary use.  Until that happens, I
> recommend the following cookbook entry:
>
> # from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259173
>
> class groupby(dict):
> def __init__(self, seq, key=lambda x:x):
> for value in seq:
> k = key(value)
> self.setdefault(k, []).append(value)
> __iter__ = dict.iteritems

The itertools groupby is incredibly useful for writing SQL object
mappers.  It's exactly what I wanted when I first started looking in
itertools to see if there was a way to consolidate rows.

Also, that recipe goes against the spirit of itertools--if I'm going
out of my way to use itertools, it usually means I may be working with
very large data sets that I can't read into memory.  It's a useful
recipe, but it's also likely to be unusable in the context of
itertools-related problem domains.

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


Re: Sending cookies with python. When download with python

2007-06-05 Thread Yongjian Xu

yes. urllib2 has Request class that compose html headers (dict object) into
a request object where you can put Cookie: header into it. Also, there are a
few Cookie related modules you can use too.

An example using urllib2 can be something like this:

def myrequest(url):
  req = urllib2.Request(url)
  headers = {'Cookie':'cookies','some_other_headers':'contents'}
  for k,v in headers.iteritems():
 req.add_header(k,v)
  return req

Hope it helps.
Jim

On 6/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


I need to download files off a password protected website. So if I try
to download files off the site with python I will be blocked. Is there
anyway to send cookies with python. So I will be authenticated.

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





--
Yongjian (Jim) Xu
===
Sysops
-- 
http://mail.python.org/mailman/listinfo/python-list

ANN: matplotlib 0.90.1 graphing package

2007-06-05 Thread [EMAIL PROTECTED]
matplotlib-0.90.1 has just been released.  matplotlib is a graphing
package for python which can be used interactively from the python
shell ala Mathematica or Matlab, embedded in a GUI application, or
used in batch mode to generate graphical hardcopy, eg in a web
application server.  Many raster and vector outputs are supported
(PNG, SVG, PDF, PS, and more).  You can get the source release, eggs
and binary builds for OS X and windows at the download link below

homepage:  http://matplotlib.sourceforge.net/
what's new:   http://matplotlib.sourceforge.net/whats_new.html
screenshots: http://matplotlib.sourceforge.net/screenshots.html
tutorial: http://matplotlib.sourceforge.net/tutorial.html
mailing list: 
http://sourceforge.net/mailarchive/forum.php?forum_name=matplotlib-users
downloads: 
http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=82474


The CHANGELOG entries for the 0.90.1 release are below -- see the
what's new link above for an overview

Thanks,
John Hunter

==
2007-06-02 Released 0.90.1 at revision 3352

2007-06-02 Display only meaningful labels when calling legend()
  without args. - NN

2007-06-02 Have errorbar follow the color cycle even if line is not
plotted.
  Suppress plotting of errorbar caps for capsize=0. - NN

2007-06-02 Set markers to same alpha value as line. - NN

2007-06-02 Fix mathtext position in svg backend. - NN

2007-06-01 Deprecate Numeric and numarray for use as numerix. Props to
  Travis -- job well done. - ADS

2007-05-18 Added LaTeX unicode support. Enable with the
  'text.latex.unicode' rcParam. This requires the ucs and
  inputenc LaTeX packages. - ADS

2007-04-23 Fixed some problems with polar -- added general polygon
  clipping to clip the lines a nd grids to the polar axes.
  Added support for set_rmax to easily change the maximum
  radial grid.  Added support for polar legend - JDH

2007-04-16 Added Figure.autofmt_xdate to handle adjusting the bottom
  and rotating the tick labels for date plots when the ticks
  often overlap - JDH

2007-04-09 Beginnings of usetex support for pdf backend. -JKS

2007-04-07 Fixed legend/LineCollection bug. Added label support
  to collections. - EF

2007-04-06 Removed deprecated support for a float value as a gray-
scale;
  now it must be a string, like '0.5'.  Added alpha kwarg to
  ColorConverter.to_rgba_list. - EF

2007-04-06 Fixed rotation of ellipses in pdf backend
  (sf bug #1690559) -JKS

2007-04-04 More matshow tweaks; documentation updates; new method
  set_bounds() for formatters and locators. - EF

2007-04-02 Fixed problem with imshow and matshow of integer arrays;
  fixed problems with changes to color autoscaling. - EF

2007-04-01 Made image color autoscaling work correctly with
  a tracking colorbar; norm.autoscale now scales
  unconditionally, while norm.autoscale_None changes
  only None-valued vmin, vmax. - EF

2007-03-31 Added a qt-based subplot-adjustment dialog - DSD

2007-03-30 Fixed a bug in backend_qt4, reported on mpl-dev - DSD

2007-03-26 Removed colorbar_classic from figure.py; fixed bug in
  Figure.clf() in which _axobservers was not getting
  cleared.  Modernization and cleanups. - EF

2007-03-26 Refactored some of the units support -- units now live in
  the respective x and y Axis instances.  See also
  API_CHANGES for some alterations to the conversion
  interface.  JDH

2007-03-25 Fix masked array handling in quiver.py for numpy. (Numeric
  and numarray support for masked arrays is broken in other
  ways when using quiver. I didn't pursue that.) - ADS

2007-03-23 Made font_manager.py close opened files. - JKS

2007-03-22 Made imshow default extent match matshow - EF

2007-03-22 Some more niceties for xcorr -- a maxlags option, normed
  now works for xcorr as well as axorr, usevlines is
  supported, and a zero correlation hline is added.  See
  examples/xcorr_demo.py.  Thanks Sameer for the patch.  -
  JDH

2007-03-21 Axes.vlines and Axes.hlines now create and returns a
  LineCollection, not a list of lines.  This is much faster.
  The kwarg signature has changed, so consult the docs.
  Modified Axes.errorbar which uses vlines and hlines.  See
  API_CHANGES; the return signature for these three functions
  is now different

2007-03-20 Refactored units support and added new examples - JDH

2007-03-19 Added Mike's units patch - JDH

2007-03-18 Matshow as an Axes method; test version matshow1() in
  pylab; added 'integer' Boolean kwarg to MaxNLocator
  initializer to force ticks at integer locations. - EF

2007-03-17 Preliminary support for clipping to paths agg - JDH

2007-03-17 Text.set_text() accepts anything convertible with '%s' - E

Re: Getting mount stats for filesystems

2007-06-05 Thread Mitko Haralanov
On Tue, 05 Jun 2007 09:19:08 +0200
"Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> I'm not quite sure what you want to achieve. You are on machine B,
> and you want to find out whether a remote file system (on machine A)
> is mounted remotely (say, from machine C)?

Ok, let me try to explain:

I am on machine A, which has a NFS mounted filesystem hosted on machine
B. All I need to find out is whether the NFS filesystem is mounted
using tcp or udp.

-- 
Mitko Haralanov  [EMAIL PROTECTED]
Senior Software Engineer 650.934.8064
System Interconnect Group   http://www.qlogic.com

==
 Paul: If rubbin' frozen dirt in your crotch is wrong, hey, 
 I don't wanna be right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: magic names in python

2007-06-05 Thread Lenard Lindstrom
Steven D'Aprano wrote:
> On Mon, 04 Jun 2007 22:19:35 +, Lenard Lindstrom wrote:
> 
>> What is "magic" about __init__ and __repr__? They are identifiers just 
>> like "foo" or "JustAnotherClass". They have no special meaning to the 
>> Python compiler. The leading and trailing double underscores represent 
>> no special incantation. It is just a naming convention.
> 
> That's not quite true, as you point out:

Disassemble the code object of a class statement. "__init__" is just an 
identifier, a Python name. So there is no "magic" here.

> 
>> So a number of method names like __init__ and __repr__ have a 
>> pre-defined usage. 
> 
> That makes them magic, in the best possible way.

I was careful to use the word "usage". Maybe I should have used 
"protocol" or "specification" here. A method named "write" is understood 
to have a particular definition and purpose. Is it "magic"? These 
methods are simply callbacks. And yes, these callbacks make Python flexible.

> 
> 
>> In every other respect they are just normal methods. 
> 
> That is *almost* true. Or, to put it another way, that is wrong. Some of
> the double-underscore magic methods are automatically called on the class
> instead of the instance, bypassing normal inheritance. 
> 

They exist as Python functions in the class dictionary. They have no 
hidden flags that distinguish them from other class level function 
attributes.

> 
 import new
 class Test(object):
>  def foo(self):
>  return "foo called from the class"
>  def __str__(self):
>  return "__str__ called from the class"
> 
 obj = Test()
 obj.foo()
> 'foo called from the class'
 str(obj) # calls obj.__str__
> '__str__ called from the class'
> 
> Now see what happens when we add methods to the instance.
> 
 obj.foo = new.instancemethod(
>  lambda self: "foo called from the instance", obj, Test)
 obj.foo()
> 'foo called from the instance'
 obj.__class__.foo(obj) # Check the method in the class is still there.
> 'foo called from the class'
> 
> So calling a random method like foo() goes through the usual procedure:
> check the instance, then check the class. Now let's try it with a magic
> method.
> 
> 
 obj.__str__ = new.instancemethod(
>  lambda self: "__str__ called from the instance", obj, Test)
 obj.__str__()
> '__str__ called from the instance'
 str(obj) # calls obj.__str__() maybe?
> '__str__ called from the class'
> 

Yes, method lookup for an operation differs from attribute lookup in 
new-style classes. But it is a property of new-style classes, not the 
methods themselves. For instance, classic classes behave differently:

 >>> class Test:
def __str__(self):
return "__str__ called from the class"


 >>> obj = Test()
 >>> obj.__str__()
'__str__ called from the class'
 >>> str(obj)
'__str__ called from the class'
 >>> obj.__str__ = new.instancemethod(
lambda self: "__str__ called from the instance", obj, Test)
 >>> str(obj)
'__str__ called from the instance'
 >>> obj.__class__.__str__(obj)
'__str__ called from the class'


I do admit that the special methods are given special treatment by the 
type and ClassType types to ensure they are called by their 
corresponding operations. But this special treatment is restricted to 
the types themselves. In CPython an extension type can be written from 
scratch that treats special methods exactly as a new-style class does. 
Or an extension type can implement a completely novel approach. The 
point is, at some level, the machinery which defines special method 
"magic" is accessible to the programmer. So is it really "magic" or 
advanced technology?

This comes down to the original posting not defining a "magic name". It 
does not mention what is so objectionable about __init__ and __repr__. I 
am claiming they are not as "magical" as they may first appear.

--
Lenard Lindstrom
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting mount stats for filesystems

2007-06-05 Thread Martin v. Löwis
> I am on machine A, which has a NFS mounted filesystem hosted on machine
> B. All I need to find out is whether the NFS filesystem is mounted
> using tcp or udp.

Ah, ok. I recommend to parse /proc/mounts.

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


Re: url encode

2007-06-05 Thread Yongjian Xu

you can take a look urlib.quote or quote_plus methods.

Jim

On 6/5/07, Lee Jones <[EMAIL PROTECTED]> wrote:


 Hello,



I am trying to urlencode a string.  In python the only thing I can see is
the urllib.urlencode().  But this takes a dictionary, and returns
"key=value", which is not what I want.  I only want to url-encode a string.
Does any one know how to do this in python

Thanks

Lee





Lee Jones,

Software Developer

*SecureTrading Ltd*
European Operations Centre
Parc Menai
Bangor
Gwynedd LL57 4BL
T: 01248 672 028
F: 01248 672 099

www.securetrading.com



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





--
Yongjian (Jim) Xu
===
Sysops
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Sending cookies with python. When download with python

2007-06-05 Thread Matimus
On Jun 5, 9:14 am, [EMAIL PROTECTED] wrote:
> I need to download files off a password protected website. So if I try
> to download files off the site with python I will be blocked. Is there
> anyway to send cookies with python. So I will be authenticated.

Yes. I haven't done it but I know you should be looking at urllib2 and
cookielib. I'm sure you can find some examples online. Dive Into
Python (google it) has some examples that may help you get started
with more general purpose  use of urllib2.

Matt

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


Re: Python for embedded systems with memory constraints

2007-06-05 Thread Jürgen Urner
Who else is using python (programmers, scientists, finance)?

Me! Graduated in fine arts. Python is what I do when I am fed up with
all those colors. Much easier to manufacture sense with.




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


Re: itertools.groupby

2007-06-05 Thread BJörn Lindqvist
On 27 May 2007 10:49:06 -0700, 7stud <[EMAIL PROTECTED]> wrote:
> On May 27, 11:28 am, Steve Howell <[EMAIL PROTECTED]> wrote:
> > The groupby method has its uses, but it's behavior is
> > going to be very surprising to anybody that has used
> > the "group by" syntax of SQL, because Python's groupby
> > method will repeat groups if your data is not sorted,
> > whereas SQL has the luxury of (knowing that it's)
> > working with a finite data set, so it can provide the
> > more convenient semantics.
> > The groupby method has its uses
>
> I'd settle for a simple explanation of what it does in python.

Here is another example:

import itertools
import random

dierolls = sorted(random.randint(1, 6) for x in range(200))

for number, numbers in itertools.groupby(dierolls):
number_count = len(list(numbers))
print number, "came up", number_count, "times."

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: c[:]()

2007-06-05 Thread Warren Stringer
Roland Puntaier [mailto:[EMAIL PROTECTED]
> Warren, can you please restate your point.

Hey Roland, where were you a few days ago ;-) I think most suggestions were
valid, in their own context. Only yesterday, was I finally able to get it in
perspective, so here goes:

There are two idioms: a domain specific language, called Tr3
http://muse.com/tr3/Tr3%20Overview.pdf , and Python. The idioms both
complement each other and conflict. Most of this thread has explored that
conflict.

Tr3 has three main components: a namespace tree, a directed graph of inputs
and a directed graph of outputs. By analogy: the namespace functions like
XML, inputs function like callbacks, and outputs function like standard
procedures. 

The precursor to Tr3 was written C++. The inputs were script while the
outputs were in C++. So, any changes in procedure required a recompile. The
new version still allows C++ plugins, but the procedures can be written in
Python.

Inputs to Tr3 are queries to other parts of the namespace. By analogy,
inputs behave like an Xpath query. So `a//z` searches for all descendants of
`a` named `z`. The results of a query yields a list that can change state
for the node on the tree which made the query. Another example, more in line
with the title of this thread, is the query  `a[:4]b`, which returns a list
`[a[0].b, a[1].b, a[2].b, a[3].b]`

Outputs are Python. This thread was my way of exploring to what degree that
the `a[:4]b` of inputs could be applied to outputs as `a[:4]b()`. It would
be idiomatic to Tr3 but not as idiomatic to Python. Here's why:

What should this mean?
if a[:4]b():  .

Should it mean:
if a[0].b() and a[1].b() and a[2].b() and a[3].b(): .
or
if a[0].b() or a[1].b() or a[2].b() or a[3].b(): .
or
if a[0].b(): .
if a[1].b(): .
if a[2].b(): .
if a[3].b(): .

Each interpretation could be justified. Thus, the implicit iteration is
ambiguous. 

I am porting code that only uses this form
a[:4]b()

Which translates to:

for i in range(4):  
a[i].b()

There is only one interpretation and thus unambiguous.

I have also explored writing client code that interprets  `a[:4]b` as:
 if a[0].b() and a[1].b() and a[2].b() and a[3].b(): .
A few algorithms, like Huffman codes, wind up looking much simpler, with
implicit iterators. Be that as it may, making such algorithms easier to read
may not be worth the cost of adding ambiguity to a general purpose
procedural language. 

So, you're all right. Relax. Get outdoors. Fall in love. Make someone happy.

And thanks again,

\~/

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


Re: Getting mount stats for filesystems

2007-06-05 Thread Mitko Haralanov
On Tue, 05 Jun 2007 20:14:01 +0200
"Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> Ah, ok. I recommend to parse /proc/mounts.

I was looking for something that reminded me less of Perl and more of C
but haven't been able to find such a method.

-- 
Mitko Haralanov  [EMAIL PROTECTED]
Senior Software Engineer 650.934.8064
System Interconnect Group   http://www.qlogic.com

==
... A booming voice says, "Wrong, cretin!", and you notice that you
have turned into a pile of dust.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you htmlentities in Python

2007-06-05 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Matimus  <[EMAIL PROTECTED]> wrote:
>On Jun 4, 6:31 am, "js " <[EMAIL PROTECTED]> wrote:
>> Hi list.
>>
>> If I'm not mistaken, in python, there's no standard library to convert
>> html entities, like & or > into their applicable characters.
>>
>> htmlentitydefs provides maps that helps this conversion,
>> but it's not a function so you have to write your own function
>> make use of  htmlentitydefs, probably using regex or something.
>>
>> To me this seemed odd because python is known as
>> 'Batteries Included' language.
>>
>> So my questions are
>> 1. Why doesn't python have/need entity encoding/decoding?
>> 2. Is there any idiom to do entity encode/decode in python?
>>
>> Thank you in advance.
>
>I think this is the standard idiom:
>
 import xml.sax.saxutils as saxutils
 saxutils.escape("&")
>'&'
 saxutils.unescape(">")
>'>'
 saxutils.unescape("A bunch of text with entities: & > <")
>'A bunch of text with entities: & > <'
>
>Notice there is an optional parameter (a dict) that can be used to
>define additional entities as well.
.
.
.
Good points; I like your mention of the optional entity dictionary.

It's possible that your solution is to a different problem than the original
poster intended.  http://wiki.python.org/moin/EscapingHtml > has de-
tails about HTML entities vs. XML entities.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python for industrial control (was: Who uses Python?)

2007-06-05 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> "walterbyrd" <[EMAIL PROTECTED]> wrote:
>
>> Anything else? Finance? Web-analytics? SEO? Digital art?
>
>Industrial control and alarm annunciation
.
.
.
Python can be *great* in these roles.  A couple of us launched
http://www.engcorp.com/acf/RecentChanges > to promote 
co-operation in the area.  While the Wiki has been moribund this
year, it would take little to bring it alive again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web development without using frameworks

2007-06-05 Thread Christoph Haas
On Tue, Jun 05, 2007 at 03:01:01PM -0400, Chris Stewart wrote:
> I'm interested in learning web based python without the use of fancy 
> frameworks
> that are out there.  I'm having a hard time coming up with resources and
> examples for this.  Does anyone have anything that could be helpful?

I'd say the only decent ways are either using a full-featured framework
(I favor Pylons) or write plain CGIs. Even for the later a look into
http://wiki.python.org/moin/WebFrameworks might be useful (I wouldn't
say that "web.py" is really a framework - and it's listed there). Or you
write plain-old CGIs with Python's "cgi" module. I have also started
like that but currently only use frameworks because the "cgi" module is
pretty limited (compared to what Perl offers) and for serious
applications not really the way to go.

My 2¢

 Christoph

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


web development without using frameworks

2007-06-05 Thread Chris Stewart

I'm interested in learning web based python without the use of fancy
frameworks that are out there.  I'm having a hard time coming up with
resources and examples for this.  Does anyone have anything that could be
helpful?

--
Chris Stewart
[EMAIL PROTECTED]
http://www.compiledmonkey.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000: Standard API for archives?

2007-06-05 Thread Chuck Rhode
Tim Golden wrote this on Mon, 04 Jun 2007 15:55:30 +0100.  My reply is
below.

> Chuck Rhode wrote:

>> samwyse wrote this on Mon, 04 Jun 2007 12:02:03 +.  My reply is
>> below.

>>> I think it would be a good thing if a standardized interface
>>> existed, similar to PEP 247.  This would make it easier for one
>>> script to access multiple types of archives, such as RAR, 7-Zip,
>>> ISO, etc.

>> Gee, it would be great to be able to open an archive member for
>> update I/O.  This is kind of hard to do now.  If it were possible,
>> though, it would obscure the difference between file directories
>> and archives, which would be kind of neat.  Furthermore, you could
>> navigate archives of archives (zips of tars and other
>> abominations).

> Just put something together a module called "archive" or whatever,
> which exposes the kind of API you're thinking of, offering support
> across zip, bz2 and whatever else you want. Put it up on the
> Cheeseshop, announce it on c.l.py.ann and anywhere else which seems
> apt. See if it gains traction.  Take it from there.

> NB This has the advantage that you can start small, say with zip and
> bz2 support and maybe see if you get contributions for less common
> formats, even via 3rd party libs. If you were to try to get it into
> the stdlib it would need to be much more fully specified up front, I
> suspect.

Yeah, this is in the daydreaming stages.  I'd like to maintain
not-just-read-only libraries of geographic shapefiles, which are
available free from governmental agencies and which are riddled with
obvious errors.  Typically these are published in compressed archives
within which every subdirectory is likewise compressed (apparently for
no other purpose than a rather vain attempt at flattening the
directory structure, which must be reconstituted on the User's end
anyway).  Building a comprehensive index to what member name(s) the
different map layers (roads, political boundaries, watercourses) have
in various political districts of varying geographic resolutions is
much more than merely frustrating.  I've given it up.  However, I
believe that once I've located something usable, the thing to do is
save a grand unified reference locator (GURL) for it.  The GURL would
specify a directory path to the highest level archive followed by a
(potential cascade of) archive member name(s for enclosed archives) of
the data file(s) to be operated on.  Unpacking and repacking would be
behind the scenes.  Updates (via FTP) of non-local resources would be
transparent, too.  I think, though, that notes about the publication
date, publisher, resolution, area covered, and format of the map or
map layer ought to be kept out of the GURL.

My whole appetite for this sort of thing would vanish if access to the
shapefiles were more tractable to begin with.

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. 1979 Honda Goldwing GL1000 (Geraldine)
.. Weather:  http://LacusVeris.com/WX
.. 52° — Wind N 9 mph — Sky overcast.
-- 
http://mail.python.org/mailman/listinfo/python-list

Does Boost.Python participate in cyclic gc?

2007-06-05 Thread skip
We encountered a situation today where it appeared that a
Boost.Python-provided class didn't participate in Python's cyclic garbage
collection.  The wrapped C++ instance held a reference to a method in the
Python object which referenced the Boostified C++ instance, e.g.:

class Foo:
def __init__(self, ...):
self.over_there = BoostifiedClass()
self.over_there.set_callback(self.boost_callback)
...

def boost_callback(self, ...):
...

When an instance of Foo went out of scope the BoostifiedClass instance it
referred to didn't disappear.  (We could tell because it made connections to
another server which didn't disappear.)  The solution was to recognize when
we where finished with it to set self.over_there to None.  It would be nice
if Boost.Python knew how to play in the gc sandbox, but I suspect it may
not.

Thx,

Skip

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


Re: Getting mount stats for filesystems

2007-06-05 Thread Martin v. Löwis
Mitko Haralanov schrieb:
> On Tue, 05 Jun 2007 20:14:01 +0200
> "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> 
>> Ah, ok. I recommend to parse /proc/mounts.
> 
> I was looking for something that reminded me less of Perl and more of C
> but haven't been able to find such a method.

You could try to invoke getmntent(3). I'm not aware of a Python wrapper
for it, so you either try to write one yourself in C, or use ctypes to
write it in Python.

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


Re: Logging: how to suppress default output when adding handlers?

2007-06-05 Thread Chris Shenton
Vinay Sajip <[EMAIL PROTECTED]> writes:

> The default handler is created because you are calling the convenience
> functions of the logging package: logging.error, etc. If you don't
> want the default handler to be created, either
>
> (a) Configure the logging system yourself before any logging call is
> made (I'm not sure why you're not doing this - it could be done in
> your main script before anything else happens) - or

Yeah, I think this is the cause.  Unfortunately I'm using a couple
dozen files and a bunch more libraries and if they're doing a
logging.debug() or whatnot they're creating this.  

Do you have any ideas how I can trace where the first call is made?
This seems a newbie question but if I have a bunch of other files
which do stuff like "from sqlalchemy import *" they might be invoking
a logging call so I'm not sure how to chase these down.

> (b) Make calls on a specific named logger, e.g.
> logging.getLogger("logtest2").error("foo"), rather than
> logging.error("foo") which is for casual/unsophisticated use only.

I'm dreading having to be so verbose with my (copious) loggers, which
is why I was curious if there was a way to nuke any auto-created
ones.  I thought calling logging.shutdown() before configuring my
loggers might do this but it didn't.  

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


Re: Who uses Python?

2007-06-05 Thread Stef Mientki
walterbyrd wrote:
> On Jun 5, 3:01 am, Maria R <[EMAIL PROTECTED]> wrote:
>> I tend to agree with some earlier poster that if you use Python you
>> are, in a sense, a programmer :o)
>>
> 
> Yes, in a sense. But, in another sense, that is sort of like saying
> that people who post on message boards are "writers."
> 
> I should have been more clear, when I posted "programmers" I meant
> "professional programmers" i.e. people who develop software
> applications for a living.

I've heard that 80% of what google is doing, is done in Python ;-)

I use Python as  a replacement for MatLab,
and intend to use it as replacement for Delphi, AutoIt, PHP, VB.
And I'ld love to use it as a replacement for micro controller programming.
The hardest to replace language is Delphi.
And all the work I perform with these languages is paid ;-)
The compagnies that only uses Python is growing.

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


Re: web development without using frameworks

2007-06-05 Thread [EMAIL PROTECTED]
On Jun 5, 9:24 pm, Christoph Haas <[EMAIL PROTECTED]> wrote:
> On Tue, Jun 05, 2007 at 03:01:01PM -0400, Chris Stewart wrote:
> > I'm interested in learning web based python without the use of fancy 
> > frameworks
> > that are out there.  I'm having a hard time coming up with resources and
> > examples for this.  Does anyone have anything that could be helpful?
>
> I'd say the only decent ways are either using a full-featured framework
> (I favor Pylons) or write plain CGIs. Even for the later a look 
> intohttp://wiki.python.org/moin/WebFrameworksmight be useful (I wouldn't
> say that "web.py" is really a framework - and it's listed there). Or you
> write plain-old CGIs with Python's "cgi" module. I have also started
> like that but currently only use frameworks because the "cgi" module is
> pretty limited (compared to what Perl offers) and for serious
> applications not really the way to go.
>


I can only second Christoph's answer. Using bare CGI, you'll rapidly
find you have to set up some common things like sessions, templating,
url to actions dispatch etc - IOW, reinventing the (square) wheel. So
unless your goal is to learn the "low-level" parts of web programming
(which is a very legitimate goal - as far as I'm concerned, I'd like
to see more 'web developpers' doing so), my advice is also to look for
a simple, flexible, non-intrusive framework (web.py and Pylons come to
mind).

My 2 (euro) cents.

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


Re: subprocess leaves child living

2007-06-05 Thread Rob Wolfe
Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes:

> But you can't ever catch sigkill.

There is no protection against sigkill.

> Isn't there a way to make sure the os kills the childprocess when the 
> parrent dies?

If the parent dies suddenly without any notification childprocesses
become zombies and there is no way to avoid that.

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


Re: subprocess leaves child living

2007-06-05 Thread Michael Bentley

On Jun 5, 2007, at 3:01 PM, Rob Wolfe wrote:

> Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes:
>
>> But you can't ever catch sigkill.
>
> There is no protection against sigkill.
>
>> Isn't there a way to make sure the os kills the childprocess when the
>> parrent dies?
>
> If the parent dies suddenly without any notification childprocesses
> become zombies and there is no way to avoid that.

Apologies for picking nits...

But actually *that* is an orphan process.  When a parent process dies  
and the child continues to run, the child becomes an orphan and is  
adopted by init.  Orphan processes can be cleaned up on most Unices  
with 'init q' (or something very similar).

Zombies on the other hand, are those processes that have completed  
execution but still have an entry in the process table.  The cause of  
zombies AFAIK, is a parent that has failed to call wait(2).  To clean  
up zombies, you can send a SIGCHLD signal to the parent process --  
probably with 'kill -17' (but use 'kill -l' to find out what it is on  
your system).

hth,
Michael
---
"I would rather use Java than Perl. And I'd rather be eaten by a  
crocodile than use Java." — Trouser


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


Strange errors on exit

2007-06-05 Thread Thomas Dybdahl Ahle
When I close my (gtk) program, I get errors like the below.
It seams that when the interpreter shuts down, it sets every variable to 
None, but continues running the threads, (seems only in cases where 
they've just been asleep)
I don't think this would be intended behavior?

Exception in thread Thread-4 (most likely raised during interpreter 
shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap
  File "/home/thomas/Programmering/python/skak/0.7/lib/pychess/System/
ThreadPool.py", line 49, in run
  File "/usr/lib/python2.4/Queue.py", line 89, in put
  File "/usr/lib/python2.4/threading.py", line 237, in notify
exceptions.TypeError: exceptions must be classes, instances, or strings 
(deprecated), not NoneType
Unhandled exception in thread started by 
Error in sys.excepthook:

Original exception was:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting mount stats for filesystems

2007-06-05 Thread Mitko Haralanov
On Tue, 05 Jun 2007 21:32:21 +0200
"Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> You could try to invoke getmntent(3). I'm not aware of a Python wrapper
> for it, so you either try to write one yourself in C, or use ctypes to
> write it in Python.

I am looking at ctypes and it might do what I need but I can't figure
out a way to convert a Python File object to a C FILE pointer (which is
the needed argument for getmntent).

Any ideas?

-- 
Mitko Haralanov  [EMAIL PROTECTED]
Senior Software Engineer 650.934.8064
System Interconnect Group   http://www.qlogic.com

==
 Fry: That clover helped my rat-fink brother steal my dream of going
into space. Now I'll never get there. 
 Leela: You went there this morning for donuts.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >