0

I have two script, one for generate data.

main.py

import numpy as np
import os
data = np.array([[1,2,3,4],dtype=np.float32)
os.system("python draw.py "+data.tostring())

Another one for plot:

draw.py

import numpy as np
param = np.fromstring(sys.argv[1], dtype=np.float32)
print param

I just want to pass the numpy variable to another script through string,However, When I tried to use this command to run.

python main.py

I got this:

----> 1 os.system("python draw.py "+data.tostring())

TypeError: must be string without null bytes, not str

I think it's because the splashes, but I don't know how to deal with it. It there any body faced this problem before?

1 Answer 1

1

If you don't want to put them both in the same script, then you can define your plotting routine as a function in draw.py and then import it in main.py. You should avoid invoking Python scripts externally, since Python's import mechanism is more direct and less error-prone.

draw.py:

import numpy as np

def plot(param):
    # Your plotting code here.
    print param

main.py:

import numpy as np
from draw import plot

data = np.array([[1,2,3,4],dtype=np.float32)
plot(data)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.