accessing variables in Ini files from python
- rockandsalt
- Offline
- New Member
-
Less
More
- Posts: 9
- Thank you received: 0
08 May 2019 01:42 #133108
by rockandsalt
accessing variables in Ini files from python was created 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
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.
08 May 2019 11:08 #133126
by pl7i92
Replied by pl7i92 on topic accessing variables in Ini files from python
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.
08 May 2019 23:33 #133205
by BigJohnT
Replied by BigJohnT on topic accessing variables in Ini files from python
The following user(s) said Thank You: rockandsalt
Please Log in or Create an account to join the conversation.
05 Jan 2022 12:31 #230859
by harry4516
Replied by harry4516 on topic accessing variables in Ini files from python
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?
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.
02 Nov 2023 14:39 - 02 Nov 2023 14:40 #284333
by Talla
Replied by Talla on topic accessing variables in Ini files from python
Hallo Harry,
u can use the path to your machine.ini.
Example:
inifile = linuxcnc.ini('/home/cnc/linuxcnc/configs/testmachine/testmachine.ini')
greetings Peter
u can use the path to your machine.ini.
Example:
inifile = linuxcnc.ini('/home/cnc/linuxcnc/configs/testmachine/testmachine.ini')
greetings Peter
Last edit: 02 Nov 2023 14:40 by Talla.
Please Log in or Create an account to join the conversation.
Time to create page: 0.102 seconds