Так что в основном мой код запускается, но он не выполняется должным образом. Я не уверен, что я сделал не так. Вот код. Когда я ввожу что-то в оболочку, он просто игнорирует его. Как я могу это исправить? Я никогда не использовал функцию if "___name__ == '_main_':
раньше, поэтому бы почему?Код Python запускается, но не выполняется
import os.path
import os
import shutil
def search_files(direct):
directory=os.path.join(direct)
directory1=os.path.exists(directory)
if directory1:
return directory
else:
print ('ERROR')
direct = input()
def search_characteristics(direct):
interesting = input()
space = interesting.count(' ')
list1 = []
list2 = []
list3 = []
directory = os.path.join(direct)
files = nested_dir(directory)
directory1=os.path.exists(directory)
keyword = interesting[space + 1:len(interesting) + 1]
if interesting[0] == 'N':
for item in files:
if item[item.rfind('\\')+1:item.rfind('.')] == interesting[space+1:len(interesting)+1]:
list3.append(tem)
return list3
elif interesting[0] == 'E' :
for item in files:
if item[item.rfind('.')+1:len(item)+ 1] == ((interesting[space:len(interesting)+1]).strip('')).strip('.'):
list2.append(item)
return list2
elif interesting[0] == 'S' :
for item in files:
if int(keyword) <os.path.getsize(item):
list1.append(item)
return list1
else:
print('ERROR')
def directory_files(nested_directory) -> list:
file_list = []
for element in os.listdirectory(nested_directory):
path = os.path.join(nested_directory,element)
if os.path.isdir(path):
file_list.extend(nested_directory(path))
else:
file_list.append(path)
return file_list
def path(interesting_files):
for files in interesting_files:
print(files)
def read_file(interesting_files):
for files in interesting_files:
infile=file
open_file=open(infile)
for line in open_file.readlines():
print(line)
open_file.close()
def duplicate(interesting_files):
for files in interesting_files:
shutil.copy(files,files+'.dup')
def modify(interesting_files):
for files in interesting_files:
os.utime(files,(1330712280, 1330712292))
if __name__ == '_main_':
while True:
file_input = input("Enter file name")
if file_input.lower() == 'p':
path(operation)
elif file_input.lower() == 'f':
read_file(operation)
elif file_input.lower() == 'd':
duplicate(operation)
elif file_input.lower() == 't':
modify(operation)
else:
print('ERROR')
direct = input()
search_files(direct)
operation = search_characteristics(direct)
print(operation)
operations(operation)
У вас в то время True loop как первое, что работает, и он никогда не выходит из этого цикла –
Ваш код будет работать так, как я полагаю, вы застряли в строке 'file_input = input()', он ждет ввода , Если вы 'file_input = input (« Введите имя файла »), это может помочь. Также вы должны определить функции, прежде чем вы их назовете, 'если __name __ ==" __ main __ "' обычно будет идти в конце вашего скрипта. –
@PadraicCunnningham И продолжает искать входные данные. Это была моя точка –