我正在尝试运行下面的简单代码片段
port = int(os.getenv('PORT'))
print("Starting app on port %d" % port)
Run Code Online (Sandbox Code Playgroud)
我可以理解 PORT 是 s 字符串,但我需要转换为 int。为什么我收到错误
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Run Code Online (Sandbox Code Playgroud) 我们\xe2\x80\x99在生产中面临一个奇怪的问题,其中一个应用程序陷入终止和同步状态。
\nArgoCD版本:2.1.7
\n背景:
\n我们手动终止了应用程序的同步,现在应用程序陷入终止同步状态,并且禁用自动同步按钮也不起作用。
\n注意:\n使用类似的配置创建一个新应用程序是可行的,但我们想调查当前应用程序卡住的原因。
\n执行的步骤:
\n已尝试的命令
\nargocd app terminate-op APPNAME\nargocd app sync APPNAME\nargocd app sync APPNAME --force --prune \n
Run Code Online (Sandbox Code Playgroud)\n一些日志(不确定这些是否相关):
\ntime="2022-01-07T16:19:36Z" level=debug msg="Failed to apply normalization: error in remove for path: \'/spec/preserveUnknownFields\': Unable to remove nonexistent key: preserveUnknownFields: missing value"\ntime="2022-01-07T16:19:36Z" level=debug msg="Failed to apply normalization: error in remove for path: \'/status\': Unable to remove nonexistent key: …
Run Code Online (Sandbox Code Playgroud) 假设我有一个如下所示的元组列表:
a = [('a','b'), ('c','d'), ('e','f')]
如果我要执行这一行,'a' in a
我会得到False
.
有没有办法告诉python“只搜索第一个参数并接受第二个参数”?
这样我就可以搜索类似的东西('a', *) in a
并得到True
?
我正在处理 presto sql 并被卡住了。
我想将列变成新行并保存值。
例如:
前
NAME COMDEDY HORROR ROMANCE
brian 10 20 14
tom 20 10 11
Run Code Online (Sandbox Code Playgroud)
后
NAME GANRE RATING
brian comedy 10
brian horror 20
brian romance 14
tom comedy 20
tom horror 10
tom romance 11
Run Code Online (Sandbox Code Playgroud)
如果我不能用 prestodb 做到这一点,我至少需要用 python pandas 做到这一点
谢谢!
我有一本字典的字典,如下所示:
d = {0: {1: ["hello"], 2: ["How are you"]}, 1: {1: ["!"], 2: ["?"]}}
Run Code Online (Sandbox Code Playgroud)
我希望它采用所需的格式:
result = {1:["hello", "!"], 2: ["How are you", "?"]}
Run Code Online (Sandbox Code Playgroud)
但是,我使用以下代码以以下格式获得此信息:
new_d = {}
for sub in d.values():
for key, value in sub.items():
new_d.setdefault(key, []).append(value)
Run Code Online (Sandbox Code Playgroud)
结果不具有所需的结构,并且会导致列表的列表。
{1: [['hello'], ['!']], 2: [['How are you'], ['?']]}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。谢谢。
我有这个 Python 程序:
#! python3
# random_quiz_generator.py - Creates quizzes with questions and answers in random order, along with the answer key.
import random
# The quiz data. Keys are states and values are their capitals
capitals = {'Alabama': 'Montgomery',
.......
'Wyoming': 'Cheyenne'
}
# Generate 35 quiz files
for quiz_num in range(35):
# create the quiz and answer key files
quiz_file = open(f'capitalsquiz{quiz_num + 1}.txt', 'w')
answer_key_file = open(f'capitalsquiz_answers{quiz_num +1}.txt', 'w')
# write out the header for the quiz …
Run Code Online (Sandbox Code Playgroud) 我已经实现了以下代码来从维基百科页面提取数据
import bs4
import sys
import requests
res = requests.get('https://en.wikipedia.org/wiki/Agriculture' )
res.raise_for_status()
wiki = bs4.BeautifulSoup(res.text,"html.parser")
for i in wiki.select('p'):
print(i.getText())
Run Code Online (Sandbox Code Playgroud)
该代码根据我的需要从页面中提取所有数据。但是我想使用 Python 将其存储在文本文件中,但我无法做到。该文本文件的名称应为“Agriculture”(如果从 URL 本身中提取该名称则更好,以便可以在多个 wiki 页面上使用)。
我基本上需要以下格式的字典字典:
cable_footage = {"AER": {144: len1, 48: len2, 24: len3}, "UG": {144: len1, 48: len2, 24: len3}}
Run Code Online (Sandbox Code Playgroud)
这段代码是我到目前为止所拥有的:
cable_footage = defaultdict(dict)
for placement in ("AER", "UG"):
for size in (144, 48, 24):
cable_footage[placement][size] = 0.0
for cable in adss_layer.features:
if cable.data["Placement"] == "AER":
if cable.data["Size"] == 144:
cable_footage["AER"][144] += cable.data["Length"]
if cable.data["Size"] == 48:
cable_footage["AER"][48] += cable.data["Length"]
if cable.data["Placement"] == "UG":
if cable.data["Size"] == 144:
cable_footage["UG"][144] += cable.data["Length"]
if cable.data["Size"] == 48:
cable_footage["UG"][48] += cable.data["Length"]
Run Code Online (Sandbox Code Playgroud)
但是,我希望能够以这种方式简化/概括它,因为上面的代码很长且非 Pythonic:
for cable in …
Run Code Online (Sandbox Code Playgroud) python ×7
list ×3
python-3.x ×3
dictionary ×2
io ×2
argo ×1
argocd ×1
defaultdict ×1
file ×1
getenv ×1
pandas ×1
presto ×1
sql ×1
tuples ×1
unpivot ×1
web-scraping ×1