Giter Site home page Giter Site logo

Comments (8)

fernandez85 avatar fernandez85 commented on July 19, 2024

this is by design I guess
tobinstr is a function of IntelHex
list is constructor here, which allows iterable object as parameter by default and IntelHex has getItem implemented and it makes iterable
there could be iter (Python 3.x only) and/or next (Python 2.x compatybility) implemented, but I don't know if this creator(/s) intention to do so

neverthelees you could use list(intelhex.tobinarray()) instead

from intelhex.

jfongattw avatar jfongattw commented on July 19, 2024

fernandez85, I am totally agree with your point, but can't resist the temptation of doing some experiment on it:-)

After referring to timgeb's answer (On point 6: iter wins) to this question:
https://stackoverflow.com/questions/1952464/in-python-how-do-i-determine-if-an-object-is-iterable
I added the following method in class IntelHex:

def __iter__(self):
    return iter(self.tobinstr())

Here is the result:

from intelhex import IntelHex
ih = IntelHex('pimp_my_xor.hex')
ih.minaddr()
256
ihx = ih[0x100:0x103]
list(ihx)
[137, 194, 141]
for i in ihx:
... print(i)
...
137
194
141

Not sure if it will cause any side effect:-)

from intelhex.

fernandez85 avatar fernandez85 commented on July 19, 2024

I guess not.
tobinarray would be better, instead of tobinstr

And now I see we don't have to deal with backward compatibility for Python 2.x

from intelhex.

bialix avatar bialix commented on July 19, 2024

from intelhex.

The-42 avatar The-42 commented on July 19, 2024

I don't think list(ih) is necessarily such a bad idea. With #54 something had to happen as suffocating the interpreter wasn't an option (as __getitem__ would always return either padding or an actual byte, list(ih) crashed when running out of memory). Implementing rather than forbidding list(ih) seemed like the better approach to me, so now list conversion already works. If no byte has ever been set, the returned list is empty. Otherwise the list length corresponds to the highest address of the ih object, filled with padding where necessary. Not perfect for all possible usages, but I can see use cases for that.

from intelhex.

bialix avatar bialix commented on July 19, 2024

from intelhex.

jfongattw avatar jfongattw commented on July 19, 2024

Unfortunately, the IntelHex object behaved a little strange at this moment.

len(ihx)
3
ihx._buf
{1: 137, 2: 194, 3: 141}
list(ihx)
[255, 137, 194, 141]

from intelhex.

bialix avatar bialix commented on July 19, 2024

from intelhex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.