WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-17-2013, 12:49 PM
dig dig is offline
Member
 
Join Date: Apr 2006
Posts: 15
input from a text file

Hi there
I'm designing an experiment in which I read input values off a text file. The text file has 5 columns, the first two containing numbers and the other 3 Greek words. I use the following code:
s = line.split()
myTrial = [float(s[0]),float(s[1]),s[2],s[3],s[4]]

But, I'm running into a problem. If I save the the text file in ANSI format then the numbers are read correctly but the words when displayed by vizard come up as scrambled characters. If I save the text file in UTF-8 then the text shows up correctly in Greek but then vizard gives me an error when reading the numbers (I know that the text shows up correctly because I tried a text file without the numbers and it works fine).

I don't know much about character encoding so I'm not sure if there is an easy solution to this problem. One option is to have numbers and text in separate text files but this defeats the purpose of my using an input file to simplify experiment design. Any ideas?
Thanks in advance!
marios
Reply With Quote
  #2  
Old 10-17-2013, 06:15 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Try encoding to ascii before converting to float:
Code:
asciidata=s[0].encode("ascii","ignore")
number = float(asciidata)
Reply With Quote
  #3  
Old 10-18-2013, 02:03 AM
dig dig is offline
Member
 
Join Date: Apr 2006
Posts: 15
Thanks for the reply Jeff. Unfortunately, it doesn't seem to work (unless I did something stupid of course). Here's my code:

for line in JRDfile:
s = line.split()
asciidata0=s[0].encode("ascii","ignore")
asciidata1=s[1].encode("ascii","ignore")
thisTrial = [float(asciidata0),float(asciidata1),s[2],s[3],s[4]]
JRDTrials.append(thisTrial)

And here's the error message I get:

Traceback (most recent call last):
File "<string>", line 11, in ?
File "Anthi_JRD.py", line 41, in ?
asciidata0=s[0].encode("ascii","ignore")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)

Note the the text file I'm trying to read from is in UTF-8 format.
Cheers,
marios
Reply With Quote
  #4  
Old 10-18-2013, 02:06 AM
dig dig is offline
Member
 
Join Date: Apr 2006
Posts: 15
Just to clarify that indentation in the for loop went away when I copied-pasted from my script. So, there's no problem there.
Reply With Quote
  #5  
Old 10-18-2013, 10:36 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
That code worked for me in Vizard 4 (python 2.7) but produced the same error in Vizard 3 (python 2.4). Are you using Vizard 4?
Reply With Quote
  #6  
Old 10-20-2013, 02:20 AM
dig dig is offline
Member
 
Join Date: Apr 2006
Posts: 15
Hi Jeff, I tried it with Vizard 3 at home and got the error message). I have Vizard 4 at the lab, I will try it there on Monday. Thanks!
Reply With Quote
Reply

Tags
foreign text, text input

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
Use saved text file data as replay sources problem mizutani_jun Vizard 4 10-14-2010 05:49 PM
problems with output to a text file within executable Saz Vizard 1 07-01-2009 12:01 PM
How to input several model files and then save one output file mspusch Vizard 1 07-15-2008 11:30 PM
file input vsully Vizard 1 12-21-2004 11:51 PM
I cannot show wrl file with text node sled Vizard 3 06-25-2003 08:52 AM


All times are GMT -7. The time now is 08:52 AM.


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