Home > front end >  Bash script to Python
Bash script to Python

Time:01-02

I am trying to translate a Bash script to Python. I was wondering what is the equivalent of folderConfig="${homeDirectory}/conf" in Python please. Is this a working directory ?

CodePudding user response:

That's parameter expansion in a shell script (not specific to bash) and can be achieved in Python with string concatenation or string interpolation in f-strings:

folderConfig = homeDirectory   '/conf' # string concatenation
folderConfig = f'{homeDirectory}/conf' # f-string

CodePudding user response:

You could use pathlib to obtain a Path object:

from pathlib import Path

# Either use the slash operator:
folderConfig = Path.home() / 'conf'

# Or call joinpath to do the same thing:
folderConfig = Path.home().joinpath('conf')

print(folderConfig.as_posix())
  • Related