Have you used the second approach and, if so, what was your motivation?
Is there a good/bad reason to choose one over the other?
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
e 3, in
Exception: Long exception text
Then, you can indent the individual lines any way you like.
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
ng (the trailing comma suppresses the new
line) and you'll never have to count the number of items in lst.
You also have some statements like:
sqlchk = "select * from employees where id = \"%s\"" % (arg)
Since a Python list can be enclosed in apostrophes as well as
quotations, you can get the same thing without the escapes:
sqlchk = 'select * from employees where id = "%s"' % (arg)
Anyway -- just some food for thought.
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
;s the general feeling about this? Adhere to the PEP 8
binary operators style, or modify it for string formatting?
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
ld do this:
>>> l = [1,2,3,4,5]
>>> l[0:1, 3:4]
Traceback (most recent call last):
File "", line 1, in
TypeError: list indices must be integers, not tuple
but that clearly doesn't work! So, when and how can one use slice lists?
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
roach 2 sets
up loop machinery which you don't really need in this case.
I have a couple of questions:
1. If you had to choose between approaches 1 and 2, which one would
you go for, and why?
2. What other techniques have you used in such a situation?
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
ot in a context
manager on f:
with h as f():
# insert code here to return True, since I am in a context manager on f:
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
On Dienstag 01 Februar 2011, Gerald Britton wrote:
> I'd like to know how (perhaps with the inspect module) I can
> tell if I am running in a context manager.
>>class f(object):
>> def __init__(self):
>> self.inContext = False
>>def __enter__(sel
ss of how
it was created. Whatever the test, it needs to return False in the
first case and True in the second case, without modifying the class
definition.
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
ack (most recent call last):
File "", line 1, in
File "", line 2, in f
File "", line 2, in g
File "", line 2, in h
Exception
>>>
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
ter. BTW, if you like:
[item for item in iterable if predicate(item)]
you can use:
filter(predicate, item)
I find the latter neater for the same reasons as above
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
0 loops, best of 3: 879 usec per loop
granted, but not on topic here. we're talking about map vs list comps
when you want to use a function.
>map is only likely to be faster if you wanted to call a function in both cases.
Which is exactly the point.
>f you have an expression that can be inlined you save the function call
>overhead with the list comprehension.
Of course, but that's not the point.
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
gt; Timer('map(g, s)', 'from __main__ import s, g').timeit()
1.8645310401916504
>>> Timer('[x.__class__ for x in s]', 'from __main__ import s').timeit()
1.7232599258422852
>>> Timer('map(a, s)', 'from __main__ import s, a').timeit()
2.4131419658660889
>>>
So, what's the feeling out there? Go with map and the operators or
stick with the list comps?
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
I see that Python 3.2 includes a new module -- html -- with a single
function -- escape. I would like to know how this function differs
from xml.sax.saxutils.escape and, if there is no difference (or only a
minor one), what the need is for this new module and its lone function
--
Gerald Britton
&& x < 7')
'x > 2 && x < 7'
--
Gerald Britton
--
http://mail.python.org/mailman/listinfo/python-list
(Forgot the subject)
> >* On 25 Mar 2017, at 15:51, Gerald Britton ><https://mail.python.org/mailman/listinfo/python-ideas>> wrote:
> *> >* On 25 March 2017 at 11:24, Pavel Velikhov <http://gmail.com> <http://gmail.com/ <http://gmail.com/>>> wrot
Did u get the answer to that question???
To find out more about Reuters visit www.about.reuters.com
Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Reuters Ltd.
--
http://mail.python.org/m
101 - 117 of 117 matches
Mail list logo