About 11,300,000 results
Open links in new tab
  1. Storing filepath as variable in python - Stack Overflow

    %f is the format code for float. Just because it's the initial for file doesn't mean Python can redefine the standard format string syntax to accommodate that. Read the docs for printf -style formatting. use file = open('%s/EventLog.txt' % (filefolder), "a") with %s instead of %f.

  2. In Python Use Current Directory as variable - Stack Overflow

    Jul 15, 2015 · I want to use my current directory inside my fout = file statement. The timestamp variable works fine but i have to manually enter the directory to get that part to work and i would like it to be automatic. timeStamp = datetime.datetime.now().strftime("%A, %d. %B %Y %I-%M%p") You have: timeStamp = datetime.datetime.now().strftime("%A, %d.

  3. python - Path in variable - Stack Overflow

    Aug 30, 2011 · For example if i have a path like 'c:\example2\media\uploads\test5.txt' (stored in a variable), but I need something like r'c:\example2\media\uploads\test5.txt', how can I add letter `r? Because the function open() does not want to open the first path.

  4. Create a File Path with Variables in Python - GeeksforGeeks

    May 10, 2024 · Managing file paths is a typical chore in Python programming, particularly when working with file I/O operations. You can construct paths dynamically based on user input or specified criteria by creating a file path with variables. This article will walk you through the ideas and methods for using variables in Python to create file paths.

  5. How to Set File Path in Python - Delft Stack

    Feb 14, 2024 · Setting an absolute file path in Python involves specifying the complete and unambiguous location of a file within the file system. Below are examples using both the os.path module and the pathlib module, two commonly used approaches.

  6. Get Current directory in Python - GeeksforGeeks

    Feb 3, 2024 · os.path.realpath () can be used to get the path of the current Python script. Actually, os.path.realpath () method in Python is used to get the canonical path of the specified filename by eliminating any symbolic links encountered in the path. A special variable __file__ is passed to the realpath () method to get the path of the Python script.

  7. File and directory Paths - Python Cheatsheet

    Checking if a path is a directory Using os.path on *nix: >>> import os >>> os.path.isdir('/') # True >>> os.path.isdir('setup.py') # False >>> os.path.isdir('/spam') # False Using pathlib on *nix: >>> from pathlib import Path >>> Path('/').is_dir() # True >>> Path('setup.py').is_dir() # False >>> Path('/spam').is_dir() # False

  8. PYTHONPATH Environment Variable in Python | GeeksforGeeks

    Sep 5, 2020 · The PYTHONPATH variable holds a string with the name of various directories that need to be added to the sys.path directory list by Python. The primary use of this variable is to allow users to import modules that are not made installable yet.

  9. Python Path: Interact with File System Using Path from pathlib

    In this tutorial, you'll learn how to use the Python Path class from the pathlib to interact with the file system easily and effectively.

  10. python - How do I put a variable in a path - Stack Overflow

    Mar 9, 2022 · You can use f-string (to directly enter your variable) and r-string (to enter the path without escape characters like \) together. val = os.getlogin() # Returns username

Refresh