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?? - 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()
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.
6 1410
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?? - 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()
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! - 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()
Like the error says, you have indentatoin problem -
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()
-
try to use spaces instead of tabs.
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]
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!
The full error message is:
Traceback <mosr recent call last>:
File "<string>", line 16, in ?
AttributeError: MFNode instance has no atrribute '__getitem__'
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: DE |
last post by:
Hello,
Here is what I do in C++ and can not right now in python :
pushMatrix()
{
drawStuff();
pushMatrix();
{
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |