def greet(self): parser = argparse.ArgumentParser(description='') parser.add_argument('--hello', type=str, default='Hello') parser.add_argument('--world', type=str, default='World!') if self._one_func_mode: args = parser.parse_args(sys.argv[1:]) else: args = parser.parse_args(sys.argv[2:]) print(mymodule.greet(**vars(args)))
#!/usr/bin/env python3.7 import mymodule mymodule.greet("prathamesh") p = mymodule.person1["age"] print(p)
#use a module import mymodule mymodule.greet('Ayush') a = mymodule.person1['age'] print(a)
import mymodule assert (mymodule.greet("world") == "Hello, world!") print(mymodule.greet("world") == "Hello, world!") diditwork: str = mymodule.hello() print(diditwork)
#A file containing set of functions, which you want to include in your application. #Module is nothing but a file containing python code. To break larger coder in smaller manageable & organized code #Modules help in organizing our code, makes code easy to maintain & place similar code at one place according to their functionality. #Module names must end with .py extension #We created a module named mymodule.py which contains 2 methods import mymodule #To access functions from mymodule, use - moduleName.functionName() print(mymodule.greet('elon musk')) #ELON MUSK!!! print(mymodule.whisp('Guido Van Rossum')) #guido van rossum... #A module can contain variables also like a list, string, dictionary or any other variable. #mymodule file contains variable num, which is of type list print(mymodule.num[2]) #9 print(mymodule.num[0]) #1 newList = mymodule.num for n in newList: print(n, end=', ') #1, 4, 9, 16, 25, 36, 49, #Sometimes your module name is longer, in that case calling functionName with module name becomes too long for developer #Typing larger code becomes boring so, you can create alias name for your module while importing import mymodule as my print(my.greet('elon musk')) #There are several built-in standard modules also like - random, math, sys, datetime, time etc import random as r print(r.randint(0, 9)) #5 import math as m
from mymodule import greet from MyMainPackage import my_main_script from MyMainPackage.MySubPackage import mysubscript """ It imports greet functions from other module(program) i.e mymodyle.py """ greet('hari') my_main_script.main_report() mysubscript.sub_report()
import mymodule mymodule.greet("name") a = mymodule.person1["age"] b = mymodule.person1["country"] print(a) print(b) import platform x = platform.system() print(platform.machine()) print(x) print(platform.processor()) print(dir(platform))