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?
#1
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.
Reply
#2
see: http://stackoverflow.com/questions/37869...on-2-and-3
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to compare string values in an if statement israelsattleen 1 519 Jul-08-2023, 03:49 PM
Last Post: deanhystad
Question How to compare two parameters in a function that has *args? Milan 4 1,183 Mar-26-2023, 07:43 PM
Last Post: Milan
  Changing a string value to a numerical value using python code and a lamda function Led_Zeppelin 6 1,539 Jul-05-2022, 11:29 PM
Last Post: deanhystad
  Convert a string to a function mikepy 8 2,421 May-13-2022, 07:28 PM
Last Post: mikepy
  Compare two Excel sheets with Python and list diffenrences dmkfon 1 14,488 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 11,348 Sep-18-2020, 10:10 PM
Last Post: tienttt
  Python crypto byte plaintext to hexint Mangaz90 2 2,806 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 31,473 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 4,513 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 3,266 Jan-14-2020, 11:43 AM
Last Post: Formationgrowthhacking

Forum Jump:

User Panel Messages

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