t be more than twice as expensive as simple_func
# no matter how fast or slow they are in absolute terms.
Any other lessons or hints I should know?
If it helps, my code will be targeting Python 3.1, and I'm using a
combination of doctest and unittest for the tests.
Thanks in advance,
On Mon, 04 Apr 2011 20:59:52 -0700, geremy condra wrote:
> On Mon, Apr 4, 2011 at 7:45 PM, Steven D'Aprano
> wrote:
>> * The disclaimers about timing code snippets that can be found in the
>> timeit module apply. If possible, use timeit rather than roll-you-own
>>
want to have their code accepted into
the Python standard library.
Personally, I find that the discipline of keeping to 80 characters is
good for me. It reduces the temptation of writing obfuscated Python one-
liners when two lines would be better. The *only* time it is a burden is
when I write do
slow.
You should avoid it. Python 3.1 is the first production-ready version of
Python 3, and 3.2 is the current version.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 06 Apr 2011 01:19:06 +1000, Chris Angelico wrote:
> On Wed, Apr 6, 2011 at 1:07 AM, Steven D'Aprano
> wrote:
>> On Tue, 05 Apr 2011 15:38:28 +0200, Daniel Fetchinson wrote:
>>
>>> Seriously, who would want to limit
>>> him/herself to 80 characte
re that is compatible with .NET and is
available on Linux, Mac OS, Solaris, Unix and even that little-known
operating system "Windows". *wink*
http://www.mono-project.com/Main_Page
And some FUD-busting:
http://ubuntu-tutorials.com/2007/03/13/squashing-a-few-myths-about
uld be more useful if it took an arbitrary number of
iterable arguments rather than just a single. The equivalent of:
filter(func, *seqs) -> [x for x in itertools.chain(*seqs) if func(x)]
although I suppose functional programming purists might object :)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
o much that I couldn't afford to move away from Linux and
GNU. Damn lock-in.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
omething to the effect of:
> someClass(newInstance)
I don't know. What effect do you expect?
Please don't assume that just because you've spent hours searching for an
answer, we know what the question is.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
except bzillions of euros ( or dollars ) of
> wasteful litigation and head-ache.
Do you have an example of this wasteful litigation?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 07 Apr 2011 07:50:56 +1000, Ben Finney wrote:
> Steven D'Aprano writes:
>
>> Mono is free, open source software that is compatible with .NET
> […]
>
> It's difficult to take a claim of “free” seriously for a technology
> (Mono) that knowingly implem
t are you going to do
to punish them?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
/
http://wiki.python.org/jython/WhyJython
Hope this helps.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 08 Apr 2011 01:37:45 -0500, harrismh777 wrote:
> Steven D'Aprano wrote:
>>> The reason Mono gets hit (from others besides me) is that they are in
>>> > partnership and collaboration with Microsoft, consciously and
>>> > unconsciously. This must
On Sun, 10 Apr 2011 03:28:10 +0200, candide wrote:
> Python is very good at introspection, so I was wondering if Python (2.7)
> provides any feature to retrieve the list of its keywords (and, as,
> assert, break, ...).
import keyword
--
Steven
--
http://mail.python.org/mailman
cts, the language itself is only
partly object oriented, and it rarely gets in the way. The OO aspect of
Python is mostly syntax and namespaces.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
by Apple; does that make it a discovery
rather than an invention? On the other hand, it is doing Apple a great
disservice to ignore their creativity in finding that design point, out
of the infinite number of almost-iPods that suck[3] or don't work.
[1] Probably aleph-1 uncountably infinite rather than aleph-0 countably
infinite, proving it is not obvious to me.
[2] In maths things are usually named after Euler, or the first person to
discover them after Euler.
[3] Or suck worse than the iPod. YMMV.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 11 Apr 2011 11:17:09 -0700, geremy condra wrote:
> On Mon, Apr 11, 2011 at 2:10 AM, Steven D'Aprano
> wrote:
[...]
>> Of course, some mathematics is obvious, or at least intuitive (although
>> proving it rigorously can be remarkably difficult -- after 4000 year
like the idea of a conditional return, but I *hate* the
proposed syntax. But I don't think it's useful enough to deserve a new
keyword either.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
arithmetic, and therefore in everyday use.
Alas, that's not the case. Peano arithmetic is undecidable:
http://mathworld.wolfram.com/PeanoArithmetic.html
Oh, and this may be of interest:
http://scienceblogs.com/goodmath/2006/06/extreme_math_1_1_2.php
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ts for multiple platforms. E.g. EVE Online (to pick an old, well
established one that just so happens to use Python as its scripting
engine).
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
that a legislature could not write a law, nor a
> lawyer submit a legal brief, without possibly having to pay royalties or
> violate a patent.
That would be a patent on a business process, which is allowed. In fact,
as I recall, at least one lawyer has made an attempt to patent a business
process relating to law.
Too-lazy-to-google-for-it-ly y'rs,
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
s or generator expressions.
Indentation is not appropriate here because it doesn't involve a block of
code. The whole point is that it just involves a single expression.
But in any case, I'm -1 on any syntax involving ? in Python, and +0 on
the concept on a conditional return. I s
e has contributed. Also Mark Dickson,
and probably a few others.
Personally, I'm glad that most of Python Dev don't hang around here. We
are far better off if Python Dev, you know, actually Devs Python, rather
than answering (mostly) easy questions and getting stuck in tar-pits.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
th the introduction of "tiled TK" with native-looking widgets.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ty, it is true, but still a
minority.
Now, if only we could convince web users that having your browser execute
untrusted code downloaded from the Internet is not such a good idea,
supposed sandbox or not. What the world needs is a virus that silently
removes Javascript and Flash fr
ctly, the proportion of IE users still using IE 6 is
about 10%, which makes it about 5% of the total browser share. Between
Google (YouTube, Gmail, etc) and Microsoft dropping support for IE 6, I
would expect that percentage to rapidly fall.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
I'm a python beginer so can't imlement much in python. I
>>found this python-farsight from Gajim src
>>code(http://www.gajim.org/downloads.php?lang=en).Can you people describe
>>which all functions are to be used for starting video chat.
Who are you quoting? Did you
gt; Microsoft?
A little of both.
Personally, I think it is *good* that there is a plurality of browsers in
the market. In my perfect world, no single browser should capture more
than 20% share of users.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
for style over substance, of sizzle without sausage, rather
than anything actually useful or desirable: think of a misfeature that
*degrades* the user-experience, and chances are it's implemented in Flash
or Javascript on tens of thousands of sites.
Yes-I-am-a-bitter-old-curmudgeon-ly y
very short,
helpful post he writes, he writes about 80 or 100 long, useless posts
that turn this list into a tar-pit of wasted time and frustration and
halves its usefulness.
Save yourself a lot of time and just killfile him now. You'll thank me
for it later.
--
Steven
--
http://mail.p
i]) for i in xrange(1, len(dct)+1)]
If you don't care about the order of the results:
lst = [parse_kwdlist(value) for value in dct.values()]
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 15 Apr 2011 13:55:58 +1000, Ben Finney wrote:
> Steven D'Aprano writes:
>
>> Save yourself a lot of time and just killfile him now. You'll thank me
>> for it later.
>
> You never thanked *me* for it, after you eventually realised that was
> th
{"Keyword": [value_for_keyword_1, value_for_keyword_2, ...]}
>>
>> if you try hard enough.
>
> The initial data structure comes from a CSV file, and is not under my
> control.
There's no reason to duplicate the CSV file's design in your own data
structures though.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
tch that format (some of them are pure
> free-form text). This has to get only the ones starting with Keyword,
> and in order. Steven, the line you suggested:
>
> lst = [parse_kwdlist(dct["Keyword%d"%i]) for i in xrange(1, len(dct)+1)]
>
> will bomb with KeyError when i
just gloss over the differences with a handwave and a
confident assertion.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
-- and other proprietary but multi-user OSes, such as VMS,
are more easily configured.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
hering with a cache?), that could be expensive:
compute_from = is_prime_number
get_from_cache(253590421923456781012937340348512751108342137327 *
195789732345627381015532937340363481051277321451)
:)
A better way is to explicitly test for the sentinel:
y = cache.get(x)
if y is not None:
...
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
you think are being created and destroyed needlessly?
(This is not a rhetorical question.)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
t die?"
> OR because the "Jump" command is
> already inside the Python terminal would this be considered inside
> Python`s working memory from the MMUs point of view?
I don't know. That depends on what you mean by "into Python".
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ppear
anywhere else:
SENTINEL = object()
obj = cache.get(x, SENTINEL)
if obj is SENTINEL:
obj = calculate(x)
cache[x] = obj
return obj
You can create the sentinel once, at the start of your program, rather
than each time.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
x27;s the fun in that?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
racters)? bool is the
canonical way to get an explicit boolean value. It's even shorter than
"not not x" (nine characters), and far more obvious than either of the
alternatives.
You're also correct that there very rarely is a need to explicitly
convert arbitrary objects to booleans. That's okay. That's not why bool
exists, that's just an occasionally useful side-effect.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 17 Apr 2011 22:49:41 -0700, Chris Rebert wrote:
>> Pro: You can do anything.
>> Con: You can do anything.
>
> I think someone already beat you to it. They call their invention
> "Lisp". :-P
Also Forth.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
tandard Python" install in one of my replies.
IronPython *is* standard Python. As are Jython, PyPy and CPython.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 18 Apr 2011 10:53:00 +0100, wisecracker wrote:
> global somestring
> somestring = " "
You don't need to declare a name in the global scope as global. It just
is global.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
enation, the usual idiom is to collect all the
substrings in a list, then join them all at once at the end:
pieces = []
while condition:
pieces.append('append stuff at end')
s = ''.join(pieces)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
rantee that.
*raises eyebrow*
Either of these should do the job:
sum(map(bool, (a, b, c, d)))
sum(bool(x) for x in (a, b, c, d))
but I don't see how
(arbitrary expression) + (another expression) + ... + (last expression)
can have any guarantees applied. I mean, you can't ev
kw = {}
class Foo(object, **kw):
if sys.version < "3":
__metaclass__ = MyMetaClass
Inelegant as it gets, but it should work.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
, {42: None, 'type': 'CALC'}]
[{'type': 'calc'}, {42: None, 'type': 'CALC'}]
[...]
> If I use the filter() method, the resulting list is completely empty. If
> I use the list comprehension, it works perfectly. Oddly, either version
> works in the stand-alone interpreter.
Let me guess... you're using an IDE?
There's your problem. IDEs often play silly buggers with the environment
in order to be "clever". You've probably found a bug in whatever IDE
you're using.
And this is why I won't touch the buggers with a 30 ft pole, at least not
for anything serious.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
has
done? He's such a hack!"
Given the wide range of pejorative meanings of "hack" going back at least
to the 19th century (to cut roughly without skill, a mediocre and
talentless writer, a person engaged to perform unskilled and boring
labour, a broken-down old horse, etc.
did cut out the URL though, so he gets credit for that.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
o re-use immutable objects, or not re-
use them, as it sees fit.
>>> sys.version
'2.6.4 (r264:75706, Feb 1 2010, 13:33:07) \n[GCC 4.1.2 20070925 (Red Hat
4.1.2-27)]'
>>>
>>>
>>> a = 1.23; b = 1.23; a is b
True
>>> c = 1.23
>>> c is a
False
but:
>>> a = 1001; b = 10001; a is b
False
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 21 Apr 2011 14:35:25 +0200, Peter Otten wrote:
> Steven D'Aprano wrote:
>
>> but:
>>
>>>>> a = 1001; b = 10001; a is b
>> False
>
> I would hope so ;)
Doh!
>> The point is that Python is free to re-use immutable objects, or
is, as using global functions is normally
harmless.)
http://c2.com/cgi/wiki?GlobalVariablesAreBad
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
inherits behaviour from BaseHandler.
(The details are a little more complex than the sketch above, but broadly
equivalent.)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
that so often
trades off machine efficiency for developer efficiency.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
en be caught by the usual
exception-handling mechanism. So it's not quite Boom.
>>> try:
... sys.exit(42)
... except SystemExit as e:
... print(e.code)
...
42
>>>
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
or backwards-
incompatible changes (described in a PEP, naturally), but for new
features, generally the package maintainer is free to add them without a
PEP.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
is-subclass relationship:
>>> issubclass(HomeHandler, BaseHandler)
True
>>> isinstance(test, HomeHandler)
True
>>> isinstance(test, BaseHandler)
True
If you *had* created a direct instance of BaseHandler by calling
BaseHandler:
>>> base = BaseHandler()
>>> isinstance(base, BaseHandler)
True
>>> isinstance(base, HomeHandler):
False
It's like this... "Toyota Prius" is a subclass of "Motor Vehicle", so
each and every Prius car is also a motor vehicle. But not every motor
vehicle is a Toyota Prius.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ems--- OS/2 and VM/CMS. In REXX
> everything is a string... everything.
This is much like my experience with Apple's Hypertalk, where the only
data structure is a string. I'm very fond of Hypertalk, but it is hardly
designed with machine efficiency in mind. If you think Python is slow
now, imagine how slow it would be if every expression had to be converted
from a number back into a string, and vice versa, after every operation:
x = str(int("1") + int("2"))
y = str(int("9")/int("3"))
z = str(int(x) - int(y))
flag = str(int(z) == int("0"))
only implicitly, by the interpreter.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 24 Apr 2011 11:35:28 +1000, Chris Angelico wrote:
> On Sun, Apr 24, 2011 at 10:42 AM, Steven D'Aprano
> wrote:
>> This is much like my experience with Apple's Hypertalk, where the only
>> data structure is a string. I'm very fond of Hypertalk, but it i
an function, and DWIM is
a notoriously bad anti-pattern that causes far more trouble than it is
worth. I'm even a little suspicious of numeric coercions between integer
and float. (But only a little.)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Consider this in Python 3.1:
>>> def f(a=42):
... return a
...
>>> f()
42
>>> f.__defaults__ = (23,)
>>> f()
23
Is this an accident of implementation, or can I trust that changing
function defaults in this fashion is guaranteed to work?
--
Steven
On Sun, 24 Apr 2011 10:07:02 -0700, Ken Seehart wrote:
> On 4/24/2011 2:58 AM, Steven D'Aprano wrote:
[...]
>> Is this an accident of implementation, or can I trust that changing
>> function defaults in this fashion is guaranteed to work?
>
> This is documented in pyth
On Mon, 25 Apr 2011 16:26:37 -0700, Paul Rubin wrote:
> Chris Angelico writes:
>> results = [function() for function in actions]
>
> results = map(apply, actions)
Sadly not in Python 3, where map is lazy and you need to add a call to
list to make it equivalent to the list comp
17, 19]}
>>> [(key[0], list(group)) for key,group in groupby(range(30), even_odd)
if key is not None]
[(0, [10]), (1, [11]), (0, [12]), (1, [13]), (0, [14]), (1, [15]), (0,
[16]), (1, [17]), (0, [18]), (1, [19]), (0, [20])]
So... when can we expect map_reduce in the functo
like this?:
>
> ['0A', '1B', '2C', '3D',...
Others have pointed you at a list comprehension, but just for completion,
there's also this:
from operator import itemgetter
map(itemgetter(0), list_of_tuples)
In Python 3, map becomes lazy
ere's only so many tiny little tests you can write before your head
explodes, so I'm going to keep putting "for arg in spam" loops in my
tests. But now I know to unroll those suckers into individual tests on
the first sign of trouble.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
oop updating the file names by
> adding a number to that name with each cycle. But can't get to first
> base.
Don't do it that way. Instead of:
filename1 = 'foo.txt'
filename2 = 'spam.doc'
filename3 = 'image.jpg'
Keep a list of file names:
filenames = ['foo.txt', 'spam.doc', 'image.jpg']
and work with that.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
specific value NA to use for missing,
distinct from NANs.
Still, it could be worse... I've seen a programs use to represent
missing values, on the basis that nobody could ever have more than (say)
5000 invoices in the database...
(I wish I was exaggerating.)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
by applying a
function to the output of another. E.g.:
f o g(x) is equivalent to f(g(x))
(Strictly speaking, the "o" in the f o g should be a little circle rather
than lowercase "O".)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ly slow and
memory-hungry.
This seems to have give rise to a myth that recursion should be avoided.
What needs to be avoided is *badly thought out* recursion. More sensible
recursive forms performs much better. I leave them as an exercise for
those who care, or an exercise in googling for those who care a little
less *wink*
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
native values. I believe (but could be wrong) that another language of
about the same vintage as Python, Emerald, also uses the same model.
That's not surprising, because I believe that Emerald (just like Python)
was strongly influenced by CLU.
What other languages use the same, or most
it and sys.setrecursionlimit, but
be careful, if you increase the limit too high, a deeply recursive
function will overflow the stack.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 01 May 2011 10:27:14 +0100, Hans Georg Schaathun wrote:
> On 01 May 2011 09:04:27 GMT, Steven D'Aprano
>wrote:
> : Why? You might have 4000 MB of main memory, and only 2 MB (say?) of
> call : stack allocated. The call stack can't grow indefinitely. If it
>
On Sun, 01 May 2011 14:15:35 +0100, Hans Georg Schaathun wrote:
> On 01 May 2011 11:56:57 GMT, Steven D'Aprano
>wrote:
> : Just google on "stack overflow crash".
>
> And I get loads of examples of stack overflows, but I could not see
> anybody linking th
On Mon, 02 May 2011 01:27:39 -0700, rusi wrote:
> On Apr 30, 12:18 pm, Steven D'Aprano [email protected]> wrote:
>
>> The number of calls is given by a recursive function with a similar
>> form as that of Fibonacci. As far as I know, it doesn't ha
On Mon, 02 May 2011 10:53:52 +0100, Hans Georg Schaathun wrote:
> On 02 May 2011 08:56:57 GMT, Steven D'Aprano
>wrote:
> : I see your smiley, but there are a number of similar series as
> Fibonacci, : with the same recurrence but different starting values, or
> sim
s
precisely the information that is blown away by tail-recursion
optimization.
* Tail-recursion is only a special case of recursion, and not a very
common special case either, so it is hardly worth the extra complexity of
the compiler to treat it specially.
Regardless of whether you agree wit
t you, perhaps Python is not the
language for you.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
t use bignums for non-integers. Out of curiosity, how would
you calculate:
sin(sqrt(7)*pi/31)
using bignums?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 03 May 2011 13:39:24 +0100, Hans Georg Schaathun wrote:
> On 01 May 2011 08:45:51 GMT, Steven D'Aprano
>wrote:
> : Python uses a data model of "name binding" and "call by object" (also
> : known as "call by sharing"). I trust I don
ition of words, how can they
communicate? Pass by reference Ruby is completely different from the
older usage in Pascal, VB and other languages. Likewise, pass by value in
Java is completely different from that in older languages. Pass by
reference in Ruby, and pass by value in Java, describe the same thing.
What were these people thinking?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
on level, or bit flipping at the hardware level, or von
Neumann machines, or ref counting, or garbage collection, or any of a
million other implementation details. All you need understand is the
declared semantics of the language.
Surely I can't be the only one who sometimes tries to work out a tr
only
character strings and integers.
Or (one of my personal favourites), Apple's Hypertalk? *Everything* is a
string in Hypertalk. I love Hypertalk, but good for data abstraction?
Don't make me laugh.
You should read Paul Graham on the Blub Paradox:
http://www.paulgraham.com/avg.html
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
y) and
> isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then.
`is` is supposed to be a *fast* operator, not even slower than equality
testing.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
l.
The only difference between the two scenarios is that writing a BASIC
interpreter is a tad harder than dereferencing a pointer, but that's just
a matter of degree, not of kind.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
self-hosting for many years now.
http://en.wikipedia.org/wiki/Self-hosting
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
e coder, as opposed to a
language feature.
I believe this distinction between what the compiler does, and what the
coder does, is at the heart of much confusion. Pointers that are passed
as arguments are themselves data, just as much as ints or floats, or (in
languages that have first-class fun
s yourself.
That's a pretty big difference though, and gets to the core of the
argument: it's a bit like arguing that manual cars are fitted with
exactly the same automatic transmission as auto cars, it's just that you
have to engage the clutch and shift gears yourself.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ython virtual machine, which
is at least two levels below that of Python code. The first is the byte
code which runs in the virtual machine; the second is the code in the VM.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote:
> Steven D'Aprano writes:
>
>> Given the following statement of Python code:
>>
>> >>> x = "spam"
>>
>> what is the value of the variable x?
>
> Mu (無).
>
> ‘x’ is a
18, Aug 12 2010, 02:17:22)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import warnings
>>> warnings.simplefilter("always")
>>> "%d" % 42
'42'
I see no DeprecationWarning.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 06 May 2011 02:23:19 -0700, Chris Rebert wrote:
> On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano
> wrote:
>> On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote:
>>> Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans
>>> :
>>>> Hi,
recated. It has
gone away.
Obsolete is a value judgment you are welcome to ignore. Deprecation is a
formal process that warns you that your code *will* break in the future.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
>>> def test(a, b, c, d):
... s = "The %s brown %s jumped over the %s %s." % (a, b, c, d)
... num_vowels = sum(s.count(c) for c in 'aeiou')
... return num_vowels in (12, 18, 19)
...
>>> for _ in amb(test):
... print a, b, c, d
...
quick fox lazy sloth
quick fox lazy dog
quick kangaroo stupid aardvark
[...more solutions cut for brevity]
hungry kangaroo confused aardvark
As written, amb is just a brute-force solver using more magic than is
good for any code, but it's fun to play with.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
as so:
>
> print("the {} is {}".format('sky', 3.4))
This is not comparing apples with apples. The format equivalent is:
print("the {} is {:d}".format('sky', 'blue'))
which will also raise an exception, ValueError instead of TypeError.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
e unrelated to the truth/falseness of
x. But that's quite rare. Normally I trust x to decide for itself whether
it is empty or not.
[1] Arguably with the exception of iterables. But then the len(x) test
doesn't work for them either.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
tics of checking for object identity.
Yes, if li == [] works too. But how do you know li is a list and not some
other sequence type?
The advantage of the "if x" test is that it is independent of the type of
x.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
2001 - 2100 of 15562 matches
Mail list logo