Skip to content

Commit 80e2862

Browse files
committed
u3
1 parent 1646f29 commit 80e2862

12 files changed

+664
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": []
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 2",
16+
"language": "python",
17+
"name": "python2"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 2
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython2",
29+
"version": "2.7.10"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 0
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": []
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 2",
16+
"language": "python",
17+
"name": "python2"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 2
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython2",
29+
"version": "2.7.10"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 0
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": []
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 2",
16+
"language": "python",
17+
"name": "python2"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 2
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython2",
29+
"version": "2.7.10"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 0
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": []
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 2",
16+
"language": "python",
17+
"name": "python2"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 2
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython2",
29+
"version": "2.7.10"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 0
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# StringIO \n",
8+
"\n",
9+
"The StringIO module implements an in-memory file like object. This object can then be used as input or output to most functions that would expect a standard file object.\n",
10+
"\n",
11+
"The best way to show this is by example:"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 1,
17+
"metadata": {
18+
"collapsed": true
19+
},
20+
"outputs": [],
21+
"source": [
22+
"import StringIO"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 16,
28+
"metadata": {
29+
"collapsed": true
30+
},
31+
"outputs": [],
32+
"source": [
33+
"# Arbitrary String\n",
34+
"message = 'This is just a normal string.'"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 25,
40+
"metadata": {
41+
"collapsed": true
42+
},
43+
"outputs": [],
44+
"source": [
45+
"# Use StringIO method to set as file object\n",
46+
"f = StringIO.StringIO(message)"
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"metadata": {},
52+
"source": [
53+
"Now we have an object *f* that we will be able to treat just like a file. For example:"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 30,
59+
"metadata": {
60+
"collapsed": false
61+
},
62+
"outputs": [
63+
{
64+
"data": {
65+
"text/plain": [
66+
"''"
67+
]
68+
},
69+
"execution_count": 30,
70+
"metadata": {},
71+
"output_type": "execute_result"
72+
}
73+
],
74+
"source": [
75+
"f.read()"
76+
]
77+
},
78+
{
79+
"cell_type": "markdown",
80+
"metadata": {},
81+
"source": [
82+
"We can also write to it:"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": 27,
88+
"metadata": {
89+
"collapsed": false
90+
},
91+
"outputs": [],
92+
"source": [
93+
"f.write(' Second line written to file like object')"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": 28,
99+
"metadata": {
100+
"collapsed": true
101+
},
102+
"outputs": [],
103+
"source": [
104+
"# Reset cursor just like you would a file\n",
105+
"f.seek(0)"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": 29,
111+
"metadata": {
112+
"collapsed": false
113+
},
114+
"outputs": [
115+
{
116+
"data": {
117+
"text/plain": [
118+
"'This is just a normal string. Second line written to file like object'"
119+
]
120+
},
121+
"execution_count": 29,
122+
"metadata": {},
123+
"output_type": "execute_result"
124+
}
125+
],
126+
"source": [
127+
"# Read again\n",
128+
"f.read()"
129+
]
130+
},
131+
{
132+
"cell_type": "markdown",
133+
"metadata": {},
134+
"source": [
135+
"Great! Now you've seen how we can use StringIO to turn normal strings into in-memory file objects in our code. This kind of action has various use cases, especially in web scraping cases where you want to read some string you scraped as a file.\n",
136+
"\n",
137+
"For more info on StringIO check out the documentation:https://docs.python.org/2/library/stringio.html"
138+
]
139+
}
140+
],
141+
"metadata": {
142+
"kernelspec": {
143+
"display_name": "Python 2",
144+
"language": "python",
145+
"name": "python2"
146+
},
147+
"language_info": {
148+
"codemirror_mode": {
149+
"name": "ipython",
150+
"version": 2
151+
},
152+
"file_extension": ".py",
153+
"mimetype": "text/x-python",
154+
"name": "python",
155+
"nbconvert_exporter": "python",
156+
"pygments_lexer": "ipython2",
157+
"version": "2.7.10"
158+
}
159+
},
160+
"nbformat": 4,
161+
"nbformat_minor": 0
162+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": []
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 2",
16+
"language": "python",
17+
"name": "python2"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 2
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython2",
29+
"version": "2.7.10"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 0
34+
}

Collections Module.ipynb

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": []
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 2",
16+
"language": "python",
17+
"name": "python2"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 2
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython2",
29+
"version": "2.7.10"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 0
34+
}

0 commit comments

Comments
 (0)