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


Python FileAsObj.check方法代码示例

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


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

示例1: test_check_failure

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
 def test_check_failure(self):
     """ Test check() method with wrong parameter type. """
     test_file = FileAsObj()
     with self.assertRaises(TypeError):
         test_file.check(1)
     with self.assertRaises(TypeError):
         test_file.check(False)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:9,代码来源:tests_fileasobj.py

示例2: test_replace_list

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
 def test_replace_list(self):
     """ Test substitute lines using a list of strings. """
     test_file = FileAsObj()
     test_file.contents = TESTCONTENTS.split('\n')
     self.assertFalse(test_file.changed)
     old = ['#', '# ', '#1']
     new = '###'
     self.assertTrue(test_file.replace(old, new))
     self.assertTrue(test_file.changed)
     for this in old:
         self.assertFalse(test_file.check(this))
     self.assertEqual(test_file.check(new), new)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:14,代码来源:tests_fileasobj.py

示例3: test_replace_list

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
 def test_replace_list(self):
     test_file = FileAsObj(TestFile, verbose=True)
     old = ['#', '# ', '#1']
     new = '###'
     self.assertTrue(test_file.replace(old, new))
     for this in old:
         self.assertFalse(test_file.check(this))
开发者ID:nullpass,项目名称:fileasobj,代码行数:9,代码来源:test_fileasobj.py

示例4:

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
# Get all lines that contain a #
result = my_file.grep('#')


#
# Remove all lines that contain the word "foo"
# NOTE: this is dangerous and rarely needed.
my_file.rm(my_file.grep('foo'))


#
# Check for line in file, if exists remove it
if 'foo bar' in my_file:
    my_file.rm('foo bar')
# or
my_file.rm(my_file.check('foo bar'))
# or
my_file.rm('foo bar')  # OK if line not found.


#
# Now that you've changed data let's save it back to disk.
my_file.save()
# or
my_file.write()
# of
if my_file.virgin is False:
    my_file.save()


#
开发者ID:jkudria,项目名称:fileasobj,代码行数:33,代码来源:examples.py

示例5: test_check_line_not_present

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
 def test_check_line_not_present(self):
     """ Test check() method with line that is not present in file. """
     test_file = FileAsObj()
     test_file.contents = TESTCONTENTS.split('\n')
     self.assertFalse(test_file.check('This line does not exist in the file.'))
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例6: test_check_blank_line

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
 def test_check_blank_line(self):
     """ Test check() method with empty line that is present in file. """
     test_file = FileAsObj()
     test_file.contents = BLANKFILE.split('\n')
     self.assertEqual(test_file.check(''), '')
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例7: test_check_present

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
 def test_check_present(self):
     """ Test check() method with line that is present in file. """
     test_file = FileAsObj()
     test_file.contents = TESTCONTENTS.split('\n')
     self.assertTrue(test_file.check('# This is a test hosts file'))
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例8: example_search_for_whole_line_using_check

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def example_search_for_whole_line_using_check():
    """ Shorter version, find a complete line in file. """
    my_file = FileAsObj('/etc/hosts')
    return my_file.check('127.0.0.1 localhost')
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:6,代码来源:examples.py


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