Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60953 > unrolled thread
| Started by | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| First post | 2013-12-03 09:14 -0800 |
| Last post | 2013-12-05 01:50 +0000 |
| Articles | 20 on this page of 57 — 20 participants |
Back to article view | Back to comp.lang.python
Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-03 09:14 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ned Batchelder <ned@nedbatchelder.com> - 2013-12-03 12:38 -0500
Re: Why is there no natural syntax for accessing attributes with names
not being valid identifiers? Dave Angel <davea@davea.name> - 2013-12-03 12:48 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 14:05 -0800
Re: Why is there no natural syntax for accessing attributes with
names not being valid identifiers? Dave Angel <davea@davea.name> - 2013-12-04 17:28 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-03 09:31 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-03 15:49 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? random832@fastmail.us - 2013-12-03 13:03 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-03 15:47 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Tim Chase <python.list@tim.thechases.com> - 2013-12-03 19:06 -0600
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 12:35 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-04 20:46 +0000
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Jerry Hill <malaclypse2@gmail.com> - 2013-12-04 15:58 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 13:02 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Neil Cerutti <neilc@norwich.edu> - 2013-12-04 21:41 +0000
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 13:54 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Neil Cerutti <neilc@norwich.edu> - 2013-12-06 14:07 +0000
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-06 08:51 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Rotwang <sg552@hotmail.co.uk> - 2013-12-07 00:47 +0000
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 14:13 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 15:09 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 15:57 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 16:26 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ned Batchelder <ned@nedbatchelder.com> - 2013-12-04 20:17 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Terry Reedy <tjreedy@udel.edu> - 2013-12-04 21:58 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 19:05 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Steven D'Aprano <steve@pearwood.info> - 2013-12-05 07:56 +0000
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Tim Roberts <timr@probo.com> - 2013-12-03 21:45 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-03 22:31 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-04 01:57 -0700
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 02:09 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-12-04 11:29 +0100
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 04:01 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-12-04 13:32 +0100
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 05:02 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-12-04 20:57 +0100
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Chris Angelico <rosuav@gmail.com> - 2013-12-04 21:33 +1100
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 03:27 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Tim Chase <python.list@tim.thechases.com> - 2013-12-04 05:25 -0600
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-04 13:30 +0200
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Chris Angelico <rosuav@gmail.com> - 2013-12-04 22:40 +1100
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 07:56 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-04 19:43 -0700
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? rusi <rustompmody@gmail.com> - 2013-12-04 20:48 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-04 19:27 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Roy Smith <roy@panix.com> - 2013-12-04 20:03 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 01:12 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Roy Smith <roy@panix.com> - 2013-12-04 08:23 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 13:00 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 12:07 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 12:22 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-04 20:55 +0000
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Ethan Furman <ethan@stoneleaf.us> - 2013-12-04 13:00 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Terry Reedy <tjreedy@udel.edu> - 2013-12-04 17:11 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Piotr Dobrogost <p@google-groups-2013.dobrogost.net> - 2013-12-04 15:42 -0800
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Terry Reedy <tjreedy@udel.edu> - 2013-12-04 22:21 -0500
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Rotwang <sg552@hotmail.co.uk> - 2013-12-05 01:50 +0000
Page 1 of 3 [1] 2 3 Next page →
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-03 09:14 -0800 |
| Subject | Why is there no natural syntax for accessing attributes with names not being valid identifiers? |
| Message-ID | <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> |
Hi! I find global getattr() function awkward when reading code. What is the reason there's no "natural" syntax allowing to access attributes with names not being valid Python identifiers in a similar way to other attributes? Something along the line of my_object.'valid-attribute-name-but-not-valid-identifier'? Regards, Piotr Dobrogost
[toc] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-12-03 12:38 -0500 |
| Message-ID | <mailman.3523.1386092315.18130.python-list@python.org> |
| In reply to | #60953 |
On 12/3/13 12:14 PM, Piotr Dobrogost wrote: > Hi! > > I find global getattr() function awkward when reading code. > What is the reason there's no "natural" syntax allowing to access attributes with names not being valid Python identifiers in a similar way to other attributes? > Something along the line of my_object.'valid-attribute-name-but-not-valid-identifier'? > > > Regards, > Piotr Dobrogost > I don't know the real reason, but I imagine it would be that it would be very rarely used. It would need to be an attribute that isn't a valid identifier, and you know the attribute at the time you write the code. I can see scenarios for needing attributes that aren't identifiers, but in many of them you also need to access them through a variable rather than literally. --Ned.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-12-03 12:48 -0500 |
| Subject | Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? |
| Message-ID | <mailman.3524.1386092873.18130.python-list@python.org> |
| In reply to | #60953 |
On Tue, 3 Dec 2013 09:14:49 -0800 (PST), Piotr Dobrogost <p@google-groups-2013.dobrogost.net> wrote: > I find global getattr() function awkward when reading code. Me too. > What is the reason there's no "natural" syntax allowing to access attributes with names not being valid Python identifiers in a similar way to other attributes? There is. Just use a dictionary. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-04 14:05 -0800 |
| Message-ID | <a788544a-e2c6-4a93-a9c4-a5c004eeae54@googlegroups.com> |
| In reply to | #60956 |
On Tuesday, December 3, 2013 6:48:38 PM UTC+1, Dave Angel wrote: > On Tue, 3 Dec 2013 09:14:49 -0800 (PST), Piotr Dobrogost > > wrote: > > > What is the reason there's no "natural" syntax allowing to access > > attributes with names not being valid Python identifiers in a similar > > way to other attributes? > > There is. Just use a dictionary. Object's attributes and dictionary's keys are quite different things. What about descriptors? Regards, Piotr
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-12-04 17:28 -0500 |
| Subject | Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers? |
| Message-ID | <mailman.3591.1386196030.18130.python-list@python.org> |
| In reply to | #61055 |
On Wed, 4 Dec 2013 14:05:11 -0800 (PST), Piotr Dobrogost <p@google-groups-2013.dobrogost.net> wrote: > Object's attributes and dictionary's keys are quite different things. Right. So if you need arbitrary keys, use a dict. Attributes are keyed by identifiers, which are constrained. No problem. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2013-12-03 09:31 -0800 |
| Message-ID | <mailman.3525.1386093172.18130.python-list@python.org> |
| In reply to | #60953 |
On 12/03/2013 09:14 AM, Piotr Dobrogost wrote: > > I find global getattr() function awkward when reading code. > What is the reason there's no "natural" syntax allowing to > access attributes with names not being valid Python > identifiers in a similar way to other attributes? > > Something along the line of my_object.'valid-attribute-name-but-not-valid-identifier'? When would you have attribute names that are not valid identifiers? -- ~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-03 15:49 -0800 |
| Message-ID | <0c86f511-9f41-4758-b9f4-5306402ff50f@googlegroups.com> |
| In reply to | #60957 |
On Tuesday, December 3, 2013 6:31:58 PM UTC+1, Ethan Furman wrote: > > When would you have attribute names that are not valid identifiers? > See my answer to rand's post.
[toc] | [prev] | [next] | [standalone]
| From | random832@fastmail.us |
|---|---|
| Date | 2013-12-03 13:03 -0500 |
| Message-ID | <mailman.3527.1386093834.18130.python-list@python.org> |
| In reply to | #60953 |
On Tue, Dec 3, 2013, at 12:14, Piotr Dobrogost wrote: > Hi! > > I find global getattr() function awkward when reading code. > What is the reason there's no "natural" syntax allowing to access > attributes with names not being valid Python identifiers in a similar way > to other attributes? > Something along the line of > my_object.'valid-attribute-name-but-not-valid-identifier'? The getattr function is meant for when your attribute name is in a variable. Being able to use strings that aren't valid identifiers is a side effect. Why are you designing classes with attributes that aren't valid identifiers?
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-03 15:47 -0800 |
| Message-ID | <eb15e1a8-49b1-4d55-a864-141efc65394e@googlegroups.com> |
| In reply to | #60959 |
On Tuesday, December 3, 2013 7:03:41 PM UTC+1, rand...@fastmail.us wrote: > On Tue, Dec 3, 2013, at 12:14, Piotr Dobrogost wrote: > > > Hi! > > > I find global getattr() function awkward when reading code. > > What is the reason there's no "natural" syntax allowing to access > > attributes with names not being valid Python identifiers in a similar way > > to other attributes? > > Something along the line of > > my_object.'valid-attribute-name-but-not-valid-identifier'? > > The getattr function is meant for when your attribute name is in a > variable. Being able to use strings that aren't valid identifiers is a > side effect. Why do you say it's a side effect? Could you elaborate? I see nothing odd in passing literal (string literal in this case) as a value of function's argument. > Why are you designing classes with attributes that aren't > valid identifiers? Attribute access syntax being very concise is very often preferred to dict's interface. That's why various containers expose their elements as attributes. In my case I'm using in-house web form library which provides FieldSet class holding objects of type Field or other FieldSets. This nesting leads to names of the form 'outer_fieldset-inner_fieldset-third_field' which are not valid identifiers due to minus sign.
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2013-12-03 19:06 -0600 |
| Message-ID | <mailman.3543.1386119133.18130.python-list@python.org> |
| In reply to | #60972 |
On 2013-12-03 15:47, Piotr Dobrogost wrote:
> > The getattr function is meant for when your attribute name is in a
> > variable. Being able to use strings that aren't valid identifiers
> > is a side effect.
>
> Why do you say it's a side effect?
I think random832 is saying that the designed purpose of setattr()
was to dynamically set attributes by name, so they could later be
accessed the traditional way; not designed from the ground-up to
support non-identifier names. But because of the getattr/setattr
machinery (dict key/value pairs), it doesn't prevent you from having
non-identifiers as names as long as you use only the getattr/setattr
method of accessing them.
I see non-traditional-identifiers most frequently in test code where
the globals() dictionary gets injected with various objects for
testing purposes, driven by a table with descriptors. Something like
(untested)
tests = [
dict(desc="Test 1", input=10, expected=42),
dict(desc="Test 2", input=314, expected=159),
]
for test in tests:
test_name = "test_" + test["desc"]
globals()[test_name] = generate_test_function(
test["input"], test["output"])
-tkc
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-04 12:35 -0800 |
| Message-ID | <d13e811f-f496-418a-b737-f4fbf1286cc5@googlegroups.com> |
| In reply to | #60981 |
On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: > > I think random832 is saying that the designed purpose of setattr() > was to dynamically set attributes by name, so they could later be > accessed the traditional way; not designed from the ground-up to > support non-identifier names. But because of the getattr/setattr > machinery (dict key/value pairs), it doesn't prevent you from having > non-identifiers as names as long as you use only the getattr/setattr > method of accessing them. Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too. Regards, Piotr
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-12-04 20:46 +0000 |
| Message-ID | <mailman.3583.1386190006.18130.python-list@python.org> |
| In reply to | #61045 |
On 04/12/2013 20:35, Piotr Dobrogost wrote: > On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: >> >> I think random832 is saying that the designed purpose of setattr() >> was to dynamically set attributes by name, so they could later be >> accessed the traditional way; not designed from the ground-up to >> support non-identifier names. But because of the getattr/setattr >> machinery (dict key/value pairs), it doesn't prevent you from having >> non-identifiers as names as long as you use only the getattr/setattr >> method of accessing them. > > Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too. > > Regards, > Piotr > The obvious thing to do is to either raise this on python ideas, or if you're that confident about it raise an issue on the bug tracker with a patch, which would include changes to unit tests and documentation as well as code, get it reviewed and approved and Bob's your uncle, job done. Too late for Python 3.4 of course, but no problem for 3.5. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Jerry Hill <malaclypse2@gmail.com> |
|---|---|
| Date | 2013-12-04 15:58 -0500 |
| Message-ID | <mailman.3586.1386190722.18130.python-list@python.org> |
| In reply to | #61045 |
On Wed, Dec 4, 2013 at 3:35 PM, Piotr Dobrogost
<p@google-groups-2013.dobrogost.net> wrote:
> Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too.
Given the follow code, what do you think should print?
class My_Class(object):
pass
bar = 1
my_object = My_Class()
setattr(my_object, 'foo', 10)
setattr(my_object, 'bar', 100)
setattr(my_object, 'foo-bar', 1000)
print(my_object.foo-bar)
Today (in python 3.3), it prints 9, because my_object.foo is 10, the
local variable bar is equal to 1, and 10 minus 1 is 9.. Under your
new proposal, it would print 1000, right? Is there any way for your
proposal to be backwards compatible?
--
Jerry
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2013-12-04 13:02 -0800 |
| Message-ID | <mailman.3587.1386192424.18130.python-list@python.org> |
| In reply to | #61045 |
On 12/04/2013 12:58 PM, Jerry Hill wrote: > On Wed, Dec 4, 2013 at 3:35 PM, Piotr Dobrogost > <p@google-groups-2013.dobrogost.net> wrote: >> Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too. > > Given the follow code, what do you think should print? > > class My_Class(object): > pass > > bar = 1 > my_object = My_Class() > setattr(my_object, 'foo', 10) > setattr(my_object, 'bar', 100) > setattr(my_object, 'foo-bar', 1000) > > print(my_object.foo-bar) Actually, under his proposal it would be: print(my_object."foo-bar") and it would print 1000, while yours would still print 9. -- ~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2013-12-04 21:41 +0000 |
| Message-ID | <mailman.3588.1386193334.18130.python-list@python.org> |
| In reply to | #61045 |
On 2013-12-04, Piotr Dobrogost <p@google-groups-2013.dobrogost.net> wrote: > On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: >> >> I think random832 is saying that the designed purpose of setattr() >> was to dynamically set attributes by name, so they could later be >> accessed the traditional way; not designed from the ground-up to >> support non-identifier names. But because of the getattr/setattr >> machinery (dict key/value pairs), it doesn't prevent you from having >> non-identifiers as names as long as you use only the getattr/setattr >> method of accessing them. > > Right. If there's already a way to have attributes with these > "non-standard" names (which is a good thing) At best its a neutral thing. You can use dict for the same purpose with very little effort and no(?) loss of efficiency. > then for uniformity with dot access to attributes with > "standard" names there should be a variant of dot access > allowing to access these "non-standard" named attributes, too. New syntax needs more than theoretical justifications; it needs persuasive use cases. Using invalid identifiers as attributes is generally a bad idea, not something to do commonly. Your proposed syntax leaves the distinction between valid and invalid identifiers a problem the programmer has to deal with. It doesn't unify access to attributes the way the getattr and setattr do. -- Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-04 13:54 -0800 |
| Message-ID | <e106efd6-a604-4ccc-b225-a9a566d43a26@googlegroups.com> |
| In reply to | #61052 |
On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti wrote: > > not something to do commonly. Your proposed syntax leaves the > distinction between valid and invalid identifiers a problem the > programmer has to deal with. It doesn't unify access to > attributes the way the getattr and setattr do. Taking into account that obj.'x' would be equivalent to obj.x any attribute can be accessed with the new syntax. I don't see how this is not unified access compared to using getattr instead dot... Regards, Piotr
[toc] | [prev] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2013-12-06 14:07 +0000 |
| Message-ID | <mailman.3650.1386338903.18130.python-list@python.org> |
| In reply to | #61054 |
On 2013-12-04, Piotr Dobrogost <p@google-groups-2013.dobrogost.net> wrote: > On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti > wrote: >> not something to do commonly. Your proposed syntax leaves the >> distinction between valid and invalid identifiers a problem >> the programmer has to deal with. It doesn't unify access to >> attributes the way the getattr and setattr do. > > Taking into account that obj.'x' would be equivalent to obj.x > any attribute can be accessed with the new syntax. I don't see > how this is not unified access compared to using getattr > instead dot... I thought of that argument later the next day. Your proposal does unify access if the old obj.x syntax is removed. -- Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-06 08:51 -0800 |
| Message-ID | <07ce304a-644b-4e90-8c7d-5d1dcc28ed81@googlegroups.com> |
| In reply to | #61150 |
On Friday, December 6, 2013 3:07:51 PM UTC+1, Neil Cerutti wrote: > On 2013-12-04, Piotr Dobrogost > > <p@google-groups-2013.dobrogost.net> wrote: > > > On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti > > wrote: > > >> not something to do commonly. Your proposed syntax leaves the > >> distinction between valid and invalid identifiers a problem > >> the programmer has to deal with. It doesn't unify access to > > >> attributes the way the getattr and setattr do. > > > > > > Taking into account that obj.'x' would be equivalent to obj.x > > any attribute can be accessed with the new syntax. I don't see > > how this is not unified access compared to using getattr > > instead dot... > > I thought of that argument later the next day. Your proposal does > unify access if the old obj.x syntax is removed. As long as obj.x is a very concise way to get attribute named 'x' from object obj it's somehow odd that identifier x is treated not like identifier but like string literal 'x'. If it were treated like an identifier then we would get attribute with name being value of x instead attribute named 'x'. Making it possible to use string literals in the form obj.'x' as proposed this would make getattr basically needless as long as we use only variable not expression to denote attribute's name. This is just casual remark. Regards, Piotr
[toc] | [prev] | [next] | [standalone]
| From | Rotwang <sg552@hotmail.co.uk> |
|---|---|
| Date | 2013-12-07 00:47 +0000 |
| Message-ID | <l7tr6b$856$1@dont-email.me> |
| In reply to | #61169 |
On 06/12/2013 16:51, Piotr Dobrogost wrote: >> [...] >> >> I thought of that argument later the next day. Your proposal does >> unify access if the old obj.x syntax is removed. > > As long as obj.x is a very concise way to get attribute named 'x' from > object obj it's somehow odd that identifier x is treated not like > identifier but like string literal 'x'. If it were treated like an > identifier then we would get attribute with name being value of x > instead attribute named 'x'. Making it possible to use string literals > in the form obj.'x' as proposed this would make getattr basically > needless as long as we use only variable not expression to denote > attribute's name. But then every time you wanted to get an attribute with a name known at compile time you'd need to write obj.'x' instead of obj.x, thereby requiring two additional keystrokes. Given that the large majority of attribute access Python code uses dot syntax rather than getattr, this seems like it would massively outweigh the eleven keystrokes one saves by writing obj.'x' instead of getattr(obj,'x').
[toc] | [prev] | [next] | [standalone]
| From | Piotr Dobrogost <p@google-groups-2013.dobrogost.net> |
|---|---|
| Date | 2013-12-04 14:13 -0800 |
| Message-ID | <3a27ef53-64b7-4cf3-9879-8452fab458a1@googlegroups.com> |
| In reply to | #61052 |
On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti wrote: > On 2013-12-04, Piotr Dobrogost <> wrote: > > > Right. If there's already a way to have attributes with these > > "non-standard" names (which is a good thing) > > At best its a neutral thing. You can use dict for the same > purpose with very little effort and no(?) loss of efficiency. As much as many people in this topic would like to put equal sign between attributes and dictionary's keys they are not the same thing. AFAIK descriptor protocol works only with attributes, right? Regards, Piotr
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web