RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

Gleb's questions

Martin Hope
Gleb
Asked: 2020-03-21 00:52:02 +0000 UTC

__add__ 魔术方法在 python 3 中如何工作?

  • 3

这是代码:

class Add():
    def __init__(self, argument):
        self.argument = argument

    def __add__(self, other):
        return other + self.argument
z = Add(12)
x = Add(2)
t = z + x
print(t)

他工作。没有理由批评。

这是另一个带有新行的代码。

class Add():
    def __init__(self, argument):
        self.argument = argument

    def __add__(self, other):
        print(self.argument + other)
        return other + self.argument

z = Add(12)
x = Add(2)
t = z + x
print(t)

它会抛出一个 TypeError 错误,即一个类型无法self.argument + other对两种不同的数据类型执行算术运算。但以牺牲return other + self.argument一些东西为代价,他保持沉默。

请帮我弄清楚特殊方法如何仍然有效__add__。为什么脚本 2 不起作用?

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-01-12 21:50:40 +0000 UTC

为什么分配的变量“取决于”另一个变量

  • 3

这是代码:

a = {"1": "2", "3":"4"}
b = a
print(a, b)
b['1'] = "5"
print(a, b)

为什么最后显示{"1": "5", "3":"4"}变量a的这个值

{"1": "5", "3":"4"}这就是变量 b 的值。那么这就是为什么当变量 b 的值发生变化时,变量 a 的值也发生了变化?也许我错了,也许应该是这样。但如果我没记错的话,那么 b 是 a 的副本。

python
  • 4 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-01-10 21:54:31 +0000 UTC

tkinter 中的事件问题(python 3)

  • 0

有这个代码

from tkinter import *
from re_text import *

root=Tk()

def func(event):
    print("123")
    def fi(event):
        top_read(root,l['text'],l)
    l=Label(root, text="hello")
    l.bind("<Button-1>", fi)
    l.pack()
_list=Listbox(root)
_list.insert(END, "test element")
_list.bind("<<ListboxSelect>>", func)
_list.pack()
root.mainloop()

re_text 模块:

from tkinter import Toplevel, Text, FLAT, Tk, END
from tkinter.ttk import Button

class top_read(Toplevel):
    def __init__(self, master, text, widget):
        self.text = text
        self.widget = widget
        super().__init__(master)
        self.title("Редактировать строку")
        self.gui()
    def gui(self):
        self.geometry("680x300")
        self.ob = Text(self, relief=FLAT, height=17, width=72)
        self.ob.insert('end',self.text)
        self.b = Button(self, text="Сохранить", command=self._command_for_button)
        self.b.place(x=600,y=261)
        self.ob.place(x=15,y=9)
    def _command_for_button(self):
        self.widget['text'] = self.ob.get(1.0,END)[:-1]
        self.destroy()

问题:

当单击带有文本 hello 的标签后,编辑窗口按预期出现。如果您在此窗口中选择文本,那么 func 函数将以某种神奇的方式(或不是)启动。如果我们允许将 ListboxSelect 替换为 Button-1,则不会观察到“魔法”。

请帮助理解。

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-12-10 04:04:20 +0000 UTC

\xa0 字符和简单空格有什么区别

  • 1

好吧,假设我们有这样的例子(在python中)

一:

print(repr(" "))(如果您通过问题预览复制此示例,那么将有一个空格而不是 \xa0,如果通过编辑器(编辑),那么它不会被替换)

2:

print(repr(" "))

其实它们并没有什么不同,只是第一个字符是\xa0,第二个是空格。

那么这个符号是什么?为什么需要它?

python
  • 2 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-12-04 01:03:34 +0000 UTC

re.split 输出不是预期的(python3.6.1)

  • 1
from re import *
v=split(r"[\s,)(]", r"(C:\Users\Gleb\Desktop\сайты.txt,C:\Users\Gleb\Desktop\istock_000020116885large_-_copy-700x461.jpg)")
print(v)

代码输出:

['', 'C:\Users\Gleb\Desktop\сайты.txt', 'C:\Users\Gleb\Desktop\istock_000020116885large_-_copy-700x461.jpg', '']

并且应该输出:

['C:\Users\Gleb\Desktop\сайты.txt', 'C:\Users\Gleb\Desktop\istock_000020116885large_-_copy-700x461.jpg']

为什么会这样输出?

python
  • 2 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-28 03:45:01 +0000 UTC

如何通过具有管理员权限的python打开文件?

  • 0

如何通过具有管理员权限的python打开文件?如果我有 Windows 10

python
  • 2 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-26 19:20:17 +0000 UTC

PyQt5 中的 SetAlignment() 函数参数

  • 4

你能解释一下应该采用什么函数参数吗?

setAlignment(联合,Qt_Alignment=None,Qt_AlignmentFlag=None):

提前致谢。

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-26 16:53:44 +0000 UTC

这是什么标志| 而是它在python 3中做了什么。

  • 2

这是什么标志| 而是它在python 3中做了什么。

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-21 01:04:40 +0000 UTC

如何使用鼠标在 tkinter 画布中移动对象

  • 1

如何在 python3 tkinter 画布中移动对象?

我尝试了移动功能,但它不起作用,因为我需要沿给定坐标移动对象。

python
  • 2 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-13 03:51:41 +0000 UTC

re.sub 输出不是预期的(python3.6.1)

  • 0

re.sub 输出不是预期的下面是示例代码

import re
i=input() #H:\build\exe.win32-3.4\collections введите эту строку
print(re.sub(r"\w+",i,"f"))

我意识到你需要用双斜线书写,但我认为将进入路径的用户不会放两个斜线,因为他根本不知道。本质上应该输出 H:\build\exe.win32-3.4\collections 和

输出 Huild\exe.win32-3.4\collections

为什么会发生这种情况以及如何解决?

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-05 03:59:27 +0000 UTC

如何找出pyglet(或其他)中的音乐音量

  • 2

如何找出pyglet(或其他)中的音乐音量?

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-05 02:14:47 +0000 UTC

如何通过python中的pyglet(或其他)找出音乐持续多少秒

  • 1

我正在通过 pyglet 在 python3.6.1 中播放音乐。

import pyglet
pyglet.lib.load_library('avbin')
pyglet.have_avbin=True
song = pyglet.media.load('music.mp3')
song.seek(67)
song.play()
pyglet.app.run()

只有我不明白如何找出音乐中的秒数(歌曲、哔声等)。

如何找出秒数?

提前致谢。

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-11-04 20:20:49 +0000 UTC

在python中播放音乐的模块[关闭]

  • 2
关闭。这个问题不可能给出客观的答案。目前不接受回复。

你想改进这个问题吗? 重新构建问题,以便可以根据事实和引用来回答。

1 个月前关闭。

改进问题

推荐一个用python播放音乐的模块并展示一个例子。

python
  • 2 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-10-11 03:15:42 +0000 UTC

如何通过请求查看您是否在 stackoverflow.com 上收到消息或回复

  • 5

是否可以制作一个使用该模块的python脚本requests(为什么请求:嗯,因为它是轻量级的,我知道一点,如果有其他选项,那么建议)以便在 中观看新消息ru.stackoverflow.com?而不是看,而是找出它们是什么。

使用 Python 3.6.1

可以做到吗?如果可能,怎么做?

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-10-10 18:06:38 +0000 UTC

如何在 python3.6.1 中读取 13 GB 的 .json 文件

  • 1

你可能会问我在哪里或如何找到这个文件。

我回答你 - 像这样:

import json,os,sys
e = r"C:\Program Files (x86)\T-Rex help\Mount & Blade - Napoleonic Wars Enhancement"
hjson = "."
name_ins = "filejson"
y=open(hjson+"\\"+name_ins+".json","w")
y.write("[")
dirs=[]
po=0
files=[]
number_of_file=0
y.write("[")
json.dump(os.path.split(os.path.abspath(e))[1],y)
def scandir1(m):
    global number_of_file
    for i in os.scandir(m):
        if i.is_dir():
            number_of_file += 1
            print(os.path.abspath(i),"-->",hjson+"\\"+name_ins+".json")
            y.write(",")
            json.dump(os.path.relpath(i, e),y)
            scandir1(os.path.abspath(i))
        else:
            pass
scandir1(e)
y.write("]")
y.write(",[")
def scandir2(m):
    global number_of_file, po
    for i in os.scandir(m):
        if i.is_dir():
            scandir2(os.path.abspath(i))
        else:
            number_of_file+=1
            if po==0:
                po=1
            else:
                y.write(",")
            print(os.path.abspath(i),"-->",hjson+"\\"+name_ins+".json")
            json.dump([os.path.relpath(i, e),
                              open(os.path.abspath(i), "rb").read().decode("Latin-1")],
                      y)
scandir2(e)
y.write("]")
y.write("]")
print("Загрузка данных...")
print("===============")
y.close()

该程序(立即)将列表写入 .json 文件[dirs,["name_file","file_read"]]

顺便说一句,游戏 C:\Program Files (x86)\T-Rex help\Mount & Blade - Napoleonic Wars Enhancement 重约 3 GB。

一切都什么都不是,但是当您尝试阅读此内容并循环安装时(即首先创建文件夹,然后创建文件)。

这是实际示例:

import json as js
import os, codecs
er=0
locate_wer=input("Введите путь к JSON файлу")
locate_dir = input("Введите путь к папке куда установить")
y=open(locate_wer,"r")
print(y.readline())
y.close()
files=r[1]
dirs=r[0]
gh=dirs[0]#gh это название папки из которой были взяты файлы снизу эта папка  создаётся 
try:
    os.mkdir(locate_dir+"\\"+gh)
except FileExistsError: pass
for y in dirs[1:]:
    print(locate_dir+"\\"+gh+"\\"+y)
    os.mkdir(locate_dir+"\\"+gh+"\\"+y)
for y1 in files:
    er+=1
    try:
        t=open(locate_dir+"\\"+gh+"\\"+y1[0],"w")
        print(locate_dir + "\\" + gh + "\\" + y1[0])
        t.write(y1[1])
        t.close()
    except UnicodeEncodeError:
        t = codecs.open(locate_dir + "\\" + gh + "\\" + y1[0], "wb")
        print(locate_dir + "\\" + gh + "\\" + y1[0])
        t.write(y1[1].encode("Latin-1"))
        t.close()

我一般认为有必要分篇阅读,但不知道怎么读

那么如何读取这个文件呢?

python
  • 2 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-10-08 17:14:32 +0000 UTC

如何在 Button tkinter.ttk python 中更改高度选项

  • 0

解释如何height从Buttonpython tkinter.ttk3.6.1 更改参数?

例子:

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

# Стандартная tk кнопка
b = tk.Button(root, text='Button', height=10, width=10)  # Ошибки нет
b.pack()

# Кнопка из ttk
b = ttk.Button(root, text='Button', height=10, width=10)  # Ошибка _tkinter.TclError: unknown option "-height"
b.pack()

root.mainloop()
python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-10-06 02:55:45 +0000 UTC

两种获取字符串的方法有什么区别(python 3.x)

  • 2

有什么区别:

print(open("test.txt","r",encoding="Latin-1").read())

从

print(open("test.txt","rb").read().decode("Latin-1"))

它不同,我不明白,在一种情况下,第一个给出一个东西,第二个给出一个完全不同的东西。在其他情况下,一切都是一样的。帮助我理解。提前致谢。

python
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-10-04 15:29:05 +0000 UTC

如何使用python制作c++模块

  • 5

How to make a module for c++ using python 3.6.1 也就是用python写一些模块,用它做点什么,然后通过c++运行,例如 print("Hello, world"),当我们将这个库导入c++时,它会输出Hello, world

c++
  • 1 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-08-29 03:56:14 +0000 UTC

如何创建拼写排序器:按给定字母顺序的首字母对单词列表进行排序

  • 1

如何创建一个字母分类器。从任何字母到任何字母?(在python 3中)实际上写了代码:

list=["e","r","t","y","w"]
h=0
list2=["write","english","teacher","read","yellow"]
enter=[]
for u in range(1000):           #while len(enter)<=4:
    for qw in list2:
        try:
            if qw[0]==list[h]:
                enter.append(qw)
                h=h+1
        except IndexError:
            pass
print(enter)

但是这段代码的缺点是,如果碰巧在我们遇到的列表 2 中,让我们为字母 r 说两个单词,那么它会为字母 r 打印一个单词,它更接近列表的开头,这是由于我创建了一个变量 h 来显示哪个是下一个字母。

使用 Python 3.6.1

python
  • 3 个回答
  • 10 Views
Martin Hope
Gleb
Asked: 2020-05-28 03:32:21 +0000 UTC

如何通过python读取utf-16编码的文件

  • 2

如何使用 python 读取 utf-16 编码的文件。这是我写的代码,但是功能.decode()不喜欢,怎么办?

f=open(r"test.txt", "r").read()
print(f, f.decode('utf-16'))
python
  • 2 个回答
  • 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 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

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