python打印print彩色信息&pypi上传自己的python包
python打印print彩色信息 print-with-color
安装包
pip install print-wcolor==0.0.8
使用print_wcolor可以打印出彩色字体和彩色背景 使用示例
from print_wcolor import print_wcolor
a=[1,2,3,4]
c={}
c["r"]=255
c["g"]=255
print("*"*20)
print_wcolor("i think","therefor i am",a,c,fg="red",bg="green")
print("*"*20)
print_wcolor("i think","therefor i am",a,c,fg="red")
print("*"*20)
print_wcolor("i think","therefor i am",a,c,bg="green")
print("*"*20)
print_wcolor("i think","therefor i am",a,c)
其中"i think,therefor i am"是要打印的信息,fg是字体颜色,bg是背景颜色。 关键词fg选项如下
{"black","red","green","yellow","blue","purple","cyan","white"}
关键词bg选项如下
{"black","red","green","yellow","blue","purple","cyan","white"}
pypi上传自己的包
主要参考了博客
1 注册账号
地址
2 创建python包
参考资料 本项目如下:
├── LICENSE
├── print_wcolor
│ ├── __init__.py
│ └── print_wcolor.py
├── README.md
└── setup.py
init.py
这一步很关键,否则安装好之后,你导入不了包。
from .print_wcolor import print_wcolor
setup.py
这个是粘贴别人的,不是很懂,照做就行。
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="print_wcolor",
version="0.0.8",
author="xxx",
author_email="xxx@qq.com",
description="print_wcolor",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/wanggaoping/print_wcolor.git",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
LICENSE
也是粘贴别人的。
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 打包Python包
python3 setup.py sdist bdist_wheel
4 上传Python包
twine upload dist/*
5 更新包
删除打包时产生的编译文件,把setup.py里面的version改一下,再打包、上传即可。
error
其中在遇到一个错误
Invalid or non-existent authentication information
看别的博客都是在home目录下新建~/.pypirc,里面内容如下:
[distutils]
index-servers=pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = xxxxxx
password = 123456
我这样做了依然错误,参考官网教程 里面内容应该是这样
[pypi]
username = xxxxxx
password = 123456
注意最后一行password = 123456后面不要有换行符号。
|