2021年10月1日 星期五

csv class writer : a bytes-like object is required, not 'str'

 open(path, 'w')

You opened the file in binary mode:

with open(fname, 'rb') as f:

This means that all data read from the file is returned as bytes objects, not str. You cannot then use a string in a containment test:

if 'some-pattern' in tmp: continue

You'd have to use a bytes object to test against tmp instead:

if b'some-pattern' in tmp: continue

or open the file as a textfile instead by replacing the 'rb' mode with 'r'

from: https://stackoverflow.com/questions/43413018/csv-class-writer-a-bytes-like-object-is-required-not-str

Remove files from Git commit

 I will explain to you with example.

Let A, B, C be 3 successive commits. Commit B contains a file that should not have been committed.

git log  # take A commit_id
git rebase -i "A_commit_ID" # do an interactive rebase
change commit to 'e' in rebase vim # means commit will be edited
git rm unwanted_file
git rebase --continue
git push --force-with-lease <branchName>  


from: https://stackoverflow.com/questions/12481639/remove-files-from-git-commit