Python clumsy



  • I'm down loading a compressed file into a variable hexstr on my gpy which I then write to flash as gzip.py so I can extract it with

    with open('gzip.py', 'r') as f: byts=uzlib.DecompIO(f, 31); f=open('main.py', 'w'); f.write(byts.read().decode())
    

    then put it back into flash as main.py. But it feels clumsy. Surely there is a way I can extract it from hexstr directly without having to save it to gzip.py first? I tried stuff like zlib.DecompIO(hexstr, 31) and zlib.DecompIO(hexstr.read(), 31) but wild stabs in the dark never work. I think I need a StringIO or something in there to change the string into an object the extractor can use?


Log in to reply
 

Pycom on Twitter