Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.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; 'elif': 0.04; 'method.': 0.05; 'function,': 0.07; 'strings.': 0.07; 'subject:Error': 0.07; 'subject:help': 0.07; "'w')": 0.09; 'argument,': 0.09; 'command- line': 0.09; 'mode,': 0.09; 'sane': 0.09; 'skip:d 70': 0.09; 'subtract': 0.09; 'wraps': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'skip:f 30': 0.15; "'r')": 0.16; '540': 0.16; 'belongs': 0.16; 'blocks': 0.16; 'filename:fname piece:signature': 0.16; 'generator.': 0.16; 'outputs': 0.16; 'structure.': 0.16; 'stuff.': 0.16; 'later': 0.16; 'wrote:': 0.17; 'skip:p 30': 0.20; 'variable': 0.20; 'import': 0.21; 'assignment': 0.22; 'clock': 0.22; 'option.': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'values': 0.26; 'lines': 0.28; 'arguments.': 0.29; 'pickle': 0.29; 'probably': 0.29; "skip:' 10": 0.30; 'url:python': 0.32; 'file': 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'belong': 0.33; 'another': 0.33; 'skip:d 20': 0.34; 'text': 0.34; 'received:192.168.2': 0.34; 'needed': 0.35; 'skip:f 40': 0.35; 'pm,': 0.35; 'there': 0.35; 'url:org': 0.36; 'smaller': 0.36; 'method': 0.36; 'useful': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'available.': 0.37; 'two': 0.37; 'previous': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'delete': 0.38; 'instead': 0.39; 'received:192': 0.39; 'called': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'back': 0.62; 'differences': 0.65; 'wish': 0.70; 'experiment': 0.84; 'thing,': 0.84; 'average': 0.93; 'url:tutorial': 0.93 Date: Thu, 02 Aug 2012 13:34:50 +0200 From: Philipp Hagemeister User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.5) Gecko/20120624 Icedove/10.0.5 MIME-Version: 1.0 To: danielashiloh@googlemail.com Subject: Re: Error help References: In-Reply-To: X-Enigmail-Version: 1.4 OpenPGP: id=FAFB085C Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig735C8942020D4D301C204E96" Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 122 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343907302 news.xs4all.nl 6989 [2001:888:2000:d::a6]:53168 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26406 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig735C8942020D4D301C204E96 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Let's go thorugh this program: On 08/02/2012 12:58 PM, danielashiloh@googlemail.com wrote: > import cPickle, pickle you probably want to transparently fall back to pickle if cPickle is not available. > print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST' > file=3Draw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALY= SE: ') This should be a command-line option. Look for optparse, or use sys.argv[= 1] > pickle_file=3Dopen(file, 'r') > data=3DcPickle.load(pickle_file) You're opening a file in text mode, and leaking the handle. > file_name=3Dfile-'pck' + 'txt' You cannot subtract strings. You probably want to use + . Also, move this assignment down to where it's needed > partifipant_info=3Ddata'Participant Info'] You later use participant_info. typo? > first_block_data=3Ddata['First block data'] > second_block_data=3Ddata['Second block data'] > first_block_estimates=3Dfirst_block_data['Estimated times'] > first_block_times=3Dfirst_block_data['Actual times'] > second_block_estimates=3Dsecond_block_data['Estimated times'] > second_block_times=3Dsecond_block_data['Actual times'] This is not a useful data structure. You want: blocks =3D [{ 'estimates': data[name]['Estimated times'], 'actuals': data[name]['Actual Times'], } for name in ["First block data", "Second block data"}] or better yet, a sane pickle format. > def firstBlockDifferences(): This method should be called blockDifferences, and take a block as an argument, and return differenes. See http://docs.python.org/tutorial/controlflow.html#defining-functions for an introduction. > print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1'=20 This belongs in the calling method. > count=3D0 > first_block_differences=3D[] > total=3D0 > while count differences=3Dfloat(first_block_estimates[count])-float(first_b= lock_times[count]) > if differences >=3D 180: > differences-=3D360 > elif differences <=3D-180: > differences+=3D360 What if the value is larger than 540 or smaller than -540? > total+=3Ddifferences > differences=3D[differences] This line looks strange. Please use another variable name for values of another type. > first_block_differences+=3Ddifferences If that's all there is to this function, have a look at writing a generator. If you delete the previous line, you can also write jsut first_block_differences.append(differences) > count+=3D1 Not required if you use zip above. > average_diff_first_block=3Dtotal/len(first_block_estimates) > text_file.write('\nAverage differences for block 1: ', average_diff= _first_block) These two lines don't look as if they belong in this method. Better write another one that wraps the calculation and outputs stuff. >=20 > def secondBlockDifferences(): Instead of writing two methods to do the same thing, write one with arguments. > (...) > text_file=3Dopen(file_name, 'w') You're leaking the handle. Use with(open(file_name, 'w')) as text_file: .= > text_file.write('\nParticipant info: ', participant_info) > firstBlockDifferences() > secondBlockDifferences() - Philipp --------------enig735C8942020D4D301C204E96 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEAREKAAYFAlAaZdsACgkQ9eq1gvr7CFz4DQCeKsleAU3D95lyKkLhPUnrPk1E YMYAn3VoPHIu7v5H9Q1x5bGXY9fgagmz =FpE0 -----END PGP SIGNATURE----- --------------enig735C8942020D4D301C204E96--