Example #1
0
def main():
    print('sys.path:', sys.path)
    print('module name:', module.__name__)
    print('module.global_variable:', module.global_variable)
    module.hello()
    fun()
    try:
        fun2()
    except NameError:
        print('NameError exception')
        print('not found fun2()')
Example #2
0
# @Author  : bxd
# @Email   : [email protected]
# @File    : test.py
# @Software: PyCharm

#from module import *  #不建议这样用,容易被重载
'''
    模块: 一个python文件,用来组织(变量 函数 类 逻辑)
    包:一个带有__init__.py的文件夹,用于组织模块
    import 模块本质:将文件解释一遍
    import 包本质:执行包下的__init__.py文件
'''

import module #将整个文件形成一个变量   import 本质:将文件解释一遍
from module import name as name3  #只取name形成一个变量
from module import hello
import sys,os
# module.hello()
# print(module.name)

name = 'aaa'

print(module.name)

# print(name3)

name3 = 'bbb'
hello()
print(sys.path)
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) )
Example #3
0
# output of 'print hello("Alice")'.

import module

# And in fact, we don't.  If we were to run this from the command
# line, however, we would see both calls.  This is an important point:
# when you import a module, ALL the code will be run, unless it is in
# that special if statement.

# Like other things that we've imported, we can import functions and
# classes from modules, or just access them using the '.'.  This
# includes imports done in the module as well (this wlil become even
# more relevant in just a bit).

# running 'hello' without using an import
print module.hello("world")

# running 'hello' using an import
from module import hello

print hello("world")

# running 'pickled_hello' from the module
print module.pickled_hello("world")
# using the pickle module, as imported from the module
print module.pickle.dumps(hello("world"))

## Basic packages

# What if we want multiple modules?  For example, let's say we wanted
# to put together a statistics package.  We could put all of our
Example #4
0
import module

module.create_dir("/home/etenal/pzhxbz")
module.hello("/home/etenal/pzhxbz")
Example #5
0
#python当中的数据类型转换
#int() 将参数转换为int型 str() bool  以此类推
from selfFunctions import add
import functools
from selfFunctions import nop
from selfFunctions import divde
import module


c = add(10,5)
print(c)

#返回多个参数 tuple
s = divde(45)
print(s)
module.hello();
#关于函数参数 
#默认参数 同C++ 
#定义默认参数要牢记一点:默认参数必须指向不变对象!
#可变参数 *
#递归参数

#闭包
def add(x,y):
    def selfSum():
        return x+y;
    return selfSum
f = add(5,10)
print(f())
#匿名函数
#偏函数
Example #6
0
# testa a chamada em C de hello para python 2.7
#
from module import hello

ola = hello()

print " "
print ola
print " "
#https://docs.python.org/ko/3/library/__main__.html

#main.py

#from module import *
import module

if __name__ == "__main__":
    print(__name__)

#hello()
module.hello()
# output of 'print hello("Alice")'.

import module

# And in fact, we don't.  If we were to run this from the command
# line, however, we would see both calls.  This is an important point:
# when you import a module, ALL the code will be run, unless it is in
# that special if statement.

# Like other things that we've imported, we can import functions and
# classes from modules, or just access them using the '.'.  This
# includes imports done in the module as well (this wlil become even
# more relevant in just a bit).

# running 'hello' without using an import
print module.hello("world")

# running 'hello' using an import
from module import hello
print hello("world")

# running 'pickled_hello' from the module
print module.pickled_hello("world")
# using the pickle module, as imported from the module
print module.pickle.dumps(hello("world"))


## Basic packages

# What if we want multiple modules?  For example, let's say we wanted
# to put together a statistics package.  We could put all of our
Example #9
0
def foo():
    from module import hello  # Import from function
    hello()
Example #10
0
def main():
    logger.info('hello')
    logger.info(hello())

    return 0
Example #11
0
def call_hello():
    print(module.hello(2))