Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Chris Angelico
On Sun, Sep 25, 2011 at 3:31 PM, Steven D'Aprano wrote: 2.1 == F(21, 10) > False > Ahh, but that may just mean that Fraction doesn't implement an == that compares with floats. >>> 2.1==float(F(21,10)) True This may be because one oughtn't to use == with floats anyway. >>> F(2.1)==F(21,10)

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Terry Reedy
On 9/25/2011 1:21 AM, Steven D'Aprano wrote: Terry Reedy wrote: On 9/24/2011 9:53 AM, Steven D'Aprano wrote: [...] [0.0 + i*width for i in range(8)] [0.0, 0.3, 0.6, 0.8999, 1.2, 1.5, 1.7998, 2.1] The 4th and 7th values have rounding errors, the rest are exact No th

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Chris Angelico
On Sun, Sep 25, 2011 at 3:31 PM, Steven D'Aprano wrote:>> If you look again at the code I used, I did. I just did it inside the list> comp. You did, but you created a Fraction from a float; my version used Fraction(21,10) instead of (effectively) Fraction(2.1). My description was a little sloppy,

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread John Ladasky
On Sep 24, 6:53 am, Steven D'Aprano wrote: > I'm trying to generate a sequence of equally-spaced numbers between a lower > and upper limit. Given arbitrary limits, what is the best way to generate a > list of equally spaced floats with the least rounding error for each point? > > For example, supp

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Chris Angelico wrote: > On Sun, Sep 25, 2011 at 3:01 AM, Steven D'Aprano > wrote: >> Mark Dickinson wrote: >> >>> Using Fraction for intermediate calculations actually works perfectly >>> for this, since conversions from float to Fraction are exact, while >>> conversions from Fraction to float ar

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Terry Reedy wrote: > On 9/24/2011 9:53 AM, Steven D'Aprano wrote: [...] > [0.0 + i*width for i in range(8)] >> [0.0, 0.3, 0.6, 0.8999, 1.2, 1.5, 1.7998, 2.1] >> >> The 4th and 7th values have rounding errors, the rest are exact > > No they are not. Their errors are jus

Re: Why is the shutil module called shutil?

2011-09-24 Thread Matt Joiner
Please continue On Sun, Sep 25, 2011 at 8:36 AM, rantingrick wrote: > On Sep 23, 10:36 pm, Fletcher Johnson wrote: >> The topic says it all: >> Why is shutil named shutil? What does it stand for? This is just a >> mild curiosity of mine. >> The shutil module for >> reference:http://docs.python.

Re: Suggested coding style

2011-09-24 Thread Devin Jeanpierre
> Padding numbers with leading zeroes is very common. I'm surprised that > more languages don't make it a string method. By making it a string method, instead of a function, we force all implementations of strings to implement that method. That sort of sucks, and it's a reason not to include it as

Re: Suggested coding style

2011-09-24 Thread Steven D'Aprano
MRAB wrote: > On 24/09/2011 20:10, Tim Johnson wrote: >> * Passiday [110924 09:47]: >> <...> >>> I have been coding in many other languages, most of the time it was >>> Java and C#. I don't like the function mess of PHP (ie, loads and >>> loads of functions without any namespaces etc), but I'd li

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Arnaud Delobelle wrote: > On these examples, using fractions is no better than what I suggested > in my previous post. I'm sorry, I can't see your previous post. Perhaps it isn't available on my news provider? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 2.5 zlib trouble

2011-09-24 Thread Christian Heimes
Am 25.09.2011 01:33, schrieb Benjamin Kaplan: > There is no binary installer on that page. That means you downloaded > the source code and compiled it yourself. Yes, you didn't patch it. > But it's still a self-compiled version of Python. > > In order to get zlib in a self-compiled version of Pyth

Re: Python Mixins

2011-09-24 Thread Tim Chase
On 09/24/11 17:41, rantingrick wrote: On Sep 24, 3:57 am, Steven D'Aprano wrote: class StandardTestMixin: def test_requires_one_argument(self): self.assertRaises(TypeError, self.func) def test_has_docstring(self): self.assertTrue(self.func.__doc__) And this is ano

Re: Why is the shutil module called shutil?

2011-09-24 Thread Terry Reedy
On 9/23/2011 11:36 PM, Fletcher Johnson wrote: The topic says it all: Why is shutil named shutil? What does it stand for? This is just a mild curiosity of mine. The shutil module for reference: http://docs.python.org/library/shutil.html#module-shutil I think it would be nice if the doc explain

Re: Python Mixins

2011-09-24 Thread Terry Reedy
On 9/24/2011 4:57 AM, Steven D'Aprano wrote: Python says is that issubclass(Cat, Yamlafiable) will return True. The *interpretation* of that fact is entirely up to you. If you want to interpret it as meaning that cats are Yamlafiables, go right ahead. If you want to interpret it as a technical r

Re: Python 2.5 zlib trouble

2011-09-24 Thread Benjamin Kaplan
On Sat, Sep 24, 2011 at 7:08 PM, Jesramz wrote: > > I installed it from here: http://www.python.org/getit/releases/2.5.6/ > > What do you think a solution might be? > There is no binary installer on that page. That means you downloaded the source code and compiled it yourself. Yes, you didn't pat

Re: Python 2.5 zlib trouble

2011-09-24 Thread Jesramz
I installed it from here: http://www.python.org/getit/releases/2.5.6/ What do you think a solution might be? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Mixins

2011-09-24 Thread rantingrick
On Sep 24, 3:57 am, Steven D'Aprano wrote: > class StandardTestMixin: >     def test_requires_one_argument(self): >         self.assertRaises(TypeError, self.func) >     def test_has_docstring(self): >         self.assertTrue(self.func.__doc__) And this is another example of why we need doc-stri

Re: Why is the shutil module called shutil?

2011-09-24 Thread rantingrick
On Sep 23, 10:36 pm, Fletcher Johnson wrote: > The topic says it all: > Why is shutil named shutil? What does it stand for? This is just a > mild curiosity of mine. > The shutil module for > reference:http://docs.python.org/library/shutil.html#module-shutil Because even after 20 freaking years o

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Terry Reedy
On 9/24/2011 9:53 AM, Steven D'Aprano wrote: I'm trying to generate a sequence of equally-spaced numbers between a lower and upper limit. Given arbitrary limits, what is the best way to generate a list of equally spaced floats with the least rounding error for each point? For example, suppose I

Re: Python Mixins

2011-09-24 Thread rantingrick
On Sep 22, 4:14 pm, Matt wrote: > I'm curious about what people's opinions are about using mixins in > Python. I really like, for example, the way that class based views > were implemented in Django 1.3 using mixins. It makes everything > extremely customizable and reusable. I think this is a very

Re: Suggested coding style

2011-09-24 Thread Tim Johnson
* Arnaud Delobelle [110924 12:04]: > On 24 September 2011 20:34, MRAB wrote: > > >>> In my brief coding experience I have stumbled upon Python zfill(width) > >>> method, > [...] > >>   It could be some sort of legacy. I imagine we will hear from some > >>   more senior pythonists on this matter.

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread f . derainville
>>> import numpy >>> numpy.arange(0, 3, 0.3) array([ 0. , 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4, 2.7]) -- http://mail.python.org/mailman/listinfo/python-list

Re: PyEval_EvalCodeEx return value

2011-09-24 Thread Mateusz Loskot
John Pinner-3 wrote: > > I assume that you have read the documentation at > http://docs.python.org/c-api/veryhigh.html, > and I agree that it's sparse, but the entry for the next entry, > PyEval_EvalCodeEx, tells you a little more, as does that for > PyEval_EvalFrameEx. > It does help, but onl

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Stefan Krah
Arnaud Delobelle wrote: > start, stop, n = -1, 1.1, 7 > [float(F(start) + i*(F(stop)-F(start))/n) for i in range(n+1)] > > [-1.0, -0.7, -0.39997, -0.09996, > > 0.20004, 0.5001, 0.8, 1.1] > > >>> start, stop, n = -1, 1.1, 7 > >>> [((n-i)*st

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Arnaud Delobelle
On 24 September 2011 18:01, Steven D'Aprano wrote: > Mark Dickinson wrote: > >> Using Fraction for intermediate calculations actually works perfectly >> for this, since conversions from float to Fraction are exact, while >> conversions from Fraction to float are correctly rounded.  So if >> you're

Re: Suggested coding style

2011-09-24 Thread Arnaud Delobelle
On 24 September 2011 20:34, MRAB wrote: >>> In my brief coding experience I have stumbled upon Python zfill(width) >>> method, [...] >>   It could be some sort of legacy. I imagine we will hear from some >>   more senior pythonists on this matter. >> > The documentation says "New in version 2.2.2

Re: Suggested coding style

2011-09-24 Thread MRAB
On 24/09/2011 20:10, Tim Johnson wrote: * Passiday [110924 09:47]: <...> I have been coding in many other languages, most of the time it was Java and C#. I don't like the function mess of PHP (ie, loads and loads of functions without any namespaces etc), but I'd like to think that Python is dif

Re: Suggested coding style

2011-09-24 Thread Tim Johnson
* Passiday [110924 09:47]: <...> > I have been coding in many other languages, most of the time it was > Java and C#. I don't like the function mess of PHP (ie, loads and > loads of functions without any namespaces etc), but I'd like to think > that Python is different. It is ... > In my brief

Re: Suggested coding style

2011-09-24 Thread MRAB
On 24/09/2011 18:31, Passiday wrote: Hello, I have started to code random stuff in Python only recently, still lots to learn. So please bear with me if my question sounds like rant. I have been coding in many other languages, most of the time it was Java and C#. I don't like the function mess o

Re: Python-list Digest, Vol 96, Issue 137

2011-09-24 Thread Ricardo Mansilla
On Saturday 24 September 2011 01:48:29 you wrote: > Ricardo wrote: > > Hi everyone > > I'm trying to use the cgi library to create a python script and loading > > it from a web page. I have already done the necessary imports, and the > > default commands to receive data from "html" are written too.

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mark Dickinson
On Sep 24, 6:01 pm, Steven D'Aprano wrote: > Ah, I knew it was too easy! > > >>> from fractions import Fraction as F > >>> start, stop, n = 1, 3.1, 7 > >>> [float(F(start) + i*(F(stop)-F(start))/n) for i in range(n+1)] > > [1.0, 1.3, 1.6, 1.9001, 2.2, 2.5, 2.8003, 3.1] I b

Suggested coding style

2011-09-24 Thread Passiday
Hello, I have started to code random stuff in Python only recently, still lots to learn. So please bear with me if my question sounds like rant. I have been coding in many other languages, most of the time it was Java and C#. I don't like the function mess of PHP (ie, loads and loads of functions

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Chris Angelico
On Sun, Sep 25, 2011 at 3:01 AM, Steven D'Aprano wrote: > Mark Dickinson wrote: > >> Using Fraction for intermediate calculations actually works perfectly >> for this, since conversions from float to Fraction are exact, while >> conversions from Fraction to float are correctly rounded.  So if >> y

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Mark Dickinson wrote: > Using Fraction for intermediate calculations actually works perfectly > for this, since conversions from float to Fraction are exact, while > conversions from Fraction to float are correctly rounded. So if > you're using Python, you're not too bothered about efficiency, an

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Chris Angelico
On Sun, Sep 25, 2011 at 12:26 AM, Mel wrote: > low_limit + (total_width * i) / intervals > Definite improvement, if the range is comparatively small. Multiply first, then divide. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mark Dickinson
On Sep 24, 5:46 pm, Steven D'Aprano wrote: > Speed is important, but secondary to correctness. To be honest, I never even > thought of using fractions as an intermediate result -- I was thinking of > generating lists of Fractions. I think I can use this approach. Speed could be improved greatly b

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Mark Dickinson wrote: > On Sep 24, 2:53 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> I'm trying to generate a sequence of equally-spaced numbers between a >> lower and upper limit. Given arbitrary limits, what is the best way to >> generate a list of equally spaced floats with t

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mark Dickinson
On Sep 24, 2:53 pm, Steven D'Aprano wrote: > I'm trying to generate a sequence of equally-spaced numbers between a lower > and upper limit. Given arbitrary limits, what is the best way to generate a > list of equally spaced floats with the least rounding error for each point? > > For example, supp

Re: Python 2.5 zlib trouble

2011-09-24 Thread Christian Heimes
Am 23.09.2011 23:34, schrieb Jesramz: > Im running on Ubuntu Natty and I am not running a self-compiled > install, its a regular release. Ubuntu Natty doesn't come with Python 2.5. How did you install Python 2.5 on Natty? If you used some sort of installer or 3rd party repository, there is a big

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mel
Steven D'Aprano wrote: > I'm trying to generate a sequence of equally-spaced numbers between a > lower and upper limit. Given arbitrary limits, what is the best way to > generate a list of equally spaced floats with the least rounding error for > each point? > > For example, suppose I want to div

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Arnaud Delobelle
On Sep 24, 2011 2:59 PM, "Chris Angelico" wrote: > > On Sat, Sep 24, 2011 at 11:53 PM, Steven D'Aprano > wrote: > > #1 add multiples of the width to the starting value, 0. > > > > #2 subtract multiples of width from the ending value, 2.1. > > #3, go half and half - generate the lower half by addi

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Vlastimil Brom
2011/9/24 Chris Angelico : > On Sat, Sep 24, 2011 at 11:53 PM, Steven D'Aprano > wrote: >> #1 add multiples of the width to the starting value, 0. >> >> #2 subtract multiples of width from the ending value, 2.1. > > #3, go half and half - generate the lower half by adding to the lower > bound, and

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Chris Angelico
On Sat, Sep 24, 2011 at 11:53 PM, Steven D'Aprano wrote: > #1 add multiples of the width to the starting value, 0. > > #2 subtract multiples of width from the ending value, 2.1. #3, go half and half - generate the lower half by adding to the lower bound, and the upper half by subtracting from the

Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
I'm trying to generate a sequence of equally-spaced numbers between a lower and upper limit. Given arbitrary limits, what is the best way to generate a list of equally spaced floats with the least rounding error for each point? For example, suppose I want to divide the range 0 to 2.1 into 7 equal

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Mark Dickinson
On Sep 24, 10:38 am, Ian Kelly wrote: > On Sat, Sep 24, 2011 at 12:55 AM, Steven D'Aprano > > > > > > > > > > wrote: > > If you want unbiased, random (or at least pseudo-random) integers chosen > > from an uniform distribution with proper error checking, you should use > > randint or randrange. >

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Chris Angelico
On Sat, Sep 24, 2011 at 4:55 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > > If you want unbiased, random (or at least pseudo-random) integers chosen > from an uniform distribution with proper error checking, you should use > randint or randrange. > > "I only need random-ish ints, but I nee

Re: pyWin build 216

2011-09-24 Thread Michel Claveau - MVP
Hi! Me, because some bugs in 216, I come back to 214... (215 has another bugs). @-salutations -- MCi -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Mixins

2011-09-24 Thread Carl Banks
On Thursday, September 22, 2011 2:14:39 PM UTC-7, Matt wrote: > In terms of code, lets say we have the following classes: > > class Animal > class Yamlafiable > class Cat(Animal, Yamlafiable) > class Dog(Animal, Yamlafiable) > > I've got an Animal that does animal things, a Cat that does cat thin

Re: Python Mixins

2011-09-24 Thread Carl Banks
On Thursday, September 22, 2011 2:14:39 PM UTC-7, Matt wrote: [snip] > class MyMixin(object): > def one_thing(self): > return "something cool" > > @mixin(MyMixin) > class MyClass(object): > pass > > x = MyClass() > x.one_thing() == 'something cool' > x.__class__.__bases__ == (obj

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Ian Kelly
On Sat, Sep 24, 2011 at 12:55 AM, Steven D'Aprano wrote: > If you want unbiased, random (or at least pseudo-random) integers chosen > from an uniform distribution with proper error checking, you should use > randint or randrange. > > >> but if you just >> want a pile of more-or-less random integer

MailingLogger 3.5.0 Released!

2011-09-24 Thread Chris Withers
I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features

Re: Python Mixins

2011-09-24 Thread Steven D'Aprano
Matt wrote: > I'm curious about what people's opinions are about using mixins in > Python. I really like, for example, the way that class based views > were implemented in Django 1.3 using mixins. Mixins considered harmful: http://www.artima.com/weblogs/viewpost.jsp?thread=246341 http://www.artim

Re: multinomial combinations

2011-09-24 Thread Arnaud Delobelle
(sorry about the top posting) Change yield c to yield (c,) HTH Arnaud PS: you could also change the if ... To If not ns: Yield ((),) Else: ... On Sep 24, 2011 8:06 AM, "Dr. Phillip M. Feldman" < phillip.m.feld...@gmail.com> wrote: > > I wrote a small generator function that produces mu

Re: multinomial combinations

2011-09-24 Thread Chris Rebert
On Sat, Sep 24, 2011 at 12:06 AM, Dr. Phillip M. Feldman wrote: > > I wrote a small generator function that produces multinomial combinations. > (Python's itertools module does ordinary combinations, but not multinomial > combinations).  The code essentially works, except that the the last > combi

parse html to get tr content

2011-09-24 Thread contro opinion
here is my code: import lxml.html sfile='http://finance.yahoo.com/q/op?s=A+Options' root=lxml.html.parse(sfile).getroot() t = root.xpath("//table[@class='yfnc_datamodoutline1']")[0] trs=t.xpath(".//tr") for i, tr in enumerate(trs): print (i,

parse html:strange tr problem

2011-09-24 Thread 守株待兔
here is my code: import lxml.html sfile='http://finance.yahoo.com/q/op?s=A+Options' root=lxml.html.parse(sfile).getroot() t = root.xpath("//table[@class='yfnc_datamodoutline1']")[0] trs=t.xpath(".//tr") for i, tr in enumerate(trs): print (i, len(tr),tr.text_content()) the output is: 0 1

multinomial combinations

2011-09-24 Thread Dr. Phillip M. Feldman
I wrote a small generator function that produces multinomial combinations. (Python's itertools module does ordinary combinations, but not multinomial combinations). The code essentially works, except that the the last combination in each tuple is not enclosed in a nested tuple: In [2]: x= multi

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Sep 23, 2011 at 4:14 AM, Steven D'Aprano > wrote: >> What makes you think it's in C? I don't have Python 3.3a, but in 3.2 the >> random module is mostly Python. There is an import of _random, which >> presumably is in C, but it doesn't have a randint method: > > T