Skip to content

donate-cpu.py: Fix Python3 compatibility problem with f.read().decode()#1507

Merged
danmar merged 1 commit intocppcheck-opensource:masterfrom
versat:donate_cpu_script
Dec 7, 2018
Merged

donate-cpu.py: Fix Python3 compatibility problem with f.read().decode()#1507
danmar merged 1 commit intocppcheck-opensource:masterfrom
versat:donate_cpu_script

Conversation

@versat
Copy link
Copy Markdown
Collaborator

@versat versat commented Dec 6, 2018

With Python3 f.read() directly returns a string object that has no
decode() function. As a workaround AttributeError exceptions during
calling the decode() function are ignored and the data read from the file
is left unchanged.
With Python2 calling the decode() function is necessary and still done.

With Python3 f.read() directly returns a string object that has no
decode() function. As a workaround AttributeError exceptions during
calling the decode() function are ignored and the data read from the file
is left unchanged.
With Python2 calling the decode() function is necessary and still done.
@versat
Copy link
Copy Markdown
Collaborator Author

versat commented Dec 6, 2018

Something like

                filedata = f.read()
                if sys.version_info.major < 3:
                    filedata = filedata.decode(encoding='utf-8', errors='ignore')

would also be a solution i guess.

@danmar danmar merged commit fe6f419 into cppcheck-opensource:master Dec 7, 2018
@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Dec 7, 2018

Thanks!

@versat versat deleted the donate_cpu_script branch December 7, 2018 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants