I have a class which has the function of parsing data.
class DataContainer(object):
def parser1(data):
# Handle data in one way
self.parsed_data = parsed_data
def parser2(data):
# Handle data another way
self.parsed_data = parsed_data
The parser functions popular the instance variables of the class. This parser may be changed or have many variations, so I would like to import another file with the functions, something like this:
class DataContainer(object):
import parsers # Contains all the parsing functions which can then be called from instances
Is there a particular 'pythonic' way to do this?
self.NameErrors. But to answer your question, no there isn't because what you are trying to do isn't Pythonic. What is better about having the methods in a different file rather than just in the class? What problem does this solve? Why is this even a class if it has no attributes?