Skip to content

Instantly share code, notes, and snippets.

@bound2
Created June 1, 2017 14:44
Show Gist options
  • Save bound2/e5fb117cff2c8a6ec967128524cd2ab9 to your computer and use it in GitHub Desktop.
Save bound2/e5fb117cff2c8a6ec967128524cd2ab9 to your computer and use it in GitHub Desktop.
import ConfigParser
class BasicUser:
def __init__(self, username, password):
self.username = username
self.password = password
def __str__(self):
return "(username={:s}, password={:s})".format(self.username, self.password)
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.username == other.username and self.password == other.password
return NotImplemented
def __ne__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
return NotImplemented
def __hash__(self):
return hash(self.username) + hash(self.password)
def parse_users(config):
users = set()
sections = config.sections()
for section in sections:
user = BasicUser(
config.get(section, "username"),
config.get(section, "password")
)
users.add(user)
return users
config = ConfigParser.ConfigParser()
config.read("ig.ini")
print parse_users(config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment