Q:

Python not running as main for a pyserial class

I have made a small class to open a serial port (ttyUSB0) on python, but when I try to run it as main it gives me back a whole lot of stuff I really don't know.
I want the class to create a Serial port instance when I run it and have the propper functions (or methods) give me back what I ask them to with the classe's instance. instead I'm getting the output below when I run:
$ python3  entrada.py

How do I make it run as I intend it to? 
Here's the code for entrada.py
import serial #for port opening
import sys #for exceptions

from collections import __main__
#

#configure the serial connections (the parameters differs on the device you are connecting to)

class Serializer: 
    def __init__(self, port, baudrate=9600, timeout=5): 
        self.port = serial.Serial(port = port, baudrate=baudrate, 
        timeout=timeout, writeTimeout=timeout)

    def open(self): 
        ''' Open the serial port.'''
        self.port.open()

    def close(self): 
        ''' Close the serial port.'''
        self.port.close() 

    def send(self, msg):
        self.prot.write(msg)

    def recv(self):
        return self.port.readline()

PORT = '/dev/ttyUSB0' #Esto puede necesitar cambiarse

def main():
    test_port = Serializer(port = PORT)
    try:
        test_port().open()
    except:
        print ("Could not open serial port: ", sys.exc_info()[0])
        sys.exit(2)

    while True:
        print(test_port.recv())

if __name__ == __main__:
    main()

and here's the output:
from builtins import property as _property, tuple as _tuple
from operator import itemgetter as _itemgetter
from collections import OrderedDict

class Point(tuple):
    'Point(x, y)'

    __slots__ = ()

    _fields = ('x', 'y')

    def __new__(_cls, x, y):
        'Create new instance of Point(x, y)'
        return _tuple.__new__(_cls, (x, y))

    @classmethod
    def _make(cls, iterable, new=tuple.__new__, len=len):
        'Make a new Point object from a sequence or iterable'
        result = new(cls, iterable)
        if len(result) != 2:
            raise TypeError('Expected 2 arguments, got %d' % len(result))
        return result

    def _replace(_self, **kwds):
        'Return a new Point object replacing specified fields with new values'
        result = _self._make(map(kwds.pop, ('x', 'y'), _self))
        if kwds:
            raise ValueError('Got unexpected field names: %r' % list(kwds))
        return result

    def __repr__(self):
        'Return a nicely formatted representation string'
        return self.__class__.__name__ + '(x=%r, y=%r)' % self

    @property
    def __dict__(self):
        'A new OrderedDict mapping field names to their values'
        return OrderedDict(zip(self._fields, self))

    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values.'
        return self.__dict__

    def __getnewargs__(self):
        'Return self as a plain tuple.  Used by copy and pickle.'
        return tuple(self)

    def __getstate__(self):
        'Exclude the OrderedDict from pickling'
        return None

    x = _property(_itemgetter(0), doc='Alias for field number 0')

    y = _property(_itemgetter(1), doc='Alias for field number 1')

Point: x= 3.000  y= 4.000  hypot= 5.000
Point: x=14.000  y= 0.714  hypot=14.018
Point(x=100, y=22)
Point3D(x, y, z)
TestResults(failed=0, attempted=66)

Thanks for the help.

A:

if __name__ == "__main__":
   do_it()

im suprised if __name__ == __main__: didnt give you an error about undefined __main__

