7bisso 7bisso - 1 month ago 6
Python Question

How do I dynamically generate a file name in python?

We're working on a python application for MAC OSX that should be pip-installable, and we want to automate the creation of a

plist
file during installation, but the file name must contain the OSX username in order for the application to work, eg.
com.username.app.plist
.

Q : How do I dynamically generate such a file in python ?

Answer

Since you just need the username:

import getpass
user = getpass.getuser()
fname = "com.strange.things." + user + ".more.strange.things"
Comments