開始使用 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
| if (argc < 2) | |
| { | |
| // Launch normally. | |
| return; | |
| } | |
| NSString *path = [NSString stringWithUTF8String:argv[1]]; | |
| path = [path stringByStandardizingPath]; // You should do this, BTW. | |
| if ([[NSFileManager defaultManager] fileExistsAtPath:path]) | |
| { | |
| // Open the file. |
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
| @echo off | |
| setlocal | |
| set /p PYTHONEXE="Drag and drop python.exe here, and press ENTER: " | |
| for %%d in (%PYTHONEXE%) do set PYTHONROOT=%%~dpd | |
| :: Strip trailing backslash. | |
| set PYTHONROOT=%PYTHONROOT:~0,-1% |
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
| \\[ | |
| 1*2*3 multi-line math | |
| \\] | |
| \\( 1*2*3 inline-math \\) | |
| $$ 1*2*3 math with dollar $$ | |
| $$ 1*2*3 \$ \\ \text{dollar with escapes} $$ |
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 os | |
| import sys | |
| import io | |
| import tarfile | |
| import urllib.request | |
| ARCHIVE_URL = 'http://d.pr/f/YqS5+' |
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
| # ↓↓↓ Scroll to bottom for an example. ↓↓↓ | |
| import importlib | |
| import pkgutil | |
| def pythonize(qt_package): | |
| proxy = _PackageProxy(qt_package) | |
| return proxy |
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
| ' Requirements: | |
| ' * Windows 7 or later. (Might work on Vista; XP is definitely out.) | |
| ' * Python 3 installation. (Will prompt for installation path.) | |
| ' The installation path should be both readable and *writable*. | |
| Set fs = CreateObject("Scripting.FileSystemObject") | |
| Set shell = CreateObject("WScript.Shell") | |
| home = shell.ExpandEnvironmentStrings("%HOMEPATH%") |
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 toga | |
| f_input = toga.TextInput() | |
| c_input = toga.TextInput(readonly=True) | |
| c_label = toga.Label('Celcius', alignment=toga.LEFT_ALIGNED) | |
| f_label = toga.Label('Fahrenheit', alignment=toga.LEFT_ALIGNED) | |
| join_label = toga.Label('is equivalent to', alignment=toga.RIGHT_ALIGNED) |
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
| ' Requirements: | |
| ' * Windows 7 or later. (Might work on Vista and XP.) | |
| ' * Python 3 installation. (Will prompt for installation path.) | |
| ' The installation path should be both readable and *writable*. | |
| ' * msysGit installation. | |
| Function GetPath(ByVal prompt) | |
| ' Collect path. | |
| path = InputBox(prompt) |
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 functools | |
| class Api: | |
| def __init__(self): | |
| self.apis = [] | |
| def register(self, f): | |
| self.apis.append(f.__name__) |