0

I don't know why, but something's wrong with my os module.

import os

a = os.getcwd()
print(a)

I swear to god, I just typed in these three lines and ran the code, and I got C:\Users\Username for the result.

My python file isn't on that directory, but my computer keeps giving me C:\Users\Username no matter what I do.

Can anybody tell me what's the problem and how I can solve it? I already restarted my computer, but nothing changed.

김규민
  • 49
  • 6
  • 2
    Why do you think that CWD is the one where your script is? What do you want to do? – buran Feb 13 '22 at 18:26
  • 2
    Chek [What exactly is current working directory?](https://stackoverflow.com/q/45591428/4046632) – buran Feb 13 '22 at 18:27
  • "and ran the code"—how did you do this, specifically? – ChrisGPT was on strike Feb 13 '22 at 18:30
  • I was trying to print the place where my code is located in, and google told me that I should use getcwd, but it looks like it wasn't the right way... – 김규민 Feb 13 '22 at 18:32
  • @Chris I typed in those 3 lines in Visual Studio Code and ran the python file. – 김규민 Feb 13 '22 at 18:33
  • `os.getcwd()` shows the current working directory (see buran's link). Python is doing exactly what it should. I think you're looking for [How do you properly determine the current script directory?](https://stackoverflow.com/q/3718657/354577) – ChrisGPT was on strike Feb 13 '22 at 18:36
  • Side note: _always_ assume your code is wrong. If there is a problem, the default should be that you did something wrong. This is always true (for me as well, for any individual contributor). Python is nearly 30 years old. It is one of the most popular programming languages on the planet, with thousands of contributors and tons of automated tests. While it is _possible_ that a bug lies in Python or VSCode or some library, it is _vastly_ more likely that it is in your own code, or your understanding. – ChrisGPT was on strike Feb 13 '22 at 18:38

0 Answers0