A common pattern I use is to have logging calls for debug and information with
my applications.
The logging calls can be separately enabled and disabled.
For example:
debug_log_enabled = False
def debugLog( msg ):
If debug_log_enabled:
print( ‘Debug: %s’ % (msg,) )
Then the ca
> On 14 Feb 2017, at 15:51, Barry Scott wrote:
> And have the evaluation of the argument skipped unless its dbg_log is enabled.
>
> I cannot see how to do this with python as it stands.
>
> Something would have to be added to allow python to short circuit the
> argument tuple evaluation.
>
>
Can you wrap the expensive functions in lambdas? And have your logger
evaluate it, only if required?
> debugLog( ‘info is %r’ % (lambda: expensiveFunction(),) )
On 2017-02-14 10:51, Barry Scott wrote:
> A common pattern I use is to have logging calls for debug and information
> with my applica
Seems slightly simpler to just make debugLog accept a callable as an
alternative to a string.
debugLog(lambda:( ‘info is %s’ % expensiveFunction()) )
Op 14 feb. 2017 18:42 schreef "Kyle Lahnakoski" :
Can you wrap the expensive functions in lambdas? And have your logger
evaluate it, only if req
On 2017-02-14 15:51, Barry Scott wrote:
A common pattern I use is to have logging calls for debug and information with
my applications.
The logging calls can be separately enabled and disabled.
For example:
debug_log_enabled = False
def debugLog( msg ):
If debug_log_enabled:
I have a small syntax idea.
In short, contraction of
for x in range(a,b,c) :
to
for x in a,b,c :
I really think there is something cute in it.
So like a shortcut for range() which works only in for-in statement.
So from syntactical POV, do you find it nice syntax?
Visually it seems to me less b
On Tue, Feb 14, 2017 at 3:06 PM, Mikhail V wrote:
> I have a small syntax idea.
> In short, contraction of
>
> for x in range(a,b,c) :
>
> to
>
> for x in a,b,c :
>
> I really think there is something cute in it.
> So like a shortcut for range() which works only in for-in statement.
> So from synt
I would be surprised if this hasn't been suggested many times before. It's
similar to Matlab's syntax:
for x = start:step:finish
end
Any such change would represent a large departure from normal python syntax
for dubious gain. In general, you can put any expression after the `in`
keyword so
On Feb 14, 2017, at 12:48 PM, Steven D'Aprano wrote:
>On Fri, Feb 10, 2017 at 09:05:49PM -0500, Terry Reedy wrote:
>> Saving about 10 keystrokes is close to trivial.
>
>The same argument can be made for @decorator syntax.
>
>And, if I understand correctly, the same argument *was* made against
>d
On 2017-02-14 21:09, Zachary Ware wrote:
On Tue, Feb 14, 2017 at 3:06 PM, Mikhail V wrote:
I have a small syntax idea.
In short, contraction of
for x in range(a,b,c) :
to
for x in a,b,c :
I really think there is something cute in it.
So like a shortcut for range() which works only in for-in
On Tue, Feb 14, 2017 at 4:41 PM, MRAB wrote:
> On 2017-02-14 21:09, Zachary Ware wrote:
>
>> On Tue, Feb 14, 2017 at 3:06 PM, Mikhail V wrote:
>>
>>> I have a small syntax idea.
>>> In short, contraction of
>>>
>>> for x in range(a,b,c) :
>>>
>>> to
>>>
>>> for x in a,b,c :
>>>
>>> I really thin
for i in range(...) is *sometimes* indicative of code smell, especially
when then doing x[i], though it has its uses. I've never had a need to
shorten a for...range line though.
Other than it being "cute", do you have an example where it's definitively
better?
On Tue, Feb 14, 2017 at 4:03 PM, Tod
There are several mechanisms in the logging module to handle this use-case.
First, note that logging functions can take multiple arguments (
https://docs.python.org/3/library/logging.html?highlight=logging#logging.Logger.debug
):
>>> import logging
>>> msg = "hello, %s! %s to %s you!"
>>> args = (
> On 14 Feb 2017, at 17:39, Kyle Lahnakoski wrote:
>
>
> Can you wrap the expensive functions in lambdas? And have your logger
> evaluate it, only if required?
>
>> debugLog( ‘info is %r’ % (lambda: expensiveFunction(),) )
Interesting idea. I will bench mark and see what the cost of the lamba
> On 14 Feb 2017, at 17:03, Cory Benfield wrote:
>
>
>> On 14 Feb 2017, at 15:51, Barry Scott wrote:
>> And have the evaluation of the argument skipped unless its dbg_log is
>> enabled.
>>
>> I cannot see how to do this with python as it stands.
>>
>> Something would have to be added to all
On 14 February 2017 at 22:41, MRAB wrote:
> On 2017-02-14 21:09, Zachary Ware wrote:
>
>> On Tue, Feb 14, 2017 at 3:06 PM, Mikhail V wrote:
>>
>>> I have a small syntax idea.
>>> In short, contraction of
>>>
>>> for x in range(a,b,c) :
>>>
>>> to
>>>
>>> for x in a,b,c :
>>>
>>> I really think t
Make some shim object that you can index into to get that functionality,
could even call it Z (for the set of all integers). Short, and requires no
new syntax.
class IndexableRange:
def __getitem__(self, item):
if isinstance(item, slice):
start = item.start if item.start is
On 15 February 2017 at 00:41, Nick Timkovich
wrote:
> Make some shim object that you can index into to get that functionality,
> could even call it Z (for the set of all integers). Short, and requires no
> new syntax.
>
> class IndexableRange:
> def __getitem__(self, item):
> if isins
The point is that the cost of creating the msg argument can be very
high.
At the point that logging decides to skip output it is to late to save
the cost of creating the arg tuple.
This sounds like an optimization that's sufficiently rare and complex to
warrant a custom fix or a 3rd p
On 2017-02-14 19:51, Abe Dillon wrote:
>The point is that the cost of creating the msg argument can be very
> high.
>
> At the point that logging decides to skip output it is to late to
> save the cost of creating the arg tuple.
>
> This sounds like an optimization that's sufficiently
On Sun, Feb 12, 2017, at 21:55, Steven D'Aprano wrote:
> But honestly, no. This is not going to happen. .Net VB and C# have
> something like this, as does Lua, and people still write classes the
> ordinary way 99.99% of the time.
The VB/C# thing you are referring to is, I assume, extension metho
21 matches
Mail list logo