benschneider / PyGnuplot

Python interface to gnuplot
MIT License
45 stars 18 forks source link

support in python3 #4

Closed zhashuyu closed 7 years ago

zhashuyu commented 7 years ago

hi, is this going to support python3?

benschneider commented 7 years ago

Will run some tests on Python 3, but should work.

zhashuyu commented 7 years ago

But I didn't get it work , the error is bellow

[boomer@boomer prometheus-report]$ python3
Python 3.6.2 (default, Aug 11 2017, 11:59:59) 
[GCC 7.1.1 20170622 (Red Hat 7.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyGnuplot import *
>>> c("plot sin(x)")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/PyGnuplot.py", line 63, in c
    proc.stdin.write(command + '\n')  # \n 'send return'
TypeError: a bytes-like object is required, not 'str'
>>> 
zhashuyu commented 7 years ago

I found solution from https://stackoverflow.com/questions/5965874/python-3-writing-to-a-pipe, see below

proc.stdin.write(bytearray(command + '\n', 'utf-8'))
benschneider commented 7 years ago

Ok thank you, you were faster than me :)