Comments (4)
Why don't we fix the __contains__ operation instead? has_key() is more of a
legacy API that has been replaced by the 'in' operator.
Original comment by [email protected]
on 7 Mar 2012 at 7:01
from coil.
I didn't want to change the default behavior of iterating over a struct.Struct;
i.e., I did not want to force an iteration over all keys in a struct
(recursively), just the immediate keys of that struct.
>>> x = coil.text.fromString('a: { b: c d: { e: True } }')
>>> for key in x:
... print key
a
>>> x.has_key('a.b')
True
I suppose __contains__ works, I hadn't looked into that, but I wanted to keep
iteration distinct from whether the (fully-dotted) key exists in the struct.
Original comment by [email protected]
on 3 Apr 2012 at 5:30
from coil.
Making iteration "for key in x" slightly different from comtains "if key in x"
slightly different is slightly odd, but I'd prefer that than making the legacy
contains api "x.has_key" different from the new api. Or perhaps an entirely new
method would be better, "x.has_child" or some such where the recursiveness of
the lookup is explicit. I think I'm leaning to the entirely new method at the
moment.
Original comment by [email protected]
on 3 Apr 2012 at 5:41
from coil.
how about adding a recursive=False kwarg to has_key (or write a new
coil-specific fn)?
It seems to me that the correct way to iterate and test keys in coil is the
same way as in dicts. If you want a coil-specific way to test for existence,
make a coil-specific function?
Original comment by [email protected]
on 3 Apr 2012 at 6:06
from coil.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coil.