WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-23-2006, 11:45 AM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Yes, I understand I can use the 'w' flag but what happens when I want to add data to the same data file. I can use the 'w' flag for the first time, but then i'd want to append to the file after that. I tried the 'w' flag and it printed out correctly, but then when I changed it to the 'a' flag, it went back to printing strangely again.

The 'w' flag prints like this:
Subject 12 Condition 1

The 'a' flag prints like this:
Subject Condition
Subject 12 Condition 2
Reply With Quote
  #2  
Old 03-23-2006, 12:07 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Then I'm not sure exactly what you want. You can either append the data to the file using the 'a' flag, or you can override the existing data using the 'w' flag. What other option do you need?
Reply With Quote
  #3  
Old 03-23-2006, 06:57 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Talking

No problem,
I figured out the problem. I had to put those statements in a onkeydown event.

Thanks!
Reply With Quote
  #4  
Old 05-04-2006, 02:23 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
I created this data file but one question I had was whether there was a way to place Headings at the beginning of the file. If you notice right now, there is text (eg 'male count', 'female count', etc) before the actual data used to identify the data that is being shown during a question_data.write() command. Is there a way to only put those headings at the beginning of the data file instead of having them included in the write command. I hope I'm being clear. Here is an example I typed out (attachment)

Code:
#Mark the time that the program was started.
start_time_sec = time.time()
start_time_clock = time.ctime()
#Open a file to collect the data on this subject.
question_data = open('omar_data','a')
#Get the data from the button press.
def mykey(key):
 global autospawn, soldierCount, maleCount, femaleCount
 if key == 'a':
  autospawn = not autospawn
  if autospawn:
   viz.starttimer(SPAWN_TIMER,GetSpawnTime())
  else:
   viz.killtimer(SPAWN_TIMER)
 elif key == 's':
  StartAvatar(randint(0,5))
 elif key == 'q':
  miss_count = bulletCount - avatarsHit
  #print "miss count is", miss_count
  #Use our starting time variable to find out how much
  #time has elapsed.
  elapsed_time_sec = time.time() - start_time_sec
  #elapsed_time_clock = time.ctime(elapsed_time_sec) + time.ctime(start_time_sec)
  final_time_sec = start_time_sec + elapsed_time_sec
  final_time_clock = time.ctime(final_time_sec)
  #Create string lines to put in the data file, depending on which button was pushed.
  subject_data = str(subject) + '\t'  
  start_data = str(start_time_clock) + '\t'
  final_time_data = str(final_time_clock) + '\t'
  avatar_hit_count = str(avatarsHit) + '\t'
  bullet_count_data = str(bulletCount) + '\t'
  miss_count_data = 'miss count ' + str(miss_count) + '\t'
  soldier_Count_data = 'soldier count ' + str(soldierCount) + '\t'
  male_Count_data = 'male count ' + str(maleCount) + '\t'
  female_Count_data = 'female count ' + str(femaleCount) + '\t'  
  threat_Count_data = 'threat count ' + str(threatCount) + '\t'
  nonthreat_Count_data = 'nonthreat count ' + str(nonthreatCount) + '\t\n'
  question_data.write(subject_data)  
  question_data.write(start_data)
  question_data.write(final_time_data)
  question_data.write(avatar_hit_count)
  question_data.write(bullet_count_data)
  question_data.write(miss_count_data)
  question_data.write(soldier_Count_data)
  question_data.write(male_Count_data)
  question_data.write(female_Count_data)
  question_data.write(threat_Count_data)
  question_data.write(nonthreat_Count_data)  
  #Flush the internal buffer.
  question_data.flush() 
  #Close the world.
  viz.quit()
viz.callback(viz.KEYBOARD_EVENT,mykey)
Attached Files
File Type: txt example.txt (484 Bytes, 5665 views)
Reply With Quote
  #5  
Old 05-04-2006, 02:43 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

After you open the file, check if it is empty. If it is then write the headings.
Code:
data = open('test.data','a')

#Seek to end of file
data.seek(0,2)
if data.tell() == 0:
	#File is empty, write heading
	data.write('Column 1\tColumn 2\tColumn 3\n')

data.write('some data')
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC