當前位置: 首頁>>代碼示例>>Python>>正文


Python sys.exec_prefix方法代碼示例

本文整理匯總了Python中sys.exec_prefix方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.exec_prefix方法的具體用法?Python sys.exec_prefix怎麽用?Python sys.exec_prefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sys的用法示例。


在下文中一共展示了sys.exec_prefix方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def __init__(self, fileName):
        scriptEnv = Python.CreateRuntime()
        self.fileName = fileName
        self.engine = scriptEnv.GetEngine("python")        
        self.context = HostingHelpers.GetLanguageContext(self.engine) 
        scriptEnv.LoadAssembly(Type.GetType("System.String").Assembly) #mscorlib.dll
        scriptEnv.LoadAssembly(UriBuilder().GetType().Assembly)  #System.dll
                
        self.InitializePath()
        
        executable = Assembly.GetEntryAssembly().Location
        prefix = Path.GetDirectoryName(executable)
        
        self.context.SystemState.executable = executable
        self.context.SystemState.exec_prefix = self.context.SystemState.prefix = prefix
        
        import imp
        mod = imp.new_module('__main__')
        mod.__file__ = fileName
        mod.__builtins__ = sys.modules['__builtin__']
        self.context.SystemState.modules['__main__'] = mod
        self.mainScope = scriptEnv.CreateScope(mod.__dict__) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:run_interactive.py

示例2: test_user_similar

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_user_similar(self):
        # Issue #8759: make sure the posix scheme for the users
        # is similar to the global posix_prefix one
        base = get_config_var('base')
        user = get_config_var('userbase')
        # the global scheme mirrors the distinction between prefix and
        # exec-prefix but not the user scheme, so we have to adapt the paths
        # before comparing (issue #9100)
        adapt = sys.prefix != sys.exec_prefix
        for name in ('stdlib', 'platstdlib', 'purelib', 'platlib'):
            global_path = get_path(name, 'posix_prefix')
            if adapt:
                global_path = global_path.replace(sys.exec_prefix, sys.prefix)
                base = base.replace(sys.exec_prefix, sys.prefix)
            user_path = get_path(name, 'posix_user')
            self.assertEqual(user_path, global_path.replace(base, user, 1)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_sysconfig.py

示例3: test_S

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_S(self):
        """Test the -S (suppress site initialization) option."""

        # Create a local site.py that sets some global context. Do this in a temporary directory to avoid accidently
        # overwriting a real site.py or creating confusion. Use the IRONPYTHONPATH environment variable to point
        # IronPython at this version of site.py.
        from System import Environment
        with open(os.path.join(self.tmpdir, "site.py"), "w") as f:
            f.write("import sys\nsys.foo = 123\n")
        
        with IronPythonVariableContext("IRONPYTHONPATH", self.tmpdir, prepend=True):
            print(Environment.GetEnvironmentVariable("IRONPYTHONPATH"))
            # Verify that the file gets loaded by default.
            self.TestCommandLine(("-c", "import sys; print(sys.foo)"), "123\n")
            
            # CP778 - verify 'site' does not show up in dir()
            self.TestCommandLine(("-c", "print('site' in dir())"), "False\n")
            
            # Verify that Lib remains in sys.path.
            self.TestCommandLine(("-S", "-c", "import os ; import sys; print(str(os.path.join(sys.exec_prefix, 'Lib')).lower() in [x.lower() for x in sys.path])"), "True\n")
            
            # Now check that we can suppress this with -S.
            self.TestCommandLine(("-S", "-c", "import sys; print(sys.foo)"), ("lastline", "AttributeError: 'module' object has no attribute 'foo'\n"), 1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_stdconsole.py

示例4: test_from_cmdline

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_from_cmdline():
    '''
    '''
    from iptest.console_util import IronPythonInstance
    from sys import executable, exec_prefix
    from System import Environment
    
    extraArgs = ""
    if "-X:PreferComInteropAssembly" in Environment.GetCommandLineArgs():
        extraArgs += "-X:PreferComInteropAssembly"
        
    #Does it work from the commandline with positive cases?
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    try:
        ipi.ExecuteLine("from System import Type, Activator")
        ipi.ExecuteLine("com_obj = Activator.CreateInstance(Type.GetTypeFromProgID('DlrComLibrary.DlrUniversalObj'))")
        
        #Dev10 409941    
        Assert("System.__ComObject" in ipi.ExecuteLine("print com_obj"))            
        AreEqual(ipi.ExecuteLine("print com_obj.m0()"), "None")
    finally:
        ipi.End() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:method.py

示例5: test_cp20519

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_cp20519(self):
        import os
        import System

        cp20519_vb_filename = os.path.join(self.temporary_dir, "cp20519_vb_module.vb")
        f = open(cp20519_vb_filename, "w")
        f.writelines(cp20519_vb_snippet)
        f.close()

        cp20519_vb_exename  = os.path.join(self.temporary_dir, "cp20519_vb.exe")
        compile_cmd = "/target:exe /out:%s %s /reference:%s /reference:%s /reference:%s" % (cp20519_vb_exename,
                                                                            cp20519_vb_filename,
                                                                            os.path.join(sys.exec_prefix, "IronPython.dll"),
                                                                            os.path.join(sys.exec_prefix, "Microsoft.Scripting.dll"),
                                                                            os.path.join(sys.exec_prefix, "Microsoft.Dynamic.dll"))
        self.assertEqual(self.run_vbc(compile_cmd), 0)
        for x in ["IronPython.dll", "Microsoft.Scripting.dll", "Microsoft.Dynamic.dll"]:
            System.IO.File.Copy(os.path.join(sys.exec_prefix, x), os.path.join(self.temporary_dir, x), True)

        self.assertEqual(os.system(cp20519_vb_exename), 0)
        os.remove(cp20519_vb_exename)
        os.remove(cp20519_vb_filename) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_dynamic_regressions.py

示例6: test_c1cs

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_c1cs(self):
        """verify re-loading an assembly causes the new type to show up"""
        if not self.has_csc():
            return
        
        c1cs = get_local_filename('c1.cs')
        outp = sys.exec_prefix
        
        self.compileAndRef('c1', c1cs, '/d:BAR1')
        
        import Foo
        class c1Child(Foo.Bar): pass
        o = c1Child()
        self.assertEqual(o.Method(), "In bar1")
        
        
        self.compileAndRef('c1_b', c1cs)
        import Foo
        class c2Child(Foo.Bar): pass
        o = c2Child()
        self.assertEqual(o.Method(), "In bar2")
        # ideally we would delete c1.dll, c2.dll here so as to keep them from cluttering up
        # /Public; however, they need to be present for the peverify pass.

    #TODO: @skip("multiple_execute") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_importpkg.py

示例7: test_exceptions_nested

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_exceptions_nested():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)

    ipi.ExecutePartialLine("def a(): return b()")
    ipi.ExecuteLine("")
    ipi.ExecutePartialLine("def b(): return 1/0")
    ipi.ExecuteLine("")
    response = ipi.ExecuteLine("a()", True)
    response = response.replace("\r\r\n", "\n").strip()
    Assert(response.startswith('''Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in a
  File "<stdin>", line 1, in b
ZeroDivisionError:'''), response)
            
    ipi.End()


###############################################################################
# Test "ipy.exe -i script.py" 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,代碼來源:test_interactive.py

示例8: test_incomplate_syntax_backslash

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_incomplate_syntax_backslash():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
       
    for i in xrange(4):
        for j in xrange(i):
            ipi.ExecutePartialLine("\\")
        ipi.ExecutePartialLine("1 + \\")
        for j in xrange(i):
            ipi.ExecutePartialLine("\\")
        response = ipi.ExecuteLine("2", True)
        Assert("3" in response)
    
    ipi.End()

###########################################################
# if , while, try, for and then EOF. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_interactive.py

示例9: test_whitespace

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_whitespace():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecuteLine("  ")
    response = ipi.ExecuteLine("")
    ipi.End()
    
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecuteLine("  ")
    response = ipi.ExecuteLine("2")
    Assert("2" in response)
    ipi.End()
    
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecuteLine("  ")
    response = ipi.ExecuteLine("  2", True)
    Assert("SyntaxError:" in response)
    ipi.End()


###########################################################
# test the indentation error in the interactive mode 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_interactive.py

示例10: test_comments

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_comments():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    
    response = ipi.ExecuteLine("# this is some comment line")
    AreEqual(response, "")
    response = ipi.ExecuteLine("    # this is some comment line")
    AreEqual(response, "")
    response = ipi.ExecuteLine("# this is some more comment line")
    AreEqual(response, "")
    ipi.ExecutePartialLine("if 100:")
    ipi.ExecutePartialLine("    print 100")
    ipi.ExecutePartialLine("# this is some more comment line inside if")
    ipi.ExecutePartialLine("#     this is some indented comment line inside if")
    ipi.ExecutePartialLine("    print 200")
    response = ipi.ExecuteLine("")
    AreEqual(response, "100" + newline + "200")
    ipi.End() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_interactive.py

示例11: test_globals8961

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_globals8961():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    
    response = ipi.ExecuteLine("print globals().keys()")
    res = set(eval(response))
    AreEqual(res, set(['__builtins__', '__name__', '__doc__']))
    
    ipi.ExecuteLine("a = None")
    response = ipi.ExecuteLine("print globals().keys()")
    res = set(eval(response))
    AreEqual(res, set(['__builtins__', '__name__', '__doc__', 'a']))
    response = ipi.ExecuteLine("print globals().values()")
    l = eval(response.replace("<module '__builtin__' (built-in)>", '"builtin"'))
    res = set(l)
    AreEqual(len(l), 4)
    AreEqual(res, set(['builtin', '__main__', None]))
    
    ipi.ExecuteLine("b = None")
    response = ipi.ExecuteLine("print globals().values()")
    l = eval(response.replace("<module '__builtin__' (built-in)>", '"builtin"'))
    res = set(l)
    AreEqual(len(l), 5)
    AreEqual(res, set(['builtin', '__main__', None])) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_interactive.py

示例12: test_console_input_output

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_console_input_output():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    input_output = [
    ("x=100",""),
    ("x=200\n",""),
    ("\nx=300",""),
    ("\nx=400\n",""),
    ("500","500"),
    ("600\n\n\n\n\n\n\n\n\n\n\n","600"),
    ("valid=3;more_valid=4;valid","3"),
    ("valid=5;more_valid=6;more_valid\n\n\n\n\n","6"),
    ("valid=7;more_valid=8;#valid",""),
    ("valid=9;valid;# more_valid\n","9"),
    ("valid=11;more_valid=12;more_valid# should be valid input\n\n\n\n","12"),
    ]
    
    
    for x in input_output:
        AreEqual(ipi.Start(), True)
        AreEqual(ipi.ExecuteLine(x[0]),x[1])
        ipi.End()
    
# expect a clean exception message/stack from thread 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_interactive.py

示例13: test_ipy_dash_m_pkgs

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_ipy_dash_m_pkgs(): 
    # Python packages work
    import nt
    Assert("testpkg1" in [x.lower() for x in nt.listdir(nt.getcwd())], nt.getcwd())
    
    old_ipy_path = get_environ_variable("IRONPYTHONPATH")
    try:
        nt.environ["IRONPYTHONPATH"] = nt.getcwd()
        ipi = IronPythonInstance(executable, exec_prefix, extraArgs + " -m testpkg1")
        res, output, err, exit = ipi.StartAndRunToCompletion()
        AreEqual(res, True) # run should have worked
        AreEqual(exit, 0)   # should have returned 0
        AreEqual(output, "")
    
        # Bad module names should not work
        ipi = IronPythonInstance(executable, exec_prefix, extraArgs + " -m libxyz")
        res, output, err, exit = ipi.StartAndRunToCompletion()
        AreEqual(res, True) # run should have worked
        AreEqual(exit, 1)   # should have returned 0
        Assert("ImportError: No module named libxyz" in err,
               "stderr is:" + str(err))
    finally:
        nt.environ["IRONPYTHONPATH"] = old_ipy_path 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_interactive.py

示例14: test_exception_slicing_warning

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def test_exception_slicing_warning():
    ipi = IronPythonInstance(executable, exec_prefix, '-c "print Exception(*range(2))[1]"')
    res = ipi.StartAndRunToCompletion()
    AreEqual(res[0], True)  # should have started
    AreEqual(res[1], '1\r\n')   # some std out
    AreEqual(res[2], '')    # no std err
    AreEqual(res[3], 0)     # should return 0
    
    ipi = IronPythonInstance(executable, exec_prefix,
        '-3 -c "import warnings;'
        'warnings.filters.reverse();'
        'warnings.filters.pop();'
        'print Exception(*range(2))[1]"')
    res = ipi.StartAndRunToCompletion()
    AreEqual(res[0], True)  # should have started
    AreEqual(res[1], '1\r\n')   # std out
    Assert(res[2].endswith('DeprecationWarning: __getitem__ not supported for exception classes in 3.x; use args attribute\r\n')) #std err
    AreEqual(res[3], 0)     # should return 0

#------------------------------------------------------------------------------ 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_interactive.py

示例15: _find_w9xpopen

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exec_prefix [as 別名]
def _find_w9xpopen(self):
            """Find and return absolut path to w9xpopen.exe"""
            w9xpopen = os.path.join(
                            os.path.dirname(_winapi.GetModuleFileName(0)),
                                    "w9xpopen.exe")
            if not os.path.exists(w9xpopen):
                # Eeek - file-not-found - possibly an embedding
                # situation - see if we can locate it in sys.exec_prefix
                w9xpopen = os.path.join(os.path.dirname(sys.base_exec_prefix),
                                        "w9xpopen.exe")
                if not os.path.exists(w9xpopen):
                    raise RuntimeError("Cannot locate w9xpopen.exe, which is "
                                       "needed for Popen to work with your "
                                       "shell or platform.")
            return w9xpopen 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:17,代碼來源:subprocess.py


注:本文中的sys.exec_prefix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。