accessing variables in Ini files from python

More
08 May 2019 01:42 #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 or Create an account to join the conversation.

More
08 May 2019 11:08 #133126 by pl7i92
welcome frech boarder and deep dive into
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)
The following user(s) said Thank You: rockandsalt

Please Log in or Create an account to join the conversation.

More
08 May 2019 23:33 #133205 by BigJohnT
The following user(s) said Thank You: rockandsalt

Please Log in or Create an account to join the conversation.

More
05 Jan 2022 12:31 #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 or Create an account to join the conversation.

Time to create page: 0.054 seconds
Powered by Kunena Forum