2017-09-17 2 views
0

입니다. 저는 python을 사용하여 sth를 검색하려고합니다. 여기 내 코드 :open()은 1에서 3까지의 위치 인수를 취하지 만 5는

if request.get().strip() in inte: #that's just to understand my script 
subprocess.Popen(['C:\Program Files\Internet Explorer\\iexplore.exe']) 
else: 
     webbrowser.open("https://www.google.it/search?q=",request.get().strip(),"&oq=",request.get().strip(),"&aqs=chrome..69i57j0j69i61j0l3.1306j0j7&sourceid=chrome&ie=UTF-8") 

요청 =하면 textVariable는 엔트리 위젯에서 얻었다.

API와 같은 다른 방법을 이해하지 못해서 작동하지 않습니다. 감사합니다.

답변

0

오류가 분명하다 : 당신은 당신의 open 방법 (5 개) 인수를 전달하고 있습니다 :

webbrowser.open("https://www.google.it/search?q=",request.get().strip(),"&oq=",request.get().strip(),"&aqs=chrome..69i57j0j69i61j0l3.1306j0j7&sourceid=chrome&ie=UTF-8") 

당신은 제대로이 같은 주장을 계속 str.format 또는 (너무 많이 입력하지 않고 게으른 방법)을 사용하여 포맷 할 수 있지만 당신이 두 번 같은 인수를 사용하고 있기 때문에, 말했다

webbrowser.open("".join(("https://www.google.it/search?q=",request.get().strip(),"&oq=",request.get().strip(),"&aqs=chrome..69i57j0j69i61j0l3.1306j0j7&sourceid=chrome&ie=UTF-8"))) 

, str.format이 선호하는 방법입니다 :

,691,363 단지 tuple에 내장 된 문자열 가입210
webbrowser.open("https://www.google.it/search?q={0}&oq={0}&aqs=chrome..69i57j0j69i61j0l3.1306j0j7&sourceid=chrome&ie=UTF-8".format(request.get().strip())) 
관련 문제