Pete O'Connell wrote:
Hi I was wondering if anyone could give me some insight as to the best
way to get and save variables from a user the first time a script is
opened. For example if the script prompts something like "What is the
path to the folder?" and the result is held in a variable called
thePath, what is the best way to have that variable saved for all
subsequent uses of the script by the same user.
Pete
------------------------------------------------------------------------
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ConfigParser can read/write config files or using Pickle/cPickle to save
& load your variables or using something like JSON (JavaScript Object
Notation) will do what you want.
For something like just storing a path for future use using ConfigParser
would be perfectly suited to the task.
import ConfigParser
cfg = ConfigParser.ConfigParser()
cfg.read('options.cfg')
if not cfg.sections():
work_path = raw_input('Please enter the workspace path: ')
cfg.add_section('PATH')
cfg.set('PATH', 'workspace', work_path)
f = open('options.cfg', 'w')
cfg.write(f)
f.close()
else:
work_path = cfg.get('PATH', 'workspace')
--
Kind Regards,
Christian Witts
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor