Feb-20-2018, 02:40 AM
i have found that a few of my scripts, while functional in python2, work better (or at least the way i prefer) in python3. for example: the attribute "st_mtime_ns" is available in the result from
the code being inserted:
this probably only works in unix and linux. any other os experts around here? the best i know of to do is iterate over an empty list from an empty string where the PATH environment variable is not available.
os.lstat(filename)
only in python3 (not in python2). my code, in that case, checks for the existence of that attribute since it can also be absent for other reasons, and deals with it appropriately. so what i am doing is inserting the code shown below, into the script code file (not as a separate file) somewhere near the top after the imports (at least os and sys) are done.the code being inserted:
if sys.version_info.major < 3: for p in os.environ.get('PATH','').split(':'): if p and os.path.exists(p+'/python3'): os.execvp(p+'/python3',['python3']+sys.argv)maybe there is a better way to iterate over the PATH environment variable.
this probably only works in unix and linux. any other os experts around here? the best i know of to do is iterate over an empty list from an empty string where the PATH environment variable is not available.