Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66736

Re: Cannot figure out line of code, also not understanding error

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <vincent.vandevyvre@swing.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'subject:not': 0.03; 'else:': 0.03; 'syntax': 0.04; 'elif': 0.05; 'url:launchpad': 0.05; 'subject:code': 0.07; 'here?': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; "'-'": 0.16; "':'": 0.16; '__future__': 0.16; 'from:addr:swing.be': 0.16; 'from:addr:vincent.vandevyvre': 0.16; 'from:name:vincent vande vyvre': 0.16; 'ioerror:': 0.16; 'message-id:@swing.be': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'received:mobistar.be': 0.16; 'subject:skip:u 10': 0.16; 'syntaxerror:': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; '\xe9crit': 0.16; 'examples': 0.20; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'code:': 0.26; 'header :In-Reply-To:1': 0.27; 'fastest': 0.30; 'along': 0.30; 'code': 0.31; 'getting': 0.31; 'helpful.': 0.31; 'time:': 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; 'text': 0.33; 'are:': 0.33; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'except': 0.35; 'located': 0.36; 'doing': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'explain': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'here:': 0.62; 'times': 0.62; 'making': 0.63; 'invalid': 0.68; 'skip:r 40': 0.68; 'skip:r 30': 0.69
Date Thu, 20 Feb 2014 08:56:57 +0100
From Vincent Vande Vyvre <vincent.vandevyvre@swing.be>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Cannot figure out line of code, also not understanding error
References <da9b6b96-7e9a-4094-a3f4-74cdedaf869e@googlegroups.com>
In-Reply-To <da9b6b96-7e9a-4094-a3f4-74cdedaf869e@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7175.1392883488.18130.python-list@python.org> (permalink)
Lines 88
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392883488 news.xs4all.nl 2884 [2001:888:2000:d::a6]:49441
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66736

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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