python - "TypeError: read() takes exactly 1 argument (2 given)" when trying to use read() from subclass -


i'm writing class extends pyserial's serial.serial class, , i'm having trouble using readline() function.

i'm able reproduce problem little code this:

import serial class a(serial.serial):     def read(self):         return super(a, self).readline()  = a() a.read() 

when run code, traceback:

traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "<stdin>", line 3, in read typeerror: read() takes 1 argument (2 given) 

i know i'm missing here. expect pass 1 argument (self). second argument come from?

also, tried using inspect.getcallargs(a.read) figure out second argument, got traceback:

traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "/usr/lib/python2.7/inspect.py", line 900, in getcallargs     args, varargs, varkw, defaults = getargspec(func)   file "/usr/lib/python2.7/inspect.py", line 815, in getargspec     raise typeerror('{!r} not python function'.format(func)) typeerror: <built-in method readline of object @ 0xecf3d0> not python function 

this makes sense, assuming pyserial's readline() native c function or system call. correct in assuming why happens?

serial.read() accepts optional argument, size, default value 1. presumably serial.readline() calls read() method using argument. you've overridden read(), haven't given version size argument, error when readline() calls version of read().

when fix error, you'll have problem recursion; suspect read() method should not call readline().


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -