Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81315 > unrolled thread
| Started by | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| First post | 2014-11-22 21:47 -0500 |
| Last post | 2014-11-23 15:35 +0000 |
| Articles | 8 on this page of 28 — 11 participants |
Back to article view | Back to comp.lang.python
I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 21:47 -0500
Re: I have no class random832@fastmail.us - 2014-11-22 22:08 -0500
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 22:16 -0500
Re: I have no class Rustom Mody <rustompmody@gmail.com> - 2014-11-22 19:09 -0800
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 22:18 -0500
Re: I have no class Ned Batchelder <ned@nedbatchelder.com> - 2014-11-22 22:14 -0500
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 22:35 -0500
Re: I have no class Joel Goldstick <joel.goldstick@gmail.com> - 2014-11-22 22:52 -0500
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 23:15 -0500
Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-23 17:00 +1100
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-23 05:52 -0500
Re: I have no class Dave Angel <davea@davea.name> - 2014-11-23 10:16 -0500
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-23 10:54 -0500
Re: I have no class Dave Angel <davea@davea.name> - 2014-11-23 11:14 -0500
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-23 11:49 -0500
Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-24 03:59 +1100
Re: I have no class Rustom Mody <rustompmody@gmail.com> - 2014-11-23 09:02 -0800
Re: I have no class Steven D'Aprano <steve@pearwood.info> - 2014-11-24 04:21 +0000
Re: I have no class Dave Angel <davea@davea.name> - 2014-11-24 00:11 -0500
Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-24 16:11 +1100
Re: I have no class Dan Sommers <dan@tombstonezero.net> - 2014-11-24 13:44 +0000
Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-25 00:48 +1100
Re: I have no class Dave Angel <davea@davea.name> - 2014-11-24 00:20 -0500
Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-24 16:21 +1100
Re: I have no class Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-24 13:47 -0500
Re: I have no class Rustom Mody <rustompmody@gmail.com> - 2014-11-22 19:55 -0800
Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 23:19 -0500
Re: I have no class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-23 15:35 +0000
Page 2 of 2 — ← Prev page 1 [2]
| From | Dan Sommers <dan@tombstonezero.net> |
|---|---|
| Date | 2014-11-24 13:44 +0000 |
| Message-ID | <m4vcni$97h$1@dont-email.me> |
| In reply to | #81429 |
On Mon, 24 Nov 2014 16:11:32 +1100, Chris Angelico wrote: > On Mon, Nov 24, 2014 at 3:21 PM, Steven D'Aprano <steve@pearwood.info> wrote: >> On Sun, 23 Nov 2014 09:02:57 -0800, Rustom Mody wrote: >> >>> Python is a bit odd in the OO-world in that it prioritizes "Explicit is >>> better than implicit" over convenience. >>> >>> Notice that you use self.throw where in most other OOP languages you >>> would use just throw. >> >> I don't think that is correct. I think that most OOP languages are like >> Python, and use a special variable to reference the current instance: >> >> In some of these languages, the use of "this/self/me" is optional, but >> I'm not aware of *any* OOP language where there is no named reference to >> the current object at all. > > I believe his point is that Python, unlike every other language he can > think of, requires "self.x" instead of just "x". Every language needs > a way to say "current object", but not every language needs you to say > that for every member reference. C++, Pike, and Java let you > short-hand that. (They're all deriving from the same syntactic style > anyway.) JavaScript doesn't, I believe, although its variable scoping > rules are some of the most insane I've ever met, so there might be a > way to shortcut it. If your experience of OO is mainly from C++/Java > family languages, then yes, Python will seem odd. And then, at least in C++, you see coding standards that demand that member variables (aka instance variables aka attributes) be named in such a way that you can tell that they're member variables and not local variables (one common convenstion is that all member variables begin with "m_"). IMO, that's a concession that all that implicitness and convenience just causes confusion. In Python, the names of all instance attributes begin with "self." Dan
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-25 00:48 +1100 |
| Message-ID | <mailman.16249.1416836891.18130.python-list@python.org> |
| In reply to | #81455 |
On Tue, Nov 25, 2014 at 12:44 AM, Dan Sommers <dan@tombstonezero.net> wrote: > And then, at least in C++, you see coding standards that demand that > member variables (aka instance variables aka attributes) be named in > such a way that you can tell that they're member variables and not local > variables (one common convenstion is that all member variables begin > with "m_"). IMO, that's a concession that all that implicitness and > convenience just causes confusion. In Python, the names of all instance > attributes begin with "self." Either that, or it's a concession that bureaucracy has no idea what makes for good code. One or t'other. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-11-24 00:20 -0500 |
| Message-ID | <mailman.16228.1416806448.18130.python-list@python.org> |
| In reply to | #81422 |
On 11/24/2014 12:11 AM, Dave Angel wrote: > On 11/23/2014 11:21 PM, Steven D'Aprano wrote: > >> In some of these languages, the use of "this/self/me" is optional, but >> I'm not aware of *any* OOP language where there is no named reference to >> the current object at all. >> > > The case I found astounding in C++ was in the initializer list where the > line > > value:value > > would assume that the first one was this->value, and the second was a > local named value (usually an argument to the constructor). > > That was rather sloppy. Since this is only used in a constructor, and it appears before the body of the function/method, the second one must be an argument, or else something non-local. Anyway, the construct is a bit of a surprise the first time you see it. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-24 16:21 +1100 |
| Message-ID | <mailman.16229.1416806507.18130.python-list@python.org> |
| In reply to | #81422 |
On Mon, Nov 24, 2014 at 4:11 PM, Dave Angel <davea@davea.name> wrote:
> The case I found astounding in C++ was in the initializer list where the
> line
>
> value:value
>
> would assume that the first one was this->value, and the second was a local
> named value (usually an argument to the constructor).
That's occasionally quite useful. You can create a variable which
shadows another, and reference the original in its initialization, as
a simple means of mocking for debug:
//Maybe a global, or at least at wider scope
string separator="whatever... maybe pulled from a MIME document";
...
{
string separator="** DEBUG **"+separator+"** DEBUG **";
...
code using separator
...
}
You can comment or uncomment the debug line, and everything inside the
braces will be affected by its alteration - but nothing outside them
will, because it's shadowed and not altered. Can be extremely handy.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-11-24 13:47 -0500 |
| Message-ID | <mailman.16256.1416855006.18130.python-list@python.org> |
| In reply to | #81422 |
On 24 Nov 2014 04:21:32 GMT, Steven D'Aprano <steve@pearwood.info>
declaimed the following:
>In any case, Python is not unusual in this regard.
What may be unusual is that the name used is not language defined, as
any name can be used as the first parameter in the method definition.
The other languages (or those I've seen) make the object an implicit
parameter.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-11-22 19:55 -0800 |
| Message-ID | <bf2507c8-2492-4f84-ab36-4304fbf4f2eb@googlegroups.com> |
| In reply to | #81322 |
On Sunday, November 23, 2014 9:06:03 AM UTC+5:30, Seymore4Head wrote:
> Now I am trying to add a dictionary, but it is broke too.
>
> How do I fix:
> class RPS:
> key={0:"rock", 1:"paper",2:"scissors"};
> def __init__(self):
> self.throw=random.randrange(3)
> self.key=key[self.throw]
Maybe you want this?
class RPS:
key ={0:"rock", 1:"paper", 2:"scissors"}
def __init__(self):
self.throw=random.randrange(3)
self.key=RPS.key[self.throw]
Whether reusing 'key' like this is a good idea is another matter!
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-11-22 23:19 -0500 |
| Message-ID | <tsn27a5ci2a4sq3eh7qtffrggtfses1kb2@4ax.com> |
| In reply to | #81325 |
On Sat, 22 Nov 2014 19:55:08 -0800 (PST), Rustom Mody
<rustompmody@gmail.com> wrote:
>On Sunday, November 23, 2014 9:06:03 AM UTC+5:30, Seymore4Head wrote:
>> Now I am trying to add a dictionary, but it is broke too.
>>
>> How do I fix:
>> class RPS:
>> key={0:"rock", 1:"paper",2:"scissors"};
>> def __init__(self):
>> self.throw=random.randrange(3)
>> self.key=key[self.throw]
>
>Maybe you want this?
>
>class RPS:
> key ={0:"rock", 1:"paper", 2:"scissors"}
> def __init__(self):
> self.throw=random.randrange(3)
> self.key=RPS.key[self.throw]
>
>Whether reusing 'key' like this is a good idea is another matter!
That works.
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-11-23 15:35 +0000 |
| Message-ID | <mailman.16187.1416756940.18130.python-list@python.org> |
| In reply to | #81325 |
On 23/11/2014 03:55, Rustom Mody wrote:
> On Sunday, November 23, 2014 9:06:03 AM UTC+5:30, Seymore4Head wrote:
>> Now I am trying to add a dictionary, but it is broke too.
>>
>> How do I fix:
>> class RPS:
>> key={0:"rock", 1:"paper",2:"scissors"};
>> def __init__(self):
>> self.throw=random.randrange(3)
>> self.key=key[self.throw]
>
> Maybe you want this?
>
> class RPS:
> key ={0:"rock", 1:"paper", 2:"scissors"}
> def __init__(self):
> self.throw=random.randrange(3)
> self.key=RPS.key[self.throw]
>
> Whether reusing 'key' like this is a good idea is another matter!
>
As I'm hopeless at thinking of good names to me it's always 'lookup'.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web