Error help

D

danielashiloh

Hi all

This error has been bugging me for days. I know it's minor, but it's reallygetting in the way of my programming. I'm programming a data analysis programme for a psychology experiment which takes pickled data from the experiment and produces averages. For some reason python is insisting there is an indentation error on line 18. I have untabified and retabified and nothing seems to work. Here is the full code:


import cPickle, pickle

print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST'
file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ')
pickle_file=open(file, 'r')
data=cPickle.load(pickle_file)
file_name=file-'pck' + 'txt'
partifipant_info=data'Participant Info']
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']


def firstBlockDifferences():
print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1'
count=0
first_block_differences=[]
total=0
while count<len(first_block_estimates):
differences=float(first_block_estimates[count])-float(first_block_times[count])
if differences >= 180:
differences-=360
elif differences <=-180:
differences+=360
total+=differences
differences=[differences]
first_block_differences+=differences
count+=1
average_diff_first_block=total/len(first_block_estimates)
text_file.write('\nAverage differences for block 1: ', average_diff_first_block)

def secondBlockDifferences():
print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 2'
count=0
second_block_differences=[]
total=0
while count<len(second_block_estimates):
differences=float(second_block_estimates[count])-float(second_block_times[count])
if differences >= 180:
differences-=360
elif differences <=-180:
differences+=360
total+=differences
differences=[differences]
second_block_differences+=differences
count+=1
average_diff_second_block=total/len(second_block_estimates)
text_file.write('\nAverage differences for block 2: ', average_diff_second_block)


text_file=open(file_name, 'w')
text_file.write('\nParticipant info: ', participant_info)
firstBlockDifferences()
secondBlockDifferences()

I apologise for the lack of annotation and it may be a little inefficient, but I am really only after a solution to the error on line 18.

Thanks.
 
P

Peter Otten

This error has been bugging me for days. I know it's minor, but it's
really getting in the way of my programming. I'm programming a data
analysis programme for a psychology experiment which takes pickled data
from the experiment and produces averages. For some reason python is
insisting there is an indentation error on line 18.

I can't confirm that, I get an error in line 8
partifipant_info=data'Participant Info']

where you forgot the opening '['.

Please post your actual code and don't forget to include a cut-and-paste
version of the traceback you get.
 
M

marmata

Hi,
This error has been bugging me for days.

Doesn't look like a tab error but:
partifipant_info=data'Participant Info']

This line is wrong, it should be:

partifipant_info=data['Participant Info']

That's probably what's triggering the error!

Cheers,
]\/[arco
 
D

Dave Angel

Hi all

This error has been bugging me for days. I know it's minor, but it's really getting in the way of my programming. I'm programming a data analysis programme for a psychology experiment which takes pickled data from the experiment and produces averages. For some reason python is insisting there is an indentation error on line 18. I have untabified and retabified and nothing seems to work. Here is the full code:


import cPickle, pickle

print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST'
file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ')
pickle_file=open(file, 'r')
data=cPickle.load(pickle_file)
file_name=file-'pck' + 'txt'
partifipant_info=data'Participant Info']
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']


def firstBlockDifferences():
print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1'
count=0
first_block_differences=[]
total=0
while count<len(first_block_estimates):
differences=float(first_block_estimates[count])-float(first_block_times[count])
if differences >= 180:
differences-=360
elif differences <=-180:
differences+=360
total+=differences
differences=[differences]
first_block_differences+=differences
count+=1
average_diff_first_block=total/len(first_block_estimates)
text_file.write('\nAverage differences for block 1: ', average_diff_first_block)

def secondBlockDifferences():
print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 2'
count=0
second_block_differences=[]
total=0
while count<len(second_block_estimates):
differences=float(second_block_estimates[count])-float(second_block_times[count])
if differences >= 180:
differences-=360
elif differences <=-180:
differences+=360
total+=differences
differences=[differences]
second_block_differences+=differences
count+=1
average_diff_second_block=total/len(second_block_estimates)
text_file.write('\nAverage differences for block 2: ', average_diff_second_block)


text_file=open(file_name, 'w')
text_file.write('\nParticipant info: ', participant_info)
firstBlockDifferences()
secondBlockDifferences()

I apologise for the lack of annotation and it may be a little inefficient, but I am really only after a solution to the error on line 18.

Thanks.

You didn't include the error message, so how are we supposed to know
which line is #18 ? if I take your message literally, it's a blank line.

Even better, you could have reduced the code down to a minimum which
still shows the error.

As your code stands now, I get an error on line 10:

File "daniel.py", line 10
partifipant_info=data'Participant Info']
^
SyntaxError: invalid syntax

It appears you're missing a left bracket.

That line also has a strange spelling for participant, so you'd get an
error later when you tried to use participant_info. Did you by any
chance retype your program into the message? If you don't use
copy/paste, it's useless for us to study your code.

Finally, in case it matters, just what version of python did you use,
and on what OS?
 
P

Philipp Hagemeister

Let's go thorugh this program:

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)
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



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEAREKAAYFAlAaZdsACgkQ9eq1gvr7CFz4DQCeKsleAU3D95lyKkLhPUnrPk1E
YMYAn3VoPHIu7v5H9Q1x5bGXY9fgagmz
=FpE0
-----END PGP SIGNATURE-----
 
D

danielashiloh

(e-mail address removed) wrote:


This error has been bugging me for days. I know it's minor, but it's
really getting in the way of my programming. I'm programming a data
analysis programme for a psychology experiment which takes pickled data
from the experiment and produces averages. For some reason python is
insisting there is an indentation error on line 18.



I can't confirm that, I get an error in line 8


partifipant_info=data'Participant Info']



where you forgot the opening '['.



Please post your actual code and don't forget to include a cut-and-paste

version of the traceback you get.

Thank you, everyone, for the replies. It does seem to stem from that missing bracket, indeed the error did start coming up when I first included that line. Do I feel silly! Incidentally, the error message I got was for an unexpected indent. All is resolved now.
 
D

danielashiloh

(e-mail address removed) wrote:


This error has been bugging me for days. I know it's minor, but it's
really getting in the way of my programming. I'm programming a data
analysis programme for a psychology experiment which takes pickled data
from the experiment and produces averages. For some reason python is
insisting there is an indentation error on line 18.



I can't confirm that, I get an error in line 8


partifipant_info=data'Participant Info']



where you forgot the opening '['.



Please post your actual code and don't forget to include a cut-and-paste

version of the traceback you get.

Thank you, everyone, for the replies. It does seem to stem from that missing bracket, indeed the error did start coming up when I first included that line. Do I feel silly! Incidentally, the error message I got was for an unexpected indent. All is resolved now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top