私信  •  关注

marcos

marcos 最近回复了
3 年前
回复了 marcos 创建的主题 » 如何在Python中将文本作为水印垂直打印到图像上

将图像顺时针旋转90°,添加文本,然后将图像旋转回原始位置。

# Rotate 90º clockwise
img_rot = cv2.rotate(img1 , cv2.ROTATE_90_CLOCKWISE)
# Add your text here, adjusting x and y coordinates to the new orientation.
#   The new adjusted coordinates will be:
#   (x2, y2) = (original_height - y, x)
# [...]
# Rotate back
img1 = cv2.rotate(img_rot, cv2.ROTATE_90_CLOCKWISE)
5 年前
回复了 marcos 创建的主题 » Python代码只打印以A开头的字母[副本]

只需使用 startswith

w = ["Algorithm", "Logic", "Filter", "Software", "Network", "Parameters", "Analyze", "Algorithm", "Functionality", "Viruses"]

for word in w:
    if word.startswith('A'):
        print(word)

>>> Algorithm
>>> Analyze
>>> Algorithm

编辑:因为你不能使用 开始使用

for word in w:
    if word[0] == 'A':
        print(word)
5 年前
回复了 marcos 创建的主题 » 在Python 3中通过for循环使用用户输入填充列表

C++ 您需要首先定义数组大小,在 python 蟒蛇 我会写类似这样的代码(我补充道 print 要证明的陈述 a_list 正在增长):

size = int(input("Enter size: "))  # for input 3
a_list = []
for i in range(size):
    a_list.append(input())  # for input 1, 2, 3

print('python list:', a_list)

>>> python list: ['1', '2', '3']

你可以使用 json 如注释中所建议的模块,例如这样的模块应该可以工作:

import json

long_text = '[{"A":"apple"}, {"B":"ball"} , {"c":"cat"}]'
list_of_dicts = json.loads(long_text)
print(list_of_dicts)

>>> [{'A': 'apple'}, {'B': 'ball'}, {'c': 'cat'}]
5 年前
回复了 marcos 创建的主题 » 将变量与多字符串python3进行比较

因为 or 使 if True 如果 tag 不等于 centos 价值观,不管是一个还是全部, and 使 如果 真的 只有当它不同于所有的值。现在写起来更简单:

options = ['centos6', 'centos7', 'centos8']
tag = 'centos6'

if tag not in options:
    ...

这可能是因为默认的python安装是python 2。我认为您应该创建一个虚拟环境并在其上安装psycopg2。这样,您将使用pip3并具有独立的依赖项,这些依赖项不会与其他版本产生冲突(可能会损坏您的系统):

python3 -m venv ~/.environments/test
source ~/.environments/test/bin/activate
pip install psycopg2