Python Forum

Full Version: Does Python 3.x have a built-in byte string compare function?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm just starting to learn Python 3.6 and this will be my first program. (I have coded in Basic and C about 20 years ago)
Does Python 3.x have a built-in byte string compare function or will I need to code it myself?

My task is:
1. Read a file as binary into 'mydata'.
2. Get the length of mydata. ..... mydataLength = len(mydata)
3. Search for a 5 byte string (like 43 2A 7E 59 C6)
........ If found, skip ahead 52 bytes and change the contents of that byte.
........ Note: The searching will be done byte-by-byte using indexing. ..... mydata[indexcount]
4. Repeat step 3 until the end of the binary string where ..... indexcount => mydataLength.

If there is a built-in byte string compare function, then please provide a link to it so I can learn how to use it. 

Just asking here before I start coding a byte compare function myself, to save the extra work if a built-in compare function already exists.  I did do a Google search but could not find a specific answer to my question.

Thanks.
(Feb-17-2017, 07:54 PM)Larz60+ Wrote: [ -> ]see: http://stackoverflow.com/questions/37869...on-2-and-3

I couldn't figure out how to apply the info in the link to my task, probably because of my being a Python newbie.

So I coded my task and found that to code the search and replace in my step-3 above is actually very easy in Python.  No need to find a Python function to do it.

Thanks,
Raptor88