question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run Python File In Terminal doesn't escape special chars in pathnames

See original GitHub issue

Environment data

  • VS Code version: 1.30.2
  • Extension version (available under the Extensions sidebar): 2018.12.1
  • OS and version: macOS 10.14.2
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.2 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions: XXX

Expected behaviour

Running a script via Terminal would execute no matter where inside the project directory the script is stored

Actual behaviour

filepathes can’t be resolved due to lack of escaping special characters:

example for special characters in pathname: image image

Steps to reproduce:

  1. Create a subdirectory in your project folder having brackets in it’s name, for instance “foo(bar)”.
  2. Create a file inside that directory. (In my case foo.py)
  3. Open the main project folder via the File-Handler in VSC.
  4. Open the foo.py file inside the subdirectory and execute it via “Run Python File In Terminal”

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Starting Jedi Python language engine.
##########Linting Output - pylint##########

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

XXX 

Old Second Part of Issue

Expected behaviour

linked path resources would be resolved relatively to the directory of the executed script

Actual behaviour

example for non resolvable pathes inside scripts: image image

line 3 of the script: image

Steps to reproduce:

  1. Create a subdirectory in your project folder having brackets in it’s name, for instance “foo(bar)”.
  2. Create a file inside that directory. (In my case foo.py)
  3. Open the main project folder via the File-Handler in VSC.
  4. Open the foo.py file inside the subdirectory and execute it via “Run Python File In Terminal”
  5. Terminal replies then with “FileNotFoundError: [Errno 2] No such file or directory:”

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ericsnowcurrentlycommented, Feb 4, 2019

Thanks for letting us know about this, @lockejan. There are two separate issues at play here:

  1. special characters in filenames are interpreted by the shell
  2. scripts are executed relative to the project root

(In the future you’ll be best served by opening separate issues.)

For the first one that seems like something we could address (e.g. quote the entire filename when passing to the shell). I expect we haven’t done so because having such characters in your file/directory names is pretty uncommon. Regardless, we’ll look into it.

0reactions
karrtikrcommented, Dec 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python escape character - path - Stack Overflow
You are on Windows with a variable containing a path. You are trying to open a file with it, but it contains escape...
Read more >
Best Practice: Working with Paths in Python - Part 1 - b.telligent
Step 1: How do I input the right path? ... The interpreter doesn't understand the character sequence \U, since this initiates Unicode characters...
Read more >
Python Files and os.path - 2021 - BogoToBogo
When we run the graphical Python Shell, the current working directory starts as the ... The os.path.join() function constructs a pathname out of...
Read more >
Long filenames or paths with spaces require quotation marks
Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name ......
Read more >
Python Tutorial - File and Text Processing
It ignores interpretation of the Python's string escape sequence. For example, r'\n' is '\'+'n' (two characters) instead of newline (one character) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found