Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

python - Facing issue with loading a .pyc file from a separate script

I have a .pyc file with code:

def myfunc(in_str = "Hello World"):
    print(in_str)

I try to run it from a separate code like this:

import marshal
s = open('script2.cpython-37.pyc', 'rb')
s.seek(12)  # Also tried s.seek(8) here

code_obj = marshal.load(s)
exec(code_obj)
myfunc()
myfunc("Testing from script4")

The error I am getting:

(base) C:UsersashishDesktopcode_202101282>python script4.py
Traceback (most recent call last):
  File "script4.py", line 5, in <module>
    code_obj = marshal.load(s)
ValueError: bad marshal data (unknown type code)

Please let me know if am doing something wrong and how to fix this.

question from:https://stackoverflow.com/questions/65933705/facing-issue-with-loading-a-pyc-file-from-a-separate-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...