A custom module is just a python file with fiunctions in it. You can create a python file and put in the same location as the program where you are going to call it. Here is an example: A custom module is just a python file with fiunctions in it. You can create a python file and put in the same location as the program where you are going to call it. Here is an example:
I will create a new file called mymodule.py
def banana(filename):
name = open(filename)
content = name.read()
list = content.split(” “)
print (list)
counter = 0
for i in list:
if i.lower() == “banana”:
counter += 1
print (counter)<\/span><\/span>
def calculate_e(precision):
counter = 1
accumulative = 1
variable = 1
while True:
accumulative += variable*(1\/counter)
variable = (1\/counter)*variable
new = accumulative + variable*(1\/counter)
if (new – accumulative) < precision:
break
counter += 1
return accumulative<\/span><\/span>
And now i\u00b4m going to call that file just like if it were a module. This file is called file.py and is located in the same directory as mymodule.py:<\/span><\/span><\/span><\/span>
import mymodule.py<\/span><\/span>
a = mymodule.banana(“text.txt”) #You must have a file named “text”<\/span> called “text”<\/span><\/span>
b = mymodule.calculate_e(35)<\/span><\/span>
print (a)<\/span><\/span>
print(b)<\/span><\/span>
2<\/span><\/span><\/span><\/span>
2.71825 <\/span><\/span> <\/span><\/span>
As you can see in file.py i used the functions inside of mymodule.py by calling them as if they were a module(well, it is a module now)<\/span><\/span><\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"
I will create a new file called mymodule.py
def banana(filename):
name = open(filename)
content = name.read()
list = content.split(” “)
print (list)
counter = 0
for i in list:
if i.lower() == “banana”:
counter += 1
print (counter)<\/span><\/span>
def calculate_e(precision):
counter = 1
accumulative = 1
variable = 1
while True:
accumulative += variable*(1\/counter)
variable = (1\/counter)*variable
new = accumulative + variable*(1\/counter)
if (new – accumulative) < precision:
break
counter += 1
return accumulative<\/span><\/span>
And now i´m going to call that file just like if it were a module. This file is called file.py and is located in the same directory as mymodule.py:<\/span><\/span><\/span><\/span>
import mymodule.py<\/span><\/span>
a = mymodule.banana(“text.txt”) #You must have a file named “text”<\/span> called “text”<\/span><\/span>
b = mymodule.calculate_e(35)<\/span><\/span>
print (a)<\/span><\/span>
print(b)<\/span><\/span>
2<\/span><\/span><\/span><\/span>
2.71825 <\/span><\/span> <\/span><\/span>
As you can see in file.py i used the functions inside of mymodule.py by calling them as if they were a module(well, it is a module now)<\/span><\/span><\/span><\/span><\/p>\n","protected":false},"author":198,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[647,214,249],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/27222"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/users\/198"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/comments?post=27222"}],"version-history":[{"count":1,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/27222\/revisions"}],"predecessor-version":[{"id":27223,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/27222\/revisions\/27223"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media?parent=27222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/categories?post=27222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/tags?post=27222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}