Re: Problem with OrderedDict - progress report

2018-06-01 Thread Chris Angelico
On Sat, Jun 2, 2018 at 9:10 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> if you 'break' immediately after a mutation, that isn't >> continuing to iterate. Even though you're inside the loop, there's no >> further action taken to process the loop, and no problem. > > > Yes, but you're als

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Gregory Ewing
Chris Angelico wrote: if you 'break' immediately after a mutation, that isn't continuing to iterate. Even though you're inside the loop, there's no further action taken to process the loop, and no problem. Yes, but you're also not calling next() again, so no exception would be triggered. My po

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Steven D'Aprano
gt;>> for k in d: > ... if k == 2: > ... d[3] = 'three' > ... > Traceback (most recent call last): > File "", line 1, in > RuntimeError: dictionary changed size during iteration just because k == 2 does not mean this matches on the last iteration. I

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Frank Millman
st key, what should happen? My feeling is that this should be an error, because it's not clear whether iteration should stop at that point or not. I agree. A normal dictionary raises an exception. I think that an OrderedDict should do so as well. In fact this was the reason for my intermi

Re: Problem with OrderedDict - progress report

2018-06-01 Thread INADA Naoki
On Fri, Jun 1, 2018 at 4:56 PM Gregory Ewing wrote: > Chris Angelico wrote: > > It is an error to mutate the dictionary *and then continue to iterate > over it*. > > But if you're processing the last key, and you add one so > that it's no longer the last key, what should happen? > > My feeling is

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Chris Angelico
On Fri, Jun 1, 2018 at 5:54 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> It is an error to mutate the dictionary *and then continue to iterate over >> it*. > > > But if you're processing the last key, and you add one so > that it's no longer the last key, what should happen? > > My feeli

Re: Problem with OrderedDict - progress report

2018-06-01 Thread Gregory Ewing
Chris Angelico wrote: It is an error to mutate the dictionary *and then continue to iterate over it*. But if you're processing the last key, and you add one so that it's no longer the last key, what should happen? My feeling is that this should be an error, because it's not clear whether itera

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Chris Angelico
ou will see that adding a key while >> > processing the *last* key in an OrderedDict does not give rise to an >> > exception. >> >> If you mutate the dict, and then stop iterating over it, there is no >> check that the dict was mutated. >> >> It isn&#x

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Frank Millman
"Steven D'Aprano" wrote in message news:peorib$1f4$2...@blaine.gmane.org... On Thu, 31 May 2018 10:05:43 +0200, Frank Millman wrote: > From the interpreter session below, you will see that adding a key while > processing the *last* key in an OrderedDict does not give r

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Steven D'Aprano
oved the problem to > a different place, which is progress. > > From the interpreter session below, you will see that adding a key while > processing the *last* key in an OrderedDict does not give rise to an > exception. If you mutate the dict, and then stop iterating over it, there

Re: Problem with OrderedDict - progress report

2018-05-31 Thread Frank Millman
key while processing the *last* key in an OrderedDict does not give rise to an exception. Adding a key while processing any prior key in an OrderedDict does raise the exception. I have checked this fairly thoroughly and it behaves the same way every time. from collections import OrderedDict as OD

Re: Problem with OrderedDict

2018-05-30 Thread INADA Naoki
p plugging away and report > back with any findings. > C implementation of OrderedDict checks ​all ​ "key change" ​(remove or insert key) ​ while iteration always. But you can bypass the check by using dict methods ​. Both of dict and OrdredDict checks size is not changed from st

Re: Problem with OrderedDict

2018-05-30 Thread Frank Millman
ced the intermittent nature > yet. > > 2. It gives a different error - > > RuntimeError: dictionary changed size during iteration Can you share your simple example? I can, but I actually found my error. I habitually type - from collections import OrderedDict as OD and

Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 10:48:06 +0200, Frank Millman wrote: > I tried to reduce it to a simple example. I succeeded, but there are two > problems - > > 1. It always fails, so I have not reproduced the intermittent nature > yet. > > 2. It gives a different error - > > RuntimeError: dictionary c

Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 23:05:53 +1000, Chris Angelico wrote: > You can always change the *values*, but not the *order* of the keys. Okay, so far we have these operations which are allowed: - changing a value associated with a key and these operations which all raise RuntimeError with the "mutated"

Re: Problem with OrderedDict

2018-05-30 Thread INADA Naoki
> However, the error seems to be intermittent - there are times when it should > fail, but does not - so I want to investigate further. CPython raise RuntimeError *by chance*. Detecting all invalid usage will increase runtime cost. So CPython may and may not raise RuntimeError. > I tried to redu

Re: Problem with OrderedDict

2018-05-30 Thread Chris Angelico
in it >>> forwards to put you in the picture. >>> >>> I have an Ordered Dictionary. Under certain circumstances I am getting >>> this error - >>> >>> RuntimeError: OrderedDict mutated during iteration >> >> This should mean that the va

Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 10:48:06 +0200, Frank Millman wrote: > So my first question is, what is the difference between the two error > messages? I am using an OrderedDict for my test as well, so the > difference is not caused by using a normal dictionary. >From Object/orderd

Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
onary. Under certain circumstances I am getting >> this error - >> >>    RuntimeError: OrderedDict mutated during iteration > > This should mean that the value associated with a key was sometimes > changed. I don't think so. It should be legal to iterate over

Re: Problem with OrderedDict

2018-05-30 Thread Terry Reedy
On 5/30/2018 4:48 AM, Frank Millman wrote: Hi all I want to work backwards to solve this problem, so I have to explain it forwards to put you in the picture. I have an Ordered Dictionary. Under certain circumstances I am getting this error -    RuntimeError: OrderedDict mutated during

Problem with OrderedDict

2018-05-30 Thread Frank Millman
Hi all I want to work backwards to solve this problem, so I have to explain it forwards to put you in the picture. I have an Ordered Dictionary. Under certain circumstances I am getting this error - RuntimeError: OrderedDict mutated during iteration I can see why this is happening, and

Re: OrderedDict with kwds

2017-04-22 Thread Ben Finney
Albert-Jan Roskam writes: > The basic problem is that kwds is a regular, unordered dict […] (Albert, you are probably aware that the above passage is not what you wrote. But your message shows it indistinguishable from your other text. Please teach your email client to compose quoted material u

Re: OrderedDict with kwds

2017-04-22 Thread Ben Finney
INADA Naoki writes: > On Sat, Apr 22, 2017 at 10:41 PM, Ben Finney > wrote: > > So, I would recommend continuing to code as though ‘dict’ is not > > ordered, at least until a Python version is released with a clear > > statement that ordering can be relied upon. > > While dict's order is implem

Re: OrderedDict with kwds

2017-04-22 Thread INADA Naoki
On Sat, Apr 22, 2017 at 10:41 PM, Ben Finney wrote: > INADA Naoki writes: > >> From Python 3.6, keyword arguments are ordered. So the docstring is >> outdated. > > (Thank you, Inada-san, for the implementation!) > > The announcement of the change specifies that we should not rely on > ordered ‘di

Re: OrderedDict with kwds

2017-04-22 Thread Albert-Jan Roskam
From: eryk sun Sent: Saturday, April 22, 2017 7:59 AM To: Python Main Cc: Albert-Jan Roskam Subject: Re: OrderedDict with kwds   On Fri, Apr 21, 2017 at 6:08 PM, Albert-Jan Roskam wrote: > Would the insertion order be preserved if the last line were to be > replaced with: >

Re: OrderedDict with kwds

2017-04-22 Thread Ben Finney
INADA Naoki writes: > From Python 3.6, keyword arguments are ordered. So the docstring is > outdated. (Thank you, Inada-san, for the implementation!) The announcement of the change specifies that we should not rely on ordered ‘dict’: The order-preserving aspect of this new implementation i

Re: OrderedDict with kwds

2017-04-22 Thread Peter Otten
Albert-Jan Roskam wrote: > For regular dicts I like to use the dict() function because the code is > easier to write and read. But OrderedDict() is not equivalent to dict(): > In the docstring of collections.OrderedDict it says "keyword arguments are > not recommended becaus

Re: OrderedDict with kwds

2017-04-22 Thread INADA Naoki
On Sat, Apr 22, 2017 at 3:08 AM, Albert-Jan Roskam wrote: > For regular dicts I like to use the dict() function because the code is > easier to write and read. But OrderedDict() is not equivalent to dict(): > In the docstring of collections.OrderedDict it says "keyword argume

Re: OrderedDict with kwds

2017-04-22 Thread eryk sun
On Fri, Apr 21, 2017 at 6:08 PM, Albert-Jan Roskam wrote: > Would the insertion order be preserved if the last line were to be > replaced with: > > if kwds: > for k, v in kwds.items(): > self[k] = v > if args: > self.__update(*args) # no **kwds! The basic problem is that kwds is

OrderedDict with kwds

2017-04-22 Thread Albert-Jan Roskam
For regular dicts I like to use the dict() function because the code is easier to write and read. But OrderedDict() is not equivalent to dict(): In the docstring of collections.OrderedDict it says "keyword arguments are not recommended because their insertion order is arbitrary&quo

Re: OrderedDict

2016-06-09 Thread silver0346
18:44.0 +0200 > > >> +++ py2_xmltodict/local/lib/python2.7/site-packages/xmltodict.py > > >> 2016-05-18 11:11:13.417665697 +0200 @@ -35,6 +35,13 @@ > > >> __version__ = '0.10.1' > > >> __license__ = 'MIT' > > &g

Re: OrderedDict

2016-05-19 Thread silver0346
11:11:13.417665697 +0200 @@ -35,6 +35,13 @@ > >> __version__ = '0.10.1' > >> __license__ = 'MIT' > >> > >> +_OrderedDict = OrderedDict > >> +class OrderedDict(_OrderedDict): > >> +def __getitem__(self, key): > >

Re: OrderedDict

2016-05-18 Thread Peter Otten
ages/xmltodict.py >> 2016-05-18 11:18:44.0 +0200 >> +++ py2_xmltodict/local/lib/python2.7/site-packages/xmltodict.py >> 2016-05-18 11:11:13.417665697 +0200 @@ -35,6 +35,13 @@ >> __version__ = '0.10.1' >> __license__ = 'MIT' >> >

Re: OrderedDict

2016-05-18 Thread Chris Angelico
gt; +++ py2_xmltodict/local/lib/python2.7/site-packages/xmltodict.py > 2016-05-18 11:11:13.417665697 +0200 > @@ -35,6 +35,13 @@ > __version__ = '0.10.1' > __license__ = 'MIT' > > +_OrderedDict = OrderedDict > +class OrderedDict(_OrderedDict):

Re: OrderedDict

2016-05-18 Thread Peter Otten
s __fd: > __doc = xmltodict.parse(__fd.read()) > > __doc > > I get > > OrderedDict([(u'profiles', OrderedDict([(u'profile', OrderedDict([(u'@id', > u'visio02'), (u'@revision', u'2015051501'), (u'pack

Re: OrderedDict

2016-05-18 Thread Chris Angelico
On Wed, May 18, 2016 at 6:32 PM, wrote: > Hi all, > > I have a understanding problem with return values from xmltodict. > > I have a xml file. Content: > > > > > > > > > > > > > > > > > No prints __doc['profiles']['profile']['package'][0]['@package-id']: > > u'0964-gpg4

OrderedDict

2016-05-18 Thread silver0346
Hi all, I have a understanding problem with return values from xmltodict. I have a xml file. Content: With code __f_name = '' with open(__f_name) as __fd: __doc = xmltodict.parse(__fd.read()) __doc I get OrderedDict([(u'profiles', OrderedDict([(u&#

Re: OrderedDict / DIctComprehension

2012-10-29 Thread Christian
Too bad that's not (using python2.7) 'ordered_dict_generator' ((), {}) 1.089588 sec Anyway thanks for your hint! > Hi, > > > > is there a way building an OrderedDict faster? > > > > Thanks in advance > > Christian > > > >

Re: OrderedDict / DIctComprehension

2012-10-29 Thread Terry Reedy
On 10/29/2012 8:36 AM, Christian wrote: Hi, is there a way building an OrderedDict faster? Thanks in advance Christian @timeit def ordered(n=10): d = OrderedDict() for i in xrange(n): d['key'+str(i)] = i return d try d = OrderedDict(['key

OrderedDict / DIctComprehension

2012-10-29 Thread Christian
Hi, is there a way building an OrderedDict faster? Thanks in advance Christian @timeit def ordered(n=10): d = OrderedDict() for i in xrange(n): d['key'+str(i)] = i return d @timeit def comprehension(n=10): d = { 'key'+str(i):i for i in xran

Re: Inheriting from OrderedDict causes problem

2012-02-22 Thread Bruce Eckel
On Feb 22, 10:10 am, Peter Otten <__pete...@web.de> wrote: > Looks like invoking OrderedDict.__init__() is necessary: > > >>> from collections import OrderedDict > >>> class X(OrderedDict): > > ...     def __init__(self, stuff): > ...             supe

Re: Inheriting from OrderedDict causes problem

2012-02-22 Thread Peter Otten
Bruce Eckel wrote: > Notice that both classes are identical, except that one inherits from > dict (and works) and the other inherits from OrderedDict and fails. > Has anyone seen this before? Thanks. > > import collections > > class Y(dict): > def __init__(self, st

Inheriting from OrderedDict causes problem

2012-02-22 Thread Bruce Eckel
Notice that both classes are identical, except that one inherits from dict (and works) and the other inherits from OrderedDict and fails. Has anyone seen this before? Thanks. import collections class Y(dict): def __init__(self, stuff): for k, v in stuff: self[k] = v

Re: replacing __dict__ with an OrderedDict

2012-01-18 Thread Ulrich Eckhardt
Am 06.01.2012 12:44, schrieb Peter Otten: [running unit tests in the order of their definition] class Loader(unittest.TestLoader): def getTestCaseNames(self, testCaseClass): """Return a sequence of method names found within testCaseClass sorted by co_firstlineno. "

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Roy Smith
In article , Lie Ryan wrote: > >> All serious database has rollback feature when they're available to > >> quickly revert database state in the setUp/cleanUp phase. > > > > I guess MongoDB is not a serious database? > > I guess there are always those oddball cases, but if you choose MongoDB >

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Ulrich Eckhardt
Am 10.01.2012 13:31, schrieb Lie Ryan: While it is possible to replace __dict__ with OrderedDict and it is possible to reorder the test, those are not his original problem, and the optimal solution to his original problem differs from the optimal solution to what he think he will need. Oh, and

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Tim Wintle
On Tue, 2012-01-10 at 09:05 -0500, Roy Smith wrote: > > I guess MongoDB is not a serious database? That's opening up a can of worms ;) ... anyway, cassandra is far better. Tim -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Lie Ryan
On 01/11/2012 01:05 AM, Roy Smith wrote: In article, Lie Ryan wrote: On 01/10/2012 12:05 PM, Roy Smith wrote: Somewhat more seriously, let's say you wanted to do test queries against a database with 100 million records in it. You could rebuild the database from scratch for each test, but d

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Roy Smith
In article , Lie Ryan wrote: > On 01/10/2012 12:05 PM, Roy Smith wrote: > > Somewhat more seriously, let's say you wanted to do test queries against > > a database with 100 million records in it. You could rebuild the > > database from scratch for each test, but doing so might take hours per >

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Lie Ryan
On 01/10/2012 03:59 AM, Ulrich Eckhardt wrote: There is another dependency and that I'd call a logical dependency. This occurs when e.g. test X tests for an API presence and test Y tests the API behaviour. In other words, Y has no chance to succeed if X already failed. Unfortunately, there is n

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Lie Ryan
certain way to make debugging easier, to quote the OP: """ ... I just want to take the first test that fails and analyse that instead of guessing the point to start debugging from the N failed tests. """ and then he goes on concluding that he need to reorde

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Lie Ryan
On 01/10/2012 12:05 PM, Roy Smith wrote: Somewhat more seriously, let's say you wanted to do test queries against a database with 100 million records in it. You could rebuild the database from scratch for each test, but doing so might take hours per test. Sometimes, real life is just*so* incon

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Terry Reedy
On 1/9/2012 8:05 PM, Roy Smith wrote: In article<11jrt8-l32@satorlaser.homedns.org>, Ulrich Eckhardt wrote: Some people advocate that the test framework should intentionally randomize the order, to flush out inter-test dependencies that the author didn't realize existed (or intend). If

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Roy Smith
In article <11jrt8-l32@satorlaser.homedns.org>, Ulrich Eckhardt wrote: > > Some people advocate that the test framework should > > intentionally randomize the order, to flush out inter-test dependencies > > that the author didn't realize existed (or intend). > > If you now > happen to infl

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ian Kelly
On Mon, Jan 9, 2012 at 9:59 AM, Ulrich Eckhardt wrote: > There is another dependency and that I'd call a logical dependency. This > occurs when e.g. test X tests for an API presence and test Y tests the API > behaviour. In other words, Y has no chance to succeed if X already failed. > Unfortunatel

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ulrich Eckhardt
Am 09.01.2012 15:35, schrieb Roy Smith: The classic unittest philosophy says that tests should be independent of each other, which means they should be able to be run in arbitrary order. Some people advocate that the test framework should intentionally randomize the order, to flush out inter-tes

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Neil Cerutti
On 2012-01-09, Roy Smith wrote: > If somebody (i.e. the classic "consenting adult" of the Python > world) wants to take advantage of that to write a test suite > where the tests *do* depend on each other, and have to be run > in a certain order, there's nothing wrong with that. As long > as they

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Roy Smith
In article , Ian Kelly wrote: > Randomizing the order is not a bad idea, but you also need to be able > to run the tests in a consistent order, from a specific random seed. > In the real world, test conflicts and dependencies do happen, and if > we observe a failure, make a change, rerun the tes

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ulrich Eckhardt
Am 09.01.2012 13:10, schrieb Lie Ryan: I was just suggesting that what the OP thinks he wants is quite likely not what he actually wants. Rest assured that the OP has a rather good idea of what he wants and why, the latter being something you don't know, because he never bothered to explain

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Lie Ryan
On 01/09/2012 09:03 AM, Eelco wrote: i havnt read every post in great detail, but it doesnt seem like your actual question has been answered, so ill give it a try. AFAIK, changing __dict__ to be an ordereddict is fundamentally impossible in python 2. __dict__ is a builtin language construct

Re: replacing __dict__ with an OrderedDict

2012-01-08 Thread alex23
On Jan 7, 2:06 am, Ian Kelly wrote: > wrote: > > Nonetheless, I'm still wondering if I could somehow replace the dict with an > > OrderedDict. > > In Python 3, yes.  This is pretty much the entire use case for the new > __prepare__ method of metaclasses.  S

Re: Using an OrderedDict for __dict__ in Python 3 using __prepare__

2012-01-08 Thread Christian Heimes
Am 09.01.2012 03:21, schrieb Steven D'Aprano: > What am I doing wrong? You aren't doing anything wrong. It's just not possible to have something different than a dict as a type's __dict__. It's a deliberate limitation and required optimization. The __prepare__ hook allows to you have a dict subcla

Using an OrderedDict for __dict__ in Python 3 using __prepare__

2012-01-08 Thread Steven D'Aprano
I'm using Python 3.1 and trying to create a class using an OrderedDict as its __dict__, but it isn't working as I expect. See http://www.python.org/dev/peps/pep-3115/ for further details. Here is my code: from collections import OrderedDict # The metaclass class Ordered

Re: replacing __dict__ with an OrderedDict

2012-01-08 Thread Eelco
i havnt read every post in great detail, but it doesnt seem like your actual question has been answered, so ill give it a try. AFAIK, changing __dict__ to be an ordereddict is fundamentally impossible in python 2. __dict__ is a builtin language construct hardcoded into the C API. There is no way

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ian Kelly
On Fri, Jan 6, 2012 at 5:49 PM, Steven D'Aprano wrote: > In the real world, test conflicts and dependencies are bugs in your test > suite that should be fixed, like any other bug in code. The fact that it > is test code that is failing is irrelevant. I agree 100%, but none of that changes my poin

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Lie Ryan
On 01/07/2012 11:49 AM, Steven D'Aprano wrote: You may not be able to run tests*simultaneously*, due to clashes involving external resources, but you should be able to run them in random order. tests that involves external resources should be mocked, although there are always a few external re

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Steven D'Aprano
On Fri, 06 Jan 2012 10:20:28 -0700, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 10:01 AM, Lie Ryan wrote: >> That unittest executes its tests in alphabetical order is >> implementation detail for a very good reason, and good unittest >> practice dictates that execution order should never be defined

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Steven D'Aprano
On Sat, 07 Jan 2012 04:01:44 +1100, Lie Ryan wrote: > On 01/07/2012 12:36 AM, Ulrich Eckhardt wrote: >> True, perhaps, but doing it this way would be more fun and easier >> reusable in other cases where the default order is not desirable. I can >> also go and name the test functions test_000 to te

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Arnaud Delobelle
ndering if I could somehow replace the dict with an > OrderedDict. No, you can't. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Arnaud Delobelle
On 6 January 2012 11:44, Peter Otten <__pete...@web.de> wrote: > class Loader(unittest.TestLoader): >    def getTestCaseNames(self, testCaseClass): >        """Return a sequence of method names found within testCaseClass >        sorted by co_firstlineno. >        """ That's a clever trick! -- A

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Lie Ryan
On 01/07/2012 04:20 AM, Ian Kelly wrote: On Fri, Jan 6, 2012 at 10:01 AM, Lie Ryan wrote: That unittest executes its tests in alphabetical order is implementation detail for a very good reason, and good unittest practice dictates that execution order should never be defined (some even argued th

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ian Kelly
On Fri, Jan 6, 2012 at 10:01 AM, Lie Ryan wrote: > That unittest executes its tests in alphabetical order is implementation > detail for a very good reason, and good unittest practice dictates that > execution order should never be defined (some even argued that the execution > order should be ran

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Lie Ryan
On 01/07/2012 12:36 AM, Ulrich Eckhardt wrote: Am 06.01.2012 12:43, schrieb Lie Ryan: On 01/06/2012 08:48 PM, Ulrich Eckhardt wrote: Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the orde

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ian Kelly
On Fri, Jan 6, 2012 at 9:06 AM, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 6:40 AM, Ulrich Eckhardt > wrote: >> Nonetheless, I'm still wondering if I could somehow replace the dict with an >> OrderedDict. > > In Python 3, yes.  This is pretty much the entire use c

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ian Kelly
On Fri, Jan 6, 2012 at 6:40 AM, Ulrich Eckhardt wrote: > Nonetheless, I'm still wondering if I could somehow replace the dict with an > OrderedDict. In Python 3, yes. This is pretty much the entire use case for the new __prepare__ method of metaclasses. See the "OrderedClass&q

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ethan Furman
Ulrich Eckhardt wrote: Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the order of their declaration. This in turn should hopefully make unittest execute my tests in the order of their d

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ulrich Eckhardt
Am 06.01.2012 12:44, schrieb Peter Otten: Alternatively you can write your own test loader: [...CODE...] Well, actually you just did that for me and it works! ;) Nonetheless, I'm still wondering if I could somehow replace the dict with an OrderedDict. Thank you! Uli --

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ulrich Eckhardt
Am 06.01.2012 12:43, schrieb Lie Ryan: On 01/06/2012 08:48 PM, Ulrich Eckhardt wrote: Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the order of their declaration. This in turn should hope

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Peter Otten
Ulrich Eckhardt wrote: > The topic explains pretty much what I'm trying to do under Python > 2.7[1]. The reason for this is that I want dir(SomeType) to show the > attributes in the order of their declaration. This in turn should > hopefully make unittest execute my tests in the order of their > d

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Lie Ryan
On 01/06/2012 08:48 PM, Ulrich Eckhardt wrote: Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the order of their declaration. This in turn should hopefully make unittest execute my tests in

replacing __dict__ with an OrderedDict

2012-01-06 Thread Ulrich Eckhardt
Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the order of their declaration. This in turn should hopefully make unittest execute my tests in the order of their declaration[2], so that t

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
code should I be this > careful? For the standard library, it pays to really think out the corner cases because you never know what people are going to rely on. The Liskov substitution principle asks us to make OrderedDict behave as much like dict as possible (so that OD's can be used a

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread andrew cooke
Is that normal? I mean, OK, it's possible (and yes I forgot it could be called directly), but is there any usual reason to do so? I guess what I'm asking is: if I'm writing library code should I be this careful? (I've written quite a lot of Python code without this ever biting me, but maybe

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
od will only be > called when the object is first being created, so __root will always be > missing. First of all, three cheers for reading the source code! A user can call __init__() even after the OrderedDict instance has already been created. If so, the __root attribute will alread

Why is __root checked for in OrderedDict?

2011-04-07 Thread andrew cooke
If you look at the code in http://hg.python.org/cpython/file/6adbf5f3dafb/Lib/collections/__init__.py#l49 the attribute __root is checked for, and only created if missing. Why? I ask because, from what I understand, the __init__ method will only be called when the object is first being created

Re: Is there a OrderedDict which can perform an iteritems() in order?

2010-11-04 Thread Vlastimil Brom
only perform items() in order, but iteritems()... >      Would you help me here? > songjian > ... Hi, it seems the standard library implementation in collections (OrderedDict) has the iteritems() method (checked on python 2.7). Does it not work the way you need? hth, vbr -- http://mail.

Is there a OrderedDict which can perform an iteritems() in order?

2010-11-04 Thread Jo Chan
Hello all, I have working on a program which need a ordered dictionary that could perform iteritems() sequentially. I found a package on : http://www.voidspace.org.uk/python/odict.html#creating-an-ordered-dictionary

Re: Python 3: Plist as OrderedDict

2010-02-09 Thread Stephen Hansen
On Tue, Feb 9, 2010 at 8:07 AM, Gnarlodious wrote: > To extract the list I am saying this: > > ordered=plistlib.readPlist(path) > print(list(ordered)) # only a list of keys > print(ordered[list(ordered)[0]]) > > However this seems too laborious. is there an easier way? > I'm not familiar with p

Re: Python 3: Plist as OrderedDict

2010-02-09 Thread Gnarlodious
On Feb 9, 12:15 am, Raymond Hettinger wrote: > You may be able to monkey patch an OrderedDict into the PlistParser. > Here's an untested stab at it: >     from collections import OrderedDict >     import plistlib >     plistlib._InteralDict = OrderedDict Genius! After f

Re: Python 3: Plist as OrderedDict

2010-02-09 Thread Gnarlodious
On Feb 9, 12:15 am, Raymond Hettinger wrote: > You may be able to monkey patch an OrderedDict into the PlistParser. > Here's an untested stab at it: > >     from collections import OrderedDict >     import plistlib >     plistlib._InteralDict = OrderedDict Genius! Afte

Re: Python 3: Plist as OrderedDict

2010-02-08 Thread Raymond Hettinger
On Feb 8, 8:02 pm, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: ... > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... You may be abl

Re: Python 3: Plist as OrderedDict

2010-02-08 Thread Ned Deily
In article , Terry Reedy wrote: > On 2/8/2010 11:02 PM, Gnarlodious wrote: > > I am trying to read a *.plist into Python 3's OrderedDict but can't > > figure it out. Saying something like this: > > from plistlib import readPlist > As a general note, include a l

Re: Python 3: Plist as OrderedDict

2010-02-08 Thread Terry Reedy
On 2/8/2010 11:02 PM, Gnarlodious wrote: I am trying to read a *.plist into Python 3's OrderedDict but can't figure it out. Saying something like this: from plistlib import readPlist As a general note, include a link or something when discussing a relatively obscure module that se

Re: Python 3: Plist as OrderedDict

2010-02-08 Thread Benjamin Kaplan
On Mon, Feb 8, 2010 at 11:02 PM, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: > > from plistlib import readPlist > dict=readPlist('/path/file.plist') > --> arbitrari

Re: Python 3: Plist as OrderedDict

2010-02-08 Thread Ben Finney
le order. >>> foo = dict( ... [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]) >>> foo {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} > from collections import Or

Python 3: Plist as OrderedDict

2010-02-08 Thread Gnarlodious
I am trying to read a *.plist into Python 3's OrderedDict but can't figure it out. Saying something like this: from plistlib import readPlist dict=readPlist('/path/file.plist') --> arbitrarily ordered dictionary compared to the XML file from collections import OrderedDic

Re: FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you

2009-11-20 Thread Scott David Daniels
Jonathan Fine wrote:... A big thanks to Armin Ronacher and Raymond Hettinger for PEP 372: Adding an ordered dictionary to collections ... I prototyped (in about an hour). I then thought - maybe someone has been down this path before So all that I want has been done already, and will be

FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you

2009-11-17 Thread Jonathan Fine
Hi A big thanks to Armin Ronacher and Raymond Hettinger for PEP 372: Adding an ordered dictionary to collections I'm using ConfigParser and I just assumed that the options in a section were returned in the order they were given. In fact, I relied on this fact. http://docs.python.org/li