ben bu şekilde benim kod çalıştırmasına:Bu "NoneType" hatası neden bir bölünme gerçekleştirilirken ortaya çıkıyor?
What number? 4
1 (write) or 2? 2
İlk bu basılır: Daha sonra aşağıdaki hata ortaya çıkar
['', '1233', '8989', '5\n']
None
:
Traceback (most recent call last):
File "/Users/Documents/explab.py", line 16, in <module>
split_2 = split_2.remove(split[3])
AttributeError: 'NoneType' object has no attribute 'remove'
benim anlayacakları bir split_2
itibaren Bir NoneType yerine bir liste olmalı, bu doğru mu? Kodun nasıl düzeltileceğini bilen biri, istediği gibi çalışır.
number = input("What number? ")
choice = input("1 (write) or 2? ")
if choice == "1":
with open("r_3exp","a") as file_1:
file_1.write (' \n')
file_1.write ('Here are some numbers : 1233 8989' + ' ' + number)
elif choice == "2":
with open("r_3exp","r") as file_1:
for line in file_1:
split_1 = line.split (":")
if len(split_1[1]) < 500:
split_2 = split_1[1].split(' ')
print (split_2)
split_2 = split_2.insert(0, number)
print (split_2)
split_2 = split_2.remove(split[3])
print (split_2)
Gerçek kodunuzu gönderebilir misiniz? – Torxed
'split [3]', tanımladığınız bir değişken değil –
http://stackoverflow.com/questions/9983254/python-list-functions-not-returning-new-lists –