我正在使用
os.system('powershell.exe "Invoke-WebRequest -Uri Link')
如果您可以將鏈接設定為我已經定義的變數,我會很高興。我的整個代碼看起來像這樣
import os
link=input("What link do you want? ")
os.system('powershell.exe "Invoke-WebRequest -Uri link')
但我不知道如何(如果可能的話)將變數放在那里?
uj5u.com熱心網友回復:
您可以簡單地定義一個變數來保存您要運行的整個字串。
input_var = str(input("Write -> "))
basic_command = "'powershell.exe " '"Invoke-WebRequest -Uri '
full_command = basic_command input_var '"' "'"
os.system(full_command)
在 input_var 中,我們將輸入轉換為字串。在基本命令中,我們設定了您要運行的命令的第一部分。在 full_command 中,我們添加 input_var,然后用正確的 " ' 關閉整行。然后我們使用完整的命令列運行 os system。
我希望這可以幫助你。我在很多腳本中使用這個概念
uj5u.com熱心網友回復:
在 Python 中使用格式化字串的解決方案
import os
link = input("What link do you want? ")
os.system('powershell.exe "Invoke-WebRequest -Uri {link}'.format(link = link))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/406957.html
標籤:
