相关疑难解决方法(0)

Python中的树实现

如何在Python中实现树?

我是Python初学者.

给我一个大致的想法!

python

0
推荐指数
3
解决办法
5593
查看次数

如何在另一个文件中执行类函数?

我正在尝试调用一个类函数,它将一些文本写入Tkinter的控制台窗口.

但是,当我尝试运行它.我收到以下错误.

TypeError: write() missing 1 required positional argument: 'txt'
Run Code Online (Sandbox Code Playgroud)

这是我的完整代码:

main.py

from tkinter import *
from tkinter.filedialog import askdirectory
import os
import nam


class Window(Frame):

    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.master = master
        self.init_window()


    def init_window(self):
        self.master.title("Source Data Checker")
        self.pack(fill=BOTH, expand=1)

        self.pathLabel = Label(text='Select the location of the source data below and press "Generate Excel"')
        self.pathLabel.place(x=110, y=40)

        self.selectFolderButton = Button(self, text='Select Folder', command=self.openfile)
        self.selectFolderButton.place(x=180, y=350)

        self.executeButton= Button(self, text='Generate Excel', command=self.run)
        self.executeButton.config(state=DISABLED)
        self.executeButton.place(x=330, y=350)

        self.outputWindow = Text()
        self.outputWindow.place(x=100, …
Run Code Online (Sandbox Code Playgroud)

python class tkinter

0
推荐指数
1
解决办法
63
查看次数

什么是“实例方法”?

来自3.数据模型

\n
\n

实例方法

\n

实例方法对象组合了类、类实例和任何\n可调用对象(通常是用户定义的\xef\xac\x81ned 函数)。

\n
\n

如果是定义的话,它的含义是什么?

\n

如果不是定义,那么“实例方法”的定义是什么?

\n

“实例方法”与类的方法是同一概念吗?

\n

既然有人提出了类方法和静态方法、绑定方法和非绑定方法,那么我澄清一下:

\n

我理解类的方法可以是普通方法、类方法或静态方法。我了解通过类或其实例访问的类的方法可以被绑定或函数。我从未听说过“实例方法”。即使看了引用,我也不知道它是什么,也不确定它是否与普通方法、类方法、静态方法、绑定方法或函数相关。

\n

python class object instance-methods python-3.x

0
推荐指数
1
解决办法
5154
查看次数

Python-静态方法与类方法

我有一个返回机器运行状况统计信息的类。

class HealthMonitor(object):
    """Various HealthMonitor methods."""

    @classmethod
    def get_uptime(cls):
        """Get the uptime of the system."""
        return uptime()

    @classmethod
    def detect_platform(cls):
        """Platform detection."""
        return platform.system()

    @classmethod
    def get_cpu_usage(cls):
        """Return CPU percentage of each core."""
        return psutil.cpu_percent(interval=1, percpu=True)

    @classmethod
    def get_memory_usage(cls):
        """Return current memory usage of a machine."""
        memory = psutil.virtual_memory()
        return {
            'used': memory.used,
            'total': memory.total,
            'available': memory.available,
            'free': memory.free,
            'percentage': memory.percentage
        }

    @classmethod
    def get_stats(cls):
        return {
            'memory_usage': cls.get_memory_usage(),
            'uptime': cls.uptime(),
            'cpu_usage': cls.get_cpu_usage(),
            'security_logs': cls.get_windows_security_logs()
        }
Run Code Online (Sandbox Code Playgroud)

方法get_stats将从类外部调用。这是定义相关功能的正确方法。使用classmethods …

python

-1
推荐指数
1
解决办法
1482
查看次数

标签 统计

python ×4

class ×2

instance-methods ×1

object ×1

python-3.x ×1

tkinter ×1