MomentumDash (교육용으로 만 사용)에서 일부 이미지를 다운로드하려고합니다. 나는 다음 파이썬 코드를 작성했습니다 :다운로드 한 이미지가 항상 배경으로 설정되지 않습니까?
import urllib
import os
import random
#Chooses an image between 1 to 14
choice=random.randint(01,14)
print choice
#Downloads images
a=urllib.urlretrieve("https://momentumdash.com/backgrounds/"+"%02d" % (choice,)+".jpg", str(choice)+".jpg")
print a #Tells the image
#Getting the location of the saved image
cwd = os.getcwd()
random=random.choice(os.listdir(cwd))
file =cwd+ '\\' +random
#Making the image to desktop image
import ctypes
SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER , 0, file, 3)
것은이 이미지를 설정하려면이 progrm의 확률 1/7 틱입니다.
대부분의 경우 검은 색 배경 화면을 제공합니다.
어디서 잘못 되었나요?
'os.listdir()'은 주어진 디렉토리에있는 모든 파일의 목록을 제공합니다 - 작업 디렉토리에 다운로드하는 이미지 이외의 파일이 있습니까? (힌트 :이 python 스크립트) – asongtoruin
먼저 'random'에 다른 변수 이름을 쓰면 라이브러리 이름을 덮어 쓰게됩니다. 둘째,'os.listdir (cwd)'에 대해 얻은 것을 출력하십시오. 일부 항목은 적절한 이미지 파일이 아닙니다. –