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


Groups > comp.lang.python > #26406

Re: Error help

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 <phihag@phihag.de>
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 <phihag@phihag.de>
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 <ec01d1a9-f9e4-41ef-9e8a-71787bcd1aa9@googlegroups.com>
In-Reply-To <ec01d1a9-f9e4-41ef-9e8a-71787bcd1aa9@googlegroups.com>
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 <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2873.1343907302.4697.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ')
This should be a command-line option. Look for optparse, or use sys.argv[1]

> pickle_file=open(file, 'r')
> data=cPickle.load(pickle_file)
You're opening a file in text mode, and leaking the handle.

> file_name=file-'pck' + 'txt'
You cannot subtract strings. You probably want to use + . Also, move
this assignment down to where it's needed

> partifipant_info=data'Participant Info']
You later use participant_info. typo?

> first_block_data=data['First block data']
> second_block_data=data['Second block data']
> first_block_estimates=first_block_data['Estimated times']
> first_block_times=first_block_data['Actual times']
> second_block_estimates=second_block_data['Estimated times']
> second_block_times=second_block_data['Actual times']

This is not a useful data structure. You want:

blocks = [{
  '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' 
This belongs in the calling method.

>     count=0
>     first_block_differences=[]
>     total=0
>     while count<len(first_block_estimates):
You want to use zip here, like
for estimate,actual in zip(block['estimates'], block['actuals']):

>         differences=float(first_block_estimates[count])-float(first_block_times[count])
>         if differences >= 180:
>             differences-=360
>         elif differences <=-180:
>             differences+=360
What if the value is larger than 540 or smaller than -540?
>         total+=differences

>         differences=[differences]
This line looks strange. Please use another variable name for values of
another type.

>         first_block_differences+=differences
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+=1
Not required if you use zip above.

>     average_diff_first_block=total/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.

> 
> def secondBlockDifferences():
Instead of writing two methods to do the same thing, write one with
arguments.
>     (...)

> text_file=open(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


Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Error help danielashiloh@googlemail.com - 2012-08-02 03:58 -0700
  Re: Error help marmata@gmail.com - 2012-08-02 04:23 -0700
  Re: Error help Peter Otten <__peter__@web.de> - 2012-08-02 13:18 +0200
    Re: Error help danielashiloh@googlemail.com - 2012-08-02 06:12 -0700
    Re: Error help danielashiloh@googlemail.com - 2012-08-02 06:12 -0700
  Re: Error help Dave Angel <d@davea.name> - 2012-08-02 07:27 -0400
  Re: Error help Philipp Hagemeister <phihag@phihag.de> - 2012-08-02 13:34 +0200

csiph-web