Skip to content

Instantly share code, notes, and snippets.

@mertyildiran
Created November 6, 2020 02:18
Show Gist options
  • Save mertyildiran/fd3c69a59172acd3a50436b8380386f7 to your computer and use it in GitHub Desktop.
Save mertyildiran/fd3c69a59172acd3a50436b8380386f7 to your computer and use it in GitHub Desktop.
Homework iterator
#!/bin/python3
import glob
import subprocess
import psutil
def kill(proc_pid):
process = psutil.Process(proc_pid)
for proc in process.children(recursive=True):
proc.kill()
process.kill()
files = glob.glob("*/*", recursive = True)
files.sort()
with open("grades.txt", "a") as grades:
for filepath in files:
folder = filepath.split('/')[0]
student_name = folder.split('_')[0]
process = subprocess.Popen(["libreoffice", "--calc", "--norestore", filepath], shell=False)
grade = input("Enter the grade for student %s: " % student_name)
grades.write("{: >20} {: >20}\n".format(student_name, grade))
kill(process.pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment