Duncan Booth wrote:
> Steven D'Aprano wrote:
[...]
>> My refactoring, with the bare minimum use of exec necessary:
>>
>> https://code.activestate.com/recipes/578918-yet-another-namedtuple/
>
>
> This may be a silly question, but what would stop you moving the exec
> inside the class?
I don't
Steven D'Aprano wrote:
> Consider the namedtuple implementation in the standard library.
> There's a lot of criticism of it, some of it justified. It uses exec
> extensively, which means the code is dominated by a giant string
> template. This defeats your editor's syntax colouring, makes
> refac
On 02/08/2014 03:59, Steven D'Aprano wrote:
My refactoring, with the bare minimum use of exec necessary:
https://code.activestate.com/recipes/578918-yet-another-namedtuple/
FTR I get the feed of new recipes from
gwene.com.activestate.code.feeds.recipes.langs.python from news.gmane.org.
--
Steven D'Aprano wrote:
> On Fri, 01 Aug 2014 17:44:27 +0200, Peter Otten wrote:
> [...]
>>> bool = ((df['a'] == 1) & (df['A'] == 0) |
>>> (df['b'] == 1) & (df['B'] == 0) |
>>> (df['c'] == 1) & (df['C'] == 0))
>>
>> This is how it might look without eval():
>>
>> #untested
>> r
On Fri, 01 Aug 2014 17:44:27 +0200, Peter Otten wrote:
> Alex van der Spek wrote:
>
>
>> I do know eval() lends itself to code injection but can't say I am
>> fully aware of its dangers. It seemed like a handy tool to me.
>
> In a lab if you don't need to protect your script against attacks fro
On 8/1/2014 11:02 AM, Steven D'Aprano wrote:
On Fri, 01 Aug 2014 09:32:36 -0400, Roy Smith wrote:
In article <53db95e6$0$29986$c3e8da3$54964...@news.astraweb.com>,
Steven D'Aprano wrote:
eval is almost never the right solution to any problem, and in the very
few exceptions, it needs carefu
On 01 Aug 2014 14:26:38 GMT, Alex van der Spek wrote:
[snip]
> This newsgroup scares me, it appears to be for professional computer
> scientists only, the theoretical part is sometimes too much for this
> practical physicist with an old background in FORTRAN.
>
> Is there a better place to ask q
On Fri, 01 Aug 2014 16:50:51 +0100, Mark Lawrence wrote:
>> which can be simplified to:
>>
>> flag = any( cond[c] == 1 and cond[c.upper()] for c in ['a', 'b', 'c'] )
>>
>>
> Shouldn't that be cond[c.upper()] == 0 ?
Yes it should be, thank you!
--
Steven
--
https://mail.python.org/mailman/list
On 01/08/2014 15:26, Alex van der Spek wrote:
On Fri, 01 Aug 2014 12:45:12 +, Alex van der Spek wrote:
With a dict like so:
cond = {'a': 1, 'b': 1, 'c': 1,
'A': 0, 'B', 0, 'C':0}
how would you make a boolean expression like this:
bool = (('a' == 1) & ('A' == 0) |
('b' =
On 01/08/2014 16:24, Steven D'Aprano wrote:
I don't know of anyone here who is an expert in pandas, so if you ask
questions which are specific to pandas, we may run into the limits of our
knowledge. If you can find a dedicated pandas mailing list or other
forum, they may help too, but I don't kno
On 01/08/2014 14:28, Steven D'Aprano wrote:
On Fri, 01 Aug 2014 12:45:12 +, Alex van der Spek wrote:
With a dict like so:
cond = {'a': 1, 'b': 1, 'c': 1,
'A': 0, 'B', 0, 'C':0}
how would you make a boolean expression like this:
bool = (('a' == 1) & ('A' == 0) |
('b' ==
Alex van der Spek wrote:
> I do know eval() lends itself to code injection but can't say I am
> fully aware of its dangers. It seemed like a handy tool to me.
In a lab if you don't need to protect your script against attacks from
outside eval() (and exec()) is fine. If the data fed to eval() is
On Fri, 01 Aug 2014 14:26:38 +, Alex van der Spek wrote:
[...]
> bool = ((df['a'] == 1) & (df['A'] == 0) |
> (df['b'] == 1) & (df['B'] == 0) |
> (df['c'] == 1) & (df['C'] == 0))
>
> I do know eval() lends itself to code injection but can't say I am fully
> aware of its dange
Hi,
Are you aware of the Python operator module?
It provides function equivalents of all (most?)
python operator. So instead of a==b, you can
state operator.eq(a,b). As a result, you can
loop over the key/value pairs in the dict and
built your logic with the operator.eq,
operator.and_, and operat
On Fri, 01 Aug 2014 09:32:36 -0400, Roy Smith wrote:
> In article <53db95e6$0$29986$c3e8da3$54964...@news.astraweb.com>,
> Steven D'Aprano wrote:
>
>> eval is almost never the right solution to any problem, and in the very
>> few exceptions, it needs careful handling by an expert to ensure you'
On 8/1/14 8:45 AM, Alex van der Spek wrote:
With a dict like so:
cond = {'a': 1, 'b': 1, 'c': 1,
'A': 0, 'B', 0, 'C':0}
how would you make a boolean expression like this:
bool = (('a' == 1) & ('A' == 0) |
('b' == 1) & ('B' == 0) |
('c' == 1) & ('C' == 0))
The fact t
On Fri, 01 Aug 2014 12:45:12 +, Alex van der Spek wrote:
> With a dict like so:
>
> cond = {'a': 1, 'b': 1, 'c': 1,
> 'A': 0, 'B', 0, 'C':0}
>
> how would you make a boolean expression like this:
>
> bool = (('a' == 1) & ('A' == 0) |
> ('b' == 1) & ('B' == 0) |
> ('c
In article <53db95e6$0$29986$c3e8da3$54964...@news.astraweb.com>,
Steven D'Aprano wrote:
> eval is almost never the right solution to any problem, and in the very
> few exceptions, it needs careful handling by an expert to ensure you're
> not introducing serious security bugs.
Corollary to th
On Fri, 01 Aug 2014 12:45:12 +, Alex van der Spek wrote:
> With a dict like so:
>
> cond = {'a': 1, 'b': 1, 'c': 1,
> 'A': 0, 'B', 0, 'C':0}
>
> how would you make a boolean expression like this:
>
> bool = (('a' == 1) & ('A' == 0) |
> ('b' == 1) & ('B' == 0) |
> ('c
In article <53db8bd8$0$2976$e4fe5...@news2.news.xs4all.nl>,
Alex van der Spek wrote:
> With a dict like so:
>
> cond = {'a': 1, 'b': 1, 'c': 1,
> 'A': 0, 'B', 0, 'C':0}
>
> how would you make a boolean expression like this:
>
> bool = (('a' == 1) & ('A' == 0) |
> ('b' == 1) &
On Fri, Aug 1, 2014 at 10:45 PM, Alex van der Spek wrote:
> how would you make a boolean expression like this:
>
> bool = (('a' == 1) & ('A' == 0) |
> ('b' == 1) & ('B' == 0) |
> ('c' == 1) & ('C' == 0))
Not sure what the use of this is, because 'a' will never be equal to
1. Are y
With a dict like so:
cond = {'a': 1, 'b': 1, 'c': 1,
'A': 0, 'B', 0, 'C':0}
how would you make a boolean expression like this:
bool = (('a' == 1) & ('A' == 0) |
('b' == 1) & ('B' == 0) |
('c' == 1) & ('C' == 0))
The fact that lowercase and uppercase keys are stringed tog
22 matches
Mail list logo