Chris Angelico wrote:
> On Fri, Jul 15, 2011 at 3:28 PM, Steven D'Aprano
> wrote:
>> My question is, should I accept None as the missing value, or a dedicated
>> singleton?
>>
>> In favour of None: it's already there, no extra code required. People may
Chris Angelico wrote:
> On Fri, Jul 15, 2011 at 8:46 PM, Steven D'Aprano
> wrote:
>> In general, you have missing values in statistics because somebody
>> wouldn't answer a question, and the Ethics Committee frowns on
>> researchers torturing their subjects
r code with
assertions turned off if you use assert for testing?)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
com/tailing-in-python/
Modifying it to be non-blocking should be pretty straightforward -- just add
a `yield ""` after the `if not line`.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
to take the square root of it.
Assertions should be rare, and never used for testing arguments (except,
maybe, for purely internal functions that only get called by your own
functions, never by the caller). If the caller ever sees an AssertionError
generated by your code, that is a bug in your cod
nt token or expression. Including a newline
inside an expression is an error, unless you explicitly silence it by using
a backslash or using brackets. It's a bit too far to say that "any if
statement is an explicit way to silent newline errors".
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
tremely detailed and useful.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Chris Rebert wrote:
> On Fri, Jul 15, 2011 at 7:47 PM, Steven D'Aprano
> wrote:
>
>> Assertions are for testing internal program logic, not for validation.
>>
>> (I don't even like using assert for testing. How do you test your code
>> with assertio
concentrate on
concrete examples. As far as Python goes, the use of list comps/generator
expressions, iterators and decorators are the main functional idioms, not
so much map, filter and especially reduce, which only avoided being removed
from Python 3 by the narrowest margin.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
I have a custom object that customises the usual maths functions and
operators, such as addition, multiplication, math.ceil etc.
Is there a way to also customise math.sqrt? I don't think there is, but I
may have missed something.
--
Steven
--
http://mail.python.org/mailman/listinfo/p
way to go:
>
> from distutils.core import setup
>
> setup(
> name = 'Elucidation',
> version = '0.0.1-WIP',
[snip]
Hilariously, in my newsreader, the first example (allegedly unaligned) was
lined up as straight as an arrow, while the allegedly aligned s
tion he craves, or that he honestly believes this crap.
I suspect the later. I get the impression that he genuinely has so little
self-awareness that he doesn't notice that for all his talk about FREEDOM,
he's constantly trying to deny it to others by forcing them to do what he
wants them to do.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
nd forum software, even those aimed at programmers, often do
an astonishingly crap job at not messing with your text.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
but were too terrified to say so publicly would drop CPython in a flash and
follow him.
Thread starts here: read and weep.
http://www.gossamer-threads.com/lists/python/python/835227?do=post_view_threaded#835227
How's that fork going Rick? Written a single line of code yet?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
80 columns is hogwash.
I agree! Which is why I set my line width to 78 columns.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano wrote:
> Roy Smith wrote:
>
>> We don't have that problem any more. It truly boggles my mind that
>> we're still churning out people with 80 column minds. I'm willing to
>> entertain arguments about readability of long lines, but th
r 23 to 42 of theStr
put suffix after theStr
delete first char of theStr
although this only applied to built-in functions, not user-functions.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Tim Chase wrote:
> On 07/17/2011 08:01 PM, Steven D'Aprano wrote:
>> Roy Smith wrote:
>>> We don't have that problem any more. It truly boggles my
>>> mind that we're still churning out people with 80 column
>>> minds. I'm willing to ente
t()
0.7412619590759277
>>> t2.timeit()
0.3557558059692383
So in this example, the partial function is about twice as fast as the one
written in Python.
This does not necessarily apply for all functions, but it sometimes is
useful.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
SCII, rather than understand you
meant it as a sign of the utmost respect for the richness and diversity of
human beings and their languages, cultures, maths and sciences.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
rusi wrote:
> Every time I try to understand unicode and remain stuck I come to the
> conclusion that I must be an imbecile.
http://www.joelonsoftware.com/articles/Unicode.html
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
o treat it as UTF-8 will give an error, just as
trying to view a mp3 file as if it were a jpeg will give an error. Why you
imagine this is a problem for Unicode is beyond me.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ry backslash with an extra backslash:
>>> print "logs\\2011-07-03"
logs\2011-07-03
(2) Use forward slashes, as Windows will happily accept them instead of
backslashes.
(3) Use another operating system. *wink*
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Thomas Jollans wrote:
> On 19/07/11 06:42, Steven D'Aprano wrote:
>> (1) Escape every backslash with an extra backslash:
>>
>>>>> print "logs\\2011-07-03"
>> logs\2011-07-03
>
> There is a more elegant solution: use raw strings: r'c
uggestions?
# Untested.
def get_winner(adict):
values = sorted(adict.values(), reverse=True)
if values[0] == values[1]:
return adict['b']
else:
return values[0]
Assumes that adict has at least two items. May be slow if it has millions of
items.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
gt; 5. No particular GUI thread synchronization is needed -- Python has a
> GIL.
Except for Jython, IronPython and PyPy.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 20 Jul 2011 05:20 pm Stefan Behnel wrote:
> Steven D'Aprano, 20.07.2011 06:28:
>>> Python has a GIL.
>>
>> Except for Jython, IronPython and PyPy.
>
> PyPy has a GIL, too.
Isn't it optional though?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
n()
turning on
turning off
turning on
turning off
Traceback (most recent call last):
File "", line 1, in
File "", line 9, in run
KeyboardInterrupt
More complex finite state machines can have many different states, and much
more complicated behaviour.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 20 Jul 2011 05:54 pm jmfauth wrote:
> DRY? acronym for ?
I'd like to tell you, but I already told somebody else...
*grins*
http://en.wikipedia.org/wiki/Don't_repeat_yourself
http://c2.com/cgi/wiki?DontRepeatYourself
--
Steven
--
http://mail.python.org/mailman/li
On Wed, 20 Jul 2011 05:51 pm Andrew Berg wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: RIPEMD160
>
> On 2011.07.20 02:28 AM, Steven D'Aprano wrote:
>> Isn't it optional though?
> No.
> http://doc.pypy.org/en/latest/faq.html#does-pypy-have-a-gil-why
Ah,
sn't. Rambling off on a new topic under the wrong subject is
> rude.
Ha ha, rantingrick lecturing others on rudeness! How cute!
Or hypocritical. Sometimes I get those two confused.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
amming is deciding *precisely* what behaviour you want. Once
you've done that, the rest is easy.
Apart from debugging and writing documentation and making it fast enough,
which is the other 90%.
*wink*
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ating more heat in the CPU and making other developers laugh at you :)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
raise ValueError('Invalid literal for int')
> return int(num)
> return int(s)
Consider what happens if you pass s = "42.-0".
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ident that Python A does everything that Perl A does.
Possibly *better* than the Perl module, since if you don't have a test
suite for it, it probably has many hidden bugs.
Continue in this way with the rest of the modules. At the end, you will have
a full test suite against the entire collection of modules.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
n Python 3.
Generator expressions become more efficient; itertools.imap disappears; the
built-in map becomes a lazy generator rather than returning a list.)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
haven't seen your
code, so I could be way off base here, but I expect you're using deeply
hierarchical data structures, and violating the Law of Demeter:
paper = paper_boy.give_newspaper()
# Pay the paper boy.
paper_boy.collect_payment(customer.backpocket.wallet(2.0, tip=300.00))
Don&
tive Get Out Of Kill-File card. Don't
make me regret it.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
hould be, not
what your terminal is actually using.
Your console app (xterm, konsole, Gnome terminal, whatever...) probably has
a way to query what encoding it is using, but I'll be buggered if I can
find out what that is. In konsole I can look at the Settings > Encodings
menu, but it claim
e
web, but nothing about showing the already running application when 1
instance of the program already exists. Is there a way to realize this
in python?
I'm now doing the development on a linux machine, but the final
program should work on Windows.
Cheers,
Steven
--
http://mail.python.o
er words, BE CONSISTENT!
Oh, and you were doing so good there for all of one day.
Back to the kill-file with you.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
here.
As for True and False, bool has to be able to return them, because the whole
purpose of exposing bool is so people can call it: if bool(some_value) was
an error, that would defeat the purpose of having bool!
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ce if it didn't explode when list_of_objects contains None.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
empty': str, 'null': lambda: None }
does the job. No need for a top-level named function.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
;m currently writing a library where nearly all the
functions violate the No Constant Argument rule. (The API isn't yet stable,
so I may still change my mind.) Make of that what you will.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
would be a major bug. Did you actually try
it?
>>> '/home//h1122/bin///ghi/'.split('/')
['', 'home', '', 'h1122', 'bin', '', '', 'ghi', '']
Exactly as expected, and correct.
Now obviously if you intend treating this as a list of path components, you
have to filter out the empty strings, but otherwise works fine.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ect.
Been there, done that, floundered on the inability of people to work out the
details.
http://www.python.org/dev/peps/pep-0355/
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
i = y[0]
i = y[1]
i = y[2]
...
until IndexError is raised. You break after calling y[0], but the next loop
starts at y[0] again, and so you never progress beyond the first item in
the xrange object.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Brian Blais wrote:
> On Jul 29, 2011, at 9:22 PM, Steven D'Aprano wrote:
>
>> Billy Mays wrote:
>>
>>> Is xrange not a generator? I know it doesn't return a tuple or list, so
>>> what exactly is it?
>>
>> xrange pre-dates generators
sures?
def factory(x):
def inner(param):
return param + x
return inner
plusone = factory(1)
plustwo = factory(2)
I'm betting that this will be much faster than exec, and much more readable.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
[email protected] wrote:
> On 25 juil, 17:36, "Steven W. Orr" wrote:
>> I have been doing a lot of reading. I'm starting to get it. I think it's
>> really cool as well as dangerous,
>
> Dangerous ??? Why so ? Is there anything "dangero
that there's only one instance of each.
I'm sure that I remember a short period during which Python had bools, but
didn't guarantee that there would only be one instance of True and one of
False, but I'm damned if I can find any evidence of this. Am I
confabulating?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ded all the spammer's
URLs, as that will help improve their Google page ranks. I'm sure the
spammer will thank you for your assistance.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
File "test.py", line 1
def func:
^
SyntaxError: invalid syntax
Note that the error shows the line that is bad, and puts an up-arrow ^
directly under where it goes bad.
Please COPY and PASTE the FULL error. Do not re-type it from memory,
summarise it, put it in your own words, o
o write:
cache = [-1]*900
Even better is to use a dict instead of a list.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Billy Mays wrote:
> I have fixed the problem for you:
>
>
> def fibo(n):
> phi = (1+5**.5)/2; iphi = 1-phi;
> return (phi**n - iphi**n) / (5**.5)
Does your definition of "fixed" mean "gives wrong results for n >= 4 "?
>>> fibo(4) ==
o be so far out on the
bleeding edge that even Slackware users consider them nuts. :)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
wered, "Who
cares, we're making great time!"
(True story.)
> I find this tradeoff acceptable.
Given that Fibonacci numbers are mostly of interest to number theorists, who
care about the *actual* Fibonacci numbers and not almost-but-not-quite
Fibonacci numbers, I&
.
However, at some point I would expect adding hand-crafted optimizations to
CPython will cease to be worthwhile. Guido is already talking about CPython
becoming the reference implementation, and PyPy the production
implementation because it's faster. PyPy's optimizing compiler is already
abou
7;t all have
a "more options" link.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
;NoneType' object has no attribute 'recv'
Am I right to expect that the above idiom cannot work? If not, what sort of
context managers do work as shown?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
nt
targets. While slightly ugly, it doesn't seem ugly enough to justify the
extra complexity of special syntax for such a special case.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
next time I call
test() I'll get len=None.
[...]
> So... Would this potentially produce wrong results? Would it be of any
> use, or would its benefit be only valued in times when the whole
> function needs to be redone in C?
You really would need to demonstrate that the bottleneck in useful code (as
opposed to toy examples) was the name lookups.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
r:
(1) use a different name: length = len
(2) use a fully-qualified name: import builtins; len = builtins.len
(3) do the assignment as a default parameter, which has slightly different
binding rules: def func(x, len=len)
(4) manual lookup: len = builtins.__dict__['len'] # untested
I don't recommend that last one, unless you're deliberately trying to write
obfuscated code :)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
t code simply calls isperfect(n) for each n. The number of iterations in
each call to isperfect is approximately sqrt(n), so the total in any
exhaustive test is approximately sum(x**0.5 for x in range(upperlimit)),
which gets rather large.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Chris Angelico wrote:
> On Thu, Aug 4, 2011 at 4:01 AM, Steven D'Aprano
> wrote:
>> a, b = divmod(n, i)
>> if b == 0:
>> total += a+i
>>
>
> Wouldn't this fail on squares? It happens to give correct results as
> far as I've checked; no squ
/www.joelonsoftware.com/items/2007/06/12.html
http://www.codinghorror.com/blog/2007/06/whats-wrong-with-apples-font-rendering.html
http://jujusoft.com/?page_id=25
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
on. I would recommend not catching ImportError at all,
and just let the standard Python error handling print the traceback.
Especially for a tool aimed at programmers (who else would be interested in
PyWhich?), hiding useful diagnostic errors and replacing them with a
generic, and potentially wrong, message, is very bad.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Thomas Rachel wrote:
> Am 03.08.2011 04:15 schrieb Steven D'Aprano:
[...]
> > but to me that looks badly wrong. Surely the spam context manager
> > object will exit after the first iteration, and always raise an
> > exception on the second? But I don't quite u
Tim Chase wrote:
> On 08/04/2011 07:34 PM, Steven D'Aprano wrote:
>> Billy Mays wrote:
>>> #!/usr/bin/python
>>
>> I believe the recommended, platform independent hash-bang line is
>>
>> #!/usr/bin/which python
>
> I think you mean
>
>
tain code. Even methods are just
wrappers around functions. Even built-in functions like len don't contain
code! (Or at least, their code isn't accessible from Python.) Which makes
sense, if you think about it: their code is part of the Python virtual
machine, not the object.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ing recursive:
An easier way to demonstrate the process:
>>> def f(x):
... print x
... if x > 0: f(x-1)
...
>>> f(3)
3
2
1
0
>>> g = f
>>> del f
>>> g(3)
3
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in f
NameError: global name 'f' is not defined
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
g special with it.
Well you better also catch SyntaxError, because a later version of your
script might need to do something special with it too :)
Also RuntimeError, ValueError, TypeError... *wink*
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Eric Snow wrote:
> On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano
> wrote:
>> Eric Snow wrote:
>>
>>> In Python, three types of objects have special syntax and mechanics
>>> for their instantiation, during which a code object is generated:
>>>
you the tools to shoot
yourself in the foot, although it won't necessarily be easy, or pretty, or
fast.
So, tell us what your real problem is, the end towards which you
think "replace all..." is the solution, and we'll see if we can help.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Mel wrote:
> Steven D'Aprano wrote:
>
>> There may be some other obscure built-in type that includes code objects,
>> but I can't imagine what it would be. I feel confident in saying that
>> functions, and functions alone, contain code. Even methods are just
Eric Snow wrote:
> On Fri, Aug 5, 2011 at 11:29 AM, Steven D'Aprano
> wrote:
[...]
>> Do you believe that this process of generating a code object and throwing
>> it away is a part of the Python language specification, which any
>> compiler must do in order to ca
s is the default for Mac OS's
terminal app, but I have no idea about the many different Linux terminals).
Then:
>>> bytes = 'ao\xc3\xbbt' # From calendar.month_name[8]
>>> s = bytes.decode('utf-8') # Like unicode(bytes, 'utf-8')
>>&g
such big files, because it *takes* a lot
more work.
For something as small as one million numbers, chances are the Unix sort
falls back on a heapsort or a quicksort, which will be pretty fast, but it
ain't no timsort.
So yes, Python's timsort is awesome, but so is Unix's sort, just in
different ways.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
8/
sudo python setup.py install
and if that doesn't work, try asking on an Editra mailing list.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
t in any version of Python between 1.5 and 3.3
that I have.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
s to a list,
> below works because there are exactly 2 items on the rhs.
> Does Python have a catchall, or an ignore the rest?
Yes. In Python 3, you can do this:
>>> a, b, *t, c = (1, 2, 3, 4, 5, 6, 7, 8, 9)
>>> t
[3, 4, 5, 6, 7, 8]
(but not in Python 2)
--
Steven
--
http
t really doesn't matter what you do, they will all be more
or less as efficient. Write whatever you feel looks best.
But if L is huge, then the difference between a four-liner that iterates
over the list once, and one-liner that iterates over it four times, may be
considerable.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
t was he wanted to avoid
*writing out an explicit loop*. That is, he wants a one-liner, so he
doesn't have to think about the details of iterating over the list.
When we write:
a = sum(a_sequence)
aren't we doing the same thing really?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
"name"? Double-leading-and-trailing-underscore attributes are
reserved for Python, and have special semantics.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
#x27;)
that's a prime candidate for turning into an assertion:
assert condition, 'condition unexpectedly false'
do_something()
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
d "b", or by index, 0 and 1:
instance = ThingWithTwoIntegers(23, 42)
instance[0]
=> 23
instance.b
=> 42
Obviously this isn't a full blown list, but if you don't need all the
list-like behaviour (sorting, inserting, deleting items, etc.) why support
it?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
sion(s) of Python are you using?
Depending on whether you are asking out of curiosity, or because you have
code that uses import hooks and you're about to migrate from Python 2.3 to
3.1, the answers may be different.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
l be interfering with
the keyboard buffer, for its own purposes. E.g. in IDLE 2.6.2, if I call
getch it *immediately* returns without blocking:
>>> msvcrt.getch()
'\xff'
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
f I would have gotten a dollar for every time I talked to someone in a
> company about why they dont use python for their products and I was served
> the answer "Well it kind of sucks in GUI development", I would be a
> millionaire.
What, these millions of companies don't ha
teger, so t.fred.__doc__ returns the
docstring from the integer, not for the property.
>>> t.__class__.fred.__doc__
'attribute'
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
But the hard part is ensuring that Test.fred doesn't get replaced:
>>> Test.fred = 11
>>> Test.fred.__doc__
'int(x[, base]) -> integer\n\nConvert a string or number ...'
Not impossible to solve, but an awful lot of trouble for very little
benefit. Just put
Ethan Furman wrote:
> So if property docstrings are so hard to get to, what's the point in
> having them?
Hard to get, not impossible. But I have no idea really -- they don't seem
very useful to me.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ources may help:
http://wiki.python.org/moin/DistributedProgramming
http://wiki.python.org/moin/ParallelProcessing
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ngs on the individual
getter/setter/deleter functions. But property() itself explicitly takes a
docstring parameter. It is that docstring that seems of limited value,
except that Eric Snow has pointed out that help(instance) will display
property help strings.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
with this is that there are roughly a dozen items I
> would like to make available via the `import *` mechanism in my dbf
> module, and another dozen that, while part of the public API, don't need
> to be available via an `import *`.
You have to choose both, or neither, but you can't have just one.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
!"
...
>>>
>>> for obj in MyClass:
... print obj
...
42
23
-99
Surprise!
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
;)
for line in f:
if some_condition(line):
continue # skip the line
process(line)
f.close()
some_condition can be anything you like. You just have to write the code to
make it so.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
y to do it
> this way.
But it does force people to read it, because some people will use it, and so
others will have to suffer for their poor judgement.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
se join,
which is consistently fast.
You should limit string addition to small numbers of substrings:
result = head + body + tail # This is okay.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
1701 - 1800 of 15559 matches
Mail list logo