我在寫文件列表,但只寫最後一行。爲什麼我的代碼只寫最後一行?
這是我的代碼。我在Python 2.7。
server=os.listdir('.') #contents of the current directory
for files in server:
public_html = []
if os.path.isfile(files) == True :
pass
elif os.path.isdir(files) == True :
public_html.insert(0, files)
print public_html
f = open("index.html","w")
f.write("<html>\n<head>\n<meta charset='utf-8'>\n<title></title>\n<link rel='stylesheet' href='css/normalize.css'>\n<script src=''></script></head>\n<body>")
for folder in public_html:
print folder
f.write("<a>" + folder + "<a/>" + "\n")
f.close()
什麼是輸出? – slezica