3 ms·
There's no well known module to do most this for you? In perl, the recent canonical way is to use the FindBin module to find the current binary's running dir,
by kbenson 5y ago
There's no well known module to do most this for you? In perl, the recent canonical way is to use the FindBin module to find the current binary's running dir, and the the local::lib module to set the import path (or just use lib for older style library dirs). That always seemed cumbersome to me at 2-3 lines that weren't very clean looking.
Also, say what you will about Perl and esoteric global variables, but it's kinda nice to be able to toggle buffered output on and off on the fly. Is there really no way to do this in python without re-executing the script like that?
- icegreentea2 5y agoYa... if you're trying to get the path of the script, you can use `__file__` special variable (instead of loading it from bash $0 and grabbing sys.argv[0]). For adding current directory to front of path, the sys.path.insert() call is a pretty sound way of doing it.
- yongjik 5y agoYeah, I think you're right - didn't know about __file__. (To clarify, using "$0" with bash is just standard method to invoke the same script with an interpreter - sys.argv[0] will work with or without bash exec part.)