나는 사용자가 선택하는가,이 폴더에서 그들에게 파일을 표시 폴더로파이썬에서 나열된 항목에 변수를 할당하는 방법은 무엇입니까?
이동을 수행 할 작업을
나는이
싶습니다 할 싶습니다 방법 사용자에게 포함 된 파일 및 폴더의 목록을 표시 한 다음 사용자가 파일 및 폴더를 선택할 수 있도록 허용합니다.
나는이 시도했습니다
코드 : items
이후
#!/usr/bin/env python
import os, sys, glob
os.chdir(glob.glob("/var/mobile/TP/")[0])
print("Please select a Texture Pack (##):")
items = os.listdir(".")
i = 1
for item in items:
print("[%.2d] %s" % (i, item))
i += 1
#And then something that will assign the variables to the listed items, like
*firstlisteditem*=a ; *secondlisteditem*=b #... and so on
#and then i need to get the user to tell me which folder he wants to go to. This I will do using a number.
se=raw_input()
if "1" in se then
exec /var/mobile/TP/$a
if "2" in se then
exec /var/mobile/TP/$b
이 컨텍스트에서 'a' 및'b'는 무엇입니까? 그리고 * listing item *에 의해'items' 요소 나 인쇄중인 값을 의미합니까? 'for' 루프를 세는 것은 나쁜 습관 일뿐만 아니라 ['enumerate()'] (http://docs.python.org/3.3/library/functions.html#enumerate)를 사용하는 것도 중요합니다. –
'for i, enumerate (items)의 항목 :'대신 i = 1, i + = 1; print 문을 i에서 i + 1로 변경하십시오. – tMJ