0

I have a python script (test.py) and it will call another python script (x.py) to do something and I would like the x.py can return the object "Person" to test.py.

test.py:

cmd= "python /usr/example/x.py"
command= Popen(cmd, shell=True, stdout=PIPE, stdin=PIPE, stderr=PIPE)

x.py:

--The following coding is used to assign a name to object "person"
person = people.name("Peter")  
printAreeter

Is there any ways that can archive my goals?

Thanks a lot.

the.salman.a
  • 945
  • 8
  • 29
Alan Lee
  • 3
  • 1

2 Answers2

0

solution:

1 use json return and read it back to the object

2 is it possible to try import the function or class in x.py and u can run the func as native func or classes

3 if not i suppose u r running on another machine, i strongly recommend paramiko library

陈海栋
  • 90
  • 5
0

quote: this is how to dump to json

class Foo(object):
    def __init__(self):
        self.x = 1
        self.y = 2

foo = Foo()
s = json.dumps(foo) # raises TypeError with "is not JSON serializable"

s = json.dumps(foo.__dict__) # s set to: {"x":1, "y":2}

this is how to read it back:

class Foo(object):
    def __init__(self,*kwags):
        if kwags == None:
            self.x = 1
            self.y = 2
        else:
            self.x = kwags.get("x")
            self.y = kwags.get("y")    
foo = Foo(json.loads("{"x":1, "y":2}"))

from:class serieslization

陈海栋
  • 90
  • 5