Hybrid meeting ANN: Using properties and descriptors

2023-07-11 Thread dn via Python-list
This month's meeting (Wed 19 July, 1800 for 1830 NZST = 0600/0630 UTC) will cover more-advanced OOP Python skills. You will be most-welcome to join us... "Using properties and descriptors" will look at a series of code-examples exploring problems and how these constructs o

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-27 Thread Peter J. Holzer
On 2018-12-17 21:57:22 +1100, Paul Baker wrote: > class C: > def __init__(self): > self.__dict__['a'] = 1 > > @property > def a(self): > return 2 > > o = C() > print(o.a) # Prints 2 What version of Python is this? I get a different res

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-27 Thread Peter J. Holzer
On 2018-12-27 14:17:34 +0100, Peter J. Holzer wrote: > On 2018-12-17 21:57:22 +1100, Paul Baker wrote: > > class C: > > def __init__(self): > > self.__dict__['a'] = 1 > > > > @property > > def a(self): > > return 2 > > > > o = C() > > pr

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-18 Thread Ian Kelly
On Mon, Dec 17, 2018, 12:09 PM Paul Baker When Python looks up an attribute on an object (i.e. when it executes > `o.a`), it uses an interesting priority order [1]. It looks for: > > 1. A class attribute that is a data-descriptor (most commonly a property) > 2. An instance attribute > 3. Any ot

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-18 Thread dieter
Paul Baker writes: > When Python looks up an attribute on an object (i.e. when it executes > `o.a`), it uses an interesting priority order [1]. It looks for: > > 1. A class attribute that is a data-descriptor (most commonly a property) > 2. An instance attribute > 3. Any other class attribute >

Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-17 Thread Paul Baker
When Python looks up an attribute on an object (i.e. when it executes `o.a`), it uses an interesting priority order [1]. It looks for: 1. A class attribute that is a data-descriptor (most commonly a property) 2. An instance attribute 3. Any other class attribute We can confirm this using the c

Re: How to store properties

2017-02-22 Thread MRAB
On 2017-02-22 21:08, Gilmeh Serda wrote: On Wed, 08 Feb 2017 09:31:09 -0800, Rob Gaddi wrote: JSON's cute, but the format doesn't support inline comments. { "your_key": "whatever", "COMMENT": "blah", "meh": [ "yup", "yep", "yip" ], "COMMENT": "mooh"

Re: How to store properties

2017-02-09 Thread Chris Angelico
On Thu, Feb 9, 2017 at 7:43 PM, dieter wrote: > "pickle", too, has a potential security risk -- if you allow > unpickling from untrusted source. Usually, however, configuration > comes from trusted sources. Pickle's other downside is that it's an opaque binary file, unlike ConfigParser, JSON, and

Re: How to store properties

2017-02-09 Thread Cecil Westerhof
On Wednesday 8 Feb 2017 12:26 CET, Cecil Westerhof wrote: > In Java you (can) use a properties file store configuration. What is > the best way to do something like that in Python? > I saw ConfigParser, but have the feeling that it is not really used. > Would a JSON file be a good i

Re: How to store properties

2017-02-09 Thread dieter
Cecil Westerhof writes: > ... >> If you only want to read the configuration, just use an ordinary >> file you import. For example config.py contains the lines: >> username=myuser >> server=myserver >> password=secret >> >> In your script: >> >> import config >> >> Now you can referenc all the var

Re: How to store properties

2017-02-08 Thread Terry Reedy
On 2/8/2017 6:26 AM, Cecil Westerhof wrote: In Java you (can) use a properties file store configuration. What is the best way to do something like that in Python? I saw ConfigParser, but have the feeling that it is not really used. IDLE uses it for default and user configuration files

Re: How to store properties

2017-02-08 Thread Cecil_Westerhof
From: Cecil Westerhof On Wednesday 8 Feb 2017 13:11 CET, Peter Heitzer wrote: > Cecil Westerhof wrote: >> In Java you (can) use a properties file store configuration. What >> is the best way to do something like that in Python? I saw >> ConfigParser, but have the feeling

Re: How to store properties

2017-02-08 Thread Michael_Torrie
From: Michael Torrie On 02/08/2017 04:26 AM, Cecil Westerhof wrote: > In Java you (can) use a properties file store configuration. What is > the best way to do something like that in Python? > I saw ConfigParser, but have the feeling that it is not really used. > Would a JSON file be

Re: How to store properties

2017-02-08 Thread Rob Gaddi
On 02/08/2017 03:26 AM, Cecil Westerhof wrote: In Java you (can) use a properties file store configuration. What is the best way to do something like that in Python? I saw ConfigParser, but have the feeling that it is not really used. Would a JSON file be a good idea? In the interest of

Re: How to store properties

2017-02-08 Thread Michael Torrie
On 02/08/2017 04:26 AM, Cecil Westerhof wrote: > In Java you (can) use a properties file store configuration. What is > the best way to do something like that in Python? > I saw ConfigParser, but have the feeling that it is not really used. > Would a JSON file be a good idea

Re: How to store properties

2017-02-08 Thread Neil Cerutti
On 2017-02-08, Cholo Lennon wrote: > On 02/08/2017 08:26 AM, Cecil Westerhof wrote: >> In Java you (can) use a properties file store configuration. >> What is the best way to do something like that in Python? I >> saw ConfigParser, but have the feeling that it is not really

Re: How to store properties

2017-02-08 Thread Cecil Westerhof
On Wednesday 8 Feb 2017 13:11 CET, Peter Heitzer wrote: > Cecil Westerhof wrote: >> In Java you (can) use a properties file store configuration. What >> is the best way to do something like that in Python? I saw >> ConfigParser, but have the feeling that it is not really

Re: How to store properties

2017-02-08 Thread David Palao
2017-02-08 13:34 GMT+01:00 Cholo Lennon : > On 02/08/2017 08:26 AM, Cecil Westerhof wrote: >> >> In Java you (can) use a properties file store configuration. What is >> the best way to do something like that in Python? >> I saw ConfigParser, but have the feeling that it

Re: How to store properties

2017-02-08 Thread Cholo Lennon
On 02/08/2017 08:26 AM, Cecil Westerhof wrote: In Java you (can) use a properties file store configuration. What is the best way to do something like that in Python? I saw ConfigParser, but have the feeling that it is not really used. I use it a lot ;-) Would a JSON file be a good idea

Re: How to store properties

2017-02-08 Thread Peter Heitzer
Cecil Westerhof wrote: >In Java you (can) use a properties file store configuration. What is >the best way to do something like that in Python? >I saw ConfigParser, but have the feeling that it is not really used. >Would a JSON file be a good idea? If you only want to read the c

How to store properties

2017-02-08 Thread Cecil Westerhof
In Java you (can) use a properties file store configuration. What is the best way to do something like that in Python? I saw ConfigParser, but have the feeling that it is not really used. Would a JSON file be a good idea? -- Cecil Westerhof Senior Software Engineer LinkedIn: http

Re: Question about abstract base classes and abstract properties -- Python 2.7

2017-01-10 Thread Steven D'Aprano
On Wednesday 11 January 2017 12:26, Gerald Britton wrote: > I was rereading the 2.7 docs about abstract base classes the other day. I > found this line in the usage section of the abc.abstractproperty function: > > "This defines a read-only property; you can also define a read-write > abstract

Re: Question about abstract base classes and abstract properties -- Python 2.7

2017-01-10 Thread Gerald Britton
I was rereading the 2.7 docs about abstract base classes the other day. I found this line in the usage section of the abc.abstractproperty function: "This defines a read-only property; you can also define a read-write abstract property using the ‘long’ form of property declaration:" along with

Question about abstract base classes and abstract properties -- Python 2.7

2016-10-22 Thread Gerald Britton
I was rereading the 2.7 docs about abstract base classes the other day. I found this line in the usage section of the abc.abstractproperty function: "This defines a read-only property; you can also define a read-write abstract property using the ‘long’ form of property declaration:" along with

Question about abstract base classes and abstract properties -- Python 2.7

2016-09-04 Thread Gerald Britton
I was rereading the 2.7 docs about abstract base classes the other day. I found this: "This defines a read-only property; you can also define a read-write abstract property using the ‘long’ form of property declaration:" along with an example. so I copied the example and put in a little surrou

Re: zero argument member functions versus properties

2013-11-04 Thread Peter Cacioppi
Ian said : "Since the compiler generally can't predict what the types of objects will be, the bytecode that it generates can't depend on those types." very nice, the py is strong with you. Thanks, Pete -- https://mail.python.org/mailman/listinfo/python-list

Re: zero argument member functions versus properties

2013-11-03 Thread Ian Kelly
On Sun, Nov 3, 2013 at 2:23 PM, Peter Cacioppi wrote: > Ian said : > > " Whereas in Python, an attribute access is just > compiled as an attribute access no matter what the underlying > implementation of that access may end up being at run-time. " > > Really? Very nice. Have a good link handy for

Re: zero argument member functions versus properties

2013-11-03 Thread Peter Cacioppi
Ian said : " Whereas in Python, an attribute access is just compiled as an attribute access no matter what the underlying implementation of that access may end up being at run-time. " Really? Very nice. Have a good link handy for that? I'm compiling a codex of "why py is better?". -- https://ma

Re: zero argument member functions versus properties

2013-11-03 Thread Ian Kelly
On Sun, Nov 3, 2013 at 1:06 AM, Peter Cacioppi wrote: > Actually C# is mature enough for this idiom. C# and Python both support > getter/setter methods that present as direct attribute access to client code, > and thus allow you to refactor the class without breaking backwards > compatibility.

Re: zero argument member functions versus properties

2013-11-03 Thread Peter Cacioppi
Steve said: "(This isn't Java or Ruby, where data-hiding is compulsory :-) " At the risk of striking a sessile equine, when the attribute shouldn't be modified directly by client code, then you hide it and use a property to allow client code access. It is the idiom of allowing client code to e

Re: zero argument member functions versus properties

2013-11-03 Thread Peter Cacioppi
Steve said: "(This isn't Java or Ruby, where data-hiding is compulsory :-) " (You could add C++ and C# to this list). This is golden nugget for me. The old synapses are pretty well grooved to think of data hiding as good hygiene. Even though I've read a fair bit of Python text I still need to

Re: zero argument member functions versus properties

2013-11-02 Thread Steven D'Aprano
ght out, but it's also quite late in Python's history. Properties didn't get added until "new style classes" and descriptors, which was in version 2.2. I'm not sure if it's Guido to thank for them. > But the ease with which you can do this makes the "zero a

Re: zero argument member functions versus properties

2013-11-02 Thread Peter Cacioppi
I just said "1-> the zero argument function is sort of factory-like. It potentially has non-trivial run time, or it substitutes calling a class constructor when building certain objects. 2-> it simply retrieves a stored value (perhaps lazily evaluating it first) so 1 should clearly be a zero

zero argument member functions versus properties

2013-11-02 Thread Peter Cacioppi
Python makes it very easy to turn a zero argument member function into a property (hooray!) by simply adding the @property decorator. (Meme for well thought py feature - "Guido was here") But the ease with which you can do this makes the "zero argument member function or property" discussion t

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-15 Thread Mr. Joe
On Wed, May 15, 2013 at 12:15 PM, dieter wrote: > > If Python would automatically redecorate overridden methods in a derived > class, I would have no control over the process. What if I need > the undecorated method or a differently decorated method (an > uncached or differently cached met

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-14 Thread dieter
"Mr. Joe" writes: > ... > Sorry for digging this old topic back. I see that my "'property' does not > play well with polymorphic code" comment generated some controversy. So > here's something in my defense: I did not intend to "attack" you. > ... > Yes, I like decorators and descriptors. I also

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-14 Thread Mr. Joe
Sorry for digging this old topic back. I see that my "'property' does not play well with polymorphic code" comment generated some controversy. So here's something in my defense: Here's the link to stackoveflow topic I am talking about: http://stackoverflow.com/ques

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-03 Thread Steven D'Aprano
you consider "exotic"? Neither properties nor __getattr__ are exotic, although of course like all features of a language they have their own quirks. > One is this[ Took me hours to get to the bottom ]. Well, of course hindsight is 20:20, and I don't know how complicated your a

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-03 Thread dieter
"Mr. Joe" writes: > ... > Then I came to know that 'property' does not play well > with polymorphic code. :( Can you elaborate? I like "polymorphic code" and decorators (such a "property") never met a problem with the two working nicely together. > I resorted to some lambda hacks learned from

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-03 Thread Mr. Joe
Thanks for clearing up. Developers of python should address this issue, in my opinion. 3.4/3.5 maybe, but better late than never. Recently, I've been beaten back for using some exotic features of python. One is this[ Took me hours to get to the bottom ]. The other one is 'property' decorator. I wa

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-02 Thread Steven D'Aprano
s AttributeError. Since __getattr__ uses AttributeError to decide whether or not the name exists, the behaviour shown is correct: Alphabet.a does not exist, as far as the Python semantics of attribute access are concerned. Either write better code *wink* that doesn't raise AttributeError fr

Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-02 Thread Mr. Joe
Is there any way to raise the original exception that made the call to __getattr__? I seem to stumble upon a problem where multi-layered attribute failure gets obscured due to use of __getattr__. Here's a dummy code to demonstrate my problems: """ import traceback class BackupAlphabet(object):

Re: OOP noob question: Mixin properties

2012-12-14 Thread Micky Hulse
the future. :( Thanks for adding the indentation back. :) > The use of @property here doesn't give you any benefit (except, maybe, if > you are paid by the line of code). Better to just expose the "cache" > attribute directly, and likewise for the others. If, in the future, you

Re: OOP noob question: Mixin properties

2012-12-13 Thread Steven D'Aprano
ttribute directly, and likewise for the others. If, in the future, you need to turn them into computed properties, you can easily do so. But for now: class JSONResponseMixin(object): def __init__(self): self.cache = False self.cache_timeout = 86400 self.cache_key = None

Re: OOP noob question: Mixin properties

2012-12-13 Thread Micky Hulse
On Wed, Dec 12, 2012 at 7:49 PM, Micky Hulse wrote: > I hope you don't mind that this question involves Django... I'm just > looking to improve my core Python skills (so, generic Python examples > would be cool). Just experimenting: I think that will help me ac

OOP noob question: Mixin properties

2012-12-12 Thread Micky Hulse
, I've added these constants: CACHE_TIMEOUT = 86400 # 24 hours. CACHE_NAME = 'ad_manager_api' Question(s): I'd like to convert those constants to properties and make my JSONResponseMixin() class more generic and portable. Django aside, could someone provide OOP Python examples of

Re: lazy properties?

2012-11-02 Thread Stefan H. Holek
On 01.11.2012, at 22:38, Andrea Crotti wrote: > Seeing the wonderful "lazy val" in Scala I thought that I should try to get > the following also in Python. > The problem is that I often have this pattern in my code: > > class Sample: >def __init__(self): >self._var = None > >@pr

Re: lazy properties?

2012-11-01 Thread Miki Tebeka
> If you're using Python 3.2+, then functools.lru_cache probably > ... And if you're on 2.X, you can grab lru_cache from http://code.activestate.com/recipes/498245-lru-and-lfu-cache-decorators/ -- http://mail.python.org/mailman/listinfo/python-list

Re: lazy properties?

2012-11-01 Thread Cameron Simpson
On 01Nov2012 21:38, Andrea Crotti wrote: | Seeing the wonderful "lazy val" in Scala I thought that I should try to | get the following also in Python. | The problem is that I often have this pattern in my code: | | class Sample: | def __init__(self): | self._var = None | | @p

Re: lazy properties?

2012-11-01 Thread Ian Kelly
On Thu, Nov 1, 2012 at 3:38 PM, Andrea Crotti wrote: > What I would like to write is > @lazy_property > def var_lazy(self): > return long_computation() > > and this should imply that the long_computation is called only once.. If you're using Python 3.2+, then functools.lru_cache p

lazy properties?

2012-11-01 Thread Andrea Crotti
Seeing the wonderful "lazy val" in Scala I thought that I should try to get the following also in Python. The problem is that I often have this pattern in my code: class Sample: def __init__(self): self._var = None @property def var(self): if self._var is None:

Re: Reading properties file in Python, except using ConfigParser()

2012-10-08 Thread justmailharsh
On Friday, October 5, 2012 5:03:01 PM UTC+5:30, Günther Dietrich wrote: > justmailha...@gmail.com wrote: > > > > >How to read properties file in Python? I found ConfigParser() but it has a > > >'section' limitation, so looking for other alternati

Re: Reading properties file in Python, except using ConfigParser()

2012-10-05 Thread Günther Dietrich
justmailha...@gmail.com wrote: >How to read properties file in Python? I found ConfigParser() but it has a >'section' limitation, so looking for other alternatives. Have a look at PyYAML. Best regards, Günther -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading properties file in Python, except using ConfigParser()

2012-10-05 Thread Laszlo Nagy
On 2012-10-05 09:20, justmailha...@gmail.com wrote: Hi All, How to read properties file in Python? I found ConfigParser() but it has a 'section' limitation, so looking for other alternatives. http://wiki.python.org/moin/ConfigParserShootout -- http://mail.python.org/mailman/listi

Reading properties file in Python, except using ConfigParser()

2012-10-05 Thread justmailharsh
Hi All, How to read properties file in Python? I found ConfigParser() but it has a 'section' limitation, so looking for other alternatives. Thanks, Harsh -- http://mail.python.org/mailman/listinfo/python-list

Re: list of properties

2012-02-16 Thread Emile van Sebille
On 2/16/2012 9:19 AM Emmanuel Mayssat said... Hello, Is there a way to list 'properties' ? dir(thingy) from PyQt4.QtCore import * class LObject(QObject): def __init__(self, parent=None): super(LObject, self).__init__(parent) self.arg1 = 'toto

list of properties

2012-02-16 Thread Emmanuel Mayssat
Hello, Is there a way to list 'properties' ? from PyQt4.QtCore import * class LObject(QObject): def __init__(self, parent=None): super(LObject, self).__init__(parent) self.arg1 = 'toto' def getArg2(self): return self.arg1 + " <--&

Re: A way to write properties

2012-01-24 Thread HEK
On Jan 23, 12:45 pm, Arnaud Delobelle wrote: > Hi all, > > It just occurred to me that there's a very simple but slightly > different way to implement properties: > > class PropertyType(type): >     def __get__(self, obj, objtype): >         return self if obj is None

A way to write properties

2012-01-23 Thread Arnaud Delobelle
Hi all, It just occurred to me that there's a very simple but slightly different way to implement properties: class PropertyType(type): def __get__(self, obj, objtype): return self if obj is None else self.get(obj) def __set__(self, obj, val): self.set(obj, val)

Re: Get Class properties

2011-12-29 Thread Emeka
Chris, Thanks a million! Regards, Emeka On Thu, Dec 29, 2011 at 1:27 AM, Chris Angelico wrote: > On Wed, Dec 28, 2011 at 11:13 PM, Emeka wrote: > > Hello All, > > > > I have seen what I am looking for.. __dict__. > > > > Yep! You may also want to look at the dir() function. > > Chris Angelico

Re: Get Class properties

2011-12-28 Thread Chris Angelico
On Wed, Dec 28, 2011 at 11:13 PM, Emeka wrote: > Hello All, > > I have seen what I am looking for.. __dict__. > Yep! You may also want to look at the dir() function. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Get Class properties

2011-12-28 Thread Emeka
Hello All, Say I have a class like below class Town: state = StateClass() cities = CityClass() Is there way to introspect such that one can list the properties keys and their values in such a way that it would look like playing around dictionary ? Regards, Janus -- *Satajanus

Re: Get Class properties

2011-12-28 Thread Emeka
there way to introspect such that one can list the properties keys and > their values in such a way that it would look like playing around > dictionary ? > > Regards, > Janus > -- > *Satajanus Nig. Ltd > > > * > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate java .properties files in python

2011-12-05 Thread Arnaud Delobelle
On 5 December 2011 21:46, Serhiy Storchaka wrote: > 05.12.11 22:25, Arnaud Delobelle написав(ла): >> On 5 December 2011 20:05, Serhiy Storchaka  wrote: >>> You must also encode backslash ('\\'), whitespaces and control characters >>> (ord(c)<=32), '=' and ':' (key/value delimiters), '#' (comment)

Re: How to generate java .properties files in python

2011-12-05 Thread Serhiy Storchaka
05.12.11 22:25, Arnaud Delobelle написав(ла): > On 5 December 2011 20:05, Serhiy Storchaka wrote: >> You must also encode backslash ('\\'), whitespaces and control characters >> (ord(c)<=32), '=' and ':' (key/value delimiters), '#' (comment) and '!'. > Fortunately there aren't any of these in the

Re: How to generate java .properties files in python

2011-12-05 Thread Arnaud Delobelle
On 5 December 2011 20:05, Serhiy Storchaka wrote: > 03.12.11 23:34, Arnaud Delobelle написав(ла): > >> Is there a simple way to achieve this? I could do something like this: >> >> def encode(u): >>     """encode a unicode string in .properties format

Re: How to generate java .properties files in python

2011-12-05 Thread Serhiy Storchaka
03.12.11 23:34, Arnaud Delobelle написав(ла): Is there a simple way to achieve this? I could do something like this: def encode(u): """encode a unicode string in .properties format""" return u"".join(u"\\u%04x" % ord(c) if ord(c)>

Re: How to generate java .properties files in python

2011-12-04 Thread Arnaud Delobelle
On 4 December 2011 10:22, Peter Otten <__pete...@web.de> wrote: > I found another one: > u"äöü ΦΧΨ".encode("latin1", "backslashreplace") > '\xe4\xf6\xfc \\u03a6\\u03a7\\u03a8' That's it! I was hoping for a built-in solution and this is it. FTR, the 'backslashreplace' argument tells the enco

Re: How to generate java .properties files in python

2011-12-04 Thread Peter Otten
Arnaud Delobelle wrote: > On 3 December 2011 23:51, Peter Otten <__pete...@web.de> wrote: >> Arnaud Delobelle wrote: >> >>> I need to generate some java .properties files in Python (2.6 / 2.7). >>> It's a simple format to store key/value pairs e.g. &g

Re: How to generate java .properties files in python

2011-12-04 Thread Arnaud Delobelle
On 3 December 2011 23:51, Peter Otten <__pete...@web.de> wrote: > Arnaud Delobelle wrote: > >> I need to generate some java .properties files in Python (2.6 / 2.7). >> It's a simple format to store key/value pairs e.g. >> >> blue=bleu >> green=ve

Re: How to generate java .properties files in python

2011-12-03 Thread Peter Otten
Arnaud Delobelle wrote: > I need to generate some java .properties files in Python (2.6 / 2.7). > It's a simple format to store key/value pairs e.g. > > blue=bleu > green=vert > red=rouge > > The key/value are unicode strings. The annoying thing is that the &g

How to generate java .properties files in python

2011-12-03 Thread Arnaud Delobelle
Hi all, I need to generate some java .properties files in Python (2.6 / 2.7). It's a simple format to store key/value pairs e.g. blue=bleu green=vert red=rouge The key/value are unicode strings. The annoying thing is that the file is encoded in ISO 8859-1, with all non Latin1 chara

Re: Dynamically creating properties?

2011-10-30 Thread DevPlayer
To be honest, I was hoping someone would have posted a link to a well known and tested recipe. You'd think this function would be in the standard library or a specific Exception tied directly with setattr() and getattr() (and possibly __getattr__(), __getattribute__(), __setattr__()) The main thin

Re: Dynamically creating properties?

2011-10-28 Thread Steven D'Aprano
On Thu, 27 Oct 2011 16:00:57 -0700, DevPlayer wrote: > def isvalid_named_reference( astring ): > # "varible name" is really a named_reference > # import string # would be cleaner I don't understand the comment about "variable name". > valid_first_char = > '_abcdefghijklmnopqrstuvw

Re: Dynamically creating properties?

2011-10-27 Thread Lie Ryan
On 10/28/2011 08:48 AM, DevPlayer wrote: On Oct 27, 3:59 pm, Andy Dingley wrote: I have some XML, with a variable and somewhat unknown structure. I'd like to encapsulate this in a Python class and expose the text of the elements within as properties. How can I dynamically generate prope

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
Second error def isvalid_named_reference( astring ): # "varible name" is really a named_reference import __builtin__# add line -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
At least one error: change: > for astr in dir(__builtins__): to: for astr in __builtins__.__dict__: -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
Personally I like to use this function instead of a "try: except:" because try-except will allow names like __metaclass__. Remember, setattr(obj, attr_name, value) allows attr_name to be any valid str(). For example: '!@kdafk11', or '1_1', '1e-20', '0.0', '*one', '\n%%', etc. def isvalid_named_re

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
On Oct 27, 3:59 pm, Andy Dingley wrote: > I have some XML, with a variable and somewhat unknown structure. I'd > like to encapsulate this in a Python class and expose the text of the > elements within as properties. > > How can I dynamically generate properties (or methods)

Re: Dynamically creating properties?

2011-10-27 Thread John Gordon
In Andy Dingley writes: > How can I dynamically generate properties (or methods) and add them to > my class? I can easily produce a dictionary of the required element > names and their text values, but how do I create new properties at run > time? You can set dynamic attribu

Dynamically creating properties?

2011-10-27 Thread Andy Dingley
I have some XML, with a variable and somewhat unknown structure. I'd like to encapsulate this in a Python class and expose the text of the elements within as properties. How can I dynamically generate properties (or methods) and add them to my class? I can easily produce a dictionary o

Re: Testing properties that are date-related

2011-10-07 Thread Tim Chase
On 10/07/11 09:45, Ethan Furman wrote: Tim Chase wrote: On 10/07/11 07:38, Peter Otten wrote: def setUp(self): foo.window_date = functools.partial(foo.window_date, around=date(2011, 1, 1)) it worked like a charm. Another option is injection: import foo def window_date(...)

Re: Testing properties that are date-related

2011-10-07 Thread Ethan Furman
Tim Chase wrote: On 10/07/11 07:38, Peter Otten wrote: Are there best practices for testing dates that are properties which take the current date into consideration The problem is that the behavior of the window_date function depends on the current date (the function makes a guess about adding

Re: Testing properties that are date-related

2011-10-07 Thread Tim Chase
On 10/07/11 07:38, Peter Otten wrote: Are there best practices for testing dates that are properties which take the current date into consideration The problem is that the behavior of the window_date function depends on the current date (the function makes a guess about adding the century if

Re: Testing properties that are date-related

2011-10-07 Thread Peter Otten
Tim Chase wrote: > Are there best practices for testing dates that are properties > which take the current date into consideration? I have something > like > >class Foo: > def _get_year_range(self): >return (self._min_year, self._max_year) > def _s

Testing properties that are date-related

2011-10-07 Thread Tim Chase
Are there best practices for testing dates that are properties which take the current date into consideration? I have something like class Foo: def _get_year_range(self): return (self._min_year, self._max_year) def _set_year_range(self, year): if isinstance(year, tuple

Indexable properties recipe

2011-05-18 Thread Ian Kelly
http://code.activestate.com/recipes/577703-item-properties/ -- http://mail.python.org/mailman/listinfo/python-list

Re: generate properties code in class dynamically

2011-05-12 Thread JamesEM
On May 12, 10:04 pm, Terry Reedy wrote: > On 5/12/2011 9:11 AM, JamesEM wrote: > > > > > I would prefer to generate the properties code dynamically from the > > keys of the dictionaries. > > What I am looking for is something like: > > > class MyClas

Re: generate properties code in class dynamically

2011-05-12 Thread Terry Reedy
On 5/12/2011 9:11 AM, JamesEM wrote: I would prefer to generate the properties code dynamically from the keys of the dictionaries. What I am looking for is something like: class MyClass(object): def __init__(self): self.d = {} d['field1'] = 1.0 d[

Re: generate properties code in class dynamically

2011-05-12 Thread nn
On May 12, 9:11 am, JamesEM wrote: > Hello, > I have a python class that contains a dictionary. > I would like to use python properties to access the elements of the > dictionary. > This could be achieved as follows: > > class MyClass(object): > >     def __ini

generate properties code in class dynamically

2011-05-12 Thread JamesEM
Hello, I have a python class that contains a dictionary. I would like to use python properties to access the elements of the dictionary. This could be achieved as follows: class MyClass(object): def __init__(self): self.d = {} d['field1'] = 1.0 d[

dbus and properties multivalue

2010-06-24 Thread ste
hello, i want to build a simple script to resize a window of konqueror using the dbus protocol. Normally use the python interface, but the problem is most general because this operation it is impossible for me also if use qdbusviewer and is to complex for me if use dbus-send. If i use the python

Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 28, 11:50 am, Christian Heimes wrote: > Am 28.05.2010 11:31, schrieb eb303: > > > > > On May 27, 3:24 pm, Christian Heimes wrote: > >>>  Do I miss something? > >>> Is this the way to do it, or is there a better one? > > >> A better way was introduced in Python 2.6. > >> Seehttp://docs.pyt

Re: Minor annoyances with properties

2010-05-28 Thread Christian Heimes
Am 28.05.2010 11:31, schrieb eb303: > On May 27, 3:24 pm, Christian Heimes wrote: >>> Do I miss something? >>> Is this the way to do it, or is there a better one? >> >> A better way was introduced in Python 2.6. >> Seehttp://docs.python.org/library/functions.html?highlight=property#prop... >> I

Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 27, 3:14 pm, Neil Cerutti wrote: > On 2010-05-27, eb303 wrote: > > > I've been using Python properties quite a lot lately and I've > > found a few things that are a bit annoying about them in some > > cases. I wondered if I missed something or if anybody

Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 27, 8:56 pm, Francesco Bochicchio wrote: > On 27 Mag, 14:37, eb303 wrote: > > > > > Hello all, > > > I've been using Python properties quite a lot lately and I've found a > > few things that are a bit annoying about them in some cases. I >

Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 27, 3:24 pm, Christian Heimes wrote: > >  Do I miss something? > > Is this the way to do it, or is there a better one? > > A better way was introduced in Python 2.6. > Seehttp://docs.python.org/library/functions.html?highlight=property#prop... > I have a Python only version around if you a

Re: Minor annoyances with properties

2010-05-27 Thread Francesco Bochicchio
On 27 Mag, 14:37, eb303 wrote: > Hello all, > > I've been using Python properties quite a lot lately and I've found a > few things that are a bit annoying about them in some cases. I > wondered if I missed something or if anybody else has this kind of > problems

Re: Minor annoyances with properties

2010-05-27 Thread John Posner
On 5/27/2010 9:14 AM, Neil Cerutti wrote: On 2010-05-27, eb303 wrote: I've been using Python properties quite a lot lately and I've found a few things that are a bit annoying about them in some cases. I wondered if I missed something or if anybody else has this kind of problems t

Re: Minor annoyances with properties

2010-05-27 Thread Christian Heimes
Do I miss something? Is this the way to do it, or is there a better one? A better way was introduced in Python 2.6. See http://docs.python.org/library/functions.html?highlight=property#property I have a Python only version around if you are still using Python 2.5. Christian -- http://mail.p

  1   2   3   4   5   6   >