Decode it.
>>> b'a string'.decode('ascii')
'a string'
To get bytes from string, encode it.
>>> 'a string'.encode('ascii')
b'a string'
More Related Contents:
- Finding and counting the frequency of known pairs of words in multiple files [closed]
- How to handle special cases in my Python code?
- Convert bytes to a string
- What does the ‘b’ character do in front of a string literal?
- How can I concatenate str and int objects?
- Which is the preferred way to concatenate a string in Python?
- How to convert string to binary?
- TypeError: not all arguments converted during string formatting python
- String formatting in Python 3
- Pandas Extract Number from String
- How do I format a string using a dictionary in python-3.x?
- What’s the difference between str.isdigit, isnumeric and isdecimal in python?
- Extract Number from String in Python
- Why are str.count(”) and len(str) giving different output?
- Python – difference between two strings
- Most pythonic way to interleave two strings
- Python 3.1.1 string to hex
- Count number of words per row
- Regular expression parsing a binary file?
- What is a clean way to convert a string percent to a float?
- How can I split a string of a mathematical expressions in python?
- Why do numbers in a string become “x0n” when a backslash precedes them?
- can only concatenate str (not “bytes”) to str
- What’s the difference between str.isdigit(), isnumeric() and isdecimal() in Python?
- Print without b’ prefix for bytes in Python 3
- Deleting consonants from a string in Python
- Finding the position of a word in a string
- Why are str.count(”) and len(str) giving different outputs when used on an empty string?
- Convert bytes to a string in python 3
- Convert binary string to bytearray in Python 3