0

The following line is from a python script for a serial bootloader. The file being read is an .elf file.

It seems like the line is converting the file to a binary array or something similar, but I'm confused about the data = data = ... part.

data = data = [ord(x) for x in open(options.file, 'rb').read()]

Can someone shed some light on how this works?

Peter Kapteyn
  • 354
  • 1
  • 13
  • 2
    `data = data = ...` can always be replaced by `data = ...`. Doing something like `x = y = ` is equivalent to `temp = ; x = temp; y = temp; del temp` – juanpa.arrivillaga Mar 05 '20 at 19:27
  • 3
    ps, just in case it isn't immediately obvious, one of the `data = ` part is completely redundant, and this is probably a copy paste typo that slipped by – Paritosh Singh Mar 05 '20 at 19:27
  • 1
    @ParitoshSingh I make this same exact copy-paste type all the time :) – juanpa.arrivillaga Mar 05 '20 at 19:27
  • Interesting. I thought it was some python syntactic sugar trick, but being a typo makes sense. – Peter Kapteyn Mar 05 '20 at 19:29
  • 1
    Don't get us wrong, it *is* a valid syntax, but it would have made more sense if it was `data1 = data2 = some_val`. The fact that it's the same "name" essentially means it's the same as writing `data = some_val` twice. There is no logical reason why you'd want to do that, hence it's a typo *in this particular case* – Paritosh Singh Mar 05 '20 at 19:30

0 Answers0