🔥

Claude Codeに似ているOpenHands CLIが出たので触ってみた

に公開

はじめに

OpenHandsからClaude CodeのようにCLIで動作するOpenHands CLIがリリースされました。

https://www.all-hands.dev/blog/the-openhands-cli-ai-powered-development-in-your-terminal

今回は早速触ってみた感触などをお伝えできればと思います。

OpenHandsCLIとは

https://x.com/allhands_ai/status/1934990437627936949

OpenHandsはこれまでDocker環境とGUIが必須だったが、もっと手軽に使えるようになりたいというユーザの声を元に開発されたとのことです。
MITライセンスで完全にオープンソースとして提供されているといった特徴があります。
また公式のSNSでも言及されていますがClaude Codeに似ています。

similar to Claude Code

公式ドキュメントはこちら

https://docs.all-hands.dev/usage/how-to/cli-mode#cli

触ってみた

準備編

python3.12 or 3.13が動作する環境で

$ pip install openhands-ai

もしくはuvxを用いて
$ uvx --python 3.12 --from openhands-ai openhands

でopenhandsをインストールします。
私はローカル環境にて動作させることを躊躇ったため,Docker環境を用意してインストールしました。

$ openhands

で起動します。
その後、anthropicを使いますか?モデルは何を使いますか?

などの質問に回答していき最後にAPIキーを設定すればOKです。
ここまでのプロセスで迷うところは特にありませんでした。

     ___                    _   _                 _
    /  _ \ _ __   ___ _ __ | | | | __ _ _ __   __| |___
    | | | | '_ \ / _ \ '_ \| |_| |/ _` | '_ \ / _` / __|
    | |_| | |_) |  __/ | | |  _  | (_| | | | | (_| \__ \
    \___ /| .__/ \___|_| |_|_| |_|\__,_|_| |_|\__,_|___/
          |_|

OpenHands CLI v0.44.0

Initialized conversation 7936085b-****-****-****-************

Let's start building!

What do you want to build? Type /help for help

>

/help コマンドをとりあえず実行

/helpの結果
> /help

OpenHands CLI v0.44.0
OpenHands CLI lets you interact with the OpenHands agent from the command line.

Things that you can try:
 Ask questions about the codebase > How does main.py work?
 Edit files or add new features > Add a new function to ...
 Find and fix issues > Fix the type error in ...

Some tips to get the most out of OpenHands:
 Be as specific as possible about the desired outcome or the problem to be solved.
 Provide context, including relevant file paths and line numbers if available.
 Break large tasks into smaller, manageable prompts.
 Include relevant error messages or logs.
 Specify the programming language or framework, if not obvious.

Interactive commands:
/exit - Exit the application
/help - Display available commands
/init - Initialize a new repository
/status - Display conversation details and usage metrics
/new - Create a new conversation
/settings - Display and modify current settings
/resume - Resume the agent when paused

Learn more at: https://docs.all-hands.dev/usage/getting-started

日本語でも会話できるか試してみました。

> あなたは何ができますか?

Agent running... (Press Ctrl-P to pause)

こんにちは!私はOpenHandsエージェントです。コンピューターと対話してさまざまなタスクを実行できる AI アシスタントです。以下のようなことができます:

## 🛠️ **技術的なタスク**
- **プログラミング**: コードの作成、編集、デバッグ、リファクタリング
- **ファイル操作**: ファイルやディレクトリの作成、編集、管理
- **コマンド実行**: Bashコマンドの実行、スクリプトの実行
- **環境設定**: 依存関係のインストール、開発環境のセットアップ

## 💻 **開発支援**
- **バージョン管理**: Gitを使った変更管理、コミット、プルリクエスト作成
- **テスト**: テストコードの作成と実行
- **デバッグ**: 問題の特定と修正
- **コードレビュー**: コード品質の改善提案

## 🌐 **ウェブ関連**
- **ブラウザ操作**: ウェブページの閲覧、フォーム入力、クリック操作
- **API連携**: RESTful APIの呼び出しとデータ処理
- **ウェブアプリケーション**: フロントエンドとバックエンドの開発

## 📊 **データ処理**
- **Python**: データ分析、機械学習、スクリプト作成
- **ファイル処理**: CSV、JSON、XMLなどの各種ファイル形式の処理
- **データベース**: SQLクエリの作成と実行

## 🔧 **システム管理**
- **パッケージ管理**: npm、pip、aptなどを使った依存関係管理
- **設定ファイル**: 各種設定ファイルの作成と編集
- **ログ解析**: エラーログの分析と問題解決

## 📝 **ドキュメント作成**
- **技術文書**: README、API仕様書、コメントの作成
- **マークダウン**: 構造化された文書の作成

何か具体的にお手伝いできることがあれば、お気軽にお聞かせください!どのようなプロジェクトに取り組んでいらっしゃいますか?

Agent is waiting for your input...

日本語での会話も問題なくできています。
DeprecationWarningが出ている部分は割愛しています。
応答時間はClaude Codeに比較すると少し遅いなと感じました。

ただ、本当にそんなことできるの?と言う部分もあったりと...

公式のブログページでは

  • Add a new feature: add a user data validation function to user_data.py
  • Fix a bug: do RCA on the bug causing new users to be unable to login
  • Add tests: increase test coverage of the mapping service
  • Refactor code: refactor the process_user_data function to be more readable
  • Document code: document the database schema
  • Explain code: explain to me how the location service works

ができるよと言及されています。

実践編

やはり最初はhello worldを出力するプログラムを作ってもらいます。

> 「hello world!」と出力するプログラムを組んでください


「hello world!」と出力するプログラムを作成いたします。いくつかの言語で作成してみますね。

~~省略~~

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ python3 /app/hello.py
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

プログラムを作成しました!それぞれ実行してみましょう:

## Python版の実行

Proceed with action? (y)es/(n)o/(a)lways >

y / n / aで回答するインターフェースになっています。

Proceed with action? (y)es/(n)o/(a)lways > y

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ python3 /app/hello.py
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────────────────────────| Command Output |─────────────────────────────────────────────────────────────────────────────────────────────────┐
│hello world!

└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

python版は無事に実行できました。
次はjavascript版を作ったので実行するようです。

## JavaScript版の実行

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ node /app/hello.js
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────────────────────────| Command Output |─────────────────────────────────────────────────────────────────────────────────────────────────┐
│bash: line 1: node: command not found

└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Agent running... (Press Ctrl-P to pause)

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ apt update && apt install -y nodejs
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Node.jsがインストールされていないようですので、インストールしてから実行します:

Proceed with action? (y)es/(n)o/(a)lways >

当然Python以外に何も入っていない環境ですのでnodeはありません。
ちゃんとエラー内容を理解した上で次のアクションの実行許可を得ようとしています。

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ node /app/hello.js                                                                                                                                                                                                │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────────────────────────| Command Output |─────────────────────────────────────────────────────────────────────────────────────────────────┐
│hello world!                                                                                                                                                                                                        │
│                                                                                                                                                                                                                    │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

長いので割愛しましたが、C言語版、Java版のプログラムも作成してくれたようです。
Javaはjavaをインストールしたりファイル名を変更したりと試行錯誤を実施していました。
最後にマークダウン形式で結果が表示されまので興味がありましたらご覧ください。

最終の出力結果

完璧です!「hello world!」と出力するプログラムを複数の言語で作成し、すべて正常に実行できました。

📋 作成したプログラム一覧

1. Python版 (hello.py)

print("hello world!")

2. JavaScript版 (hello.js)

console.log("hello world!");

3. C言語版 (hello.c)

#include <stdio.h>

int main() {
    printf("hello world!\n");
    return 0;
}

4. Java版 (hello.java)

class Hello {
    public static void main(String[] args) {
        System.out.println("hello world!");
    }
}

実行結果

すべてのプログラムが正常に実行され、「hello world!」と出力されました:

  • Python: python3 hello.py
  • JavaScript: node hello.js
  • C言語: gcc hello.c -o hello_c && ./hello_c
  • Java: javac hello.java && java Hello

どの言語のプログラムも /app ディレクトリに保存されているので、いつでも実行できます!

まとめ

今回はOpenHands CLIがリリースされたと言うことで簡単にではありますが触ってみました。
触った感想としてはそこまで品質が悪いものではないなという印象です。
今回はAnthropicのAPIキーを設定して利用したのですが、ローカル環境に構築したローカルLLMと接続して利用することもできるようです。

ただし随所にwarningが出てくるのでまだまだ発展途上のツールだなと実感しました。
現時点では応答速度や機能面などではClaude Codeが先を行っていますが、今後どのようなスピードでアップデートが行われるのかとても楽しみなツールだなと感じました。

簡単に試せますのでぜひ皆さんも試してみてください。

Appendix

python版のプログラムをより改良してアップデートしてもらいました。
出力が長いため興味がある方のみご覧ください。

出力されるwarningなど全てそのまま載せています。

OpenHands CLIとの全文
> python版のプログラムのアップデートを進めていきましょう。
/usr/local/lib/python3.12/site-packages/httpx/_models.py:408: DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.
  headers, stream = encode_request(

Agent running... (Press Ctrl-P to pause)
/usr/local/lib/python3.12/site-packages/httpx/_models.py:408: DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.
  headers, stream = encode_request(

Python版のプログラムをアップデートしていきましょう!現在のプログラムを確認してから、どのような機能を追加したいか教えてください。

┌───────────────────────────────────────────────────────────────────────────────────────────────────| File Read |────────────────────────────────────────────────────────────────────────────────────────────────────┐
│Here's the result of running `cat -n` on /app/hello.py:                                                                                                                                                             │
│     1 print("hello world!")                                                                                                                                                                                        │
│                                                                                                                                                                                                                    │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

現在のPython版は非常にシンプルですね。以下のようなアップデートが考えられます:

## 🚀 **アップデート案**

1. **ユーザー入力対応** - 名前を入力してもらって個人的な挨拶
2. **時間帯別挨拶** - 朝・昼・夜で挨拶を変える
3. **多言語対応** - 複数の言語で挨拶
4. **カラフル出力** - 色付きテキストで表示
5. **ログ機能** - 実行履歴を記録
6. **コマンドライン引数対応** - 引数で動作を変更
7. **GUI版** - tkinterを使った簡単なGUI
8. **Web版** - Flaskを使った簡単なWebアプリ

どのような機能を追加したいですか?それとも、特定の方向性があれば教えてください!

例えば:
- 「ユーザーとの対話機能を追加したい」
- 「時間に応じた挨拶にしたい」
- 「GUI版にしたい」
- 「もっと実用的な機能を追加したい」

など、ご希望をお聞かせください。

Agent is waiting for your input...

> 1から4まで実装しましょう
/usr/local/lib/python3.12/site-packages/httpx/_models.py:408: DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.
  headers, stream = encode_request(

Agent running... (Press Ctrl-P to pause)
/usr/local/lib/python3.12/site-packages/httpx/_models.py:408: DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.
  headers, stream = encode_request(

素晴らしいですね!1から4までの機能を実装していきましょう。

┌───────────────────────────────────────────────────────────────────────────────────────────────────| File Edit |────────────────────────────────────────────────────────────────────────────────────────────────────┐
│[Existing file /app/hello.py is edited with 1 changes.]                                                                                                                                                             │
│[begin of edit 1 / 1]                                                                                                                                                                                               │
│(content before edit)                                                                                                                                                                                               │
│-1|print("hello world!")                                                                                                                                                                                            │
│(content after edit)                                                                                                                                                                                                │
│+1|import datetime                                                                                                                                                                                                  │
│+2|import colorama                                                                                                                                                                                                  │
│+3|from colorama import Fore, Back, Style                                                                                                                                                                           │
│+4|                                                                                                                                                                                                                 │
│+5|# カラー出力の初期化                                                                                                                                                                                             │
│+6|colorama.init()                                                                                                                                                                                                  │
│+7|                                                                                                                                                                                                                 │
│+8|def get_time_based_greeting():                                                                                                                                                                                   │
│+9|    """時間帯に応じた挨拶を返す"""                                                                                                                                                                               │
│+10|    current_hour = datetime.datetime.now().hour                                                                                                                                                                 │
│+11|                                                                                                                                                                                                                │
│+12|    if 5 <= current_hour < 12:                                                                                                                                                                                  │
│+13|        return "おはようございます", "Good morning", "Buenos días", "Bonjour"                                                                                                                                   │
│+14|    elif 12 <= current_hour < 18:                                                                                                                                                                               │
│+15|        return "こんにちは", "Good afternoon", "Buenas tardes", "Bon après-midi"                                                                                                                                │
│+16|    else:                                                                                                                                                                                                       │
│+17|        return "こんばんは", "Good evening", "Buenas noches", "Bonsoir"                                                                                                                                         │
│+18|                                                                                                                                                                                                                │
│+19|def get_user_name():                                                                                                                                                                                            │
│+20|    """ユーザーの名前を取得"""                                                                                                                                                                                  │
│+21|    print(f"{Fore.CYAN}🌟 多言語対応挨拶プログラム 🌟{Style.RESET_ALL}")                                                                                                                                        │
│+22|    print(f"{Fore.YELLOW}=" * 40 + Style.RESET_ALL)                                                                                                                                                             │
│+23|                                                                                                                                                                                                                │
│+24|    name = input(f"{Fore.GREEN}あなたのお名前を教えてください: {Style.RESET_ALL}")                                                                                                                              │
│+25|    return name.strip() if name.strip() else "ゲスト"                                                                                                                                                           │
│+26|                                                                                                                                                                                                                │
│+27|def display_greetings(name):                                                                                                                                                                                    │
│+28|    """多言語・時間帯別・カラフルな挨拶を表示"""                                                                                                                                                                │
│+29|    japanese, english, spanish, french = get_time_based_greeting()                                                                                                                                              │
│+30|                                                                                                                                                                                                                │
│+31|    print(f"\n{Fore.MAGENTA}{'=' * 50}{Style.RESET_ALL}")                                                                                                                                                       │
│+32|    print(f"{Fore.CYAN}🎉 {name}さんへの挨拶 🎉{Style.RESET_ALL}")                                                                                                                                              │
│+33|    print(f"{Fore.MAGENTA}{'=' * 50}{Style.RESET_ALL}")                                                                                                                                                         │
│+34|                                                                                                                                                                                                                │
│+35|    # 日本語                                                                                                                                                                                                    │
│+36|    print(f"{Fore.RED}🇯🇵 日本語: {Back.WHITE}{Fore.BLACK}{japanese}、{name}さん!{Style.RESET_ALL}")                                                                                                            │
│+37|                                                                                                                                                                                                                │
│+38|    # 英語                                                                                                                                                                                                      │
│+39|    print(f"{Fore.BLUE}🇺🇸 English: {Back.YELLOW}{Fore.BLACK}{english}, {name}!{Style.RESET_ALL}")                                                                                                               │
│+40|                                                                                                                                                                                                                │
│+41|    # スペイン語                                                                                                                                                                                                │
│+42|    print(f"{Fore.GREEN}🇪🇸 Español: {Back.RED}{Fore.WHITE}{spanish}, {name}!{Style.RESET_ALL}")                                                                                                                 │
│+43|                                                                                                                                                                                                                │
│+44|    # フランス語                                                                                                                                                                                                │
│+45|    print(f"{Fore.YELLOW}🇫🇷 Français: {Back.BLUE}{Fore.WHITE}{french}, {name}!{Style.RESET_ALL}")                                                                                                               │
│+46|                                                                                                                                                                                                                │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ pip install colorama                                                                                                                                                                                              │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

coloramaライブラリが必要なので、まずインストールしてから実行してみましょう:

Proceed with action? (y)es/(n)o/(a)lways > a
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.86s: CmdRunAction (id=122)
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.86s: CmdRunAction (id=122)
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.86s: CmdRunAction (id=122)
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.87s: CmdRunAction (id=122)
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.87s: CmdRunAction (id=122)
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.87s: CmdRunAction (id=-1)
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.87s: CmdRunAction (id=124)
10:56:38 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 60.87s: CmdRunAction (id=124)
10:56:39 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 61.36s: CmdRunAction (id=124)
10:56:39 - openhands:WARNING: agent_controller.py:877 - [Agent Controller 5aff23a6-6fff-489c-ad5b-0f769a0e5b91-4b1810415e96c3a0] Pending action active for 61.36s: CmdRunAction (id=124)
/usr/local/lib/python3.12/site-packages/httpx/_models.py:408: DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.
  headers, stream = encode_request(

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ pip install colorama                                                                                                                                                                                              │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────────────────────────| Command Output |─────────────────────────────────────────────────────────────────────────────────────────────────┐
│Collecting colorama                                                                                                                                                                                                 │
│  Downloading colorama-0.4.6-py2.py3-none-any.whl.metadata (17 kB)                                                                                                                                                  │
│Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)                                                                                                                                                             │
│Installing collected packages: colorama                                                                                                                                                                             │
│Successfully installed colorama-0.4.6                                                                                                                                                                               │
│WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual envi│
│ronment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.                                                             │
│                                                                                                                                                                                                                    │
│[notice] A new release of pip is available: 25.0.1 -> 25.1.1                                                                                                                                                        │
│[notice] To update, run: pip install --upgrade pip                                                                                                                                                                  │
│                                                                                                                                                                                                                    │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Agent running... (Press Ctrl-P to pause)

それでは、アップデートされたプログラムを実行してみましょう!

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ echo "太郎" | python3 /app/hello.py                                                                                                                                                                               │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

┌────────────────────────────────────────────────────────────────────────────────────────────────────| Command |─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│$ echo "太郎" | python3 /app/hello.py                                                                                                                                                                               │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
/usr/local/lib/python3.12/site-packages/httpx/_models.py:408: DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.
  headers, stream = encode_request(

┌─────────────────────────────────────────────────────────────────────────────────────────────────| Command Output |─────────────────────────────────────────────────────────────────────────────────────────────────┐
│🌟 多言語対応挨拶プログラム 🌟                                                                                                                                                                                      │
│========================================                                                                                                                                                                            │
│あなたのお名前を教えてください:                                                                                                                                                                                     │
│==================================================                                                                                                                                                                  │
│🎉 太郎さんへの挨拶 🎉                                                                                                                                                                                              │
│==================================================                                                                                                                                                                  │
│🇯🇵 日本語: おはようございます、太郎さん!                                                                                                                                                                           │
│🇺🇸 English: Good morning, 太郎!                                                                                                                                                                                     │
│🇪🇸 Español: Buenos días, 太郎!                                                                                                                                                                                      │
│🇫🇷 Français: Bonjour, 太郎!                                                                                                                                                                                         │
│==================================================                                                                                                                                                                  │
│📅 現在時刻: 2025年06月20日 10:56:45                                                                                                                                                                                │
│                                                                                                                                                                                                                    │
│✨ ありがとうございました!また会いましょう! ✨                                                                                                                                                                    │
│                                                                                                                                                                                                                    │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
最終の出力結果

素晴らしい!プログラムが正常に動作しています。色付きの出力も含めて、すべての機能が実装されました。

🎉 実装完了!アップデートされた機能

1. ユーザー入力対応

  • ユーザーの名前を入力してもらい、個人的な挨拶を表示
  • 名前が空の場合は「ゲスト」として扱う

2. 時間帯別挨拶

  • 朝 (5:00-11:59): おはようございます / Good morning / Buenos días / Bonjour
  • 昼 (12:00-17:59): こんにちは / Good afternoon / Buenas tardes / Bon après-midi
  • 夜 (18:00-4:59): こんばんは / Good evening / Buenas noches / Bonsoir

3. 多言語対応

  • 🇯🇵 日本語
  • 🇺🇸 英語
  • 🇪🇸 スペイン語
  • 🇫🇷 フランス語

4. カラフル出力

  • 各言語ごとに異なる色とスタイル
  • 背景色と文字色の組み合わせ
  • 絵文字と装飾線でより見やすく

🔧 追加機能

  • エラーハンドリング: Ctrl+Cでの中断や例外処理
  • 現在時刻表示: 実行時の日時を表示
  • 美しいUI: 装飾線と絵文字でユーザーフレンドリーに

実際に対話的に実行してみたい場合は、以下のコマンドで実行できます:

python3 /app/hello.py

他にも何か追加したい機能があれば、お気軽にお聞かせください!

完成したpythonコード
hello.py
import datetime
import colorama
from colorama import Fore, Back, Style

# カラー出力の初期化
colorama.init()

def get_time_based_greeting():
    """時間帯に応じた挨拶を返す"""
    current_hour = datetime.datetime.now().hour
    
    if 5 <= current_hour < 12:
        return "おはようございます", "Good morning", "Buenos días", "Bonjour"
    elif 12 <= current_hour < 18:
        return "こんにちは", "Good afternoon", "Buenas tardes", "Bon après-midi"
    else:
        return "こんばんは", "Good evening", "Buenas noches", "Bonsoir"

def get_user_name():
    """ユーザーの名前を取得"""
    print(f"{Fore.CYAN}🌟 多言語対応挨拶プログラム 🌟{Style.RESET_ALL}")
    print(f"{Fore.YELLOW}=" * 40 + Style.RESET_ALL)
    
    name = input(f"{Fore.GREEN}あなたのお名前を教えてください: {Style.RESET_ALL}")
    return name.strip() if name.strip() else "ゲスト"

def display_greetings(name):
    """多言語・時間帯別・カラフルな挨拶を表示"""
    japanese, english, spanish, french = get_time_based_greeting()
    
    print(f"\n{Fore.MAGENTA}{'=' * 50}{Style.RESET_ALL}")
    print(f"{Fore.CYAN}🎉 {name}さんへの挨拶 🎉{Style.RESET_ALL}")
    print(f"{Fore.MAGENTA}{'=' * 50}{Style.RESET_ALL}")
    
    # 日本語
    print(f"{Fore.RED}🇯🇵 日本語: {Back.WHITE}{Fore.BLACK}{japanese}{name}さん!{Style.RESET_ALL}")
    
    # 英語
    print(f"{Fore.BLUE}🇺🇸 English: {Back.YELLOW}{Fore.BLACK}{english}, {name}!{Style.RESET_ALL}")
    
    # スペイン語
    print(f"{Fore.GREEN}🇪🇸 Español: {Back.RED}{Fore.WHITE}{spanish}, {name}!{Style.RESET_ALL}")
    
    # フランス語
    print(f"{Fore.YELLOW}🇫🇷 Français: {Back.BLUE}{Fore.WHITE}{french}, {name}!{Style.RESET_ALL}")
    
    print(f"{Fore.MAGENTA}{'=' * 50}{Style.RESET_ALL}")
    
    # 現在時刻の表示
    current_time = datetime.datetime.now().strftime("%Y年%m月%d日 %H:%M:%S")
    print(f"{Fore.CYAN}📅 現在時刻: {current_time}{Style.RESET_ALL}")

def main():
    """メイン関数"""
    try:
        # ユーザー名を取得
        user_name = get_user_name()
        
        # 挨拶を表示
        display_greetings(user_name)
        
        # 終了メッセージ
        print(f"\n{Fore.GREEN}✨ ありがとうございました!また会いましょう! ✨{Style.RESET_ALL}")
        
    except KeyboardInterrupt:
        print(f"\n{Fore.RED}👋 プログラムを終了します。さようなら!{Style.RESET_ALL}")
    except Exception as e:
        print(f"{Fore.RED}❌ エラーが発生しました: {e}{Style.RESET_ALL}")

if __name__ == "__main__":
    main()

関連記事

https://zenn.dev/shirochan/articles/cf8b23a9925455

MIXI DEVELOPERS Tech Blog

Discussion