Re: memory efficient set/dictionary

2007-06-10 Thread Josiah Carlson
Rafael Darder Calvo wrote:
>> > > Please recommend a module that allows persistent set/dict storage +
>> > > fast query that best fits my problem,
>> >
>> > What is the problem you are trying to solve? How many keys do you have?
>>
>> Corpus processing. There are in the order of billions to tens of
>> billions keys (64bit integers).
>>
> I would recommend you to use a database since it meets your
> requirements (off-memory, fast, persistent). The bsdddb module
> (berkeley db) even gives you a dictionary like interface.
> http://www.python.org/doc/lib/module-bsddb.html

Standard SQL databases can work for this, but generally your 
recommendation of using bsddb works very well for int -> int mappings. 
In particular, I would suggest using a btree, if only because I have had 
troubles in the past with colliding keys in the bsddb.hash (and recno is 
just a flat file, and will attempt to create a file i*(record size) to 
write to record number i .

As an alternative, there are many search-engine known methods for 
mapping int -> [int, int, ...], which can be implemented as int -> int, 
where the second int is a pointer to an address on disk.  Looking into a 
few of the open source search implementations may be worthwhile.

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


Re: read 9 bytes

2007-06-10 Thread Tim Roberts
nik <[EMAIL PROTECTED]> wrote:
>
>I need to read a 9 byte response from a device on the serial port.
>From reading the pySerial documentation it appears that I can only
>read in characters at a time.

Yes, but it is 8-bit characters.  That is, characters == bytes in this
instance.


>If I do: serialport.read(4)
>I would get 8 bytes,

No.  You would get 4 bytes.  Do you see documentation to the contrary?
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-10 Thread Joachim Durchholz
Twisted schrieb:
> After all, you can't really take a language seriously if
> it's either impossible to write unmaintainable code in it

That's true for any language.
Substitute "not straightforward" for "impossible", and you have a 
condition that actually distinguishes languages.

 > OR impossible to write maintainable code in it.

It is possible to write maintainable Perl.
It's just too easy to write unmaintainable Perl.
Also, a Perl "golfer" and an intermediate Perl programmer will have 
quite different ideas about what idioms should be considered 
maintainable. (I consider Perl's mantra of "many ways to express it" to 
be a weakness, not a strength, since it lengthens the learning curve 
considerably and doesn't buy much. YMMV.)

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread Josiah Carlson
Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>>> Not tail calls, in general, no.
>> Sorry, how does that work? You're suggesting that there is an algorithm
>> which the compiler could follow to optimize away tail-recursion, but human
>> beings can't follow the same algorithm?
>>
>> Now I'm confused.
> 
> The usual compiler method is to translate the code into
> continuation-passing style and thereby gain tail-recursion
> optimization automagically.  Of course a human could do the same thing
> in principle, but it would result in insanely difficult-to-write,
> unreadable and unmaintainable code.  At a higher level, there are no
> Python features whatsoever, either existing or proposed, that couldn't
> be eliminated and left to the human.  Iterators?  While loops?  Who
> needs 'em?  We could all go back to programming in machine code.  But
> Python is supposed to make programming easier, not harder.  

Thanks to Richie Hindle, there exists a goto for Python implementation 
that makes such things quite trivial (assuming one doesn't like 
"abusing" break/continue/else).  http://entrian.com/goto/  (which, by 
the way, is the best April-fools joke ever)


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


Re: updating db with csv

2007-06-10 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
>#1 If any one familiar with godaddy hosting. They have apparently have
>a hosing server i.e.(scripts, html files etc.), and a server for
>databases. How can I import from my script,  with a csv. if the db is
>on a different server than the script server.

What does this have to do with either Python or MySQL?

When you connect to the database, you have to specify a hostname.  As long
as you provide the right one, it doesn't matter where your script runs.

>#2 I would like to update and insert with the same csv file. Is there
>a way to tell the database for some lines to update, and for some
>lines to insert.

Not in standard SQL.  MySQL supports a REPLACE extension that does an
UPDATE if the key already exists, and an INSERT if it does not.  There is
also an extension clause to the INSERT statement called "ON DUPLICATE KEY
UPDATE xxx" that might do what you want.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread Josiah Carlson
John Nagle wrote:
> Josiah Carlson wrote:
[snip]
>> Constant folding happens regardless of optimization level in current 
>> Pythons.
> 
>> So really, assert and docstring removals.  Eh.
> 
>It's hard to optimize Python code well without global analysis.
> The problem is that you have to make sure that a long list of "wierd
> things", like modifying code or variables via getattr/setattr, aren't
> happening before doing significant optimizations.  Without that,
> you're doomed to a slow implementation like CPython.
> 
>ShedSkin, which imposes some restrictions, is on the right track here.
> The __slots__ feature is useful but doesn't go far enough.
[snip]
> Python could get much, much faster.  Right now CPython is said to be 60X 
> slower
> than C.  It should be possible to get at least an order of magnitude over
> CPython.

Don't get me wrong; I'm all for adding optimizations, I was merely 
expressing that currently, 'python -OO' doesn't really do a whole lot. 
I've a long-time user of psyco, have mucked about with 
scipy.weave.inline, and have been a heavy user of Pyrex and C.  If there 
was a method of offering some simple optimization cues to the Python 
runtime to improve its speed, I would be happy to add them when I really 
care about speed (I already do more than that when writing Pyrex).  The 
real question is whether we can get a practical implementation of these 
optimizations as easy to use as psyco.


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


Why does one regex routine work and not the other one?

2007-06-10 Thread TtfnJohn
I have two small scripts that while on the surface should both work
the problem is they don't.

Here's the first one:
import re

testString = 'Thap,fpvi,[EMAIL PROTECTED]:[EMAIL PROTECTED]
dialin.net:[EMAIL PROTECTED]::'

reobj = re.compile(r"(.*),(.*),(.*):::(.*):::(.*)")

testString1 = reobj.search(testString)

if testString1:
   match0 = testString1.group(0)
   match1 = testString1.group(1)

This works as expected with any number of seed strings.

Now then:

This one consistently fails even though it should work, as near as I
can tell.
import os
import re
import readline
from buzhug import Base

# initialize a few things
voiceuser = Base('voiceuser')
# now  to create & open the database. If the database already exists
this will
# simply open it
voiceuser.create(('name',str),('ircname',str),('first',str),
('second',str),('third',str),('fourth',str),('fifth',str),
('sixth',str),('seventh',str),mode="open")

#next is to open the file we'll read from and then process it and add
the names
# to the database
# the first step is to compile the regular expression
testString = re.compile(r"(.*),(.*),(.*):::(.*):::(.*)")
voiceList = open('friendslist','r')

while 1:
line = voiceList.readline()
if not line:
break
print len(line)
line = line[:-2]
print line
print len(line)
regex = testString.search(line)
# fails here with regex showing a value of None in the debugger in
Komodo
if regex:
targetUser = regex.group(1)
targetFlag = regex.group(2)
targetHosts = regex.group(3)
targetName = regex.group(4)
retVal = targetFlag.find('v')
if retVal == -1:
continue
doneSplit = targetHosts.split(':')
counterSplit = len(doneSplit)

# initialize or refresh list for database insertion
insertRecordList = []
insertRecordList = insertRecordList * 9

insertRecordList[0] = targetUser
insertRecordList[1] = targetName

for i in range(2,counterSplit,1):

Obviously I don't get down to the part where I start to populate a
database record and it does look a bit kludgey to this Python n00b.

My question is that if it is bringing in strings from the file with
the same format as the one in the first listing why would it all fail
here?  Could the newline character at the end of the line be the
villian of the piece?

Thanks for any advice in advance

John

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


Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread Steve Howell

--- Kay Schluehr <[EMAIL PROTECTED]> wrote:

> On Jun 11, 12:43 am, Steve Howell
> <[EMAIL PROTECTED]> wrote:
> 
> > To the extent that some of these optimizations
> could
> > be achieved by writing better Python code, it
> would
> > nice for optimization tools to have a "suggest"
> mode.
> 
> Is anyone out there who uses MS Word and doesn't
> deactivate the
> "suggest" mode i.e. Clippy? Maybe someone shall
> write a lucid blog
> entry about the failure of "suggest" modes in
> general or point me to
> one. Autocompletion as a typing aid might be
> considered as a counter
> example but only because you don't really have a
> choice and will not
> be confronted with nonsensical AI guesses.
> 

Unless I'm misunderstanding what you're saying, you
are wildly overinterpreting my use of the phrase
"suggest mode."  

I was making the simple suggestion that code
optimizers could suggest opportunities for
optimization that the tools couldn't unilaterally
decide themselves to enforce.

In other words, there are scenarios where an automated
tool has to assume the extreme case of dynamicism,
when in fact I, the programmer, know that I'm writing
basically static code within Python, and I simply
forgot to pull a subexpression out of a loop.

Maybe you just need to rant about animated office
supplies every now and then.

And regarding autocompletion--yes, it's an extremely
useful feature.







  

Park yourself in front of a world of choices in alternative vehicles. Visit the 
Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python optimization (was Python's "only one way to do it"philosophy isn't good?)

2007-06-10 Thread Doug Phillips
> Is anyone out there who uses MS Word and doesn't deactivate 
> the "suggest" mode i.e. Clippy?

Me... I don't install Clippy (or any of his horribly annoying friends)
to start with. :)

On the topic though, the suggest mode of the MS help system is generally
way off-base, even for my 80-yr-old grandmother's needs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read 9 bytes

2007-06-10 Thread Gabriel Genellina
En Mon, 11 Jun 2007 00:52:28 -0300, nik <[EMAIL PROTECTED]> escribió:

> I need to read a 9 byte response from a device on the serial port.
>> From reading the pySerial documentation it appears that I can only
> read in characters at a time.
>
> If I do: serialport.read(4)
> I would get 8 bytes,

Why do you think so? read(4) will read up to 4 bytes, or less if the  
specified timeout elapses.

> Is there a trick to read 9 bytes off of a serial port?

read(9) (don't forget to set the timeout)

-- 
Gabriel Genellina

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


read 9 bytes

2007-06-10 Thread nik
Hi,

I need to read a 9 byte response from a device on the serial port.
>From reading the pySerial documentation it appears that I can only
read in characters at a time.

If I do: serialport.read(4)
I would get 8 bytes, and if I did
serialport.read(5)
I think the port will block until a time out, since there

Is there a trick to read 9 bytes off of a serial port?

Thanks,
Nik

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


Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread Kay Schluehr
On Jun 11, 12:43 am, Steve Howell <[EMAIL PROTECTED]> wrote:

> To the extent that some of these optimizations could
> be achieved by writing better Python code, it would
> nice for optimization tools to have a "suggest" mode.

Is anyone out there who uses MS Word and doesn't deactivate the
"suggest" mode i.e. Clippy? Maybe someone shall write a lucid blog
entry about the failure of "suggest" modes in general or point me to
one. Autocompletion as a typing aid might be considered as a counter
example but only because you don't really have a choice and will not
be confronted with nonsensical AI guesses.



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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> > Not tail calls, in general, no.
> 
> Sorry, how does that work? You're suggesting that there is an algorithm
> which the compiler could follow to optimize away tail-recursion, but human
> beings can't follow the same algorithm?
> 
> Now I'm confused.

The usual compiler method is to translate the code into
continuation-passing style and thereby gain tail-recursion
optimization automagically.  Of course a human could do the same thing
in principle, but it would result in insanely difficult-to-write,
unreadable and unmaintainable code.  At a higher level, there are no
Python features whatsoever, either existing or proposed, that couldn't
be eliminated and left to the human.  Iterators?  While loops?  Who
needs 'em?  We could all go back to programming in machine code.  But
Python is supposed to make programming easier, not harder.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread Steven D'Aprano
On Mon, 11 Jun 2007 01:28:09 +0100, Alexander Schmolck wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> 
>> On Sat, 09 Jun 2007 22:42:17 +0100, Alexander Schmolck wrote:
>>
 As for why tail calls are not optimized out, it was decided that being able
 to have the stack traces (with variable information, etc.) was more useful
 than offering tail call optimization
>>> 
>>> I don't buy this. 
>>
>> Do you mean you don't believe the decision was made, or you don't agree
>> with the decision?
> 
> Neither. I don't believe the rationale stated in this thread to be the true
> reason.


Don't keep us in suspense. What do you believe is the true reason?


>> Are you volunteering? If you are, I'm sure your suggestion will be welcomed
>> gratefully.
> 
> I rather doubt it. Guido has stated quite clearly that his not
> interested in incorporating this feature.

He's not the only one who gets to make these decisions. But even if he
uses his veto to prevent tail-recursion optimization from being put into
the main branch, there are other options.



 (do what I say).
>>> 
>>> Where did you say run out of memory and fail? More importantly how do
>>> you say "don't run out of memory and fail"?
>>
>> If we can live with a certain amount of "arbitrary failures" in simple
>> arithmetic,
> 
> I prefer not too, and thus when possible avoid to use languages where
> ``a + b`` is liable to fail arbitrarily (such as C, where the behavior
> will often be undefined).

That's not the sort of arbitrary failure I was discussing, but for that
matter Python is one of those languages. Perhaps Python is not the
language for you?

Correct me if I'm wrong, but surely it is C++ that can have arbitrary
behaviour for "a + b", not C?



>> then the world won't end if tail recursion isn't optimized away by the
>> compiler.
> 
> I'd personally much rather have arithmetic working properly.
> Unfortunately this is not an option at the moment, although quite a few
> smart people are working on it and although it is an immensely costly
> problem.
> 
>> You can always hand-optimize it yourself.
> 
> Not tail calls, in general, no.

Sorry, how does that work? You're suggesting that there is an algorithm
which the compiler could follow to optimize away tail-recursion, but human
beings can't follow the same algorithm?

Now I'm confused.


-- 
Steven.

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


Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell

--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
> 
> this is good to know except I am somewhat cautious
> about the end result given 
> that it's from Microsoft (explained below)
> 

Believe me, I agree!  I work mostly in the Unix world
now, but I've done enough serious development in the
Windows world to be fearful of what MS can do to any
simple idea.


> Simple idea, complex partial 
> solution, simpler solution.  only experience will
> tell you when you have gotten 
> the most simplicity out of the solution possible. 

Agreed, this is a very common phenomenon in
engineering, science, etc.

> [...]
> This is yet another good reason why folks should
> really push for a simple 
> browser environment to replace JavaScript.  I really
> don't think it's horribly 
> hard but on the other hand, I don't understand the
> full environment (starting 
> with a simple idea... :-)

Ajax and Javascript are far from perfect, but I do
think they carry some baggage from things that are
really are outside of the scope of their basically
well-founded purposes.  For example, even if you
replaced Javascript with Python, you wouldn't
necessarily solve these problems:

   1) Browser environments, like all GUI environments,
are inherently difficult environments for things like
debugging, unit testing, etc.  (From what I
understand, there are some half decent debuggers for
Javascript, but they are not batteries included with
all browsers.)

   2) Browsers will always differ on subtle, but
important, details of how they render things, how they
expose a DOM, etc.  In some cases this will be due to
benevolent factors (one browser goes to a simpler
model, but you still have to support the old models),
and in other cases there will be the Microsoft
conspiracy to make everything more difficult. ;)

   3) There will always be web designers who are
focused on flaming logos, skinnability, etc., vs.
actual usability.

Also, remember that Ajax and Javascript are still
young technologies.

> Thanks for the post.  It's triggered some nice ideas
> in my head.
> 

You're welcome, and likewise!


   

Choose the right car based on your needs.  Check out Yahoo! Autos new Car 
Finder tool.
http://autos.yahoo.com/carfinder/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread John Nagle
Steve Howell wrote:
> --- John Nagle <[EMAIL PROTECTED]> wrote:
> 
>>With this, the heavy optimizations are possible. 
>>Strength reduction.  Hoisting
>>common subexpressious out of loops.  Hoisting
>>reference count updates out of
>>loops.  Keeping frequently used variables in
>>registers.  And elimination of
>>many unnecessary dictionary lookups.
>>
> To the extent that some of these optimizations could
> be achieved by writing better Python code, it would
> nice for optimization tools to have a "suggest" mode. 
> For example, if I code a Fourier series and duplicate
> the subexpression n*f*t, it would be nice for a tool
> to tell me that I should refactor that expression. 
> Something like this:
> 
>n*f*t should be refactored out of this expression,
> assuming muliplication has no desired side effects for
> n, f, and t.

  Too labor-intensive.  These are well understood optimizations
that can be done quite well automatically.  The problem is Python's
gratutious dynamism - it's hard to tell, when examining code, if
something can be patched by other code elsewhere.  Where "setattr"
is allowed, the compiler has to assume side effects almost everywhere.

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


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-10 Thread Twisted
On Jun 10, 8:50 pm, "BCB" <[EMAIL PROTECTED]> wrote:
> I wholeheartedly agree, and did not mean to imply as much in my original
> post, in which my intent was to emphasize the fact that, until you learn the
> language, a J program /does/ resemble line noise! :-)

Eh. This isn't right. The whole discussion was supposed to have died
after the original Perl joke, certainly after the subsequent exclusion
of joke and toy languages. I think I made it clear also that an
editor's command set, Turing-complete though it may be, constitutes a
toy language. Anyway I amend the original claim to cover joke
languages, toy languages, and any write-only languages that
mysteriously aren't considered to fall into either of the former two
categories. After all, you can't really take a language seriously if
it's either impossible to write unmaintainable code in it OR
impossible to write maintainable code in it. The one is necessarily
trivial, and the other unsuitable for anything serious, except as a
machine-compiled intermediate format or a mechanism for assuring job
security.

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


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-10 Thread BCB



>
> Neither APL nor Snobol nor J are toy or joke languages

I wholeheartedly agree, and did not mean to imply as much in my original 
post, in which my intent was to emphasize the fact that, until you learn the 
language, a J program /does/ resemble line noise! :-)


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


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-10 Thread Reilly
On Jun 10, 3:11 pm, Larry Elmore <[EMAIL PROTECTED]>
wrote:
> Twisted wrote:
> > On Jun 9, 8:21 pm, "BCB" <[EMAIL PROTECTED]> wrote:
> >> "Paul McGuire" <[EMAIL PROTECTED]> wrote in message
>
> >>news:[EMAIL PROTECTED]
>
> >>> On Jun 9, 6:49 am, Lew <[EMAIL PROTECTED]> wrote:
> > In particular, Perl code looks more like line
> > noise than like code from any known programming language. ;))
>  Hmm - I know of APL and SNOBOL.
>  --
>  Lew
> >>> TECO editor commands.  I don't have direct experience with TECO, but
> >>> I've heard that a common diversion was to type random characters on
> >>> the command line, and see what the editor would do.
> >>> -- Paul
> >> J
>
> >>http://www.jsoftware.com/
>
> > Oh come on! Toy languages (such as any set of editor commands) and
> > joke languages (ala Intercal) don't count, even if they are
> > technically Turing-complete. ;)
>
> > Nor does anything that was designed for the every-character-at-a-
> > premium punch-card era, particularly if it is, or rhymes with,
> > "COBOL".
>
> > Those have excuses, like it's a joke or it's a constrained
> > environment. Perl, unfortunately, has no such excuses. If there were
> > such a thing as "embedded Perl", I'd have to hesitate here, but since
> > there isn't...
>
> Neither APL nor Snobol nor J are toy or joke languages.

I'd like register my agreement.  SNOBOL was a very sophisticated
language and way ahead of its time in many ways.  While it's not
really used anymore, SNOBOL's legacy does live on in languages that
are in wide use.

APL and it's successors (including J & K) are neither toys nor extinct
relics.  APL is still used in a variety of applications.  The price of
the last airline ticket you bought was probably determined by a yield
management application written in APL.  K was created in 1993 and Kx
systems has built an incredibly valuable company on top of it.

APL's terseness has more to do with the Iverson's notational goals
than economy with characters related to punchcards.  In fact, the
dominant languages of the punchcard era (COBOL & FORTRAN) are both
pretty verbose.

Lastly, ITS Teco wasn't a joke or toy language either.. It was
psychotically terse and virtually impenetrable to later review.  But
it wasn't a toy.  When I learned to use EMACS, it was still
implemented in ITS Teco.


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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread Alexander Schmolck
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Sat, 09 Jun 2007 22:42:17 +0100, Alexander Schmolck wrote:
>
>>> As for why tail calls are not optimized out, it was decided that being able
>>> to have the stack traces (with variable information, etc.) was more useful
>>> than offering tail call optimization
>> 
>> I don't buy this. 
>
> Do you mean you don't believe the decision was made, or you don't agree
> with the decision?

Neither. I don't believe the rationale stated in this thread to be the true
reason.

> Are you volunteering? If you are, I'm sure your suggestion will be welcomed
> gratefully.

I rather doubt it. Guido has stated quite clearly that his not interested in
incorporating this feature.
  
>>> (do what I say).
>> 
>> Where did you say run out of memory and fail? More importantly how do
>> you say "don't run out of memory and fail"?
>
> If we can live with a certain amount of "arbitrary failures" in simple
> arithmetic,

I prefer not too, and thus when possible avoid to use languages where ``a +
b`` is liable to fail arbitrarily (such as C, where the behavior will often be
undefined).

> then the world won't end if tail recursion isn't optimized away by the
> compiler.

I'd personally much rather have arithmetic working properly. Unfortunately
this is not an option at the moment, although quite a few smart people are
working on it and although it is an immensely costly problem.

> You can always hand-optimize it yourself.

Not tail calls, in general, no.

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


Re: Python in the Mozilla world

2007-06-10 Thread Eric S. Johansson
Steve Howell wrote:
> --- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
> 
>> Steve Howell wrote:
>>> --- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
>>>
> http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702
 interesting.  Very interesting but I suspect the
 message is "don't hold your 
 breath but don't give up hope."

>>> Exactly. :)
>> This is one of those things where a foundation, with
>> a smart person for making 
>> really simple things should get some money from the
>> foundation and get it built. 
> 
> Well, this is a case where smart people (including Jim
> Hugunin) are getting some money from Microsoft, which
> probably still has more dollars to spend than the
> average foundation.  And some really smart people in
> the open source world (Miguel de Icaza, etc.) are
> tracking to it, according to the article.

this is good to know except I am somewhat cautious about the end result given 
that it's from Microsoft (explained below)

   As far as
> "really simple things" goes, it doesn't really fit in
> that category.

I spent way too many years as a designer of software and then systems and may 
have found what may be a universal constant based on how people understand 
complexity and politics.

In the beginning, almost every idea is simple.  simplicity helps you get a 
rough 
go/no go estimation of project success.  Simplicity helps you communicate the 
essential elements of the project to others so that you can get them to buy in 
(funding, resources).  However as you develop use cases, the project gets more 
and more complex those in command issue to implement at the worst possible time 
because they are nervous about the increased complexity blowing up the budget.

The really cool thing about complex systems is that it's like climbing a 
mountain.  You never know when you reach the top until you are almost there. 
the simplicity doesn't emerge until you're almost done but it will emerge.  If 
the apparent solution keeps getting more and more complex, then you really 
don't 
understand the problem and shouldn't even try to implement the solution.

this is a pattern I can almost take to the bank.  Simple idea, complex partial 
solution, simpler solution.  only experience will tell you when you have gotten 
the most simplicity out of the solution possible.  Now granted, some problems 
are inherently complex but if you contrast mid-understanding versus final 
solution, there will always be a big difference and complexity.

I've always thought Microsoft interfaces were horribly horribly complex and I 
think it's due to two factors.  The first is that they implement at the worst 
point in their understanding, and it's a barrier to entry for all third-party 
developers.

If you don't agree with these ideas, that's cool.  We can agree to disagree but 
this has been my experience over many years.

> As much as I love Python, though, I still think the
> future of browser-side programming for the next five
> or ten years is Javascript, and I think the real
> productivity gains are going to come when Javascript
> libraries mature, it becomes more common knowledge
> which libraries are best of breed, etc.

that's really a pity.  Although that is consistent with a recent announcement I 
thought regarding IBM and their funding of the Linux desktop accessibility.  I 
personally hate the whole Ajax JavaScript crap because it is really 
inaccessible 
on multiple levels.  a sardonic corner of my mind wonders if the productivity 
gains you mention it will be offset by the productivity losses caused by the 
unbelievably horrible debuggers and IDs available and users trying to use user 
applications with even worse user interfaces than we have today.  But I will 
say, they will be prettier with all sorts of flashing colors and moving things. 
  Skins!  Don't forget the choice of skins you'll have for applications just by 
changing a cascading style sheet.  Who needs usability when you can the color 
and type font of your user interface to match your whim...grumble

I think your observation is far more correct than either of us want it to be. 
This is yet another good reason why folks should really push for a simple 
browser environment to replace JavaScript.  I really don't think it's horribly 
hard but on the other hand, I don't understand the full environment (starting 
with a simple idea... :-)

Thanks for the post.  It's triggered some nice ideas in my head.

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


Re: codecs / subprocess interaction: utf help requested

2007-06-10 Thread smitty1e
On Jun 10, 6:10 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 11, 7:17 am, smitty1e <[EMAIL PROTECTED]> wrote:
>
> > The first print statement does what you'd expect.
> > The second print statement has rather a lot of rat in it.
> > The goal here is to write a function that will return the man page for
> > some command (mktemp used as a short example here) as text to client
> > code, where the groff markup will be chopped to extract all of the
> > command options.  Those options will eventually be used within an
> > emacs mode, all things going swimmingly.
> > I don't know what's going on with the piping in the second version.
> > It looks like the output of p0 gets converted to unicode at some
> > point,
>
> Whatever gave you that idea?
>
> > but I might be misunderstanding what's going on.  The 4.8
> > codecs  module documentation doesn't really offer much enlightment,
> > nor google.  About the only other place I can think to look would be
> > the unit test cases shipped with python.
>
> Get your head out of the red herring factory; unicode, "utf" (which
> one?) and codecs have nothing to do with your problem. Think about
> looking at your own code and at the bzip2 documentation.
>
>
>
> > Sort of hoping one of the guru-level pythonistas can point to
> > illumination, or write something to help out the next chap.  This
> > might be one of those catalytic questions, the answer to which tackles
> > five other questions you didn't really know you had.
> > Thanks,
> > Chris
> > ---
> > #!/usr/bin/python
> > import subprocess
>
> > p = subprocess.Popen(["bzip2", "-c", "-d", "/usr/share/man/man1/mktemp.
> > 1.bz2"]
> > , stdout=subprocess.PIPE)
> > stdout, stderr = p.communicate()
> > print stdout
>
> > p0 = subprocess.Popen(["cat","/usr/share/man/man1/mktemp.1.bz2"],
> > stdout=subprocess.PIPE)
> > p1 = subprocess.Popen(["bzip2"], stdin=p0.stdout,
> > stdout=subprocess.PIPE)
> > stdout, stderr = p1.communicate()
> > print stdout
> > ---
>
> You left out the command-line options for bzip2. The "rat" that you
> saw was the result of compressing the already-compressed man page.
> Read this:http://www.bzip.org/docs.html
> which is a bit obscure. The --help output from my copy of an antique
> (2001, v1.02) bzip2 Windows port explains it plainly:
> """
>If invoked as `bzip2', default action is to compress.
>   as `bunzip2',  default action is to decompress.
>   as `bzcat', default action is to decompress to stdout.
>
>If no file names are given, bzip2 compresses or decompresses
>from standard input to standard output.
> """
>
> HTH,
> John

Don't I feel like the biggest dork on the planet.
I had started with
>cat /usr/share/man/man1/paludis.1.bz2 | bunzip2
then proceeded right to a self-foot-shoot when I went to python.
*sigh*
Thanks for the calibration, sir.
Rm
C

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


Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell

--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:

> Steve Howell wrote:
> > --- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
> >
>
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702
> >> interesting.  Very interesting but I suspect the
> >> message is "don't hold your 
> >> breath but don't give up hope."
> >>
> > 
> > Exactly. :)
> 
> This is one of those things where a foundation, with
> a smart person for making 
> really simple things should get some money from the
> foundation and get it built. 

Well, this is a case where smart people (including Jim
Hugunin) are getting some money from Microsoft, which
probably still has more dollars to spend than the
average foundation.  And some really smart people in
the open source world (Miguel de Icaza, etc.) are
tracking to it, according to the article.  As far as
"really simple things" goes, it doesn't really fit in
that category.

As much as I love Python, though, I still think the
future of browser-side programming for the next five
or ten years is Javascript, and I think the real
productivity gains are going to come when Javascript
libraries mature, it becomes more common knowledge
which libraries are best of breed, etc.








  

Luggage? GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic subclassing ?

2007-06-10 Thread Gabriel Genellina
En Sun, 10 Jun 2007 18:16:12 -0300, James T. Dennis <[EMAIL PROTECTED]>  
escribió:

>  When I try something like this I run into a little problem:
>
>   class Foo:
>   def foo(self):
>   return "foo"
>   class Bar:
>   def bar(self):
>   return "bar"
>
>   f = Foo()
>   f.__dict__.update(Bar.__dict__)
>
>  ... the problem is that while f now has a "bar" method it doesn't
>  work quite like a normal instance method:
>
>   >>> f.bar()
>   Traceback (most recent call last):
> File "", line 1, in ?
>   TypeError: bar() takes exactly 1 argument (0 given)
>   >>>
>
>  ... though I can get by with f.bar(f)

Bar.__dict__ contains *unbound* methods - that is, methods not linked to  
any particular instance. If you copy them directly into f.__dict__ you  
lose the "magic" that binds methods to instances.
You could store a bound method into the instance but it's not a good idea  
(there are cyclic references).
I think the easiest way is to define a dynamic class (as the subject on  
this old thread suggests):

py> f = Foo()
py> Foo2 = type("Foo2", (Foo,Bar), {})
py> f.__class__ = Foo2
py> f.bar()
'bar'

The code above changes the object class once it was created, but you don't  
have to. Also, you don't have to use a different class name (altough it  
may be confusing...):

py> f = type("Foo", (Foo,Bar), {})()
py> f.bar()
'bar'

>  This "new" module seems to be the key to it all;

It's almost useless now that types are callable.

> but the only docs I have for that say:
>
 help(new)
> Help on module new:
> [...]
> MODULE DOCS
> http://www.python.org/doc/current/lib/module-new.html

Did you follow the above link?

-- 
Gabriel Genellina

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


Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread Steve Howell

--- John Nagle <[EMAIL PROTECTED]> wrote:
> 
> With this, the heavy optimizations are possible. 
> Strength reduction.  Hoisting
> common subexpressious out of loops.  Hoisting
> reference count updates out of
> loops.  Keeping frequently used variables in
> registers.  And elimination of
> many unnecessary dictionary lookups.
> 

To the extent that some of these optimizations could
be achieved by writing better Python code, it would
nice for optimization tools to have a "suggest" mode. 
For example, if I code a Fourier series and duplicate
the subexpression n*f*t, it would be nice for a tool
to tell me that I should refactor that expression. 
Something like this:

   n*f*t should be refactored out of this expression,
assuming muliplication has no desired side effects for
n, f, and t.




 

TV dinner still cooling? 
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Repository - file scanner

2007-06-10 Thread John Machin
On Jun 9, 5:33 am, HMS Surprise <[EMAIL PROTECTED]> wrote:
> Greetings,
>
> Could someone point my muddled head at a/the python repository. I know
> that one exists but cannot find it again. In particular I am looking
> for a standalone search tool that given a path searches files for a
> text string.
>

Why not use grep?

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


Tits Live Webcams Boobs all naturals

2007-06-10 Thread en.wikipedia.org
http://www.tits.sc/ The Best Resource for Tits on the Net. 

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


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-10 Thread Lew
Twisted wrote:
>> Oh come on! Toy languages (such as any set of editor commands) and
>> joke languages (ala Intercal) don't count, even if they are
>> technically Turing-complete. ;)
>>
>> Nor does anything that was designed for the every-character-at-a-
>> premium punch-card era, particularly if it is, or rhymes with,
>> "COBOL".
>>
>> Those have excuses, like it's a joke or it's a constrained
>> environment. Perl, unfortunately, has no such excuses. If there were
>> such a thing as "embedded Perl", I'd have to hesitate here, but since
>> there isn't...

Larry Elmore wrote:
> Neither APL nor Snobol nor J are toy or joke languages.

Indeed.  One wonders where Perl would be if Snobol hadn't preceded it.

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


Re: Select one of 2 functions with the same name ?

2007-06-10 Thread Stef Mientki
7stud wrote:
> On Jun 10, 2:03 pm, Stef Mientki <[EMAIL PROTECTED]>
> wrote:
>> thanks Francesco and "7stud",
>>
>> The solution with objects is too difficult,
>> because I want to stay very close to the orginal language,
>>
> 
> Why would you want to duplicate poorly written code?
> 
I didn't know that a program written without OOP's is "poorly written" ;-)

The orginal language is thé best language available for that particular micro.

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


Re: How to get existing frames in non-current thread?

2007-06-10 Thread Gabriel Genellina
En Sun, 10 Jun 2007 09:17:21 -0300, Fabio Zadrozny <[EMAIL PROTECTED]>  
escribió:

> On 6/10/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>>
>> En Sat, 09 Jun 2007 21:40:40 -0300, Fabio Zadrozny <[EMAIL PROTECTED]>
>> escribió:
>>
>> > Is there some way to get all the frames for any given thread? -- in a
>> way
>> > that does not require a compiled extension.
>>
>> For the current (calling) thread, you can use sys._getframe()
>> For other threads, you can use sys._current_frames()
>> Frames have a f_back attribute pointing to the previous one, that you  
>> can
>> use to navigate them.
>>
>
> Thanks a lot... I guess I'll have to find another way for versions before
> 2.5 ;-)

The original idea came from  
 but it  
uses a compiled C extension, yes. The code is really small and you should  
not have problems compiling it...

-- 
Gabriel Genellina

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


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-10 Thread Larry Elmore
Twisted wrote:
> On Jun 9, 8:21 pm, "BCB" <[EMAIL PROTECTED]> wrote:
>> "Paul McGuire" <[EMAIL PROTECTED]> wrote in message
>>
>> news:[EMAIL PROTECTED]
>>
>>> On Jun 9, 6:49 am, Lew <[EMAIL PROTECTED]> wrote:
> In particular, Perl code looks more like line
> noise than like code from any known programming language. ;))
 Hmm - I know of APL and SNOBOL.
 --
 Lew
>>> TECO editor commands.  I don't have direct experience with TECO, but
>>> I've heard that a common diversion was to type random characters on
>>> the command line, and see what the editor would do.
>>> -- Paul
>> J
>>
>> http://www.jsoftware.com/
> 
> Oh come on! Toy languages (such as any set of editor commands) and
> joke languages (ala Intercal) don't count, even if they are
> technically Turing-complete. ;)
> 
> Nor does anything that was designed for the every-character-at-a-
> premium punch-card era, particularly if it is, or rhymes with,
> "COBOL".
> 
> Those have excuses, like it's a joke or it's a constrained
> environment. Perl, unfortunately, has no such excuses. If there were
> such a thing as "embedded Perl", I'd have to hesitate here, but since
> there isn't...

Neither APL nor Snobol nor J are toy or joke languages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: codecs / subprocess interaction: utf help requested

2007-06-10 Thread John Machin
On Jun 11, 7:17 am, smitty1e <[EMAIL PROTECTED]> wrote:
> The first print statement does what you'd expect.
> The second print statement has rather a lot of rat in it.
> The goal here is to write a function that will return the man page for
> some command (mktemp used as a short example here) as text to client
> code, where the groff markup will be chopped to extract all of the
> command options.  Those options will eventually be used within an
> emacs mode, all things going swimmingly.
> I don't know what's going on with the piping in the second version.
> It looks like the output of p0 gets converted to unicode at some
> point,

Whatever gave you that idea?

> but I might be misunderstanding what's going on.  The 4.8
> codecs  module documentation doesn't really offer much enlightment,
> nor google.  About the only other place I can think to look would be
> the unit test cases shipped with python.

Get your head out of the red herring factory; unicode, "utf" (which
one?) and codecs have nothing to do with your problem. Think about
looking at your own code and at the bzip2 documentation.

> Sort of hoping one of the guru-level pythonistas can point to
> illumination, or write something to help out the next chap.  This
> might be one of those catalytic questions, the answer to which tackles
> five other questions you didn't really know you had.
> Thanks,
> Chris
> ---
> #!/usr/bin/python
> import subprocess
>
> p = subprocess.Popen(["bzip2", "-c", "-d", "/usr/share/man/man1/mktemp.
> 1.bz2"]
> , stdout=subprocess.PIPE)
> stdout, stderr = p.communicate()
> print stdout
>
> p0 = subprocess.Popen(["cat","/usr/share/man/man1/mktemp.1.bz2"],
> stdout=subprocess.PIPE)
> p1 = subprocess.Popen(["bzip2"], stdin=p0.stdout,
> stdout=subprocess.PIPE)
> stdout, stderr = p1.communicate()
> print stdout
> ---

You left out the command-line options for bzip2. The "rat" that you
saw was the result of compressing the already-compressed man page.
Read this:
http://www.bzip.org/docs.html
which is a bit obscure. The --help output from my copy of an antique
(2001, v1.02) bzip2 Windows port explains it plainly:
"""
   If invoked as `bzip2', default action is to compress.
  as `bunzip2',  default action is to decompress.
  as `bzcat', default action is to decompress to stdout.

   If no file names are given, bzip2 compresses or decompresses
   from standard input to standard output.
"""

HTH,
John

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


Re: Select one of 2 functions with the same name ?

2007-06-10 Thread BJörn Lindqvist
On 6/10/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
> I can realize it with a simple switch within each function,
> but that makes the code much less readable:
>
> def Some_Function():
>if simulation_level == 1:
>  ... do things in a way
>elif simulation_level == 2:
>  ... do things in another way
>elif simulation_level == 3:
>  ... do things in yet another way

If you only have three levels, then that definitely is the best way to
solve the  problem. If you have more, and if they may change, then use
a dispatch-dict:

def simulator_1():
print 'mooo'
...
simulators = {1 : simulartor_1, 2 : simulator_2, 3 : simulator_3}
def Some_Function():
simulators[simulation_level]()


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


Re: Select one of 2 functions with the same name ?

2007-06-10 Thread 7stud
On Jun 10, 2:03 pm, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> thanks Francesco and "7stud",
>
> The solution with objects is too difficult,
> because I want to stay very close to the orginal language,
>

Why would you want to duplicate poorly written code?

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


Re: MI5 Persecution: Goldfish and Piranha 29/9/95 (5104)

2007-06-10 Thread Shmuel (Seymour J.) Metz
In <[EMAIL PROTECTED]>, on 06/10/2007
   at 04:57 AM, "Mike" <[EMAIL PROTECTED]> said:

>And this is here because ???

 1. MI5 didn't take him down like they were supposed to

 2. You didn't include followup-to in your header

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to [EMAIL PROTECTED]

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


Re: memory efficient set/dictionary

2007-06-10 Thread Rafael Darder Calvo
> > > Please recommend a module that allows persistent set/dict storage +
> > > fast query that best fits my problem,
> >
> > What is the problem you are trying to solve? How many keys do you have?
>
> Corpus processing. There are in the order of billions to tens of
> billions keys (64bit integers).
>
I would recommend you to use a database since it meets your
requirements (off-memory, fast, persistent). The bsdddb module
(berkeley db) even gives you a dictionary like interface.
http://www.python.org/doc/lib/module-bsddb.html

regards,
Rafa
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Hooking exceptions outside of call stack

2007-06-10 Thread Warren Stringer
Hey Josiah,

I just spent a couple hours with your example, and it explains a lot. Some
of your interactive session got garbled, so am reposting your
merged_namespace example, with tweaks:

#-
def merged_namespace(*ns):
   try:
   __builtins__
   namespaces = ns + (globals(),__builtins__.__dict__)
   except NameError:
   namespaces = ns + (globals(),__builtin__)
   ns = {}
   for i in reversed(namespaces):
   ns.update(i)
   return ns

def foo():
   print type(globals())
   print a.b[c] #works!
   return 
#--
# was having trouble with embedded classes
# so, I tried this to track down the problem

class a(object):
def __init__(self): print 'init a'
class b(object):
def __init__(self): print 'init b'
class c(object):
def __init__(self): print 'init c'
pass

aa = a() # only prints 'init a', oops

# so, starting with this:

class A(dict):
def __getattr__(self, name):
# here's where a namespace resolver might go
return self[name]

def __getitem__(self,key):
return key # useless, but simple

a = A()  # build from scratch
a.__dict__['b'] = A()
a.b.__dict__['c'] = A()
print a.b[a.b.c] # works as expected
#print a.b[c] # NameError: name 'c' is not defined

#-
# back to Josiah's example 

ns = merged_namespace(a.b.__dict__)  
foo2 = type(foo)(foo.func_code, ns, foo.func_name, foo.func_defaults,
foo.func_closure)  
foo2() 
#-

As I was tracing through merged_namespace, I noticed how large resulting
dict is. Too, bad there isn't an equivalent namespace resolution order, as
the there is for methods (or, is there? Am not sure where/how locals are
managed). Then a tupple could be passed to `foo2 = type(foo)(foo.func_code,
namespace, ...)` 

With a mro-style namespace, __getattr__ might be able to change namespaces,
on the fly. Too much of a performance hit? Could be. Fortunately, your
example precludes the performance question. Thanks

"Restartable exceptions", as Jean-Paul Calderone called it, might have
yielded results. But searching on his specific phrase yielded a long
discussion (http://www.python.org/search/hypermail/python-1994q2/0425.html)
that illuminates the implausibility of this approach in Python.

So, am replacing `a.b[c]` with `f(a.b,'c')`. The user still can type
"a.b[c]" but, no longer at the python prompt. Oh well.

Thanks again,

\~/ 

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


codecs / subprocess interaction: utf help requested

2007-06-10 Thread smitty1e
The first print statement does what you'd expect.
The second print statement has rather a lot of rat in it.
The goal here is to write a function that will return the man page for
some command (mktemp used as a short example here) as text to client
code, where the groff markup will be chopped to extract all of the
command options.  Those options will eventually be used within an
emacs mode, all things going swimmingly.
I don't know what's going on with the piping in the second version.
It looks like the output of p0 gets converted to unicode at some
point, but I might be misunderstanding what's going on.  The 4.8
codecs  module documentation doesn't really offer much enlightment,
nor google.  About the only other place I can think to look would be
the unit test cases shipped with python.
Sort of hoping one of the guru-level pythonistas can point to
illumination, or write something to help out the next chap.  This
might be one of those catalytic questions, the answer to which tackles
five other questions you didn't really know you had.
Thanks,
Chris
---
#!/usr/bin/python
import subprocess

p = subprocess.Popen(["bzip2", "-c", "-d", "/usr/share/man/man1/mktemp.
1.bz2"]
, stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
print stdout


p0 = subprocess.Popen(["cat","/usr/share/man/man1/mktemp.1.bz2"],
stdout=subprocess.PIPE)
p1 = subprocess.Popen(["bzip2"], stdin=p0.stdout,
stdout=subprocess.PIPE)
stdout, stderr = p1.communicate()
print stdout
---

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


Re: Dynamic subclassing ?

2007-06-10 Thread James T. Dennis
Karlo Lozovina <[EMAIL PROTECTED]> wrote:
> manatlan wrote:

>> I can't find the trick, but i'm pretty sure it's possible in an easy
>> way.

> It's somewhat easy, boot looks ugly to me. Maybe someone has a more 
> elegant solution:

> In [6]: import new

> In [13]: class Button:
>: def buttonFunc(self):
>: pass

> In [14]: class ExtensionClass:
>: def extendedMethod(self):
>: pass

> In [15]: hybrid = new.instance(Button, 
> Button.__dict__.update(ExtensionClass.__dict__))

> In [17]: dir(hybrid)
> Out[17]: ['__doc__', '__module__', 'buttonFunc', 'extendedMethod']

> Seems to do what you want it to do.

> HTH,
> Karlo.

 When I try something like this I run into a little problem:

class Foo:
def foo(self):
return "foo"
class Bar:
def bar(self):
return "bar"

f = Foo()
f.__dict__.update(Bar.__dict__)

 ... the problem is that while f now has a "bar" method it doesn't
 work quite like a normal instance method:

>>> f.bar()
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: bar() takes exactly 1 argument (0 given)
>>> 

 ... though I can get by with f.bar(f)

 This "new" module seems to be the key to it all; but the only
 docs I have for that say:

>>> help(new)
Help on module new:

NAME
new - Create new objects of various types.  Deprecated.

FILE
/usr/lib/python2.4/new.py

MODULE DOCS
http://www.python.org/doc/current/lib/module-new.html

DESCRIPTION
This module is no longer required except for backward compatibility.
Objects of most types can now be created by calling the type object.


 ... which sounds like a bad idea (from the word "Deprecated").








-- 
Jim Dennis,
Starshine: Signed, Sealed, Delivered

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


Re: Needed: FTP Upload Directory Tree script

2007-06-10 Thread Stefan Schwarzer
Hello Ian,

On 2007-06-10 10:01, IanC wrote:
> Does anyone know of a function or script to upload an entire
> subdirectory tree from a local file space to an FTP server?
> 
> The Python distribution comes with "ftpmirror.py", which performs
> a mirror download of a directory tree, but I need the "Upload"
> version of this.

I'm just working on an ftputil[1] extension[2] to copy/mirror
directory trees between local filesystems and remote FTP hosts.
It's in pre-alpha state (just in development), but maybe it
already does what you want. Did I note that this is an only
slightly tested module and might destroy your files? - That is,
use it at your own risk. I recommend you look at the source
code of ftp_sync.py before using it.

It works like this:

- Download[3] and install ftputil.

- Download the file[2] and put it into the site-packages/ftputil
  directory.

- Use the library like:

import ftputil
from ftputil import ftp_sync

source = ftp_sync.LocalHost()
target = ftputil.FTPHost(hostname, username, password)
syncer = ftp_sync.Syncer(source, target)
syncer.sync(source_directory, target_directory)

Note that the _contents_ of source_directory (_not_ the directory
itself) will be copied to the already-existing target_directory.

If you have further questions or feedback, please send e-mail
to the ftputil mailing list[4] or to me[5].

[1] http://ftputil.sschwarzer.net
[2] http://ftputil.sschwarzer.net/trac/browser/trunk/ftp_sync.py?format=txt
[3] http://ftputil.sschwarzer.net/trac/wiki/Download
[4] mailto:[EMAIL PROTECTED]
[5] mailto:[EMAIL PROTECTED]

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


Re: Select one of 2 functions with the same name ?

2007-06-10 Thread Stef Mientki
thanks Francesco and "7stud",

The solution with objects is too difficult,
because I want to stay very close to the orginal language,
( so the users can understand the Python code,
   and the automatic translation becomes as simple as possible).

But after some tests, it seems to be quit simple:


   simulation_level = 0

   def f1():
 print 'f1'

   if simulation_level == 2:
 def f1():
   print 'f2'

   f1()



cheers,
Stef Mientki

Francesco Guerrieri wrote:
> If the functions are
> f1, f2, f3  you could go this way:
> 
> def SimulationRun():
>if simulation_level = 1: SimulationFunction = f1
>else if simulation_level = 2: SimulationFunction = f2
>else 
> 
> 
> and in the rest of the code you can refer to SimulationFunction
> instead of explicitly calling f1, f2 or f3.
> 
> I'm sure that there are many smarter methods :-)
> 
> 
> 
> On 6/10/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
>> hello,
>>
>> For a simulation at different levels,
>> I need different functions with the same name.
>> Is that possible ?
>>
>> I can realize it with a simple switch within each function,
>> but that makes the code much less readable:
>>
>> def Some_Function():
>>if simulation_level == 1:
>>  ... do things in a way
>>elif simulation_level == 2:
>>  ... do things in another way
>>elif simulation_level == 3:
>>  ... do things in yet another way
>>
>>
>> thanks,
>> Stef Mientki
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>>
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Redux: Allowing 'return obj' in generators

2007-06-10 Thread Dustin J. Mitchell
This question was first brought up in October of 2005[1], and was included in
the "Unresolved Issues" section of my microthreading PEP, which I have quietly
withdrawn from consideration due to lack of community interest.

PEP 255 says

Q. Then why not allow an expression on "return" too?

A. Perhaps we will someday.  In Icon, "return expr" means both "I'm
   done", and "but I have one final useful value to return too, and
   this is it".  At the start, and in the absence of compelling uses
   for "return expr", it's simply cleaner to use "yield" exclusively
   for delivering values.

As those of you who looked at my PEP or are familiar with some of the
implementations will realize, microthreaded functions are syntactically
generator functions, but semantically act as regular functions.  There
is a well-defined meaning to 'return x' in such a function: take the
value of x, and use it in the expression where this function was called.
For example:

def read_integer(sock):
txt = yield sock.readline().strip()
try:
return int(txt)
except:
raise AppProtocolError("Expected an integer")

The implementation of the syntax would be similar to that of an
expressionless 'return', but supplying the expression_list to the
StopIteration's 'args' -- this is described quite well in Piet Delport's
post[2].

Given this use-case (and note that I chose an example that will exercise
the interactions of try/except blocks with the StopIteration behavior),
is it time to revisit this issue?  BDFL said:

  I urge you to leave well enough alone. There's room for extensions
  after people have built real systems with the raw material provided by
  PEP 342 and 343.[3]

and Nick Coghlan said (to applause from GvR):

  I'm starting to think we want to let PEP 342 bake for at least one
  release cycle before deciding what (if any) additional behaviour
  should be added to generators.[4]

I think we have a decent number of implementations in the wild now
(I have learned of Christopher Stawarz's 'multitask'[5] since last
posting my PEP).  With 2.5.1 out, might I suggest this is worth
reconsidering for the 2.6 release?

Dustin

[1] 
http://www.python.org/dev/summary/2005-10-01_2005-10-15/#allowing-return-obj-in-generators
[2] http://mail.python.org/pipermail/python-dev/2005-October/056957.html
[3] http://mail.python.org/pipermail/python-dev/2005-October/057119.html
[4] http://mail.python.org/pipermail/python-dev/2005-October/057133.html
[5] http://o2s.csail.mit.edu/o2s-wiki/multitask
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help with python

2007-06-10 Thread James T. Dennis
[EMAIL PROTECTED] wrote:
> On May 11, 10:16 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
>> On May 11, 9:41 pm, [EMAIL PROTECTED] wrote:

 [... much ellided ...]

["ellided" is a fancy word for "left out" or "replaced
 with ellipses."]

> I was looking around in my Python folder and saw something to do with
> that IDLE thing you were talking about.  When I right clicked on a .py
> file, it said edit with IDLE.  I opened it and it was my code but each
> line was a different color.  It looked confusing so I decide to save
> it for later.  I knew that I could get the run thing to do the command
> thing, but I had forgotten how to get the black window to come up.

 Idle is an "IDE" (integrated development environment).  It's sort
 of like an editor and a "terminal window" ("command shell") combined.
 The different colors are the result of a feature called "syntax 
 highlighting" which is available in most of the modern IDEs and better
 text editors.

 To "get the black window to come up" use the [Start] menu, choose
 the "Run" option and type in the name of the program: "cmd" (then
 hit [Enter]).

 You can can also find it if you chase far enough down the various
 sub-menus off the [Start] menu.


> Ok.  Well, I tried to us the cmd window.  It says python: can't open
> file 'area.py'  I'm guessing that's not good.  It won't open any of
> my .py files.  It's because of where I saved them.  I can see how this
> i going to work now.  Ok so I'll just move them to the place that the
> command line says.  Now it still won't run my other program:

 Yes it's because of where you saved them and because of where the
 command prompt (The C:\> thing that you see inside the "terminal window").

 Rather than moving your .py files to wherever your prompt is pointing,
 it's generally better to change your prompt to point to the right place.

 For example if you've been saving you .py files to "C:\My Documents" then
 type: 

cd "\My Documents" 

 ... (with the quotes around it). 

 Then try to run your files from there.

> # Area calculation program

> print "Welcome to the Area calculation program"
> print "-"
> print

> # Print out the menu:
> print "Please select a shape:"
> print "1  Rectangle"
> print "2  Circle"

> # Get the user's choice:
> shape = input("> ")

> # Calculate the area:
> if shape == 1:
>height = input("Please enter the height: ")
>width = input("Please enter the width: ")
>area = height*width
>print "The area is", area
> else:
>radius = input("Please enter the radius: ")
>area = 3.14*(radius**2)
>print "The area is", area

> Perhaps it isn't written correctly.  I don't think it likes the pound
> signs.  I'm not sure.  But, I did go to that mailing list you
> recommended.  Thanks for that.

 The pound signs are used by Python to mark "comments" (stuff the
 Python interpreter ignores; that's there just as hints and reminders
 to humans who are reading the source code).

 So, from the first # sign on a line until the end of the line Python
 is ignoring everything.

 The only exceptions to this rule are when the # is inside quotes:

print "This is technically called an octothorpe: #. See?" 

 ... in that line the octothorpe (#) is part of a quoted string
 so it and the text following it are NOT ignored.

 Incidentally, I would use the raw_input() function in place of
 the input() function that these examples have been using.

 The problem with the Python input() function is that it parses 
 the input as if it were Python code.  So it will raise an 
 exception for any input you enter which is NOT valid, legal 
 Python code.  (So far you've been lucky in that you've only been
 using it to enter simple numbers, which are, of course, valid
 Python expressions.

 You can actually get away with inserting one line:

input = raw_input

 ... near the beginning of any of your code examples to alleviate
 this issue.  The raw_input() function will accept any string you can
 enter up to the first [Enter] key.  (Actually on my platform, Linux,
 it's possible to embed newline and/or carriage return characters
 --- the ASCII characters which are normally generated by the [Enter]
 key on various computing platforms --- into a raw_input() value by
 preceding each of them with a Ctrl-V key.  Just off hand I don't
 know if that works under Windows using a command prompt window.
 Just pointing that out for other readers to make the observation that
 Python's raw_input() might not be as "raw" as you might expect).


-- 
Jim Dennis,
Starshine: Signed, Sealed, Delivered

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


Re: New mailing list mirrors

2007-06-10 Thread kirby urner
Thanks tomer, I joined both through Google.

Kirby "moe" Urner
4dsolutions.net/ocn/cp4e.html
myspace.com/4dstudios
[EMAIL PROTECTED]

(moe rhymes with Minister of Education was my thinking -- a portfolio
I sometimes grab for a gig, but always put back where I found it).

On 6/10/07, sebulba <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I created two new google groups to mirror the activity of python-dev
> and python-3000:
> * http://groups.google.com/group/python-3000
> * http://groups.google.com/group/python-dev2
>
> There are many mirrors out there, but none of them lets you post
> to a thread. With google groups you can just hit "reply" on the
> message you want to reply to, and that's it. No need to send an
> email to the group (although you still need to register your email
> with python mailing list).
>
> Supports searching, tree-view, list-view, fixed/proportional font,
> tracking
> of read/unread messages, etc. Enjoy.
>
>
> -tomer
>
> --
> http://mail.python.org/mailman/listinfo/python-announce-list
>
>Support the Python Software Foundation:
>http://www.python.org/psf/donations.html
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I obtain the exception object on a generlized except statement?

2007-06-10 Thread Chris Allen
Just what I was looking for thanks Diez and John.

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


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

2007-06-10 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, I asked:
>In article <[EMAIL PROTECTED]>,
>ahlongxp  <[EMAIL PROTECTED]> wrote:
>   .
>   .
>   .
>>I'm a Chinese.
>>Language/English is really a  big problem for Chinese programmers.
>>If python can be written in Chinese, it may become the  most  popular
>>program language in China(though popular alreay).
>>Considering the potential large amount of users in China,  the effort
>>of internationalization for Chinese will totally worth.
>   .
>   .
>   .
>Tcl can be (more-or-less) written in Chinese now.  How popular is it
>among Chinese-speaking developers?

A private correspondent told me it's not at all popular--Tcl, in
China, that is.  On the other hand, I came across http://www.china-pub.com/computers/common/info.asp?id=6271 >, and,
more significantly, http://www.tclchina.com/ >.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyexe "format"

2007-06-10 Thread hg
John Machin wrote:

> On Jun 10, 11:25 am, John Machin <[EMAIL PROTECTED]> wrote:
>> On Jun 10, 10:38 am, hg <[EMAIL PROTECTED]> wrote:
>>
>> > hg wrote:
>> > > Hi,
>>
>> > > Is there a clean way to figure out that a .exe was actually generated
>> > > by pyexe ?
>>
>> > > hg
>>
>> > I should gave writtent "definite" instead of "clean"
>>
>> > hg
>>
>> Reminds me of the story about a teacher trying to correct a student
>> who was using rather dialectal English:
>>You have went and putten "putten" when you should of putten "put"!
>> :-)
>>
>> You should of looken at this:
>>
>> http://www.py2exe.org/index.cgi/WhereAmI
>>
>> HTH,
>> John
> 
> I presumed that you were really asking: "How can Python code tell
> whether it is being run in a py2exe-generated exe, or by the Python
> interpreter?".
> 
> Alternatively, "How can a human inspect an exe and determine whether
> it was generated by py2exe?": (1) I don't know (2) Why do you care?
> 
> Cheers,
> John


An ex-partner might "by mistake" be in possession of some of my source
code ... so if this source code happens to be repackaged in a .exe and I
get to audit it ... I'd like to know where to start.

So the above link ... which I had read ... does not help me.

Regards,

hg

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


Re: Select one of 2 functions with the same name ?

2007-06-10 Thread 7stud
On Jun 10, 11:11 am, 7stud <[EMAIL PROTECTED]> wrote:
> On Jun 10, 10:37 am, Stef Mientki <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > hello,
>
> > For a simulation at different levels,
> > I need different functions with the same name.
> > Is that possible ?
>
> > I can realize it with a simple switch within each function,
> > but that makes the code much less readable:
>
> > def Some_Function():
> >if simulation_level == 1:
> >  ... do things in a way
> >elif simulation_level == 2:
> >  ... do things in another way
> >elif simulation_level == 3:
> >  ... do things in yet another way
>
> > thanks,
> > Stef Mientki
>
> Try something like this:
>
> class Simulation1(object):
> def greet(self):
> print "hello"
>
> class Simulation2(object):
> def greet(self):
> print "hello"
>
> class Simulation3(object):
> def greet(self):
> print "hello"
>
> def someFunc(simObj):
> simObj.greet()
>
> s1 = Simulation1()
> s2 = Simulation2()
> s3 = Simulation3()
>
> someFunc(s1)
> someFunc(s2)
> someFunc(s3)

Horrible example.  Look at this instead:

class Simulation1(object):
def greet(self):
print "hello from sim1"

class Simulation2(object):
def greet(self):
print "Hi. I'm sim2"

class Simulation3(object):
def greet(self):
print "sim3 is #1! Hello there."


def someFunc(simObj):
simObj.greet()


s1 = Simulation1()
s2 = Simulation2()
s3 = Simulation3()

someFunc(s1)
someFunc(s2)
someFunc(s3)


---output:---
hello from sim1
Hi. I'm sim2
sim3 is #1! Hello there.

As the output shows, you can call the same function, but the function
can do different things.

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


Re: Repository - file scanner

2007-06-10 Thread kyosohma
On Jun 9, 12:38 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Sat, 09 Jun 2007 12:30:49 -0300, <[EMAIL PROTECTED]> escribió:
>
> > On Jun 8, 2:33 pm, HMS Surprise <[EMAIL PROTECTED]> wrote:
> >> Could someone point my muddled head at a/the python repository. I know
> >> that one exists but cannot find it again. In particular I am looking
> >> for a standalone search tool that given a path searches files for a
> >> text string.
>
> > Are you looking for
>
> > A.) a Python script to search for file names that match a given text
> > string?
> > B.) a script to search for a given text string within a text file?
> > C.) a Python repository, as in the SVN/CVS area?
>
> D.) The Python Package Index perhaps?http://www.python.org/pypi
>
> --
> Gabriel Genellina

Sorry about the dual post...google groups was acting very weird for me
yesterday.

Mike

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

Re: Needed: FTP Upload Directory Tree script

2007-06-10 Thread kyosohma
On Jun 10, 3:01 am, IanC <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Does anyone know of a function or script to upload an entire
> subdirectory tree from a local file space to an FTP server?
>
> The Python distribution comes with "ftpmirror.py", which performs
> a mirror download of a directory tree, but I need the "Upload"
> version of this.
>
> Thanks for any hints
> --
> -- Ian -- [EMAIL PROTECTED]  ---

Here's some links that should give you some pointers:

http://zephyrfalcon.org/weblog/arch_d7_2003_06_28.html#e262
http://www.example-code.com/python/python-ftp-upload.asp
http://www.thescripts.com/forum/thread22534.html

Mike

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| > Terry Reedy wrote:
| > > In Python, you have a choice of recursion (normal or tail)

[snip Stroud questions]

| I'm afraid Terry is wrong here, at least if he meant that CPython had
| tail recursion *optimization*.

NO!!!
I did not mean that or imply that in any way.

|  (and just for those who don't know yet, it's not a shortcoming, it's a
| design choice.)

And I already noted in a followup that I am working on a Python Papers 
paper explaining that choice, including Guido's claim that 'for statements 
are better'.

So frankly I am a little annoyed that you dragged my name into your answer 
to Stroud when you should have succintly said 'No, Never', or better, 
nothing at all, as someone else already did say that.  Read more of the 
tread before jumping in and acribing ignorance to people.

Terry Jan Reedy



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


Re: load data infile problem

2007-06-10 Thread Michael Hoffman
[EMAIL PROTECTED] wrote:
> does any one know why when I execute this mysql statement with python
> api
> 
> LOAD DATA INFILE  'data.txt' INTO TABLE merchandise;
> 
> I get this error and how can I fix it
> 
> #1045 - Access denied for user: '[EMAIL PROTECTED]' (Using password: YES)

This has nothing to do with Python. It is obvious from the error that 
the user "papermen" doesn't have the privileges to load data into that 
table. Ask your database administrator to give you the appropriate 
privileges.

Followups set.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Select one of 2 functions with the same name ?

2007-06-10 Thread Francesco Guerrieri
If the functions are
f1, f2, f3  you could go this way:

def SimulationRun():
if simulation_level = 1: SimulationFunction = f1
else if simulation_level = 2: SimulationFunction = f2
else 


and in the rest of the code you can refer to SimulationFunction
instead of explicitly calling f1, f2 or f3.

I'm sure that there are many smarter methods :-)



On 6/10/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> For a simulation at different levels,
> I need different functions with the same name.
> Is that possible ?
>
> I can realize it with a simple switch within each function,
> but that makes the code much less readable:
>
> def Some_Function():
>if simulation_level == 1:
>  ... do things in a way
>elif simulation_level == 2:
>  ... do things in another way
>elif simulation_level == 3:
>  ... do things in yet another way
>
>
> thanks,
> Stef Mientki
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as
both victim and villain by the vicissitudes of fate. This visage, no
mere veneer of vanity, is a vestige of the vox populi, now vacant,
vanished. However, this valorous visitation of a bygone vexation
stands vivified, and has vowed to vanquish these venal and virulent
vermin vanguarding vice and vouchsafing the violently vicious and
voracious violation of volition. The only verdict is vengeance; a
vendetta held as a votive, not in vain, for the value and veracity of
such shall one day vindicate the vigilant and the virtuous. Verily,
this vichyssoise of verbiage veers most verbose vis-à-vis an
introduction, so let me simply add that it's my very good honor to
meet you and you may call me V." -- V's introduction to Evey
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Select one of 2 functions with the same name ?

2007-06-10 Thread 7stud
On Jun 10, 10:37 am, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> hello,
>
> For a simulation at different levels,
> I need different functions with the same name.
> Is that possible ?
>
> I can realize it with a simple switch within each function,
> but that makes the code much less readable:
>
> def Some_Function():
>if simulation_level == 1:
>  ... do things in a way
>elif simulation_level == 2:
>  ... do things in another way
>elif simulation_level == 3:
>  ... do things in yet another way
>
> thanks,
> Stef Mientki

Try something like this:

class Simulation1(object):
def greet(self):
print "hello"

class Simulation2(object):
def greet(self):
print "hello"

class Simulation3(object):
def greet(self):
print "hello"


def someFunc(simObj):
simObj.greet()


s1 = Simulation1()
s2 = Simulation2()
s3 = Simulation3()

someFunc(s1)
someFunc(s2)
someFunc(s3)

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


Sharon Stone - Anna Kournikova Lindsay lohan

2007-06-10 Thread D - A - T - I - N - G
Sharon Stone - Anna  Kournikova  Lindsay lohan

search   engines  +
cams

www.alphasearch.gr
www.alphasearch.ru-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python in the Mozilla world

2007-06-10 Thread Eric S. Johansson
Steve Howell wrote:
> --- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
> http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702
>> interesting.  Very interesting but I suspect the
>> message is "don't hold your 
>> breath but don't give up hope."
>>
> 
> Exactly. :)

This is one of those things where a foundation, with a smart person for making 
really simple things should get some money from the foundation and get it 
built. 
  I don't know about you but when I have a customer asking for a modification 
to 
an open source project, I respond much more quickly when they say "here's your 
budget".  Although sometimes the budget is so small, I'm tempted to find 
someone 
in Romania or other cheap locations and stretch my dollar as far as possible. 
I'm certainly tempted to do that on my own projects.

> Well, that sounds pretty reasonable, and I'm sure a
> lot of folks are in a similar quandary.  They need to
> use JS to a certain degree, but nobody wants to make a
> career out of plug-in writing, etc.  (I certainly
> don't!) It wouldn't surprise me that there are lots of
> Python programmers who do JS maybe 5% of the time, and
> many of those folks can't justify the effort to go a
> bit deeper on the learning curve, create more of a
> community, etc.
> 
> I guess I'm not helping you much other than to
> commiserate, but can I ask you to what extent you've
> looked into existing Python web frameworks, to see how
> much code there is out there that you could mine for
> your projects?  I stumbled on some pretty high quality
> Python code a few weeks ago that amounted to
> Javascript helpers, but now I can't find it for the
> life of me.  But it's out there...

actually, I've looked at some toolkits and they look really nice if I had a 
week 
to spend on them.  I'm trying to figure out how to fit something like these 
toolkits into my own framework (yes, another web framework.  This time, with 
accessibility in mind.  The motto is, learn in the morning, use in the 
afternoon, go home at night.)  But figuring out how to fit in Ajax type stuff
in the same way that the HTML has been simplified for 80% of the uses, requires 
a deeper knowledge of Ajax than I have.  And I'm unlikely to acquire in the 
near 
term unless I have a partner in crime to show me common idioms.

which is a pity because I have in mind a tool which could help writers for 
online comments.  Most of the current common techniques involve comments to a 
log entry or in some cases inter-line comments but the primary failing of these 
models is the ability to highlight just what the comment is about.  The user 
interface would be fairly simple.  Highlight the region and a text area appears 
below.  You enter text and hit submit or you can cancel.  A marker is left in 
the margins indicating the presence of a comment when you hit the marker, the 
text becomes visible again and the highlighted region becomes visible again. 
There are other refinements but that's fundamentally it.  I'll probably be 
motivated to jump into the JavaScript necessary after I finish and publish to 
other projects in Python.

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


Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread John Nagle
Josiah Carlson wrote:
> Steven D'Aprano wrote:
> 
>> On Sat, 09 Jun 2007 22:52:32 +, Josiah Carlson wrote:
>>
>>> the only thing that optimization currently does in Python at present 
>>> is to discard docstrings
>>
>>
>> Python, or at least CPython, does more optimizations than that. Aside 
>> from
>> run-time optimizations like interned strings etc., there are a small
>> number of compiler-time optimizations done.
>>
>> Running Python with the -O (optimize) flag tells Python to ignore
>> assert statements. Using -OO additionally removes docstrings.
...
> 
> I would guess it is because some other data types may have side-effects. 
>  On the other hand, a peephole optimizer could be written to trim out 
> unnecessary LOAD_CONST/POP_TOP pairs.
> 
>> Some dead code is also optimized away:
> 
> Obviously dead code removal happens regardless of optimization level in 
> current Pythons.
> 
>> Lastly, in recent versions (starting with 2.5 I believe) Python 
>> includes a
>> peephole optimizer that implements simple constant folding: 
> 
> Constant folding happens regardless of optimization level in current 
> Pythons.

> So really, assert and docstring removals.  Eh.

It's hard to optimize Python code well without global analysis.
The problem is that you have to make sure that a long list of "wierd
things", like modifying code or variables via getattr/setattr, aren't
happening before doing significant optimizations.  Without that,
you're doomed to a slow implementation like CPython.

ShedSkin, which imposes some restrictions, is on the right track here.
The __slots__ feature is useful but doesn't go far enough.

I'd suggest defining "simpleobject" as the base class, instead of "object",
which would become a derived class of "simpleobject".   Objects descended
directly from "simpleobject" would have the following restrictions:

- "getattr" and "setattr" are not available (as with __slots__)
- All class member variables must be initialized in __init__, or
  in functions called by __init__.  The effect is like __slots__,
  but you don't have to explictly write declarations.
- Class members are implicitly typed with the type of the first
  thing assigned to them.  This is the ShedSkin rule.  It might
  be useful to allow assignments like

self.str = None(string)

  to indicate that a slot holds strings, but currently has the null
  string.
- Function members cannot be modified after declaration.  Subclassing
  is fine, but replacing a function member via assignment is not.
  This allows inlining of function calls to small functions, which
  is a big win.
- Private function members (self._foo and self.__foo) really are
  private and are not callable outside the class definition.

You get the idea.  This basically means that "simpleobject" objects have
roughly the same restrictions as C++ objects, for which heavy compile time
optimization is possible.  Most Python classes already qualify for
"simpleobject".  And this approach doesn't require un-Pythonic stuff like
declarations or extra "decorators".

With this, the heavy optimizations are possible.  Strength reduction.  Hoisting
common subexpressious out of loops.  Hoisting reference count updates out of
loops.  Keeping frequently used variables in registers.  And elimination of
many unnecessary dictionary lookups.

Python could get much, much faster.  Right now CPython is said to be 60X slower
than C.  It should be possible to get at least an order of magnitude over
CPython.

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


load data infile problem

2007-06-10 Thread moishyyehuda
does any one know why when I execute this mysql statement with python
api

LOAD DATA INFILE  'data.txt' INTO TABLE merchandise;

I get this error and how can I fix it

#1045 - Access denied for user: '[EMAIL PROTECTED]' (Using password: YES)

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


Select one of 2 functions with the same name ?

2007-06-10 Thread Stef Mientki
hello,

For a simulation at different levels,
I need different functions with the same name.
Is that possible ?

I can realize it with a simple switch within each function,
but that makes the code much less readable:

def Some_Function():
   if simulation_level == 1:
 ... do things in a way
   elif simulation_level == 2:
 ... do things in another way
   elif simulation_level == 3:
 ... do things in yet another way


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


Re: memory efficient set/dictionary

2007-06-10 Thread koara
Hello Steven,

On Jun 10, 5:29 pm, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> > ...
> How do you know it won't fit in main memory if you don't know the
> overhead? A guess? You've tried it and your computer crashed?

exactly

> > Please recommend a module that allows persistent set/dict storage +
> > fast query that best fits my problem,
>
> Usually I love guessing what people's problems are before making a
> recommendation, but I'm feeling whimsical so I think I'll ask first.
>
> What is the problem you are trying to solve? How many keys do you have?

Corpus processing. There are in the order of billions to tens of
billions keys (64bit integers).

> Can you group them in some way, e.g. alphabetically? Do you need to search
> on random keys, or can you queue them and do them in the order of your
> choice?


Yes, keys in sets and dictionaries can be grouped in any way, order
doesn't matter. Not sure what you mean.
Yes, i need fast random access (at least i do without having to
rethink and rewrite everything, which is what i'd like to avoid with
the help of this thread :-)

Thanks for the reply!


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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread John Nagle
[EMAIL PROTECTED] wrote:
> On Jun 9, 12:16 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> 
>>Terry Reedy wrote:
>>
>>>In Python, you have a choice of recursion (normal or tail)
>>
>>Please explain this. I remember reading on this newsgroup that an
>>advantage of ruby (wrt python) is that ruby has tail recursion, implying
>>that python does not. Does python have fully optimized tail recursion as
>>described in the tail recursion Wikipedia entry? Under what
>>circumstances can one count on the python interpreter recognizing the
>>possibility for optimized tail recursion?
>>
> 
> 
> I'm afraid Terry is wrong here, at least if he meant that CPython had
> tail recursion *optimization*.
> 
> (and just for those who don't know yet, it's not a shortcoming, it's a
> design choice.)
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell

--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702
> 
> interesting.  Very interesting but I suspect the
> message is "don't hold your 
> breath but don't give up hope."
>

Exactly. :)
 
> [...]  What I need to do would take maybe a
> day if you're distracted but 
> to spend some number of weeks learning how to
> accomplish that day's effort is a 
> pretty low return on investment.  I don't see a
> career in plug-in writing is 
> something worth chasing.  Anyway, that's my opinion
> and I'm living with the 
> consequences.  :-)
> 

Well, that sounds pretty reasonable, and I'm sure a
lot of folks are in a similar quandary.  They need to
use JS to a certain degree, but nobody wants to make a
career out of plug-in writing, etc.  (I certainly
don't!) It wouldn't surprise me that there are lots of
Python programmers who do JS maybe 5% of the time, and
many of those folks can't justify the effort to go a
bit deeper on the learning curve, create more of a
community, etc.

I guess I'm not helping you much other than to
commiserate, but can I ask you to what extent you've
looked into existing Python web frameworks, to see how
much code there is out there that you could mine for
your projects?  I stumbled on some pretty high quality
Python code a few weeks ago that amounted to
Javascript helpers, but now I can't find it for the
life of me.  But it's out there...




 

8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python in the Mozilla world

2007-06-10 Thread Eric S. Johansson
Steve Howell wrote:
> --- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
> I would not completely give up on the idea of Python
> itself running in the browser, although obviously
> there have been lots of false starts.
> 
> http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702

interesting.  Very interesting but I suspect the message is "don't hold your 
breath but don't give up hope."


> Regarding using Python to generate JavaScript, I just
> get nervous any time code generation happens.  While
> JS is not a perfect language, it's tolerably close to
> Python in lots of cases, and if you have a Python back
> end, you can feed it JSON very easily from Python.

personally, that doesn't bother me.  I lived with Cfront to the point where I 
understood the output and was filing bug reports on it.
> 
> To the extent that JS code incorporates lots of
> cross-platform idiosyncracies, I still think the
> strategy there is to dig into JS and learn how to
> encapsulate those within JS itself.

pick a toolkit and live with it.  Most of the reason why I'm looking for a 
JavaScript backend is because well, my hands and speech recognition don't work 
well with JavaScript.  So, if I could just generate JavaScript from Python I 
would be happy.  I especially would be happy if I could create Thunderbird or 
Firefox extensions using Python because the current model is so 
incomprehensibly 
documented.  What I need to do would take maybe a day if you're distracted but 
to spend some number of weeks learning how to accomplish that day's effort is a 
pretty low return on investment.  I don't see a career in plug-in writing is 
something worth chasing.  Anyway, that's my opinion and I'm living with the 
consequences.  :-)


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


Re: Python editors again (it's not the same old request)

2007-06-10 Thread Eric S. Johansson
Chris Mellon wrote:
> wx does (in large part), but most likely the problem is that the "rich
> text" control used in most editors is not the win32 rich text control,
> but instead Scintilla, which is designed for source editing and is
> much easier to use. Very few editors, of any kind, use the native
> win32 text control for source highlighting.
> 
> wx does have (some)  support for the accessibility features in win32,
> you might post a feature request on the wx bug tracker to add them to
> the wx platform bindings for Scintilla.
> 
> The main reason editors don't use the standard control is for syntax
> highlighting and perhaps folding and margins, though, which I'm not
> sure are especially valuable to you. What kind of features makes a
> Python editor 'smart' for someone who's coding with a screen reader?

what you said makes wonderful scents.  Thank you for explaining.  Now, if you 
read the application note, after the list of rich text objects they expect, 
they 
described a fuzzy in between state where if you tweak the configuration, you 
get 
Select-and-Say but you know a whole bunch of things about the objects etc. 
would 
you be so kind as to read over that part of the application note and tell me if 
it applies to any of the Scintilla objects for text display?

I'm glad to hear you have some of the extensibility features.  Some are better 
than none.  There is an event coming up in the next few weeks that will trigger 
a need for accessibility interfaces on the Linux side.

Well, I'm not sure about a screen reader but I'm using speech to text.  My 
apologies if I wasn't clear (reading back, I see a couple dropouts that I 
didn't 
catch and change the meaning significantly. As a brief aside, one of the 
classic 
problems is can versus can't.  Which leaves you very much in doubt if someone 
writes "I can go to bed with you."  Is it a misrecognition or an expression of 
desire?  only your natural language processing will know for sure:-)

there's a whole hierarchy of needs.  The voice coder project has done some nice 
work in that domain.  For me, the fundamental level is the ability to correct 
and replace without error.  I should be up to select a phrase or set of words 
and have that region highlighted properly so I can operate on it.  I should be 
able to delete the last utterance and not have it count wrong.

the next level (that the voice coder project handles) is the ability to dictate 
a word and depending on the context or its knowledge of symbols, generate a 
code 
symbol be a bumpy cap or joined with underscores or some combination thereof. 
Additionally, David Fox, primary developer, did some  absolutely  gorgeous 
worked with correction mechanisms.

The next level up would be contextual awareness of variables within your scope 
so that when you dictate something, you don't have to have a big collection of 
static symbols.  You create them dynamically based on where you are located in 
your code, which file, and what modules you include.  This last one is going to 
be difficult.  May not show up for a few years.

But all I'm asking for right now is simple Select-and-Say as outlined in that 
application note from nuance.  I can say "_" with English words on either side 
and the code will work.


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


Re: memory efficient set/dictionary

2007-06-10 Thread Steven D'Aprano
On Sun, 10 Jun 2007 07:27:56 -0700, koara wrote:

> What is the best to go about using a large set (or dictionary) that
> doesn't fit into main memory? What is Python's (2.5 let's say)
> overhead for storing int in the set, and how much for storing int ->
> int mapping in the dict?

How do you know it won't fit in main memory if you don't know the
overhead? A guess? You've tried it and your computer crashed?


> Please recommend a module that allows persistent set/dict storage +
> fast query that best fits my problem, 

Usually I love guessing what people's problems are before making a
recommendation, but I'm feeling whimsical so I think I'll ask first.

What is the problem you are trying to solve? How many keys do you have?
Can you group them in some way, e.g. alphabetically? Do you need to search
on random keys, or can you queue them and do them in the order of your
choice?


> and as lightweight as possible.
> For queries, the hit ratio is about 10%. Fast updates would be nice,
> but i can rewrite the algo so that the data is static, so update speed
> is not critical.
> 
> Or am i better off not using Python here? Cheers.


-- 
Steven.

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


Re: Hooking exceptions outside of call stack

2007-06-10 Thread Josiah Carlson
Warren Stringer wrote:
> Josiah Carlson wrote:
>>  >>> foo = type(foo)(foo.func_code, d, foo.func_name, foo.func_defaults,
>> foo.func_closure)
> 
> Wow! I've never seen that, before. Is there documentation for `type(n)(...)`
> somewhere? I did find a very useful "Decorator for Binding Constants, by
> Raymond Hettinger", that uses this technique.

type(obj) gets you the type of the object.  To discover what it takes to 
construct a function object, I just used...

 >>> help(type(foo))
Help on class function in module __builtin__:

class function(object)
  |  function(code, globals[, name[, argdefs[, closure]]])
  |
  |  Create a function object from a code object and a dictionary.
  |  The optional name string overrides the name from the code object.
  |  The optional argdefs tuple specifies the default argument values.
  |  The optional closure tuple supplies the bindings for free variables.

...


> The calls are made from embedded classes that are constructed on the fly:
> 
>   class a(object): ...
> class b(object): ...
>class c(object): ...
> 
> for `a.b[c]=1`, a.__getattr__('b') is called but 'c' need to be resolved as
> an object before a.b.__getitem__(c) is called. Could a.b.__init__ set
> globals so that 'c' gets resolved? Is this global namespace the same as the
> `globals()` namespace? 

I don't believe there is any confusion as to *why* you are getting the 
error.  It seems plain to everyone involved.  You are getting the error 
because c is not defined in the namespace in which you are executing 
'a.b[c] = 1'.  Unless you modify the namespace in which it is running...

 >>> class a(object):
... class b(object):
... class c(object):
... pass
...
 >>> def merged_namespace(*ns):
... try:
... __builtins__
... namespaces = ns + (globals(),__builtins__.__dict__)
... except NameError:
... namespaces = ns + (globals(),__builtin__)
... ns = {}
... for i in reversed(namespaces):
... ns.update(i)
... return ns
...
 >>> class m_level_namespace(dict):
... def __init__(self, *ns):
... try:
... __builtins__
... self.namespaces = ns + (globals(),__builtins__.__dict__)
... except NameError:
... self.namespaces = ns + (globals(),__builtin__)
... def __getitem__(self, key):
... for i in self.namespaces:
... print "..."
... if key in i:
... return i[key]
... raise NameError("Name %r not found"%(key,))
... def __setitem__(self, key, value):
... self.ns[0][key] = value
... def __delitem__(self, key):
... del self.ns[0][key]
...
 >>> def foo():
... print type(globals())
... a.b[c] = 1
...
 >>> ns = m_level_namespace(a.b.__dict__)
 >>>
 >>> foo1 = type(foo)(foo.func_code, ns, foo.func_name, 
foo.func_defaults, foo.func_closure)
 >>>
 >>> foo1()
Traceback (most recent call last):
   File "", line 1, in 
   File "", line 2, in foo
NameError: global name 'type' is not defined
 >>>
 >>> ns = merged_namespace(a.b.__dict__)
 >>>
 >>> foo2 = type(foo)(foo.func_code, ns, foo.func_name, 
foo.func_defaults, foo.func_closure)
 >>>
 >>> foo2()

Traceback (most recent call last):
   File "", line 1, in 
   File "", line 3, in foo
TypeError: 'type' object does not support item assignment
 >>>

Due to the vagaries of Python's lookup mechanism, the m_level_namespace 
class doesn't work as a method of trying to build a name resolution 
order.  However, if you are OK with the limitations of needing to merge 
namespaces, then the merged_namespace function should work for you (it 
doesn't pick up changed globals, builtins, your class contents, etc.)

With all of that said, you still shouldn't be trying to do a.b[c] .  You 
should instead be doing a.b[a.b.c] .  Is it cumbersome?  Yes.  but it's 
the only mechanism that really makes sense (hacking namespaces is a 
great way of breaking your application in new and unexpected ways).


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


Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell

--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
> 
> As a result, I started looking at Python generating
> JavaScript and I know there 
> is pypy but is that really something one can count
> on or is it more a good 
> demonstration of technology?
> 

I would not completely give up on the idea of Python
itself running in the browser, although obviously
there have been lots of false starts.

http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702

Regarding using Python to generate JavaScript, I just
get nervous any time code generation happens.  While
JS is not a perfect language, it's tolerably close to
Python in lots of cases, and if you have a Python back
end, you can feed it JSON very easily from Python.

To the extent that JS code incorporates lots of
cross-platform idiosyncracies, I still think the
strategy there is to dig into JS and learn how to
encapsulate those within JS itself.

-- Steve




 

TV dinner still cooling? 
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python editors again (it's not the same old request)

2007-06-10 Thread Chris Mellon
On 6/10/07, Eric S. Johansson <[EMAIL PROTECTED]> wrote:
> I upgraded to version 9.5 and all of my tools which enabled me to program by
> voice in Emacs are broken.  it's one of those dagnabbit a moment's of life.
>
> What I am looking for is a Windows based Python Smart editor that uses 
> specific
> rich text edit controls as specified here:
>
> http://knowledgebase.nuance.com/view.asp?tnID=5104&sQuery=4247
>
> Quoting from the article:
> """
> A window is considered standard if its window class name is one of the 
> following:
>
> Edit
>
> RichEdit
>
> RichEdit20A
>
> RichEdit20W
>
> RichEdit50W
>
> If the name is not one of those, then an edit control is still considered
> standard if its window class name and window styles are similar to those of
> standard edit controls.
>
> """
>
> There is some other stuff in there about other classes that may be able to 
> work
> in so far, they haven't yield anything useful to me.  Doesn't mean I won't 
> keep
> trying but it's more than a tad frustrating trying to root out some of these
> magic numbers.  Any help would be most appreciated.  Actually, it would be
> really nice if wxwindows  and gtk used the standard classes underneath so
> accessibility would be there semiautomatically on Windows but that's a 
> different
> conversation.
>

wx does (in large part), but most likely the problem is that the "rich
text" control used in most editors is not the win32 rich text control,
but instead Scintilla, which is designed for source editing and is
much easier to use. Very few editors, of any kind, use the native
win32 text control for source highlighting.

wx does have (some)  support for the accessibility features in win32,
you might post a feature request on the wx bug tracker to add them to
the wx platform bindings for Scintilla.

The main reason editors don't use the standard control is for syntax
highlighting and perhaps folding and margins, though, which I'm not
sure are especially valuable to you. What kind of features makes a
Python editor 'smart' for someone who's coding with a screen reader?
-- 
http://mail.python.org/mailman/listinfo/python-list


memory efficient set/dictionary

2007-06-10 Thread koara
What is the best to go about using a large set (or dictionary) that
doesn't fit into main memory? What is Python's (2.5 let's say)
overhead for storing int in the set, and how much for storing int ->
int mapping in the dict?

Please recommend a module that allows persistent set/dict storage +
fast query that best fits my problem, and as lightweight as possible.
For queries, the hit ratio is about 10%. Fast updates would be nice,
but i can rewrite the algo so that the data is static, so update speed
is not critical.

Or am i better off not using Python here? Cheers.

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread Josiah Carlson
Steven D'Aprano wrote:
> On Sat, 09 Jun 2007 22:52:32 +, Josiah Carlson wrote:
> 
>> the only thing that optimization 
>> currently does in Python at present is to discard docstrings
> 
> Python, or at least CPython, does more optimizations than that. Aside from
> run-time optimizations like interned strings etc., there are a small
> number of compiler-time optimizations done.
> 
> Running Python with the -O (optimize) flag tells Python to ignore
> assert statements. Using -OO additionally removes docstrings.

Oh yeah, asserts.  I never run with -O, and typically don't use asserts, 
so having or not having either isn't a big deal for me.

> Regardless of the flag, in function (and class?) definitions like the
> following:
> 
> def function(args):
> "Doc string"
> x = 1 
> s = "this is a string constant"
> "and this string is treated as a comment"
> return s*x
> 
> The string-comment is ignored by the compiler just like "real" comments.
> (The same doesn't necessarily hold for other data types.)

I would guess it is because some other data types may have side-effects. 
  On the other hand, a peephole optimizer could be written to trim out 
unnecessary LOAD_CONST/POP_TOP pairs.

> Some dead code is also optimized away:

Obviously dead code removal happens regardless of optimization level in 
current Pythons.

> Lastly, in recent versions (starting with 2.5 I believe) Python includes a
> peephole optimizer that implements simple constant folding: 

Constant folding happens regardless of optimization level in current 
Pythons.


So really, assert and docstring removals.  Eh.

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


Re: Pyrex problem with cdef'd attribute

2007-06-10 Thread Michael Hoffman
[EMAIL PROTECTED] wrote:

> I'll play around a bit
> more and if I continue to confuse myself will subscribe to the pyrex mailing
> list (or at least use the somewhat clunky gmane.org interface).

I find that using a newsreader for gmane stuff is far more convenient. I 
use Thunderbird to access various infrequently-used mailing lists via 
NNTP and Gmane.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Python in the Mozilla world

2007-06-10 Thread Eric S. Johansson
this morning I was looking at Python and XUL.  I was impressed by the very 
interesting projects that were happening around 2005 but it seems like they 
have 
all died.  Integrating Python at the Mozilla was also very intriguing as it 
held 
the promise of eliminating JavaScript for extension development (yaaa).  But 
that seems to have died as well.  In fact, it looks like that almost all of the 
alternative languages for browsers have died for lack of interest or something. 
  I was really looking forward to pyax

As a result, I started looking at Python generating JavaScript and I know there 
is pypy but is that really something one can count on or is it more a good 
demonstration of technology?

Just wondering.

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


Python editors again (it's not the same old request)

2007-06-10 Thread Eric S. Johansson
I upgraded to version 9.5 and all of my tools which enabled me to program by 
voice in Emacs are broken.  it's one of those dagnabbit a moment's of life.

What I am looking for is a Windows based Python Smart editor that uses specific 
rich text edit controls as specified here:

http://knowledgebase.nuance.com/view.asp?tnID=5104&sQuery=4247

Quoting from the article:
"""
A window is considered standard if its window class name is one of the 
following:

Edit

RichEdit

RichEdit20A

RichEdit20W

RichEdit50W

If the name is not one of those, then an edit control is still considered 
standard if its window class name and window styles are similar to those of 
standard edit controls.

"""

There is some other stuff in there about other classes that may be able to work 
in so far, they haven't yield anything useful to me.  Doesn't mean I won't keep 
trying but it's more than a tad frustrating trying to root out some of these 
magic numbers.  Any help would be most appreciated.  Actually, it would be 
really nice if wxwindows  and gtk used the standard classes underneath so 
accessibility would be there semiautomatically on Windows but that's a 
different 
conversation.

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


Re: matching objects by a tuple field criterion

2007-06-10 Thread bullockbefriending bard
> There are certainly cases where the speedup is tremendous - think of a
> single integer in the first criteria - but then the overall performance
> depends on the real-live queries. If lot's of wildcards are used, you
> might end up slower if the tree-walk takes more time than the
> C-implemented list-iteration will cost you.

hopefully, won't need to do this then. i'll test the filter approach
tonight. generally speaking, going to be mostly wildcards most of the
time.

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


Re: matching objects by a tuple field criterion

2007-06-10 Thread Diez B. Roggisch
bullockbefriending bard schrieb:
>> Instead of passing a wild-card tuple like (*,*,*,4,*,*) simply pass the
>> integer you want to match and the position you want to match it in.
> 
> for sure. that was more for expository purpose rather than how i was
> planning to go about it.
> 
> 
>> As a generator expression:
>>
>> (obj for obj in list_of_objects if obj.data[what] == where)
> 
> above or equivalent list comprehension was what i had in mind as far
> as linear search goes. and scanning the list like this will most
> likely be 'good enough' performance-wise. however, partly just out of
> curiosity, i was wondering if there is some kind of data structure
> which might let me find all the matches a bit faster.

You can of course create a tree from the tuples, where the first level 
of nodes corresponds to the first attribute of the tuple and so forth.

There are certainly cases where the speedup is tremendous - think of a 
single integer in the first criteria - but then the overall performance 
depends on the real-live queries. If lot's of wildcards are used, you 
might end up slower if the tree-walk takes more time than the 
C-implemented list-iteration will cost you.

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


Re: matching objects by a tuple field criterion

2007-06-10 Thread bullockbefriending bard
quite so, i rephrased docstring to be:

"""criteria is an iterable containing either '*' instances or  strings
of comma-separated integers. e.g.  ['*','1,2,3', '11,12']"""

thanks very much for the idea! upon further reflection, this seems to
be a more elegant solution for my case than the ad-hoc generator or
list comprehension approach. this is because i *do* have to filter
data based on multiple single field criteria and i know all of these
criteria at the same time - so it makes a lot of sense to do as you
have done and then only do one filter operation to pull out all the
objects i am interested in.

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


Re: matching objects by a tuple field criterion

2007-06-10 Thread John Machin
On Jun 10, 10:32 pm, bullockbefriending bard <[EMAIL PROTECTED]>
wrote:
> quite so, i rephrased docstring to be:
>
> """criteria is an iterable containing either '*' instances or  strings
> of comma-separated integers. e.g.  ['*','1,2,3', '11,12']"""
>
> thanks very much for the idea! upon further reflection, this seems to
> be a more elegant solution for my case than the ad-hoc generator or
> list comprehension approach. this is because i *do* have to filter
> data based on multiple single field criteria and i know all of these
> criteria at the same time - so it makes a lot of sense to do as you
> have done and then only do one filter operation to pull out all the
> objects i am interested in.

"""i want to search on *one only* tuple field/value."""
"""i will only ever specify an integer match for one tuple field."""
"""the cheque's in the mail"""
"""of course i'll still love you in the morning"""

So augment my pre-built approach by intersection (or union? your
wording is somewhat vague) of the selected answer sets.


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


Re: How can I obtain the exception object on a generlized except statement?

2007-06-10 Thread John Machin
On Jun 10, 10:13 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Chris Allen schrieb:
>
>
>
> > I am confused on one aspect of exception handling.  If you specify the
> > exception object type to match in an except statement it is possible
> > to also obtain the exception object itself, but I can't figure out how
> > to get the exception object when I don't specify a match.
>
> > for example:
>
>  try: urlopen('http://www.google.com')
>  except socket.error, msg:
>  print str(msg)
>
> > this works and I can do what I like with the exception object (msg).
> > but I can't do this with a simple except statment.
>
>  except msg:
>
> > this won't work because it will think msg is the type to match
>
>  except ,msg:
>
> > syntax error
>
>  except *,msg:
>
> > syntax error
>
>  except (),msg:
>
> > Hmm I didn't try that one before I started this post.  It doesn't give
> > me a syntax error.  I'll experiment.
> > Even if the above syntax works, is this the way to do this?  It seems
> > sort of funky.
>
> > How do I do this?  Thanks.
>
> pydoc sys.exc_info
>

In particular, you want sys.exc_info()[:2]




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


Re: matching objects by a tuple field criterion

2007-06-10 Thread John Machin
On Jun 10, 8:58 pm, bullockbefriending bard <[EMAIL PROTECTED]>
wrote:
> i have a large collection of python objects, each of which contains an
> integer 6-tuple as part of its data payload. what i need to be able to
> do is select only those objects which meet a simple tuple element
> wildcard matching criterion. e.g. given the following python objects:
>
> object A includes tuple (1,2,3,4,5,6)
> object B includes tuple (1,4,4,4,11,1)
> object C includes tuple (1,3,9,1,1,1)
>
> all tuples are unique. for what it's worth, the values in each field
> are independent of the other fields and range from 1 to 14. although
> 'large', my collection is sparse cf. the 14^6 possible tuples.
>
> i want to search on *one only* tuple field/value. if my search
> criterion is (*,*,*,4,*,*), then i want to find object A and object B.
> if (1,*,*,*,*,*), i want to find objects A, B, and C, etc. i will only
> ever specify an integer match for one tuple field.
>
> i can think of some naive approaches, but is there an elegant way to
> do this?

You are going to have to tell us how many is in a "large" collection,
how often you will do this query, how much memory you have to spare,
how fast you want the answer back, whether you want the answer as a
generator, or in a list/tuple/set/whatever -- or you are going to have
to do a fair bit of prototyping and benchmarking.

Steven has given you one end of the spectrum: a naive serial scan. Now
I'll give you another end: a naive pre-build all possible answers
method:

[quite untested]
# build 14x6 array of empty sets
answer = [[set() for what in range(14)] for slot in range(6)]
# populate the sucker
for obj in obj_list:
for slot in range(6):
answer[slot][obj.data[slot]-1].add(obj)

Later, the answer to 'Which objects have the value 11 in slot 3?' is
answer[3][11-1]

HTH,
John

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


Re: How to get existing frames in non-current thread?

2007-06-10 Thread Fabio Zadrozny

On 6/10/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:


En Sat, 09 Jun 2007 21:40:40 -0300, Fabio Zadrozny <[EMAIL PROTECTED]>
escribió:

> Is there some way to get all the frames for any given thread? -- in a
way
> that does not require a compiled extension.

For the current (calling) thread, you can use sys._getframe()
For other threads, you can use sys._current_frames()
Frames have a f_back attribute pointing to the previous one, that you can
use to navigate them.



Thanks a lot... I guess I'll have to find another way for versions before
2.5 ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How can I obtain the exception object on a generlized except statement?

2007-06-10 Thread Diez B. Roggisch
Chris Allen schrieb:
> I am confused on one aspect of exception handling.  If you specify the
> exception object type to match in an except statement it is possible
> to also obtain the exception object itself, but I can't figure out how
> to get the exception object when I don't specify a match.
> 
> for example:
> 
 try: urlopen('http://www.google.com')
 except socket.error, msg:
 print str(msg)
> 
> this works and I can do what I like with the exception object (msg).
> but I can't do this with a simple except statment.
> 
 except msg:
> 
> this won't work because it will think msg is the type to match
> 
 except ,msg:
> 
> syntax error
> 
 except *,msg:
> 
> syntax error
> 
 except (),msg:
> 
> Hmm I didn't try that one before I started this post.  It doesn't give
> me a syntax error.  I'll experiment.
> Even if the above syntax works, is this the way to do this?  It seems
> sort of funky.
> 
> How do I do this?  Thanks.

pydoc sys.exc_info


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


Re: matching objects by a tuple field criterion

2007-06-10 Thread bullockbefriending bard

> Instead of passing a wild-card tuple like (*,*,*,4,*,*) simply pass the
> integer you want to match and the position you want to match it in.

for sure. that was more for expository purpose rather than how i was
planning to go about it.


> As a generator expression:
>
> (obj for obj in list_of_objects if obj.data[what] == where)

above or equivalent list comprehension was what i had in mind as far
as linear search goes. and scanning the list like this will most
likely be 'good enough' performance-wise. however, partly just out of
curiosity, i was wondering if there is some kind of data structure
which might let me find all the matches a bit faster.

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


Re: Third-party libs in version control

2007-06-10 Thread [EMAIL PROTECTED]
On Jun 10, 5:26 am, Marcus <[EMAIL PROTECTED]> wrote:
> Good evening,
>
> I'm new to developing large subversion-controlled projects. This one
> will involve a few third-party libraries like wxWidgets, and perhaps
> Twisted. Ordinarily you could just install these into your system and
> they'll end up globally (in Python's Lib/site-packages directory). Is it
> proper practice to instead install the libraries into a separate [vendor
> branch] of the repository and reference that instead?
>
> I've read about vendor branches, and I'm under the impression that
> you're supposed to do that /instead/ of installing the libraries
> globally into Python's subdirectories... is that correct?
>

As Mark already mentionned, svn's 'vendor branches' are only
meaningfull when you do have to maintain a customized version of the
third-party libs. For 'ordinary' dependencies, you can use  eggs or
just explicitly states the dependencies in the README or INSTALL
doc.

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


How can I obtain the exception object on a generlized except statement?

2007-06-10 Thread Chris Allen
I am confused on one aspect of exception handling.  If you specify the
exception object type to match in an except statement it is possible
to also obtain the exception object itself, but I can't figure out how
to get the exception object when I don't specify a match.

for example:

>>> try: urlopen('http://www.google.com')
>>> except socket.error, msg:
>>> print str(msg)

this works and I can do what I like with the exception object (msg).
but I can't do this with a simple except statment.

>>> except msg:

this won't work because it will think msg is the type to match

>>> except ,msg:

syntax error

>>> except *,msg:

syntax error

>>> except (),msg:

Hmm I didn't try that one before I started this post.  It doesn't give
me a syntax error.  I'll experiment.
Even if the above syntax works, is this the way to do this?  It seems
sort of funky.

How do I do this?  Thanks.

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


Re: matching objects by a tuple field criterion

2007-06-10 Thread Diez B. Roggisch
Diez B. Roggisch schrieb:
> bullockbefriending bard schrieb:
>> i have a large collection of python objects, each of which contains an
>> integer 6-tuple as part of its data payload. what i need to be able to
>> do is select only those objects which meet a simple tuple element
>> wildcard matching criterion. e.g. given the following python objects:
>>
>> object A includes tuple (1,2,3,4,5,6)
>> object B includes tuple (1,4,4,4,11,1)
>> object C includes tuple (1,3,9,1,1,1)
>>
>> all tuples are unique. for what it's worth, the values in each field
>> are independent of the other fields and range from 1 to 14. although
>> 'large', my collection is sparse cf. the 14^6 possible tuples.
>>
>> i want to search on *one only* tuple field/value. if my search
>> criterion is (*,*,*,4,*,*), then i want to find object A and object B.
>> if (1,*,*,*,*,*), i want to find objects A, B, and C, etc. i will only
>> ever specify an integer match for one tuple field.
>>
>> i can think of some naive approaches, but is there an elegant way to
>> do this?
> 
> Depends on what you find elegant. Are the criteria runtime-specified, 
> and is anything other than the * allowerd, e.g. [1,3,8]? IMHO the best 
> thing is to create a filter-function that you then use to... filter :)
> 
> Like this:
> 
> def create_filter_predicate(criteria):
> """
> criteria is an iterable containing either
> an '*' or a list of comma-separated
> integers
> """
> sub_preds = []
> for i, sub_crit in enumerate(criteria):
> if sub_crit == "*":
>continue
> matching_set = set(int(n) for n in sub_crit.split(","))
> sub_preds.append((i, matching_set))
> def predicate(o):
> t = o.my_tuple
> for i, ms in sub_preds:
> if not t[i] in ms:
>return False
> return True
> return predicate

Obviously the docs are faulty - the criteria looks like this:

['*', '1,2,3']

But I think you can get the gist of it - regardless on how the actual 
criteria are entered.

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


userinteraction for a webspider

2007-06-10 Thread Chris
hi guys,

i would like to to write a little spider, where, occasionally, the user 
has to interact. For example show a log-in page or something similar 
(since everyone has those verification letter/number pics), or send a 
message by hand.

I had the idea of the script relaying the page to localhost but i 
thought there might be an easier way...

Thanks for your help

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-10 Thread [EMAIL PROTECTED]
On Jun 9, 12:16 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> Terry Reedy wrote:
> > In Python, you have a choice of recursion (normal or tail)
>
> Please explain this. I remember reading on this newsgroup that an
> advantage of ruby (wrt python) is that ruby has tail recursion, implying
> that python does not. Does python have fully optimized tail recursion as
> described in the tail recursion Wikipedia entry? Under what
> circumstances can one count on the python interpreter recognizing the
> possibility for optimized tail recursion?
>

I'm afraid Terry is wrong here, at least if he meant that CPython had
tail recursion *optimization*.

(and just for those who don't know yet, it's not a shortcoming, it's a
design choice.)


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


Re: Where can I suggest an enchantment for Python Zip lib?

2007-06-10 Thread Anders J. Munch
durumdara wrote:
> Only one way I have to control this: if I modify the ZipFile module.

Since you already have the desired feature implemented, why don't you submit a 
patch.

See http://www.python.org/patches/

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


Re: matching objects by a tuple field criterion

2007-06-10 Thread Diez B. Roggisch
bullockbefriending bard schrieb:
> i have a large collection of python objects, each of which contains an
> integer 6-tuple as part of its data payload. what i need to be able to
> do is select only those objects which meet a simple tuple element
> wildcard matching criterion. e.g. given the following python objects:
> 
> object A includes tuple (1,2,3,4,5,6)
> object B includes tuple (1,4,4,4,11,1)
> object C includes tuple (1,3,9,1,1,1)
> 
> all tuples are unique. for what it's worth, the values in each field
> are independent of the other fields and range from 1 to 14. although
> 'large', my collection is sparse cf. the 14^6 possible tuples.
> 
> i want to search on *one only* tuple field/value. if my search
> criterion is (*,*,*,4,*,*), then i want to find object A and object B.
> if (1,*,*,*,*,*), i want to find objects A, B, and C, etc. i will only
> ever specify an integer match for one tuple field.
> 
> i can think of some naive approaches, but is there an elegant way to
> do this?

Depends on what you find elegant. Are the criteria runtime-specified, 
and is anything other than the * allowerd, e.g. [1,3,8]? IMHO the best 
thing is to create a filter-function that you then use to... filter :)

Like this:

def create_filter_predicate(criteria):
 """
 criteria is an iterable containing either
 an '*' or a list of comma-separated
 integers
 """
 sub_preds = []
 for i, sub_crit in enumerate(criteria):
 if sub_crit == "*":
continue
 matching_set = set(int(n) for n in sub_crit.split(","))
 sub_preds.append((i, matching_set))
 def predicate(o):
 t = o.my_tuple
 for i, ms in sub_preds:
 if not t[i] in ms:
return False
 return True
 return predicate

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


Re: matching objects by a tuple field criterion

2007-06-10 Thread Steven D'Aprano
On Sun, 10 Jun 2007 03:58:44 -0700, bullockbefriending bard wrote:

> i have a large collection of python objects, each of which contains an
> integer 6-tuple as part of its data payload. what i need to be able to
> do is select only those objects which meet a simple tuple element
> wildcard matching criterion. e.g. given the following python objects:
> 
> object A includes tuple (1,2,3,4,5,6)
> object B includes tuple (1,4,4,4,11,1)
> object C includes tuple (1,3,9,1,1,1)
> 
> all tuples are unique. for what it's worth, the values in each field
> are independent of the other fields and range from 1 to 14. although
> 'large', my collection is sparse cf. the 14^6 possible tuples.
> 
> i want to search on *one only* tuple field/value. if my search
> criterion is (*,*,*,4,*,*), then i want to find object A and object B.
> if (1,*,*,*,*,*), i want to find objects A, B, and C, etc. i will only
> ever specify an integer match for one tuple field.
> 
> i can think of some naive approaches, but is there an elegant way to
> do this?

Instead of passing a wild-card tuple like (*,*,*,4,*,*) simply pass the
integer you want to match and the position you want to match it in.

As a generator:


def matcher(list_of_objects, what, where):
for obj in list_of_objects:
if obj.data[where] == what:
yield obj


As a generator expression:

(obj for obj in list_of_objects if obj.data[what] == where)



-- 
Steven.

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


matching objects by a tuple field criterion

2007-06-10 Thread bullockbefriending bard
i have a large collection of python objects, each of which contains an
integer 6-tuple as part of its data payload. what i need to be able to
do is select only those objects which meet a simple tuple element
wildcard matching criterion. e.g. given the following python objects:

object A includes tuple (1,2,3,4,5,6)
object B includes tuple (1,4,4,4,11,1)
object C includes tuple (1,3,9,1,1,1)

all tuples are unique. for what it's worth, the values in each field
are independent of the other fields and range from 1 to 14. although
'large', my collection is sparse cf. the 14^6 possible tuples.

i want to search on *one only* tuple field/value. if my search
criterion is (*,*,*,4,*,*), then i want to find object A and object B.
if (1,*,*,*,*,*), i want to find objects A, B, and C, etc. i will only
ever specify an integer match for one tuple field.

i can think of some naive approaches, but is there an elegant way to
do this?

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


Re: read xml file from compressed file using gzip

2007-06-10 Thread John Machin
On 10/06/2007 8:08 PM, flebber wrote:
> 
> Thanks that was so helpful to see how to do it. I have read a lot but
> it wasn't sinking in, and sometimes its better to learn by doing.

IMHO it's always better to learn by: read some, try it out, read some, ...

> Some
> of the books I have read just seem to go from theory to theory with
> the occasional example ( which is meant to show us how good the author
> is rather than help us).

Well, that's the wrong sort of book for learning a language. You need 
one with little exercises on each page, plus a couple of bigger ones per 
chapter. It helps to get used to looking things up in the manual. 
Compare the description in the manual with what's in the book.

> 
> For the record
> 
 ## working on region in file /usr/tmp/python-F_C5sr.py...
> ['mimetype', 'maindata.xml']
> File Name
> Modified Size
> mimetype   2007-05-27
> 20:36:20   17
> maindata.xml   2007-05-27
> 20:36:2010795
 print len(xml_string)
> 10795
 for line in xml_string:
>print line
> ... ...
> <
> ?
> x
> m
> l
> 
> v
> e
> r
> s
> i.(etc ...it went for a while)

Yup. At a rough guess, I'd say it printed 10795 lines.

So now you've learned by doing it what
 for x in a_string:
does :-)

I hope you've also learned that "xml_string" was a good name and "line" 
wasn't quite so good.

> 
> and
> 
 lines = xml_string.splitlines()

Have you looked up splitlines in the manual?


 print len(lines)
> 387
 print len(lines[0])
> 38
 for line in lines:
> ... print line
>   File "", line 2
> print line
> ^
> IndentationError: expected an indented block
 for line in lines:
> print line
> 

After you fixed your indentation error, did it look like what you 
expected to find?

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


Re: read xml file from compressed file using gzip

2007-06-10 Thread flebber
On Jun 10, 7:43 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On 10/06/2007 3:06 PM, flebber wrote:
>
>
>
> > On Jun 10, 3:45 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> >> flebber wrote:
> >>> I was working at creating a simple program that would read the content
> >>> of a playlist file( in this case *.k3b") and write it out . the
> >>> compressed "*.k3b" file has two file and the one I was trying to read
> >>> was maindata.xml
> >> The k3b format is a ZIP archive. Use the zipfile library:
>
> >> file:///usr/share/doc/python2.5-doc/html/lib/module-zipfile.html
>
> >> Stefan
>
> > Thanks for all the help, have been using the docs at python.org and
> > the magnus t Hetland book. Is there any docs tha re a little more
> > practical or expressive as most of the module documentation is very
> > confusing for a beginner and doesn't provide much in the way of
> > examples on how to use the modules.
>
> > Not criticizing the docs as they are probably very good for
> > experienced programmers.
>
> Somebody else has already drawn your attention to the/a tutorial. You
> need to read, understand, and work through a *good* introductory book or
> tutorial before jumping into the deep end.
>
>  > class GzipFile([playlist_file[decompress[9, 'rb']]]);
>
> Errr, no, the [] are a documentation device used in most computer
> language documentation to denote optional elements -- you don't type
> them into your program. See below.
>
> Secondly as Stefan pointed out, your file is a ZIP file (not a gzipped
> file), they're quite different animals, so you need the zipfile module,
> not the gzip module.
>
>  > os.system(open("/home/flebber/tmp/maindata.xml"));
>
> The manuals say quite simply and clearly that:
> open() returns a file object
> os.system's arg is a string (a command, like "grep -i fubar *.pl")
> So that's guaranteed not to work.
>
>  From the docs of the zipfile module:
> """
> class ZipFile( file[, mode[, compression[, allowZip64]]])
>
> Open a ZIP file, where file can be either a path to a file (a string) or
> a file-like object. The mode parameter should be 'r' to read an existing
> file, 'w' to truncate and write a new file,
> or 'a' to append to an existing file.
> """
> ... and you don't care about the rest of the class docs in your simple
> case of reading.
>
> A class has to be called like a function to give you an object which is
> an instance of that class. You need only the first argument; the second
> has about a 99.999% chance of defaulting to 'r' if omitted, but we'll
> play it safe and explicit:
>
> import zipfile
> zf = zipfile.ZipFile('/home/flebber/oddalt.k3b', 'r')
>
> OK, some more useful docs:
> """
> namelist( )
>Return a list of archive members by name.
> printdir( )
>Print a table of contents for the archive to sys.stdout.
> read( name)
>  Return the bytes of the file in the archive. The archive must be
> open for read or append.
> """
>
> So give the following a try:
>
> print zf.namelist()
> zf.printdir()
> xml_string = zf.read('maindata.xml')
> zf.close()
>
> # xml_string will be a string which may or may not have line endings in
> it ...
> print len(xml_string)
>
> # If you can't imagine what the next two lines will do,
> # you'll have to do it once, just to see what happens:
> for line in xml_string:
> print line
>
> # Wasn't that fun? How big was that file? Now do this:
> lines = xml_text.splitlines()
> print len(lines) # number of lines
> print len(lines[0]) # length of first line
>
> # Ummm, maybe if it's only one line you don't want to do this either,
> # but what the heck:
> for line in lines:
>  print line
>
> HTH,
> John

Thanks that was so helpful to see how to do it. I have read a lot but
it wasn't sinking in, and sometimes its better to learn by doing. Some
of the books I have read just seem to go from theory to theory with
the occasional example ( which is meant to show us how good the author
is rather than help us).

For the record

>>> ## working on region in file /usr/tmp/python-F_C5sr.py...
['mimetype', 'maindata.xml']
File Name
Modified Size
mimetype   2007-05-27
20:36:20   17
maindata.xml   2007-05-27
20:36:2010795
>>> print len(xml_string)
10795
>>> for line in xml_string:
   print line
... ...
<
?
x
m
l

v
e
r
s
i.(etc ...it went for a while)

and

>>> lines = xml_string.splitlines()
>>> print len(lines)
387
>>> print len(lines[0])
38
>>> for line in lines:
... print line
  File "", line 2
print line
^
IndentationError: expected an indented block
>>> for line in lines:
print line

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


Re: read xml file from compressed file using gzip

2007-06-10 Thread John Machin
On 10/06/2007 3:06 PM, flebber wrote:
> On Jun 10, 3:45 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>> flebber wrote:
>>> I was working at creating a simple program that would read the content
>>> of a playlist file( in this case *.k3b") and write it out . the
>>> compressed "*.k3b" file has two file and the one I was trying to read
>>> was maindata.xml
>> The k3b format is a ZIP archive. Use the zipfile library:
>>
>> file:///usr/share/doc/python2.5-doc/html/lib/module-zipfile.html
>>
>> Stefan
> 
> Thanks for all the help, have been using the docs at python.org and
> the magnus t Hetland book. Is there any docs tha re a little more
> practical or expressive as most of the module documentation is very
> confusing for a beginner and doesn't provide much in the way of
> examples on how to use the modules.
> 
> Not criticizing the docs as they are probably very good for
> experienced programmers.
> 


Somebody else has already drawn your attention to the/a tutorial. You 
need to read, understand, and work through a *good* introductory book or 
tutorial before jumping into the deep end.

 > class GzipFile([playlist_file[decompress[9, 'rb']]]);

Errr, no, the [] are a documentation device used in most computer 
language documentation to denote optional elements -- you don't type 
them into your program. See below.

Secondly as Stefan pointed out, your file is a ZIP file (not a gzipped 
file), they're quite different animals, so you need the zipfile module, 
not the gzip module.


 > os.system(open("/home/flebber/tmp/maindata.xml"));

The manuals say quite simply and clearly that:
open() returns a file object
os.system's arg is a string (a command, like "grep -i fubar *.pl")
So that's guaranteed not to work.

 From the docs of the zipfile module:
"""
class ZipFile( file[, mode[, compression[, allowZip64]]])

Open a ZIP file, where file can be either a path to a file (a string) or 
a file-like object. The mode parameter should be 'r' to read an existing 
file, 'w' to truncate and write a new file,
or 'a' to append to an existing file.
"""
... and you don't care about the rest of the class docs in your simple 
case of reading.

A class has to be called like a function to give you an object which is 
an instance of that class. You need only the first argument; the second 
has about a 99.999% chance of defaulting to 'r' if omitted, but we'll 
play it safe and explicit:

import zipfile
zf = zipfile.ZipFile('/home/flebber/oddalt.k3b', 'r')

OK, some more useful docs:
"""
namelist( )
   Return a list of archive members by name.
printdir( )
   Print a table of contents for the archive to sys.stdout.
read( name)
 Return the bytes of the file in the archive. The archive must be 
open for read or append.
"""

So give the following a try:

print zf.namelist()
zf.printdir()
xml_string = zf.read('maindata.xml')
zf.close()

# xml_string will be a string which may or may not have line endings in 
it ...
print len(xml_string)

# If you can't imagine what the next two lines will do,
# you'll have to do it once, just to see what happens:
for line in xml_string:
print line

# Wasn't that fun? How big was that file? Now do this:
lines = xml_text.splitlines()
print len(lines) # number of lines
print len(lines[0]) # length of first line

# Ummm, maybe if it's only one line you don't want to do this either,
# but what the heck:
for line in lines:
 print line

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


Needed: FTP Upload Directory Tree script

2007-06-10 Thread IanC
Hi,

Does anyone know of a function or script to upload an entire
subdirectory tree from a local file space to an FTP server?

The Python distribution comes with "ftpmirror.py", which performs
a mirror download of a directory tree, but I need the "Upload"
version of this.

Thanks for any hints
-- 
-- Ian -- [EMAIL PROTECTED]  ---
-- 
http://mail.python.org/mailman/listinfo/python-list