Chapter folders renamed
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
|
||||
import mypanda
|
||||
|
||||
def my_main():
|
||||
|
||||
dict = {"country": ["Brazil", "Russia", "India", "China", "South Africa"],
|
||||
"capital": ["Brasilia", "Moscow", "New Dehli", "Beijing", "Pretoria"],
|
||||
"area": [8.516, 17.10, 3.286, 9.597, 1.221],
|
||||
"population": [200.4, 143.5, 1252, 1357, 52.98]}
|
||||
|
||||
mypanda.print_dataframe (dict)
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,9 @@
|
||||
# mypanda.py with default and custom random functions
|
||||
import pandas
|
||||
|
||||
def print_dataframe(dict):
|
||||
"""This function output a dictionary as a data frame """
|
||||
|
||||
brics = pandas.DataFrame(dict)
|
||||
print(brics)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# myrandomv2.py with default and custom random functions
|
||||
import random
|
||||
|
||||
#random = __import__('random')
|
||||
|
||||
#random = importlib.import_module('random')
|
||||
print (globals())
|
||||
|
||||
def random_1d():
|
||||
"""This function get a random number between 0 and 9"""
|
||||
return random.randint(0,9)
|
||||
|
||||
def random_2d():
|
||||
"""This function get a random number between 10 and 99"""
|
||||
return random.randint(10,99)
|
||||
@@ -0,0 +1,18 @@
|
||||
# calcmain1.py with a main function
|
||||
import mycalculator
|
||||
import myrandom
|
||||
|
||||
def my_main( ):
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = myrandom.random_2d( )
|
||||
y = myrandom.random_1d( )
|
||||
sum = mycalculator.add(x, y)
|
||||
diff = mycalculator.subtract(x, y)
|
||||
|
||||
print("x = {}, y = {}".format(x, y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,22 @@
|
||||
# calcmain2.py with alias for modules
|
||||
import mycalculator as calc
|
||||
import myrandom as rand
|
||||
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = rand.random_2d()
|
||||
y = rand.random_1d()
|
||||
|
||||
sum = calc.add(x,y)
|
||||
diff = calc.subtract(x,y)
|
||||
|
||||
print("x = {}, y = {}".format(x,y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
|
||||
print (globals())
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,22 @@
|
||||
# calcmain3.py with from and alias combined
|
||||
from mycalculator import add as my_add
|
||||
from mycalculator import subtract as my_subtract
|
||||
from myrandom import random_2d, random_1d
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = random_2d()
|
||||
y = random_1d()
|
||||
|
||||
sum = my_add(x,y)
|
||||
diff = my_subtract(x,y)
|
||||
|
||||
print("x = {}, y = {}".format(x,y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
|
||||
print (globals())
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,10 @@
|
||||
# globalmain.py with globals function
|
||||
|
||||
def print_globals():
|
||||
print (globals())
|
||||
|
||||
def hello():
|
||||
print ("Hello")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print_globals()
|
||||
@@ -0,0 +1,10 @@
|
||||
# mycalculator.py with add and subtract functions
|
||||
def add(x, y):
|
||||
"""This function adds two numbers"""
|
||||
return x + y
|
||||
|
||||
|
||||
def subtract(x, y):
|
||||
"""This function subtracts two numbers"""
|
||||
return x - y
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# myrandomv2.py with default and custom random functions
|
||||
import random
|
||||
|
||||
#random = __import__('random')
|
||||
|
||||
#random = importlib.import_module('random')
|
||||
print (globals())
|
||||
|
||||
def random_1d():
|
||||
"""This function get a random number between 0 and 9"""
|
||||
return random.randint(0,9)
|
||||
|
||||
def random_2d():
|
||||
"""This function get a random number between 10 and 99"""
|
||||
return random.randint(10,99)
|
||||
@@ -0,0 +1,19 @@
|
||||
# myrandomv2.py with default and custom random functions
|
||||
import random
|
||||
|
||||
#random = __import__('random')
|
||||
|
||||
#random = importlib.import_module('random')
|
||||
print (globals())
|
||||
|
||||
def random_1d():
|
||||
"""This function get a random number between 0 and 9"""
|
||||
return random.randint(0,9)
|
||||
|
||||
def random_2d():
|
||||
"""This function get a random number between 10 and 99"""
|
||||
return random.randint(10,99)
|
||||
|
||||
def get_random(lower, upper):
|
||||
"""This function get a random number between lower and upper"""
|
||||
return random.randint(lower,upper)
|
||||
@@ -0,0 +1,27 @@
|
||||
# pkgmain3.py with with main function
|
||||
|
||||
import masifutil
|
||||
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = masifutil.random_2d()
|
||||
y = masifutil.random_1d()
|
||||
|
||||
sum = masifutil.add(x,y)
|
||||
diff = masifutil.subtract(x,y)
|
||||
|
||||
sroot = masifutil.sqrt(x)
|
||||
log10x = masifutil.log(x)
|
||||
log2x = masifutil.ln(x)
|
||||
|
||||
print("x = {}, y = {}".format(x, y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
print("square root is {}".format(sroot))
|
||||
print("log base of 10 is {}".format(log10x))
|
||||
print("log base of 2 is {}".format(log2x))
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,30 @@
|
||||
# pkgmain4.py with with main function
|
||||
|
||||
import sys
|
||||
sys.path.append('/Users/muasif/Google Drive/PythonForGeeks/source_code/chapter2/mypackages')
|
||||
|
||||
import masifutil
|
||||
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = masifutil.random_2d()
|
||||
y = masifutil.random_1d()
|
||||
|
||||
sum = masifutil.add(x,y)
|
||||
diff = masifutil.subtract(x,y)
|
||||
|
||||
sroot = masifutil.sqrt(x)
|
||||
log10x = masifutil.log(x)
|
||||
log2x = masifutil.ln(x)
|
||||
|
||||
print("x = {}, y = {}".format(x, y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
print("square root is {}".format(sroot))
|
||||
print("log base of 10 is {}".format(log10x))
|
||||
print("log base of 2 is {}".format(log2x))
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,30 @@
|
||||
# pkgmain5.py with with main function
|
||||
|
||||
import site
|
||||
site.addsitedir('/Users/muasif/Google Drive/PythonForGeeks/source_code/chapter2/mypackages')
|
||||
|
||||
import masifutil
|
||||
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = masifutil.random_2d()
|
||||
y = masifutil.random_1d()
|
||||
|
||||
sum = masifutil.add(x,y)
|
||||
diff = masifutil.subtract(x,y)
|
||||
|
||||
sroot = masifutil.sqrt(x)
|
||||
log10x = masifutil.log(x)
|
||||
log2x = masifutil.ln(x)
|
||||
|
||||
print("x = {}, y = {}".format(x, y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
print("square root is {}".format(sroot))
|
||||
print("log base of 10 is {}".format(log10x))
|
||||
print("log base of 2 is {}".format(log2x))
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
from .mycalculator import add, subtract
|
||||
from .myrandom import random_1d, random_2d
|
||||
from .advcalc.advcalculator import sqrt, log, ln
|
||||
@@ -0,0 +1 @@
|
||||
#empty
|
||||
@@ -0,0 +1,14 @@
|
||||
# advcalculator.py with sqrt,log and ln functions
|
||||
import math
|
||||
|
||||
def sqrt(x):
|
||||
"""This function takes square root of a number"""
|
||||
return math.sqrt(x)
|
||||
|
||||
def log(x):
|
||||
"""This function returns log of base 10"""
|
||||
return math.log(x,10)
|
||||
|
||||
def ln(x):
|
||||
"""This function returns log of base 2"""
|
||||
return math.log(x,2)
|
||||
@@ -0,0 +1,9 @@
|
||||
# mycalculator.py with add and subtract functions
|
||||
|
||||
def add(x, y):
|
||||
"""This function adds two numbers"""
|
||||
return x + y
|
||||
|
||||
def subtract(x, y):
|
||||
"""This function subtracts two numbers"""
|
||||
return x - y
|
||||
@@ -0,0 +1,14 @@
|
||||
# myrandom.py with default and custom random functions
|
||||
import random
|
||||
|
||||
def random_1d():
|
||||
"""This function get a random number between 0 and 9"""
|
||||
return random.randint(0,9)
|
||||
|
||||
def random_2d():
|
||||
"""This function get a random number between 10 and 99"""
|
||||
return random.randint(10,99)
|
||||
|
||||
def get_random(lower, upper):
|
||||
"""This function get a random number between lower and upper"""
|
||||
return random.randint(lower,upper)
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2016 The Python Packaging Authority (PyPA)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
self software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and self permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,10 @@
|
||||
include pyproject.toml
|
||||
|
||||
# Include the README
|
||||
include *.md
|
||||
|
||||
# Include the license file
|
||||
include LICENSE.txt
|
||||
|
||||
# Include the data files
|
||||
recursive-include data *
|
||||
@@ -0,0 +1,5 @@
|
||||
# A sample package project
|
||||
|
||||

|
||||
|
||||
A sample project to build a package and then deploy it using different approaches
|
||||
@@ -0,0 +1 @@
|
||||
#empty file for GitHub upload
|
||||
@@ -0,0 +1 @@
|
||||
#empty file for GitHub upload
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
from .mycalculator import add, subtract
|
||||
from .myrandom import random_1d, random_2d
|
||||
from .advcalc.advcalculator import sqrt, log, ln
|
||||
@@ -0,0 +1 @@
|
||||
#empty
|
||||
@@ -0,0 +1,14 @@
|
||||
# advcalculator.py with sqrt,log and ln functions
|
||||
import math
|
||||
|
||||
def sqrt(x):
|
||||
"""This function takes square root of a number"""
|
||||
return math.sqrt(x)
|
||||
|
||||
def log(x):
|
||||
"""This function returns log of base 10"""
|
||||
return math.log(x,10)
|
||||
|
||||
def ln(x):
|
||||
"""This function returns log of base 2"""
|
||||
return math.log(x,2)
|
||||
@@ -0,0 +1,9 @@
|
||||
# mycalculator.py with add and subtract functions
|
||||
|
||||
def add(x, y):
|
||||
"""This function adds two numbers"""
|
||||
return x + y
|
||||
|
||||
def subtract(x, y):
|
||||
"""This function subtracts two numbers"""
|
||||
return x - y
|
||||
@@ -0,0 +1,14 @@
|
||||
# myrandom.py with default and custom random functions
|
||||
import random
|
||||
|
||||
def random_1d():
|
||||
"""This function get a random number between 0 and 9"""
|
||||
return random.randint(0,9)
|
||||
|
||||
def random_2d():
|
||||
"""This function get a random number between 10 and 99"""
|
||||
return random.randint(10,99)
|
||||
|
||||
def get_random(lower, upper):
|
||||
"""This function get a random number between lower and upper"""
|
||||
return random.randint(lower,upper)
|
||||
@@ -0,0 +1,16 @@
|
||||
Metadata-Version: 1.2
|
||||
Name: masifutilv2
|
||||
Version: 0.1.0
|
||||
Summary: A sample package for illustration purposes
|
||||
Home-page: http://pypi.python.org/pypi/PackageName/
|
||||
Author: Muhammad Asif
|
||||
Author-email: ma@example.com
|
||||
License: LICENSE.txt
|
||||
Description: # A sample package project
|
||||
|
||||

|
||||
|
||||
A sample project to build a package and then deploy it using different approaches
|
||||
|
||||
Platform: UNKNOWN
|
||||
Requires-Python: >=3.5, <4
|
||||
@@ -0,0 +1,14 @@
|
||||
LICENSE.txt
|
||||
MANIFEST.in
|
||||
README.md
|
||||
setup.cfg
|
||||
setup.py
|
||||
masifutil/__init__.py
|
||||
masifutil/mycalculator.py
|
||||
masifutil/myrandom.py
|
||||
masifutil/advcalc/__init__.py
|
||||
masifutil/advcalc/advcalculator.py
|
||||
masifutilv2.egg-info/PKG-INFO
|
||||
masifutilv2.egg-info/SOURCES.txt
|
||||
masifutilv2.egg-info/dependency_links.txt
|
||||
masifutilv2.egg-info/top_level.txt
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
masifutil
|
||||
masifutil/advcalc
|
||||
@@ -0,0 +1,4 @@
|
||||
[metadata]
|
||||
# This includes the license file(s) in the wheel.
|
||||
# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file
|
||||
license_files = LICENSE.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='masifutilv2',
|
||||
version='0.1.0',
|
||||
author='Muhammad Asif',
|
||||
author_email='ma@example.com',
|
||||
packages=['masifutil','masifutil/advcalc'],
|
||||
python_requires='>=3.5, <4',
|
||||
url='http://pypi.python.org/pypi/PackageName/',
|
||||
license='LICENSE.txt',
|
||||
description='A sample package for illustration purposes',
|
||||
long_description=open('README.md').read(),
|
||||
install_requires=[
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
#empty file for GitHub upload
|
||||
@@ -0,0 +1,27 @@
|
||||
# mypkgmain0.py with absolute imports
|
||||
import masifutil.mycalculator as calc
|
||||
import masifutil.myrandom as rand
|
||||
import masifutil.advcalc.advcalculator as acalc
|
||||
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = rand.random_2d()
|
||||
y = rand.random_1d()
|
||||
|
||||
sum = calc.add(x,y)
|
||||
diff = calc.subtract(x,y)
|
||||
sroot = acalc.sqrt(x)
|
||||
log10x = acalc.log(x)
|
||||
log2x = acalc.ln(x)
|
||||
|
||||
print("x = {}, y = {}".format(x, y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
print("square root is {}".format(sroot))
|
||||
print("log base of 10 is {}".format(log10x))
|
||||
print("log base of 2 is {}".format(log2x))
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,27 @@
|
||||
# mypkgmain1.py with main function
|
||||
from masifutil import mycalculator as calc
|
||||
from masifutil import myrandom as rand
|
||||
from masifutil.advcalc import advcalculator as acalc
|
||||
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = rand.random_2d()
|
||||
y = rand.random_1d()
|
||||
|
||||
sum = calc.add(x,y)
|
||||
diff = calc.subtract(x,y)
|
||||
sroot = acalc.sqrt(x)
|
||||
log10x = acalc.log(x)
|
||||
log2x = acalc.ln(x)
|
||||
|
||||
print("x = {}, y = {}".format(x, y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
print("square root is {}".format(sroot))
|
||||
print("log base of 10 is {}".format(log10x))
|
||||
print("log base of 2 is {}".format(log2x))
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
@@ -0,0 +1,25 @@
|
||||
# pkgmain2.py with with main function
|
||||
import masifutil
|
||||
|
||||
def my_main():
|
||||
""" This is a main function which generates two random numbers and then apply calculator functions on them """
|
||||
x = masifutil.random_2d()
|
||||
y = masifutil.random_1d()
|
||||
|
||||
sum = masifutil.add(x,y)
|
||||
diff = masifutil.subtract(x,y)
|
||||
|
||||
sroot = masifutil.sqrt(x)
|
||||
log10x = masifutil.log(x)
|
||||
log2x = masifutil.ln(x)
|
||||
|
||||
print("x = {}, y = {}".format(x, y))
|
||||
print("sum is {}".format(sum))
|
||||
print("diff is {}".format(diff))
|
||||
print("square root is {}".format(sroot))
|
||||
print("log base of 10 is {}".format(log10x))
|
||||
print("log base of 2 is {}".format(log2x))
|
||||
|
||||
""" This is executed only if the special variable '__name__' is set as main"""
|
||||
if __name__ == "__main__":
|
||||
my_main()
|
||||
Reference in New Issue
Block a user