tags:

views:

1539

answers:

3

Before starting, I ask you all to apologize for the question. Maybe it is stupid, but I cannot find a solution !!! I am working on a remote machine, I HAVE NO IDEA OF WHAT TYPE !!!

My python code, that seems to work, is the one below. The problem is that I am trying to print some outputs on the screen but nothing happens ! I have tried both print and raw_input but nothing happens ... Do you know any other way to do it ???

# Set up fields of reply message based on query
def prepareReply():
    global authorReply, authorReplyLen, localConvId, originConvId, blbContentAndUntUnz, linkName

    print "PLOP!"
    raw_input("blabla")

    #print "="*10

Thanks !

+2  A: 

This is a wild guess, but looking at the wording in your comments indicates that it might be a web server application (hint: more detail on your environment would be helpful). In this case, stdout is probably going somewhere else, at least not to the browser.

How are you actually running that code? Do you type "python myprogram.py" at a shell prompt, or do you hit Reload in your browser?

Greg Hewgill
the app is running on a server, but not a web server ! It's a particular server processing the transactions...To run the python program I have to run a shell script that runs my python application ! I have no idea ho the shell script is done ...
IceMan85
Well, it looks like you're already doing what can be expected from a Python point of view. Since your script is run through some other framework that none of us know anything about, stdout could be redirected anywhere. One thing you could try is: out = open("/dev/tty", "w"); print >>out, "hello world"
Greg Hewgill
If it runs by some framwework, maybe `return "PLOP!"` will work?
paffnucy
+1  A: 

To redirect stdout to something that you can read, a file in this case:

class PyLogger:

  def __init__(self, source):
    self.file_handle = open('Python_Log.txt', 'a')
    self.source=source
    self.buf = []

  def write(self, data):
    self.buf.append(data)
    if data.endswith('\n'):
      self.file_handle = open('Python_Log.txt', 'a')
      self.file_handle.write('\t' * indent_level)
      self.file_handle.write(self.source + "::" + ''.join(self.buf))
      self.file_handle.close()
      self.buf = []

  def __del__(self):
    if self.buf != []:
      self.file_handle = open('Python_Log.txt', 'a')
      self.file_handle.write('\t' * indent_level)
      self.file_handle.write(self.source + "::" + ''.join(self.buf) + '\n')
      self.file_handle.close()      
    self.file_handle.close()

import sys
sys.stdout = PyLogger('stdout')
sys.stderr = PyLogger('stderr')
MadKeithV
Looks like the first open() and close() in write() and __del__() are superfluous. Or did you want to do self.file_handle.flush()?Plus, file_handle could really be a class attribute instead of an instance attribute, since it is shared by all instances.
EOL
It's a simple copy-paste of some "code that works" that I haven't thought about in ages, probably originally off the internet somewhere. You could well be right that much of the code is superfluous.
MadKeithV
+1  A: 
import sys
print "Hi!"
sys.stdout.flush()
grawity