Skip to content

Instantly share code, notes, and snippets.

@nnelluri928
Created October 12, 2021 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnelluri928/94e1f0b8f24cbfddbd6ca7ff57c9a9ee to your computer and use it in GitHub Desktop.
Save nnelluri928/94e1f0b8f24cbfddbd6ca7ff57c9a9ee to your computer and use it in GitHub Desktop.

In [22]: import os

In [23]: os.path.dirname("/Users/nnelluri/Desktop/nnelluri/python3-proj/add_device.py") Out[23]: '/Users/nnelluri/Desktop/nnelluri/python3-proj'

In [24]: import pathlib

In [25]: path=pathlib.Path("/Users/nnelluri/Desktop/nnelluri/python3-proj/add_device.py")

In [26]: path.parent Out[26]: PosixPath('/Users/nnelluri/Desktop/nnelluri/python3-proj')

In [27]: str(path.parent) Out[27]: '/Users/nnelluri/Desktop/nnelluri/python3-proj'

In [28]: with open(filename) as my_file: contents = my_file.read()

from pathlib import Path contents = Path(filename).read_text()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment