Data transfer from Python CGI to javascript
I have written the following program #!c:\Python27\Python.exe import cgi, cgitb; import sys, serial cgitb.enable() ser = serial.Serial('COM27', 9600) myvar = ser.readline() print "Content-type:text/html\n\n" print """ Real Time Temperature window.onload = startInterval; function startInterval() { setInterval("startTime();",1000); } function startTime(myvar) { document.getElementById('mine').innerHTML ="Temperature" +parseInt(myvar); } Real Time Temperature: """ It is giving an output of 'NaN' in the output. If the python program is run alone it is giving the correct output. Can anyone please help. Is it also possible to separate the python and the javascript to two different files. If so how will I get/transfer the data in/from HTML . Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: passing Python data to a javascript function
On Thursday, October 27, 2011 9:25:28 AM UTC+5:30, Chris Angelico wrote: > On Thu, Oct 27, 2011 at 2:51 PM, Bill Allen wrote: > > > Chris, > > > > > > Wow, that seems so simple now that I see it. I was dancing around that all > > > day, but just not landing on it. Thanks so very much for the assist. > > >This code is giving an error 500 when run. Although the python code is > >independently running OK > > > --Bill > > > > > > Final code that works perfectly, passes the value from the Python script to > > > the javascript correctly: > > > > > > > > > > Congratulations! You've just written code that writes code. It takes a > > bit to get your head around it (especially when you start worrying > > about literal strings that might contain quotes, for instance), but > > it's really cool and seriously powerful stuff. Your server-side Python > > code can generate client-side Javascript code any way it likes... > > unlimited possibilities. > > > > ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Plz help..SocketServer UDP server losing lots of packets
logFileName = 'log.txt' logfile = open(logFileName, "a") class MyUDPServer(SocketServer.UDPServer): def server_bind(self): self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 8388608) self.socket.bind(self.server_address) class LogsDumpHandler(SocketServer.DatagramRequestHandler): def handle(self): global logfile # fileExists is a function which checks the existence of a file if not fileExists(logFileName): logfile = open(logFileName, "a") logfile.writelines(self.rfile.readlines()) server = MyUDPServer(("",PORT), LogsDumpHandler) server.serve_forever() logfile.close() The above python code is a UDP server based on SocketServer framework and I am losing a lot of messages, I have tried almost everything, increasing the size of the receive buffer, changing the way i read the messages coming into server. The above code is supposed to work as a tracing server and it does but is losing messages. Is there a way I can improve this code? Any help will be highly appreciated. Thanks, Sam -- http://mail.python.org/mailman/listinfo/python-list