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


Python FileAsObj.read方法代码示例

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


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

示例1: example_read_catch_errors

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import read [as 别名]
def example_read_catch_errors():
    """ Reading a file and catch errors. """
    try:
        my_file = FileAsObj()
        my_file.read('/tmp/example_file.txt')
    except Exception as msg:
        print(msg)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:9,代码来源:examples.py

示例2: example_sort_during_read

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import read [as 别名]
def example_sort_during_read():
    """
    To sort contents during read().
    The .sorted attribute is checked every time contents are modified.
    Whenever a change occurs if sorted is True the contents are sorted with self.sort().
    """
    my_file = FileAsObj()
    my_file.sorted = True
    my_file.read('/tmp/example_file.txt')
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:11,代码来源:examples.py

示例3: test_unique_failure_during_read

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

示例4: test_blank_file_without_unique

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import read [as 别名]
 def test_blank_file_without_unique(self):
     """ Testing not-unique on empty lines during .read() """
     test_file = FileAsObj()
     test_file.filename = TESTFILE
     test_file.contents = BLANKFILE.split('\n')
     self.assertTrue(test_file.save())
     test_file = FileAsObj()
     test_file.unique = False
     test_file.read(TESTFILE)
     self.assertTrue(test_file.contents == ['', '', '', ''])
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:12,代码来源:tests_fileasobj.py

示例5: test_param_failure

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import read [as 别名]
 def test_param_failure(self):
     """ Passing anything other than String as filename should raise TypeError. """
     with self.assertRaises(TypeError):
         FileAsObj(1)
     with self.assertRaises(TypeError):
         FileAsObj(True)
     with self.assertRaises(TypeError):
         FileAsObj([])
     with self.assertRaises(TypeError):
         FileAsObj({})
     with self.assertRaises(TypeError):
         test_file = FileAsObj()
         test_file.read(False)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:15,代码来源:tests_fileasobj.py

示例6: FileAsObj

# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import read [as 别名]
"""
fileasobj/examples.py

"""
import sys
import os

from fileasobj import FileAsObj


# Reading a file
my_file = FileAsObj()
try:
    my_file.read('./input.txt')
except Exception as msg:
    print('File was NOT loaded, here are the errors')
    print(msg)


# Reading a file during instantiation and catching errors.
try:
    my_file = FileAsObj(os.path.join(os.sep, 'home', 'bob', 'clients.txt'), verbose=True)
except Exception as msg:
    print(msg)
    sys.exit(10)

#
# If your file does not yet exist...
new_file = FileAsObj()
new_file.filename = './new_file.txt'
new_file.add('new data')
开发者ID:jkudria,项目名称:fileasobj,代码行数:33,代码来源:examples.py


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