在本文中,我们将带你了解AttributeError:'模块'对象没有属性'setdefaultencoding'在这篇文章中,我们将为您详细介绍AttributeError:'模块'对象没有属性's
在本文中,我们将带你了解AttributeError:'模块'对象没有属性'setdefaultencoding'在这篇文章中,我们将为您详细介绍AttributeError:'模块'对象没有属性'setdefaultencoding'的方方面面,并解答对象模块不存在常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的AtributeError:“模块”对象没有属性“ plt”-Seaborn、AttributeError: 'ADC' 对象没有属性 'atten'、AttributeError: 'tuple' 对象没有属性 'set_author' discord.py、AttributeError: module ''sys'' has no attribute ''setdefaultencoding''。
本文目录一览:- AttributeError:'模块'对象没有属性'setdefaultencoding'(对象模块不存在)
- AtributeError:“模块”对象没有属性“ plt”-Seaborn
- AttributeError: 'ADC' 对象没有属性 'atten'
- AttributeError: 'tuple' 对象没有属性 'set_author' discord.py
- AttributeError: module ''sys'' has no attribute ''setdefaultencoding''
AttributeError:'模块'对象没有属性'setdefaultencoding'(对象模块不存在)
我尝试安装xadmin(这是django的插件,用于将backoffice与twitter的引导程序一起使用)。但是当我运行项目时,我的PyCharm终端出现以下错误:
File "C:\Python34\lib\site-packages\xadmin\sites.py", line 10, in <module>sys.setdefaultencoding("utf-8")AttributeError: ''module'' object has no attribute ''setdefaultencoding''
这是xadmin插件中sites.py的源代码摘录:
import sysfrom functools import update_wrapperfrom django.conf import settingsfrom django.core.exceptions import ImproperlyConfiguredfrom django.db.models.base import ModelBasefrom django.views.decorators.cache import never_cachefrom imp import reloadreload(sys)sys.setdefaultencoding("utf-8")
该项目使用python 3.4解释器和Django 1.7.1运行。xadmin的版本是0.5.0
我能做什么 ?
答案1
小编典典Python 3没有sys.setdefaultencoding()
功能。不能reload(sys)
像在Python
2上那样恢复它(在任何情况下都不应该这样做)。
由于Python 3的默认设置 已经 是UTF-8 ,因此保留这些语句毫无意义。
在Python
2中,使用sys.setdefaultencoding()
来解决隐式编码问题(由连接字节字符串和unicode值以及其他此类混合类型的情况引起),而不是解决问题本身。Python
3取消了隐式编码和解码,因此使用石膏设置不同的编码将毫无区别。
但是,如果这是一个第三方库,那么您可能会遇到其他问题,因为它显然尚未与Python 3兼容。
AtributeError:“模块”对象没有属性“ plt”-Seaborn
我对这些库非常陌生,在绘制此图时遇到了麻烦:
import pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltimport numpy as npimport randomdf5 = 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 tiempoTotal0 1 0 22741 2 0 33702 3 0 57093 4 0 89594 5 0 133545 6 0 185036 7 0 263297 8 0 338598 9 0 411109 10 0 5271010 11 0 6436411 12 0 7414212 13 0 8107213 14 0 6933214 15 0 7102715 16 0 8972116 17 0 8545917 18 0 9521718 19 0 11921019 20 0 13688820 21 0 13190321 22 0 13839522 23 0 15122223 24 0 16354224 25 0 17723625 26 0 19247526 27 0 24016227 28 0 26070128 29 0 23575229 30 0 250835.. ... .. ...580 581 0 88306854581 582 0 89276420582 583 0 87457875583 584 0 90807004584 585 0 87790003585 586 0 89821530586 587 0 89486585587 588 0 88496901588 589 0 89090661589 590 0 89110803590 591 0 90397942591 592 0 94029839592 593 0 92749859593 594 0 105991135594 595 0 95383921595 596 0 105155207596 597 0 114193414597 598 0 98108892598 599 0 97888966599 600 0 103802453600 601 0 97249346601 602 0 101917488602 603 0 104943847603 604 0 98966140604 605 0 97924262605 606 0 97379587606 607 0 97518808607 608 0 99839892608 609 0 100046492609 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''], df5[''tiempoTotal''], kind="reg")---> 11 sns.plt.show()AttributeError: ''module'' object has no attribute ''plt''
我在我这运行Jupyter Notebook
使用Python 2.7.12
。有任何想法吗?
答案1
小编典典sns.plt.show()
使用seaborn 0.7.1。对我来说工作正常。可能是其他版本不同。但是,无论如何,importmatplotlib.pyplot asplt
您还是可以简单地使用plt.show()
,sns.plt.show()
因为pyplot
它可以在seaborn命名空间中使用,因此只能正常工作。
AttributeError: 'ADC' 对象没有属性 'atten'
如何解决AttributeError: ''ADC'' 对象没有属性 ''atten''?
我的 pyboard 有点问题。我想测量电压,我想使用这个程序:
from machine import Pin,ADC
adc=ADC(Pin(''A0''))
adc.atten(ADC.ATTN_11DB)
3.3/4095
adc.read()* 0.000805
但我有属性 atten
的问题并阅读
解决方法
问题是因为 ADC 没有名为 ADC.atten() 的方法可以调用。您可以看到 here 的所有方法。
AttributeError: 'tuple' 对象没有属性 'set_author' discord.py
如何解决AttributeError: ''tuple'' 对象没有属性 ''set_author'' discord.py?
再次,我一直在考虑我的准备问题。我刚刚开始为不和谐编写机器人并坐了几个小时寻找错误,最终我还是没有找到它。这就是我写论坛帖子作为最后手段的原因。我期待您的帮助,并在此先感谢您。
这是我的代码:
@tasks.loop(hours=24)
async def covid_hour():
channel = client.get_channel(809881992367702117),embed = discord.Embed(
title = "Dane dot. COVID-19 w Polsce:",color = discord.Color.blue(),),url = ''API''
async with aiohttp.ClientSession() as session:
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
embed.set_author(name=str(f''{date}''))
embed.add_field(name=''• **Kraj**:'',value=str(f"Polska"),inline=False)
embed.add_field(name=''• **Nowe zakażenia**:'',value=str(f"{response[''dailyInfected'']}"),inline=True)
embed.add_field(name=''• **Nowe zgony**:'',value=str(f"{response[''dailyDeceased'']}"),inline=True)
embed.add_field(name=''• **Nowe testy**:'',value=str(f"{respons[''dailyTested'']}"),inline=True)
embed.add_field(name=''• **Nowe uzdrowienia**:'',value=str(f"{response[''dailyRecovered'']}"),inline=True)
embed.add_field(name=''• **Aktualnie zakażonych**:'',value=str(f"{respons[''activeCase'']}"),inline=True)
embed.add_field(name=''• **Łącznie potwierdzonych**:'',value=str(f"{response[''infected'']}"),inline=True)
embed.add_field(name=''• **Łączne zgony**:'',value=str(f"{response[''deceased'']}"),inline=True)
embed.add_field(name=''• **Wyzdrowiałych**:'',value=str(f"{response[''recovered'']}"),inline=True)
embed.add_field(name=''• **Nowych na kwarantannie**:'',value=str(f"{response[''dailyQuarantine'']}"),inline=True)
embed.set_footer(text="dBot created by Diablo#4700")
await channel.send(embed=embed)
#await channel.send(''`` ``'')
控制台错误:
Unhandled exception in internal background task ''covid_hour''.
Traceback (most recent call last):
File "C:\Users\konta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\discord\ext\tasks\__init__.py",line 101,in _loop
await self.coro(*args,**kwargs)
File "bot.py",line 64,in covid_hour
embed.set_author(name=str2(f''{date}''))
AttributeError: ''tuple'' object has no attribute ''set_author''
解决方法
在您创建 discord.Embed 实例的那一行,最后有一个 ,
。这告诉python它是一个tuple
。因此,将其删除将解决此问题。
AttributeError: module ''sys'' has no attribute ''setdefaultencoding''
python3版本
import requests, re, sys
reload(sys)
sys.setdefaultencoding("utf-8")
出现错误:
sys.setdefaultencoding("utf-8")
AttributeError: module ''sys'' has no attribute ''setdefaultencoding''
原因:
Python3字符串默认编码unicode, 所以sys.setdefaultencoding也不存
解决方法:
去掉,sys.setdefaultencoding
关于AttributeError:'模块'对象没有属性'setdefaultencoding'和对象模块不存在的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于AtributeError:“模块”对象没有属性“ plt”-Seaborn、AttributeError: 'ADC' 对象没有属性 'atten'、AttributeError: 'tuple' 对象没有属性 'set_author' discord.py、AttributeError: module ''sys'' has no attribute ''setdefaultencoding''的相关知识,请在本站寻找。
本文标签: