Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试替换字符串中的字符并为其分配新变量,然后将其用作参数时出错_Python_Typeerror - Fatal编程技术网

Python 尝试替换字符串中的字符并为其分配新变量,然后将其用作参数时出错

Python 尝试替换字符串中的字符并为其分配新变量,然后将其用作参数时出错,python,typeerror,Python,Typeerror,当尝试替换字符串中的字符并为其分配新的字符时,有人可以帮助我修复此错误吗 变量,然后将其用作参数并获得以下错误: 总的来说, ping(域) TypeError:“str”对象不可调用 from selenium import webdriver from selenium.webdriver.common.keys import Keys import platform import subprocess class pingStats: packets = ''

当尝试替换字符串中的字符并为其分配新的字符时,有人可以帮助我修复此错误吗 变量,然后将其用作参数并获得以下错误: 总的来说, ping(域) TypeError:“str”对象不可调用

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import platform    
import subprocess  






class pingStats:
packets = ''



def Main():
    url = input("Enter url: ")
    urlArray = [url]
    path = 'C://Users//me//Downloads//ChromeDriver88//chromedriver.exe'
    bot1 = webdriver.Chrome(executable_path=path)
    bot1.get(url)


    pack_user = pingStats
    ping = input('')
    packetsUser = input('')
    pack_user.packets = packetsUser
    if ping == 'ping':
       #where the error is happening i think
       domain = url.replace('https://', '')
       ping(domain)
       #where the error is happening i think
    else:
    print('no command named ' + ping)



def ping(host):
packets = pingStats

param = '-n' if platform.system().lower()=='windows' else '-c'


command = ['ping', param, pingStats.packets, host]

return subprocess.call(command) == 0



if __name__ == '__main__':
    Main()

问题在于对不同的对象使用相同的名称
ping

ping
这里表示由
input()
返回的
str
对象:

您还定义了一个名为
ping()
的函数:

直接的解决方法是更改为
input()
定义的对象的名称

例如,使用:

userInput = input('')
并在所有位置使用
userInput
,而不是:

ping = input('')

始终以完全回溯的方式发布整个错误消息。
userInput = input('')
ping = input('')