Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "with open('/resources/data/Example2.txt','w') as writefile:\n",
- " writefile.write(\"This is line A\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "This is line A\n"
- ]
- }
- ],
- "source": [
- "with open('/resources/data/Example2.txt','r') as testwritefile:\n",
- " print(testwritefile.read())"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [],
- "source": [
- "with open('/resources/data/Example2.txt','w') as writefile:\n",
- " writefile.write(\"This is line B\\n\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "with open('/resources/data/Example2.txt','a') as writefile:\n",
- " writefile.write(\"This is line c\\n\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "Lines=[\"This is line A\\n\",\"This is line B\\n\",\"This is line C\\n\"]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [],
- "source": [
- "with open('/resources/data/Example3.txt','a') as writefile:\n",
- " for line in Lines:\n",
- " writefile.write(line)\n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "This is line A\n",
- "This is line B\n",
- "This is line C\n",
- "\n"
- ]
- }
- ],
- "source": [
- "with open('/resources/data/Example3.txt','r') as testreadfille:\n",
- " print(testreadfille.read())"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "This is line E\n",
- "This is line F\n",
- "This is line G\n",
- "\n",
- "This is line B\n",
- "This is line B\n",
- "This is line c\n",
- "\n"
- ]
- }
- ],
- "source": [
- "with open('/resources/data/Example3.txt','r') as readfile:\n",
- " print(readfile.read())\n",
- " \n",
- " with open('/resources/data/Example2.txt','a') as writefile: \n",
- " for line in readfile:\n",
- " writefile.write(line)\n",
- "with open('/resources/data/Example2.txt','r') as readfile:\n",
- " print(readfile.read())\n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.6"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment