scotty101 wrote: ↑Mon Jul 30, 2018 9:14 am
The variable conflict is why using "import <filename>" alone is a bad idea. Variables on the global namespace will just overwrite each other.
A better method is to do something like this
Code: Select all
import <filename> as <someabbreviationoffilename>
e.g.
Then variables/functions from that file will need to have the correct namespace before they can be used.
Code: Select all
import tkinter as tk
root = tk.Tk()
It is difficult to make a more detailed recommendation without seeing your code, but it is generally a bad idea for you to have these variable conflicts in the first place. When you import a module, it (generally) shouldn't contain global variables, just functions or classes.
Erm, not sure what you are thinking here... The only difference between
import tkinter and
import tkinter as tk is that the local name bound to the module for the former will be called
tkinter and for the latter will be called
tk. In both cases any names declared in the module will only be in that module's namespace.
I think you are confusing this with
from, e.g.
which would bind local names to each of the module's module-level names.