In schedule, how do I print a nice list of jobs?

  • Windows 10 Pro with Python 3.11
  • I’m just using a text editor to write programs and running the program in cmd.exe in a virtual environment.
  • I’m still fairly new to Python.

Our Windows task scheduler is unreliable, jobs get cancelled for some reason. So I’m writing my own scheduler in Python.

I try to print the jobs like this:

    joblist = schedule.get_jobs()
    print("Jobs are: ")
    print(joblist)

It runs jobs just fine but when I print a list of jobs the output is messy. Here’s what I get.

[Every 1 week at 04:00:00 do rundailypw() (last run: [never], next run: 2024-05-06 04:00:00), Every 1 week at 04:00:00 do rundailypw() (last run: [never], next run: 2024-05-07 04:00:00), Every 1 week at 04:00:00 do rundailypw() (last run: [never], next run: 2024-05-01 04:00:00), Every 1 week at 04:00:00 do rundailypw() (last run: [never], next run: 2024-05-02 04:00:00), Every 1 week at 04:00:00 do rundailypw() (last run: [never], next run: 2024-05-03 04:00:00)]

If I split on a comma it won’t look right because commas appear to be used within each entry not just between entries. A single entry appears to be this:

Every 1 week at 04:00:00 do rundailypw() (last run: [never], next run: 2024-05-06 04:00:00)

Any ideas how to get each job to print on one line?

Have you tried the pprint module from the standard library?

1 Like

Use a for loop and print each string in the list.
It is a list of strings.

That did it! I forgot about that. #noobMistake