Re: magic names in python

2007-06-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, per9000 wrote:

> I just used a search engine a little on this topic and I found no
> comprehensive list of magic names in python.

They are usually mentioned in parts of the docs where the relevant
functionality is explained.  For example in `Special method names`_ in the
reference manual.

And of course all covered in the reference manual are under
`_ (underscore)`_ in its index.  In the `library reference's index`_
you'll find some more that are used by modules.

.. _`_ (underscore)`: http://docs.python.org/ref/genindex.html#letter-_
.. _library reference's index: http://docs.python.org/lib/genindex.html
.. _Special method names: http://docs.python.org/ref/specialnames.html

>  * are these lists complete or can magic names be added over time (to
> the python "core")?

Magic names can be added over time.  For example the ``with`` statement
introduced `__enter__()` and `__exit__()` in Python 2.5.  And some special
names may even change were the docs say so or if they aren't mentioned at
all in the docs.

>  * are magic names the same in different python versions?

Yes.

> So another question emerges:
>  * is the use of magic names encouraged and/or part of good coding
> practice.

What do you mean by "use"?  Implement them to override behavior?  Yes,
that's their purpose.  Invent new magic names?  No of course not, they are
special for a reason:  preventing name clashes with the user's names.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: example: 40286 -> 68204

2007-06-04 Thread Shihpin
Thanks Steven, I will try to decipher that.

Shihpin


On 6 4 ,   1:45, [EMAIL PROTECTED] wrote:
> On Jun 3, 5:23 pm, Shihpin <[EMAIL PROTECTED]> wrote:
> > Is there a fuction that reverse the digits of a number?
> One can use int, str and a slice:
>
> print int(str(40286)[::-1])
>
> --
> Hope this helps,
> Steven


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


Re: magic names in python

2007-06-04 Thread Josiah Carlson
per9000 wrote:
> So my questions:
>  * is there a comprehensive list of magic names in python (so far i
> know of __init__ and __repr__)?
>  * are these lists complete or can magic names be added over time (to
> the python "core")?
>  * are magic names the same in different python versions?

I don't believe that there is a full list of all __magic__ methods.  The 
operator module has a fairly extensive listing of functions that call 
such methods, but I know that some have been left out.

Among those that I remember off the top of my head while typing this 
message...

__init__
__new__
__str__
__repr__
__len__
__nonzero__
__hash__
__cmp__ (__eq__, __ne__, __lt__, __gt__, __le__, __ge__)
__getattr__
__setattr__
__delattr__
__getitem__
__setitem__
__delitem__
__iter__
__neg__
__not__

There's also the not-magic named, but still somewhat magic .next() 
method on iterators/generators.

  - Josiah

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


Re: Dict naming, global vs local imports, etc. [was Re: *Naming Conventions*]

2007-06-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, George Sakkis
wrote:

> While we're at it, although it's not strictly a naming convention
> issue I still waste brain cycles on where to put the import statements
> that are used only once or twice in a module. Should
> (1) all imports be at the global scope at the top of the module, or
> (2) be imported in the function or method they are actually used ?
> 
> […]
> 
> Reasons for (2)
> ---
> - Point of import closer to point of use; easy to notice if a given
> import is not used any more after refactoring.

`pylint` reports unused imported names.  I don't follow PEP8 only if it's
not possible otherwise.  But cyclic imports are bad anyway.  :-)

And if the import is *really* expensive and only needed in some special
circumstances.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: int vs long

2007-06-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Alex Martelli wrote:

> Paul Rubin  wrote:
> 
>> Dan Bishop <[EMAIL PROTECTED]> writes:
>> > If you ever do, it's trivial to write your own enumerate():
>> > def enumerate(seq):
>> > index = 0
>> > for item in seq:
>> > yield (index, item)
>> > index += 1
>> 
>> That's a heck of a lot slower than the builtin, and if you're running it
>> often enough for sys.maxint to be an issue, you may care about the speed.
> 
> Perhaps itertools.izip(itertools.count(), seq) might be faster (haven't
> timed it, but itertools tends to be quite fast).

I think correct is more important than fast.  `itertools.count()` has the
same issues that `enumerate()`:

>>> from itertools import count
>>> from sys import maxint
>>> c = count(maxint)
>>> c.next()
2147483647
>>> c.next()
-2147483648

What I find most disturbing here, is that it happens silently.  I would
have expected an exception instead of the surprise.

Ciao,
Marc 'BlackJack' Rintsch

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


Re: int vs long

2007-06-04 Thread Peter Otten
Marc 'BlackJack' Rintsch wrote:

> In <[EMAIL PROTECTED]>, Alex Martelli wrote:
> 
>> Paul Rubin  wrote:
>> 
>>> Dan Bishop <[EMAIL PROTECTED]> writes:
>>> > If you ever do, it's trivial to write your own enumerate():
>>> > def enumerate(seq):
>>> > index = 0
>>> > for item in seq:
>>> > yield (index, item)
>>> > index += 1
>>> 
>>> That's a heck of a lot slower than the builtin, and if you're running it
>>> often enough for sys.maxint to be an issue, you may care about the
>>> speed.
>> 
>> Perhaps itertools.izip(itertools.count(), seq) might be faster (haven't
>> timed it, but itertools tends to be quite fast).

This approach is indeed much faster than the hand-crafted generator (10 vs
240% slowdown on my machine compared to the builtin)

> I think correct is more important than fast.  `itertools.count()` has the
> same issues that `enumerate()`:
> 
 from itertools import count
 from sys import maxint
 c = count(maxint)
 c.next()
> 2147483647
 c.next()
> -2147483648
> 
> What I find most disturbing here, is that it happens silently.  I would
> have expected an exception instead of the surprise.

This is fixed in Python2.5:

>>> from itertools import count
>>> import sys
>>> c = count(sys.maxint)
>>> c.next(), c.next()
(2147483647, 2147483648L)

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


Re: int vs long

2007-06-04 Thread Peter Otten
Paul Rubin wrote:

> Dan Bishop <[EMAIL PROTECTED]> writes:
>> If you ever do, it's trivial to write your own enumerate():
>> def enumerate(seq):
>> index = 0
>> for item in seq:
>> yield (index, item)
>> index += 1
> 
> That's a heck of a lot slower than the builtin, and if you're running it
> often enough for sys.maxint to be an issue, you may care about the speed.

Yes, but the overall slowdown is probably still negligable when you are
doing anything useful inside the for loop.

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


Re: magic names in python

2007-06-04 Thread per9000
On Jun 4, 9:11 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, per9000 wrote:
> >
> > [...]
> >
> > So another question emerges:
> >  * is the use of magic names encouraged and/or part of good coding
> > practice.
>
> What do you mean by "use"?  Implement them to override behavior?  Yes,
> that's their purpose.  Invent new magic names?  No of course not, they are
> special for a reason:  preventing name clashes with the user's names.
>

[in my taste: UGLY]
I think of something like this: Perhaps I create a class that works
with a lot of files, and with inheritance new types of files can be
opened and worked with.

When it is time for an instance of this class to die the files need to
be closed - perhaps "right now" and not when it is suitable for the
garbage collector. To facilitate this I create a number of functions
with names like close_*_file (f.x. close_indata_file,
close_outdata_file, close_error_file etc). (compare with [PyTest|
unittest] "test*" names.)

If this class has been inherited to some other class that works with
more than one indata file perhaps we want to magically close all files
that are open by calling all function in this instance that has names
matching "close_*_file".

I would consider this an ugly way of solving it.

[in my taste: NICER]
I'd perhaps add file-handles to some list (and encourage inherited
classes to use this list) and close everything in the list. I would
not use magic wildcard names.

So in other words: Do I need to go to yellow alert, and watch out for
magic names in non-core add-on packages to python? Or should I just
RTFM a little more? (I hate RTFM'ing.)

Live long and prosper,
Per

--

Per Erik Strandberg
home: www.pererikstrandberg.se
work: www.incf.org
also: www.spongswedencare.se

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


Re: Python memory handling

2007-06-04 Thread Frédéric PICA
Greets,

Sorry for my late answer, google groups lost my post...
First, thanks you for your explanations about memory handling in the
os and python.
I've tried with python 2.5 under linux :
For the parsing of a 66 Mb xml file with cElementTree :
When starting python : 2.1 Mb private memory used
import xml.etree.cElementTree as ElementTree #3.4 Mb used
et=ElementTree.parse('otherdata.xml') #218.6 Mb used
del et #43.3 Mb used
et=ElementTree.parse('otherdata.xml') #218.6 Mb used
del et #60.6 Mb used
et=ElementTree.parse('otherdata.xml') #218.6 Mb used
del et #54.1 Mb used
et=ElementTree.parse('otherdata.xml') #218.6 Mb used
del et #54.1 Mb used
et=ElementTree.parse('otherdata.xml') #218.6 Mb used
del et #54.1 Mb used

Why does I have a such erratic memory freeing ?
I've tried the same test many time with a new interpreter and I've got
43.3 Mb after the first free and 54.1 Mb after the others.
If there is a memory pool limit in list ans dict, why can't I goes
back to 43.3 or 54.1 Mb all the times ?

I've tried using readlines():
When starting python : 2.1 Mb private memory used
f=open('otherdata.xml') #2.2 Mb used
data=f.readlines() #113 Mb used
del data #2.7 Mb used
f.seek(0) #2.7 Mb used
data=f.readlines() #113 Mb used
del data #2.7 Mb used

That time I have a good memory handling (for my definition of memory
handling)

So is there a problem with cElementTree ?

I've done a last test with ElementTree :
When starting python : 2.1 Mb private memory used
import xml.etree.ElementTree as ElementTree #3.2 Mb used
et=ElementTree.parse('otherdata.xml') #211.4 Mb used (but very
slow :p)
del et #21.4 Mb used
et=ElementTree.parse('otherdata.xml') #211.4 Mb used
del et #29.8 Mb used

So why does I have such differences in memory freeing ? Only due to
fragmentation ?

Anyway, python 2.5 has a better memory handling than 2.4, but still
not perfect for me.
I think I've not really understood the problem with the use of malloc
(fragmentation,...)

Thanks for your help
Regards,
FP

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


Re: Strange behavior in Windows

2007-06-04 Thread Gabriel Genellina
En Sat, 02 Jun 2007 15:31:40 -0300, Jakob Svavar Bjarnason  
<[EMAIL PROTECTED]> escribió:

> I have been trying to switch to Python from other languages such as Perl  
> and now I have a newbie question.
>
> I have been trying to run a setup script to install a python library. To  
> do that I need to run "c:> python setup.py install" but the strange  
> thing is is that when it runs the command:
>
 from distutils import log
>
> I get the error ONLY while in cmd. If I run this from the interactive  
> shell that comes with IDLE it works. But if I go into the interactive  
> shell in the Windows shell cmd then I get:
>
> ImportError: cannot import log

Maybe you have two different versions installed? Try this and post what  
you get:

import sys
print sys.version
print sys.executable
print sys.path

both from inside IDLE and the console.
Python versions earlier than 2.3 did not have a distutils.log module.

-- 
Gabriel Genellina

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


Re: subexpressions (OT: math)

2007-06-04 Thread stef
Gary Herron wrote:
> Wildemar Wildenburger wrote:
>   
>> Gary Herron wrote:
>>   
>> 
>>> Of course not!  Angles have units, commonly either degrees or radians.
>>>
>>> However, sines and cosines, being ratios of two lengths, are unit-less.
>>>   
>>> 
>>>   
 To understand it: sin() can't have dimensioned argument. It is can't
 to be - sin(meters)
   
 
   
 
>>> No it's sin(radians) or sin(degrees). 
>>>   
>>> 
>>>   
>> NO!
>> The radian is defined as the ratio of an arc of circumfence of a circle 
>> to the radius of the circle and is therefore *dimensionless*. End of story.
>> http://en.wikipedia.org/wiki/Radian  and esp.
>> http://en.wikipedia.org/wiki/Radian#Dimensional_analysis
>>
>> *grunt*
>>   
>> 
> No, not end-of-story.  Neither of us are being precise enough here.  To
> quote from your second link:
> "Although the radian is a unit of measure, it is a dimensionless
> quantity."
>
> But NOTE: Radians and degrees *are* units of measure., however those
> units are dimensionless quantities , i.e., not a length or a time etc.
>
> The arguments to sine and cosine must have an associated unit so you
> know whether to interpret sin(1.2) as sine of an angle measured in
> degrees or radians (or whatever else).
>
> Gary Herron
>
>
>   
Sorry about entering the discussion so late,
and not sure I repeat one of the messages.

But can't we see it this way:
 radians / degrees (which one 360 or 400) are just mathematical 
scaling factors,
 like kilo, mega etc.

If a wheel is turning around at
2*pi*100  [rad /sec]
does something physical change is we leave the radian out
the wheeel is turning at
100  [1/sec]

No it's now called frequency, and has just some different scaling.

SQRT of "rad/sec" ?
Yes, in electronics the noise density is often expressed in   [nV/SQRT(Hz)]

cheers,
Stef Mientki





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


Re: magic names in python

2007-06-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, per9000 wrote:

> On Jun 4, 9:11 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> In <[EMAIL PROTECTED]>, per9000 wrote:
>> >
>> > [...]
>> >
>> > So another question emerges:
>> >  * is the use of magic names encouraged and/or part of good coding
>> > practice.
>>
>> What do you mean by "use"?  Implement them to override behavior?  Yes,
>> that's their purpose.  Invent new magic names?  No of course not, they are
>> special for a reason:  preventing name clashes with the user's names.
>>
> 
> [in my taste: UGLY]
> I think of something like this: Perhaps I create a class that works
> with a lot of files, and with inheritance new types of files can be
> opened and worked with.
> 
> When it is time for an instance of this class to die the files need to
> be closed - perhaps "right now" and not when it is suitable for the
> garbage collector. To facilitate this I create a number of functions
> with names like close_*_file (f.x. close_indata_file,
> close_outdata_file, close_error_file etc). (compare with [PyTest|
> unittest] "test*" names.)
> 
> If this class has been inherited to some other class that works with
> more than one indata file perhaps we want to magically close all files
> that are open by calling all function in this instance that has names
> matching "close_*_file".
> 
> I would consider this an ugly way of solving it.
> 
> [in my taste: NICER]
> I'd perhaps add file-handles to some list (and encourage inherited
> classes to use this list) and close everything in the list. I would
> not use magic wildcard names.
> 
> So in other words: Do I need to go to yellow alert, and watch out for
> magic names in non-core add-on packages to python? Or should I just
> RTFM a little more? (I hate RTFM'ing.)

Now I'm a little confused.  What does this have to do with magic names?  I
thought you are talking about names that start and end with two
underscores (`__magic__`)!?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int vs long

2007-06-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Peter Otten wrote:

> Marc 'BlackJack' Rintsch wrote:
> 
> from itertools import count
> from sys import maxint
> c = count(maxint)
> c.next()
>> 2147483647
> c.next()
>> -2147483648
>> 
>> What I find most disturbing here, is that it happens silently.  I would
>> have expected an exception instead of the surprise.
> 
> This is fixed in Python2.5:
> 
 from itertools import count
 import sys
 c = count(sys.maxint)
 c.next(), c.next()
> (2147483647, 2147483648L)

Hm, my test above was from 2.5!?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a new class on the fly

2007-06-04 Thread Josh West
Alex Martelli wrote:
>
> Thanks for snipping all the actual helpful stuff I posted, it makes SO
> much easier for me to be snide!
>
> You can find a few examples of me demonstrating the subject of your
> interest by searching for my name e.g. on video.google.com; searching
> for my name on Amazon will show some books using similar techniques, and
> searching for my name on groups.google.com will find about 50,000 posts
> many of which exhibit essentially the same approach.  Unfortunately, I
> can't currently offer such courses commercially while staying employed
> as Uber Tech Lead for Google, Inc, but if the monies on offer make it
> worth my while for me to drop million bucks worth of stock options, plus
> a vigorish for my other comp package _and_ the incredible amount of
> happiness I get every day from my job (where I get to interact with
> truly brlliant people, who, if and when they "leave an erroneous snippet
> in", are GRATEFUL to me for pointing it out, rather than RESENTFUL and
> DEFENSIVE), I'll surely consider that most seriously (as long as the
> monies in question are in escrow for my personal reassurance).
>
> Until such conditions should obtain, I'll just have to keep freely
> helping the people who are WORTH helping, and poking sarcastic funs at
> those who prove themselves ot be a waste of oxygen instead.
>
>
> May you have the life you deserve,
I'm new to all this, but I didn't get the impression that sickeningly 
smug self-satisfaction was a "pythonic" characteristic. Let's hope for a 
Waco (cults, siege, bloodbath) style conclusion to the Google story. 
That would be truly (Monty) Pythonic.
> Alex
>   

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


Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote:
> if you are discordant read more :P :
> sine is a dimensionless value.
> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120
> etc.
> you can see that sin can be dimensionless only if x is dimensionless
> too.
>
> I am a professional physicist and a know about what I talk
>
>   
No you don't. I'm a student of physics, and I know better:

First of all, what you have presented here is called the MacLaurin 
series. It is however a special case of the Taylor series, so you are 
correct. I just thought I'd let you know. (Sorry to sound like a bitch 
here, i love smartassing ;))

Let me start by saying that *if* x had a dimension, none of the terms in 
your expansion would have the same dimension. A well well-versed 
physicist's head should, upon seeing such a thing, explode so as to warn 
the other physicists that something is terribly off there. How (ye 
gods!) do you add one metre to one square-metre? You don't, that's how!

OK, the *actual* form of the MacLaurin series for some function f(x) is

f(x) = f(0) + x/1! f'(0) + x^2/2! f''(0) + ...

So  in each term of the sum you have a derivative of f, which in the 
case of the sine function translates to sine and cosine functions at the 
point 0. It's not like you're rid of the function just by doing a 
polynomial expansion. The only way to *solve* this is to forbid x from 
having a dimension. At least *I* see no other way. Do you?


/W
(Don't take this as a personal attack, please. I'm a good guy, I just 
like mathematical nitpicking.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int vs long

2007-06-04 Thread Peter Otten
Marc 'BlackJack' Rintsch wrote:

> In <[EMAIL PROTECTED]>, Peter Otten wrote:
> 
>> Marc 'BlackJack' Rintsch wrote:
>> 
>> from itertools import count
>> from sys import maxint
>> c = count(maxint)
>> c.next()
>>> 2147483647
>> c.next()
>>> -2147483648
>>> 
>>> What I find most disturbing here, is that it happens silently.  I would
>>> have expected an exception instead of the surprise.
>> 
>> This is fixed in Python2.5:
>> 
> from itertools import count
> import sys
> c = count(sys.maxint)
> c.next(), c.next()
>> (2147483647, 2147483648L)
> 
> Hm, my test above was from 2.5!?

Then your installation is broken. What does

>>> import itertools
>>> itertools


print? 

By the way, here's what I get if I force the wrong library upon python2.5:

/usr/local/lib/python2.4/lib-dynload $ python2.5
Python 2.5 (r25:51908, Oct  3 2006, 08:48:09)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
sys:1: RuntimeWarning: Python C API version mismatch for module readline:
This Python has API version 1013, module readline has version 1012.
>>> import itertools
__main__:1: RuntimeWarning: Python C API version mismatch for module
itertools: This Python has API version 1013, module itertools has version
1012.
>>> itertools

>>> import sys
>>> c = itertools.count(sys.maxint)
>>> c.next(), c.next()
(2147483647, -2147483648)

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


Re: subexpressions (OT: math)

2007-06-04 Thread Erik Max Francis
Wildemar Wildenburger wrote:

> So  in each term of the sum you have a derivative of f, which in the 
> case of the sine function translates to sine and cosine functions at the 
> point 0. It's not like you're rid of the function just by doing a 
> polynomial expansion. The only way to *solve* this is to forbid x from 
> having a dimension. At least *I* see no other way. Do you?

That was precisely his point.  The Maclaurin series (not MacLaurin) only 
makes any sense if the independent variable is dimensionless.  And thus, 
by implication, so it is also the case for the original function.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   The time to repair the roof is when the sun is shining.
-- John F. Kennedy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Erik Max Francis wrote:
> Wildemar Wildenburger wrote:
>
>   
>> So  in each term of the sum you have a derivative of f, which in the 
>> case of the sine function translates to sine and cosine functions at the 
>> point 0. It's not like you're rid of the function just by doing a 
>> polynomial expansion. The only way to *solve* this is to forbid x from 
>> having a dimension. At least *I* see no other way. Do you?
>> 
>
> That was precisely his point.  The Maclaurin series (not MacLaurin) only 
> makes any sense if the independent variable is dimensionless.  And thus, 
> by implication, so it is also the case for the original function.
>
>   
No that was not his point. Maybe he meant it, but he said something 
profoundly different. To quote:

[EMAIL PROTECTED] wrote:
> if we expand sine in taylor series sin(x) = x - (x3)/6 + (x5)/120 etc.
> you can see that sin can be dimensionless only if x is dimensionless too.


This argumentation gives x (and sin(x)) the option of carrying a unit. 
That however is *not* the case. This option does not exist. Until 
someone proves the opposite, of course.

Geez, I love stuff like that. Way better than doing actual work. :D


/W

(PS: THX for the MacLaurin<>Maclaurin note. I can't help that 
appearantly; I also write 'LaGrange' all the time.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int vs long

2007-06-04 Thread Douglas Woodrow
On Mon, 4 Jun 2007 10:50:14, Peter Otten <[EMAIL PROTECTED]> wrote
>>>
>>> This is fixed in Python2.5:
>>>
>> Hm, my test above was from 2.5!?
>
>Then your installation is broken. What does
>
 import itertools
 itertools
>'/usr/local/lib/python2.5/lib-dynload/itertools.so'>
>
>print?


Maybe it's a problem with the Windows build of Python 2.5

,
| Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310
| 32 bit (Intel)] on win32
| Type "help", "copyright", "credits" or "license" for more information.
| >>> import sys
| >>> import itertools
| >>> itertools
| 
| >>> c = itertools.count(sys.maxint)
| >>> c.next()
| Traceback (most recent call last):
|   File "", line 1, in 
| OverflowError: cannot count beyond LONG_MAX
| >>>
`

-- 
Doug Woodrow

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


Re: magic names in python

2007-06-04 Thread Diez B. Roggisch
per9000 wrote:

> On Jun 4, 9:11 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> In <[EMAIL PROTECTED]>, per9000
>> wrote:
>> >
>> > [...]
>> >
>> > So another question emerges:
>> >  * is the use of magic names encouraged and/or part of good coding
>> > practice.
>>
>> What do you mean by "use"?  Implement them to override behavior?  Yes,
>> that's their purpose.  Invent new magic names?  No of course not, they
>> are
>> special for a reason:  preventing name clashes with the user's names.
>>
> 
> [in my taste: UGLY]
> I think of something like this: Perhaps I create a class that works
> with a lot of files, and with inheritance new types of files can be
> opened and worked with.
> 
> When it is time for an instance of this class to die the files need to
> be closed - perhaps "right now" and not when it is suitable for the
> garbage collector. To facilitate this I create a number of functions
> with names like close_*_file (f.x. close_indata_file,
> close_outdata_file, close_error_file etc). (compare with [PyTest|
> unittest] "test*" names.)
> 
> If this class has been inherited to some other class that works with
> more than one indata file perhaps we want to magically close all files
> that are open by calling all function in this instance that has names
> matching "close_*_file".
> 
> I would consider this an ugly way of solving it.
> 
> [in my taste: NICER]
> I'd perhaps add file-handles to some list (and encourage inherited
> classes to use this list) and close everything in the list. I would
> not use magic wildcard names.

This is a completely different topic than the usage of "magic" names in
python to allow e.g. operator overloading and the like.

> So in other words: Do I need to go to yellow alert, and watch out for
> magic names in non-core add-on packages to python? Or should I just
> RTFM a little more? (I hate RTFM'ing.)

Certainly RTFM.

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


Re: WSGI/wsgiref: modifying output on windows ?

2007-06-04 Thread [EMAIL PROTECTED]
On Jun 3, 10:11 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am currently trying to port my web software AFoC 
> to Windows and have hit a strange problem: it seams that binary files
> (PNG images in this case) get distorted by wsgiref. (I have tried both
> the CGIHandler with both Xitami and Apache2 and WSGIServer).

I have just realised that the WSGIServer works after all, I do not
know why I thought it didn't.

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


Re: Non-blocking subprocess call

2007-06-04 Thread Nick Craig-Wood
Kevin Walzer <[EMAIL PROTECTED]> wrote:
>  I'm currently using os.popen in an application of mine, which calls for 
>  non-blocking data, in this fashion:
> 
>self.file = os.popen('echo %s | sudo -S /sw/bin/fink -y install %s' % 
>  (self.passtext, self.packagename), 'r', os.O_NONBLOCK)
> 
>  What is the equivalent/comparable call in the new subprocess module? I 
>  can't find any reference in the Python docs to non-blocking
>  streams.

You'll probably be better off with the pexpect module for this

  http://pexpect.sourceforge.net/

Doesn't work on windows.  Looks like you are doing OS X though so
should work fine there

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


making a opc client in Python and use opc server Events

2007-06-04 Thread getelectronic
Hi all
I have a sample code to implement opc client in Python. i use a
file .py making by makepy with pythonwin for Com Interface.
i can get all server in machine, connect to server opc, disconnect,
add group, add item, read, write item in server opc.

import win32com.client  # librairie pour utiliser l'interface COM/DCOM
from win32com.client import gencache
gencache.EnsureModule('{DFB83232-A952-11D2-A46B-00C04F796375}', 0, 1,
0)

for svr in opcserver.GetOPCServers():
print svr

#connect to server OPC Demo Simulation from Matrikon
opcserver.Connect('Matrikon.OPC.Simulation.1')

# Instance object Groups
groups=opcserver.OPCGroups
#add group
group=groups.Add('Group1')

#instance onject Items
items=group.OPCItems
# add item in server opc
tem=items.AddItem('File1.item1',1)

#read item value
item.Read(win32com.client.constants.OPCDevice)

# write a new value
item.Write(100)

#read item value
item.Read(win32com.client.constants.OPCDevice)
#if no pb you have 100 :)

#Disconnect
#opcserver.Disconnect()

BUT, and BUT, i want to use a event from opc server for uodating item
value with this below class. And i don't konw how make it
help me plz

opcserver=win32com.client.Dispatch('OPC.Automation.1')
and now i want to use events from opc server. in a class:
class DIOPCGroupEvent:
class DIOPCGroupsEvent:
class DIOPCServerEvent:

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


Re: int vs long

2007-06-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Peter Otten wrote:

>> Hm, my test above was from 2.5!?
> 
> Then your installation is broken. What does
> 
 import itertools
 itertools
>  '/usr/local/lib/python2.5/lib-dynload/itertools.so'>
> 
> print? 

Python 2.5 (r25:51908, Oct  6 2006, 15:22:41)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>> itertools


> By the way, here's what I get if I force the wrong library upon python2.5:
> 
> /usr/local/lib/python2.4/lib-dynload $ python2.5
> Python 2.5 (r25:51908, Oct  3 2006, 08:48:09)
> [GCC 3.3.3 (SuSE Linux)] on linux2

Seems to be the same Python version, just build three days earlier and
with a different GCC version.  Weird.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subexpressions (OT: math)

2007-06-04 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> sine is a dimensionless value.
> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120
> etc.
> you can see that sin can be dimensionless only if x is dimensionless
> too.

With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...)

area is dimensionless, too, I suppose.
 
> I am a professional physicist and a know about what I talk

Then you can kindly point me to the flaw in that logic :-)

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



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

2007-06-04 Thread montyphyton

Steve Howell je napisao/la:
> some European alphabets:
>
>Spanish -- accented, includes digraphs ch and ll
>German -- accented
>French -- accented
>Italian -- accented, no J/K/W/X/Y
>

what about slavic languages?
in croatian you have five accented letters plus three letters for
digrahps. russian, bulgarian, serbian, macedonian, ukranian etc. use
cyrilic alphabet (lets not forget that russia isn't that small -
around 150 million people), polish also has some of its own
characters...
all in all, it is estimated that some 400 million people speak slavic
languages...

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


Re: int vs long

2007-06-04 Thread Peter Otten
Douglas Woodrow wrote:

> On Mon, 4 Jun 2007 10:50:14, Peter Otten <[EMAIL PROTECTED]> wrote

 This is fixed in Python2.5:

>>> Hm, my test above was from 2.5!?
>>
>>Then your installation is broken. What does
>>
> import itertools
> itertools
>>>'/usr/local/lib/python2.5/lib-dynload/itertools.so'>
>>
>>print?
> 
> 
> Maybe it's a problem with the Windows build of Python 2.5
> 
> ,
> | Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310
> | 32 bit (Intel)] on win32
> | Type "help", "copyright", "credits" or "license" for more information.
> | >>> import sys
> | >>> import itertools
> | >>> itertools
> | 
> | >>> c = itertools.count(sys.maxint)
> | >>> c.next()
> | Traceback (most recent call last):
> |   File "", line 1, in 
> | OverflowError: cannot count beyond LONG_MAX
> | >>>
> `
> 

Revision 51950 check-in message:
"""
* regression bug, count_next was coercing a Py_ssize_t to an unsigned
Py_size_t
  which breaks negative counts
* added test for negative numbers
will backport to 2.5.1
"""

Turns out I was wrong, count() does not escalate from int to long correctly.
It just had an unsigned internal counter in 2.5. Sorry for the confusion.

Peter

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


Re: Comments appreciated on Erlang inspired Process class.

2007-06-04 Thread Nick Craig-Wood
Brian L. Troutwine <[EMAIL PROTECTED]> wrote:
>  Lately I've been tinkering around with Erlang and have begun to sorely want 
>  some of its features in Python, mostly the ease at which new processes can 
> be 
>  forked off for computation. To that end I've coded up a class I call, 
>  boringly enough, Process. It takes a function, its args and keywords and 
> runs 
>  the function in another process using os.fork. Processes can be treated as 
>  callables to retrieve the return value of the passed in function.
> 
>  The code is pasted here: http://deadbeefbabe.org/paste/4972. A simple 
>  exposition of Process is included at the end of the code in some __main__ 
>  magic. (Note: The code will not run on any system which lacks os.fork and 
>  spawns 100 child processes while running.)
> 
>  I'd very much appreciate people to look the code over and give me their 
>  reactions to it, or suggests for improvement. As it stands, I see three 
> major 
>  defects with the current implementation: 
> 
>   1) Process hangs forever if its child errors out.
> 
>   2) Process isn't portable because of its use of os.fork().
> 
>   3) Process should use AF_UNIX when available instead of TCP.

You could use os.pipe() or socket.socketpair().  It would simplify the
code a lot too!

The biggest problem I see is that there is no non-blocking way of
seeing whether the Process() has finished or not, and no way to wait
on more than one Process() at once.

If there is an exception then you should return it to the parent (see
the subprocess module for an example).

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int vs long

2007-06-04 Thread Peter Otten
Marc 'BlackJack' Rintsch wrote:

> Seems to be the same Python version, just build three days earlier and
> with a different GCC version.  Weird.

Indeed. Also, it seems to prove the explanation wrong that I just in
response to Douglas' post...

Peter

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


RE: c[:]()

2007-06-04 Thread Warren Stringer
> "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> || Warren Stringer wanted to call the functions just for the side effects
> | without interest in the return values.  So building a list of return
> | values which is immediately thrown away is a waste of time and memory.
> 
> Also unnecessary: for f in callables: f()

What do you mean?

This is very relevant to what I need to implement now. I am converting a
domain specific language script into python statements. For debugging the
script gets parsed and generates a .py file. The final bypasses the
intermediate step; instead it parses the script and does something like
this:

code = compile(_call,"ParseCall",'exec')
for coname in code.co_names:
 ... cleanup goes here
exec code in self._dict

I am already worried about speed. There are about 2000 macro statements that
look like this:

demo4:demo.stop()
  ball.smooth()
  video.live() 
  preset.video.straight()
  view.front3d() 
  luma.real() 
  seq[:]lock(1)

In this example, the preprocessor translates the statements into a list of
10 callable objects. That last `seq[:]lock(1)` statement generates 4 objects
on its own. All of the __getattr__ resolution is done in the preprocessor
step. For the sort term version are no return values. For the long term
version, there may be return statements, but prefer simplest, for now.

It sounds like list comprehension may be slower because it builds a list
that never gets used. I'm curious if eval statements are faster than def
statements? Any bytecode experts?
 
Sorry if I got sidetracked on philosophical discussion, earlier. The above
example is lifted from a working c++ version with a tweaked syntax. This is
a real problem that I need to get working in a couple weeks. 

As an aside, the code base will be open source.

Much appreciated,

\~/



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


Re: c[:]()

2007-06-04 Thread Erik Max Francis
Warren Stringer wrote:

> demo4:demo.stop()
>   ball.smooth()
>   video.live() 
>   preset.video.straight()
>   view.front3d() 
>   luma.real() 
>   seq[:]lock(1)

You're way off in la-la land, now.

> It sounds like list comprehension may be slower because it builds a list
> that never gets used. I'm curious if eval statements are faster than def
> statements? Any bytecode experts?

Are you serious?  Something that builds a list that never gets used is 
exactly what you were proposing this whole time.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   Get there first with the most men.
-- Gen. Nathan Bedford Forrest, 1821-1877
-- 
http://mail.python.org/mailman/listinfo/python-list


ctypes: error passing a list of str to a fortran dll

2007-06-04 Thread luis
I'm using ctypes to call a fortran dll from python. I have no problems
passing integer and double arryas, but I have an error with str arrys.
For example:


StringVector = c_char_p * len(id) # id is a list of strings

Id_dat=StringVector()
for i in range(len(Id)):
...Id_dat[i]=id[i]

n=c_int(len(Id_dat))

myDll = windll.LoadLibrary(org)

myDll.myFunc(byref(n), byref(Id_dat))

and then

ValueError: Procedure probably called with not enough arguments (4
bytes missing)

In a similar way I have bo problemns with int or double arryas

Some suggestions are wellcome !

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


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

2007-06-04 Thread Steve Howell

--- [EMAIL PROTECTED] wrote:
> what about slavic languages?
> in croatian you have five accented letters plus
> three letters for
> digrahps. russian, bulgarian, serbian, macedonian,
> ukranian etc. use
> cyrilic alphabet (lets not forget that russia isn't
> that small -
> around 150 million people), polish also has some of
> its own
> characters...
> all in all, it is estimated that some 400 million
> people speak slavic
> languages...
> 

Agreed, but FWIW, if you compared Slavic-writing
people to Chinese-writing people, I would think that a
higher percentage of Slavic-writing people would be
bilingual in terms of their ability to write code in
non-Slavic alphabets, due to various
cultural/geographical factors.

I don't predict a huge upswing in Slavic-writing
Python programmers after PEP 3131, even among
children.






 

It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Peter Otten wrote:
> With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...)
>
> area is dimensionless, too, I suppose.
>   

Ehr, ... maybe this is obvious, but I don't see it: Please explain the 
second equality sign.
/W
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WSGI/wsgiref: modifying output on windows ?

2007-06-04 Thread [EMAIL PROTECTED]
On Jun 3, 10:11 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Might this be a bug in wsgiref ? I will hopefully be able to do some
> more testing, ...

The following simple CGI script should, AFAIK, on any platform, output
exactly the file specified in code. It does not on Apache 2 on
Windows; I believe this to be a bug in wsgiref.handlers.CGIHandler.
Can someone test this in a similar environment (Windows+a web server?)
to confirm this ? (The first two lines need to be edited depending on
the site)

#!c:\python25\python.exe
fname, type = r'c:\hdr.png', 'image/png'

from wsgiref.handlers import CGIHandler

def wsgiapp(env, start_response):
f = file(fname, 'rb')
start_response('200 OK', [('Content-Type', type)])
return [f.read()]


CGIHandler().run(wsgiapp)

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


Re: subexpressions (OT: math)

2007-06-04 Thread Peter Otten
Wildemar Wildenburger wrote:

> Peter Otten wrote:
>> With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...)
>>
>> area is dimensionless, too, I suppose.
>>   
> 
> Ehr, ... maybe this is obvious, but I don't see it: Please explain the
> second equality sign.

I know not much more about Fourier series than that they do exist, so let me
refer you to

http://en.wikipedia.org/wiki/Fourier_series

for a general explanation, and to

http://www.exampleproblems.com/wiki/index.php/FS6

for the series given above.

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


Re: Python 2.5.1 broken os.stat module

2007-06-04 Thread Joe Salmeri

""Martin v. Löwis"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> It appears that you may have missed part of my tests.  Sorry it was such 
>> a
>> long reply but I was trying to provide a lot of detail so that others had 
>> a
>> clear understanding of what was going on.
>
> Please understand that it is *extremely* tedious to follow your
> messages. It would have been much better if they had been short and
> to the point.
>
>> Changing the timezone will defintely change the "textual representation" 
>> of
>> all timestamps just as you say (even though the actual UTC value has 
>> *not*
>> changed), however, when DST starts/ends the "textual representation" of 
>> the
>> timestamps on some files WILL ALSO CHANGE when the automatically adjust 
>> for
>> DST setting is turned on.
>
> Right, and that's because switching to DST means that YOU MOVE TO A
> DIFFERENT TIME ZONE.
>
> EST != EDT.
>
>> While it is true that I did change the timezone in the first part of the
>> test (to establish the baseline), in the second part of the tests where 
>> the
>> difference you are referring to occured, the timezone was *not* changed, 
>> the
>> only thng that occured was that DST started.
>
> And that meant that the time zone *did* change.
>
>> When the date progressed to a point after DST had started Windows now
>> reports the timestamp on that *unmodified* file now is 01/01/2007 08:00 
>> PM.
>>
>> I did not change the timezone, the only thing that occurred was DST 
>> started.
>
> So you did change the timezone.
>
>> Over the years this issue has caused all sorts of problems for backup
>> programs and CVS (greatly detailed in the article I provided the link 
>> for).
>
> That is very hard to believe. CVS and backup programs use the UTC time
> stamp, and completely ignore the timezone. So when you agree that the
> UTC time stamp did not change, CVS and the backup programs will work
> just fine.
>
> There was a long-standing problem with changing time-stamps ON FAT.
> On a FAT file system, the actual UTC time stamps change when the
> timezone changes (including the change to and from DST). *That*
> was a big problem for backup programs and CVS, and is now fixed
> with NTFS.
>
>> You mixed up my tests, in that case as shown above the timezone did *not*
>> change, the only thing that changed was that DST started and the file was
>> created during a time when DST was not in effect.
>
> Right, so the timezone did change.
>
> Regards,
> Martin 


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

Re: Python 2.5.1 broken os.stat module

2007-06-04 Thread Joe Salmeri
There is a conflict with the answers that you and Terry have given.

The original issue I raised was that I Python 2.5.1 and Windows did not have 
the same textual represenation for a localize date.

You have stood true to the statements that Python 2.5.1 is correct and that 
previous versions were wrong.

I agree with you that Python 2.5.1 is correct which means that Windows is 
showing the incorrect dates.

Since that point in time you and Terry have disagreed with my statements 
regarding timezones and DST.

All dates in my below comments are the textual representation of those dates 
from Windows or from Python 2.5.1

For the test file created at 01/02/2007 07:00 PM.

>From that date up until just before DST starts both Windows AND Python 2.5.1 
will report that date as 01/02/2007 07:00 PM.

Once DST starts Python 2.5.1 will still report that date as 01/02/2007 07:00 
PM, however Windows will now report that
date as 01/02/2007 at 08:00 PM.

I agree and believe that Python 2.5.1 is reporting the correct textual 
representation of that timestamp, however, using
*your* logic that a DST change *is a timezone change* that would mean that 
Python 2.5.1 is wrong and should be reporting the
date 1 hour later just as Windows is reporting.

You cannot have it both ways.

If a DST change is the same as a timezone change then Python 2.5.1 should be 
reporting the dates that Windows reports.
If a DST change is NOT the same as a timezone change then Python 2.5.1 
should be reporting the dates that it currently is.


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


Re: Python 2.5.1 broken os.stat module

2007-06-04 Thread Joe Salmeri
Perspective is often the source of problems with communication.

You view timezones and DST as offsets from GMT.  I understand and respect 
that perspective.

When I think of timezones and DST I think of the timezone setting and the 
DST setting in Windows.

These settings are two separate settings in Windows that can be configured 
individually and independent of each other.

When I think of a time I think of

somedate, sometime, Eastern Standard Time (EST)

OR

somedate, sometime, Eastern Standard Time Daylight Saving Time (EST DST)

If you view things from my perspective then I would hope my comments become 
more clear.

Last night I was talking to my wife about this discussion (I need to get a 
life :-)) and she came up with an analogy
that I like even better than my TV analogy.

Suppose she has a baby 01/02/2007 07:00 PM.

Today, a time after DST has started for this region someone asks her when 
her baby was born.

Here answer would be 01/02/2007 07:00 PM.

If we ask Windows that same question it would be 01/02/2007 08:00 PM.

Please see my other response to Martin because using your logic of "a DST 
change is a timezone change" that would mean that the textual representation 
of dates by Python 2.5.1 is WRONG.  I don't believe that to be true but you 
cannot have it both ways, if a DST change is a timezone change then Python 
should show the same dates as Windows does, if it is not the same then 
Python should show the dates that it is.


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


Re: another thread on Python threading

2007-06-04 Thread sturlamolden
On Jun 4, 3:10 am, Josiah Carlson <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
> > I've recently been working on an application[1] which does quite a bit
> > of searching through large data structures and string matching, and I
> > was thinking that it would help to put some of this CPU-intensive work
> > in another thread, but of course this won't work because of Python's
> > GIL.
>
> If you are doing string searching, implement the algorithm in C, and
> call out to the C (remembering to release the GIL).
>
> > There's a lot of past discussion on this, and I want to bring it up
> > again because with the work on Python 3000, I think it is worth trying
> > to take a look at what can be done to address portions of the problem
> > through language changes.
>
> Not going to happen.  All Python 3000 PEPs had a due-date at least a
> month ago (possibly even 2), so you are too late to get *any*
> substantial change in.
>
> > I remember reading (though I can't find it now) one person's attempt
> > at true multithreaded programming involved adding a mutex to all
> > object access.  The obvious question though is - why don't other true
> > multithreaded languages like Java need to lock an object when making
> > changes?
>
>  From what I understand, the Java runtime uses fine-grained locking on
> all objects.  You just don't notice it because you don't need to write
> the acquire()/release() calls.  It is done for you.  (in a similar
> fashion to Python's GIL acquisition/release when switching threads)

The problem is CPython's reference counting. Access to reference
counts must be synchronized.

Java, IronPython and Jython uses another scheme for the garbage
collector and do not need a GIL.

Changing CPython's garbage collection from reference counting to a
generational GC will be a major undertaking. There are also pros and
cons to using reference counts instead of 'modern' garbage collectors.
For example, unless there are cyclic references, one can always know
when an object is garbage collected. One also avoids periodic delays
when garbage are collected, and memory use can be more modest then a
lot of small temporary objects are being used.

Also beware that the GIL is only a problem for CPU bound code. IO
bound code is not slowed by the GIL. The Python runtime itself is a
bigger problem for CPU bound code.

In C or Fortran, writing parallell algorithms for multiprocessor
systems typically involves using OpenMP or MPI. Parallelizing
algorithms using manual threading should be discouraged. It is far
better to insert a compiler directive (#pragma omp) and let an OpenMP
compiler to the job.

There are a number of different options for exploiting multiple CPUs
from CPython, including:

- MPI (e.g. mpi4py or PyMPI)
- PyPar
- os.fork() on Linux or Unix
- subprocess.Popen
- C extensions that use OpenMP
- C extensions that spawn threads (should be discouraged!)

> They also have a nice little decorator-like thingy (I'm not a Java guy,
> so I don't know the name exactly) called 'synchronize', which locks and
> unlocks the object when accessing it through a method.

A similar Python 'synchronized' function decorator may look like this:

def synchronized(fun):
   from threading import RLock
   rl = RLock()
   def decorator(*args,**kwargs):
  with rl:
 retv = fun(*args,**kwargs)
  return retv
   return decorator

It is not possible to define a 'synchronized' block though, as Python
do not have Lisp macros :(




















>
>   - Josiah
>
> > == Why hasn't __slots__ been successful? ==
>
> > I very rarely see Python code use __slots__.  I think there are
> > several reasons for this.  The first is that a lot of programs don't
> > need to optimize on this level.  The second is that it's annoying to
> > use, because it means you have to type your member variables *another*
> > time (in addition to __init__ for example), which feels very un-
> > Pythonic.
>
> > == Defining object attributes ==
>
> > In my Python code, one restriction I try to follow is to set all the
> > attributes I use for an object in __init__.   You could do this as
> > class member variables, but often I want to set them in __init__
> > anyways from constructor arguments, so "defining" them in __init__
> > means I only type them once, not twice.
>
> > One random idea is to for Python 3000, make the equivalent of
> > __slots__ the default, *but* instead gather
> > the set of attributes from all member variables set in __init__.  For
> > example, if I write:
>
> > class Foo(object):
> >   def __init__(self, bar=None):
> > self.__baz = 20
> > if bar:
> >   self.__bar = bar
> > else:
> >   self.__bar = time.time()
>
> > f = Foo()
> > f.otherattr = 40  # this would be an error!  Can't add random
> > attributes not defined in __init__
>
> > I would argue that the current Python default of supporting adding
> > random attributes is almost never what you really want.  If you *do*
> > want to set random attributes

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

2007-06-04 Thread montyphyton
> Agreed, but FWIW, if you compared Slavic-writing
> people to Chinese-writing people, I would think that a
> higher percentage of Slavic-writing people would be
> bilingual in terms of their ability to write code in
> non-Slavic alphabets, due to various
> cultural/geographical factors.

of course. but maybe it would be a nice effort to enable writing code
in cyrillic, since it is a whole new alphabet. for the accented
letters from slavic (or other) languages, i agree that one wouldn't
gain much from enabling their use in source code.
but my point being, if we are going to add chinese and japanese, why
not do everything right and add all languages/alphabets? after all,
after adding chinese, how hard can it be to add a few accedented
letters :)

>
> I don't predict a huge upswing in Slavic-writing
> Python programmers after PEP 3131, even among
> children.
>

you are probably right.

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


Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Peter Otten wrote:
> [EMAIL PROTECTED] wrote:
>
>   
>> sine is a dimensionless value.
>> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120
>> etc.
>> you can see that sin can be dimensionless only if x is dimensionless
>> too.
>> 
>
> With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...)
>
> area is dimensionless, too, I suppose.
>  
No, its not dimensionless (phew, that took me a while ... got pretty 
anxious there for a moment):

If you look at the definition of the fourier coefficients on the page 
you presented (http://www.exampleproblems.com/wiki/index.php/FS6), 
you'll see that they have
the same unit as f(x) (or y(x) as in your example).
Which, btw,  is VERY MUCH desired because all science (and with it the 
universe, mind you!) would blow up if functions didn't  have the same 
unit as any of their series expansions. After all, they are meant to 
*replace* the function.
Man! You scared me good!
:D


Oh my, remember when we used to discuss murderous snakes and silly 
British comedians on this group?
I hardly do ...
/W
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell
--- Peter Otten <[EMAIL PROTECTED]> wrote:
> 
> I know not much more about Fourier series than that
> they do exist, so let me
> refer you to
> 
> http://en.wikipedia.org/wiki/Fourier_series
> 

I'd like to try to bring this thread back full circle
(or maybe at least 7*pi/4).

   1) OP posted an example of sin(x*x) + cos(x*x).

   2) I posted the observation (slight paraphrase of
myself) that above formula looks like a high school
math mistake.

   3) I also asked for geometric interpretation of
square root of an arc length, not really expecting
one, although eventually somebody posted an
interesting physical interpretation (noise density).

   4) I also asked about units in general.  The
general consensus is that radians are dimensionless.

   5) Any exploration of trigonometry among smart
people eventually leads to Fourier Series expansions. 

   
Trying to bring this back to Python, I think Fourier
Series make a better example of a situation where you
end up repeating subexpressions:

lambda t: a[0]/2 + sum(a[n]*cos(n*f*t) +
b[n]*sin(n*f*t) \
for n in range(1,101))

   


   

Pinpoint customers who are looking for what you sell. 
http://searchmarketing.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


How to do this with groupby (or otherwise)? (Was: iterblocks cookbook example)

2007-06-04 Thread Gerard Flanagan
On Jun 2, 10:47 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> On Jun 2, 10:19 am, Steve Howell <[EMAIL PROTECTED]> wrote:
>
> > George Sakkis produced the following cookbook recipe,
> > which addresses a common problem that comes up on this
> > mailing list:
>
> ISTM, this is a common mailing list problem because it is fun
> to solve, not because people actually need it on a day-to-day basis.
>
> In that spirit, it would be fun to compare several different
> approaches to the same problem using re.finditer, itertools.groupby,
> or the tokenize module.  To get the ball rolling, here is one variant:
>
> from itertools import groupby
>
> def blocks(s, start, end):
> def classify(c, ingroup=[0], delim={start:2, end:3}):
> result = delim.get(c, ingroup[0])
> ingroup[0] = result in (1, 2)
> return result
> return [tuple(g) for k, g in groupby(s, classify) if k == 1]
>
> print blocks('the  brown  jumped', start='<', end='>')
>
> One observation is that groupby() is an enormously flexible tool.
> Given a well crafted key= function, it makes short work of almost
> any data partitioning problem.
>

Can anyone suggest a function that will split text by paragraphs, but
NOT if the paragraphs are contained within a [quote]...[/quote]
construct.  In other words, the following text should yield 3 blocks
not 6:

TEXT = '''
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Pellentesque dolor quam, dignissim ornare, porta et,
auctor eu, leo. Phasellus malesuada metus id magna.

[quote]
Only when flight shall soar
not for its own sake only
up into heaven's lonely
silence, and be no more

merely the lightly profiling,
proudly successful tool,
playmate of winds, beguiling
time there, careless and cool:

only when some pure Whither
outweighs boyish insistence
on the achieved machine

will who has journeyed thither
be, in that fading distance,
all that his flight has been.
[/quote]

Integer urna nulla, tempus sit amet, ultrices interdum,
rhoncus eget, ipsum. Cum sociis natoque penatibus et
magnis dis parturient montes, nascetur ridiculus mus.
'''

Other info:

* don't worry about nesting
* the [quote] and [/quote] musn't be stripped.

Gerard

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


Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell

--- Wildemar Wildenburger <[EMAIL PROTECTED]>
wrote:
> 
> 
> Oh my, remember when we used to discuss murderous
> snakes and silly 
> British comedians on this group?
> I hardly do ...
> /W

Although all of us are mere amateurs
in this business of making parameters
when it's circles in question 
I have a suggestion:
Try not to forget the diameters.

More here:

http://www.xs4all.nl/~jcdverha/scijokes/1_4.html





   

Building a website is a piece of cake. Yahoo! Small Business gives you all the 
tools to get online.
http://smallbusiness.yahoo.com/webhosting 
-- 
http://mail.python.org/mailman/listinfo/python-list


pyhon 2.5.1 build fails

2007-06-04 Thread Robin Becker
I am getting an error while building python-2.5.1 on a freebsd 6.1 machine as a 
normal user

./configure --prefix=/home/me/mypython --enable-unicode=ucs2

seems to work fine, but make install fails whilst running

Compiling
/home/my/mypython/lib/python2.5/test/test_module.py ...
Compiling /home/me/mypython/lib/python2.5/test/test_multibytecodec.py ...
Sorry: UnicodeError: ("\\N escapes not supported (can't load unicodedata 
module)",)
Compiling /home/me/mypython/lib/python2.5/test/test_multibytecodec_support.py 
...

I see there was a bug reported about this
http://www.mail-archive.com/[EMAIL PROTECTED]/msg09544.html

but I didn't really understand what the resolution was. I do not have any 
special PYTHONHOME or PYTHONPATH set. The install partially works and I have a 
running python without the unicodedata module. Looking in Modules I don't see 
any unicodedata.o so I guess it's not being built for some reason.
-- 
Robin Becker

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


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

2007-06-04 Thread M�ta-MCI
Et le klingon ? 

Please, don't forget klingons
SVP, n'oubliez pas les klingons

;o) 


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


Python 3000: Standard API for archives?

2007-06-04 Thread samwyse
I'm a relative newbie to Python, so please bear with me.  There are 
currently two standard modules used to access archived data:  zipfile 
and tarfile.  The interfaces are completely different.  In particular, 
script wanting to analyze different types of archives must duplicate 
substantial pieces of logic.  The problem is not limited to method 
names; it includes how stat-like information is accessed.

I think it would be a good thing if a standardized interface existed, 
similar to PEP 247.  This would make it easier for one script to access 
multiple types of archives, such as RAR, 7-Zip, ISO, etc.  In 
particular, a single factory class could produce PEP 302 import hooks 
for future as well as current archive formats.

I think that an archive module adhering to the standard should adopt a 
least-common-denominator approach, initially supporting read-only access 
without seek, i.e. tar files on actual tape.  For applications that 
require a seek method (such as importers) a standard wrapper class could 
transparently cache archive members in temp files; this would fit in 
well with Python 3000's rewrite of the I/O interface to support 
stackable interfaces.  To this end, we'd need is_seekable and 
is_writable attributes for both the module and instances (moduel level 
would declare if something is possible, not if it is always true).

Most importantly, all archive modules should provide a standard API for 
accessing their individual files via a single archive_content class that 
provides a standard 'read' method.  Less importantly but nice to have 
would be a way for archives to be auto-magically scanned during walks of 
  directories.

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


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

2007-06-04 Thread montyphyton

Méta-MCI je napisao/la:
> Et le klingon ?
>
> Please, don't forget klingons
> SVP, n'oubliez pas les klingons
>
> ;o)

je pense que le klingon utilise les mems lettres comme l'anglais

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

Re: excel library without COM

2007-06-04 Thread John Machin
On Jun 4, 3:52 pm, yuce <[EMAIL PROTECTED]> wrote:
> i think this one works pretty nice:http://www.python.org/pypi/xlrd

Sure does :-) However the "rd" in "xlrd" is short for "ReaD". As
Waldemar suggested, "xlwt" ("wt" as in WriTe) is more like what the OP
needs.

Cheers,
John

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


Re: pyhon 2.5.1 build fails

2007-06-04 Thread Robin Becker
Robin Becker wrote:
> I am getting an error while building python-2.5.1 on a freebsd 6.1 machine as 
> a 
> normal user
> 
> ./configure --prefix=/home/me/mypython --enable-unicode=ucs2
> 
> seems to work fine, but make install fails whilst running
> 
> Compiling
> /home/my/mypython/lib/python2.5/test/test_module.py ...
> Compiling /home/me/mypython/lib/python2.5/test/test_multibytecodec.py ...
> Sorry: UnicodeError: ("\\N escapes not supported (can't load unicodedata 
> module)",)
> Compiling /home/me/mypython/lib/python2.5/test/test_multibytecodec_support.py 
> ...
> 
> I see there was a bug reported about this
> http://www.mail-archive.com/[EMAIL PROTECTED]/msg09544.html
> 
> but I didn't really understand what the resolution was. I do not have any 
> special PYTHONHOME or PYTHONPATH set. The install partially works and I have 
> a 
> running python without the unicodedata module. Looking in Modules I don't see 
> any unicodedata.o so I guess it's not being built for some reason.
well regardless of the resolution of the so called bug, my fis is to edit 
Modules/Setup.dist and uncomment line 180 beginning #unicodedata then the test 
don't fail halfway through and things get built properly.

Strangely I thought that all this was supposed to be handled automatically now.
-- 
Robin Becker

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


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

2007-06-04 Thread Steve Howell

--- [EMAIL PROTECTED] wrote:

> 
> Méta-MCI je napisao/la:
> > Et le klingon ?
> >
> > Please, don't forget klingons
> > SVP, n'oubliez pas les klingons
> >
> > ;o)
> 
> je pense que le klingon utilise les mems lettres
> comme l'anglais
> 

Oui, mais en tous case, dans l'Enterprise on doit
utiliser le Java, a cause du patron d'une chevelure
pointu.





  

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


How do you htmlentities in Python

2007-06-04 Thread js
Hi list.

If I'm not mistaken, in python, there's no standard library to convert
html entities, like & or > into their applicable characters.

htmlentitydefs provides maps that helps this conversion,
but it's not a function so you have to write your own function
make use of  htmlentitydefs, probably using regex or something.

To me this seemed odd because python is known as
'Batteries Included' language.

So my questions are
1. Why doesn't python have/need entity encoding/decoding?
2. Is there any idiom to do entity encode/decode in python?

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


RE: c[:]()

2007-06-04 Thread Roland Puntaier
Hi,

I have started to look into the last postings. It is funny and sad how 
people talking the same language cannot understand each other.
I have become curious on what exactly you mean.

Warren, can you please restate your point. 
When doing so, please define every identifier or non-plain english word 
before you use it and be concise.

e.g.
You cannot use b if it is not clear what it means. 
When writing "c[:]()" there is no "b". So where does "b" come from?
You told us that "b" is a container (*), but where should the python 
interpreter or the people take it from.

People start to guess, as I did:
  (1) - Might you mean: "b() for b in c". (I use python syntax here)
This means c is a container, an undertanding that is supported 
also by the used slicing ("[:]").
  (2) - Let's suppose that by (*) you mean that, in addition to "c", "b" 
is a container, too.
  (3) - Now for a standard container "b()" does not make sense. Maybe you 
mean "b[:]()" according to the guessed interpretation (1).
This would then be a recursive evaluation of all functions with no 
parameters in a tree ("tree" in the informatics sense).
  (end of my guess)
 

I think somehow it should be possible to convey an idea so that others can 
grasp it.
If it does not work the first time, it is good to clarify the points that 
one found others to misunderstand.
Otherwise one risks to be regarded as esoteric.

Thanks, Roland

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


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

2007-06-04 Thread olive

Lol!

What is a "sharp hair boss" ?

My boss does not look like a punk !

But he does want me to dance "la Java".

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


python for EE CAD program

2007-06-04 Thread chewie54
Hi All,

I have read some posts on this subject but I haven't been able to make
a decision whether to use Python or not.

I'm considering converting a Java CAD program to Python/C with
wxWdigets for the GUI.

I don't have good answers for:

1)  Can I use py2exe or pyinstaller to produce an executable for
Linux, Windows, and Mac?  If not,  is there a way it can be done?

2)  Is there any way to protect the source code,  like obfuscation?

3)  Memory footprint of application seems large for python demo. Is
this typical for large python applications?

I guess the best thing to do is convert a little portion of the Java
program and see how  it works out with respect to the concerns above.

Suggestions and comments appreciated.

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


Re: magic names in python

2007-06-04 Thread markacy
On 4 Cze, 08:43, per9000 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I recently started working a lot more in python than I have done in
> the past. And I discovered something that totally removed the pretty
> pink clouds of beautifulness that had surrounded my previous python
> experiences: magic names (I felt almost as sad as when I discovered
> the strange pink worms that eat you in nethack, not to mention the
> mind flayers - I really hate them).
>
> I guess all programming languages have magic names to some extent
> (f.x. classes in the "C-family" have constructors that must have the
> same name as the class (foo::foo) instead of foo.__init__).
>
> I just used a search engine a little on this topic and I found no
> comprehensive list of magic names in python.
>
> So my questions:
>  * is there a comprehensive list of magic names in python (so far i
> know of __init__ and __repr__)?
>  * are these lists complete or can magic names be added over time (to
> the python "core")?
>  * are magic names the same in different python versions?
>
> I also tried (selected parts of(?)) the unittest package for use in
> Zope and it seemed functions that I created for my test with the magic
> prefix "test" were magic, other functions were not.
>
> So another question emerges:
>  * is the use of magic names encouraged and/or part of good coding
> practice.
>
> Live long and prosper,
> Per
>
> --
>
> Per Erik Strandberg
> home:www.pererikstrandberg.se
> work:www.incf.org
> also:www.spongswedencare.se

On "magic" methods and their usage You can read here:
http://diveintopython.org/object_oriented_framework/special_class_methods.html
By the way - this is a very good book on python.
Cheers,
Marek

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


Using pyTTS with other languages.

2007-06-04 Thread simon kagwe
Hi,

I would like to create a TTS program for a local (Kenyan) language. I have
installed pyTTS on my computer and it works perfectly with English sentences.
However, my language is very different from English (sylabbles, pronounciation
etc.) How can I go about having a TTS program that correctly speaks my language?
Can pyTTS do this?

I need all the help I can get.

Regards,
Simon.

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


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

2007-06-04 Thread ahlongxp
On Jun 4, 11:54 am, Ross Ridge <[EMAIL PROTECTED]>
wrote:
> Steve Howell  <[EMAIL PROTECTED]> wrote:
>
> >about Japan:
> >major linguistic influences: Chinese, English,
> >Dutch
>
> English and Dutch are minor linguistic influences.
>
Obviously. But language evolves.

>
> >Asia:
>
> >   Python should be *completely* internationalized for
> >Mandarin, Japanese, and possibly Hindi and Korean.
> >Not just identifiers.  I'm talking the entire
> >language, keywords and all.
>
> This would be more convincing if it came from someone who spoke Mandarin,
> Japanese, Hindi or Korean.
>
I'm a Chinese.
Language/English is really a  big problem for Chinese programmers.
If python can be written in Chinese, it may become the  most  popular
program language in China(though popular alreay).
Considering the potential large amount of users in China,  the effort
of internationalization for Chinese will totally worth.

> btw. Mandarin is a spoken dialect Chinese, what you're actually asking
> for is a Simplified-Chinese version of Python.

Mandarin is not a friendly way of saying Chinese and it is totally
unacceptable in some area.
Either Simplified Chinese or Traditional Chinese  will be better.

and last but not least, python ROCKS.

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


Re: python for EE CAD program

2007-06-04 Thread Diez B. Roggisch
chewie54 wrote:

> Hi All,
> 
> I have read some posts on this subject but I haven't been able to make
> a decision whether to use Python or not.
> 
> I'm considering converting a Java CAD program to Python/C with
> wxWdigets for the GUI.
> 
> I don't have good answers for:
> 
> 1)  Can I use py2exe or pyinstaller to produce an executable for
> Linux, Windows, and Mac?  If not,  is there a way it can be done?
> 
> 2)  Is there any way to protect the source code,  like obfuscation?
> 
> 3)  Memory footprint of application seems large for python demo. Is
> this typical for large python applications?
> 
> I guess the best thing to do is convert a little portion of the Java
> program and see how  it works out with respect to the concerns above.
> 
> Suggestions and comments appreciated.

Look at python-cad, that might give you an idea how such a thing is to be
accomplished using python.

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


Re: `yield` in a `try/finally` block, pre-Python 2.5

2007-06-04 Thread Adam Atlas
On Jun 4, 1:49 am, yuce <[EMAIL PROTECTED]> wrote:
> I had the same problem, you can 
> see:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/130004
> for a solution.
>
> Happy hacking,
>
> Yuce

Thanks. I thought of doing something like that, but in my program,
it's important that the order follow the actual nesting order. That
is, I have a few nested generator each of which has its own 'finally',
and I need the innermost ones to run first. How can I deal with that?

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


python for EE CAD program

2007-06-04 Thread chewie54
Hi All,

I have read some posts on this subject but I haven't been able to make
a decision whether to use Python or not.

I'm considering converting a Java CAD program to Python/C with
wxWdigets for the GUI.

I don't have good answers for:

1)  Can I use py2exe or pyinstaller to produce an executable for
Linux, Windows, and Mac?  If not,  is there a way it can be done?

2)  Is there any way to protect the source code,  like obfuscation?

3)  Memory footprint of application seems large for python demo. Is
this typical for large python applications?

I guess the best thing to do is convert a little portion of the Java
program and see how  it works out with respect to the concerns above.

Suggestions and comments appreciated.

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


Re: How do you htmlentities in Python

2007-06-04 Thread Adam Atlas
As far as I know, there isn't a standard idiom to do this, but it's
still a one-liner. Untested, but I think this should work:

import re
from htmlentitydefs import name2codepoint
def htmlentitydecode(s):
return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:
name2codepoint[m.group(1)], s)

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


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

2007-06-04 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Ross Ridge  <[EMAIL PROTECTED]> wrote:
>Steve Howell  <[EMAIL PROTECTED]> wrote:
>>about Japan:
>>major linguistic influences: Chinese, English,
>>Dutch
>
>English and Dutch are minor linguistic influences.
.
.
.
Korean's arguably more important in Japanese philology than 
Dutch.  Portuguese and Spanish are also present, at a level
somewhat below that of Dutch.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python unix install, sqlite3

2007-06-04 Thread vasudevram
On May 29, 11:40 pm, Simon <[EMAIL PROTECTED]> wrote:
> On May 29, 7:05 am, vasudevram <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On May 29, 5:52 pm, Simon <[EMAIL PROTECTED]> wrote:
>
> > > I installed the source code on unix for python 2.5.1. The install went
> > > mainly okay, except for some failures regarding:
> > > _ssl, _hashlib, _curses, _curses_panel.
>
> > > No errors regarding sqlite3.
> > > However, when I start python and do an import sqlite3 I get:
>
> > > /ptmp/bin/> python
> > > Python 2.5.1 (r251:54863, May 29 2007, 05:19:30)
> > > [GCC 3.3.2] on sunos5
> > > Type "help", "copyright", "credits" or "license" for more information.>>> 
> > > import sqlite3
>
> > > Traceback (most recent call last):
> > >   File "", line 1, in 
> > >   File "/ptmp/Python-2.5.1/lib/python2.5/sqlite3/__init__.py", line
> > > 24, in 
> > > from dbapi2 import *
> > >   File "/ptmp/Python-2.5.1/lib/python2.5/sqlite3/dbapi2.py", line 27,
> > > in 
> > > from _sqlite3 import *
> > > ImportError: No module named _sqlite3
>
> > Some ideas:
>
> > I don't know if sqlite3 comes bundled with the standard Python source
> > bundle. My guess is not. If not, that's the cause of the error - you
> > need to install sqlite3 (and probably pysqlite3 (not sure of the name
> > (whether it has a trailing 3) which, if I remember, is the Python
> > binding/wrapper for sqlite3 (which is a C library, I think). Other
> > possible cause of the error (if sqlite3 _is_ bundled with Python and
> > no Python binding/wrapper is needed, is that sqlite3 depends on one of
> > those other libraries you mention (such as _hashlib) for which you got
> > errors while installing Python from source.
>
> > HTH
> >VasudevRam
> > Dancing Bison Enterpriseswww.dancingbison.com-Hide quoted text -
>
> > - Show quoted text -
>
> Vasudev,
>   Thanks so much for the reply. I went to their website and your guess
> was correct. Python 2.5 has included support for sqlite but it only
> includes the PySqlite interface module (now called sqlite3). It does
> not include sqlite3 with the source distribution.
>
> Simon

You're welcome, Simon. Good to hear that it worked :-)

Vasudev


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


Re: another thread on Python threading

2007-06-04 Thread [EMAIL PROTECTED]
On Jun 3, 9:10 pm, Josiah Carlson <[EMAIL PROTECTED]>
wrote:
>
> If you are doing string searching, implement the algorithm in C, and
> call out to the C (remembering to release the GIL).

I considered that, but...ick!  The whole reason I'm writing this
program
in Python in the first place is so I don't have to deal with the mess
that is involved when you do string matching and data structure
traversal
in C.

On the other hand, there are likely C libraries out there for
searching the
kinds of data structures I use; I'll investigate.

> > There's a lot of past discussion on this, and I want to bring it up
> > again because with the work on Python 3000, I think it is worth trying
> > to take a look at what can be done to address portions of the problem
> > through language changes.
>
> Not going to happen.  All Python 3000 PEPs had a due-date at least a
> month ago (possibly even 2), so you are too late to get *any*
> substantial change in.

=(  Too bad.  It might be possible to do these changes in a backwards
compatible way,
though less elegantly.  For example, the object change could be
denoted by inheriting from "fixedobject"
or something.

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


Re: python for EE CAD program

2007-06-04 Thread chewie54
On Jun 4, 9:56 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> chewie54 wrote:
> > Hi All,
>
> > I have read some posts on this subject but I haven't been able to make
> > a decision whether to use Python or not.
>
> > I'm considering converting a Java CAD program to Python/C with
> > wxWdigets for the GUI.
>
> > I don't have good answers for:
>
> > 1)  Can I use py2exe or pyinstaller to produce an executable for
> > Linux, Windows, and Mac?  If not,  is there a way it can be done?
>
> > 2)  Is there any way to protect the source code,  like obfuscation?
>
> > 3)  Memory footprint of application seems large for python demo. Is
> > this typical for large python applications?
>
> > I guess the best thing to do is convert a little portion of the Java
> > program and see how  it works out with respect to the concerns above.
>
> > Suggestions and comments appreciated.
>
> Look at python-cad, that might give you an idea how such a thing is to be
> accomplished using python.
>
> Diez


Hello Diez,

I did look at PythonCad but the distribution and install methods for
Windows is not user freindly. Since the public domain software,  I
don't think they protect the source code either.


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


Re: Using pyTTS with other languages.

2007-06-04 Thread kyosohma
On Jun 4, 8:17 am, simon kagwe <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like to create a TTS program for a local (Kenyan) language. I have
> installed pyTTS on my computer and it works perfectly with English sentences.
> However, my language is very different from English (sylabbles, pronounciation
> etc.) How can I go about having a TTS program that correctly speaks my 
> language?
> Can pyTTS do this?
>
> I need all the help I can get.
>
> Regards,
> Simon.

Hi Simon,

I am pretty sure pyTTS can do this. It has a method to tell it how to
pronounce words. See the following article:

http://www.cs.unc.edu/~parente/tech/tr02.shtml

It describes how to use mis-spelled words to force correct
pronunciation as well as how to do it with XML.

Mike

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


Re: How to do this with groupby (or otherwise)? (Was: iterblocks cookbook example)

2007-06-04 Thread Gerard Flanagan
On Jun 4, 1:52 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
> On Jun 2, 10:47 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jun 2, 10:19 am, Steve Howell <[EMAIL PROTECTED]> wrote:
>
> > > George Sakkis produced the following cookbook recipe,
> > > which addresses a common problem that comes up on this
> > > mailing list:
>
> > ISTM, this is a common mailing list problem because it is fun
> > to solve, not because people actually need it on a day-to-day basis.
>
> > In that spirit, it would be fun to compare several different
> > approaches to the same problem using re.finditer, itertools.groupby,
> > or the tokenize module.  To get the ball rolling, here is one variant:
>
> > from itertools import groupby
>
> > def blocks(s, start, end):
> > def classify(c, ingroup=[0], delim={start:2, end:3}):
> > result = delim.get(c, ingroup[0])
> > ingroup[0] = result in (1, 2)
> > return result
> > return [tuple(g) for k, g in groupby(s, classify) if k == 1]
>
> > print blocks('the  brown  jumped', start='<', end='>')
>
> > One observation is that groupby() is an enormously flexible tool.
> > Given a well crafted key= function, it makes short work of almost
> > any data partitioning problem.
>
> Can anyone suggest a function that will split text by paragraphs, but
> NOT if the paragraphs are contained within a [quote]...[/quote]
> construct.  In other words, the following text should yield 3 blocks
> not 6:
>
> TEXT = '''
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
> Pellentesque dolor quam, dignissim ornare, porta et,
> auctor eu, leo. Phasellus malesuada metus id magna.
>
> [quote]
> Only when flight shall soar
> not for its own sake only
> up into heaven's lonely
> silence, and be no more
>
> merely the lightly profiling,
> proudly successful tool,
> playmate of winds, beguiling
> time there, careless and cool:
>
> only when some pure Whither
> outweighs boyish insistence
> on the achieved machine
>
> will who has journeyed thither
> be, in that fading distance,
> all that his flight has been.
> [/quote]
>
> Integer urna nulla, tempus sit amet, ultrices interdum,
> rhoncus eget, ipsum. Cum sociis natoque penatibus et
> magnis dis parturient montes, nascetur ridiculus mus.
> '''
>
> Other info:
>
> * don't worry about nesting
> * the [quote] and [/quote] musn't be stripped.
>
> Gerard

(Sorry if I ruined the parent thread.) FWIW, I didn't get a groupby
solution but with some help from the Python Cookbook (O'Reilly), I
came up with the following:

import re

RE_START_BLOCK = re.compile('^\[[\w|\s]*\]$')
RE_END_BLOCK = re.compile('^\[/[\w|\s]*\]$')

def iter_blocks(lines):
block = []
inblock = False
for line in lines:
if line.isspace():
if inblock:
block.append(line)
elif block:
yield block
block = []
else:
if RE_START_BLOCK.match(line):
inblock = True
elif RE_END_BLOCK.match(line):
inblock = False
block.append(line.lstrip())
if block:
yield block

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


Re: Python 3000: Standard API for archives?

2007-06-04 Thread Chuck Rhode
samwyse wrote this on Mon, 04 Jun 2007 12:02:03 +.  My reply is
below.

> I think it would be a good thing if a standardized interface
> existed, similar to PEP 247.  This would make it easier for one
> script to access multiple types of archives, such as RAR, 7-Zip,
> ISO, etc.

Gee, it would be great to be able to open an archive member for update
I/O.  This is kind of hard to do now.  If it were possible, though, it
would obscure the difference between file directories and archives,
which would be kind of neat.  Furthermore, you could navigate archives
of archives (zips of tars and other abominations).

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 62° — Wind N 7 mph — Sky overcast. Mist.
-- 
http://mail.python.org/mailman/listinfo/python-list

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

2007-06-04 Thread Ross Ridge
Steve Howell  <[EMAIL PROTECTED]> wrote:
>I'm wondering if all the English keywords in Python
>would present too high a barrier for most Chinese
>people--def, if, while, for, sys, os, etc.  So you
>might need to go even further than simply allowing
>identifiers to be written in Simplified-Chinese.

Translating keywords and standard identifiers into Chinese could make
learning Python even more difficult.  It would probably make things
easier for new programmers, but I don't know if serious programmers would
actually prefer programming using Chinese keywords.  It would make their
Python implementations incompatible with the standard implementation, they
wouldn't be able to use third-party modules and their own code wouldn't
be portable.  If novice Chinese programmers would have to unlearn much
of they've learned in order to become serious Python programmers are
you really doing them a favour by teaching them Chinese Python?

It would really only work if Chinese Python became it own successful
dialect of Python, independent of the standard Python implementation.
Chinese Python programmers would be isolated from other Python
programmers, each with their own set of third-party modules and little
code sharing between the two groups.  I don't think this would be good
for Python as whole.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3000: Standard API for archives?

2007-06-04 Thread Tim Golden
Chuck Rhode wrote:
> samwyse wrote this on Mon, 04 Jun 2007 12:02:03 +.  My reply is
> below.
> 
>> I think it would be a good thing if a standardized interface
>> existed, similar to PEP 247.  This would make it easier for one
>> script to access multiple types of archives, such as RAR, 7-Zip,
>> ISO, etc.
> 
> Gee, it would be great to be able to open an archive member for update
> I/O.  This is kind of hard to do now.  If it were possible, though, it
> would obscure the difference between file directories and archives,
> which would be kind of neat.  Furthermore, you could navigate archives
> of archives (zips of tars and other abominations).

FWIW, there's no need to get hung on Python-3000 or
any other release. Just put something together a module
called "archive" or whatever, which exposes the kind of
API you're thinking of, offering support across zip, bz2
and whatever else you want. Put it up on the Cheeseshop,
announce it on c.l.py.ann and anywhere else which seems
apt. See if it gains traction. Take it from there.

NB This has the advantage that you can start small, say
with zip and bz2 support and maybe see if you get
contributions for less common formats, even via 3rd
party libs. If you were to try to get it into the stdlib
it would need to be much more fully specified up front,
I suspect.

TJG

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


Pyrex: problem with blanks in string

2007-06-04 Thread Hans Terlouw
Hi,

When trying to wrap C code using Pyrex, I encountered a strange problem with a 
piece of pure Python code. I tried to isolate the problem. The following code 
causes Pyrex to generate C code which gcc cannot compile:

class Axis:
axtype = "unknown type of axis"

def __init__(self):
   pass

When I substitute the blanks in the string for something else, then the problem 
disappears:

class Axis:
axtype = "unknown_type_of_axis"

def __init__(self):
   pass

Does anybody have an idea?

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


wxPython splitwindow with interpreter on bottom

2007-06-04 Thread chewie54
Hi all,

Does anyone know of an example of wxPython source code that shows how
to put a python shell (interpreter) in a bottom window with a
graphical application in the top window?

Thanks,

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


Embedding Python in C

2007-06-04 Thread mistabean
Hello,

first of all, I am a programming newbie, especially in python...

Onwards to the problem, I have been having difficulty embedding a
python module into my C/C++ program. (just a test program before
moving on into the real thing). I have been making test runs using the
codes from http://docs.python.org/ext/pure-embedding.html as a basic,
but modifiying it now as a function inside my C/C++ code.

Problem started when I started passing an array as an argument. The
module also need an array as an argument, but somehow I can't make
them to go pass the "input-error checking" of the module.

The code for argument building and calling are as follows:

void CallSnake(char ModName[], char FuncName[], double result[])
{
  ...
  /*Some operations to import modname, and preping FuncName, all is
ok*/
  ...
  /*Processing the result array and calling the function, problem
time*/
pArgs = PyTuple_New(MAX_ELEMENT);
pArg = PyList_New(1);
for (i = 0; i < MAX_ELEMENT; ++i)
{
 pValue = Py_BuildValue("d", result[i]);
 PyTuple_SetItem(pArgs, i, pValue);

 if (!(*pArgs).ob_refcnt)
 {
Py_DECREF(pArgs);
Py_DECREF(pModule);
fprintf(stderr, "Cannot convert argument\n");
return;
 }
 }

 PyList_SetItem(pArg, 0, pArgs);
 pValue = PyObject_CallFunctionObjArgs(pFunc,pArg,NULL);
   /*Some more checking and DECREFing occurs here*/
 }

Error I have been getting is:

Traceback
   if x.ndim != 1; /*x is the input array, checking if it's a 1D*/
AttributeError: 'list' object has no attribute 'ndim'

I have been trying many call variations, but alas, I think the problem
lies in the list building process. I have no problems calling a non-
arrayed (albeit,still single) argument.

Thanks in advance...

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


Re: python for EE CAD program

2007-06-04 Thread Diez B. Roggisch
> Hello Diez,
> 
> I did look at PythonCad but the distribution and install methods for
> Windows is not user freindly. Since the public domain software,  I
> don't think they protect the source code either.

The subject of code obfuscation in python has been beaten to death quite a
few times on this list, do a search to find anything you want to know.

In a nutshell: forget about it. it's not worth it, difficult to accomplish
due to the dynamic nature of python and to be brutally honest: more or less
nothing you can come up with in your own code is really worth looking at
anyway. That's not saying that you can't code, just that more or less
everything one programs is trivial and only of value in the actual context
it was written in. So nobody is really interested in ripping stuff out.

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


Re: Using pyTTS with other languages.

2007-06-04 Thread simon kagwe
  gmail.com> writes:

> It describes how to use mis-spelled words to force correct
> pronunciation as well as how to do it with XML.
> 
> Mike
> 

Thanks Mike. I had already read that article. I thought the mis-spelling and 
XML are meant to deal with pronunciation of English words. Will it really 
handle pronunciation of words of a whole new language? 
For example, if I want to say 'good' in Zulu, I may end up saying a word that 
has entirely different phenomes (and throw in some clicking sounds like in 
those 'God's must be crazy' movies). For my language, I have already collected 
recordings of its syllables and some words. I tried it out with pyTTS and it 
pronounces some words completely different they aren't even close to the way 
they should be. 


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


Re: python for EE CAD program

2007-06-04 Thread Grant Edwards
On 2007-06-04, chewie54 <[EMAIL PROTECTED]> wrote:

> 1) Can I use py2exe or pyinstaller to produce an executable
>for Linux, Windows, and Mac?  If not, is there a way it can be
>done?
>
> 2)  Is there any way to protect the source code,  like obfuscation?
>
> 3)  Memory footprint of application seems large for python demo. Is
> this typical for large python applications?

I'm glad somebody asked these questions.  I was getting
worried.  It's almost lunchime on Monday and they hadn't come
up yet this week.  :)

-- 
Grant Edwards   grante Yow! RHAPSODY in Glue!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


pychecker

2007-06-04 Thread puff
I'm new to pychecker.  Some of my code generates the following

 No class attribute (HWND) found

While HWND is not an attribute of the class, it IS an attribute of the
instance created (my class is one of several classes used to create
the new class).  Can I use __pychecker__ to selectively supress this
message?  How?

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


Re: Pyrex: problem with blanks in string

2007-06-04 Thread Michael Hoffman
Hans Terlouw wrote:

> When trying to wrap C code using Pyrex, I encountered a strange problem 
> with a piece of pure Python code. I tried to isolate the problem. The 
> following code causes Pyrex to generate C code which gcc cannot compile:

It works for me. Try posting your error messages and versions of 
Pyrex/Python/GCC. Better yet, do this in the Pyrex mailing list rather 
than here.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FAQ: how to vary the byte offset of a field of a ctypes.Structure

2007-06-04 Thread p . lavarre
> > http://docs.python.org/lib/module-pickle.html
> > ... concise Python ways of pickling and unpickling
> > the (0xFF ** N) possible ways of
> > packing N strings of byte lengths of 0..xFE together ...

Aye, looks like an exercise left open for the student to complete:

>>> pickle.dumps("")
"S''\np0\n."
>>>
>>> pickle.dumps("abc")
"S'abc'\np0\n."
>>>
>>> pickle.loads(pickle.dumps("abc"))
'abc'
>>>
>>> pickle.dumps(ctypes.c_ubyte(0))
...
TypeError: abstract class
>>>

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


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

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


Re: How do you htmlentities in Python

2007-06-04 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Adam Atlas  <[EMAIL PROTECTED]> wrote:
>As far as I know, there isn't a standard idiom to do this, but it's
>still a one-liner. Untested, but I think this should work:
>
>import re
>from htmlentitydefs import name2codepoint
>def htmlentitydecode(s):
>return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:
>name2codepoint[m.group(1)], s)
>

How strange that this doesn't appear in the Cookbook!  I'm
curious about how others think:  does such an item better 
belong in the Cookbook, or the Wiki?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you htmlentities in Python

2007-06-04 Thread Thomas Jollans
"Adam Atlas" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> As far as I know, there isn't a standard idiom to do this, but it's
> still a one-liner. Untested, but I think this should work:
>
> import re
> from htmlentitydefs import name2codepoint
> def htmlentitydecode(s):
>return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:
> name2codepoint[m.group(1)], s)
>

'&(%s);' won't quite work: HTML (and, I assume, SGML, but not XHTML being 
XML) allows you to skip the semicolon after the entity if it's followed by a 
white space (IIRC). Should this be respected, it looks more like this: 
r'&(%s)([;\s]|$)'

Also, this completely ignores non-name entities as also found in XML. (eg 
%x20; for ' ' or so) Maybe some part of the HTMLParser module is useful, I 
wouldn't know. IMHO, these particular batteries aren't too commonly needed.

Regards,
Thomas Jollans 


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


Re: python for EE CAD program

2007-06-04 Thread chewie54
On Jun 4, 10:58 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > Hello Diez,
>
> > I did look at PythonCad but the distribution and install methods for
> > Windows is not user freindly. Since the public domain software,  I
> > don't think they protect the source code either.
>
> The subject of code obfuscation in python has been beaten to death quite a
> few times on this list, do a search to find anything you want to know.
>
> In a nutshell: forget about it. it's not worth it, difficult to accomplish
> due to the dynamic nature of python and to be brutally honest: more or less
> nothing you can come up with in your own code is really worth looking at
> anyway. That's not saying that you can't code, just that more or less
> everything one programs is trivial and only of value in the actual context
> it was written in. So nobody is really interested in ripping stuff out.
>
> diez


Your opinions are noted, thank you,  but I don't agree with you.
There are
portions of the code that are under review for patents and as such
need to
be protected.

I'm investigating whether Python is the right language to use
for a commercial CAD application. While I think Python is a great
scripting
language, there seems to limitations with regards to packaging and
distributing
programs.







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


Re: magic names in python

2007-06-04 Thread Facundo Batista
Josiah Carlson wrote:

> I don't believe that there is a full list of all __magic__ methods.  The 
> operator module has a fairly extensive listing of functions that call 
> such methods, but I know that some have been left out.

There IS a full documentation of this special methods::

  http://docs.python.org/dev/ref/specialnames.html

Note that they're named "special", not "magic".

The phrase "I'm not a wizard, I just use Python" is one of the best,
ever.

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


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

2007-06-04 Thread Wildemar Wildenburger
Ross Ridge wrote:
> Translating keywords and standard identifiers into Chinese could make
> learning Python even more difficult.  It would probably make things
> easier for new programmers, but I don't know if serious programmers would
> actually prefer programming using Chinese keywords.  It would make their
> Python implementations incompatible with the standard implementation, they
> wouldn't be able to use third-party modules and their own code wouldn't
> be portable.  If novice Chinese programmers would have to unlearn much
> of they've learned in order to become serious Python programmers are
> you really doing them a favour by teaching them Chinese Python?
>
> It would really only work if Chinese Python became it own successful
> dialect of Python, independent of the standard Python implementation.
> Chinese Python programmers would be isolated from other Python
> programmers, each with their own set of third-party modules and little
> code sharing between the two groups.  I don't think this would be good
> for Python as whole.
>   
I don't see the problem here. The bytecode wouldn't change (right?). So 
what? One would have to make sure that the interprter understands both 
(or to generalize: all) language versions of python and wham! There you 
go. It would also be trivial to write a Chinese<->English source code 
translator (for key words; anything else of course isn't that simple).

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


Re: python for EE CAD program

2007-06-04 Thread Chris Mellon
On 6/4/07, chewie54 <[EMAIL PROTECTED]> wrote:
> On Jun 4, 10:58 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > > Hello Diez,
> >
> > > I did look at PythonCad but the distribution and install methods for
> > > Windows is not user freindly. Since the public domain software,  I
> > > don't think they protect the source code either.
> >
> > The subject of code obfuscation in python has been beaten to death quite a
> > few times on this list, do a search to find anything you want to know.
> >
> > In a nutshell: forget about it. it's not worth it, difficult to accomplish
> > due to the dynamic nature of python and to be brutally honest: more or less
> > nothing you can come up with in your own code is really worth looking at
> > anyway. That's not saying that you can't code, just that more or less
> > everything one programs is trivial and only of value in the actual context
> > it was written in. So nobody is really interested in ripping stuff out.
> >
> > diez
>
>
> Your opinions are noted, thank you,  but I don't agree with you.
> There are
> portions of the code that are under review for patents and as such
> need to
> be protected.
>

For the record: This is not true. If you've already applied for the
patent, you have as much legal protection as you will ever get. Also,
since patents apply to methods and not to literal source, if you're
trying to protect something patentable you have even less protection
against analysis and disassembly than you would if you were trying to
protect the copyright on the code. If you need to make a token effort
to satisfy whatever legal hurdles are involved, shipping .pyc files
(which py2exe and all the other packagers I'm aware of do) is just as
effective as shipping executables compiled with C or C++.

> I'm investigating whether Python is the right language to use
> for a commercial CAD application. While I think Python is a great
> scripting
> language, there seems to limitations with regards to packaging and
> distributing
> programs.
>

None that don't also exist in every other language in existence. These
are fundamental issues of information theory, not language
constraints.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python for EE CAD program

2007-06-04 Thread Grant Edwards
On 2007-06-04, Chris Mellon <[EMAIL PROTECTED]> wrote:

>> Your opinions are noted, thank you, but I don't agree with
>> you. There are portions of the code that are under review for
>> patents and as such need to be protected.
>
> For the record: This is not true. If you've already applied
> for the patent, you have as much legal protection as you will
> ever get. Also, since patents apply to methods and not to
> literal source, if you're trying to protect something
> patentable you have even less protection against analysis and
> disassembly than you would if you were trying to protect the
> copyright on the code. If you need to make a token effort to
> satisfy whatever legal hurdles are involved, shipping .pyc
> files (which py2exe and all the other packagers I'm aware of
> do) is just as effective as shipping executables compiled with
> C or C++.
>
>> I'm investigating whether Python is the right language to use
>> for a commercial CAD application. While I think Python is a
>> great scripting language, there seems to limitations with
>> regards to packaging and distributing programs.
>
> None that don't also exist in every other language in
> existence. These are fundamental issues of information theory,
> not language constraints.

Especially since the alternative appears to be Java.  Just like
Java, Python compiles to byte code that runs on a VM.

If for some reason he's happy shipping Java VM byte-code and
not Python VM byte-code, then he can use Jython to generate
byte-code for the Java VM instead of for the Python VM.
Personally I think it's rather deluded to think that one is any
more secure than the other.

-- 
Grant Edwards   grante Yow! What UNIVERSE is this,
  at   please??
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2007-06-04 Thread Steve Howell

--- olive <[EMAIL PROTECTED]> wrote:

> What is a "sharp hair boss" ?
> 

"Sharp hair boss" came out from my translation into
French of "pointy-haired boss."

Wikipedia tells me I should have said "Boss a tête de
pioche."  

Here are some links, if you've never had the pleasure
of reading Dilbert:

http://fr.wikipedia.org/wiki/Personnages_de_Dilbert

http://en.wikipedia.org/wiki/Pointy-Haired_Boss






 

Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front
-- 
http://mail.python.org/mailman/listinfo/python-list


Graph plotting module

2007-06-04 Thread Viewer T.
Is there a python module anywhere out there that can plot straight
line graphs, curves (quadratic, etc). If anyone knows where I can
download one, please let me know.

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


Re: How do you htmlentities in Python

2007-06-04 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Adam Atlas  <[EMAIL PROTECTED]> wrote:
>As far as I know, there isn't a standard idiom to do this, but it's
>still a one-liner. Untested, but I think this should work:
>
>import re
>from htmlentitydefs import name2codepoint
>def htmlentitydecode(s):
>return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:
>name2codepoint[m.group(1)], s)
>

A.  I *think* you meant
import re
from htmlentitydefs import name2codepoint
def htmlentitydecode(s):
return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m: 
chr(name2codepoint[m.group(1)]), s)
We're stretching the limits of what's comfortable
for me as a one-liner.
B.  How's it happen this isn't in the Cookbook?  I'm
curious about what other Pythoneers think:  is 
this better memorialized in the Cookbook or the
Wiki?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Jun 4)

2007-06-04 Thread Gabriel Genellina
QOTW:  "Stop thinking of three lines as 'extensive coding' and your problem
disappears immediately." - Steve Holden

"Hey, did you hear about the object-oriented version of COBOL?  They call
it 'ADD ONE TO COBOL'." - Tim Roberts


 EuroPython: Registration is open!
 
http://www.europython.org/sections/registration_issues/registration-open
 EuroPython in the Python411 Podcast Series
 
http://www.europython.org/sections/tracks_and_talks/announcements/europython-in-python411

Python 2.5 appears to give wrong results on Windows for file
creation/modification/last access time - but no, it's right,
although the differences are a bit hard to explain:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/890eef2197c6f045

http://groups.google.com/group/comp.lang.python/browse_thread/thread/2a73854b3f835d78

The right way to handle Unicode filenames, including Zip archives:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4d39da08fdddc48b/

The concept of "active exception" may be a bit obscure - see a great
clarification by Duncan Booth in this thread:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/74dc5145c2bb558b
However widely it's believed that items in a Tkinter listbox can't
be differentially colored, rfg007 knows better:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a7276ce6910019e5/

itertools.groupby is a great tool. Trying to improve the documentation,
contributors arrive at pleasing examples:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/7ef930186a8e5e4c/

What people like about Python, pitfalls, desired features, misfeatures,
all in a rather serious and objective thread called -of course- "Python
rocks!" :)

http://groups.google.com/group/comp.lang.python/browse_thread/thread/2a771ba3d329d57

Python and memory handling: why you don't notice the freed memory, why
one should not care, and details on the "small-object allocator"

http://groups.google.com/group/comp.lang.python/browse_thread/thread/5d3a5a37048e707e/

If you are concerned on how __special__ methods map onto the internal type
structures, or just curious about that, these comments may be useful:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e86275f51899b0a5/


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

The Python Papers aims to publish "the efforts of Python enthusiats".
http://pythonpapers.org/

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you

Re: How do you htmlentities in Python

2007-06-04 Thread Matimus
On Jun 4, 6:31 am, "js " <[EMAIL PROTECTED]> wrote:
> Hi list.
>
> If I'm not mistaken, in python, there's no standard library to convert
> html entities, like & or > into their applicable characters.
>
> htmlentitydefs provides maps that helps this conversion,
> but it's not a function so you have to write your own function
> make use of  htmlentitydefs, probably using regex or something.
>
> To me this seemed odd because python is known as
> 'Batteries Included' language.
>
> So my questions are
> 1. Why doesn't python have/need entity encoding/decoding?
> 2. Is there any idiom to do entity encode/decode in python?
>
> Thank you in advance.

I think this is the standard idiom:

>>> import xml.sax.saxutils as saxutils
>>> saxutils.escape("&")
'&'
>>> saxutils.unescape(">")
'>'
>>> saxutils.unescape("A bunch of text with entities: & > <")
'A bunch of text with entities: & > <'

Notice there is an optional parameter (a dict) that can be used to
define additional entities as well.

Matt

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


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

2007-06-04 Thread Ross Ridge
Ross Ridge wrote:
> Translating keywords and standard identifiers into Chinese could make
> learning Python even more difficult.  It would probably make things
> easier for new programmers, but I don't know if serious programmers would
> actually prefer programming using Chinese keywords.  It would make their
> Python implementations incompatible with the standard implementation, they
> wouldn't be able to use third-party modules and their own code wouldn't
> be portable.  If novice Chinese programmers would have to unlearn much
> of they've learned in order to become serious Python programmers are
> you really doing them a favour by teaching them Chinese Python?
>
> It would really only work if Chinese Python became it own successful
> dialect of Python, independent of the standard Python implementation.
> Chinese Python programmers would be isolated from other Python
> programmers, each with their own set of third-party modules and little
> code sharing between the two groups.  I don't think this would be good
> for Python as whole.
   
Wildemar Wildenburger  <[EMAIL PROTECTED]> wrote:
>I don't see the problem here. The bytecode wouldn't change (right?).

Python code generally isn't shared as bytecode and it's not just keywords
we're talking about here, all standard Python identifiers (eg. "os" and
"sys") would be translated too.

>So what? One would have to make sure that the interprter understands both 
>(or to generalize: all) language versions of python and wham!

That might work, you'd need both the standard and Chinese versions the
Python standard libraries.  I doubt anyone outside of China would want
a distribution that included both, so there would still be barriers to
code sharing between the two communities.

Interestingly, someone has already created a Chinese version of Python
much like Steve Howell suggested:

http://www.chinesepython.org/cgi_bin/cgb.cgi/home.html
http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html

Apparently it hasn't been updated in almost four years, so I don't know
much use it gets.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list


get_traceback

2007-06-04 Thread half . italian
Hi,

Is there a function or idoim for returning an exception/traceback
rather than just printing it to stdout?  I'm running a deamon where
stdout is going to /dev/null, and I'm not even watching it..until
now.  All the functions I found in traceback and sys seemed only to
print the error rather than just returning it, so I resorted to this:

def get_traceback():
import traceback, tempfile
stdout = sys.stdout

f = tempfile.TemporaryFile(mode='w+')
sys.stdout = f

traceback.print_tb(sys.exc_info()[2])
error = f.read()
f.close()

sys.stdout = stdout
return error

Whats the right function?!?  Thanks.

~Sean

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


webbrowser.open launches firefox in background

2007-06-04 Thread BartlebyScrivener
Hello,

On Debian Etch, when I use the webbrowser.open module to launch
firefox with a url, it opens UNDER gnome terminal in the background.

If I just launch firefox from the commandline, it opens in the
foreground.

Any ideas about why? Is there a command option I'm missing.

Thanks,

Rick

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


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

2007-06-04 Thread Roel Schroeven
olive schreef:
> Lol!
> 
> What is a "sharp hair boss" ?

Pointy-haired boss, see http://en.wikipedia.org/wiki/Pointy_Haired_Boss

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: python for EE CAD program

2007-06-04 Thread chewie54
On Jun 4, 12:47 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-06-04, Chris Mellon <[EMAIL PROTECTED]> wrote:
>
>
>
> >> Your opinions are noted, thank you, but I don't agree with
> >> you. There are portions of the code that are under review for
> >> patents and as such need to be protected.
>
> > For the record: This is not true. If you've already applied
> > for the patent, you have as much legal protection as you will
> > ever get. Also, since patents apply to methods and not to
> > literal source, if you're trying to protect something
> > patentable you have even less protection against analysis and
> > disassembly than you would if you were trying to protect the
> > copyright on the code. If you need to make a token effort to
> > satisfy whatever legal hurdles are involved, shipping .pyc
> > files (which py2exe and all the other packagers I'm aware of
> > do) is just as effective as shipping executables compiled with
> > C or C++.
>
> >> I'm investigating whether Python is the right language to use
> >> for a commercial CAD application. While I think Python is a
> >> great scripting language, there seems to limitations with
> >> regards to packaging and distributing programs.
>
> > None that don't also exist in every other language in
> > existence. These are fundamental issues of information theory,
> > not language constraints.
>
> Especially since the alternative appears to be Java.  Just like
> Java, Python compiles to byte code that runs on a VM.
>
> If for some reason he's happy shipping Java VM byte-code and
> not Python VM byte-code, then he can use Jython to generate
> byte-code for the Java VM instead of for the Python VM.
> Personally I think it's rather deluded to think that one is any
> more secure than the other.
>
> --
> Grant Edwards   grante Yow! What UNIVERSE is this,
>   at   please??
>visi.com


Honestly, thank you for your opinions and suggestions.  I know this
has been
discussed before on this forum, but after reading the discussions,
I'm still
unsure about question 1.  This is a big step and I want to make sure,
if
possible, I don't run into any show stoppers after many man hours of
work.

I will put the sensitive stuff and the datbase in a C extension and I
think that solves question 2 for me.





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


safe cgi parameter

2007-06-04 Thread Robin Becker
I'm trying to pass xml into a cgi script and have some problems because I both 
want to escape all my inputs (to avoid the possibility of an html injection 
attack) and also allow my xml to be obtained in its original form.

I thought of this

from xml.sax.saxutils import escape as xmlEscape
class SafeCgiParam(str):
def __new__(cls,v):
return str.__new__(cls,xmlEscape(v))
def __init__(self,v):
self.__raw__ = v


so

 >>> x=SafeCgiParam('a<&>b')
 >>> print x
a<&>b
 >>> print x.__raw__
a<&>b


ie always wrap the value, but access to the original is possible via __raw__.

However, if you do anything like x.strip() the original is lost. I'm not sure 
that's a bad thing, but I thought I would ask what others do for this problem.
-- 
Robin Becker

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


  1   2   >