Last active
October 6, 2016 19:29
-
-
Save nicoguaro/2f02554b763172f5d603e59f442a74bc to your computer and use it in GitHub Desktop.
Python scripts for working with files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Erase all PNG files in a folder that do not end | |
with a certain pattern | |
@author: Nicolas Guarin-Zapata | |
""" | |
import os | |
files = os.listdir("./") | |
nums = tuple(str(num).zfill(3) + ".png" | |
for num in range(0, 21, 5)) | |
for fil in files: | |
if fil.endswith(".png") and\ | |
not fil.endswith(nums): | |
os.remove(fil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Crop several images in the same region | |
@author: Nicolas Guarin-Zapata | |
""" | |
import os | |
from PIL import Image | |
files = os.listdir("./") | |
x0, x1 = 480, 950 | |
y0, y1 = 470, 740 | |
for fil in files: | |
if fil.endswith(".png"): | |
im = Image.open(fil) | |
im.crop((x0, y0, x1, y1)).save("cropped_" + fil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Replace a pattern in several files | |
@author: Nicolas Guarin-Zapata | |
""" | |
import os | |
files = os.listdir("./") | |
for fil in files: | |
if fil.endswith(".png"): | |
name = fil.replace("bouligand", "bouli") | |
os.rename(fil, name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Visualize docstrings in the browser""" | |
def see_docs(fun, name=None): | |
import webbrowser | |
import docrepr # Set module options | |
from docrepr import sphinxify # html generator | |
from IPython.core.oinspect import Inspector # oinfo generator | |
oinfo = Inspector().info(fun, ) | |
oinfo['name'] = name | |
url = sphinxify.rich_repr(oinfo) | |
webbrowser.open_new_tab(url) | |
# Example | |
if __name__ == "__main__": | |
import numpy as np | |
see_docs(np.sin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment