Python: source code string cannot contain null bytes
For posterity: I had the same problem and fixed it using,
sed -i 's/\x0//g' FILENAME
The file seemed to be messed up in numerous ways (wrong endings, etc); no idea how...
See https://stackoverflow.com/a/2399817/230468
Source code string cannot contain null bytes
The problem is likely just what the error message tells you: your back-up copy somehow got "infected" with one or more null bytes (ASCII value 00). Paste your code one block at a time -- say, 50 lines -- to find which contain illegal bytes. Delete the most recently-added code, maybe 5 lines at a time, to find which has the null byte. Retype the offending line, and go on to the next.
Another possibility is to write a simple Python script that reads the file and removes the null bytes use the string replace
method:
with open("homework.py", 'r') as infile:
hw = infile.readlines().replace(chr(0), '')
Now close the file, open it again for 'w', and dump the hw
variable to it.
Related Topics
How to Override the [] Operator in Python
Get Lat/Long Given Current Point, Distance and Bearing
Find First Element in a Sequence That Matches a Predicate
Python Nested Functions Variable Scoping
What Is the Point of Indexing in Pandas
How to Apply Piecewise Linear Fit in Python
Binary Representation of Float in Python (Bits Not Hex)
Is the Server Bundled with Flask Safe to Use in Production
Underscore _ as Variable Name in Python
How to Add an Integer to Each Element in a List
How to Make a Surface with a Transparent Background in Pygame
First Non-Null Value Per Row from a List of Pandas Columns
Beginner Python: Reading and Writing to the Same File
Repeating Each Element of a Numpy Array 5 Times
Matching Nested Structures with Regular Expressions in Python
How Does Numpy's Transpose() Method Permute the Axes of an Array