PDA

View Full Version : viz.input


new_horizon
09-20-2011, 08:50 AM
Hi All,

I am trying to enter some code that will allow the experimenter to enter a filename for the test subject - I would like this file name to be the participant number, however, when I input 01 or 02 etc, the program does not run.

Is there a specific command for allowing number entry? I assume the command below only takes care of string?

filename = viz.input('What filename for dataout?')

Thanks

farshizzo
09-21-2011, 09:48 AM
You can manually convert the string to an integer. Example:
strValue = viz.input('Enter a number:')
try:
intValue = int(strValue)
print intValue
except ValueError:
print 'You did not enter a valid number'

new_horizon
09-26-2011, 04:44 AM
Thanks for the reply.

Am I correct in saying however, that you cannot combine an integer and a string to make a file name?

For example if choiceM[selectM] is a string and filename is an integer?

filename = filename + choiceM[selectM]

Thanks

farshizzo
09-27-2011, 10:59 AM
Yes, just convert the integer to a string and then you can concatenate it with another string:
filename = str(filename) + choiceM[selectM]