Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-04 Thread Paulo da Silva
!!! ___ class C:   def __init__(self):   self.__foos=5*[0]   @property   def foos(self) -> list[int]:   return self.__foos   @foos.setter   def foos(self,v: int):   self.__foos=[v for __i in self.__foos] c=C() c.foos=5 print(c.f

Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-04 Thread dn
(self): self.__foos=5*[0] @property def foos(self) -> list[int]: return self.__foos @foos.setter def foos(self,v: int): self.__foos=[v for __i in self.__foos] c=C() c.foos=5 print(c.foos) ___ mypy gives

Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-03 Thread Chris Angelico
__ > >> class C: > >> def __init__(self): > >> self.__foos=5*[0] > >> > >> @property > >> def foos(self) -> list[int]: > >> return self.__foos > >> > >> @foos.setter &

Re: typing: property/setter and lists?

2022-11-03 Thread Paulo da Silva
Às 07:55 de 03/11/22, dn escreveu: On 03/11/2022 16.24, Paulo da Silva wrote: class C:  def __init__(self): self.__foos=5*[0]  @property  def foos(self) -> list[int]: return self.__foos  @foos.setter  def foos(self,v: int): self.__foos=[v for

Re: typing: property/setter and lists? [RESOLVED]

2022-11-03 Thread Paulo da Silva
ns "X, but don't complain if it's a @property". Is that how it goes? I'm sorry. A bad transposition of the text. I meant def foos(self) -> Union[list[int],int]: Regards. Paulo -- https://mail.python.org/mailman/listinfo/python-list

Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-03 Thread Paulo da Silva
Às 05:32 de 03/11/22, Paulo da Silva escreveu: Às 03:24 de 03/11/22, Paulo da Silva escreveu: Hi! And a typing problem again!!! ___ class C:  def __init__(self): self.__foos=5*[0]  @property  def foos(self) -> list[int]: ret

Re: typing: property/setter and lists? [RESOLVED]

2022-11-03 Thread Chris Angelico
On Fri, 4 Nov 2022 at 05:03, Paulo da Silva wrote: > Changing def foos(self) -> list[int]: to > def foos(self) -> Union[list[int]]: > fixes the problem. > Not so elegant, however! Wait, what?! Union[X, Y] means "X or Y" Union[X] means "X, but don't compl

Re: typing: property/setter and lists? [RESOLVED]

2022-11-03 Thread Paulo da Silva
Às 03:24 de 03/11/22, Paulo da Silva escreveu: Hi! And a typing problem again!!! ___ class C: def __init__(self):     self.__foos=5*[0] @property def foos(self) -> list[int]:     return self.__foos @foos.setter def f

Re: typing: property/setter and lists?

2022-11-03 Thread Peter Otten
On 03/11/2022 04:24, Paulo da Silva wrote: Hi! And a typing problem again!!! ___ class C: def __init__(self):     self.__foos=5*[0] @property def foos(self) -> list[int]:     return self.__foos @foos.setter def foos(sel

Re: typing: property/setter and lists?

2022-11-03 Thread dn
On 03/11/2022 16.24, Paulo da Silva wrote: class C: def __init__(self):     self.__foos=5*[0] @property def foos(self) -> list[int]:     return self.__foos @foos.setter def foos(self,v: int):     self.__foos=[v for __i in self.__foos] c=C() c.foo

typing: property/setter and lists?

2022-11-02 Thread Paulo da Silva
Hi! And a typing problem again!!! ___ class C: def __init__(self): self.__foos=5*[0] @property def foos(self) -> list[int]: return self.__foos @foos.setter def foos(self,v:

Re: How would one scrap property listing website like this?

2022-09-23 Thread Leo
On Thu, 22 Sep 2022 09:36:47 -0700 (PDT), tripd...@gmail.com wrote: > https://nigeriapropertycentre.com/ > Has anyone scrap something like this before? > probably i should try power bi first to see if it can? You can try something like this. import urllib.request from bs4 import BeautifulSoup U

Re: Definition of "property"

2021-06-02 Thread George Fischhof
efinition of the way he's using it, making it clear > that it's not a universal definition. Python's definition > is somewhat unusual, and so would not be appropriate. > > -- > Greg > > -- > https://mail.python.org/mailman/listinfo/python-list >

Re: Definition of "property"

2021-06-01 Thread Greg Ewing
On 1/06/21 7:01 am, Alan Gauld wrote: That was the point, the OP said it was a book about OOP. Not a book about "OOP in Python". In that case it would be best to avoid the word, or give a definition of the way he's using it, making it clear that it's not a universal definition. Python's definit

Re: Definition of "property"

2021-06-01 Thread Alan Gauld via Python-list
On 31/05/2021 15:59, Dennis Lee Bieber wrote: > On Sun, 30 May 2021 21:20:24 +0100, Alan Gauld via Python-list > declaimed the following: > >> On 30/05/2021 17:57, Irv Kalb wrote: >>> I am doing some writing (for an upcoming book on OOP), and I'm a little >>> stuck. >> >> Oh dear, that's one o

Re: Definition of "property"

2021-06-01 Thread Eryk Sun
On 6/1/21, Jon Ribbens via Python-list wrote: > > I already answered that in the post you are responding to, but you > snipped it: You can tell something's definitely not a data attribute > if you have to put brackets after its name to call it as a method to > invoke its function or retrieve the v

Re: Definition of "property"

2021-06-01 Thread Jon Ribbens via Python-list
On 2021-06-01, Greg Ewing wrote: > On 1/06/21 2:34 am, Jon Ribbens wrote: >> From the outside, it's just a *data* attribute. Which, from the inside, >> it isn't. Hence "pretending". > > But what is it about the external appearance that would make > you think it's a data attribute, rather than som

Re: Definition of "property"

2021-06-01 Thread Greg Ewing
On 1/06/21 2:34 am, Jon Ribbens wrote: From the outside, it's just a *data* attribute. Which, from the inside, it isn't. Hence "pretending". But what is it about the external appearance that would make you think it's a data attribute, rather than some other kind of attribute? (I'm assuming th

Re: Definition of "property"

2021-06-01 Thread Alan Gauld via Python-list
On 31/05/2021 01:24, Greg Ewing wrote: > On 31/05/21 8:20 am, Alan Gauld wrote: >> >> That's a very Pythonic description. > > If it's a book about Python, it needs to be. The word "property" > has a very specialised meaning in Python. > >

Re: Definition of "property"

2021-06-01 Thread Jon Ribbens via Python-list
On 2021-05-31, Greg Ewing wrote: > On 31/05/21 9:13 am, Jon Ribbens wrote: >> No, I said it pretends to be a *data* attribute. > > I don't think it's pretending to be anything. From the outside, > it's just an attribute. >From the outside, it's just a *data* attribute. Which, from the inside, it

Re: Definition of "property"

2021-05-31 Thread Irv Kalb
> On May 30, 2021, at 10:15 AM, Jon Ribbens via Python-list > wrote: > > On 2021-05-30, Irv Kalb wrote: >> I understand what a "property" is, how it is used and the benefits, >> but apparently my explanation hasn't made the light bulb go on for my

Re: Definition of "property"

2021-05-31 Thread Greg Ewing
On 31/05/21 9:13 am, Jon Ribbens wrote: No, I said it pretends to be a *data* attribute. I don't think it's pretending to be anything. From the outside, it's just an attribute. Data attributes are more common than non-data attributes, so we tend to assume that an attribute is a data attribute

Re: Definition of "property"

2021-05-31 Thread Greg Ewing
On 31/05/21 4:57 am, Irv Kalb wrote: Perhaps the best I've found so far is from the Python documentation: A property object has getter, setter, and deleter methods usable as decorators that create a copy of the property with the corresponding accessor function set to the decorated fun

Re: Definition of "property"

2021-05-31 Thread Greg Ewing
On 31/05/21 8:20 am, Alan Gauld wrote: That's a very Pythonic description. If it's a book about Python, it needs to be. The word "property" has a very specialised meaning in Python. In some other languages it's used the way we use "attribute" in Python.

Re: Definition of "property"

2021-05-31 Thread Alan Gauld via Python-list
On 30/05/2021 23:57, Mike Dewhirst wrote: > > A property is an object method masquerading as a cachable object attribute Or a group of methods perhaps? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-b

Re: Definition of "property"

2021-05-31 Thread Jon Ribbens via Python-list
On 2021-05-30, Terry Reedy wrote: > Note: at least one person says a property *pretends* to be an attribute. No, I said it pretends to be a *data* attribute. It is effectively several methods in a trenchcoat pretending to be a variable. -- https://mail.python.org/mailman/listinfo/python-list

Re: Definition of "property"

2021-05-30 Thread Eryk Sun
eggs to see if it has a > __get__, __set__, or __delete__ > > method — if it does, it's a property. The above is not quite right. Having a __get__ method is not sufficient. In the quoted example, the `eggs` attribute of the SomeObject type has to be a data descriptor type, whic

RE: Definition of "property"

2021-05-30 Thread Avi Gross via Python-list
humor, give him the communist version of property. Property is owned by the state and is a reflection of such a state. It is hidden and can only be accessed through apparatchiks working for the state. You tell them what you want and they go invisibly and do whatever they want which may even include

Re: Definition of "property"

2021-05-30 Thread Dan Stromberg
On Sun, May 30, 2021 at 9:57 AM Irv Kalb wrote: > I am doing some writing (for an upcoming book on OOP), and I'm a little > stuck. > > I understand what a "property" is, how it is used and the benefits, but > apparently my explanation hasn't made the light bul

Re: Definition of "property"

2021-05-30 Thread Mike Dewhirst
On 31/05/2021 2:57 am, Irv Kalb wrote: I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. I understand what a "property" is, how it is used and the benefits, but apparently my explanation hasn't made the light bulb go on for my editor. The edi

Re: Definition of "property"

2021-05-30 Thread dn via Python-list
On 31/05/2021 04.57, Irv Kalb wrote: > I am doing some writing (for an upcoming book on OOP), and I'm a little > stuck. > > I understand what a "property" is, how it is used and the benefits, but > apparently my explanation hasn't made the light bulb go

Re: Definition of "property"

2021-05-30 Thread Alan Gauld via Python-list
s depressing how many books and articles focus on them to the exclusion of all else that make up the OOP paradigm! Anyway, rant over... > I understand what a "property" is, how it is used and the benefits, Do you? What is that based on? Is it how properties are used in OOP? Or how the

Re: Definition of "property"

2021-05-30 Thread Terry Reedy
On 5/30/2021 12:57 PM, Irv Kalb wrote: I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. I understand what a "property" is, how it is used and the benefits, but apparently my explanation hasn't made the light bulb go on for my editor. The edi

Re: Definition of "property"

2021-05-30 Thread Jon Ribbens via Python-list
On 2021-05-30, Irv Kalb wrote: > I understand what a "property" is, how it is used and the benefits, > but apparently my explanation hasn't made the light bulb go on for my > editor. The editor is asking for a definition of property. I've > looked at many articl

Re: Definition of "property"

2021-05-30 Thread Ethan Furman
On 5/30/21 9:57 AM, Irv Kalb wrote: > I understand what a "property" is, how it is used and the benefits, but apparently my explanation hasn't made the light bulb go on for my editor. My answer from Stackoverflow [1]: > Properties are a special kind of attribute. B

Re: Definition of "property"

2021-05-30 Thread Barry Scott
> On 30 May 2021, at 17:57, Irv Kalb wrote: > > I am doing some writing (for an upcoming book on OOP), and I'm a little > stuck. > > I understand what a "property" is, how it is used and the benefits, but > apparently my explanation hasn't made th

Re: Definition of "property"

2021-05-30 Thread Chris Angelico
On Mon, May 31, 2021 at 2:58 AM Irv Kalb wrote: > > I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. > > I understand what a "property" is, how it is used and the benefits, but > apparently my explanation hasn't made the ligh

Definition of "property"

2021-05-30 Thread Irv Kalb
I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. I understand what a "property" is, how it is used and the benefits, but apparently my explanation hasn't made the light bulb go on for my editor. The editor is asking for a definition of prope

Overriding property types on instances from a library

2021-02-20 Thread Joseph L. Casale
'collections.Iterable', got '() -> Any' instead How can I override the type with a hint on a property of those instances? Thanks, jlc -- https://mail.python.org/mailman/listinfo/python-list

Re: Property type hints?

2020-12-09 Thread dn via Python-list
On 10/12/2020 13:06, Paul Bryan wrote: Thanks for the comprehensive response, dn! I guess I'm influenced by data classes here, where the object's attribute type hints are represented by class variable annotations. I'm a great fan of them too - the saving of 'boilerplate code' does it for me

Re: Property type hints?

2020-12-09 Thread Paul Bryan
> Would this be a reasonably correct way to annotate a property with > > a > > type hint? > > > > > > > class Foo: > > ... bar: int > > > If we build a class with (only) the above two lines, Python's help > lookup offers th

Re: Property type hints?

2020-12-09 Thread dn via Python-list
On 09/12/2020 13:17, Paul Bryan wrote: Would this be a reasonably correct way to annotate a property with a type hint? class Foo: ... bar: int If we build a class with (only) the above two lines, Python's help lookup offers the following documentation: <<< Help on

Property type hints?

2020-12-08 Thread Paul Bryan
Would this be a reasonably correct way to annotate a property with a type hint? >>> class Foo: ... bar: int ... @property ... def bar(self): ... return 1 ... >>> foo = Foo() >>> import typing >>> typing.get_type_hints(foo) {'bar'

Re: Can property getters and setters have additional arguments?

2020-10-31 Thread Chris Angelico
On Sun, Nov 1, 2020 at 3:46 AM wrote: > > I asked this question over on the python-forum-io group but haven't gotten > much in the way of answers. I hope someone here can advise me. > > I am trying to implement getters and setters in a class using a numpy array > as the base instance value, but I

Can property getters and setters have additional arguments?

2020-10-31 Thread pjfarley3
msize + 2], dtype=np.int32) @property def visits(self, coord): return self.visited[coord[0], coord[1], coord[2]] @visits.setter def incr_visits(self, coord, incr): self.visited[coord[0], coord[1], coord[2]] += incr def Coord(x,

RE: Can property getters and setters have additional arguments?

2020-10-31 Thread pjfarley3
ctober 31, 2020 1:17 AM > To: 'python-list@python.org' > Subject: Can property getters and setters have additional arguments? > > I asked this question over on the python-forum-io group but haven't gotten > much in the way of answers. I hope someone here can advise me

Re: property

2020-06-30 Thread ast
Le 26/06/2020 à 15:12, Peter Otten a écrit : Unknown wrote: The getter/setter of the property builtin return a new property p = property() q = p.getter(None) p is q False where you def getter(self, fget): self.fget = fget return self modify the existing one

Re: property

2020-06-30 Thread ast
Le 26/06/2020 à 10:16, R.Wieser a écrit : ast, I have absolutily /no idea/ about how that "fahrenheit = property()" comes into play though. It just creates an empty property object. You can then fill this object with the read/write/delete functions with the methods gett

Re: property

2020-06-26 Thread Dieter Maurer
ast wrote at 2020-6-26 09:02 +0200: >Hello, > >I am wondering why this code is OK: > >class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def fahrenheit(self):

Re: property

2020-06-26 Thread Peter Otten
Unknown wrote: > Hello, > > I am wondering why this code is OK: > > class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def fahrenheit(self): > return 9/5*self.celsius +32

Re: property

2020-06-26 Thread Barry Scott
> On 26 Jun 2020, at 08:02, ast wrote: > > Hello, > > I am wondering why this code is OK: > > class Temperature: >def __init__(self): > self.celsius = 0 > >fahrenheit = property() > >@fahrenheit.getter >def fahrenheit(

property

2020-06-26 Thread ast
Hello, I am wondering why this code is OK: class Temperature: def __init__(self): self.celsius = 0 fahrenheit = property() @fahrenheit.getter def fahrenheit(self): return 9/5*self.celsius +32 @fahrenheit.setter def fahrenheit(self

Re: Property for dataclass field with default value

2020-06-19 Thread Peter Otten
Ivan Ivanyuk wrote: > On Thu, 18 Jun 2020 at 11:26, Peter Otten <__pete...@web.de> wrote: >> >> Ivan Ivanyuk wrote: >> >> > Hello All, >> > >> > I have some trouble using @dataclass together with @property decorator >> > or propert

Re: Property for dataclass field with default value

2020-06-18 Thread Ivan Ivanyuk
On Thu, 18 Jun 2020 at 11:26, Peter Otten <__pete...@web.de> wrote: > > Ivan Ivanyuk wrote: > > > Hello All, > > > > I have some trouble using @dataclass together with @property decorator > > or property() function. > > > > From the documentat

Re: Property for dataclass field with default value

2020-06-18 Thread Peter Otten
Ivan Ivanyuk wrote: > Hello All, > > I have some trouble using @dataclass together with @property decorator > or property() function. > > From the documentation and PEP is seems that the intended behaviour of > @dataclass is to be the same as normal __init__() that sets

Property for dataclass field with default value

2020-06-17 Thread Ivan Ivanyuk
Hello All, I have some trouble using @dataclass together with @property decorator or property() function. >From the documentation and PEP is seems that the intended behaviour of @dataclass is to be the same as normal __init__() that sets instance variables. But it seems that when us

Re: Can I have a class with property named "from"

2020-06-08 Thread zljubisic
, it could work, for processing input, because processing is under my control. However, my process will create output object that I should json serialize and return back to outer system as a response to the input. If I will have "from_" object property instead of "from", I beli

Re: Can I have a class with property named "from"

2020-06-06 Thread Terry Reedy
On 6/5/2020 6:59 PM, Ethan Furman wrote: On 06/05/2020 03:15 PM, MRAB wrote: On 2020-06-05 22:50, Ethan Furman wrote: There is no workaround that allows a keyword to be used except as a keyword, other than making it a string.  When faced with this kind of situation myself I use a synonym, li

Re: Can I have a class with property named "from"

2020-06-05 Thread DL Neil via Python-list
On 6/06/20 9:36 AM, zljubi...@gmail.com wrote: Hi, if I define class like this one: class abc: def __init__(self): self._from = None @property def from(self): return self._from @from.setter def from(self, value): self._from = value I get

Re: Can I have a class with property named "from"

2020-06-05 Thread Ethan Furman
On 06/05/2020 03:15 PM, MRAB wrote: On 2020-06-05 22:50, Ethan Furman wrote: There is no workaround that allows a keyword to be used except as a keyword, other than making it a string.  When faced with this kind of situation myself I use a synonym, like "since", or a translation, like "desde

Re: Can I have a class with property named "from"

2020-06-05 Thread MRAB
On 2020-06-05 22:50, Ethan Furman wrote: On 06/05/2020 02:36 PM, zljubi...@gmail.com wrote: class abc: def __init__(self): self._from = None @property def from(self): return self._from @from.setter def from(self, value): self._from = value

Re: Can I have a class with property named "from"

2020-06-05 Thread Ethan Furman
On 06/05/2020 02:36 PM, zljubi...@gmail.com wrote: class abc: def __init__(self): self._from = None @property def from(self): return self._from @from.setter def from(self, value): self._from = value I get the error SyntaxError: invalid

Can I have a class with property named "from"

2020-06-05 Thread zljubisic
Hi, if I define class like this one: class abc: def __init__(self): self._from = None @property def from(self): return self._from @from.setter def from(self, value): self._from = value I get the error SyntaxError: invalid syntax because of the

Re: Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Peter Otten
bject): > b = Bar() > > f = Foo() > print(f) > f.b = 10 > > 1. Now when we create/use @property.. > what is the first and second argument to dunder-set > > (my guess is, the @property is the first arg and the second arg is 'Foo' > IF you do >

Re: Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Veek M
(self, instance, value): #b-instance of Bar, f-instance of Foo, value print(self, instance, value) class Foo(object): b = Bar() f = Foo() print(f) f.b = 10 1. Now when we create/use @property.. what is the first and second argument to dunder-set (my guess is

Re: Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Peter Otten
Veek M wrote: > class Foo(object): > @property > def name(self): > if hasattr(self, '_name'): > print('Foo name', self._name) > return self._name > else: > return 'default&

Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

2019-12-03 Thread Veek M
class Foo(object): @property def name(self): if hasattr(self, '_name'): print('Foo name', self._name) return self._name else: return 'default' @name.setter def name(self, value): print(&

Re: Why can't access the property setter using the super?

2019-03-19 Thread Chris Angelico
ius) will not raise. """ if value > RefrigeratedShippingContainer.MAX_CELSIUS: raise ValueError("Temperature too hot!") @property def celsius(self): return self._celsius @celsius.setter def celsius(self, value): self.validate_temp(val

Re: Why can't access the property setter using the super?

2019-03-19 Thread Arup Rakshit
instance. This > works fine for looking up methods and property getters. It doesn't work so > well for simulating other behaviors, like setters, or comparisons, or > iteration, etc. > > A property is one example of what in Python is known as a descriptor, which > is de

Re: Why can't access the property setter using the super?

2019-03-19 Thread Ian Kelly
ance. This works fine for looking up methods and property getters. It doesn't work so well for simulating other behaviors, like setters, or comparisons, or iteration, etc. A property is one example of what in Python is known as a descriptor, which is described here: https://docs.python.

Why can't access the property setter using the super?

2019-03-19 Thread Arup Rakshit
serial=str(serial).zfill(6), category='R') @property def celsius(self): return self._celsius @celsius.setter def celsius(self, value): if value > RefrigeratedShippingContainer.MAX_CELSIUS: raise ValueError(&q

Re: property decorator?

2017-12-21 Thread Irv Kalb
Thanks to Rob, Cameron, Ian, Chris and Kirill for the detailed explanations. Very helpful, Irv > On Dec 20, 2017, at 3:56 PM, Irv Kalb wrote: > > I am trying to work through the concept of the @property decorator with > respect to object oriented programming. > >

Re: property decorator?

2017-12-21 Thread Cholo Lennon
On 20/12/17 21:39, Stefan Ram wrote: Irv Kalb writes: about property decorators. The code @property def salary(self): pass @salary.setter def salary(self, newSalary): pass is an abbreviation for def salary_get(self): pass salary = property( salary_get ) def salary_set(self

Fwd: property decorator?

2017-12-21 Thread Kirill Balunov
2017-12-21 2:56 GMT+03:00 Irv Kalb : > My questions about this are really historical. From my reading, it looks > like using an @property decorator is a reference to an older approach using > a built in "property" function. But here goes: > > 1) Why were these decorator

Re: property decorator?

2017-12-20 Thread Cameron Simpson
On 20Dec2017 15:56, Irv Kalb wrote: I am trying to work through the concept of the @property decorator with respect to object oriented programming. I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance

Re: property decorator?

2017-12-20 Thread Chris Angelico
On Thu, Dec 21, 2017 at 2:38 PM, Ian Kelly wrote: > On Wed, Dec 20, 2017 at 5:56 PM, Irv Kalb wrote: >> 2) Alternatively, if the getter was going to use the @property decorator, >> then it would seem complimentary to have the decorator name for the >> associated setter

Re: property decorator?

2017-12-20 Thread Ian Kelly
On Wed, Dec 20, 2017 at 5:56 PM, Irv Kalb wrote: > My questions about this are really historical. From my reading, it looks > like using an @property decorator is a reference to an older approach using a > built in "property" function. But here goes: > > 1) Why w

Re: property decorator?

2017-12-20 Thread Rob Gaddi
On 12/20/2017 03:56 PM, Irv Kalb wrote: I am trying to work through the concept of the @property decorator with respect to object oriented programming. I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance

property decorator?

2017-12-20 Thread Irv Kalb
I am trying to work through the concept of the @property decorator with respect to object oriented programming. I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance variables into method calls in an object

Re: newb question about @property

2017-10-06 Thread bartc
On 05/10/2017 14:13, Steve D'Aprano wrote: On Thu, 5 Oct 2017 10:51 pm, bartc wrote: Am I allowed to say that it all seems a bit of a mess? You may or may not be pleased to learn that there's a push to create a "record like" or "struct like" datatype for Python 3.7 or 3.8, tentatively called

Re: newb question about @property

2017-10-05 Thread Steve D'Aprano
On Thu, 5 Oct 2017 10:51 pm, bartc wrote: > Am I allowed to say that it all seems a bit of a mess? You may or may not be pleased to learn that there's a push to create a "record like" or "struct like" datatype for Python 3.7 or 3.8, tentatively called a "Data Class" for now. The proposed syntax

Re: newb question about @property

2017-10-05 Thread bartc
On 05/10/2017 12:29, Gregory Ewing wrote: bartc wrote: Result? You can't just look at my 'any' class and see what fields it uses. You can't even just look at the static source code. You have to run the program to find out. And it might be different each time. You can usually get a pretty good

Re: newb question about @property

2017-10-05 Thread Gregory Ewing
bartc wrote: Result? You can't just look at my 'any' class and see what fields it uses. You can't even just look at the static source code. You have to run the program to find out. And it might be different each time. You can usually get a pretty good idea of what attributes a class has by loo

Re: newb question about @property

2017-10-04 Thread Steve D'Aprano
On Wed, 4 Oct 2017 11:46 pm, Rhodri James wrote: > On 04/10/17 12:07, bartc wrote: >> I've seen that example brought up before. It still doesn't cut any ice. >> >> You might as well be condescending of someone who finds Joyce or Proust >> unreadable, and prefers McBain, Simenon or Chandler. (Sorr

Re: Constants [was Re: newb question about @property]

2017-10-04 Thread Steve D'Aprano
On Thu, 5 Oct 2017 04:00 am, Paul Moore wrote: > I wonder - would the people who want "real constants" find the > following confusing: > from demo import foo foo = 14 foo > 14 > > It's fundamental to the way the import function works, and how names > in Python behave, but I can s

Re: newb question about @property

2017-10-04 Thread Steve D'Aprano
On Thu, 5 Oct 2017 09:08 am, bartc wrote: [...] > And when I tried, it didn't really work in Python 2 (extra attributes > could still be created, and .__slots__ wasn't readonly); only Py3. Not quite, but I don't blame you for the mistake. Its an easy one to make. __slots__ only works in "new sty

Re: newb question about @property

2017-10-04 Thread bartc
On 04/10/2017 17:02, Rhodri James wrote: On 04/10/17 16:33, Paul Moore wrote: It's not an advantage or a disadvantage, just an approach. Many people like it, you may not. Specifically, yes you can't "just declare a lightweight struct or record with exactly two fields". Actually you can: >>

Re: newb question about @property

2017-10-04 Thread ROGER GRAYDON CHRISTMAN
On Wed, Oct 4, 2017 14:03 PM, bartc wrote > "A property, in some object-oriented programming languages, is a special >sort of class member, intermediate in functionality between a field (or >data member) and a method." > >But Python has some problems just in using fi

Re: Constants [was Re: newb question about @property]

2017-10-04 Thread Paul Moore
you want it. > > $ cat demo.py > import sys > > class DemoModule: > @property > def foo(self): > return 42 > > sys.modules['demo'] = DemoModule() > > $ python3 -c 'import demo; print(demo.foo); demo.foo = 14' > 42 > Traceback (most

Re: newb question about @property

2017-10-04 Thread Paul Moore
On 4 October 2017 at 17:02, Rhodri James wrote: > Actually you can: > class Point: > ... __slots__ = ("x", "y") > ... def __init__(self, x, y): > ... self.x = x > ... self.y = y > ... def __str__(self): > ... return "({0},{1})".format(self.x, self.y) > ... p = Point(3,4

Re: Constants [was Re: newb question about @property]

2017-10-04 Thread Ian Kelly
t too > unsafe for big projects. We have read-only attributes in classes, but not > read-only names in modules. That makes me a little bit sad. Which brings up the point that you can hack it in if you want it. $ cat demo.py import sys class DemoModule: @property def foo(self): return 4

Re: newb question about @property

2017-10-04 Thread Rhodri James
On 04/10/17 16:33, Paul Moore wrote: On 4 October 2017 at 16:03, bartc wrote: No error. Some would perceive all this as an advantage, but it means you can't just declare a lightweight struct or record 'Point' with exactly two fields x and y. You have to use other solutions ('namedtuples' or wha

Re: newb question about @property

2017-10-04 Thread Paul Moore
On 4 October 2017 at 16:03, bartc wrote: > No error. Some would perceive all this as an advantage, but it means you > can't just declare a lightweight struct or record 'Point' with exactly two > fields x and y. You have to use other solutions ('namedtuples' or whatever, > which probably are immuta

Constants [was Re: newb question about @property]

2017-10-04 Thread Steve D'Aprano
On Thu, 5 Oct 2017 12:41 am, Ian Kelly wrote: > Python has the simplest named constants of all: > > C = 12345 > > As long as you don't subsequently change it, it's a constant. And it's > very simple because it works just like any other variable. I do feel that the lack of constants[1] is a (mi

Re: newb question about @property

2017-10-04 Thread bartc
#x27;re > just used in the form of properties. Here's a list of languages that > support properties: > https://en.wikipedia.org/wiki/Property_(programming)#Example_syntax "A property, in some object-oriented programming languages, is a special sort of class member, intermediate in f

Re: newb question about @property

2017-10-04 Thread Ian Kelly
On Wed, Oct 4, 2017 at 5:07 AM, bartc wrote: > It is just being elitist. I have a preference for keeping things simple and > avoiding unnecessary complexity. But with programming languages many do have > a penchant for the latter. > > As an example, a recent discussion on comp.lang.c was about imp

Re: newb question about @property

2017-10-04 Thread Rhodri James
On 04/10/17 12:07, bartc wrote: I've seen that example brought up before. It still doesn't cut any ice. You might as well be condescending of someone who finds Joyce or Proust unreadable, and prefers McBain, Simenon or Chandler. (Sorry, can't think of any modern pulp novelists). I don't thin

Re: newb question about @property

2017-10-04 Thread bartc
On 04/10/2017 06:32, Steve D'Aprano wrote: On Wed, 4 Oct 2017 02:00 am, bartc wrote: Does all this advanced stuff (which I don't understand and which doesn't look very appealing either; hopefully I will never come across such code) still count as programming? I could not have hoped to see a m

Re: newb question about @property

2017-10-03 Thread Steve D'Aprano
On Wed, 4 Oct 2017 02:00 am, bartc wrote: > Does all this advanced stuff (which I don't understand and which doesn't > look very appealing either; hopefully I will never come across such > code) still count as programming? I could not have hoped to see a more perfect example of the Blub effect in

Re: newb question about @property

2017-10-03 Thread Ian Kelly
On Tue, Oct 3, 2017 at 9:16 AM, Jorge Gimeno wrote: > No, I see this as teaching the skills involved to drive a car. Practicing a > turn, scanning gauges, and checking blind spots are all a part of driving. > When one is learning, it's easier to learn these in isolation so when the > problem must

  1   2   3   4   5   6   7   8   9   >