473,461 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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

Similar topics

0
by: Magnus Lie Hetland | last post by:
Not many members on the Atox mailing list yet, so I'll venture a request here... In Atox 0.2, I've added support for indentation tokens (somewhat like the Python indentation scheme, but a bit...
147
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
7
by: diffuser78 | last post by:
I am a newbie to Python. I am mainly using Eric as the IDE for coding. Also, using VIM and gedit sometimes. I had this wierd problem of indentation. My code was 100% right but it wont run...
9
by: John Salerno | last post by:
How do you make a single string span multiple lines, but also allow yourself to indent the second (third, etc.) lines so that it lines up where you want it, without causing the newlines and tabs or...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
16
by: DE | last post by:
Hello, Here is what I do in C++ and can not right now in python : pushMatrix() { drawStuff(); pushMatrix(); {
4
by: bearophileHUGS | last post by:
This is the best praise of semantic indentation I have read so far, by Chris Okasaki: http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html A quotation: I have...
1
by: Eric S. Johansson | last post by:
in trying to make programming in Python more accessible to disabled programmers (specifically mobility impaired speech recognition users), and hitting a bit of a wall. The wall (for today) is...
19
by: Eric S. Johansson | last post by:
Almar Klein wrote: there's nothing like self interest to drive one's initiative. :-) 14 years with speech recognition and counting. I'm so looking to my 15th anniversary of being injured next...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.