Skip to content

Commit d5e2512

Browse files
committed
Added file handling to cheatsheet
1 parent a5b6b5d commit d5e2512

2 files changed

Lines changed: 16 additions & 57 deletions

File tree

.ipynb_checkpoints/cheatsheet-checkpoint.ipynb

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,71 +1384,19 @@
13841384
"outputs": [],
13851385
"source": [
13861386
"with open('test.txt', 'w') as f:\n",
1387-
" "
1387+
" f.write('Writing a new line\\n')"
13881388
]
13891389
},
13901390
{
13911391
"cell_type": "code",
13921392
"execution_count": null,
1393-
"id": "ee84bdc5",
1393+
"id": "7d69598c",
13941394
"metadata": {},
13951395
"outputs": [],
13961396
"source": [
1397-
"TypeError: can only concatenate str (not \"int\") to tuple"
1397+
"with open('test.txt', 'a') as f:\n",
1398+
" f.write('Adding a new line to the last one\\n')"
13981399
]
1399-
},
1400-
{
1401-
"cell_type": "code",
1402-
"execution_count": 2,
1403-
"id": "d196942f",
1404-
"metadata": {},
1405-
"outputs": [
1406-
{
1407-
"ename": "TypeError",
1408-
"evalue": "can only concatenate str (not \"int\") to str",
1409-
"output_type": "error",
1410-
"traceback": [
1411-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1412-
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
1413-
"Input \u001b[0;32mIn [2]\u001b[0m, in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m123\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\n",
1414-
"\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
1415-
]
1416-
}
1417-
],
1418-
"source": [
1419-
"'123' + 4"
1420-
]
1421-
},
1422-
{
1423-
"cell_type": "code",
1424-
"execution_count": 1,
1425-
"id": "7f63db06",
1426-
"metadata": {},
1427-
"outputs": [
1428-
{
1429-
"ename": "AttributeError",
1430-
"evalue": "'tuple' object has no attribute 'append'",
1431-
"output_type": "error",
1432-
"traceback": [
1433-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1434-
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
1435-
"Input \u001b[0;32mIn [1]\u001b[0m, in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m var \u001b[38;5;241m=\u001b[39m (\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43mvar\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m(\u001b[38;5;241m4\u001b[39m)\n",
1436-
"\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
1437-
]
1438-
}
1439-
],
1440-
"source": [
1441-
"var = (1,2,3)\n",
1442-
"var.append(4)"
1443-
]
1444-
},
1445-
{
1446-
"cell_type": "code",
1447-
"execution_count": null,
1448-
"id": "4faaae64",
1449-
"metadata": {},
1450-
"outputs": [],
1451-
"source": []
14521400
}
14531401
],
14541402
"metadata": {

cheatsheet.ipynb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,18 @@
13841384
"outputs": [],
13851385
"source": [
13861386
"with open('test.txt', 'w') as f:\n",
1387-
" "
1387+
" f.write('Writing a new line\\n')"
1388+
]
1389+
},
1390+
{
1391+
"cell_type": "code",
1392+
"execution_count": null,
1393+
"id": "7d69598c",
1394+
"metadata": {},
1395+
"outputs": [],
1396+
"source": [
1397+
"with open('test.txt', 'a') as f:\n",
1398+
" f.write('Adding a new line to the last one\\n')"
13881399
]
13891400
}
13901401
],

0 commit comments

Comments
 (0)