Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66774
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: Cannot figure out line of code, also not understanding error |
| Date | 2014-02-20 11:50 -0500 |
| Organization | news.gmane.org |
| References | <da9b6b96-7e9a-4094-a3f4-74cdedaf869e@googlegroups.com> <ef956f04-414f-47ff-a813-bfa1152d2f29@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7197.1392914797.18130.python-list@python.org> (permalink) |
ApathyBear <nirchernia@gmail.com> Wrote in message:
>
> On Thursday, February 20, 2014 12:54:54 AM UTC-8, Chris Angelico wrote:
>
>>Calling a class will create a new instance of it. [1] What you do with
>>it afterwards is separate.
>
> Okay. So what you are saying is that return(Athlete(temp1.pop(0),temp1.pop(0), temp1)) IS in fact creating an instance of Athlete. My problem with this is that there really is no declaration of 'self' for this instance.
>
>
> Usually when I do something like this.
> x = Athlete("Henry", "11-15-90", [1,2,3])
> I can refer to things of this instance by executing x.name or whatever other attributes the class defined.
>
> If I create an instance with no 'self' how does this make any sense? How would I get an attribute for the our instance above?
>
The code you're describing is inside a function:
def get_coach_data(filename):
try:
with open(filename) as f:
data = f.readline()
temp1 = data.strip().split(',')
return Athlete(temp1.pop(0),temp1.pop(0), temp1)
So the caller might be doing something like
x = get_coach_data ("myfile.txt")
The return statement you're asking about returns a new instance of
Athlete, which gets assigned to x. Then you may try x.data or
equivalent if you like.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Cannot figure out line of code, also not understanding error ApathyBear <nirchernia@gmail.com> - 2014-02-19 23:32 -0800
Re: Cannot figure out line of code, also not understanding error Chris Angelico <rosuav@gmail.com> - 2014-02-20 19:03 +1100
Re: Cannot figure out line of code, also not understanding error Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2014-02-20 08:56 +0100
Re: Cannot figure out line of code, also not understanding error ApathyBear <nirchernia@gmail.com> - 2014-02-20 00:26 -0800
Re: Cannot figure out line of code, also not understanding error Chris Angelico <rosuav@gmail.com> - 2014-02-20 19:54 +1100
Re: Cannot figure out line of code, also not understanding error Gary Herron <gary.herron@islandtraining.com> - 2014-02-20 01:04 -0800
Re: Cannot figure out line of code, also not understanding error ApathyBear <nirchernia@gmail.com> - 2014-02-20 01:22 -0800
Re: Cannot figure out line of code, also not understanding error Chris Angelico <rosuav@gmail.com> - 2014-02-20 20:41 +1100
Re: Cannot figure out line of code, also not understanding error Dave Angel <davea@davea.name> - 2014-02-20 11:50 -0500
Re: Cannot figure out line of code, also not understanding error ApathyBear <nirchernia@gmail.com> - 2014-02-20 02:13 -0800
csiph-web