import os home_directories = os.listdir("/home") for user in home_directories: os.system("sa-learn --spam /home/%s/mail/Junk" % user)