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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 . Qarte . PaQager