Re: What do you use as symbols for Python ?

2005-11-09 Thread Erik Max Francis
Pierre Barbier de Reuille wrote:

> When you need some symbols in your program, what do you use in Python ?
> 
> For example, an object get a state. This state is more readable if
> expressed as a symbols, for example "opened", "closed", "error".
> Typically, in C or C++, I would use an enum for that:
> enum OBJECT_STATE
> {
>   opened, closed, error
> }

OPENED, CLOSED, ERROR = range(3)

object.state = OPENED

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Whoever named it necking was a poor judge of anatomy.
   -- Groucho Marx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread George Sakkis
"Steve Holden" <[EMAIL PROTECTED]> wrote:

> George Sakkis wrote:
> > Itertools is your friend in this case:
> >
> from itertools import takewhile
> list(takewhile(p, xrange(1000)))
> >
> > [0, 1]
>
> Maybe, but the code also implies an esoteric knowledge that the trught
> value of the predicate is monotonically decreasing (in a Boolean sense).
> This would not be true if (e.g.) p = lambda x: x % 2 == 0. So while
> itertools.takewhile can save you unnecessary computations, such savings
> rely on provable conditions of the predicate which are frequently false.

Right, it wasn't intended as a general solution for any p. For p =
lambda x: x % 2 == 0, you do have to iterate till the iterator is
consumed anyway, so a list comprehension is not less efficient (unless
you replaced it with xrange(0,1000,2), which again implies an
esoteric knowledge of p; as usually, there's no free meal).

George

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


What do you use as symbols for Python ?

2005-11-09 Thread Pierre Barbier de Reuille
When you need some symbols in your program, what do you use in Python ?

For example, an object get a state. This state is more readable if
expressed as a symbols, for example "opened", "closed", "error".
Typically, in C or C++, I would use an enum for that:
enum OBJECT_STATE
{
  opened, closed, error
}

In CAML or Haskell I would use the union types:

type ObjectState = Opened | Closed | Error

In Ruby I would use the symbols :

object.state = :opened
object.state = :closed
object.state = :error

... but I don't know what to use in Python !

Thanks,

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


Re: which feature of python do you like most?

2005-11-09 Thread egbert
python is almost pseudocode, 
so much so that you don't need pseudocode anymore.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

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


Re: How to set program name in Python? ($0 in Perl)

2005-11-09 Thread Steve Holden
Fredrik Lundh wrote:
> Steve Holden wrote:
> 
> 
>>>Is there a way to set the program name in Python, similar to $0 in
>>>Perl?
>>>
From `man perlvar`:
>>>
>>>$0  Contains the name of the program being executed.  On some oper-
>>>   ating systems assigning to "$0" modifies the argument
>>>area that
>>>   the ps program sees.  This is more useful as a way of
>>>indicat-
>>>   ing the current program state than it is for hiding the
>>>program
>>>   you're running.  (Mnemonic: same as sh and ksh.)
> 
> 
>>import sys
>>print sys.argv[0]
> 
> 
> that *gets* the name, but assigning to sys.argv[0] doesn't *set* it (afaik).
> 
> setting the name involves overwriting the C level argv array, several large
> buckets of worms, and huge portability issues, and is thus better left to non-
> standard extensions.
> 
Indeed. My bad.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: How to set program name in Python? ($0 in Perl)

2005-11-09 Thread Fredrik Lundh
Steve Holden wrote:

> > Is there a way to set the program name in Python, similar to $0 in
> > Perl?
> >
> >>From `man perlvar`:
> >
> > $0  Contains the name of the program being executed.  On some oper-
> >ating systems assigning to "$0" modifies the argument
> > area that
> >the ps program sees.  This is more useful as a way of
> > indicat-
> >ing the current program state than it is for hiding the
> > program
> >you're running.  (Mnemonic: same as sh and ksh.)

> import sys
> print sys.argv[0]

that *gets* the name, but assigning to sys.argv[0] doesn't *set* it (afaik).

setting the name involves overwriting the C level argv array, several large
buckets of worms, and huge portability issues, and is thus better left to non-
standard extensions.





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


Re: How to set program name in Python? ($0 in Perl)

2005-11-09 Thread Steve Holden
Swaroop C H wrote:
> Hi,
> 
> Is there a way to set the program name in Python, similar to $0 in
> Perl?
> 
>>From `man perlvar`:
> 
> $0  Contains the name of the program being executed.  On some oper-
>ating systems assigning to "$0" modifies the argument
> area that
>the ps program sees.  This is more useful as a way of
> indicat-
>ing the current program state than it is for hiding the
> program
>you're running.  (Mnemonic: same as sh and ksh.)
> 
> 
> 
> Thanks!
> Swaroop
> www.swaroopch.info
> 

import sys
print sys.argv[0]

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Addressing the last element of a list

2005-11-09 Thread Donn Cave
Quoth Steven D'Aprano <[EMAIL PROTECTED]>:
...
| So when working with ints, strs or other immutable objects, you aren't
| modifying the objects in place, you are rebinding the name to another
| object:
|
| py> spam = "a tasty meat-like food"
| py> alias = spam  # both names point to the same str object
| py> spam = "spam spam spam spam"  # rebinds name to new str object
| py> print spam, alias
| 'spam spam spam spam' 'a tasty meat-like food'

The semantics of assignment are like that, period.  If the right hand
side is an int, a string, a class instance, a list, whatever, doesn't
matter at all.  The question of mutability at this point can be a red
herring for someone who doesn't already understand these matters.

Mutability is nothing special, it's just a feature built into the
object type -- in general, the ability to store some state.  This
is of course useful in situations where we want to propagate state
changes, so it naturally comes up in this context, but language per
se does not observe any distinction here so far as I know.

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.minidom and user defined entities

2005-11-09 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>  Nick Craig-Wood wrote:
> 
> > I'm using xml.minidom to parse some of our XML files.  Some of these
> > have entities like "°" in which aren't understood by xml.minidom.
> 
>  ° is not a standard entity in XML (see below).

No probably not...

> > These give this error.
> >
> >  xml.parsers.expat.ExpatError: undefined entity: line 12, column 1
> >
> > Does anyone know how to add entities when using xml.minidom?
> 
>  the document is supposed to contain the necessary entity declarations
>  as an inline DTD, or contain a reference to an external DTD.  (iirc, mini-
>  dom only supports inline DTDs, but that may have been fixed in recent
>  versions).

The document doesn't define the entitys either internally or
externally.  I don't fancy adding an inline definition either as there
are 100s of documents I need to process!

>  if you don't have a DTD, your document is broken (if so, and the set of
>  entities is known, you can use re.sub to fix replace unknown entities with
>  the corresponding characters before parsing.  let me know if you want
>  sample code).

I was kind of hoping I could poke my extra entities into some dict or
other in the guts of xml.minidom...

However the job demands quick and nasty rather than elegant so I'll go
for the regexp solution I think, as the list of entities is well
defined.

Thanks for your help

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


ANN: P(x) 0.2 applet builder

2005-11-09 Thread Mike Meyer
P(x) is hard to describe. It might be called a "Framework", but that's
a grandiose word for a couple of hundred lines of code. It might be
called a programmable calculator, but it has none of the things one
associates with calculators. It might be called a programming
language, but it's just Python some extra builtins. So I settled
on "applet builder".

A P(x) applet has a set of input variables, a set of output variables,
and a function that calculates the latter from the former. P(x)
provides the GUI to let the user enter input variables and read and
copy output variables. The current implementation restricts the
variables to integers, strings and floats. Examples include
temperature converters and a numerical integration tool.

The tarball can be found at http://www.mired.org/downloads/P(x)-0.2.tar.gz >.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python obfuscation

2005-11-09 Thread The Eternal Squire
Two things:

1) The decrypted modules should only reside in RAM, never in virtual
memory.  Those RAM locations should be rendered inaccessible to Python
code.

2) Only sell to an honest customer willing to be locked into
nondisclosure agreements.  This goes back to the maxim of good
salesmanship:  Know Your Customer.

By definition, a lock keeps honest people out.  The object of a lock is
to make it too expensive for all but the most dishonest, desperate, or
nihilistic to get into the house, because they can always smash a
window or a door open.

IMHO, I have never encountered a dishonest developer or business owner
who at the same time possessed anything remotely resembling a rational
business model.   A person who cannot afford to get tools honestly is
seldom able to accomplish anything significant or constructive from a
business point of view with tools obtained dishonestly.

Consider EDA software like Cadence, Matlab, or BEACON that is guarded
by network license servers.   The temptation is very strong for an
individual to rip it off, but then consider all the user technical
support and bug fixes that go into the package.  Most relatively honest
people see a strong lock and get the message not to try.   The others
who may rip off a locked package, but then the package becomes
worthless not because it doesn't work, but because the thief has to
work completely outside the knowledge base that an honest copy has
access to.

I have heard of the warez culture, but it seems to be nihilistic in the
extreme.  I don't search for warez, I don't touch warez, and I do not
recommend anyone else to do so, because using it is simply bad business
practice and will get one ostracised by the very people one wants to
sell to.   But at the end of the day it seems to serve as an
unauthorized marketing and sales channel to whet the appetites for
people to try the real thing. 

The Eternal Squire

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


Re: Floating numbers and str

2005-11-09 Thread Christian Stapfer
"Tuvas" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
>
>
> x=.13241414515
> y=str(x)+" something here"
>
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do something like %.4d, but how can I do this
> with converting the number to a string? Thanks!

from scipy import round

print round(0.13241414515,4)

Regards,
Christian



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


Re: need an example of Python numarray to C++ and back again, Boost / SWIG?

2005-11-09 Thread Fernando Perez
PL wrote:

> I want to pass a 2D array from Python to C++, manipulate it in C++ (for
> example, add 1 to each element) and pass it back to Python.
> 
> With these building blocks I will be able to figure out all the rest of
> what I need to do for my project.  I am very familiar with Python, but
> less so with C++ and Boost or SWIG.
> 
> Does anyone have an example with all steps that I can follow?  More
> specifically I am looking for the C++ code, ".i" file for SWIG and/or
> the analagous setup files that Boost would need to do this.

You may want to look into weave.inline or weave.blitz, from scipy.  Typemaps for
conversion to blitz++ were recently posted on the scipy list:

http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/2883831

In particular look at Stefan's post.

For info on weave, here you can find some old slides and example code:

http://amath.colorado.edu/faculty/fperez/python/

Cheers,

f

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


Re: Iterator addition

2005-11-09 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes:
> > Is there a good reason to not define iter1+iter2 to be the same as

> If you mean for *ALL* built-in types, such as generators, lists, files,
> dicts, etc, etc -- I'm not so sure.

Yes, that's what I mean.

> Right now, if I mistakenly try to add a list to a dict, I get an
> exception which immediately alerts me to my mistake.  I definitely
> wouldn't want to lose that...

Hmm, there might also be __add__ operations on the objects, that would
have to take precedence over iterator addition.  Iterator addition
itself would have to be a special kludge like figuring out "<" from
__cmp__, etc.

Yeah, I guess the idea doesn't work out that well.  Oh well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterator addition

2005-11-09 Thread Alex Martelli
Paul Rubin  wrote:

> Is there a good reason to not define iter1+iter2 to be the same as
> itertools.chain(iter1, iter2)?

No -- feel free to define __add__ accordingly in every one of your
iterator classes.

If you mean for *ALL* built-in types, such as generators, lists, files,
dicts, etc, etc -- I'm not so sure.  Right now, if I mistakenly try to
add a list to a dict, I get an exception which immediately alerts me to
my mistake.  I definitely wouldn't want to lose that...


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


Iterator addition

2005-11-09 Thread Paul Rubin
Is there a good reason to not define iter1+iter2 to be the same as
itertools.chain(iter1, iter2)?

Examples:

   # all lines in a collection of files, like perl <>
   all_lines = file1 + file2 + file3

   candidate_primes = (2,) + (1+2*i for i in itertools.count(1))
   # candidate_primes is 2,3,5,7,9,11,...
   primes = itertools.ifilter(is_prime, candidate_primes)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gmpy 1.01 rc near... anybody wanna test>

2005-11-09 Thread casevh
> > Will you be updating the information in setup.py file?
>
> Done, in the current CVS version.

I will grab the CVS version and create installers.

> > Which versions of Python do you want to support?
>
> I have tested gmpy with 2.3 and 2.4 on Mac, and those two and also 2.2
> on Linux.  I think supporting 2.2 with a Windows download is probably
> unneeded, but 2.4 is a must and I suspect 2.3 would be nice...

I will definately build for 2.3 and 2.4.

>
> > Do you want versions that include GMP tailored for specific processors?
>
> My gut reaction here is that people with special processors, Windows,
> and demanding performance needs should probably get their own
> development environments and build GMP and gmpy accordingly.
>
> Any opinions from the public on this one...?

Unless there is a demand for compatibilty with older processors
(Pentium, Pentium Pro, Pentium II), I will build for Pentium 3.

>
> > With GMP 4.1.4 compiled for pentium3, and running on a 1.8Ghz Pentium
> > M, I'm able to calculate the decimal form of 2^25964951 (the 43rd
> > Mersenne prime) in 10 seconds. The prior gmpy release takes just over
> > 14 seconds. Without gmpy, Python takes 25.4 seconds. On an Athlon
> > MP2800+ (2.133Ghz) with GMP compiled for that processor, I can do it in
> > 6.6 seconds using gmpy and 22.4 seconds without gmpy. I'm working with
> > blocks of 1000 digits and using a combination of Toom-Cook and
> > Nussbaumer convolution to perform the multiplies and squares.
>
> Sounds quite decent -- about a 2.5 to 3+ times speedup wrt Python, and
> some speedup wrt gmpy 1.0 (all GMP's merit -- I didn't address
> performance aspects at all in this delta).  Just out of curiosity: what
> performance do you get on the Athlon with a pentium3-compiled GMP?
>
I'll try to find out. Unfortunately, my Athlon box won't run Windows.
;-)

> Thanks,
> 
> Alex

You're welcome,

Case

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


Re: ANN: Wing IDE for Python 2.0.4 released

2005-11-09 Thread AllenDang
Thanks!
Learning how to write a templateI also think the macro script
is a big fun.

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread [EMAIL PROTECTED]

George Sakkis wrote:
> >>> list(takewhile(p, xrange(1000)))
> [0, 1]
thanks. that is what I am doing now, in a more generic form :

takewhile(p, (x for x in xrange(1)))

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread Steve Holden
George Sakkis wrote:
> "[EMAIL PROTECTED]" wrote:
> 
> 
>>Alex Martelli wrote:
>>
>>>This becomes a valid list comprehension by writing 'if' instead of
>>>'when'.
>>
>>valid, yes. efficient, I am not sure.
>>
>>[ x for x in xrange(1000) if p(x) ]
>>
>>means I need to go through the whole range even if p = lambda x: x < 2
> 
> 
> Itertools is your friend in this case:
> 
from itertools import takewhile
list(takewhile(p, xrange(1000)))
> 
> [0, 1]

Maybe, but the code also implies an esoteric knowledge that the trught 
value of the predicate is monotonically decreasing (in a Boolean sense). 
This would not be true if (e.g.) p = lambda x: x % 2 == 0. So while 
itertools.takewhile can save you unnecessary computations, such savings 
rely on provable conditions of the predicate which are frequently false.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread [EMAIL PROTECTED]
I just try to use list/generator expression when possible and found I
need dropwhile/takewhile from time to time and see if there will be a
construct like this.

As I sort of think that the language in general encouraging this
style(like the talk about dropping map/filter/reduce).

Alex Martelli wrote:
> Of course, barring semantically-very-deep optimizations (ones no
> production implementation I know of ANY language would even try).  And,
> your POINT would be...?
> 
> 
> Alex

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread George Sakkis
"[EMAIL PROTECTED]" wrote:

> Alex Martelli wrote:
> > This becomes a valid list comprehension by writing 'if' instead of
> > 'when'.
>
> valid, yes. efficient, I am not sure.
>
> [ x for x in xrange(1000) if p(x) ]
>
> means I need to go through the whole range even if p = lambda x: x < 2

Itertools is your friend in this case:
>>> from itertools import takewhile
>>> list(takewhile(p, xrange(1000)))
[0, 1]

George

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread [EMAIL PROTECTED]
I thought I read some where there these are intended to be dropped(or
at least moved out of built-in) ?

George Sakkis wrote:
> What about the future of itertools in python 3K ? IIRC, several
> functions and methods that currently return lists are going to return
> iterators. Could this imply that itertools.(imap/ifilter/izip) will
> take the place of map/filter/zip as builtins ?
> 
> George

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > This becomes a valid list comprehension by writing 'if' instead of
> > 'when'.
> valid, yes. efficient, I am not sure.
> 
> [ x for x in xrange(1000) if p(x) ]
> 
> means I need to go through the whole range even if p = lambda x: x < 2.

Of course, barring semantically-very-deep optimizations (ones no
production implementation I know of ANY language would even try).  And,
your POINT would be...?


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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread Alex Martelli
George Sakkis <[EMAIL PROTECTED]> wrote:
   ...
> > > FP functions like dropwhile/takewhile etc.
> >
> > No way -- the itertools module is and remains a PRECIOUS resource.
> > If you want an iterator rather than a list, itertools.ifilter is quite
> > appropriate here.
> 
> What about the future of itertools in python 3K ? IIRC, several
> functions and methods that currently return lists are going to return
> iterators. Could this imply that itertools.(imap/ifilter/izip) will
> take the place of map/filter/zip as builtins ?

I think the builtin namespace shouldn't get too crowded.  But what I
think matters little -- what __GvR__ thinks is more important...!-)


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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread [EMAIL PROTECTED]

Alex Martelli wrote:
> This becomes a valid list comprehension by writing 'if' instead of
> 'when'.
valid, yes. efficient, I am not sure.

[ x for x in xrange(1000) if p(x) ]

means I need to go through the whole range even if p = lambda x: x < 2.

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread George Sakkis

"Alex Martelli" wrote:

> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > FP functions like dropwhile/takewhile etc.
>
> No way -- the itertools module is and remains a PRECIOUS resource.
> If you want an iterator rather than a list, itertools.ifilter is quite
> appropriate here.

What about the future of itertools in python 3K ? IIRC, several
functions and methods that currently return lists are going to return
iterators. Could this imply that itertools.(imap/ifilter/izip) will
take the place of map/filter/zip as builtins ?

George

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread Jay Parlar

On Nov 9, 2005, at 7:30 PM, Alex Martelli wrote:

> No way -- the itertools module is and remains a PRECIOUS resource.  If
> you want an iterator rather than a list, itertools.ifilter is quite
> appropriate here.

Or if you're on 2.4 and want an iterator:

(x for x in xrange(10) if p(x))

Jay P.

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


Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I am wondering if there is such a thing, as python is moving away from

This becomes a valid list comprehension by writing 'if' instead of
'when'.

> FP functions like dropwhile/takewhile etc.

No way -- the itertools module is and remains a PRECIOUS resource.  If
you want an iterator rather than a list, itertools.ifilter is quite
appropriate here.


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


Re: gmpy 1.01 rc near... anybody wanna test>

2005-11-09 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> I made a successful installer for Windows using Mingw32 and Python 2.4.

Great, thanks.

> I needed to edit setup.py to list gmp as a required library.
> 
> if sys.version.find('MSC')==-1:
> gmpy_ext = Extension('gmpy', sources=['src/gmpy.c'],
> # library_dirs=['/usr/local/lib'],
> libraries=['gmp'])
> else:
> gmpy_ext = Extension('gmpy', sources=['src/gmpy.c'],
> include_dirs=['./src'],
> libraries=['gmp'])# I added libraries!
> 
> Will you be updating the information in setup.py file?

Done, in the current CVS version.

> Tomorrow, I'll recreate my build process on another computer. I am
> willing to create Windows installers.

Wonderful!

> Which versions of Python do you want to support?

I have tested gmpy with 2.3 and 2.4 on Mac, and those two and also 2.2
on Linux.  I think supporting 2.2 with a Windows download is probably
unneeded, but 2.4 is a must and I suspect 2.3 would be nice...

> Do you want versions that include GMP tailored for specific processors?

My gut reaction here is that people with special processors, Windows,
and demanding performance needs should probably get their own
development environments and build GMP and gmpy accordingly.

Any opinions from the public on this one...?

> With GMP 4.1.4 compiled for pentium3, and running on a 1.8Ghz Pentium
> M, I'm able to calculate the decimal form of 2^25964951 (the 43rd
> Mersenne prime) in 10 seconds. The prior gmpy release takes just over
> 14 seconds. Without gmpy, Python takes 25.4 seconds. On an Athlon
> MP2800+ (2.133Ghz) with GMP compiled for that processor, I can do it in
> 6.6 seconds using gmpy and 22.4 seconds without gmpy. I'm working with
> blocks of 1000 digits and using a combination of Toom-Cook and
> Nussbaumer convolution to perform the multiplies and squares.

Sounds quite decent -- about a 2.5 to 3+ times speedup wrt Python, and
some speedup wrt gmpy 1.0 (all GMP's merit -- I didn't address
performance aspects at all in this delta).  Just out of curiosity: what
performance do you get on the Athlon with a pentium3-compiled GMP?

 
> I did very that the tp_compare errors are fixed. I removed the warnings
> filter in my code and the warning did occur with the old gmpy but did
> not occur with my version.

Excellent.  Sounds like an "all systems go"...!-)


Thanks,

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


ANN: Wing IDE for Python 2.0.4 released

2005-11-09 Thread sdeibel
Hi,

Wing IDE for Python 2.0.4 has been released.  This is a bugfix 
release and is a free upgrade for Wing IDE 2.0 users.  It
can be downloaded from:

http://wingware.com/downloads

Highlights of this release include:

* Preference for syntax highlighting colors in Python, C/C++,
and Java files
* Support for Zope 2.8 and gtk 2.8
* Modest improvements in search performance
* Template panel is part of default tool set (Wing Pro only)
* Over 40 bug fixes

This release is available for Windows, Linux, and Mac OS X, and
can be compiled from sources on *BSD, Solaris, and other Posix
operating systems.

A complete list of changes is available here:

http://wingware.com/pub/wingide/2.0.4/CHANGELOG.txt

For more information see:

Product Info:   http://wingware.com/products
Sales:  http://wingware.com/store/purchase
Upgrades:   http://wingware.com/store/upgrade

Sincerely,

Stephan Deibel

--
Wingware
Wing IDE for Python
Advancing Software Development

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


[ x for x in xrange(10) when p(x) ]

2005-11-09 Thread [EMAIL PROTECTED]
Hi,

I am wondering if there is such a thing, as python is moving away from
FP functions like dropwhile/takewhile etc.

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


Re: Python obfuscation

2005-11-09 Thread Alex Martelli
Anand S Bisen <[EMAIL PROTECTED]> wrote:

> I dont know much !! But if somebody asks me this question my answer 
> would be to convert some of the meat inside my programs to C/C++ and 
> then provide the interface to those novel ideas to Python using swig.
> And for another level of protection maybe use these offuscator on the
> remaining Python source. What do you think ?

I think that's feeble protection.  If you have valuable code, and
distribute it, people WILL crack it -- just check the warez sites for
experimental proof... EVERYTHING that people are really interested in
DOES get cracked, no matter what tricky machine-code the "protections"
are coded in.

There's ONE way to have uncrackable code -- don't distribute it, but
rather put it up on the net on a well-secured machine under your
control, available as (say) a webservice (subscription-only, pay per
use, or whatever business model you want).  You can distribute all the
parts of your app that aren't worth protecting as a "fat client" app (in
Python or whatever) and keep those which ARE worth protecting on the
server that YOU control (and make sure it's very, VERY safe, of course);
and you may write the precious parts in Python, too, no problem.

This is (a minor) one of the many reasons that make webservices the way
of the future (hey, even *MSFT* noticed that recently, it seems...).
There are many other advantages, especially if you keep the clients
thin.  The only issue is, your apps will require network connectivity to
execute... but these days, with airlines and train lines busy adding
wi-fi, and towns busily blanketing themselves with free wi-fi, etc, etc,
that's less and less likely to be a big problem...


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


Re: Newb ??

2005-11-09 Thread Alex Martelli
Norman Silverstone <[EMAIL PROTECTED]> wrote:
   ...
> challenging. What I am thinking about at the moment is how to program for
> the computer to guess the number which I select. I know it can be done but
> I suspect it requires an approach which I have not yet learnt. I would
> welcome suggestions on the best way to approach this problem.

I assume the way the computer is going to guess is by trying some
number, and you respond either that it's guessed right, or to go lower,
or to go higher.

In that case, think of "bisection".  Originally, all the computer knows
is that the number is in some range, say 0 to 100.  It can then guess
the midpoint, 50.  If it's right, yay!  Otherwise: if it's told to go
lower, then the range is now 0 to 49 -- if higher, it's 51 to 100; in
each case the range was just halved (actually, a bit more than halved).

It does not take many halvings to squeeze even a pretty large original
range down to a range which only includes one possible number... that's
because "2 to the power of N" grows VERY fast with N, as the old story
about the inventor of chess shows (the king told him to ask for a
reward, and all he wanted was some rice -- one grain on the first cell
of the chessboard, two on the next, then four, eight... all the way
through the 64 squares of the board; the kind thought the inventor was
being very moderate in his request, and granted it... to soon find out
that not enough rice existed in the world to satisfy the request...;-).

Well, repeated halving is just like repeated doubling "backwards", so it
squeezes vast ranges of possibilities down to tiny ones just as fast as
repeated doubling produces oceans of rice from a small chessboard;-).


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


Re: Newb ??

2005-11-09 Thread Chad Everett
Hey guys,

Thanks for your help.  I am glad to know there is a community out there 
willing to put the effort out to help us newbies.  I will work on it.  Some 
of the suggestions are things that I have not covered yet but I am sure I 
will figure it out.

Thanks again.

I am sure I will be back with more questions before too long.

Chad


"Chad Everett" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi all,  I am new to the group.  Trying to learn Python programming on my 
> own.  I am working through Michael Dawson's Book Python Programming for 
> the absolute beginner.
>
> I am tring to write a program that is a number guessing game.  I want to 
> be able to give the user 5 tries to guess the number before the program 
> ends.
>
> I get the result that I want when the user misses after the 5th try.  But 
> it does not go down to my closing statement to end.  Rather is askes for 
> another guess.
>
> I appreciate any help you can give.  If  this is not the correct group for 
> these types of questions, I apologize and hope that you can direct me to 
> another NG.
>
> Thanks,
> Chad
>
> import random
>
> print "\tWelcome to 'Guess my Number'!"
> print "\nI'm Thinking of a Number between 1 and 100."
> print "\nTry to Guess it in as few attempts as possible.\n"
>
> #Set the initial values
> the_number = random.randrange(100) + 1
> guess = int(raw_input("Take a guess:"))
> tries = 1
>
> #Guessing Loop
>
> while (guess != the_number):
>if (guess >the_number):
>print "Lower..."
>else:
>print "Higher..."
>guess = int(raw_input("Take another Guess:"))
>tries +=1
>if tries == 5:
> print "Sorry you lose."
> print "The Correct Number was ", the_number
>
>
> print "You guess correctly!!"
> print "The number was:", the_number
> print "You got it correct in", tries, "tries"
>
> raw_input("Press Enter to exit the program")
> 


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


Re: Looking Python script to compare two files

2005-11-09 Thread david
Hello Tim:

One more thing:

There some Python scripts that can extract text from PDF or WORD file?

Thx

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


Re: Looking Python script to compare two files

2005-11-09 Thread david
Hello Tim:

One more thing:

There some Python scripts that can extract text from PDF or WORD file?

Thx

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


Re: Looking Python script to compare two files

2005-11-09 Thread david
Hello Tim:

One more thing:

There some Python scripts that can extract text from PDF or WORD file?

Thx

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


Re: Pythonising the vim (e.g. syntax popups) -> vimpst

2005-11-09 Thread Jeffrey Schwab
Roman Roelofsen wrote:
>>Evening,
>>
>>Is there a decent way to get that help into vim? Or like showing docstrings
>>or help that I get through pydoc on request? I've been working myself
>>through a pile of vim macros/plugins but couldn't find even one which
>>simplifies programming in Python. Further issues would be handling the
> 
> 
> Hi Christoph,
> Hi Vim users,
> 
> The last 5 days I´ve been working on a code-completion/calltips plugin for 
> vim. It´s working pretty good but not finished yet. I will anounce the first 
> beta version on this mailling list. I hope during the next week.
> 
> I recorded a swf-video so that you can take a look at the current status.
> Link: http://www.tuxed.de/vimpst/video.tar.gz
> 
> Note that it is not necessary to generate symboltable files, etc. Everything 
> is done "on demand". It is even possible to change the python implementation 
> e.g. CPython, Jython, IronPython.
> 
> It is also possible to add some "special feature" interceptor. Currently this 
> is working for SQLObject:
> Lets say you have the class User and the attribute username is a alternate ID.
> Then, the method User.byUsername("...") will always return a User object. 
> vimpst checks this and provides a suitable help.

Right on!  Good luck!  Can't wait!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking Python script to compare two files

2005-11-09 Thread david
Hello Tim:

Thanks for your reply!
I want to compare PDF-PDF files and WORD-WORD files.

It seems that the right way is :
First, extract text from PDF file or Word file.
Then, use Difflib to compare these text files.

Would you please give me some more information about the external diff
tools?

Thx!

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


Re: Sending email in utf-8?

2005-11-09 Thread morphex
By turning everything into unicode objects (unicode(string)) and then
running body.encode('utf-8') and using quoted printable, it works.

Thanks for all the help, it's really appreciated!

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


Re: XML GUI

2005-11-09 Thread William Park
py <[EMAIL PROTECTED]> wrote:
> Looking for information on creating a GUI using a configuration file
> (like an XML file or something).  Also, how do you map actions (button
> clicks, menu selections, etc) to the XML?
> 
> Any other suggestions for building GUI's for Python projects...even
> Jython.

If you're talking about simple "dialog" thing, where you ask question
and users respond, then take a look at
http://home.eol.ca/~parkw/index.html#gtk

Also, you may want to look at Glade which spits out the layout in XML.

But, for more intricate to-and-fro, use C and GTK+2. :-)

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to identify a particular directory / file on remote machine

2005-11-09 Thread Mike Meyer
"Swarna" <[EMAIL PROTECTED]> writes:

> Hi all,
>
> I am trying to find out whether a particular directory is present on a
> remote machine or not from my local Python script in Linux . Can anyone
> help me with the command that i need to issue to os.system in my python
> script to acheive this?

Lots of possibilities, depending on whats running on the remote
machine. My first try would be to use os.popen (or the subprocess
module) and read the output of an "ssh remotemachine ls -d /path/to/dir".

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating numbers and str

2005-11-09 Thread Jeffrey Schwab
Tuvas wrote:
> Wait, one more question. If the number is something like:
> 
> 1.32042
> 
> It is like
> "1.32 stuff"
> 
> I would like it's size to remain constant. Any way around this?

s/%g/%f

 >>> print "%.4f stuff" % 1.3241414515
1.3241 stuff
 >>> print "%.4f stuff" % 1.32042
1.3204 stuff
 >>>
-- 
http://mail.python.org/mailman/listinfo/python-list


how to identify a particular directory / file on remote machine

2005-11-09 Thread Swarna
Hi all,

I am trying to find out whether a particular directory is present on a
remote machine or not from my local Python script in Linux . Can anyone
help me with the command that i need to issue to os.system in my python
script to acheive this?

Thanks, for all your time !

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


Re: parse data

2005-11-09 Thread Larry Bates
py wrote:
> I have some data (in a string) such as
> 
> person number 1
> 
> Name: bob
> Age: 50
> 
> 
> person number 2
> 
> Name: jim
> Age: 39
> 
> ...all that is stored in a string.  I need to pull out the names of the
> different people and put them in a list or something.  Any
> suggestions...besides doing data.index("name")...over and over?
> 
> thanks!
> 
Something like this works if line spacing can be depended on.
Also a good way to hide the actual format of the string from your
main program.

Larry Bates

class personClass:
def __init__(self, nameline, ageline):
self.name=nameline.split(':')[1].strip()
self.age=int(ageline.split(':')[1].strip())
return

class peopleClass:
def __init__(self, initialstring):
#
# Define a list where I can store people
#
self.peoplelist=[]
self.next_index=0
#
# Split the initial string on newlines
#
lines=initialstring.split('\n')
#
# Loop over the lines separating the people out
#
while 1:
lines.pop(0)   # Throw away the person number line
bl1=lines.pop(0)   # Throw away the blank line
nameline=lines.pop(0)  # Get name line
ageline=lines.pop(0)   # Get age line
#
# Create person instance and append to peoplelist
#
self.peoplelist.append(personClass(nameline, ageline))
try: bl2=lines.pop(0)  # Throw away trailing blank line 1
except: break  # All done if there is none
try: bl3=lines.pop(0)  # Throw away trailing blank line 2
except: break  # All done if there is none

return

def __len__(self):
return len(self.peoplelist)

def __iter__(self):
return self

def next(self):
#
# Try to get the next person
#
try: PERSON=self.peoplelist[self.next_index]
except:
self.next_index=0
raise StopIteration
#
# Increment the index pointer for the next call
#
self.next_index+=1
return PERSON

if __name__== "__main__":
initialstring='person number 1\n\nName: bob\nAge: 50\n\n\n' \
  'person number 2\n\nName: jim\nAge: 39'
people=peopleClass(initialstring)
for person in people:
print "Name:", person.name
print "Age:", person.age
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating numbers and str

2005-11-09 Thread Grant Edwards
On 2005-11-10, Dan Bishop <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>> On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:
>>
>> > I would like to limit a floating variable to 4 signifigant digits, when
>> > running thorugh a str command.
>>
>> Sorry, that's not possible.
>
> Technically, it is.

Ah well, I assumed that by "floating variable" he meant the
built-in "float" type.

-- 
Grant Edwards   grante Yow!  I always wanted a
  at   NOSE JOB!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating numbers and str

2005-11-09 Thread Dan Bishop
Grant Edwards wrote:
> On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:
>
> > I would like to limit a floating variable to 4 signifigant digits, when
> > running thorugh a str command.
>
> Sorry, that's not possible.

Technically, it is.

>>> class Float4(float):
...def __str__(self):
...   return '%.4g' % self
...
>>> x = Float4(1.23456789)
>>> str(x)
'1.235'

But, of course, I'd recommend just using '%.4g'%x directly.

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


Re: struct, IEEE-754 and internal representation

2005-11-09 Thread ej
Ah! Well! That explains it. I started to suspect that but (obviously) did
not know that. LOL

Thanks for your prompt reply, Grant.  :)

-ej


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


Re: Python obfuscation

2005-11-09 Thread Carl Friedrich Bolz
hi!

[EMAIL PROTECTED] wrote:
> How effective can it be when python is designed to make writing this
> kind of code hard(hopefully impossible) ? The most effective would be
> renaming function and may be variables but if the functions are kept
> short, they would at most looks like haskell ;-)
> 

There just cannot be a python obfuscator that works for a general python 
program. The problem is that on the one hand regular strings can be used 
to lookup values in namespaces (e.g. with getattr) and on the other hand 
the lookup of names can be controlled (e.g. with __getattr__ and 
friends). Therefore any string can potentially contain a name that would 
have to be changed to keep the code working after obfuscation. For 
example how would you automatically obfuscate the following code:


class HelloWorld(object):
 def hello(self):
 return "world"

 def world(self):
 return "!"

if __name__ == '__main__':
 h = HelloWorld()
 s = "hello"
 while 1:
 f = getattr(h, s, None)
 print s,
 if f is None:
 break
 s = f()

While this is surely a contrived case that intentionally mixes names and 
strings that are used for something in the application there are also 
quite often legitimate use cases for this sort of behaviour. Duck typing 
is basically based on this.

Cheers,

Carl Friedrich Bolz

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


Pythonising the vim (e.g. syntax popups) -> vimpst

2005-11-09 Thread Roman Roelofsen

> Evening,
>
> Is there a decent way to get that help into vim? Or like showing docstrings
> or help that I get through pydoc on request? I've been working myself
> through a pile of vim macros/plugins but couldn't find even one which
> simplifies programming in Python. Further issues would be handling the

Hi Christoph,
Hi Vim users,

The last 5 days I´ve been working on a code-completion/calltips plugin for 
vim. It´s working pretty good but not finished yet. I will anounce the first 
beta version on this mailling list. I hope during the next week.

I recorded a swf-video so that you can take a look at the current status.
Link: http://www.tuxed.de/vimpst/video.tar.gz

Note that it is not necessary to generate symboltable files, etc. Everything 
is done "on demand". It is even possible to change the python implementation 
e.g. CPython, Jython, IronPython.

It is also possible to add some "special feature" interceptor. Currently this 
is working for SQLObject:
Lets say you have the class User and the attribute username is a alternate ID.
Then, the method User.byUsername("...") will always return a User object. 
vimpst checks this and provides a suitable help.

Regards,

Roman

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


Re: struct, IEEE-754 and internal representation

2005-11-09 Thread jepler
Use 'd' as the format character for 64-bit double precision numbers with struct.

>>> x = 148.73
>>> unpack(">> unpack("

pgpB2b9owxZs7.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: struct, IEEE-754 and internal representation

2005-11-09 Thread Robert Kern
ej wrote:

> If that's true, then I guess I am confused why Python is displaying
> 148.72999572753906 when you unpack the 4 bytes, implying a lot more
> precision that was available in the original 32-bits?   Python is doing
> 64-bit floating point here? I'm obviously not understanding something...
> help?

Yes, Python uses C double precision floats for float objects.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: struct, IEEE-754 and internal representation

2005-11-09 Thread Grant Edwards
On 2005-11-09, ej <> wrote:

> If that's true, then I guess I am confused why Python is displaying
> 148.72999572753906 when you unpack the 4 bytes, implying a lot more
> precision that was available in the original 32-bits?   Python is doing
> 64-bit floating point here?

Yes. C-Python "float" objects are of the C type "double" and
use 64-bit IEEE-754 representation on all the common platforms
I know about.

-- 
Grant Edwards   grante Yow!  .. or were you
  at   driving the PONTIAC that
   visi.comHONKED at me in MIAMI last
   Tuesday?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Invoking Python from Python

2005-11-09 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Mike Meyer  <[EMAIL PROTECTED]> wrote:
.
.
.
>It's very flexible - but at this point, the "configuration file" is a
>Python program, and not really suitable to use by non-programmers.
.
.
.
Or both.  I have lived through a lot of experiences where
customers think a configuration file has a very simple
syntax--but in case of some puzzle/emergency/challenge/...,
I can tell 'em, "put 'complicated_script_that_I_can_recite_
on_the_telephone' right at the bottom, and tell me what
happens."  That's saved weeks of thrashing around.

I should make that explicit:  application developers, you
don't have to tell customers everything your programs do.
Your obligation is to make 'em meet requirements.  If it
helps *you* that they do more, so be it.
-- 
http://mail.python.org/mailman/listinfo/python-list


struct, IEEE-754 and internal representation

2005-11-09 Thread ej

I ran into something today I don't quite understand and I don't know all the
nitty gritty details about how Python stores and handles data internally.
(I think) I understand why, when you type in certain floating point values,
Python doesn't display exactly what you typed (because not all decimal
numbers are exactly representable in binary, and Python shows you the full
precision of what is representable). For example:

>>> 0.9
0.90002

and

>>> 148.73
148.72

So, I think I've got a pretty good handle on what the struct module is all
about. Let's take that number, 148.73, and use struct functions to look at
the raw bit pattern of what would be in a 32-bit register using IEEE754
float representation:

>>> hex(unpack('L', pack('f', x))[0])
'0x4314BAE1L'

That is, the four bytes representing this are 0x43, 0x14, 0xBA, 0xE1

Now let's go back the other way, starting with this 32 bit representation,
and turn it back into a float:

>>> unpack('>f', pack('', 0x43, 0x14, 0xBA, 0xE1))[0]
148.72999572753906


H...  Close, but I seem to be losing more the I would expect here.  I
initially thought I should be able to get back to at least what python
previously displayed:  148.72

I know there are 23 bits of mantissa in an IEEE-754, with a free '1'...

>>> hex(14872999)
'0xe2f1a7'

Looks like it takes 6 * 4 = 24 bits to represent that as an int

I am starting to think my expectation is wrong...

If that's true, then I guess I am confused why Python is displaying
148.72999572753906 when you unpack the 4 bytes, implying a lot more
precision that was available in the original 32-bits?   Python is doing
64-bit floating point here? I'm obviously not understanding something...
help?

-ej




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


Re: how to modify code while debugging it without having to stop and then restart debugger

2005-11-09 Thread Neil Hodgson
Steven D'Aprano:

> You write a function:
> 
> def myfunct(s):
> # input arg s is a string
> foo = s*3
> bar = s.upper() + foo   # LINE 2
> blob = foo.lower() + bar
> return blob
> 
> You enter the debugger and single-step to the marked line LINE 2. Then you
> edit the code to this:
> 
> def myfunct(n):
> # input arg n is an int
> foo = n + 1
> bar = foo*2   # LINE 2
> blob = foo**bar
> return blob
> 
> What should Python do when you step the debugger, 

Python should throw the power switch and sulk for at least an hour.

 > and why is it useful?

Teaches the user who's boss.

Debug time code modification is useful to me in C++ for two reasons. 
The first is where there is a simple bug: step, step, step, aah!, 
fiddle, step, works! The second is where you want to perturb the code to 
produce some unusual situation within a test run: how would the calling 
code cope if this code allowed a duplicate element through? fiddle, 
step, step, crash! Mmm, that looks like the fault report, maybe there is 
another way that duplicates are possible. The first type of change 
become permanent parts of the code while the second type are ephemeral.

There are limitations to the technology: if you add too much code it 
won't fit in the allocation (which has been padded a bit for debugging 
but not much) or the function is being reentered. I'm not sure about all 
the limitations and they change between releases but it probably fails 
about one time in ten for me. This doesn't stop the session, just leaves 
your change unapplied.

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


Re: which feature of python do you like most?

2005-11-09 Thread matt . schinckel
>>>I have no idea why people are so facinating with python.

> Hey, I'm fascinating even without python!

>And so modest, too :-) 

People as good as us usually are.

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


Re: triangulation

2005-11-09 Thread Robert Kern
Shi Mu wrote:
> Delaunay triangulations

Besides Delny, which runs the external program qhull to do its
calculations, I've recently written a package for scipy that uses Steve
Fortune's sweep-line code to calculate Delaunay triangulations. I don't
think there are any public implementations of Delaunay triangulation in
pure Python, though, if that's what you want. You can easily find more
sample code in other languages by googling.

http://svn.scipy.org/svn/scipy/branches/newscipy/Lib/sandbox/delaunay/

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: overloading *something

2005-11-09 Thread Robert Kern
James Stroud wrote:

> That **kwargs insists on using the C-side interface is precisely the 
> annoyance 
> to which I am referring. I should be able to write a dictionary-like 
> interface in python and **kwargs should in turn be able to use it. If the 
> retort is that the C-side interface is used for performance, my retort to the 
> retort is that an isinstance() is already being called somewhere, so no 
> additional tests would need to be made to make **kwargs more generalized.

Well, the test is in Python/ceval.c (grep for the error message) and the
function that needs a bona fide dictionary is PyObject_Call in
Objects/abstract.c . If you can work up a patch, Guido will probably
consider it although I would suggest searching python-dev for previous
discussions first.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Python obfuscation

2005-11-09 Thread Grant Edwards
On 2005-11-09, Anand S Bisen <[EMAIL PROTECTED]> wrote:

> I dont know much !! But if somebody asks me this question my
> answer would be to convert some of the meat inside my programs
> to C/C++ and then provide the interface to those novel ideas
> to Python using swig.  And for another level of protection
> maybe use these offuscator on the remaining Python source.
> What do you think ?

Um... sounds like an excellent way to burn hours while
introducing bugs and security problems?

-- 
Grant Edwards   grante Yow!  I feel... JUGULAR...
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: user account logon from python

2005-11-09 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Philippe C. Martin wrote:

> I am attempting to write a linux logon manager with python.

Have you considered looking at the sources of xdm/gdm/kdm/... to see how
they solve the problems you have?

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


Re: Python obfuscation

2005-11-09 Thread Anand S Bisen
I dont know much !! But if somebody asks me this question my answer 
would be to convert some of the meat inside my programs to C/C++ and 
then provide the interface to those novel ideas to Python using swig. 
And for another level of protection maybe use these offuscator on the 
remaining Python source. What do you think ?

Anand S Bisen

petantik wrote:
> Are there any commercial, or otherwise obfuscators for python source
> code or byte code and what are their relative advantages or
> disadvantages.  I wonder because there are some byte code protection
> available for java and .NET, although from what i've read these seem to
> be not comprehensive as protection schemes
> 
> 
> 
> 
> 
> 
> 
> http://petantik.blogsome.com - Telling it like it is
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overloading *something

2005-11-09 Thread [EMAIL PROTECTED]
Robert Kern wrote:
> James Stroud wrote:
>
> > Does anyone else find the following annoying:
> >
> > py> from UserDict import UserDict
> > py> aud = UserDict({"a":1, "b":2})
> > py> def doit(**kwargs):
> > ...   print kwargs
>
> UserDict only exists for backwards compatibility with old code that used
> it before one could subclass from dict directly. Don't use it if you can
> avoid it. UserDict only ever exposed the Python-side interface of dicts.
> It couldn't expose the C-side interface, and it's the C-side interface
> that **kwds is using.

Which means that you can't subclass dict with, say, a lazy dictionary
(that doesn't retrieve values until they're looked up) and use it with
**kwargs.  That bit me last year:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/95cfa91b732cd482/24b7e17bb395494e

It would be useful in some situations to be able to do this (especially
where getting the dictionary values is time-consuming and the function
you're calling doesn't use all the values in the dictionary).  For my
particular case I had a fairly easy workaround.

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


Re: Python obfuscation

2005-11-09 Thread [EMAIL PROTECTED]
Mike Meyer wrote:
> Step one: globally replace all names in all python module withb names
> that are composed of long strings of l, 1, 0 and 0. Fixing
> cross-module references should be fun. Don't just make them random -
> make them all start with the same sequence, and end with the same
> sequence, having differences only in the middle.

Eliminating the original variable names may be useful in obfuscation,
but this doesn't seem to buy much over just replacing with random
strings; it's trivial to do a similar replacement to go from "10Oll10"
strings to "firstVariable", "secondVariable", etc strings.

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


Re: Cursor Position.

2005-11-09 Thread Diez B. Roggisch
> That is my exact problem. I want to have the mouse event captured from 
> another application window. In this case an image window opened in Paint 
> Shop Pro that by the way uses Python to make scripts. I would like to be 
> able to click on the image and get the X,Y positions. I have been able to 
> get the X,Y from Tkinter own window as you say. Once I have those positions 
> I can use them in a Paint Shop Pro script.
> Thanks for your reply. Do you have any advise as to how I can do what I am 
> trying or is it, in a practical matter, impossible.

As I said - it certainly is doable. But I fear not in tkinter "as is" 
(you can use tk still for your _own_ gui), and not without deeper 
knowledge of the windows event system. Then mark hammond's win32 
extensions are a starting point. And you should search for example code 
on MSDN or something like that (obviously _not_ in python), to get a 
starting point.

Regards,

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


Re: Pythonising the vim (e.g. syntax popups)

2005-11-09 Thread Lonnie Princehouse
There is a Python folding script, as someone already mentioned.  That
will help you track indentation, although it's not perfect (iirc, long
triple quoted strings cause folding malfunctions)

I don't know of any way to get dynamic help about functions, although
it seems like an ideal use of Vim's built-in Python interpreter and the
vim python module.

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


Re: Python obfuscation

2005-11-09 Thread petantik
Yu-Xi Lim wrote:
> Steve Holden wrote:
> > Before adding complex protection mechanisms to your code you first need
> > some code worth protecting, which is to say it should have some novel
> > features or represent a lot of work that offers useful integrated
> > functionality for a task or a skill area.
> >
> > Most inquiries of this nature appear to fall at that first hurdle.
> >
> > There are things you can do, but I'm always keenly aware that very few
> > users of a program have both the skills and the inclination to rip off
> > the code even when the source is distributed as part of the product.
> > Personally I've never bothered with obfuscation, and prefer to rely on
> > copyright when I deliver code to customers.
>
> As you said, if you have some novel features, you will need obfuscation.
> Copyright doesn't protect the process and patents may take a while. In
> the meanwhile, good obfuscation is reasonable protection, imho.
>
> But I think you failed to note that it may not be a novel feature or
> useful functionality. In fact, it might be the opposite: a function the
> users want removed. A typical example would be a shareware registration
> or nag screen. When the users have to start paying, they might then feel
> inclied to "rip off the code", or in this case, rip out the code.

This is what I am talking about.  If you look at programs written in C,
or others that compile into native binaries, there are  many protection
schemes which are mainly used not to protect some novel process but to
ensure that their commercial software remains marketable.

People who download cracks/serial numbers rarely care about copyright.
So when python is used in more commercial software some sort of high
grade obfuscation may be needed.   These packers sometimes also have an
embedded compression so that it can decompress the code 'on the fly'
reducing filesizes





http://petantik.blogsome.com - A Lucid Look at Reality

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


Re: PIL-> Tkinter

2005-11-09 Thread robert . dowell
I'm having issues with gmail at work but I will try to email it from
home tonight.

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


Re: append to non-existing list

2005-11-09 Thread James Stroud
On Wednesday 09 November 2005 07:00, Yves Glodt wrote:
>
> I will never mention any p-language except python in this list anymore...

+1 QOTW

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

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


Re: triangulation

2005-11-09 Thread Jorgen Grahn
On Wed, 9 Nov 2005 04:14:22 -0800, Shi Mu <[EMAIL PROTECTED]> wrote:
> is there any sample code to triangulation? many thanks!

Don;t know if this is what you're looking for, but I have some code here:

  http://www.algonet.se/~jgrahn/comp/projects/geese-1.6.tar.gz

find(neighbors)

  Find a (x, y) coordinate of a point, based on a sequence of (x, y, d) -
  neighbor coordinates and their individual distances from the desired
  point.

It's completely unsupported, and probably sucks badly. But it works for my
purposes, and there are unit tests.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python obfuscation

2005-11-09 Thread Mike Meyer
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> How effective can it be when python is designed to make writing this
> kind of code hard(hopefully impossible) ? The most effective would be
> renaming function and may be variables but if the functions are kept
> short, they would at most looks like haskell ;-)

I haven't looked at obfuscator, so I have *no idea* how it works. The
following is how I'd do it.

Step one: globally replace all names in all python module withb names
that are composed of long strings of l, 1, 0 and 0. Fixing
cross-module references should be fun. Don't just make them random -
make them all start with the same sequence, and end with the same
sequence, having differences only in the middle.

Step two: repeat this process for the contents of binary modules, not
neglecting __builtins__. In this case, you probably can't remove the
old names, but you can add new things to the module, and make sure you
only reference those.

I'm not sure how to go about fixing things that are referenced by name
in binary modules. Maybe you'll have to leave those names in the
modules. But you an make sure that all references in Python source use
the new, binary-like names.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: append to non-existing list

2005-11-09 Thread Mike Meyer
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:

> Mike Meyer wrote:
>
>> Float doesn't handle implicit conversion to anything but but builtin types.
>> In particular, it doesn't check to see if the object beinng added has a
>> __float__ method, and invoke that to do the conversion if it does.
>
> that's because __float__ is there to let you control what float() does,
> not to get automatic type conversion for mixed operations.

So is there a mechanism to indicate to the builtin types how they
should coerce some user-defined class into themselves?

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: not able to HTTPS page from python

2005-11-09 Thread Larry Bates
It is possible that the links have been obscured (something
I do on my own web pages) by inserting Javascript that creates
the links on the fly using document.write().  That way web
spiders can't go through the web pages and easily pick up email
addresses to send spam to all my employees.  Just a thought
since you have spent days on this.

-Larry Bates


[EMAIL PROTECTED] wrote:
> Hi all,
> 
> Am trying to read a email ids which will be in the form of links ( on
> which if we click, they will redirect to outlook with their respective
> email ids).
> 
> And these links are in the HTTPS page, a secured http page.
> 
> The point is that am able to read some links with HTTP page, but am not
> able to read the same when I try with HTTPS.
> 
> 
> 
> Using the following code from sgmllib am able to read the links,
> 
> 
> 
> 
> 
> class MyParser(sgmllib.SGMLParser):
> 
> def __init__(self):
> 
> sgmllib.SGMLParser.__init__(self)
> 
> self.inside_a = False
> 
> self.address = ''
> 
> def start_a(self,attrs):
> 
> if DEBUG:
> 
> print "start_a"
> 
> print attrs
> 
> for attr,value in attrs:
> 
> if attr == 'href' and value.startswith('mailto:'):
> 
> self.address = value[7:]
> 
> self.inside_a = True
> 
> def end_a(self):
> 
> if DEBUG:
> 
> print "end_a"
> 
> if self.address:
> 
> print '"%s" <%s>' % (self.nickname, self.address)
> 
> mailIdList.append(self.address)
> 
> 
> 
> self.inside_a = False
> 
> self.address = self.nickname = ''
> 
> def handle_data(self,data):
> 
> if self.inside_a:
> 
> self.nickname = data
> 
> 
> 
> 
> 
> And for the proxy authentication and the https handler am using the
> following lines of code
> 
> 
> 
> 
> 
> authinfo = urllib2.HTTPBasicAuthHandler()
> 
> 
> 
> proxy_support = urllib2.ProxyHandler ({"http" :
> "http://user:[EMAIL PROTECTED]:port"})
> 
> 
> 
> opener = urllib2.build_opener(proxy_support, authinfo,
> urllib2.HTTPSHandler)
> 
> 
> 
> urllib2.install_opener(opener)
> 
> 
> 
> 
> 
> Then am trying to call the parser for the links in a particular https
> page which will be given as a command line argument. Which will read me
> all the links in that page.
> 
> 
> 
> p = MyParser()
> 
> for ln in urllib2.urlopen( sys.argv[1] ):
> 
> p.feed(ln)
> 
> p.close()
> 
> 
> 
> 
> 
> NOTE : I have installed python with _ssl support also.
> 
> 
> 
> 
> 
> So with this code am able to read the links with HTTP page but not for
> the HTTPS page.
> 
> AM NOT GETTING ANY ERRORS EITHER BUT ITS NOT READING THE LINKS, THAT
> ARE PRESENT IN THE GIVEN HTTPS PAGE
> 
> 
> 
> Could you please tell me am I doing some thing wrong in the above code
> for any of the handlers.
> 
> 
> 
> 
> 
> I have got struck here from so many days, please give me the solution
> for this.
> 
>  
> 
> Thanks and regards
> 
> YOGI
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonising the vim (e.g. syntax popups)

2005-11-09 Thread Micah Elliott
On Nov 09, Christoph Haas wrote:
> I'm an addicted vim user and don't really use the IDLE for anything
> more than calculations where I'm too lazy to start KCalc. But one
> feature is very pretty: the built-in help for function calls while
> you type. Like you enter...
> 
> var1,var2=mystring.split(
> ...and the IDLE shows me a popup saying...
> "S.split([sep [,maxsplit]]) -> list of strings

The PIDA IDE  claims
to be able to do something like this.  I have not used PIDA, but I too
am a vim zealot and I think wrapping vim with extra functionality is a
great idea, and I'll try it out when I get a chance.

> Is there a decent way to get that help into vim? Or like showing
> docstrings or help that I get through pydoc on request?

You can set 'keywordprg' to something like "pydoc" to enable "K" to
pull up the help.  Its default setting is to open manpages for words
under the cursor.  I don't use it since I've got an interpreter shell
sitting in the corner of most virtual desktops -- doesn't everyone?

And ctags features are excessively prevalent in vim, and ctags works
fine with python IME.  You can create a tags file of your whole
python installation.

> I've been working myself through a pile of vim macros/plugins but
> couldn't find even one which simplifies programming in Python.

Matchit is a good one for %-matching:
http://www.vim.org/scripts/script.php?script_id=39

> Further issues would be handling the indentation

Eric McSween wrote a python indenter:
http://www.vim.org/scripts/script.php?script_id=974

> - maybe a plugin which syntax colors

Sure, that's builtin.  But Dmitry Vasiliev wrote some useful
enhancements:
http://www.vim.org/scripts/script.php?script_id=790
Note that you'll have to enable some variables in the macro.

> syntax colors different levels of indentation so I don't have to use
> my plastic ruler on the screen.

That's kind of a nice idea, and it should be an easy one to write (but
I'm not volunteering).  You could write it (:h syntax-highlighting) or
maybe post a request to the vim mailing list <[EMAIL PROTECTED]>.

Otherwise, folding would be useful for this.  Pyfold might be helpful,
though I haven't tried it:
http://www.vim.org/scripts/script.php?script_id=781

I like the ruler idea!  Usually when I find myself straining to figure
out what level I'm at it means it's time to refactor.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overloading *something

2005-11-09 Thread James Stroud
On Tuesday 08 November 2005 22:54, Robert Kern wrote:
> James Stroud wrote:
> > Does anyone else find the following annoying:
> >
> > py> from UserDict import UserDict
> > py> aud = UserDict({"a":1, "b":2})
> > py> def doit(**kwargs):
> > ...   print kwargs
> > ...
> > py> aud
> > {'a': 1, 'b': 2}
> > py> doit(**aud)
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > TypeError: doit() argument after ** must be a dictionary
> >
> > UserDict should be isomorphic with a dict. The fact that it is not in
> > this case seems terribly un-pythonic to me.
>
> UserDict only exists for backwards compatibility with old code that used
> it before one could subclass from dict directly. Don't use it if you can
> avoid it. UserDict only ever exposed the Python-side interface of dicts.
> It couldn't expose the C-side interface, and it's the C-side interface
> that **kwds is using.

That **kwargs insists on using the C-side interface is precisely the annoyance 
to which I am referring. I should be able to write a dictionary-like 
interface in python and **kwargs should in turn be able to use it. If the 
retort is that the C-side interface is used for performance, my retort to the 
retort is that an isinstance() is already being called somewhere, so no 
additional tests would need to be made to make **kwargs more generalized.

James

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

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


Re: where to download md5.py?

2005-11-09 Thread Jorgen Grahn
On Wed, 2 Nov 2005 18:59:28 +0100, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> "Bell, Kevin" wrote:
>
>> I've been looking around, but haven't found a place to download the
>> md5.py module.  I need it to run the dupinator.py
>
> md5 is a standard Python module (written in C).  it's been in Python since
> the early ages, so if you don't have it, your install is most likely broken 
> (per-
> haps intentionally, based on this: http://eprint.iacr.org/2004/199 )

Intentionally breaking md5 in a Python installation that would be really,
really stupid -- the md5 algorithm, is useful even if it's not
cryptographically secure.

(I understand that you don't /advocate/ ripping out module md5, of course).

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web automation

2005-11-09 Thread Mike Meyer
[EMAIL PROTECTED] writes:
> Hi Mike,
> thank you very much for your reply.
> I know that mine could be considered
>> a "very" silly way to define automation.
> but I'm not a purist nor a professional
> programmer.

Yes, but you still need to communicate with other people. Using words
to mean something other than what those people expect them to mean is
a recipe for trouble.

> Besides that, I know that case by case
> every problem can be solved and in more
> "right" way, also in very difficult environments
> (framed, Javascript heavy pages) ... but not by me!

The "right" way is what works for you. I'd call using a higher-level
approach the "easy" way - at least when compared to to simulating GUI
events!

> I must confess: before pressing manually 220 times a
> "Next" button and save the data sent by the
> html server (using simply cut/paste), I tried to use
> shell programming, DCOP etc., but in the end
> I reverted to the "by hand" method...
>
> Perhaps if I were an expert like you, I could have
> programmed a small script in a matter of minutes.

I can't say without having looked at your example whether or not
that's possible. I can say that it would probably take more than a few
minutes, having done similar things myself.

Automating web stuff is very fragile in any case. Minor changes in web
formatting can break the automation. Someone already pointed out that
the web isn't well-designed for automation.

> Only after a week I found the solution (twill) but
> I have discovered that also this solution obliges
> to consider every case and program the script
> accordingly (to not mentioning the need of
> disguising it as a browser).
> On the other end, the "cheating" method doesn't
> assure a 100% success, because the html servers can
> have a high degree of "cleverness".

So can your twill script.

> If I would cut out all automatic queries from my server,
> I would also time between them to see if the stream
> of queries ("apparently" coming from a browser) are
> indeed compatible with a browser operated by a
> human being...

So I'd add an automatic - and random - delay between each fetch. No
problem. Well, once I figured out what you were checking for, anyway.

> For all this reasons, reluctantly, I am going back to Windows
> and its macro languages.
>
> Unfortunately in Windows there are many more security problems...
>
> If you have a "general" solution for the X world...

Well, what you want is SMOP. The problem is, there are easier to use
solutions for almost every case you run into in the real world, so
there's little incentive for providing a "general" (i.e. - low-level,
as you can't force a high-level interface on apps) solution. Scripting
tools on Windows aren't generally as capable - or at least weren't
until relatively recently - so there's more incentive for a low-level
solution to be developed. You happen to be hitting one of the corner
cases where the high-level ltools on Unix just aren't up to the job.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Flat file, Python accessible database?

2005-11-09 Thread Jorgen Grahn
On Tue, 1 Nov 2005 21:02:20 + (UTC), Karlo Lozovina <[EMAIL PROTECTED]> 
wrote:
> [EMAIL PROTECTED] (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) wrote in 
> news:[EMAIL PROTECTED]:
>
>> If you need it to be SQL-like, SQLite seems to be the right thing.
>
> Tried that one, but had some problems setting things up. On the other 
> hand, BerkeleyDB + Pybsddb worked like a charm, with no setting up (under 
> Cygwin).
>
> The problem is, Pybsddb is as badly documented as Windows Registry, no 
> examples, no tutorials, no nothing :(.

What about the standard module bsddb, then? It's not a /relational/ database
though, if that is what you're looking for.  But it's simple to understand,
well documented, and unbelievably fast.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to modify code while debugging it without having to stop and then restart debugger

2005-11-09 Thread Mike Meyer
Steve Holden <[EMAIL PROTECTED]> writes:
> Steven D'Aprano wrote:
>> On Tue, 08 Nov 2005 13:38:28 -0500, python wrote:
> [...]
>>>as i mentioned even micro$soft can do this using statically type languages 
>>>like visual basic and csharp.
>>> also, both visualbasic and csharp have goto statements, which i do
>>> to not use in final code but can be real handy when used with the
>>> ability to change debugged code on the fly while inside the
>>> function being debugged.
>> Better and better. Yes, I can see how the ability to jump around a
>> function on the fly would really help you understand how the function is
>> supposed to work when you take the gotos out.
> I must admit I had been wondering just how far the OP wanted to go in
> mangling the code. I suspect that the interesting bit to the OP is
> having a visual editor available to alter functions and class
> definitions "on the fly" rather than having to completely re-enter the
> definition as you would at the interactive interpreter prompt. He or
> she'd probably be a bit unhappy about the need to reload() modules
> too, I suppose.

In that case, you're using the wrong IDE. I run the Python interpeter
inside of Emacs. I edit my code in another buffer. In the source code
buffer, I hit M-C-x, and the current version of the function I'm
currently editing gets sent to the interpreter. Reload is pretty easy
as well - C-c RETURN, and the module I'm editing gets reloaded.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating numbers and str

2005-11-09 Thread Grant Edwards
On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:
> Wait, one more question. If the number is something like:
>
> 1.32042
>
> It is like
> "1.32 stuff"
>
> I would like it's size to remain constant. Any way around this?

http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-211

-- 
Grant Edwards   grante Yow!  WHO sees a BEACH
  at   BUNNY sobbing on a SHAG
   visi.comRUG?!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python obfuscation

2005-11-09 Thread Yu-Xi Lim
Steve Holden wrote:
> Before adding complex protection mechanisms to your code you first need 
> some code worth protecting, which is to say it should have some novel 
> features or represent a lot of work that offers useful integrated 
> functionality for a task or a skill area.
> 
> Most inquiries of this nature appear to fall at that first hurdle.
> 
> There are things you can do, but I'm always keenly aware that very few 
> users of a program have both the skills and the inclination to rip off 
> the code even when the source is distributed as part of the product. 
> Personally I've never bothered with obfuscation, and prefer to rely on 
> copyright when I deliver code to customers.

As you said, if you have some novel features, you will need obfuscation. 
Copyright doesn't protect the process and patents may take a while. In 
the meanwhile, good obfuscation is reasonable protection, imho.

But I think you failed to note that it may not be a novel feature or 
useful functionality. In fact, it might be the opposite: a function the 
users want removed. A typical example would be a shareware registration 
or nag screen. When the users have to start paying, they might then feel 
inclied to "rip off the code", or in this case, rip out the code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating numbers and str

2005-11-09 Thread Fredrik Lundh
"Tuvas" <[EMAIL PROTECTED]> wrote:

>I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
>
> x=.13241414515
> y=str(x)+" something here"
>
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do something like %.4d, but how can I do this
> with converting the number to a string? Thanks!

you mean "%.4g" ?  the % operator is a string operator, and can be used
outside print:

text = "%.4g" % value

for more details, here's the first google hit for "python string formatting":

http://docs.python.org/lib/typesseq-strings.html

but that doesn't make too much sense if you don't know how things work
in C, which is explained here:

http://www.cplusplus.com/ref/cstdio/printf.html

here are some examples:

>>> x=.13241414515
>>> x
0.13241414515
>>> "%.4f" % x
'0.1324'
>>> "%.4g" % x
'0.1324'

>>> x=5.13241414515
>>> "%.4f" % x
'5.1324'
>>> "%.4g" % x
'5.132'

 



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


Re: Floating numbers and str

2005-11-09 Thread Tuvas
Wait, one more question. If the number is something like:

1.32042

It is like
"1.32 stuff"

I would like it's size to remain constant. Any way around this?

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


Re: Floating numbers and str

2005-11-09 Thread Grant Edwards
On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:

> I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command.

Sorry, that's not possible.

> x=.13241414515
> y=str(x)+" something here"
>
> But somehow limiting that to 4 sign. digits. I know that if
> you use the print statement, you can do something like %.4d,
> but how can I do this with converting the number to a string?

I don't understand what you mean about the print statement.  

If using str() isn't really a requirement, you can use the
string formatting operator "%" like this:

>>> x=.13241414515
>>> y = "%0.4g" % x
>>> y
'0.1324'

-- 
Grant Edwards   grante Yow!  A GRAM?? A BRAM... A
  at   GROOM... A BROOM... Oh,
   visi.comYeh!! Wash the ROOM!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating numbers and str

2005-11-09 Thread Tuvas
Yep, I was thinking in C, not python. Thanks for the help!

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


Re: Floating numbers and str

2005-11-09 Thread Jeremy Moles
I think you answered your own question. :)

x = 0.12345678
y = "%.4f something here" % x

On Wed, 2005-11-09 at 11:52 -0800, Tuvas wrote:
> I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
> 
> 
> x=.13241414515
> y=str(x)+" something here"
> 
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do something like %.4d, but how can I do this
> with converting the number to a string? Thanks!
> 

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


Re: Floating numbers and str

2005-11-09 Thread Jeffrey Schwab
Tuvas wrote:
> I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
> 
> 
> x=.13241414515
> y=str(x)+" something here"
> 
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do something like %.4d, but how can I do this
> with converting the number to a string? Thanks!

%d for a floating-point type?  Is that right?

Anyway, ITYW:

"%.4g" % x

E.g:

 >>> x=.13241414515
 >>> y="%.4g something here" % x
 >>> print y
0.1324 something here
 >>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cursor Position.

2005-11-09 Thread Samantha
Diez,
> Won't be easy - a toolkit (like tkinter) will only capture your mouse 
> events that are directed towards it's own windows.

That is my exact problem. I want to have the mouse event captured from 
another application window. In this case an image window opened in Paint 
Shop Pro that by the way uses Python to make scripts. I would like to be 
able to click on the image and get the X,Y positions. I have been able to 
get the X,Y from Tkinter own window as you say. Once I have those positions 
I can use them in a Paint Shop Pro script.
Thanks for your reply. Do you have any advise as to how I can do what I am 
trying or is it, in a practical matter, impossible.
S

"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Samantha wrote:
>> I will be using Tkinter. All I need is a way to get the X,Y position from 
>> a mouse click. I am trying to have an image loaded to click on, but that 
>> seems to be a problem. So if I can just get the position from the screen 
>> of a graphics program, showing an image, it will work for me.
>
> Won't be easy - a toolkit (like tkinter) will only cpature your mous 
> events that are directed towards it's own windows. You might be able to 
> convince your program to collect mouse-events outside for a short period 
> of time - like snapshot programs do - but that will reqiure pretty 
> complicated, OS-dependant coding. Certainly way more complicated than 
> loading an image using tkinter. Better tell us what's giving you a hard 
> time there.
>
> Diez 


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


Re: xml.minidom and user defined entities

2005-11-09 Thread Fredrik Lundh
Nick Craig-Wood wrote:

> I'm using xml.minidom to parse some of our XML files.  Some of these
> have entities like "°" in which aren't understood by xml.minidom.

° is not a standard entity in XML (see below).

> These give this error.
>
>  xml.parsers.expat.ExpatError: undefined entity: line 12, column 1
>
> Does anyone know how to add entities when using xml.minidom?

the document is supposed to contain the necessary entity declarations
as an inline DTD, or contain a reference to an external DTD.  (iirc, mini-
dom only supports inline DTDs, but that may have been fixed in recent
versions).

if you don't have a DTD, your document is broken (if so, and the set of
entities is known, you can use re.sub to fix replace unknown entities with
the corresponding characters before parsing.  let me know if you want
sample code).

 



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


Re: Invoking Python from Python

2005-11-09 Thread Mike Meyer
[EMAIL PROTECTED] (Cameron Laird) writes:
> I'll rein myself in and suggest an even easier introduction
> to this subject:  configuration files.  RARELY is the correct
> answer to create a new syntax, although many development
> organizations give the impression that's their first choice.
> ".ini"-speak is a safe-enough choice.  Most interesting,
> though, is to interpret Python or some subset as a configu-
> ration specification, so that one has immediately not just
> HOME = "/some/folder"
> STEP_LIMIT = 16
> but 
> pool_size = cpu_count * 30
> and even
> if today == "Sunday":
> total_process_maximum = 8
> available in the configuration language.  Neat, eh?  

I once carried this a step further, and used methodless classes as a
configuration mechanism:

class PlainFoo:
  # Values for a plain foo

class FancyFoo(PlainFoo):
  # Overrides for just the things that are different

The program that used this created needed lots of objects, in a
variety of different flavers that were literally specified as "Just
like PlainFoo, but with ...". Doing it this way made configuring
things trivial.

At the time, I attached "configuration variables" to instances. If I
were going to do it today, I'd look into making the parent classes of
the class that implements Foo dynanmic.

plwm (an X11 window manager - sort of - built in top of python-xlib)
carries this another step further. You configure your window manager
by creating a subclass of the WindowManager (or other) class that
mixes in the features you want, and sets the attributes to control
specific features.

It's very flexible - but at this point, the "configuration file" is a
Python program, and not really suitable to use by non-programmers.

> But if configuration is *that* powerful, then it can also
> do great damage.  How does one make Python interpretation safe?
> That's a subject for another day.

We're all waiting for this, somewhat impatiently :-).

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Floating numbers and str

2005-11-09 Thread Tuvas
I would like to limit a floating variable to 4 signifigant digits, when
running thorugh a str command. Ei,


x=.13241414515
y=str(x)+" something here"

But somehow limiting that to 4 sign. digits. I know that if you use the
print statement, you can do something like %.4d, but how can I do this
with converting the number to a string? Thanks!

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


Re: Python obfuscation

2005-11-09 Thread Jean-Paul Calderone
On 9 Nov 2005 11:34:38 -0800, The Eternal Squire <[EMAIL PROTECTED]> wrote:
>Perhaps this could be a PEP:
>
>1)  Add a system path for decryption keys.
>2)  Add a system path for optional decryptors supplied by user
> (to satisfy US Export Control)
>3)  When importing a module try:  import routine except importation
>error : for all decryptors present for all keys present run decryptor
>upon module and retry, finally raise importation error.
>
>With PGP encryption one could encrypt the pyc's with the private key
>and sell a public key to the end user.

What's to stop someone from publishing the decrypted code online for anyone to 
download?

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


Re: web interface

2005-11-09 Thread Jean-Paul Calderone
On Wed, 9 Nov 2005 19:08:28 +, Tom Anderson <[EMAIL PROTECTED]> wrote:
>On Mon, 7 Nov 2005, Ajar wrote:
>
>> I have a stand alone application which does some scientific
>> computations. I want to provide a web interface for this app. The app is
>> computationally intensive and may take long time for running. Can
>> someone suggest me a starting point for me? (like pointers to the issues
>> involved in this,
>
>You're probably best off starting a new process or thread for the
>long-running task, and having the web interface return to the user right
>after starting it; you can then provide a second page on the web interface
>where the user can poll for completion of the task, and get the results if
>it's finished. You can simulate the feel of a desktop application to some
>extent by having the output of the starter page redirect the user to the
>poller page, and having the poller page refresh itself periodically.
>
>What you really want is a 'push' mechanism, by which the web app can
>notify the browser when the task is done, but, despite what everyone was
>saying back in '97, we don't really have anything like that.

Yea, there's no way something like this will work:

# push.tac
from zope.interface import Interface, implements 

from twisted.internet import defer, reactor
from twisted.application import service, internet

from nevow import appserver, loaders, tags, rend, athena

class ICalculator(Interface):
def add(x, y):
"""
Add x and y.  Return a Deferred that fires with the result.
"""

class Adder(object):
implements(ICalculator)

def add(self, x, y):
# Go off and talk to a database or something, I don't know.  We'll
# pretend something interesting is happening here, but actually all
# we do is wait a while and then return x + y.
d = defer.Deferred()
reactor.callLater(5, d.callback, x + y)
return d


class LongTaskPage(athena.LivePage):   
docFactory = loaders.stan(tags.html[
tags.head[
tags.directive('liveglue'),
tags.title['Mystical Adding Machine of the Future'],
tags.script(type="text/javascript")["""

/* onSubmit handler for the form on the page: ask the server
 * to add two numbers together.  When the server sends the
 * result, stick it into the page.
 */
function onAdd(x, y) {
var d = server.callRemote('add', x, y);   
var resultNode = document.getElementById('result-node');
d.addCallback(function(result) {
resultNode.innerHTML = String(result);
});
d.addErrback(function(err) {
var s = "Uh oh, something went wrong: " + err + ".";
resultNode.innerHTML = s
});
resultNode.innerHTML = "Thinking...";
return false;
}""",
],
],
tags.body[
tags.form(onsubmit="return onAdd(this.x.value, this.y.value);")[
tags.input(type="text", name="x"),
"+",
tags.input(type="text", name="y"),
"=",
tags.span(id="result-node")[
tags.input(type="submit"),
],
],
],
])

class Root(rend.Page):
docFactory = loaders.stan(tags.html[
tags.head[
tags.meta(**{"http-equiv": "refresh", "content": "0;calc"})]])

def child_calc(self, ctx):
return LongTaskPage(ICalculator, Adder())

application = service.Application("Push Mechanism, like back in '97")
webserver = internet.TCPServer(8080, appserver.NevowSite(Root()))
webserver.setServiceParent(application)
# eof

Right?  But maybe you can explain why, for those of us who aren't enlightened.

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


Re: append to non-existing list

2005-11-09 Thread bruno at modulix
Yves Glodt wrote:
(snip)
> 
> ok I see your point, and python's...
> 
> (just FYI, and not to start a flamewar ;-):
> In php, the [] means "append to an array object".

yes, I know this.

> If the array does not exist yet, it's created.

Which is what I don't like. It should crash.

> [] *is* explicit for
> arrays, 

IIRC, you can also use it to sbscript strings, but I wouldn't bet my
life on this.

> thus for php it's clear what you want.)

Nope. You may be in the case where you think the array already exists,
and then you (well, I at least...) would prefer that PHP don't try to
second-guess you... If and when I want to create an object, I tell it.
If I dont tell "create me an array", I don't want one to come in existence.

(snip)
> an "undefined" notice, yes, not a warning... ;-)
> 
(snip)
>
> Ok... I thank you for all the explanations.
> 
> It helps me to see more far. I (and will continue to) use php for web,
> and wanna standardize on python for all non-web stuff we are doing, 

You might discover that Python is just great for web programming too !-)

> so I
> might be a frequent guest on this list...

You're welcome !-)
And if you're a french speaker, there's also french-speaking mailing
list and newsgroups.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can python 'read disk sectors' like/via linux:dd ?

2005-11-09 Thread Tauno Voipio
[EMAIL PROTECTED] wrote:
> OP wrote:
> }in order to justify learning another language I'd first need to be
> }convinced that python could easily do the following:-
> }
> }ReadSectors2Bufr(hdx, StartSectr, SectrCnt, Bufr); <-- like linux:dd
> }PrintDecOf4Bytes(Offset, Bufr);   <-- and also 1 and 2 byte values
> }OverWriteBufr(Offset, Bufr, Byte);
> }WriteBufr2Sectors . <-- like linux: dd
> }
> }I guess one would normally use bash, but I'd rather invest effort
> }in python if it can do this.
> }
> }Thanks for any info.
> ---
> 
> Pascal Bourguignon wrote:
> 
>>>In unix, disks are files like any other file.   
>>>So if your programming language allows you to 
>>>read and write files, it allows you to read and
>>>write disks.
>>>Just write the equivalent of:
>>>   int fd=open("/dev/hda",O_RDWR,0);
>>>   if(0<==fd){
>>> check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
>>> check_errors(read(fd,buffer,SECT_SIZE));
>>> modify(buffer);
>>> check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
>>> check_errors(write(fd,buffer,SECT_SIZE));  close(fd); }
>>>and be sure to have the access rights on /dev/hda (and to know
>>>what you're doing!).
> 
> 
> Tauno Voipio wrote:
> 
>>Are you attempting to create a boot block virus?
> 
> 
> Firstly, if you asked me advice on where to buy some goats-milk,
> I'd answer in the context of where YOU stand now [especially
> since you told me], NOT form where I'm standing.
> 
> For several reasons I need many partitions on my IDEs.
> The one lost the chain of logical partitions at hdx26.
> It's not linux, but that's not important.
> The most convenient tool for ME [at my present status] to
> read/write blocks is linux: dd; and to see/edit is linux:mc.
> This involves a lot of tiring manual work.
> I previously read of a contributor who automated the steps
> of linux:fdisk [iterating through size guesses] inside of a bash 
> script, to recover his lost [last] partition.
> I'm not keen on investing time to become more fluent in Bash,
> which could drive dd.
> I have other reasons to invest time in Python.
> If Pyton could 'drive' dd, I would try it.
> 
> My normal OS is oberon S3, which can do better than the 
> C-code above, but I want to work at the highest level.
> 
> Understand ?

Yes, I do.

But, there is a good tool to repair partition tables.
Google for 'gpart'.

-- 

Tauno Voipio
tauno voipio (at) iki fi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Map of email origins to Python list

2005-11-09 Thread Michael
Paul McGuire wrote:

> "Claire McLister" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>   We've been working with Google Maps, and have created a web service to
> map origins of emails to a group. As a trial, we've developed a map of
> emails to this group at:
> 
>   http://www.zeesource.net/maps/map.do?group=668
> 
>   This represents emails sent to the group since October 27.
> 
>   Would like to hear what you think of it.
> --
> 
> 
> Another sleepless camera pointed at the fishbowl that is my online life.
> 
> I guess it's a great way to find where there might be Python jobs to be
> found, or at least kindred souls (or dissident Python posters in countries
> where Internet activity is closely monitored...)
> 
> To me, it's either cool in a creepy sort of way, or creepy in a cool sort
> of way.

As long as it gets my location WRONG, I'm happy.

:-|


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


Re: Python obfuscation

2005-11-09 Thread The Eternal Squire
Perhaps this could be a PEP:

1)  Add a system path for decryption keys.
2)  Add a system path for optional decryptors supplied by user
 (to satisfy US Export Control)
3)  When importing a module try:  import routine except importation
error : for all decryptors present for all keys present run decryptor
upon module and retry, finally raise importation error.

With PGP encryption one could encrypt the pyc's with the private key
and sell a public key to the end user.

The Eternal Squire

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


xml.minidom and user defined entities

2005-11-09 Thread Nick Craig-Wood
I'm using xml.minidom to parse some of our XML files.  Some of these
have entities like "°" in which aren't understood by xml.minidom.
These give this error.

  xml.parsers.expat.ExpatError: undefined entity: line 12, column 1

Does anyone know how to add entities when using xml.minidom?

I've spend some time searching the docs/code/google but I haven't
found the answer to this question!

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


Re: Pythonising the vim (e.g. syntax popups)

2005-11-09 Thread Jeffrey Schwab
Christoph Haas wrote:
> Evening,
> 
> I'm an addicted vim user and don't really use the IDLE for anything more 
> than calculations where I'm too lazy to start KCalc. But one feature is 
> very pretty: the built-in help for function calls while you type. Like you 
> enter...
> 
> var1,var2=mystring.split(
> ...and the IDLE shows me a popup saying...
> "S.split([sep [,maxsplit]]) -> list of strings
> 
> Is there a decent way to get that help into vim? Or like showing docstrings 
> or help that I get through pydoc on request? I've been working myself 
> through a pile of vim macros/plugins but couldn't find even one which 
> simplifies programming in Python. Further issues would be handling the 
> indentation - maybe a plugin which syntax colors different levels of 
> indentation so I don't have to use my plastic ruler on the screen. ;) 
> Perhaps some more experienced Python/Vim users have a tip which macro sets 
> help most here.

Vim is my editor of choice, too.  I've even gone back to Vim from Eclipse.

I believe what you want are "tags."

http://www.vmunix.com/vim/tags.html

I have not tried these in Vim yet, although I did use etags with Emacs 
(before I discovered the miracle of Vim).

If you get context-sensitive help to work properly in Vim, please let me 
know!
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >