{ "cells": [ { "cell_type": "markdown", "id": "b2b7391d-ac57-4721-9d64-5b3c691de954", "metadata": {}, "source": [ " - 10 *

XPUB

\n", " - write this\n" ] }, { "cell_type": "code", "execution_count": 17, "id": "f341c0e7-5d49-48f4-b190-6113adbfff72", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

\n" ] } ], "source": [ "print('

XPUB

'*10)" ] }, { "cell_type": "code", "execution_count": 18, "id": "e4e0ab58-cf69-4417-9f73-6283d0c4d126", "metadata": {}, "outputs": [], "source": [ "html='

XPUB

'*10" ] }, { "cell_type": "code", "execution_count": 19, "id": "e789d926-6625-4235-9dc9-0500da8ae2ee", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

XPUB

\n" ] } ], "source": [ "print(html)" ] }, { "cell_type": "markdown", "id": "2c0279fd-2f11-47e7-904d-8c551ff5f1b2", "metadata": {}, "source": [ "OPENING AND READING FILE" ] }, { "cell_type": "code", "execution_count": 51, "id": "ced51d65-34ac-4f02-bde3-5728cbb6bc3a", "metadata": {}, "outputs": [], "source": [ "with open ('mywebpage.html',mode='w') as f:\n", " f.write('something you are scared of will happen soon')" ] }, { "cell_type": "code", "execution_count": 25, "id": "998f6999-436f-4dd4-a906-c19ddb64c17d", "metadata": {}, "outputs": [], "source": [ "f = open ('mywebpage.html', mode='r')\n", "f.read()\n", "f.close()" ] }, { "cell_type": "markdown", "id": "d198e4c2-5caa-48a5-bf19-9340aa1e4db4", "metadata": {}, "source": [ "OPENING AND WRITING TO A FILE" ] }, { "cell_type": "code", "execution_count": 33, "id": "8a590504-f894-4894-b04b-a9f9fbd138f0", "metadata": {}, "outputs": [], "source": [ "f=open ('mywebpage.html', mode='w')\n", "f.write('

something you are scared of will happen soon

')\n", "f.close()" ] }, { "cell_type": "code", "execution_count": 45, "id": "22c8c797-4a9d-4041-b7cf-c77b424745c9", "metadata": {}, "outputs": [], "source": [ "html='

something you are scared of will happen soon

'*10" ] }, { "cell_type": "code", "execution_count": 97, "id": "8dc01d1f-4fff-4b8c-b501-d881acbe74ac", "metadata": {}, "outputs": [], "source": [ "template= f'''\n", "\n", "\n", " \n", " \n", " MY WEBPAGE :---)\n", "\n", "{ html }\n", "\n", "\n", "'''" ] }, { "cell_type": "code", "execution_count": 50, "id": "b149d641-7e6d-4943-a757-38f0d64206cc", "metadata": {}, "outputs": [], "source": [ "f=open ('mywebpage.html', mode='w')\n", "f.write(template)\n", "f.close()" ] }, { "cell_type": "code", "execution_count": 58, "id": "52795edf-143a-4389-89b1-1d8668555930", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "write() takes exactly one argument (0 given)", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/tmp/ipykernel_8188/3994302114.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'words.txt'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'w'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mTypeError\u001b[0m: write() takes exactly one argument (0 given)" ] } ], "source": [ "with open ('words.txt', mode='w'):\n", " f.write()\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 69, "id": "584b443f-010c-4bc7-972d-061c85d7eea9", "metadata": {}, "outputs": [], "source": [ "file=open ('words.txt',mode='r')" ] }, { "cell_type": "code", "execution_count": 70, "id": "1bd0a1a5-3803-4dc5-89ad-f46f57bb77d0", "metadata": {}, "outputs": [], "source": [ "words=file.readlines()" ] }, { "cell_type": "code", "execution_count": 75, "id": "b2a0ea86-24e4-4170-892b-ce1a7904e59e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['with\\n',\n", " 'all\\n',\n", " 'these\\n',\n", " 'colours\\n',\n", " 'around\\n',\n", " 'i\\n',\n", " 'feel\\n',\n", " 'i\\n',\n", " 'could\\n',\n", " 'live\\n',\n", " 'forever']" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "words" ] }, { "cell_type": "code", "execution_count": 161, "id": "7d4ac53c-a202-4934-86d6-663056347270", "metadata": {}, "outputs": [], "source": [ "images=[\n", " 'images/DSC_3949.jpg',\n", " 'images/DSC_5576.jpg',\n", " 'images/DSC_5531.jpg',\n", "]" ] }, { "cell_type": "code", "execution_count": 162, "id": "2bd094df-91e8-4cdb-9e8d-3691ef62e778", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['images/DSC_3949.jpg', 'images/DSC_5576.jpg', 'images/DSC_5531.jpg']" ] }, "execution_count": 162, "metadata": {}, "output_type": "execute_result" } ], "source": [ "images" ] }, { "cell_type": "code", "execution_count": 163, "id": "9b20c6c4-8953-4293-980d-32ae696c3033", "metadata": {}, "outputs": [], "source": [ "import os\n", "foldername= 'images'\n", "files = os.listdir(foldername)" ] }, { "cell_type": "code", "execution_count": 164, "id": "756384b1-c6b9-4671-a740-74cb037d584c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['DSC_5576.jpg', 'DSC_5531.jpg', 'DSC_3949.jpg']" ] }, "execution_count": 164, "metadata": {}, "output_type": "execute_result" } ], "source": [ "files" ] }, { "cell_type": "code", "execution_count": 165, "id": "8dbe6a65-9044-4af6-951d-c0bc0ec96d78", "metadata": {}, "outputs": [], "source": [ "images=[] #empty list\n", "foldername='images'\n", "\n", "for filename in os.listdir(foldername):\n", " path=os.path.join(foldername, filename)\n", " #print(path)\n", " images.append(path)" ] }, { "cell_type": "code", "execution_count": 166, "id": "e3fc6ddf-e3e6-408e-988f-676b048c6dc3", "metadata": {}, "outputs": [], "source": [ "from random import choice" ] }, { "cell_type": "code", "execution_count": 167, "id": "81b5a99c-1d23-4729-9035-bfc0fa1a918a", "metadata": {}, "outputs": [], "source": [ "html=''\n", "for image in images:\n", " img=f''\n", " caption= choice(words)+choice(words)+choice(words)\n", " small=f'{caption}'\n", " \n", " html= html+img+small" ] }, { "cell_type": "code", "execution_count": 168, "id": "147310e9-50d2-4642-b723-6fae04c2752e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'all\\naround\\nfeel\\naround\\nfeel\\nfeel\\nlive\\nforeverlive\\n'" ] }, "execution_count": 168, "metadata": {}, "output_type": "execute_result" } ], "source": [ "html" ] }, { "cell_type": "code", "execution_count": 169, "id": "898e4278-3009-4e3d-9ed1-dd7e2067dd62", "metadata": {}, "outputs": [], "source": [ "template= f'''\n", "\n", "\n", " \n", " \n", " \n", " MY WEBPAGE :---)\n", "\n", "{ html }\n", "\n", "\n", "'''" ] }, { "cell_type": "code", "execution_count": 170, "id": "5c80b4ac-7741-443d-a3e3-8c126601bc5e", "metadata": {}, "outputs": [], "source": [ "f=open ('mywebpage.html', mode='w')\n", "f.write(template)\n", "f.close()" ] }, { "cell_type": "code", "execution_count": null, "id": "84832863-8160-47bb-9dfe-90ee2f7a3dca", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.7.3" } }, "nbformat": 4, "nbformat_minor": 5 }