Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aec034a

Browse files
Check Markdowns & Comments for more clarity
1 parent d0e70f8 commit aec034a

File tree

1 file changed

+309
-0
lines changed

1 file changed

+309
-0
lines changed

‎Assignment-9.ipynb‎

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Alternatively referred to as a partial path or non-absolute path, a relative path is a URL that only contains a portion of the full path."
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory."
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"## On Windows, what does Path('C:/Users') / 'Al' evaluate to?\n",
22+
"## Ans : It is invalid path"
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"metadata": {},
28+
"source": [
29+
"## On Windows, what does 'C:/Users' / 'Al' evaluate to?\n",
30+
"## Answer: It is unable to find AI so it is giving this error ,The system cannot find the path specified."
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 2,
36+
"metadata": {},
37+
"outputs": [
38+
{
39+
"data": {
40+
"application/javascript": [
41+
"\n",
42+
" if (window._pyforest_update_imports_cell) { window._pyforest_update_imports_cell('import os'); }\n",
43+
" "
44+
],
45+
"text/plain": [
46+
"<IPython.core.display.Javascript object>"
47+
]
48+
},
49+
"metadata": {},
50+
"output_type": "display_data"
51+
},
52+
{
53+
"data": {
54+
"text/plain": [
55+
"'C:\\\\Users\\\\91706\\\\Python Assignments'"
56+
]
57+
},
58+
"execution_count": 2,
59+
"metadata": {},
60+
"output_type": "execute_result"
61+
}
62+
],
63+
"source": [
64+
"## returns the current working directory\n",
65+
"os.getcwd()"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 3,
71+
"metadata": {},
72+
"outputs": [
73+
{
74+
"data": {
75+
"application/javascript": [
76+
"\n",
77+
" if (window._pyforest_update_imports_cell) { window._pyforest_update_imports_cell('import os'); }\n",
78+
" "
79+
],
80+
"text/plain": [
81+
"<IPython.core.display.Javascript object>"
82+
]
83+
},
84+
"metadata": {},
85+
"output_type": "display_data"
86+
}
87+
],
88+
"source": [
89+
"## changes the current working directory\n",
90+
"os.chdir(r'C:\\\\Users\\\\91706\\\\Python-ML Tutorials')"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 4,
96+
"metadata": {},
97+
"outputs": [
98+
{
99+
"data": {
100+
"application/javascript": [
101+
"\n",
102+
" if (window._pyforest_update_imports_cell) { window._pyforest_update_imports_cell('import os'); }\n",
103+
" "
104+
],
105+
"text/plain": [
106+
"<IPython.core.display.Javascript object>"
107+
]
108+
},
109+
"metadata": {},
110+
"output_type": "display_data"
111+
},
112+
{
113+
"data": {
114+
"text/plain": [
115+
"'C:\\\\Users\\\\91706\\\\Python-ML Tutorials'"
116+
]
117+
},
118+
"execution_count": 4,
119+
"metadata": {},
120+
"output_type": "execute_result"
121+
}
122+
],
123+
"source": [
124+
"os.getcwd()"
125+
]
126+
},
127+
{
128+
"cell_type": "markdown",
129+
"metadata": {},
130+
"source": [
131+
"## The . folder is the current folder, and .. is the parent folder"
132+
]
133+
},
134+
{
135+
"cell_type": "markdown",
136+
"metadata": {},
137+
"source": [
138+
"## C:\\bacon\\eggs is the dir name, while spam.txt is the base name"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"metadata": {},
144+
"source": [
145+
"## The string 'r' for read mode, 'w' for write mode, and 'a' for append mode"
146+
]
147+
},
148+
{
149+
"cell_type": "markdown",
150+
"metadata": {},
151+
"source": [
152+
"## If existing file is opened in write mode the it is erased and completely overwritten."
153+
]
154+
},
155+
{
156+
"cell_type": "code",
157+
"execution_count": 10,
158+
"metadata": {},
159+
"outputs": [
160+
{
161+
"data": {
162+
"application/javascript": [
163+
"\n",
164+
" if (window._pyforest_update_imports_cell) { window._pyforest_update_imports_cell('import os'); }\n",
165+
" "
166+
],
167+
"text/plain": [
168+
"<IPython.core.display.Javascript object>"
169+
]
170+
},
171+
"metadata": {},
172+
"output_type": "display_data"
173+
}
174+
],
175+
"source": [
176+
"os.chdir(r'C:\\\\Users\\\\91706\\\\Python Assignments')\n"
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": 12,
182+
"metadata": {},
183+
"outputs": [
184+
{
185+
"name": "stdout",
186+
"output_type": "stream",
187+
"text": [
188+
"b'Hi, I am Akash.\\nI work in Capgemini as MuleSoft Developer.\\nI live in Mumbai.\\n'\n",
189+
"Closed the file successfully!!\n"
190+
]
191+
}
192+
],
193+
"source": [
194+
"import os, sys\n",
195+
"# Open a file\n",
196+
"fd = os.open(\"Sample.txt\",os.O_RDWR)\n",
197+
"# Reading text using read function\n",
198+
"result = os.read(fd,150)\n",
199+
"print(result)\n",
200+
"# Close opened file\n",
201+
"os.close(fd)\n",
202+
"print(\"Closed the file successfully!!\")"
203+
]
204+
},
205+
{
206+
"cell_type": "code",
207+
"execution_count": 17,
208+
"metadata": {},
209+
"outputs": [
210+
{
211+
"name": "stdout",
212+
"output_type": "stream",
213+
"text": [
214+
"['Hi, I am Akash.\\n', 'I work in Capgemini as MuleSoft Developer.\\n', 'I live in Mumbai.\\n']\n"
215+
]
216+
}
217+
],
218+
"source": [
219+
"## The readlines() method returns a list containing each line in the file as a list item.\n",
220+
"f = open(\"Sample.txt\", \"r\")\n",
221+
"print(f.readlines(150))"
222+
]
223+
},
224+
{
225+
"cell_type": "markdown",
226+
"metadata": {},
227+
"source": [
228+
"## Difference between read() and readlines() is read return file contents as single string whereas, readlines returns a list where each string is a line from file contents"
229+
]
230+
},
231+
{
232+
"cell_type": "markdown",
233+
"metadata": {},
234+
"source": [
235+
"## A shelf value resembles a dictionary value; it has keys and values, along with keys() and values() methods that work similarly to the dictionary methods of the same names."
236+
]
237+
},
238+
{
239+
"cell_type": "code",
240+
"execution_count": 18,
241+
"metadata": {},
242+
"outputs": [],
243+
"source": [
244+
"# At first, we have to import the 'Shelve' module. \n",
245+
"import shelve \n",
246+
" \n",
247+
"# In this step, we create a shelf file. \n",
248+
"shfile = shelve.open(\"shelf_file\") \n",
249+
" \n",
250+
"# we create a data object which in this case is a book_list. \n",
251+
"my_movie_list =['Avengers', 'Venom', \n",
252+
" 'A_Quiet_Place'] \n",
253+
" \n",
254+
"# we are assigning a dictionary key to the list \n",
255+
"# which we will want to retrieve \n",
256+
"shfile['movie_list']= my_movie_list \n",
257+
" \n",
258+
"# now, we simply close the shelf file. \n",
259+
"shfile.close() "
260+
]
261+
},
262+
{
263+
"cell_type": "code",
264+
"execution_count": 19,
265+
"metadata": {},
266+
"outputs": [
267+
{
268+
"name": "stdout",
269+
"output_type": "stream",
270+
"text": [
271+
"['Avengers', 'Venom', 'A_Quiet_Place']\n"
272+
]
273+
}
274+
],
275+
"source": [
276+
"# In this step, we create a shelf file. \n",
277+
"var = shelve.open(\"shelf_file\") \n",
278+
" \n",
279+
"# Now, this 'var' variable points to all the \n",
280+
"# data objects in the file 'shelf_file'. \n",
281+
"print(var['movie_list']) \n",
282+
" \n",
283+
"# now, we simply close the file 'shelf_file'. \n",
284+
"var.close() "
285+
]
286+
}
287+
],
288+
"metadata": {
289+
"kernelspec": {
290+
"display_name": "Python 3",
291+
"language": "python",
292+
"name": "python3"
293+
},
294+
"language_info": {
295+
"codemirror_mode": {
296+
"name": "ipython",
297+
"version": 3
298+
},
299+
"file_extension": ".py",
300+
"mimetype": "text/x-python",
301+
"name": "python",
302+
"nbconvert_exporter": "python",
303+
"pygments_lexer": "ipython3",
304+
"version": "3.8.5"
305+
}
306+
},
307+
"nbformat": 4,
308+
"nbformat_minor": 4
309+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /