pylab, integral of sinc function

2007-02-19 Thread Schüle Daniel
Hello, In [19]: def simple_integral(func,a,b,dx = 0.001): : return sum(map(lambda x:dx*x, func(arange(a,b,dx : In [20]: simple_integral(sin, 0, 2*pi) Out[20]: -7.5484213527594133e-08 ok, can be thought as zero In [21]: simple_integral(sinc, -1000, 1000) Out[21]: 0.999797

Re: pylab, integral of sinc function

2007-02-19 Thread Schüle Daniel
my fault In [31]: simple_integral(lambda x:sinc(x/pi), -1000, 1000) Out[31]: 3.14046624406611 -- http://mail.python.org/mailman/listinfo/python-list

New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread GiBo
GiBo wrote: > Hi! > > Classic situation - I have to process an input stream of unknown length > until a I reach its end (EOF, End Of File). How do I check for EOF? > [...] > I'd better like something like: > > while not stream.eof(): > ... Is there a reason why some classes distributed wi

Re: FPE: Add bindings to exception tracebacks.

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 19:47:26 -0300, Nathan <[EMAIL PROTECTED]> escribió: > Throughout my python development career, I've occasionally made > various developer tools to show more information about assertions or > exceptions with less hassle to the programmer. Until now, these tools > didn't pass a

Re: Checking for EOF in stream

2007-02-19 Thread GiBo
Grant Edwards wrote: > On 2007-02-19, GiBo <[EMAIL PROTECTED]> wrote: >> Hi! >> >> Classic situation - I have to process an input stream of unknown length >> until a I reach its end (EOF, End Of File). How do I check for EOF? The >> input stream can be anything from opened file through sys.stdin to

Re: New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 22:30:59 -0300, GiBo <[EMAIL PROTECTED]> escribió: > Is there a reason why some classes distributed with Python 2.5 are not > new-style classes? For instance StringIO is apparently "old-style" class > i.e. not inherited from "object". Can I somehow turn an existing > old-style

Re: pylab, integral of sinc function

2007-02-19 Thread Paul Rubin
Schüle Daniel <[EMAIL PROTECTED]> writes: > In [19]: def simple_integral(func,a,b,dx = 0.001): > : return sum(map(lambda x:dx*x, func(arange(a,b,dx Do you mean def simple_integral(func,a,b,dx = 0.001): return dx * sum(map(func, arange(a,b,dx))) -- http://mail.python.org/mai

Re: Checking for EOF in stream

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 21:50:11 -0300, GiBo <[EMAIL PROTECTED]> escribió: > Grant Edwards wrote: >> On 2007-02-19, GiBo <[EMAIL PROTECTED]> wrote: >>> >>> Classic situation - I have to process an input stream of unknown length >>> until a I reach its end (EOF, End Of File). How do I check for EOF? Th

Re: New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread GiBo
Gabriel Genellina wrote: > En Mon, 19 Feb 2007 22:30:59 -0300, GiBo <[EMAIL PROTECTED]> escribió: > >> Is there a reason why some classes distributed with Python 2.5 are not >> new-style classes? For instance StringIO is apparently "old-style" class >> i.e. not inherited from "object". Can I someh

Re: Newbie help looping/reducing code

2007-02-19 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Paul Rubin wrote: >Lance Hoffmeyer <[EMAIL PROTECTED]> writes: >> def even_odd_round(num): >> if(round(num,2) + .5 == int(round(num,2)) + 1): >> if num > .5: >> if(int(num) % 2): >>

Re: New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread Steven Bethard
GiBo wrote: > One more question - is it likely that StringIO will be turned into > new-style class in the future? The reason I ask is whether I should try > to deal with detection of new-/old-style classes or take the > old-styleness for granted and set in stone instead. In Python 3.0, everything

Re: pylab, integral of sinc function

2007-02-19 Thread Schüle Daniel
[...] >> In [19]: def simple_integral(func,a,b,dx = 0.001): >> : return sum(map(lambda x:dx*x, func(arange(a,b,dx > > Do you mean > > def simple_integral(func,a,b,dx = 0.001): > return dx * sum(map(func, arange(a,b,dx))) > yes, this should be faster :) -- http://mail.pyth

Re: pylab, integral of sinc function

2007-02-19 Thread Paul Rubin
Schüle Daniel <[EMAIL PROTECTED]> writes: > > return dx * sum(map(func, arange(a,b,dx))) > yes, this should be faster :) You should actually use itertools.imap instead of map, to avoid creating a big intermediate list. However I was mainly concerned that the original version might be incorrec

Re: Checking for EOF in stream

2007-02-19 Thread Grant Edwards
On 2007-02-20, GiBo <[EMAIL PROTECTED]> wrote: >>> stream = sys.stdin >>> while True: >>> data = stream.read(1024) >> if len(data) == 0: >> break #EOF >>> process_data(data) > > Right, not a big difference though. Isn't there a cleaner / > more intuitive way? A file is at E

Re: pylab, integral of sinc function

2007-02-19 Thread Robert Kern
Schüle Daniel wrote: > Hello, > > In [19]: def simple_integral(func,a,b,dx = 0.001): > : return sum(map(lambda x:dx*x, func(arange(a,b,dx > : > > In [20]: simple_integral(sin, 0, 2*pi) > Out[20]: -7.5484213527594133e-08 > > ok, can be thought as zero > > In [21]: simple_

Re: Checking for EOF in stream

2007-02-19 Thread Jon Ribbens
In article <[EMAIL PROTECTED]>, Gabriel Genellina wrote: > So this is the way to check for EOF. If you don't like how it was spelled, > try this: > >if data=="": break How about: if not data: break ? ;-) -- http://mail.python.org/mailman/listinfo/python-list

Found a product for running Python-based websites off CDROM -have anybody tried it?

2007-02-19 Thread David Wishnie
Hello, Recently I've found a product that allows to create CDs or DVDs with mod_python -based websites (and CGI python of course) so that apache-based webserver, python and mod_python are run directly off CD on Windows, MacOS X and Linux at the same time (also it seems to support perl, java,

exec "def.." in globals(), locals() does not work

2007-02-19 Thread xml0x1a
How do I use exec? >python -V Python 2.4.3 from math import * G = 1 def d(): L = 1 exec "def f(x): return L + log(G) " in globals(), locals() f(1) How do I use exec() such that: 1. A function defined in exec is available to the local scope (after exec returns) 2. The defined funct

Re: exec "def.." in globals(), locals() does not work

2007-02-19 Thread George Sakkis
On Feb 19, 10:52 pm, [EMAIL PROTECTED] wrote: > How do I use exec? Before you ask this question, the one you should have an answer for is "why do I (think I) have to use exec ?". At least for the example you gave, you don't; Python supports local functions and nested scopes, with no need for exec:

Bypassing __setattr__ for changing special attributes

2007-02-19 Thread George Sakkis
I was kinda surprised that setting __class__ or __dict__ goes through the __setattr__ mechanism, like a normal attribute: class Foo(object): def __setattr__(self, attr, value): pass class Bar(object): pass >>> f = Foo() >>> f.__class__ = Bar >>> print f.__class__ is Foo True Is

Re: exec "def.." in globals(), locals() does not work

2007-02-19 Thread xml0x1a
On Feb 19, 8:15 pm, "George Sakkis" <[EMAIL PROTECTED]> wrote: > On Feb 19, 10:52 pm, [EMAIL PROTECTED] wrote: > > > How do I use exec? > > Before you ask this question, the one you should have an answer for is > "why do I (think I) have to use exec ?". At least for the example you > gave, you don'

Re: threading and multicores, pros and cons

2007-02-19 Thread Paul Rubin
Nikita the Spider <[EMAIL PROTECTED]> writes: > note, there a (sort of) new module available that allows interprocess > communication via shared memory and semaphores with Python. You can find > it here: > http://NikitaTheSpider.com/python/shm/ This is from the old shm module that was floating

file io (lagged values) newbie question

2007-02-19 Thread hiro
Hey there, I'm currently doing data preprocessing (generating lagged values for a time series) and I'm having some difficulties trying to write a file to disk. A friend of mine, wrote this quick example for me: ---

Re: 'import dl' on AMD64 platform

2007-02-19 Thread Nick Craig-Wood
John Pye <[EMAIL PROTECTED]> wrote: > On Feb 19, 6:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > John Pye <[EMAIL PROTECTED]> wrote: > > > application from running on the Debian Etch AMD64 platform. > > > It seems that the 'dl' module is not available on that platform. The > > > only re

SICP video lectures

2007-02-19 Thread Paul Rubin
I didn't know about these! Enjoy. http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/ -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if one dict is subset of another?

2007-02-19 Thread Hendrik van Rooyen
"Jay Tee" <[EMAIL PROTECTED]> wrote: > Hi, > > I have some code that does, essentially, the following: > > - gather information on tens of thousands of items (in this case, jobs > running on a > compute cluster) > - store the information as a list (one per job) of Job items > (essentially

Re: Bypassing __setattr__ for changing special attributes

2007-02-19 Thread Ziga Seilnacht
George Sakkis wrote: > I was kinda surprised that setting __class__ or __dict__ goes through > the __setattr__ mechanism, like a normal attribute: > > class Foo(object): > def __setattr__(self, attr, value): > pass > > class Bar(object): > pass > > >>> f = Foo() > >>> f.__class__ =

<    1   2