Re: Attack a sacred Python Cow

2008-08-03 Thread Michele Simionato
On Jul 28, 8:46 pm, "Russ P." <[EMAIL PROTECTED]> wrote:
> Letting "self" (or whatever the first argument was) be implied in
> ".cat" does absolutely *NOTHING* to change the internal workings of
> the Python interpreter. It's a very simple idea that you insist on
> making complicated. As I said, I could write a pre-processor myself to
> implement it in less than a day.

I implemented such a pre-processor 6+ years ago and I am absolutely
sure
I was not to first one to reinvent this particular wheel. But now I
have grown up
and I am happy with self, because sometimes it can
be named cls, mcl, obj or anything else, and I take advantage of this
fact in my code. self is more readable than a dot and there is
no point in making a special case for it.

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


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Avi
> Apart from the initial installation of Python itself, I
> never use an installer to install a Python package if I
> can avoid it. I wouldn't trust it to install into the right
> Python version.

On that: how would I go about updating the system Python, then?  Or is
that going to be stuck at whatever it is, and Mac users are expected
to run two simultaneous Python installations?  I'm not entirely
comfortable with having a separate MacPython (I used to do so, but it
caused so many issues with installing new packages that I gave up on
it) and would prefer to just update system Python.

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


Re: Attack a sacred Python Cow

2008-08-03 Thread Michele Simionato
On Aug 3, 9:29 am, Michele Simionato <[EMAIL PROTECTED]>
wrote:
> On Jul 28, 8:46 pm, "Russ P." <[EMAIL PROTECTED]> wrote:
>
> > Letting "self" (or whatever the first argument was) be implied in
> > ".cat" does absolutely *NOTHING* to change the internal workings of
> > the Python interpreter. It's a very simple idea that you insist on
> > making complicated. As I said, I could write a pre-processor myself to
> > implement it in less than a day.
>
> I implemented such a pre-processor 6+ years ago and I am absolutely
> sure
> I was not to first one to reinvent this particular wheel.

I have found the relevant thread:

http://groups.google.com/group/comp.lang.python/browse_frm/thread6a7dd33dc287481f/3210d0be45113c23?hl=en&lnk=gst&=simionato+no+self#3210d0be45113c23

See also the comment by Alex Martelli.

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


Re: base-96

2008-08-03 Thread Kless
On 3 ago, 00:16, Tim Roberts <[EMAIL PROTECTED]> wrote:
> Kless <[EMAIL PROTECTED]> wrote:
>
> >I think that would be very interesting thay Python would have a module
> >for working on base 96 too. [1]
>
> Well, then, write one.
>
> However, I'm not sure I see the point.  Base 64 is convenient because 6
> bits becomes 8 bits exactly, so 3 bytes translates exactly to 4 characters.
> With base 96, you would end up doing division instead of just shifting and
> masking; the conversion isn't as "neat".
>
> >As you can see here [2], the printable ASCII characters are 94
> >(decimal code range of 33-126). So only left to add another 2
> >characters more; the space (code 32), and one not-printable char
> >(which doesn't create any problem) by last.
>
> This leaves some tricky issues.  How will you denote the end of a base 96
> sequence?  If every printable character can be part of the ciphertext, what
> can you use as an end marker or a padding character?
Well, it could be used an Unicode (UTF-8) character -wich isn't in
ASCII set-, if it isn't possible use a non-printable char.
--
http://mail.python.org/mailman/listinfo/python-list


Re: base-96

2008-08-03 Thread Kless
On 3 ago, 00:33, Terry Reedy <[EMAIL PROTECTED]> wrote:
> seehttp://en.wikipedia.org/wiki/Base-85
> for something more practical

In this thread [1] --a mirror group of python-dev mailing list-- where
I sent the same post, has been named too that enconding way.


[1] 
http://groups.google.com/group/python-dev2/browse_thread/thread/c843ecf222948167
--
http://mail.python.org/mailman/listinfo/python-list


Re: base-96

2008-08-03 Thread Kless
On 3 ago, 00:31, Tim Roberts <[EMAIL PROTECTED]> wrote:
> Whether it creates problems depends on how you intend to use it.  The
> biggest use for Base64, for instance, is in translating binary files to a
> form where they can be send via email using only printable characters.  If
> you use a non-printable character, that's a problem for email.
There would be that make tests, it's possible that there isn't problem
for any non-printable chars.
>
> With Base64, 3 bytes becomes 4.  With Base96, 5 bytes becomes 6.  So, you
> would reduce the conversion penalty from 1.33 down to 1.17.

> It's not hard to write modules to translate from binary to Base96 and back
> again, and doing so would be a great exercise to explore the issues in this
> kind of encoding.
Yes, it's easy in python, but the ideal would be make the arithmetic
in C as it's implemented for base 64.
--
http://mail.python.org/mailman/listinfo/python-list


Project Question

2008-08-03 Thread ToshiBoy
I'm a newbie to Python... well a newbie to programming, really. I know
the basics and try to learn by setting myself simple tasks and goals
just to find out if I can work out a way to code the solutions. Works
for me. However, now I've set my eyes on a more ambitious project:

We sell office machines, and most of them need to be connected to a
network these days. I've got a routine setup for each model which
enters the most common information, eg. NetBIOS names, mailservers,
etc.The information is input through a webinterface as you have
probably seen on many other printers.

Currently, I'm using iMacro, an add-on to Firefox, which runs a macro
and enters all the info. It's great, but I would like to try and write
a program for this in Python. It needs to collect some user input at
the beginning, and then open the default web browser (or preferably
runs its own interface) and enter the information by identifying the
fields and inputting the text, and "saving" the info by "clicking"
buttons.

Is there a web browser interface module in Python that would have
methods to do this kind of stuff?
--
http://mail.python.org/mailman/listinfo/python-list


Re: why goes the time change after import statement ?

2008-08-03 Thread Paul Hankin
On Aug 3, 8:12 am, binaryjesus <[EMAIL PROTECTED]> wrote:
> On Aug 3, 1:46 am, Paul Hankin <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 2, 10:35 pm, binaryjesus <[EMAIL PROTECTED]> wrote:
>
> > > hi i am working on a S3 project and facing a really weird problem!
> > > take a look at the following import statements and the time output
>
> > > >>> import time
> > > >>> time.strftime("%a, %d %b %Y %X GMT", time.gmtime())
>
> > > 'Sat, 02 Aug 2008 20:21:56 GMT'
>
> > > # OK
>
> > > >>> import pygtk
> > > >>> time.strftime("%a, %d %b %Y %X GMT", time.gmtime())
>
> > > 'Sat, 02 Aug 2008 20:22:04 GMT'
>
> > > # OK
>
> > > >>> import gtk
> > > >>> time.strftime("%a, %d %b %Y %X GMT", time.gmtime())
>
> > > 'Sat, 02 Aug 2008 08:22:11 PM GMT'
>
> > > # HOW THE HELL THIS HAPPEN ??? not DATE_RFC2822 format gmt time !
>
> > Reading the manual page for strftime 
> > --http://docs.python.org/lib/module-time.html
> > -- says that '%X' is the locale's appropriate time representation, so
> > obviously gtk is adjusting your locale. Perhaps use a formatting
> > string that doesn't depend on the locale: '%H:%M:%S' instead of '%X'
> > seems to give your preferred format.
>
> ok that explain it.
> but what command does gtk runs that it sets the default behaviour of
> strfime() to that ?

Maybe setlocale?

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


Re: Genetic programming: pygene, pygp, AST, or (gasp) Lisp?

2008-08-03 Thread John Ladasky
Thanks to everyone who replied.  I haven't chosen a definite direction
for my project yet.  But you have given me some good leads.

Google Books offers previews of many pages of John Koza's book,
published in the early 1990's.  I'm reading through the preview pages,
with the idea of purchasing a more recent book on the subject once I
understand the subject a bit better.

Apropos to Python, I've had a quick look at the parse and compile
functions in Python's compiler module.  The Python AST is MUCH longer
than I expected it to be, for just a few lines of code.  It may
contain more information than I need.  I'll see whether I can make
sense of EasyExtend or Dione next.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to redirect operation methods to some sepcific method easily?

2008-08-03 Thread Steven D'Aprano
On Sun, 03 Aug 2008 02:44:34 -0700, Victor Lin wrote:

> Now, here comes the problem : I have to override all the operation
> methods, such as __add__ and __mul__. I know the most stupid way is just
> to write all of them like this.
> 
> def __add__(self, other):
>  self.leftOperation('add', other)
> 
> def __mul__(self, other):
>  self.leftOperation('mul', other)
> 
> But I don't want to do that in this stupid way. I want to use little
> code to redirect these operation methods to some specific method with
> it's name.
> 
> What can I do?


I usually dislike code that uses exec, but this is one place where I'm 
tempted to make an exception (mainly because I can't think of an 
alternative). Untested and at your own risk:

def factory(name):
"""Return a method name and a function."""
def func(self, other):
return self.LeftOperation(name, other)
return "__%s__" % name, func


class Parrot(object):
for name in ["mul", "add", "sub", "pow"]: # and many more...
name, f = factory(name)
exec "%s = f" % name
del name, f


Urrggh. I feel dirty. *wink*



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


How to redirect operation methods to some sepcific method easily?

2008-08-03 Thread Victor Lin
Hi,
I'd like to write some class that can help me build reusable formula
easily, some simple code like this.

# -*- coding: utf8 -*-

class OperationResult:
def __init__(self, left, right):
self.dataSource = dataSource

def __add__(self, other):
self.dataSource.stack.append('+')
return self

def __div__(self, other):
self.dataSource.stack.append('/')
return self

class Operand:
def __init__(self, dataSource, name):
self.dataSource = dataSource
self.name = name

def __add__(self, other):
self.dataSource.stack.append(self)
self.dataSource.stack.append(other)
self.dataSource.stack.append('+')
return OperationResult(self.dataSource)

class DataSource:
def __init__(self):
self.stack = []

def __getitem__(self, key):
return Operand(self, key)

def ROE(dataSource):
a = dataSource[u'股東權益總額']
b = dataSource[u'每股淨額']
c = dataSource[u'當季平均市價']
return (a + b) / c

Now I can use ROE formula easily, it will return a object that contain
formula stack like this
[a, b, +, c, /]

And then I can get real data of those items from database or other
place. The formula depends on nothing. It don't care where to get data
and how to calculate it. I can reuse it easily.

Now, here comes the problem : I have to override all the operation
methods, such as __add__ and __mul__.
I know the most stupid way is just to write all of them like this.

def __add__(self, other):
 self.leftOperation('add', other)

def __mul__(self, other):
 self.leftOperation('mul', other)

But I don't want to do that in this stupid way. I want to use little
code to redirect these operation methods to some specific method with
it's name.

What can I do?

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

Re: Attack a sacred Python Cow

2008-08-03 Thread Paul McGuire
On Jul 31, 6:15 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Jul 28, 12:15 pm, Kay Schluehr <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On 28 Jul., 06:42, "Russ P." <[EMAIL PROTECTED]> wrote:
>
> > > On Jul 27, 8:58 pm, castironpi <[EMAIL PROTECTED]> wrote:
>
> > > > On Jul 27, 2:39 pm, Bruno Desthuilliers
>
> > > > <[EMAIL PROTECTED]> wrote:
> > > > > Derek Martin a écrit :
> > > > > > It's bad programming, but the world is full of bad programmers, and 
> > > > > > we
> > > > > > don't always have the choice not to use their code.  Isn't one of
> > > > > > Python's goals to minimize opportunities for bad programming?
>
> > > > > Nope. That's Java's goal. Python's goals are to maximize opportunities
> > > > > for good programming, which is quite different.
>
> > > Oh, gosh, that is so clever. What a bunch of crap.
>
> > > > +1 QOTW
>
> > > Do you realize what an insult that is to everyone else who has posted
> > > here in the past week?
>
> > Nothing glues a community together so well as a common enemy. Or even
> > better: two enemies i.e. Perl and Java in Pythons case. On the other
> > hand, some enemies have to be ignored or declared to be not an enemy
> > ( Ruby ), although oneself is clearly an enemy for them. The same
> > antisymmetry holds for Python and Java. Java is an enemy for Python
> > but Python is not worth for Java to be an enemy as long as it can be
> > ignored. C++ and Java are enemies for each other. Same holds for Java
> > and C#.- Hide quoted text -
>
> > - Show quoted text -
>
> Help... being... sucked into... black hole... inside a... Klein...
> bottle...- Hide quoted text -
>
> - Show quoted text -

... which is inside... the black hole...
--
http://mail.python.org/mailman/listinfo/python-list


Re: current week / weeks in year - best practice

2008-08-03 Thread egbert
On Sat, Aug 02, 2008 at 07:46:49PM -0700, Dennis Lee Bieber wrote:
>   
> 
What is the meaning of  ?
e.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

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


Re: Multiline text in XML file

2008-08-03 Thread Pete Kirkham
http://www.w3.org/TR/REC-xml/#sec-white-space is relevant, as is the
following section on handling carriage returns.

Don't mix C escapes "\n" and XML markup - there really is is no point, and
it reduces the portability of the XML. XML lets you put carriage returns in
without excapes into text, and the back-slash isn't significant in XML. Such
use forces clients to use specific processing, rather than standard tools
for editing. If you don't care whether applications beyond your control can
edit the data, you might not want to bother with XML, and use C literals or
whatever you want.

In many cases, it's easier to use elements to mark up the line breaks -
either as Stefan suggested, or using a standard vocabulary such as XHTML
which is the dual of that approach ( text  text  text rather
than text text text ) which is easier for
hand editing, but a little more difficult for XPath processing.

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

proposal, change self. to .

2008-08-03 Thread Equand
how about changing the precious self. to .
imagine

self.update()

.update()

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


HELP with PIL and grainy text

2008-08-03 Thread Huuuze
I could really use some help.  Please take a look at the following
image:

http://img227.imageshack.us/img227/1346/grainynn3.png

As you can see, the text in the image is fairly grainy.  To get to
that point, I converted an ArialBold TTF to a BDF using otf2bdf
(http://crl.nmsu.edu/~mleisher/ttf2bdf.html) and then I used pilfont
utility (http://www.pythonware.com/library/pil/handbook/pilfont.htm)
to convert the file into a .PIL and .PBM file.  I'd expect the font to
be smooth, but no such luck.

Any idea what could be happening here?

For what it's worth, I'm using a Mac (OSX 10.5.4).  Here is the PIL
code as well:

>> import Image, ImageDraw, ImageFont
>> font = ImageFont.load("Arial.pil")
>> im = Image.open("../images/image.png")
>> dr = ImageDraw.Draw(im)
>> dr.text((79,34), "Successfully used the Python Image Library", font=font)
>> im.save("../images/grainy.png", "PNG")


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


Re: Profiling weirdness: Timer.timeit(), fibonacci and memoization

2008-08-03 Thread ssecorp
I think you are confusing 2 people in this thread but that doesn't
really matter.
What surprised me was that I didn't think fib would benefit from
memoization because it didn't repeat the same calculations. fibmem
without memoization is the classic naive implementation that grows
exponentially and obv that would benefit from memoization.


from timeit import Timer
import Decorators

@Decorators.memoize
def fib(n):
a, b = 1, 0
while n:
a, b, n = b, a+b, n-1
return b

@Decorators.memoize
def fibmem(nbr):
if nbr > 1:
return fibmem(nbr-1) + fibmem(nbr-2)
if nbr == 1:
return 1
if nbr == 0:
return 0

s = 100
t1 = Timer('fib(s)', 'from __main__ import fib, s')
t2 = Timer('fibmem(s)', 'from __main__ import fibmem, s')
print t1.repeat(number=1)
print t2.repeat(number=1)
print t1.timeit()
print t2.timeit()


>>>
[4.895097002557e-005, 3.6317464929201785e-006,
3.0730162632401604e-006]
[0.0014432001832635141, 5.5873022968000452e-006,
3.0730162632417596e-006]
1.4421612244
1.34121264015
>>>
--
http://mail.python.org/mailman/listinfo/python-list


Re: proposal, change self. to .

2008-08-03 Thread Heiko Wundram

Am 03.08.2008, 12:51 Uhr, schrieb Equand <[EMAIL PROTECTED]>:

how about changing the precious self. to .
imagine

self.update()

.update()

simple right?


What about:

class x:

 def x(self,ob):
 ob.doSomethingWith(self)

? Not so simple anymore, isn't it? If you're not trolling, there's
hundreds of reasons why the explicit self is as it is, and it's not going
to go away, just as a thread that produced immense amounts of response
demonstrated around a week ago. Read that, and rethink.

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


Re: proposal, change self. to .

2008-08-03 Thread Nick Dumas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

It's also worth noting that you can use a different name for the object
that represents your class. If you did def __init__(foo):pass, then you
would be able to access the class's objects with foo.objectname. Using
self is simply the recommended standard.

Heiko Wundram wrote:
> Am 03.08.2008, 12:51 Uhr, schrieb Equand <[EMAIL PROTECTED]>:
>> how about changing the precious self. to .
>> imagine
>>
>> self.update()
>>
>> .update()
>>
>> simple right?
> 
> What about:
> 
> class x:
> 
>  def x(self,ob):
>  ob.doSomethingWith(self)
> 
> ? Not so simple anymore, isn't it? If you're not trolling, there's
> hundreds of reasons why the explicit self is as it is, and it's not going
> to go away, just as a thread that produced immense amounts of response
> demonstrated around a week ago. Read that, and rethink.
> 
> --- Heiko.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkiVqEcACgkQLMI5fndAv9j8KgCgmS2e+bTOT+sUPLYhtHBOVlyq
kxwAn028YSOGYGB4RyHZxYq6n4+tsSd+
=vH9d
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: scanf in python

2008-08-03 Thread [EMAIL PROTECTED]
On Jul 22, 2:00 pm, AMD <[EMAIL PROTECTED]> wrote:
> Hello Fredrik,
>
> I didn't think my comment would offend anyone [...]

I doubt that it offended anyone else.  Having been the recipient of a
few F-bombs :-) myself, I'd just let it go by...

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


Re: Project Question

2008-08-03 Thread Simon Brunning
2008/8/3 ToshiBoy <[EMAIL PROTECTED]>:
> Currently, I'm using iMacro, an add-on to Firefox, which runs a macro
> and enters all the info. It's great, but I would like to try and write
> a program for this in Python. It needs to collect some user input at
> the beginning, and then open the default web browser (or preferably
> runs its own interface) and enter the information by identifying the
> fields and inputting the text, and "saving" the info by "clicking"
> buttons.
>
> Is there a web browser interface module in Python that would have
> methods to do this kind of stuff?

Take a look at Mechanize: .

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues | Twitter: brunns
--
http://mail.python.org/mailman/listinfo/python-list


Re: scanf in python

2008-08-03 Thread castironpi
On Aug 3, 8:27 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Jul 22, 2:00 pm, AMD <[EMAIL PROTECTED]> wrote:
>
> > Hello Fredrik,
>
> > I didn't think my comment would offend anyone [...]
>
> I doubt that it offended anyone else.  Having been the recipient of a
> few F-bombs :-) myself, I'd just let it go by...
>
> Mike

The regular expression module (re) should be pretty handy at this.
This may not be a typical case, but:

>>> re.match( r"([0-9]+) ([0-9]*.?[0-9]+) (.{1,5})", '1 2.02 abcde' ).groups( )
('1', '2.02', 'abcde')

The float catcher doesn't catch "2."  If you need that to work or
other classes, speak up.
--
http://mail.python.org/mailman/listinfo/python-list


Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread CNiall
I am very new to Python (I started learning it just yesterday), but I 
have encountered a problem.


I want to make a simple script that calculates the n-th root of a given 
number (e.g. 4th root of 625--obviously five, but it's just an example 
:P), and because there is no nth-root function in Python I will do this 
with something like x**(1/n).


However, with some, but not all, decimals, they do not seem to 'equal 
themselves'. This is probably a bad way of expressing what I mean, so 
I'll give an example:

>>> 0.5
0.5
>>> 0.25
0.25
>>> 0.125
0.125
>>> 0.2
0.20001
>>> 0.33
0.33002

As you can see, the last two decimals are very slightly inaccurate. 
However, it appears that when n in 1/n is a power of two, the decimal 
does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
and not 0.20001?


This discrepancy is very minor, but it makes the whole n-th root 
calculator inaccurate. :\

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


Re: Profiling weirdness: Timer.timeit(), fibonacci and memoization

2008-08-03 Thread Rob Williscroft
Steven D'Aprano wrote in news:[EMAIL PROTECTED] in 
comp.lang.python:

>> So the question is: whats going on with timeit.Timer ?
> 
> As far as I can see, nothing. I think you have misunderstood the results 
> you got.

No, the answer is that is it repeats a million times.  It might better be
called repeat_one_million_times().

Or put another way, myself and the OP misinterpreted what the call 
t1.repeat( number = 1 ) did.

its a confusing API.

For the OP:

The call t1.timeit() is equivalent to t1.repeat( number = 100 ).

So it bennefits from memoization because the call *is* repeated, not
just called once like you intended.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Diez B. Roggisch

CNiall schrieb:
I am very new to Python (I started learning it just yesterday), but I 
have encountered a problem.


I want to make a simple script that calculates the n-th root of a given 
number (e.g. 4th root of 625--obviously five, but it's just an example 
:P), and because there is no nth-root function in Python I will do this 
with something like x**(1/n).


However, with some, but not all, decimals, they do not seem to 'equal 
themselves'. This is probably a bad way of expressing what I mean, so 
I'll give an example:

 >>> 0.5
0.5
 >>> 0.25
0.25
 >>> 0.125
0.125
 >>> 0.2
0.20001
 >>> 0.33
0.33002

As you can see, the last two decimals are very slightly inaccurate. 
However, it appears that when n in 1/n is a power of two, the decimal 
does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
and not 0.20001?


This discrepancy is very minor, but it makes the whole n-th root 
calculator inaccurate. :\


Welcome to the wonderful world of IEEE754. Just because other languages 
shield you from the gory details they still are there. Python chose to 
not do that, instead showing the rounding errors introduced and making 
the developer decide how to deal with these.


http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate

Diez

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


RE: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Edwin . Madari
for nth square root: use math.sqrt n times for example
>>> import math
>>> num = 625
>>> how_many_sqrt = 2
>>> for i in range(how_many_sqrt):
.. num = math.sqrt(num)
.. 
>>> num
5.0

all comparisons work fine for arbitrary floating point numbers... 
For readability print them with required precision. for example
>>> a = .2
>>> b = .4
>>> b = b/2
>>> a == b
True
>>> a, b
(0.20001, 0.20001)
>>> '%.2f' % a, '%.2f' % b
('0.20', '0.20')
>>>  

thx. Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of CNiall
Sent: Sunday, August 03, 2008 10:03 AM
To: python-list@python.org
Subject: Decimals not equalling themselves (e.g. 0.2 = 0.21)


I am very new to Python (I started learning it just yesterday), but I 
have encountered a problem.

I want to make a simple script that calculates the n-th root of a given 
number (e.g. 4th root of 625--obviously five, but it's just an example 
:P), and because there is no nth-root function in Python I will do this 
with something like x**(1/n).

However, with some, but not all, decimals, they do not seem to 'equal 
themselves'. This is probably a bad way of expressing what I mean, so 
I'll give an example:
 >>> 0.5
0.5
 >>> 0.25
0.25
 >>> 0.125
0.125
 >>> 0.2
0.20001
 >>> 0.33
0.33002

As you can see, the last two decimals are very slightly inaccurate. 
However, it appears that when n in 1/n is a power of two, the decimal 
does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
and not 0.20001?

This discrepancy is very minor, but it makes the whole n-th root 
calculator inaccurate. :\
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


__new__

2008-08-03 Thread Ethan Furman

Greetings, List!

I was browsing through the Decimal source today, and found this:

# We're immutable, so use __new__ not __init__
def __new__. . .
self = object.__new__(cls)
.
.
.
return self

Out of curiousity I then tried this:
--> import decimal
--> d25 = decimal.Decimal(25)
--> d25
Decimal("25")
--> d25._int
(2, 5)
--> d25._int = (1, 5)
--> d25
Decimal("15")
--> d25 + 15
Decimal("30")

If Decimals were really immutable, that should not have worked -- so in 
what sense are they immutable?  Does Python treat them as immutable if 
they are created with __new__ instead of __init__?


Any pointers to appropriate docs also greatly appreciated.

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


Re: Error:can't assign to operator

2008-08-03 Thread Emile van Sebille

Dennis Lee Bieber wrote:

just an fyi


self.towers = [ list(reversed(range(self.numDisks))),


or range(self.numDisks-1,-1,-1)

Emile

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


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Timothy Grant
On Sun, Aug 3, 2008 at 12:37 AM, Avi <[EMAIL PROTECTED]> wrote:
>> Apart from the initial installation of Python itself, I
>> never use an installer to install a Python package if I
>> can avoid it. I wouldn't trust it to install into the right
>> Python version.
>
> On that: how would I go about updating the system Python, then?  Or is
> that going to be stuck at whatever it is, and Mac users are expected
> to run two simultaneous Python installations?  I'm not entirely
> comfortable with having a separate MacPython (I used to do so, but it
> caused so many issues with installing new packages that I gave up on
> it) and would prefer to just update system Python.
>
> - Avi
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You will likely cause more problems updating the system python than
managing the two separate installations. OSX relies on the version of
python they ship. While there are likely cases where it could be
replaced completely safely the risks of having to re-install your OS
at some point because it has the wrong version of python are not worth
it.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: __new__

2008-08-03 Thread Emile van Sebille

Ethan Furman wrote:

--> d25._int = (1, 5)


Python considers names that start with a leading underscore as internal 
or private, and that abuse is the burden of the abuser...


Is bytecodehacks still around?  That was serious abuse  :)

Emile

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


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Tommy Nordgren


On 3 aug 2008, at 17.16, [EMAIL PROTECTED] wrote:


for nth square root: use math.sqrt n times for example


Ehum. The OP wants to compute the nth root ( not the nth square root)



import math
num = 625
how_many_sqrt = 2
for i in range(how_many_sqrt):

.. num = math.sqrt(num)
..

num

5.0

all comparisons work fine for arbitrary floating point numbers...
For readability print them with required precision. for example

a = .2
b = .4
b = b/2
a == b

True

a, b

(0.20001, 0.20001)

'%.2f' % a, '%.2f' % b

('0.20', '0.20')




thx. Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
]

On Behalf Of CNiall
Sent: Sunday, August 03, 2008 10:03 AM
To: python-list@python.org
Subject: Decimals not equalling themselves (e.g. 0.2 = 0.21)


I am very new to Python (I started learning it just yesterday), but I
have encountered a problem.

I want to make a simple script that calculates the n-th root of a  
given

number (e.g. 4th root of 625--obviously five, but it's just an example
:P), and because there is no nth-root function in Python I will do  
this

with something like x**(1/n).

However, with some, but not all, decimals, they do not seem to 'equal
themselves'. This is probably a bad way of expressing what I mean, so
I'll give an example:

0.5

0.5

0.25

0.25

0.125

0.125

0.2

0.20001

0.33

0.33002

As you can see, the last two decimals are very slightly inaccurate.
However, it appears that when n in 1/n is a power of two, the decimal
does not get 'thrown off'. How might I make Python recognise 0.2 as  
0.2

and not 0.20001?

This discrepancy is very minor, but it makes the whole n-th root
calculator inaccurate. :\
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


--
What is a woman that you forsake her, and the hearth fire and the home  
acre,
to go with the old grey Widow Maker.  --Kipling, harp song of the Dane  
women

Tommy Nordgren
[EMAIL PROTECTED]



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


module for generating captcha images

2008-08-03 Thread Irmen de Jong


Hi,

I wanted to generate Captcha images(*) from Python and I couldn't find any module that 
suited my needs so I made one myself.


It only needs PIL. (I used PIL 1.1.6)

It can generate images with a provided background or it can make a random background for 
you. It needs a truetype font to draw the letters, and outputs jpeg images.


You can download the module from http://www.razorvine.net/download/captcha.py
and see some images it made here: 
http://www.razorvine.net/download/captcha-examples/

I'm planning to improve it a bit still, I don't like the random noise lines.
It should probably draw an angled line such as you see in the wikipedia article.

Hope it's useful for anyone beside myself :)


--irmen


(*) http://en.wikipedia.org/wiki/Captcha
--
http://mail.python.org/mailman/listinfo/python-list


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Avinash Vora

You will likely cause more problems updating the system python than
managing the two separate installations.


That's sadly worrying.


OSX relies on the version of python they ship.


I think that helps my point--there *are* bug fixes between major  
versions despite the new language changes, and that can really only be  
a good thing.



While there are likely cases where it could be
replaced completely safely the risks of having to re-install your OS
at some point because it has the wrong version of python are not worth
it.



I haven't been a Mac user long enough to see a major version change (I  
was on Linux/XP/Vista for most of 2.4 and switched distributions right  
after 2.5 came out, and then XP before that), so I've never seen a  
version change, but is this the sort of thing that will be upgraded in  
Software Update?


- Avinash

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


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Timothy Grant
On Sun, Aug 3, 2008 at 10:44 AM, Avinash Vora <[EMAIL PROTECTED]> wrote:
>> You will likely cause more problems updating the system python than
>> managing the two separate installations.
>
> That's sadly worrying.
>
>> OSX relies on the version of python they ship.
>
> I think that helps my point--there *are* bug fixes between major versions
> despite the new language changes, and that can really only be a good thing.
>
>> While there are likely cases where it could be
>> replaced completely safely the risks of having to re-install your OS
>> at some point because it has the wrong version of python are not worth
>> it.
>
>
> I haven't been a Mac user long enough to see a major version change (I was
> on Linux/XP/Vista for most of 2.4 and switched distributions right after 2.5
> came out, and then XP before that), so I've never seen a version change, but
> is this the sort of thing that will be upgraded in Software Update?
>
> - Avinash

I haven't paid enough attention to the system python in my four years
as an Apple user to know. I simply installed the python I wanted and
went from there.

I honestly don't think it is a cause for concern though. The situation
is very similar to on Linux (Red Hat has their version of python) you
simply install what you want and use it.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Diez B. Roggisch

CNiall schrieb:
I am very new to Python (I started learning it just yesterday), but I 
have encountered a problem.


I want to make a simple script that calculates the n-th root of a given 
number (e.g. 4th root of 625--obviously five, but it's just an example 
:P), and because there is no nth-root function in Python I will do this 
with something like x**(1/n).


There is - pow.

>>> from math import pow
>>> pow(625, .25)
5


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


Using two pythons in an application

2008-08-03 Thread Allen
I'm in the process of developing an application that will use Python for 
a scripting support.  In light of the upcoming changes to Python, I was 
wondering if it is possible to link to and use two different versions of 
 Python so that in the future, scripts could be migrated to the new 
version, and older scripts would still work as well.  If so are there 
any code examples of this.


Brian Vanderburg II
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: pyspread 0.0.8

2008-08-03 Thread Colin J. Williams

[EMAIL PROTECTED] wrote:

On Sat, 02 Aug 2008 13:39:25 -0400
"Colin J. Williams" <[EMAIL PROTECTED]> wrote:


[EMAIL PROTECTED] wrote:

pyspread 0.0.8 has been released.



Are you planning any documentation?


Actually, yes.
0.0.10 will feature some docs.
Any help writing and doing the layout is highly appreciated ;-)


I've tried:
# tpySpread.py
print 'start'
import pyspread
print pyspread.__doc__



[snip]


I hope that this helps as a quick start.


Best Regards

Martin

I've copied your tutorial in my 
site-packages\pyspread directory


When I try it (a) I can't open your test 
data and (b)I enter 1 in [0,0], 'abc' in 
[0,1], 'def' in [0,2] and 'ghi' in [1.2].


The first gives an unable to find rpy 
message and the second doesn't display.


Here is a copy of the spreadsheet:

1   'def'
__import__("math")'ghi'
a = numpy.arange(-1,1,.001) 

rpy.r.plot(a,b,xlab='',ylab='',type='l')

I hope that this helps.

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


Re: Using two pythons in an application

2008-08-03 Thread Jorgen Grahn
On Sun, 03 Aug 2008 14:01:49 -0400, Allen <[EMAIL PROTECTED]> wrote:
> I'm in the process of developing an application that will use Python for 
> a scripting support.  In light of the upcoming changes to Python, I was 
> wondering if it is possible to link to and use two different versions of 
>   Python so that in the future, scripts could be migrated to the new 
> version, and older scripts would still work as well.  If so are there 
> any code examples of this.

I cannot answer that, sorry.

But if I were you, I'd pick a current, stable Python version for my
application, and stop worrying for now.

If there is a new, incompatible Python version (I assume you're
talking about Py3k?) these things will happen:

- people around the world will decide to migrate
- people will gain experience with migrating Python code
- Python 2.x will start to look obsolete
- things like Linux distributions and web hosting companies will
  stop offering Python 2.x
- you will be forced (for practical reasons, or to avoid looking silly)
  to migrate your application (and break old scripts)

All this will happen *slowly* -- I believe so slowly that you will
have plenty of time to act later.  And your users (or whoever has to
deal with the scripts) will not be alone; lots of people will sit
around migrating old Python code.

(Caveat: I don't know much about the Py3k transition, just about other
cases like that.  Killing off an old language dialect takes time!)

/Jorgen

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


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Jorgen Grahn
On Sun, 03 Aug 2008 16:50:22 +0200, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> CNiall schrieb:
...
>>  >>> 0.2
>> 0.20001
...

> Welcome to the wonderful world of IEEE754. Just because other languages 
> shield you from the gory details they still are there. Python chose to 
> not do that, instead showing the rounding errors introduced and making 
> the developer decide how to deal with these.

Which other languages try to hide how floating-point numbers behave?

The correct way of dealing with this (you probably agree) is never to
expect infinite precision from floats, and design your code/algorithms
accordingly -- never use "if f1==f2:" and so on.

Floating-point is a tricky area. Lots of programmers (including me)
know too little about it.

/Jorgen

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


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Diez B. Roggisch

Jorgen Grahn schrieb:

On Sun, 03 Aug 2008 16:50:22 +0200, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

CNiall schrieb:

...

 >>> 0.2
0.20001

...

Welcome to the wonderful world of IEEE754. Just because other languages 
shield you from the gory details they still are there. Python chose to 
not do that, instead showing the rounding errors introduced and making 
the developer decide how to deal with these.


Which other languages try to hide how floating-point numbers behave?


PHP and Java, amongst others. The implicitly apply a formatting when 
producing a string-representation.



The correct way of dealing with this (you probably agree) is never to
expect infinite precision from floats, and design your code/algorithms
accordingly -- never use "if f1==f2:" and so on.

Floating-point is a tricky area. Lots of programmers (including me)
know too little about it.


It sure is and I don't know too much myself. But IMHO python does 
something right when making the programmer aware of the problems that 
can appear.


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


Re: Strong/weak typing

2008-08-03 Thread Jorgen Grahn
On Fri, 01 Aug 2008 22:47:04 -0400, Mel <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>
>> I'm writing Python as if it were strongly typed, never recycling a
>> name to hold a type other than the original type.
>> 
>> Is this good software engineering practice, or am I missing something
>> Pythonic?
>
> Nothing wrong with what you're doing.  I've never come up with a really
> convincing reason to recycle names.  Possibly something that follows the
> evolution of the data:
>
> middle_name = raw_input ('Name?')
> middle_name = middle_name.split()
> middle_name = middle_name[1]
>
> It works, but I don't like it enough to actually use it.

I don't like that there are two lines where 'middle_name' isn't
actually a middle name.  It confuses me, even though I know that
everything is ok after the third line.

I reuse names though, mostly because I don't want to invent additional
names which would feel "overburdened".  I like this example better:

   months = range(1, 13)
   # do something with the months-as-numbers list,
   # and then:
   months = [ monthname(x) for x in months ]
   # do something where we only need the names

Your comment "something that follows the evolution of the data"
applies here.  It's the same data, but refined to a more usable form.

It also kills off an object which I have decided I will not need
further down, so it kind of documents that decision.

I only do this very locally, like in a simple function.

/Jorgen

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


My Python error...

2008-08-03 Thread SaMTHG
Basically I have Mac OS X 10.4.11 and I've  got python 2.5.
When I go to TextEdit and type in something like
#!/usr/bin/env python
print 2+2
and save it as simplescript.py.
Then I go to terminal and cd my way to the dir that the script source
is in and type:
python simplescript.py
And the output is:
File "simplescript.py", line 1
SyntaxError: Non-ASCII character '\xfe' in file simplescript.py on
line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details
What does this mean? And how do I make it work again?
Thanks for reading
SaMTHG
--
http://mail.python.org/mailman/listinfo/python-list


Re: very large dictionary

2008-08-03 Thread Jorgen Grahn
On Fri, 1 Aug 2008 01:05:07 -0700 (PDT), Simon Strobl <[EMAIL PROTECTED]> wrote:
>> What does "load a dictionary" mean?
>
> I had a file bigrams.py with a content like below:
>
> bigrams = {
> ", djy" : 75 ,
> ", djz" : 57 ,
> ", djzoom" : 165 ,
> ", dk" : 28893 ,
> ", dk.au" : 854 ,
> ", dk.b." : 3668 ,
> ...
>
> }
>
> In another file I said:
>
> from bigrams import bigrams
>
>> How about using a database instead of a dictionary?
>
> If there is no other way to do it, I will have to learn how to use
> databases in Python.

If you use Berkeley DB ("import bsddb"), you don't have to learn much.
These databases look very much like dictionaries string:string, only
they are disk-backed.

(I assume here that Berkeley DB supports 7GB data sets.)

/Jorgen

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


Re: My Python error...

2008-08-03 Thread Erik Max Francis

[EMAIL PROTECTED] wrote:


Basically I have Mac OS X 10.4.11 and I've  got python 2.5.
When I go to TextEdit and type in something like
#!/usr/bin/env python
print 2+2
and save it as simplescript.py.
Then I go to terminal and cd my way to the dir that the script source
is in and type:
python simplescript.py
And the output is:
File "simplescript.py", line 1
SyntaxError: Non-ASCII character '\xfe' in file simplescript.py on
line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details
What does this mean? And how do I make it work again?


It probably means that your text editor is saving as UTF-16 and it's 
seeing part of a byte order marker (0xFE 0xFF or 0xFF 0xFE depending on 
endianness) -- either that or you've accidentally injected some extra 
garbage into the file.  Save as ASCII instead.


--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
  Heaven ne'er helps the man who will not act.
   -- Sophocles
--
http://mail.python.org/mailman/listinfo/python-list


Re: very large dictionary

2008-08-03 Thread Jorgen Grahn
On 3 Aug 2008 20:36:33 GMT, Jorgen Grahn <[EMAIL PROTECTED]> wrote:
> On Fri, 1 Aug 2008 01:05:07 -0700 (PDT), Simon Strobl <[EMAIL PROTECTED]> 
> wrote:
...
>> If there is no other way to do it, I will have to learn how to use
>> databases in Python.
>
> If you use Berkeley DB ("import bsddb"), you don't have to learn much.
> These databases look very much like dictionaries string:string, only
> they are disk-backed.

... all of which Sean pointed out elsewhere in the thread.

Oh well. I guess pointing it out twice doesn't hurt.  bsddb has been
very pleasant to work with for me. I normally avoid database
programming like the plague.

/Jorgen

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


Re: Project Question

2008-08-03 Thread ToshiBoy

Great, I think that's exactly what I'm after. Thank you!

Simon Brunning wrote:

2008/8/3 ToshiBoy <[EMAIL PROTECTED]>:
  

Currently, I'm using iMacro, an add-on to Firefox, which runs a macro
and enters all the info. It's great, but I would like to try and write
a program for this in Python. It needs to collect some user input at
the beginning, and then open the default web browser (or preferably
runs its own interface) and enter the information by identifying the
fields and inputting the text, and "saving" the info by "clicking"
buttons.

Is there a web browser interface module in Python that would have
methods to do this kind of stuff?



Take a look at Mechanize: .

  


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


Re: [unittest] Run setUp only once

2008-08-03 Thread Jorgen Grahn
On Tue, 29 Jul 2008 20:12:14 +0200, Nikolaus Rath <[EMAIL PROTECTED]> wrote:
> Jean-Paul Calderone <[EMAIL PROTECTED]> writes:
>> On Tue, 29 Jul 2008 19:26:09 +0200, Nikolaus Rath <[EMAIL PROTECTED]> wrote:
>>>Jean-Paul Calderone <[EMAIL PROTECTED]> writes:
 On Tue, 29 Jul 2008 16:35:55 +0200, Nikolaus Rath <[EMAIL PROTECTED]> 
 wrote:
>Hello,
>
>I have a number of conceptually separate tests that nevertheless need
>a common, complicated and expensive setup.
>
>Unfortunately, unittest runs the setUp method once for each defined
>test, even if they're part of the same class as in

...

> Yeah, well, I guess that would work. But to me this looks really more
> like a nasty hack.. isn't there a proper solution?

[Someone described elsewhere in the thread how it's xUnit's philosophy
to have one environment per executed test.]

One option is to look into other unit test tools. People sometimes
mention "py.test" as being superior.  I haven't tried it -- I'm just a
slightly dissatisfied unittest user.

  http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#Python

/Jorgen

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


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Dan Bishop
On Aug 3, 9:02 am, CNiall <[EMAIL PROTECTED]> wrote:
> I am very new to Python (I started learning it just yesterday), but I
> have encountered a problem.
>
> I want to make a simple script that calculates the n-th root of a given
> number (e.g. 4th root of 625--obviously five, but it's just an example
> :P), and because there is no nth-root function in Python I will do this
> with something like x**(1/n).
>
> However, with some, but not all, decimals, they do not seem to 'equal
> themselves'. This is probably a bad way of expressing what I mean, so
> I'll give an example:
>  >>> 0.5
> 0.5
>  >>> 0.25
> 0.25
>  >>> 0.125
> 0.125
>  >>> 0.2
> 0.20001
>  >>> 0.33
> 0.33002
>
> As you can see, the last two decimals are very slightly inaccurate.
> However, it appears that when n in 1/n is a power of two, the decimal
> does not get 'thrown off'.

This is because your computer stores numbers in binary, and thus those
numbers can be represented exactly.

decimal 0.5 = binary 0.1
decimal 0.25 = binary 0.01
decimal 0.125 = binary 0.001

However, numbers that have "nice" representations in decimal are often
non-terminating in binary.

decimal 0.2 = binary 0.0011 0011 0011 0011 0011 0011...
decimal 0.33 = binary 0.01 0101000010111000
0101000010111000...

It's just like in decimal where 1/3 = 0.33..., so if you're
limited to a finite number of digits, you get rounding error.
(Interesting that you picked 0.33 as one of your examples.)

> How might I make Python recognise 0.2 as 0.2
> and not 0.20001?

With floats, you can't.  As far as your computer is concerned, there's
no such number as 0.2.  The closest you can get with IEEE 754 double
precision is

binary 0.001100110011001100110011001100110011001100110011001101 (53
significant bits)
= decimal 0.200011102230246251565404236316680908203125
(exactly)

If absolutely necessary, you can use the decimal.Decimal("0.2").
However, I do *NOT* recommend always using decimal arithmetic, for the
following reasons:

(1) You still have to deal with round-off errors resulting from finite
precision.  For example:

>>> Decimal(1) / 3 * 3
Decimal("0.")
>>> Decimal.sqrt(Decimal(2)) ** 2
Decimal("1.999")

(2) There's nothing special about the number ten.  We chose it as our
number base not because of any of its mathematical properties, but
simply because of the number of fingers we have.  The designers of our
computers recognized this fact and chose to optimize the hardware for
base-two instead, therefore...

(3) Decimal arithmetic is at least an order of magnitude slower binary
arithmetic.

If your complaint is merely about all the "noise" digits displayed,
simply use a smaller number of significant digits.

>>> repr(0.2)
'0.20001'
>>> '%.17g' % 0.2
'0.20001'
>>> '%.16g' % 0.2
'0.2'

> This discrepancy is very minor, but it makes the whole n-th root
> calculator inaccurate. :\

I think you may have unrealistic expectations for accuracy.

Unlike ints, which are used for counted (and therefore exact)
quantities, floats are typically used for measured (and therefore
inexact) quantities.

The error in approximating 0.2 by its double-precision approximation
is less than 56 parts per quintillion.  There are very few physical
measurements that require that level of accuracy.  Suppose you went to
the butcher's and ordered a pound of beef, and got only
0.444888487687 pound.  Would you even notice?  And if
you did, how exactly would you expect them to compensate you for the
less than a trillionth of a cent that you got shortchanged?
--
http://mail.python.org/mailman/listinfo/python-list


How do I find out from inside pdb which namespace contains an object?

2008-08-03 Thread Jonathan Mark
I am inside a Pdb-like Plone debugging tool and I get the following
error at the prompt. I was wondering how to find out from inside the
debugger which namespace the collective.dancing.channel object is
located in. :

collective.dancing.channel.tool_added(DelegateNichols.portal_newsletters,
None)
collective.dancing.channel.tool_added(DelegateNichols.portal_newsletters,
None)
002
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'collective' is not defined
--
http://mail.python.org/mailman/listinfo/python-list


Re: very large dictionary

2008-08-03 Thread member thudfoo
On 3 Aug 2008 20:40:02 GMT, Jorgen Grahn <[EMAIL PROTECTED]> wrote:
> On 3 Aug 2008 20:36:33 GMT, Jorgen Grahn <[EMAIL PROTECTED]> wrote:
>  > On Fri, 1 Aug 2008 01:05:07 -0700 (PDT), Simon Strobl <[EMAIL PROTECTED]> 
> wrote:
>
> ...
>
> >> If there is no other way to do it, I will have to learn how to use
>  >> databases in Python.
>  >
>  > If you use Berkeley DB ("import bsddb"), you don't have to learn much.
>  > These databases look very much like dictionaries string:string, only
>  > they are disk-backed.
>
>
> ... all of which Sean pointed out elsewhere in the thread.
>
>  Oh well. I guess pointing it out twice doesn't hurt.  bsddb has been
>  very pleasant to work with for me. I normally avoid database
>  programming like the plague.
>
>

13.4 shelve -- Python object persistence

 A ``shelf'' is a persistent, dictionary-like object. The difference
with ``dbm'' databases is that the values (not the keys!) in a shelf
can be essentially arbitrary Python objects -- anything that the
pickle module can handle. This includes most class instances,
recursive data types, and objects containing lots of shared
sub-objects. The keys are ordinary strings

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


Re: ANN: pyspread 0.0.8

2008-08-03 Thread Martin Manns
On Sun, 03 Aug 2008 14:25:11 -0400
"Colin J. Williams" <[EMAIL PROTECTED]> wrote:
> I've copied your tutorial in my 
> site-packages\pyspread directory

I wrote the tutorial in this thread as a step by step guide that
can be followed manually. You do not need to put it anywhere on your
hard drive. Start pyspread and type in the lines starting with "> "
manually.

> When I try it (a) I can't open your test 
> data and (b)I enter 1 in [0,0], 'abc' in 
> [0,1], 'def' in [0,2] and 'ghi' in [1.2].

I assume that you tried to open the "test.pys" file. This file is not
needed for the tutorial. Type in as you did into the empty grid and it
should work.
(Please tell me if it does not display 1 in [0,0], abc in [0,1], def in
[0,2] and ghi in [1,2].)

> The first gives an unable to find rpy 
> message and the second doesn't display.

The "test.pys" file is an example how to use the 3rd party package rpy
for convenient plotting. Probably on your system, rpy is not installed.
When you install rpy, do not forget to install the statistics package R
that it depends on as well.

However, you do not have to use rpy for plotting. If you prefer other
plotting packages (e.g. gnuplot), feel free to import them as displayed
with the decimal built-in package. You can import (almost) everything
that you can import in any Python program (though matplotlib made some
trouble the last time I tried). 

(Hint: pyspread does *not* protect your system in any special way. So if
you write a system command to delete all files and have sufficient
rights to do this, the files will be deleted.)

Please let me know, which OS you are using (Unix/Linux, MacOS, Windows
or something else).

Best Regards

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


Re: ANN: pyspread 0.0.8

2008-08-03 Thread Colin J. Williams

Martin Manns wrote:

On Sun, 03 Aug 2008 14:25:11 -0400
"Colin J. Williams" <[EMAIL PROTECTED]> wrote:
I've copied your tutorial in my 
site-packages\pyspread directory


I wrote the tutorial in this thread as a step by step guide that
can be followed manually. You do not need to put it anywhere on your
hard drive. Start pyspread and type in the lines starting with "> "
manually.
This was just for interim project 
documwntation


When I try it (a) I can't open your test 
data and (b)I enter 1 in [0,0], 'abc' in 
[0,1], 'def' in [0,2] and 'ghi' in [1.2].


I assume that you tried to open the "test.pys" file. 

Yes, nothing was loaded.
This file is not

needed for the tutorial. Type in as you did into the empty grid and it
should work.

It did not.

(Please tell me if it does not display 1 in [0,0], abc in [0,1], def in
[0,2] and ghi in [1,2].)

The first gives an unable to find rpy 
message and the second doesn't display.


The "test.pys" file is an example how to use the 3rd party package rpy
for convenient plotting. Probably on your system, rpy is not installed.
When you install rpy, do not forget to install the statistics package R
that it depends on as well.
I suggest that such prerequisites go in 
the __doc__.


However, you do not have to use rpy for plotting. If you prefer other
plotting packages (e.g. gnuplot), feel free to import them as displayed
with the decimal built-in package. You can import (almost) everything
that you can import in any Python program (though matplotlib made some
trouble the last time I tried). 


(Hint: pyspread does *not* protect your system in any special way. So if
you write a system command to delete all files and have sufficient
rights to do this, the files will be deleted.)

Please let me know, which OS you are using (Unix/Linux, MacOS, Windows
or something else).


Windows XP Pro


Best Regards

Martin


I'll get rpy to try it again in a few days.

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


Keg - A python web framework

2008-08-03 Thread eghansah
Hi,

I've been working on a python web framework which I think might be of
interest to you.
Details may be found at http://code.google.com/p/keg/wiki/Concept.


All suggestions or comments will be greatly appreciated.


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

Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Larry Bates

CNiall wrote:
I am very new to Python (I started learning it just yesterday), but I 
have encountered a problem.


I want to make a simple script that calculates the n-th root of a given 
number (e.g. 4th root of 625--obviously five, but it's just an example 
:P), and because there is no nth-root function in Python I will do this 
with something like x**(1/n).


However, with some, but not all, decimals, they do not seem to 'equal 
themselves'. This is probably a bad way of expressing what I mean, so 
I'll give an example:

 >>> 0.5
0.5
 >>> 0.25
0.25
 >>> 0.125
0.125
 >>> 0.2
0.20001
 >>> 0.33
0.33002

As you can see, the last two decimals are very slightly inaccurate. 
However, it appears that when n in 1/n is a power of two, the decimal 
does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
and not 0.20001?


This discrepancy is very minor, but it makes the whole n-th root 
calculator inaccurate. :\


What are they teaching in computer science classes these days?

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


from Tkinter import *,win = Tk() "from Tkinter import *"

2008-08-03 Thread Pierre Dagenais

from Tkinter import *
win = Tk()


If I type those two lines at the command prompt (in WindowsXP) I get a 
new window on my screen. Yet if I copy those lines in a file called 
test.py and then run "python test.py" at the command prompt I am 
returned to the command prompt and nothing shows up on the screen. Is 
this normal behavior or is it a bug?


Thanks to all who responded to my previous post, it was quite helpfull.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using two pythons in an application

2008-08-03 Thread Larry Bates

Allen wrote:
I'm in the process of developing an application that will use Python for 
a scripting support.  In light of the upcoming changes to Python, I was 
wondering if it is possible to link to and use two different versions of 
 Python so that in the future, scripts could be migrated to the new 
version, and older scripts would still work as well.  If so are there 
any code examples of this.


Brian Vanderburg II


Unlike languages you pay for, Python has on real motivation to "obsolete" old 
versions of Python (e.g. to force you to pay of an upgrade).  You can still get 
version 1.5.2 of Python and it is MANY years old and most could consider quite 
obsolete.  I just would not worry about it and stick with 2.5/2.6 for 
development and begin looking at Python 3.0 so I can learn what's new and exciting.


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


Inserting into a combo box

2008-08-03 Thread Brandon
I'm attempting to insert items into a combo box, but when it goes to run it, 
throws up the error:

TypeError: argument 1 of QComboBox.insertItem() has an invalid type

and here is what I'm trying to do:

self.editUsername.insertItem(uname)
editUsername is the combo box, and uname is a string I'm attempting to 
insert.

Any suggestions? 


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


Re: from Tkinter import *,win = Tk() "from Tkinter import *"

2008-08-03 Thread Larry Bates

Pierre Dagenais wrote:

from Tkinter import *
win = Tk()


If I type those two lines at the command prompt (in WindowsXP) I get a 
new window on my screen. Yet if I copy those lines in a file called 
test.py and then run "python test.py" at the command prompt I am 
returned to the command prompt and nothing shows up on the screen. Is 
this normal behavior or is it a bug?


Thanks to all who responded to my previous post, it was quite helpfull.


The window opens and closes so fast you can't see it.  You will need to put 
something in the window and start a message loop for it to stay up there.


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


Re: very large dictionary

2008-08-03 Thread Avinash Vora


On Aug 4, 2008, at 4:12 AM, Jörgen Grahn wrote:


(You might want to post this to comp.lang.python rather than to me --
I am just another c.l.p reader.  If you already have done to, please
disregard this.)


Yeah, I hit "reply" by mistake and didn't realize it.  My bad.


(I assume here that Berkeley DB supports 7GB data sets.)


If I remember correctly, BerkeleyDB is limited to a single file size
of 2GB.


Sounds likely.  But with some luck maybe they have increased this in
later releases?  There seem to be many competing Berkeley releases.


It's worth investigating, but that leads me to:


I haven't caught the earlier parts of this thread, but do I
understand correctly that someone wants to load a 7GB dataset into  
the

form of a dictionary?


Yes, he claimed the dictionary was 6.8 GB.  How he measured that, I
don't know.



To the OP: how did you measure this?

--
Avi

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


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Fuzzyman
On Aug 3, 3:02 pm, CNiall <[EMAIL PROTECTED]> wrote:
> I am very new to Python (I started learning it just yesterday), but I
> have encountered a problem.
>
> I want to make a simple script that calculates the n-th root of a given
> number (e.g. 4th root of 625--obviously five, but it's just an example
> :P), and because there is no nth-root function in Python I will do this
> with something like x**(1/n).
>
> However, with some, but not all, decimals, they do not seem to 'equal
> themselves'. This is probably a bad way of expressing what I mean, so
> I'll give an example:
>  >>> 0.5
> 0.5
>  >>> 0.25
> 0.25
>  >>> 0.125
> 0.125
>  >>> 0.2
> 0.20001
>  >>> 0.33
> 0.33002
>
> As you can see, the last two decimals are very slightly inaccurate.
> However, it appears that when n in 1/n is a power of two, the decimal
> does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2
> and not 0.20001?
>
> This discrepancy is very minor, but it makes the whole n-th root
> calculator inaccurate. :\

You're using floating point numbers and not decimals. For the
precision of decimals use the Python standard library decimal module.

As others have noted, the accuracy issue with floating point numbers
is enshrined in their implementation at the platform level and has
nothing to do with Python.

Michael Foord
--
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: __new__

2008-08-03 Thread Ethan Furman

Emile van Sebille wrote:

Ethan Furman wrote:

--> d25._int = (1, 5)


Python considers names that start with a leading underscore as internal 
or private, and that abuse is the burden of the abuser...


Is bytecodehacks still around?  That was serious abuse  :)

Emile


Good point.  What I'm curious about, though, is the comment in the code 
about making the Decimal instance immutable.  I was unable to find docs 
on that issue.


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


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Grant Edwards
On 2008-08-03, Larry Bates <[EMAIL PROTECTED]> wrote:

>> However, it appears that when n in 1/n is a power of two, the decimal 
>> does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
>> and not 0.20001?
>> 
>> This discrepancy is very minor, but it makes the whole n-th root 
>> calculator inaccurate. :\
>
> What are they teaching in computer science classes these days?

When I was an undergrad the only courses that dealt with FP
issues were classes on numerical analysis.  I don't even know
if numerical analysis classes were required for CS majors.  I
think most of us in that class were engineering majors.

-- 
Grant Edwards   grante Yow! I wish I was a
  at   sex-starved manicurist
   visi.comfound dead in the Bronx!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Steven D'Aprano
On Sun, 03 Aug 2008 17:30:29 -0500, Larry Bates wrote:

>> As you can see, the last two decimals are very slightly inaccurate.
>> However, it appears that when n in 1/n is a power of two, the decimal
>> does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2
>> and not 0.20001?
>> 
>> This discrepancy is very minor, but it makes the whole n-th root
>> calculator inaccurate. :\
> 
> What are they teaching in computer science classes these days?


I don't know about these days, but 20-odd years ago there was no 
discussion of floating point accuracy in the Comp Sci classes I did at 
Melbourne Uni. I did a class in computational mathematics, run by the 
maths department, and it discussed a lot of issues about accuracy in 
float calculations. However, if they mentioned anything about e.g. 0.2 
not being exactly representable in binary, I slept through it.

Maybe that's why I failed that class. *wry grin*


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


Re: Profiling weirdness: Timer.timeit(), fibonacci and memoization

2008-08-03 Thread Steven D'Aprano
On Sun, 03 Aug 2008 09:46:45 -0500, Rob Williscroft wrote:

> Steven D'Aprano wrote in news:[EMAIL PROTECTED]
> in comp.lang.python:
> 
>>> So the question is: whats going on with timeit.Timer ?
>> 
>> As far as I can see, nothing. I think you have misunderstood the
>> results you got.
> 
> No, the answer is that is it repeats a million times.  It might better
> be called repeat_one_million_times().

But that would be seriously broken if you call it like this:

Timer.repeat_one_million_times(5, 1000)

It doesn't repeat one million times. It repeats five times, of 1000 loops 
each.


> Or put another way, myself and the OP misinterpreted what the call
> t1.repeat( number = 1 ) did.
>
> its a confusing API.

There's certainly confusion happening. Perhaps reading the doc strings 
might clear up some confusion? help(Timer.repeat) and help(Timer.timeit) 
state very clearly that they default to one million iterations.


> For the OP:
> 
> The call t1.timeit() is equivalent to t1.repeat( number = 100 ).

No it isn't. Try running the code and looking at the results it gives.

t1.repeat(number=10**6) returns a list of three numbers. The function is 
called *three* million times in total.

t1.timeit() returns a single number.

In fact, t1.timeit() is equivalent to 
t1.repeat(repeat=1, number=100), (apart from it being in a list). 
That can be written more simply as: t1.repeat(1)


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


Re: __new__

2008-08-03 Thread Calvin Spealman
its a good point you make. if its not _technically_ immutable, why use
__new__ when __init__ would work just as fine? well, if it should be
treated as immutable, then we should do what we can to follow that,
even in internal code that knows otherwise. Besides, maybe down the
road, protections will be added to disallow assignment to _int, and
the author thought to future proof it. In any case, the author can
only know, perhaps. ask if you really feel the need to know.

On Sun, Aug 3, 2008 at 2:32 PM, Ethan Furman <[EMAIL PROTECTED]> wrote:
> Emile van Sebille wrote:
>>
>> Ethan Furman wrote:
>>>
>>>--> d25._int = (1, 5)
>>
>> Python considers names that start with a leading underscore as internal or
>> private, and that abuse is the burden of the abuser...
>>
>> Is bytecodehacks still around?  That was serious abuse  :)
>>
>> Emile
>
> Good point.  What I'm curious about, though, is the comment in the code
> about making the Decimal instance immutable.  I was unable to find docs on
> that issue.
>
> ~Ethan~
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I find out from inside pdb which namespace contains an object?

2008-08-03 Thread Jonathan Mark
Never mind. I had to run "import collective.dancing" first.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using two pythons in an application

2008-08-03 Thread Allen

Larry Bates wrote:

Allen wrote:
I'm in the process of developing an application that will use Python 
for a scripting support.  In light of the upcoming changes to Python, 
I was wondering if it is possible to link to and use two different 
versions of  Python so that in the future, scripts could be migrated 
to the new version, and older scripts would still work as well.  If so 
are there any code examples of this.


Brian Vanderburg II


Unlike languages you pay for, Python has on real motivation to 
"obsolete" old versions of Python (e.g. to force you to pay of an 
upgrade).  You can still get version 1.5.2 of Python and it is MANY 
years old and most could consider quite obsolete.  I just would not 
worry about it and stick with 2.5/2.6 for development and begin looking 
at Python 3.0 so I can learn what's new and exciting.


-Larry


I agree.  I had wanted for scripts of the program to be able to use the 
new string format method that is only in py3k, but I'm currently looking 
into other template solutions.


Brian Vanderburg II
--
http://mail.python.org/mailman/listinfo/python-list


Re: Teething troubles with Python on a Mac

2008-08-03 Thread greg

Avi wrote:


On that: how would I go about updating the system Python, then?


The usual advice is not to try to do that at all.
Generally it's best to treat anything in /System
as off-limits.


(I used to do so, but it
caused so many issues with installing new packages that I gave up on
it)


I've very rarely had any problem with maintaining my
own Python installation, but as I said, I always install
packages using "python setup.py".

Python itself copes very well with having multiple
versions installed, on all platforms, but you have to
do things the Python way.

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


PyWorks Call for Papers extended

2008-08-03 Thread Brian Jones
For those who don't follow PlanetPython, Python Magazine, OnLAMP, or
some of the other Python news/blog outlets, PyWorks is a Python
conference being held November 12-14, 2008, in Atlanta, by MTA
(publisher of Python Magazine). The call for papers has been what I
would call a success, but I've noticed that lots of people were at
conferences when the deadline passed on July 25, and so I've been
getting the bulk of the submissions over just the past few days! I'd
like to see even more proposals, in the interest of offering the "best
of the best" to our audience, so if you've held off because you missed
the July 25 deadline, don't. If you would like to give a talk, or
you'd like to see a talk given, please shoot me an email, preferably
after perusing the Call for Papers page located here -->
http://pyworks.mtacon.com/c/p/pyworks,cfp

If you have any other questions about the conference, you can also
send me an email, or join me (and the authors and editors of Python
Magazine, among others) on irc in #pymag on irc.freenode.net

Thanks to everyone here -- I've learned tons by lurking here over the
past year or so. Hope to meet some of you in November!
brian



-- 
Brian K. Jones
Python Magazine http://www.pythonmagazine.com
My Blog http://www.protocolostomy.com
--
http://mail.python.org/mailman/listinfo/python-list


Trying to fix Invalid CSV File

2008-08-03 Thread Ryan Rosario
I have a very large CSV file that contains double quoted fields (since
they contain commas). Unfortunately, some of these fields also contain
other double quotes and I made the painful mistake of forgetting to
escape or double the quotes inside the field:

123,"Here is some, text "and some quoted text" where the quotes should
have been doubled",321

Has anyone dealt with this problem before? Any ideas of an algorithm I
can use for a Python script to create a new, repaired CSV file?

TIA,
Ryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Cameron Simpson
On 03Aug2008 23:14, Avinash Vora <[EMAIL PROTECTED]> wrote:
>> You will likely cause more problems updating the system python than
>> managing the two separate installations.
>
> That's sadly worrying.

It shouldn't be. It is often useful to have multiple versions of stuff
installed.

Replacing the system stuff means playing in the vendor/distributor's
namespace, and you may expect they to cheerfully and freely tread all
over your changes if something in Software Update wants to.

By keeping a separate Python install you know you are not damaging the
system, and the system will not damage you.

Personally I use python 2.5 from the macports stuff, which installs to
/opt/local. Neatly out of the way. It's all very easy.

>> OSX relies on the version of python they ship.
>
> I think that helps my point--there *are* bug fixes between major  
> versions despite the new language changes, and that can really only be a 
> good thing.

No, it does not help your point. The OS may rely on a _bug_!  It is best
to keep the OS and the stuff it uses pristine, because the two parts are
shaped to fit each other. They work now, and you're changing something
that works. Whether an "upgrade" changes a bug or a feature is irrelevant
- it changes behaviour.

Cheers,
-- 
Cameron Simpson <[EMAIL PROTECTED]> DoD#743
http://www.cskk.ezoshosting.com/cs/

Zombies don't get pumped.   - Jake, in rec.climbing
--
http://mail.python.org/mailman/listinfo/python-list


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Sean DiZazzo
> Question 1: How can I locate the Python installation? There a few
> files under Applications > MacPython 2.5, but this is clearly not the
> entire installation.

find / -name "site-packages"

Will lead you to where SciPy and Numpy should be installed for each
Python installation.  You can work backwards from there.

>
> Question 2: In Finder, If I click on Search For > Past week, I can see
> a sequence of folders under the horizontal scroll bar at the bottom of
> the window, allowing me to determine that some files that were placed
> under Applications > MacPython 2.5> Extra> Demo. But I do not seem to
> be able to see the sequence of folders under the horizontal scroll bar
> in any finder window. What do I need to do to make the folder sequence
> visible in all Finder Windows?

You can do what you want in Leopard, but not in Tiger.  I Don't have a
Leopard install in front of me.  Check Finder->Preferences, or Finder-
>View->Show View Options

> Question 4. How do I get MacPython 2.5.2 to see SciPy, NumPy etc.

I've had very good luck with "easy_install" It downloads and installs
the right package for your install.

http://peak.telecommunity.com/DevCenter/EasyInstall

> Question 5. How can I find the current value of the PYTHONPATH
> environment variable, and how can I edit it and add a directory in
> which I keep my Python programs.

I'm not even sure it's set.  I have never had to worry about it.

> Question 6. Apparently there's a Property List Editor that must be
> used to create a file called ~ /.MacOSX/environment.plist. I can't
> find a directory called ~/.MacOSX. Is this a hidden directory?

It doesn't exist by default, you have to create it.  I don't have the
format of the environment.plist in front of me, but if I remember
correctly, you can create it with any text editor.  Or you can
download a freeware program to do the whole shebang for you:
http://www.versiontracker.com/dyn/moreinfo/macosx/15073

> Item 4. I opened a terminal window, and typed ipython. Here's what I
> got:
>
> The ipython/IPython directory should be in a directory belonging to
> your
> PYTHONPATH environment variable (that is, it should be in a directory
> belonging to sys.path). You can copy it explicitly there or just link
> to it.
>
> Question 7. What is this cryptic message all about? I'm completely
> confused.

Try copying the ipython directory into the corresponding "site-
packages" directory from earlier.  Otherwise, scrap it and use
easy_install.

Good luck!

~Sean

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


Peer-to-Peer Chat Program

2008-08-03 Thread Trevor Slocum
Python seemed like the right choice for writing a peer-to-peer application,
as the support for sockets is adequate and the cross-platform ability is
nominal.  That's why I searched around for P2P frameworks in Python, and
didn't have much luck.  The framework that I did find was designed
specifically for file transfers, rather than simple message carriers, and
implemented a complex multicast system.

So, with Python in one hand and Google in the other, I set out to write my
own P2P app in Python, with zero previous P2P experience.  I had to start
off by looking up how P2P works, then figure out how to get messages across
the network, and then how to bootstrap each node, without centralizing the
network.

I decided to make it connectionless because they were simple messages.  The
current implementation is that a peer creates a message and forwards it to
all of its known peers, and then the other peers do the same.  This is for
simplicity, as it causes quite a bit of needless rebound from each of the
other peers sending a message which has already been received.  In order to
reduce this, each message is tagged with a unique ID which is verified
against upon each arrival.

Once that worked well, I needed to get peers to know each other.  My current
solution is a provider script running on a single server which is
auto-pinged every minute by each peer, and any new peers receive a list of
known peers from it.  This can easily be expanded to many more servers in
case any go offline.  Even if zero providers are online, users can manually
add nodes from the console and the framework will automatically build a
known peer list from them.

Like I said, I didn't know anything about P2P before this, and I'm sure much
of what I've done so far can be improved upon.  That's why I'm posting
here.  I'd like to make an open request to anyone who would like to assist
me in the application development to reduce the resource usage and improve
the overall network efficiency.  Even simple "Ah, I saw you were doing this
in your code, I recommend you do this..." would be of great help.

If you are interested, you may view the Google Code page at
http://code.google.com/p/kaishi/ or checkout the SVN repository directly
using http://kaishi.googlecode.com/svn/trunk/

I have proper hosting and can set up a specific website for collaboration on
project ideas and such if support is carried after this message.  I thank
anyone who has taken their time to read this.

-- 
Trevor "tj9991" Slocum
--
http://mail.python.org/mailman/listinfo/python-list

Re: Trying to fix Invalid CSV File

2008-08-03 Thread Emile van Sebille

Ryan Rosario wrote:

I have a very large CSV file that contains double quoted fields (since
they contain commas). Unfortunately, some of these fields also contain
other double quotes and I made the painful mistake of forgetting to
escape or double the quotes inside the field:

123,"Here is some, text "and some quoted text" where the quotes should
have been doubled",321




rec = '''123,"Here is some, text "and some quoted text" where the quotes 
should have been doubled",321'''


import csv

csv.reader([rec.replace(',"',',"""')
   .replace('",','""",')
   .replace('"""',"'''")
   .replace('"','""')
   .replace("'''",'"')]).next()

['123', 'Here is some, text "and some quoted text" where the quotes 
should have been doubled', '321']


:))

Emile



Has anyone dealt with this problem before? Any ideas of an algorithm I
can use for a Python script to create a new, repaired CSV file?

TIA,
Ryan
--
http://mail.python.org/mailman/listinfo/python-list



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


Are makepy-generated COM wrapper classes distributable?

2008-08-03 Thread gundlach
Hi!

I've just written a Python speech-recognition module (http://
pyspeech.googlecode.com).  It provides a clean and simple interface to
the Microsoft Speech SDK using COM wrapper classes generated by
PythonWin's MakePY utility.

Once this is a mature module, I'd like to make it as useful as
possible to the community, so I'd like to make installation as simple
as possible.  Currently, to get speech.py to work, you must first:

* install the Microsoft Speech SDK onto a Windows box, and
* possibly install PythonWin, and then
* run PythonWin's MakePY utility to generate modules into the gen_py
dir.

I'd like to remove the MakePY steps, so that as long as a user has run
the SDK installer, she can install the 'speech' package and be ready
to use it.  Can I somehow bundle the generated modules into my
setuptools package so that the wrappers are installed at the same
time?  (If so, how -- just copy them into the package directory?)  Or
are the wrappers targeted to my machine or installation, so that
everyone is forced to go through this?

Thanks for any pointers,
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: A bug in difflib module? (find_longest_match)

2008-08-03 Thread Calvin Spealman
This came up again and I was taking a look at it. There seems to still
be no resolution. I have a patch that can add a kwarg to skip this
behavior if you know you need otherwise. Right now its a simple
boolean flag, but is this enough?

Are there any use cases anyone has to define how this case is
determined? For example, does the user of SequenceMatcher ever need to
tell it what is considered a large sequence? Right now it is hardcoded
at 200 and an element is popular is more than 1% of the elements are
it. So, does anyone need more than boolean or do you also need to say
"a large sequence is 1000 or more in size and a popular element needs
to be 10% of the sequence", as well as just turning off the behavior
completely.

With that answered, I'll apply submit the patch to the tracker.

On Thu, May 1, 2008 at 6:52 AM, Gabriel Genellina
<[EMAIL PROTECTED]> wrote:
> En Thu, 01 May 2008 06:21:22 -0300, n00m <[EMAIL PROTECTED]> escribió:
>
>>> > import difflib
>>> > s = difflib.SequenceMatcher(None, s1, s2)
>>> > print s.find_longest_match(0, len(s1), 0, len(s2))
>>> > (0, 0, 0)
>>> >
>>> > I think it's line #314 in difflib "who's to blame" --
>>>
>>> Me too. Could you think of some alternative? Simply disabling that
>>> "popularity check" would slow down the algorithm, according to the
>>> comments.
>>
>> No idea :)
>
> The "ignore popular elements" is only an optmization, and it should not be
> applied in your case because it forces the algorithm to yield an invalid
> result.
> I can think of two alternatives:
> - tune up the conditions when the optimization is used, or
> - make it user configurable
>
> SequenceMatcher is a public class, and it is also internally used by Differ
> and others to compare both sequences of lines *and* pairs of similar lines
> (considered as sequences of characters). In this last usage the "ignore
> popular elements" has no much sense, as shown in your example feeding
> directly two dissimilar strings.
> In principle one should disable the "populardict" stuff when dealing with
> strings. Below is a simple attempt to detect that case:
>
> (around line 311 in difflib.py)
>
>b_is_string = isinstance(b, basestring) # add this line
>for i, elt in enumerate(b):
>if elt in b2j:
>indices = b2j[elt]
>if not b_is_string and n >= 200 and len(indices) * 100 > n: #
> change this line
>populardict[elt] = 1
>del indices[:]
>else:
>indices.append(i)
>else:
>b2j[elt] = [i]
>
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list