Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66736
| Date | 2014-02-20 08:56 +0100 |
|---|---|
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
| Subject | Re: Cannot figure out line of code, also not understanding error |
| References | <da9b6b96-7e9a-4094-a3f4-74cdedaf869e@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7175.1392883488.18130.python-list@python.org> (permalink) |
Le 20/02/2014 08:32, ApathyBear a écrit :
> I have two questions that come along with the following code:
>
> ----------------------------------------------------------------------
>
> from __future__ import print_function
>
> def sanitize(time):
> if '-' in time:
> splitter = '-'
> (mins,secs) = time.split(splitter, 1)
> return (mins+'.'+secs)
> elif ':' in time:
> splitter = ':'
> (mins,secs) = time.split(splitter, 1)
> return (mins+'.'+secs)
> else:
> return time
>
>
> #start class
> class Athlete:
> def __init__(self, a_name, a_dob=None, a_times=[]):
> self.name = a_name
> self.dob= a_dob
> self.times = a_times
>
> def top3(self):
> return(sorted(set([sanitize(t) for t in self.times]))[0:3])
> #end class
>
> 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)
>
> except IOError:
> print ('File error')
> return (None)
>
> james = get_coach_data('james2.txt')
>
> print (james.name + "'s fastest times are: " + str(james.top3()))
>
>
> ----------------------------------------------------------------------
> This is the original text file data I am working with called james2.txt located on my desktop:
>
> James Lee,2002-3-14,2-34,3:21,2.34,2.45,3.01,2:01,2:01,3:10,2-22,2-01,2.01,2:16
>
>
>
>
> ----------------------------------------------------------------------
>
>
>
>
>
> 1. What does this line of code mean:
> return(Athlete(temp1.pop(0),temp1.pop(0), temp1)
>
> Is it making an Athlete class? if you can give examples to help explain what this is doing that would be helpful.
>
>
>
>
> 2. Why am I getting this error when I try to run the file?
> PS C:\Users\N\desktop> python gg.py
> File "gg.py", line 34
> except IOError:
> ^
> SyntaxError: invalid syntax
> PS C:\Users\N\desktop>
>
> What syntax is invalid here?
One parenthesis missing here:
return(Athlete(temp1.pop(0),temp1.pop(0), temp1))
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
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