Python Forum
Defining Variables in outside modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Defining Variables in outside modules
#1
I'm just getting into coding and I'm attempting to write a script that will print out the required plumbing fixture count for a building based on its
occupancy type. I was finally able to do it but the code is a bit longer than it needs to be. Its made up of several different functions that I've tried to import as outside module but when I do I get an error.

This is one of the functions I have and it continues through all the Occupancy Types of a building, its saved as examplemod.py :

def Plumbing():
    if Occupancy_type == "A-1":
        Description = "Theaters and other buildings for the performing arts and motion pictures"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/125)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/65)
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/200)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/500)
        Other = "(1) Service Sink"

    print("Description = ", Description)
    print("Male Water Closets = ", Male_Water_Closet)
    print("Female Water Closets = ", Female_Water_Closet)
    print("Male Lavatories = ", Male_Lavatories)
    print("Female Lavatories = ", Female_Lavatories)
    print("Bathtubs / Showers = ", Bathtubs_Showers)
    print("Drinking Fountains = ", Drinking_Fountain)
    print("Other = ", Other) 
This is were I get an error:
import examplemod
import math

Occupancy_type = input("What is Occupancy type? ").strip().upper()
Occupancy_load = input("What is Occupancy load? ").strip().upper()
examplemod.Plumbing()
And this is the error:

Error:
Traceback (most recent call last): File "C:/Users/Barnett Chenault/Desktop/CODE SUMMARY/test.py", line 8, in <module> examplemod.Plumbing() File "C:/Users/Barnett Chenault/Desktop/CODE SUMMARY\examplemod.py", line 2, in Plumbing if Occupancy_type == "A-1": NameError: name 'Occupancy_type' is not defined >>>
Reply
#2
Occupancy_type and Occupancy_load are local to the script that imports examplemod; they are not visible within examplemod. To put it another way, there are no globally global variables.

The better solution (even if globals are available) is to pass Occupancy_type and Occupancy_load as parameters to your Plumbing function.
Reply
#3
This has to do with scope.
when you define a variable in a function, it's only visible from within the 'scope' of that function, not from the outside.
The way you get around this is to pass the variable as an a argument to the function:
def Plumbing(Occupancy_type):
and calling like:
examplemod.Plumbing(Occupancy_type)
You have another error here as well,
If occupanct_type does not equal "A-1", the print statements will fail because
none of the variables will have been defined.
You can avoid this by declaring the variables at the start of the function like:
Description = None
but the best way would be to include the print statements within your if statement.
Reply
#4
(Dec-12-2017, 07:27 PM)Larz60+ Wrote: This has to do with scope.
when you define a variable in a function, it's only visible from within the 'scope' of that function, not from the outside.
The way you get around this is to pass the variable as an a argument to the function:
def Plumbing(Occupancy_type):
and calling like:
examplemod.Plumbing(Occupancy_type)
You have another error here as well,
If occupanct_type does not equal "A-1", the print statements will fail because
none of the variables will have been defined.
You can avoid this by declaring the variables at the start of the function like:
Description = None
but the best way would be to include the print statements within your if statement.

Thank you Larz60. I understand that now and it worked perfectly.

import examplemod
import math

Occupancy_type = input("What is Occupancy type? ").strip().upper()
Occupancy_load = float(input("What is Occupancy load? "))


examplemod.Plumbing(Occupancy_type, Occupancy_load)
As for the 2nd error, I only have "A-1" as an example. Here is the original script were the Occupancy_type are exhausted, I'm
just trying to make it shorter.

#Libraries
import math
import time

#Variables
welcome = "Hello! Welcome to the Florida Building Code, Plumbing Python App, created by Barnett Chenault RA."

#Lists
Options = ["A-1", "A-2A", "A-2B", "A-3A", "A-3B", "A-3C", "A-4", "A-5",
           "B", "E", "F-1", "F-2", "I-1", "I-2A", "I-2B", "I-2C", "I-3A",
           "I-3B", "I-3C", "I-4", "M", "R-1", "R-2A", "R-2B", "S-1", "S-2"]

#Functions
def Welcome():
        print(welcome)
        while True:
                begin_program = input ("Would you like to get started? Y/N: ").strip().upper()
                if begin_program == "Y":
                     print("Awesome! I have a few questions for you.")
                     break
                elif begin_program == "N":
                    print("That's okay, maybe later!")
                    time.sleep(2)
                    quit()
                else:
                    print("That is an incorrect input, please try again")

def Rerun():
        while True:
                rerun_program = input ("Would you like to run this program again? Y/N: ").strip().upper()
                if rerun_program == "Y":
                     print("Please type 'Run()' and hit enter.")
                     break
                elif rerun_program == "N":
                    print("Thank you! Goodbye")
                    time.sleep(2)
                    quit()
                else:
                    print("That is an incorrect input, please try again")
        
 
def Plumbing ():
    if Occupancy_type == "A-1":
        Description = "Theaters and other buildings for the performing arts and motion pictures"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/125)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/65)
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/200)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/500)
        Other = "(1) Service Sink"

    elif Occupancy_type == "A-2A":
        Description = "Nightclubs, Bars, taverns, dance halls and buildins for similar purposes"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/40)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/40)
        Male_Lavatories = math.ceil((Occupancy_load/2)/75)
        Female_Lavatories = math.ceil((Occupancy_load/2)/75)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/500)
        Other = "(1) Service Sink"

    elif Occupancy_type == "A-2B":
        Description = "Restaurants, banquet, halls and food courts"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/75)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/75)
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/200)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/500)
        Other = "(1) Service Sink"

    elif Occupancy_type == "A-3A":
        Description = "Auditoriums without permanent seating, art galleries, exhibition halls, museums, lecture halls, libraries, arcades and gymnasiums"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/125)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/65)
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/200)
        Bathtubs_Showers = 0
        Drinking_Fountain = math.ceil(Occupancy_load/500)
        Other = "(1) Service Sink"
        
    elif Occupancy_type == "A-3B":
        Description = "Passenger, terminals, and transportation facilities"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/500)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/500)
        Male_Lavatories = math.ceil((Occupancy_load/2)/750)
        Female_Lavatories = math.ceil((Occupancy_load/2)/750)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/1000)
        Other = "(1) Service Sink"

    elif Occupancy_type == "A-3C":
        Description = "Place of worship and other religious services"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/150)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/75)
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/200)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/1000)
        Other = "(1) Service Sink"

    elif Occupancy_type == "A-4":
        Description = "Coliseums, arenas, skating rinks, pools and tennis courts for indoor sporting events and activities"
        if Occupancy_load <= 1500:
            Male_Water_Closet = math.ceil((Occupancy_load/2)/75)
        else:
            Male_Water_Closet = math.ceil((1500/2)/75)+(((Occupancy_load-1500)/2)/120)
        if Occupancy_load <= 1520:
            Female_Water_Closet = math.ceil((Occupancy_load/2)/40)
        else:
            Female_Water_Closet = math.ceil(((1520/2)/40)+((Occupancy_load-1520)/2)/60)
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/150)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/1000)
        Other = "(1) Service Sink"

    elif Occupancy_type == "A-4":
        Description = "	Stadiums, amusementparks, bleachers and grandstands for outdoor sporting events and activities"
        if Occupancy_load <= 1500:
            Male_Water_Closet = math.ceil((Occupancy_load/2)/75)
        else:
            Male_Water_Closet = math.ceil((1500/2)/75)+(((Occupancy_load-1500)/2)/120)
        if Occupancy_load <= 1520:
            Female_Water_Closet = math.ceil((Occupancy_load/2)/40)
        else:
            Female_Water_Closet = math.ceil(((1520/2)/40)+(((Occupancy_load-1520)/2)/60))
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/150)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil((Occupancy_load/2)/1000)
        Other = "(1) Service Sink"

    elif Occupancy_type == "B":
        Description = "Buildings for the transaction of business, professional services, other services involving merchandise, office buildings, baks, light industrial and similar uses"
        if Occupancy_load <=50:
            Male_Water_Closet = math.ceil(((Occupancy_load/2)/25))
        else:
            Male_Water_Closet = math.ceil(((50/2)/25)+(((Occupancy_load-50)/2)/50))
        if Occupancy_load <= 50:
            Female_Water_Closet = math.ceil(((Occupancy_load/2)/25))
        else:
            Female_Water_Closet = math.ceil(((50/2)/25)+((Occupancy_load-50)/50))
        if Occupancy_load <=80:
            Male_Lavatories = math.ceil(((Occupancy_load/2)/40))
        else:
            Male_Lavatories = math.ceil(((80/2)/40)+(((Occupancy_load-80)/2)/80))
        if Occupancy_load <= 80:
            Female_Lavatories = math.ceil(((Occupancy_load/2)/40))
        else:
            Female_Lavatories = math.ceil(((80/2)/40)+(((Occupancy_load-80)/2)/80))
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/1000)
        Other = "(1) Service Sink"

    elif Occupancy_type == "E":
        Description = "Education"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/125)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/65)
        Male_Lavatories = math.ceil((Occupancy_load/2)/200)
        Female_Lavatories = math.ceil((Occupancy_load/2)/200)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/500)
        Other = "(1) Service Sink"

    elif Occupancy_type == "F-1":
        Description = "Structures in  which occupants are engaged in work fabricating, assembly orprocessing ofproducts or materials"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/100)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/100)
        Male_Lavatories = math.ceil((Occupancy_load/2)/100)
        Female_Lavatories = math.ceil((Occupancy_load/2)/100)
        Bathtubs_Showers = "See section 411"
        Drinking_Fountain = math.ceil(Occupancy_load/400)
        Other = "(1) Service Sink"

    elif Occupancy_type == "F-2":
        Description = "Structures in  which occupants are engaged in work fabricating, assembly or processing of products or materials"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/100)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/100)
        Male_Lavatories = math.ceil((Occupancy_load/2)/100)
        Female_Lavatories = math.ceil((Occupancy_load/2)/100)
        Bathtubs_Showers = "See section 411"
        Drinking_Fountain = math.ceil(Occupancy_load/400)
        Other = "(1) Service Sink"

    elif Occupancy_type == "I-1":
        Description = "Residential Care"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/10)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/10)
        Male_Lavatories = math.ceil((Occupancy_load/2)/10)
        Female_Lavatories = math.ceil((Occupancy_load/2)/10)
        Bathtubs_Showers = math.ceil(Occupancy_load/8)
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"

    elif Occupancy_type == "I-2A":
        Description = "Hospitals, ambulatory nursing home care recipient"
        Male_Water_Closet = math.ceil(Num_Rooms/1)
        Female_Water_Closet = math.ceil(Num_Rooms/1)
        Male_Lavatories = math.ceil(Num_Rooms/1)
        Female_Lavatories = math.ceil(Num_Rooms/1)
        Bathtubs_Showers = math.ceil(Occupancy_load/15)
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"

    elif Occupancy_type == "I-2B":
        Description = "Employees, other than residential care"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/25)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/25)
        Male_Lavatories = math.ceil((Occupancy_load/2)/35)
        Female_Lavatories = math.ceil((Occupancy_load/2)/35)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "N/A"

    elif Occupancy_type == "I-2C":
        Description = "Visitors, other than residential care"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/75)
        Female_Water_Closet = math.ceil((Occupancy_load/2)/75)
        Male_Lavatories = math.ceil((Occupancy_load/2)/100)
        Female_Lavatories = math.ceil((Occupancy_load/2)/100)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/500)
        Other = "N/A"

    elif Occupancy_type == "I-3A":
        Description = "Prisons"
        Male_Water_Closet = "1 per Cell"
        Female_Water_Closet = "1 per Cell"
        Male_Lavatories = "1 per Cell"
        Female_Lavatories = "1 per Cell"
        Bathtubs_Showers = math.ceil(Occupacy_load/15)
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"

    elif Occupancy_type == "I-3B":
        Description = "Reformitories, detention centers, and correctional centers"
        Male_Water_Closet = math.ceiling((Occupancy_load/2)/15)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/15)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/15)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/15)
        Bathtubs_Showers = math.ceil(Occupacy_load/15)
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"

    elif Occupancy_type == "I-3C":
        Description = "Employees"
        Male_Water_Closet = math.ceiling((Occupancy_load/2)/25)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/25)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/35)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/35)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "N/A"

    elif Occupancy_type == "I-4":
        Description = "	Adult day care and child day care"
        Male_Water_Closet = math.ceiling((Occupancy_load/2)/15)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/15)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/15)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/15)
        Bathtubs_Showers = "(1)Bathtub or Shower"
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"
        
    elif Occupancy_type == "M":
        Description = " Retail stores, service stations, shops, salesrooms, markets and shopping centers"
        Male_Water_Closet = math.ceiling((Occupancy_load/2)/500)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/500)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/750)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/750)
        Bathtubs_Showers = "N/A"
        Drinking_Fountain = math.ceil(Occupancy_load/1000)
        Other = "(1) Service Sink"

    elif Occupancy_type == "R-1":
        Description = "Hotels, motels, boarding houses (transient)"
        Male_Water_Closet = math.ceil(Num_Units/1)
        Female_Water_Closet = math.ceiling(Num_Units/1)
        Male_Lavatories = math.ceiling(Num_Units)
        Female_Lavatories = math.ceiling(Num_Units/1)
        Bathtubs_Showers = math.ceiling(Num_Units/1)
        Drinking_Fountain = "N/A"
        Other = "(1) Service Sink"

    elif Occupancy_type == "R-2A":
        Description = "Dormitories,fraternities,sororities andboarding houses(not transient)"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/10)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/10)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/10)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/10)
        Bathtubs_Showers = math.ceiling(Occupancy_load/8)
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"

    elif Occupancy_type == "R-2B":
        Description = "Apartment house"
        Male_Water_Closet = math.ceil(Num_Units/1)
        Female_Water_Closet = math.ceiling(Num/1)
        Male_Lavatories = math.ceiling(Num_Units/1)
        Female_Lavatories = math.ceiling(Num_Units/1)
        Bathtubs_Showers = math.ceiling(Num_Units/1)
        Drinking_Fountain = "N/A"
        Other = "(1) Kitchen sink per dwelling, (1) automatic clothes washer connection per 20 dwelling units"

    elif Occupancy_type == "R-3A":
        Description = "Congregate living facilities with 16 or fewer persons"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/10)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/10)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/10)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/10)
        Bathtubs_Showers = math.ceiling(Occupancy_load/8)
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"

    elif Occupancy_type == "R-3B":
        Description = "	One- and two-family dwellings and lodging houses with five or fewer guestrooms"
        Male_Water_Closet = math.ceil(Num_Units/1)
        Female_Water_Closet = math.ceiling(Num_Units/1)
        Male_Lavatories = math.ceiling(Num_Units/1)
        Female_Lavatories = math.ceiling(Num_Units/1)
        Bathtubs_Showers = math.ceiling(Occupancy_load/8)
        Drinking_Fountain = "N/A"
        Other = "(1) Kitchen sink per dwelling, (1) automatic clothes washer per dwelling unit"

    elif Occupancy_type == "R-4":
        Description = "Congregate living facilities with 16 or fewer persons"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/10)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/10)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/10)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/10)
        Bathtubs_Showers = math.ceiling(Occupancy_load/8)
        Drinking_Fountain = math.ceil(Occupancy_load/100)
        Other = "(1) Service Sink"

    elif Occupancy_type == "S-1":
        Description = "Structures for the storage of goods, warehouses,storehouse and freight depots. Low and Moderate Hazard"
        Male_Water_Closet = math.ceil((Occupancy_load/2)/100)
        Female_Water_Closet = math.ceiling((Occupancy_load/2)/100)
        Male_Lavatories = math.ceiling((Occupancy_load/2)/100)
        Female_Lavatories = math.ceiling((Occupancy_load/2)/100)
        Bathtubs_Showers = "See section 411"
        Drinking_Fountain = math.ceil(Occupancy_load/1000)
        Other = "(1) Service Sink"

        
    print("Description = ", Description)
    print("Male Water Closets = ", Male_Water_Closet)
    print("Female Water Closets = ", Female_Water_Closet)
    print("Male Lavatories = ", Male_Lavatories)
    print("Female Lavatories = ", Female_Lavatories)
    print("Bathtubs / Showers = ", Bathtubs_Showers)
    print("Drinking Fountains = ", Drinking_Fountain)
    print("Other = ", Other)         

    Assembly = ["A-1", "A-2A", "A-2B", "A-3A", "A-3B", "A-3C", "A-4", "A-5",]
    if any(item.upper() == Occupancy_type for item in Assembly):
        print('''403.1.3Potty parity.In assembly occupancies, restrooms which are open to the public must have a ratio of 3:2
              water closets provided for women as the combined total of water closets and urinals provided for men, unless
              these are two or fewer such fixtures for men, in accordance with §553.86, Florida Statutes.
              Exception: This section does not apply to establishments licensed under Chapter 509, Florida Statutes, if
              the establishment does not provide meeting or banquet rooms which accommodate more than 150 people, and the
              establishment has at least the same number of water closets for women as the combined total of water closets and urinals for men.
              403.1.3.1Definitions.
              1.New construction. Means new construction, building, alteration, rehabilitation or repair that equals or exceeds 50 percent of
              the replacement value existing on October 1, 1992, unless the same was under design or construction, or under construction contract
              before October 1, 1992.
              2.Assembly occupancy. The use of a building or structure, or any portion thereof, for the gathering together of people for purposes
              such as civic, social or religious functions or for recreation, or for food or drink consumption, or awaiting transportation.
              3.Historic building. For the purposes of this section, a historic building is:
              1.Individually listed in the National Register of Historic Places; or
              2.A contributing resource within a National Register of Historic Places listed district; or
              3.Designated as historic property under an official municipal, county, special district or state designation, law, ordinance or
              resolution either individually or as a contributing property in a district, provided the local program making the designation is
              approved by the Department of the Interior (the Florida state historic preservation officer maintains a list of approved local programs); or
              4.Determined eligible by the Florida State Historic Preservation Officer for listing in the National Register of Historic Places, either
              individually or as a contributing property in a district.)''')
    
#Program
while True:
        Welcome()

        while True:
                Occupancy_type = input("What is the Occupancy type?").strip().upper()
                if any(item.upper() == Occupancy_type for item in Options):
                    print("You selected: ", Occupancy_type)
                    break
                else:
                    print("That is an incorrect input, please try one of these.", Options)
                          
        Occupancy_load = float(input("What is the Occupancy Load? "))
        Num_Rooms = float(input("How many Rooms are in the project? "))
        Num_Units = float(input("How many Units are in the project? "))

        print ("Thank you your Plumbing Fixture Combinations are listed below: ")

        Plumbing()

        Rerun()
Reply
#5
If you have all these entries hard coded, why not put the data into a dictionary, and create a json file that can be easily read back in by programs needing the data.
Or better yet, create a database which contains the data.
Here's an example of creating a dictionary and saving the data into a json file:
import json
from pathlib import Path


class InitializationData:
    def __init__(self):
        self.homepath = Path('.')
        self.datapath = self.homepath / 'data'
        self.enigma_info = self.datapath / 'enigma_data.json'

        self.datapath.mkdir(exist_ok=True)
        self.init_data = {
            'rotor_info': {
                'rotor1_info': {
                    'name': 'rotor1',
                    'cipher': 'EKMFLGDQVZNTOWYHXUSPAIBRCJ',
                    'notches': ['R'],
                },
                'rotor2_info': {
                    'name': 'rotor2',
                    'cipher': 'AJDKSIRUXBLHWTMCQGZNPYFVOE',
                    'notches': ['F']
                },
                'rotor3_info': {
                    'name': 'rotor3',
                    'cipher': 'BDFHJLCPRTXVZNYEIWGAKMUSQO',
                    'notches': ['W']
                },
                'rotor4_info': {
                    'name': 'rotor4',
                    'cipher': 'ESOVPZJAYQUIRHXLNFTGKDCMWB',
                    'notches': ['K']
                },
                'rotor5_info': {
                    'name': 'rotor5',
                    'cipher': 'VZBRGITYUPSDNHLXAWMJQOFECK',
                    'notches': ['A']
                },
                # Rotor 6 - 8 available on Kriegsmarine M3 and M4 only
                'rotor6_info': {
                    'name': 'rotor6',
                    'cipher': 'JPGVOUMFYQBENHZRDKASXLICTW',
                    'notches': ['A', 'N']
                },
                'rotor7_info': {
                    'name': 'rotor7',
                    'cipher': 'NZJHGRCXMYSWBOUFAIVLPEKQDT',
                    'notches': ['A', 'N']
                },
                'rotor8_info': {
                    'name': 'rotor8',
                    'cipher': 'FKQHTLXOCBJSPDZRAMEWNIUYGV',
                    'notches': ['A', 'N']
                },
            },
            'reflector_B': 'YRUHQSLDPXNGOKMIEBFZCWVJAT',
            'reflector_C': 'FVPJIAOYEDRZXWGCTKUQSBNMHL',
            'unencoded': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        }
        with self.enigma_info.open('w') as f:
            json.dump(self.init_data, f)

    def test_read(self):
        with self.enigma_info.open() as f:
            self.init_data = json.load(f)

        for entry in self.init_data.items():
            print(entry)

if __name__ == '__main__':
    idata = InitializationData()
    idata.test_read()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A problem with defining variables meru120 5 3,343 Apr-16-2019, 03:13 PM
Last Post: buran
  Use of global variables from several modules. Jstechg 3 2,763 Jan-03-2019, 03:39 AM
Last Post: scidam
  Sharing variables across modules j.crater 4 3,408 Jul-30-2018, 09:09 PM
Last Post: j.crater
  Class Modules, and Passing Variables: Seeking Advice Robo_Pi 21 10,095 Mar-02-2018, 05:22 PM
Last Post: snippsat
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,353 May-25-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020