You import a Python module with the variable you’ll define, not a filename. “import mymod” tells Python to find mymod.py in each dir in sys.path. The first directory is ” (the empty string) — i.e., the directory where the program is running (i.e., not where it was defined).
I recently asked subscribers to my free, weekly “better developers” newsletter to send me their Python programming questions, promising that (a) I’d try to solve them, and publish the result to YouTube, and (b) anyone who submitted a problem that I selected would then get a coupon for 30% off of any of my books…
One of the first things that Python programmers learn is that you can easily read through the contents of an open file by iterating over it: f = open(‘/etc/passwd’) for line in f: print(line) Note that the above code is possible because our file object “f” is an iterator. In other words, f…