WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-21-2008, 02:03 PM
adimov adimov is offline
Member
 
Join Date: Sep 2003
Location: Santa Barbara, CA
Posts: 11
Writing text files with executable

Hi,

I'm trying to generate a text file via an executable but it is not creating a file. Here's the code (the main code, a Parser module and how the the input csv file should look):

import viz
import Parser

viz.go()


def CreateTemplate():
# Creates a sequence of zeroes and ones based on the duration and SampleRate and the input data
length = int(duration+1)
print "Duration: " + str(length)
outputsequence = []
for i in range (0, length):
if (i in sequence):
outputsequence.append(1.0)
print "SUCCESS: " + str(i)
else:
outputsequence.append(0.0)
return outputsequence


sequence = Parser.getSequence()
print sequence
duration = max(sequence)

CreateTemplate()

# Opens file 'response.txt' in write mode
file = open('response.txt', 'w')




# Define a function that saves data
def SaveData():
# Create the output string
data = CreateTemplate()
for each in data:
out = str(each) + '\n'
# Write the string to the output file
file.write(out)
# Makes sure the file data is really written to the harddrive
file.flush()
print "DONE"


# Define a function that is called every time a keyboard button is pressed
def mykeyboard(key):
# Calls the function SaveData and hands it the current time and key
if key==' ':
SaveData()

# Defines a callback for keyboard events
viz.callback(viz.KEYBOARD_EVENT, mykeyboard)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

import csv
import viz
SampleRate = 1.0 # samples per msec

def getSequence(name = 'inputdata.csv', language = 'English'):
mesg = viz.input('Enter the filename:')
name = str(mesg)
sequence = []
sequenceFile = open(name)
reader = csv.reader(sequenceFile)
for line in reader:
# adjust the resolution of the input based on sample rate
# We have to basically multiply each element in the input sequence by
# the SampleRate (defined as samples per msec and assuming all input is in msec)
# and use that integer result
sequence.append(int(SampleRate*float(line[0])))
return sequence


if __name__ == "__main__":
#testing code
sequence = getSequence()
for item in sequence:
print item

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
csv file:

1
2
3
8
9
Reply With Quote
  #2  
Old 03-21-2008, 03:21 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You need to prepend the publish EXE path to the filename, otherwise the file will be saved to the current directory, which is in a temp folder. Here is some code to get the full path to a file in a published EXE:
Code:
def getPublishedPath(filename):
	publishPath = viz.getOption('viz.publish.path','')
	if publishPath:
		return '/'.join([publishPath,filename])
	return filename

file = open(getPublishedPath('response.txt'), 'w')
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
text output jaclyn.bill Vizard 2 10-24-2007 06:37 AM
Error when playing wav files...? vjonshih Vizard 1 05-23-2005 12:21 PM
loading large wav files in vizard tommahhh Vizard 1 05-16-2005 03:23 PM
3d Text with Transparent Borders vjosh Vizard 3 12-01-2004 10:50 AM
Including Files that Include Other Files vjosh Vizard 1 09-21-2004 04:44 PM


All times are GMT -7. The time now is 10:07 AM.


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