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


Python FileAsObj.append方法代码示例

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


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

示例1: test_append_failure_param

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

示例2: test_append_string_unique

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import append [as 别名]
 def test_append_string_unique(self):
     """ Test content integrity using `unique` """
     test_file = FileAsObj()
     test_file.unique = True
     subject = 'uniq'
     self.assertTrue(test_file.append(subject))
     self.assertFalse(test_file.append(subject))
     self.assertTrue(test_file.contents == [subject])
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:10,代码来源:tests_fileasobj.py

示例3: test_append_list_no_unique

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import append [as 别名]
 def test_append_list_no_unique(self):
     """ Test adding a 3 element list with .add() """
     test_file = FileAsObj()
     subject = ['simultaneous', 'money shot', 'remedy']
     self.assertTrue(test_file.append(subject))
     self.assertTrue(test_file.changed)
     self.assertTrue(test_file.append(subject))
     self.assertTrue(test_file.contents == subject + subject)
     self.assertTrue(str(test_file) == '\n'.join(subject + subject))
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:11,代码来源:tests_fileasobj.py

示例4: example_add_line_to_file

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import append [as 别名]
def example_add_line_to_file():
    """ Different methods to append a given line to the file, all work the same. """
    my_file = FileAsObj('/tmp/example_file.txt')
    my_file.add('foo')
    my_file.append('bar')
    # Add a new line to my_file that contains the word 'lol' and print True|False if my_file was changed.
    print(my_file + 'lol')
    # Add line even if it already exists in the file.
    my_file.unique = False
    my_file.add('foo')
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:12,代码来源:examples.py

示例5: test_append_not_unique

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import append [as 别名]
 def test_append_not_unique(self):
     test_file = FileAsObj(TestFile, verbose=True)
     self.assertTrue(test_file.append('using __add__ three times, force unique', unique=False))
     self.assertTrue(test_file.append('using __add__ three times, force unique', unique=False))
     self.assertTrue(test_file.append('using __add__ three times, force unique', unique=False))
开发者ID:nullpass,项目名称:fileasobj,代码行数:7,代码来源:test_fileasobj.py

示例6: FileAsObj

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import append [as 别名]

# test_file = FileAsObj('Test.txt')
# print(test_file)
# print(test_file.trace)

if 'Checking for __contains__ functionality 123' in test_file:
    print('__contains__ test string present')

if 'a7s6d9f7a6sd9f76asf9a8d7s89d6f967adfsadf' not in test_file:
    print('bogus string not in test file, good!')

test_file + 'using __add__ three times, force unique'
test_file + 'using __add__ three times, force unique'
test_file + 'using __add__ three times, force unique'
test_file.append('using append three times with unique')
test_file.append('using append three times with unique')
test_file.append('using append three times with unique')
test_file.append('using append three times without unique', unique=False)
test_file.append('using append three times without unique', unique=False)
test_file.append('using append three times without unique', unique=False)


x = '#comment'
print('subtract {0}'.format(x))
print(test_file - x)
print('---')


x = 'w.*rd'
print('Find {0}'.format(x))
开发者ID:jkudria,项目名称:fileasobj,代码行数:32,代码来源:tests.py

示例7: file

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import append [as 别名]

#
# Check for a line in file.
#    if 'This entire line' in my_file:
#        return True
#
# or simply:
#    return my_file.check('This entire line')
#
#

#
# Three methods to append a given line to the file, all work the same
my_file.add('foo')
my_file.append('foo')
print(my_file + 'foo')


#
# Add line even if it exists in the file already.
my_file.add('foo', unique=False)


#
# Print number of lines in the file (as it exists in memory)
print(len(my_file))


#
# Remove all lines that are "foo bar"
开发者ID:jkudria,项目名称:fileasobj,代码行数:32,代码来源:examples.py

示例8: test_unique_failure

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import append [as 别名]
 def test_unique_failure(self):
     """ Test wrong attribute type of self.unique during append() """
     test_file = FileAsObj()
     test_file.unique = 'this is invalid attr type'
     with self.assertRaises(AttributeError):
         test_file.append('.')
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:8,代码来源:tests_fileasobj.py


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