本文整理匯總了Python中_pyio.StringIO方法的典型用法代碼示例。如果您正苦於以下問題:Python _pyio.StringIO方法的具體用法?Python _pyio.StringIO怎麽用?Python _pyio.StringIO使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類_pyio
的用法示例。
在下文中一共展示了_pyio.StringIO方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_newlines_property
# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import StringIO [as 別名]
def test_newlines_property(self):
memio = self.ioclass(newline=None)
# The C StringIO decodes newlines in write() calls, but the Python
# implementation only does when reading. This function forces them to
# be decoded for testing.
def force_decode():
memio.seek(0)
memio.read()
self.assertEqual(memio.newlines, None)
memio.write("a\n")
force_decode()
self.assertEqual(memio.newlines, "\n")
memio.write("b\r\n")
force_decode()
self.assertEqual(memio.newlines, ("\n", "\r\n"))
memio.write("c\rd")
force_decode()
self.assertEqual(memio.newlines, ("\r", "\n", "\r\n"))
示例2: test_issue5265
# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import StringIO [as 別名]
def test_issue5265(self):
# StringIO can duplicate newlines in universal newlines mode
memio = self.ioclass("a\r\nb\r\n", newline=None)
self.assertEqual(memio.read(5), "a\nb\n")
self.assertEqual(memio.getvalue(), "a\nb\n")
示例3: __new__
# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import StringIO [as 別名]
def __new__(cls, *args, **kwargs):
return pickle.loads(pickle.dumps(pyio.StringIO(*args, **kwargs)))
示例4: test_issue5265
# 需要導入模塊: import _pyio [as 別名]
# 或者: from _pyio import StringIO [as 別名]
def test_issue5265(self):
# StringIO can duplicate newlines in universal newlines mode
memio = self.ioclass("a\r\nb\r\n", newline=None)
self.assertEqual(memio.read(5), "a\nb\n")