Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
Alright I want to turn a binary string like '1010110000000010' into a bytes object in Python 3.3.2. Anyone know how I can do this? Thanks!
If you want b'1010110000000010', use bytes or str.encode:
>>> bytes('1010110000000010', encoding='ascii')
b'1010110000000010'
>>> '1010110000000010'.encode('ascii')
b'1010110000000010'
>>> '1010110000000010'.encode() # can omit encoding (default: utf-8)
b'1010110000000010'
If you want b'\xac\x02', use bytes with converted integers (using int with base 2), or struct.pack:
>>> bytes(int(b[i:i+8], 2) for i in range(0, len(b), 8))
b'\xac\x02'
>>> import struct
>>> b = '1010110000000010'
>>> b''.join(struct.pack('B', int(b[i:i+8], 2)) for i in range(0, len(b), 8))
b'\xac\x02'
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm wondering after why these assertions are passing
token_generated = ".eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImRhdmlkLmJhcnJhdEBub3ZhcnRpcy5jb20iLCJleHBpcmF0aW9uIjoiMjAxOC0wMS0xMVQyMjowNTozMi44MjIwNDUifQ.jalHa2ZpnxH00v3tP6CKL3nUkiTMt4rsjo6P3DM32DA"
self.assertTrue(type(token_generated) == str)
self.assertTrue(type(token_generated) == bytes)
Both tests pass, but I don't understand why my token variable can have two types as it should be only a String
Because when I'm printing the type of token_generated
print (type(token_generated))
I got that : .<type 'str'>
Assuming you are using Python 2, the str- and bytes-type are actually the same
>>> bytes is str
True
Therefore they are also equal.
If you want to know if token is a valid utf8-string, you should decode it:
token = '\xff'
try:
token.decode('utf8')
except UnicodeDecodeError:
print "The bytes are just bytes, or maybe some other encoding"
else:
print "The bytes are a utf8 string, hooray"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What i have is an array containing strings of length = 31. Total number of strings = 13700. I want to split all strings into substrings of length 5,22 and 4. Please help. Thank you.
With fixed-length strings and fixed-length substrings it's really easy. If they're not already, mash the strings around until they're in a 2-D char array, one string per row (cell2mat() will be your friend if they're currently in a cell array), and split:
s1 = s(:, 1:5);
s2 = s(:, 6:27);
s3 = s(:, 28:31);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Let I have two string. Say, "learn" and "haskell". How can make them list like ["learn","haskell"]
makeListFromTwoThings :: a -> a -> [a]
makeListFromTwoThings x y = [x,y]
Edit: I am assuming you want a function that does this generically. If you want to do this in the Haskell shell then it seems like nothing is stopping you from typing ["learn","haskell"] directly. If you are trying to solve some more general problem directly in the shell then let us know the details of that problem.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a sheet with some datas in D column. I need to extract the values that have less then 11 characters and adding from left many 0 untill reach 11 characters.. I explain with an example:
12345678912 --> this is correct
123456789 --> this is incorrect and has 9 characters so i need adding from left 2 zeros
result:
00123456789 --> now is correct
Is there a macro or a formula that could be useful for my goal? Thanks
Assuming the data is stored as numbers, you can simply use =TEXT(A1,"00000000000"). If it's stored as text then use =REPT("0",LEN(A1)-11))&A1
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have data in the following format:
Variable - Value
A 1
B 2
A 3
B 4
and so on.
Notice how the variable is recurring for different values. I want to draw a line for each variable that shows its different values assuming the X-axis is time.
Please any help.
I would start off by creating a Pivot table based on the data that you have and then create the line graph from there.