cnb wrote:
And there isn't a .copy function so I have to "new = []
for element in list: new.append(element)"?
You can do
new = list(old)
which I like for being explicit, or just
new = old[:]
and what is the difference between extend and + on lists?
>>> a = range(3)
>>> b = a
http://docs.python.org/lib/module-csv.html
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Now math has factorial:
http://docs.python.org/dev/library/math.html#math.factorial
That's rather underdocumented.
Does it really attempt exact calculation
for arbitrary integers?? Is there any
way to request a nice fast approximation
for large integers (e.g., with Gos
On 02 Sep 2008 06:10:51 GMT, Steven D'Aprano wrote:
At the risk of bike-shedding,
[snip]
Peter Pearson wrote:
(startled noises) It is a delight to find a reference to
that half-century-old essay (High Finance) by the wonderful
C. Northcote Parkinson, but how many readers will catch the
allus
[EMAIL PROTECTED] writes:
For Python 2.7/3.1 I'd now like to write a PEP regarding the
underscores into the number literals, like: 0b_0101_, 268_435_456
etc.
+1 on such a capability.
-1 on underscore as the separator.
On 9/1/2008 9:13 PM Ben Finney apparently wrote:
When you proposed
On 9/7/2008 12:22 PM SimonPalmer apparently wrote:
anyone recommend a way of formatting floats with comma separators?
http://code.activestate.com/recipes/498181/
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
On 9/6/2008 5:17 AM James Pilling apparently wrote:
Hi im currently starting to learn python in sixth form at school any tips?
The books suggestions of others are quite good.
Here is another approach: pick an easily understandable
application, and work doing things with it.
Perhaps immodestly,
En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith escribió:
I am having a problem when substituting a raw string. When I do the
following:
re.sub('abc', r'a\nb\nc', '123abcdefg')
I get
"""
123a
b
cdefg
"""
what I want is
r'123a\nb\ncdefg'
On 12/16/2009 9:35 AM, Gabriel Genellina wrote:
Fr
On 12/17/2009 11:24 AM, Richard Brodie wrote:
A raw string is not a distinct type from an ordinary string
in the same way byte strings and Unicode strings are. It
is a merely a notation for constants, like writing integers
in hexadecimal.
(r'\n', u'a', 0x16)
('\\n', u'a', 22)
Yes, that was
Alan G Isaac wrote:
>>> re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc',
'a\\nb\\n.c\\a','123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg')
True
Why are the
On 12/17/2009 2:45 PM, MRAB wrote:
re.compile('a\\nc') _does_ compile to the same as regex as
re.compile('a\nc').
However, regex objects never compare equal to each other, so, strictly
speaking, re.compile('a\nc') != re.compile('a\nc').
However, having said that, the re module contains a cache
On 12/17/2009 7:59 PM, Rhodri James wrote:
"re.compile('a\\nc')" passes a sequence of four characters to
re.compile: 'a', '\', 'n' and 'c'. re.compile() then does it's own
interpretation: 'a' passes through as is, '\' flags an escape which
combined with 'n' produces the newline character (0x0a),
On 12/18/2009 12:17 PM, MRAB wrote:
In simple cases you might be replacing with the same string every time,
but other cases you might want the replacement to contain substrings
captured by the regex.
Of course that "conversion" is needed in the replacement.
But e.g. Vim substitutions handle th
On 12/31/2009 7:30 PM, Steven D'Aprano wrote:
The message attribute is deprecated from
Python 2.6 and will print a warning if you try to use it.
http://bugs.python.org/issue6844
fwiw,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
Dr. Phillip M. Feldman writes:
I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:
if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]
(and so on). Is there a cleaner way to accomplish the
I expected this to be fixed in Python 3:
sum(['ab','cd'],'')
Traceback (most recent call last):
File "", line 1, in
TypeError: sum() can't sum strings [use ''.join(seq) instead]
Of course it is not a good way to join strings,
but it should work, should it not? Naturally,
'' + 'ab' + 'cd'
Alan G Isaac schrieb:
I expected this to be fixed in Python 3:
sum(['ab','cd'],'')
Traceback (most recent call last):
File "", line 1, in
TypeError: sum() can't sum strings [use ''.join(seq) instead]
Of course it is not a good
On 10/16/2009 3:40 PM, Tim Chase wrote:
What's always wrong is giving me an *error* when the semantics are
perfectly valid.
Exactly.
Which is why I expected this to be fixed in Python 3.
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
On 10/16/2009 5:03 PM, Christian Heimes wrote:
It's not going to happen.
That's a prediction, not a justification.
As Tim explained in detail, and as Peter
explained with brevity, whether it will
happen or not, it should happen. This
conversation has confirmed that current
behavior is a wart:
On 10/16/2009 8:16 PM, Terry Reedy wrote:
The fact that two or three people who agree on something agree on the
thing that they agree on confirms nothing. One could just as well argue
that summing anything but numbers is semantically incoherent, not
correct. Certainly, my dictionary points in tha
Alan G Isaac gmail.com> writes:
So of course join is better, as originally noted,
but that does not constitute a reason to intentionally
violate duck typing.
On 10/16/2009 1:03 PM, Benjamin Peterson wrote:
As Stephen pointed out, duck typing is not an absolute.
I do not recall any
On 10/17/2009 7:06 AM, Carl Banks wrote:
I'm basically saying here is, by shutting out strings from sum,
you don't really lose much in terms of duck typing, because duck
typing wouldn't have been that helpful anyway.
That boils down to an argument for type checking
whenever you cannot imagine m
On 10/16/2009 8:16 PM, Terry Reedy wrote:
The fact that two or three people who agree on something agree on the
thing that they agree on confirms nothing.
On 10/17/2009 7:03 PM, Terry Reedy wrote:
If you disagree with this, I think *you* are being silly.
Well, ...
Alan G Isaac wrote:
Of
The documentation at
http://docs.python.org/py3k/library/string.html#format-specification-mini-language
'<' Forces the field to be left-aligned within the available space
(This is the default.)
The conflicting example::
>>> format(3.2,'10.5f')
' 3.2'
>>>
On 5/11/2010 3:19 PM, MRAB wrote:
You usually want numbers to be right-aligned so that the decimal points
line up when writing a columns of them.
Yes. I'm not questioning the wisdom of the implementation,
just the documentation of it.
Thanks,
Alan
--
http://mail.python.org/mailman/listinfo/
On 5/11/2010 5:05 PM, Terry Reedy wrote:
http://bugs.python.org/issue8691
Thanks!
Alan
--
http://mail.python.org/mailman/listinfo/python-list
I want to modify XMP data for a bunch of JPEG files,
using Python if possible, on Windows. I expected
PIL would support this. But no?
I found the Python XMP Toolkit
http://www.spacetelescope.org/static/projects/python-xmp-toolkit/docs/installation.html#requirements
but no reports of successful
On 6/8/2010 6:59 PM, Lee Harr wrote:
Pynguin is a python-based turtle graphics application.
It combines an editor, interactive interpreter, and
graphics display area.
Do you start from scratch or make use of the
very useful new (2.6) turtle module? I hope
the latter, and that you ar
Tkinter's Scale widget had a `label` and a `resolution` attribute.
These appear to be missing from the Ttk Scale widget.
Is there a reason? These were important attributes.
Thanks,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
Of course one can do
myintvar.set(myintvar.get()+1)
but surely there is a better way?
I'm surprsied that
myintvar += 1
is not allowed.
Thanks,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
On 6/24/2010 1:59 AM, Dennis Lee Bieber wrote:
It is NOT a numeric "variable" in Python realms.
Sure, but why does it not behave more like one?
It seems both obvious and desirable, so I'm
guessing there is a good reason not to do it.
So var+=increment can't be used because Python woul
On 6/25/2010 1:14 PM, Dave Angel wrote:
the default behavior of += is to assign a new object with the new value,
rather than changing the previous object.
a = []
temp = a
a += [2]
temp
[2]
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
On 6/25/2010 1:24 PM, rantingrick wrote:
the "if __name__ == '__main__' tests" use
root.quit instead of root.destroy!
Did you open an issue?
http://bugs.python.org/
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
Surprising for a moment, if you don't
immediatelyrecognize it as a chained comparison.
(Just sharing.)
Alan Isaac
None is None is None
True
(None is None) is None
False
None is (None is None)
False
--
http://mail.python.org/mailman/listinfo/python-list
On 6/25/2010 3:52 PM, Dave Angel wrote:
I said "default", not "only" behavior. I suspect list provides an
__iadd__ method to provide this ability. Integers do not, and
therefore neither does the object the OP was asking about.
I have no idea what "default behavior" is supposed to mean.
Mut
On 6/25/2010 1:24 PM, rantingrick wrote:
the "if __name__ == '__main__' tests" use
root.quit instead of root.destroy!
On Jun 25, 12:46 pm, Alan G Isaac wrote:
Did you open an issue?http://bugs.python.org/
On 6/25/2010 4:26 PM, rantingrick wrote:
If *I* open an issu
On 7/5/2010 7:45 AM, Ritchy lelis wrote:
from pylab import*
Vref = arange(1, 20, 0.02)
Vi = arange(1, 10,0.1)
for i in Vref:
for n in Vi:
if n> i/4:
V0 = 2*n-i
elif (-i/4)<= n and n<= i/4:
V0 = 2*n
elif Vi< -i/4:
On 7/6/2010 8:05 AM, Ritchy lelis wrote:
1 - "import numpy as np
import matplotlib.pyplot as plt"
In what help's me making the call's of the libraries that way?
http://bytebaker.com/2008/07/30/python-namespaces/
2 - What's the instruction linspace means/does?
>>> help(np.lins
On 7/6/2010 12:11 PM, Ritchy lelis wrote:
My intention with de for loop was to iterate each point of the arrays
Vi and Vref at the math calculations. The V0 it's the result of the
math expressions between the Vi and Vref. I can't just create one V0
by a function set by parametters (i don't see ho
On 6/12/2009 5:55 AM Virgil Stokes apparently wrote:
> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows
> Vista platform?
Maintainers for some packages have run into a wall
compiling for 2.6. Matplotlib is one of these:
http://www.nabble.com/binary-installers-for-python2.6
On 6/12/2009 7:51 AM khem...@gmail.com apparently wrote:
> d = {'fname': [], 'ename': []}
> name1 = 'ricky'
> name2 = 'martin'
> d['fname'].append(name1)
> d['ename'].append(name2)
>
> name1 = 'britney'
> name2 = 'spears'
> d['fname'].append(name1)
> d['ename'].append(name2)
>
>
> This gives me:
On 6/13/2009 2:11 PM kj apparently wrote:
> Switching from Perl here, and having a hard time letting go...
>
> Suppose I have an "array" foo, and that I'm interested in the 4th, 8th,
> second, and last element in that array. In Perl I could write:
>
> my @wanted = @foo[3, 7, 1, -1];
>>> a = n
On 6/17/2009 4:03 PM J. Cliff Dyer apparently wrote:
> example code
> should always include relevant imports.
Agreed. It was a cut and paste failure.
Apologies.
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
On 6/18/2009 5:24 AM yadin apparently wrote:
> I got this python program that returns me a set like this..
> Set ([‘A\n’, B\n’, ‘C\n’, ‘D\n’, ‘E\n’, ‘F\n’, ‘G\n’ ])
> And a list pp = [‘100\n’ ‘200\n’ ‘300\n’ ‘400\n’]
> I was reading this from a file….
> How can I transform this to something that lo
On 6/17/2009 8:38 AM Jean-Michel Pichavant apparently wrote:
> I'm pretty sure you'll be able to find OOP scripting
> language.
http://www.amazon.com/Scripting-Objects-Comparative-Presentation-Object-Oriented/dp/047039725X/ref=sr_1_1?ie=UTF8&s=books&qid=1245276357&sr=1-1>
fwiw,
Alan Isaac
--
h
On 6/22/2009 3:40 PM saurabh apparently wrote:
> I am an experienced C programmer and recently dived into python,
> I have developed an instant love for it.
> I have been doing some routine scripting for day to day admin tasks,also
> have done some Tkinter and socket programming using python.
>
>
Using the 3.1 Windows installer, I chose that I did not
want the extensions registered, and the installer
unregistered the .py and .pyw extensions (which I had wanted
to keep associated with Python 2.6).
Is this intentional?
Alan Isaac
PS I already fixed the problem. My question
is about intent
On 7/3/2009 10:05 AM kj apparently wrote:
> The context is the concept of a binary search. In one of their
> homeworks, my students will have two occasions to use a binary
> search. This seemed like a perfect opportunity to illustrate the
> idea of abstracting commonalities of code into a re-usab
> In Alan G Isaac
> writes:
>> 1. Don't use assertions to test argument values!
On 7/3/2009 12:19 PM kj apparently wrote:
> Out of curiosity, where does this come from?
http://docs.python.org/reference/simple_stmts.html#grammar-token-assert_stmt
"The current cod
> Alan G Isaac wrote:
>> Using the 3.1 Windows installer, I chose that I did not
>> want the extensions registered, and the installer
>> unregistered the .py and .pyw extensions (which I had
>> wanted to keep associated with Python 2.6).
>> Is this intentional?
On 7/4/2009 12:30 PM kj apparently wrote:
> I'm beginning to think that the original "precept" was simply "cargo
> cult," i.e. one of those rules that are parroted without being
> fully understood.
Adopting such a view is of course an alternative to
attempting to understand, but perhaps less usef
As a recurrent situation, I need to invoke the same method
on many instances. Speed matters, but the solution should
be pure Python. Is the following convenience function
a reasonable approach?
def apply2(itr, methodname, *args, **kwargs):
f = operator.methodcaller(methodname, *args, **kwarg
> On Fri, 17 Jul 2009 05:19:50 +0000, Alan G Isaac wrote:
>> def apply2(itr, methodname, *args, **kwargs):
>> f = operator.methodcaller(methodname, *args, **kwargs)
>> for item in itr:
>> f(item)
On 7/17/2009 3:45 AM Steven D'Aprano appare
Are user defined classes hashable?
(The classes; *not* the instances!)
I want to use some classes as dictionary keys.
Python is not objecting,
but I'm not sure how to think about
whether this could be dangerous.
I'm inclined to guess it will be hashed by id
and this is OK.
Thanks for any insights
> * Alan G Isaac [2009-07-19 13:48:16 +]:
>> Are user defined classes hashable?
>> (The classes; *not* the instances!)
>> I'm inclined to guess it will be hashed by id and this is
>> OK.
On 7/19/2009 10:07 AM Nicolas Dandrimont apparently wrote:
> Y
>>> On Fri, 17 Jul 2009 05:19:50 +0000, Alan G Isaac wrote:
>>>> def apply2(itr, methodname, *args, **kwargs):
>>>> f = operator.methodcaller(methodname, *args, **kwargs)
>>>> for item in itr:
>>>> f(item)
>> On 7/1
Given a csv.DictWriter instance `dw`
I think it would be nice to be able to
say dw.write_header()
instead of
dw.writer.writerow(dw.fieldnames)
Good idea?
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
> On Aug 13, 6:45 am, Alan G Isaac wrote:
>> Given a csv.DictWriter instance `dw`
>> I think it would be nice to be able to
>> say dw.write_header()
>> instead of
>> dw.writer.writerow(dw.fieldnames)
>>
>> Good idea?
On 8/12/2009 10:24 PM John Mac
> On Aug 13, 1:15 pm, Alan G Isaac wrote:
>> I do not understand the reason for your silly, sarcastic response.
On 8/13/2009 7:58 AM John Machin apparently wrote:
> Duck typing: ask a silly question, get a silly answer.
Maybe if you learned to be a more generous reader,
fewer que
`lst` is a nested list
`tpl` is the indexes for an item in the list
What is the nice way to retrieve the item?
(Speedy access is nice.)
I don't want to use NumPy, but I'd like somehow
to avoid an explicit loop. I did consider using
eval. E.g., eval('lst' + '[%d]'*len(tpl)%tpl).
It works but se
On 8/14/2009 1:09 PM Steven D'Aprano apparently wrote:
> Try this instead:
>
from operator import getitem
reduce(getitem, (2, 1, 0), lst)
> 'aaa'
reduce(getitem, (2, 1, 0, 0), lst)
> 'a'
>
> operator.getitem is less ugly too.
Yes, that's better.
Thanks,
Alan
--
http://mail.pytho
Quoting http://docs.python.org/3.1/library/random.html#random.gauss:
Gaussian distribution. mu is the mean, and sigma is the
standard deviation. This is slightly faster than the
normalvariate() function defined below.
So since both are offered and gauss is faster, I assume it
must have
> On Aug 15, 12:49 pm, Alan G Isaac wrote:
>> Quotinghttp://docs.python.org/3.1/library/random.html#random.gauss:
>> Gaussian distribution. mu is the mean, and sigma is the
>> standard deviation. This is slightly faster than the
>> normalvariate() funct
On 8/16/2009 5:47 AM Terry apparently wrote:
> Is there a simple way (the pythonic way) to flatten a list of list?
> rather than my current solution:
> new_list=[]
> for l in list_of_list:
> new_list.extend(l)
new_list = list(xi for lst in list_of_list for xi in lst)
hth,
Alan Isaac
--
h
On 8/28/2009 3:45 AM hoffik wrote:
> I'm quite new in Python and I have one question. I have a 2D matrix of
> values stored in list (3 columns, many rows). I wonder if I can select one
> column without having to go through the list with 'for' command.
Not quite what you asked but ...
>>> rows = [
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
class MyError(Exception):
... def __init__(self, message):
... Exception.__init__(self)
... self.message = message
...
Alan G Isaac wrote:
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
class MyError(Exception):
... def __init__(self, message):
... Exception._
On 9/5/2009 9:07 AM, exar...@twistedmatrix.com wrote:
You are using the deprecated practice.
Clearly not, or it would fail in Python 3,
which it does not.
Attributes are not scoped to a
particular class. There is only one "message" attribute on your
"MyError" instance. It does not belong just
I've filed a bug report:
http://bugs.python.org/issue6844
Sadly the Twisted developers apparently did not file
a bug report when they were bitten by this ...
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
On 9/5/2009 5:50 PM, Alan G Isaac wrote:
I've filed a bug report:
http://bugs.python.org/issue6844
This is now an accepted bug with a patch request.
Can someone on this list please assist with a patch?
Thanks,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
MYSTERY: how can "%s"%error be different from "%s"%str(error) in Python 2.6?
APOLOGY: I tried to strip this down, but could not find a simple way to
reproduce the problem. This way works, however. (There is a discussion on
the docutils-develop list.) Although there are several steps, we are ta
Does the Windows application offer a COM interface?
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
http://sourceforge.net/projects/pywin32/
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
Michael Foord came up with a much simpler
illustration. With Python 2.6::
>>> try:
... open('flooble')
... except Exception as e:
... pass
...
>>> e
IOError(2, 'No such file or directory')
>>> unicode(e)
u"(2, 'No such fil
On 9/11/2009 9:42 PM, Steven D'Aprano wrote:
However, I must admit I'm perplexed why the original example is calling
__unicode__() in the first place! Given the line:
raise self.severe('Problems with "%s" directive path:\n%s: %s.'
% (self.name, error.__class__.__name__, error))
it looks to
There's John Zelle's graphics.py:
http://mcsp.wartburg.edu/zelle/python/
provides basic functionality.
Pmw.Blt
http://heim.ifi.uio.no/~hpl/Pmw.Blt/doc/reference.html
pygooglechart
You suggested this needs a browser, but not so,
you can download the PNGs and use the default viewer
to display them
Alan G Isaac wrote:
There's John Zelle's graphics.py:
http://mcsp.wartburg.edu/zelle/python/
provides basic functionality.
On 9/16/2009 12:33 AM, John Nagle wrote:
"The package is a wrapper around Tkinter". It runs Tkinter
in a separate thread and sends commands to it.
You could learn a lot of Python contributing to
docutils or bibstuff, and if you write papers
or presentations, it may pay off directly.
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
101 - 177 of 177 matches
Mail list logo