How to distribute C/C++ python extension module on Linux?

2008-12-05 Thread Allen
I have build an extension module PyRPC.so (why not be libPyRPC.so?).
The PyRPC.so uses API in libRPCPacker.so.
How to distribute the PyRPC.so?

I just put PyRPC.so and libRPCPacker.so in the same folder.
And under this folder, run python.
It tells PyRPC module cannot find a method in libRPCPacker.so.
--
http://mail.python.org/mailman/listinfo/python-list


Python C API

2008-12-05 Thread googler . 1 . webmaster
Hi :)

I have a main() function of my app which intializes the Python
Interpreter and some other stuff. When I am finished I call:

PyGILState state = PyGILState_Ensure()
//call PyRun_String()
PyGILStateRelease(state);

The first question is, I found out the API contains other commands lik
PyEval_AcquireLock(). I don't really understand if I have to use them
too, could anyone explain? Thanks.

Okay, back to topic. In PyRun_String() I call a wrapped function. This
wrapped function does some internal calculations and takes a pointer
to another function which is called in another thread while it
calculates the stuff.

void MyProgressbar(Real p, void* hook) // this function wil be called
in another thread
{
PyGILState_STATE gilstate = PyGILState_Ensure();

PyObject* func = (PyObject*)hook;
//do some python stuff

PyGILState_Release(gilstate)
}

PyObject *pyMyFunction(PyObject *pSelf, PyObject *args, PyObject
*keywords)
{
static char *kwlist[] = {"hook", NULL};

PyObject  *hook=NULL;

if (!PyArg_ParseTupleAndKeywords(args, keywords, "O!", kwlist,
&PyFunction_Type, &hook))
return NULL;

LONG ok = MyFunction(myprogress, hook);   //hook is a pointer which
is passed to the threaded function.

Py_RETURN_INT(ok);
}

I want to do the same in Python. I want to pass a reference of a
function to the function which is called from the other thread. But it
stops (not crash) here: PyGILState_STATE gilstate = PyGILState_Ensure
();



What can I do? Thank you very much.
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-12-05 Thread Duncan Booth
Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:

> In message <[EMAIL PROTECTED]>, Duncan Booth wrote:
> 
>> Have you ever considered trying to write readable code instead?
>> 
>> (I must admit I haven't checked whether GZipFile works with the 'with'
>> statement...
> 
> That's why I prefer writing _correct_ code instead.

Good idea, but the mess you posted is going to be virtually untestable 
whereas splitting it up into small testable functions will make it much 
easier for you to actually get somewhere near your goal of correct code.

BTW, by trimming half of my sentence you changed its meaning significantly. 
You implied that I gave an example without caring whether it could work 
whereas the other half of the sentence pointed out that if GZipFile 
requires it you may need to add a single function call to my code.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to distribute C/C++ python extension module on Linux?

2008-12-05 Thread David Cournapeau
On Fri, Dec 5, 2008 at 5:09 PM, Allen <[EMAIL PROTECTED]> wrote:
> I have build an extension module PyRPC.so (why not be libPyRPC.so?).
> The PyRPC.so uses API in libRPCPacker.so.
> How to distribute the PyRPC.so?

The simple answer is you can't. Depending on the distribution, the
python interpreter is built differently in an ABI-incompatible way. As
on other platforms, the binary also depends on the python version.

The only real solution is to package it using the native package
manager of the distributions you are interested in supporting (rpm,
deb, etc...); you still have to build the package for all different
combinations, though. Something like the opensuse build service can
help in those situations.

> I just put PyRPC.so and libRPCPacker.so in the same folder.
> And under this folder, run python.
> It tells PyRPC module cannot find a method in libRPCPacker.so.

We need more informations on how you built the extension, and about
the exact error message. Note also that on Linux, by default,
libraries are not looked in the current directory, so it is likely
that PyRPC.so does not look in the libRPCPaker.so in your current
directory, but from another path (you can check how the loader
resolves libraries paths with the command ldd).

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


Re: ANN: New Book: Programming in Python 3

2008-12-05 Thread Dotan Cohen
2008/12/5 Mark Summerfield <[EMAIL PROTECTED]>:
> I don't think the book is due in Europe until the end of January, but
> could take longer for elsewhere. (Of course Israel is in Europe
> according to the Eurovision Song Contest, so you might get lucky:)
>

Yes, we are in the unique geographical and political position to be in
Europe when it suits us, in Asia when it suits us, and to be in the
Middle East when it suits us!

Thanks!

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list


Re: CONNECTION TIMED OUT ERROR using urllib2

2008-12-05 Thread svalbard colaco
Hi

I set my http_proxy and now
i get the following error

*urllib2.HTTPError: HTTP Error 403: Forbidden ( The ISA Server denied the
specified Uniform Resource Locator (URL).  *

what other variables have to be set ?

Regards,
sv

On Fri, Dec 5, 2008 at 12:47 PM, rishi pathak <[EMAIL PROTECTED]>wrote:

> Before executing script do
> export http_proxy=http://:/
>
>
>
> On Fri, Dec 5, 2008 at 12:06 PM, svalbard colaco <[EMAIL PROTECTED]
> > wrote:
>
>> Hi rishi,
>>
>> Thanks for ur reply,
>> yes i set the following enviroment variables (FC6 platform)
>> http_proxy,http_user,http_password
>>
>> But i get the same error; Can u tell me which other  variables i need to
>> set or am i going wrong in the syntax of these
>> variables?
>>
>> Regards
>> sv
>>
>>
>> On Fri, Dec 5, 2008 at 11:57 AM, rishi pathak <[EMAIL PROTECTED]>wrote:
>>
>>> Are you sitting behind a proxy. If so then you have to set proxy for http
>>>
>>> On Fri, Dec 5, 2008 at 11:47 AM, svalbard colaco <
>>> [EMAIL PROTECTED]> wrote:
>>>
 Hi all

 I have written a small code snippet to open a URL using urllib2 to open
 a web page , my python version is 2.4 but i get an urlopen error called
 connection timed out

 The following is the code snippet

 *import urllib2

 f = urllib2.urlopen('http://www.google.com/')
 print f.read(100)*


 where as the same url http://www.google.com/ works through my browser.

 The following is the back trace :

 File "test_url.py", line 3, in ?
 f = urllib2.urlopen('http://www.google.com/')
   File "/usr/lib/python2.4/urllib2.py", line 130, in urlopen
 return _opener.open(url, data)
   File "/usr/lib/python2.4/urllib2.py", line 358, in open
 response = self._open(req, data)
   File "/usr/lib/python2.4/urllib2.py", line 376, in _open
 '_open', req)
   File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
 result = func(*args)
   File "/usr/lib/python2.4/urllib2.py", line 1021, in http_open
 return self.do_open(httplib.HTTPConnection, req)
   File "/usr/lib/python2.4/urllib2.py", line 996, in do_open
 raise URLError(err)
 *urllib2.URLError: 


 Any pointers in this regard will be of great help.

 Thanking you'll in advance.

 Regards,
 sv



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


>>>
>>>
>>> --
>>> Regards--
>>> Rishi Pathak
>>> Pune-Maharastra
>>>
>>
>>
>
>
> --
> Regards--
> Rishi Pathak
> Pune-Maharastra
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python C API

2008-12-05 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> The first question is, I found out the API contains other commands lik
> PyEval_AcquireLock(). I don't really understand if I have to use them
> too, could anyone explain? Thanks.

That's unrelated. The GIL is special in that it has its own handling functions.


> void MyProgressbar(Real p, void* hook) // this function wil be called
> in another thread
> {
>   PyGILState_STATE gilstate = PyGILState_Ensure();
> 
>   PyObject* func = (PyObject*)hook;
>   //do some python stuff
> 
>   PyGILState_Release(gilstate)
> }
> 
> PyObject *pyMyFunction(PyObject *pSelf, PyObject *args,   PyObject
> *keywords)
> {
>   static char *kwlist[] = {"hook", NULL};
> 
>   PyObject  *hook=NULL;
> 
>   if (!PyArg_ParseTupleAndKeywords(args, keywords, "O!", kwlist,
> &PyFunction_Type, &hook))
>   return NULL;

You have to release the GIL around the following function call, so that the
thread above can acuire it while you wait for the function to return in
this thread here (which I assume you do).

>   LONG ok = MyFunction(myprogress, hook);   //hook is a pointer which
> is passed to the threaded function.

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


Re: Python C API

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

thats a very interesting point and good to know.  I have to release
the GIL but how do I do?
In this case i need PyEval_AcquireLock and PyEval_ReleaseLock?


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


dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud

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:

http://bugs.python.org/issue826897

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

Am I missing something? Is there a workaround for this bug that makes 
fixing it pointless or has it just fallen through the cracks for the 
last 5 years?


Here is an example:

class DictPlus(dict):
  def __init__(self, *args, **kwargs):
self.extra_thing = ExtraThingClass()
dict.__init__(self, *args, **kwargs)
  def __setitem__(self, k, v):
do_something_with(self.extra_thing, k, v)
dict.__setitem__(self, k, v)

Upon unpickling, the error would be:

AttributeError: 'DictPlus' object has no attribute 'extra_thing'


I'm still using python 2.5.1.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com
--
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 13:27:35 +1300, Lawrence D'Oliveiro wrote:
> 
>> In message <[EMAIL PROTECTED]>, Cong
>> Ma wrote:
>> 
>>> The "if ... != None" is not necessary...  "if PatchDatePat.search(f)"
>>> is OK.
>> 
>> I don't do that.
> 
> Perhaps you should?

I prefer using explicitly Boolean values for conditions.
--
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:

> ... stupid formatting ...

withallthedifferenttermsruntogetherintoonelinesoyoudon'tknowwhereoneendsandtheotherbeginsifthat'showyouliketowritecodefinethat'snothowIliketodoit
--
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:

> 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.
--
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]>, Duncan Booth wrote:

> ... but the mess you posted is going to be virtually untestable ...

The "mess" I posted did actually work as written.

> ... whereas splitting it up into small testable functions will make it
> much easier for you to actually get somewhere near your goal of correct
> code. 

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...
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict subclass and pickle bug (?)

2008-12-05 Thread James Stroud

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:

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


This violates this:

  Beautiful is better than ugly.


I can't imagine this bug has survived but I also can't imagine any 
better way to do this without specifying a different protocol, which 
would probably break other pickling I'm doing. I don't feel like finding 
out right now.


Maybe repeal pep 307 ;o)


James


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com
--
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 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
--
http://mail.python.org/mailman/listinfo/python-list


Re: using distutils to cross-compile extensions?

2008-12-05 Thread Paul Boddie
On 5 Des, 00:58, "David Cournapeau" <[EMAIL PROTECTED]> wrote:
>
> The first step for cross compilation would be the ability to build
> python itself wtih different build/host, and that's already non
> trivial.

Now that Python 3.0 is out, perhaps there will be a possibility of one
of the many cross-compilation patches being applied to Python 2.x:

http://bugs.python.org/issue?%40columns=id%2Cactivity%2Ctitle%2Ccreator%2Cassignee%2Cstatus&%40sort=-activity&%40group=priority&%40filter=status&status=-1%2C1%2C3&%40search_text=cross-compile&submit=search+in+open+issues

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


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

2008-12-05 Thread Mark Dufour
Hi all,

I have just released version 0.0.30 of Shed Skin, an experimental
(restricted) Python-to-C++ compiler.

Most importantly, this release adds (efficient) support for
user-defined classes in generated extension modules, which should make
it much easier to integrate compiled code within larger projects. More
specifically, compiled classes can now be instantiated on the CPython
side, and instances can be passed freely between CPython and Shed Skin
without any conversion taking place. (Instances of builtin classes are
still (recursively) copied, though, at the moment..)

Another major improvement was contributed by FFAO: a new 'set'
implementation, directly based on the CPython code. While I haven't
tested it on many benchmarks, it is clear that is now much faster, and
on one benchmark it even outperforms CPython on my system by about
35%.

Other notable changes include complex number support, mapping None to
NULL instead of 0 and printing it as 'None', as well as an important
type inference fix.

With support for user-defined classes in extension modules, it looks
like all the major pieces are now there to do a 0.1 release. The only
thing I'd really like to do before that, is to improve support for the
'os' module. Please let me know if you'd like to help out here!
Hopefully, with many details out of the way, I can have another good
look at type inference for 0.2..


Thanks,
Mark.
-- 
"One of my most productive days was throwing away 1000 lines of code"
- Ken Thompson
--
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 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.



-- 
Steven
--
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 23:32:49 +1300, Lawrence D'Oliveiro wrote:

> In message <[EMAIL PROTECTED]>, Duncan Booth wrote:
> 
>> ... but the mess you posted is going to be virtually untestable ...
> 
> The "mess" I posted did actually work as written.
> 
>> ... whereas splitting it up into small testable functions will make it
>> much easier for you to actually get somewhere near your goal of correct
>> code.
> 
> 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...

Gosh Lawrence, do tell, which category do YOU fall into? 

I'd probably be able to work it out on my own, if not for me being one of 
the plodders incapable of imaginative leaps.


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


Re: Python surpasses Perl in popularity?

2008-12-05 Thread Jorgen Grahn
["Followup-To:" header set to comp.unix.shell.]
On 29 Nov 2008 16:23:49 GMT, Tam Ha <[EMAIL PROTECTED]> wrote:
> Jorgen Grahn <[EMAIL PROTECTED]> wrote: 
>>(I could get away with using Bash in these cases. It has functions, 
>>local variables and so on. Writing portable Bourne shell is not as 
>>much fun.)
>
> Can you explain this?

Sorry for the late answer. No, it's actually what I said:

I could get away with using bash in these cases, so I did it. It was
an in-house application, it had already unknown dependencies to bash,
and to Linux versions of other utilities. If I had asked for time to
modify it to make sure it was portable Bourne shell, people would have
laughed at me.

> Bourne is always more portable than Bash.
> That's why you'll find experienced shell programmers writing everything
> that doesn't absolutely require a bash feature in /bin/sh.  Boot scripts,
> install scripts, etc. should never be written in bash and if where you
> find one using bash you can be sure a Linux-only newbie has written it.

Sure, nothing controversial about that.  I don't argue that people
should use bash features in any random script they write. I just noted
that if you decide to use it, it's a pretty useful language. Probably
more useful than Python in my case, where most of the work was about
starting and managing external commands and pipelines.

> For one there are too many versions of bash, for two it is not installed
> by default on every Unix/Linux OS, for three it has poor backwards
> (and forwards) compatibility.

Worse compatibility than Perl or Python?  The Bourne shell timescale
is probably impressive, but often you aren't interested in decades.

> It is also found at different places on
> the path.

Surely that applies to almost any interpreter, like perl and python.
It's a problem (on the non-free Unixes at least) but if you let it be
the deciding factor, you could use no scripting language except
/bin/sh and awk.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
--
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 23:16:08 +1300, Lawrence D'Oliveiro wrote:

> In message <[EMAIL PROTECTED]>, Steven D'Aprano
> wrote:
> 
>> On Fri, 05 Dec 2008 13:27:35 +1300, Lawrence D'Oliveiro wrote:
>> 
>>> In message <[EMAIL PROTECTED]>, Cong
>>> Ma wrote:
>>> 
 The "if ... != None" is not necessary...  "if PatchDatePat.search(f)"
 is OK.
>>> 
>>> I don't do that.
>> 
>> Perhaps you should?
> 
> I prefer using explicitly Boolean values for conditions.

Perhaps you do, but there's no evidence of such in your post. 

bool(PatchDatePat.search(f) != None)

would be an "explicitly Boolean value". What you posted was an 
*implicitly* Boolean value, and not even guaranteed to be Boolean, as 
__ne__ can return any object it likes.

And yes, such a call to bool would be pointless.


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


i use the urllib question

2008-12-05 Thread Huytason
i use pthon 3.0 today

python code:
import urllib.request

then use PyRun_StringFlag to run it.

get this 

it's a bug?
--
http://mail.python.org/mailman/listinfo/python-list


Re: generating a liste of characters

2008-12-05 Thread Mark Tolonen


"Yves Dorfsman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Is there any built in way to generate a list of characters, something
along the line of range('a'-'z') ?

Right now I am using:

 chars  = [ chr(l)  for l in range(0x30, 0x3a) ] # 0 - 9
 chars += [ chr(l)  for l in range(0x41, 0x5b) ] # A - Z
 chars += [ chr(l)  for l in range(0x61, 0x7b) ] # a - z

Is there a better, more straight forward way of doing that ?


Writing a helper function reduces code repetition and improves readability:

   def crange(startch,endch):
   '''Return a list of characters from startch to endch, inclusive.'''
   return [chr(c) for c in xrange(ord(startch),ord(endch)+1)]

   chars = crange('0','9') + crange('A','Z') + crange('a','z')

-Mark


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


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

2008-12-05 Thread Marco Mariani

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.

His programs have an inner poetry that we're obviously too stupid to 
understand.


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


Re: generating a liste of characters

2008-12-05 Thread bearophileHUGS
Mark Tolonen:
> Writing a helper function reduces code repetition and improves readability:
>     def crange(startch,endch):
>         '''Return a list of characters from startch to endch, inclusive.'''
>         return [chr(c) for c in xrange(ord(startch),ord(endch)+1)]

In Python ranges are open on the right, so I name cinterval such
function.

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


Re: RELEASED Python 2.6.1

2008-12-05 Thread malkarouri
On 5 Dec, 05:07, Barry Warsaw <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Hot on the heals of Python 3.0 comes the Python 2.6.1 bug-fix  
> release.

Nice work. Thanks.

> Source tarballs and Windows installers can be downloaded from the  
> Python 2.6.1 page

I note that OS X installers have not been released (yet). I don't know
if you plan to, but I think it is important to release installers that
do not suffer from the bug http://bugs.python.org/issue4017 which
renders Tkinter unusable in the 2.6.0 release and which (I believe) is
a build issue. Can we expect such an updated release?

Many thanks,

Muhammad Alkarouri
--
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 Paul Boddie
On 5 Des, 12:24, "Mark Dufour" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have just released version 0.0.30 of Shed Skin, an experimental
> (restricted) Python-to-C++ compiler.

I think Mark forgot to post some links. ;-)

http://shed-skin.blogspot.com/
http://code.google.com/p/shedskin/

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


Re: generating a liste of characters

2008-12-05 Thread Mark Tolonen


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

Mark Tolonen:
Writing a helper function reduces code repetition and improves 
readability:

def crange(startch,endch):
'''Return a list of characters from startch to endch, inclusive.'''
return [chr(c) for c in xrange(ord(startch),ord(endch)+1)]


In Python ranges are open on the right, so I name cinterval such
function.


Yes, and that's fine when dealing with integers and slicing, but when 
dealing with characters, it is non-obvious what character to use.  What 
"looks" correct?


  chars = crange('0','9') + crange('A','Z') + crange('a','z') # inclusive

or

  chars = crange('0',':') + crange('A','[') + crange('a','{')  # open right

or if you didn't know the character after the one you actually wanted:

  chars = crange('0',chr(ord('9')+1)) + crange('A',chr(ord('Z')+1)) + 
crange('a',chr(ord('z')+1))  # open right, but messy


-Mark 



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


Re: pretty strange behavior of "strip"

2008-12-05 Thread Guy Doune

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'

Thanks.

Guy

Guy Doune a écrit :

Hi everybody,

Could it be a bug?

Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> test=['03.html', '06.html', 'questions.html', '04.html', 
'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html']

>>> 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'

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

Guy


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


Re: EBCDIC <--> ASCII

2008-12-05 Thread Michael Ströder

[EMAIL PROTECTED] wrote:

On Dec 4, 4:45 pm, Michael Ströder <[EMAIL PROTECTED]> wrote:

[EMAIL PROTECTED] wrote:

I'm having a problem trying to use the codecs package to aid me in
converting some bytes from EBCDIC into ASCII.

Which EBCDIC variant?


sEBCDIC = unicode(sSource, 'cp500', 'ignore')

Are you sure CP500 is the EBCDIC variant for the language you want?

http://www.ietf.org/rfc/rfc1345.txtlists it as:

   &charset IBM500
   &rem source: IBM NLS RM Vol2 SE09-8002-01, March 1990
   &alias CP500
   &alias ebcdic-cp-be
   &alias ebcdic-cp-ch


Obviously I could just knock up a 255 character lookup table and do it
myself, I was just trying to be a little more Pythonic and use that
built in table.

It's pythonic to implement a Unicode codec for unknown character tables.
I've put these two on my web site:

http://www.stroeder.com/pylib/encodings/ebcdicatde.pyhttp://www.stroeder.com/pylib/encodings/cp273.py(needs
 ebcdicatde)


Thanks for the tables, ebcdicatde.py does look more suitable.

My problem appears to be that my source is a byte string. In a
nutshell I need "\x81\x82\x83\xf1\xf2\xf3" to become "abc123" in a
byte string.


Python 2.5.2 (r252:60911, Aug  1 2008, 00:43:38)
>>> import ebcdicatde
>>> "\x81\x82\x83\xf1\xf2\xf3".decode('ebcdic-at-de').encode('ascii')
'abc123'
>>>

Ciao, Michael.
--
http://mail.python.org/mailman/listinfo/python-list


A more pythonic way of writting

2008-12-05 Thread eric
Hi,

I've got this two pieces of code that works together, and fine

def testit():
for vals in [[i&mask==mask for mask in [1<',  flag(*vals)

def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False,
DOTALL=False, UNICODE=False, VERBOSE=False):
vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE, VERBOSE]
filtered = map( lambda m:m[1],filter( lambda m: m[0], zip(vals,
'iLmsux')))
return '?'+''.join( filtered  )

testit()

but I'm not proud of the way it is written. I dont find it very
pythonic.
I have to multiplex (using zip) bool and value, filter using only the
bool, and demultiplex later using map

the first simply parses all the possible combination of 6 boolean
(can't hardly be made simpler)

the second function, should simply return a string based on the
boolean value
i,   L,   m,  s,  u, x,
True, False, False, True, True, False
=  ?isu

that's should take only one line, shouldn't it?

any idea ?

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


Re: generating a liste of characters

2008-12-05 Thread Duncan Booth
"Mark Tolonen" <[EMAIL PROTECTED]> wrote:

><[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> .. 
>>In Python ranges are open on the right, so I name cinterval such
>>function.
> 
> Yes, and that's fine when dealing with integers and slicing, but when 
> dealing with characters, it is non-obvious what character to use. 
> What "looks" correct?
> 
>chars = crange('0','9') + crange('A','Z') + crange('a','z') #
>inclusive 
> 

I think bearophile's point was that you had the parameters correct, 
(specifying 'a' and 'z' makes sense), but the function itself had the wrong 
name. If you call it 'crange' you are implying the wrong behaviour. Call it 
something like 'cinterval' instead.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-12-05 Thread Guy Doune



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'

Thanks.

Guy

Guy Doune a écrit :

Hi everybody,

Could it be a bug?

Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> test=['03.html', '06.html', 'questions.html', '04.html', 
'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html']

>>> 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'

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

Guy




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


Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Johannes Bauer
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.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

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]>
--
http://mail.python.org/mailman/listinfo/python-list


Re: A more pythonic way of writting

2008-12-05 Thread Mark Tolonen


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



def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False,
DOTALL=False, UNICODE=False, VERBOSE=False):
   vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE, VERBOSE]
   filtered = map( lambda m:m[1],filter( lambda m: m[0], 
zip(vals,'iLmsux')))

   return '?'+''.join( filtered  )


   filtered = [c for c,v in zip('iLmsux',vals) if v]

-Mark


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


Re: pretty strange behavior of "strip"

2008-12-05 Thread Mark Tolonen


"Guy Doune" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

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'


It doesn't strip the character set from the whole string, it strips it from 
the beginning and end of the string only.  If it encounters a character that 
isn't in the set, it stops.  Does this make it more clear?



'aabdabcdccb'.strip('cba')

'dabcd'

-Mark




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


mod_python and files directory

2008-12-05 Thread mete bilgin
Hi all,
I try to make a websevice with python and mod_python. İ try to make a po
files, but i can not reach them in the page. When i ask the page like "
os.listdir('.') " but i want to get files directory, what can i do? sorry
for my bad describe of that. Thanks a lot...
--
http://mail.python.org/mailman/listinfo/python-list


ftp retrlines with re...

2008-12-05 Thread isabellkna...@googlemail.com
Hey!
Ive been working on an application quite some time now and i wanted to
include something to let the user load a new version. i therefore
tried to include this here:

from ftplib import FTP
import string,re


 def handleDownload(block):
processfile.write(block)
print ".",

 def load_new_version(old_version):
host='host.bla'
user='usr_ftp_76512'
password='45mhBLl3lXRX.332'
account='usr_ftp_76512'
download=''
directory = 'htdocs'
server = FTP(host)
server.login(user,password,account)
server.cwd(directory)
filelist=server.retrlines('LIST')
#okay this works :logged into the ftpserver,changed dir and now have a
#string that tells the files like this:
#-rw-r--r--   1 usr_ftp_76512 ftpgroup14454 Dec  5 14:10
Pict5.2.2.jpg
#-rw-r--r--   1 usr_ftp_76512 ftpgroup16174 Dec  5 12:37 Picture
3.jpg
#-rw-r--r--   1 usr_ftp_76512 ftpgroup14139 Dec  5 12:38 Picture
6.jpg
#-rw-r--r--   1 usr_ftp_76512 ftpgroup42713 Dec  5 12:38 Picture
7.jpg
#226 Transfer complete.
print filelist
files=re.findall(' .{2,20}[.][a-z]{3,3}', filelist,re.I|re.S)
#the dot means every char, because of the flag re.S
# re.I ignores case
#{2,20} this means 2 to twenty of the char that is before it
#heres the problem... if you copy the output and put it into a string
he
#finds all the files with findall, but not inside here... and i dont
get why
#help:(
print files
for file in files:

number=re.findall('pict([0-9])[.]([0-9])[.]?
([0-9]?)',file,re.I)
version=100*int(number[0][0])+ 10*int(number[0][1])+ int(number
[0][2])
if version >old_version:
print version
print old_version
old_version=version
download=file
if download :
   processfile = open(download, 'wb')
   server.retrbinary('RETR ' + download, handleDownload)
   processfile.close()
   server.close()
   return True
else:
   server.close()
   return False
load_new_version(201)

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


Small problem with Psyco

2008-12-05 Thread bearophileHUGS
I post it here because I am using a Psyco version that was compiled by
people here.
I am using Python 2.6.1, on Win, with Psyco (1, 6, 0, 'final', 0).

This minimized code:

from psyco.classes import psyobj
class Bar(psyobj):
def __init__(self, baz):
pass
b = Bar(0)

Produces:
C:\...\test.py:5: DeprecationWarning: object.__new__() takes no
parameters
  b = Bar(0)

Bye,
bearophile
--
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 Fri, 2008-12-05 at 02:10 +0100, "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.
> 
> > or for the default
> > source code filename to change to '.py3' or something.
> 
> Such a proposal would be rejected. In a few years from now, Python 2
> will be gone, and we would be stuck with an ugly file extension
> (similar to how \windows\system is now an empty directory, and
> \windows\system32 actually contains the 64-bit binaries on x64)-
> 
> Regards,
> Martin

I have to agree with Terry; installing the released python-3.0.msi
results in an executable named 'python.exe' in the filesystem.  I have
not built it yet, but I assume the *NIX package results in a 'python'
executable file.

For a machine that runs existing Python 2.x applications, what should be
in the PATH variable?

For *NIX machines, will 'python' be placed into /usr/bin?  If so, then
the Python scripts that start out with a shebang like the following will
have difficulty.

#!/usr/bin/python
#!/usr/bin/env python

Has there been any guidance issued?

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


Re: RELEASED Python 3.0 final

2008-12-05 Thread bearophileHUGS
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.

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).

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


Re: "as" keyword woes

2008-12-05 Thread Andreas Waldenburger
On 04 Dec 2008 22:29:41 GMT Steven D'Aprano
<[EMAIL PROTECTED]> wrote:

> Thank goodness we don't have to program in verbose, explicit English!
Then you'll HATE Inform 7:

http://en.wikipedia.org/wiki/Inform_7#Example_game_2

:)
/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: Small problem with Psyco

2008-12-05 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> I post it here because I am using a Psyco version that was compiled by
> people here.
> I am using Python 2.6.1, on Win, with Psyco (1, 6, 0, 'final', 0).
> 
> This minimized code:
> 
> from psyco.classes import psyobj
> class Bar(psyobj):
> def __init__(self, baz):
> pass
> b = Bar(0)
> 
> Produces:
> C:\...\test.py:5: DeprecationWarning: object.__new__() takes no
> parameters
>   b = Bar(0)

I noticed that, too, when using Cython to compile a Python class that
inherits from object into an extension type that inherits from its C
equivalent at the C level. I assume that psyco does something similar here.

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


Re: pretty strange behavior of "strip"

2008-12-05 Thread rdmurray

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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A more pythonic way of writting

2008-12-05 Thread Gerard flanagan

eric wrote:

Hi,

I've got this two pieces of code that works together, and fine

def testit():
for vals in [[i&mask==mask for mask in [1<',  flag(*vals)

def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False,
DOTALL=False, UNICODE=False, VERBOSE=False):
vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE, VERBOSE]
filtered = map( lambda m:m[1],filter( lambda m: m[0], zip(vals,
'iLmsux')))
return '?'+''.join( filtered  )

testit()

but I'm not proud of the way it is written. I dont find it very
pythonic.
I have to multiplex (using zip) bool and value, filter using only the
bool, and demultiplex later using map

the first simply parses all the possible combination of 6 boolean
(can't hardly be made simpler)

the second function, should simply return a string based on the
boolean value
i,   L,   m,  s,  u, x,
True, False, False, True, True, False
=  ?isu

that's should take only one line, shouldn't it?

any idea ?

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



#after Paul Rubin (c.l.py)
def hypercube(ndims):
if ndims == 0:
yield ()
return
for h in 1, 0:
for y in hypercube(ndims-1):
yield (h,)+y

#after Mark Tolonen
for item in hypercube(6):
print ''.join(c for c,v in zip('iLmsux', item) if v)


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


Re: RELEASED Python 3.0 final

2008-12-05 Thread Andreas Waldenburger
On Thu, 4 Dec 2008 15:49:46 -0600 [EMAIL PROTECTED] wrote:

> 
> Andreas> Whenever has it been a pythonic ideal to "not allow"
> Andreas> stuff? You get warnings. Everything else is up to you.
> 
> 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.
> 
I just looked at "python --help", it seems that there is no warning per
default.

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. It's
your choice, and I think it's pretty nice that Python lets you
choose. After all, some people are of the "indentation for structure,
spaces for alignment" faction. Why make their life harder?

/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: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread Andreas Waldenburger
On Thu, 4 Dec 2008 16:17:20 -0800 "Warren DeLano" <[EMAIL PROTECTED]>
wrote:

> 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!
> 
You seem mildly irritated. Please don't be. Clearly you are not
"personally unable" to "live up to" anybody's standards. His advice was
a good one because there is a merrit to standards compliance. Just
because you didn't know the standards (or rather "best
practices") doesn't mean you're in any way deficient.

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

regards
/W


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


[no subject]

2008-12-05 Thread Fred

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


Re: A more pythonic way of writting

2008-12-05 Thread eric
On Dec 5, 3:44 pm, "Mark Tolonen" <[EMAIL PROTECTED]> wrote:
> "eric" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False,
> > DOTALL=False, UNICODE=False, VERBOSE=False):
> >    vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE, VERBOSE]
> >    filtered = map( lambda m:m[1],filter( lambda m: m[0],
> > zip(vals,'iLmsux')))
> >    return '?'+''.join( filtered  )
>
>     filtered = [c for c,v in zip('iLmsux',vals) if v]
>
> -Mark

thank you very much ! great !

I can't get used to this late 'if' syntax !

@Gerard
nice hypercube function. But I'll keep with my implementation :
I like to believe that the less the 'debug pointer' stands in the
python code, the fastest the code is (or is potentially)

I keep thinking that
def hypercube(ndims) :
for i in range(1

Re: RELEASED Python 3.0 final

2008-12-05 Thread bearophileHUGS
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?

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


Re: Switching windows in PyQT

2008-12-05 Thread ShanMayne
On Dec 3, 8:12 pm, Дамјан Георгиевски <[EMAIL PROTECTED]> wrote:
> > I am new to PyQT and GUI programming in general. What tutorials I have
> > found are relatively clear on standard operations within a single
> > window (QtGui.QWidget or QtGui.QMainWindow). Exiting this window exits
> > the overall application.
>
> > How would I switch between windows, that is close one and open
> > another, within a running application. I would imagine this to be a
> > standard feature often coded.
>
> most often you don't close windows but hide them.
>
> Still, the app object has a property quitOnLastWindowClosed that you can
> set to false.
>
> --
> дамјан (http://softver.org.mk/damjan/)
>
> Q: What's tiny and yellow and very, very, dangerous?
> A: A canary with the super-user password.



Thanks, that does sound like a more accessible way of doing it. Would
know where I could find full application code (as an example to me) so
that I can get to grips with the details of it all?

Good stuff, merry be
--
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


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 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: 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: 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: 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: 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


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: 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


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 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: 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: 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: 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


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: 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


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: 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


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 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


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


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


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


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: 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 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: 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 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: 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: 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: 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


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


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


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


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 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: 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: 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: 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: 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: 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


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: 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


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: 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.


 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: 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: 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: 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


  1   2   >