Reputation: 21
I'm trying to simplify the code instead of changing a bunch of variables.
For example:
title = "example"
filepath = r"C:\Users\User\Desktop\Research\title"
I want the output to be C:\Users\User\Desktop\Research\example
, but it returns the quoted string.
How would I make it read the "title" variable instead?
Upvotes: 1
Views: 28
Reputation: 21305
Use a formatting string along with your raw string.
title = "example"
filepath = rf"C:\Users\User\Desktop\Research\{title}"
Output:
>>> print(filepath)
C:\Users\User\Desktop\Research\example
>>>
Upvotes: 1