首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(Notepad++克隆)

(Notepad++克隆)
EN

Stack Overflow用户
提问于 2013-09-28 05:27:15
回答 1查看 78关注 0票数 0

我正在用Python/PyQt4创建一个超级简单的Notepad++克隆,我想知道存储编辑器选项卡数据的这些选项中的哪一个:

选项1:我有一个名为QQCodeTab的类,它存储当前选项卡的当前Qsci.QsciScintilla实例、文件路径、当前语言等。这些内容通过字典映射到选项卡索引。

选项2:与选项1相同,但删除类并将所有内容存储在字典中(例如:{1: {"scintilla": <blah>, "filepath": "C:/File/whatevs.py"}, "language": "python"})

我的代码注释可以更好地解释它。

代码语言:javascript
复制
from PyQt4 import QtGui, Qsci

class QQCodeEditor(QtGui.QTabWidget):
    def __init__(self, parent=None):
        QtGui.QTabWidget.__init__(self, parent)
        self.new_tab()
        self.new_tab()
        # Option 1: Maps index to tab object
        # Option 2: Maps index to dict of options
        self.tab_info = {}

    def new_tab(self):
        scin = Qsci.QsciScintilla()
        index = self.addTab(scin, "New Tab")

    def get_tab_info(self, index):
        # Returns QQCodeTab object
        return self.tab_info[index]

    def save(self, index):
        # Option 2: Save dialog boc and file system stuff goes here
        pass

class QQCodeTab(object):
    def __init__(self, scintilla, editor):
        self.scintilla = scintilla
        self.editor = editor

    def save(self):
        # Option 1: Save dialog box and file system stuff goes here
        pass
EN

回答 1

Stack Overflow用户

发布于 2013-09-28 05:33:59

如果你想知道是否使用一个类的字典,你可能需要一个namedtuple。这为您提供了dict的简单性和类的属性语法:

代码语言:javascript
复制
from collections import namedtuple

FooBar = namedtuple("FooBar", ["these", "are", "the", "attributes"])

FooBar(123, 324, the=12, attributes=656).these
#>>> 123
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19060320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档