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


Python builtins.open方法代码示例

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


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

示例1: __init__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def __init__(self, pos_features, pipeline_obj_path):
        """
        Args:
          pos_features: list of positional features to use
          pipeline_obj_path: path to the serialized pipeline obj_path
        """
        self.pos_features = pos_features
        self.pipeline_obj_path = pipeline_obj_path

        # deserialize the pickle file
        with open(self.pipeline_obj_path, "rb") as f:
            pipeline_obj = pickle.load(f)
        self.POS_FEATURES = pipeline_obj[0]
        self.minmax_scaler = pipeline_obj[1]
        self.imp = pipeline_obj[2]

        self.funct_transform = FunctionTransformer(func=sign_log_func,
                                                   inverse_func=sign_log_func_inverse)
        # for simplicity, assume all current pos_features are the
        # same as from before
        assert self.POS_FEATURES == self.pos_features 
开发者ID:kipoi,项目名称:models,代码行数:23,代码来源:dataloader.py

示例2: __init__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def __init__(self, stream, errors='strict'):

        """ Creates a StreamWriter instance.

            stream must be a file-like object open for writing
            (binary) data.

            The StreamWriter may use different error handling
            schemes by providing the errors keyword argument. These
            parameters are predefined:

             'strict' - raise a ValueError (or a subclass)
             'ignore' - ignore the character and continue with the next
             'replace'- replace with a suitable replacement character
             'xmlcharrefreplace' - Replace with the appropriate XML
                                   character reference.
             'backslashreplace'  - Replace with backslashed escape
                                   sequences (only for encoding).

            The set of allowed parameter values can be extended via
            register_error.
        """
        self.stream = stream
        self.errors = errors 
开发者ID:war-and-code,项目名称:jawfish,代码行数:26,代码来源:codecs.py

示例3: setUp

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def setUp(self):
    super(DeployImplTest, self).setUp()
    # Save the real modules for clean up.
    self.real_open = builtins.open
    # Create a fake file system and stub out builtin modules.
    self.fs = fake_filesystem.FakeFilesystem()
    self.os = fake_filesystem.FakeOsModule(self.fs)
    self.open = fake_filesystem.FakeFileOpen(self.fs)
    self.shutil = fake_filesystem_shutil.FakeShutilModule(self.fs)
    self.stubs = mox3_stubout.StubOutForTesting()
    self.stubs.SmartSet(builtins, 'open', self.open)
    self.stubs.SmartSet(deploy_impl, 'os', self.os)
    self.stubs.SmartSet(deploy_impl, 'shutil', self.shutil)
    # Populate the fake file system with the expected directories and files.
    self.fs.CreateDirectory('/this/is/a/workspace/loaner/web_app/frontend/dist')
    self.fs.CreateDirectory('/this/is/a/workspace/loaner/chrome_app/dist')
    self.fs.CreateFile('/this/is/a/workspace/loaner/web_app/app.yaml')
    self.fs.CreateFile('/this/is/a/workspace/loaner/web_app/endpoints.yaml') 
开发者ID:google,项目名称:loaner,代码行数:20,代码来源:deploy_impl_test.py

示例4: setUp

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def setUp(self):
    super(AuthTest, self).setUp()
    self._test_project = 'test_project'
    self._test_client_id = 'test_client_id'
    self._test_client_secret = 'test_client_secret'
    self._test_config = common.ProjectConfig(
        'test_key', self._test_project, self._test_client_id,
        self._test_client_secret, None, '/test/path.yaml')
    # Save the real modules for clean up.
    self.real_open = builtins.open
    # Create a fake file system and stub out builtin modules.
    self.fs = fake_filesystem.FakeFilesystem()
    self.os = fake_filesystem.FakeOsModule(self.fs)
    self.open = fake_filesystem.FakeFileOpen(self.fs)
    self.stubs = mox3_stubout.StubOutForTesting()
    self.stubs.SmartSet(builtins, 'open', self.open)
    self.stubs.SmartSet(auth, 'os', self.os) 
开发者ID:google,项目名称:loaner,代码行数:19,代码来源:auth_test.py

示例5: __init__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def __init__(self, stream, errors='strict'):

        """ Creates a StreamWriter instance.

            stream must be a file-like object open for writing.

            The StreamWriter may use different error handling
            schemes by providing the errors keyword argument. These
            parameters are predefined:

             'strict' - raise a ValueError (or a subclass)
             'ignore' - ignore the character and continue with the next
             'replace'- replace with a suitable replacement character
             'xmlcharrefreplace' - Replace with the appropriate XML
                                   character reference.
             'backslashreplace'  - Replace with backslashed escape
                                   sequences.
             'namereplace'       - Replace with \\N{...} escape sequences.

            The set of allowed parameter values can be extended via
            register_error.
        """
        self.stream = stream
        self.errors = errors 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:26,代码来源:codecs.py

示例6: __init__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def __init__(self, file, mode='r', *, search=524288, _idx=0, _am=None):
        if mode != 'r':
            raise NotImplementedError("mode != 'r' not implemented")
        if isinstance(file, str):
            self.__file = builtins.open(file, 'rb')
            self.__filename = file
        else:
            if not file.seekable():
                raise TypeError("file must be filename or "
                                "seekable file-like object")
            self.__file = file
            self.__filename = '-'
        self.__file.seek(0, 2)
        self.__filesize = self.__file.tell()
        self.__main_header = None
        self.__file_headers = []
        self.__all_headers = []
        try:
            self._parse_headers(search)
            if self.__main_header == None:
                raise CorruptedArchiveError("no main header")
        except:
            self.close()
            raise 
开发者ID:cyber-prog0x,项目名称:PoC-Bank,代码行数:26,代码来源:acefile.py

示例7: _open

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def _open(cls, file, mode='r', *, search=524288):
        """
        Open archive from *file*, which is either a filename or seekable
        file-like object, and return an instance of :class:`AceArchive`
        representing the opened archive that can function as a context
        manager.
        Only *mode* 'r' is implemented.
        If *search* is 0, the archive must start at position 0 in *file*,
        otherwise the first *search* bytes are searched for the magic bytes
        ``**ACE**`` that mark the ACE main header.
        For 1:1 compatibility with the official unace, 1024 sectors are
        searched by default, even though none of the SFX stubs that come with
        ACE compressors are that large.

        Multi-volume archives are represented by a single :class:`AceArchive`
        object to the caller, all operations transparently read into subsequent
        volumes as required.
        To load a multi-volume archive, either open the first volume of the
        series by filename, or provide a list or tuple of all file-like
        objects or filenames in the correct order in *file*.
        """
        return cls(file, mode, search=search) 
开发者ID:cyber-prog0x,项目名称:PoC-Bank,代码行数:24,代码来源:acefile.py

示例8: __getattr__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def __getattr__(self, name,
                    getattr=getattr):

        """ Inherit all other methods from the underlying stream.
        """
        return getattr(self.stream, name)

    # these are needed to make "with codecs.open(...)" work properly 
开发者ID:war-and-code,项目名称:jawfish,代码行数:10,代码来源:codecs.py

示例9: open

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def open(filename):
    """Open a file in read only mode using the encoding detected by
    detect_encoding().
    """
    buffer = builtins.open(filename, 'rb')
    encoding, lines = detect_encoding(buffer.readline)
    buffer.seek(0)
    text = TextIOWrapper(buffer, encoding, line_buffering=True)
    text.mode = 'r'
    return text 
开发者ID:war-and-code,项目名称:jawfish,代码行数:12,代码来源:tokenize.py

示例10: tearDown

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def tearDown(self):
    super(DeployImplTest, self).tearDown()
    self.stubs.UnsetAll()
    builtins.open = self.real_open 
开发者ID:google,项目名称:loaner,代码行数:6,代码来源:deploy_impl_test.py

示例11: testManifestCheck

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def testManifestCheck(self, mock_rawinput):
    """Test the manifest file check opens and loads json data."""
    file_name = '/this/is/a/workspace/loaner/chrome_app/manifest.json'
    self.fs.CreateFile(file_name, contents=_CORRECT_JSON)
    test_chrome_app_config = self.CreateTestChromeAppConfig()
    test_chrome_app_config._ManifestCheck()
    assert mock_rawinput.call_count == 1
    with open(file_name, 'r') as f:
      data = json.load(f)
      assert data['version'] == '1.0' 
开发者ID:google,项目名称:loaner,代码行数:12,代码来源:deploy_impl_test.py

示例12: setUp

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def setUp(self):
    super(CommonTest, self).setUp()
    # Save the real modules for clean up.
    self.real_open = builtins.open
    # Create a fake file system and stub out builtin modules.
    self.fs = fake_filesystem.FakeFilesystem()
    self.os = fake_filesystem.FakeOsModule(self.fs)
    self.open = fake_filesystem.FakeFileOpen(self.fs)
    self.stubs = mox3_stubout.StubOutForTesting()
    self.stubs.SmartSet(builtins, 'open', self.open)
    self.stubs.SmartSet(common, 'os', self.os) 
开发者ID:google,项目名称:loaner,代码行数:13,代码来源:common_test.py

示例13: tearDown

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def tearDown(self):
    super(CommonTest, self).tearDown()
    self.stubs.UnsetAll()
    builtins.open = self.real_open 
开发者ID:google,项目名称:loaner,代码行数:6,代码来源:common_test.py

示例14: tearDown

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def tearDown(self):
    super(AuthTest, self).tearDown()
    self.stubs.UnsetAll()
    builtins.open = self.real_open 
开发者ID:google,项目名称:loaner,代码行数:6,代码来源:auth_test.py

示例15: setUp

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import open [as 别名]
def setUp(self):
    super(ManagerTest, self).setUp()
    # Save the real modules for clean up.
    self.real_open = builtins.open
    # Create a fake file system and stub out builtin modules.
    self.fs = fake_filesystem.FakeFilesystem()
    self.os = fake_filesystem.FakeOsModule(self.fs)
    self.open = fake_filesystem.FakeFileOpen(self.fs)
    self.stdout = StringIO()
    self.stubs = mox3_stubout.StubOutForTesting()
    self.stubs.SmartSet(builtins, 'open', self.open)
    self.stubs.SmartSet(common, 'os', self.os)
    self.stubs.SmartSet(sys, 'stdout', self.stdout)

    # Setup Testdata.
    self._testdata_path = '/testdata'
    self._valid_config_path = self._testdata_path + '/valid_config.yaml'
    self._blank_config_path = self._testdata_path + '/blank_config.yaml'

    self.fs.CreateFile(self._valid_config_path, contents=_VALID_CONFIG)
    self.fs.CreateFile(self._blank_config_path, contents=_BLANK_CONFIG)

    # Load the default config.
    self._valid_default_config = common.ProjectConfig.from_yaml(
        common.DEFAULT, self._valid_config_path)

    # Create test constants.
    self._constants = {
        'test': app_constants.Constant(
            'test', 'message', '',
            parser=utils.StringParser(allow_empty_string=False),),
        'other': app_constants.Constant('other', 'other message', 'value'),
    }

    # Mock out the authentication credentials.
    self.auth_patcher = mock.patch.object(auth, 'CloudCredentials')
    self.mock_creds = self.auth_patcher.start()
    self.mock_creds.return_value.get_credentials.return_value = (
        credentials.AnonymousCredentials()) 
开发者ID:google,项目名称:loaner,代码行数:41,代码来源:gng_impl_test.py


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