Render using Python

When I want to render a file in the background, I often use something like this:

/Applications/ --background /Users/paul/Desktop/myfile.blend --render-output //filename_ --render-frame 1

But, how can I do the same thing as a line or two of Python code in a file? I would then call that Python file with:

/Applications/ --background /Users/paul/Desktop/myfile.blend --python Documents/code/

The result is the same, but I can also have many other lines of code in the Python file.

bpy.context.scene.render.filepath = "/where/to/save/the/output.png"

Ah! That’s great. Thank you.

I changed it very slightly:

bpy.context.scene.render.filepath = "/where/to/save/the/output"

Then the file format is given by the blend file and the suffix is added to the file name. And, if one wanted to change the file format:
bpy.context.scene.render.image_settings.file_format = 'PNG'

What do you think?