Hi Hartmut,
> This is what I meant. But seeing the result I propose not using varnames> 
> therefore doing at all :-)
It is sort of a trade of between safety:- i.e. not accidentally
misspelling a string literal when used for the 4th timeand
readability- i.e.    sys._MEIPASS = os.environ[MEIPASS2]  is easier to
comprehend than    setattr(sys, MEIPASS, os.environ[MEIPASS2])
So just to make sure what you want to be the result: A, B or C:(See
below.)
Personally, I believe that B is the nicest as we use a var for
"_MEIPASS2" to avoid using the same string literal 4 times. Also, the
code is rewritten to only access attr _MEIPASS once so we can get rid
of the call to setattr.I think B gives at least as good readability as
C if not better as you do not have to assure youself that "_MEIPASS2"
is spelled the same way 4 times.
Do you agree?
/Martin
A) Both _MEIPASS and _MEIPASS2 as variablesMEIPASS =
'_MEIPASS'MEIPASS2 = '_MEIPASS2'if MEIPASS2 in os.environ:   
meipass2Value = os.environ[MEIPASS2]
    # Ensure sys._MEIPASS is absolute path.    meipass2Value =
os.path.normpath(meipass2Value)    meipass2Value =
os.path.abspath(meipass2Value)    setattr(sys, MEIPASS, meipass2Value)
    # Delete _MEIPASS2 from environment.    del os.environ[MEIPASS2]
    # On some platforms (e.g. AIX) 'os.unsetenv()' is not available
and then    # deleting the var from os.environ does not delete it from
the environment.    # In those cases we cannot delete the variable but
only set it to the    # empty string.    if not hasattr(os,
'unsetenv'):        os.putenv(MEIPASS2, '')
B) Only _MEIPASS2 as variable (it is used 4 time).MEIPASS2 =
'_MEIPASS2'if MEIPASS2 in os.environ:    meipass2Value =
os.environ[MEIPASS2]
    # Ensure sys._MEIPASS is absolute path.    meipass2Value =
os.path.normpath(meipass2Value)    meipass2Value =
os.path.abspath(meipass2Value)    sys._MEIPASS = meipass2Value
    # Delete _MEIPASS2 from environment.    del os.environ[MEIPASS2]
    # On some platforms (e.g. AIX) 'os.unsetenv()' is not available
and then    # deleting the var from os.environ does not delete it from
the environment.    # In those cases we cannot delete the variable but
only set it to the    # empty string.    if not hasattr(os,
'unsetenv'):        os.putenv(MEIPASS2, '')
C) Neither _MEIPASS nor _MEIPASS2 as variables.if '_MEIPASS2' in
os.environ:    meipass2Value = os.environ['_MEIPASS2']
    # Ensure sys._MEIPASS is absolute path.    meipass2Value =
os.path.normpath(meipass2Value)    meipass2Value =
os.path.abspath(meipass2Value)    sys._MEIPASS = meipass2Value
    # Delete _MEIPASS2 from environment.    del
os.environ['_MEIPASS2']
    # On some platforms (e.g. AIX) 'os.unsetenv()' is not available
and then    # deleting the var from os.environ does not delete it from
the environment.    # In those cases we cannot delete the variable but
only set it to the    # empty string.    if not hasattr(os,
'unsetenv'):        os.putenv('_MEIPASS2', '')

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyinstaller?hl=en.

Reply via email to