Python Forum
Does Python 3.x have a built-in byte string compare function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does Python 3.x have a built-in byte string compare function?
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.

(Feb-17-2017, 07:54 PM)Larz60+ Wrote: see:

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.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare two Excel sheets with Python and list diffenrences dmkfon 1 549 Oct-09-2021, 03:30 PM
Last Post: Larz60+
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 4,737 Sep-18-2020, 10:10 PM
Last Post: tienttt
  Python crypto byte plaintext to hexint Mangaz90 2 1,464 Feb-21-2020, 07:42 PM
Last Post: Mangaz90
  'utf-8' codec can't decode byte 0xda in position 184: invalid continuation byte karkas 8 26,476 Feb-08-2020, 06:58 PM
Last Post: karkas
  how to compare two different size images in python and find corresponding pixel value squidsirymchenry 1 2,275 Feb-03-2020, 06:48 AM
Last Post: michael1789
  How to compare in python an input value with an hashed value in mysql table? Formationgrowthhacking 4 1,726 Jan-14-2020, 11:43 AM
Last Post: Formationgrowthhacking
  Compare two images with Python is possible? Delemir78 3 2,134 Dec-17-2019, 09:03 PM
Last Post: Larz60+
  First Byte of a string is missing while receiving data over TCP Socket shahrukh1987 3 2,063 Nov-20-2019, 10:34 AM
Last Post: shahrukh1987
  How can I compare Python XML-Files and add missing values from one to another kirat 2 1,261 Aug-30-2019, 12:17 PM
Last Post: perfringo
  Byte string catenation inefficient in 3.7? RMJFlack 13 2,988 Aug-18-2019, 05:19 AM
Last Post: RMJFlack

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020