Style question: Importing modules from packages
Chris Angelico
rosuav at gmail.com
Wed Dec 3 06:02:17 EST 2014
More information about the Python-list mailing list
Wed Dec 3 06:02:17 EST 2014
- Previous message (by thread): Python, C++ interaction
- Next message (by thread): Style question: Importing modules from packages - 'from' vs 'as'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
When importing a module from a subpackage, it's sometimes convenient to refer to it throughout the code with a one-part name rather than two. I'm going to use 'os.path' for the examples, but my actual use-case is a custom package where the package name is, in the application, quite superfluous. Throughout the code, I want to refer to "path.split()", "path.isfile()", etc, without the "os." in front of them. I could do either of these: import os.path as path from os import path Which one would you recommend? Does it depend on context? An "as" import works only if it's a module in a package, where the "from" import can also import other objects (you can't go "import pprint.pprint as pprint"). I'm fairly sure that's an argument... on one side or another. :) Thoughts? ChrisA
- Previous message (by thread): Python, C++ interaction
- Next message (by thread): Style question: Importing modules from packages - 'from' vs 'as'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list