I have multiple strings and I want to keep track of them when save them on a binary file. In fact I like to know each string occupy how many bytes of a binary file. I don't know how to do it in python.Please help me.
Asked
Active
Viewed 40 times
0
-
1If it's an ASCII-string, each character is 1 byte. Otherwise it depends on the encoding of the string. Does this thread help you? https://stackoverflow.com/questions/5290182/how-many-bytes-does-one-unicode-character-take – ascripter Jan 27 '18 at 12:36
-
And what do you actually mean by "keep track of them"? – ascripter Jan 27 '18 at 12:37
-
1can you explain more about it or put on an section scripts? – Benyamin Jafari Jan 27 '18 at 12:38
-
Each string was vectors of numbers that converted to string and wrote in a binary file. I want to read each vector from this binary file one by one and converted it to its old self. – Zahra Jan 27 '18 at 17:58
-
That would be string parsing and depends on the string representation of your object - however there are probably better ways to solve your problem: What type is your "vector". numpy array? python list? Please clarify and tell also in what environment you like to load the vector again. Maybe you could also dump a JSON or XML file? – ascripter Jan 27 '18 at 21:49
-
Thank you for your consideration, My vectors are python lists and I want to get them as string or python list or numpy array (It does'nt matter, they can convert to each other). – Zahra Jan 28 '18 at 05:48