5

ユーザー向けのすべての文字列を 1 つのファイルにまとめて、これらの文字列を簡単に変更できるようにしようとしています。読みやすさの点でベストプラクティスを探しています。現在、同じファイルの 2 つのバージョンがあり、両方のバージョンにトレードオフが見られます。したがって、この状況についてベストプラクティスがあるかどうか疑問に思っていました。

最初の constants.py ファイル

class strings:

    esc_statuses = {
        "RETURNED": "Returned",
        "SUBMITTED": "Submitted",
        "DRAFT": "Draft",
        "CANCELED": "Canceled",
        "ESCALATED": "Escalated"
        }

    NewEscFieldText = {
        "customer_name": "The name of the customer who encountered this bug.",
        "summary": "A brief summary of the bug.",
        "request": "The request.",
        "customer_impact": "How the customer is impacted.",
        "severity": "The severity of the bug.",
        "component": "The component of this bug.",
        "related_bugs": "Bugs which are related to this one.",
        "logs": "The logs assosciated with this bug.",
        "description": "A detailed discription of the problem and any work \
                put into reproducting it.",
        "documentation": "Documentation consulted before escalation.",
        }

最初のバージョンでは、次のように言う必要があります。

from constants import strings

そして、私が何かを参照したいときはいつでも、私は言わなければなりません

strings.esc_statuses["RETURNED"]

constants.py ファイルはこの形式の方が読みやすいと思いますが、文字列を使用するたびに、もっと長い名前が必要になります。

2 番目の constants.py ファイル。

class strings:

    # ------------------------ Escalation status -----------------------------
    RETURNED = "Returned"
    SUBMITTED = "Submitted"
    DRAFT =: "Draft"
    CANCELED =: "Canceled"
    ESCALATED =: "Escalated"

    # ----------------------- New Escalation Field Text ----------------------
    customer_name = "The name of the customer who encountered this bug."
    summary = "A brief summary of the bug."
    request = "The request."
    customer_impact = "How the customer is impacted."
    severity = "The severity of the bug."
    component = "The component of this bug."
    related_bugs = "Bugs which are related to this one."
    logs = "The logs assosciated with this bug."
    description = "A detailed discription of the problem and any work put \
            into reproducting it."
    documentation = "Documentation consulted before escalation."

このバージョンで私が言わなければならないのは、

from constants import strings
strings.RETURNED

これにより、文字列の使用が読みやすくなりますが、ファイル自体も読みにくくなります。

それで、これをカバーするスタイルガイドはありますか? 私が見逃した考慮事項はありますか?

4

1 に答える 1

6
class stringer(type):
    esc_statuses = {
        "RETURNED": "Returned",
        "SUBMITTED": "Submitted",
        "DRAFT": "Draft",
        "CANCELED": "Canceled",
        "ESCALATED": "Escalated"
        }

    NewEscFieldText = {
        "customer_name": "The name of the customer who encountered this bug.",
        "summary": "A brief summary of the bug.",
        "request": "The request.",
        "customer_impact": "How the customer is impacted.",
        "severity": "The severity of the bug.",
        "component": "The component of this bug.",
        "related_bugs": "Bugs which are related to this one.",
        "logs": "The logs assosciated with this bug.",
        "description": "A detailed discription of the problem and any work \
                put into reproducting it.",
        "documentation": "Documentation consulted before escalation.",
        }

def __getattr__(self, name):
    if name in stringer.NewEscFieldText: 
        return stringer.NewEscFieldText[name]
    else:
        return stringer.esc_statuses[name]

class strings:
    __metaclass__ = stringer

print strings.customer_name
于 2013-07-17T02:19:13.363 に答える