Skip to content

Instantly share code, notes, and snippets.

@zanerobinson
zanerobinson / python_curses_example.py
Last active July 20, 2021 18:22
[python curses] #python #curses
import sys,os
import curses
def draw_menu(stdscr):
k = 0
cursor_x = 0
cursor_y = 0
# Clear and refresh the screen for a blank canvas
stdscr.clear()
@zanerobinson
zanerobinson / run_command.py
Created September 21, 2018 21:27
[run bash command](use subprocess to pip stderr and stdout) #subprocess #Popen #stdout #stderr #bash
def run_command(cmd_to_run):
"""
Wrapper around subprocess that pipes the stderr and stdout from `cmd_to_run`
to temporary files. Using the temporary files gets around subprocess.PIPE's
issues with handling large buffers.
Note: this command will block the python process until `cmd_to_run` has completed.
Returns a tuple, containing the stderr and stdout as strings.
"""
@zanerobinson
zanerobinson / recursive_parse_file_structure.py
Last active September 21, 2018 23:16
[directory parse] #walk #recursive #files #os
# Import the os module, for the os.walk function
import os
# Set the directory you want to start from
rootDir = '.'
for dirName, subdirList, fileList in os.walk(rootDir):
print('Found directory: %s' % dirName)
for fname in fileList:
print('\t%s' % fname)