Example #1
0
def main():
    print(f(-1))
Example #2
0
from a import f

print (f(['a', 'b', 'c']))
Example #3
0
# 导入系统模块会发现,并没有执行操作。因为系统模块中,并没有立即执行的可执行语句
import time

# 内存中如果成功导入模块,遇到同名模块,就不会再进行导入,只会用已经导入的模块

# 如何在导入模块的时候,不执行其中的可执行语句??
# python 中提供了一种 判断自定义模块是属于开发阶段还是使用阶段。当处于开发阶段,可执行语句会自动执行,而当属于调用使用阶段,就不会执行。

#__name__ ← 用这个内嵌变量来进行判断

# 将已脚本方式运行时,他的值是固定字符串: __main__
# 以导入方式运行时,就是本模块的名字 假设模块是time ,那么__name__ = time

print(a.b)
a.f()

# 内置路径中:安装路径下,lib
# sys 属于内置包, sys.path 是一个路径的列表 , 当导入模块时,如果不存在与内置源码中,或者在lib下找不到,就会到sys.path这个路径列表中,每个路径都寻找一次。如果都找不到则报错
# 所以如果模块在奇异路径,就需要将该路径添加到sys.path 中

# sys.path.append(r"/User/123") # r代表字符串中的转义字符都不进行自动转义,按原始输出
# print(sys.path)

# 使用相对路径找到b.py , 因为使用绝对路径的话,就写死了

print(__file__)  # __file__输出当前文件的绝对路径

# 使用os模块获取一个路径的父路径
dir = os.path.dirname(__file__)
#print(dir + r'/aa')
Example #4
0
def main():
    print(a.f(42))
Example #5
0
File: b.py Project: danavm/Rep1
import a

print(a.f())
Example #6
0
import a
import math

print(a.magicNumber)
print(a.f(200))
print(math.cos("abc"))

Example #7
0
from b import *
# from a import *
from a import magicNumber as magic2, f

print(magicNumber)
print(magic2)
print(f(100))
Example #8
0
def g():
    a.f()
    print "name = " + __name__
Example #9
0
from a import f

print f("http://example.com/")
Example #10
0
def use_f():
    f()
Example #11
0
import lib1
from a import f
import lib2

f()
Example #12
0
if '##__init__ ##module':

    # A *module* is either:

    # - a `.py` or `.pyc` file

    # - dir with and `__init__.py`

        # `__init__.py` code is executed when the module is loaded,

        # Just like code in a file is executed when it is loaded

    # It is not possible to distinguish between both except by looking at <#__file__>

    import a
    assert a.f() == 'a.f()'
    assert a.C().m() == 'a.C.m()'

    import d
    assert d.f() == 'd.f()'

if '##module search path':

    # View current python module search path:

    print sys.path

    if '##append to module search path':

        if '##environment variable':
Example #13
0
def use_f():
    f()
Example #14
0
def main():
    print(a.f(42))
Example #15
0
def g():
    print(a.f())
Example #16
0
import a
import b.b1
import b.b2
import b.b3

a.f()
print a
print b.b1
print b.b2
print b.b3
b.b3.f()
Example #17
0
import a
import time

r = a.f()
print(r)

print(a.variable_de_a)
a.variable_de_a = 6
print(a.variable_de_a)

while True:
    print(4)
    time.sleep(4)
    print(5)
Example #18
0
def main():
    print(f(-1))
Example #19
0
def g():
    # Solution
    # import a
    print a.f()
Example #20
0
def g():
    # import a
    print(a.f())
Example #21
0
if '##__init__ ##module':

    # A *module* is either:

    # - a `.py` or `.pyc` file

    # - dir with and `__init__.py`

    # `__init__.py` code is executed when the module is loaded,

    # Just like code in a file is executed when it is loaded

    # It is not possible to distinguish between both except by looking at <#__file__>

    import a
    assert a.f() == 'a.f()'
    assert a.C().m() == 'a.C.m()'

    import d
    assert d.f() == 'd.f()'

if '##module search path':

    # View current python module search path:

    print sys.path

    if '##append to module search path':

        if '##environment variable':
Example #22
0
# -*- coding: utf-8 -*-
import a
from a import p

print 'p={}'.format(p)
p = 100
print 'a.p={}'.format(a.p)
print 'p={}'.format(p)
cl = a.f()
instance1 = cl()
print ".....>........"
print 'dir(cl.mem)={}'.format(dir(cl.mem))
print 'type(cl.mem)={}'.format(type(cl.mem))
print 'cl.mem.__self__={}'.format(cl.mem.__self__)
print 'cl.mem={}'.format(cl.mem)

print 'dir(cl)={}'.format(dir(cl))
print 'dir(instance1.mem)={}'.format(dir(instance1.mem))
print 'instance1.mem.__self__={}'.format(instance1.mem.__self__)
print 'type(instance1.mem)={}'.format(type(instance1.mem))
print 'instance1.mem={}'.format(instance1.mem)
instance1.mem()
cl.mem(instance1)
print 'dir(instance1)={}'.format(dir(instance1))

instance1.counter = 1
print 'dir(instance1)={}'.format(dir(instance1))
while instance1.counter < 10:
    instance1.counter = instance1.counter * 2
print 'instance1.counter={}'.format(instance1.counter)
del instance1.counter