Reinhold Birkenfeld wrote:
>
> This is Open Source. If you want an initiative, start one.
+1 QOTW.
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Erik Wilsher wrote:
> And I think the discussion that followed proved your point perfectly
> Fredrik. Big discussion over fairly minor things, but no "big
> picture". Where are the initiatives on the "big stuff" (common
> documentation format, improved build system, improved web modules,
> rew
Uri Nix wrote:
> Using the following snippet:
> p =
> subprocess.Popen(nmake,stderr=subprocess.PIPE,stdout=subprocess.PIPE, \
>universal_newlines=True, bufsize=1)
> os.sys.stdout.writelines(p.stdout)
> os.sys.stdout.writelines(p.stderr)
> Works fine on the command li
Steven D'Aprano wrote:
> py> class Klass:
> ... pass
> ...
> py> def eggs(self, x):
> ... print "eggs * %s" % x
> ...
> py> inst = Klass() # Create a class instance.
> py> inst.eggs = eggs # Dynamically add a function/method.
> py> inst.eggs(1)
> Traceback (most recent call last):
> Fil
Terry Reedy wrote:
> "Ron Adam" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>Actually I think I'm getting more confused. At some point the function
>>is wrapped. Is it when it's assigned, referenced, or called?
>
>
> When it is referenced via the class.
> If you lookup i
Jorge Godoy wrote:
> From Google I found almost all of those. But do you have any suggestion on
> which one would be better to parse Fortran code? Or more productive to use
> for this task?
>
[snip]
>
>>PyParsing
>> http://pyparsing.sourceforge.net/
Well, I've never had to parse Fortan code,
David Murmann wrote:
> Hi all!
>
> I could not find out whether this has been proposed before (there are
> too many discussion on join as a sequence method with different
> semantics). So, i propose a generalized .join method on all sequences
> with these semantics:
>
> def join(self, seq):
>
vdrab wrote:
> hello pythoneers,
>
> I recently tried to install wordnet 2.0 and pywordnet on both an ubuntu
> linux running python 2.4 and a winXP running activePython 2.4.1, and I
> get the exact same error on both when I try to "from wordnet import *"
> :
>
> running install
> error: invalid P
vdrab wrote:
> I had WordNet 2.0 installed but just now I tried it with 1.7.1 as well
> and the result was the same. It's a shame, glossing over the pywordnet
> page really made me want to give it a try.
> Are there any workarounds you can recommend ?
What's your wordnet setup like? I have mine i
Laszlo Zsolt Nagy wrote:
> class A(object):
>cnt = 0
>a_cnt = 0
>def __init__(self):
>A.cnt += 1
>if self.__class__ is A:
>A.a_cnt += 1
> class B(A):
>pass
> print A.cnt,A.a_cnt # 0,0
> b = B()
> print A.cnt,A.a_cnt # 1,0
> a = A()
> print A.c
Robin Becker wrote:
> ## my silly example
> class ObserverProperty(property):
> def __init__(self,name,observers=None,validator=None):
> self._name = name
> self._observers = observers or []
> self._validator = validator or (lambda x: x)
> self._pName = '_' + nam
[EMAIL PROTECTED] wrote:
> Jason Stitt wrote:
>
>>Using // for 'in' looks really weird, too. It's too bad you can't
>>overload Python's 'in' operator. (Can you? It seems to be hard-coded
>>to iterate through an iterable and look for the value, rather than
>>calling a private method like some other
Andrew Jaffe wrote:
> Hi,
>
> I have a class with various class-level variables which are used to
> store global state information for all instances of a class. These are
> set by a classmethod as in the following (in reality the setcvar method
> is more complicated than this!):
>
> class sup(
Alex Martelli wrote:
>
>>>class Base(object)
>>>def getFoo(self): ...
>>>def setFoo(self): ...
>>>foo = property(getFoo, setFoo)
>>>
>>>class Derived(Base):
>>>def getFoo(self):
>>
[snip]
> the solution, in Python 2.4 and earlier, is to use
> one extra
darren kirby wrote:
> quoth the Fredrik Lundh:
>
>>(using either on the output from glob.glob is just plain silly, of course)
>
[snip]
>
> It is things like this that make me wary of posting to this list, either to
> help another, or with my own q's. All I usually want is help with a specific
Antoon Pardon wrote:
> Christopher Subich schreef :
>
>> Antoon Pardon wrote:
>>> >>>from decimal import Decimal
>>> >>>Zero = Decimal(0)
>>> >>>cmp( ( ) , Zero)
>>> -1
>>> >>>cmp(Zero, 1)
>>> -1
>>> >>>cmp(1, ( ) )
>>> -1
>>
>> I'd argue that the wart here is that cmp doesn't throw an exception,
Alex Hunsley wrote:
> The two main versions I've encountered for data pseudo-hiding
> (encapsulation) in python are:
>
> method 1:
>
> _X - (single underscore) - just cosmetic, a convention to let someone
> know that this data should be private.
>
>
> method 2:
>
> __X - (double unders
George Sakkis wrote:
> - Where do the attributes of a datetime.date instance live if it has
> neither a __dict__ nor __slots__ ?
> - How does dir() determine them ?
py> from datetime import date
py> d = date(2003,1,23)
py> dir(date) == dir(d)
True
py> for attr_name in ['day', 'month', 'year']:
...
Ewald R. de Wit wrote:
> I'm running into a something unexpected for a new-style class
> that has both a class attribute and __slots__ defined. If the
> name of the class attribute also exists in __slots__, Python
> throws an AttributeError. Is this by design (if so, why)?
>
> class A( object ):
James Stroud wrote:
> Hello All,
>
> I'm running 2.3.4
>
> I was reading the documentation for classes & types
>http://www.python.org/2.2.3/descrintro.html
> And stumbled on this paragraph:
>
> """
> __new__ must return an object. There's nothing that requires that it return a
> new obj
[EMAIL PROTECTED] wrote:
> so the following would not result in any conflicts
>
> class A:
>def __init__(self):
> self.__i= 0
>
> class B(A):
>def __init__(self):
> A.__init__(self)
> self.__i= 1
>
Be careful here. The above won't result in any conflicts, but related
Pierre Barbier de Reuille wrote:
> Proposal
>
>
> First, I think it would be best to have a syntax to represent symbols.
> Adding some special char before the name is probably a good way to
> achieve that : $open, $close, ... are $ymbols.
How about using the prefix "symbol." instead of "
[EMAIL PROTECTED] wrote:
> The "Python LIbrary Reference" at
> http://docs.python.org/lib/contents.html seems to be an important
> document. I have two questions
>
> Q1. How do you search inside "Python LibraryReference" ? Does it exist
> in pdf or chm form?
One other option. Go to google and us
Ok, so I have a module that is basically a Python wrapper around a big
lookup table stored in a text file[1]. The module needs to provide a
few functions::
get_stem(word, pos, default=None)
stem_exists(word, pos)
...
Because there should only ever be one lookup table, I feel lik
Terry Hancock wrote:
> On Thu, 17 Nov 2005 12:18:51 -0700
> Steven Bethard <[EMAIL PROTECTED]> wrote:
>
>>My problem is with the text file. Where should I keep it?
>>
>>I can only think of a few obvious places where I could
>>find the text file at import
Larry Bates wrote:
> Personally I would do this as a class and pass a path to where
> the file is stored as an argument to instantiate it (maybe try
> to help user if they don't pass it). Something like:
>
> class morph:
> def __init__(self, pathtodictionary=None):
> if pathtodictiona
So I've recently been making pretty frequent use of textwrap.dedent() to
allow me to use triple-quoted strings at indented levels of code without
getting the extra spaces prefixed to each line. I discovered today that
not only does textwrap.dedent() strip any leading spaces, but it also
substi
[EMAIL PROTECTED] wrote:
0xL
>
> 4294967295L
>
> OK, this is what I want, so I tried
>
> s = long("0xL")
> ValueError: invalid literal for long(): 0xL
>>> int("0x", 0)
4294967295L
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Peter Hansen wrote:
> Steven Bethard wrote:
>
>> Note that even though the tabs are internal, they are still removed by
>> textwrap.dedent(). The documentation[1] says:
>
> ...
>
>> So it looks to me like even if this is a "feature" it is undocument
The setup: I'm working within a framework (designed by someone else)
that requires a number of module globals to be set. In most cases, my
modules look like:
(1) a class definition
(2) the creation of one instance of that class
(3) binding of the instance methods to the appropriate module global
Mardy wrote:
> I'm not sure I got your problem correctly, however see if this helps:
>
> $ cat > test.py
> class myclass:
> name = __module__
> ^D
>
[snip]
>
> >>> import test
> >>> a = test.myclass()
> >>> a.name
> 'test'
>
> This works, as we define "name" to be a class attribute.
> Is th
[Duncan Booth]
> >>> aList = ['a', 1, 'b', 2, 'c', 3]
> >>> it = iter(aList)
> >>> zip(it, it)
>[('a', 1), ('b', 2), ('c', 3)]
[Alan Isaac]
> That behavior is currently an accident.
>http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1121416
[Bengt Richter]
> That sa
[EMAIL PROTECTED] wrote:
>> > ii. The other problem is easier to explain by example.
>> > Let it=iter([1,2,3,4]).
>> > What is the result of zip(*[it]*2)?
>> > The current answer is: [(1,2),(3,4)],
>> > but it is impossible to determine this from the docs,
>> > which would allow [(1,3),(2,4)] inste
[EMAIL PROTECTED] wrote:
> Steven Bethard wrote:
>
>>[EMAIL PROTECTED] wrote:
>>
>>>>>ii. The other problem is easier to explain by example.
>>>>>Let it=iter([1,2,3,4]).
>>>>>What is the result of zip(*[it]*2)?
>>>>>The
Dan Bishop wrote:
> Mike Meyer wrote:
>
>>Is there any place in the language that still requires tuples instead
>>of sequences, except for use as dictionary keys?
>
> The % operator for strings. And in argument lists.
>
> def __setitem__(self, (row, column), value):
>...
Interesting that b
Mike Meyer wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
>
>>Dan Bishop wrote:
>>
>>>Mike Meyer wrote:
>>>
>>>
>>>>Is there any place in the language that still requires tuples instead
>>>>of sequences, except for
David Rasmussen wrote:
> Harald Armin Massa wrote:
>
>> Dr. Armin Rigo has some mathematical proof, that High Level Languages
>> like esp. Python are able to be faster than low level code like
>> Fortran, C or assembly.
>
> Faster than assembly? LOL... :)
I think the claim goes something along t
hermy wrote:
> As I understand it, using super() is the preferred way to call
> the next method in method-resolution-order. When I have parameterless
> __init__ methods, this works as expected.
> However, how do you solve the following simple multiple inheritance
> situation in python ?
>
> class
I've got a list of word substrings (the "tokens") which I need to align
to a string of text (the "sentence"). The sentence is basically the
concatenation of the token list, with spaces sometimes inserted beetween
tokens. I need to determine the start and end offsets of each token in
the sente
Fredrik Lundh wrote:
> Steven Bethard wrote:
>> I feel like there should be a simpler solution (maybe with the re
>> module?) but I can't figure one out. Any suggestions?
>
> using the finditer pattern I just posted in another thread:
>
> tokens = ['She
Paul McGuire wrote:
> "Steven Bethard" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>I've got a list of word substrings (the "tokens") which I need to align
>>to a string of text (the "sentence"). The sentence i
Fredrik Lundh wrote:
> Steven Bethard wrote:
>
>
>>>>I feel like there should be a simpler solution (maybe with the re
>>>>module?) but I can't figure one out. Any suggestions?
>>>
>>>using the finditer pattern I just posted in another t
Michael Spencer wrote:
> Steven Bethard wrote:
>
>> I've got a list of word substrings (the "tokens") which I need to
>> align to a string of text (the "sentence"). The sentence is basically
>> the concatenation of the token list, with spaces s
Steven Bethard wrote:
> Michael Spencer wrote:
>
>> Steven Bethard wrote:
>>
>>> I've got a list of word substrings (the "tokens") which I need to
>>> align to a string of text (the "sentence"). The sentence is
>>>
Tim Peters wrote:
> First, if `st` is a string, `st[::-1]` is a list.
I hate to question the great timbot, but am I missing something?
>>> 'abcde'[::-1]
'edcba'
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Ben Finney wrote:
> Maybe I need to factor out the iteration into a generic iteration
> function, taking the actual test as a function object. That way, the
> dataset iterator doesn't need to know about the test function, and
> vice versa.
>
> def iterate_test(self, test_func, test_params=
Daniel Schüle wrote:
> I am wondering if there were proposals or previous disscussions in this
> NG considering using 'while' in comprehension lists
>
> # pseudo code
> i=2
> lst=[i**=2 while i<1000]
I haven't had much need for anything like this. Can't you rewrite with
a list comprehension so
Samuel M. Smith wrote:
> The dict class has some read only attributes that generate an exception
> if I try to assign a value to them.
> I wanted to trap for this exception in a subclass using super but it
> doesn't happen.
>
> class SD(dict):
>pass
>
[snip]
> s = SD()
> super(SD,s).__set
[EMAIL PROTECTED] wrote:
> Iain> I like the Global Module Index in general - it allows quick access
> Iain> to exactly what I want. I would like a minor change to it though
> Iain> - stop words starting with a given letter rolling over to another
> Iain> column (for example, os.pat
[EMAIL PROTECTED] wrote:
> ElementTree on the other hand provides incredibly easy access to XML
> elements and works in a more Pythonic way. Why has the API not been
> included in the Python core?
While I fully agree that ElementTree is far more Pythonic than the
dom-based stuff in the core, thi
Samuel M. Smith wrote:
> On 06 Dec, 2005, at 20:53, Steven Bethard wrote:
>> You can always shadow class-level attributes in the instance dict.
>> (That's what you were doing.) If you want to (try to) replace an
>> attribute in the class dict, you need to use the class
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> A.M. Kuchling <[EMAIL PROTECTED]> wrote:
>
>>So now we're *really* stuck. The RefGuide doesn't describe the rules;
>>the PEP no longer describes them either; and probably only Guido can
>>write the new text for the RefGuide. (Or are the semantics t
[EMAIL PROTECTED] wrote:
> I think the key here is ElementTree's Pythoninc API. While it's clearly
> possible to install it as a third-party package, I think there's a clear
> best-of-breed aspect here that suggests it belongs in the standard
> distribution simply to discourage continued use of DO
Samuel M. Smith wrote:
> If you would care to elaborate on the how the lookup differs with
> method descriptor it would be most appreciated.
For the more authoritative guide, see:
http://users.rcn.com/python/download/Descriptor.htm
The basic idea is that a descriptor is an object that sits
Lad wrote:
> How can I find out in Python whether the operand is integer or a
> character and change from char to int ?
Python doesn't have a separate character type, but if you want to
convert a one-character string to it's ASCII number, you can use ord():
>>> ord('A'), ord('z')
(65, 122)
The
Antoon Pardon wrote:
> So lets agree that tree['a':'b'] would produce a subtree. Then
> I still would prefer the possibility to do something like:
>
> for key in tree.iterkeys('a':'b')
>
> Instead of having to write
>
> for key in tree['a':'b'].iterkeys()
>
> Sure I can now do it like this:
Alex Martelli wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
(2) lambda a: a.lower()
My first thought here was to use str.lower instead of the lambda, but of
course that doesn't work if 'a' is a unicode object:
Right, but string.lower works (after an 'import string
Bulba! wrote:
Thanks to everyone for their responses, but it still doesn't work re
returning next() method:
class R3:
def __init__(self, d):
self.d=d
self.i=len(d)
def __iter__(self):
d,i = self.d, self.i
while i>0:
i-=1
yield d[i]
Alex Martelli wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
py> class C(object):
... def __init__(self):
... self.plural = lambda n: int(n != 1)
...
py> c = C()
py> c.__class__.plural(1)
Traceback (most recent call last):
File "", line 1, in ?
AttributeE
Alex Martelli wrote:
Paul L. Du Bois <[EMAIL PROTECTED]> wrote:
def fn(gen):
"""Turns a generator expression into a callable."""
def anonymous(*args): return gen.next()
return anonymous
def args():
"""Works with fn(); yields args passed to anonymous()."""
while True: yield sys._getfr
Simo Melenius wrote:
map (def x:
if foo (x):
return baz_1 (x)
elif bar (x):
return baz_2 (x)
else:
global hab
hab.append (x)
return baz_3 (hab),
[1,2,3,4,5,6])
I think this would probably have to be wri
Adam DePrince wrote:
Lets not forget the "real reason" for lambda ... the elegance of
orthogonality. Why treat functions differently than any other object?
We can operate on every other class without having to involve the
namespace, why should functions be any different?
Yup. I think in most o
Hans Nowak wrote:
Adam DePrince wrote:
In sort, we must preserve the ability to create an anonymous function
simply because we can do so for every other object type, and functions
are not special enough to permit this special case.
Your reasoning makes sense... lambda enables you to create a funct
Paul Rubin wrote:
[EMAIL PROTECTED] (Alex Martelli) writes:
We should have an Evilly Cool Hack of the Year, and I nominate Paul du
Bois's one as the winner for 2004. Do I hear any second...?
The year's not over yet :).
Ok, now that we're past 0:00:00 UTC, I'll second that nomination! ;)
Steve
P.S.
Mark McEahern wrote:
drife wrote:
Hello,
Making the transition from Perl to Python, and have a
question about constructing a loop that uses an iterator
of type float. How does one do this in Python?
Use a generator:
>>> def iterfloat(start, stop, inc):
... f = start
... while f <= stop:
Sean wrote:
My problem is that many of the example scripts are run on Linux
machines and I am using Win XP Pro. Here is a specific example of what
is confusing me. If I want to open a file from the dos prompt in some
script do I just write the name of the file I want to open (assuming it
is in th
Uwe Mayer wrote:
Saturday 01 January 2005 22:48 pm Hans Nowak wrote:
I am curious, what would you do with a class that derives from both file
and dict?
I was writing a class that read /writes some binary file format. I
implemented the functions from the file interface such that they are
refering to
PEP 288 was mentioned in one of the lambda threads and so I ended up
reading it for the first time recently. I definitely don't like the
idea of a magical __self__ variable that isn't declared anywhere. It
also seemed to me like generator attributes don't really solve the
problem very cleanly
Raymond Hettinger wrote:
[Steven Bethard]
(2) Since in all the examples there's a one-to-one correlation between
setting a generator attribute and calling the generator's next function,
aren't these generator attribute assignments basically just trying to
define the 'next'
rbt wrote:
How do I set up a function so that it can take an arbitrary number of
arguments?
If you haven't already, you should check out the Tutorial:
http://docs.python.org/tut/node6.html#SECTION00673
How might I make this dynamic so
that it can handle any amount of expenses?
de
Roman Suzi wrote:
I wish lambdas will not be deprecated in Python but the key to that is
dropping the keyword (lambda). If anybody could think of a better syntax for
lambdas _with_ arguments, we could develop PEP 312 further.
Some suggestions from recent lambda threads (I only considered the ones
It's me wrote:
Another newbie question.
There must be a cleaner way to do this in Python:
section of C looking Python code
a = [[1,5,2], 8, 4]
a_list = {}
i = 0
for x in a:
if isinstance(x, (int, long)):
x = [x,]
for w in [y for y in x]:
i = i + 1
a_list[w]
Robert wrote:
I need to find the location of a short string in a long string. The
problem however is that i need to search backward.
Does anybody know how to search in reverse direction?
How about str.rfind?
py> s = 'abc:def:abc'
py> s.rfind('abc')
8
Steve
--
http://mail.python.org/mailman/listinfo
Sorry if this is a repost -- it didn't appear for me the first time.
So I was looking at the Language Reference's discussion about emulating
container types[1], and nowhere in it does it mention that .keys() is
part of the container protocol. Because of this, I would assume that to
use UserDict.Di
Nick Coghlan wrote:
Steven Bethard wrote:
Sorry if this is a repost -- it didn't appear for me the first time.
So I was looking at the Language Reference's discussion about emulating
container types[1], and nowhere in it does it mention that .keys() is
part of the container protocol.
John Machin wrote:
Steven Bethard wrote:
So I was looking at the Language Reference's discussion about
emulating container types[1], and nowhere in it does it mention that
.keys() is part of the container protocol.
I don't see any reference to a "container protocol".
S
Bengt Richter wrote:
On Mon, 03 Jan 2005 18:54:06 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote:
Roman Suzi wrote:
I wish lambdas will not be deprecated in Python but the key to that is
dropping the keyword (lambda). If anybody could think of a better syntax for
lambdas _with_ arguments, we
Roman Suzi wrote:
On Mon, 3 Jan 2005, Steven Bethard wrote:
Roman Suzi wrote:
I wish lambdas will not be deprecated in Python but the key to that is
dropping the keyword (lambda). If anybody could think of a better syntax for
lambdas _with_ arguments, we could develop PEP 312 further.
Some
John Machin wrote:
OK, I'll rephrase: what is your interest in DictMixin?
My interest: I'm into mappings that provide an approximate match
capability, and have a few different data structures that I'd like to
implement as C types in a unified manner. The plot includes a base type
that, similarly to
I wrote:
* Functions I don't know how to rewrite
Some functions I looked at, I couldn't figure out a way to rewrite them
without introducing a new name or adding new statements.
[snip]
inspect.py: def formatargspec(args, varargs=None, varkw=None,
...
formatvara
Alan Gauld wrote:
On Thu, 06 Jan 2005 21:02:46 -0600, Doug Holton <[EMAIL PROTECTED]> wrote:
used, but there are people who do not like "lambda":
http://lambda-the-ultimate.org/node/view/419#comment-3069
The word "lambda" is meaningless to most people. Of course so is "def",
which might be why Gu
Andrey Tatarinov wrote:
Hi.
It would be great to be able to reverse usage/definition parts in
haskell-way with "where" keyword. Since Python 3 would miss lambda, that
would be extremly useful for creating readable sources.
Usage could be something like:
>>> res = [ f(i) for i in objects ] where
Steven Bethard wrote:
How often is this really necessary? Could you describe some benefits of
this? I think the only time I've ever run into scoping problems is with
lambda, e.g.
[lambda x: f(x) for x, f in lst]
instead of
[lambda x, f=f: for x, f in lst]
Sorry, bad example,
I'd like to be able to have an instance variable that can sometimes be
accessed as a property, and sometimes as a regular value, e.g. something
like:
py> class C(object):
... def usevalue(self, x):
... self.x = x
... def usefunc(self, func, *args, **kwds):
... self._func,
Haibao Tang wrote:
What I would like to do is to write a function like disp(), when typed,
it can give you the code infomation.
Check the docs entitled "Retrieving source code":
http://docs.python.org/lib/inspect-source.html
Depending on what you want, you may be able to use inspect.getsource:
py>
Robert Brewer wrote:
Steven Bethard wrote:
I'd like to be able to have an instance variable that can
sometimes be
accessed as a property, and sometimes as a regular value,
e.g. something
like:
...
py> c.x is c.x # I'd like this to be False
You'd like 'c.x is c.x
Bengt Richter wrote:
On Sat, 08 Jan 2005 03:28:34 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote:
I can't recall which thread this came up in, so I'm starting a new one. . .
Barry Warsaw has kindly added a "peps" topic to the python-checkins mailing
list. If you want to be notified only when PEP's
Robert Brewer wrote:
Steven Bethard wrote:
I'm playing around with a mapping type that uses setdefault
as suggested
in http://www.python.org/moin/Python3_2e0Suggestions. The
default value
for a missing key is either a simple value, or a value
generated from a
function. If it's
Alan Gauld wrote:
On Fri, 07 Jan 2005 08:44:57 -0700, Steven Bethard
<[EMAIL PROTECTED]> wrote:
The unfamiliar argument doesn't work for me. After all most
people are unfamiliar with complex numbers (or imaginary) numbers
complex numbers. Lambdas, on the other hand, show up in all kin
Bulba! wrote:
Following advice of two posters here (thanks) I have written two
versions of the same program, and both of them work, but the
difference in speed is drastic, about 6 seconds vs 190 seconds
for about 15000 of processed records, taken from 2 lists of
dictionaries.
I've read "Python Per
Robert Kern wrote:
Andrey Tatarinov wrote:
anyway list comprehensions are just syntaxic sugar for
>>> for var in list:
>>> smth = ...
>>> res.append(smth)
(is that correct?)
so there will be no speed gain, while map etc. are C-implemented
It depends.
Try
def square(x):
return x*
John Machin wrote:
Steven Bethard wrote:
Note that list comprehensions are also C-implemented, AFAIK.
Rather strange meaning attached to "C-implemented". The implementation
generates the code that would have been generated had you written out
the loop yourself, with a speed boost (com
[EMAIL PROTECTED] wrote:
Steve Bethard wrote:
Robert Kern wrote:
def square(x):
return x*x
map(square, range(1000))
versus
[x*x for x in range(1000)]
Hint: function calls are expensive.
$ python -m timeit -s "def square(x): return x*x" "map(square, range(1000))"
1000 loops, best of 3:
Luis M. Gonzalez wrote:
It's me wrote:
z = [i + (2, -2)[i % 2] for i in range(10)]
But then why would you want to use such feature? Wouldn't that make
the code much harder to understand then simply:
z=[]
for i in range(10):
if i%2:
z.append(i-2)
else:
z.append(i+2)
Or are
harold fellermann wrote:
Python 2.4 (#1, Dec 30 2004, 08:00:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class X : pass
...
>>> attrname = "attr"
>>> eval("X.%s = val" % attrname , {"X":X, "val":5})
Terry Reedy wrote:
Never saw this specific game. Some suggestions on additional factoring out
of duplicate code.
def next_page(this_page):
print "\n"
if this_page == 0:
page = 0
return
The following elif switch can be replaced by calling a selection from a
list of functions:
[None,
David M. Cooke wrote:
Steven Bethard <[EMAIL PROTECTED]> writes:
Some timings to verify this:
$ python -m timeit -s "def square(x): return x*x" "map(square, range(1000))"
1000 loops, best of 3: 693 usec per loop
$ python -m timeit -s "[x*x for x in range(1000)]&quo
Frans Englich wrote:
Also, another newbie question: How does one make a string stretch over several
lines in the source code? Is this the proper way?
(1)
print "asda asda asda asda asda asda " \
"asda asda asda asda asda asda " \
"asda asda asda asda asda asda"
A couple of other op
Dave Merrill wrote:
Somewhat silly example:
I know you've hedged this by calling it a "silly" example, but I would
like to point out that your set_X methods are unnecessary -- since
Python allows you to overload attribute access, getters and setters are
generally unnecessary.
class Address:
michael wrote:
Hi there,
I am somewhat confused by the following :
class C(object):
def getx(self): return self.__x
def setx(self, value): self.__x = "extended" + value
def delx(self): del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")
So far so good :-) But what t
1 - 100 of 1538 matches
Mail list logo