我是 Python 的新手,我一生都无法在网上找到我的具体答案。我需要将时间戳格式化为这种确切格式以包含“T”、“Z”,并且没有像这样的 yyyy-mm-ddThh:mm:ssZ 即 2019-03-06T11:22:00Z 的子或毫秒。有很多关于解析这种格式的东西,但没有关于这种格式的内容。我几乎让它工作的唯一方法涉及我不需要的亚秒。我试过使用箭头并阅读他们的文档,但无法获得任何工作。任何帮助,将不胜感激。
Python noob再次出现。我正在尝试创建一个python脚本来自动生成具有多个项目的JSON,但是使用for循环记录多次以生成它们,JSON消息的结构和基数如下:
messageHeader[1]
-item [1-*]
--itemAttributesA [0-1]
--itemAttributesB [0-1]
--itemAttributesC [0-1]
--itemLocaton [1]
--itemRelationships [0-1]
Run Code Online (Sandbox Code Playgroud)
在循环遍历同一对象之前,我已经获得了一些非常好的帮助,但是对于一个记录,例如仅是itemRelationships记录。但是,一旦我尝试创建包含多个项目(即5个)以及itemAttribute,itemLocation和itemRelationships的单个实例的一条消息,由于我不断收到关键错误,因此它不起作用。我试图定义与我尝试执行的操作有关的keyError,但是无法将我正在执行的操作链接到其他示例。
这是我的代码:
import json
import random
data = {'messageID': random.randint(0, 2147483647), 'messageType': 'messageType'}
data['item'] = list()
itemAttributeType = input("Please selct what type of Attribute item has, either 'A', 'B' or 'C' :")
for x in range(0, 5):
data['item'].append({
'itemId': "I",
'itemType': "T"})
if itemAttributeType == "A":
data['item'][0]['itemAttributesA']
data['item'][0]['itemAttributesA'].append({
'attributeA': "ITA"})
elif itemAttributeType == "B":
data['item'][0]['itemAttributesB']
data['item'][0]['itemAttributesB'].append({
'attributeC': "ITB"})
else:
data['item'][0]['itemAttributesC']
data['item'][0]['itemAttributesC'].append({
'attributeC': "ITC"})
pass
data['item'][0]['itemLocation'] …
Run Code Online (Sandbox Code Playgroud) 我正在尝试连接两个列,空格分隔,第一列需要SUBSTR而另一列不需要.我写了这个查询:
SELECT CONCAT(SUBSTR(FIRST_NAME,1,1), ' ',LAST_NAME) AS NAME
FROM OEHR_EMPLOYEES;
Run Code Online (Sandbox Code Playgroud)
然而,我尝试了许多在线搜索,并尝试了不同的方式来让它工作,我不能.我收到很多错误.我想要获得的结果是,例如,如果原始数据是Ray Adams,那么结果将是R Adams.任何帮助,将不胜感激.