Last active
January 3, 2019 09:31
-
-
Save brunakov/a82fe38ac89d65511602353f4d9a075a to your computer and use it in GitHub Desktop.
try/except use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Query: | |
def __init__(self, data): | |
try: | |
self.message = int(data, 16) | |
except ValueError as e: | |
print("You can't have empty strings for conversion") | |
class Poll: | |
def __init__(self, idx, query_data): | |
self.id = idx | |
self.query = self._get_query(query_data) | |
def _get_query(self, query_data): | |
try: | |
q = Query(query_data) | |
return q | |
except Exception as e: | |
print("Can't create query on poll with id:", self.id) | |
if __name__ == '__main__': | |
p = Poll(1, "") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Query: | |
def __init__(self, data): | |
self.message = int(data, 16) | |
class Poll: | |
def __init__(self, idx, query_data): | |
self.id = idx | |
self.query = self._get_query(query_data) | |
def _get_query(self, query_data): | |
try: | |
q = Query(query_data) | |
return q | |
except ValueError as e: | |
print('invalid literal for int() with base 16') | |
except Exception as e: | |
print("Can't create query on poll with id:", self.id) | |
if __name__ == '__main__': | |
p = Poll(1, "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Query: | |
def __init__(self, data,id): | |
try: | |
self.message = int(data, 16) | |
except ValueError as e: | |
print("Can't create query on poll with id:", id) | |
print("You can't have empty strings for conversion") | |
class Poll: | |
def __init__(self, idx, query_data): | |
self.id = idx | |
self.query = self._get_query(query_data) | |
def _get_query(self, query_data): | |
q = Query(query_data,self.id) | |
return q | |
if __name__ == '__main__': | |
p = Poll(1, "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Query: | |
def __init__(self, data, id): | |
try: | |
self.body = data[2:4] | |
self.x = self.body[3] | |
self.message = int(data, 16) | |
except ValueError as e: | |
print("Can't create query on poll with id:", id) | |
print("You can't have empty strings for conversion") | |
except IndexError as e: | |
print("Can't create query on poll with id:", id) | |
print("Can't create x. Body index out of range") | |
class Poll: | |
def __init__(self, idx, query_data): | |
self.id = idx | |
self.query = self._get_query(query_data) | |
def _get_query(self, query_data): | |
q = Query(query_data, self.id) | |
return q | |
if __name__ == '__main__': | |
p = Poll(1, "") | |
if __name__ == '__main__': | |
p = Poll(1, "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment