Tab键补全设置:
使用ubuntu12.03中的python2.7
在/usr/lib/python.27/dist-packages/ 下新建 vi tab.py
root@meng-VirtualBox:/usr/lib/python2.7/dist-packages# vi tab.py
# python startup file
import sys
import readline
import rlcompleter
#import atexit
import os
# tab completion
readline.parse_and_bind(' tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
#try:
# readline.read_history_file(histfile)
#except IOError
# pass
#atexit.register(readline.write_history_file,histfile)
在python里面引入import有三种方法
Import moduleName
如 import os
From module import sayHi
如from os import system
Import moduleName as new Name
如import SocketServer as SS
下面我们开始学习 新建input.py
#!/usr/bin/env python
this_year = 2013
name = raw_input("please input your name:")
age = int(raw_input("how old are you?")) //输入字符串转为int类型
print "hello, ",name,'\n'
print "you are ",age,'years old!'
print "so you were born in: ", this_year - age
执行 python input.py
#!/usr/bin/env python
this_year = 2013
name = raw_input("please input your name:")
age = int(raw_input("how old are you?"))
sex = raw_input("please input your sex:")
dep = raw_input("which department:")
//将输入作为参数
message = ''' Information of the company staff:
Name: %s
Age : %d
Sex : %s
Dep : %s
''' % (name, age, sex , dep)
print message
print "hello, ",name,"\n"
print "you are ",age,"years old!"
print "so you were born in: ", this_year - age
#!/usr/bin/env python
import sys
this_year = 2013
true_name = "meng"
true_password = "99999"
#counter = 0
while True:
#if counter < 3:
name = raw_input("please input your name:").strip()
if len(name) == 0:
print " empty name,try again!"
continue
for i in range(1,3):
name = raw_input("please input your name:").strip()
if name == true_name:
print "Welcome to login,%s" %name
else:
print "%s is not a valid user,please try again!" % name
#counter+=1
continue
break
else:
print " too many error"
sys.exit()
break
age = int(raw_input("how old are you?"))
sex = raw_input("please input your sex:")
dep = raw_input("which department:")
password = raw_input("please input you password:")
message = ''' Information of the company staff:
Name: %s
Age : %d
Sex : %s
Dep : %s
''' % (name, age, sex , dep)
print message
if name != true_name:
print "you input name is error!"
else:
print "you input name is ",name," is right!"
if password != true_password:
print "you input password is error!"
else:
print "you input password is ",password," is right!"
if age < 28 :
print "Congratulations! you've got half day's public holiday!"
elif age == 28:
print "As you are at the right age, i am think about to give 2 hours holiday!"
else:
print "Sorry, you are too old to have this holiday! get back to work!"
print "hello, ",name,"\n"
print "you are ",age,"years old!"
print "so you were born in: ", this_year - age