Python Forum
Convert string to a specific number of bytes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert string to a specific number of bytes
#1
Hello!

I have a class with instance attributes. I need to create an object with each instance having its own values (some are ints, others are strings). Each instance value needs to be converted to binary and saved to a file that will be accessed and updated. My problem is saving the attributes with string values to a specific number of bytes. Each attribute value needs to be a specific number of bytes. I think I know how to convert the integer values but I can't find anything to help with the strings. I can get how large each string is in bytes but I need to save it to a specific byte size, no matter what size it actually is. Is there a way to pad it or something?

Thanks in advance,
Reply
#2
What have you tried?
Show your code attempts
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  String to Number in Python Godjuned 3 3,791 Nov-17-2022, 07:22 AM
Last Post: Godjuned
  number to string Ali_ 1 2,201 Mar-31-2022, 11:22 AM
Last Post: ndc85430
  How to convert every even number in a list to odd? Bruizeh 4 6,569 Aug-27-2021, 03:04 AM
Last Post: naughtyCat
  Convert list of numbers to string of numbers kam_uk 5 5,042 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Convert multiple decimal numbers in string to floats Katy8 6 6,628 Aug-16-2020, 06:06 PM
Last Post: Katy8
  Counting the number of occurrences of characters in a string nsadams87xx 1 4,440 Jun-16-2020, 07:22 PM
Last Post: bowlofred
  How can I convert specific rows from excel to pandas dataframe? mcva 1 2,778 Apr-20-2020, 09:14 AM
Last Post: pyzyx3qwerty
  Error could not convert string to float: deadendstreet 4 8,505 Oct-02-2019, 05:49 PM
Last Post: ichabod801
  how to convert list into string Shevach 3 4,026 May-14-2019, 09:51 AM
Last Post: perfringo
  Convert number to a different base and make calculations frequency 12 10,599 Dec-17-2018, 05:21 PM
Last Post: frequency

Forum Jump:

User Panel Messages

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