__file__ should be avoided in library code
See original GitHub issueWe should be using pkg_resources
(or importlib.resources
if our min Python version is 3.7) instead of uses of __file__
.
$ get grep '__file__' sklearn/
sklearn/__check_build/__init__.py: local_dir = os.path.split(__file__)[0]
sklearn/datasets/_base.py: module_path = dirname(__file__)
sklearn/datasets/_base.py: module_path = dirname(__file__)
sklearn/datasets/_base.py: module_path = dirname(__file__)
sklearn/datasets/_base.py: module_path = dirname(__file__)
sklearn/datasets/_base.py: module_path = dirname(__file__)
sklearn/datasets/_base.py: base_dir = join(dirname(__file__), 'data/')
sklearn/datasets/_base.py: with open(dirname(__file__) + '/descr/linnerud.rst') as f:
sklearn/datasets/_base.py: module_path = dirname(__file__)
sklearn/datasets/_base.py: module_path = join(dirname(__file__), "images")
sklearn/datasets/_california_housing.py: module_path = dirname(__file__)
sklearn/datasets/_covtype.py: module_path = dirname(__file__)
sklearn/datasets/_kddcup99.py: module_path = dirname(__file__)
sklearn/datasets/_lfw.py: module_path = dirname(__file__)
sklearn/datasets/_lfw.py: module_path = dirname(__file__)
sklearn/datasets/_olivetti_faces.py: module_path = dirname(__file__)
sklearn/datasets/_rcv1.py: module_path = dirname(__file__)
sklearn/datasets/_twenty_newsgroups.py: module_path = dirname(__file__)
sklearn/datasets/_twenty_newsgroups.py: module_path = dirname(__file__)
sklearn/datasets/tests/test_openml.py:currdir = os.path.dirname(os.path.abspath(__file__))
sklearn/datasets/tests/test_svmlight_format.py:currdir = os.path.dirname(os.path.abspath(__file__))
sklearn/utils/__init__.py: root = str(Path(__file__).parent.parent) # sklearn package
sklearn/utils/_testing.py: cwd = op.normpath(op.join(op.dirname(sklearn.__file__), '..'))
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Characters to Avoid in Filenames and Directories
Keep your filenames to a reasonable length and be sure they are under 31 characters. Most operating systems are case sensitive; always use...
Read more >How to avoid including the same code when using C++ ...
I'm worried that when the library is compiled, and then linked to another project that also uses string and cout, the code for...
Read more >File naming and structure - Research Data Management at ...
Avoid special characters or spaces in a file name; Use capitals and underscores instead of periods or spaces or slashes; Use date format...
Read more >Code style and coding guidelines — C++ library for Named ...
File names should be all lower case. If the class name is a composite of several words, each word in a file name...
Read more >Difference between Header file and Library - GeeksforGeeks
Header Files: The files that tell the compiler how to call some ... user can compile his/her code without using these libraries.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @devpramod, I believe @jackzyliu is waiting for comments and reviews in #20297 . It would be nice if you comment there rather than starting a new pull request. Thanks!
For future reference: see https://github.com/indygreg/PyOxidizer/issues/69 for more context why using
__file__
is problematic.