Mar-01-2018, 05:43 PM
(This post was last modified: Mar-01-2018, 07:07 PM by Gribouillis.)
(Mar-01-2018, 02:25 PM)Robo_Pi Wrote: I would also like to learn more about how to create and implement a configuration file that Gribouillis had suggested for the file path names and global variables.Here is a way to do this. You first create a configuration file such as this one
Output:# alysha.conf
[tasks]
command_file = C:/100_Robo_pass/Commands.txt
This file can be somewhere on your filesystem such as YOURHOMEDIR/.config/alysha.d/alysha.conf
Your program can then read the configuration file by using python's configparser module. For python 2 it reads
from ConfigParser import SafeConfigParser import os from os.path import join as pjoin conf_filename = pjoin( os.path.expanduser('~'), '.config', 'alysha.d', 'alysha.conf') conf = SafeConfigParser() conf.read(conf_filename) command_filename = conf.get('tasks', 'command_file')The location of the configuration file can be fined-tuned later, for example the program can have a command line option to override the default location, different locations can be tried such as the current working directory or some other standard place. The above code gives you a simple start to using a configuration file for your application. You can also read this overview of configparser.