day 28 module os,sys

a sys module

# from my_module import func1 
# print(money)
# money = 20
# print(money)

# def func():
# print('in demo2')
#
# func()
# func1()
# import sys
# print(sys. modules)
# from my_module import func1

# When importing modules sys.modules import
# When using variables, look at the namespace globals()

# from my_module import func1,func2
# money = 999
# func1()
# func2()
# Although The imported func1 and func2 are global variables,
# but the variables used when using func2 are still local

# from my_module import func1, func2
# if inp == 'sha':
# from my_module import func1 as func
# elif inp == 'sha2':
# from my_module import func2 as func
# elif inp == 'md5':
# from my_module import func3 as func
#
# func()
# from time import time as t,sleep as s
# import my_module
# my_module.a
# from my_module import *
# print(a)
# print(A)
# print(func1)

# from my_module import *
# print(a)
# print(func1)
# print(func2)

import my_module
my_module.func2()

# from ... import ...
# from module name import Name
# The imported name belongs to the global directly, but points to the memory space where the name of the module is located
# If the imported name is a function or method, it refers to a global variable,
# Still use the variable in the module
# The imported name and the global name are The same, whoever preempts it last
# You can import multiple names, separated by commas
# You can also alias as
# from module import * By default, all names in the module will be imported into the global
# * and __all__

# Assignment 1: Calculate the size of all files in a folder
# Assignment 2
# Think: Suppose there are two modules a, b.
# Can I import b in module a and import a in module b?

two,
# from my_module import func1 
# print(money)
# money = 20
# print(money)

# def func():
# print('in demo2')
#
# func()
# func1()
# import sys
# print(sys. modules)
# from my_module import func1

# When importing modules sys.modules import
# When using variables, look at the namespace globals()

# from my_module import func1,func2
# money = 999
# func1()
# func2()
# Although The imported func1 and func2 are global variables,
# but the variables used when using func2 are still local

# from my_module import func1, func2
# if inp == 'sha':
# from my_module import func1 as func
# elif inp == 'sha2':
# from my_module import func2 as func
# elif inp == 'md5':
# from my_module import func3 as func
#
# func()
# from time import time as t,sleep as s
# import my_module
# my_module.a
# from my_module import *
# print(a)
# print(A)
# print(func1)

# from my_module import *
# print(a)
# print(func1)
# print(func2)

import my_module
my_module.func2()

# from ... import ...
# from module name import Name
# The imported name belongs to the global directly, but points to the memory space where the name of the module is located
# If the imported name is a function or method, it refers to a global variable,
# Still use the variable in the module
# The imported name and the global name are The same, whoever preempts it last
# You can import multiple names, separated by commas
# You can also alias as
# from module import * By default, all names in the module will be imported into the global
# * and __all__

# Assignment 1: Calculate the size of all files in a folder
# Assignment 2
# Think: Suppose there are two modules a, b.
# Can I import b in module a and import a in module b?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324935833&siteId=291194637