小编ppp*_*ery的帖子

Python 3类继承带参数

所以我有一个类,字符()和子类,npc(字符).它们看起来像这样:

class character():
    def __init__(self,name,desc):
        self.name = name
        self.desc = desc
        self.attr = ""    
        #large list of attributes not defined by parameters
Run Code Online (Sandbox Code Playgroud)

class npc(character):
    def __init__(self,greetings,topics):
        self.greetings = greetings
        self.topics = topics
        character.__init__(self)
        self.pockets = []
        #more attributes specific to the npc subclass not defined by parameters
Run Code Online (Sandbox Code Playgroud)

然而,当我从'Npc'中调用'Character'中应该存在(或者我认为)的属性时,比如'name'或'desc'或'attr',我得到一个"不存在/未定义"的错误.我只是不做继承吗?这里发生了什么?我混淆了属性和参数吗?

parameters inheritance attributes subclass python-3.x

6
推荐指数
1
解决办法
4306
查看次数

使用检查元素通过 css 加载本地存储的图像

我正在尝试重新设计巨大网站的一小部分,有人告诉我,如果自定义图像位于与网站重新映射到的样式表相同的路径中,我可以将它们加载到 Inspect Element (Chrome)。(所有这些都是通过 'content: url('...');' 通过 css 完成的),但网页仍在自己的资源中查找它们。那么有没有办法将本地存储的图像与 Inspect Element 一起使用呢?

browser element inspect web-inspector local-storage

6
推荐指数
1
解决办法
2万
查看次数

IndexError:无法将“int”放入索引大小的整数中

所以我试图让我的程序从文本文件中打印出每个单词和标点符号的索引(当它出现时)。我已经完成了那部分。- 但问题是当我尝试使用这些索引位置重新创建带有标点符号的原始文本时。这是我的代码:

with open('newfiles.txt') as f:
    s = f.read()
import re
#Splitting string into a list using regex and a capturing group:
matches = [x.strip() for x in re.split("([a-zA-Z]+)", s) if x not in ['',' ']]
print (matches)
d = {} 
i = 1
list_with_positions = []
# the dictionary entries:
for match in matches:
    if match not in d.keys():
        d[match] = i
        i+=1
    list_with_positions.append(d[match])

print (list_with_positions)
file = open("newfiletwo.txt","w")
file.write (''.join(str(e) for e in list_with_positions))
file.close()
file = open("newfilethree.txt","w") …
Run Code Online (Sandbox Code Playgroud)

python runtime-error list append indexof

6
推荐指数
1
解决办法
2万
查看次数

ClearDB 默认连接字符串上的 reconnect 关键字参数导致 MySQLdb 出错

我将 Django 应用程序上传到 Heroku,然后使用 Heroku 文档中的以下 3 个命令配置 cleardb 附加组件:

heroku addons:create cleardb:ignite
heroku config | grep CLEARDB_DATABASE_URL
heroku config:set DATABASE_URL='mysql://adffdadf2341:adf4234@us-cdbr-east.cleardb.com/heroku_db?reconnect=true'
Run Code Online (Sandbox Code Playgroud)

它似乎没问题并且应用程序正在运行(但没有数据库)。现在我尝试运行:

$ heroku run python manage.py migrate
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 327, in execute
    self.check()
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line …
Run Code Online (Sandbox Code Playgroud)

python django heroku cleardb

6
推荐指数
1
解决办法
1101
查看次数

如何将 conda 包导入 google colab?

我能够使用 pip 在 google colab 中安装软件包,使用:

!pip install....
Run Code Online (Sandbox Code Playgroud)

但我无法从 conda-forge 安装任何软件包。我试过:

!conda install -c conda-forge cartopy
Run Code Online (Sandbox Code Playgroud)

python cartopy conda google-colaboratory

6
推荐指数
1
解决办法
6677
查看次数

调整垫凸起按钮的大小

我正在尝试减小垫高按钮的大小。我以为我可以通过减小文本的大小来减小按钮的大小。但我无能为力。

这是CSS:

button {
    margin-right: 1vw;
    background: #4285F4;
    color: white;
    font-size: 9px;
    height: auto;
    width: auto;
}
Run Code Online (Sandbox Code Playgroud)

和模板:

<button mat-raised-button class="button"><span>Click here to submit</span></button>
Run Code Online (Sandbox Code Playgroud)

html css

6
推荐指数
2
解决办法
6134
查看次数

无法安装matplotlib:致命错误C1083:无法打开包含文件:ft2build.h:没有此类文件或目录

我正在尝试安装matplotlib模块,但是当我尝试执行该操作时,我得到一个错误,这个错误很大,但这似乎是由于缺少文件ft2build.h

我该怎么做才能解决此问题?

这是我得到的错误代码(我不得不删除部分错误消息,因为它太大了,我删除了复制文件和创建文件的部分):

ERROR: Command errored out with exit status 1:
     command: 'C:\Users\Maca\AppData\Local\Programs\Python\Python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Maca\\AppData\\Local\\Temp\\pip-install-8fraia6a\\matplotlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\Maca\\AppData\\Local\\Temp\\pip-install-8fraia6a\\matplotlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Maca\AppData\Local\Temp\pip-record-1miy2gd_\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\Maca\AppData\Local\Temp\pip-install-8fraia6a\matplotlib\
    Complete output (505 lines):
    ================================================================================
    Edit setup.cfg to change the build options

    BUILDING MATPLOTLIB
      matplotlib: yes [3.1.1]
          python: yes [3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC
                      v.1916 32 bit (Intel)]]
        platform: yes [win32]

    OPTIONAL SUBPACKAGES
     sample_data: yes [installing]
           tests: no  [skipping due to configuration]

    OPTIONAL …
Run Code Online (Sandbox Code Playgroud)

python matplotlib python-3.x

6
推荐指数
1
解决办法
512
查看次数

如何使用 Python 3 停止线程内的 youtube-dl 下载

我有一个从特定 URL 下载视频的函数,我通过线程启动此函数以避免 GUI 冻结,但我想要一个函数来停止或暂停下载。这个怎么做?这是代码:

def download_videos(self):
     ydl1 = youtube_dl.YoutubeDL(self.get_opts())
     if self.get_Urls().__len__() > 0:
         ydl1.download(self.get_Urls())

def downloadVideoThrd(self):
    self.t1 = threading.Thread(target=self.download_videos())
    self.t1.start()
Run Code Online (Sandbox Code Playgroud)

python multithreading python-3.x youtube-dl

5
推荐指数
1
解决办法
2228
查看次数

“如何使用 CREATE 方法修复 python IDE 中 sql 中已存在的错误表?”

当我使用时,错误不断弹出Pycharm

Traceback (most recent call last):
  File "C:/Users/aaa/.PyCharmCE2019.2/config/scratches/sql_class.py", line 11, in <module>
    cur.execute(customers_sql)
sqlite3.OperationalError: table customers already exists
Run Code Online (Sandbox Code Playgroud)

我正在使用Pycharm导入 sqlite3

import sqlite3
con = sqlite3.connect('data_info.sqlite3')
# 'connect' is similar to 'open' in a text file
cur = con.cursor()
# instantiate a cursor obj
customers_sql = """
      CREATE TABLE customers (
      id integer PRIMARY KEY,
      first_name text NOT NULL,
      last_name text NOT NULL)"""
cur.execute(customers_sql)


products_sql = """
      CREATE TABLE products (
      id integer PRIMARY KEY,
      name text …
Run Code Online (Sandbox Code Playgroud)

python sql python-3.x

5
推荐指数
1
解决办法
2万
查看次数

如何使用 PDFPlumber 从两列 PDF 中提取文本

我正在使用 python 进行主题建模任务,我想从年度/可持续性报告中提取文本。然而我的问题是,当我尝试提取报告时,提取的行在页面中的两个不同列之间断开,即它连接相邻段落中的两个不同行以构成一个句子。如何按照报告中的显示方式准确提取行。我已附上报告的版本和函数提取的行。

\n

下面是我使用的函数:

\n

#从url获取pdf的函数

\n
def converter(url):\n    text=[]\n    req= requests.get(url)\n    with pdfplumber.open(BytesIO(req.content)) as pdf:\n        for i in range(0, len(pdf.pages)):\n            pages= pdf.pages[i]\n            text.append(pages.extract_text())\n    return "\\n".join(str(i) for i in text)\n
Run Code Online (Sandbox Code Playgroud)\n

该图像是我正在提取的报告中的一个片段,报告中的文本分为两列,而 extract_content 函数将这两列混合起来得到一行,即将两列中的行连接起来并显示为一行。

\n

这是报告的第一行(第一列和第二列的开头由函数合并在一起):

\n
\n

\\n2019 年我的首要职责之一是接受采访。当我们\n在 2016 年\n开始新的战略时期\xe2\x80\x9c早安挪威\xe2\x80\x9d节目\n进行谈话时,我表示希望AF 会感到 \\n关于 AF\xe2\x80\x99s\n当我们\n希望超越 \\n女性时,将同样紧密结合的百分比增加一倍的目标

\n
\n

如果我能按照报告中给出的确切方式提取句子,那将会很有帮助。

\n

python text-extraction information-extraction topic-modeling pdfplumber

5
推荐指数
1
解决办法
2447
查看次数