About 1,790,000 results
Open links in new tab
  1. How should I write a Windows path in a Python string literal?

    Apr 9, 2023 · Path takes a path-like string and adjusts everything for the current OS, either Windows or Linux. For example, on Linux it would convert all backslashes to forward slashes, and on Windows it …

  2. python - Formatting File Paths - Stack Overflow

    Aug 13, 2013 · My script takes in multiple file names that can be in any directory. In my script I need python to change to the directory of the file and then perform some actions.

  3. What is the preferred way to write a file path in Python

    0 When writing a file path in python, I have seen several variations to write the syntax and I was curious if there is just one preferred way: the examples are:

  4. python - How to change the format of a path string to a different OS ...

    I need to change a file path from MAC to Windows and I was about to just do a simple .replace() of any / with \\ but it occurred to me that there may be a better way. So for example I need to change...

  5. Python Convert Windows File path in a variable - Stack Overflow

    Oct 1, 2018 · Assuming your task relates only to Windows, so you are getting a Windows-specific path from somewhere in a Windows-native representation (i.e. the "\t" is not expected to be an escape …

  6. python - How can I create a full path to a file from parts (e.g. path ...

    I need to pass a file path name to a module. How do I build the file path from a directory name, base filename, and a file format string? The directory may or may not exist at the time of call. ...

  7. Path name format - Windows - Python - Stack Overflow

    May 23, 2018 · I am working on a code that takes the path of a file and the reads it. The code is, import sys import os user_input = input ("Enter the path of your file: ") assert os.path.exists (user_input), ...

  8. How to get an absolute file path in Python - Stack Overflow

    Sep 9, 2008 · You could give any pathname- non-existent files and directory heirarchies are fine- and abspath will simply resolve the bits of the path (including the parent directory ".. " element) and return …

  9. Python: Formatting file paths with a variable filename

    Jun 30, 2020 · I would suggest using either pathlib or os.path module in case you are working with paths and want your project to be compatible with different OS. For pathlib, you can use the following snippet.

  10. Extract file name from path, no matter what the os/path format

    Dec 5, 2011 · Which Python library can I use to extract filenames from paths, no matter what the operating system or path format could be? For example, I'd like all of these paths to return me c: …