Ejemplo n.º 1
0
# 色々なインポート

# import モジュール as 別名
import module2 as mod

result1 = mod.add(5, 3)
result2 = mod.sub(5, 3)
print(result1, result2)

# from モジュール import 名前, ...
from module2 import add, sub

result3 = add(5, 3)
result4 = sub(5, 3)
print(result3, result4)

# from モジュール import 名前 as 別名
from module2 import add as mod_add

result5 = mod_add(5, 3)
print(result5)
Ejemplo n.º 2
0
import module2

c = module2.add(3,4)
print(c)

d = module2.sub(3,4)
print(d)

e = module2.mul(3,4)
print(e)

f = module2.div(10,5)
print(f)
Ejemplo n.º 3
0
import moduleTest as mod
from module2 import add, mul, div
print("this is our basemodule ")
mod.hello()
mod.hii()
mod.go()
adres = add(12, 12)
dres = div(12, 3)
mres = mul(12, 3)
print("this  addres = \t %d" % adres)
print(" this is  divide  =\t %d" % dres)
print(" this multiplication  = \t  %d" % mres)
if __name__ == '__main__':
    print(" this my executable code ")

# 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)
Ejemplo n.º 5
0
Created on Thu Oct 31 14:39:42 2019

@author: agnib
"""

import module2

ins = int(
    input(
        '''Enter Your Choice :\n\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Modulus\n6.Square Root\n\nChoice : '''
    ))

if (ins == 1):
    a = float(input("Enter 1st number : "))
    b = float(input("Enter 2nd number : "))
    print(module2.add(a, b))
if (ins == 2):
    a = float(input("Enter 1st number : "))
    b = float(input("Enter 2nd number : "))
    print(module2.subt(a, b))
if (ins == 3):
    a = float(input("Enter 1st number : "))
    b = float(input("Enter 2nd number : "))
    print(module2.mult(a, b))
if (ins == 4):
    a = float(input("Enter 1st number : "))
    b = float(input("Enter 2nd number : "))
    print(module2.div(a, b))
if (ins == 5):
    a = float(input("Enter 1st number : "))
    b = float(input("Enter 2nd number : "))
Ejemplo n.º 6
0
module2.add(*list(range(1,6)))
print('클래스: ',end='')
mc=module2.MyClass()
print('value:{},type:{}'.format(mc,type(mc)))#value:<module2.MyClass object at 0x000001C6331B1FA0>,type:<class 'module2.MyClass'>
mc.hello()
'''
'''
print('[import 모듈명 as 별칭]')
import module2 as md2
print(dir())#module2가 아닌 md2가 이름공간에 있기 때문에 md2로 접근
print('변수:',md2.PI)
print('함수: ',end='')
md2.add(*list(range(1,6)))
print('클래스: ',end='')
mc=md2.MyClass()
print('value:{},type:{}'.format(mc,type(mc)))#value:<module2.MyClass object at 0x000001C6331B1FA0>,type:<class 'module2.MyClass'>
mc.hello()
'''
print('[from 모듈명 import * 혹은 변수,함수,클래스]')
#from module2 import *
#print(dir())
#print('변수 : ',PI)#모듈명을 붙이지 않고 바로 접근
from module2 import add, MyClass  #'MyClass', 'add' 바로 함수명,클래스명으로 접근할 수 있다
print(dir())
#print('변수 : ',PI)#NameError: name 'PI' is not defined
print('함수: ', end='')
add(*list(range(1, 6)))
print('클래스: ', end='')
mc = MyClass()
mc.hello()
Ejemplo n.º 7
0
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)

from module1 import (add, sub)
print(add(4, 5))
print(sub(4, 5))

from module2 import *
from module3 import *
from module2 import *
print(name)
print(city)
print(add(3, 4))
print(div(12, 3))

import module3
import module2
print(module3.name)
print(module2.add(3, 4))
print(module2.div(12, 3))
print(module3.div(12, 3))
print(name)