python Programming Glossary: os.path
Looking for File Traversal Functions in Python that are Like Java's http://stackoverflow.com/questions/140758/looking-for-file-traversal-functions-in-python-that-are-like-javas below a given starting path. An Example import os from os.path import join for root dirs files in os.walk ' usr' print Current..
PYTHON: Replace SRC of all IMG elements using Parser http://stackoverflow.com/questions/1579133/python-replace-src-of-all-img-elements-using-parser really easy from BeautifulSoup import BeautifulSoup from os.path import basename splitext soup BeautifulSoup my_html_string for..
how can i get the executable's current directory in py2exe? http://stackoverflow.com/questions/2292703/how-can-i-get-the-executables-current-directory-in-py2exe platform way where exactly it's being run from SCRIPT_ROOT os.path.dirname os.path.realpath __file__ Pretty simple. I then go on.. exactly it's being run from SCRIPT_ROOT os.path.dirname os.path.realpath __file__ Pretty simple. I then go on to use SCRIPT_ROOT.. basis sys.executable else basis sys.argv 0 required_folder os.path.split basis 0 As I say that worked but I don't recall why I..
How to get file creation & modification date/times in Python? http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python You have a couple of choices. For one you can use the os.path.getmtime and os.path.getctime functions import os.path time.. of choices. For one you can use the os.path.getmtime and os.path.getctime functions import os.path time print last modified s.. the os.path.getmtime and os.path.getctime functions import os.path time print last modified s time.ctime os.path.getmtime file..
Count the number of files in a directory using python http://stackoverflow.com/questions/2632205/count-the-number-of-files-in-a-directory-using-python an ordinary file and not a directory or other entity use os.path.isfile import os os.path print len name for name in os.listdir.. a directory or other entity use os.path.isfile import os os.path print len name for name in os.listdir '.' if os.path.isfile..
Get parent directory in Python http://stackoverflow.com/questions/2860153/get-parent-directory-in-python python share improve this question Try this import os.path print os.path.abspath os.path.join yourpath os.pardir where.. improve this question Try this import os.path print os.path.abspath os.path.join yourpath os.pardir where yourpath is the.. question Try this import os.path print os.path.abspath os.path.join yourpath os.pardir where yourpath is the path you want..
How to list all files of a directory in Python http://stackoverflow.com/questions/3207219/how-to-list-all-files-of-a-directory-in-python want just files you could either filter this down using os.path from os import listdir from os.path import isfile join onlyfiles.. filter this down using os.path from os import listdir from os.path import isfile join onlyfiles f for f in listdir mypath if isfile..
Test if executable exists in Python? http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python I understand but I thought maybe there's something in os.path that does that though named strangely . python path share.. of def which program import os def is_exe fpath return os.path.isfile fpath and os.access fpath os.X_OK fpath fname os.path.split.. fpath and os.access fpath os.X_OK fpath fname os.path.split program if fpath if is_exe program return program else..
How do you check in Linux with Python if a process is still running? [duplicate] http://stackoverflow.com/questions/38056/how-do-you-check-in-linux-with-python-if-a-process-is-still-running there. For something a little more copy pasteable import os.path os.path.exists proc 0 False os.path.exists proc 12 True share.. For something a little more copy pasteable import os.path os.path.exists proc 0 False os.path.exists proc 12 True share improve..
How to get the home directory in Python? http://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python home share improve this question You want to use os.path.expanduser . This will ensure it works on all platforms from.. . This will ensure it works on all platforms from os.path import expanduser home expanduser ~ share improve this answer..
Silent printing of a PDF in Python http://stackoverflow.com/questions/4498099/silent-printing-of-a-pdf-in-python file . Here I found this implementation import win32ui dde os.path time from win32api import FindExecutable from os import spawnl.. os import spawnl P_NOWAIT ... pd C temp test.pdf pdbits os.path.split pd readerexe FindExecutable pdbits 1 pdbits 0 spawnl P_NOWAIT..
cross-platform splitting of path in python http://stackoverflow.com/questions/4579908/cross-platform-splitting-of-path-in-python will work with Windows paths too. I know that there is an os.path.split but that doesn't do what I want and I didn't see anything.. good idea to separate out any drive designator first using os.path.splitdrive . Then reassembling the path if required can be done.. the path if required can be done correctly by drive os.path.join other_pieces Secondly Windows paths can contain slashes..
Find current directory and file's directory http://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory asked for directory of given file so the proper answer is os.path.dirname os.path.realpath __file__ To get the current working.. of given file so the proper answer is os.path.dirname os.path.realpath __file__ To get the current working directory use os.getcwd.. of the current directory file you can use the os module os.path in particular and os.path.realpath __file__ . To get the path..
Filtering os.walk() dirs and files http://stackoverflow.com/questions/5141437/filtering-os-walk-dirs-and-files for path in paths append None for include in includes if os.path.isdir path append True break if fnmatch.fnmatch path include.. include append True break for exclude in excludes if os.path.isdir path and path exclude append False break if fnmatch.fnmatch.. in os.walk ' home paulo freitas' dirs _filter map lambda d os.path.join root d dirs files _filter map lambda f os.path.join root..
Python, extract file name from path, no matter what the os/path format http://stackoverflow.com/questions/8384737/python-extract-file-name-from-path-no-matter-what-the-os-path-format .. .. a b c python share improve this question Using os.path.split or os.path.basename as others suggest won't work in all.. share improve this question Using os.path.split or os.path.basename as others suggest won't work in all cases if you're.. Therefore the ntpath module which is equivalent to os.path when running on windows will work for all 1 paths on all platforms...
|