2025-07-03 17:19:20 +08:00

80 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Python
date: 2025-03-10 14:26:30
tags:
---
# pip
## 查看版本
```shell
pip --version
```
## 使用Pip安装Github上的软件包
接下来使用以下命令来安装Github上的软件包
```python
pip install git+https://github.com/username/repository.git
```
## 升级和卸载软件包
要升级软件包,可以使用以下命令:
```python
pip install --upgrade package_name
```
其中,`package_name`是你要升级的软件包的名称。Pip会自动检查版本并安装最新的软件包。
如果你想卸载已安装的软件包,可以使用以下命令:
```python
pip uninstall package_name
```
Pip会询问你是否确定卸载软件包并删除相关的文件。
# Python __name__
首先需要了解 __name__ 是属于 python 中的内置类属性,就是它会天生就存在于一个 python 程序中,代表对应程序名称
```python
import requests
class requests(object):
def __init__(self,url):
self.url=url
self.result=self.getHTMLText(self.url)
def getHTMLText(url):
try:
r=requests.get(url,timeout=30)
r.raise_for_status()
r.encoding=r.apparent_encoding
return r.text
except:
return "This is a error."
print(__name__)
```
结果:
```shell
__main__
Process finished with exit code 0
```
当这个 pcRequests.py 作为模块被调用时,则它的 __name__ 就是它自己的名字:
```python
import pcRequestspcRequestsc=pcRequestsc.__name__
```
结果:
```shell
'pcRequests'
```