当前位置: 首页>>代码示例>>Python>>正文


Python os.getcwd方法代码示例

本文整理汇总了Python中os.getcwd方法的典型用法代码示例。如果您正苦于以下问题:Python os.getcwd方法的具体用法?Python os.getcwd怎么用?Python os.getcwd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.getcwd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dash_in_project_slug

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_dash_in_project_slug(cookies):
    ctx = {'project_slug': "my-package"}
    project = cookies.bake(extra_context=ctx)

    assert project.exit_code == 0

    with open(os.path.join(str(project.project), 'setup.py')) as f:
        setup = f.read()
    print(setup)

    cwd = os.getcwd()
    os.chdir(str(project.project))

    try:
        sh.python(['setup.py', 'install'])
        sh.python(['setup.py', 'build_sphinx'])
    except sh.ErrorReturnCode as e:
        pytest.fail(e)
    finally:
        os.chdir(cwd) 
开发者ID:NLeSC,项目名称:python-template,代码行数:22,代码来源:test_values.py

示例2: find_executable

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def find_executable(name) -> str:
    is_windows = os.name == 'nt'
    windows_exts = os.environ['PATHEXT'].split(ENV_PATH_SEP) if is_windows else None
    path_dirs = os.environ['PATH'].split(ENV_PATH_SEP)

    search_dirs = path_dirs + [os.getcwd()] # cwd is last in the list

    for dir in search_dirs:
        path = os.path.join(dir, name)

        if is_windows:
            for extension in windows_exts:
                path_with_ext = path + extension

                if os.path.isfile(path_with_ext) and os.access(path_with_ext, os.X_OK):
                    return path_with_ext
        else:
            if os.path.isfile(path) and os.access(path, os.X_OK):
                return path

    return '' 
开发者ID:godotengine,项目名称:godot-mono-builds,代码行数:23,代码来源:os_utils.py

示例3: ensure_lambda_helper

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def ensure_lambda_helper():
    awslambda = getattr(clients, "lambda")
    try:
        helper_desc = awslambda.get_function(FunctionName="aegea-dev-process_batch_event")
        logger.info("Using Batch helper Lambda %s", helper_desc["Configuration"]["FunctionArn"])
    except awslambda.exceptions.ResourceNotFoundException:
        logger.info("Batch helper Lambda not found, installing")
        import chalice.cli
        orig_argv = sys.argv
        orig_wd = os.getcwd()
        try:
            os.chdir(os.path.join(os.path.dirname(__file__), "batch_events_lambda"))
            sys.argv = ["chalice", "deploy", "--no-autogen-policy"]
            chalice.cli.main()
        except SystemExit:
            pass
        finally:
            os.chdir(orig_wd)
            sys.argv = orig_argv 
开发者ID:kislyuk,项目名称:aegea,代码行数:21,代码来源:batch.py

示例4: exit_maintenance

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def exit_maintenance():
    config = get_config()
    auth = request.authorization
    if auth \
            and auth.username in config.MAINTENANCE_CREDENTIALS \
            and config.MAINTENANCE_CREDENTIALS[auth.username] == auth.password:
        try:
            os.remove(config.MAINTENANCE_FILE)  # remove maintenance file
        except OSError:
            return 'Not in maintenance mode. Ignore command.'
        open(os.path.join(os.getcwd(), 'reload'), "w+").close()  # uwsgi reload
        return 'success'
    else:
        return Response(
            'Could not verify your access level for that URL.\n'
            'You have to login with proper credentials', 401,
            {'WWW-Authenticate': 'Basic realm="Login Required"'}) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:19,代码来源:views_main.py

示例5: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def __init__(self, label="DefaultValues", logfile=None, verbose=False, debug=False):
        super(DefaultValues, self).__init__(label=label, logfile=logfile, verbose=verbose, debug=debug)
        self._validator = Validator(logfile=logfile, verbose=verbose, debug=debug)
        pipeline_dir = os.path.dirname(self._validator.get_full_path(os.path.dirname(scripts.__file__)))

        self._DEFAULT_seed = random.randint(0, 2147483640)
        self._DEFAULT_tmp_dir = tempfile.gettempdir()
        self._DEFAULT_directory_pipeline = pipeline_dir

        original_wd = os.getcwd()
        os.chdir(pipeline_dir)
        file_path_config = os.path.join(pipeline_dir, "default_config.ini")
        if self._validator.validate_file(file_path_config, silent=True):
            self._from_config(file_path_config)
        else:
            self._from_hardcoded(pipeline_dir)
        os.chdir(original_wd) 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:19,代码来源:defaultvalues.py

示例6: cd

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def cd(self, message, conn):
        message = message.split()[1]                          # 截取目录名
        # 如果是新连接或者下载上传文件后的发送则 不切换 只将当前工作目录发送过去
        if message != 'same':
            f = r'./' + message
            os.chdir(f)
        # path = ''
        path = os.getcwd().split('\\')                        # 当前工作目录
        for i in range(len(path)):
            if path[i] == 'resources':
                break
        pat = ''
        for j in range(i, len(path)):
            pat = pat + path[j] + ' '
        pat = '\\'.join(pat.split())
        # 如果切换目录超出范围则退回切换前目录
        if 'resources' not in path:
            f = r'./resources'
            os.chdir(f)
            pat = 'resources'
        conn.send(pat.encode())

    # 判断输入的命令并执行对应的函数 
开发者ID:11ze,项目名称:The-chat-room,代码行数:25,代码来源:server.py

示例7: test_double_quotes_in_name_and_description

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_double_quotes_in_name_and_description(cookies):
    ctx = {'project_short_description': '"double quotes"',
           'full_name': '"name"name'}
    project = cookies.bake(extra_context=ctx)

    assert project.exit_code == 0

    with open(os.path.join(str(project.project), 'setup.py')) as f:
        setup = f.read()
    print(setup)

    cwd = os.getcwd()
    os.chdir(str(project.project))

    try:
        sh.python(['setup.py', 'install'])
    except sh.ErrorReturnCode as e:
        pytest.fail(e)
    finally:
        os.chdir(cwd) 
开发者ID:NLeSC,项目名称:python-template,代码行数:22,代码来源:test_values.py

示例8: test_single_quotes_in_name_and_description

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_single_quotes_in_name_and_description(cookies):
    ctx = {'project_short_description': "'single quotes'",
           'full_name': "Mr. O'Keeffe"}
    project = cookies.bake(extra_context=ctx)

    assert project.exit_code == 0

    with open(os.path.join(str(project.project), 'setup.py')) as f:
        setup = f.read()
    print(setup)

    cwd = os.getcwd()
    os.chdir(str(project.project))

    try:
        sh.python(['setup.py', 'install'])
    except sh.ErrorReturnCode as e:
        pytest.fail(e)
    finally:
        os.chdir(cwd) 
开发者ID:NLeSC,项目名称:python-template,代码行数:22,代码来源:test_values.py

示例9: test_space_in_project_slug

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_space_in_project_slug(cookies):
    ctx = {'project_slug': "my package"}
    project = cookies.bake(extra_context=ctx)

    assert project.exit_code == 0

    with open(os.path.join(str(project.project), 'setup.py')) as f:
        setup = f.read()
    print(setup)

    cwd = os.getcwd()
    os.chdir(str(project.project))

    try:
        sh.python(['setup.py', 'install'])
        sh.python(['setup.py', 'build_sphinx'])
    except sh.ErrorReturnCode as e:
        pytest.fail(e)
    finally:
        os.chdir(cwd) 
开发者ID:NLeSC,项目名称:python-template,代码行数:22,代码来源:test_values.py

示例10: test_install

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_install(cookies):
    project = cookies.bake()

    assert project.exit_code == 0
    assert project.exception is None

    cwd = os.getcwd()
    os.chdir(str(project.project))

    try:
        sh.python(['setup.py', 'install'])
    except sh.ErrorReturnCode as e:
        pytest.fail(e)
    finally:
        os.chdir(cwd) 
开发者ID:NLeSC,项目名称:python-template,代码行数:17,代码来源:test_project.py

示例11: test_building_documentation_apidocs

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_building_documentation_apidocs(cookies):
    project = cookies.bake(extra_context={'apidoc': 'yes'})

    assert project.exit_code == 0
    assert project.exception is None

    cwd = os.getcwd()
    os.chdir(str(project.project))

    try:
        sh.python(['setup.py', 'build_sphinx'])
    except sh.ErrorReturnCode as e:
        pytest.fail(e)
    finally:
        os.chdir(cwd)

    apidocs = project.project.join('docs', '_build', 'html', 'apidocs')

    assert apidocs.join('my_python_project.html').isfile()
    assert apidocs.join('my_python_project.my_python_project.html').isfile() 
开发者ID:NLeSC,项目名称:python-template,代码行数:22,代码来源:test_project.py

示例12: test_polynomial_kernel_svm_binary_classifier

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_polynomial_kernel_svm_binary_classifier(self):

        input_train_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), 'FukuML/dataset/non_linear_train.dat')
        input_test_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), 'FukuML/dataset/non_linear_test.dat')

        svm_bc = svm.BinaryClassifier()
        svm_bc.load_train_data(input_train_data_file)
        svm_bc.load_test_data(input_test_data_file)
        svm_bc.set_param(svm_kernel='polynomial_kernel', zeta=100, gamma=1, Q=3)
        svm_bc.init_W()
        W = svm_bc.train()
        print("\n訓練得出權重模型:")
        print(W)
        print("SVM Marging:")
        print(svm_bc.get_marge())
        print("Support Vectors")
        print(svm_bc.get_support_vectors())

        print("W 平均錯誤率(Ein):")
        print(svm_bc.calculate_avg_error(svm_bc.train_X, svm_bc.train_Y, W))
        print("W 平均錯誤率(Eout):")
        print(svm_bc.calculate_test_data_avg_error())
        print('-'*70) 
开发者ID:fukuball,项目名称:fuku-ml,代码行数:25,代码来源:test_fuku_ml.py

示例13: test_gaussian_kernel_svm_binary_classifier

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_gaussian_kernel_svm_binary_classifier(self):

        input_train_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), 'FukuML/dataset/non_linear_train.dat')
        input_test_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), 'FukuML/dataset/non_linear_test.dat')

        svm_bc = svm.BinaryClassifier()
        svm_bc.load_train_data(input_train_data_file)
        svm_bc.load_test_data(input_test_data_file)
        svm_bc.set_param(svm_kernel='gaussian_kernel', gamma=0.001)
        svm_bc.init_W()
        W = svm_bc.train()
        print("\n訓練得出權重模型:")
        print(W)
        print("SVM Marging:")
        print(svm_bc.get_marge())
        print("Support Vectors")
        print(svm_bc.get_support_vectors())

        print("W 平均錯誤率(Ein):")
        print(svm_bc.calculate_avg_error(svm_bc.train_X, svm_bc.train_Y, W))
        print("W 平均錯誤率(Eout):")
        print(svm_bc.calculate_test_data_avg_error())
        print('-'*70) 
开发者ID:fukuball,项目名称:fuku-ml,代码行数:25,代码来源:test_fuku_ml.py

示例14: test_soft_polynomial_kernel_svm_binary_classifier

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def test_soft_polynomial_kernel_svm_binary_classifier(self):

        input_train_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), 'FukuML/dataset/overlap_train.dat')
        input_test_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), 'FukuML/dataset/overlap_test.dat')

        svm_bc = svm.BinaryClassifier()
        svm_bc.load_train_data(input_train_data_file)
        svm_bc.load_test_data(input_test_data_file)
        svm_bc.set_param(svm_kernel='soft_polynomial_kernel', zeta=0, gamma=1, Q=1, C=0.1)
        svm_bc.init_W()
        W = svm_bc.train()

        print("\n訓練得出權重模型:")
        print(W)
        print("SVM Marging:")
        print(svm_bc.get_marge())
        print("Support Vectors")
        print(svm_bc.get_support_vectors())

        print("W 平均錯誤率(Ein):")
        print(svm_bc.calculate_avg_error(svm_bc.train_X, svm_bc.train_Y, W))
        print("W 平均錯誤率(Eout):")
        print(svm_bc.calculate_test_data_avg_error())
        print('-'*70) 
开发者ID:fukuball,项目名称:fuku-ml,代码行数:26,代码来源:test_fuku_ml.py

示例15: load_test_data

# 需要导入模块: import os [as 别名]
# 或者: from os import getcwd [as 别名]
def load_test_data(self, input_data_file=''):

        if (input_data_file == ''):
            input_data_file = os.path.normpath(os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), "dataset/pocket_pla_binary_test.dat"))
        else:
            if (os.path.isfile(input_data_file) is not True):
                print("Please make sure input_data_file path is correct.")
                return self.test_X, self.test_Y

        self.test_X, self.test_Y = utility.DatasetLoader.load(input_data_file)

        if (self.feature_transform_mode == 'polynomial') or (self.feature_transform_mode == 'legendre'):
            self.test_X = self.test_X[:, 1:]

            self.test_X = utility.DatasetLoader.feature_transform(
                self.test_X,
                self.feature_transform_mode,
                self.feature_transform_degree
            )

        return self.test_X, self.test_Y 
开发者ID:fukuball,项目名称:fuku-ml,代码行数:23,代码来源:RidgeRegression.py


注:本文中的os.getcwd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。