# # Example file for working with os.path module # (For Python 3.x, be sure to use the ExampleSnippets3.txt file) import os from os import path import datetime from datetime import date, time, timedelta import time def main(): # Print the name of the OS print os.name # Check for item existence and type print "Item exists: " + str(path.exists("textfile.txt")) print "Item is a file: " + str(path.isfile("textfile.txt")) print "Item is a directory: " + str(path.isdir("textfile.txt")) # Work with file paths print "Item's path: " + str(path.realpath("textfile.txt")) print "Item's path and name: " + str(path.split(path.realpath("textfile.txt"))) # Get the modification time t = time.ctime(path.getmtime("textfile.txt")) print t print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")) # Calculate how long ago the item was modified td= datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")) print "It has been " + str(td) + "The file was modified" print "Or, " + str(td.total_seconds()) + " seconds" if __name__ == "__main__": main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question