質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

1016閲覧

non foundと表示される理由

Beginner_Boy

総合スコア4

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

1グッド

0クリップ

投稿2020/06/02 10:25

編集2020/06/02 15:36

前提・実現したいこと

ここに質問の内容を詳しく書いてください。
いちばんやさしいpythonの教本と言う参考書を使い辞書とファイル入出力を使ったプログラムの作成。
ターミナルでtype evaluation.txtを実装中に以下のエラーメッセージが発生しました。
参考書だと

user_name@MacBook-Pro yasashiipython % type evaluation.txt [Takanori_Suzuki] total: 269, evaluation: Excellent! [Takayuki_Shimizukiwa] total: 256, evaluation: Excellent! [Mitsuki_Sugiya] total: 231, evaluation: Good!

となるはずだったのです。
これはPythonのエラーではなく、使ってるMacの問題だそうです。

発生している問題・エラーメッセージ

user_name@MacBook-Pro yasashiipython % type evaluation.txt evaluation.txt not found

該当のソースコード

python

1ファイル名 point.txt 2Takanori_Suzuki:100,88,81 3Takayuki_Shimizukiwa:77,94,85 4Mitsuki_Sugiya:80,52,99 5 6ファイル名 05_file.py 7open_file = open('point.txt') 8raw_data = open_file.read() 9open_file.close() 10point_data = raw_data.splitlines() 11 12point_dict = {} 13for line in point_data: 14 student_name, points_str = line.split(':') 15 point_dict[student_name] = points_str 16 17score_dict = {} 18for student_name in point_dict: 19 point_list = point_dict[student_name].split(',') 20 subject_number = len(point_list) 21 total = 0 22 for point in point_list: 23 total = total + int(point) 24 average = total / subject_number 25 score_dict[student_name] = (total, average, subject_number) 26 27evaluation_dict = {} 28for student_name in score_dict: 29 score_data = score_dict[student_name] 30 total = score_data[0] 31 average = score_data[1] 32 subject_number = score_data[2] 33 34 excellent = subject_number * 100 * 0.8 35 good = subject_number * 100 * 0.65 36 if total >= excellent: 37 evaluation = 'Excellent!' 38 elif total >= good: 39 evaluation = 'Good!' 40 else: 41 evaluation = 'Bad!' 42 evaluation_dict[student_name] = evaluation 43 44file_name = 'evaluation.txt' 45output_file = open(file_name, 'w') 46for student_name in score_dict: 47 score_data = score_dict[student_name] 48 total = score_data[0] 49 50 evaluation = evaluation_dict[student_name] 51 52 text = '[{}] total: {}, evaluation: {}\n'.format(student_name, total, evaluation) 53 output_file.write(text) 54 55output_file.close() 56print('評価結果を{}に出力しました'.format(file_name)) 57 58ファイル名 evaluation.txt 59[Takanori_Suzuki] total: 269, evaluation: Excellent! 60[Takayuki_Shimizukiwa] total: 256, evaluation: Excellent! 61[Mitsuki_Sugiya] total: 231, evaluation: Good!

試したこと

print関数でevaluation.txtの原因を試したら、

File "evaluation.txt", line 1 [Takanori_Suzuki] total: 269, evaluation: Excellent! ^ SyntaxError: invalid syntax

となり変数textを見直しましたがどこが原因なのかわかりませんでした。

補足情報(FW/ツールのバージョンなど)

Python3.8.3/Atom/Kite/macOS Catalina

退会済みユーザー👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

meg_

2020/06/02 11:59

エラーメッセージは全文掲載出来ませんか?
Beginner_Boy

2020/06/02 12:09

ターミナルに表示された文をコピペしました。 これで問題ないですか?
meg_

2020/06/02 12:53

エラーとはPythonのエラーではなかったのですね? Macのことは分かりません。
Beginner_Boy

2020/06/02 13:20

これってPythonのエラーじゃなくてパソコンの問題だったんですね。 それと、typeの回答ありがとうございました。 まだ始めたばかりで完全に理解した訳でわありませんがターミナルでのtypeのなんの役割をしているのかを知ることができました。 回答ありがとうございました。
guest

回答2

0

ベストアンサー

おそらく書籍の中ではevaluation.txtの中身をコマンドプロンプトで表示させているのではないかと思われます。
質問者さんはMacを使用とのことなので「cat evaluation.txt」でevaluation.txtの中身が表示されるのではないでしょうか?

投稿2020/06/03 13:55

meg_

総合スコア10579

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Beginner_Boy

2020/06/03 14:09

回答ありがとうございます。 cat evaluation.txtで無事表示させることができました。
guest

0

typeって型を調べるに使うと思うのですが、

違いますよ。
typeは、シェルが実行できるコマンドが、PATHのどこにあるかを示すコマンドです。

$ type open
open is /usr/bin/open

$ type echo
echo is a shell builtin

$ type ls
ls is an alias for ls -AF --color=auto

$ type python
python is /Users/ユーザ名/.pyenv/shims/python

みたいな結果が返ってきます。

投稿2020/06/02 12:23

編集2020/06/02 12:24
technocore

総合スコア7200

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問