Guest User

Untitled

a guest
Dec 15th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "with open('/resources/data/Example2.txt','w') as writefile:\n",
  10. " writefile.write(\"This is line A\")"
  11. ]
  12. },
  13. {
  14. "cell_type": "code",
  15. "execution_count": 2,
  16. "metadata": {},
  17. "outputs": [
  18. {
  19. "name": "stdout",
  20. "output_type": "stream",
  21. "text": [
  22. "This is line A\n"
  23. ]
  24. }
  25. ],
  26. "source": [
  27. "with open('/resources/data/Example2.txt','r') as testwritefile:\n",
  28. " print(testwritefile.read())"
  29. ]
  30. },
  31. {
  32. "cell_type": "code",
  33. "execution_count": 3,
  34. "metadata": {},
  35. "outputs": [],
  36. "source": [
  37. "with open('/resources/data/Example2.txt','w') as writefile:\n",
  38. " writefile.write(\"This is line B\\n\")"
  39. ]
  40. },
  41. {
  42. "cell_type": "code",
  43. "execution_count": 5,
  44. "metadata": {},
  45. "outputs": [],
  46. "source": [
  47. "with open('/resources/data/Example2.txt','a') as writefile:\n",
  48. " writefile.write(\"This is line c\\n\")"
  49. ]
  50. },
  51. {
  52. "cell_type": "code",
  53. "execution_count": 6,
  54. "metadata": {},
  55. "outputs": [],
  56. "source": [
  57. "Lines=[\"This is line A\\n\",\"This is line B\\n\",\"This is line C\\n\"]"
  58. ]
  59. },
  60. {
  61. "cell_type": "code",
  62. "execution_count": 10,
  63. "metadata": {},
  64. "outputs": [],
  65. "source": [
  66. "with open('/resources/data/Example3.txt','a') as writefile:\n",
  67. " for line in Lines:\n",
  68. " writefile.write(line)\n",
  69. " "
  70. ]
  71. },
  72. {
  73. "cell_type": "code",
  74. "execution_count": 11,
  75. "metadata": {},
  76. "outputs": [
  77. {
  78. "name": "stdout",
  79. "output_type": "stream",
  80. "text": [
  81. "This is line A\n",
  82. "This is line B\n",
  83. "This is line C\n",
  84. "\n"
  85. ]
  86. }
  87. ],
  88. "source": [
  89. "with open('/resources/data/Example3.txt','r') as testreadfille:\n",
  90. " print(testreadfille.read())"
  91. ]
  92. },
  93. {
  94. "cell_type": "code",
  95. "execution_count": 18,
  96. "metadata": {},
  97. "outputs": [
  98. {
  99. "name": "stdout",
  100. "output_type": "stream",
  101. "text": [
  102. "This is line E\n",
  103. "This is line F\n",
  104. "This is line G\n",
  105. "\n",
  106. "This is line B\n",
  107. "This is line B\n",
  108. "This is line c\n",
  109. "\n"
  110. ]
  111. }
  112. ],
  113. "source": [
  114. "with open('/resources/data/Example3.txt','r') as readfile:\n",
  115. " print(readfile.read())\n",
  116. " \n",
  117. " with open('/resources/data/Example2.txt','a') as writefile: \n",
  118. " for line in readfile:\n",
  119. " writefile.write(line)\n",
  120. "with open('/resources/data/Example2.txt','r') as readfile:\n",
  121. " print(readfile.read())\n",
  122. " "
  123. ]
  124. },
  125. {
  126. "cell_type": "code",
  127. "execution_count": null,
  128. "metadata": {},
  129. "outputs": [],
  130. "source": []
  131. }
  132. ],
  133. "metadata": {
  134. "kernelspec": {
  135. "display_name": "Python 3",
  136. "language": "python",
  137. "name": "python3"
  138. },
  139. "language_info": {
  140. "codemirror_mode": {
  141. "name": "ipython",
  142. "version": 3
  143. },
  144. "file_extension": ".py",
  145. "mimetype": "text/x-python",
  146. "name": "python",
  147. "nbconvert_exporter": "python",
  148. "pygments_lexer": "ipython3",
  149. "version": "3.6.6"
  150. }
  151. },
  152. "nbformat": 4,
  153. "nbformat_minor": 2
  154. }
Add Comment
Please, Sign In to add comment