Skip to content

Instantly share code, notes, and snippets.

@johanek
Last active August 31, 2021 08:59
Show Gist options
  • Save johanek/f09ef6cc922c796e8834b68e60da8702 to your computer and use it in GitHub Desktop.
Save johanek/f09ef6cc922c796e8834b68e60da8702 to your computer and use it in GitHub Desktop.
[python basics] #python

List files in a directory

os.listdir(path)

List files recursively

os.walk(path)

Read YAML file

with open("data.yaml", 'r') as stream:
	data_loaded = yaml.load(stream)

ipython autoreload

%load_ext autoreload
%autoreload 2

File exists

os.path.exists(path)
os.path.isdir(path)

Write to file

with open("demofile2.txt", "w+") as f:
	f.write("Now the file has more content!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment