Pythonスクリプト(work.py)と記述し、Windowsで正常に動作していますが、Ubuntuで実行すると、名前を-として入力するとエラーが表示されますstringですが、名前をintegerと入力すると問題なく動作します。
NameError:
thanapong@thanapong-Lenovo-C360:~/Desktop$ python work.py
Hours: 72
Minutes: 0
Seconds: 0
Enter the name: CHATCHAI
Traceback (most recent call last):
File "work.py", line 9, in <module>
look for = str(input("Enter the name: "))
File "<string>", line 1, in <module>
NameError: name 'CHATCHAI' is not defined
thanapong@thanapong-Lenovo-C360:~/Desktop$ python work.py
Hours: 72
Minutes: 0
Seconds: 0
Enter the name: BILLY
Traceback (most recent call last):
File "work.py", line 9, in <module>
look for = input("Enter the name: ")
File "<string>", line 1, in <module>
NameError: name 'BILLY' is not defined
Intで正常に動作します。
thanapong@thanapong-Lenovo-C360:~/Desktop$ python work.py
Hours: 72
Minutes: 0
Seconds: 0
Enter the name: 2
3
0
Not found
1
2
3
4
0
Not found
1
2
3
4
0
Not found
1
2
これは私のコードです。
import pandas as pd
import time
hourz=input('Hours: ')
minz=input('Minutes: ')
secz=input('Seconds: ')
lookfor = input("Enter the name: ")
name = str(lookfor)
x = 5
print(' ')
hour=int(hourz)
min=int(minz)
sec=int(secz)
day = int(((hour*60*60)+(min*60)+(sec))/86400)
print(day)
for b in range(day):
for a in range(x):
time.sleep(1)
print(a)
if a == 0:
data = pd.read_csv("/media/thanapong/F91B-8B18/Customer_List.txt", header=0)
query = data.loc[data['NAME']==name]
if not query.empty:
print(query)
data.loc[data['NAME']==name, 'SCORE'] = (query.SCORE - 1)
print()
print(data.loc[data['NAME']==name])
data.to_csv("/media/thanapong/F91B-8B18/Customer_List.txt", index=None)
else:
print('Not found')
print(' ')
print(' ')
print("End")
これはCustomer_List.txtの例です(多くの行があります)。
ID,NAME,LASTNAME,SCORE,TEL,PASS
61070500216,CHATCHAI,KARUNA,22,123456789,12345
61070500217,BIGM,KORATBOY,15,123456789,123456789
私はあなたのコードを実行し、それは正しく実行されました。画像と同じエラーを作成できませんでした。コードは、名前フィールドの入力として文字列を受け入れました。 Pythonバージョン3.7およびオペレーティングシステムUbuntu。以下の出力を参照してください:
Hours: 72
Minutes: 0
Seconds: 0
Enter the name: BILLY
3
0
ID NAME LASTNAME SCORE ... KORATBOY 15 123456789.1 123456789.2
0 NaN BILLY NaN NaN ... NaN NaN NaN NaN
[1 rows x 16 columns]
ID NAME LASTNAME SCORE ... KORATBOY 15 123456789.1 123456789.2
0 NaN BILLY NaN NaN ... NaN NaN NaN NaN
[1 rows x 16 columns]
1
2
3
4
0
ID NAME LASTNAME SCORE ... KORATBOY 15 123456789.1 123456789.2
0 NaN BILLY NaN NaN ... NaN NaN NaN NaN
[1 rows x 16 columns]
ID NAME LASTNAME SCORE ... KORATBOY 15 123456789.1 123456789.2
0 NaN BILLY NaN NaN ... NaN NaN NaN NaN
[1 rows x 16 columns]
1
2
3
4
0
ID NAME LASTNAME SCORE ... KORATBOY 15 123456789.1 123456789.2
0 NaN BILLY NaN NaN ... NaN NaN NaN NaN
[1 rows x 16 columns]
ID NAME LASTNAME SCORE ... KORATBOY 15 123456789.1 123456789.2
0 NaN BILLY NaN NaN ... NaN NaN NaN NaN
[1 rows x 16 columns]
1
2
3
4
End
Process finished with exit code 0
私は解決策はあなたがpython3
コマンドプロンプトで[〜#〜] not [〜#〜]python
を使用してファイルを実行します。あなたのコードは明確にpython3
システムにpython3がインストールされていない場合は、ターミナルで次のコマンドを実行してインストールできます。
Sudo apt install python3