def main(): ans = module1.add(a=2, b=3) print("using the add() function in module1, the answer is {}".format(ans)) print("inside module2 - module1 __name__ is: {}".format(module1.__name__)) print("inside module2 - module2 __name__ is: {}".format(__name__))
def main(): ans = module1.add(a = 2, b = 3) print("using the add() function in module1, the answer is {}".format(ans)) print("inside module2 - module1 __name__ is: {}".format(module1.__name__)) print("inside module2 - module2 __name__ is: {}".format(__name__))
def test1(): print("*** test1 ***") with patch("module1.add_implementation") as mocked_function: mocked_function.return_value = 42 value = module1.add(1, 2) print("add returns: {v}".format(v=value)) print("mocked function called: {c}".format(c=mocked_function.called)) mocked_function.assert_called_with(1, 2) value = module1.add(100, 100) print("add returns: {v}".format(v=value)) print("mocked function called: {c}".format(c=mocked_function.called)) mocked_function.assert_called_with(100, 100) print("calls: ", mocked_function.mock_calls)
def main(): """ The main entry point of the application """ #create a logger instance named "exampleApp" logger = logging.getLogger("exampleApp") #Set its logging level logger.setLevel(logging.INFO) # create the logging file handler to capture the logs fh = logging.FileHandler("sample1.log") formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') #The file handler has to set the formatter object as its formatter fh.setFormatter(formatter) # add handler to logger object logger.addHandler(fh) logger.info("Program started") result = module1.add(7, 8) logger.info("Done!")
#!/usr/bin/python #coding=utf-8 # import module1 # from module1 import add import module1 as cal # 如果导入目录下的模块,在目录下创建空文件 __init__.py # file.module1.add(2,3) print cal.add(2,3)
# __name__ 변수 # 모듈의 이름이 문자열로 들어있는 변수 # module1.py => 'module1' # 단, 실행할때 사용한 모듈에서는 모듈의 이름이 아니라 __main__이라는 문자열이 들어있다. print(f'main __name__ : {__name__}') import module1 # 실행할때 사용하는 모듈이라고 하더라도 나중에느 다른 모듈에서 가져다 사용할 때가 있을 수 있기 때문에 # if 문을 넣어주는것이 관례 이다 if __name__ == '__main__': r1 = module1.add(100,200) r2 = module1.minus(100,200) print(f'main r1 : {r1}') print(f'main r2 : {r2}')
print("hello") # from module1 import add import module1 add(3, 4) print(module1.add(3, 4))
from imp import reload import time import module1 module1.add(10, 20) print('befor sleeping time..') time.sleep(30) print('after sleep..') import module1 module1.product(10, 20)
import module1 num1 = input("enter a no :") num2 = input("enter a no :") print module1.add(num1, num2) b = module1.greatest(num1, num2) print b
# モジュールとは import module1 print('__name__:', __name__) result1 = module1.add(1, 2) print('module1.add(1, 2):', result1) # 変数に代入して実行 add = module1.add print('add = module1.add') result2 = add(1, 2) print('add(1, 2):', result2)
from module1 import add a = add(8, 9) print(a) import module1 d = module1.sub(8, 2) print(d)
# from module1 import x as y # print(y) # from random import choice as random_choice # print(random_choice([1, 2, 3])) # BAD, implicitly import everything # could have namespace clashes that are hard to debug # x = 20 # from module1 import * # print(x) # import module0 # print(module0.string.ascii_lowercase) # from myimports import * # print(random.randint(5, 10)) # from random import choice, randint # import string, math # print(math.acosh(1.0)) # print(__name__) import module1 print(module1.add(10, 10)) import mypackage.mymodule print(mypackage.mymodule.x)
import module1 as mod1 from module1 import sub import random print(sub(6, 7)) addval = mod1.add(1, 3) print("addition of two number: " + str(addval)) subVal = mod1.sub(6, 9) print("subtraction of two number : " + str(subVal)) mulVal = mod1.mul(8, 5) print("Multiplication of two number : " + str(mulVal)) # print("factorial of a number " + str(mod1.fact(20))) print("factorial of a number " + str(mod1.factorial(6))) print(random.randrange(0, 50))
# -*- coding:utf-8 -*- import module1 result = module1.add(11, 22) print(result)
import module1 num1 = int(input("Enter the first number: ")) num2 = int(input("Enter the second number: ")) sum = module1.add(num1, num2) print("The sum of {} + {} is: {}.".format(num1, num2, sum))
print(module3.name)#python print(module2.add(3,4))#7 print(module2.div(12,3))#144.0 print(module3.div(12,3))#4.0 print(name)#python """ ###1st method loading files import module1 print(module1.a) print(module1.b) print(module1.add(4, 5)) print(module1.sub(4, 5)) print(module1.mul(4, 5)) ###2nd method from module1 import * print(a) print(b) print(add(4, 5)) print(sub(4, 5)) print(mul(4, 5)) import sys print(sys.path) sys.path.append('C:/Users/Vali Basha/Desktop/11morning') print(sys.path)
import module1 print(module1.add(8, 8))
from sample.module1 import x, add, product # import module1 as m1 # import module1 as m1 # import module1 as m1 # import module1 as m1 import module1 as m1 print(__name__) if __name__ == '__main__': print("without from") print(m1.x) m1.add(10, 50) print(dir(m1)) # print(__name__) # print("with form :") # print(x) # add(20,90) # print(dir(m)) # print(x)
#!/usr/bin/python 3 # -*- coding: utf-8 -*- 'a test module' import module1 print('调用module1的计算结果为:', module1.add(2, 2))
# module2.py def add(a, b): print("module 2") print(a + b) # test.py from module1 import * from module2 import * add(10, 20) # This will print most recent module add which is module2 # How to print both add methods: # Way 1: import module1 import module2 module1.add(1, 2) module2.add(2, 3) # Way 2: from module1 import add as a1 from module2 import add as a2 a1.add(10, 20) a2.add(20, 30)
#import Modulename #modulename -- it file name with out extension.. # Module will check into 3 location: #1)Current working directory where current running file is there.. #2)Different location where python is installed.. #3)Environment variables path.. c=56 import module1 print(module1.a) print(module1.b) module1.add(13,12) # print(c+a) # a=43 # print(a) # # from module1 import * # from module1 import b,mul # print(a) # sub(14,12) import sys
import module1 a = 10 b = 6 c = module1.add(a, b) print(c) """ import module1 as md c = md.add(a,b) print(c) """
import time from imp import reload import module1 print('Addition is: ', module1.add(10, 20)) print('Entering in sleeping state') time.sleep(2) reload(module1) print('End of program')
'''printing Extram daat ''' import module1 as m1 import os print(m1.add(10, 20)) print(dir(m1)) print('Module : ', m1.__name__) print('Module : ', m1.__doc__) print('Module : ', m1.__file__) print(os.path.dirname(__file__)) print("for main FILE : ", __name__) print("for main FILE : ", __doc__) print("for main FILE : ", __file__)
def func3() -> str: """ Function returning the submodule name `sub_module`. """ return __package__ if __name__ == "__main__": result1 = timeit("go_fast(x)", setup="from __main__ import x, go_fast") result2 = timeit("go_slow(x)", setup="from __main__ import x, go_slow") result3 = timeit("np_sum(y)", globals=globals(), number=100) result4 = timeit("sum_parallel(y)", globals=globals(), number=100) result5 = timeit("sum_parallel_fast(y)", globals=globals(), number=100) go_slow(x) if DEBUG: p = Stats("go_slow.cprofile") p.strip_dirs().sort_stats("tottime").print_stats() print("fast result: ", result1) print("slow result: ", result2) print("np sum result: ", result3) print("parallel sum result: ", result4) print("fast parallel sum result: ", result5) x, y = 1.0, 2.0 print(add(x, y)) print(mod2.func2()) func3()
import module1 import random print(module1.add(5, 2)) print(module1.temperature) print(random.randint(2, 5)) import pkg.module3 print(pkg.module3.subtract(5, 2))
# Author: Victor Ding import os, sys # current_path = os.path.abspath(__file__) # current_dir = os.path.dirname(current_path) # module_dir = current_dir+'\\modules' current_dir = os.getcwd() module_dir = current_dir + '\\modules' # print(current_path) print(current_dir) print(module_dir) sys.path.insert(1, module_dir) import module1 as mod from module1 import sub as s from module1 import mul as m mod.add(2, 8) s(8, 2) m(3, 5)
#!/usr/bin/python #coding=utf-8 ''' Created on 2015-11-1 @author: ymy ''' import module1 reload(module1) print module1.add(5,6) module1.tt(555)
first element. :type: str :rtype: str """ if len(s) > 0: return s[1:] # if s == "hi": # return "hello" else: return "" if __name__ == "__main__": x, y = 1.0, 2.0 print(mod1.add(x, y)) mod3.foo() mod4.func1() print(math.sqrt(1.0)) # we can directly access the logger defined in module1 and e.g. set the # logging level by reading command line input: if len(sys.argv) > 1: if sys.argv[1] in ["debug", "info", "warning", "error", "critical"]: mod1.logger.setLevel( getattr(logging, sys.argv[1].upper()) ) emp1 = mod1.Employee(1234, "John", "Smith")