yes, with ast.literal_eval
which is safe since it only evaluates literals.
>>> import ast
>>> stringAsByte = "b'a'"
>>> ast.literal_eval(stringAsByte)
b'a'
More Related Contents:
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python 3
- What does a b prefix before a python string mean?
- Convert bytes to int?
- How to translate “bytes” objects into literal strings in pandas Dataframe, Python3.x?
- can only concatenate str (not “bytes”) to str
- “TypeError: a bytes-like object is required, not ‘str'” when handling file content in Python 3
- eval fails in list comprehension [duplicate]
- Why is Python’s eval() rejecting this multiline string, and how can I fix it?
- Why am getting an "elif" syntax error showing invalid syntax in python [closed]
- Why doesn’t this python code run infinite times? [closed]
- Error “Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)”
- Why is the id of a Python class not unique when called quickly?
- Freezing/Hanging tkinter GUI in waiting for the thread to complete
- Type hinting a collection of a specified type
- How can I connect to MySQL in Python 3 on Windows?
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- Using multiple Python engines (32Bit/64bit and 2.7/3.5)
- Importing class from another file [duplicate]
- When should iteritems() be used instead of items()?
- Clear QLineEdit on click event
- How do I convert a string into an f-string?
- Why doesn’t str.translate work in Python 3?
- Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b?
- How do you use subprocess.check_output() in Python?
- pip no longer working after update error ‘module’ object is not callable
- What is the correct syntax for ‘else if’?
- Find Out If a Function has been Called
- How to enable FIPS mode for libcrypto and libssl packaged with Python?
- How to redirect from a view to another view In Django
- Python: How to read and load an excel file from AWS S3?