In [
1
]: f
=
open
(
'abc.txt'
,
'r+'
)
In [
3
]: f.tell()
Out[
3
]:
0
In [
4
]: f.read()
Out[
4
]:
"Beautiful is better than ugly.\nExplicit is better than implicit.\nSimple is better than complex.\nComplex is better than complicated.\nFlat is better than nested.\nSparse is better than dense.\nReadability counts.\nSpecial cases aren't special enough to break the rules.\nAlthough practicality beats purity.\nErrors should never pass silently.\nUnless explicitly silenced.\nIn the face of ambiguity, refuse the temptation to guess.\nThere should be one-- and preferably only one --obvious way to do it.\nAlthough that way may not be obvious at first unless you're Dutch.\nNow is better than never.\nAlthough never is often better than *right* now.\nIf the implementation is hard to explain, it's a bad idea.\nIf the implementation is easy to explain, it may be a good idea.\nNamespaces are one honking great idea -- let's do more of those!\n"
In [
5
]: f.tell()
Out[
5
]:
823
In [
6
]: f.seek(
0
)
Out[
6
]:
0
In [
7
]: f.readline()
Out[
7
]:
'Beautiful is better than ugly.\n'
In [
11
]: f.readlines()
Out[
11
]:
[
'Flat is better than nested.\n'
,
'Sparse is better than dense.\n'
,
'Readability counts.\n'
,
"Special cases aren't special enough to break the rules.\n"
,
'Although practicality beats purity.\n'
,
'Errors should never pass silently.\n'
,
'Unless explicitly silenced.\n'
,
'In the face of ambiguity, refuse the temptation to guess.\n'
,
'There should be one-- and preferably only one --obvious way to do it.\n'
,
"Although that way may not be obvious at first unless you're Dutch.\n"
,
'Now is better than never.\n'
,
'Although never is often better than *right* now.\n'
,
"If the implementation is hard to explain, it's a bad idea.\n"
,
'If the implementation is easy to explain, it may be a good idea.\n'
,
"Namespaces are one honking great idea -- let's do more of those!\n"
]
In [
33
]: f.seek(
0
)
Out[
33
]:
0
In [
34
]: f.write(
'ksfdhauy3urnncb'
)
Out[
34
]:
15
In [
35
]: f.close()
In [
36
]: f
=
open
(
'abc.txt'
,
'r+'
)
In [
37
]: f.readline()
Out[
37
]:
'ksfdhauy3urnncbtter than ugly.\n'
In [
39
]: f
=
open
(
'abc.txt'
,
'a'
)
In [
40
]: f.tell()
Out[
40
]:
835
In [
41
]: f.write(
'5671528956knkxb'
)
Out[
41
]:
15
In [
47
]: f.read()
Out[
47
]:
"btter than ugly.\nExplicit is better than implicit.\nSimple is better than complex.\nComplex is better than complicated.\nFlat is better than nested.\nSparse is better than dense.\nReadability counts.\nSpecial cases aren't special enough to break the rules.\nAlthough practicality beats purity.\nErrors should never pass silently.\nUnless explicitly silenced.\nIn the face of ambiguity, refuse the temptation to guess.\nThere should be one-- and preferably only one --obvious way to do it.\nAlthough that way may not be obvious at first unless you're Dutch.\nNow is better than never.\nAlthough never is often better than *right* now.\nIf the implementation is hard to explain, it's a bad idea.\nIf the implementation is easy to explain, it may be a good idea.\nNamespaces are one honking great idea -- let's do more of those!\nhello world\n5671528956knkxb"