2.函数转化为模块setup(
name = 'nester',version ='1.0.0',py_modules =['nester'],auther ='a'
auther_email ='a@s'
description =''
)
setup.py install
<p ><span >linux:python2.7 setup.py sdist upload
<p ><span >windows:C:\Python27\python.exe <span >setup.py sdist upload
<p ><span ><span >6.deBUG过程
<p ><span ><span >import模块报错,主要有以下错因:
<p ><span ><span >(1)汉字注释。解决:开头添加#Coding: utf-8
<p ><span ><span >(2)书上用python3,实际用python2.7.在同行输出有问题
<p ><span ><span ><span >Python
2
Python 2.7.6
Hello,World!
Hello,World!
text print more text on the same line
<span >Python 3<span >
<code >print('Python',python_version())<span >(3)nameError:
print('Hello,World!')
print("some text,",end="")
print(' print more text on the same line')结果Python 3.4.1
Hello,World!
some text,print more text on the same lineprint 'Hello,World!'
报错file "@H_301_113@",line 1
print 'Hello,World!'
^
SyntaxError: invalID Syntax
name 'sys' is not defined<span ><span >解决:import sys<span ><span >代码更改为:<span >
<code ><pre name="code" >#Coding: utf-8
import sys
def print_lol(the_List,fh=sys.stdout):
"""
格式化输出列表(包含嵌套和非嵌套列表),一次显示一行,嵌套列表可以缩进
indent:是否缩进;level:tab缩进个数;fh为写入文件地址,默认显示到屏幕
"""
for eachitem in theList:
if isinstance(each_item,fh)
else:
if indent:
for tab_stop in range(level):
file=fh
print "\t",;print file
file=fh
print(each_item,file)
导入成功:
总结
以上是内存溢出为你收集整理的《head first python》— 函数定义、模块与发布、共享代码全部内容,希望文章能够帮你解决《head first python》— 函数定义、模块与发布、共享代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)