print(customer_ids)只输出一列列表,怎么处理
时间: 2024-02-20 15:56:24 浏览: 72
PHP中的print_r 与 var_dump 输出数组
5星 · 资源好评率100%
可以考虑使用 `numpy` 库中的 `reshape` 方法对列表进行重塑,将其变成多行多列的形式,这样输出时就会更易于观察。代码如下:
```
import numpy as np
url = f"http://192.168.0.2:8900/api/crmCustomer/list?page=0&size=20&sort="
headers = {"Content-Type": "application/json", "Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJjbGllbnRUeXBlIjoicGMiLCJmdWxsTmFtZSI6IkNFUzIiLCJ1c2VyTmFtZSI6IjE1Mjk0NzYyNTE2IiwidXNlcklkIjoiMTAwMDg5IiwiYXV0aExldmVsIjoiMSIsImFjY291bnQiOiIxNTI5NDc2MjUxNiIsImV4cCI6MTY4NTQxNzMwOCwianRpIjoiYTc1ZjYzYmZmMjRjNGU4NDhmZGQ3Yjg0N2JkZWZhMWEiLCJ1c2VyIjoiMTUyOTQ3NjI1MTYiLCJzdWIiOiIxNTI5NDc2MjUxNiJ9.hwxPnkCe-B7hYM0eJUEG6a6_b-czsXLo8398uM8B2O3CfXqQrhFoevOrTVbMNgpDARk9aikXH6PLIjTx6U9MrA"}
data = {
"page": 0,
"size": 20,
"sort": "",
"queryType": 1
}
r = requests.post(url=url, headers=headers, data=json.dumps(data))
customer_ids = []
for i in range(20):
customer_id = r.json()["data"]["content"][i]["customerId"]
customer_ids.append(customer_id)
customer_ids = np.array(customer_ids)
customer_ids = customer_ids.reshape((-1, 5)) # 将列表变成5列
print(customer_ids)
```
这样就会将列表变成 5 列,输出时会更加清晰。如果希望将列表变成其他列数,只需要将 `reshape` 中的参数改为对应的列数即可。
阅读全文