Skip to content

Code pour vérifier si le pyc est compatible avec l'image dans MyDocker

Code python à lancer dans jupyter

import struct
import sys

current_version = ".".join(map(str, sys.version_info[0:2]))

with open ('utilities_cours_correction.pyc','rb') as pyc:
    [n] = struct.unpack("<H", pyc.read()[:2])

print(f"Magic number from utilities_cours_correction.pyc: {n}")

!if [ ! -f /tmp/magics.py.txt ]; then  \
    curl --http1.1 https://raw.githubusercontent.com/rocky/python-xdis/refs/heads/master/xdis/magics.py -o /tmp/magics.py.txt; \
fi

with open('/tmp/magics.py.txt','r') as f:
    for line in f.readlines():
        if str(n) in line:
            print(f"Found one version with magic number {n}:")
            print(line, end='')
            if current_version in line:
                print("Matching version")
            else:
                print("Incompatible version")
Modification effectuée par Bryan Brancotte