Overriding property types on instances from a library

2021-02-20 Thread Joseph L. Casale
I have some code that makes use of the typing module. This code creates several instances of objects it creates from a library that has some issues. For example, I have multiple list comps that iterate properties of those instance and the type checker fails with: Expected type

Re: Are instances of user-defined classes mutable?

2020-08-07 Thread Richard Damon
On 8/6/20 10:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? > Or the description of "if a tuple contains any mutable object either > directly or indirectly, it cannot be used as a key." in the document > is not completely corr

Re: Are instances of user-defined classes mutable?

2020-08-07 Thread Mats Wichmann
On 8/6/20 8:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? No, they're clealry mutable. > Or the description of "if a tuple contains any mutable object either directly > or indirectly, it cannot be used as a key."

Re:Re: Are instances of user-defined classes mutable?

2020-08-06 Thread ZHAOWANCHENG
me = mycls() >>> >>> me.a = 2 # mutable? >>> >>> {(1, me): 'mycls'} >>> {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> >>> >>> >>> >>> So are

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread David Lowry-Duda
aced into a tuple that as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x000

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Richard Damon
): 'mycls'} >> {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >> >>> >> >> >> So are instances of user-defined classes mutable or immutable? >> > user class instances are clearly mutable, and in my python

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Ethan Furman
On 8/6/20 7:40 AM, Robin Becker wrote: On 06/08/2020 05:17, ZHAOWANCHENG wrote: So are instances of user-defined classes mutable or immutable? user class instances are clearly mutable, and in my python 3.8 you can do horrid things like this > > [snip buggy/incorrect uses of __hash__

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Richard Damon
hat as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x022824DAD668>):

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Robin Becker
of a dict: >>> class mycls(object): ... a = 1 ... >>> me = mycls() >>> me.a = 2 # mutable? >>> {(1, me): 'mycls'} {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> So are i

Are instances of user-defined classes mutable?

2020-08-06 Thread ZHAOWANCHENG
: ... a = 1 ... >>> me = mycls() >>> me.a = 2 # mutable? >>> {(1, me): 'mycls'} {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> So are instances of user-defined classes mutable or immutable? -- https://mail.python.org/mailman/listinfo/python-list

Re: How to use multiple instances of the same COM object at the same time

2018-12-18 Thread h . kheti . serpentcs
w to use them. > Now, I need to connect to every device separately and register for real > time events. So, I need about 40 instances of the COM object > simultaneously connected and registered to catch all events of all devices. > > I assumed I needed threading for this, and

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Bill
Bill wrote: validationma...@gmail.com wrote: i have a code in python to search and replace what i need though is to replace the first say 10 instances of the number 1 with 2 and the second 10 instances with the number 3. anybody knows how to do that? Do you mean the (integer) number 1 or the

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Peter Otten
Peter Otten wrote: > validationma...@gmail.com wrote: > >> i have a code in python to search and replace what i need though is to >> replace the first say 10 instances of the number 1 with 2 and the second >> 10 instances with the number 3. anybody knows how to do that?

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Bill
validationma...@gmail.com wrote: i have a code in python to search and replace what i need though is to replace the first say 10 instances of the number 1 with 2 and the second 10 instances with the number 3. anybody knows how to do that? Do you mean the (integer) number 1 or the character &#

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Peter Otten
validationma...@gmail.com wrote: > i have a code in python to search and replace what i need though is to > replace the first say 10 instances of the number 1 with 2 and the second > 10 instances with the number 3. anybody knows how to do that? > > fin = open(r'F:\1\xxx.txt

search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-22 Thread validationmail1
i have a code in python to search and replace what i need though is to replace the first say 10 instances of the number 1 with 2 and the second 10 instances with the number 3. anybody knows how to do that? fin = open(r'F:\1\xxx.txt') fout = open(r'F:\1\xxx2.txt', &

Re: can't add variables to instances of built-in classes

2016-08-04 Thread Lawrence D’Oliveiro
On Thursday, August 4, 2016 at 3:07:17 PM UTC+12, Chris Angelico wrote: > On Thu, Aug 4, 2016 at 12:34 PM, Lawrence D’Oliveiro wrote: >> On Thursday, July 21, 2016 at 2:29:53 PM UTC+12, Chris Angelico wrote: >> >>> Using __slots__ basically takes your object down to the level of a >>> Java one. >>

Re: can't add variables to instances of built-in classes

2016-08-03 Thread Chris Angelico
On Thu, Aug 4, 2016 at 12:34 PM, Lawrence D’Oliveiro wrote: > On Thursday, July 21, 2016 at 2:29:53 PM UTC+12, Chris Angelico wrote: > >> Using __slots__ basically takes your object down to the level of a >> Java one. > > Is Java like a bogeyman you use to scare people with if they don’t write >

Re: can't add variables to instances of built-in classes

2016-08-03 Thread Lawrence D’Oliveiro
On Thursday, July 21, 2016 at 2:29:53 PM UTC+12, Chris Angelico wrote: > Using __slots__ basically takes your object down to the level of a > Java one. Is Java like a bogeyman you use to scare people with if they don’t write Python code the way you like it? -- https://mail.python.org/mailman/li

Re: can't add variables to instances of built-in classes

2016-07-21 Thread Peter Otten
breamore...@gmail.com wrote: > I hereby request that the moderators take this idiot offline as he's Mark, please behave yourself. -- https://mail.python.org/mailman/listinfo/python-list

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Steven D'Aprano
On Thu, 21 Jul 2016 08:11 am, Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 9:16:30 PM UTC+12, Peter Otten wrote: >> >> Lawrence D’Oliveiro wrote: >> >>> On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote: >>> pylint can detect candidates for accidental attrib

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Chris Angelico
On Thu, Jul 21, 2016 at 8:11 AM, Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 9:16:30 PM UTC+12, Peter Otten wrote: >> >> Lawrence D’Oliveiro wrote: >> >>> On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote: >>> pylint can detect candidates for accidental attri

Re: can't add variables to instances of built-in classes

2016-07-20 Thread breamoreboy
On Wednesday, July 20, 2016 at 10:48:23 PM UTC+1, Lawrence D’Oliveiro wrote: > On Thursday, July 21, 2016 at 12:11:09 AM UTC+12, Steven D'Aprano wrote: > > > [long irrelevant rant deleted] > > Just because I pointed out what a load of nonsense you were spouting about > __slots__, by giving a cou

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Lawrence D’Oliveiro
On Wednesday, July 20, 2016 at 9:16:30 PM UTC+12, Peter Otten wrote: > > Lawrence D’Oliveiro wrote: > >> On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote: >> >>> pylint can detect candidates for accidental attribute creation: >> >> And __slots__ will prevent them outright. >

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Lawrence D’Oliveiro
On Thursday, July 21, 2016 at 12:11:09 AM UTC+12, Steven D'Aprano wrote: > [long irrelevant rant deleted] Just because I pointed out what a load of nonsense you were spouting about __slots__, by giving a counterexample of their usefulness? Man, your pride must be hurt... -- https://mail.python

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Steven D'Aprano
On Wed, 20 Jul 2016 06:50 pm, Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote: > >> pylint can detect candidates for accidental attribute creation: > > And __slots__ will prevent them outright. As well as those added intentionally. Sometimes I

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote: > >> pylint can detect candidates for accidental attribute creation: > > And __slots__ will prevent them outright. And attributes added intentionally. -- https://mail.python.org/mailman/listinfo/

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Lawrence D’Oliveiro
On Tuesday, July 19, 2016 at 9:48:15 AM UTC+12, I wrote: > When you have lots of read/write properties, I find __slots__ to be a good > idea. Let me amend that. When you have *any* read/write properties, I find __slots__ to be a good idea. -- https://mail.python.org/mailman/listinfo/python-list

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Lawrence D’Oliveiro
On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote: > pylint can detect candidates for accidental attribute creation: And __slots__ will prevent them outright. -- https://mail.python.org/mailman/listinfo/python-list

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 6:19:45 PM UTC+12, Chris Angelico wrote: >> >> On Wed, Jul 20, 2016 at 9:58 AM, Lawrence D’Oliveiro wrote: >>> >>> On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream...@gmail.com >>> wrote: On Tuesday, July 19, 2016 at 3:54

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Steven D'Aprano
On Wednesday 20 July 2016 16:45, Lawrence D’Oliveiro wrote: > I was trying something like > > ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) > > and wondering why it wasn’t working... And so are we. Since you've already solved the problem, maybe you could enlighten us? T

Re: can't add variables to instances of built-in classes

2016-07-19 Thread Lawrence D’Oliveiro
On Wednesday, July 20, 2016 at 6:19:45 PM UTC+12, Chris Angelico wrote: > > On Wed, Jul 20, 2016 at 9:58 AM, Lawrence D’Oliveiro wrote: >> >> On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream...@gmail.com wrote: >>> >>> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D’Oliveiro wrote:

Re: can't add variables to instances of built-in classes

2016-07-19 Thread Chris Angelico
On Wed, Jul 20, 2016 at 9:58 AM, Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream...@gmail.com wrote: >> >> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D’Oliveiro wrote: >>> >>> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream...@gmail.com wrot

Re: can't add variables to instances of built-in classes

2016-07-19 Thread Lawrence D’Oliveiro
On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream...@gmail.com wrote: > > On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D’Oliveiro wrote: >> >> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream...@gmail.com wrote: >>> >>> On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence

Re: can't add variables to instances of built-in classes

2016-07-19 Thread breamoreboy
On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D’Oliveiro wrote: > On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream...@gmail.com wrote: > > > > On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D’Oliveiro wrote: > >> > >> > >> When you have lots

Re: can't add variables to instances of built-in classes

2016-07-18 Thread Lawrence D’Oliveiro
On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream...@gmail.com wrote: > > On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D’Oliveiro wrote: >> >> >> When you have lots of read/write properties, I find __slots__ to be a good >> idea. > > Please explain

Re: can't add variables to instances of built-in classes

2016-07-18 Thread Lawrence D’Oliveiro
On Monday, July 18, 2016 at 7:39:09 PM UTC+12, Peter Otten wrote: > Lawrence D’Oliveiro wrote: > >> I find __slots__ very useful. I have them right through my Qahirah classes >> , for example. > > Or is there something I didn't think of that makes them useful for y

Re: can't add variables to instances of built-in classes

2016-07-18 Thread Ethan Furman
On 07/17/2016 04:50 AM, Wilson Ong wrote: Use this feature sparingly, only when you know that there are going to be many (millions rather than thousands) of Test instances. Why use it sparingly? Is it for extensibility? What if I'm pretty sure that my class is going to have exactly

Re: can't add variables to instances of built-in classes

2016-07-18 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Monday, July 18, 2016 at 3:04:13 AM UTC+12, Steven D'Aprano wrote: > >> __slots__ is not obsolete, but 99% of the time you shouldn't bother with >> it. > > I find __slots__ very useful. I have them right through my Qahirah classes >

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Lawrence D’Oliveiro
On Monday, July 18, 2016 at 3:04:13 AM UTC+12, Steven D'Aprano wrote: > __slots__ is not obsolete, but 99% of the time you shouldn't bother with it. I find __slots__ very useful. I have them right through my Qahirah classes , for example. -- https://mail.python.o

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Steven D'Aprano
On Sun, 17 Jul 2016 09:50 pm, Wilson Ong wrote: > >> Use this feature sparingly, only when you know that there are going to be >> many (millions rather than thousands) of Test instances. > > Why use it sparingly? Is it for extensibility? What if I'm pretty sure > t

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Chris Angelico
On Sun, Jul 17, 2016 at 9:50 PM, Wilson Ong wrote: >> Use this feature sparingly, only when you know that there are going to be >> many (millions rather than thousands) of Test instances. > > Why use it sparingly? Is it for extensibility? What if I'm pretty sure that >

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Kent Tong
Hi Peter, Thanks a lot for your excellent explanation! -- https://mail.python.org/mailman/listinfo/python-list

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Wilson Ong
> Use this feature sparingly, only when you know that there are going to be > many (millions rather than thousands) of Test instances. Why use it sparingly? Is it for extensibility? What if I'm pretty sure that my class is going to have exactly these attributes only

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Peter Otten
Kent Tong wrote: > Hi, > > I can add new variables to user-defined classes like: > >>>> class Test: > ... pass > ... >>>> a=Test() >>>> a.x=100 > > but it doesn't work if the instances belong to a built-in class such as >

can't add variables to instances of built-in classes

2016-07-17 Thread Kent Tong
Hi, I can add new variables to user-defined classes like: >>> class Test: ... pass ... >>> a=Test() >>> a.x=100 but it doesn't work if the instances belong to a built-in class such as str or list: >>> a='abc' >>> a.x=10

Re: __main__ vs official module name: distinct module instances

2015-08-04 Thread Jonas Wielicki
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On 02.08.2015 05:53, Cameron Simpson wrote: > When invoked this way, the module cs.app.maildb that is being > executed is actually the module named "__main__". If some other > piece of code imports "cs.app.maildb" they get a _different_ > instance

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Cameron Simpson
On 02Aug2015 18:18, Chris Angelico wrote: On Sun, Aug 2, 2015 at 6:16 PM, Chris Angelico wrote: On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano wrote: * if you don't wish to do that, you're screwed, and I think that the best you can do is program defensively by detecting the problem afte

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Cameron Simpson
On 02Aug2015 17:41, Steven D'Aprano wrote: On Sun, 2 Aug 2015 01:53 pm, Cameron Simpson wrote: Maybe this should be over in python-ideas, since there is a proposal down the bottom of this message. But first the background... I've just wasted a silly amount of time debugging an issue that reall

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Chris Angelico
On Sun, Aug 2, 2015 at 6:16 PM, Chris Angelico wrote: > On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano wrote: >> * if you don't wish to do that, you're screwed, and I think that the >> best you can do is program defensively by detecting the problem >> after the event and bailing out: >> >>

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Chris Angelico
On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano wrote: > * if you don't wish to do that, you're screwed, and I think that the > best you can do is program defensively by detecting the problem > after the event and bailing out: > > # untested > import __main__ > import myactualfilename >

Re: __main__ vs official module name: distinct module instances

2015-08-02 Thread Steven D'Aprano
On Sun, 2 Aug 2015 01:53 pm, Cameron Simpson wrote: > Hi All, > > Maybe this should be over in python-ideas, since there is a proposal down > the bottom of this message. But first the background... > > I've just wasted a silly amount of time debugging an issue that really I > know about, but had

Re: __main__ vs official module name: distinct module instances

2015-08-01 Thread Chris Angelico
nfusion when the module is invoked from the python > command line and also imported by the code; it is not intuitive that those > two things give you distinct module instances. > > Aside from the module's .__name__ being '__main__' even when accessed by the > code as cs.a

__main__ vs official module name: distinct module instances

2015-08-01 Thread Cameron Simpson
rt the standard boilerplate. This would save some confusion when the module is invoked from the python command line and also imported by the code; it is not intuitive that those two things give you distinct module instances. Aside from the module's .__name__ being '__main__' even

Re: Storing instances using jsonpickle

2014-09-15 Thread Josh English
N-able > data structure (dict of lists, whatever) into your object. Often a > version number is a good idea so that you have some chance of using old > data as your code changes. > Right now my cheap workaround is to define a function that saves the instances __dict__ using json,

Re: Storing instances using jsonpickle

2014-09-06 Thread Terry Reedy
On 9/6/2014 12:32 PM, MRAB wrote: On 2014-09-06 01:20, Chris Angelico wrote: On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: JSON has 'true' and 'false'. Python has 'True' and 'False'. Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (W

Re: Storing instances using jsonpickle

2014-09-06 Thread Ned Batchelder
On 9/6/14 12:32 PM, MRAB wrote: On 2014-09-06 01:20, Chris Angelico wrote: On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: JSON has 'true' and 'false'. Python has 'True' and 'False'. Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (Wel

Re: Storing instances using jsonpickle

2014-09-06 Thread MRAB
On 2014-09-06 01:20, Chris Angelico wrote: On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: JSON has 'true' and 'false'. Python has 'True' and 'False'. Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (Well, not unless you define 'true' a

Re: Storing instances using jsonpickle

2014-09-05 Thread Chris Angelico
On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: > JSON has 'true' and 'false'. > > Python has 'True' and 'False'. > > Therefore, if you want it to be able to drop it into Python's REPL, it > won't be compatible with JSON anyway! (Well, not unless you define > 'true' and 'false' first.) This is a new

Re: Storing instances using jsonpickle

2014-09-05 Thread Irmen de Jong
On 5-9-2014 19:16, Marko Rauhamaa wrote: > Thus, ast.literal_eval() is superior to anything JSON has to offer. Incidentally, I've made a serialization library based on Python's literal expressions. It uses ast.literal_eval() to deserialize, and a bit of custom code to serialize Python objects:

Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
Ned Batchelder : > I see what you mean about JSON, but you are mistaken about HTTP and > XML. Neither of them dictates the encoding of the data, and both of > them offer ways to declare the encoding. This means XML parsers must > be prepared for many different encodings. You can rest assured that

Re: Storing instances using jsonpickle

2014-09-05 Thread Ned Batchelder
On 9/5/14 2:04 PM, Marko Rauhamaa wrote: Ned Batchelder : I don't understand how JSON has flopped? The parser may be a bit more complex (but not much, it isn't hard to examine the first few bytes), but you're using off-the-shelf parsers anyway, so why are you concerned by this? There are occa

Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
Ned Batchelder : > I don't understand how JSON has flopped? The parser may be a bit more > complex (but not much, it isn't hard to examine the first few bytes), > but you're using off-the-shelf parsers anyway, so why are you > concerned by this? There are occasions where you need to take shortcut

Re: Storing instances using jsonpickle

2014-09-05 Thread Ned Batchelder
On 9/5/14 1:16 PM, Marko Rauhamaa wrote: MRAB : Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (Well, not unless you define 'true' and 'false' first.) Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by requiri

Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
MRAB : > Therefore, if you want it to be able to drop it into Python's REPL, it > won't be compatible with JSON anyway! (Well, not unless you define > 'true' and 'false' first.) Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by requiring the parser to heuristically support

Re: Storing instances using jsonpickle

2014-09-05 Thread MRAB
On 2014-09-04 06:17, Chris Angelico wrote: On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: I occasionally think about a superset of JSON, called, say, "pyson" ... ah, name already taken! :-( While I'm somewhat sympathetic to the concept, there are some parts of your description that I disagree wi

Re: Storing instances using jsonpickle

2014-09-04 Thread Chris Angelico
On Fri, Sep 5, 2014 at 2:38 PM, Dan Sommers wrote: > On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote: > >> On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: > >>> The key of a dict could also be int, float, or tuple. >> >> Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that

Re: Storing instances using jsonpickle

2014-09-04 Thread Dan Sommers
On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: >> The key of a dict could also be int, float, or tuple. > > Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that > outlandish an idea... Using floats is a bad idea. Consi

Re: Storing instances using jsonpickle

2014-09-04 Thread MRAB
On 2014-09-04 06:17, Chris Angelico wrote:> On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: >> I occasionally think about a superset of JSON, called, say, "pyson" >> ... ah, name already taken! :-( > > While I'm somewhat sympathetic to the concept, there are some parts > of your description that I di

Re: Storing instances using jsonpickle

2014-09-03 Thread Chris Angelico
On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: > I occasionally think about a superset of JSON, called, say, "pyson" ... > ah, name already taken! :-( While I'm somewhat sympathetic to the concept, there are some parts of your description that I disagree with. Am I misreading something? Are there ty

Re: Storing instances using jsonpickle

2014-09-03 Thread Sam Raker
1) There are, if you want to mess around with them, ways to make pickle "smarter" about class stuff: https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-normal-class-instances . I've never worked with any of this stuff (and people don't seem to like pickle

Re: Storing instances using jsonpickle

2014-09-03 Thread Ned Batchelder
On 9/3/14 6:30 PM, Josh English wrote: On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: Pickle (and it looks like jsonpickle) does not invoke the class' __init__ method when it reconstitutes objects. Your new __init__ is not being run, so new attributes it defines are no

Re: Storing instances using jsonpickle

2014-09-03 Thread Denis McMahon
On Thu, 04 Sep 2014 00:39:07 +0100, MRAB wrote: > It would add tuples, delimited by (...), which are not used otherwise > (no expressions): I guess <> and () are both unused as delims by json at present. I like the idea of other key types than string. -- Denis McMahon, denismfmcma...@gmail.com

Re: Storing instances using jsonpickle

2014-09-03 Thread MRAB
On 2014-09-03 23:30, Josh English wrote: On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: Pickle (and it looks like jsonpickle) does not invoke the class' __init__ method when it reconstitutes objects. Your new __init__ is not being run, so new attributes it defines are

Re: Storing instances using jsonpickle

2014-09-03 Thread Josh English
On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: > Pickle (and it looks like jsonpickle) does not invoke the class' > __init__ method when it reconstitutes objects. Your new __init__ is not > being run, so new attributes it defines are not being created. > > This is one o

Re: Storing instances using jsonpickle

2014-09-03 Thread Ned Batchelder
On 9/3/14 4:32 PM, Josh English wrote: I am using jsonpickle to store instances of an object into separate data files. If I make any changes to the original class definition of the object, when I recreate my stored instances, they are recreated using the original class definition, so any new

Storing instances using jsonpickle

2014-09-03 Thread Josh English
I am using jsonpickle to store instances of an object into separate data files. If I make any changes to the original class definition of the object, when I recreate my stored instances, they are recreated using the original class definition, so any new attributes, methods, or properties, are

Re: Switching between cmd.CMD instances

2014-04-03 Thread Josh English
d('submission {}'.format(line)) return True Boss = BossCmd() Sub = SubmissionCmd(Boss) Story = StoryCmd(Boss) Boss.cmdloop() This gives me a flexible framework to bounce between Cmd instances at will, and quit the program from anywhere. Josh -- https://mail.python.org/mailman/listinfo/python-list

Re: Switching between cmd.CMD instances

2014-04-02 Thread Jason Swails
On Wed, Apr 2, 2014 at 1:03 AM, Josh English wrote: > I have a program with several cmd.Cmd instances. I am trying to figure out > what the best way to organize them should be. > > I've got my BossCmd, SubmissionCmd, and StoryCmd objects. > > The BossCmd object can start

Re: Switching between cmd.CMD instances

2014-04-02 Thread William Ray Wing
On Apr 2, 2014, at 1:03 AM, Josh English wrote: > I have a program with several cmd.Cmd instances. I am trying to figure out > what the best way to organize them should be. > > I've got my BossCmd, SubmissionCmd, and StoryCmd objects. > > The BossCmd object can start

Switching between cmd.CMD instances

2014-04-01 Thread Josh English
I have a program with several cmd.Cmd instances. I am trying to figure out what the best way to organize them should be. I've got my BossCmd, SubmissionCmd, and StoryCmd objects. The BossCmd object can start either of the other two, and this module allows the user switch back and forth be

Re: Finding all instances of a string in an XML file

2013-06-23 Thread Jason Friedman
> xml = """ > > > > > > > > > > > > > > """ > > import xml.etree.ElementTree as etree > > tree = etree.fromstring(xml) > > def walk(elem, path, token): > path += (elem,) > if token in elem.attrib.values(): > yield path > for child i

Re: Finding all instances of a string in an XML file

2013-06-21 Thread Jason Friedman
Thank you Peter and Dieter, will give those thoughts a try and report back. -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding all instances of a string in an XML file

2013-06-20 Thread dieter
Jason Friedman writes: > I have XML which looks like: > > > > > > > > > > > > > > > > > The "Property X" string appears twice times and I want to output the "path" > that leads to all such appearances. You could use "lxml" and its "xpath" support.

Re: Finding all instances of a string in an XML file

2013-06-20 Thread Peter Otten
Jason Friedman wrote: > I have XML which looks like: > > > > > > > > > > > > > > > > > The "Property X" string appears twice times and I want to output the > "path" > that leads to all such appearances. In this case the output would be: > > LEVE

Finding all instances of a string in an XML file

2013-06-20 Thread Jason Friedman
I have XML which looks like: The "Property X" string appears twice times and I want to output the "path" that leads to all such appearances. In this case the output would be: LEVEL_1 {}, LEVEL_2 {"ATTR": "hello"}, ATTRIBUTE {"NAME": "Property X",

How to use multiple instances of the same COM object at the same time

2013-03-22 Thread Jan
time events. So, I need about 40 instances of the COM object simultaneously connected and registered to catch all events of all devices. I assumed I needed threading for this, and I have done a simple implementation. All I want to ask is: Does anybody see something that I could have done in a b

Re: Instances as dictionary key, __hash__ and __eq__

2013-02-19 Thread Jean-Michel Pichavant
> > Additionally, If I'm making things much more complicated than they > > need to be, let me know. > > You are. There are ways to achieve what you want, but it requires a > lot more setup and discipline. The simplest way is probably to have > a _equal_fields() method that subclasses override, r

Re: Instances as dictionary key, __hash__ and __eq__

2013-02-18 Thread Terry Reedy
On 2/18/2013 2:51 PM, Jean-Michel Pichavant wrote: Greetings, I opened something like a month ago a thread about hash functions and how I could write classes which instances can be safely used as dictionary keys. I though I had it but when I read back my code, I think I wrote yet another bug

Re: Instances as dictionary key, __hash__ and __eq__

2013-02-18 Thread Tim Delaney
On 19 February 2013 06:51, Jean-Michel Pichavant wrote: > Greetings, > > I opened something like a month ago a thread about hash functions and how > I could write classes which instances can be safely used as dictionary keys. > I though I had it but when I read back my code, I th

Instances as dictionary key, __hash__ and __eq__

2013-02-18 Thread Jean-Michel Pichavant
Greetings, I opened something like a month ago a thread about hash functions and how I could write classes which instances can be safely used as dictionary keys. I though I had it but when I read back my code, I think I wrote yet another bug. Consider the following simple (buggy) class, python

Re: running multiple django/bottle instances

2013-01-07 Thread andrea crotti
Not really, on the staging server we are using the django/bottle webserver.. Anyway I was thinking that a great possible solution might be to set up something like buildbot to: - checkout all the needed branches - run the various servers for all of them on different ports, where maybe the mappi

running multiple django/bottle instances

2013-01-03 Thread Andrea Crotti
I'm working on a quite complex web app that uses django and bottle (bottle for the API which is also restful). Before I came they started to use a staging server to be able to try out things properly before they get published, but now we would like to have the possibility to see multiple branches

Re: pickling instances of metaclass generated classes

2012-01-03 Thread Ian Kelly
> Ok, > > After reading all posts (thanks a lot), I am considering to use the > following base metaclass for all metaclasses that must lead to > pickleable instances (not pickleable classes): > > > import sys > > class Meta(type): >def __new__(mcls, name, b

Re: pickling instances of metaclass generated classes

2012-01-03 Thread lars van gemerden
On Dec 29 2011, 10:55 am, lars van gemerden wrote: > Hello, > > Can someone help me with the following: > > I am using metaclasses to make classes and these classes to make > instances. Now I want to use multiprocessing, which needs to pickle > these instances. > > P

Re: pickling instances of metaclass generated classes

2012-01-01 Thread Peter Otten
lars van gemerden wrote: >> import pickle >> import sys >> >> class MetaClass(type): >> pass >> >> class M(object): >> def __init__(self, module): >> self.__module = module >> def __getattr__(self, name): >> print "creating class", name >> class_ = MetaC

Re: pickling instances of metaclass generated classes

2011-12-30 Thread Ian Kelly
On Fri, Dec 30, 2011 at 9:51 AM, lars van gemerden wrote: > I still wonder whether it might be easier to add the class to the > namespace. Can anyone help me with that? from mypackage import mymodule setattr(mymodule, myclass.__name__, myclass) -- http://mail.python.org/mailman/listinfo/python-

Re: pickling instances of metaclass generated classes

2011-12-30 Thread lars van gemerden
; > > > Hello, > > > > > Can someone help me with the following: > > > > > I am using metaclasses to make classes and these classes to make > > > > instances. Now I want to use multiprocessing, which needs to pickle > > > > these instances

Re: pickling instances of metaclass generated classes

2011-12-30 Thread lars van gemerden
ollowing: > > > > I am using metaclasses to make classes and these classes to make > > > instances. Now I want to use multiprocessing, which needs to pickle > > > these instances. > > > > Pickle cannot find the class definitions of the instances. I am trying >

Re: pickling instances of metaclass generated classes

2011-12-30 Thread Peter Otten
lars van gemerden wrote: > On Dec 29, 8:55 pm, Ian Kelly wrote: >> On Thu, Dec 29, 2011 at 2:55 AM, lars van gemerden >> wrote: >> >> > Hello, >> >> > Can someone help me with the following: >> >> > I am using metaclasses to make cla

  1   2   3   4   5   6   7   8   >