python27使用
❶ python27是什么
python目前主要分为2.x和3.x两种版本,3.x属于新版本,与2.x有些不兼容,所以目前使用2.x的人还是占大多数,python27是指python2.7版本,属于2.x最新版本
❷ 新手求救python高手..我用的是python27..
两个问题的代码都帮你写出来了,其中都有“输入的合法性校验”,这样可以提高程序的健壮性。
有不明白的地方可以继续提问。
问题(2):
def initList():
'Function : initList for initing the list for program.'
theList=['','','','','',.......................] # Init your list for this program.
return theList
def outPut(List):
'Function : output the result for client.'
while True:
print('-'*50)
Choice=input("Please input the number : ").strip()[0]
if int(Choice) in range(len(List)):
break
else:
print("Please input your choice again!")
print("The result is ",end=':')
print(List[int(Choice)])
def Main(theList):
'Function : main function of this program.'
List=theList
while True:
outPut(List)
Main(initList()) # Running program.
问题(3):
def initVar():
'Function: init dic for setting a,b and c.'
var={'a':None,'b':None,'c':None}
for v in var:
while True:
value=input("Please input %s :"%v).strip()[0]
try:
NumValue=float(value)
var[v]=NumValue
break
except Exception as e:
print("There is Error ",end=':')
print(e)
print("Please input again!")
print("Finish initing var.")
return var
def Calculate(var):
'Function: calculate equation.'
theVar=var
NumX=0.0
print("The equation is :")
print("y=%fx^2+%fx+%f"%(theVar['a'],theVar['b'],theVar['c']))
while True:
x=input("Please input X : ")
try:
NumX=float(x)
break
except Exception as e:
print("There is Error is ",end=':')
print(e)
print("Please input X again :")
y=NumX*NumX*theVar['a']+NumX*theVar['b']+theVar['c']
return y
def Main():
'Function: main.'
y=Calculate(initVar())
print("The result is : %f ."%y)
Main() #Running program
❸ 如何使用python 2.7.10 内置pip安装package
python使用内置的pip安装package很简单,以WINDOWS下使用为例说明,使用命令pip install 包名即可。
1、在命令行下切换到python目录,一般为c:\python27,pip在python安装目录的Scripts目录下,命令如下:
cd c:\python27\scripts
2、切换到目录之后直接使用命令安装即可,命令如下,例如要安装flask,则使用:
pip insatll flask
3、其它说明,如果卸载包则使用pip uninstall 包名 来卸载包,以下为pip参数说明:
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring
environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be
used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output.
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form
[user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should
attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup.
--trusted-host <hostname> Mark this host as trusted, even though it does
not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
4、注意事项,如果在windows下安装失败提示:Unable to find vcvarsall.bat,则说明这个包需要编译,则要在WINDOWS系统中安装visual studio 2008。
5、linux下pip安装package与WINDOWS的语法相同,使用pip install SomePackage
即可,linux下需要注意的是权限问题,应当使用root用户执行命令。
❹ python2.7自带的pip怎么用
目录如下:
C:Python27Libsite-packagespip
配置内容:
[global]
index-url =http://pypi.douban.com/simple
在powershell中输入pip install nose后仍从官方源下载文件,并连接超时失败
后改为直接在powershell中输入命令,结果如下:
❺ python 27 可以使用ttfont这个库吗
你好reportlab有这个ttfont的库。他们同时也支持这个python2.7,你可以试试。
❻ 求助大神,在c盘Python27文件夹中存了这个数组txt,然后怎么能在Python中读取这个数组
open和括号之间不能有空格,采用以下语句更好:
with open('xxx.txt') as f:
L=f.readlines()
❼ python27下怎么用sqlite3
肯定不是放在Lib目录下的,好像放在python目录下就可以了。具体记不清楚了,好久以前用过,楼主可以尝试下
刚亲自尝试了下
如果楼主用的是python2.7的话,还需要下载一个python和数据库sqlite的接口pysqlite-2.6.3.win32-py2.7这个要安装。
数据库sqlite从网上下载后,直接把EXE文件放在C:/PTHON27 目录下就可以了。