This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person(object): | |
| def __init__(self, name): | |
| self.name = name | |
| def say(self,stuff): | |
| return self.name + ' says:' + stuff | |
| def __str__(self): | |
| return self.name | |
| class Lecture(Person): | |
| def lecture(self, stuff): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import yaml | |
| MONSTER = """ | |
| --- !Monster | |
| name: Cave spider | |
| hp: [2,6] # 2d6 | |
| ac: 16 | |
| attacks: [BITE, HURT] | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import yaml | |
| class Monster(yaml.YAMLObject): | |
| yaml_tag = u'!Monster' | |
| def __init__(self, name, hp, ac, attacks): | |
| self.name = name | |
| self.hp = hp | |
| self.ac = ac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # coding: utf-8 | |
| import re | |
| import os | |
| import json | |
| from datetime import datetime | |
| import requests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv | |
| import pickle | |
| files = ['a.pickle', 'b.pickle', ...] | |
| csv.register_dialect('mycsv', 'excel', delimiter=',') | |
| for fil in files: | |
| csv_name = "%s.csv" % fil.split('.')[0] | |
| pf = open(fil, 'rb') | |
| cf = open(csv_name, 'wb') | |
| csvwriter = csv.writer(cf, dialect='mycsv') | |
| csvwriter.writerows(pickle.load(pf)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # !/usr/bin/env python | |
| # coding:UTF-8 | |
| import re | |
| import json | |
| from datetime import datetime | |
| import requests | |
| requests.packages.urllib3.disable_warnings() | |
| html = requests.get('https://www.hch.gov.tw/hch/Information/LatestNewsDetail.aspx?MNO=C025&ID=9791', verify=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # !/usr/bin/env ptyhon | |
| # coding:UTF-8 | |
| import requests, json, re | |
| from datetime import datetime | |
| html = requests.get('http://www.tyh.com.tw/ERActive/ERBMEIMS.aspx') | |
| keys = ['pending_doctor', 'pending_bed', 'pending_ward', 'pending_icu'] | |
| pending = re.findall('".+">(.+?)</span>', html.text) | |
| values = [int(ele) for ele in pending[1:5]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def try_else(x, y): | |
| a = lambda x, y: x % y | |
| b = lambda x, y: x / y | |
| try: | |
| result = a(x,y) + b(x,y) | |
| f = open('Cookie', 'w+') | |
| except ZeroDivisionError as z: | |
| print(z) | |
| # divide by zero. | |
| except PermissionError as p: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def rm_dict(dicts, keyword, recursive=True): | |
| """ remove a keyword(k-v pair) from (nest) dict. default is recursived. | |
| :param: dicts - an dict (nested allow). | |
| :param: keyword - an tuple with 2 values, means (key, value). | |
| :param: recursive - recursive search, default is True. | |
| ... admonition : doctest string below. | |
| pretty a as: | |
| a = \ | |
| { | |
| 'name':'adam', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def bi_exp_tree(expstr): | |
| """ infix to postfix. | |
| >>> bi_exp_tree("(a+(b*c))") | |
| 'abc*+' | |
| >>> bi_exp_tree("((a+b)*(z+x))") | |
| 'ab+zx+*' | |
| >>> bi_exp_tree("((a+t)*((b+(a+c))^(c+d)))") | |
| 'at+bac++cd+^*' | |
| """ | |
| result = "" |