Skip to content

Commit 0af97b1

Browse files
Add files via upload
1 parent 000f374 commit 0af97b1

File tree

1 file changed

+307
-0
lines changed

1 file changed

+307
-0
lines changed

33-MyFile.ipynb

+307
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 6,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Writing myfile.txt\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"%%writefile myfile.txt\n",
18+
"Test1\n",
19+
"Test2\n",
20+
"Test3"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 7,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"my_file = open(\"myfile.txt\")"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 8,
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"data": {
39+
"text/plain": [
40+
"'Test1\\nTest2\\nTest3'"
41+
]
42+
},
43+
"execution_count": 8,
44+
"metadata": {},
45+
"output_type": "execute_result"
46+
}
47+
],
48+
"source": [
49+
"my_file.read()"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 9,
55+
"metadata": {},
56+
"outputs": [
57+
{
58+
"data": {
59+
"text/plain": [
60+
"''"
61+
]
62+
},
63+
"execution_count": 9,
64+
"metadata": {},
65+
"output_type": "execute_result"
66+
}
67+
],
68+
"source": [
69+
"my_file.read()"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 10,
75+
"metadata": {},
76+
"outputs": [
77+
{
78+
"data": {
79+
"text/plain": [
80+
"0"
81+
]
82+
},
83+
"execution_count": 10,
84+
"metadata": {},
85+
"output_type": "execute_result"
86+
}
87+
],
88+
"source": [
89+
"my_file.seek(0)"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": 11,
95+
"metadata": {},
96+
"outputs": [
97+
{
98+
"data": {
99+
"text/plain": [
100+
"'Test1\\nTest2\\nTest3'"
101+
]
102+
},
103+
"execution_count": 11,
104+
"metadata": {},
105+
"output_type": "execute_result"
106+
}
107+
],
108+
"source": [
109+
"my_file.read()"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": 12,
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"my_file.close()"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 13,
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"with open(\"myfile.txt\") as my_file:\n",
128+
" file_read = my_file.read()"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": 14,
134+
"metadata": {},
135+
"outputs": [
136+
{
137+
"data": {
138+
"text/plain": [
139+
"'Test1\\nTest2\\nTest3'"
140+
]
141+
},
142+
"execution_count": 14,
143+
"metadata": {},
144+
"output_type": "execute_result"
145+
}
146+
],
147+
"source": [
148+
"file_read"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": 15,
154+
"metadata": {},
155+
"outputs": [
156+
{
157+
"data": {
158+
"text/plain": [
159+
"'Test1\\nTest2\\nTest3'"
160+
]
161+
},
162+
"execution_count": 15,
163+
"metadata": {},
164+
"output_type": "execute_result"
165+
}
166+
],
167+
"source": [
168+
"file_read"
169+
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": 22,
174+
"metadata": {},
175+
"outputs": [],
176+
"source": [
177+
"with open(\"myfile.txt\",mode=\"w\") as my_new_file:\n",
178+
" my_new_file.write(\"test4\")"
179+
]
180+
},
181+
{
182+
"cell_type": "code",
183+
"execution_count": 23,
184+
"metadata": {},
185+
"outputs": [
186+
{
187+
"data": {
188+
"text/plain": [
189+
"<_io.TextIOWrapper name='myfile.txt' mode='w' encoding='UTF-8'>"
190+
]
191+
},
192+
"execution_count": 23,
193+
"metadata": {},
194+
"output_type": "execute_result"
195+
}
196+
],
197+
"source": [
198+
"my_new_file"
199+
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"execution_count": 24,
204+
"metadata": {},
205+
"outputs": [],
206+
"source": [
207+
"with open(\"myfile.txt\",mode=\"r\") as my_new_file_2:\n",
208+
" contents = my_new_file_2.read()"
209+
]
210+
},
211+
{
212+
"cell_type": "code",
213+
"execution_count": 25,
214+
"metadata": {},
215+
"outputs": [
216+
{
217+
"data": {
218+
"text/plain": [
219+
"'test4'"
220+
]
221+
},
222+
"execution_count": 25,
223+
"metadata": {},
224+
"output_type": "execute_result"
225+
}
226+
],
227+
"source": [
228+
"contents"
229+
]
230+
},
231+
{
232+
"cell_type": "code",
233+
"execution_count": 26,
234+
"metadata": {},
235+
"outputs": [],
236+
"source": [
237+
"with open(\"myfile.txt\",mode=\"a\") as my_new_file_3:\n",
238+
" my_new_file_3.write(\" test 5\")"
239+
]
240+
},
241+
{
242+
"cell_type": "code",
243+
"execution_count": 27,
244+
"metadata": {},
245+
"outputs": [],
246+
"source": [
247+
"with open(\"myfile.txt\",mode=\"r\") as my_new_file_5:\n",
248+
" contents_2 = my_new_file_5.read()"
249+
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": 28,
254+
"metadata": {},
255+
"outputs": [
256+
{
257+
"data": {
258+
"text/plain": [
259+
"'test4 test 5'"
260+
]
261+
},
262+
"execution_count": 28,
263+
"metadata": {},
264+
"output_type": "execute_result"
265+
}
266+
],
267+
"source": [
268+
"contents_2"
269+
]
270+
},
271+
{
272+
"cell_type": "markdown",
273+
"metadata": {},
274+
"source": [
275+
"# r = read, w = write, a = append"
276+
]
277+
},
278+
{
279+
"cell_type": "code",
280+
"execution_count": null,
281+
"metadata": {},
282+
"outputs": [],
283+
"source": []
284+
}
285+
],
286+
"metadata": {
287+
"kernelspec": {
288+
"display_name": "Python 3",
289+
"language": "python",
290+
"name": "python3"
291+
},
292+
"language_info": {
293+
"codemirror_mode": {
294+
"name": "ipython",
295+
"version": 3
296+
},
297+
"file_extension": ".py",
298+
"mimetype": "text/x-python",
299+
"name": "python",
300+
"nbconvert_exporter": "python",
301+
"pygments_lexer": "ipython3",
302+
"version": "3.6.4"
303+
}
304+
},
305+
"nbformat": 4,
306+
"nbformat_minor": 2
307+
}

0 commit comments

Comments
 (0)