RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-269491

Vadim's questions

Martin Hope
Vadim
Asked: 2022-05-10 16:54:54 +0800 CST

帮助 Bash 中的重定向

  • 0

我不太了解重定向逻辑。假设我在根目录 /root 中有这样的文件

ls -l
total 16692
-rw-r--r--  1 root   root   1249479 May  5 22:40 bootstrap-5.0.0-examples.zip
-rw-r--r--  1 root   root       786 May  9 12:49 in
drwxr-xr-x  9 root   root    4096 May  5 16:43 nginx-1.19.0
-rw-r--r--  1 root   root   1043748 May 26  2020 nginx-1.19.0.tar.gz
drwxrwxr-x 18 root   root      4096 May  5 16:52 openssl-1.1.1g
-rw-r--r--  1 root   root   9801502 Apr 21  2020 openssl-1.1.1g.tar.gz
-rw-r--r--  1 root   root       177 May  9 12:00 out_bash
drwxr-xr-x  9   1169   1169   12288 May  5 16:10 pcre-8.44
-rw-r--r--  1 root   root   2090750 Feb 12  2020 pcre-8.44.tar.gz
-rw-r--r--  1 root   root   2253029 May  7 11:02 v4.0.0.zip
drwxr-xr-x 14    501 staff     4096 May  5 16:18 zlib-1.2.11
-rw-r--r--  1 root   root    607698 Jan 15  2017 zlib-1.2.11.tar.gz

如果我满足

bash > out.txt

现在,如果您在同一目录中运行 ls,则 ls 将显示一个空目录!

为了让我可以再次看到我的文件和目录,我需要退出。在这种情况下,out.txt 文件将包含我所有的文件和目录的列表。

如果可能,如何实际应用?

bash
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2022-04-13 14:00:25 +0800 CST

调用类的实例时 None 来自哪里?

  • 0

提示,在给定示例中的输出值从何而来 - 没有结果。以及如何摆脱它?

class Person:

    def __init__(self, n='John', s='Doe'):
        self.name = n
        self.surname = s

    def identity(self):
        if self.name == 'John':
            print('Some suspicious man!')
        else:
            print(f'My regards {self.name} {self.surname}')

p = Person('V', 'N')
p2 = Person()
    
print(p.identity())
print(p2.identity())

结论

My regards V N
None
Some suspicious man!
None
python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2022-02-25 16:28:49 +0800 CST

如何将循环的输出写入文件?

  • 1

循环遍历文本文件中的地址:

...
https://github.com/22982
https://digitalocean.com
https://www.linux.org.ru/

目标是将循环的输出写入文件。循环本身:

for url in urls:
    r = requests.get(url)
    sc = r.status_code
    if sc == 200:
       valid = 'Valid'
    else:
       valid = "Not valid"
    
    with open('out.txt', 'w') as f:
        print(f'URL: {url}',  f'Status code: {sc}',  f'{valid}', file=f)

在其当前形式中,只有最后一次迭代被写入文件。
你能告诉我如何记录整个输出吗?

python
  • 2 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2022-02-25 14:47:50 +0800 CST

如何计算已检查的网址数量?

  • 0

有一个带有近似内容的 url 文件

https://www.docker.com/products/docker-hub
https://www.codewars.com/
https://realpython.com/
https://githubX.com/
www.digitalocean.com
https://www.linux.org.ru/

目标是计算可用/地址的数量。但是计算不正确,在所有地址都正确的情况下,我得到结果1

import requests

with open('urls.txt', 'r') as file:
    urls = file.read().splitlines()

for url in urls:
    good_urls = 0
    bad_url = 0
    r = requests.get(url)
    sc = r.status_code
    if sc == 200:
        valid = 'Valid'
        good_urls =+ 1
    else:
        valid = "Not valid"
        bad_url =+ 1
    print(good_urls)
    print(bad_url)
python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-06-29 20:48:26 +0800 CST

如何在模板文件的正确位置替换变量的值?

  • 0

使用 stat 命令,我获得了有关文件的最后更改的信息,该文件被写入 FileTimeChenge 文件

stat --format=%z ~/Price > FileTimeChenge

在 mutt 的帮助下,我使用文件附件进行用户分发

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=«Content-Type» content=«text/html; charset=utf-8»>
</head>
<body>
<p><font ><em><strong>Здравствуйте!</strong></em></font></p>
<p>Файл изменён - "Тут должна быть дата"</p>
</p>
</body>
</html>

告诉我如何将文件中的数据插入到 html 代码中 - FileTimeChenge

根据用户@aleksandr barakin 的建议,在连接时设法获得变量的输出

cat body | envsubst '${Test}'

但是,执行 mutt 循环时,变量显示在字母的正文中,而不是变量的值

for I in `cat list`; do cat body |envsubst '${Test}' | mutt -e "set content_type=text/html" -a "/var/log/mail.log" -s "Title" -- $I < body;echo $I;sleep 3 ;done
html
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-06-01 15:18:42 +0800 CST

测量唯一对象的数量

  • -1

有一个 csv 文件,其中只有一列 - “站点所在的城市”。该列包含城市名称,并非每一行都有一个值。该文件大致如下所示:

Москва
Киев

Париж
Киев
Осло

Токио
Токио

如何获得这样的输出:

Москва -1
Киев -2
Париж -1
Осло -1
Токио -2
powershell
  • 2 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-10-28 20:24:49 +0800 CST

如何隐藏php评论输出

  • 2

请告诉我如何使用正则表达式在 bash 中隐藏 php 注释输出。例如,要隐藏 bash 注释,我使用 sed

cat /etc/samba/smb.conf | sed '/#/d'

如何隐藏多行注释

/* Это многострочный комментарий
       еще одна строка комментария */
регулярные-выражения
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-02-28 13:41:57 +0800 CST

附加到 CSV 文件末尾的 Pandas

  • 3

我有这个 csv 文件

,Date,Model,Mark
0,2019-02-15,Q2612X,HP
1,2019-02-15,TK-1150,Kyocera
2,2019-02-15,MP2000,Ricoh
3,2019-02-26,CE255X,HP

追加到文件末尾

import pandas as pd

columns = ['Date', 'Model', 'Mark']

data = [
['2019-02-28', 'Q2612X', 'HP']
]
df = pd.DataFrame(data, columns=columns)
df.to_csv(r'cart.csv', mode='a', header=False)

该行已附加

,Date,Model,Mark
0,2019-02-15,Q2612X,HP
1,2019-02-15,TK-1150,Kyocera
2,2019-02-15,MP2000,Ricoh
3,2019-02-26,CE255X,HP
0,2019-02-28,Q2612X,HP

但索引为空。提示实现索引的延续。

python
  • 2 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-02-27 16:20:26 +0800 CST

Python 创建 csv 文件

  • 2

我csv为会计墨盒创建了一个文件

import csv

with open('cartridge_accounting.csv', 'w') as csvfile:
    filewriter = csv.writer(csvfile, delimiter=',',
    quotechar='|', quoting=csv.QUOTE_MINIMAL)
    filewriter.writerow(['Date', 'Model', 'Mark'])
    filewriter.writerow(['2019-02-26', 'CE255X', 'nv print'])
    filewriter.writerow(['2019-02-26', 'CE255X', 'nv print'])

结果,文件被写入了一行

['Date', 'Model', 'Mark']
[]
['2019-02-26', 'CE255X', 'nv print']
[]
['2019-02-26', 'CE255X', 'nv print']
[]

请告诉我如何摆脱它。以及如何添加索引行使文件如下所示:

['Date', 'Model', 'Mark']
[0,'2019-02-26', 'CE255X', 'nv print']
[1,'2019-02-26', 'CE255X', 'nv print']
[2,'2019-02-26', 'CE255X', 'nv print']
[3,'2019-02-26', 'CE255X', 'nv print']
python
  • 2 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-02-22 14:49:56 +0800 CST

烧瓶如何在邮件列表中隐藏收件人列表

  • 0

有一个脚本可以从数据库向所有用户发送文件。但收件人可以看到所有其他收件人。如何隐藏它们?

from flask import Flask, render_template, make_response
from flask_celery import make_celery
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail, Message
import os

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///subscribe.db'
app.config['MAIL_SERVER'] = 'mail.post.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USERNAME'] = 'UserName'
app.config['MAIL_PASSWORD'] = 'Secret'


db = SQLAlchemy(app)
celery = make_celery(app)
mail = Mail(app)

class Subscribe(db.Model):
    id = db.Column('id', db.Integer, primary_key=True)
    email = db.Column('email', db.String(50), unique=True, nullable=False)
    company = db.Column(db.String(50), nullable=False)


    def __repr__(self):
        return f"Subscribe('{self.company}', '{self.email}')"


@app.route('/sendmail', methods=['GET', 'POST'])
def index():
    with app.app_context():
        theuser = Subscribe.query.filter(Subscribe.id).all()
        msg = Message('Hello', sender='flask@post.com', recipients=[theuser.email for theuser in Subscribe.query.all()])

        msg.body = "testing"
        msg.html = "<b>testing</b>"

        with app.open_resource(r"C:\dir\worry_cat.jpg") as fp:
            msg.attach("image.png", "image/png", fp.read())

        for theuser in Subscribe.query.all():
            mail.send(msg)

        return 'Message sent!'
python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-02-18 14:14:22 +0800 CST

您需要使用 Python 2.6、2.7 或 3.2 编译的 vim 以及更高版本的 Powerline 支持才能工作

  • 1

启动 vim 时,消息您需要使用 Python 2.6、2.7 或 3.2 编译的 vim 以及更高版本对 Powerline 工作的支持崩溃。Vim 版本 8.0.707。德比安。vim --version 显示

-python       
-python3  

告诉我在哪里激活正确版本的python!

python
  • 2 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-02-10 22:59:53 +0800 CST

获取目录的最大深度

  • 0

我想知道目录的深度

import os
src = r'C:\path'
for dir_name, dirs, files in os.walk(src):
    print(dir_name, len(dirs))

我得到所有子目录的输出,指示每个子目录的深度。以及如何为所有目录获得最大但一个输出。

python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-02-08 18:29:44 +0800 CST

字符移动到行尾

  • 1

我在代码变量上遇到了一个问题,并且似乎已经解决了它,如果不是为了一个但是!任务本身很简单,您需要将列表中所有 0(零)的内容发送到行尾。这就是它的工作原理

def move_zeros(array):
    for i in array:
        array.append(array.pop(array.index(0)))
        if array.index != 0:
            continue
    print(array)
# [9, -10, {}, True, 1, 2, 'a', 1, 1, [], None, 3, 'z', 1, 0, 0, 0, 0, 0, 0, 0]

但是直到您将 False 滑入数据中

if array.index != 0 and array.index is False:

我仍然得到类似的东西

[9, -10, {}, True, 1, 2, 'a', 1, 1, [], None, 3, 'z', 1, 0, 0, 0, False, 0, 0, 0, 0]
python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-01-31 21:56:19 +0800 CST

将列表和字典解包成字符串

  • 1

有一个简单的例子

def test(x, y, z):
    print(x, y, z)

l = [1, 2, 3]
d = {'x': 1, 'y': 2, 'z': 3}

print(*l)
print(*d)

在这里,一切都被打开了,但是如果您尝试从字典中获取值

print(**d)

不再犁地

python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-01-23 14:39:15 +0800 CST

Python字典,如何检查值是否与键匹配

  • 0

有一个模块可以从字典中随机选择一个键。用户必须为此键输入一个值。请告诉我如何编写验证。

import random

example = {('one'):'один', ('two'):'два', ('three'):'три'}

get_key = random.choice(list(example))

user_in = input(f'Enter a match of {get_key} : ')

if get_key[key] in example == user_in[value]:
    print('yes')
else:
    print('Not')
python
  • 2 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-01-21 14:56:48 +0800 CST

从网页中获取 JSON 格式的数据

  • 1

站点 API 允许您接收 json 格式的数据:

{
 "query": {
  "count": 2
},
" results": {
  "EUR_RUB": {
    "id": "EUR_RUB",
    "val": 75.489179,
    "to": "RUB",
    "fr": "EUR"
},
  "USD_RUB": {
    "id": "USD_RUB",
    "val": 66.343801,
    "to": "RUB",
    "fr": "USD"
   }
  }
}

我正在尝试从中获取数据:

import json
from urllib.request import urlopen

with urlopen('https://free.currencyconverterapi.com/api/v6/convert?q=EUR_RUB,USD_RUB') as response:
    source = response.read()

data = json.loads(source)

for item in data["results"]:
    print(item)

但是,在编写完脚本后,我只得到:

 EUR_RUB
 USD_RUB

请告诉我如何正确编写请求。

python
  • 3 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-01-18 18:03:22 +0800 CST

Python如何计算for循环中的迭代次数

  • 0

我正在学习列表的冒泡排序。告诉我如何计算 for 循环中的迭代次数:

list_for_sorting = [20, -34, -42, 4, -20, -20, 29, 16, 79]

def sorting(new_list):
    last_item = len(new_list) -1
    for i in range(0, last_item):
        # print(new_list)
        for x in range(0, last_item):
            if new_list[x] > new_list[x + 1]:
                new_list[x], new_list[x + 1] = new_list[x + 1], new_list[x]

    return new_list

print('Original list: ', list_for_sorting)
new_list = sorting(list_for_sorting).copy()
print('Sorting list: ', new_list)
python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-01-16 18:38:36 +0800 CST

使用 pygame 渲染 png 图像

  • 0

我无法弄清楚循环有什么问题。我想根据列表创建图像。其中 0 是一个 10 x 10 px 的灰色正方形,1 是空白空间。该模块可以正常工作,但是我得到的不是所需的图像

在此处输入图像描述

编码:

import pygame

class Gui:
    def __init__(self):
        self.level = [
                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,
                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                ]

    def create_image(self):
        screen = pygame.Surface((441, 441), pygame.SRCALPHA, 32)
        x = 1
        y = 1
        for i in self.level:
            if i == 0:
                pygame.draw.rect(screen, pygame.Color('Grey'), pygame.Rect(x,y,10,10))
                x += 11
                if x == 441:
                    y += 11
                    x = 1
        pygame.image.save(screen, 'images/gui.png')
python
  • 2 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-01-14 17:27:43 +0800 CST

在pygame中显示一个窗口

  • 1

告诉我如何克服。当应用程序启动时,会显示一个黑色窗口而不是背景。关闭应用程序时,背景会出现半秒

import pygame

pygame.init()
x = 6
y = 440
width = 50
height = 37
speed = 5
isJump = False
jumpCount = 10
    
left = False
right = False
animationCount = 0
    
window = pygame.display.set_mode((512, 256))
pygame.display.set_caption('Firts Game')
clock = pygame.time.Clock()
    
walkRight = [pygame.image.load('assets\\player-run-right-01.png'),
                 pygame.image.load('assets\\player-run-right-02.png'), pygame.image.load('assets\\player-run-right-03.png'),
                 pygame.image.load('assets\\player-run-right-04.png'), pygame.image.load('assets\\player-run-right-05.png')]
walkLeft = [pygame.image.load('assets\\player-run-left-01.png'),
                pygame.image.load('assets\\player-run-left-02.png'), pygame.image.load('assets\\player-run-left-03.png'),
                pygame.image.load('assets\\player-run-left-04.png'), pygame.image.load('assets\\player-run-left-05.png')]
                
background = pygame.image.load('assets\\background.png')
playerStand = pygame.image.load('assets\\adventurer-idle-03.png')
    
    
def drawWindow():
    global animationCount
    
    window.blit(background, (0, 0))
    
    if animationCount >= 25:
        animationCount = 0
  
    if left:
        window.blit(walkLeft[animationCount // 5], (x, y))
        animationCount += 1
    elif right:
        window.blit(walkRight[animationCount // 5], (x, y))
        animationCount += 1
    else:
        window.blit(playerStand, (x, y))
    
    pygame.display.update()
    
    
run = True
while run:
    clock.tick(25)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT] and x > 5:
        x -= speed
        left = True
        right = False
    elif keys[pygame.K_RIGHT] and x < 500 - width - 5:
        x += speed
        left = False
        right = True
    else:
        left = False
        right = False
        animationCount = 0

    if not(isJump):
        if keys[pygame.K_SPACE]:
            isJump = True
    else:
        if jumpCount >= -10:
            y -= jumpCount * 2
            jumpCount -= 1
        else:
            isJump = False
            jumpCount = 10

    drawWindow()
    
pygame.quit()
python
  • 1 个回答
  • 10 Views
Martin Hope
Vadim
Asked: 2020-01-09 13:48:45 +0800 CST

向所有数据库用户发送消息

  • 1

有一个简单的数据库,其中包含需要发送消息的用户

class Subscribe(db.Model):
    id = db.Column('id', db.Integer, primary_key=True)
    company = db.Column('company', db.String(50))
    email = db.Column('email', db.String(50))

有一个发送消息的脚本,在这种情况下发送给数据库的第一个用户

@app.route('/sendmail', methods=['POST'])
def index():
    theuser = Subscribe.query.filter(Subscribe.id).first()
    msg = Message('Hello', sender='flask@mail.com', recipients=[theuser.email])

    with app.open_resource(r"C:\py\image.jpg") as fp:
        msg.attach("image.png", "image/png", fp.read())
    mail.send(msg)
    return 'Message sent!'

告诉我如何向所有 db 用户发送消息

python
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0800 CST
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0800 CST
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0800 CST
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0800 CST
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0800 CST
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0800 CST
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0800 CST
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0800 CST
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0800 CST
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0800 CST

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5