469,267 Members | 1,059 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

Indentation problem in my code

5
Hello!
I'm a begginer at Python and I'm having some problems with my code.
Can someone try and help me figuring out what is the problem??

Expand|Select|Wrap|Line Numbers
  1. class EndTrial(Dependent(SFBool)):
  2. def __init__(self):
  3.         SFBool.__init__(self)
  4.     def evaluate(self, input):
  5.         if KS.actionKeyRelease==17:
  6.           write_file.write()
  7.           experimentHandle.ftime.close()
  8.           experimentHandle.fposition.close()
  9.           experimentHandle.fforce.close()
  10.           experimentHandle.screen=2
  11.           SCREEN.whichChoice.set(2)
  12.           QuitAPI()
I'm getting an error message in the command line:
"IndentationError: expected an idented block"
with reference to the "if" line.

But when I change the order of the lines, the error messege remain one line after the "evaluate" line so I think it might be the origin.
Plus, there are little red dots before the if line...

Lots of thanks!!
May.
Mar 26 '07 #1
6 1269
bartonc
6,596 Expert 4TB
Hello!
I'm a begginer at Python and I'm having some problems with my code.
Can someone try and help me figuring out what is the problem??

Expand|Select|Wrap|Line Numbers
  1. class EndTrial(Dependent(SFBool)):
  2. def __init__(self):
  3.         SFBool.__init__(self)
  4.     def evaluate(self, input):
  5.         if KS.actionKeyRelease==17:
  6.           write_file.write()
  7.           experimentHandle.ftime.close()
  8.           experimentHandle.fposition.close()
  9.           experimentHandle.fforce.close()
  10.           experimentHandle.screen=2
  11.           SCREEN.whichChoice.set(2)
  12.           QuitAPI()
I'm getting an error message in the command line:
"IndentationError: expected an idented block"
with reference to the "if" line.

But when I change the order of the lines, the error messege remain one line after the "evaluate" line so I think it might be the origin.
Plus, there are little red dots before the if line...

Lots of thanks!!
May.
Hi May. You only have 2 spaces for the indentation in the if block. I have re-indented your post. I also used CODE tags instead of HTML tags. Thanks for posting!
Expand|Select|Wrap|Line Numbers
  1. class EndTrial(Dependent(SFBool)):
  2. def __init__(self):
  3.         SFBool.__init__(self)
  4.     def evaluate(self, input):
  5.         if KS.actionKeyRelease==17:
  6.             write_file.write()
  7.             experimentHandle.ftime.close()
  8.             experimentHandle.fposition.close()
  9.             experimentHandle.fforce.close()
  10.             experimentHandle.screen=2
  11.             SCREEN.whichChoice.set(2)
  12.             QuitAPI()
Mar 26 '07 #2
ghostdog74
511 Expert 256MB
Like the error says, you have indentatoin problem
Expand|Select|Wrap|Line Numbers
  1. class EndTrial(Dependent(SFBool)):
  2.     def __init__(self):
  3.     SFBool.__init__(self)
  4.     def evaluate(self, input):    
  5.         if KS.actionKeyRelease==17:
  6.           write_file.write()
  7.           experimentHandle.ftime.close()
  8.           experimentHandle.fposition.close()
  9.           experimentHandle.fforce.close()
  10.           experimentHandle.screen=2
  11.           SCREEN.whichChoice.set(2)
  12.           QuitAPI()
  13.  
try to use spaces instead of tabs.
Mar 26 '07 #3
karmaB
5
Thank you!
It's working now.
Since my Python knowledge isn't that good, I have problem with understanding the error messages.

Now the message is:
"AttributeError: MFNode instance has no attribute '__getitem__'

My code:
[HTML]import math
import time
import string

#referencing ################################################## ################
DYN=references[1]
TM=references[2]
HD1=refernces[3]
KS=references[4]
TrialN=references[5]
SCREEN=references[6]
# referencing ################################################## ###############

#ExperimentHandle - called every loop from X3D #########################################
class ExperimentHandle(Dependent(SFVec3f)):
def __init__(self):
SFVec3f.__init__(self)
#making the folders for writing
subject_name=raw_input('\n Enter subjects name:')
self.fposition=open('%s_position.txt'%subject_name ,'w')
self.ftime=open('%s_time.txt'%subject_name,'w')
self.fforce=open('%s_force.txt'%subject_name,'w')
##
self.trial=0
self.screen=0
def evaluate(self,input):
if self.screen==1:
#getting the position
self.pos=HD1.weightedProxyPosition.get()
TM.enabled.set(1)
#the time pos storing will be called now each routing cycle from the VRML

#end of ExperimentHandle class definition and creating the class instance ####
experimentHandle=ExperimentHandle()

#Time, position and velocity storing ################################
class Time_Pos_Storing(Dependent(SFTime)):
def __init__(self):
SFTime.__init__(self)
self.pos=[]
self.time=[]
self.flag_time=1
def evaluate(self,inpt):
#position storing
self.pos.append(experimentHandle.pos)
#time storing
if self.flag_time==1:
self.first_time_memory=TM.time.get()
self.flag_time=0
self.time.append(0)
else:
self.time.append(TM.time.get()-self.first_time_memory)

if len(self.pos)>=1:
self.current=self.pos[len(self.pos)-1]

if self.current>-0.1:
gForce.setGforce()
else:
DYN.force.set(Vec3f(0,0,0))
#end of Time, position and velocity storing #########################
t_p_stor=Time_Pos_Storing()

#GForce - creating gravity-like environment ########################
class GForce:
def __init__( self ):
SFVec3f.__init__(self)
self.forceLog=[]
self.g = 9.806
def setGforce( self ):
mass=DYN.mass.get()
gravityForce=self.mass*self.g
DYN.force.set(Vec3f(0,gravityForce,0))
#end of GForce class ###################################
gForce=GForce()

# Writting Data to txt files #######################################

class WriteFile:
def write(self):
for i in t_p_stor.pos:
experimentHandle.fposition.write(str(i.y)+'\n')
for i in t_p_stor.time:
experimentHandle.ftime.write(str(i)+'\n')
for i in gForce.forceLog:
experimentHandle.fforce.write(str(i)+'\n')
# end of WriteFile ############################################
write_file=WriteFile()

# Initializing new trial #####################################
class New_Trial:
def initiate(self):
##writing all the lists to files
write_file.write()
##initiating the list and the variables for next trial
t_p_stor.pos=[]
t_p_stor.time=[]
gForce.forceLog=[]
t_p_stor.flag_time=1
##writing a que in the files for ending a trial
experimentHandle.fposition.write('end of '+str(experimentHandle.trial)+'trial \n')
experimentHandle.ftime.write('end of '+str(experimentHandle.trial)+'trial \n')
experimentHandle.fforce.write('end of '+str(experimentHandle.trial)+'trial \n')
TM.enabled.set(0)

# end of New_trial #########################################
new_trial=New_Trial()

# Starting anf ending trials ####################################
class EndTrial(Dependent(SFBool)):
def __init__(self):
SFBool.__init__(self)
def evaluate(self, input):
if KS.actionKeyRelease==17:
write_file.write()
experimentHandle.ftime.close()
experimentHandle.fposition.close()
experimentHandle.fforce.close()
experimentHandle.screen=2
SCREEN.whichChoice.set(2)
QuitAPI()

endTrial=EndTrial()

class StartTrial( Dependent(SFBool)):
def __init__(self):
SFBool.__init__(self)
def evaluate(self, input):
if KS.actionKeyRelease==16:
experimentHandle.screen=1
SCREEN.whichChoice.set(1)
experimentHandle.trial+=1
TrialN.string.set(str(experimentHandle.trial))
QuitAPI()

startTrial=StartTrial()

# end of EndTrial and StartTrial ###########################[/HTML]
Mar 26 '07 #4
karmaB
5
I forgot to mention that I work with H3D (3D software) as well so the references are from the .x3d file.

I use Python for changing parameters and switching properties.

Thanks again!
Mar 26 '07 #5
karmaB
5
The full error message is:

Traceback <mosr recent call last>:
File "<string>", line 16, in ?
AttributeError: MFNode instance has no atrribute '__getitem__'
Mar 26 '07 #6
bartonc
6,596 Expert 4TB
The full error message is:

Traceback <mosr recent call last>:
File "<string>", line 16, in ?
AttributeError: MFNode instance has no atrribute '__getitem__'
Well, it doesn't look like you've provided there pertainate snippet.

First of all, reference is not defined.
Secondly, an MFNode class object doesn't seem to be instantiated here.
And "File "<string>", line 16, in ?" should tell us which file to look in, but (since it doesn't), I suspect it's in the library that you are using.

Is there a chance that you can narrow down which assignment from references list (or tuple, or whatever) or which class creation is causing the error. Just get close enough to post the pertainate snippet. Thanks.

I'll also need to change the title of this thread soon. Thanks for joining and welcome.
Mar 26 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Magnus Lie Hetland | last post: by
147 posts views Thread by Sateesh | last post: by
177 posts views Thread by C# Learner | last post: by
7 posts views Thread by diffuser78 | last post: by
9 posts views Thread by John Salerno | last post: by
135 posts views Thread by Xah Lee | last post: by
16 posts views Thread by DE | last post: by
4 posts views Thread by bearophileHUGS | last post: by
1 post views Thread by Eric S. Johansson | last post: by
19 posts views Thread by Eric S. Johansson | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.