diff --git a/.ipynb_checkpoints/index-checkpoint.ipynb b/.ipynb_checkpoints/index-checkpoint.ipynb index ecea739..294f454 100644 --- a/.ipynb_checkpoints/index-checkpoint.ipynb +++ b/.ipynb_checkpoints/index-checkpoint.ipynb @@ -60,14 +60,14 @@ " - [第五节:迭代器](04-PythonAdvancedFeatures/迭代器.ipynb)\n", " \n", "- 第五章 面向对象高级编程\n", - " - [创建和使用类](05-PythonObject-oriented/创建和使用类.ipynb)\n", - " - [访问属性](05-PythonObject-oriented/访问属性.ipynb)\n", - " - [Python内置类属性](05-PythonObject-oriented/Python内置类属性.ipynb)\n", - " - [继承](05-PythonObject-oriented/继承.ipynb)\n", - " - [垃圾回收](05-PythonObject-oriented/垃圾回收.ipynb)\n", - " - [方法重写和运算符重载](05-PythonObject-oriented/方法重写和运算符重载.ipynb)\n", - " - [导入类](05-PythonObject-oriented/导入类.ipynb)\n", - " - [类编码风格](05-PythonObject-oriented/类编码风格.ipynb)\n", + " - [创建和使用类](05-PythonObject/创建和使用类.ipynb)\n", + " - [访问属性](05-PythonObject/访问属性.ipynb)\n", + " - [Python内置类属性](05-PythonObject/Python内置类属性.ipynb)\n", + " - [继承](05-PythonObject/继承.ipynb)\n", + " - [垃圾回收](05-PythonObject/垃圾回收.ipynb)\n", + " - [方法重写和运算符重载](05-PythonObject/方法重写和运算符重载.ipynb)\n", + " - [导入类](05-PythonObject/导入类.ipynb)\n", + " - [类编码风格](05-PythonObject/类编码风格.ipynb)\n", " \n", "- 第六章 函数式编程\n", " - [第一节:高阶函数](06-PythonFunctionalProgramming/高阶函数.ipynb)\n", @@ -80,9 +80,11 @@ " - []()\n", " - []()\n", "- 第八章 网络相关\n", + " - [网络通讯socket]()\n", "\n", "- 第九章 IO编程\n", " - [文件读写](09-IO-programming/文件读写.ipynb)\n", + " - [数据库读写操作](09-IO-programming/Sql/index.ipynb)\n", " - [StringIO和BytesIO](09-IO-programming/StringIO和BytesIO.ipynb)\n", " - [序列化](09-IO-programming/序列化.ipynb)\n", " - [异步IO](09-IO-programming/异步IO.ipynb)\n", @@ -121,7 +123,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.7.3" } }, "nbformat": 4, diff --git "a/02-PythonBasics/Python\345\244\232\347\272\247\346\216\222\345\272\217(sorted).ipynb" "b/02-PythonBasics/Python\345\244\232\347\272\247\346\216\222\345\272\217(sorted).ipynb" index 6f4f172..1d1d59e 100644 --- "a/02-PythonBasics/Python\345\244\232\347\272\247\346\216\222\345\272\217(sorted).ipynb" +++ "b/02-PythonBasics/Python\345\244\232\347\272\247\346\216\222\345\272\217(sorted).ipynb" @@ -2,16 +2,16 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[('a', 2), ('a', 3), ('a', 4), ('b', 1)]" + "[('b', 1), ('a', 2), ('a', 3), ('a', 4)]" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -19,7 +19,7 @@ "source": [ "# 多级排序\n", "L=[('a',2),('a',3),('b',1),('a',4)]\n", - "L = sorted(L, key = lambda x:(x[0],x[1]))\n", + "L = sorted(L, key = lambda x:(x[1],x[0]))\n", "L" ] } @@ -40,7 +40,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.6" } }, "nbformat": 4, diff --git "a/02-PythonBasics/\345\255\227\347\254\246\344\270\262\345\222\214\347\274\226\347\240\201.ipynb" "b/02-PythonBasics/\345\255\227\347\254\246\344\270\262\345\222\214\347\274\226\347\240\201.ipynb" index 8b9f221..69f8c39 100644 --- "a/02-PythonBasics/\345\255\227\347\254\246\344\270\262\345\222\214\347\274\226\347\240\201.ipynb" +++ "b/02-PythonBasics/\345\255\227\347\254\246\344\270\262\345\222\214\347\274\226\347\240\201.ipynb" @@ -451,6 +451,9 @@ "\n", "### a.decode(* *):将a 解码 为 unicode编码格式的字符串或unicode对象\n", "\n", + ">python3中encode和decode跟python2还是有一定的区别的,在python3中: \n", + "- encode(编码):按照某种规则将“文本”转换为“字节流”。 python 3中表示:unicode变成str\n", + "- decode(解码):将“字节流”按照某种规则转换成“文本”。 python3中表示:str变成unicode\n", "\n", "![encode](./img/encode.png)" ] @@ -461,33 +464,59 @@ "source": [ "### 操作范例:\n", "\n", - "1、查看默认编码,python遇到中文字符,会识别他是utf-8编码。" + "1、查看默认编码,python遇到中文字符,会识别他是utf-8编码。\n", + "\n", + "如果我们没有在代码文件开始的部分指定字符编码,Python解释器就会使用哪种字符编码把从代码文件中读取到的字节转换为UNICODE代码点呢?就像我们配置某些软件时,有很多默认选项一样,需要在Python解释器内部设置默认的字符编码来解决这个问题,这就是文章开头所说的“默认编码”。因此大家所说的Python中文字符问题就可以总结为一句话:当无法通过默认的字符编码对字节进行转换时,就会出现解码错误(UnicodeEncodeError)。\n", + "\n", + "Python2和Python3的解释器使用的默认编码是不一样的,我们可以通过sys.getdefaultencoding()来获取默认编码:" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "('中文', str)" + "'utf-8'" ] }, - "execution_count": 31, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import sys\n", + "# 解释器使用的默认编码\n", + "sys.getdefaultencoding()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('中文', str, '中')" + ] + }, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "str_test = '中文'\n", - "str_test, type(str_test)" + "str_test, type(str_test),str_test[0]." ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -496,14 +525,14 @@ "(b'\\xe4\\xb8\\xad\\xe6\\x96\\x87', bytes)" ] }, - "execution_count": 32, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "str_utf8 = str_test.encode('utf-8')\n", - "str_utf8, type(str_utf8)" + "str_utf8_to_bytes = str_test.encode('utf-8')\n", + "str_utf8_to_bytes, type(str_utf8_to_bytes)" ] }, { @@ -576,7 +605,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.7.0" } }, "nbformat": 4, diff --git "a/02-PythonBasics/\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264.ipynb" "b/02-PythonBasics/\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264.ipynb" new file mode 100644 index 0000000..20566b6 --- /dev/null +++ "b/02-PythonBasics/\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264.ipynb" @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1546603771.304786\n", + "time.struct_time(tm_year=2019, tm_mon=1, tm_mday=4, tm_hour=20, tm_min=9, tm_sec=31, tm_wday=4, tm_yday=4, tm_isdst=0)\n" + ] + } + ], + "source": [ + "import time\n", + "\n", + "# time.time()获取当前时间戳\n", + "print(time.time())\n", + "print(time.localtime())" + ] + } + ], + "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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/05-PythonObject-oriented/Python\345\206\205\347\275\256\347\261\273\345\261\236\346\200\247.ipynb" "b/05-PythonObject/Python\345\206\205\347\275\256\347\261\273\345\261\236\346\200\247.ipynb" similarity index 100% rename from "05-PythonObject-oriented/Python\345\206\205\347\275\256\347\261\273\345\261\236\346\200\247.ipynb" rename to "05-PythonObject/Python\345\206\205\347\275\256\347\261\273\345\261\236\346\200\247.ipynb" diff --git "a/05-PythonObject/\345\205\203\347\261\273\347\274\226\347\250\213.ipynb" "b/05-PythonObject/\345\205\203\347\261\273\347\274\226\347\250\213.ipynb" new file mode 100644 index 0000000..888df80 --- /dev/null +++ "b/05-PythonObject/\345\205\203\347\261\273\347\274\226\347\250\213.ipynb" @@ -0,0 +1,287 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# 动态创建类\n", + "\n", + "def creat_class(name):\n", + " if name == \"user\":\n", + " class User:\n", + " def __str__(self):\n", + " return \"user\"\n", + " return User\n", + " elif name == \"company\":\n", + " class Company:\n", + " def __str__(self):\n", + " return \"Company\"\n", + " return Company" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".User'>\n" + ] + } + ], + "source": [ + "# 创建一个类\n", + "\n", + "MyClass = creat_class(\"user\")\n", + "my_obj = MyClass()\n", + "print(type(my_obj))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "使用type方法创建一个类\n", + "\n", + "> type(class_name, bases, dict) -> a new type\n", + "type函数接收3个参数\n", + "\n", + "1: 要被创建的类名 --str\n", + "\n", + "2: 被创建的类的父类 --tuple\n", + "\n", + "3: 该类中的方法和属性 -- dict" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "user\n", + "I am user\n", + "I am BaseClass\n" + ] + } + ], + "source": [ + "class BaseClass:\n", + " def answer(self):\n", + " return \"I am BaseClass\"\n", + "\n", + "\n", + "def say(self):\n", + " return \"I am user\"\n", + "\n", + "User = type(\"User\", (BaseClass, ), {\"name\": \"user\", \"say\":say})\n", + "\n", + "my_obj = User()\n", + "\n", + "print(my_obj.name)\n", + "print(my_obj.say())\n", + "print(my_obj.answer())" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "User\n" + ] + } + ], + "source": [ + "# 元类\n", + "class MetaClass(type):\n", + " def __new__(cls, *args, **kwargs):\n", + " return super().__new__(cls, *args, **kwargs)\n", + " \n", + "\n", + "class User(metaclass=MetaClass):\n", + " def __init__(self, name):\n", + " self.name = name\n", + "\n", + " def __str__(self):\n", + " return self.name\n", + "\n", + "my_obj = User(\"User\")\n", + "print(my_obj)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "通过元类实现orm\n", + "\n", + "以django Model模块为例" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "insert user(name,age) value(bobby,28)\n" + ] + } + ], + "source": [ + "# 需求\n", + "import numbers\n", + "\n", + "\n", + "class Field:\n", + " pass\n", + "\n", + "class IntField(Field):\n", + " # 数据描述符\n", + " def __init__(self, db_column, min_value=None, max_value=None):\n", + " self._value = None\n", + " self.min_value = min_value\n", + " self.max_value = max_value\n", + " self.db_column = db_column\n", + " if min_value is not None:\n", + " if not isinstance(min_value, numbers.Integral):\n", + " raise ValueError(\"min_value must be int\")\n", + " elif min_value < 0:\n", + " raise ValueError(\"min_value must be positive int\")\n", + " if max_value is not None:\n", + " if not isinstance(max_value, numbers.Integral):\n", + " raise ValueError(\"max_value must be int\")\n", + " elif max_value < 0:\n", + " raise ValueError(\"max_value must be positive int\")\n", + " if min_value is not None and max_value is not None:\n", + " if min_value > max_value:\n", + " raise ValueError(\"min_value must be smaller than max_value\")\n", + "\n", + " def __get__(self, instance, owner):\n", + " return self._value\n", + "\n", + " def __set__(self, instance, value):\n", + " if not isinstance(value, numbers.Integral):\n", + " raise ValueError(\"int value need\")\n", + " if value < self.min_value or value > self.max_value:\n", + " raise ValueError(\"value must between min_value and max_value\")\n", + " self._value = value\n", + "\n", + "\n", + "class CharField(Field):\n", + " def __init__(self, db_column, max_length=None):\n", + " self._value = None\n", + " self.db_column = db_column\n", + " if max_length is None:\n", + " raise ValueError(\"you must spcify max_lenth for charfiled\")\n", + " self.max_length = max_length\n", + "\n", + " def __get__(self, instance, owner):\n", + " return self._value\n", + "\n", + " def __set__(self, instance, value):\n", + " if not isinstance(value, str):\n", + " raise ValueError(\"string value need\")\n", + " if len(value) > self.max_length:\n", + " raise ValueError(\"value len excess len of max_length\")\n", + " self._value = value\n", + "\n", + "\n", + "class ModelMetaClass(type):\n", + " def __new__(cls, name, bases, attrs, **kwargs):\n", + " if name == \"BaseModel\":\n", + " return super().__new__(cls, name, bases, attrs, **kwargs)\n", + " fields = {}\n", + " for key, value in attrs.items():\n", + " if isinstance(value, Field):\n", + " fields[key] = value\n", + " attrs_meta = attrs.get(\"Meta\", None)\n", + " _meta = {}\n", + " db_table = name.lower()\n", + " if attrs_meta is not None:\n", + " table = getattr(attrs_meta, \"db_table\", None)\n", + " if table is not None:\n", + " db_table = table\n", + " _meta[\"db_table\"] = db_table\n", + " attrs[\"_meta\"] = _meta\n", + " attrs[\"fields\"] = fields\n", + " del attrs[\"Meta\"]\n", + " return super().__new__(cls, name, bases, attrs, **kwargs)\n", + "\n", + "\n", + "class BaseModel(metaclass=ModelMetaClass):\n", + " def __init__(self, *args, **kwargs):\n", + " for key, value in kwargs.items():\n", + " setattr(self, key, value)\n", + " return super().__init__()\n", + "\n", + " def save(self):\n", + " fields = []\n", + " values = []\n", + " for key, value in self.fields.items():\n", + " db_column = value.db_column\n", + " if db_column is None:\n", + " db_column = key.lower()\n", + " fields.append(db_column)\n", + " value = getattr(self, key)\n", + " values.append(str(value))\n", + "\n", + " sql = \"insert {db_table}({fields}) value({values})\".format(db_table=self._meta[\"db_table\"],\n", + " fields=\",\".join(fields), values=\",\".join(values))\n", + " print(sql)\n", + " pass\n", + "\n", + "class User(BaseModel):\n", + " name = CharField(db_column=\"name\", max_length=10)\n", + " age = IntField(db_column=\"age\", min_value=1, max_value=100)\n", + "\n", + " class Meta:\n", + " db_table = \"user\"\n", + "\n", + "\n", + "if __name__ == \"__main__\":\n", + " user = User(name=\"bobby\", age=28)\n", + " user.name = \"bobby\"\n", + " user.age = 28\n", + " user.save()\n" + ] + } + ], + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/05-PythonObject-oriented/\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\347\261\273.ipynb" "b/05-PythonObject/\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\347\261\273.ipynb" similarity index 91% rename from "05-PythonObject-oriented/\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\347\261\273.ipynb" rename to "05-PythonObject/\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\347\261\273.ipynb" index db81db6..4454312 100644 --- "a/05-PythonObject-oriented/\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\347\261\273.ipynb" +++ "b/05-PythonObject/\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\347\261\273.ipynb" @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 241, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 250, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -44,14 +44,14 @@ }, { "cell_type": "code", - "execution_count": 424, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "__call__ with (175, 2)\n" + "__call__ with (3, 2)\n" ] } ], @@ -76,7 +76,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.7.3" } }, "nbformat": 4, diff --git "a/05-PythonObject-oriented/\345\236\203\345\234\276\345\233\236\346\224\266.ipynb" "b/05-PythonObject/\345\236\203\345\234\276\345\233\236\346\224\266.ipynb" similarity index 100% rename from "05-PythonObject-oriented/\345\236\203\345\234\276\345\233\236\346\224\266.ipynb" rename to "05-PythonObject/\345\236\203\345\234\276\345\233\236\346\224\266.ipynb" diff --git "a/05-PythonObject-oriented/\345\257\274\345\205\245\347\261\273.ipynb" "b/05-PythonObject/\345\257\274\345\205\245\347\261\273.ipynb" similarity index 100% rename from "05-PythonObject-oriented/\345\257\274\345\205\245\347\261\273.ipynb" rename to "05-PythonObject/\345\257\274\345\205\245\347\261\273.ipynb" diff --git "a/05-PythonObject/\345\272\217\345\210\227\347\261\273.ipynb" "b/05-PythonObject/\345\272\217\345\210\227\347\261\273.ipynb" new file mode 100644 index 0000000..d067300 --- /dev/null +++ "b/05-PythonObject/\345\272\217\345\210\227\347\261\273.ipynb" @@ -0,0 +1,150 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 6]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = [1,2,3]\n", + "b = [4,5,6]\n", + "c = a + b\n", + "c" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from collections import abc" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "class Group:\n", + " def __init__(self, ind):\n", + " self.ind = ind\n", + " \n", + " def __reversed__(self):\n", + " pass\n", + " \n", + " def __getitem__(self, item):\n", + " print(item)\n", + " return self.ind[item]\n", + " def __len__(self):\n", + " pass\n", + " def __iter__(self):\n", + " return iter(self.ind)\n", + " def __contains__(self, item):\n", + " if item in self.ind:\n", + " return True\n", + " else:\n", + " return False\n", + " def __add__(self, other):\n", + " return self.ind.ex" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "pop = Group(ind = [[1,2],[3,4],[5,6]])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "slice(0, 3, None)\n" + ] + }, + { + "data": { + "text/plain": [ + "[1, 2, 3]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sub_pop = pop[0:3]\n", + "sub_pop" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2]\n", + "[3, 4]\n", + "[5, 6]\n" + ] + } + ], + "source": [ + "for i in pop:\n", + " print(i)" + ] + }, + { + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/05-PythonObject-oriented/\346\226\271\346\263\225\351\207\215\345\206\231\345\222\214\350\277\220\347\256\227\347\254\246\351\207\215\350\275\275.ipynb" "b/05-PythonObject/\346\226\271\346\263\225\351\207\215\345\206\231\345\222\214\350\277\220\347\256\227\347\254\246\351\207\215\350\275\275.ipynb" similarity index 100% rename from "05-PythonObject-oriented/\346\226\271\346\263\225\351\207\215\345\206\231\345\222\214\350\277\220\347\256\227\347\254\246\351\207\215\350\275\275.ipynb" rename to "05-PythonObject/\346\226\271\346\263\225\351\207\215\345\206\231\345\222\214\350\277\220\347\256\227\347\254\246\351\207\215\350\275\275.ipynb" diff --git "a/05-PythonObject-oriented/\347\261\273\347\274\226\347\240\201\351\243\216\346\240\274.ipynb" "b/05-PythonObject/\347\261\273\347\274\226\347\240\201\351\243\216\346\240\274.ipynb" similarity index 100% rename from "05-PythonObject-oriented/\347\261\273\347\274\226\347\240\201\351\243\216\346\240\274.ipynb" rename to "05-PythonObject/\347\261\273\347\274\226\347\240\201\351\243\216\346\240\274.ipynb" diff --git "a/05-PythonObject-oriented/\347\273\247\346\211\277.ipynb" "b/05-PythonObject/\347\273\247\346\211\277.ipynb" similarity index 100% rename from "05-PythonObject-oriented/\347\273\247\346\211\277.ipynb" rename to "05-PythonObject/\347\273\247\346\211\277.ipynb" diff --git "a/05-PythonObject-oriented/\350\256\277\351\227\256\345\261\236\346\200\247.ipynb" "b/05-PythonObject/\350\256\277\351\227\256\345\261\236\346\200\247.ipynb" similarity index 100% rename from "05-PythonObject-oriented/\350\256\277\351\227\256\345\261\236\346\200\247.ipynb" rename to "05-PythonObject/\350\256\277\351\227\256\345\261\236\346\200\247.ipynb" diff --git "a/05-PythonObject/\351\255\224\346\263\225\345\207\275\346\225\260.ipynb" "b/05-PythonObject/\351\255\224\346\263\225\345\207\275\346\225\260.ipynb" new file mode 100644 index 0000000..788f3a4 --- /dev/null +++ "b/05-PythonObject/\351\255\224\346\263\225\345\207\275\346\225\260.ipynb" @@ -0,0 +1,171 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "class MyArray:\n", + " def __init__(self, val):\n", + " self.val = val\n", + " \n", + " def __get__(self, instance):\n", + " return self.val\n", + " \n", + " def __set__(self, instance, var):\n", + " self.val = var\n", + " \n", + " def __call__(self, instance):\n", + " return self.val\n", + " \n", + " def get(self):\n", + " return self.val\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "a = MyArray(123)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "a = 3" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "class A:\n", + " def __init__(self):\n", + " self.list = []\n", + "\n", + " def __iadd__(self, other):\n", + " self.list.append(other)\n", + " return self" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "a = A()" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 1, 2, 1, 2, 1, 2]" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a += 1\n", + "a += 2\n", + "a.list" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 计算相关" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2458350603904\n", + "__add__\n" + ] + } + ], + "source": [ + "class pop(object):\n", + " def __init__(self, var):\n", + " self.var = var\n", + " def __add__(self, other):\n", + " print(\"__add__\")\n", + " self.var += other.var\n", + " return self\n", + " def __str__(self):\n", + " return self.var\n", + "\n", + "a = pop(1)\n", + "print(id(a))\n", + "b = pop(2)\n", + "a = a + b" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "<__main__.pop at 0x23c611d4e80>" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + } + ], + "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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/09-IO-programming/Excel/data.xlsx b/09-IO-programming/Excel/data.xlsx new file mode 100644 index 0000000..765b046 Binary files /dev/null and b/09-IO-programming/Excel/data.xlsx differ diff --git a/09-IO-programming/Excel/index.ipynb b/09-IO-programming/Excel/index.ipynb index 75970fa..f8ebfa0 100644 --- a/09-IO-programming/Excel/index.ipynb +++ b/09-IO-programming/Excel/index.ipynb @@ -61,7 +61,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.7.0" } }, "nbformat": 4, diff --git "a/09-IO-programming/Excel/xlsx\350\257\273\345\206\231\346\223\215\344\275\234-openpyxl.ipynb" "b/09-IO-programming/Excel/xlsx\350\257\273\345\206\231\346\223\215\344\275\234-openpyxl.ipynb" index 1e3382c..f617cf7 100644 --- "a/09-IO-programming/Excel/xlsx\350\257\273\345\206\231\346\223\215\344\275\234-openpyxl.ipynb" +++ "b/09-IO-programming/Excel/xlsx\350\257\273\345\206\231\346\223\215\344\275\234-openpyxl.ipynb" @@ -35,14 +35,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " utf-8 ['page1', 'page2']\n" + " utf-8 ['双到表(村)']\n" ] } ], @@ -51,7 +51,7 @@ "import openpyxl\n", "import sys\n", "\n", - "excel = openpyxl.load_workbook(\"read_test1.xlsx\")\n", + "excel = openpyxl.load_workbook(\"data.xlsx\")\n", "\n", "print(excel.active, excel.encoding, excel.sheetnames)" ] @@ -79,23 +79,49 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 72, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "('hello', 'world')" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "因病 : 0.5669642857142857\n", + "因学 : 0.26785714285714285\n", + "缺技术 : 0.026785714285714284\n", + "自身发展动力不 : 0.013392857142857142\n", + "因残 : 0.09821428571428571\n", + "缺劳力 : 0.008928571428571428\n", + "缺资金 : 0.013392857142857142\n", + "因灾 : 0.004464285714285714\n", + "总计: 0.9999999999999999\n" + ] } ], "source": [ - "sheet = excel['page1']\n", - "sheet.cell(1, 1).value, sheet.cell(1, 2).value" + "sheet = excel['双到表(村)']\n", + "# a = sheet.cell(11, 4).value.split(\"、\")\n", + "\n", + "ans = {}\n", + "\n", + "for i in range(7,203+1):\n", + " a = sheet.cell(i, 4).value.split(\"、\")\n", + " for j in a:\n", + " if j in ans.keys():\n", + " ans[j.strip()] += 1\n", + " else:\n", + " ans[j.strip()] = 1\n", + "\n", + "s = 0\n", + "for i in ans.keys():\n", + " s += ans[i]\n", + "\n", + "b = 0\n", + "for i in ans.keys():\n", + " print(i,\" : \",ans[i]/s)\n", + " b += ans[i]/s\n", + "\n", + "print(\"总计:\", b)" ] }, { @@ -272,7 +298,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.7.0" } }, "nbformat": 4, diff --git a/09-IO-programming/Python Socket.ipynb b/09-IO-programming/Python Socket.ipynb new file mode 100644 index 0000000..b1ed5c1 --- /dev/null +++ b/09-IO-programming/Python Socket.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"code","outputs":[],"source":[],"metadata":{},"execution_count":null}],"nbformat":4,"nbformat_minor":2,"metadata":{"language_info":{"name":"python","codemirror_mode":{"name":"ipython","version":3}},"orig_nbformat":2,"file_extension":".py","mimetype":"text/x-python","name":"python","npconvert_exporter":"python","pygments_lexer":"ipython3","version":3}} \ No newline at end of file diff --git "a/09-IO-programming/Sql/MongoDB\346\225\260\346\215\256\345\272\223\350\257\273\345\206\231\346\223\215\344\275\234.ipynb" "b/09-IO-programming/Sql/MongoDB\346\225\260\346\215\256\345\272\223\350\257\273\345\206\231\346\223\215\344\275\234.ipynb" new file mode 100644 index 0000000..bb5be40 --- /dev/null +++ "b/09-IO-programming/Sql/MongoDB\346\225\260\346\215\256\345\272\223\350\257\273\345\206\231\346\223\215\344\275\234.ipynb" @@ -0,0 +1,604 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Python Mongodb\n", + "Mongodb 是目前最流行的 NoSQL 数据库之一,使用的数据类型 BSON(类似 JSON)。\n", + "\n", + "## 一、环境准备PyMongo\n", + "Python 要连接 MongoDB 需要 MongoDB 驱动,这里我们使用 PyMongo 驱动来连接。\n", + "\n", + "[PyMongo官网传送门](http://api.mongodb.com/python/current/installation.html)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 二、pymongo使用方法" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.1连接数据库" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "MongoDB存储\n", + " 在这里我们来看一下Python3下MongoDB的存储操作,在本节开始之前请确保你已经安装好了MongoDB并启动了其服务,另外安装好了Python\n", + " 的PyMongo库。\n", + " \n", + "连接MongoDB\n", + " 连接MongoDB我们需要使用PyMongo库里面的MongoClient,一般来说传入MongoDB的IP及端口即可,第一个参数为地址host,\n", + " 第二个参数为端口port,端口如果不传默认是27017。\n", + "\"\"\"\n", + "import pymongo\n", + "\n", + "\"\"\"\n", + "这样我们就可以创建一个MongoDB的连接对象了。另外MongoClient的第一个参数host还可以直接传MongoDB的连接字符串,以mongodb开头,\n", + "例如:client = MongoClient('mongodb://localhost:27017/')可以达到同样的连接效果。\n", + "\"\"\"\n", + "client = pymongo.MongoClient(host='localhost', port=27017)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.2指定数据库" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# MongoDB中还分为一个个数据库,我们接下来的一步就是指定要操作哪个数据库,在这里我以test数据库为例进行说明,所以下一步我们\n", + "# 需要在程序中指定要使用的数据库。\n", + " \n", + "db = client.test\n", + "# 调用client的test属性即可返回test数据库,当然也可以这样来指定:\n", + "# db = client['test']\n", + "# 两种方式是等价的。\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.3指定集合并插入数据" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "# MongoDB的每个数据库又包含了许多集合Collection,也就类似与关系型数据库中的表,下一步我们需要指定要操作的集合,\n", + "# 在这里我们指定一个集合名称为students,学生集合。还是和指定数据库类似,指定集合也有两种方式。\n", + " \n", + "collection = db.students\n", + "# collection = db['students']\n", + "# 插入数据,接下来我们便可以进行数据插入了,对于students这个Collection,我们新建一条学生数据,以字典的形式表示:\n", + " \n", + "student = {\n", + " 'id': '20170101',\n", + " 'name': 'Jordan',\n", + " 'age': 20,\n", + " 'gender': 'male'\n", + "}\n", + "# 在这里我们指定了学生的学号、姓名、年龄和性别,然后接下来直接调用collection的insert()方法即可插入数据。\n", + " \n", + "result = collection.insert_one(student)\n", + "print(result)\n", + "# 运行结果:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 在MongoDB中,每条数据其实都有一个_id属性来唯一标识,如果没有显式指明_id,MongoDB会自动产生一个ObjectId类型的_id属性。\n", + "- insert()方法会在执行后返回的_id值。" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "> - 实际上在PyMongo 3.X版本中,insert()方法官方已经不推荐使用了,当然继续使用也没有什么问题,\n", + "- 官方推荐使用insert_one()和insert_many()方法将插入单条和多条记录分开。" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "# 当然我们也可以同时插入多条数据,只需要以列表形式传递即可,示例如下:\n", + " \n", + "student1 = {\n", + " 'id': '20170101',\n", + " 'name': 'Jordan',\n", + " 'age': 20,\n", + " 'gender': 'male'\n", + "}\n", + " \n", + "student2 = {\n", + " 'id': '20170202',\n", + " 'name': 'Mike',\n", + " 'age': 21,\n", + " 'gender': 'male'\n", + "}\n", + " \n", + "result = collection.insert_many([student1, student2])\n", + "print(result)\n", + "# 返回的结果是对应的_id的集合,运行结果:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.4查询\n", + "\n", + "> 插入数据后我们可以利用find_one()或find()方法进行查询,find_one()查询得到是单个结果,find()则返回多个结果。" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "{'_id': ObjectId('5c2f2b900cf63e2e08407598'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n" + ] + } + ], + "source": [ + "# 在这里我们查询name为Mike的数据,它的返回结果是字典类型,运行结果:\n", + "# \n", + "# {'_id': ObjectId('5c2f2b900cf63e2e08407598'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n", + "# 可以发现它多了一个_id属性,这就是MongoDB在插入的过程中自动添加的。\n", + "\n", + "result = collection.find_one({'name': 'Mike'})\n", + "print(type(result))\n", + "print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 我们也可以直接根据ObjectId来查询,这里需要使用bson库里面的ObjectId。" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'_id': ObjectId('5c2f2b900cf63e2e08407598'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n" + ] + } + ], + "source": [ + "from bson.objectid import ObjectId\n", + " \n", + "result = collection.find_one({'_id': ObjectId('5c2f2b900cf63e2e08407598')})\n", + "print(result)\n", + "# 其查询结果依然是字典类型,运行结果:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 对于多条数据的查询,我们可以使用find()方法,例如在这里查找年龄为20的数据,示例如下:" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "{'_id': ObjectId('5c2f2a0a0cf63e43645e7931'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2a280cf63e291ce097bb'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2b900cf63e2e08407596'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2b900cf63e2e08407597'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2ece0cf63e27d42a9f98'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2eda0cf63e27d42a9f99'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2f250cf63e27d42a9f9a'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2f4e0cf63e27d42a9f9b'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2f530cf63e27d42a9f9d'), 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male'}\n" + ] + } + ], + "source": [ + "results = collection.find({'age': 20})\n", + "print(results)\n", + "for result in results:\n", + " print(result)\n", + "# 运行结果:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 如果要查询年龄大于20的数据,则写法如下:" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "{'_id': ObjectId('5c2f2b900cf63e2e08407598'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2f4e0cf63e27d42a9f9c'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2f530cf63e27d42a9f9e'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n" + ] + } + ], + "source": [ + "# 在这里将比较符号归纳如下表:\n", + "\"\"\"\n", + "符号含义示例\n", + "$lt小于{'age': {'$lt': 20}}\n", + "$gt大于{'age': {'$gt': 20}}\n", + "$lte小于等于{'age': {'$lte': 20}}\n", + "$gte大于等于{'age': {'$gte': 20}}\n", + "$ne不等于{'age': {'$ne': 20}}\n", + "$in在范围内{'age': {'$in': [20, 23]}}\n", + "$nin不在范围内{'age': {'$nin': [20, 23]}}\n", + "\"\"\"\n", + "\n", + "results = collection.find({'age': {'$gt': 20}})\n", + "# 在这里查询的条件键值已经不是单纯的数字了,而是一个字典,其键名为比较符号$gt,意思是大于,键值为20,这样便可以查询出所有\n", + "# 年龄大于20的数据。\n", + "\n", + "print(results)\n", + "for result in results:\n", + " print(result)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "{'_id': ObjectId('5c2f2b900cf63e2e08407598'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2f4e0cf63e27d42a9f9c'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n", + "{'_id': ObjectId('5c2f2f530cf63e27d42a9f9e'), 'id': '20170202', 'name': 'Mike', 'age': 21, 'gender': 'male'}\n" + ] + } + ], + "source": [ + "# 另外还可以进行正则匹配查询,例如查询名字以M开头的学生数据,示例如下:\n", + " \n", + "results = collection.find({'name': {'$regex': '^M.*'}})\n", + "# 在这里使用了$regex来指定正则匹配,^M.*代表以M开头的正则表达式,这样就可以查询所有符合该正则的结果。\n", + " \n", + "# 在这里将一些功能符号再归类如下:\n", + "\"\"\"\n", + "符号含义示例示例含义\n", + "$regex匹配正则{'name': {'$regex': '^M.*'}}name以M开头\n", + "$exists属性是否存在{'name': {'$exists': True}}name属性存在\n", + "$type类型判断{'age': {'$type': 'int'}}age的类型为int\n", + "$mod数字模操作{'age': {'$mod': [5, 0]}}年龄模5余0\n", + "$text文本查询{'$text': {'$search': 'Mike'}}text类型的属性中包含Mike字符串\n", + "$where高级条件查询{'$where': 'obj.fans_count == obj.follows_count'}自身粉丝数等于关注数\n", + "\"\"\"\n", + "# 这些操作的更详细用法在可以在MongoDB官方文档找到:\n", + "# https://docs.mongodb.com/manual/reference/operator/query/\n", + "\n", + "print(results)\n", + "for result in results:\n", + " print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.5计数" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n", + "9\n" + ] + } + ], + "source": [ + "# 要统计查询结果有多少条数据,可以调用count()方法,如统计所有数据条数:\n", + "# 要统计查询结果有多少条数据,可以调用count()方法,如统计所有数据条数:\n", + " \n", + "count = collection.count_documents({})\n", + "print(count)\n", + "# 或者统计符合某个条件的数据:\n", + " \n", + "count = collection.count_documents({'age': 20})\n", + "print(count)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.6排序" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Mike', 'Mike', 'Mike']\n" + ] + } + ], + "source": [ + "# 可以调用sort方法,传入排序的字段及升降序标志即可,示例如下:\n", + " \n", + "results = collection.find().sort('name', pymongo.ASCENDING)\n", + "print([result['name'] for result in results])\n", + "# 运行结果:\n", + " \n", + "# ['Harden', 'Jordan', 'Kevin', 'Mark', 'Mike']" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Jordan', 'Mike', 'Mike', 'Mike']\n", + "['Jordan', 'Jordan']\n" + ] + } + ], + "source": [ + "# 偏移,可能想只取某几个元素,在这里可以利用skip()方法偏移几个位置,比如偏移2,就忽略前2个元素,得到第三个及以后的元素。\n", + " \n", + "results = collection.find().sort('name', pymongo.ASCENDING).skip(2)\n", + "print([result['name'] for result in results])\n", + "# 运行结果:\n", + "# ['Kevin', 'Mark', 'Mike']\n", + "# 另外还可以用limit()方法指定要取的结果个数,示例如下:\n", + " \n", + "results = collection.find().sort('name', pymongo.ASCENDING).skip(2).limit(2)\n", + "print([result['name'] for result in results])\n", + "# 运行结果:\n", + "# ['Kevin', 'Mark']\n", + "# 如果不加limit()原本会返回三个结果,加了限制之后,会截取2个结果返回。\n", + " \n", + "# 值得注意的是,在数据库数量非常庞大的时候,如千万、亿级别,最好不要使用大的偏移量来查询数据,很可能会导致内存溢出,\n", + "# 可以使用类似find({'_id': {'$gt': ObjectId('593278c815c2602678bb2b8d')}}) 这样的方法来查询,记录好上次查询的_id" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.7更新" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'_id': ObjectId('5c2f2b900cf63e2e08407598'), 'id': '20170202', 'name': 'Mike', 'age': 28, 'gender': 'male'}\n", + "\n", + "\n", + "1 1\n", + "\n", + "1 1\n", + "\n", + "3 3\n" + ] + } + ], + "source": [ + "# 对于数据更新可以使用update()方法,指定更新的条件和更新后的数据即可,例如:\n", + "\n", + "condition = {'id': '20170202'}\n", + "student = collection.find_one(condition)\n", + "print(student)\n", + "student['age'] = 25\n", + "result = collection.update_one(condition, {'$set':student})\n", + "print(result)\n", + "\n", + "# 在这里我们将name为Kevin的数据的年龄进行更新,首先指定查询条件,然后将数据查询出来,修改年龄,\n", + "# 之后调用update方法将原条件和修改后的数据传入,即可完成数据的更新。\n", + " \n", + "# 运行结果:\n", + " \n", + "# {'ok': 1, 'nModified': 1, 'n': 1, 'updatedExisting': True}\n", + "# 返回结果是字典形式,ok即代表执行成功,nModified代表影响的数据条数。\n", + " \n", + "# 另外update()方法其实也是官方不推荐使用的方法,在这里也分了update_one()方法和update_many()方法,用法更加严格,\n", + "# 第二个参数需要使用$类型操作符作为字典的键名,我们用示例感受一下。\n", + "\n", + "condition = {'name': 'Mike'}\n", + "student = collection.find_one(condition)\n", + "student['age'] = 26\n", + "result = collection.update_one(condition, {'$set': student})\n", + "print(result)\n", + "print(result.matched_count, result.modified_count)\n", + "# 在这里调用了update_one方法,第二个参数不能再直接传入修改后的字典,而是需要使用{'$set': student}这样的形式,\n", + "# 其返回结果是UpdateResult类型,然后调用matched_count和modified_count属性分别可以获得匹配的数据条数和影响的数据条数。\n", + " \n", + "# 运行结果:\n", + "#\n", + "# \n", + "# 1 0\n", + "# 我们再看一个例子:\n", + " \n", + "condition = {'age': {'$gt': 20}}\n", + "result = collection.update_one(condition, {'$inc': {'age': 1}})\n", + "print(result)\n", + "print(result.matched_count, result.modified_count)\n", + "# 在这里我们指定查询条件为年龄大于20,然后更新条件为{'$inc': {'age': 1}},执行之后会讲第一条符合条件的数据年龄加1。\n", + " \n", + "# 运行结果:\n", + "#\n", + "# \n", + "# 1 1\n", + "# 可以看到匹配条数为1条,影响条数也为1条。\n", + " \n", + "# 如果调用update_many()方法,则会将所有符合条件的数据都更新,示例如下:\n", + " \n", + "condition = {'age': {'$gt': 20}}\n", + "result = collection.update_many(condition, {'$inc': {'age': 1}})\n", + "print(result)\n", + "print(result.matched_count, result.modified_count)\n", + "# 这时候匹配条数就不再为1条了,运行结果如下:\n", + "#\n", + "# \n", + "# 3 3\n", + "# 可以看到这时所有匹配到的数据都会被更新。" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 删除\n", + "# 删除操作比较简单,直接调用remove()方法指定删除的条件即可,符合条件的所有数据均会被删除,示例如下:\n", + " \n", + "result = collection.remove({'name': 'Kevin'})\n", + "print(result)\n", + "# 运行结果:\n", + "#\n", + "# {'ok': 1, 'n': 1}\n", + "# 另外依然存在两个新的推荐方法,delete_one()和delete_many()方法,示例如下:\n", + " \n", + "result = collection.delete_one({'name': 'Kevin'})\n", + "print(result)\n", + "print(result.deleted_count)\n", + "result = collection.delete_many({'age': {'$lt': 25}})\n", + "print(result.deleted_count)\n", + "# 运行结果:\n", + " \n", + "# \n", + "# 1\n", + "# 4\n", + "# delete_one()即删除第一条符合条件的数据,delete_many()即删除所有符合条件的数据,返回结果是DeleteResult类型,\n", + "# 可以调用deleted_count属性获取删除的数据条数。\n", + " \n", + "# 更多\n", + "# 另外PyMongo还提供了一些组合方法,如find_one_and_delete()、find_one_and_replace()、find_one_and_update(),\n", + "# 就是查找后删除、替换、更新操作,用法与上述方法基本一致。\n", + " \n", + "# 另外还可以对索引进行操作,如create_index()、create_indexes()、drop_index()等。\n", + " \n", + "# 详细用法可以参见官方文档:http://api.mongodb.com/python/current/api/pymongo/collection.html\n", + " \n", + "# 另外还有对数据库、集合本身以及其他的一些操作,在这不再一一讲解,可以参见\n", + "# 官方文档:http://api.mongodb.com/python/current/api/pymongo/" + ] + } + ], + "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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/09-IO-programming/Sql/index.ipynb b/09-IO-programming/Sql/index.ipynb new file mode 100644 index 0000000..fe9de69 --- /dev/null +++ b/09-IO-programming/Sql/index.ipynb @@ -0,0 +1,36 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 数据库读写操作\n", + "\n", + "\n", + "## 目录:\n", + "- [MongoDB数据库操作](./MongoDB数据库读写操作.ipynb)" + ] + } + ], + "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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/11-PythonThird-partyLibraries/01-ScientificComputing/Numpy/Numpy\346\225\260\346\215\256\346\240\207\345\207\206\345\214\226.ipynb" "b/11-PythonThird-partyLibraries/01-ScientificComputing/Numpy/Numpy\346\225\260\346\215\256\346\240\207\345\207\206\345\214\226.ipynb" new file mode 100644 index 0000000..6e39f1b --- /dev/null +++ "b/11-PythonThird-partyLibraries/01-ScientificComputing/Numpy/Numpy\346\225\260\346\215\256\346\240\207\345\207\206\345\214\226.ipynb" @@ -0,0 +1,129 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# numpy.std() 计算矩阵标准差" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "a = np.array([[1, 2], [3, 4]])" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "计算全局标准差: 1.118033988749895\n", + "axis=0计算每一列的标准差: [1. 1.]\n", + "计算每一行的标准差: [0.5 0.5]\n" + ] + } + ], + "source": [ + "# 计算全局标准差\n", + "print(\"计算全局标准差: \", np.std(a))\n", + "\n", + "\n", + "# axis=0计算每一列的标准差\n", + "print(\"axis=0计算每一列的标准差: \", np.std(a, axis=0))\n", + "\n", + "# 计算每一行的标准差\n", + "print(\"计算每一行的标准差: \", np.std(a, axis=1))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 利用广播机制标准化Numpy矩阵" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "a = np.array([[1, 2], [3, 4]])" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(array([[-1.34164079, -0.4472136 ],\n", + " [ 0.4472136 , 1.34164079]]), (2, 2))" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = (a - a.mean())/a.std()\n", + "b, b.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(array([[0. , 0.33333333],\n", + " [0.66666667, 1. ]]), (2, 2))" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = (a - a.min())/(a.max() - a.min())\n", + "b, b.shape" + ] + } + ], + "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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/11-PythonThird-partyLibraries/03-DataVisualization/Matplotlib/webapp.png b/11-PythonThird-partyLibraries/03-DataVisualization/Matplotlib/webapp.png new file mode 100644 index 0000000..c7753ba Binary files /dev/null and b/11-PythonThird-partyLibraries/03-DataVisualization/Matplotlib/webapp.png differ diff --git a/11-PythonThird-partyLibraries/03-DataVisualization/Matplotlib/webapp_demo_sgskip.ipynb b/11-PythonThird-partyLibraries/03-DataVisualization/Matplotlib/webapp_demo_sgskip.ipynb new file mode 100644 index 0000000..f642aca --- /dev/null +++ b/11-PythonThird-partyLibraries/03-DataVisualization/Matplotlib/webapp_demo_sgskip.ipynb @@ -0,0 +1,108 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# Webapp Demo\n", + "\n", + "\n", + "This example shows how to use the agg backend directly to create\n", + "images, which may be of use to web application developers who want\n", + "full control over their code without using the pyplot interface to\n", + "manage figures, figure closing etc.\n", + "\n", + "

Note

It is not necessary to avoid using the pyplot interface in order to\n", + " create figures without a graphical front-end - simply setting\n", + " the backend to \"Agg\" would be sufficient.

\n", + "\n", + "It is also worth noting that, because matplotlib can save figures to file-like\n", + "object, matplotlib can also be used inside a cgi-script *without* needing to\n", + "write a figure to disk.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib.backends.backend_agg import FigureCanvasAgg\n", + "from matplotlib.figure import Figure\n", + "import numpy as np\n", + "\n", + "# Fixing random state for reproducibility\n", + "np.random.seed(19680801)\n", + "\n", + "\n", + "def make_fig():\n", + " \"\"\"\n", + " Make a figure and save it to \"webagg.png\".\n", + "\n", + " \"\"\"\n", + " fig = Figure()\n", + " ax = fig.add_subplot(1, 1, 1)\n", + "\n", + " ax.plot([1, 2, 3], 'ro--', markersize=12, markerfacecolor='g')\n", + "\n", + " # make a translucent scatter collection\n", + " x = np.random.rand(100)\n", + " y = np.random.rand(100)\n", + " area = np.pi * (10 * np.random.rand(100)) ** 2 # 0 to 10 point radii\n", + " c = ax.scatter(x, y, area)\n", + " c.set_alpha(0.5)\n", + "\n", + " # add some text decoration\n", + " ax.set_title('My first image')\n", + " ax.set_ylabel('Some numbers')\n", + " ax.set_xticks((.2, .4, .6, .8))\n", + " labels = ax.set_xticklabels(('Bill', 'Fred', 'Ted', 'Ed'))\n", + "\n", + " # To set object properties, you can either iterate over the\n", + " # objects manually, or define you own set command, as in setapi\n", + " # above.\n", + " for label in labels:\n", + " label.set_rotation(45)\n", + " label.set_fontsize(12)\n", + "\n", + " FigureCanvasAgg(fig).print_png('webapp.png', dpi=150)\n", + "\n", + "\n", + "make_fig()" + ] + } + ], + "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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/11-PythonThird-partyLibraries/05-Cython/index.ipynb b/11-PythonThird-partyLibraries/05-Cython/index.ipynb index c67b209..da2e0e7 100644 --- a/11-PythonThird-partyLibraries/05-Cython/index.ipynb +++ b/11-PythonThird-partyLibraries/05-Cython/index.ipynb @@ -2,10 +2,28 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: Cython in d:\\anaconda3\\lib\\site-packages (0.28.5)\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "You are using pip version 18.1, however version 19.0.3 is available.\n", + "You should consider upgrading via the 'python -m pip install --upgrade pip' command.\n" + ] + } + ], + "source": [ + "!pip install Cython" + ] } ], "metadata": { diff --git "a/11-PythonThird-partyLibraries/05-Cython/\346\236\204\345\273\272Cython\344\273\243\347\240\201.ipynb" "b/11-PythonThird-partyLibraries/05-Cython/\346\236\204\345\273\272Cython\344\273\243\347\240\201.ipynb" new file mode 100644 index 0000000..971fd62 --- /dev/null +++ "b/11-PythonThird-partyLibraries/05-Cython/\346\236\204\345\273\272Cython\344\273\243\347\240\201.ipynb" @@ -0,0 +1,514 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext Cython" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "45\n" + ] + } + ], + "source": [ + "%%cython\n", + "\n", + "cdef int a = 0\n", + "for i in range(10):\n", + " a += i\n", + "print(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "您可以通过传递——annotate选项来显示Cython的代码分析:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "45\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + " \n", + " Cython: _cython_magic_d0a8accb6e69d1923a756ceb3bafbb84.pyx\n", + " \n", + "\n", + "\n", + "

Generated by Cython 0.28.5

\n", + "

\n", + " Yellow lines hint at Python interaction.
\n", + " Click on a line that starts with a \"+\" to see the C code that Cython generated for it.\n", + "

\n", + "
+1: cdef int a = 0
\n", + "
  __pyx_v_46_cython_magic_d0a8accb6e69d1923a756ceb3bafbb84_a = 0;\n",
+       "
+2: for i in range(10):
\n", + "
  for (__pyx_t_1 = 0; __pyx_t_1 < 10; __pyx_t_1+=1) {\n",
+       "    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error)\n",
+       "    __Pyx_GOTREF(__pyx_t_2);\n",
+       "    if (PyDict_SetItem(__pyx_d, __pyx_n_s_i, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error)\n",
+       "    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;\n",
+       "
+3:     a += i
\n", + "
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_46_cython_magic_d0a8accb6e69d1923a756ceb3bafbb84_a); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error)\n",
+       "    __Pyx_GOTREF(__pyx_t_2);\n",
+       "    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3, __pyx_L1_error)\n",
+       "    __Pyx_GOTREF(__pyx_t_3);\n",
+       "    __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3, __pyx_L1_error)\n",
+       "    __Pyx_GOTREF(__pyx_t_4);\n",
+       "    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;\n",
+       "    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;\n",
+       "    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3, __pyx_L1_error)\n",
+       "    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;\n",
+       "    __pyx_v_46_cython_magic_d0a8accb6e69d1923a756ceb3bafbb84_a = __pyx_t_5;\n",
+       "  }\n",
+       "
+4: print(a)
\n", + "
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_46_cython_magic_d0a8accb6e69d1923a756ceb3bafbb84_a); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4, __pyx_L1_error)\n",
+       "  __Pyx_GOTREF(__pyx_t_4);\n",
+       "  __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error)\n",
+       "  __Pyx_GOTREF(__pyx_t_3);\n",
+       "  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;\n",
+       "  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;\n",
+       "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%cython --annotate\n", + "cdef int a = 0\n", + "for i in range(10):\n", + " a += i\n", + "print(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "%%cython\n", + "from cpython cimport array\n", + "import array\n", + "\n", + "cdef array.array a = array.array('i', [1, 2, 3])\n", + "cdef int[:] ca = a\n", + "\n", + "cdef int overhead(object a):\n", + " cdef int[:] ca = a\n", + " return ca[0]\n", + "\n", + "cdef int no_overhead(int[:] ca):\n", + " return ca[0]\n", + "\n", + "print(overhead(a)) # new memory view will be constructed, overhead\n", + "print(no_overhead(ca)) # ca is already a memory view, so no overhead" + ] + } + ], + "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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/README.md b/README.md index 8de9ae4..38c5b27 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -# test # Python 学习笔记 [查看笔记](http://nbviewer.jupyter.org/github/ZhengHui-Z/PythonNoteForZZH/blob/master/index.ipynb) diff --git a/index.ipynb b/index.ipynb index 50ae2ce..431bffb 100644 --- a/index.ipynb +++ b/index.ipynb @@ -12,7 +12,9 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", @@ -60,14 +62,14 @@ " - [第五节:迭代器](04-PythonAdvancedFeatures/迭代器.ipynb)\n", " \n", "- 第五章 面向对象高级编程\n", - " - [创建和使用类](05-PythonObject-oriented/创建和使用类.ipynb)\n", - " - [访问属性](05-PythonObject-oriented/访问属性.ipynb)\n", - " - [Python内置类属性](05-PythonObject-oriented/Python内置类属性.ipynb)\n", - " - [继承](05-PythonObject-oriented/继承.ipynb)\n", - " - [垃圾回收](05-PythonObject-oriented/垃圾回收.ipynb)\n", - " - [方法重写和运算符重载](05-PythonObject-oriented/方法重写和运算符重载.ipynb)\n", - " - [导入类](05-PythonObject-oriented/导入类.ipynb)\n", - " - [类编码风格](05-PythonObject-oriented/类编码风格.ipynb)\n", + " - [创建和使用类](05-PythonObject/创建和使用类.ipynb)\n", + " - [访问属性](05-PythonObject/访问属性.ipynb)\n", + " - [Python内置类属性](05-PythonObject/Python内置类属性.ipynb)\n", + " - [继承](05-PythonObject/继承.ipynb)\n", + " - [垃圾回收](05-PythonObject/垃圾回收.ipynb)\n", + " - [方法重写和运算符重载](05-PythonObject/方法重写和运算符重载.ipynb)\n", + " - [导入类](05-PythonObject/导入类.ipynb)\n", + " - [类编码风格](05-PythonObject/类编码风格.ipynb)\n", " \n", "- 第六章 函数式编程\n", " - [第一节:高阶函数](06-PythonFunctionalProgramming/高阶函数.ipynb)\n", @@ -80,9 +82,11 @@ " - []()\n", " - []()\n", "- 第八章 网络相关\n", + " - [网络通讯socket]()\n", "\n", "- 第九章 IO编程\n", " - [文件读写](09-IO-programming/文件读写.ipynb)\n", + " - [数据库读写操作](09-IO-programming/Sql/index.ipynb)\n", " - [StringIO和BytesIO](09-IO-programming/StringIO和BytesIO.ipynb)\n", " - [序列化](09-IO-programming/序列化.ipynb)\n", " - [异步IO](09-IO-programming/异步IO.ipynb)\n", @@ -121,7 +125,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.7.1" } }, "nbformat": 4,