DigiHouse
English

TECH ARTICLE · 6 MIN READ

Blog / DigiHouse

W1|Codespaces 雲端開發與首支 Python 程式

W1 第二、三小時實作:從 GitHub Codespaces 啟動、Python 執行到第一個可追蹤的 Git commit。

本週完成成果

完成本週後,你能從 GitHub 開啟課程 Codespace、確認 Python 與 Git 可用、執行第一支程式,並以一個可追蹤的 commit 將 week01_hello.py 推回自己的 Repo。

完成標準:終端機顯示指定的三行輸出;git status 在 commit 後顯示 working tree clean;GitHub Repo 可以看到本週 commit。

課前準備

步驟 1|GitHub 網頁:登入教師指定的 GitHub 帳號,確認你已接受課程 Template/Classroom 邀請。不要共用他人的帳號。

步驟 2|GitHub 網頁:進入自己的課程 Repo,確認 Repo 名稱與擁有者正確。若看不到 Code 按鈕或 Codespaces 分頁,先停止並截圖回報。

步驟 3|GitHub 網頁:按 Code → Codespaces → Create codespace。第一次建立可能需要數分鐘;看到 VS Code 網頁版與終端機後再繼續。

第二、三小時|課堂教材與個人技術實作

步驟 1|Codespaces 終端機:確認目前目錄、Python 與 Git。三個指令都成功後再建立檔案。

bash
pwd
python --version
git --version

預期結果:pwd 位於你的 Repo;Python 與 Git 都顯示版本號。實際小版本可能不同,不要為了和截圖相同而自行降版。

步驟 2|Codespaces 編輯器:開啟 week01_hello.py,輸入以下程式並儲存。name 請填課堂使用的暱稱,不要放學號、電話或其他個資。

python
course = 'GS3073-B AI 人工智慧導論'
week = 1
name = '你的暱稱'

print(f'Course: {course}')
print(f'Week: W{week}')
print(f'Hello, {name}! Codespaces is ready.')

步驟 3|Codespaces 終端機:執行程式。

bash
python week01_hello.py

預期結果:依序看到 Course、Week: W1 與 Hello 三行;若出現 SyntaxError,先比對引號、括號與每一行的拼字。

步驟 4|Codespaces 終端機:檢查變更,只應看到本週允許的檔案。

bash
git status --short
git diff -- week01_hello.py

課堂後半段|教師示範 Git 的 working tree、staging area 與 commit 三個狀態;學生用 git status 與 git diff 說明自己改了什麼,但此段的重點是理解版本紀錄,不是搶先完成課後作業。

指定閱讀與課後作業

指定閱讀|依課綱完成 Python Introduction、Syntax 與 Comments 練習;閱讀是回家複習,不計入第二、三小時課堂操作時間。

步驟 1|個人 GitHub 作業:確認 week01_hello.py 能獨立執行,且姓名欄只使用課堂暱稱。

步驟 2|Codespaces 終端機:只加入本週檔案,建立清楚的 commit 並推送至自己的 GitHub Repo。

bash
git add week01_hello.py
git commit -m 'W1: complete Codespaces Python hello'
git push

步驟 3|GitHub 網頁:重新整理 Repo,開啟 commit history,確認最新紀錄由自己的帳號建立且包含 week01_hello.py。

驗收方式

bash
python week01_hello.py
git status --short
git log -1 --oneline

通過條件:Python 結束碼為 0;git status --short 沒有輸出;最新 commit 訊息以 W1: 開頭。三項缺一都先修正再提交。

應提交的 Repo 檔案

必交:week01_hello.py。Commit 證據:最新 commit URL。不得提交 .env、API key、Codespaces token、終端機完整歷史或含個資的截圖。

常見問題與排除

問題 1|找不到 python:先執行 python3 --version;若只有 python3 可用,回報教師,避免每位同學自行修改環境。

問題 2|git commit 要求姓名與信箱:在 GitHub 帳號設定確認 commit email;課堂 Repo 建議使用 GitHub 提供的 noreply email。

問題 3|git push 被拒絕:先執行 git status 與 git branch --show-current,確認你在自己的 Repo/分支;不要使用 force push。

問題 4|Codespace 開不起來:在 github.com/codespaces 檢查是否已有建立中或可恢復的 Codespace,不要連續建立多個造成額度浪費。

引用資料

國立中央大學授課課綱/劉書銘老師,《劉書銘老師課程大綱_基礎模型與生成式人工智慧-更新版.pdf》;教師提供附件。用途:W1–W16 時段、實作主題、評量與交付物。

GitHub Docs,《Setting up a Python project for GitHub Codespaces》;https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/setting-up-your-python-project-for-codespaces;查閱日期:2026-08-04。用途:Codespaces 開啟方式、Python 專案與 Dev Container 流程。

Git project,《gittutorial》;https://git-scm.com/docs/gittutorial;查閱日期:2026-08-04。用途:status、add、commit 與版本紀錄基本流程。

Python Software Foundation,《An Informal Introduction to Python》;https://docs.python.org/3/tutorial/introduction.html;查閱日期:2026-08-04。用途:Python 註解、字串、變數與 print 基礎。