0

I started to use visual studio code yesterday and i'm having this problem...

Let's suppose I have this code:

myFile = open("file.txt", "w+")
myFile.write("something \n")
myFile.close()

When I run it on VScode it don't save the file, but when I run it in SublimeText it does.

do you know how to solve it?. I didn't find anything (or I don't know how to search), my launch.json look like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "internalConsole"
        }
    ]
}

**After I wrote that I noticed that it saves the file in "C: \ Users \ User \ Documents \ vsprofiles", but I have my .py file on the desktop, I want it to save the file in the same path where the .py file is, like SublimeText does.

4
  • 1
    If you run import os; print(os.getcwd()) does that matchup with the path you found? Commented Nov 28, 2021 at 4:52
  • @StevenSummers yes it does 🤔 Commented Nov 28, 2021 at 4:53
  • 1
    Try setting the current working directory then. I use "cwd": "${fileDirname}" Commented Nov 28, 2021 at 4:54
  • Go to settings and search for terminal and you will see cwd integrated something Commented Nov 28, 2021 at 4:58

1 Answer 1

1

For completeness here is my config file

"launch": {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${fileDirname}",
            "env": {},
            "pythonArgs": [],
            "stopOnEntry": false
        }
    ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

it worked!, i added "cwd": "${fileDirname}", at the end and it worked, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.