- Posts: 9
- Thank you received: 0
accessing variables in Ini files from python
- rockandsalt
- Topic Author
- Offline
- New Member
-
Less
More
7 years 5 months ago #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 to join the conversation.
7 years 5 months ago #133126
by pl7i92
Replied by pl7i92 on topic accessing variables in Ini files from python
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.
7 years 5 months ago #133205
by BigJohnT
Replied by BigJohnT on topic accessing variables in Ini files from python
Please Log in to join the conversation.
4 years 9 months ago #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 to join the conversation.
2 years 11 months ago #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
Please Log in to join the conversation.
Time to create page: 0.162 seconds
