I’m having trouble with the following simple open statement. The code dies on that
line and the diagnostics are of no help.` This is Python 3.9 PyCharm
c:\users\asha\appdata\local\jetbrains\pycharm community edition 2020.3.5\plugins\python-ce\helpers\pydev\pydevd.py(1)()
→ ‘’’
(Pdb)
Process finished with exit code -1
It might be the case that you have copied the code from somewhere, and the double inverted commas are not compatible. So, there are two potential fixes:
First, always use a raw string for addresses. So just put a r before the address string in open statement.
If the quotes were Unicode “smart quotes” or “double inverted commas”,
the code wouldn’t even get to the debugger because it would be an
immediate syntax error:
>>> open(“filename”)
File "<stdin>", line 1
open(“filename”)
^
SyntaxError: invalid character '“' (U+201C)
Also, it is not good advice to use raw strings for file names. I know
lots of people do it on Windows, but it is still not the best advice.
The problem is that raw strings cannot end with a backslash, so you
cannot write a path like this:
path = r'path\to\directory\'
The generally preferred way to write pathnames on Windows is to use
forward slashes:
path = 'path/to/directory/'
The Windows OS will accept forward slashes instead of backslashes for
paths under most circumstances. In the context of using Python’s open()
function, it will always work.