{ "cells": [ { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": "\nMappe1.xlsx\n.xlsx\nMappe1\n" } ], "source": [ "from pathlib import PurePath\n", "\n", "filename = PurePath(\"Excel\\\\Mappe1.xlsx\")\n", "\n", "print(filename.absolute)\n", "print(filename.name)\n", "# prints \"raw_data.txt\"\n", "\n", "print(filename.suffix)\n", "# prints \"txt\"\n", "\n", "print(filename.stem)\n", "# prints \"raw_data\"\n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "output_type": "error", "ename": "TypeError", "evalue": "This COM object can not automate the makepy process - please run makepy manually for this object", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mcom_error\u001b[0m Traceback (most recent call last)", "\u001b[1;32mC:\\dev\\Python\\Python38-32\\lib\\site-packages\\win32com\\client\\gencache.py\u001b[0m in \u001b[0;36mEnsureDispatch\u001b[1;34m(prog_id, bForDemand)\u001b[0m\n\u001b[0;32m 529\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 530\u001b[1;33m \u001b[0mti\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdisp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_oleobj_\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mGetTypeInfo\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 531\u001b[0m \u001b[0mdisp_clsid\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mti\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mGetTypeAttr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mcom_error\u001b[0m: (-2147467263, 'Nicht implementiert', None, None)", "\nDuring handling of the above exception, another exception occurred:\n", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mwin32com\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclient\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mtr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mwin32com\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclient\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgencache\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mEnsureDispatch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"CognosTransformer.Application\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32mC:\\dev\\Python\\Python38-32\\lib\\site-packages\\win32com\\client\\gencache.py\u001b[0m in \u001b[0;36mEnsureDispatch\u001b[1;34m(prog_id, bForDemand)\u001b[0m\n\u001b[0;32m 539\u001b[0m \u001b[0mdisp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdisp_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdisp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_oleobj_\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 540\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mpythoncom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcom_error\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 541\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This COM object can not automate the makepy process - please run makepy manually for this object\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 542\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mdisp\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 543\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mTypeError\u001b[0m: This COM object can not automate the makepy process - please run makepy manually for this object" ] } ], "source": [ "import win32com.client\n", "tr = win32com.client.gencache.EnsureDispatch(\"CognosTransformer.Application\")\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": "Could not locate a type library matching 'C:\\Program Files (x86)\\Cognos\\cer5\\bin\\trnsfrmr.dll'\n" } ], "source": [ "import sys\n", "from win32com.client import makepy\n", "\n", "outputFile = \"C:\\\\Projekte\\\\Python\\\\transformer_automation.py\"\n", "comTypeLibraryOrDLL = \"C:\\\\Program Files (x86)\\\\Cognos\\\\cer5\\\\bin\\\\transdll.dll\"\n", "sys.argv = [\"makepy\", \"-o\", outputFile, comTypeLibraryOrDLL]\n", "\n", "makepy.main ()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'jvvr://yyy.ravjqpejcnngpig.eqo/re/fgh/ocr.jvon'" ] }, "metadata": {}, "execution_count": 18 } ], "source": [ "sentence = 'g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyrq ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.'\n", "url = 'http://www.pythonchallenge.com/pc/def/map.html'\n", "alphabet = [chr(x) for x in range(97, 123)] + ['a', 'b']\n", "''.join([alphabet[alphabet.index(x)+2] if x in alphabet else x for x in url])" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Help on built-in function maketrans:\n\nmaketrans(...)\n Return a translation table usable for str.translate().\n \n If there is only one argument, it must be a dictionary mapping Unicode\n ordinals (integers) or characters to Unicode ordinals, strings or None.\n Character keys will be then converted to ordinals.\n If there are two arguments, they must be strings of equal length, and\n in the resulting dictionary, each character in x will be mapped to the\n character at the same position in y. If there is a third argument, it\n must be a string, whose characters will be mapped to None in the result.\n\n" ] } ], "source": [ "help(str.maketrans)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'htmlheadtitleocrtitlelinkrelstylesheettypetextcsshrefstylecssheadbodycenterimgsrcocrjpgbrfontcolorcrecognizethecharactersmaybetheyareinthebookbrbuttheyareinthepagesourcecenterbrbrbrfontsizecolorgoldeneraltipslisethehintsheyarehelpfulmostofthetimeslilinvestigatethedatagiventoyoulilivoidlookingforspoilerslibrorumsahrefhttpwwwpythonchallengecomforumsythonhallengeorumsareadbeforeyoupostbrircfreenodenetpythonchallengebrbroseethesolutionstothepreviouslevelreplacepcwithpcciegotohttpwwwpythonchallengecompccdefocrhtmlbodyhtmlfindrarecharactersinthemessbelowequality'" ] }, "metadata": {}, "execution_count": 31 } ], "source": [ "import requests\n", "import re\n", "\n", "res = requests.get('http://www.pythonchallenge.com/pc/def/ocr.html')\n", "''.join([x if x in alphabet else '' for x in res.content.decode('utf-8')])\n", "# p.match(res.content.decode())" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "['qIQNlQSLi', 'eOEKiVEYj', 'aZADnMCZq', 'bZUTkLYNg', 'uCNDeHSBj', 'kOIXdKBFh', 'dXJVlGZVm', 'gZAGiLQZx', 'vCJAsACFl', 'qKWGtIDCj']\n" ] } ], "source": [ "import requests\n", "import re\n", "\n", "res = requests.get('http://www.pythonchallenge.com/pc/def/equality.html')\n", "p = re.compile(r'[^A-Z][A-Z]{3}[a-z][A-Z]{3}[^A-Z]')\n", "m = p.findall(res.content.decode('utf-8'))\n", "print(m)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "output_type": "error", "ename": "IndexError", "evalue": "list index out of range", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mres\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0mmultiply_matrix\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32m\u001b[0m in \u001b[0;36mmultiply_matrix\u001b[1;34m(m1, m2)\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mj\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mm2_col\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mm2\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm2\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mres\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mx1\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mx2\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx2\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mm2_col\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mres\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mIndexError\u001b[0m: list index out of range" ] } ], "source": [ "def multiply_matrix(m1, m2):\n", "\tif len(m1[0]) != len(m2):\n", "\t\treturn \"ERROR\"\n", "\tres = []\n", "\tfor i in range(len(m2)):\n", "\t\tres.append([])\n", "\t\tfor j in range(len(m1)):\n", "\t\t\tm2_col = [m2[x][j] for x in range(len(m2[0]))]\n", "\t\t\tres[i].append(sum([x1 * x2 for x1, x2 in zip(m1[i], m2_col)]))\n", "\treturn res\n", "\n", "multiply_matrix([[1,2,3]],[[1],[2],[3]])\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "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.8.2-final" }, "orig_nbformat": 2, "kernelspec": { "name": "python38232bitbfe000d0e0804f0ba6fab56a16b38371", "display_name": "Python 3.8.2 32-bit", "language": "python" } }, "nbformat": 4, "nbformat_minor": 2 }