如何访问python中成员函数中指定的该类成员属性?
我正在使用Selenium从事一个Python项目,我需要访问另一个成员函数中指定值的成员属性,但我似乎无法弄清楚,尽管我知道这很容易解决,这是我的代码和我的内容到目前为止尝试了
`class User_data:
'''Get important info ab user'''
def __init__ (self, url, product_name):
self.url = url
self.product_name = product_name
def askFor_info (self):
self.url = str(input("Please enter the url of the site you wish to make purchase from: "))
self.prodcut_name = str(input("Please enter the name of the product you wish to purchase: "))
# person = User_data(url = self.url, product_name= self.product_name)
print(f"{self.url},", f"{self.prodcut_name}")
这是错误的代码
driver.get(user_data.askfor_info.url)
当我这样做时,我会发现一个错误,上面写着“ attributeError:'function' 对象没有属性“ url””
I'm working on a python project using selenium and I need to access a member attribute who's value is specified in another member function, I can't seem to figure it out although i know it's an easy fix here's my code and what I've tried so far
`class User_data:
'''Get important info ab user'''
def __init__ (self, url, product_name):
self.url = url
self.product_name = product_name
def askFor_info (self):
self.url = str(input("Please enter the url of the site you wish to make purchase from: "))
self.prodcut_name = str(input("Please enter the name of the product you wish to purchase: "))
# person = User_data(url = self.url, product_name= self.product_name)
print(f"{self.url},", f"{self.prodcut_name}")
this is the piece of code that's wrong
driver.get(User_data.askFor_info.url)
when i do this i get an error that says " AttributeError: 'function'
object has no attribute 'url'"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
askfor_info
是一种方法,self.url
是类成员,因此要访问该变量,首先您需要使用类实例化使用类askFor_info
is a method andself.url
is a class member so to access that variable, First you need to instantiate the class using