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
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 3,544 Sep-18-2020, 10:10 PM
Last Post: tienttt
  Python crypto byte plaintext to hexint Mangaz90 2 1,171 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 24,690 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 1,769 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,254 Jan-14-2020, 11:43 AM
Last Post: Formationgrowthhacking
  Compare two images with Python is possible? Delemir78 3 1,527 Dec-17-2019, 09:03 PM
Last Post: Larz60+
  First Byte of a string is missing while receiving data over TCP Socket shahrukh1987 3 1,629 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,026 Aug-30-2019, 12:17 PM
Last Post: perfringo
  Byte string catenation inefficient in 3.7? RMJFlack 13 2,499 Aug-18-2019, 05:19 AM
Last Post: RMJFlack
  HELP: String of Zero's and One's to binary byte schwasskin 1 2,256 May-19-2019, 07:31 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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