hatop issue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: hatop issue (/thread-22824.html) |
RE: hatop issue - deepakkr3110 - Nov-28-2019 i just want that i don't want to give full path of my sock file every time while running this program, i just want to run via my program_name.py and it will read the sock path from a file called abc.ini or .txt and print the output. Thats it! RE: hatop issue - Gribouillis - Nov-28-2019 deepakkr3110 Wrote:i just want that i don't want to give full path of my sock file every time while running this program, i just want to run via my program_name.py and it will read the sock path from a file called abc.ini or .txt and print the output. Thats it!Then you need to learn how to use configuration files in python. There are several ways. Configparser is the simplest tool to do this. Another solution is json. All this is very well documented but you need to invest the minimal effort to run the examples. RE: hatop issue - deepakkr3110 - Nov-28-2019 ok, thank you so much for your time. RE: hatop issue - Gribouillis - Nov-28-2019 Sorry I just see that I mistyped config.read('spam', 'sockets') instead of config.get('spam', 'socket') . It may work better this way!
RE: hatop issue - deepakkr3110 - Nov-28-2019 yeah its print the socket file path https://github.com/JamesBarwell/haproxy-status.py see Example output i want this output also RE: hatop issue - Gribouillis - Nov-28-2019 Once you've read the path to the sockets from the configuration file, you need to use them as arguments to the main() function instead of sys.argv[1:]. You're not James Barwell, are you? RE: hatop issue - deepakkr3110 - Nov-28-2019 for filename in sys.argv[1:]: readfile(sockets)like this? or can you show me some example. RE: hatop issue - Malt - Nov-28-2019 (Nov-28-2019, 07:03 AM)Gribouillis Wrote: If I understand the question well, you want to read the paths to the sockets in an external file. You can use a configuration file for this and the configparser module Here replace read with get method i.e, sockets = config.get('spam', 'sockets')
RE: hatop issue - deepakkr3110 - Nov-28-2019 yes its print the path but i want output like this https://github.com/JamesBarwell/haproxy-status.py i just want that i don't want to give full path of my sock file every time while running this program, i just want to run via my program_name.py and it will read the sock path from a file called abc.ini or .txt and print the output. Thats it! @Malt RE: hatop issue - deepakkr3110 - Nov-29-2019 i just want that i don't want to give full path of my sock file every time while running this program, i just want to run via my program_name.py and it will read the sock path from a file called abc.ini or .txt and print the output. Thats it! @Malt |