Constant string file in python

I'm trying to tie all of its users to the rows in a single file to simplify change these lines. I am looking for best practice in terms of readability. I have two versions of the same file right now and I see a compromise between the two versions. So I was wondering if there is any best practice in this situation.

First .py constants file

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.", } 

In the first version, I have to say:

 from constants import strings 

and then, whenever I want to refer to something, I have to say

 strings.esc_statuses["RETURNED"] 

I think the .py const file looks more readable in this format, but every time I have to use a string, I will have a much longer chewing name.

The second constant .py file.

 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." bug." 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." ." 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." ." 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." ." 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." this one." 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." bug." 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." problem and any work put \ 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." 

In this version, all I have to say it

 from constants import strings strings.RETURNED 

I think that the use of lines more readable, but also makes it more difficult to file for reading.

So, is there any style guides that cover it? Are there any reasons that I missed?

+4
source share
1 answer
 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 the customer who encountered this bug.", 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 ", 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 is impacted.", 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 this bug.", 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 of the problem and any work \ 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 escalation.", 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 
+6
source

Source: https://habr.com/ru/post/1491755/


All Articles