Re: Guido's new method definition idea

2008-12-05 Thread Russ P.
On Dec 5, 6:21 pm, "Daniel Fetchinson" <[EMAIL PROTECTED]>
wrote:
> Hi folks,
>
> The story of the explicit self in method definitions has been
> discussed to death and we all know it will stay. However, Guido
> himself acknowledged that an alternative syntax makes perfect sense
> and having both (old and new) in a future version of python is a
> possibility since it maintains backward compatibility. The alternative
> syntax will be syntactic sugar for the old one. This blog post of his
> is what I'm talking about:
>
> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay...
>
> The proposal is to allow this:
>
> class C:
>     def self.method( arg ):
>         self.value = arg
>         return self.value
>
> instead of this:
>
> class C:
>     def method( self, arg ):
>         self.value = arg
>         return self.value
>
> I.e. explicit self stays only the syntax is slightly different and may
> seem attractive to some. As pointed out by Guido classmethods would
> work similarly:
>
> class C:
>     @classmethod
>     def cls.method( arg ):
>         cls.val = arg
>         return cls.val
>
> The fact that Guido says,
>
> "Now, I'm not saying that I like this better than the status quo. But
> I like it a lot better than [...] but it has the great advantage that
> it is backward compatible, and can be evolved into a PEP with a
> reference implementation without too much effort."
>
> shows that the proposal is viable.
>
> I'd like this new way of defining methods, what do you guys think?
> Anyone ready for writing a PEP?
>
> Cheers,
> Daniel
>
> --
> Psss, psss, put it down! -http://www.cafepress.com/putitdown

I like it.

I'll even go a step further and suggest that "$" be allowed as a
substitute for "self". It looks like a capital "S" (for Self), and it
stands out clearly. It also makes code more succinct with no loss of
readability. Think of the line wraps that could be avoided.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread Lawrence D'Oliveiro
In message
<[EMAIL PROTECTED]>, Istvan
Albert wrote:

> Originally, like many others here I said YIKES! but on a second read,
> it is not that bad. It actually grows on you.
> 
> After looking at it one more time I found it neat, very concise
> without being unreadable.

The key thing is, it's functional, not procedural. Instead of a sequence of
statements performing actions, it uses expressions that compute values.

Here's another one (from ):

def MapRect(SrcRect, DstRect) :
"""returns a Matrix that does appropriate scaling and translation
to map the corners of SrcRect to DstRect."""
return \
  (
Matrix.translation(- SrcRect.topleft())
*
Matrix.scaling(DstRect.dimensions() / SrcRect.dimensions())
*
Matrix.translation(DstRect.topleft())
  )
#end MapRect

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


Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> It would have been far more concise ...

Gee, I thought people were complaining it was too cryptic, now it turns out
they were actually complaining because it was too verbose.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> On Fri, 05 Dec 2008 23:28:48 +1300, Lawrence D'Oliveiro wrote:
> 
>> In message <[EMAIL PROTECTED]>, Steven D'Aprano
>> wrote:
>> 
>>> Since the context has been deleted, it's hard to tell whether the code
>>> as written by Lawrence ...
>> 
>> If you want to reply to my message, reply to my message, don't reply to
>> my reply to someone else's reply to my message.
> 
> I did reply to your message. It was your message that was missing all the
> context necessary to tell what you were rabbiting on about.

If you wanted the context for your reply, you should have replied to the
message with the context. That way you automatically get the context when
you hit reply, no need to go out of your way to dig it up from a different
posting.

Does that make any sense to you, or should I start drawing simple diagrams?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Quick Newbie Question

2008-12-05 Thread r0g
Josh wrote:
> Can Python be used on one Linux machine to drive another Linux machine
> through SSH? I am currently running Putty on my XP box to run tests on a
> Linux box. I need to automate these tests and thought it would be fun to
>  do so from a Linux VMWare Image I recently setup. Does this sound
> do-able without too much effort? I already know the Linux commands I
> need to run but just need an interactive shell connection through SSH.
> Again is Python a good choice for this or something else?
> Thanks,
> 
> JR

Yep, python has several options, I've been using paramiko for this for a
couple of years: http://www.lag.net/paramiko/

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


Re: Guido's new method definition idea

2008-12-05 Thread Kay Schluehr
On 6 Dez., 03:21, "Daniel Fetchinson" <[EMAIL PROTECTED]>
wrote:
> Hi folks,
>
> The story of the explicit self in method definitions has been
> discussed to death and we all know it will stay. However, Guido
> himself acknowledged that an alternative syntax makes perfect sense
> and having both (old and new) in a future version of python is a
> possibility since it maintains backward compatibility. The alternative
> syntax will be syntactic sugar for the old one. This blog post of his
> is what I'm talking about:
>
> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay...
>
> The proposal is to allow this:
>
> class C:
> def self.method( arg ):
> self.value = arg
> return self.value
>
> instead of this:
>
> class C:
> def method( self, arg ):
> self.value = arg
> return self.value
>
> I.e. explicit self stays only the syntax is slightly different and may
> seem attractive to some. As pointed out by Guido classmethods would
> work similarly:
>
> class C:
> @classmethod
> def cls.method( arg ):
> cls.val = arg
> return cls.val
>
> The fact that Guido says,
>
> "Now, I'm not saying that I like this better than the status quo. But
> I like it a lot better than [...] but it has the great advantage that
> it is backward compatible, and can be evolved into a PEP with a
> reference implementation without too much effort."
>
> shows that the proposal is viable.

So both forms are dual to each other ( "backwards compatibility" ) and
can be used both?

I'm -0 on this although I think the proposition fits better with the
method call syntax.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Guido's new method definition idea

2008-12-05 Thread Patrick Mullen
>> Daniel Fetchinson wrote:
>>> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-
> stay.html
>>>
>>> The proposal is to allow this:
>>>
>>> class C:
>>> def self.method( arg ):
>>> self.value = arg
>>> return self.value
>>>
>>> instead of this:
>>>
>>> class C:
>>> def method( self, arg ):
>>> self.value = arg
>>> return self.value
>>> I'd like this new way of defining methods, what do you guys think?

I don't really like the proposed syntax any better than the old
syntax.  I certainly wouldn't use "def self." in any of my old code.
I doubt I would use it in a new project were I to have the choice
either.  However, I don't really have a problem with other people
liking it.

the symetry of "def self.func(blah)==def func(self,blah)" and
"ob.func(blah)==func(ob.blah)" is kind of neat.

Could I do something like this:

def a.add(b): return a+b

Outside of a class?  Of course then that makes you think you could do
5.add(6) or something crzy like that.  (I mean, you can do
(5).__add__(6) but that's something else entirely)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Guido's new method definition idea

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 20:35:07 -0800, James Stroud wrote:

> Daniel Fetchinson wrote:
>> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-
stay.html
>> 
>> The proposal is to allow this:
>> 
>> class C:
>> def self.method( arg ):
>> self.value = arg
>> return self.value
>> 
>> instead of this:
>> 
>> class C:
>> def method( self, arg ):
>> self.value = arg
>> return self.value
> 
>> I'd like this new way of defining methods, what do you guys think?
> 
> Consider the maverick who insists on
> 
> class C:
>def me.method(arg):
>  self.value = arg

Replace "self" with "me".
 
> which should be equivalent to
> 
> class C:
>def method(me, arg):
>  me.value = arg
> 
> What's the interpreter going to do with our maverick's code?

I don't see why you think this is a problem. The compiler merely treats:

def ANYTHING.method(arg):

inside a class as if it were 

def method(ANYTHING, arg):


and it will Just Work. If you want a classmethod, you still need to use 
the classmethod decorator -- there's no reason to make self and cls 
keywords.

Personally, I'm neutral on the idea. Perhaps +0.1.


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


Can't get exclusive file lock when safely renaming a file

2008-12-05 Thread Steven D'Aprano
I'm trying to safely rename a file without over-writing any existing 
files, and I've run into a problem with file locks. Here's a naive way of 
renaming without over-writing:

import os
oldname = "ham.txt"
newname = "spam.txt"
if not os.path.exists(newname):
os.rename(oldname, newname)

It's naive because there's a race-condition: if file newname is created 
by another process after the call to exists(), but before the call to 
rename(), then it will be over-written.

Here's my current solution, based on advice given by people on this 
thread:
http://mail.python.org/pipermail/python-list/2006-October/411432.html

and this recipe:
http://code.activestate.com/recipes/65203/

but it isn't working for me.


import os, fcntl
oldname = "ham.txt"
newname = "spam.txt"

def lock_destination(name):
fileno = os.open(name, os.O_CREAT | os.O_EXCL)
fcntl.flock(fileno, fcntl.LOCK_EX)  # POSIX systems only
return fileno

# Create a test file to be renamed.
f = open(oldname, 'w')
f.write('this is my file\n')
f.close()
fileno = lock_destination(newname)

# At this point, I can see "ham.txt" plus an empty file 
# "spam.txt" in my file browser

os.rename(oldname, newname)



The rename works, but here is my problem: after getting what I thought 
was an exclusive lock on the new file, but before calling os.rename(), I 
can still over-write it from another process:

$ echo "this comes from another process" > spam.txt
$ cat spam.txt
this comes from another process


This is despite running lock_destination("spam.txt"). What am I doing 
wrong?

Before anyone asks, yes I have checked that the Python process and the 
shell process are in the same working directory, and therefore are 
writing to the same file:

>>> os.read(fileno, 200)
'this comes from another process\n'


I'm using Linux (Fedora).



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


Re: Running Python 2 and Python 3 on the same machine

2008-12-05 Thread Paul Watson
On Sat, 2008-12-06 at 01:27 +0100, "Martin v. Löwis" wrote:
> > For *NIX machines, will 'python' be placed into /usr/bin?
> 
> Not by default, no. Just try it and see for yourself.
> 
> Regards,
> Martin

Ok.  I built the source on an openSUSE 11.0 system.  I used 'sudo make
altinstll'.  It created an executable /usr/local/bin/python3.0 file.
Nothing was touched in /usr/bin.

I need to start writing some code with Python 3.  I want to write the
code in such a way that it can be easily shared with others with the
least difficulty and overhead as possible.  How should I write the code
to enable this?  What, if anything, should I assume about another
system's configuration?

As someone suggested before, naming the files as '.py3' is probably a
bad idea in the long run.  It also does not really solve the problem.

I could use a shebang.  But, what should it specify?  If I use
'python3.0', then that will soon be quite old.  If I make up a link for
python3 -> python3.0, that would work, but then every other system that
is to run the code must that link also.  However, I am thinking that
this would be the best long term answer.

#!/usr/bin/env python3

My existing /usr/bin directory has three entires for python.

python -> python2.5
python2 -> python2.5
python2.5

If I write scripts for Python 3, another developer writes scripts for
Python 2, and a common customer wants to install both of our packages
onto a single machine, then what is the best plan for everyone to make
that happen with as little difficulty as possible?

When we find out the answer to this, we can go back and talk about
Windows platforms.

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


Re: m2crypto loading cert file from memory buffer

2008-12-05 Thread Heikki Toivonen
netpork wrote:
> ctx = SSL.Context('sslv3')
> ctx.load_cert_chain('client.pem')
> 
> anyone knows a way of loading cert file from memory buffer and not
> from a file?

Yeah, see for example how I did it for Chandler:
http://svn.osafoundation.org/chandler/trunk/chandler/parcels/osaf/framework/certstore/ssl.py
(the loadCertificatesToContext function). You just need an SSL.Context,
get_cert_store() from it, and call the store's add_x509() for each cert.

> i just do not want to have my cert file in the directory of my app
> that anyone can get.

Typically certificates are public, for example all of your peers will
get the certificate anyway, so I don't see this as a problem. Your
private key is what you want to protect. Just make sure it is not
concatenated to your certificate file and there would probably be no
problem leaving the cert file publicly available.

-- 
  Heikki Toivonen - http://heikkitoivonen.net/blog/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Guido's new method definition idea

2008-12-05 Thread James Stroud


Of course I meant

class C:
  def me.method(arg):
me.value = arg

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


Re: Guido's new method definition idea

2008-12-05 Thread James Stroud

Daniel Fetchinson wrote:

http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html

The proposal is to allow this:

class C:
def self.method( arg ):
self.value = arg
return self.value

instead of this:

class C:
def method( self, arg ):
self.value = arg
return self.value



I'd like this new way of defining methods, what do you guys think?


Consider the maverick who insists on

class C:
  def me.method(arg):
self.value = arg

which should be equivalent to

class C:
  def method(me, arg):
me.value = arg

What's the interpreter going to do with our maverick's code?

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


Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 20:19:22 -0800, Istvan Albert wrote:

> On Dec 3, 8:07 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED]
> central.gen.new_zealand> wrote:
> 
> 
> 
> Originally, like many others here I said YIKES! but on a second read, it
> is not that bad. It actually grows on you.

Just like a disfiguring skin disease.

 
> After looking at it one more time I found it neat, very concise without
> being unreadable.

It would have been far more concise without the for statement (not the 
entire loop) being spread over EIGHT lines... one of which was a lonely 
colon, all by itself.



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


Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread James Stroud

alex23 wrote:

On Dec 6, 8:00 am, James Stroud <[EMAIL PROTECTED]> wrote:

I think its a symptom of the language's
maturing, getting popular, and a minority fraction* of the language's
most devout advocates developing an egotism that complements their
python worship in a most unsavory way.


It's hard to see how anyone could ever take offence at your posts
given such unbiased objectivity ;)


I know you are winking, but I literally keep a sock stuffed in my mouth 
at work to keep my own python advocacy at bay so I can get some work 
done and not drive my coworkers crazy.

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


Cambodia TEFL - Gap Year, Travel & Study, Paid Teaching Job - http://www.cambodiatefl.com

2008-12-05 Thread Jobs Teaching English in Asia
Cambodia TEFL - Gap Year, Travel & Study, Paid Teaching Job


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


Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 19:00:12 -0800, alex23 wrote:

> On Dec 6, 8:00 am, James Stroud <[EMAIL PROTECTED]> wrote:
>> I think its a symptom of the language's maturing, getting popular, and
>> a minority fraction* of the language's most devout advocates developing
>> an egotism that complements their python worship in a most unsavory
>> way.
> 
> It's hard to see how anyone could ever take offence at your posts given
> such unbiased objectivity ;)

I see your wink, but, please, did you read that thread started by "r" 
about the Ruby API for some piece of Google software? That was so 
offensively fanboyish that I almost removed Python from my computer.



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


Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread Istvan Albert
On Dec 3, 8:07 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED]
central.gen.new_zealand> wrote:



Originally, like many others here I said YIKES! but on a second read,
it is not that bad. It actually grows on you.

After looking at it one more time I found it neat, very concise
without being unreadable.

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


Re: slow Python 3.0 write performance?

2008-12-05 Thread Istvan Albert
On Dec 5, 3:41 pm, Christian Heimes <[EMAIL PROTECTED]> wrote:

> I've fixed the read() slowness yesterday. You'll get the fix in the next
> release of Python 3.0 in a couple of weeks.

Does this fix speed up the write() function as well?

A previous poster suggested that in this case the slowdown is caused
by the new io code being written in python rather than C.

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


Re: Python 3.0 C API migration tools, or docs?

2008-12-05 Thread Benjamin
On Dec 4, 9:06 pm, illume <[EMAIL PROTECTED]> wrote:
> Cool thanks Benjamin!
>
> Maybe it should be in a wiki as well?  So that as people convert their
> modules we can add notes as well.
>
> I started a wiki with that in mind here:http://wiki.python.org/moin/cporting
>
> It'd be good if there was a link from the 2to3 docs, and in the C API
> docs to either/both of these resources.
>
> I thought there'd be much more help for people migrating considering
> the 2to3 tool exists... but I'll get over it... hehe.

Thanks for being so positive. If you'd like to help with the HowTo,
feel free to email [EMAIL PROTECTED]
>
> cheers,

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


Re: RELEASED Python 3.0 final

2008-12-05 Thread bearophileHUGS
Steven D'Aprano:

>I think you're talking about mixed spaces/tabs in the one module.<

Right.


>My gut feeling is that you have to have a fairly unusual set of circumstances 
>before it causes actual bugs.<

I don't mix tab and spaces in my code, and my editor is able to
convert them, so after the first few days of Python coding, it more or
less never caused me problems.
But such thing in code written by others has caused me enough
troubles, I am generally unable to edit such code keeping it
functional, so I have to (sometimes by trial and error) convert it to
a space only (or tabs only) format.
Such troubles aren't that large compared for example to the usual
troubles I receive writing and comping C++ code, but enough compared
to the usual smoothness of coding in Python :-)


>Er, what do you mean? What wart?<

Not using {:}/{} as literals for empty dict/set.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread alex23
On Dec 6, 8:00 am, James Stroud <[EMAIL PROTECTED]> wrote:
> I think its a symptom of the language's
> maturing, getting popular, and a minority fraction* of the language's
> most devout advocates developing an egotism that complements their
> python worship in a most unsavory way.

It's hard to see how anyone could ever take offence at your posts
given such unbiased objectivity ;)
--
http://mail.python.org/mailman/listinfo/python-list


Guido's new method definition idea

2008-12-05 Thread Daniel Fetchinson
Hi folks,

The story of the explicit self in method definitions has been
discussed to death and we all know it will stay. However, Guido
himself acknowledged that an alternative syntax makes perfect sense
and having both (old and new) in a future version of python is a
possibility since it maintains backward compatibility. The alternative
syntax will be syntactic sugar for the old one. This blog post of his
is what I'm talking about:

http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html

The proposal is to allow this:

class C:
def self.method( arg ):
self.value = arg
return self.value

instead of this:

class C:
def method( self, arg ):
self.value = arg
return self.value

I.e. explicit self stays only the syntax is slightly different and may
seem attractive to some. As pointed out by Guido classmethods would
work similarly:

class C:
@classmethod
def cls.method( arg ):
cls.val = arg
return cls.val

The fact that Guido says,

"Now, I'm not saying that I like this better than the status quo. But
I like it a lot better than [...] but it has the great advantage that
it is backward compatible, and can be evolved into a PEP with a
reference implementation without too much effort."

shows that the proposal is viable.

I'd like this new way of defining methods, what do you guys think?
Anyone ready for writing a PEP?

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: A more pythonic way of writting

2008-12-05 Thread eric
On Dec 6, 12:19 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Fri, 05 Dec 2008 07:44:21 -0800, eric wrote:
> > I like to believe that the less the 'debug pointer' stands in the python
> > code, the fastest the code is (or is potentially)
>
> What's a debug pointer?
>
> Pre-mature optimization is the root of evil in programming. Unless you
> have actually *measured* the speed of the code, how do you know you
> aren't making it slower instead of faster?
>
> Experience with other languages often is misleading when programming with
> Python. If you are used to programming in C, for example, then you will
> tend to program one way because comparisons are fast and moving records
> is slow. But in Python, comparisons can be slow and moving records is
> fast, so the C programmer's intuitions about "fast code" are often
> pessimations instead of optimizations.
>
> --
> Steven

you are right about premature optimization. I cannot disagree.

My 'rule of thumb' was more about that:
1/ keep the code the more descriptive and the less procedural as
possible.
2/ the less instructions you write, the more optimization you'll get
from the others

the hypercube function is cool, and I would use it, if I weren't in
charge of maintaining the code.


I've done some 'timeit'

import timeit

t1 = timeit.Timer(
"""
h1 = hypercube(6)
""",
"""def hypercube(ndims):
return [[i&mask==mask for mask in [1

Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Aaron Brady wrote:

> On Dec 5, 4:32 am, Lawrence D'Oliveiro <[EMAIL PROTECTED]
> central.gen.new_zealand> wrote:
>
>> The code people write is probably a direct reflection of their thinking
>> processes: For example, slow, plodding, one step at a time, incapable of
>> imaginative leaps, versus those who operate directly on larger patterns
>> at once...
> 
> That distinction operates indirectly on smaller patterns.

Do you find this

(open, gzip.GzipFile)[Entry.endswith(".gz")](os.path.join(PatchesDir, 
Entry), "r")

complicated or hard to understand? It's made up of very simple pieces,
combined according to very simple rules, viz:-

A tuple of candidate functions:

(open, gzip.GzipFile)

A choice from that tuple according to a condition:

[Entry.endswith(".gz")]

And finally, arguments to pass to the chosen function:

(os.path.join(PatchesDir, Entry), "r")

See, it's so simple, a child could understand it. A child who isn't burdened
with the preconceptions that seem to afflict some participants in this
noisegroup...
--
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 3.0 final

2008-12-05 Thread Ben Finney
[EMAIL PROTECTED] (Aahz) writes:

> In article <[EMAIL PROTECTED]>,
> Ben Finney  <[EMAIL PROTECTED]> wrote:
> >James Stroud <[EMAIL PROTECTED]> writes:
> >>
> >> comp.lang.python3k ?
> >
> >The language has undergone an incompatible divide. Hopefully the
> >community need not do the same.
> 
> Pish and tosh. James was clearly making a funny; there's not *that*
> much difference between 2.x and 3.x.

You appear to assume I was not going along with the funny. To be
expected, I suppose, given the well-documented context lossage in a
message-based medium.

I hereby recommend “pish and tosh” for use by anyone who wants to
counter someone's point. It beats by a country furlong the invective
that has become regrettably common here in recent months.

-- 
 \“I was once walking through the forest alone and a tree fell |
  `\   right in front of me, and I didn't hear it.” —Steven Wright |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread MRAB

John Machin wrote:

On Dec 6, 10:35 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:

On Fri, 05 Dec 2008 12:00:59 -0700, Joe Strout wrote:

So UTF-16 has an explicit EOF marker within the text?

No, it does not.  I don't know what Terry's thinking of there, but text
files do not have any EOF marker.  They start at the beginning
(sometimes including a byte-order mark), and go till the end of the
file, period.

Windows text files still interpret ctrl-Z as EOF, or at least Windows XP
does. Vista, who knows?


This applies only to files being read in an 8-bit text mode. It is
inherited from MS-DOS, which followed the CP/M convention, which was
necessary because CP/M's file system recorded only the physical file
length in 128-byte sectors, not the logical length. It is likely to
continue in perpetuity, just as standard railway gauge is (allegedly)
based on the axle-length of Roman chariots.

The chariots in question were drawn by 2 horses, so the gauge is based 
in the width of a horse. :-)



None of this is relevant to the OP's problem; his file appears to have
been truncated rather than having spurious data appended to it.

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


Progressive download with Urllib2.

2008-12-05 Thread r0g
Hi There,

I am trying to download some video with python but have run aground on
the rocky shores of pseudostreaming. Fingers crossed someone else here
has some experience with this! Here's what I've done so far...

The initial link is foo.asx so I download that with...

handle = urllib2.urlopen( 'http://www.example.com/foo.asx' )
mime_type = url_handle.info().getheader("Content-Type","")
data = urllib2.read()

It comes back with mime type of 'video/x-ms-asf' and the content...
'ASF http://www.example.com/foo-100.wmv'

I then used the same code again to grab the URL (ditching the 'ASF '
bit) and this time it comes back with a mime type of 'video/x-ms-wvx'
and two URLs...

Ref1=http://www.example.com/foo-100.wmv?MSWMExt=.asf
Ref2=http://192.168.0.1/foo-100.wmv?MSWMExt=.asf

The latter is no use as it's on a private LAN and the second is the same
URL as last time, just with a different mime type and naturally it
returns the same thing if I use Urllib2 open and read to fetch it with
or without the '?MSWMExt=.asf' part. So...

I fired up wireshark and spotted these lines coming back in the headers:

Server: Cougar/9.01.01.3862

Supported: com.microsoft.wm.srvppair, com.microsoft.wm.sswitch,
com.microsoft.wm.predstrm, com.microsoft.wm.fastcache,
com.microsoft.wm.startupprofile

Euw...

I suspected for a second that meant I have to connect with a MS media
player or something but the same URL works fine when I paste it into
Firefox and the video starts pseudostreaming away so...

How can I get their server to give me the video data?  Do I need to ask
for the file with some other protocol? RTSP? or change my user_agent
string and pretend to be Windows Media Player??  Do I need another
module as opposed to urllib2? and if so which one? I've had a search but
drawn a blank.

I guess I'll plug on in wireshark and see what some other programs do
but I'd appreciate it if anyone can put me out of my misery!

Yours stuck,

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


Re: Running Python 2 and Python 3 on the same machine

2008-12-05 Thread Martin v. Löwis
> For *NIX machines, will 'python' be placed into /usr/bin?

Not by default, no. Just try it and see for yourself.

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


Re: Running Python 2 and Python 3 on the same machine

2008-12-05 Thread Martin v. Löwis
Terry Reedy wrote:
> Martin v. Löwis wrote:
>>> Since the source code is incompatible, I was expecting the Python
>>> executable to have a new name such as 'python3'
>>
>> It does: the executable is called python3.0.
> 
> Why do you say that? 

Because it is - on Unix. I assumed that was the platform that the OP
cared about.

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


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread John Machin
On Dec 6, 10:35 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Fri, 05 Dec 2008 12:00:59 -0700, Joe Strout wrote:
> >> So UTF-16 has an explicit EOF marker within the text?
>
> > No, it does not.  I don't know what Terry's thinking of there, but text
> > files do not have any EOF marker.  They start at the beginning
> > (sometimes including a byte-order mark), and go till the end of the
> > file, period.
>
> Windows text files still interpret ctrl-Z as EOF, or at least Windows XP
> does. Vista, who knows?

This applies only to files being read in an 8-bit text mode. It is
inherited from MS-DOS, which followed the CP/M convention, which was
necessary because CP/M's file system recorded only the physical file
length in 128-byte sectors, not the logical length. It is likely to
continue in perpetuity, just as standard railway gauge is (allegedly)
based on the axle-length of Roman chariots.

None of this is relevant to the OP's problem; his file appears to have
been truncated rather than having spurious data appended to it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple Versions of Python on Windows XP

2008-12-05 Thread Martin v. Löwis
Glenn Linderman wrote:
> I'm unaware of it needing to handle multiple extensions
> from the command line or via double clicking in Explorer, so was
> exploiting the extra level of indirection to save typing, and make the
> command simpler to remember.

Python *does* provide multiple useful extensions that you might want to
double-click, namely .py and .pyw. It also provides an association for
.pyc; whether that is useful or not may be debatable.

> Not sure what your reference to an editor is about.

This I also wonder about. Apparently, his editor has the capability of
running Python scripts, and then his question is how to make the editor
use a different Python version (and he assumed that there is the notion
of a "default" Python version in Windows, and that the editor would just
run the default).

I'm still very unsure as to what his editor actually does, but his
report of success seems to indicate that it choses the interpreter
associated with .py.

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


Re: Centralized logging server...

2008-12-05 Thread Sam
Yep...I'm planning on using SysLogHandler.  Although if I were to use
rsyslog, for example, I might potentially be better off using tcp or
even doing it using rfc 3195.  Sysloghandler uses udp...I imagine that
will be faster but with less reliability.  I'll have to think about
that.  Has anyone implemented a library for rfc 3195, or would I have
to do that from scratch.

I was more curious as to what people are using to receive the
messages?  Syslog-ng?  traditoinal?  rsyslog?  Home grown solutions?

I know syslog is already running, but I'm not sure the traditional
version could keep up with all the traffic I'm going to have.  Anyone
know how well it scales compared to the alternatives?

Thanks
Sam

On Dec 5, 12:24 pm, [EMAIL PROTECTED] wrote:
>     Sam> I've been playing with the python logging module.  I'd like all of
>     Sam> these applications to write their logs to the same place in order
>     Sam> to make analysis easier.
>
>     Sam> Any ideas on best practices?
>
> Perhaps use logging.handlers.SysLogHandler?
>
>     Sam> What are my options for a syslog server to receive the messages?
>     Sam> Rsyslog looks like it would be good.  Anyone know anything else?
>
> If you're running on a Unix system of any type you should have syslog by
> default.  You shouldn't need to install anything.
>
> --
> Skip Montanaro - [EMAIL PROTECTED] -http://smontanaro.dyndns.org/

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


Re: RELEASED Python 3.0 final

2008-12-05 Thread Aahz
In article <[EMAIL PROTECTED]>,
Ben Finney  <[EMAIL PROTECTED]> wrote:
>James Stroud <[EMAIL PROTECTED]> writes:
>>
>> comp.lang.python3k ?
>
>The language has undergone an incompatible divide. Hopefully the
>community need not do the same.

Pish and tosh.  James was clearly making a funny; there's not *that* much
difference between 2.x and 3.x.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
--
http://mail.python.org/mailman/listinfo/python-list


Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 14:00:18 -0800, James Stroud wrote:

> Andreas Waldenburger wrote:
>> Is it me, or has c.l.p. developed a slightly harsher tone recently?
>> (Haven't been following for a while.)
> 
> Yep. I can only post here for about a week or two until someone blows a
> cylinder and gets ugly because they interpreted something I said as a
> criticism of the language and took it personally by extension.


What do you mean??? Python is PERFECT and if you don't AGREE than you 
should go back to Ruby you Ruby-lover!!!


*wink*




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


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 12:00:59 -0700, Joe Strout wrote:

>> So UTF-16 has an explicit EOF marker within the text?
> 
> No, it does not.  I don't know what Terry's thinking of there, but text
> files do not have any EOF marker.  They start at the beginning
> (sometimes including a byte-order mark), and go till the end of the
> file, period.

Windows text files still interpret ctrl-Z as EOF, or at least Windows XP 
does. Vista, who knows?


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


Re: RELEASED Python 3.0 final

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 22:01:55 +, je.s.te.r wrote:

> Fernando H. Sanches <[EMAIL PROTECTED]> wrote:
>> And I personally disliked most of the changes (specially the ones on
>> map and reduce). I hope functional programming doesn't get even more
>> hindered in future releases, because I believe these changes only made
>> Python weaker.
> 
> The functional programming aspect of Python is one of my favorite parts,
> having a mixed background in functional/non-functional languages.

map is still a built-in.

reduce is moved to functools.

I think the only change to map is that instead of returning a list, it 
returns an iterator. What this means is that Python's functional 
programming aspect is now lazy, and that's a good thing.



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


Re: Python C API

2008-12-05 Thread googler . 1 . webmaster
Hi!

Any ideas? Thanks, :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I load a python program at the interactive >>> prompt?

2008-12-05 Thread Diez B. Roggisch

Tim Golden schrieb:

walterbyrd wrote:

I am running cygwin on xp.


 and I just noticed this vital bit. So not sure
how much of my other post applies. Sorry. Maybe it'll
help anyway. :)



Everything. The atrocity that the windows terminal window is isn't 
mitigated by an out-of-the-box cygwin. Did anybody *ever* need a 
rectangular marking mode?


You could use rxvt. But that's also far from perfect.

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


Re: A more pythonic way of writting

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 07:44:21 -0800, eric wrote:

> I like to believe that the less the 'debug pointer' stands in the python
> code, the fastest the code is (or is potentially)

What's a debug pointer?

Pre-mature optimization is the root of evil in programming. Unless you 
have actually *measured* the speed of the code, how do you know you 
aren't making it slower instead of faster?

Experience with other languages often is misleading when programming with 
Python. If you are used to programming in C, for example, then you will 
tend to program one way because comparisons are fast and moving records 
is slow. But in Python, comparisons can be slow and moving records is 
fast, so the C programmer's intuitions about "fast code" are often 
pessimations instead of optimizations. 


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


Re: Find Files in a Folder Between 2 Dates

2008-12-05 Thread John Machin
On Dec 6, 9:41 am, Gregory Plantaine <[EMAIL PROTECTED]> wrote:
> That worked perfectly!
>
> Thanks Tim!
>
> Since we can print the files, does that mean the list of files is in a
> tuple, or something?  Would there be a way to further split up the
> file names?
>
> For example, now that the files are processed into the list, we want
> to look through that list to find different filetypes.
>
> files
>
> C:\Folder\File_200812051439.111
> C:\Folder\File_200812051539.222

*DANGER* It looks like you are interested in the timestamps that are
embedded in the names of the files. Tim's code assumes [reasonably
given that your problem description was ambiguous and had no examples
of good and bad results] that you are interested in the last
modification time of the file. You may say "same thing". Yes, same
thing, until somebody sucks a file into a text editor, messes with it,
and saves it again. No, Murphy's Law has not been repealed.

>
> Can we split up .111 files?
>
> Actually, where would I look something like this up?

In the Library Reference Manual ... there are all sorts of goodies in
the os and os.path modules e.g. like those used by Tim; make sure you
read the docs on the methods Tim used so that you understand what's
happening.

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


Re: RELEASED Python 3.0 final

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 07:09:27 -0800, bearophileHUGS wrote:

> Andreas Waldenburger:
>> Whenever has it been a pythonic ideal to "not allow" stuff? You get
>> warnings. Everything else is up to you.
> 
> It's a strong source for bugs, especially for newbies, that I have hoped
> to see removed from Python3 (my first request of this was years ago). I
> was nearly sure to see this wart removed from Python3, and now I hear
> it's presents still. I don't understand why they haven't fixed it.

"It"? Context please... snipping unnecessarily quoted text is a good 
thing, but please leave enough context for people to know what you're 
talking about.

I think you're talking about mixed spaces/tabs in the one module. 
Frankly, I question just how "strong" a source of bugs it really is. Oh, 
I don't doubt that there are circumstances where it can cause bugs, but I 
don't remember the last time the solution to some newbie's problem on 
comp.lang.python was "use spaces or tabs but not both". My gut feeling is 
that you have to have a fairly unusual set of circumstances before it 
causes actual bugs.

So perhaps nobody on the python-dev team have fixed it yet because nobody 
cares enough to do the work, or it's unexciting and tedious to fix. Or 
maybe python-dev *think* they've fixed it, and the fact that it isn't 
fixed is a bug that needs reporting.


 
> Then this is the third thing I don't like of Python3 (the other two
> being the removal of automatic tuple unpacking in function signature and
> the wart of literals for empty set/dict).

Er, what do you mean? What wart?




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


Re: Find Files in a Folder Between 2 Dates

2008-12-05 Thread Gregory Plantaine
That worked perfectly!

Thanks Tim!

Since we can print the files, does that mean the list of files is in a
tuple, or something?  Would there be a way to further split up the
file names?

For example, now that the files are processed into the list, we want
to look through that list to find different filetypes.

files

C:\Folder\File_200812051439.111
C:\Folder\File_200812051539.222

Can we split up .111 files?

Actually, where would I look something like this up?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread John Machin
On Dec 6, 5:36 am, Johannes Bauer <[EMAIL PROTECTED]> wrote:
> So UTF-16 has an explicit EOF marker within the text? I cannot find one
> in original file, only some kind of starting sequence I suppose
> (0xfeff). The last characters of the file are 0x00 0x0d 0x00 0x0a,
> simple \r\n line ending.

Sorry, *WRONG*. It ends in 00 0d 00 0a 00. The file is 1559 bytes
long, an ODD number, which shouldn't happen with utf16.  The file is
stuffed. Python 3.0 has a bug; it should give a meaningful error
message.

Python 2.6.0 silently ignores the problem [that's a BUG] when read by
a similar method:

| >>> import codecs
| >>> lines = codecs.open('x.txt', 'r', 'utf16').readlines()
| >>> lines[-1]
| u'[PhonePBK004]\r\n'

Python 2.x does however give a meaningful precise error message if you
try a decode on the file contents:

| >>> s = open('x.txt', 'rb').read()
| >>> len(s)
| 1559
| >>> s[-35:]
| '\x00\r\x00\n\x00[\x00P\x00h\x00o\x00n\x00e\x00P\x00B\x00K
\x000\x000\x004\x00]\x00\r\x00\n\x00'
| >>> u = s.decode('utf16')
| Traceback (most recent call last):
|   File "", line 1, in 
|   File "C:\python26\lib\encodings\utf_16.py", line 16, in decode
| return codecs.utf_16_decode(input, errors, True)
| UnicodeDecodeError: 'utf16' codec can't decode byte 0x00 in position
1558: truncated data

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


Re: Project structure - Best practices

2008-12-05 Thread Casey McGinty
>
> This is first time that I am building python application that is
> larger than a single module and I would like to do it right.


I want to just say I am in agreement with the OP. Basically, there are a lot
of factors to balance out and consider when starting a python application
for the first time. For a new developer, tracking down this information is
not a trivial task, as it is spread out over many location, or in worse
cases, left up for the developer to "discover" on his/her own. I know it was
not an easy task for me at first, and if we can make it easier for the next
set of newcomeres, than that would be all the better.

As far as open source projects go, the Python documentation is some of the
best I've seen, however it would be nice to see a "Python Project Quick
Start Guide" as part of the standard docs. The basics of this document would
touch on packaging, imports, logging, testing, documenting, naming
conventions, SCM, etc. Instead of rehashing the current docs, the focus
would be on the combined integration of all of these features into a single
code base.

I realize that there is a wide range of preferences on specifics of each
topic. But, just like PEP 8[1] is a good standard on code style, so would
having a document as reference for other project-level "style" fundamentals.

Ultimately, there could be a template project directory and source files
that a user could build from. This is much more preferable to a blank
directory, and might have the added benefit of influencing users to pick up
recommended, but often ignored, practices at the beginning of a project.

So, with all this said. I'd be willing to capture a lot of the methods I've
picked up over the last couple months working with python. If anyone wants
to add some suggestions, I'd love to have more discussion to organize
thoughts and see if any new ideas come out. As a starting point, what is a
good markup language to use for some slick HTML and PDF output?

- Casey McGinty

[1] http://www.python.org/dev/peps/pep-0008/
--
http://mail.python.org/mailman/listinfo/python-list


Re: slow Python 3.0 write performance?

2008-12-05 Thread bearophileHUGS
Christian Heimes:
> I've fixed the read() slowness yesterday. You'll get the fix in the next
> release of Python 3.0 in a couple of weeks.

Thank you.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread Mike Driscoll
On Dec 5, 4:00 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> Andreas Waldenburger wrote:
> > Is it me, or has c.l.p. developed a slightly harsher tone recently?
> > (Haven't been following for a while.)
>
> Yep. I can only post here for about a week or two until someone blows a
> cylinder and gets ugly because they interpreted something I said as a
> criticism of the language and took it personally by extension. Then I
> have to take a 4 month break because I'm VERY prone to
> reciprocating--nastily. I think its a symptom of the language's
> maturing, getting popular, and a minority fraction* of the language's
> most devout advocates developing an egotism that complements their
> python worship in a most unsavory way.
>
> I wish they would instead spend their energy volunteering to moderate
> this list and culling out some of the spam.
>
> *No names were mentioned in the making of this post.

I really like Python, but I seem to get blasted enough on this list
that I don't post much on here any more without being extremely
careful in how I word my answers. Bleh!

Oh well. You win some, you lose some.

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


Re: Problems running on hp duo Pentium R processor

2008-12-05 Thread Benjamin Kaplan
On Fri, Dec 5, 2008 at 4:08 PM, jim-on-linux <[EMAIL PROTECTED]> wrote:

> On Friday 05 December 2008 15:27, Kevin Kelley wrote:
> > If they are running standard Win XP (Home or Pro),
> > as opposed to 64-bit Win XP, then whether or not the
> > CPU supports the IA64 instruction set really doesn't
> > matter. As far as I know every Intel Core2 and
> > Pentium Dual-Core CPU since ~ 2006 has supported
> > 64bit instructions, even the Atom is 64bit. Also,
> > the "R" is for Registered Trademark (of Pentium),
> > it's not part of the name/model
> > (http://ark.intel.com/cpu.aspx?groupId=33925).
> >
> > Kevin
>
> Kevin ,
> I'm trying to find out why my program gets an import
> error on only one machine.  Is there any problem with
> python running on a 64 bit Architecture machine or is
> it something specific to this one HP machine?  None of
> my other clients have had this problem, nor have I on
> any machine that I've tried tested it on.
>
> jim-on-linux
>
> What Kevin's saying is that the architecture of the processor doesn't
really matter here. Just about every processor made in the last 2 years is a
64-bit processor. Even though they have 64-bit processors, most people are
still running the 32-bit version of Windows. In that case, for programming
purposes, the computer should be treated as 32-bit. If your customer is
using 64-bit Windows, however, things will change. On 64-bit operating
systems, you should use the 64-bit version of Python. Windows x64 can run
32-bit programs but the 32-bit programs can't load the 64-bit DLLs and
vice-versa so you might see an error like the one you posted.. Try using the
AMD64 version of python and see if that fixes the problem for them.



>
> >
> > On Fri, Dec 5, 2008 at 2:02 PM, jim-on-linux
> <[EMAIL PROTECTED]> wrote:
> > > Python help,
> > >
> > > In September I wrote:
> > > I have a number of clients running a program built
> > > with python 2.5.  One has just purchased an HP
> > > with a duo core Pentium R processor E2200,  2.2G
> > > with .99g ram.
> > >
> > > Only on the new HP, when they try to print they
> > > get an import error;
> > > File win32ui.pyc line 12, in 
> > > File win32ui.pyc, line 10, in _load
> > > ImportError: DLL load failed:  The specified
> > > module could not be found.
> > >
> > > It turns out that the E2200 processor is 64 bit
> > > architecture.
> > >
> > > What are my options?
> > >
> > > I've run DependecyWalker,
> > > They are using Win XP Service Pack 2
> > >
> > >
> > >
> > > jim=on-linux
> > >
> > >
> > >
> > >
> > > --
> > > http://mail.python.org/mailman/listinfo/python-lis
> > >t
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud

James Stroud wrote:

Terry Reedy wrote:

because there is no bug to fix.  I have suggesting closing.


May I suggest to add something to this effect within the issue itself so 
others won't spend time trying to figure out why the "bug" is still 
open?


Sorry, you did that.

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


Re: dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud

Terry Reedy wrote:

because there is no bug to fix.  I have suggesting closing.


May I suggest to add something to this effect within the issue itself so 
others won't spend time trying to figure out why the "bug" is still 
open? If this is a more general feature of issues, then perhaps it would 
be helpful to provide a footnote at the bottom of all issue pages via 
the page template that explains why they are not bugs and suggests a 
general course of action for the programmer.


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


Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread James Stroud

Andreas Waldenburger wrote:

Is it me, or has c.l.p. developed a slightly harsher tone recently?
(Haven't been following for a while.)


Yep. I can only post here for about a week or two until someone blows a 
cylinder and gets ugly because they interpreted something I said as a 
criticism of the language and took it personally by extension. Then I 
have to take a 4 month break because I'm VERY prone to 
reciprocating--nastily. I think its a symptom of the language's 
maturing, getting popular, and a minority fraction* of the language's 
most devout advocates developing an egotism that complements their 
python worship in a most unsavory way.


I wish they would instead spend their energy volunteering to moderate 
this list and culling out some of the spam.


*No names were mentioned in the making of this post.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Overriding a method at the instance level on a subclass of a builtin type

2008-12-05 Thread Arnaud Delobelle
Arnaud Delobelle <[EMAIL PROTECTED]> writes:

[...]

> class ClassGetItem(object):
> def __get__(self, obj, objtype=None):
> return obj._getitem_
> def __set__(self, obj, val):
> obj._getitem_ = val
>
> class GetItem(object):
> def __get__(self, obj, objtype=None):
> return obj._getitem_
> def __set__(self, obj, val):
> obj._getitem_ = val

It's funny how the brain works.  I didn't realise both classes were the
same until I read my own post!

[...]

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


Re: slow Python 3.0 write performance?

2008-12-05 Thread Christian Heimes

MRAB wrote:
Does pysco with with Python 3.0 (the homepage says 2.5)? If it does then 
that might help! :-)


No, it won't help.

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


Re: Can I load a python program at the interactive >>> prompt?

2008-12-05 Thread Brian Blais

On Dec 5, 2008, at 15:52 , walterbyrd wrote:


Can I load a file into the python interactive environment?  For
example I have a file called test.py that consists of the following:

print "hello"
print "hello again"

Can I load that file into python at the >>> prompt?


load "test.py"


or something like that?



I think you mean:

execfile('test.py')

that should work.  if you have iPython, which is a great shell for  
running python code, you can do:


run test.py

as far as copy/paste, I think in Windows Python runs in a DOS prompt,  
so you should be able to right-click and choose Edit/Paste.  Not too  
convenient, but I think it works.



bb



--
Brian Blais
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais



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


Re: Can I load a python program at the interactive >>> prompt?

2008-12-05 Thread Tim Golden

walterbyrd wrote:

I am running cygwin on xp.


 and I just noticed this vital bit. So not sure
how much of my other post applies. Sorry. Maybe it'll
help anyway. :)

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


Re: Problems running on hp duo Pentium R processor

2008-12-05 Thread jim-on-linux
On Friday 05 December 2008 15:27, Kevin Kelley wrote:
> If they are running standard Win XP (Home or Pro),
> as opposed to 64-bit Win XP, then whether or not the
> CPU supports the IA64 instruction set really doesn't
> matter. As far as I know every Intel Core2 and
> Pentium Dual-Core CPU since ~ 2006 has supported
> 64bit instructions, even the Atom is 64bit. Also,
> the "R" is for Registered Trademark (of Pentium),
> it's not part of the name/model
> (http://ark.intel.com/cpu.aspx?groupId=33925).
>
> Kevin

Kevin ,
I'm trying to find out why my program gets an import 
error on only one machine.  Is there any problem with 
python running on a 64 bit Architecture machine or is 
it something specific to this one HP machine?  None of 
my other clients have had this problem, nor have I on 
any machine that I've tried tested it on.

jim-on-linux



>
> On Fri, Dec 5, 2008 at 2:02 PM, jim-on-linux 
<[EMAIL PROTECTED]> wrote:
> > Python help,
> >
> > In September I wrote:
> > I have a number of clients running a program built
> > with python 2.5.  One has just purchased an HP
> > with a duo core Pentium R processor E2200,  2.2G
> > with .99g ram.
> >
> > Only on the new HP, when they try to print they
> > get an import error;
> > File win32ui.pyc line 12, in 
> > File win32ui.pyc, line 10, in _load
> > ImportError: DLL load failed:  The specified
> > module could not be found.
> >
> > It turns out that the E2200 processor is 64 bit
> > architecture.
> >
> > What are my options?
> >
> > I've run DependecyWalker,
> > They are using Win XP Service Pack 2
> >
> >
> >
> > jim=on-linux
> >
> >
> >
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-lis
> >t
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I load a python program at the interactive >>> prompt?

2008-12-05 Thread Tim Golden

walterbyrd wrote:

I am running cygwin on xp.

Much to my annoyance, I can not cut-and-paste from a windows app to
the python prompt. I think I could do this with putty, but I do not
have the permissions to install putty on my xp box.


I do this all the time. The key (altho' not strictly essential)
is to access the console window Properties from the top-left drop-down
menu and then on the first tab, select Quick Edit. With this, you
can just right-click with the mouse and whatever you had in the
clipboard (as long as it's text) will drop into your Python
session. Whenever I'm posting code snippets here, I always
copy them from the email and do what I've described to run
them in a fresh interpreter session to make sure they work.



Can I load a file into the python interactive environment?  For
example I have a file called test.py that consists of the following:

print "hello"
print "hello again"

Can I load that file into python at the >>> prompt?


load "test.py"


or something like that?



Well, you can use execfile if you want.

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


Re: slow Python 3.0 write performance?

2008-12-05 Thread MRAB

Istvan Albert wrote:

On Dec 5, 3:06 pm, [EMAIL PROTECTED] wrote:


It should get faster over time.  It will get faster over a shorter period of
time if people contribute patches.


I see, thanks for the clarification.

I will make the point though that this makes python 3.0 unsuited for
anyone who has to process data. One could live with slowdowns of say
20-50 percent, to get the goodies that 3.0 offers, but when a process
that takes 1 second suddenly starts to take 10, it is makes the
situation untenable.

Does pysco with with Python 3.0 (the homepage says 2.5)? If it does then 
that might help! :-)

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


Can I load a python program at the interactive >>> prompt?

2008-12-05 Thread walterbyrd
I am running cygwin on xp.

Much to my annoyance, I can not cut-and-paste from a windows app to
the python prompt. I think I could do this with putty, but I do not
have the permissions to install putty on my xp box.

Can I load a file into the python interactive environment?  For
example I have a file called test.py that consists of the following:

print "hello"
print "hello again"

Can I load that file into python at the >>> prompt?

>>> load "test.py"

or something like that?
--
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 3.0 final

2008-12-05 Thread Andreas Waldenburger
On Fri, 5 Dec 2008 12:16:47 -0800 (PST) "Fernando H. Sanches"
<[EMAIL PROTECTED]> wrote:

> On Dec 4, 5:45 pm, Andreas Waldenburger <[EMAIL PROTECTED]> wrote:
> > On Thu, 4 Dec 2008 11:52:38 -0600 [EMAIL PROTECTED] wrote:
> > [snip]
> > Whenever has it been a pythonic ideal to "not allow" stuff? You get
> > warnings. Everything else is up to you.
> >
> >  [snip]
> 
> Python has "not allowed stuff" for a long time.
> 
> For example, it disallows statements in lambdas.
> 
Which is sensible (for Python) because it does not have block
delimiters.

Also, lambdas are syntactic sugar for special use cases. It's not
like they are needed at all. But sometimes mixing tabs and spaces can
be needed (think coding standards).

What else is disallowed?


> "Disallowing" is not bad. Disallowing bad practices (like mixing tabs
> and spaces) is actually good!
> 
This presupposes that mixing tabs and spaces is "bad". That's like
saying C++ is bad.


> I agree that the tab/space thing should be changed. Would it be too
> hard to make the parser see if the indentation is consistent in the
> whole file?
Maybe not, but it would be rather hard to agree on what can be
called consistent and what can not, I think. You can mix spaces and
tabs consistently, just as you can use any one consistently.


> This is a annoying source of problems, specially since
> you can't tell a whitespace from a tab just looking at it.
> 
There are editors that let you show different symbols for spaces and
tabs (I know, I know ...).


> And I personally disliked most of the changes (specially the ones on
> map and reduce). I hope functional programming doesn't get even more
> hindered in future releases, because I believe these changes only made
> Python weaker.
> 
+1


/W



-- 
My real email address is constructed by swapping the domain with the
recipient (local part).

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


Re: slow Python 3.0 write performance?

2008-12-05 Thread Christian Heimes

Istvan Albert wrote:

I see, thanks for the clarification.

I will make the point though that this makes python 3.0 unsuited for
anyone who has to process data. One could live with slowdowns of say
20-50 percent, to get the goodies that 3.0 offers, but when a process
that takes 1 second suddenly starts to take 10, it is makes the
situation untenable.


The speed issue slipped through the alpha and beta releases. Apparently 
no user has tested Python 3.0 with large files so far. Some bugs just 
can't be found by the developers.


I've fixed the read() slowness yesterday. You'll get the fix in the next 
release of Python 3.0 in a couple of weeks.


Christian

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


Re: Overriding a method at the instance level on a subclass of a builtin type

2008-12-05 Thread Arnaud Delobelle
Arnaud Delobelle <[EMAIL PROTECTED]> writes:

> "Zac Burns" <[EMAIL PROTECTED]> writes:
>
>> Ok. Feature request then - assignment of a special method name to an
>> instance raises an error.
>
> I haven't got the time to implement it, but I'm sure you can obtain the
> behaviour you want.

OK I've had half an hour to fill this afternoon so I tried to implement
it.  I've restriced the ability to override special methods to
__getitem__ but this could be extended to any special method AFAICS.  It
combines a metaclass and two descriptors (one for the metaclass and one
for the class), there may be a simpler way!  It is proof-of-concept
code, I have not tried to make it behave sensibly when no __getitem__
method is defined (although that would be straighforward) and I have not
thought about how it would work with (multiple) inheritance (this may
require lots more thinking).  Here it is, tested very succintly on
Python 2.5:

class ClassGetItem(object):
def __get__(self, obj, objtype=None):
return obj._getitem_
def __set__(self, obj, val):
obj._getitem_ = val

class GetItem(object):
def __get__(self, obj, objtype=None):
return obj._getitem_
def __set__(self, obj, val):
obj._getitem_ = val

class MetaOverrideSpecial(type):
def __new__(meta, name, bases, attrs):
if '__getitem__' in attrs:
attrs['_getitem_'] = attrs['__getitem__']
attrs['__getitem__'] = GetItem()
return type.__new__(meta, name, bases, attrs)
__getitem__ = ClassGetItem()

class OverrideSpecial(object):
__metaclass__ = MetaOverrideSpecial


Here is an example that shows it in action:

>>> class Foo(OverrideSpecial):
... def __getitem__(self, key): return 'Class getitem(%s)' % key
... 
>>> foo=Foo()
>>> foo[3]
'Class getitem(3)'

Override the class's __getitem__ special method:

>>> Foo.__getitem__ = lambda self, key: 'Overriden class getitem(%s)' % key
>>> foo['bar']
'Overriden class getitem(bar)'

Override the instance's __getitem__ special method:

>>> foo.__getitem__ = lambda key: 'Instance getitem(%s)' % key
>>> foo['baz']
'Instance getitem(baz)'

What-a-way-to-waste-time'ly yours

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


Re: Problems running on hp duo Pentium R processor

2008-12-05 Thread Kevin Kelley
If they are running standard Win XP (Home or Pro), as opposed to 64-bit Win
XP, then whether or not the CPU supports the IA64 instruction set really
doesn't matter. As far as I know every Intel Core2 and Pentium Dual-Core CPU
since ~ 2006 has supported 64bit instructions, even the Atom is 64bit. Also,
the "R" is for Registered Trademark (of Pentium), it's not part of the
name/model (http://ark.intel.com/cpu.aspx?groupId=33925).

Kevin

On Fri, Dec 5, 2008 at 2:02 PM, jim-on-linux <[EMAIL PROTECTED]> wrote:

> Python help,
>
> In September I wrote:
> I have a number of clients running a program built
> with python 2.5.  One has just purchased an HP with
> a duo core Pentium R processor E2200,  2.2G with .99g
> ram.
>
> Only on the new HP, when they try to print they get an
> import error;
> File win32ui.pyc line 12, in 
> File win32ui.pyc, line 10, in _load
> ImportError: DLL load failed:  The specified module
> could not be found.
>
> It turns out that the E2200 processor is 64 bit
> architecture.
>
> What are my options?
>
> I've run DependecyWalker,
> They are using Win XP Service Pack 2
>
>
>
> jim=on-linux
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Centralized logging server...

2008-12-05 Thread skip

Sam> I've been playing with the python logging module.  I'd like all of
Sam> these applications to write their logs to the same place in order
Sam> to make analysis easier.

Sam> Any ideas on best practices?

Perhaps use logging.handlers.SysLogHandler?

Sam> What are my options for a syslog server to receive the messages?
Sam> Rsyslog looks like it would be good.  Anyone know anything else?

If you're running on a Unix system of any type you should have syslog by
default.  You shouldn't need to install anything.

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


Re: slow Python 3.0 write performance?

2008-12-05 Thread Istvan Albert
On Dec 5, 3:06 pm, [EMAIL PROTECTED] wrote:

> It should get faster over time.  It will get faster over a shorter period of
> time if people contribute patches.

I see, thanks for the clarification.

I will make the point though that this makes python 3.0 unsuited for
anyone who has to process data. One could live with slowdowns of say
20-50 percent, to get the goodies that 3.0 offers, but when a process
that takes 1 second suddenly starts to take 10, it is makes the
situation untenable.

best,

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


Re: RELEASED Python 3.0 final

2008-12-05 Thread Fernando H. Sanches
On Dec 4, 5:45 pm, Andreas Waldenburger <[EMAIL PROTECTED]> wrote:
> On Thu, 4 Dec 2008 11:52:38 -0600 [EMAIL PROTECTED] wrote:
>
>
>
> >     >>> As you have probably guessed: nothing changed here.
> >     >>> Also see:http://www.python.org/dev/peps/pep-0666/
>
> >     >> What? Do you mean it's possible to mix tabs and spaces still?
> >     >> Why?
>
> >     Daniel> Why not?
>
> > Because it has historically been a source of errors in a mixed
> > development environment (people using text editors with different tab
> > stops).  Better to not allow them to be mixed.
>
> Whenever has it been a pythonic ideal to "not allow" stuff? You get
> warnings. Everything else is up to you.
>
> /W
>
> --
> My real email address is constructed by swapping the domain with the
> recipient (local part).

Python has "not allowed stuff" for a long time.

For example, it disallows statements in lambdas.

"Disallowing" is not bad. Disallowing bad practices (like mixing tabs
and spaces) is actually good!

I agree that the tab/space thing should be changed. Would it be too
hard to make the parser see if the indentation is consistent in the
whole file? This is a annoying source of problems, specially since you
can't tell a whitespace from a tab just looking at it.

And I personally disliked most of the changes (specially the ones on
map and reduce). I hope functional programming doesn't get even more
hindered in future releases, because I believe these changes only made
Python weaker.

Well, anyway, congratulations for everyone for Python 3 release. Some
of the changes were a real improvement (like the Unicode sources). And
I hope that, in the end, these changes help making Python a better
language.
--
http://mail.python.org/mailman/listinfo/python-list


Re: slow Python 3.0 write performance?

2008-12-05 Thread skip

Istvan> Could someone run the code below on both Python 2.5 and 3.0 For
Istvan> me (on Windows) it runs over 7 times slower with Python 3.0

...

I/O was completely rewritten for Python 3.0.  Stdio is no longer used.  At
the moment I believe much of the io subsystem is still implemented in
Python.  Note these comments in io.py:

# New I/O library conforming to PEP 3116.

# This is a prototype; hopefully eventually some of this will be
# reimplemented in C.

It should get faster over time.  It will get faster over a shorter period of
time if people contribute patches.

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


Centralized logging server...

2008-12-05 Thread Sam
Hi...

I'm working with a small team writing a bunch of python applications
that communicate via xml/http in a somewhat restful way.  :)  They are
running on about half a dozen computers.  We'll probably be scaling
that to a lot more computers soon.

I've been playing with the python logging module.  I'd like all of
these applications to write their logs to the same place in order to
make analysis easier.

Any ideas on best practices?

What are my options for a syslog server to receive the messages?
Rsyslog looks like it would be good.  Anyone know anything else?

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


Problems running on hp duo Pentium R processor

2008-12-05 Thread jim-on-linux
Python help,

In September I wrote:
I have a number of clients running a program built
with python 2.5.  One has just purchased an HP with
a duo core Pentium R processor E2200,  2.2G with .99g 
ram.

Only on the new HP, when they try to print they get an
import error;
File win32ui.pyc line 12, in 
File win32ui.pyc, line 10, in _load
ImportError: DLL load failed:  The specified module
could not be found.

It turns out that the E2200 processor is 64 bit 
architecture.  

What are my options?

I've run DependecyWalker, 
They are using Win XP Service Pack 2



jim=on-linux




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


Re: slow Python 3.0 write performance?

2008-12-05 Thread Bruno Desthuilliers

Istvan Albert a écrit :

Could someone run the code below on both Python 2.5 and 3.0

For me (on Windows) it runs over 7 times slower with Python 3.0


Already covered, I think:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/9046eee09137c657#



import time

lo, hi, step = 10**5, 10**6, 10**5

# writes increasingly more lines to a file
for N in range(lo, hi, step):
fp = open('foodata.txt', 'wt')
start = time.time()
for i in range( N ):
fp.write( '%s\n' % i)
fp.close()
stop = time.time()
print ( "%s\t%s" % (N, stop-start) )




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


Re: pytz and timezone specialists

2008-12-05 Thread Ned Deily
In article 
<[EMAIL PROTECTED]>,
 manatlan <[EMAIL PROTECTED]> wrote:
> Here is a really simple code :
> ---
> from datetime import datetime
> from pytz import timezone
> 
> tz=timezone("Europe/Paris")
> 
> d=datetime(2008,12,12,19,00,00,tzinfo=tz)
> print d.isoformat()
> 
> d=datetime.now(tz)
> print d.isoformat()
> ---
> when I run it, it displays (according current time ;-):
> 
> 2008-12-12T19:00:00+00:09
> 2008-12-05T19:15:38.135467+01:00
> 
> The Europe/Paris timezone is GMT+1 ... the second date seems to be
> right (+01:00 at the end)
> 
> But why the first date ends with "+00:09" ?!? it should be +01:00 ...
> no ?!
> Where's the bug ?!? (sure : it's me ;-) ... but i don't understand
> this simple thing)

>>> tz = timezone("Europe/Paris")
>>> d = tz.localize(datetime(2008,12,12,19,00,00))
>>> print d.isoformat()
2008-12-12T19:00:00+01:00



"This library only supports two ways of building a localized time. The 
first is to use the .localize() method provided by the pytz library. 
This is used to localize a naive datetime (datetime with no timezone 
information).  ... Unfortunately using the tzinfo argument of the 
standard datetime constructors ''does not work'' with pytz for many 
timezones."

-- 
 Ned Deily,
 [EMAIL PROTECTED]

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


Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread Aaron Brady
On Dec 5, 4:32 am, Lawrence D'Oliveiro <[EMAIL PROTECTED]
central.gen.new_zealand> wrote:
> The code people write is probably a direct reflection of their thinking
> processes: For example, slow, plodding, one step at a time, incapable of
> imaginative leaps, versus those who operate directly on larger patterns at
> once...

That distinction operates indirectly on smaller patterns.

There are two types of people.  Those who can grasp this distinction,
and those who cannot.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread MRAB

Joe Strout wrote:

On Dec 5, 2008, at 11:36 AM, Johannes Bauer wrote:


I suspect that '?' after \n (\u0a00) is indicates not 'question-mark'
but 'uninterpretable as a utf16 character'.  The traceback below
confirms that.  It should be an end-of-file marker and should not be
passed to Python.  I strongly suspect that whatever wrote the file
screwed up the (OS-specific) end-of-file marker.  I have seen this
occasionally on Dos/Windows with ascii byte files, with the same symptom
of reading random garbage pass the end of the file.  Or perhaps
end-of-file does not work right with utf16.


So UTF-16 has an explicit EOF marker within the text?


No, it does not.  I don't know what Terry's thinking of there, but text 
files do not have any EOF marker.  They start at the beginning 
(sometimes including a byte-order mark), and go till the end of the 
file, period.


Text files _do_ sometimes have an EOF marker, such as character 0x1A. It 
can occur in text files in Windows.


I cannot find one in original file, only some kind of starting 
sequence I suppose

(0xfeff).


That's your byte-order mark (BOM).


The last characters of the file are 0x00 0x0d 0x00 0x0a,
simple \r\n line ending.


Sounds like a perfectly normal file to me.

It's hard to imagine, but it looks to me like you've found a bug.


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


Re: slow Python 3.0 write performance?

2008-12-05 Thread Mike Driscoll
On Dec 5, 12:54 pm, Istvan Albert <[EMAIL PROTECTED]> wrote:
> Could someone run the code below on both Python 2.5 and 3.0
>
> For me (on Windows) it runs over 7 times slower with Python 3.0
>
> import time
>
> lo, hi, step = 10**5, 10**6, 10**5
>
> # writes increasingly more lines to a file
> for N in range(lo, hi, step):
>     fp = open('foodata.txt', 'wt')
>     start = time.time()
>     for i in range( N ):
>         fp.write( '%s\n' % i)
>     fp.close()
>     stop = time.time()
>     print ( "%s\t%s" % (N, stop-start) )

Ran on Windows XP virtual machine:

3.0 output:

10  0.88866486
20  1.7963134
30  2.875
40  3.7336758
50  4.71899986267
60  5.59400010109
70  7.0463134
80  7.3126376
90  8.375


2.5.2 output:

10  0.156000137329
20  0.29631335
30  0.64104904
40  0.64104904
50  0.7826485
60  0.952999830246
70  1.1386649
80  1.25
90  1.4213134

Slowness in this exercise is confirmed on Windows XP.

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


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread info
On Dec 5, 3:25 pm, Johannes Bauer <[EMAIL PROTECTED]> wrote:
> Hello group,
>
> I'm having trouble reading a utf-16 encoded file with Python3.0. This is
> my (complete) code:
>
> #!/usr/bin/python3.0
>
> class AddressBook():
>         def __init__(self, filename):
>                 f = open(filename, "r", encoding="utf16")
>                 while True:
>                         line = f.readline()
>                         if line == "": break
>                         print([line[x] for x in range(len(line))])
>                 f.close()
>
> a = AddressBook("2008_11_05_Handy_Backup.txt")
>
> This is the file (only 1 kB, if hosting doesn't work please tell me and
> I'll see if I can put it someplace else):
>
> http://www.file-upload.net/download-1297291/2008_11_05_Handy_Backup.t...
>
> What I get: The file reads file the first few lines. Then, in the last
> line, I get lots of garbage (looking like uninitialized memory):
>
> ['E', 'n', 't', 'r', 'y', '0', '0', 'T', 'e', 'x', 't', ' ', '=', ' ',
> '"', 'A', 'D', 'A', 'C', ' ', 'V', 'e', 'r', 'k', 'e', 'h', 'r', 's',
> 'i', 'n', 'f', 'o', '"', '\u0d00', '\u0a00', '䔀', '渀', '琀', '爀', '礀
> ', '\u3000', '\u3100', '吀', '礀', '瀀', '攀', '\u2000', '㴀', '\u2000',
> '一', '甀', '洀', '戀', '攀', '爀', '䴀', '漀', '戀', '椀', '氀', '攀',
> '\u0d00', '\u0a00', '䔀', '渀', '琀', '爀', '礀', '\u3000', '\u3100', '
> 吀', '攀', '砀', '琀', '\u2000', '㴀', '\u2000', '∀', '⬀', '㐀', '㤀',
> '\u3100', '㜀', '㤀', '㈀', '㈀', '㐀', '㤀', '㤀', '∀', '\u0d00',
> '\u0a00', '\u0d00', '\u0a00', '嬀', '倀', '栀', '漀', '渀', '攀', '倀',
> '䈀', '䬀', '\u3000', '\u3000', '㐀', '崀', '\u0d00', '\u0a00']
>
> Where the line
>
> Entry00Text = "ADAC Verkehrsinfo"\r\n
>
> is actually the only thing the line contains, Python makes the rest up.
>
> The actual file is much longer and contains private numbers, so I
> truncated them away. When I let python process the original file, it
> dies with another error:
>
> Traceback (most recent call last):
>   File "./modify.py", line 12, in 
>     a = AddressBook("2008_11_05_Handy_Backup.txt")
>   File "./modify.py", line 7, in __init__
>     line = f.readline()
>   File "/usr/local/lib/python3.0/io.py", line 1807, in readline
>     while self._read_chunk():
>   File "/usr/local/lib/python3.0/io.py", line 1556, in _read_chunk
>     self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
>   File "/usr/local/lib/python3.0/io.py", line 1293, in decode
>     output = self.decoder.decode(input, final=final)
>   File "/usr/local/lib/python3.0/codecs.py", line 300, in decode
>     (result, consumed) = self._buffer_decode(data, self.errors, final)
>   File "/usr/local/lib/python3.0/encodings/utf_16.py", line 69, in
> _buffer_decode
>     return self.decoder(input, self.errors, final)
> UnicodeDecodeError: 'utf16' codec can't decode bytes in position 74-75:
> illegal encoding
>
> With the place where it dies being exactly the place where it outputs
> the weird garbage in the shortened file. I guess it runs over some page
> boundary here or something?
>
> Kind regards,
> Johannes
>
> --
> "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
> verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
>          -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
>                          <[EMAIL PROTECTED]>

2 problems: endianness and trailing zer byte.
This works for me:

class AddressBook():
def __init__(self, filename):
f = open(filename, "r", encoding="utf_16_be", newline="\r\n")
while True:
line = f.readline()
if len(line) == 0:
break
print (line.replace("\r\n",""))
f.close()


a = AddressBook("2008_11_05_Handy_Backup2.txt")

Please note the filename: I modified your file by dropping the
trailing zer byte
--
http://mail.python.org/mailman/listinfo/python-list


Re: Overwrite single line of file

2008-12-05 Thread MRAB

[EMAIL PROTECTED] wrote:

Hi,

I have about 900 text files (about 2 GB of data) and I need to make
some very specific changes to the last line of each file.  I'm
wondering if there is a way to just overwrite the last line of a file
or replace the spots I want (I even know the position of the
characters I need to replace).

I know how to open files and read the contents and then write
everything out again after making the changes, but is there a way to
replace just the last line without having to completely rewrite each
file after making the changes?


f = open(path, "r+")
f.seek(start_of_last_line)
f.write(new_line) # Assuming that new_line ends with "\n"
f.truncate() # In case the new line is shorter than what it's replacing
f.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Joe Strout

On Dec 5, 2008, at 11:36 AM, Johannes Bauer wrote:


I suspect that '?' after \n (\u0a00) is indicates not 'question-mark'
but 'uninterpretable as a utf16 character'.  The traceback below
confirms that.  It should be an end-of-file marker and should not be
passed to Python.  I strongly suspect that whatever wrote the file
screwed up the (OS-specific) end-of-file marker.  I have seen this
occasionally on Dos/Windows with ascii byte files, with the same  
symptom

of reading random garbage pass the end of the file.  Or perhaps
end-of-file does not work right with utf16.


So UTF-16 has an explicit EOF marker within the text?


No, it does not.  I don't know what Terry's thinking of there, but  
text files do not have any EOF marker.  They start at the beginning  
(sometimes including a byte-order mark), and go till the end of the  
file, period.


I cannot find one in original file, only some kind of starting  
sequence I suppose

(0xfeff).


That's your byte-order mark (BOM).


The last characters of the file are 0x00 0x0d 0x00 0x0a,
simple \r\n line ending.


Sounds like a perfectly normal file to me.

It's hard to imagine, but it looks to me like you've found a bug.

Best,
- Joe

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


Re: slow Python 3.0 write performance?

2008-12-05 Thread Benjamin Kaplan
On Fri, Dec 5, 2008 at 1:54 PM, Istvan Albert <[EMAIL PROTECTED]>wrote:

> Could someone run the code below on both Python 2.5 and 3.0
>
> For me (on Windows) it runs over 7 times slower with Python 3.0
>
> import time
>
> lo, hi, step = 10**5, 10**6, 10**5
>
> # writes increasingly more lines to a file
> for N in range(lo, hi, step):
>fp = open('foodata.txt', 'wt')
>start = time.time()
>for i in range( N ):
>fp.write( '%s\n' % i)
>fp.close()
>stop = time.time()
>print ( "%s\t%s" % (N, stop-start) )
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

This bug was already found.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9046eee09137c657#
--
http://mail.python.org/mailman/listinfo/python-list


slow Python 3.0 write performance?

2008-12-05 Thread Istvan Albert
Could someone run the code below on both Python 2.5 and 3.0

For me (on Windows) it runs over 7 times slower with Python 3.0

import time

lo, hi, step = 10**5, 10**6, 10**5

# writes increasingly more lines to a file
for N in range(lo, hi, step):
fp = open('foodata.txt', 'wt')
start = time.time()
for i in range( N ):
fp.write( '%s\n' % i)
fp.close()
stop = time.time()
print ( "%s\t%s" % (N, stop-start) )



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


Overwrite single line of file

2008-12-05 Thread chrispoliquin
Hi,

I have about 900 text files (about 2 GB of data) and I need to make
some very specific changes to the last line of each file.  I'm
wondering if there is a way to just overwrite the last line of a file
or replace the spots I want (I even know the position of the
characters I need to replace).

I know how to open files and read the contents and then write
everything out again after making the changes, but is there a way to
replace just the last line without having to completely rewrite each
file after making the changes?

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


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Johannes Bauer
Terry Reedy schrieb:
> Johannes Bauer wrote:
>> Hello group,
>>
>> I'm having trouble reading a utf-16 encoded file with Python3.0. This is
>> my (complete) code:
> 
> what OS.  This is often critical when you have a problem interacting
> with the OS.

It's a 64-bit Linux, currently running:

Linux joeserver 2.6.20-skas3-v9-pre9 #4 SMP PREEMPT Wed Dec 3 18:34:49
CET 2008 x86_64 Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz GenuineIntel GNU/Linux

Kernel, however, 2.6.26.1 yields the same problem.

>> Entry00Text = "ADAC Verkehrsinfo"\r\n
> 
> From \r\n I guess Windows.  Correct?

Well, not really. The file was created with gammu, a Linux opensource
tool to extract a phonebook off cell phones. However, gammu seems to
generate those Windows-CRLF lineendings.

> I suspect that '?' after \n (\u0a00) is indicates not 'question-mark'
> but 'uninterpretable as a utf16 character'.  The traceback below
> confirms that.  It should be an end-of-file marker and should not be
> passed to Python.  I strongly suspect that whatever wrote the file
> screwed up the (OS-specific) end-of-file marker.  I have seen this
> occasionally on Dos/Windows with ascii byte files, with the same symptom
> of reading random garbage pass the end of the file.  Or perhaps
> end-of-file does not work right with utf16.

So UTF-16 has an explicit EOF marker within the text? I cannot find one
in original file, only some kind of starting sequence I suppose
(0xfeff). The last characters of the file are 0x00 0x0d 0x00 0x0a,
simple \r\n line ending.

>> is actually the only thing the line contains, Python makes the rest up.
> 
> No it does not.  It echoes what the OS gives it with system calls, which
> is randon garbage to the end of the disk block.

Could it not be, as Richard suggested, that there's an off-by-one?

> Try open with explicit 'rt' and 'rb' modes and see what happens.  Text
> mode should be default, but then \r should be deleted.

rt:

[...]
['[', 'P', 'h', 'o', 'n', 'e', 'P', 'B', 'K', '0', '0', '3', ']', '\n']
['L', 'o', 'c', 'a', 't', 'i', 'o', 'n', ' ', '=', ' ', '0', '0', '3', '\n']
['E', 'n', 't', 'r', 'y', '0', '0', 'T', 'y', 'p', 'e', ' ', '=', ' ',
'N', 'a', 'm', 'e', '\n']
Traceback (most recent call last):
  File "./modify.py", line 12, in 
a = AddressBook("2008_11_05_Handy_Backup.txt")
  File "./modify.py", line 7, in __init__
line = f.readline()
  File "/usr/local/lib/python3.0/io.py", line 1807, in readline
while self._read_chunk():
  File "/usr/local/lib/python3.0/io.py", line 1556, in _read_chunk
self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
  File "/usr/local/lib/python3.0/io.py", line 1293, in decode
output = self.decoder.decode(input, final=final)
  File "/usr/local/lib/python3.0/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
  File "/usr/local/lib/python3.0/encodings/utf_16.py", line 69, in
_buffer_decode
return self.decoder(input, self.errors, final)
UnicodeDecodeError: 'utf16' codec can't decode bytes in position 74-75:
illegal encoding

rb works, as it doesn't take an encoding parameter.

> Malformed EOF more likely.

Could you please elaborate?

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list


pytz and timezone specialists

2008-12-05 Thread manatlan
Here is a really simple code :
---
from datetime import datetime
from pytz import timezone

tz=timezone("Europe/Paris")

d=datetime(2008,12,12,19,00,00,tzinfo=tz)
print d.isoformat()

d=datetime.now(tz)
print d.isoformat()
---
when I run it, it displays (according current time ;-):

2008-12-12T19:00:00+00:09
2008-12-05T19:15:38.135467+01:00

The Europe/Paris timezone is GMT+1 ... the second date seems to be
right (+01:00 at the end)

But why the first date ends with "+00:09" ?!? it should be +01:00 ...
no ?!
Where's the bug ?!? (sure : it's me ;-) ... but i don't understand
this simple thing)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Terry Reedy

Johannes Bauer wrote:

Hello group,

I'm having trouble reading a utf-16 encoded file with Python3.0. This is
my (complete) code:


what OS.  This is often critical when you have a problem interacting 
with the OS.



#!/usr/bin/python3.0

class AddressBook():
def __init__(self, filename):
f = open(filename, "r", encoding="utf16")
while True:
line = f.readline()
if line == "": break
print([line[x] for x in range(len(line))])
f.close()

a = AddressBook("2008_11_05_Handy_Backup.txt")

This is the file (only 1 kB, if hosting doesn't work please tell me and
I'll see if I can put it someplace else):

http://www.file-upload.net/download-1297291/2008_11_05_Handy_Backup.txt.gz.html

What I get: The file reads file the first few lines. Then, in the last
line, I get lots of garbage (looking like uninitialized memory):

['E', 'n', 't', 'r', 'y', '0', '0', 'T', 'e', 'x', 't', ' ', '=', ' ',
'"', 'A', 'D', 'A', 'C', ' ', 'V', 'e', 'r', 'k', 'e', 'h', 'r', 's',
'i', 'n', 'f', 'o', '"', '\u0d00', '\u0a00', '䔀', '渀', '琀', '爀', '礀
', '\u3000', '\u3100', '吀', '礀', '瀀', '攀', '\u2000', '㴀', '\u2000',
'一', '甀', '洀', '戀', '攀', '爀', '䴀', '漀', '戀', '椀', '氀', '攀',
'\u0d00', '\u0a00', '䔀', '渀', '琀', '爀', '礀', '\u3000', '\u3100', '
吀', '攀', '砀', '琀', '\u2000', '㴀', '\u2000', '∀', '⬀', '㐀', '㤀',
'\u3100', '㜀', '㤀', '㈀', '㈀', '㐀', '㤀', '㤀', '∀', '\u0d00',
'\u0a00', '\u0d00', '\u0a00', '嬀', '倀', '栀', '漀', '渀', '攀', '倀',
'䈀', '䬀', '\u3000', '\u3000', '㐀', '崀', '\u0d00', '\u0a00']

Where the line

Entry00Text = "ADAC Verkehrsinfo"\r\n


From \r\n I guess Windows.  Correct?

I suspect that '?' after \n (\u0a00) is indicates not 'question-mark' 
but 'uninterpretable as a utf16 character'.  The traceback below 
confirms that.  It should be an end-of-file marker and should not be 
passed to Python.  I strongly suspect that whatever wrote the file 
screwed up the (OS-specific) end-of-file marker.  I have seen this 
occasionally on Dos/Windows with ascii byte files, with the same symptom 
of reading random garbage pass the end of the file.  Or perhaps 
end-of-file does not work right with utf16.



is actually the only thing the line contains, Python makes the rest up.


No it does not.  It echoes what the OS gives it with system calls, which 
is randon garbage to the end of the disk block.


Try open with explicit 'rt' and 'rb' modes and see what happens.  Text 
mode should be default, but then \r should be deleted.



The actual file is much longer and contains private numbers, so I
truncated them away. When I let python process the original file, it
dies with another error:

Traceback (most recent call last):
  File "./modify.py", line 12, in 
a = AddressBook("2008_11_05_Handy_Backup.txt")
  File "./modify.py", line 7, in __init__
line = f.readline()
  File "/usr/local/lib/python3.0/io.py", line 1807, in readline
while self._read_chunk():
  File "/usr/local/lib/python3.0/io.py", line 1556, in _read_chunk
self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
  File "/usr/local/lib/python3.0/io.py", line 1293, in decode
output = self.decoder.decode(input, final=final)
  File "/usr/local/lib/python3.0/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
  File "/usr/local/lib/python3.0/encodings/utf_16.py", line 69, in
_buffer_decode
return self.decoder(input, self.errors, final)
UnicodeDecodeError: 'utf16' codec can't decode bytes in position 74-75:
illegal encoding

With the place where it dies being exactly the place where it outputs
the weird garbage in the shortened file. I guess it runs over some page
boundary here or something?


Malformed EOF more likely.

Terry Jan Reedy

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


Re: RELEASED Python 3.0 final

2008-12-05 Thread Terry Reedy

[EMAIL PROTECTED] wrote:

Andreas Waldenburger:

Whenever has it been a pythonic ideal to "not allow" stuff? You get
warnings. Everything else is up to you.


It's a strong source for bugs, especially for newbies, that I have
hoped to see removed from Python3 (my first request of this was years
ago). I was nearly sure to see this wart removed from Python3, and now
I hear it's presents still. I don't understand why they haven't fixed
it.


Did you or someone fine a specific rejection of disallowing mixture in 
3.0, or did no one specifically suggest it and offer to make the change?


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


Re: dict subclass and pickle bug (?)

2008-12-05 Thread Terry Reedy

James Stroud wrote:

James Stroud wrote:

Hello All,

I subclassed dict and overrode __setitem__. When instances are 
unpickled, the __setstate__ is not called before the keys are assigned 
via __setitem__ in the unpickling protocol.


I googled a bit and found that this a bug filed in 2003:


It is an 'issue' reporting a possibly unexpected side-effect of protocol 
working as designed and documented.  Possibly a design flaw, but not a 
bug in the narrow sense (in spite of the url of the issue tracker).



http://bugs.python.org/issue826897

It is still "open" with "normal" priority.


Here is the ugly "fix" I'm basically going to have to live with, it seems:

class DictPlus(dict):
  def __init__(self, *args, **kwargs):
self.extra_thing = ExtraThingClass()
dict.__init__(self, *args, **kwargs)
  def __setitem__(self, k, v):
try:
  do_something_with(self.extra_thing, k, v)
except AttributeError:
  self.extra_thing = ExtraThingClass()
  do_something_with(self.extra_thing, k, v)
dict.__setitem__(self, k, v)
  def __setstate__(self, adict):
pass


I took the liberty of adding this to the issue.


I can't imagine this bug has survived


because there is no bug to fix.  I have suggesting closing.

Terry Jan Reedy

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


etree, minidom unicode

2008-12-05 Thread n00b
hi,

i have a feew questions concnering unicode and utf-8 handling and
would appreciate any insights.

1) i got a xml document, utf-8, encoded and been trying to use etree
to parse and then commit to mysql db. using etree, everything i've
been extracting is return as a string except ascii char > 127, which
come back as a unicode.  using minidom on the same document, however,
i get all unicode. is there a way to 'force' etree to use unicode?

2) i'm using mysql 5.x on * nix (mac, linux) and after much messing
around, have things
working, i.e. i have unicode from the (minidom) parser, set all mysql
and mysqldb attributes, i get  back from mysql. is that expected
behavior? #!/usr/bin/env python
# -*- coding: UTF-8 -*-
from xml.dom import minidom
import MySQLdb
import codecs
from onix_model_01 import *

db = MySQLdb.connect(host='localhost', user='root', passwd='',
db='lsi', charset='utf8')
cur = db.cursor()
#cur.execute('SET NAMES utf8')
#cur.execute('SET CHARACTER SET utf8')
cur.execute('SET character_set_connection=utf8')
cur.execute('SET character_set_server=utf8')
cur.execute('''SHOW VARIABLES LIKE 'char%'; ''')
...
>>> print 'firstname, lastname types from xml: ', type(a.firstname), 
>>> type(a.lastname)
>>>firstname, lastname types from xml:   
...
>>>cur.execute('''INSERT INTO encoding_test VALUES(null, %s, %s)''', 
>>>(a.firstname, a.lastname))

... now i'm getting the results back from mysql

>>>cur.execute('SELECT * FROM encoding_test')
>>>query = cur.fetchall()
>>>for q in query:
print q, type(q[0]), type(q[1]), type(q[2])
print q[1], q[2]
print repr(q[1]), repr(q[2])

>>>(24L, 'Bront\xc3\xab', 'Charlotte ')   
>>> Brontë Charlotte
>>>'Bront\xc3\xab' 'Charlotte '

so everything is coming back as it should, but i though i would get
the sql results back as unicode not str ... what gives?

finally, from a utf-8 perspective, is there any advantage using innodb
over myisam?

thx


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


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Richard Brodie

"J Kenneth King" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> It probably means what it says: that the input file contains characters
> it cannot read using the specified encoding.

That was my first thought. However it appears that there is an off by one
error somewhere in the intersection of line ending/codec processing.
Half way through the codec starts byte-flipping characters. 


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


Re: RELEASED Python 3.0 final

2008-12-05 Thread Peter Pearson
On Thu, 4 Dec 2008 15:49:46 -0600, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> It's more than warnings.  With properly crafted
> combinations of spaces and tabs you can get code which
> looks like it has a certain indentation to the human
> observer but which looks like it has different indentation
> (and thus different semantics) to the byte code compiler.
> There is often no warning.

Fascinating.  Has anybody developed demo code that looks,
during code review, as if it prints a Snoopy calendar, but
really, during execution, emails your password file to
Minsk?  The security implications are intriguing. What's the
most underhanded thing anybody has seen done?

-- 
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Shed Skin 0.0.30, an experimental (restricted-)Python-to-C++ Compiler

2008-12-05 Thread Scott David Daniels

Mark Dufour wrote:

Hi all,

I have just released version 0.0.30 of Shed Skin, ...


Normally, including a link is a good idea.

--Scott David Daniels
[EMAIL PROTECTED]

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


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Johannes Bauer
J Kenneth King schrieb:

> It probably means what it says: that the input file contains characters
> it cannot read using the specified encoding.

No, it doesn't. The file is just fine, just as the example.

> Are you generating the file from python using a file object with the
> same encoding? If not, then you might want to look at your input data
> and find a way to deal with the exception.

I did. The file is fine. Could you try out the example?

Regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list


Re: pretty strange behavior of "strip" FORGET THE LAST ONE

2008-12-05 Thread Scott David Daniels

Guy Doune wrote:



Guy Doune a écrit :

Ok, didn't show the whole problem...

I will read the doc anyway, but why "questions.html" keep it "t"??

>>> test=['03.html', '06.html', 'questions.html', '04.html', 
'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html']

>>> test[4]
'toc.html'
>>> test[4].strip('.html')
'oc'
>>> test[2].strip('.html')
'questions'


Well, why does '  a b c  '.strip() leave two spaces?

--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread J Kenneth King
Johannes Bauer <[EMAIL PROTECTED]> writes:

> Traceback (most recent call last):
>   File "./modify.py", line 12, in 
> a = AddressBook("2008_11_05_Handy_Backup.txt")
>   File "./modify.py", line 7, in __init__
> line = f.readline()
>   File "/usr/local/lib/python3.0/io.py", line 1807, in readline
> while self._read_chunk():
>   File "/usr/local/lib/python3.0/io.py", line 1556, in _read_chunk
> self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
>   File "/usr/local/lib/python3.0/io.py", line 1293, in decode
> output = self.decoder.decode(input, final=final)
>   File "/usr/local/lib/python3.0/codecs.py", line 300, in decode
> (result, consumed) = self._buffer_decode(data, self.errors, final)
>   File "/usr/local/lib/python3.0/encodings/utf_16.py", line 69, in
> _buffer_decode
> return self.decoder(input, self.errors, final)
> UnicodeDecodeError: 'utf16' codec can't decode bytes in position 74-75:
> illegal encoding

It probably means what it says: that the input file contains characters
it cannot read using the specified encoding.

Are you generating the file from python using a file object with the
same encoding? If not, then you might want to look at your input data
and find a way to deal with the exception.
--
http://mail.python.org/mailman/listinfo/python-list


Whitespace in Python (3) [was: RELEASED Python 3.0 final]

2008-12-05 Thread Andreas Waldenburger
On Fri, 5 Dec 2008 07:46:02 -0800 (PST) [EMAIL PROTECTED] wrote:

> Andreas Waldenburger:
> > My point is: If you mix tabs and spaces in a way that breaks code,
> > you'll find out pretty easily, because your program will not work.
> 
> - Most newbies don't know that.
> - Sometimes it may produce wrong results.
> - And even if you are an expert when you go changing a little a source
> code that mixes tabs and spaces you usually break the code.
> Is this enough for you?
> 
No.

While you are right on all accounts, forcing uniformity would still
interfere with (some) people's coding styles, "wrong" as they might be.
Python is not Gnome.

Maybe having Python issue warnings for inconsistent whitespace per
default might be a good idea. But that's about as far as I would go.


/W

-- 
My real email address is constructed by swapping the domain with the
recipient (local part).
--
http://mail.python.org/mailman/listinfo/python-list


Re: simplest way to strip a comment from the end of a line?

2008-12-05 Thread eric
On Dec 5, 11:56 am, eric <[EMAIL PROTECTED]> wrote:
> On Dec 4, 11:35 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
> > Yowza!  My eyes glaze over when I see re's like "r'(?m)^(?P.*?
> > (".*?".*?)*)(?:#.*?)?$"!
>
> yeah, I know ... :( ( I love complicated regexp ... it's like a puzzle
> game for me)
>
>
>
> > from pyparsing import quotedString, Suppress, restOfLine
>
> > comment = Suppress('#' + restOfLine)
> > recognizer = quotedString | comment
>
> > for t in tests:
> >     print t
> >     print recognizer.transformString(t)
> >     print
>
> > Prints:
>
> > this is a test 1
> > this is a test 1
>
> > this is a test 2 #with a comment
> > this is a test 2
>
> > this is a '#gnarlier' test #with a comment
> > this is a '#gnarlier' test
>
> > this is a "#gnarlier" test #with a comment
> > this is a "#gnarlier" test
>
> > For some added fun, add a parse action to quoted strings, to know when
> > we've really done something interesting:
>
> > def detectGnarliness(tokens):
> >     if '#' in tokens[0]:
> >         print "Ooooh, how gnarly! ->", tokens[0]
> > quotedString.setParseAction(detectGnarliness)
>
> > Now our output becomes:
>
> > this is a test 1
> > this is a test 1
>
> > this is a test 2 #with a comment
> > this is a test 2
>
> > this is a '#gnarlier' test #with a comment
> > Ooooh, how gnarly! -> '#gnarlier'
> > this is a '#gnarlier' test
>
> > this is a "#gnarlier" test #with a comment
> > Ooooh, how gnarly! -> "#gnarlier"
> > this is a "#gnarlier" test
>
> > -- Paul
>
> I didn't knew pyparsing. It's amazing ! thanks


maybe you'd rather replace:
splitter = re.compile(r'(?m)^(?P.*?(".*?".*?)*)(?:#.*?)?$')

by

from reO import *
quote = characters('"') # defining the characters used as string sep
sharp= string('#') # defining the sharp symbol
data = ALL + repeat( group( quote + ALL + quote + ALL ) )# ALL
( "ALL" ALL)*
comment = group(sharp+ALL+END_LINE) # the comment itself

xp = flag(MULTILINE=True) + START_LINE + group( data, name="data") +
if_exists(comment)

splitter = xp.compile()



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


Re: pretty strange behavior of "strip"

2008-12-05 Thread rdmurray

On Fri, 5 Dec 2008 at 07:54, Mark Tolonen wrote:

> >  import re
> >  re.split('[,.]','blah,blah.blah')

['blah', 'blah', 'blah']


Thank you.  Somehow it never occurred to me that I could use that
kind of pattern that way.  I guess my brain just doesn't think
in regexes very well :)

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


Re: Don't you just love writing this sort of thing :)

2008-12-05 Thread George Sakkis
On Dec 5, 8:06 am, Marco Mariani <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano wrote:
> > Gosh Lawrence, do tell, which category do YOU fall into?
>
> I suppose a mix-up between a cowbody (or Fonzie) coder and a troll.

Naah.. more likely an (ex?) Lisper/Schemer.
--
http://mail.python.org/mailman/listinfo/python-list


Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread Michael Mabin
Warren, weren't you aware that Python.org is now a church.  So you can never
live up to the standards of the Pythonista high priests.  You can only ask a
question or submit your comment then cower, hoping the pythonista high
priests don't beat you with clubs for heresy.

;)



2008/12/4 Warren DeLano <[EMAIL PROTECTED]>

> > From: Ben Finney <[EMAIL PROTECTED]<[EMAIL PROTECTED]>
> >
> >
> > "Chris Mellon" <[EMAIL PROTECTED]> writes:
> >
> > > Peculiarities in usenet resulted in this discussion having several
> > > threads and I missed some messages before I wrote this email.
> >
> > I'll put this more bluntly: Warren's messages to date
> > egregiously break the flow of discussion.
> >
> > Warren, in the interest of sane discussion in these forums, please:
> >
> > * preserve attribution lines on quoted material so we can see who
> >   wrote what.
> >
> > * use the convention of ?New subject (was: Old subject)? when you
> >   change the ?Subject? field of a message.
> >
> > * switch to a client that preserves threading in messages you send,
> >   i.e. that properly constructs the ?References? and ?In-Reply-To?
> >   fields.
> >
> > General advice good for everyone, of course, but particularly
> > apropos to this reply. Any one of the above is detrimental to
> > omit; striking on all three makes a discussion almost
> > impossible to follow. (Thank you, though, for avoiding the
> > worse habit of top posting!)
>
> Thank so much for the suggestions Ben.  Sorry that I am personally
> unable to live up to your high standards, but it is nevertheless an
> honor to partipicate in such a helpful and mutually respectful community
> mailing list!
>
> Warren
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: pretty strange behavior of "strip"

2008-12-05 Thread MRAB

[EMAIL PROTECTED] wrote:

On Thu, 4 Dec 2008 at 20:54, Terry Reedy wrote:

 'toc.html'
> > >  test[4].strip('.html')
 'oc'

 Can't figure out what is going on, really.


What I can't figure out is why, when people cannot figure out what is 
going on with a function (or methods in this case), they do not look 
it up the doc. (If you are an exception and did, what confused you?)  
Can you enlighten me?


I'm a little embarrassed to admit this, since I've been using python for
many years, but until I read these posts I did not understand how strip
used its string argument, and I _have_ read the docs.  I can't tell you
what confused the OP, but I can tell you what confused me.

I have often wished that in 'split' I could specify a _set_ of characters
on which the string would be split, in the same way the default list
of whitespace characters causes a split where any one (or more) of
them appears.  But instead the string argument is a multi-character
separator.  (Which is sometimes useful and I wouldn't want to lose the
ability to specify a multi-character separator!)

My first experience in using the string argument was with split, so when I
ended up using it with strip, by analogy I assumed that the string passed
to strip would also be a multi-character string, and thus stripped only
if the whole string appeared exactly.  Reading the documentation did
not trigger me reconsider that assumption.  I guess I'm just lucky that
I haven't run into any bugs (but I think I've used the string argument
to strip only once or twice in my career).

It would be lovely if both the split and strip methods would have a
second string argument that would use the string in the opposite sense
(as a set for split, as a sequence match for strip).

In the meantime the docs could be clarified by replacing:

the characters in the string will be stripped

with

all occurrences of any of the characters in the string will be
stripped

--RDM

PS: the OP might want to look at th os.path.splitext function.

>
If I had thought about it early enough I could have suggested that in 
Python 3 split() and strip() should accept either a string or a set of 
strings. It's still possible to extend split() in the future, but 
changing the behaviour of strip() with a string argument would break 
existing code, something which might have been OK as part of changes in 
Python 3. Unfortunately I don't have access to the time machine! :-)

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


Re: Mathematica 7 compares to other languages

2008-12-05 Thread Xah Lee
On Dec 4, 6:09 pm, [EMAIL PROTECTED] wrote:
> For the interested, with MMA 6, on a Pentium 4 3.8Ghz:
>
> The code that Jon posted:
>
> Timing[Export["image-jon.pgm", [EMAIL PROTECTED]@Main[2, 100, 4]]]
> {80.565, "image-jon.pgm"}
>
> The code that Xah posted:
>
> Timing[Export["image-xah.pgm", [EMAIL PROTECTED]@Main[2, 100, 4.]]]
> {42.3186, "image-xah.pgm"}
>
> So Xah's code is about twice as fast as Jon's code, on my computer.
>
> The resulting files were identical (and both looked like pure white
> images; I thought they'd be interesting!).

The result is not pure white images. They are ray traced spheres
stacked in some recursive way. Here's the output in both my and jon's
version: http://xahlee.org/xx/image.pgm

also, note that Mathematica 6 has the function Normalize builtin,
which is used in Jon's code deeply in the core. Normalize is not in
Mathematica 4, so i had to code it myself, in this line: “norm=Function
[#/Sqrt@(Plus@@(#^2))];”. This possibly slow down my result a lot. You
might want to replace any call of “norm” in my program by the builtin
Normalize.

Also, each version of Mathematica has more optimizations. So, that
might explain why on v4 the speed factor is ~0.2 on my machine while
in v6 you see ~0.5.

My machine is OS X 10.4.x, PPC G5 1.9 Ghz.

-

let me take the opportunity to explain some high powered construct of
Mathematica.

Let's say for example, we want to write a function that takes a vector
(of linear algebra), and return a vector in the same direction but
with length 1. In linear algebar terminology, the new vector is called
the “normalized” vector of the original.

For those of you who don't know linear algebra but knows coding, this
means, we want a function whose input is a list of 3 elements say
{x,y,z}, and output is also a list of 3 elements, say {a,b,c}, with
the condition that

a = x/Sqrt[x^2+y^2+z^2]
b = y/Sqrt[x^2+y^2+z^2]
c = z/Sqrt[x^2+y^2+z^2]

For much of the history of Mathematica, normalize is not a builtin
function. It was introduced in v6, released sometimes in 2007. See
bottom of:
http://reference.wolfram.com/mathematica/ref/Normalize.html

Now, suppose our task is to write this function. In my code, you see
it is:

norm=Function[#/Sqrt@(Plus@@(#^2))];

let me explain how it is so succinct.

Mathematica's syntax support what's called FullForm, which is
basically a fully nested notation like lisp's. In fact, the
Mathematica compiler works with FullForm. The FullForm is not
something internal. A programer can type his code that way if he so
pleases.

in FullForm, the above expression is this:
 Set[ norm, Function[ Times[Slot[1], Power[ Sqrt[ Apply[ Plus, Power
[ Slot[1], 2 ] ] ], -1 ] ] ]

Now, in this
norm=Function[#/Sqrt@(Plus@@(#^2))]

The “Function” is your lisper's “lambda”. The “#” is the formal
parameter. So, in the outset we set “norm” to be a pure function.

Now, note that the “#” is not just a number, but can be any argument,
including vector of the form {x,y,z}. So, we see here that math
operations are applied to list entities directly. For example, in
Mathematica, {3,4,5}/2 returns {3/2,2,5/2} and {3,4,5}^2 returns
{9,16,25}.

In typical lang such as python, including lisp, you would have to map
the operation into each lisp elements instead.

The [EMAIL PROTECTED] is a syntax shortcut for “Sqrt[...]”, and the
“Plus@@...” is a syntax shortcut for “Apply[Plus, ...]”, which is
lisp's “funcall”. So, taking the above all together, the code for
“norm” given above is _syntactically equivalent_ to this:

norm=Function[ #/Sqrt[ Apply[Plus, #^2] ]]

this means, square the vector, add them together, take the square
root, then have the original vector divide it.

The “#” is in fact a syntax shortcut for “Slot[1]”, meaning the first
formal parameter. The “=” is in fact a syntax shortcut for “Set[]”.
The “^” is a shortcut for “Power[]”, and the “/” is a shortcut for
“Power[..., -1]”. Putting all these today, you can see how the code is
syntactically equivalent to the above nested FullFolm.

Note, that the “norm” as defined above works for any dimentional
vectors, i.e. list of any length.

In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
you'll have 50 or hundreds lines.

For more detail on syntax, see:

• The Concepts and Confusions of Prefix, Infix, Postfix and Fully
Nested Notations
  http://xahlee.org/UnixResource_dir/writ/notations.html

  Xah
∑ http://xahlee.org/

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


Re: pretty strange behavior of "strip"

2008-12-05 Thread Mark Tolonen


<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

On Thu, 4 Dec 2008 at 20:54, Terry Reedy wrote:

[snip]

I have often wished that in 'split' I could specify a _set_ of characters
on which the string would be split, in the same way the default list
of whitespace characters causes a split where any one (or more) of
them appears.  But instead the string argument is a multi-character
separator.  (Which is sometimes useful and I wouldn't want to lose the
ability to specify a multi-character separator!)



import re
re.split('[,.]','blah,blah.blah')

['blah', 'blah', 'blah']

-Mark


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


  1   2   >