accessing variables in Ini files from python

More
7 years 5 months ago #133108 by rockandsalt
Hi,

I would like to know if it is possible to access variables in the INI file using python.

I know it can be done using O-word in this example .

cheers

Please Log in to join the conversation.

More
7 years 5 months ago #133126 by pl7i92
welcome frech boarder and deep dive into
Code:
import sys import linuxcnc inifile = linuxcnc.ini(sys.argv[1]) # inifile.find() returns None if the key wasnt found - the # following idiom is useful for setting a default value: machine_name = inifile.find('EMC', 'MACHINE') or "unknown" print "machine name: ", machine_name # inifile.findall() returns a list of matches, or an empty list # if the key wasnt found: extensions = inifile.findall("FILTER", "PROGRAM_EXTENSION") print "extensions: ", extensions # override default NML file by ini parameter if given nmlfile = inifile.find("EMC", "NML_FILE") if nmlfile: linuxcnc.nmlfile = os.path.join(os.path.dirname(sys.argv[1]), nmlfile)

Please Log in to join the conversation.

More
7 years 5 months ago #133205 by BigJohnT

Please Log in to join the conversation.

More
4 years 9 months ago #230859 by harry4516
inifile = linuxcnc.ini(sys.argv[1])

gives an error message: index out of range

is there any change in the actual linuxcnc version, or what is missing?

Please Log in to join the conversation.

More
2 years 11 months ago #284333 by Talla
Hallo Harry,
u can use the path to your machine.ini.
Example:
inifile = linuxcnc.ini('/home/cnc/linuxcnc/configs/testmachine/testmachine.ini')
greetings Peter

Please Log in to join the conversation.

Time to create page: 0.162 seconds
Powered by Kunena Forum