0

I'm trying to make a program that reads a JSON string from a javascript file, and I just can't seem to do it. I can only the opposite of what I want. Here is my code

#python 2.7?
import sys
from subprocess import Popen, PIPE

messages = [] #store messages from send.js
sensor = Popen([communication.html, send.js])
buffer = b''
while True:

    # read the sensor a character at a time
    out = sensor.stdout.read(1)

    #after reading
    if out = b'\n':
        messages.append(float(buffer))
        print(messages)
        buffer = b''
    else:
        buffer += out #append to buffer
//javascript
function sendMsg(){
    var msg = document.getElementById('talk').value;
    var data = {
        "sending": msg
    };
    data = JSON.stringify(data)
}
<!DOCTYPE html>
<html>
    <head>
        <!--<script src="comScrp.py"></script>-->
    </head>
    <body>
        <script src="send.js"></script>
        <!--Without the Python, we wouldn't be able to use this without a server or nodeJs.-->
        <input id="talk"><button onclick="sendMsg()">Send</button>
        <p id="output"></p>
    </body>
</html>

Thanks!

Westlenando
  • 88
  • 1
  • 8
  • 1
    JFYI if you are saying `print(messages)` instead of `print messages` then it is probably not python 2.7. Can you describe your problem in more detail please? What does the HTML look like? What do you mean by "I can only the opposite of what I want"? What result are you seeing? If you provide code we can run to reproduce your problem, we can help you much better. :) – Peaceful James Jul 01 '20 at 17:47
  • 1
    @PeacefulJames, `print(foo)` works in Python 2. It's not the _same_ as Python 3's `print()`, but it will work. If `print foo` works that indicates you're not using Python 3, but `print(foo)` working doesn't tell us anything about the Python version. – ChrisGPT was on strike Jul 01 '20 at 17:47
  • @Chris yes that's true. I was speaking loosely. I will change "definitely" to "probably" – Peaceful James Jul 01 '20 at 17:49
  • IMO "probably" is still too strong. `print(foo)` gives us _no information_ about the Python version. – ChrisGPT was on strike Jul 01 '20 at 17:53
  • @Chris I use 2.7.17 – Westlenando Jul 01 '20 at 17:59
  • @Westlenando, fine, but that's irrelevant. – ChrisGPT was on strike Jul 01 '20 at 18:00
  • @Chris Oh ok- I'll update it right now – Westlenando Jul 01 '20 at 18:02
  • 1
    @Westlenando, I'm not sure what you mean by that. Your question has nothing to do with your Python version. James added a comment with an invalid conclusion about Python versions in it. I'm just commenting on that. – ChrisGPT was on strike Jul 01 '20 at 18:03

0 Answers0