開始使用 Pyhton 之前,首先要確定電腦上能不能執行 Pyhton 程式。本教學將需要 Python 3.4 或更高的版本,因此請確認電腦上是否有對應版本。若不確定電腦上是否已經安裝 Python,建議直接按照以下步驟設定,以保證教學中的程式皆能夠正常執行。由於各作業系統安裝流程不同,以下請按照作業系統,選擇自己需要的部份閱讀。
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
| # Copy from http://www.scipy.org/getting-started.html | |
| import argparse | |
| import numpy as np | |
| from scipy import special, optimize | |
| import matplotlib.pyplot as plt | |
| def main(): | |
| # Parse command-line arguments | |
| parser = argparse.ArgumentParser(usage=__doc__) |
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
| """ | |
| Output all plim to the folder | |
| e.g. | |
| python plimcd.py ./templates ../mako | |
| """ | |
| import sys | |
| import os.path | |
| import subprocess | |
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
| ________________ TestAssetSpecs.test_asset_spec_no_static_view _________________ | |
| self = <pyramid_webassets.tests.test_webassets.TestAssetSpecs testMethod=test_asset_spec_no_static_view> | |
| def test_asset_spec_no_static_view(self): | |
| from webassets import Bundle | |
| self.create_files({ | |
| 'dotted/__init__.py': '', | |
| 'dotted/package/__init__.py': '', |
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
| """ | |
| Usage: | |
| 1. Enter your plim templates folder | |
| cd app/templates | |
| 2. Run this Python script | |
| python bulk_compile_plims.py | |
| 3. Check it out | |
| tree __plim_output | |
| """ | |
| from pathlib import Path |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
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 time | |
| import concurrent.futures | |
| import rx | |
| num_stream = [1, 2, 3, 4, 5] | |
| def heavy_work(data): | |
| time.sleep(1) | |
| return data |
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 alog | |
| from threading import Thread | |
| from multiprocessing import Process | |
| def make_log(x): | |
| def logging(): | |
| for i in range(5): | |
| alog.info("loging {}:{}".format(x, i)) | |
| return logging |
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 logging | |
| logging.basicConfig(level=logging.INFO) | |
| import alog | |
| from threading import Thread | |
| from multiprocessing import Process | |
| def make_log(name, x): | |
| def logging(): | |
| for i in range(5): |
這邊用 Miniconda,選擇 Python 3.5 Windows 64-bit。
安裝 Anaconda 一樣沒有問題,兩個裡面是一樣的, 只是 Anaconda 預設下載了很多常用套件。
開一個 Command Prompt (Win+R -> cmd + [Enter]) 輸入 conda