好的,初学者:
我如何实现以下目标:
到目前为止,我有以下内容:
#!/bin/bash
# File to consider
FILENAME=./testfile.txt
# MAXSIZE is 5 MB
MAXSIZE = 500000
# Get file size
FILESIZE=$(stat -c%s "$FILENAME")
# Checkpoint
echo "Size of $FILENAME = $FILESIZE bytes."
# The following doesn't work
if [ (( $FILESIZE > MAXSIZE)) ]; then
echo "nope"
else
echo "fine"
fi
Run Code Online (Sandbox Code Playgroud)
使用此代码,我可以在变量$ FILESIZE中获取文件名,但我无法将其与固定的整数值进行比较.
#!/bin/bash
filename=./testfile.txt
maxsize=5
filesize=$(stat -c%s "$filename")
echo "Size of $filename = $filesize bytes."
if (( filesize > maxsize )); then
echo "nope"
else …Run Code Online (Sandbox Code Playgroud) 我的 FastAPI 应用程序有以下 Pydantic 架构。
在以下架构中,每当我将其ParameterSchema作为 的架构验证器时params,它都会出现以下错误:
fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'typing._GenericAlias'> is a valid pydantic field type
Run Code Online (Sandbox Code Playgroud)
我不知道发生了什么事!
class ParameterSchema(BaseModel):
expiryDate = Optional[datetime]
class Config:
arbitrary_types_allowed = True
class RequestProvisioningEventData(BaseModel):
some_attribute: List[str]
other_attribute: Optional[List[str]] = []
bool_attribute: bool
params: ParameterSchema
class Config:
use_enum_values = True
Run Code Online (Sandbox Code Playgroud) 菜鸟来了
我有一个简单的 python 代码,它应该订阅一个主题并使用 MQTT 协议将 JSON 有效负载发布到同一主题。但是由于某种原因,我无法将有效负载加载为 JSON!
我在这里做错了什么?
# -*- coding: utf-8 -*-
import paho.mqtt.client as mqtt
import json
mqtt_broker = '192.168.1.111'
mqtt_topic_one = 'mqtt_topic/tops_one'
mqtt_topic_two = 'mqtt_topic/tops_two'
json_data_1 = '''{
"this_json": "info",
"data": {
"multi_keyval": {
"1": "1",
"5": "5",
"15": "15"
},
"single_keyval": {
"single_key": "200"
}
}
}'''
def pass_to_func_and_pub(data_to_pub):
print(data_to_pub) # --------> This PRINTS
print(json.loads(data_to_pub)) # --------> This DOES NOT PRINT
# The following two lines don't work either.
unpacked_json = json.loads(data_to_pub)
client.publish(mqtt_topic_two, unpacked_json['this_json']) …Run Code Online (Sandbox Code Playgroud)