Python 基础

Python基础 import与from…import…

1
2
3
If the import module in the same dir, use e.g: from . import core
If the import module in the top dir, use e.g: from .. import core
If the import module in the other subdir, use e.g: from ..other import core
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import sys
print('================Python import mode==========================');
print ('The command line arguments are:')
for i in sys.argv:
print (i)
print ('\n The python path',sys.path)

from sys import argv,path#导入特定的成员
print('================python from import===================================')
print('path:',path)

如果你要使用所有sys模块使用的名字,你可以这样:

from sys import *
print('path:',path)

############################

导入mode,import与from…import的不同之处在于,简单说:

如果你想要直接输入argv变量到你的程序中而每次使用它时又不想打sys,

则可使用:from sys import argv

一般说来,应该避免使用from..import而使用import语句,

因为这样可以使你的程序更加易读,也可以避免名称的冲突

###########################

后台运行python程序

nohup cmd会后台运行python程序并输出在nohup.txt

Python技巧

判断是否空行
if line[:-1].strip(): 表示当前line不是空行