About 324,000 results
Open links in new tab
  1. python - How do I get the full path of the current file's directory ...

    The special variable __file__ contains the path to the current file. From that we can get the directory using either pathlib or the os.path module. Python 3. For the directory of the script being run: import pathlib pathlib.Path(__file__).parent.resolve() For the current working directory: import pathlib pathlib.Path().resolve() Python 2 and 3

  2. python - Find the current directory and file's directory - Stack …

    In Python 3.4 and 3.5 that caused some pain, because open built-in function could only work with string or bytes objects, and did not support Path objects, so you had to convert Path objects to strings or use the Path.open() method, but the latter option required you to change old code:

  3. How do I get the path of the current executed file in Python?

    getsourcefile(lambda:0) somehow gets the internal source file of the lambda function object, so returns '<pyshell#nn>' in the Python shell or returns the file path of the Python code currently being executed.

  4. How do I find out my PYTHONPATH using Python? - Stack Overflow

    Sep 28, 2009 · I find it easier to use the following, since it makes it clear if the empty string ('') is in the path: python -c "import sys, pprint; pprint.pprint(sys.path)" ( And I found this answer more helpful, too; the title of the question mislead me into thinking it was about the actual path python was using, rather than the contents of the PYTHONPATH environment variable.)

  5. python - Find path to currently running file - Stack Overflow

    Note that sys.argv[0] contains the full working directory (path) + filename whereas sys.path[0] is the current working directory without the filename. I have tested sys.path[0] on windows and it works.

  6. How do I get the path of the Python script I am running in?

    Use this to get the path of the current file. It will resolve any symlinks in the path. import os file_path = os.path.realpath(__file__) This works fine on my mac. It won't work from the Python interpreter (you need to be executing a Python file).

  7. How do I get the path and name of the python file that is currently ...

    FILENAME = str(os.path.basename(FULL_PATH_TO_SCRIPT)) FILENAME_NO_EXTENSION = os.path.splitext(FILENAME)[0] FILENAME_EXTENSION = os.path.splitext(FILENAME)[1] # the full path to the executable script being run EXECUTABLE_FULL_PATH = sys.argv[0] # the name of the executable being run EXECUTABLE_NAME = os.path.basename(EXECUTABLE_FULL_PATH ...

  8. python - How to get the PYTHONPATH in shell? - Stack Overflow

    Apr 29, 2013 · @variable No, the paths in PYTHONPATH is added to the paths in sys.path when the Python interpreter starts. In other words, sys.path will include all the paths in PYTHONPATH, but also additional paths, like the path to the Python standard library …

  9. How can I find where Python is installed on Windows?

    Mar 15, 2009 · Fortunately, typing path at the windows path let me find where I had installed it. The path was an option when I installed Python which I just forgot. If you didn't select setting the path when you installed Python 3 that probably won't work - unless you manually updated the path when you installed it.

  10. python - How do you properly determine the current script …

    It should also be noted that this can return a relative filepath, so it should be used within the immediate current working directory context. Also if you run this from Windows and use a '\' delimited full path (e.g. python c:\path\to\directory\filepath.py), the result will incorrectly be blank. –