> To get this into core Python, you'd usually submit a feature request
> athttp://bugs.python.org.
If you do submit a patch, please assign it to me.
I've been the primary maintainer for that module
for several years.
Raymond Hettinger
--
http://mail.python.org/mailman/listinfo/python-list
or protocol in a way that
is consistent with the rest of the language.
The second way, using the two argument form of iter(),
is the standard way of creating an iterator from a
function that has a sentinel return value.
IOW, it is not normal to use StopIteration in a function
that isn't an ite
.
There is no significant difference.
All three are implemented using substantially the same code.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
a = [1, 2] then
>
> a += [3]
>
> will first append 3 to the list and then reassign the list to 'a' (it is
> unnecessary in this case but if this step was omitted, the "in place"
> operators wouldn't work on immutables types).
This is an excellent explanation.
Perhaps, you can submit a documentation
patch for the operator module so this
doesn't get lost.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
about the
performance
characteristics of various data structures.
Raymond
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
lists tuples and string do support
slicing and some objects like deque do not. Interestingly, the grammar
has rules for slicing, but that is implemented as making a slice
instance as the argument to the lookup. The actual lookup work is
dispatched to the concrete class and there is no fast path along the
way.
Hope you all found this to be informative,
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
inane concerns with newline placement overwhelmed
the substance of the post.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
port it, and that else where it is
optional.
Another way of saying it is: if you are ever writing a __getitem__()
method in Python (even for a subclass of a builtin sequence), then it
is up to you to decide whether to add support for negative indices
and slicing.
Raymond
--
http://mail.python.org
b],[a,c],[a,d],...,[x,z],[y,z]]
Try this:
>>> from itertools import combinations
>>> list(combinations('abcde', 2))
[('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'), ('b', 'c'), ('b',
'd'), ('b', 'e'), ('c', 'd'), ('c', 'e'), ('d', 'e')]
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
[Steven D'Aprano]
> But if I try to create a regular dict from this, dict() doesn't call my
> __getitem__ method:
>
> >>> dict(d)
>
> {0: ('a', 'extra_data'), 1: ('b', 'extra_data')}
>
> instead of {0: '
rest
to people tracking this list. I learned quite a bit last year.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
.root # find the outermost enclosing context
f = c.new_child() # create a subcontext of c, independent of d
& e
I would appreciate any feedback on the API and on how well it fits
with various use cases that you've found in the wild.
Raymond
--
http://mail.python.org/ma
On Oct 21, 4:28 pm, Paul Rubin wrote:
> Raymond Hettinger writes:
> What I really want is a Haskell-like persistent (i.e. purely functional)
> dictionary implemented as an AVL tree or something like that.
Hopefully, that discussion can be in a separate thread.
This is really about ke
ue, it removes 'foo' from the
parent context, c.
Depends on whether you want parent contexts to be mutable or not.
With Python's nonlocal keyword, we can set values in an enclosing
scope. This tool lets you do that also.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
gt; b["x"] = 2
> >>> len(b)
> 2
> >>> b.keys()
>
> ['x', 'x']
>
> I would have expected equal keys to occur/count just once.
Thanks for reviewing the recipe.
Since only the first (unshadowed) 'x' is accessible, I can
see why it would make sense to count it only once.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 22, 8:48 am, Robert Kern wrote:
> On 10/21/10 6:19 PM, Raymond Hettinger wrote:
>
> > I would appreciate any feedback on the API and on how well it fits
> > with various use cases that you've found in the wild.
>
> We've done something similar in the past:
On Oct 21, 6:13 pm, Paul Rubin wrote:
> Raymond Hettinger writes:
> > The c.parent.parent.parent chain finds successive enclosing contexts:
>
> I was asking about finding the child contexts, not the parents. This is
> analogous to how you can find the keys in a dict with dict
ptive nor a bible ...
This is Tim we're talking about. I would put his work during
commercial breaks against most programmer's work during
uninterrupted full days at the office. He probably created
the Timsort routine while playing Farmville in another window :-)
Raymond
--
htt
ep] # only when b == a+n*step
So, it's not obvious what the semantics should be when b != a+n*step.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
looks like there is a good reason to do so.
The OP doesn't have any use cases to light the way
and I don't yet see any useful invariants that would
arise out of either definition. And since the ambiguity
only shows-up in a somewhat rare case, I'm inclined to
just mark it as undefined.
On Nov 5, 3:52 pm, Ian wrote:
> On Nov 5, 2:51 pm, Raymond Hettinger wrote:
>
> > You may have missed my point. I wrote the tools, the docs, and the
> > tests.
> > If you interpret a "promise" in text, I can assure you it was not
> > intended. The
rators are going to accumulate a ton of data
unless they are consumed roughly in parallel. Of course, if they are
consumed *exactly* in lockstep, the you don't need to split them into
separate iterables -- just use the tuples as they come.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
may enable a
single server to handle a greater traffic load. Has anyone here tried
that?
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
Tuvas wrote:
> Anyone know a module that does CRC16 for Python? I have an aplication
> that I need to run it, and am not having alot of sucess. I have a
> program in C that uses a CRC16 according to CCITT standards, but need
> to get a program that tests it with python as well. Thanks!
>
Try this
Shi Mu wrote:
> any python module to calculate sin, cos, arctan?
The other answers in this thread point you to the standard modules. If
you need arbitrary precision floating point versions of these functions
check out:
http://calcrpnpy.sourceforge.net/clnumManual.html
--
http://mail.python.org/
Alex Martelli wrote:
> As things stand now (gmpy 1.01), an instance d of decimal.Decimal cannot
> transparently become an instance of any of gmpy.{mpz, mpq, mpf}, nor
> vice versa (the conversions are all possible, but a bit laborious, e.g.
> by explicitly going through string-forms).
>
> I'm thin
The rpncalc package adds an interactive Reverse Polish Notation (RPN)
interpreter to Python. This interpreter allows the use of Python as
an RPN calculator. You can easily switch between the RPN interpreter
and the standard Python interpreter.
Home page: http://calcrpnpy.sourceforge.net/
Chang
Peter Hansen wrote:
> Larry Bates wrote:
>
>> I'm trying to get the results of binascii.crc32
>> to match the results of another utility that produces
>> 32 bit unsigned CRCs.
>
>
> What other utility? As Tim says, there are many CRC32s... the
> background notes on this one happen to stumble
Tim Peters wrote:
> [Raymond L. Buvel]
>
>>Check out the unit test in the following.
>>
>>http://sourceforge.net/projects/crcmod/
>
>
> Cool!
>
>
>>I went to a lot of trouble to get the results to match the results of
>>binascii.crc32. As y
Bo Peng wrote:
Dear list,
I am writing a Python extension module that needs a way to expose pieces
of a big C array to python. Currently, I am using NumPy like the following:
PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE,
char*buf);
Users will get a Numeric Array object an
The rpncalc package adds an interactive Reverse Polish Notation (RPN)
interpreter to Python. This interpreter allows the use of Python as
an RPN calculator. You can easily switch between the RPN interpreter
and the standard Python interpreter.
Home page: http://calcrpnpy.sourceforge.net/
Changes
The ratfun module provides classes for defining polynomial and rational
function (ratio of two polynomials) objects. These objects can be used
in arithmetic expressions and evaluated at a particular point.
Home page: http://calcrpnpy.sourceforge.net/ratfun.html
Note: If you are using rpncalc-1.
Robert Brewer wrote:
Gavin Bauer wrote:
My DOS window (running in windows ME) closes the second it finishes
running my programs. As you can imagine, this makes it hard to see the
results. I've gotten in the habit of putting raw_input("Press enter to
exit") at the end of every program, and in additi
I am preparing to release an extension module that interfaces Python to
the Class Library for Numbers (http://www.ginac.de/CLN/). This module
will provide Python types for arbitrary precision floating point
numbers, rational numbers, and their complex counterparts. The module
also includes most o
I have just released a new module that interfaces the Class Library for
Numbers (CLN) to Python. The CLN library is a C++ library that provides
rational and arbitrary precision floating point numbers in real and
complex form. The clnum module exposes these types to Python and also
provides arbitr
Chris Spencer wrote:
> Is there any library for Python that implements a kind of universal
> number object. Something that, if you divide two integers, generates a
> ratio instead of a float, or if you take the square root of a negative,
> generates a complex number instead of raising an exception?
If you are using the root finder in Numeric, and are having problems,
check out the root finder in the ratfun module. My testing indicates
that it will give the exact roots of a Wilkinson polynomial of degree
100. For more information see
http://calcrpnpy.sourceforge.net/ratfun.html
--
http://m
Grant Edwards wrote:
> I give up, how do I make this not fail under 2.4?
>
> fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00))
>
> I get an OverflowError: long int too large to convert to int
>
> ioctl() is expecting a 32-bit integer value, and 0xc0047a80 has
> the hi
David Joyner wrote:
Hi:
I'm trying to compile python 2.4 with tkinter.
(I'm trying to write a gui interface which
calls a program called GAP - I'm hoping to use
subprocess, a python 2.4 module, since I was getting
deadlocks using popen).
The instructions at the python web site said basically
to edi
Just wrote:
SciPy indeed appear to contain a solver, but I'm currently stuck in
trying to _get_ it for my platform (OSX). I'm definitely not going to
install a Fortran compiler just to evaluate it (even though my name is
not "Ilias" ;-). Also, SciPy is _huge_, so maybe a Python translation of
Alex Renelt wrote:
Alex Renelt wrote:
in addition:
I'm writing a class for polynomial manipulation. The generalization of
the above code is:
definitions:
1.) p = array([a_0, a_i, ..., a_n]) represents your polynomial
P(x) = \sum _{i=0} ^n a_i x^i
2.) deg(p) is its degree
3.) monic(p) makes P moni
I posted the following a while back. I think this is what you are
looking for.
This can be done fairly easily by creating a module (lets call it
interactive) with the following code in it.
---
import sys,os
def debug_exception(type, value, traceback):
# Restore redirected standard I
Mike Meyer wrote:
PEP: XXX
Title: A rational number module for Python
I think it is a good idea to have rationals as part of the standard
distribution but why not base this on the gmpy module
(https://sourceforge.net/projects/gmpy)? That module already provides
good performance. However, it d
Alex Martelli wrote:
Raymond L. Buvel <[EMAIL PROTECTED]> wrote:
Mike Meyer wrote:
PEP: XXX
Title: A rational number module for Python
I think it is a good idea to have rationals as part of the standard
distribution but why not base this on the gmpy module
(https://sourceforge.net/pr
The rpncalc package adds an interactive Reverse Polish Notation (RPN)
interpreter to Python. This interpreter allows the use of Python as
an RPN calculator. You can easily switch between the RPN interpreter
and the standard Python interpreter.
Home page: http://calcrpnpy.sourceforge.net/
Changes
Larry Bates wrote:
Looking over the code, it seems very inefficient and hard to understand.
You really should check out the following.
http://sourceforge.net/projects/crcmod/
It will allow you to generate efficient CRC functions for use in Python
and in C or C++. The only thing you need to in
[EMAIL PROTECTED] wrote:
> I am writing a C extension with python 2.3.5 and need constructs
> similar to python
>func(*args, **kwds)
> What's a neat way to do that?
> I found pyrex has a __Pyx_GetStarArgs -
> is there something I'm missing from the regular C/API maybe using one
> of the PyArg_P
The clnum package adds rational numbers and arbitrary precision floating
point numbers in real and complex form to Python. Also provides
arbitrary precision floating point replacements for the functions in the
math and cmath standard library modules.
Home page: http://calcrpnpy.sourceforge.net/cln
The ratfun module provides classes for defining polynomial and rational
function (ratio of two polynomials) objects. These objects can be used
in arithmetic expressions and evaluated at a particular point.
Home page: http://calcrpnpy.sourceforge.net/ratfun.html
Note: If you are using rpncalc-1.2
The rpncalc package adds an interactive Reverse Polish Notation (RPN)
interpreter to Python. This interpreter allows the use of Python as
an RPN calculator. You can easily switch between the RPN interpreter
and the standard Python interpreter.
Home page: http://calcrpnpy.sourceforge.net/
Chang
Bas wrote:
> Are there any differences between this module and the one already
> present in numpy?
>
> http://www.scipy.org/doc/numpy_api_docs/numpy.lib.polynomial.html
>
> Cheers,
> Bas
>
Yes, there are quite a few. This module uses a multi-precision library
(clnum) to make the calculations m
The clnum package adds rational numbers and arbitrary precision floating
point numbers in real and complex form to Python. Also provides
arbitrary precision floating point replacements for the functions in the
math and cmath standard library modules.
Home page: http://calcrpnpy.sourceforge.net/cln
Felipe Almeida Lessa wrote:
> Em Dom, 2006-06-11 às 11:19 -0700, fl1p-fl0p escreveu:
>> import math
>> math.pow(34564323, 456356)
>>
>> will give math range error.
>>
>> how can i force python to process huge integers without math range
>> error? Any modules i can use possibly?
>
> 34564323**45635
K.S.Sreeram wrote:
> Raymond L. Buvel wrote:
>> I just tried this and it is taking an extremely long time even on a fast
>> machine with 4 Gb of RAM. Killed it after a couple of minutes.
>
> Thats odd.
> 34564323**456356 completed on my laptop in 28 seconds.
> [Pyt
The clnum package adds rational numbers and arbitrary precision floating
point numbers in real and complex form to Python. Also provides
arbitrary precision floating point replacements for the functions in the
math and cmath standard library modules.
Home page: http://calcrpnpy.sourceforge.net/cln
The ratfun module provides classes for defining polynomial and rational
function (ratio of two polynomials) objects. These objects can be used
in arithmetic expressions and evaluated at a particular point.
Home page: http://calcrpnpy.sourceforge.net/ratfun.html
Note: If you are using rpncalc-1.2
The rpncalc package adds an interactive Reverse Polish Notation (RPN)
interpreter to Python. This interpreter allows the use of Python as
an RPN calculator. You can easily switch between the RPN interpreter
and the standard Python interpreter.
Home page: http://calcrpnpy.sourceforge.net/
Chang
Neil Cerutti wrote:
>> Another guess could be that real numbers being closed under the
>> four arithmetic operations, there is no danger to accidentally
>> step into complex numbers. OTOH floats and rationals are two
>> (conflicting) ways of extending integers.
>
> You would have to adopt a few s
Crcmod is a Python package for creating functions computing the Cyclic
Redundancy Check (CRC). Any generating polynomial producing 8, 16, 32,
or 64 bit CRCs is allowed. Generated functions can be used in Python or
C/C++ source code can be generated.
Home page: http://crcmod.sourceforge.net/
Chang
[EMAIL PROTECTED] wrote:
> Does anyone know where I can get python code to perform a CRC
> calculation on an IP packet?
>
Check out http://crcmod.sourceforge.net/
--
http://mail.python.org/mailman/listinfo/python-list
The clnum package adds rational numbers and arbitrary precision floating
point numbers in real and complex form to Python. Also provides
arbitrary precision floating point replacements for the functions in the
math and cmath standard library modules.
Home page: http://calcrpnpy.sourceforge.net/cln
Due to the contribution of Frank Palazzolo, a Windows binary installer
and build instructions are available for the clnum package. This also
makes ratfun and rpncalc usable on the Windows platform.
The clnum package adds rational numbers and arbitrary precision floating
point numbers in real and c
Gary Wessle wrote:
> Erik Max Francis <[EMAIL PROTECTED]> writes:
>
>
>>chun ping wang wrote:
>>
>>
>>>Hey i have a stupid question.
>>>How do i get python to print the result in only three decimal
>>>place...
>>>Example>>> round (2.9954254, 3)
>>>2.9951
>>>but i want to get r
compboy wrote:
> How do you print elements of the list in one line?
>
> alist = [1, 2, 5, 10, 15]
>
> so it will be like this:
> 1, 2, 5, 10, 15
>
> because if I use this code
>
> for i in alist:
> print i
>
> the result would be like this
>
> 1
> 2
> 5
> 10
> 15
>
> Thanks.
>
There ar
Gary Wessle wrote:
> Hi
>
> I am trying to install NumPy in my debian/testing linux
> 2.6.15-1-686.
>
When installing from source on a Debian system, you want the installed
package to wind up in /usr/local/lib/python2.x/site-packages (where x
represents the version of Python you are running th
Robert Kern wrote:
> Gary Wessle wrote:
>
>>"Raymond L. Buvel" <[EMAIL PROTECTED]> writes:
>
>
>>>When installing from source on a Debian system, you want the installed
>>>package to wind up in /usr/local/lib/python2.x/site-packages (where x
Gary Wessle wrote:
> Robert Kern <[EMAIL PROTECTED]> writes:
>
>
>>Raymond L. Buvel wrote:
>>
>>
>>>Since you are a new Linux user, you should definitely follow Robert's
>>>advice about building as an ordinary user separately from the
elventear wrote:
> Hi,
>
> I am the in the need to do some numerical calculations that involve
> real numbers that are larger than what the native float can handle.
>
> I've tried to use Decimal, but I've found one main obstacle that I
> don't know how to sort. I need to do exponentiation with re
Tim Peters wrote:
> The GNU GMP library (for which Python bindings are available) also
> supports "big floats", but their power operation is also restricted to
> integer powers and/or exact roots. This can be painful even to try;
> e.g.,
>
>>>> from gmpy import mpf
>>>> mpf("1e1") *
Tim Peters wrote:
> [Raymond L. Buvel, on
>http://calcrpnpy.sourceforge.net/clnumManual.html
> ]
>
>> The clnum module handles this calculation very quickly:
>>
>> >>> from clnum import mpf
>> >>> mpf("1e1") ** mpf("3.
Since the interest is more in extended precision than in decimal
representation, there is another module that may be of interest.
http://calcrpnpy.sourceforge.net/clnum.html
It interfaces to the Class Library for Numbers (CLN) library to provide
both arbitrary precision floating point and comp
Hello,
My name is Rev. Raymond Anderson. Can you Please provide unit cost on your
dock boxes with the dimension ( 46"W x 26"D x 27"H ) to enable me choose the
quantities i will like to purchase. Hope to hear back from you.
with kind regards
Rev. Raymond Anderson.
D
--
http://
To learn python, I've been trying to write a simple graphics program
which displays a 1D cellular automaton's evolution. The last time I
wrote this program, it was in C for a CGA adaptor (!) in which the
display was mapped to two interlaced blocks of memory, and scrolling
up two lines of pixels wa
> I *must* do:
>
> with device_open() as device:
>device.do_something()
>
> Nevertheless, I _need_ to have a class
> where the device is opened in the __init__()
> and used in some methods.
>
> Any ideas?
Perhaps take a look at contextlib.ExitStack and see if you can do something
with it.
nt for slices, only lists with the same length as
the slice should be acceptable, otherwise an error should be given.
Anything that re-indexes items not covered by the slice is against the
essential idea of assignment. For changes that imply re-indexing (e.g.,
inserting a list longer than the slice), Python offers cleaner solutions.
Comments are welcome.
With best regards,
Raymond
--
https://mail.python.org/mailman/listinfo/python-list
801 - 875 of 875 matches
Mail list logo