스크립트는 사용자 입력을 받아들이고 특정 형식으로 폴더의 모든 내용을 인쇄합니다. 예 : Folder1 (주 폴더) -> Folder2 -> Folder3 -> Folder4. 내용Python - 디렉토리의 특정 폴더에 대한 사용자 입력 후 디렉토리의 모든 내용 인쇄
내용 하위 폴더를 포함 할 수 있습니다 :
디렉토리 형식 니모닉 와 니모닉 (폴더 1)가 포함되어 있습니다.
이 오류를 던지고 내가 여기있다 : ValueError를 너무 많은 값을 풀고 (2, 예상 도착 일)이 줄
"os.listdir에서 single_mnemonic, 내용 (startpath)에 대한 : (: 내용 즉, 니모닉)
당신은 시도 할 수 : "당신은 당신의 폴더에있는 모든 파일 이름이 특정 경우
def search_specific_mnemonic(startpath):
user_entered_mnemonic = input("Enter Client Mnemonic: ")
facility_types = ["clinic", "hospital", "lab", "hub_millennium", "client_millennium"]
for single_mnemonic, contents in os.listdir(startpath):
CRED = "\033[91m"
CEND = "\033[0m"
print(CRED + "\n",user_entered_mnemonic + CEND)
for facility_type in facility_types:
if contents[facility_type]:
box_display_char = "X"
else:
box_display_char = "_"
print(" [{0}] - {1}".format(box_display_char, facility_type.replace("_", " ").title()))
if contents[facility_type]:
for practice_name in sorted(contents[facility_type]):
print(" {}".format(practice_name))
for practice_scripts in sorted(contents[facility_type]):
print(" {}".format(contents[facility_type][practice_name]))
break
PM2Ring @ 내가 업데이트 스크립트를 사용하고 parse_directory를 꺼내 었습니다. 다음은 오류입니다. Valueerror이 줄에서 압축을 풀 수있는 값이 너무 많습니다 (예상 2, 가져 오기 1). "single_mnemonic, os.listdir (startpath)의 내용 :" – FFF
아, 알았습니다. : oops : 더 자세히 살펴보면 코드의 여러 요소를 이해하지 못합니다. 'os.listdir (startpath)'는'startpath'에있는 파일/폴더 이름 목록을 반환합니다. 보통'fname in os.listdir (startpath) :'와 같이 문자열을 반복 할 것입니다. 그렇다면 왜 '싱글 _ 니모닉, 내용'이 있습니까? 나중에 코드에서 '내용'을 사전처럼 취급하는 것으로 보입니다. –
@ PM2Ring 솔직히 모르겠지만, 파이썬에 대해서는 새로운 것입니다. 만약 내가 처음부터 다시 시작할 필요가 있는지 궁금하다. – FFF