G
G
Grandma Luda2021-10-12 12:54:53
Python
Grandma Luda, 2021-10-12 12:54:53

How to count the byte code of a file?

I need to read the byte code of the file in order to move it

file1 = open(direct + "/eee.py", mode="rb")
file = file1.read()

file2 = open("C:/Users/"+file+"/"+"AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup", mode="wb")
file2.write(file)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-10-12
@KirasiH

What for?
To read the bytecode of a file, it must be copied.
python file example

[email protected]:~/project/test_nuitka# cat test_program.py
def test():
    print('passed')

if __name__ == "__main__":
    test()

compilation example
[email protected]:~/project/test_nuitka# python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_compile
>>> import os
>>> os.listdir()
['include', 'share', 'test_program.py', 'lib64', 'bin', 'pyvenv.cfg', 'lib', 'ping.py']
>>> py_compile.compile('test_program.py')
'__pycache__/test_program.cpython-37.pyc'

we move the resulting file anywhere with the help of shutil .
this is if this is what the bytecode meant, and your code shows that you just need to move the file using shutil, here are examples .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question