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 1,381 Nov-17-2022, 07:22 AM
Last Post: Godjuned
  number to string Ali_ 1 1,298 Mar-31-2022, 11:22 AM
Last Post: ndc85430
  How to convert every even number in a list to odd? Bruizeh 4 3,800 Aug-27-2021, 03:04 AM
Last Post: naughtyCat
  Convert multiple decimal numbers in string to floats Katy8 6 3,600 Aug-16-2020, 06:06 PM
Last Post: Katy8
  Counting the number of occurrences of characters in a string nsadams87xx 1 1,949 Jun-16-2020, 07:22 PM
Last Post: bowlofred
  How can I convert specific rows from excel to pandas dataframe? mcva 1 1,826 Apr-20-2020, 09:14 AM
Last Post: pyzyx3qwerty
  Error could not convert string to float: deadendstreet 4 5,429 Oct-02-2019, 05:49 PM
Last Post: ichabod801
  how to convert list into string Shevach 3 2,652 May-14-2019, 09:51 AM
Last Post: perfringo
  Convert number to a different base and make calculations frequency 12 5,687 Dec-17-2018, 05:21 PM
Last Post: frequency
  Trying to get the week number from a string of numbers fad3r 2 3,242 Apr-15-2018, 06:52 PM
Last Post: ljmetzger

Forum Jump:

User Panel Messages

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