Re: Block Structure Parsing

2006-10-06 Thread hanumizzle
On 10/4/06, Blacktiger <[EMAIL PROTECTED]> wrote:
> Hi all, I'm new to this list because I had a question about parsing
> python block structure. I am taking a programming languages course
> this semester and for our final project we are writing an interperator
> in scheme(awful language) for whatever language that we want. The
> language that I want to do is one I have been designing for a little
> while and it shares some syntactic features of Python; most notably
> the block structure.

What dialect of scheme are you limited to, if any? Because PLT and
Chicken appear to have the widest selection of extensions, it might be
good to look at them. Already on the chicken website (the cumbersome
http://www.call-with-current-continuation.org/eggs/) I found this:
http://www.iro.umontreal.ca/~boucherd/Lalr/documentation/lalr.html.
Might be what you need, might not, can't be sure.

Or you can just cheat, use s-exp syntax with unique semantics, and
then use (read) as your 'parser'. :)

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


Re: Strange sorting error message

2006-10-06 Thread Fredrik Lundh
Steve Holden wrote:

> Even when it smacks you in the face, apparently. Anyway, I'm sorry if 
> you thought I was getting at you in any way. Just trying to amuse the 
> group ...

time to reinstate mandatory use of the  tag ?



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


Re: Strange sorting error message

2006-10-06 Thread hanumizzle
On 10/5/06, Neil Cerutti <[EMAIL PROTECTED]> wrote:

> It was a joke, based on you hiding what you are doing, he decided
> to hide the solution to your problem. Get it?

What if it was for a proprietary software of some kind?

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


RE: CGI Tutorial

2006-10-06 Thread Sells, Fred
content is great, my comments are editorial.

I prefer PDF with bookmarks rather than HTML. 
1. easy to print the whole thing and read offline.
2. easy to find a secion from bookmarks, rather that chasing links
3. easy to save on my local "doc" folder so I can be sure It will always be
there.  (i.e. I don't have to try to find it when you change servers)

Of course that's just my opinion, I could be wrong ;)

If you choose to go the PDF route, I've found OpenOffice 2.0 pretty good at
generating PDF with bookmarks.  Just don't get too complex or OO may hose
you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-04, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Georg Brandl wrote:
>
>> This is an issue in most Python documentation: you're not told
>> if the described function is implemented in C, and if it is
>> keyword arg-enabled. The arguments must be given names though,
>> to be able to document them.
>
> the general rule is that if the documentation doesn't explicitly say 
> that something is a keyword argument, it isn't, and shouldn't be treated 
> as such.

Is this general rules documeted somewhere? My impression is that readers
of the documentation will treat arguments as keyword arguments unless
this is explicitly contradicted. The reason for this is that when they learn
about writing functions, parameters can be used as keuword arguments by
default.

So I don't think you can fault the readers for treating the
documentation as if it is talking about python functions. 

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


Re: Why do this?

2006-10-06 Thread hanumizzle
On 10/6/06, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Thu, 5 Oct 2006 11:28:08 +0100, "Matthew Warren"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> >
> > Now, I started programming when I was 8 with BBC Basic.
> >
> Remember what the acronym BASIC stands for?

Boobie-drawing Adolescent Symbolic Instruction Code.

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


Re: OT Request

2006-10-06 Thread Steve Holden
Dennis Lee Bieber wrote:
> On Thu, 5 Oct 2006 14:40:23 +0100, "Matthew Warren"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
> 
>>This email is confidential and may be privileged. If you are not the intended 
>>recipient please notify the sender immediately and delete the email from your 
>>computer. 
>>
>>You should not copy the email, use it for any purpose or disclose its 
>>contents to any other person.
>>Please note that any views or opinions presented in this email may be 
>>personal to the author and do not necessarily represent the views or opinions 
>>of Digica.
>>It is the responsibility of the recipient to check this email for the 
>>presence of viruses. Digica accepts no liability for any damage caused by any 
>>virus transmitted by this email.
>>
> 
> 
>   Pardon, but is there any possibility you can disable this rather
> long block? I'm presuming you are accessing via the mailing list, but
> that mailing list is gatewayed to a Usenet news group (and unless you've
> managed to embed an X-noarchive header in email, Google Groups is going
> to have the message available in perpetuity). There is no single
> "intended recipient" -- the messages are being sent to anyone in the
> world interested in reading comp.lang.python, so all this overhead is
> meaningless.
> 
>   Or, at least, somehow fit a Usenet/email conventional signature
> marker "-- " (dash, dash, space, newline) before it... Most decent
> clients are designed not to quote material below such a marker.

Sadly such garbage is usually appended at the insistence of 
pointy-haired corporate typess, many of them lawyers who need to justify 
their existence by helping companies to "avoid liability".

Since these declarations usually don't contain any definition of the 
phrase "intended recipient" we are presumably left to read the monds of 
the originators before deciding whether to notify the sender immediately 
and delete the email from your computer".

For some reason the mail administrators of the same companies often 
appear to believe that Microsoft Exchange defines email standards for 
the Internet, and they don't even know what a signature separator is.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: CGI Tutorial

2006-10-06 Thread hanumizzle
On 10/5/06, Sells, Fred <[EMAIL PROTECTED]> wrote:
> content is great, my comments are editorial.

wrt what document?

> I prefer PDF with bookmarks rather than HTML.
> 1. easy to print the whole thing and read offline.
> 2. easy to find a secion from bookmarks, rather that chasing links
> 3. easy to save on my local "doc" folder so I can be sure It will always be
> there.  (i.e. I don't have to try to find it when you change servers)

wget will save you everytime.

> Of course that's just my opinion, I could be wrong ;)
>
> If you choose to go the PDF route, I've found OpenOffice 2.0 pretty good at
> generating PDF with bookmarks.  Just don't get too complex or OO may hose
> you.

LyX + pdflatex :)

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


Package to handle table text render (handle space or tab between the columns) ?

2006-10-06 Thread KLEIN Stéphane
Hi,

I would like print tabular values on terminal (stdout). Are there 
package to handle table text render ?

Thanks for your help,
Stephane
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Steve Holden
Ilias Lazaridis wrote:
> Ben Finney wrote:
> 
>>"Ilias Lazaridis" <[EMAIL PROTECTED]> writes:
>>
>>
>>>I admit it is difficult to detect that this post is in-topic.
>>>But it is.
>>
>>Really, it's not. If you want a voice, you already have your
>>website. Mailing lists and other discussion forums have conventions
>>about "topic" for a good reason.
> 
> 
> of course.
> 
> 
>>>http://case.lazaridis.com/wiki/Host
>>>http://case.lazaridis.com/wiki/License
>>>http://case.lazaridis.com/wiki/Copyright
>>>
>>>I should have posted them immediately.
>>
>>No, you should have found a forum where you know that the topic is
>>appropriate -- even if that restricts it to your own website.
> 
> 
> ??? my website is not a forum (and I'm currently reducing it to the
> minimum necessary information.)
> 
> and once more: this topic _is_ appropriate for a python / ruby / java
> crosspost.
> 
> really very important (if you don't look to much at the subject but the
> message contents).
> 
Well if you can't even be bothered to formulate a subject line that 
makes its signinficance immediately important you can hrdly be surprised 
at our failure to wade through reams of irrelevant drivel.

If you have a dispute, go resolve it. But not here, please.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Package to handle table text render (handle space or tab between the columns) ?

2006-10-06 Thread hanumizzle
On 10/6/06, KLEIN Stéphane <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like print tabular values on terminal (stdout). Are there
> package to handle table text render ?

Have a look at:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662

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


Re: Access to static members from inside a method decorator?

2006-10-06 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> Thanks for all the help guys ... in almost every way using a metaclass
> seems to be the right solution for what I'm trying to do here.  I say
> almost because there is one thing that is still confusing me: what is
> the most elegant way to provide base-class implementations of methods
> that are expected to be overriden by some of the derived classes (or in
> the case of metaclasses, the classes that either declare __metaclass__
> = Exposed or are derived from such classes).
> 
> Here's what I've just knocked out:

[snip example]

> The problem here is that the implementation of 'bar' inside
> Exposed.__init__ overrides the implementation of bar() in Process,
> which makes sense I guess seeing as Exposed.__init__() is called after
> the class has been initialised.  It's not a problem for
> getExposedMethods() seeing as it's not overriden by any derived
> classes.
> 
> So what is the accepted way of doing this?  Do I need two Exposed
> classes, one is the metaclass that handles all the static mapping
> stuff, and another provides base implementations of methods and is what
> is actually derived from? E.g.:

You define one base type with a custom metaclass and inherit from that. Your
example then becomes:

import sys

class ExposedType( type ):
def __init__( cls, *args, **kw ):
# Track marked exposed methods
cls.s_exposedMethods = []
for superclass in cls.__mro__:
for name, meth in superclass.__dict__.items():
if hasattr( meth, "exposed" ):
cls.s_exposedMethods.append( name )

class Exposed:
__metaclass__ = ExposedType
def getExposedMethods(self):
return self.s_exposedMethods
def bar(self):
print "bar\n"
@staticmethod
def expose( f ):
f.exposed = True
return f

class Process( Exposed):
@Exposed.expose
def foo( self ):
pass
def bar( self ):
print "BAR"


class BotProcess( Process ):
@Exposed.expose
def addBots( self ):
pass

p = Process()
p.bar()

This prints "BAR" as expected.

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


Re: Metaprogramming question

2006-10-06 Thread Georg Brandl
Steve Menard wrote:
> I have a need to create class instance without invokking the class' __init__ 
> method.
> 
> Were I using old-style classes, I'd  use new.instance() function. However, I 
> am using new-style classes and new.instance() complain "TypeError: 
> instance() argument 1 must be classobj, not type" ...
> 
> So my question is, how to replicate new.instance() functionality with new 
> classes?

Use object.__new__.

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


Re: Package to handle table text render (handle space or tab between the columns) ?

2006-10-06 Thread KLEIN Stéphane
hanumizzle a écrit :
> On 10/6/06, KLEIN Stéphane <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I would like print tabular values on terminal (stdout). Are there
>> package to handle table text render ?
> 
> Have a look at:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662

Thanks, this package is very useful ! But I'm suprised than this package 
isn't in python standard library !

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


Re: Python to use a non open source bug tracker?

2006-10-06 Thread Giovanni Bajo
Martin v. Löwis wrote:

> That, in principle, could happen to any other free software as well.
> What is critical here is that SF *hosted* the installation. If we
> would use a tracker that is free software, yet hosted it elsewhere,
> the same thing could happen: the hoster could make modifications to
> it which
> are non-free. Not even the GPL could protect from this case: the
> hoster would be required to publish source only if he publishes
> binaries, but he wouldn't publish any binaries, so he wouldn't need
> to release the source changes, either.
>
> Also, even if it the software is open source and unmodified, there
> still wouldn't be a guarantee that you can get the data out of it
> if you want to. You *only* get the advantages of free software if
> you also run it yourself. Unfortunately, there is a significant
> cost associated with running the software yourself.

You have many good points here, Martin. Let me notice, though, that people
providing hosting not necessarily want to maintain the software by themselves
alone: some python developers could still have admin access to the boxes so to
double check if weird things are being done behind the curtain. I think the
point of uncertainty araises only if you totally trust someone else to do the
job for you.
-- 
Giovanni Bajo


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

Re: Python to use a non open source bug tracker?

2006-10-06 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote:

> Martin> The regular admin tasks likely include stuff like this:
> Martin> - the system is unavailable, bring it back to work
> Martin>   This is really the worst case, and a short response time
> Martin>   is the major factor in how users perceive the service
> Martin> - the system is responding very slowly
>
> To all those people who have been moaning about needing 6-10 people to
> administer the system, in my opinion these are the most important
> reasons to have more than one person available to help.  Python isn't
> only used in the USofA.  It has been very helpful to have
> administrators scattered around the globe who were awake and alert to
> handle problems with python.org when folks in the US were asleep.  Of
> course, spreading the load among several people helps with the other
> tasks as well.
>
> As Martin pointed out in an earlier post, with only one person
> actively administering Subversion (Martin), new requests for access
> had to wait if he was away for an extended period of time.

This is true of many open source projects. I don't dispute that having 6-10
people to administer Roundup would not be good. I dispute that it is the
minimum requirement to make a Roundup installation acceptable for Python
development.

Are bug-tracker configuration issues so critical that having to wait 48-72hrs
to have them fixed is absolutely unacceptable for Python development? It looks
like an overexaggeration. People easily cope with 2-3 days of SVN freezing,
when they are politically (rather than technically) stopped from committing to
SVN. I guess they can wait 48 hrs to be able to close that bug, or open that
other one, or run that query.
-- 
Giovanni Bajo


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


Re: Python to use a non open source bug tracker?

2006-10-06 Thread Paul Rubin
"Giovanni Bajo" <[EMAIL PROTECTED]> writes:
> Are bug-tracker configuration issues so critical that having to wait
> 48-72hrs to have them fixed is absolutely unacceptable for Python
> development? It looks like an overexaggeration. People easily cope
> with 2-3 days of SVN freezing, when they are politically (rather
> than technically) stopped from committing to SVN. I guess they can
> wait 48 hrs to be able to close that bug, or open that other one, or
> run that query.

How often should a tracker freeze anyway?  People with no technical
knowledge at all run BBS systems that almost never freeze.  Is a
tracker somehow more failure-prone?  It's just a special purpose BBS,
I'd have thought.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on pickle tool

2006-10-06 Thread virg
Hi,
 The data is simple dictionary with one or more keys. If i use YAML at
the client (webui) do i have to change serialisation method to YAML at
server also. Without changing serialisation method at server, can i use
any of the deserialisation methods at the client. We cannot change the
serialisation methods at the server since it is not under our control.

Thanks & reagards
virg


hanumizzle wrote:

> On 5 Oct 2006 21:52:56 -0700, virg <[EMAIL PROTECTED]> wrote:
> > Hi,
> >  i have client-server application which is written in python using
> > XMLRPC protocol. The existing client is a command line. Now client
> > application we are converting it as Web UI using java. I have seen some
> > problems in writing a java client. At the server for each request from
> > client, the server sends a response in hashtable and is serialized
> > using "pickle". The python function we call at the server is...
>
> What kind of data are we talking about? Is it strictly dictionary /
> list stuff or is it more complex (functions & other objects)? I can
> see 2 possible options: Jython or YAML. (I have been answering a lot
> of questions re: serialization today and mentioned YAML in all of them
> :))

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


Re: Package to handle table text render (handle space or tab between the columns) ?

2006-10-06 Thread hanumizzle
On 10/6/06, KLEIN Stéphane <[EMAIL PROTECTED]> wrote:
> hanumizzle a écrit :
> > On 10/6/06, KLEIN Stéphane <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> I would like print tabular values on terminal (stdout). Are there
> >> package to handle table text render ?
> >
> > Have a look at:
> >
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662
>
> Thanks, this package is very useful ! But I'm suprised than this package
> isn't in python standard library !

The occurence of such a problem is relatively rare I would imagine.
Rendering anything formatted to a character cell terminal is
inherently limited, which is why I like lynx: it eliminates all the
dumb formatting crap that people put on their websites, and even
collapses multiple columns into a single stream of pages. Yay!

See also reStructuredText for rendering plain text input to HTML and
other formats (includes tables), sil vous plait.

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


Re: help on pickle tool

2006-10-06 Thread hanumizzle
On 6 Oct 2006 01:41:48 -0700, virg <[EMAIL PROTECTED]> wrote:
> Hi,
>  The data is simple dictionary with one or more keys. If i use YAML at
> the client (webui) do i have to change serialisation method to YAML at
> server also. Without changing serialisation method at server, can i use
> any of the deserialisation methods at the client. We cannot change the
> serialisation methods at the server since it is not under our control.

Oh, poopy.

What do you have at the server end?

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


Re: tkinter newsgroup or mailing list

2006-10-06 Thread Hendrik van Rooyen
"Franz Steinhaeusler" <[EMAIL PROTECTED]> wrote:


> Hello NG,
>
> I'm asking this, (although I know a mailing list on gmane
> gmane.comp.python.tkinter and there is so little traffic
> compared to the mailing list of wxPython also mirrored
> on gmane gmane.comp.python.wxpython.
>
> I cannot imagine, that there is no more interest
> in exchanging opinions, or is this really the case?
>
> Is tkinter so simple, that no more questions appear?
> Or is it simply so uninteresting? :)
>
> --
> Franz Steinhaeusler

It is neither uninteresting, nor simple - see my very recent posts here... -
Hendrik

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


Re: Python/Tkinter crash.

2006-10-06 Thread Hendrik van Rooyen
"Steve Holden" <[EMAIL PROTECTED]> wrote:
> Hendrik van Rooyen wrote:
> > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:
> >
> >>Eric Brunel wrote:
> >>
> >>
> >>>AFAIK, Tkinter is not thread safe. Using some kind of lock to serialize
> >>>the calls from different threads may seem to work (I never tested it
> >>>actually), but the safest way I found to use threads with Tkinter was to
> >>>call it only from the thread where the main loop executes.
> >>
> >>the Tkinter binding contains some code that attempts to deal with re-
> >>entrant calls, but I don't know/remember to what extent it's actually
> >>supposed to work (in other words, if the observed problems are bugs or
> >>just limitations).
> >>
> >>(maybe Martin's memory is better?)
> >>
> >>anyway, I usually play it safe and make sure to use a single thread to
> >>deal with the UI.
> >>
> >>
> >
> >
> > I must be dense - After I have called mainloop, if I have not started
another
> > thread to respond to events that are not generated by the user on the screen
(in
> > this case values of variables to display from the field generated by
different
> > processes - there is other hardware out there), how do I get control back to
do
> > the necessary updating? - I suppose I can use the call back after some time
> > thingy to implement a polling loop - possibly as Russel Owen suggested - by
> > polling a queue - but queues are for between threads - and I have seen here
> > somewhere that sockets also want to be the main thread  - so that leaves a
> > pipe - and I have had bad experiences with pipes that are unblocked, and if
I
> > don't unblock it, then the gui will grind to a haltso I need a thread
for
> > the pipe between processes, and a queue between threads, and a time out
based
> > polling loop to read the queue, it seems - is it even safe to change a main
loop
> > variable from another thread? , or should I do it all via commands through a
> > queue, implementing a whole goddam serial protocol just between threads?
and If
> > I don't have another thread to do the timing for the animation bits, then I
must
> > base that on a timed callback too, and somehow keep state between
callbacks...
> > now is it ok to call widget command methods from a callback in the same
thread,
> > or do I have to use invoke?
> >
> > My head is beginning to hurt... - what was a nice simple threaded
implementation
> > is turning into a spaghetti monster of timed callbacks - you thought gotos
was
> > bad? - you aint seen nothing yet...
> >
> See if this helps:
>
>  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965
>
> It's Jacob Hallen's description of how he solved the problem.
>
> regards
>   Steve

Thanks Steve - It is the same one Paul Rubin pointed me to and it describes
nicely how to get the "worker" thread going, and the queue between it and the
GUI thread.

In my case, I will have a thread for input, as well as one for output to send
commands away.  The bit I was complaining about above is the replacement of a
thread to do the animation timing with a "stutter" machine inside the gui
thread, where the timing is handled by callbacks.

A piece of feedback - the stutter machine animation timing is much smoother than
the timing based on threaded sleep calls - less jittery - looks much
better...

So I am kind of glad the thing fell over because this implementation is going to
be much better.

Thank You All.
- Hendrik



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


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Fredrik Lundh
Antoon Pardon wrote:

> Is this general rules documeted somewhere? My impression is that readers
> of the documentation will treat arguments as keyword arguments unless
> this is explicitly contradicted.

Sorry, I missed that this was comp.lang.python.alternate.reality.  My 
mistake.



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


Re: help on pickle tool

2006-10-06 Thread Steve Holden
Fredrik Lundh wrote:
> MonkeeSage wrote:
> 
> 
> 
>>YAML is a little more complex
> 
> 
> a little?  when did you last look at the spec?
> 
> 
>>and a little more mature.
> 
> 
> than JavaScript's expression syntax?  are you sure you're not confusing 
> libraries with standards here?  (has anyone even managed to write a YAML 
> library that's small and simple enough to be "obviously correct"?)

I have to agree that YAML, having started out with simplicity in mind, 
has become a monster that threatens to collapse under its own weight. 
The very existence of JSON is a good indicator that YAML has failed to 
meet its design goals for a significant proportion of application 
developers.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: help on pickle tool

2006-10-06 Thread virg
At the server, based on client request it does some computations , it
sends the result as dictionary (serialized) to the client.

hanumizzle wrote:
> On 6 Oct 2006 01:41:48 -0700, virg <[EMAIL PROTECTED]> wrote:
> > Hi,
> >  The data is simple dictionary with one or more keys. If i use YAML at
> > the client (webui) do i have to change serialisation method to YAML at
> > server also. Without changing serialisation method at server, can i use
> > any of the deserialisation methods at the client. We cannot change the
> > serialisation methods at the server since it is not under our control.
>
> Oh, poopy.
> 
> What do you have at the server end?
> 
> -- Theerasak

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


Re: help on pickle tool

2006-10-06 Thread hanumizzle
On 10/6/06, Steve Holden <[EMAIL PROTECTED]> wrote:

> I have to agree that YAML, having started out with simplicity in mind,
> has become a monster that threatens to collapse under its own weight.
> The very existence of JSON is a good indicator that YAML has failed to
> meet its design goals for a significant proportion of application
> developers.

I am looking at JSON, but YAML does work fine for my purposes w/ no
discernable disadvantages. Of course I didn't implement the library,
so I can't really speak with any kind of expertise on this matter. I'm
just saying that, at least at the front end, it's pretty simple to
use. (JMO)

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


Re: help on pickle tool

2006-10-06 Thread hanumizzle
On 6 Oct 2006 02:03:07 -0700, virg <[EMAIL PROTECTED]> wrote:
> At the server, based on client request it does some computations , it
> sends the result as dictionary (serialized) to the client.

If I interpret your message correctly, you are receiving a Python
dictionary object from the server. Yes? In this case, I guess it might
be necessary to use Jython. I'm drawing a blank otherwise.

(This may be naive, but can you write the client in Python as well?)

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


groupby and itemgetter

2006-10-06 Thread Roman Bertle
Hello,

there is an example how to use groupby in the itertools documentation
(http://docs.python.org/lib/itertools-example.html):

# Show a dictionary sorted and grouped by value
>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(d.iteritems(), key=itemgetter(1))
>>> for k, g in groupby(di, key=itemgetter(1)):
... print k, map(itemgetter(0), g)
...
1 ['a', 'c', 'e']
2 ['b', 'd', 'f']
3 ['g']

Now i wonder why itemgetter is used in this example. More
straightforward is:

>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(d.iterkeys(), key=d.get)
>>> for k, g in groupby(di, key=d.get):
... print k, list(g)
...
1 ['a', 'c', 'e']
2 ['b', 'd', 'f']
3 ['g']

This code does not need the operator module, and its also faster (tested
using timeit). Why was the, imho, more complicated version used as
example in the documentation?

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


Re: Why do this?

2006-10-06 Thread Hendrik van Rooyen
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote:

> On Thu, 5 Oct 2006 11:28:08 +0100, "Matthew Warren"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
> > 
> > Now, I started programming when I was 8 with BBC Basic.
> >
> Remember what the acronym BASIC stands for?

8<---

yes

- Hendrik


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


Re: How do I read Excel file in Python?

2006-10-06 Thread Simon Brunning
On 5 Oct 2006 12:49:53 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Actually was about to post same solution and got same results. (BTW
> Simon, the OP date is Aug 9th, 2006).  Scratched head and googled for
> excel date calculations... found this bug where it treats 1900 as leap
> year incorrectly:
> http://www.ozgrid.com/Excel/ExcelDateandTimes.htm

Ah - I was reading the OP's 8/9/2006 in the European way - DD/MM/.

One might argue over whether DD/MM/ or MM/DD/ are more
rational, but I find it best to avoid *both* those formats, 'cos they
are so easily confused.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: printing variables

2006-10-06 Thread Gerrit Holl
On 2006-10-06 04:50:33 +0200, [EMAIL PROTECTED] wrote:
> say i have variables like these
> 
> var1 = "blah"
> var2 = "blahblah"
> var3 = "blahblahblah"
> var4 = ""
> var5 = "..."..
> 
> bcos all the variable names start with "var", is there a way to
> conveniently print those variables out...
> eg print var* ??
> i don't want to do :
> 
> print var1, var2, var3, var4 ..etc...

Don't do this:

>>> import fnmatch
>>> var1, var2, var3 = "foo", "bar", "baz"
>>> for k in fnmatch.filter(locals(), "var*"):
...  print locals()[k]
...
foo
baz
bar

This is evil.
It's unpythonic.
This is yet another way to do it - QED.

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


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
>
>> Is this general rules documeted somewhere? My impression is that readers
>> of the documentation will treat arguments as keyword arguments unless
>> this is explicitly contradicted.
>
> Sorry, I missed that this was comp.lang.python.alternate.reality.  My 
> mistake.
>

A personal attack won't make my argument go away. It also doesn't
answer my question.

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


Re: help on pickle tool

2006-10-06 Thread virg
Yes your are right. I will send a dictionary object from the server to
the client.
I already have client which is written in python. But we are migrating
the python client which is a command line tool  to Web UI client
(java).  If it is possible to call python function from java, i need to
read more about jython, i am new to this.


hanumizzle wrote:
> On 6 Oct 2006 02:03:07 -0700, virg <[EMAIL PROTECTED]> wrote:
> > At the server, based on client request it does some computations , it
> > sends the result as dictionary (serialized) to the client.
>
> If I interpret your message correctly, you are receiving a Python
> dictionary object from the server. Yes? In this case, I guess it might
> be necessary to use Jython. I'm drawing a blank otherwise.
>
> (This may be naive, but can you write the client in Python as well?)
> 
> -- Theerasak

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


Re: Why do this?

2006-10-06 Thread [EMAIL PROTECTED]
Nobody's mentioned the ability to save a formatted string and then
substitute the variables later...

string = "There are %s ways to skin a %s"

print string % (3, "furry animal")
print string % (166, "beast")

~half.italian

Matthew Warren wrote:
> Ok, not really python focused, but it feels like the people here could
> explain it for me :)
>
> Now, I started programming when I was 8 with BBC Basic.
>
> I never took any formal classes however, and I have never become an
> expert programmer. I'm an average/hobbyist programmer with quite a few
> languages under my belt but I cant do any really fancy tricks with any
> of them. (although Python might be nudging me into more advanced things,
> now I'm starting to get what all the __method__ thingies and operators
> are all about)
>
> I learned over the years to do things like the following, and I like
> doing it like this because of readability, something Python seems to
> focus on :-
>
> Print "There are "+number+" ways to skin a "+furryanimal
>
> But nowadays, I see things like this all over the place;
>
> print("There are %s ways to skin a %s" % (number, furryanimal))
>
> Now I understand there can be additional formatting benefits when
> dealing with numbers, decimal places etc.. But to me, for strings, the
> second case is much harder to read than the first.
>
> I hope I'm not being dense.
>
> The result is that I have pathalogically avoided print "%s" % (thing)
> because it seems to just over complicate things.
>
>
> Ta, :)
>
> Matt.
>
>
>
>
>
> This email is confidential and may be privileged. If you are not the intended 
> recipient please notify the sender immediately and delete the email from your 
> computer.
>
> You should not copy the email, use it for any purpose or disclose its 
> contents to any other person.
> Please note that any views or opinions presented in this email may be 
> personal to the author and do not necessarily represent the views or opinions 
> of Digica.
> It is the responsibility of the recipient to check this email for the 
> presence of viruses. Digica accepts no liability for any damage caused by any 
> virus transmitted by this email.
>
> UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
> Reception Tel: + 44 (0) 115 977 1177
> Support Centre: 0845 607 7070
> Fax: + 44 (0) 115 977 7000
> http://www.digica.com
>
> SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South 
> Africa
> Tel: + 27 (0) 21 957 4900
> Fax: + 27 (0) 21 948 3135
> http://www.digica.com

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


Re: Request for recommendations: shared database without a server

2006-10-06 Thread Paul Boddie
EP wrote:
>

[Client-only application with shared storage and concurrent access]

> Can I get there with MySQL?  Or do I need to pair a pure python
> approach (including the database) with py2exe?  Has anyone achieved
> this with a db framework like Dabo?  Or is there another, entirely
> different and better approach?

One of the features of SQLite version 3 is supposedly the possibility
of having multiple processes safely access an SQLite database:

http://www.sqlite.org/faq.html#q7

Unfortunately, networked storage may not be supported to any level
acceptable for your application.

Paul

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


extract certain values from file with re

2006-10-06 Thread Fabian Braennstroem
Hi,

I would like to remove certain lines from a log files. I had
some sed/awk scripts for this, but now, I want to use python
with its re module for this task. 

Actually, I have two different log files. The first file looks
like:

   ...
   'some text'
   ...
   
   ITER I- GLOBAL ABSOLUTE RESIDUAL -I  
I FIELD VALUES AT MONITORING LOCATION  --I
NOUMOM VMOM WMOM MASS T EN DISS ENTH   
UVWP   TE   EDT
 1  9.70E-02 8.61E-02 9.85E-02 1.00E+00 1.61E+01 7.65E+04 0.00E+00  
1.04E-01-8.61E-04 3.49E-02 1.38E-03 7.51E-05 1.63E-05 2.00E+01
 2  3.71E-02 3.07E-02 3.57E-02 1.00E+00 3.58E-01 6.55E-01 0.00E+00  
1.08E-01-1.96E-03 4.98E-02 7.11E-04 1.70E-04 4.52E-05 2.00E+01
 3  2.64E-02 1.99E-02 2.40E-02 1.00E+00 1.85E-01 3.75E-01 0.00E+00  
1.17E-01-3.27E-03 6.07E-02 4.02E-04 4.15E-04 1.38E-04 2.00E+01
 4  2.18E-02 1.52E-02 1.92E-02 1.00E+00 1.21E-01 2.53E-01 0.00E+00  
1.23E-01-4.85E-03 6.77E-02 1.96E-05 9.01E-04 3.88E-04 2.00E+01
 5  1.91E-02 1.27E-02 1.70E-02 1.00E+00 8.99E-02 1.82E-01 0.00E+00  
1.42E-01-6.61E-03 7.65E-02 1.78E-04 1.70E-03 9.36E-04 2.00E+01
   ...
   ...
   ...
   
  2997  3.77E-04 2.89E-04 3.05E-04 2.71E-02 5.66E-04 6.28E-04 0.00E+00 
-3.02E-01 3.56E-02-7.97E-02-7.11E-02 4.08E-02 1.86E-01 2.00E+01
  2998  3.77E-04 2.89E-04 3.05E-04 2.71E-02 5.65E-04 6.26E-04 0.00E+00 
-3.02E-01 3.63E-02-8.01E-02-7.10E-02 4.02E-02 1.83E-01 2.00E+01
  2999  3.76E-04 2.89E-04 3.05E-04 2.70E-02 5.64E-04 6.26E-04 0.00E+00 
-3.02E-01 3.69E-02-8.04E-02-7.10E-02 3.96E-02 1.81E-01 2.00E+01
  3000  3.78E-04 2.91E-04 3.07E-04 2.74E-02 5.64E-04 6.26E-04 0.00E+00 
-3.01E-01 3.75E-02-8.07E-02-7.09E-02 3.91E-02 1.78E-01 2.00E+01
&&  --  
   
   
   'some text'
   

I actually want to extract the lines with the numbers, write
them to a file and finally use gnuplot for plotting them. A
nicer and more python way would be to extract those numbers,
write them into an array according to their column and plot
those using the gnuplot or matplotlib module :-)

Unfortunately, I am pretty new to the re module and tried
the following so far:


  import re
  pat = re.compile('\ \ \ NO.*?&&', re.DOTALL)
  print re.sub(pat, '', open('log_star_orig').read()) 
  

but this works just the other way around, which means that
the original log file is printed without the number part. So
the next step would be to delete the part from the first
line to '\ \ \ \ NO' and the part from '&&' to the end,
but I do not know how to address the first and last line!?

Would be nice, if you can give me a hint and especially
interesting would it be, when you have an idea, how I can
put those columns in arrays, so I can plot them right away!


A more difficult log file looks like:

 ==
 OUTER LOOP ITERATION =1 CPU SECONDS = 2.40E+01
 --
 |   Equation   | Rate | RMS Res | Max Res |  Linear Solution |
 +--+--+-+-+--+
 | U-Mom| 0.00 | 1.0E-02 | 5.0E-01 |   4.9E-03  OK|
 | V-Mom| 0.00 | 2.4E-14 | 5.6E-13 |   3.8E+09  ok|
 | W-Mom| 0.00 | 2.5E-14 | 8.2E-13 |   8.3E+09  ok|
 | P-Mass   | 0.00 | 1.1E-02 | 3.4E-01 |  8.9  2.7E-02  OK|
 +--+--+-+-+--+
 | K-TurbKE | 0.00 | 1.8E+00 | 1.8E+00 |  5.8  2.2E-08  OK|
 | E-Diss.K | 0.00 | 1.9E+00 | 2.0E+00 | 12.4  2.2E-08  OK|
 +--+--+-+-+--+

 ==
 OUTER LOOP ITERATION =2 CPU SECONDS = 8.57E+01
 --
 |   Equation   | Rate | RMS Res | Max Res |  Linear Solution |
 +--+--+-+-+--+
 | U-Mom| 1.44 | 1.5E-02 | 5.3E-01 |   9.6E-03  OK|
 | V-Mom|99.99 | 1.1E-03 | 6.2E-02 |   5.7E-02  OK|
 | W-Mom|99.99 | 1.9E-03 | 6.0E-02 |   5.9E-02  OK|
 | P-Mass   | 0.27 | 3.0E-03 | 2.0E-01 |  8.9  7.9E-02  OK|
 +--+--+-+-+--+
 | K-TurbKE | 0.03 | 5.4E-02 | 4.4E-01 |  5.8  2.9E-08  OK|
 | E-Diss.K | 0.05 | 8.9E-02 | 9.3E-01 | 12.4  2.6E-08  OK|
 +--+--+-+-+--+



...
...
...


 ==
 OUTER LOOP ITERATION =  416 CPU SECONDS = 2.28E+04
 

Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Diez B. Roggisch
>> No, you should have found a forum where you know that the topic is
>> appropriate -- even if that restricts it to your own website.
> 
> ??? my website is not a forum (and I'm currently reducing it to the
> minimum necessary information.)

You obviously lack the skill to comprehend that a forum isn't meant to 
be a web-forum, but more generally a place where you can express your 
opinions. Which is your website by all means. So, go, restrict yourself 
and voice your private opinions there. Not here.

> and once more: this topic _is_ appropriate for a python / ruby / java
> crosspost.

Why should a private quabble over some neglectable open source 
contributions be of any interest to a community, let alone even three of 
them?

> really very important (if you don't look to much at the subject but the
> message contents).

All that I have seen were some accusations + a few ridiculously small 
subversion entries that showed default parameters changed and the like.

This is on the same level of interest to the communities of python, ruby 
& java as the color of my socks this morning - a deep black with cute 
little skulls imprinted.

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


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread hanumizzle
On 6 Oct 2006 09:21:11 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> > Antoon Pardon wrote:
> >
> >> Is this general rules documeted somewhere? My impression is that readers
> >> of the documentation will treat arguments as keyword arguments unless
> >> this is explicitly contradicted.
> >
> > Sorry, I missed that this was comp.lang.python.alternate.reality.  My
> > mistake.
> >
>
> A personal attack won't make my argument go away. It also doesn't
> answer my question.

Not sure exactly what is going on / being argued about in this thread but HTH :?

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

This doesn't say anything positive or negative about the practice in
question, but does point out that it is possible. I think it is a
reasonable assumption that if it isn't necessary, most users will
elide the keywords.

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


Re: printing variables

2006-10-06 Thread hanumizzle
On 10/6/06, Gerrit Holl <[EMAIL PROTECTED]> wrote:

> >>> import fnmatch
> >>> var1, var2, var3 = "foo", "bar", "baz"
> >>> for k in fnmatch.filter(locals(), "var*"):
> ...  print locals()[k]
> ...
> foo
> baz
> bar
>
> This is evil.
> It's unpythonic.

It's so evil, Perl 4 would look upon it in scorn.

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


Re: Subclassing built-in classes

2006-10-06 Thread Maric Michaud
Le jeudi 05 octobre 2006 20:24, Steve Holden a écrit :
>   >>> class mystr(oldstr):
>   ...   def __new__(*a, **kw):
>   ...     print "called:", a, kw
>   ...

you don't return the string here...

>   >>> import __builtin__
>   >>> __builtin__.str = mystr
>   >>>
> Readline internal error
> Traceback (most recent call last):
>    File "C:\Python24\lib\site-packages\readline\Console.py", line 644,
> in hook_wrapper_23
>      raise TypeError, 'readline must return a string.'

...It should explain this error.

>
> So, what are you trying to say? The type of the literal strings is
> clearly just what it always was. Where, when and how exactly does this
> magical monkey patch affect literals?

ooops, maybe we aren't on the same plan.

As the first post said "...couldn't python (in theory)...", I was discussing 
if it would be possible for python (in some future version) to manage the 
literals so that they use the constructors in the __builtin__ module, I 
didn't say it works actually (I'm aware it's not the case).


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do this?

2006-10-06 Thread Corrado Gioannini
On Thu, Oct 05, 2006 at 10:48:36AM +, Duncan Booth wrote:
> The other main reason for preferring format strings is that they make it 
> easier to refactor the code. If you ever want to move the message away from 
> where the formatting is done then it's a lot easier to extract a single 
> string than it is to clean up the concatenation.

This is a good point imho. 
I often do things like this:

  sql = a_complex_select_sql % (id_foo, value_bar, ...)
  cursor.execute(sql)

inside the body of a function (or a class method), where
a_complex_select_sql is a string, containing several %s, %d ecc., 
that is defined globally (or somewhere else in the class).

c.
-- 
"Thought is only a flash between two long nights,
 but this flash is everything."
  (H. Poincaré)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on pickle tool

2006-10-06 Thread hanumizzle
On 6 Oct 2006 02:29:59 -0700, virg <[EMAIL PROTECTED]> wrote:
> Yes your are right. I will send a dictionary object from the server to
> the client.
> I already have client which is written in python. But we are migrating
> the python client which is a command line tool  to Web UI client
> (java).

Please explain 'Web UI'. Can Python perform an equivalent function?

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


Using twisted, not telnetlib for interactive telnet (WAS: RE: Improving telnetlib)

2006-10-06 Thread Matthew Warren
 

> >The trouble is, I havent got a clue where to start and would 
> appreciate
> >a couple of pointers to get me going...
> >
> 
> I'd suggest taking a look at Twisted, which contains a more complete
> telnet implementation (not as important for being able to launch vi),
> an ssh implementation (which you might want to use instead of telnet),
> a VT102 implementation (which is actually what will help you 
> run programs
> that want to fiddle around with the cursor in fancy ways), as 
> well as a
> fair amount of work towards a simple terminal emulator (to 
> help you keep
> track of what vi has done to your virtual terminal).
> 
> API docs for insults:
> 
> http://twistedmatrix.com/documents/current/api/twisted.conch.i
> nsults.html
> 
> And for the telnet implementation:
> 
> http://twistedmatrix.com/documents/current/api/twisted.conch.t
> elnet.html
>


Looking through those docs quickly leads me into quite a bewildering
maze.

As a kind of way to perhaps get me heading in the right direction and
understanding how I start to hang all that together to get what I want,
I would appreciate it if anyone could look at this little code snippet I
have, and illustrate how I can end up doing the same thing with twisted,
but end up with an interactive connection that can handle vi...  From
there I will happily trundle off by myself.

I think I'm looking for help in getting that AhA! moment :)

Snippet;

C=telnetlib.Telnet(self.TCPAddress)
.
.
((connection / password handling etc..))
.
.
if AliasedSubbedCmd=='__interact':
if system=='UNIX':
retkey='^D'
else:
retkey='^Z'
  print '\nTELNET entity '+self.Name+' entering interactive
mode. Use '+retkey+' to come back\n'
C.mt_interact()


...at this point I am essentially on the remote system command line,
with a very dumb terminal. How could I do this in twisted and end up
with a fairly  clever terminal?


Thanks,

Matt.



This email is confidential and may be privileged. If you are not the intended 
recipient please notify the sender immediately and delete the email from your 
computer. 

You should not copy the email, use it for any purpose or disclose its contents 
to any other person.
Please note that any views or opinions presented in this email may be personal 
to the author and do not necessarily represent the views or opinions of Digica.
It is the responsibility of the recipient to check this email for the presence 
of viruses. Digica accepts no liability for any damage caused by any virus 
transmitted by this email.

UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
Reception Tel: + 44 (0) 115 977 1177
Support Centre: 0845 607 7070
Fax: + 44 (0) 115 977 7000
http://www.digica.com

SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South 
Africa
Tel: + 27 (0) 21 957 4900
Fax: + 27 (0) 21 948 3135
http://www.digica.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Steve Holden
Diez B. Roggisch wrote:
[...]
> 
>>really very important (if you don't look to much at the subject but the
>>message contents).
> 
> 
> All that I have seen were some accusations + a few ridiculously small 
> subversion entries that showed default parameters changed and the like.
> 
> This is on the same level of interest to the communities of python, ruby 
> & java as the color of my socks this morning - a deep black with cute 
> little skulls imprinted.
> 
I have to say I find the colour of your socks *much* more interesting.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Python to use a non open source bug tracker?

2006-10-06 Thread Paul Boddie
Ian Bicking wrote:
>
> It handles some other kinds of repositories now (bzr, I think?).  From
> what I understand fully abstracting out the repository format seems to
> still be a work in progress, but it is in progress and you can write
> repository plugins right now.

That covers Trac, but other projects probably need to get up to speed
with providing similar functionality, too. This is another case where
people should work together rather than developing an interoperability
layer specific to their own project. Certainly, the Bazaar APIs looked
like some kind of promising umbrella project for that kind of thing.

> Trac now includes a WSGI backend, and someone has written a WSGI
> backend for ViewVC (though I don't know if it is included with the
> project).
>
> Clearly you need to get on the WSGI bandwagon ;)

Hey, WebStack supports WSGI, too, you know. ;-)

Paul

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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Richard Brodie

"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> This is on the same level of interest to the communities of python, ruby & 
> java as the 
> color of my socks this morning - a deep black with cute little skulls 
> imprinted.

I did find Andy's claim that he expected contributors to sing a
copyright transfer agreement somewhat unreasonable. It would
depend on the tune though, I guess. 


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


Re: Why do this?

2006-10-06 Thread Duncan Booth
Corrado Gioannini <[EMAIL PROTECTED]> wrote:

> I often do things like this:
> 
>   sql = a_complex_select_sql % (id_foo, value_bar, ...)
>   cursor.execute(sql)
> 
> inside the body of a function (or a class method), where
> a_complex_select_sql is a string, containing several %s, %d ecc., 
> that is defined globally (or somewhere else in the class).
> 
I hope you have a good reason why you don't do:

  cursor.execute(a_complex_select_sql, (id_foo, value_bar, ...))

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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread hanumizzle
On 10/6/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

> This is on the same level of interest to the communities of python, ruby
> & java as the color of my socks this morning - a deep black with cute
> little skulls imprinted.

Where did you get these?

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


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Fredrik Lundh
hanumizzle wrote:

> Not sure exactly what is going on / being argued about in this
 > thread

I'm describing best practices based on long experience of using and 
developing and teaching and writing about Python stuff.  Others have 
other priorities, it seems.

 > This doesn't say anything positive or negative about the practice in
 > question

The tutorial tends to describe mechanisms, not best practices, and it 
also assumes prior programming experience.  After all, basic stuff like 
"minimize coupling" and "don't depend on implementation artifacts" apply 
to all software engineering, not just Python.



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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Erik Max Francis
Steve Holden wrote:

> I have to say I find the colour of your socks *much* more interesting.

Especially what with the skulls and all.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   Can I lay with you / As your wife
-- India Arie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Fredrik Lundh
Diez B. Roggisch wrote:

> This is on the same level of interest to the communities of python, ruby 
> & java as the color of my socks this morning - a deep black with cute 
> little skulls imprinted.

are they perhaps red or green?  and look something like the skulls on this:

 http://www.rusta.se/images/products/31101067_l.jpg



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


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, hanumizzle <[EMAIL PROTECTED]> wrote:
> On 6 Oct 2006 09:21:11 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>> On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> > Antoon Pardon wrote:
>> >
>> >> Is this general rules documeted somewhere? My impression is that readers
>> >> of the documentation will treat arguments as keyword arguments unless
>> >> this is explicitly contradicted.
>> >
>> > Sorry, I missed that this was comp.lang.python.alternate.reality.  My
>> > mistake.
>> >
>>
>> A personal attack won't make my argument go away. It also doesn't
>> answer my question.
>
> Not sure exactly what is going on / being argued about in this thread but HTH 
> :?
>
> http://docs.python.org/tut/node6.html
>
> This doesn't say anything positive or negative about the practice in
> question, but does point out that it is possible. I think it is a
> reasonable assumption that if it isn't necessary, most users will
> elide the keywords.

What I am argueing is that it is very natural for python programmers to
assume that keyword arguments will work if they see a signature. IMO
if a python programmer sees something like:

  abs(x)

It is very natural to envision a corresponding def statement like:

  def abs(x):

and a python function written like this will work if called as
follows:

  abs(x=5)

IMO this is a very natural thought process for a python programmer.
So a python programmer seeing the first will tend to expect that
last call to work.

Now frederic claims that the general rule is different. Now I'm
perfectly happy to accept that those who write the documentation
do so based aacording to the rule frederic stated (you can't/shouldn't
use a parameter as a keyword argument unless explictly stated in the
documentation), but that doesn't contradict that readers may have
different expectations.

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


Re: How do I read Excel file in Python?

2006-10-06 Thread Giles Brown
John Machin wrote:
> [EMAIL PROTECTED] wrote:
> > > > >>> excel_date = 38938.0
> > > > >>> python_date = datetime.date(1900, 1, 1) + 
> > > > >>> datetime.timedelta(days=excel_date)
> > > > >>> python_date
> > > > datetime.date(2006, 8, 11)
> > >
> > > Err, that's the wrong answer, isn't it? Perhaps it shoud be
> > > datetime.date(1900, 1, 29)?
> >
> > Actually was about to post same solution and got same results. (BTW
> > Simon, the OP date is Aug 9th, 2006).  Scratched head and googled for
> > excel date calculations... found this bug where it treats 1900 as leap
> > year incorrectly:
> > http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
> >
> > Plus it treats 1 jan 1900 as day 1, not 0 so just subtract 2 in the
> > calc:
> > >>>python_date = datetime.date(1900, 1, 1) + 
> > >>>datetime.timedelta(days=excel_date - 2)
> > >>> python_date
> > datetime.date(2006, 8, 9)
> >
>
> ... and 2006-08-09 is only the correct answer if the spreadsheet was,
> when last saved, using the 1900 ("Windows") date system, not the 1904
> ("Macintosh") date system.

John,
Just for me own curiosity, is this Excel concept of date numbers same
as the OLE
concept (see http://msdn2.microsoft.com/en-us/library/82ab7w69.aspx or
search "MFC DATE" on MSDN).

I put in some test cases for conversion code here:
   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496683

But would be interested to add any additional info on variations on
this theme.

Cheers,
Giles

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


Re: Automatic import PEP

2006-10-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Robert
Kern wrote:

> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>,
>> Connelly Barnes wrote:
>> 
>>> The main point of autoimp is to make usage of the interactive Python
>>> prompt more productive by including "from autoimp import *" in the
>>> PYTHONSTARTUP file.
>> 
>> The main problem I have with your idea is that any kind of import
>> statement with wildcards in it automatically starts my bogosity meter
>> flashing its "RED ALERT" sign and clanging all its alarm bells.
> 
> "from ... import *" was *designed* for interactive use, which is exactly
> what Connelly is suggesting. It's not a bad thing in that context.

But there is nothing in the language that constrains its use to that
context, is there?

Clang, clang...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> hanumizzle wrote:
>
>> Not sure exactly what is going on / being argued about in this
> > thread
>
> I'm describing best practices based on long experience of using and 
> developing and teaching and writing about Python stuff.  Others have 
> other priorities, it seems.

I just think you shouldn't assume the readers of the documentation
are aware of best practices.

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


Re: Makin search on the other site and getting data and writing in xml

2006-10-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Paul
Boddie wrote:

> Various sites forbid wget and friends as a rule, understandably ...

No, that is not understandable.

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


Re: Recursive descent algorithm able to parse Python?

2006-10-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Diez B. Roggisch wrote:

> I have to admit that I have difficulties to compare LR(k) to recursive
> descent, but the fact that the latter contains backtracking makes it at
> least more powerful than LL(k)

LR(k) is more powerful than LL(k).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I read Excel file in Python?

2006-10-06 Thread kath
John Machin wrote:
> [EMAIL PROTECTED] wrote:
> > > > >>> excel_date = 38938.0
> > > > >>> python_date = datetime.date(1900, 1, 1) + 
> > > > >>> datetime.timedelta(days=excel_date)
> > > > >>> python_date
> > > > datetime.date(2006, 8, 11)
> > >
> > > Err, that's the wrong answer, isn't it? Perhaps it shoud be
> > > datetime.date(1900, 1, 29)?
> >
> > Actually was about to post same solution and got same results. (BTW
> > Simon, the OP date is Aug 9th, 2006).  Scratched head and googled for
> > excel date calculations... found this bug where it treats 1900 as leap
> > year incorrectly:
> > http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
> >
> > Plus it treats 1 jan 1900 as day 1, not 0 so just subtract 2 in the
> > calc:
> > >>>python_date = datetime.date(1900, 1, 1) + 
> > >>>datetime.timedelta(days=excel_date - 2)
> > >>> python_date
> > datetime.date(2006, 8, 9)
> >
>
> ... and 2006-08-09 is only the correct answer if the spreadsheet was,
> when last saved, using the 1900 ("Windows") date system, not the 1904
> ("Macintosh") date system.
>
> All the OP needs to do is to read the documentation that comes with the
> xlrd package. It describes the problems with Excel dates, and offers
> functions for conversion between the Excel date numbers and (year,
> month, day, hour, minute, second) tuples which of course are
> interoperable with Python's datetime module and with mx.DateTime.
>
> | >>> import xlrd
> | >>> xlrd.xldate_as_tuple(38938.0, 0)
> | (2006, 8, 9, 0, 0, 0)
> | >>> xlrd.xldate_as_tuple(38938.0, 1)
> | (2010, 8, 10, 0, 0, 0)
> | >>>
>
> Cheers,
> John



Hi,

>>> import xlrd
>>> book = xlrd.open_workbook("testbook1.xls")
>>> sh = book.sheet_by_index(0)
>>> sh.cell_value(rowx=1,colx=0)
38938.0
>>> type(sh.cell_value(rowx=1,colx=0))

>>> xlrd.xldate_as_tuple( sh.cell_value( rowx = 1,colx= 0 ), 0 )

Traceback (most recent call last):
  File "D:\Python23\Testing area\Python and Excel\xlrdRead.py", line
30, in ?
temp=xlrd.xldate_as_tuple(sh.cell_value(rowx=r,colx=c),0)
  File "D:\PYTHON23\Lib\site-packages\xlrd\xldate.py", line 61, in
xldate_as_tuple
xldays = int(xldate)
ValueError: invalid literal for int(): Date

because xlrd.xldate_as_tuple() function expects first argument to be an
integer. How do I convert an unicode character to integer, so that I
could get the date using xlrd.xldate_as_tuple() function.

Thank you,
sudhir.

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


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Fredrik Lundh
Antoon Pardon wrote:

> IMO this is a very natural thought process for a python programmer.
> So a python programmer seeing the first will tend to expect that
> last call to work.

on the other hand, if a Python programmer *writes* some code instead; 
say, a trivial function like:

def calculate(a, b):
 # approximate; gonna have to fix this later
 return a + b * 1.2

chances are that he did *not* intend this to be called as

 calculate(a=1, b=2)

or, for that matter,

 calculate(b=2, a=1)

or

 calculate(1, b=2)

just because the Python calling machinery currently happens to allow 
that.  And chances are that he did *not* expect to be stuck with those 
argument names for the foreseeable future, just because someone else 
decided to interpret things in the most literal way they possibly could.

Python 2.X doesn't provide convenient support for distinguishing between 
accidental and intentional argument names when you implement a function; 
that's a wart, not a feature, and it may be addressed in 3.X.



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


RE: OT Request

2006-10-06 Thread MatthewWarren
> This email is confidential and may be privileged. If you are not the intended 
> recipient please notify the sender immediately and delete the email from your 
> computer.
>
> You should not copy the email, use it for any purpose or disclose its 
> contents to any other person.
> Please note that any views or opinions presented in this email may be 
> personal to the author and do not necessarily represent the views or opinions 
> of Digica.
> It is the responsibility of the recipient to check this email for the 
> presence of viruses. Digica accepts no liability for any damage caused by any 
> virus transmitted by this email.
>

>   Pardon, but is there any possibility you can disable this rather
>long block? I'm presuming you are accessing via the mailing list, but
>hat mailing list is gatewayed to a Usenet news group (and unless you've
>anaged to embed an X-noarchive header in email, Google Groups is going
>o have the message available in perpetuity). There is no single
>intended recipient" -- the messages are being sent to anyone in the
>orld interested in reading comp.lang.python, so all this overhead is
>eaningless.

No problem, and thanks for pointing it out.  It gets silently added on
its way through, and i just hadnt noticed it in my posts.

Posting this time through google groups :)

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


Re: OT Request

2006-10-06 Thread Fredrik Lundh
Matthew Warren wrote:

> No problem, and thanks for pointing it out.  It gets silently added on
> its way through, and i just hadnt noticed it in my posts.

oh, no need to apologize.  and it did make a certain sense in some of 
your posts:

> Okok, I'm silly.
> 
> This email is confidential and may be privileged. If you are not the
> intended recipient please notify the sender immediately and delete the
> email from your computer.
> 
> You should not copy the email, use it for any purpose or disclose its
> contents to any other person.
> 
> Please note that any views or opinions presented in this email may be
> personal to the author and do not necessarily represent the views or
> opinions of Digica.

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


how to convert UNICODE to integer in Python?

2006-10-06 Thread kath
Hi,

>>> import xlrd
>>> book = xlrd.open_workbook("testbook1.xls")
>>> sh = book.sheet_by_index(0)
>>> sh.cell_value(rowx=1,colx=0)
38938.0
>>> type(sh.cell_value(rowx=1,colx=0))

>>> xlrd.xldate_as_tuple( sh.cell_value( rowx = 1,colx= 0 ), 0 )

Traceback (most recent call last):
  File "D:\Python23\Testing area\Python and Excel\xlrdRead.py", line
30, in ?
temp=xlrd.xldate_as_tuple(sh.cell_value(rowx=r,colx=c),0)
  File "D:\PYTHON23\Lib\site-packages\xlrd\xldate.py", line 61, in
xldate_as_tuple
xldays = int(xldate)
ValueError: invalid literal for int(): Date

because xlrd.xldate_as_tuple() function expects first argument to be an
integer. How do I convert an unicode character to integer, so that I
could get the date using xlrd.xldate_as_tuple() function.

Thank you,
kath.

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


Re: OT Request

2006-10-06 Thread MatthewWarren
Funniest bit of my day so far :)

Fredrik Lundh wrote:
> Matthew Warren wrote:
>
> > No problem, and thanks for pointing it out.  It gets silently added on
> > its way through, and i just hadnt noticed it in my posts.
>
> oh, no need to apologize.  and it did make a certain sense in some of
> your posts:
>
> > Okok, I'm silly.
> >
> > This email is confidential and may be privileged. If you are not the
> > intended recipient please notify the sender immediately and delete the
> > email from your computer.
> >
> > You should not copy the email, use it for any purpose or disclose its
> > contents to any other person.
> >
> > Please note that any views or opinions presented in this email may be
> > personal to the author and do not necessarily represent the views or
> > opinions of Digica.

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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Diez B. Roggisch
hanumizzle schrieb:
> On 10/6/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> 
>> This is on the same level of interest to the communities of python, ruby
>> & java as the color of my socks this morning - a deep black with cute
>> little skulls imprinted.
> 
> Where did you get these?

You can buy them at H&M, but unfortunately they aren't always in stock. 
But little skulls on thingies the have quite often - I don't wanna get 
into the details of my underwear :P

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


Re: how to convert UNICODE to integer in Python?

2006-10-06 Thread Fredrik Lundh
kath wrote:

> xldays = int(xldate)
> ValueError: invalid literal for int(): Date
> 
> because xlrd.xldate_as_tuple() function expects first argument to be an
> integer. How do I convert an unicode character to integer, so that I
> could get the date using xlrd.xldate_as_tuple() function.

the error doesn't say anything about Unicode characters, it says that 
someone's passing the string "Date" to the int() function.

 >>> int("Date")
Traceback (most recent call last):
   File "", line 1, in ?
ValueError: invalid literal for int(): Date



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


Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
>
>> IMO this is a very natural thought process for a python programmer.
>> So a python programmer seeing the first will tend to expect that
>> last call to work.
>
> on the other hand, if a Python programmer *writes* some code instead; 
> say, a trivial function like:
>
>   def calculate(a, b):
>  # approximate; gonna have to fix this later
>  return a + b * 1.2
>
> chances are that he did *not* intend this to be called as
>
>  calculate(a=1, b=2)
>
> or, for that matter,
>
>  calculate(b=2, a=1)
>
> or
>
>  calculate(1, b=2)

Well maybe he didn't intend that, but how is the reader of the
documentation to know that? The reader can only go by how
things are documented. If those are not entirely consistent
with the intend of the programmer, that is not the readers
fault.

> just because the Python calling machinery currently happens to allow 
> that.  And chances are that he did *not* expect to be stuck with those 
> argument names for the foreseeable future, just because someone else 
> decided to interpret things in the most literal way they possibly could.

And how it the reader of the documentation to know about the
expectations of the programmer? It isn't the readers fault
if those expectations aren't easily inferred from the documenation.

> Python 2.X doesn't provide convenient support for distinguishing between 
> accidental and intentional argument names when you implement a function; 
> that's a wart, not a feature, and it may be addressed in 3.X.

Again that is not the fault of those that read the documentation. If
this discinction can't be easily made in python 2.X, you can't fault
the reader for coming to a conclusion that seems to follow rather
naturally from how python currently works.

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


Re: Python to use a non open source bug tracker?

2006-10-06 Thread Martin v. Löwis
Paul Rubin schrieb:
> How often should a tracker freeze anyway?  People with no technical
> knowledge at all run BBS systems that almost never freeze.  Is a
> tracker somehow more failure-prone?  It's just a special purpose BBS,
> I'd have thought.

For whatever reason, the SF bug tracker is often down, or not
responding. I'm uncertain why that is, but it's a matter of
fact that this was one of the driving forces in moving away
from SF (so it is a real problem).

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


Re: Why do this?

2006-10-06 Thread Corrado Gioannini
On Fri, Oct 06, 2006 at 10:09:14AM +, Duncan Booth wrote:
> I hope you have a good reason why you don't do:
> 
>   cursor.execute(a_complex_select_sql, (id_foo, value_bar, ...))
> 
> instead.

hehe. 
i was just trying to be didactic, simplifying the actual situation.
(anyway, sometimes i had to print, or store, the sql statement, or 
to execute the same sql statement on different databases etc. etc..)

regards,
c.
-- 
 no, sono sempre io, non mi cambierete quel che ho dentro
forse ho solo un'altra faccia
  ho più cicatrici di prima, sorrido un po' meno,
  forse penso di più.
   (Kina)

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


Skullsocks to the rescue - was [irrelevant squabble of IL]

2006-10-06 Thread Diez B. Roggisch
Fredrik Lundh schrieb:
> Diez B. Roggisch wrote:
> 
>> This is on the same level of interest to the communities of python, 
>> ruby & java as the color of my socks this morning - a deep black with 
>> cute little skulls imprinted.
> 
> are they perhaps red or green?  and look something like the skulls on this:

Due to the unexpected interest in my foot-garments, I here present
an image of  my current collection of skullsocks(tm)


http://www.roggisch.de/img/skullsocks.jpg


They can be bought at our friendly swedish clothes retailer, H&M.

Have a nice day :)

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


Re: help on pickle tool

2006-10-06 Thread virg
Hi,

Yes, using python client we are able deserialize data using

r = pickle.loads(result).

where result is a response from the server and r is a dictionary after
deserialization.
For serialisation at the server written in python using
pickle.dumps(result, 2)

Now we are developing web based Client using java. So we are writing
client in java. If server and client are in python we dont see any
problems since we are using same serialisation tool "pickle". Now we
have seen problems because we are writing client in java. we did not
find equivalent function on java for this tool pickle. If i use
standard java desrialisation functions i am getting error as invalid
header becasue of incompatibility between python and java. Please help
me if you have any clue

regards,
- Virg

hanumizzle wrote:
> On 6 Oct 2006 02:29:59 -0700, virg <[EMAIL PROTECTED]> wrote:
> > Yes your are right. I will send a dictionary object from the server to
> > the client.
> > I already have client which is written in python. But we are migrating
> > the python client which is a command line tool  to Web UI client
> > (java).
>
> Please explain 'Web UI'. Can Python perform an equivalent function?
> 
> -- Theerasak

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


Copying file descriptors

2006-10-06 Thread Didier Trosset
I am using the following code. It is used to spawn a new process (using 
popen) and to change the file handles so that subsequent writes to 
standard output with printf goes into this child process standard input.


   import os

   child_stdin = os.popen("cat -", "w")
   old_stdout = os.dup(1)
   os.close(child_stdin.fileno())

   print "foo"

   os.dup2(old_stdout, 1)
   os.close(old_stdout)



It works. But the results is:
   close failed: [Errno 9] Bad file descriptor
when I am using python 2.4. Note that python 2.3 did not output such an 
error.

I am guessing that upon ending the script, python tries to close 
child_stdin file object, whereas the underlying file descriptor has 
already been closed. Thus the error.

Does anyone knows what to do to avoir this error message?

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


Re: how to convert UNICODE to integer in Python?

2006-10-06 Thread kath

Fredrik Lundh wrote:
> kath wrote:
>
> > xldays = int(xldate)
> > ValueError: invalid literal for int(): Date
> >
> > because xlrd.xldate_as_tuple() function expects first argument to be an
> > integer. How do I convert an unicode character to integer, so that I
> > could get the date using xlrd.xldate_as_tuple() function.
>
> the error doesn't say anything about Unicode characters, it says that
> someone's passing the string "Date" to the int() function.
>
>  >>> int("Date")
> Traceback (most recent call last):
>File "", line 1, in ?
> ValueError: invalid literal for int(): Date
> 
> 


Hi,

Thanks for reminding me. I was wrong. 

Regards,
kath

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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Diez B. Roggisch
Richard Brodie schrieb:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>> This is on the same level of interest to the communities of python, ruby & 
>> java as the 
>> color of my socks this morning - a deep black with cute little skulls 
>> imprinted.
> 
> I did find Andy's claim that he expected contributors to sing a
> copyright transfer agreement somewhat unreasonable. It would
> depend on the tune though, I guess. 

There are lots of people out there how require such things, and it might 
even be for malicious reasons sometimes - not that I'm aware of that in 
the current case, mind you! There are plenty of good reasons to do so as 
well.

The point here is: nobody is forced to sign such agreement, breakout is 
not an effort that has any importance for the python, let alone all 
three communities, and this is a totally private matter between two 
people. Maybe fellow co-developers are interested, but then there should 
be an email list.

And as Illias has a history of postings that claim others post 
containing irrelevant stuff - either to him, or in general - he is on 
very thin ice here.

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


Re: Python to use a non open source bug tracker?

2006-10-06 Thread Paul Boddie
Martin v. Löwis wrote:
>
> For whatever reason, the SF bug tracker is often down, or not
> responding. I'm uncertain why that is, but it's a matter of
> fact that this was one of the driving forces in moving away
> from SF (so it is a real problem).

As I asked before, did anyone look into asking large-scale users of the
various considered products about their experiences with regard to
reliability, scalability, and so on? Obviously, SourceForge is a
special case since it's a closed service with a code base divergent
from the last open source release (and possibly from commercial
deployments of the code), whereas the other contenders except for
Launchpad, along with non-considered but widely-deployed products,
presumably contribute to a certain amount of public experience that can
be drawn upon.

Paul

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


Re: Skullsocks to the rescue - was [irrelevant squabble of IL]

2006-10-06 Thread Fredrik Lundh
Diez B. Roggisch wrote:

> Due to the unexpected interest in my foot-garments, I here present
> an image of  my current collection of skullsocks(tm)
> 
> http://www.roggisch.de/img/skullsocks.jpg

ah, pretty close, and the green color is absolutely the right one, but 
my socks has the skulls drawn on top of the crossbones.

(no, I'm not going to fetch a camera.  not right now, at least.  and no, 
I haven't gotten around to buy a matching power drill, either.  but it's 
tempting...)

> They can be bought at our friendly swedish clothes retailer, H&M.

all Python programmers should have at least pair, I think.



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


Re: [Linux] Detect a key press

2006-10-06 Thread Sergei Organov
"Jia,Lu" <[EMAIL PROTECTED]> writes:

> Hi all
>   I write a program to detect key press,but , why there is a *space*
> before the character I typed.??

There is none. The output I see when I type 1 2 q is:

->1
   ->2
  ->q

If that is what you see, the problem is in your

   print "->%s"%ch

statement. It implicitly outputs '\n' at the end, and when terminal is
set in raw mode, this is not translated into '\r\n' as when terminal is
in canonical mode.

Try

  print "->%s\r" % ch

or just

  sys.stdout.write(ch)

-- Sergei.

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


Re: CGI Tutorial

2006-10-06 Thread Jim
Sells, Fred wrote:
> content is great, my comments are editorial.
>
> I prefer PDF with bookmarks rather than HTML.
>   
> If you choose to go the PDF route, I've found OpenOffice 2.0 pretty good at
> generating PDF with bookmarks.  Just don't get too complex or OO may hose
> you.
Since you replied to a person who replied to me and who mentioned it, I
assume that you are talking about my text _Linear Algebra_ (I have
another text up, _Number Theory_, that no one seems to know about so I
assume you are not talking about it).  If that's true then it is way
off topic, not just for the thread but for the newsgroup.  Please write
me separately at the address given on the web page for the text.

But, my book doesn't use any HTML.  It also doesn't come from a word
processor, since for mathematics the standard is LaTeX, so maybe you
are talking about something entirely unrelated?  But at all events it
seems not to have to do with CGI.

Jim

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


TypeError: unsupported type for timedelta days component: unicode

2006-10-06 Thread kath
Hi,

the following shows the contents of "datebook.xls"

Date
8/9/2006
8/9/2006
8/9/2006
8/9/2006
8/9/2006

# read_date.py
import xlrd

book = xlrd.open_workbook("datebook.xls")
sh = book.sheet_by_index(0)
ex_qdate=sh.cell_value(rowx=1,colx=0)
pyd=datetime.date(1900,1,1)+datetime.timedelta(days=sh.cell_value(rowx=1,colx=0))
print pyd

for c in range(sh.ncols):
for r in range(sh.nrows):
print sh.cell_value(rowx=r,colx=c)
print
datetime.date(1900,1,1)+datetime.timedelta(days=sh.cell_value(rowx=r,colx=c))

 Output 
>>>
2006-08-11
Date
Traceback (most recent call last):
  File "D:/Python23/Testing area/Python and Excel/read_date.py", line
12, in ?
print
datetime.date(1900,1,1)+datetime.timedelta(days=sh.cell_value(rowx=r,colx=c))
TypeError: unsupported type for timedelta days component: unicode
>>>

The first print statement gives me desired output. Whats wrong with
second print statement?
When I give the discriptor or index explicitly its giving the correct
answer.
Why not in the loop?

Am I wrong some where?


Please help me.
Thank you,
Sudhir.

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


Re: Access to static members from inside a method decorator?

2006-10-06 Thread urielka
no need for all that,i wrote a basic Ajax framework for cherrypy that
features a Ajax.Net feature,exposing functions to JavaScript via
attributes(or in python via decorators),here is a decorator that run
one time(i.e. before running the actual code) and get the name of the
class
[code]
def AddFunction(func):
stack=inspect.stack()
ClsName=stack[1][3]#get the class name from the stack
#now you both have the ClassName and the func object,so you can
populate your list
return func#return the decorated function
[/code]
it use the module inspect,to inspect the stack.

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


Re: How to run in background?

2006-10-06 Thread billie
I'm sorry. I tried with "windows=myscript.py" but it doesn't seem to
work.
I really don't know where find this information that's extremely
important for me.
I googled a lot but I didn't found a solution for my problem. :-\

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


Re: Python to use a non open source bug tracker?

2006-10-06 Thread Martin v. Löwis
Paul Boddie schrieb:
> As I asked before, did anyone look into asking large-scale users of the
> various considered products about their experiences with regard to
> reliability, scalability, and so on? 

I didn't ask anyone, primarily because of lack of time.

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


Re: How to run in background?

2006-10-06 Thread Fredrik Lundh
billie wrote:

> I'm sorry. I tried with "windows=myscript.py" but it doesn't seem to
> work.

it does work, so you've probably made some simple mistake.  figuring
out what that is is a bit hard if you don't provide more information, 
though.

can you perhaps post (the relevant portions of) your setup.py file ?



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


Re: extract certain values from file with re

2006-10-06 Thread Bernard
Hi Fabian,
I'm still a youngster in Python but I think I can help with the
"extracting data from the log file" part. As I'm seeing it right now,
the only character separating the numbers below is the space character.
You could try splitting all the lines by that character starting from
the NO Column. The starting point of the split function could easily be
defined by regexes. Using this regex : \s+\d+\s{1,2}[\d\w\.-]*\s+ ... I
was able to extract the 2 first columns of every row. And since the
while document is structured like a table, you could define a
particular index for each of the columns of the split result.

I sincerely hope this can help in any way :)

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


Re: TypeError: unsupported type for timedelta days component: unicode

2006-10-06 Thread John Machin
kath wrote:
> Hi,
>
> the following shows the contents of "datebook.xls"
>
> Date
> 8/9/2006
> 8/9/2006
> 8/9/2006
> 8/9/2006
> 8/9/2006
>
> # read_date.py
> import xlrd
>
> book = xlrd.open_workbook("datebook.xls")
> sh = book.sheet_by_index(0)
> ex_qdate=sh.cell_value(rowx=1,colx=0)
> pyd=datetime.date(1900,1,1)+datetime.timedelta(days=sh.cell_value(rowx=1,colx=0))


Go back and read *ALL* the responses to your previous question. The
above is *INCORRECT*. As you can see, for input of 8/9/2006 (M/D/
format), it produces 2006-08-11.
*Please* read the sections on Excel dates in the xlrd documentation.


> print pyd
>
> for c in range(sh.ncols):
> for r in range(sh.nrows):
> print sh.cell_value(rowx=r,colx=c)

Problem 1: you are including the heading.
Add this in here:
   print "row %d, col %d, cell_type %d" % (r, c,
sh.cell_type(r, c))
and that might give you a clue.

> print
> datetime.date(1900,1,1)+datetime.timedelta(days=sh.cell_value(rowx=r,colx=c))

Maybe Problem 2: your posting seems to be missing indentation on this
line.

>
>  Output 
> >>>
> 2006-08-11
> Date
> Traceback (most recent call last):
>   File "D:/Python23/Testing area/Python and Excel/read_date.py", line

How do you manage to get both "D:" and "/" in a path? Which version of
which OS are you running?

Why are you using Python 2.3?

Why are you keeping your own files in a subdirectory of your Python
installation?

> 12, in ?
> print
> datetime.date(1900,1,1)+datetime.timedelta(days=sh.cell_value(rowx=r,colx=c))
> TypeError: unsupported type for timedelta days component: unicode
> >>>
>
> The first print statement gives me desired output. Whats wrong with
> second print statement?
> When I give the discriptor or index explicitly its giving the correct
> answer.
> Why not in the loop?

As explained above.

>
> Am I wrong some where?

I think that's not an reasonable conclusion :-)

HTH,
John

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


Re: TypeError: unsupported type for timedelta days component: unicode

2006-10-06 Thread Fredrik Lundh
John Machin wrote:

> Why are you keeping your own files in a subdirectory of your Python
> installation?

IDLE defaults to the installation directory, so that's an easy thing
to do.  and as long as you put it in a subdirectory, it's not much of a 
problem either.  (at least not until you want to uninstall Python...)



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


Google breaks Usenet (was Re: How can I correct an error in an old post?)

2006-10-06 Thread Aahz
In article <[EMAIL PROTECTED]>,
Bryan Olson  <[EMAIL PROTECTED]> wrote:
>Blair P. Houghton wrote:
>>
>> But they do about 10 things totally wrong with Google groups that
>> I'd've fixed in my spare time in my first week if they'd hired me back
>> when I was interviewing with them.
>> 
>> So if they want it to work, they know where to find me.
>
>Doesn't seem likely, does it? But don't let it stop you. You don't
>need Google's permission to build a better Usenet service. They
>don't have any copyright on the posts, or other special protection.
>I'm a former Googler myself and I use their service all the time,
>but if yours is better I'll switch.

The problem is the network effect.  In this case, what Google has that
can't be replicated is the history of posts.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graph Theory

2006-10-06 Thread diffuser78
Thanks for all your responses.

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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Lawrence Oluyede
Ilias Lazaridis <[EMAIL PROTECTED]> wrote:
> and once more: this topic _is_ appropriate for a python / ruby / java
> crosspost.
> 
> really very important (if you don't look to much at the subject but the
> message contents).

I really don't understand why your public announcement should be in
topic in this newsgroup.

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to use a non open source bug tracker?

2006-10-06 Thread skip

Paul> How often should a tracker freeze anyway?  People with no
Paul> technical knowledge at all run BBS systems that almost never
Paul> freeze.  Is a tracker somehow more failure-prone?  It's just a
Paul> special purpose BBS, I'd have thought.

And when those BBS systems get hacked they can be down for extended periods
of time.  I have an old Porsche and participate in the discussion forums at
914club.com.  There is a team of admins to moderate the discussion forums,
but just one guy to do the technical work.  The site is powered by some
common forum software package (really a modern day bbs).  It gets hacked
from time-to-time.  When that happens, we're all left with the DTs while the
board gets put back together.

As for this question from Giovanni:

Giovanni> Are bug-tracker configuration issues so critical that having
Giovanni> to wait 48-72hrs to have them fixed is absolutely unacceptable
Giovanni> for Python development? 

Yes, I think that would put a crimp in things.  The downtimes we see for the
SourceForge tracker tend to be of much shorter duration than that (typically
a few hours) and cause usually minor problems when they occur.  For the
tracker to be down for 2-3 days would make the developers temporarily blind
to all outstanding bug reports and patches during that time and prevent
non-developers from submitting new bugs, patches and comments.  Those people
might well forget about their desired submission altogether and not return
to submit them once the tracker was back up.

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


testing machine responsiveness

2006-10-06 Thread Tim Arnold
I have a bunch of processes that I farm out over several HPux machines on 
the network. There are 60 machines to choose from and I want to
(1) find out which ones are alive (the 'ping' method below) and
(2) sort them by their current load (the 'get' method below, using the rup 
command)

I'm no expert--I bet what I'm doing could be done better. I'd appreciate any 
tips, caveats, etc.
Thanks in advance for looking at the code.
--Tim Arnold


Say the host names are in a global list tmpList...
# The final sorted list of cpus is called as:
cpuList  = [x[1] for x in Machines().get()]

#
class Machines(object):
' List of available, alive machines. '
def __init__(self):
global tmpList
self.asList = [y for y in tmpList if self.ping(y)]
self.asString = ' '.join(self.asList)

def ping(self, cpu):
''' Determine whether a machine is alive.
tcp connect to machine, port 7 (echo port).
Response within 3 seconds -> return true
'''
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
try:
s.connect((cpu,7))
except:
return 0
try:
s.send('test')
s.recv(128)
s.close()
return 1
except:
return 0

   def get(self, maxLoad=3.0,):
''' return sorted list of available machines, sorted on load.
Optionally, specify maxload, default is no more than 3.0
'''
tmpDict = {}
retList = []
try:
rup = os.popen('rup %s | sort -n -t, -k4 | grep day' % 
(self.asString))
except OSError:
return self.asList

for s in rup:
(name, t0) = s.split(' ',1)
(t1,t2,t3,avgLoad,t4) = s.split(',')
load = float(avgLoad)
if load < maxLoad:
tmpDict['%s.com' % name] = load

for (l, n) in [(v[1], v[0]) for v in tmpDict.items()]:
retList.append((l, n))
retList.sort()
return retList


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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Paul McGuire
"Erik Max Francis" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Steve Holden wrote:
>
>> I have to say I find the colour of your socks *much* more interesting.
>
> Especially what with the skulls and all.
>

Yeah, where'd you get those socks?  (Halloweens a-comin')
:)

-- Paul 


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


Re: Scientific computing and data visualization.

2006-10-06 Thread Carl Friedrich Bolz
[EMAIL PROTECTED] wrote:
> A commonly used data analysis framework is root (http://root.cern.ch).
> It offers a object oriented C++ framework with all kind of things one
> needs for plotting and data visualization. It comes along with PyRoot,
> an interface making the root objects available to Python.
> Take a look at the root manual for examples, it also contains a section
> describing the use of PyRoot.

I can definitively second that. ROOT is a bit hard to learn but very,
very powerful and PyRoot is really a pleasure to work with.

Cheers,

Carl Friedrich Bolz

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


Re: Automatic import PEP

2006-10-06 Thread Robert Kern
Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, Robert
> Kern wrote:
> 
>> Lawrence D'Oliveiro wrote:
>>> In message <[EMAIL PROTECTED]>,
>>> Connelly Barnes wrote:
>>>
 The main point of autoimp is to make usage of the interactive Python
 prompt more productive by including "from autoimp import *" in the
 PYTHONSTARTUP file.
>>> The main problem I have with your idea is that any kind of import
>>> statement with wildcards in it automatically starts my bogosity meter
>>> flashing its "RED ALERT" sign and clanging all its alarm bells.
>> "from ... import *" was *designed* for interactive use, which is exactly
>> what Connelly is suggesting. It's not a bad thing in that context.
> 
> But there is nothing in the language that constrains its use to that
> context, is there?

No. What's your point?

Connelly Barnes states that the main point of autoimp is to make usage of the 
interactive prompt better by including "from autoimp import *" into a 
PYTHONSTARTUP file. That file is only executed for interactive sessions. He's 
not suggesting that people do "from autoimp import *" in their modules.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Re: switching to numpy and failing, a user story

2006-10-06 Thread sturlamolden

[EMAIL PROTECTED] wrote:

> Given the quality of python's (free) documentation and how good it's
> been for a very long time, it's bit ironic to be using the phrase
> "normal open-source documentation" on this mailing list. Numeric
> python, which numpy aspires to be a replacement for, has perfectly
> reasonable documentation. It wasn't perfect, but it told you pretty
> much everything you needed to know to get started, use the system, and
> build extension modules. I guess this set my expectations for NumPy.


NumPy is perhaps the most well thought array object known to man. That
includes those of Matlab, Fortran 95 and C++ libraries (e.g. Blitz++).
I don't think we should be modest about the quality of NumPy. NumPy
allows us to do serious number crunching in a well designed language -
Python. Scientists pay thosands of dollars for software that are not
par with NumPy, and we get NumPy for free.

Those involved in the development of NumPy must receive some
compensation. Financial support to NumPy also ensure that the
developmentcan continue. I for one does not want to see NumPy as
abandonware in the near future. Unfortunately, getting scientists to
make volounteer financial contributions to an open-source project has
proven difficult. A modest charge for the documentation is a fair way
of doing things. I can not be reimbursed by my employer for making a
donation to NumPy, so I would have to take that out of my own pocket. I
can be reimbursed for buying a copy of the documentation, however.

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


Re: profiling memory usage

2006-10-06 Thread MrJean1
The latest Python release 2.5 includes improvements to the memory
manager and *may* work better for you, it all depends on the root cause
of the problem.  For more details, see the 5th bullet on this page
.

/Jean Brouwers


Eddie wrote:
> Hi,
>
> I am looking for a method to profile memory usage in my python program.
> The program provides web service and therefore is intended to run for a
> long time. However, the memory usage tends to increase all the time,
> until in a day or two the system cannot handle it any more and starts
> to do constant swapping. Is there a way to look at which objects or
> variables are taking the huge amount of memory space?
> 
> Thanks,
> 
> Eddie

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


Re: MIMEMultipart() and CRLF vs RFC 2046

2006-10-06 Thread alf
Gabriel Genellina wrote:
> At Thursday 5/10/2006 18:52, alf wrote:
> 
>> according to rfc2046, line breaks in MIME are CRLF. However python just
>> uses LF like in the following example:
> 
> 
> The comments inside generator.py say CRLF everywhere, but the code 
> simply uses print >>f

they also define NL as '\n\ only.

> You should file a bug report at 
> http://sourceforge.net/tracker/?group_id=5470
done

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


Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton

2006-10-06 Thread Ilias Lazaridis
Richard Brodie wrote:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> > This is on the same level of interest to the communities of python, ruby & 
> > java as the
> > color of my socks this morning - a deep black with cute little skulls 
> > imprinted.
>
> I did find Andy's claim that he expected contributors to sing a
> copyright transfer agreement somewhat unreasonable. It would
> depend on the tune though, I guess.

Such agreements seem to be nothing special within Software Business
(although the Assembla one looks a little bit one-sided). Companies
have to ensure that they own the software, otherwise they cannot sell
the product.

For a contribution which happens based on reduced rates and in context
of Open Source, such an agreement is of course inacceptable (developer
looses all rights).

That's why I've provided an alternative agreement (Joint Copyright),
which covers the needs of both sides:

http://case.lazaridis.com/wiki/AssemblaReworkProject#CopyrightAssignment

.

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


Re: How do I read Excel file in Python?

2006-10-06 Thread John Machin

Giles Brown wrote:
> John Machin wrote:
> > [EMAIL PROTECTED] wrote:
> > > > > >>> excel_date = 38938.0
> > > > > >>> python_date = datetime.date(1900, 1, 1) + 
> > > > > >>> datetime.timedelta(days=excel_date)
> > > > > >>> python_date
> > > > > datetime.date(2006, 8, 11)
> > > >
> > > > Err, that's the wrong answer, isn't it? Perhaps it shoud be
> > > > datetime.date(1900, 1, 29)?
> > >
> > > Actually was about to post same solution and got same results. (BTW
> > > Simon, the OP date is Aug 9th, 2006).  Scratched head and googled for
> > > excel date calculations... found this bug where it treats 1900 as leap
> > > year incorrectly:
> > > http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
> > >
> > > Plus it treats 1 jan 1900 as day 1, not 0 so just subtract 2 in the
> > > calc:
> > > >>>python_date = datetime.date(1900, 1, 1) + 
> > > >>>datetime.timedelta(days=excel_date - 2)
> > > >>> python_date
> > > datetime.date(2006, 8, 9)
> > >
> >
> > ... and 2006-08-09 is only the correct answer if the spreadsheet was,
> > when last saved, using the 1900 ("Windows") date system, not the 1904
> > ("Macintosh") date system.
>
> John,
> Just for me own curiosity, is this Excel concept of date numbers same
> as the OLE
> concept (see http://msdn2.microsoft.com/en-us/library/82ab7w69.aspx or
> search "MFC DATE" on MSDN).
>
> I put in some test cases for conversion code here:
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496683
>
> But would be interested to add any additional info on variations on
> this theme.
>

Hi Giles,

Those OLE date numbers coincide with Excel 1900-system date numbers
from 1900-03-01 onwards. Excel treats day 60 as the non-existent
1900-02-29.

Cheers,
John

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


Re: How do I put % in a format sting?

2006-10-06 Thread John Salerno
Carsten Haese wrote:

> While I wholeheartedly agree with the sentiment, calling the "?" a
> formatter only blurs the already blurred distinction between string
> formatting and parameter passing. The "?" is a parameter placeholder.

Yeah, you're right. I was actually raising an eyebrow as I typed 
"formatter", because I wasn't sure what to call it. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: groupby and itemgetter

2006-10-06 Thread Steven Bethard
Roman Bertle wrote:
> Hello,
> 
> there is an example how to use groupby in the itertools documentation
> (http://docs.python.org/lib/itertools-example.html):
> 
> # Show a dictionary sorted and grouped by value
 from operator import itemgetter
 d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
 di = sorted(d.iteritems(), key=itemgetter(1))
 for k, g in groupby(di, key=itemgetter(1)):
> ... print k, map(itemgetter(0), g)
> ...
> 1 ['a', 'c', 'e']
> 2 ['b', 'd', 'f']
> 3 ['g']
> 
> Now i wonder why itemgetter is used in this example. More
> straightforward is:
> 
 d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
 di = sorted(d.iterkeys(), key=d.get)
 for k, g in groupby(di, key=d.get):
> ... print k, list(g)
> ...
> 1 ['a', 'c', 'e']
> 2 ['b', 'd', 'f']
> 3 ['g']
> 
> This code does not need the operator module, and its also faster (tested
> using timeit).

It looks like it's even faster if you drop the iterkeys() call and just 
write:

 di = sorted(d, key=d.get)

As to why itemgetter is used, I don't really know...

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


  1   2   3   >