Re: Is this a bug, or is it me?

2008-01-19 Thread Arnaud Delobelle
On Jan 18, 7:01 pm, [EMAIL PROTECTED] wrote:
> I filed a bug report, and here is the short answer to my question:
> genexps are code blocks, and code blocks cannot see variables in class
> scopes. Congrats to Neil Cerutti who figured it out.
>
> Now here is another one for your enjoyment:
>
> class C:
>         @staticmethod
>         def f1(): pass
>         F = { '1' : f1 }
>
> C().F['1']()
>
> >>> TypeError: 'staticmethod' object is not callable
>
> What do you think of this one?

It's normal, the staticmethod decorator's role is to 'flag up' the
method as static for further processing when type(C).__new__ is
called.

--
Arnaud

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


Movie Stars As Sources Of Wisdom

2008-01-19 Thread bs866806
Why do many people look to movie stars for answers to some of life's
most challenging questions?

While we have great respect for the art of acting, as explicated from
Stanislavsky to Strasberg, the latter of whom we knew well and were
fond of, we have never understood how the usual snippets who decide to
become actors ascend in the minds of the public from being initially
generally regarded as likely ne'er-do-wells to being considered the
most readily available font of insightful advice on just about every
topic that troubles the frontal lobe of contemporary humanity.

Are we so doubtful of our own confidence to make up our minds that the
resplendent light in which a current movie star is illuminated by his
own publicity agents blinds us to the very probable vapidity of his or
her own mind? After all, there is a certain disjunction between what
movie stars do to win our attentions and what we expect of them once
they succeed.

They bring themselves to our attention by committing to memory, or by
reading off one kind of prompter or another, words devised by others.
We won't go so far as to say they achieve renown by presenting the
thoughts of others, since realistic drama, in most of its contemporary
manifestations, is apparently unable to present characters who might
actually have an occasional considerable thought.

But, once they ascend to the starry vault that hovers over us, do we
expect of them anything consonant with the ability to recite the usual
inanities? No, suddenly we want these storied performers to transform
themselves into the wise harbingers of original insight and exemplary
advice. We even search the most mundane aspects of their personal
lives for a hint or two as to how we might enhance the happiness of
our own comparatively desultory lives. Or, just as often, we suppose,
in the hope of finding that, despite their great reservoir of
astonishing expertise, their own lives are inexplicably entangled in
antics so confoundedly absurd that their shortcomings make us feel far
superior in the relatively rickety guidance of our own lives.

Since we can only be sure that the lights of stage and screen will
continue to be presented to us with all the wiles that can be managed
through the deft employment of colorful media, as the engaging
exemplars of how we should only hope to live, it appears that the only
way to alter the mutual mockery is to become more realistic about what
we really ought to expect from our dazzling stars-brights.

http://www.cncarrental.cn/html/Humor/20060929/25390.html
-- 
http://mail.python.org/mailman/listinfo/python-list


All about DOGS

2008-01-19 Thread mayasmith1
Hi

How much do you know about Dogs?

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


Excess whitespace in my soup

2008-01-19 Thread John Machin
I'm trying to recover the original data from some HTML written by a
well-known application.

Here are three original data items, in Python repr() format, with
spaces changed to tildes for clarity:

u'Saturday,~19~January~2008'
u'Line1\nLine2\nLine3'
u'foonly~frabjous\xa0farnarklingliness'

Here is the HTML, with spaces changed to tildes, angle brackets
changed to square brackets,
omitting \r\n from the end of each line, and stripping a large number
of attributes from the [td] tags.

~~[td]Saturday,~19
~~January~2008[/td]
~~[td]Line1[br]
Line2[br]
Line3[/td]
~~[td]foonly
~~frabjous farnarklingliness[/td]

Here are the results of feeding it to ElementSoup:

>>> import ElementSoup as ES
>>> elem = ES.parse('ws_soup1.htm')
>>> from pprint import pprint as pp
>>> pp([(e.tag, e.text, e.tail) for e in elem.getiterator()])
[snip]
 (u'td', u'Saturday, 19\n  January 2008', u'\n'),
 (u'td', u'Line1', u'\n'),
 (u'br', None, u'\nLine2'),
 (u'br', None, u'\nLine3'),
 (u'td', u'foonly\n  frabjous\xa0farnarklingliness', u'\n')]

I'm happy enough with reassembling the second item. The problem is in
reliably and
correctly collapsing the whitespace in each of the above five
elements. The standard Python
idiom of u' '.join(text.split()) won't work because the text is
Unicode and u'\xa0' is whitespace
and would be converted to a space.

Should whitespace collapsing be done earlier? Note that BeautifulSoup
leaves it as   -- ES does the conversion to \xa0 ...

Does anyone know of an html_collapse_whitespace() for Python? Am I
missing something obvious?

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


Re: Excess whitespace in my soup

2008-01-19 Thread Fredrik Lundh
John Machin wrote:

> I'm happy enough with reassembling the second item. The problem is in
> reliably and  correctly collapsing the whitespace in each of the above
 > fiveelements. The standard Python idiom of u' '.join(text.split())
 > won't work because the text is Unicode and u'\xa0' is whitespace
> and would be converted to a space.

would this (or some variation of it) work?

 >>> re.sub("[ \n\r\t]+", " ", u"foo\n  frab\xa0farn")
u'foo frab\xa0farn'



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


writing Python in Emacs

2008-01-19 Thread Richard Szopa
Hi All,

I am a devoted Emacs user and I write a lot in Python. However, I
never managed to get my Emacs configuration right for this purpose.
There were some discussions on this, but the threads that show if I
search the group are either old or not so relevant.

I need the following features:

0) Of course, syntax coloring and so on... But this works good enough
ootb in the two most popular python-modes.

1) Tab completion, ideally Slime like. That is, when there's not
enough letters to unambiguously complete a symbol, I want it to show a
buffer (w/o taking the focus) w/ the possible completions. In an ideal
world, it would be able to complete fo.ba to foo.bar. I imagine
this would require quite tight Emacs-Python integration.

2) Sending the toplevel definition (class or function) to the Python
buffer.

3) Hints on function/method arguments. IDLE has this done nearly
right, but the hints are a bit too intrusive for me. I would like to
see them in the minibuffer.

4) (optional) I would like to see the definition of a function
function or class by hitting M-. on its name. (I understand that this
may be impossible for methods, as Emacs would have to automagically
infer the type of the object).

I have tried a couple of times both python-modes (the one shipped w/
Python and the one shipped w/ Emacs), pymacs and stuff like that...
And, as I said, never got it right. But, maybe I just cannot find the
way to configure it, and some configuration hints will be enough...

As for other editors, I have tried Eclipse and Komodo... But I cannot
get used to them. As for non-emacs stuff, the most comfortable for me
has been IDLE.

Cheers and thanks in advance,

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


Re: Is this a bug, or is it me?

2008-01-19 Thread Arnaud Delobelle
On Jan 17, 3:55 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> Here is a simpler example:
>
> >>> class A:
>
> ...     a = 42
> ...     list(a for _ in "a")
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 3, in A
>   File "", line 3, in 
> NameError: global name 'a' is not defined
[...]
> So it seems that Python gets puzzled by the extra scope introduced by the
> genexp, i. e. you are seeing an obscure variant of the following
> (expected) behaviour:
>
> >>> class B:
>
> ...     a = 42
> ...     def f(): a
> ...     f()
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 4, in B
>   File "", line 3, in f
> NameError: global name 'a' is not defined

This is exactly the problem:

class A:
a = 42
list(a for _ in "a")

is in fact compiled as:

class A:
a = 42
def _genexpr():
for _ in "a":
yield a
list(_genexpr())

Except that the _genexpr function is not bound to any name, just left
on the stack for list to pick up next.  This can be checked using the
dis module.
Trying it yields exactly the same error:

>>> class A(object):
... a = 42
... def _genexpr():
... for _ in "a":
... yield a
... list(_genexpr())
...
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 6, in A
  File "", line 5, in _genexpr
NameError: global name 'a' is not defined

> I think you should file a bug report, though making the genexp recognizing
> the class scope probably isn't worth the effort.

It isn't necessary to do that to fix the problem.  I think that the
semantics of genexprs concerning free variables are confusing (and
this is a good example!).  I suggested a change on python-ideas a
while ago that would solve this particular issue.

In short, all free variables inside a generator expression could be
bound at the creation of the expression, not when it is evaluated.

So for example

((c, f(x)) for x in L)

would be the equivalent of what one could currently write as.

(lambda _c, _f: ((c, f(x) for x in L))(c, f)

so your example would compile to:

class A:
a = 42
def _genexpr(_a):
for _ in "a":
yield _a
list(_genexpr(a))

Which would behave as the OP expected (and I think as it is reasonable
to expect if one doesn't know about how genexprs are implemented).

Other reasons why I think this is desirable are exposed (maybe not
very convincingly) in this post to python-ideas.

http://mail.python.org/pipermail/python-ideas/2007-December/001260.html

--
Arnaud

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


Re: Excess whitespace in my soup

2008-01-19 Thread Remco Gerlich
Not sure if this is sufficient for what you need, but how about

import re
re.sub(u'[\s\xa0]+', ' ', s)

That should replace all occurances of 1 or more whitespace or \xa0
characters, by a single space.

Remco

On Jan 19, 2008 12:38 PM, John Machin <[EMAIL PROTECTED]> wrote:

> I'm trying to recover the original data from some HTML written by a
> well-known application.
>
> Here are three original data items, in Python repr() format, with
> spaces changed to tildes for clarity:
>
> u'Saturday,~19~January~2008'
> u'Line1\nLine2\nLine3'
> u'foonly~frabjous\xa0farnarklingliness'
>
> Here is the HTML, with spaces changed to tildes, angle brackets
> changed to square brackets,
> omitting \r\n from the end of each line, and stripping a large number
> of attributes from the [td] tags.
>
> ~~[td]Saturday,~19
> ~~January~2008[/td]
> ~~[td]Line1[br]
> Line2[br]
> Line3[/td]
> ~~[td]foonly
> ~~frabjous farnarklingliness[/td]
>
> Here are the results of feeding it to ElementSoup:
>
> >>> import ElementSoup as ES
> >>> elem = ES.parse('ws_soup1.htm')
> >>> from pprint import pprint as pp
> >>> pp([(e.tag, e.text, e.tail) for e in elem.getiterator()])
> [snip]
>  (u'td', u'Saturday, 19\n  January 2008', u'\n'),
>  (u'td', u'Line1', u'\n'),
>  (u'br', None, u'\nLine2'),
>  (u'br', None, u'\nLine3'),
>  (u'td', u'foonly\n  frabjous\xa0farnarklingliness', u'\n')]
>
> I'm happy enough with reassembling the second item. The problem is in
> reliably and
> correctly collapsing the whitespace in each of the above five
> elements. The standard Python
> idiom of u' '.join(text.split()) won't work because the text is
> Unicode and u'\xa0' is whitespace
> and would be converted to a space.
>
> Should whitespace collapsing be done earlier? Note that BeautifulSoup
> leaves it as   -- ES does the conversion to \xa0 ...
>
> Does anyone know of an html_collapse_whitespace() for Python? Am I
> missing something obvious?
>
> Thanks in advance,
> John
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Excess whitespace in my soup

2008-01-19 Thread John Machin
On Jan 19, 11:00 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> John Machin wrote:
> > I'm happy enough with reassembling the second item. The problem is in
> > reliably and  correctly collapsing the whitespace in each of the above
>
>  > fiveelements. The standard Python idiom of u' '.join(text.split())
>  > won't work because the text is Unicode and u'\xa0' is whitespace
>
> > and would be converted to a space.
>
> would this (or some variation of it) work?
>
>  >>> re.sub("[ \n\r\t]+", " ", u"foo\n  frab\xa0farn")
> u'foo frab\xa0farn'
>
> 

Yes, partially. Leading and trailing whitespace has to be removed
entirely, not replaced by one space.

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


Re: Excess whitespace in my soup

2008-01-19 Thread Stefan Behnel
John Machin wrote:
> On Jan 19, 11:00 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> John Machin wrote:
>>> I'm happy enough with reassembling the second item. The problem is in
>>> reliably and  correctly collapsing the whitespace in each of the above
>>  > fiveelements. The standard Python idiom of u' '.join(text.split())
>>  > won't work because the text is Unicode and u'\xa0' is whitespace
>>
>>> and would be converted to a space.
>> would this (or some variation of it) work?
>>
>>  >>> re.sub("[ \n\r\t]+", " ", u"foo\n  frab\xa0farn")
>> u'foo frab\xa0farn'
>>
>> 
> 
> Yes, partially. Leading and trailing whitespace has to be removed
> entirely, not replaced by one space.

Sounds like adding a .strip() to me ...

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


pyExcelerator: writing multiple rows

2008-01-19 Thread patrick . waldo
Hi all,

I was just curious if there was a  built-in or a more efficient way to
do take multiple rows of information and write them into excel using
pyExcelerator.  This is how I resolved the problem:

from pyExcelerator import *

data = [[1,2,3],[4,5,'a'],['','s'],[6,7,'g']]

wb=pyExcelerator.Workbook()
test = wb.add_sheet("test")

c=1
r=0
while rhttp://mail.python.org/mailman/listinfo/python-list


Re: Core Python Programming . . .

2008-01-19 Thread FireNWater
On Jan 18, 6:00 pm, Yu-Xi Lim <[EMAIL PROTECTED]> wrote:
> Mike Driscoll wrote:
>
> > 6-11 Conversion.
> >   (a) Create a program that will convert from an integer to an
> > Internet Protocol (IP) address in the four-octet format of WWW.XXX.YYY.ZZZ
> >   (b) Update your program to be able to do the vice verse of the
> > above.
>
> I think it's is asking to convert a 32-bit int to the dotted form.
>
> It's a little known fact, but IP addresses are valid in non-dotted
> long-int form.  Spammers commonly use this trick to disguise their IP
> addresses in emails from scanners.

I guess I'm not fully up to speed on what constitutes an IP address.
Does the term 'octet' refer to an 8-bit (xFF) number?
-- 
http://mail.python.org/mailman/listinfo/python-list


SPARQL server in Python?

2008-01-19 Thread Bart Ogryczak
Hi,
I'm trying to migrate some R&D I've done with PHP and RAP[1] to 
Python. But I've got hard time finding Python RDF/SPARQL server.
Most things I find are SPARQL clients. 
Do you know of a Python library, that could do the job?

[1] http://sites.wiwiss.fu-berlin.de/suhl/bizer/rdfapi/

bart
-- 
Set phasers on kill, fire at will.
http://candajon.azorragarse.info/ http://azorragarse.candajon.info/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Core Python Programming . . .

2008-01-19 Thread Yu-Xi Lim
FireNWater wrote:

> I guess I'm not fully up to speed on what constitutes an IP address.
> Does the term 'octet' refer to an 8-bit (xFF) number?

Yes, it somewhat archaic though. It's used when "byte" is ambiguous. On 
some ancient (by computing standards) computers, the size of a byte may 
be as small as 6 bits or as big as 9.

For the purposes of this question, I think it's safe to assume an IP 
address is just a 32-bit number. And you need to extract each group of 
8-bits and print those out with dots between them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonland documentation

2008-01-19 Thread Laurent Pointal
Le Fri, 18 Jan 2008 18:51:19 +, Simon Pickles a écrit :

> Hi
> 
> I am new to python (fairly) but can't stop pythonning.
> 
> c++ seems so far away now from here it looks like a horrid scribble
> :)
> 
> Anyway my question is really about doc tools. I've been used to
> doxygen in c++ land, and although it makes a reasonable stab with a
> python project in java mode, the output is a bit messy.
> 
> Can any one suggest a more tailored tool? or do I risk a flamewar? :)

You can take a look at epydoc

http://epydoc.sourceforge.net/


> 
> Thanks
> 
> SiPi





-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

finding memory leak in edgewall trac 0.11

2008-01-19 Thread rupert.thurner
what would be a good means of finding where the 0.11 version of
edgewall trac uses excessive memory. see
http://groups.google.com/group/trac-dev/browse_thread/thread/116e519da54f16b
for some details, where jonas suggested
http://wingolog.org/archives/2007/11/27/reducing-the-footprint-of-python-applications
as reading.

tiran already gave some hints on http://bugs.python.org/issue1871, but
also suggested to ask the general mailing list:

Do you have classes with a __del__ method which may create reference
cycles? The GC can't break cycles when a __del__ method is involved.

Are you keeping references to tracebacks, exception objects (except
Exception, err) or frames (sys._getframe())

many thanks,

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


Re: finding memory leak in edgewall trac 0.11

2008-01-19 Thread Christian Heimes
rupert.thurner wrote:
> what would be a good means of finding where the 0.11 version of
> edgewall trac uses excessive memory. see
> http://groups.google.com/group/trac-dev/browse_thread/thread/116e519da54f16b
> for some details, where jonas suggested
> http://wingolog.org/archives/2007/11/27/reducing-the-footprint-of-python-applications
> as reading.
> 
> tiran already gave some hints on http://bugs.python.org/issue1871, but
> also suggested to ask the general mailing list:
> 
> Do you have classes with a __del__ method which may create reference
> cycles? The GC can't break cycles when a __del__ method is involved.
> 
> Are you keeping references to tracebacks, exception objects (except
> Exception, err) or frames (sys._getframe())

I forgot one important point in my reply. The GC module contains some
useful methods for debugging. Check gc.garbage. It should be empty.

http://docs.python.org/lib/module-gc.html

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


python scripts with IIS

2008-01-19 Thread william paul
Hello:
 
I am trying to configure IIS to work with Python scripts:
 
I've added in the Home Directory/Configuration the .py extention and the path 
to the python.exe as: c:\Python24\python.exe %S %S
The python script has 1 line:
print "This is a test for python scripts with IIS"
 
When I launch the file using IE I get the message:
 
CGI Error
The specified CGI application misbehaved by not returning a complete set of 
HTTP headers. The headers it did return are:
 
This is a test for python scripts with IIS
 
How can I remove the CGI error?
 
Thank you
 
William


  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Efficient processing of large nuumeric data file

2008-01-19 Thread David Sanders
On Jan 18, 11:15 am, David Sanders <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am processing large files of numerical data.  Each line is either a
> single (positive) integer, or a pair of positive integers, where the
> second represents the number of times that the first number is
> repeated in the data -- this is to avoid generating huge raw files,
> since one particular number is often repeated in the data generation
> step.
>
> My question is how to process such files efficiently to obtain a
> frequency histogram of the data (how many times each number occurs in
> the data, taking into account the repetitions).  My current code is as
> follows:

Many thanks to all for the very detailed and helpful replies.  I'm
glad to see I was on the right track, but more happy to have learnt
some different approaches.

Thanks and best wishes,
David.
-- 
http://mail.python.org/mailman/listinfo/python-list


Ruby Programming

2008-01-19 Thread LinkExchange . AB
iTechArt has specialized in Ruby on Rails (ROR) development and
provides a complete software outsourcing services for web development
solutions based on Ruby. We suggest use Ruby framework for developing
database-backed web applications with Ajax on front-end because it's a
great fit for practically any type of web application: collaboration,
community, e-commerce, content management and statistics.

Ruby development environment and technologies:

* Ruby On Rails development framework
* MySQL, PostgreSQL, SQLite, Oracle, MS SQL Server, DB2
* RadRails IDE, ActionWebservice for Ruby
* Linux, Apache, lighttpd
* OOP and software development
* Search engines optimization



http://www.itechart.com/Pages/Subsections/RubyDevelopment.aspx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using "pickle" for interprocess communication - some notes and things that ought to be documented.

2008-01-19 Thread John Nagle
Paul Boddie wrote:

> Unlike your approach, pprocess employs the fork system call. 

 Unfortunately, that's not portable.  Python's "fork()" is
"Availability: Macintosh, Unix."  I would have preferred
to use "fork()".

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


Re: Ruby Programming

2008-01-19 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> iTechArt has specialized in Ruby on Rails (ROR) development and
> provides a complete software outsourcing services for web development
> solutions based on Ruby. We suggest use Ruby framework for developing
> database-backed web applications with Ajax on front-end because it's a
> great fit for practically any type of web application: collaboration,
> community, e-commerce, content management and statistics.
> 
> Ruby development environment and technologies:
> 
> * Ruby On Rails development framework
> * MySQL, PostgreSQL, SQLite, Oracle, MS SQL Server, DB2
> * RadRails IDE, ActionWebservice for Ruby
> * Linux, Apache, lighttpd
> * OOP and software development
> * Search engines optimization
> 
> 
> 
> http://itechart.is.stupid/foo.aspx


Funny. Either rails isn't so good for the company's own website - which 
I doubt - or they don't know as much about it as they claim

link changed to prevent proper indexing ...


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


Re: Using "pickle" for interprocess communication - some notes and things that ought to be documented.

2008-01-19 Thread Paul Boddie
On 19 Jan, 17:06, John Nagle <[EMAIL PROTECTED]> wrote:
> Paul Boddie wrote:
> > Unlike your approach, pprocess employs the fork system call.
>
>  Unfortunately, that's not portable.  Python's "fork()" is
> "Availability: Macintosh, Unix."  I would have preferred
> to use "fork()".

There was a discussion some time ago about providing a fork
implementation on Windows, since Cygwin attempts/attempted to provide
such support [1] and there's a Perl module which pretends to provide
fork (using threads if I recall correctly), but I'm not sure whether
anyone really believed that it was workable. I believe that on modern
releases of Windows it was the ZwCreateProcess function which was
supposed to be usable for this purpose, but you then apparently have
to add a bunch of other things to initialise the new process
appropriately.

Of course, for the purposes of pprocess - providing a multiprocess
solution which should be as easy to use as spawning threads whilst
having some shared, immutable state hanging around that you don't want
to think too hard about - having fork is essential, but if you're
obviously willing to split your program up into different components
then any of the distributed object technologies would be good enough.

Paul

[1] http://www.cygwin.com/ml/cygwin/2002-01/msg01826.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN:proxysocket(socks4,socks5)v0.1

2008-01-19 Thread Samuel
v0.2
http://proxysocket.googlecode.com/files/ProxySocket.py

On 1月18日, 下午3时04分, Tim Roberts <[EMAIL PROTECTED]> wrote:
> Samuel <[EMAIL PROTECTED]> wrote:
>
> >http://code.google.com/p/proxysocket/downloads/list
>
> Allow me to introduce you to the concept of comments.  Python allows you to
> include descriptive sentences in your program that explain what the
> functions do, what your intentions were, what the variables do, what the
> states mean, etc.  It's easy to do; you just start the text with # signs.
>
>   # This function allows you to ...
>
>   # These variables define the connection state as the connection is
>   # made.
>
> They're great.  You should try them.
> --
> Tim Roberts, [EMAIL PROTECTED]
> Providenza & Boekelheide, Inc.

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

Re: TopSort in Python?

2008-01-19 Thread duncan smith
Carl Banks wrote:
> On Jan 18, 7:01 pm, Paddy <[EMAIL PROTECTED]> wrote:
>> On Jan 18, 9:47 pm, [EMAIL PROTECTED] wrote:> Tim,
>>
>>> Thanks for the topsort code.  It would be useful in a project I'm
>>> working on.  Can I use the code for free under public domain?  Thanks!
>> When I needed one I didn't know the name. I'm curious, how did you
>> know to look for the topological sort algorithm by name?
> 
> I spent quite a bit of time looking for this one myself.  It was quite
> a stumper.  Sometimes Google gets us in the habit of just firing
> random search terms when we ought to be thinking it out.
> 
> After quite of bit of dead end searching--like a week--I stepped back,
> thought about what I was looking for.  I wanted a sort of dependency
> system: A must happen before B.  What other programs do that?  make,
> of course.  I looked at the documents for make and found the term
> "directed acyclic graph", and pretty much instantly knew I had it.

Searching for "precedence diagram" might throw up some relevant results; 
but you've probably already discovered that.  I have some basic 
precedence diagram code (no warranty etc.) somewhere if anyone is 
interested.

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


Re: What is a shortcut to the Default home directory in Windows

2008-01-19 Thread Christian Heimes
Tim Golden wrote:
> Umm... Is it not? The only thing I'm aware of doing is
> retaining backwards compat. by using SHGetPathFromIDList
> on the SHGetSpecialFolderLocation because I was writing against
> Win9x at the time. Or are you saying something else?
> 
> (Admit I haven't checked all the docs since I wrote it
> to see what's been "deprecated" this week).

A lot has been deprecated :(
MS has deprecated all functions which are using CSIDL and introduced a
new stack for Vista.

Christian

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


Re: writing Python in Emacs

2008-01-19 Thread Terry Jones
> "Richard" == Richard Szopa <[EMAIL PROTECTED]> writes:

Richard> I am a devoted Emacs user and I write a lot in Python.

Me too.

Richard> I need the following features:

Richard> 1) Tab completion, ideally Slime like. That is, when there's not
Richard> enough letters to unambiguously complete a symbol, I want it to
Richard> show a buffer (w/o taking the focus) w/ the possible
Richard> completions. In an ideal world, it would be able to complete
Richard> fo.ba to foo.bar. I imagine this would require quite tight
Richard> Emacs-Python integration.

I know this is not what you want, but I use hippie expand (M-/) to cycle
through possible completions. It's not Python aware, but it is of some use.

Richard> 2) Sending the toplevel definition (class or function) to the Python
Richard> buffer.

I switched to IPython to have better interaction with a spawned Python.

To use IPython you need to use the Python mode that is NOT the one from
(endorsed?) by the FSF. It gives you some completion (at least in the
*Python* buffer) and you can send pieces of the buffer to the python
process, via py-send-region (C-c |), py-execute-def-or-class (M-C-x), etc.

Richard> 3) Hints on function/method arguments. IDLE has this done nearly
Richard> right, but the hints are a bit too intrusive for me. I would like to
Richard> see them in the minibuffer.

I don't have this.

Richard> 4) (optional) I would like to see the definition of a function
Richard> function or class by hitting M-. on its name. (I understand that
Richard> this may be impossible for methods, as Emacs would have to
Richard> automagically infer the type of the object).

This is just an emacs tag file need. Have you googled for something like
emacs tags python? The issue of methods might be overcome by just moving
through tags with the same name. Yes, that requires _you_ to know when
you've hit the right thing. That's not optimal, but it's better than
nothing. Ideally you could send the definition to IPython, ask it for the
class info, and use that to jump to the right tag.

Richard> I have tried a couple of times both python-modes (the one shipped w/
Richard> Python and the one shipped w/ Emacs), pymacs and stuff like that...
Richard> And, as I said, never got it right. But, maybe I just cannot find the
Richard> way to configure it, and some configuration hints will be enough...

If you have the time, please summarize your findings. The emacs/python
world has always seemed quite amorphous to me too.

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


Re: pyExcelerator: writing multiple rows

2008-01-19 Thread [EMAIL PROTECTED]
On Jan 19, 7:46�am, [EMAIL PROTECTED] wrote:
> Hi all,
>
> I was just curious if there was a �built-in or a more efficient way to
> do take multiple rows of information and write them into excel using
> pyExcelerator. �This is how I resolved the problem:
>
> from pyExcelerator import *
>
> data = [[1,2,3],[4,5,'a'],['','s'],[6,7,'g']]
>
> wb=pyExcelerator.Workbook()
> test = wb.add_sheet("test")
>
> c=1
> r=0
> while r � � for d in data[r]:
> � � � � test.write(r,c,d)
> � � � � c+=1
> � � r+=1
> � � c=1
> wb.save('c:\\1\\test.xls')

Try this:

for row,rowdata in enumerate(data):
  for col,cell in enumerate(rowdata):
test.write(row,col,cell)


If you need row & col offsets, add them.

row_offset = 7
col_offset = 3
for row,rowdata in enumerate(data):
  for col,cell in enumerate(rowdata):
test.write(row+row_offset,col+col_offset,cell)
-- 
http://mail.python.org/mailman/listinfo/python-list

Default attribute values pattern

2008-01-19 Thread George Sakkis
A situation that often comes up is having to initialize several
instance attributes that accept a default value. For a single class,
passing the default values in __init__ is fine:

class Base(object):
def __init__(self, x=0, y=None):
self.x = x
self.y = y

For inherited classes that need to override __init__ while keeping a
compatible interface though, the default values have to be repeated:

class Derived(Base):
def __init__(self, x=0, y=None, z=''):
super(Derived,self).__init__(self,x,y)
self.z = ''

For just two attributes and two classes that's maybe not too bad but
for many attributes and/or derived classes that may span multiple
modules, that doesn't seem to scale from a maintenance point of view,
especially if the defaults change over time.

A pattern I've been using lately instead is store the defaults in
class attributes and let __init__ accept keyword arguments:

class Base(object):

x = 0
y = None

def __init__(self, **kwds):
setattrs(self, kwds)

where setattrs is:

def setattrs(self, attrvals, strict=True):
if strict:
# raise AttributeError if some attr doesn't exist already
for attr in attrvals.iterkeys():
getattr(self,attr)
for attr,val in attrvals.iteritems():
setattr(self, attr, val)

This way, only the new and overriden default attributes have to
repeated in derived classes:

class Derived(Base):

x = 1
z = ''

def __init__(self, **kwds):
super(Derived,self).__init__(**kwds)
print 'In Derived.__init__'


Is this a good way of doing it ? Is there a better pattern ?

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


Re: Details about pythons set implementation

2008-01-19 Thread Albert van der Horst
In article <[EMAIL PROTECTED]>,
bukzor  <[EMAIL PROTECTED]> wrote:
>On Jan 4, 2:15 pm, Steven D'Aprano <[EMAIL PROTECTED]
>cybersource.com.au> wrote:
>> On Fri, 04 Jan 2008 09:29:50 -0800, bukzor wrote:
>> > Why cant you implement < for complex numbers? Maybe I'm being naive, but
>> > isn't this the normal definition?
>> > a + bi < c + di iff sqrt(a**2 + b**2) < sqrt(c**2, d**2)
>>
>> No, it is not. Ordered comparisons are not defined for complex numbers.

Mathematically speaking, it depends what you require from ordering.
Mostly (and what we need for fast lookup) we want transitivity:
A>=B & B>=C => A>=C

Requiring transitivity you are right with your concern
about the OP's version of <. Although in mathematics you can
define things as you like, a non-transitive < is frowned upon.

>> Which is bigger, 4+2j or 2+4j?

We can make a useful ordering by defining
A<=B :  if RE(A) /= RE(B) then RE(A) <= RE(B)
 else   IM(A) <= IM(B)

So for the OP's example: 4+2i is bigger.

This is sufficient to put a bunch of complex numbers in an
array, sort the array, and have a lookup using binary search.
(Or a heap: a heap is better for frequent additions and deletions.)

>>
>> > How do you implement a set without sorting?
>>
>> With a hash table.
>>
>> Or if you are willing to limit yourself to sets of small integers, you
>> can implement it using bit flipping. E.g. 5 is an element of the set if
>> bit 5 is on.

Or if you can live with O(n) implementations are trivial.

>>
>> > Are you expecting better than O(log n)?
>>
>> Sure.

The same applies to sets of complex numbers the C++ way with the
above definition of for < for complex  numbers.

>>
>> --
>> Steven
>
>Good Answers!


--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
[EMAIL PROTECTED]&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python scripts with IIS

2008-01-19 Thread Rolf van de Krol
Adding the following lines before your print statement should do the 
trick. IIS complains about the headers, so adding headers should help.

print "Content-Type: text/html" # HTML is following
print   # blank line, end of headers



william paul wrote:
>  
> Hello:
>  
> I am trying to configure IIS to work with Python scripts:
>  
> I've added in the Home Directory/Configuration the .py extention and 
> the path to the python.exe as: c:\Python24\python.exe %S %S
> The python script has 1 line:
> print "This is a test for python scripts with IIS"
>  
> When I launch the file using IE I get the message:
>  
> *CGI Error*
> The specified CGI application misbehaved by not returning a complete 
> set of HTTP headers. The headers it did return are:
>  
> This is a test for python scripts with IIS
>  
> How can I remove the CGI error?
>  
> Thank you
>  
> William
>
> 
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try 
> it now. 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Okay I got a question regarding Tkinter and Labels

2008-01-19 Thread Lamonte Harris
Okay I've created a script and basically when I loop through a folder it is
supposed to change the Label everytime it updates a file then again it
doesn't do nothing but shows the last file edited, whats the best way to
loop through files and display that file name in a Label's text without
skipping to the last one when the loop is finished?
-- 
http://mail.python.org/mailman/listinfo/python-list

Gui front-end to version control program

2008-01-19 Thread David Delony
I spoke with Eric S. Raymond at a Linux user's group meeting a few days ago 
about the need for version control for end users.
I thought that Python might be a good candidate for this. 

Luckily, Guido was there as well. I talked this over with him and he
suggested using Google Documents sinceI usually collborate on text documents.

I want something that can work with any file, as Subversion does. I can't 
think of any 
GUI wrappers written in Python off the top of my head. I would like to use one
as a model and get my feet wet by contributing to it. I don't feel proficient
enough to lead a project yet. 


-- 
There's no place like ~!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gui front-end to version control program

2008-01-19 Thread Paul Rubin
David Delony <[EMAIL PROTECTED]> writes:
> I want something that can work with any file, as Subversion does. I
> can't think of any GUI wrappers written in Python off the top of my
> head. I would like to use one as a model and get my feet wet by
> contributing to it. I don't feel proficient enough to lead a project yet.

I don't understand what you're asking for.  cvs and svn have gui front
ends, I thought.  They certainly have web front ends, as does mercurial.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python scripts with IIS

2008-01-19 Thread william paul
Thank you,

William


- Original Message 
From: Rolf van de Krol <[EMAIL PROTECTED]>
To: python-list@python.org
Sent: Saturday, January 19, 2008 5:33:59 PM
Subject: Re: python scripts with IIS

Adding the following lines before your print statement should do the 
trick. IIS complains about the headers, so adding headers should help.

print "Content-Type: text/html"# HTML is following
print  # blank line, end of headers



william paul wrote:
>  
> Hello:
>  
> I am trying to configure IIS to work with Python scripts:
>  
> I've added in the Home Directory/Configuration the .py extention and 
> the path to the python.exe as: c:\Python24\python.exe %S %S
> The python script has 1 line:
> print "This is a test for python scripts with IIS"
>  
> When I launch the file using IE I get the message:
>  
> *CGI Error*
> The specified CGI application misbehaved by not returning a complete 
> set of HTTP headers. The headers it did return are:
>  
> This is a test for python scripts with IIS
>  
> How can I remove the CGI error?
>  
> Thank you
>  
> William
>
> 
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try 
> it now. 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: finding memory leak in edgewall trac 0.11

2008-01-19 Thread Jeroen Ruigrok van der Werven
Hi Christian,

-On [20080119 16:16], Christian Heimes ([EMAIL PROTECTED]) wrote:
>I forgot one important point in my reply. The GC module contains some
>useful methods for debugging. Check gc.garbage. It should be empty.

Yeah, we're messing around with that stuff as well as many other ways of
trying to track issues, but it can really be looking for a needle in a
haystack to be honest.
There's so much output that, I guess, make sense only when you're semi-deep
into the Python internals to even make heads or tails out of it. =\
And even third-party code is not helping much to reduce the clutter and
provide insight.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Life is not a problem to be solved but a reality to be experienced...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: writing Python in Emacs

2008-01-19 Thread Thierry Volpiatto

I add just a note about ipython:
if you use a version > 0.6.15 may be you will have a bad output
on error like:

== " ":
instead of:
if __name__ == "__main__":

all the characters are missing.

To avoid that, run in ipython:
%upgrade -nolegacy

uncomment in ~/.ipython/ipy_user_config.py:
import ipy_defaults

restart emacs and try a .py with some syntax errors.
It should be ok now.

Terry Jones <[EMAIL PROTECTED]> writes:

>> "Richard" == Richard Szopa <[EMAIL PROTECTED]> writes:
>
> Richard> I am a devoted Emacs user and I write a lot in Python.
>
> Me too.
>
> Richard> I need the following features:
>
> Richard> 1) Tab completion, ideally Slime like. That is, when there's not
> Richard> enough letters to unambiguously complete a symbol, I want it to
> Richard> show a buffer (w/o taking the focus) w/ the possible
> Richard> completions. In an ideal world, it would be able to complete
> Richard> fo.ba to foo.bar. I imagine this would require quite tight
> Richard> Emacs-Python integration.
>
> I know this is not what you want, but I use hippie expand (M-/) to cycle
> through possible completions. It's not Python aware, but it is of some use.
>
> Richard> 2) Sending the toplevel definition (class or function) to the Python
> Richard> buffer.
>
> I switched to IPython to have better interaction with a spawned Python.
>
> To use IPython you need to use the Python mode that is NOT the one from
> (endorsed?) by the FSF. It gives you some completion (at least in the
> *Python* buffer) and you can send pieces of the buffer to the python
> process, via py-send-region (C-c |), py-execute-def-or-class (M-C-x), etc.
>
> Richard> 3) Hints on function/method arguments. IDLE has this done nearly
> Richard> right, but the hints are a bit too intrusive for me. I would like to
> Richard> see them in the minibuffer.
>
> I don't have this.
>
> Richard> 4) (optional) I would like to see the definition of a function
> Richard> function or class by hitting M-. on its name. (I understand that
> Richard> this may be impossible for methods, as Emacs would have to
> Richard> automagically infer the type of the object).
>
> This is just an emacs tag file need. Have you googled for something like
> emacs tags python? The issue of methods might be overcome by just moving
> through tags with the same name. Yes, that requires _you_ to know when
> you've hit the right thing. That's not optimal, but it's better than
> nothing. Ideally you could send the definition to IPython, ask it for the
> class info, and use that to jump to the right tag.
>
> Richard> I have tried a couple of times both python-modes (the one shipped w/
> Richard> Python and the one shipped w/ Emacs), pymacs and stuff like that...
> Richard> And, as I said, never got it right. But, maybe I just cannot find the
> Richard> way to configure it, and some configuration hints will be enough...
>
> If you have the time, please summarize your findings. The emacs/python
> world has always seemed quite amorphous to me too.
>
> Terry
> ___
> help-gnu-emacs mailing list
> [EMAIL PROTECTED]
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>

-- 
A + Thierry
Pub key: http://pgp.mit.edu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding memory leak in edgewall trac 0.11

2008-01-19 Thread Christian Heimes
Jeroen Ruigrok van der Werven wrote:
> Hi Christian,
> 
> -On [20080119 16:16], Christian Heimes ([EMAIL PROTECTED]) wrote:
>> I forgot one important point in my reply. The GC module contains some
>> useful methods for debugging. Check gc.garbage. It should be empty.
> 
> Yeah, we're messing around with that stuff as well as many other ways of
> trying to track issues, but it can really be looking for a needle in a
> haystack to be honest.
> There's so much output that, I guess, make sense only when you're semi-deep
> into the Python internals to even make heads or tails out of it. =\
> And even third-party code is not helping much to reduce the clutter and
> provide insight.

Under normal circumstances gc.garbage should be an empty list. In
general it's a bad sign if gc.garbage contains lots of objects.

I found several potential leaks in trac:

$ find -name \*.py | xargs grep __del__
./trac/versioncontrol/svn_fs.py:def __del__(self):
./trac/versioncontrol/svn_fs.py:def __del__(self):
./trac/db/pool.py:def __del__(self):

$ find -name \*.py | xargs grep frame
./trac/web/main.py:
[...]
./trac/core.py:frame = sys._getframe(1)
./trac/core.py:locals_ = frame.f_locals

I recommend that you either replace __del__ with a weak reference
callback or to remove it. Referencing a frame, traceback or f_locals is
going to leak, too. You *must* explicitly del every frame and locals
variable.

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


Python 3000 and import __hello__

2008-01-19 Thread Brad
Just playing around with Python3000 a2 release on Windows XP 32-bit x86.

import __hello__

doesn't print 'hello world...' as it does on 2.5

The import doesn't fail or generate errors... just no output. Perhaps 
this is by design?

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


Naming a file

2008-01-19 Thread snoylr
I have a variable called filename
How do I create a file using the filename variable as the name of the
file?

For example if the variable is 105Markum

What statement do I need to create a file name 105Markum.txt?

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


Re: Naming a file

2008-01-19 Thread Matthias Bläsing
Am Sat, 19 Jan 2008 14:14:30 -0800 schrieb snoylr:

> For example if the variable is 105Markum
> 
> What statement do I need to create a file name 105Markum.txt?

filename_base = '105Markum'
filename = '%s.txt' % filename_base
f = open(filename, 'w')
f.write(http://mail.python.org/mailman/listinfo/python-list


Re: Default attribute values pattern

2008-01-19 Thread David Tweet
Hello,

Seems to me that setattrs sort of assumes that you want to have all your
initialization arguments set as attributes of the same name.  I would think
you'd sometimes want to be able to process the extra arguments inside of each
__init__, assign them to attributes with different names, etc.

My approach would be to treat each __init__ as a wrapping function, grabbing
the items it needs out of the keyword dictionary and then calling the next
__init__.  Curious to hear other approaches though:


def Grab(argdict, key, default):
  """Like argdict.get(key, default), but also deletes key from argdict."""
  if key in argdict:
retval = argdict["key"]
del(argdict[key])
  else:
retval = default
  return retval


class Base(object):
  def __init__(self, x=0, y=None):
print "in Base init"
self.x = x
self.y = y


class Derived1(Base):
  def __init__(self, **kwargs):
print "in Derived1 init"
self.z = Grab(kwargs, "z", None)
super(Derived1, self).__init__(**kwargs)


class Derived2(Derived1):
  def __init__(self, **kwargs):
print "in Derived2 init"
self.a = Grab(kwargs, "a", 0)
self.b = Grab(kwargs, "b", False)
super(Derived2, self).__init__(**kwargs)
print self.__dict__


newthing = Derived2(x=234, y="blah", a=5)


On Jan 19, 2008 10:14 AM, George Sakkis <[EMAIL PROTECTED]> wrote:
> A situation that often comes up is having to initialize several
> instance attributes that accept a default value. For a single class,
> passing the default values in __init__ is fine:
>
> class Base(object):
> def __init__(self, x=0, y=None):
> self.x = x
> self.y = y
>
> For inherited classes that need to override __init__ while keeping a
> compatible interface though, the default values have to be repeated:
>
> class Derived(Base):
> def __init__(self, x=0, y=None, z=''):
> super(Derived,self).__init__(self,x,y)
> self.z = ''
>
> For just two attributes and two classes that's maybe not too bad but
> for many attributes and/or derived classes that may span multiple
> modules, that doesn't seem to scale from a maintenance point of view,
> especially if the defaults change over time.
>
> A pattern I've been using lately instead is store the defaults in
> class attributes and let __init__ accept keyword arguments:
>
> class Base(object):
>
> x = 0
> y = None
>
> def __init__(self, **kwds):
> setattrs(self, kwds)
>
> where setattrs is:
>
> def setattrs(self, attrvals, strict=True):
> if strict:
> # raise AttributeError if some attr doesn't exist already
> for attr in attrvals.iterkeys():
> getattr(self,attr)
> for attr,val in attrvals.iteritems():
> setattr(self, attr, val)
>
> This way, only the new and overriden default attributes have to
> repeated in derived classes:
>
> class Derived(Base):
>
> x = 1
> z = ''
>
> def __init__(self, **kwds):
> super(Derived,self).__init__(**kwds)
> print 'In Derived.__init__'
>
>
> Is this a good way of doing it ? Is there a better pattern ?
>
> George
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: Python 3000 and import __hello__

2008-01-19 Thread Christian Heimes
Brad wrote:
> Just playing around with Python3000 a2 release on Windows XP 32-bit x86.
> 
> import __hello__
> 
> doesn't print 'hello world...' as it does on 2.5
> 
> The import doesn't fail or generate errors... just no output. Perhaps 
> this is by design?

I changed the __hello__ frozen module a while ago. The print was
unreliable for some new unit tests.

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


HTTP POST uploading large files

2008-01-19 Thread Wolfgang Draxinger
I'm thinking about writing a script to upload videos to sites
like YouTube or Google Video, which is usually done by a HTTP
POST.

The problem is, that videos, by nature are rather big files,
however urllib2 wants it's Request objects being prepared
beforehand, which would mean to first load the whole file to
memory.

I looked into pycURL, knowing that cURL can POST send files
directily from the file system, however pycURL doesn't expose
the neccesary functions yet.

Am I just blind for some urllib2/httplib feature, or some other
library? Or do I really have to fiddle around with sockets
myself (I hope not...).

Thanks in advance

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867

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


Re: Python 3000 and import __hello__

2008-01-19 Thread ajaksu
On Jan 19, 7:54 pm, Brad <[EMAIL PROTECTED]> wrote:
> Just playing around with Python3000 a2 release on Windows XP 32-bit x86.
>
> import __hello__
>
> doesn't print 'hello world...' as it does on 2.5

Thanks for spoiling this easter egg for me!





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


Re: Default attribute values pattern

2008-01-19 Thread Arnaud Delobelle
On Jan 19, 11:02 pm, "David Tweet" <[EMAIL PROTECTED]> wrote:

> def Grab(argdict, key, default):
>   """Like argdict.get(key, default), but also deletes key from argdict."""
>   if key in argdict:
>     retval = argdict["key"]
>     del(argdict[key])
>   else:
>     retval = default
>   return retval
>

Dictionaries already have a method for this.  It's called pop.  It's a
good idea to have a look at methods of builtin types before
reimplementing the wheel!

Grab(argdict, key, default) is argdict.pop(key, default)

--
Arnaud

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


How to get the user/group name from uid/gid in python ?

2008-01-19 Thread raocheng
We know that we can get process or file's uid/gid in python. For
example:
$ python
>>> import os
>>> os.getuid()
1516
>>> os.getgid()
102
>>> os.geteuid()
1516
>>> os.getegid()
102
>>> os.getgroups()
[102, 600]
>>>


$ python
>>> import os,stat
>>> uid = os.stat("./file1")[stat.ST_UID]
>>> gid = os.stat("./file1")[stat.ST_GID]
>>> print uid, gid
1516 102
>>>

How can we get the user/group name from the uid/gid ?
Generally, we can get this information from /etc/passwd. But it is too
inconvenient and when we are using integrated password management, we
can not depend on /etc/passwd.

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


Re: Gui front-end to version control program

2008-01-19 Thread Gabriel Genellina
En Sat, 19 Jan 2008 17:15:21 -0200, David Delony <[EMAIL PROTECTED]>  
escribi�:

> I want something that can work with any file, as Subversion does. I can't
> think of any
> GUI wrappers written in Python off the top of my head. I would like to

There exist TortoiseCVS and TortoiseSVN. They are very intuitive and easy  
to use front ends, but being Explorer extensions, they're tied to Windows.  
They're not written in Python, but in C++.

-- 
Gabriel Genellina

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

Re: Gui front-end to version control program

2008-01-19 Thread Neal Becker
David Delony wrote:

> I spoke with Eric S. Raymond at a Linux user's group meeting a few days
> ago about the need for version control for end users.
> I thought that Python might be a good candidate for this.
> 
> Luckily, Guido was there as well. I talked this over with him and he
> suggested using Google Documents sinceI usually collborate on text
> documents.
> 
> I want something that can work with any file, as Subversion does. I can't
> think of any
> GUI wrappers written in Python off the top of my head. I would like to use
> one as a model and get my feet wet by contributing to it. I don't feel
> proficient enough to lead a project yet.
> 
> 

For some dvcs, qct is coming along well.  A nice commit tool.
http://qct.sourceforge.net/

For merge, kdiff3 is great (and integrates with hg and qct).

There is an early version of pmpu (pushmepullyou) that I think looks good.
http://xenbits.xensource.com/maw/pmpu.hg

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


Re: Gui front-end to version control program

2008-01-19 Thread Grant Edwards
On 2008-01-20, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Sat, 19 Jan 2008 17:15:21 -0200, David Delony <[EMAIL PROTECTED]>  
> escribi?:
>
>> I want something that can work with any file, as Subversion does. I can't
>> think of any
>> GUI wrappers written in Python off the top of my head. I would like to
>
> There exist TortoiseCVS and TortoiseSVN. They are very intuitive and easy  
> to use front ends, but being Explorer extensions, they're tied to Windows.  
> They're not written in Python, but in C++.

Meld is written in Python, and it's a limited frontend for both
CVS and SVN.  There are probably almost a dozen GUI front ends
for SVN (ones that come to mind are meld, esvn, rapidsvn, ksvn,
smartsvn, qsvn, gsvn).  There's also a web-based frontend for
both SVN (and CVS).

I don't really see any need for yet another GUI frontend for SVN.

-- 
Grant

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


Re: Naming a file

2008-01-19 Thread Diez B. Roggisch
Matthias Bläsing schrieb:
> Am Sat, 19 Jan 2008 14:14:30 -0800 schrieb snoylr:
> 
>> For example if the variable is 105Markum
>>
>> What statement do I need to create a file name 105Markum.txt?
> 
> filename_base = '105Markum'
> filename = '%s.txt' % filename_base
> f = open(filename, 'w')
> f.write( f.close

You missed the cruicial parentheses here:

f.close()



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

Re: Default attribute values pattern

2008-01-19 Thread David Tweet
Ah! nice, thanks, knew I was probably missing something.

On Jan 19, 2008 5:01 PM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Jan 19, 11:02pm, "David Tweet" <[EMAIL PROTECTED]> wrote:
>
> > def Grab(argdict, key, default):
> > """Like argdict.get(key, default), but also deletes key from argdict."""
> > if key in argdict:
> > retval = argdict["key"]
> > del(argdict[key])
> > else:
> > retval = default
> > return retval
> >
>
> Dictionaries already have a method for this.  It's called pop.  It's a
> good idea to have a look at methods of builtin types before
> reimplementing the wheel!
>
> Grab(argdict, key, default) is argdict.pop(key, default)
>
> --
> Arnaud
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: HTTP POST uploading large files

2008-01-19 Thread Gabriel Genellina
En Sat, 19 Jan 2008 21:19:24 -0200, Wolfgang Draxinger  
<[EMAIL PROTECTED]> escribi�:

> I'm thinking about writing a script to upload videos to sites
> like YouTube or Google Video, which is usually done by a HTTP
> POST.
>
> The problem is, that videos, by nature are rather big files,
> however urllib2 wants it's Request objects being prepared
> beforehand, which would mean to first load the whole file to
> memory.
>
> I looked into pycURL, knowing that cURL can POST send files
> directily from the file system, however pycURL doesn't expose
> the neccesary functions yet.
>
> Am I just blind for some urllib2/httplib feature, or some other
> library? Or do I really have to fiddle around with sockets
> myself (I hope not...).

I'm afraid urllib2 currently doesn't handle this. Neither the lower layer,  
httplib. HTTPConnection should be upgraded to handle 'Transfer-Encoding:  
chunked', by example. (Chunked responses are handled correctly, but a  
request cannot be chunked)

A Q&D approach would be to patch httplib.HTTPConnection.send, to accept a  
file or file-like argument. Around line 707, instead of  
self.sock.sendall(str):

 if hasattr(str, 'read'):
 BUFSIZE = 4*1024
 while True:
 block = str.read(BUFSIZE)
 if not block: break
 self.sock.sendall(block)
 else:
 self.sock.sendall(str)

and ensure the Content-Length header is already set, so no attempt is made  
to compute len(str)

-- 
Gabriel Genellina

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

Memory errors with imaplib

2008-01-19 Thread Martey
Hi everyone,

I am trying to use imaplib to download messages, but I keep getting
memory errors when I try to download a large message (i.e. one with
attachments). Here is my test code (similar to the example in the
imaplib documentation):

import getpass, imaplib

M = imaplib.IMAP4_SSL("imap.gmail.com")
M.login("[EMAIL PROTECTED]", getpass.getpass())
M.select("[Gmail]/All Mail")
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
print 'Message %s\n%s\n' % (num, data[0][1])
M.close()
M.logout()


And here is the error message:

Python(4521) malloc: *** mmap(size=6389760) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Traceback (most recent call last):
  File "imaptest.py", line 8, in 
typ, data = M.fetch(num, '(RFC822)')
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/imaplib.py", line 437, in fetch
typ, dat = self._simple_command(name, message_set, message_parts)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/imaplib.py", line 1055, in _simple_command
return self._command_complete(name, self._command(name, *args))
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/imaplib.py", line 885, in _command_complete
typ, data = self._get_tagged_response(tag)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/imaplib.py", line 986, in _get_tagged_response
self._get_response()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/imaplib.py", line 948, in _get_response
data = self.read(size)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/imaplib.py", line 1150, in read
data = self.sslobj.read(size-read)
MemoryError

I am using Mac OS X 10.5 and Python 2.5.1 (downloaded from
python.org). I think it is possible that it is , but the workarounds suggested there do not seem to work
for me. Is this an actual Python bug, or am I doing something wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


psyco problem on mac wingide

2008-01-19 Thread Arash Arfaee
Hello All,

I have no problem using psyco on python shell on my new Mac, however I
cannot import it from WingIDE. I copied psyco directory into mac
python folder. Does wingide installs another python shell?
Thanks,

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


Re: TopSort in Python?

2008-01-19 Thread Paddy
On Jan 19, 4:30 pm, duncan smith <[EMAIL PROTECTED]>
wrote:
> Carl Banks wrote:
> > On Jan 18, 7:01 pm, Paddy <[EMAIL PROTECTED]> wrote:
> >> On Jan 18, 9:47 pm, [EMAIL PROTECTED] wrote:> Tim,
>
> >>> Thanks for the topsort code.  It would be useful in a project I'm
> >>> working on.  Can I use the code for free under public domain?  Thanks!
> >> When I needed one I didn't know the name. I'm curious, how did you
> >> know to look for the topological sort algorithm by name?
>
> > I spent quite a bit of time looking for this one myself.  It was quite
> > a stumper.  Sometimes Google gets us in the habit of just firing
> > random search terms when we ought to be thinking it out.
>
> > After quite of bit of dead end searching--like a week--I stepped back,
> > thought about what I was looking for.  I wanted a sort of dependency
> > system: A must happen before B.  What other programs do that?  make,
> > of course.  I looked at the documents for make and found the term
> > "directed acyclic graph", and pretty much instantly knew I had it.
>
> Searching for "precedence diagram" might throw up some relevant results;
> but you've probably already discovered that.  I have some basic
> precedence diagram code (no warranty etc.) somewhere if anyone is
> interested.
>
> Duncan

I searched for dependancy sort, and later dependency sort (cos I
couldn't spell). I had convinced that I was using the right term and
was flummoxed by the lack of hits. Even today the term topological
sort means far less than what it describes: sorting items based on
their interdependencies.

Is this a case of something being named after its mathematical/
technical description and so obscuring its wider practical use cases?

- Paddy.

P.S. we have revived a thread started in 1999!
-- 
http://mail.python.org/mailman/listinfo/python-list