How do I load a modified python module?
Question: I'm using the widely used module PySerial
(<http://pyserial.sourceforge.net/index.html#>) for serial communication in
Python. One of it's functions is readline() which reads a line until end of
line '\n'. I created a new function readline_v2() similar to readline() in the
same file serialutil.py. But each time I install the module using "python
install setup.py", it seems as if none of the changes are reflected. The new
function is not detected. What am I doing wrong?

I'm using Windows 8 64 bit. I first downloaded pyserial's source, uncompressed
it, and modified it when I found it didn't work the way I wanted it to.

I tried it using pip also, using "pip install pyserial" but once again there
is no change. I made sure I uninstalled the previous version before
reinstalling. The files don't exist in the "C:/python27/lib/site-packages"
folder after the uninstall. I also deleted all compiled/build files I saw in
the serial package before reinstalling.

Note: In "C:/python27/lib/site-packages", after installation, I can see the
change reflected in the specific file serialutil.py. But I still am unable to
call the function.

Note2: serialutil.py consists of functions of the form-

>
>     def readline()
>     def readline_v2()
>  

This is the only place I added my function since the original function
readline() is defined/used nowhere else.

Final Note: I can't find a fix. But I used a workaround. I defined the new
function in my file after doing an "import serial", instead of modifying the
package itself. Not the ideal solution, but it works fine.


Answer: You need to add the location of your new module to path with sys.path.append()
or alternatively keep the new module in your project directory

