The string module contains a set of useful constants, such as ascii_letters and digits, and the module is often still imported for that reason.
import using string
Can you import f-strings in Python 3.5?
No, there's no way to do that. It represents a fundamental change to the syntax of the language, requiring the interpreter itself to be modified. Modules can't do that.
It would be theoretically possible to backport the change to 3.5 available under a __future__ flag, but that's never going to happen. 3.5 is in maintenance mode status, and you can't add new major features on an existing release branch. The print_function capability happened in 2.6 because there was a concerted effort underway long before 2.6 was released to make the transition possible. 2.6 and 3.0 were coordinated releases that were developed in tandem, which is why 2.6 was able to ship with the ability to enable print as a function, since it was known that there would be a wide gulf between 2.6 and 3.0.
And it's not necessary in the way that the print function change was. You can write code that's compatible with 3.5 and 3.6 by just not using f-strings. That's not the case with the print function vs print statement. It's impossible(*) to write code that works under both without the help of __future__.
(*) If you're only passing a single argument, you can write print(foo) under 2.x and the parentheses are ignored as redundant, but that breaks down as soon as you need to do anything else.
Videos
The string module contains a set of useful constants, such as ascii_letters and digits, and the module is often still imported for that reason.
If you see a import string but never see string.something, someone just forgot to remove an unused import.
While there did use to be some things in string that are now standard methods of str objects, you still had to either
- prefix them with
string.after importing the library, or - use
from string import <whatever>syntax.
Typically, the only times you'll see something properly imported but never "explicitly used" are from __future__ import with_statement or the like - the forwards/backwards compatability triggers used by Python for new language features.
I am making a “updater” program that checks for updates, installs it, and runs scripts. So, I want to pass a file path string to the program, and make it import from there.