Thread: Data Files
View Single Post
  #6  
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, 1570 views)
Reply With Quote