7bisso 7bisso - 1 year ago 69
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

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

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

Answer Source

Since you just need the username:

import getpass
user = getpass.getuser()
fname = "com.strange.things." + user + ".more.strange.things"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download