Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
switching to python3
#1
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 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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
switching to python3 - by Skaperen - Feb-20-2018, 02:40 AM
RE: switching to python3 - by Larz60+ - Feb-20-2018, 03:40 AM
RE: switching to python3 - by Skaperen - Feb-20-2018, 03:47 AM
RE: switching to python3 - by Larz60+ - Feb-20-2018, 05:54 AM
RE: switching to python3 - by Skaperen - Feb-22-2018, 06:20 AM
RE: switching to python3 - by Gribouillis - Feb-22-2018, 01:22 PM
RE: switching to python3 - by Skaperen - Feb-23-2018, 06:11 AM
RE: switching to python3 - by Gribouillis - Feb-23-2018, 10:28 AM
RE: switching to python3 - by Skaperen - Feb-24-2018, 03:31 AM
RE: switching to python3 - by Gribouillis - Feb-24-2018, 03:44 AM
RE: switching to python3 - by Skaperen - Feb-25-2018, 02:09 AM
RE: switching to python3 - by Gribouillis - Feb-25-2018, 06:34 AM
RE: switching to python3 - by Skaperen - Feb-25-2018, 07:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  switching from notebook to pycharm enterthevoid22 1 1,767 Oct-10-2020, 05:20 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020