在这篇文章中,我们将为您详细介绍Python3:AttributeError:“模块”对象在终端中使用urllib时没有属性“__path__”的内容,并且讨论关于在python终端中运行选定内容的相
在这篇文章中,我们将为您详细介绍Python 3:AttributeError:“模块”对象在终端中使用urllib时没有属性“ __path__”的内容,并且讨论关于在python终端中运行选定内容的相关问题。此外,我们还会涉及一些关于AtributeError:“模块”对象没有属性“ plt”-Seaborn、AttributeError: 'super' 对象在 python 和 kivy 代码中没有属性 '__getattr__'、AttributeError:“列表”对象使用Selenium和Python没有属性“单击”、AttributeError:“名称空间”对象没有属性“ reportPath”的知识,以帮助您更全面地了解这个主题。
本文目录一览:- Python 3:AttributeError:“模块”对象在终端中使用urllib时没有属性“ __path__”(在python终端中运行选定内容)
- AtributeError:“模块”对象没有属性“ plt”-Seaborn
- AttributeError: 'super' 对象在 python 和 kivy 代码中没有属性 '__getattr__'
- AttributeError:“列表”对象使用Selenium和Python没有属性“单击”
- AttributeError:“名称空间”对象没有属性“ reportPath”
Python 3:AttributeError:“模块”对象在终端中使用urllib时没有属性“ __path__”(在python终端中运行选定内容)
我的代码在PyCharm中运行完美,但是在尝试在终端中打开它时出现错误消息。我的代码有什么问题,或者我在哪里出错?
import urllib.request
with urllib.request.urlopen('http://python.org/') as response:
html = response.read()
print(html)
终端输出:
λ python Desktop\url1.py
Traceback (most recent call last):
File "<frozen importlib._bootstrap>",line 2218,in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "Desktop\url1.py",line 1,in <module>
import urllib.request
File "C:\Users\Przemek\Desktop\urllib.py",in <module>
import urllib.request
ImportError: No module named 'urllib.request'; 'urllib' is not a package
AtributeError:“模块”对象没有属性“ plt”-Seaborn
我对这些库非常陌生,在绘制此图时遇到了麻烦:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import random
df5 = pd.read_csv('../../../../datos/tiempos-exacto-variando-n-m0.csv',sep=',',engine='python')
print(df5)
df5['n'] = df5['n'].apply(lambda x: x**2)
sns.jointplot(df5['n'],df5['tiempoTotal'],kind="reg")
sns.plt.show()
我得到这个输出:
n m tiempoTotal
0 1 0 2274
1 2 0 3370
2 3 0 5709
3 4 0 8959
4 5 0 13354
5 6 0 18503
6 7 0 26329
7 8 0 33859
8 9 0 41110
9 10 0 52710
10 11 0 64364
11 12 0 74142
12 13 0 81072
13 14 0 69332
14 15 0 71027
15 16 0 89721
16 17 0 85459
17 18 0 95217
18 19 0 119210
19 20 0 136888
20 21 0 131903
21 22 0 138395
22 23 0 151222
23 24 0 163542
24 25 0 177236
25 26 0 192475
26 27 0 240162
27 28 0 260701
28 29 0 235752
29 30 0 250835
.. ... .. ...
580 581 0 88306854
581 582 0 89276420
582 583 0 87457875
583 584 0 90807004
584 585 0 87790003
585 586 0 89821530
586 587 0 89486585
587 588 0 88496901
588 589 0 89090661
589 590 0 89110803
590 591 0 90397942
591 592 0 94029839
592 593 0 92749859
593 594 0 105991135
594 595 0 95383921
595 596 0 105155207
596 597 0 114193414
597 598 0 98108892
598 599 0 97888966
599 600 0 103802453
600 601 0 97249346
601 602 0 101917488
602 603 0 104943847
603 604 0 98966140
604 605 0 97924262
605 606 0 97379587
606 607 0 97518808
607 608 0 99839892
608 609 0 100046492
609 610 0 103857464
[610 rows x 3 columns]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-21-63146953b89d> in <module>()
9 df5['n'] = df5['n'].apply(lambda x: x**2)
10 sns.jointplot(df5['n'],kind="reg")
---> 11 sns.plt.show()
AttributeError: 'module' object has no attribute 'plt'
我在我这运行Jupyter Notebook
使用Python 2.7.12
。有任何想法吗?
AttributeError: 'super' 对象在 python 和 kivy 代码中没有属性 '__getattr__'
如何解决AttributeError: ''super'' 对象在 python 和 kivy 代码中没有属性 ''__getattr__''?
您好,我在使用 kivy 时遇到了这个错误。我的目的是创建我的应用程序的登录屏幕,用于检查用户输入的数据是否正确。但是这样做时,我一次又一次地收到此错误。
我的代码如下:
Python 文件:
from kivy.lang import Builder
from kivymd.app import MDApp
import MysqL.connector as ms
from kivy.properties import StringProperty,NumericProperty
from kivy.uix.screenmanager import ScreenManager,Screen
acc = NumericProperty("")
pw = StringProperty("")
class safarapp(MDApp):
def build(self):
self.theme_cls.theme_Dark''
self.theme_cls.primary_palette = ''BlueGray''
return
def Login(self):
self.acc = self.root.ids.acc_num.text
self.pw = self.root.ids.password.text
host = ms.connect(
host="localhost",user="root",password="bhawarth20",database="safar"
)
cur = host.cursor(buffered = True)
cur.execute("Select * from data where Account_Number = %s and Password = %s collate utf8mb4_bin",(self.acc,self.pw))
data="error" #initially just assign the value
for i in cur:
data=i #if cursor has no data then loop will not run and value of data will be ''error''
if data== "error":
print("User Does not exist")
else:
print("User exist")
class LoginScreen(Screen):
pass
class SignUpScreen(Screen):
pass
sm = ScreenManager()
sm.add_widget(LoginScreen(name= "login"))
sm.add_widget(SignUpScreen(name= "signup"))
if __name__ == ''__main__'':
safarapp().run()
KV 文件:
ScreenManager:
LoginScreen:
SignUpScreen:
<LoginScreen>:
name: ''login''
MDCard:
size_hint: None,None
size: 300,400
pos_hint: {''center_x'': .5,''center_y'': .5}
elevation:10
spacing: 25
padding: 25
orientation: ''vertical''
MDLabel:
text: "Safar Login"
font_size: 40
halign: ''center''
size_hint_y: None
height: self.texture_size[1]
padding_y: 10
pos_hint: {''center_y'': 1}
MDTextField:
id: acc_num
hint_text: ''Account Number''
icon_right: ''account''
max_text_length: 6
size_hint_x: None
pos_hint: {''center_x'': .5}
width: 200
font_size: 18
required: True
MDTextField:
id: password
hint_text: ''Password''
password: True
size_hint_x: None
pos_hint: {''center_x'': .5}
width: 200
font_size: 18
icon_right: ''eye''
required: True
MDFillRoundFlatButton:
id: Login
text: ''Login''
size_hint_x: None
pos_hint: {''center_x'': .5}
width: 200
elevation: 10
on_release: app.Login()
MDFillRoundFlatButton:
id: Sign_Up
text: ''Sign Up''
size_hint_x: None
pos_hint: {''center_x'': .5}
width: 200
elevation: 10
on_release: root.manager.current = ''signup''
<SignUpScreen>:
name: ''signup''
MDLabel:
text: "Hello World!!!"
这是我得到的错误:
[INFO ] [Logger ] Record log in C:\Users\Welcome\.kivy\logs\kivy_21-07-12_51.txt
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO ] [Kivy ] v2.0.0
[INFO ] [Kivy ] Installed at "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\__init
py"
[INFO ] [Python ] v3.8.2 (tags/v3.8.2:7b3ab59,Feb 25 2020,22:45:29) [MSC v.1916 32 bit (Intel)]
[INFO ] [Python ] Interpreter at "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\python.exe"
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [KivyMD ] 0.104.2,git-bc7d1f5,2021-06-06 (installed at "C:\Users\Welcome\AppData\Local\Programs\Python\python3
2\lib\site-packages\kivymd\__init__.py")
[INFO ] [Image ] Providers: img_tex,img_dds,img_sdl2,img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [Window ] Activate GLES2/ANGLE context
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] Backend used <angle_sdl2>
[INFO ] [GL ] OpenGL version <b''OpenGL ES 2.0.0 (ANGLE 2.1.13739 git hash: 385fb40fd460)''>
[INFO ] [GL ] OpenGL vendor <b''Google Inc.''>
[INFO ] [GL ] OpenGL renderer <b''ANGLE (Mobile Intel(R) 965 Express Chipset Family Direct3D11 vs_4_0 ps_4_0)''>
[INFO ] [GL ] OpenGL parsed version: 2,0
[INFO ] [GL ] Shading version <b''OpenGL ES GLSL ES 1.00 (ANGLE 2.1.13739 git hash: 385fb40fd460)''>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed,single mode,not docked
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Start application main loop
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "kivy\properties.pyx",line 861,in kivy.properties.ObservableDict.__getattr__
KeyError: ''acc_num''
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "D:\my projects of python\Safar\safar.py",line 69,in <module>
safarapp().run()
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\app.py",line 950,in run
runTouchApp()
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\base.py",line 582,in runTouchApp
EventLoop.mainloop()
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\base.py",line 347,in mainloop
self.idle()
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\base.py",line 391,in idle
self.dispatch_input()
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\base.py",line 342,in dispatch_inpu
post_dispatch_input(*pop(0))
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\base.py",line 308,in post_dispatch
put
wid.dispatch(''on_touch_up'',me)
File "kivy\_event.pyx",line 709,in kivy._event.Eventdispatcher.dispatch
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivymd\uix\behaviors\ripple_behavior.py",ne 296,in on_touch_up
return super().on_touch_up(touch)
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivymd\uix\button.py",line 981,in on_to
_up
return super().on_touch_up(touch)
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\uix\behaviors\button.py",line 179,on_touch_up
self.dispatch(''on_release'')
File "kivy\_event.pyx",line 705,in kivy._event.Eventdispatcher.dispatch
File "kivy\_event.pyx",line 1248,in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx",line 1132,in kivy._event.EventObservers._dispatch
File "C:\Users\Welcome\AppData\Local\Programs\Python\python38-32\lib\site-packages\kivy\lang\builder.py",line 57,in custom
llback
exec(__kvlang__.co_value,idmap)
File "D:\my projects of python\Safar\safar.kv",line 56,in <module>
on_release: app.Login()
File "D:\my projects of python\Safar\safar.py",line 27,in Login
self.acc = self.root.ids.acc_num.text
File "kivy\properties.pyx",line 864,in kivy.properties.ObservableDict.__getattr__
AttributeError: ''super'' object has no attribute ''__getattr__''
请帮助我尽快解决此错误。任何帮助将不胜感激。
解决方法
您的代码:
self.acc = self.root.ids.acc_num.text
self.pw = self.root.ids.password.text
正在尝试访问不在 ids
root
字典中的 ids
。这些 ids
在 <LoginScreen>:
规则中定义,因此它们出现在 LoginScreen
实例中。将这两行替换为:
login_screen = self.root.get_screen(''login'')
self.acc = login_screen.ids.acc_num.text
self.pw = login_screen.ids.password.text
AttributeError:“列表”对象使用Selenium和Python没有属性“单击”
我想在默认设置为“季度”的页面上单击“年度”按钮。有两个基本上相同的链接,除了一个链接,data-ptype="Annual"
所以我试图复制xpath来单击按钮(也尝试了其他选项,但没有一个起作用)。
但是,我得到了AttributeError: ''list'' object has no attribute''click''
。我读了很多类似的文章,但无法解决我的问题..因此,我认为必须调用/单击/执行javascript事件以某种方式不同。
from selenium import webdriverlink = ''https://www.investing.com/equities/apple-computer-inc-balance-sheet''driver = webdriver.Firefox()driver.get(link)elm = driver.find_elements_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]").click()
html如下:
<ahref="javascript:void(0);" data-type="rf-type-button" data-ptype="Annual" data-pid="6408" data-rtype="BAL">..</a>
答案1
小编典典我仍然建议您通过 XPATH* 使用 linkText 。原因xpath:是绝对的,如果 从HTML中 添加 或
删除了 另一个div ,则可能失败。而更改链接文本的机会很小。/html/body/div[5]/section/div[8]/div[1]/a[1]
*****
因此,代替此 代码 :
elm = driver.find_elements_by_xpath("/html/body/div[5]/section/div[8]/div[1]/a[1]").click()
试试这个代码:
annual_link = driver.find_element_by_link_text(''Annual'')annual_link.click()
是的@Druta是正确的,find_element
用于一个Web元素和Web元素find_elements
列表。拥有总是很好explicitwait
。
创建显式等待的实例,如下所示:
wait = WebDriverWait(driver,20)
并使用如下的等待引用:
wait.until(EC.elementToBeClickable(By.LINK_TEXT, ''Annual''))
更新:
from selenium import webdriverlink = ''https://www.investing.com/equities/apple-computer-inc-balance-sheet''driver = webdriver.Firefox()driver.maximize_window()wait = WebDriverWait(driver,40)driver.get(link)driver.execute_script("window.scrollTo(0, 200)")wait.until(EC.element_to_be_clickable((By.LINK_TEXT, ''Annual'')))annual_link = driver.find_element_by_link_text(''Annual'')annual_link.click()print(annual_link.text)
确保导入这些:
from selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as EC
AttributeError:“名称空间”对象没有属性“ reportPath”
如何解决AttributeError:“名称空间”对象没有属性“ reportPath”?
我不断得到:AttributeError:“名称空间”对象没有属性“ reportPath”
我不明白为什么,我什至无法遵循此代码,因为我一直在法医书中使用此预先编写的代码。
def WalkPath():
processCount = 0
errorCount = 0
oCVS = _CSVWriter(gl_args.reportPath + ''fileSystemReport.csv'',gl_hashType)
# Create a loop that process all the files starting at the rootPath,# all sub-directories will also be processed
log.info(''Root Path: '' + gl_args.rootPath)
for root,dirs,files in os.walk(gl_args.rootPath):
# for each file obtain the filename and call the HashFile Functionfor file in files:
fname = os.path.join(root,file)
result = HashFile(fname,file,oCVS)
# if hashing was successful,then increment the ProcessCount
if result is True:
processCount += 1
# if not successful,the increment the ErrorCount
else:
errorCount += 1
oCVS.writerClose()
return(processCount)
在此处定义reportPath:
def ParseCommandLine(): parser = argparse.ArgumentParser(“ Python文件系统哈希... p-fish”) parser.add_argument(''-v'',''-verbose'',help =''允许显示进度消息'',action =''store_true'')
# setup a group where the selection is mutually exclusive and required
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(''--md5'',help=''specifies MD5 algorithm'',action=''store_true'')
group.add_argument(''--sha256'',help=''specifies SHA256 algorithm'',action=''store_true'')
group.add_argument(''--sha512'',help=''specifies SHA512 algorithm'',action=''store_true'')
parser.add_argument(''--d'',''--rootPath'',type=ValidateDirectory,required=True,help=''specify the root path for hashing'')
parser.add_argument(''--r'',''--reportPath'',type=ValidateDirectoryWritable,help=''specify the path for reports and logs will be written'')
# creates a global object to hold the validated arguments,these will be available
# to all the functions within the _pfish.py module
global gl_args
global gl_hashType
gl_args = parser.parse_args()
if gl_args.md5:
gl_hashType = "MD5"
elif gl_args.sha256:
gl_hashType = "SHA256"
elif gl_args.sha512:
gl_hashType = "SHA512"
else:
gl_hashType = "UnkNown"
logging.error("UnkNown Hash Type Specified")
displayMessage("Command line processed: Successfully")
return
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
我们今天的关于Python 3:AttributeError:“模块”对象在终端中使用urllib时没有属性“ __path__”和在python终端中运行选定内容的分享已经告一段落,感谢您的关注,如果您想了解更多关于AtributeError:“模块”对象没有属性“ plt”-Seaborn、AttributeError: 'super' 对象在 python 和 kivy 代码中没有属性 '__getattr__'、AttributeError:“列表”对象使用Selenium和Python没有属性“单击”、AttributeError:“名称空间”对象没有属性“ reportPath”的相关信息,请在本站查询。
本文标签: