-3

i have a .properties file that statesserver-ip= and i made a python program that identifies my ipv4, but i want it to go to the proprieties file through the same program and get server-ip=(my ipv4)

import socket    
socket.gethostbyname(hostname)

I've tired many diferent types of solutions, please a need help

FBI
  • 1
  • 1

1 Answers1

1

If .properties doesn't have sections (usually doesn't) you could check this answer: - link

Else, you could use configParser:

import configparser

config = configparser.ConfigParser()
config.read('filename')

host = config['section-name']['server-ip']
andreis11
  • 1,133
  • 1
  • 6
  • 10
  • Thank you it helped alot, but where do i put `server-ip` and where do i put `socket.gethostbyname(hostname)` – FBI Apr 01 '20 at 18:02
  • I think first you would need to store the ip into a variable e.g. server_ip = config['section-name']['server-ip'], then import the variable into the module that you are using (file.py) and then use socket.gethostbyname(server_ip) moew info here [link](https://docs.python.org/3.8/library/socket.html) and configparser [link](http://zetcode.com/python/configparser/) – andreis11 Apr 02 '20 at 04:21