popen2 issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bierny
    New Member
    • Feb 2007
    • 12

    popen2 issue

    Hi All,
    I am trying to do something new in python but at this moment i really don't know if it is possible.

    I have a very simple python script that will simply prompt for any text and when the text it entered by a user the script will display it on a screen.

    Code:
    myInput = raw_input("Write something:")
    print myInput
    What i am trying to do is to start this simple script from another python script, read the prompt and write something to the first script. Let's say that the answer will be hardcoded to simple "Hello". In that case if the other script that starts the simple one and prints the result would print

    Code:
    Write something:
    Hello
    I will keep looking for a solution for this problem. I will really appreciate any hints from you, especially if it is actually possible to do :-)

    Thanks in advance for any help.

    Best regards,
  • rhitam30111985
    New Member
    • Aug 2007
    • 112

    #2
    i cant think how u can start another script from a scrip but this is all i can think of :

    script1.py:

    [CODE=python]
    #!/usr/bin/python
    string=raw_inpu t()
    [/CODE]

    script2.py

    [CODE=python]

    from script1 import *
    print string

    [/CODE]

    Comment

    • elcron
      New Member
      • Sep 2007
      • 43

      #3
      As far as I'm aware there is no such way but object oriented languages like python have functions and classes for code reuse. I would use the import statement.

      [code=python]
      # script1.py
      from script2 import formatText # import the function

      # execute the first logic
      myInput = raw_input("Writ e something: ")
      print myInput

      # call upon function
      print formatText(myIn put)
      print myInput

      # script2.py
      def formatText(text s):
      text = texts[:] # copies the variable so you can avoid side effects
      ## format the text ##
      text += '\n'
      text *= 5
      return text
      [/code]

      Comment

      • Bierny
        New Member
        • Feb 2007
        • 12

        #4
        Hmm...
        What in case when the first script (the one that uses raw_input) is not a python script, but simply some other script that i can only execute?

        I am still trying :-)

        Thanks for your comments and i am waiting for new ones :-)

        Best regards,

        Comment

        Working...