Bottom Page

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  'utf-8' codec can't decode byte 0xda in position 184: invalid continuation byte karkas 7 364 Sep-12-2019, 11:19 PM
Last Post: newbieAuggie2019
  How can I compare Python XML-Files and add missing values from one to another kirat 2 118 Aug-30-2019, 12:17 PM
Last Post: perfringo
  Byte string catenation inefficient in 3.7? RMJFlack 13 515 Aug-18-2019, 05:19 AM
Last Post: RMJFlack
  HELP: String of Zero's and One's to binary byte schwasskin 1 1,192 May-19-2019, 07:31 AM
Last Post: heiner55
  a function to layout a string Skaperen 5 311 May-13-2019, 06:36 PM
Last Post: Skaperen
  charmap codec can't decode byte error with gzipped file in python bluethundr 2 314 Apr-30-2019, 12:26 PM
Last Post: bluethundr
  how to compare some string with the database columns nick123 1 232 Apr-21-2019, 05:27 PM
Last Post: ichabod801
  Python csv compare two file, update value if two value is matched kinojom 1 269 Apr-17-2019, 10:36 AM
Last Post: DeaD_EyE
  Read Byte Array from Zigbee coordinator using python jenkins43 3 394 Mar-26-2019, 03:03 PM
Last Post: micseydel
  Compare words Python xSphere 3 362 Jan-24-2019, 10:52 AM
Last Post: perfringo

Forum Jump:


Users browsing this thread: 1 Guest(s)