Creating My Own Modules and Packages (Post-002)


The Data Engineering Channel -- Unlocking Python: Functions & Modules Explained (here)

    Notes:

    (1) Basic structure of a function and of a function call:
            def greet_the_user(message_string):               
                #^^^^-- func name and params

                name =input('What is your name? __')
                prrint(f'Hello {name}, here is a special message for you:')
                print 
 
                name =input('What is your name? __')
                print(f'Hello {name}, here is a special message for you:')
                
print(f"{message_string}")
                return name                                #-- retain the name for future use

            retained_name = greet_the_user("Your one-time passsword is "mishmash")  #--call it

(2)

def  get_secret_params(Parameters_file, Param_name):
#^^^-- a new function for fetching the value of a user-named parameter
# vvv -- Open your file of secret parameters and read the file line by line:

    with open(Parameters_file, "r") as file:
        for each_line in file:
            #vvv-- Strip away whitespaces and split the line about its equal (=) char
            key, value =  
each_line.strip().split("=")
            #vvv-- Store the split data in a local Dictionary
            params_dict[key] = value

            # vvv -- Now you can access and use your secret params without showing them in this code:

    secret_Prameter_value = params_dict[Param_name]
   #vvv-- for debug purposes only, print the gotten result for Param_name supplied to the function
    # print(f'Value gotten for {Param_name} is {Prameter_value}')

    return secret_Prameter_value
... above was 5:15 in above 17 minute tutorial by the Data Engineer

 at 8:42: How to create your own modules
a "module" is simply a python file (dot Py)
[a "package" is simply a folder filled with modules]
import GetParams.py as gp
added_numbers = gp.add(6,10)
print(f' The result of using the add function inside the module is 6 + 10 = {
added_numbers}')



More to Explore
Search of YouTube for "python move your functions to a module" -- (here)
List of built-in Python modules = (here)
Codemy lecture on using modules = Creating Modules with Python - #23 (here)
Tech with Tim -- How to create your own modules and What does '__init__.py' do in Python?
Tech with Tim -- Top 18 Most Useful Python Modules = (here)
Web Developer Pete -- 12 Learn to Code Tricks That Would’ve Saved [you] MONTHS

Comments

Popular posts from this blog

Back Stage Support for Old Man Learns to Code (Post-001)

Learn Lists and Modules --FRAME (000)

Mind Mapping the APPEND() method relative to other LIST methods (Post-003)