在Python 3.9.10替补中测试:
>>> currency = 'د.إ'
>>> price = '9.99'
>>> print(currency)
د.إ
>>> print(price)
9.99
>>> print(currency, price)
د.إ 9.99
我发现了另一个引起此问题并已经解决的问题。我不小心将脚本保存在utf-16
编码中。 PHP5似乎无法识别<?php
在16位中默认编码的标签。
之所以失败的原因是您使用的Mac使用的flutter版本3具有更改窗口小部件绑定的更改,即不需要使用不使用的限制?在小部件绑定中。包装百分比指示器不摇动3兼容。请将版本更改为percenter_indicator: ^4.2.2
flutter 3兼容。进行清洁和POD安装,它应该可以工作
编辑
清洁酒吧缓存您可以运行flutter Pub Cache Clean
请注意,这将清除所有您的酒吧缓存,然后您可能必须经营Flutter Pub参加所有项目
我解决了这个问题。 页面上工作代码
在此处在app.route函数的
if turbo.can_stream():
return turbo.stream(
turbo.replace(render_template('doc_cards.html', data=data), target='load_cards'))
else:
return render_template('home.html', form=search_form, data=data)
将在其中更新内容
<div class="container">
{% with data=data %}
{% include "doc_cards.html"%}
{% endwith %}
</div>
和动态内容
<div id="load_cards" class="container">
{% if data is defined %}
{% for item in data %}
.......
{% endfor %}
{% endif %}
</div>
pynput
没有is_presse()
- 我不知道您在哪里找到它。
您应该使用pynput.keyboard.listener
在按下q
时运行代码结束程序。
您不能有两个具有相同名称控制器
的对象。
一个控制器
替换其他控制器
,然后您使用相同的Controller
来创建鼠标
键盘代码> - 这使问题问题。
您必须使用pynput.mouse.controller
和pynput.keyboard.pynput.controller
import pynput
from pynput.mouse import Button
from pynput.keyboard import Key
import time
keyboard = pynput.keyboard.Controller()
mouse = pynput.mouse.Controller()
while True:
time.sleep(10)
mouse.click(Button.left)
#if keyboard.is_pressed('q'): # <-- this will need Listener()
# break
编辑:
在q 您必须使用
侦听器
例如:
import pynput
from pynput.mouse import Button
import time
mouse_controller = pynput.mouse.Controller()
def on_press(key):
print('pressed:', key)
if str(key) == "'q'": # it has to be with `' '` inside `" "`
# Stop listener
print("exit listener")
return False # `False` ends listener
with pynput.keyboard.Listener(on_press=on_press) as keyboard_listener:
while keyboard_listener.is_alive():
time.sleep(10)
mouse_controller.click(Button.left)
print('clicked')
您可以尝试在非全局模式下使用替换()
进行正则替换,因此,这将仅针对输入字符串中的第一匹匹配。
var input = "XX XXXX XX XXX";
var output = input.replace(/ \w+/, " YYYY");
console.log(output);
尝试使用dyplr :: rename()或在if_else()的最终消除na中替换为“”无空间。
您的问题并没有真正连接到TKINTER和GUI编程。您需要多线程或多处理。有效的解决方案取决于您想做什么。您可以看到有关选择多线程/多处理的以下页面: this 和
=“ nofollow noreferrer 对我来说并不清楚水晶,但我试图在答案中尽力而为。
您可以在下面看到一个测试代码,而无需任何并行性,因此它不是您的解决方案。
代码:
"""
Example script for data processing
"""
def call_main_script(ip_adr_str, processes_dict):
"""
Print the data structure for testing.
Args:
ip_adr_str: The IP address as string to define the dict key.
processes_dict: The dict data structure
Returns: None
"""
# Get the key-values based on the given IP address
for key, value in processes_dict[ip_adr_str].items():
print("{} -> {}".format(key, value))
print("\n\n")
class DummyCheckBox:
"""
A Dummy class for simulate the CheckBox widget of TK.
"""
def __init__(self, number_of_box):
"""
The constructor of DummyCheckBox
Args:
number_of_box: Input parameter of "widget"
"""
self.number_of_box = number_of_box
def get(self):
"""
Provides some dummy value (Class name and the input value...).
Returns: Dummy str.
"""
return "{}_{}".format(self.__class__.__name__, self.number_of_box)
class DummyName:
"""
A Dummy class for simulate the Input widget of TK.
"""
def __init__(self, name_input):
"""
The constructor of DummyName
Args:
name_input: Input parameter of "widget"
"""
self.name = name_input
def get(self):
"""
Provides some dummy value (Class name and the input value...).
Returns: Dummy str.
"""
return "{}_{}".format(self.__class__.__name__, self.name)
# Creating the instances from the Check Box class.
dummy_check_box_1 = DummyCheckBox(1)
dummy_check_box_2 = DummyCheckBox(2)
dummy_check_box_3 = DummyCheckBox(3)
# Creating the instances from the Name widget class.
dummy_name_1 = DummyName("FOO")
dummy_name_2 = DummyName("BAR")
dummy_name_3 = DummyName("BAZ")
processes = {}
# Put the instances to lists.
check_boxes = [dummy_check_box_1, dummy_check_box_2, dummy_check_box_3]
names = [dummy_name_1, dummy_name_2, dummy_name_3]
# You can process the lists in ony for loop with the "zip" function.
for check_box, name in zip(check_boxes, names):
if check_box.get():
processes["192.168.x.xx"] = {
"name": name.get(),
"ip": "dummy_ip",
"enable_disable": check_box.get(),
"email": "dummy_mail",
"email_address": "dummy_adress",
}
call_main_script("192.168.x.xx", processes)
输出:
>>> python3 test.py
name -> DummyName_FOO
ip -> dummy_ip
enable_disable -> DummyCheckBox_1
email -> dummy_mail
email_address -> dummy_adress
name -> DummyName_BAR
ip -> dummy_ip
enable_disable -> DummyCheckBox_2
email -> dummy_mail
email_address -> dummy_adress
name -> DummyName_BAZ
ip -> dummy_ip
enable_disable -> DummyCheckBox_3
email -> dummy_mail
email_address -> dummy_adress
以下示例包含多线程解决方案。我已经评论了代码中所有更改的位置。
代码:
"""
Example script for data processing
"""
import threading
import random
import time
def call_main_script(processes_dict):
"""
Print the data structure for testing.
Args:
processes_dict: The dict data structure
Returns: None
"""
# Get a random integer between 1-5 and sleep it in secs.
random_sleep = random.randint(1, 5)
time.sleep(random_sleep)
print(
"[{}] ({} secs slept) name -> {}".format(
threading.current_thread().name, random_sleep, processes_dict["name"]
)
)
class DummyCheckBox:
"""
A Dummy class for simulate the CheckBox widget of TK.
"""
def __init__(self, number_of_box):
"""
The constructor of DummyCheckBox
Args:
number_of_box: Input parameter of "widget"
"""
self.number_of_box = number_of_box
def get(self):
"""
Provides some dummy value (Class name and the input value...).
Returns: Dummy str.
"""
return "{}_{}".format(self.__class__.__name__, self.number_of_box)
class DummyName:
"""
A Dummy class for simulate the Input widget of TK.
"""
def __init__(self, name_input):
"""
The constructor of DummyName
Args:
name_input: Input parameter of "widget"
"""
self.name = name_input
def get(self):
"""
Provides some dummy value (Class name and the input value...).
Returns: Dummy str.
"""
return "{}_{}".format(self.__class__.__name__, self.name)
# Creating the instances from the Check Box class.
dummy_check_box_1 = DummyCheckBox(1)
dummy_check_box_2 = DummyCheckBox(2)
dummy_check_box_3 = DummyCheckBox(3)
# Creating the instances from the Name widget class.
dummy_name_1 = DummyName("FOO")
dummy_name_2 = DummyName("BAR")
dummy_name_3 = DummyName("BAZ")
# This list will contain the dict structures.
processes = []
# Put the instances to lists.
check_boxes = [dummy_check_box_1, dummy_check_box_2, dummy_check_box_3]
names = [dummy_name_1, dummy_name_2, dummy_name_3]
# You can process the lists in ony for loop with the "zip" function.
for check_box, name in zip(check_boxes, names):
if check_box.get():
# Creating the dict data structure.
data_structure = {
"name": name.get(),
"ip": "dummy_ip",
"enable_disable": check_box.get(),
"email": "dummy_mail",
"email_address": "dummy_adress",
}
# Append the actual dict data structure to the process list.
processes.append(data_structure)
# Creating the list for the started threads. We will wait the threads based on this list.
threads = []
# Creating threads for the dict data structures.
for single_dict in processes:
# Creating the thread which calls the "call_main_script" function with "single_dict" argument.
t = threading.Thread(target=call_main_script, args=(single_dict,))
# Start the actual thread.
t.start()
# Append the Thread object to the list.
threads.append(t)
# Join (Stop) the Threads one-by-one.
for t in threads:
# Wait until thread is completely executed
t.join()
print("Done!")
输出:
>>> python3 test.py
[Thread-3] (1 secs slept) name -> DummyName_BAZ
[Thread-1] (2 secs slept) name -> DummyName_FOO
[Thread-2] (5 secs slept) name -> DummyName_BAR
Done!
您可以在上面的输出部分中看到3个不同的DICE数据结构在3个线程上启动。我添加了一个随机的(1-5秒)睡眠以更好地表示。
尝试Vanilla JavaScript:
.setAttribute('required', true/false);
.removeAttribute('required');
.toggleAttribute('required');
如果您在jQuery对象上使用Vanilla JavaScript方法,它将无法识别它。因此,您要么使用JavaScript方法引用元素(推荐)或退参考jQuery对象:
// Two ways to de-referencing a jQuery object
$('input')[0]
//OR
$('input').get(0)
零表示您仅针对第一个目标,因此,如果您已经知道这是第二个输入使用索引1。
// Using no ids, classes, or tagnames just indexes
document.forms[0].elements[1].onclick = e =>
e.target.previousElementSibling.toggleAttribute('required');
// De-referencing the second .data
$('.data')[1].setAttribute('required', true);
[required] {
outline: 3px dashed red
}
<form>
<input name='data' class='data'><input type='button' value='Toggle'><br>
<input name='data' class='data'><br>
<button>Submit</button>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
只是一些建议,您要删除的属性通常不会因为其性质而被删除。 占位符
永远不需要删除,因为当用户专注于表单控件时,它会消失。 必需的
不应删除,因为它有助于验证。您为什么需要删除它们?
当查询在SQL Shell外面不需要半隆时,这很常见。通常它们需要,但不是强制性的。例如,在python脚本中启动SQL查询时,没有必要以;
结束查询,因为Shell不需要知道何时结束。取而代之的是,在SQL外壳中,您可以按件编写查询。
您的数据
CREATE TABLE test(
ID INTEGER NOT NULL
,Month VARCHAR(40) NOT NULL
);
INSERT INTO test
(ID,Month) VALUES
(0,'Mar'),
(1,'July'),
(2,'Jun'),
(3,'Aug');
由于月
列类型未明确表示为
Select name, alias, months, shortmonths
from sys.syslanguages
where name='us_english'
姓名 | 别名 | 月份 | 1月,2月,3月,4月,五月,五月,六月,七月,八月,九月,10月 |
---|---|---|---|
us_english | 英语 | ,10月,11月,12月,12月,1月 | 1月, ,4月,5月,6月,7月,8月,10月,11月,12月,12月,1月1月1 |
月
5 | 月 |
---|---|
月 | 月 |
6 | ,3月 |
1月1月2月2月3月3月4月4月4 | 月 |
5 | 月7月7月8月8月8月 |
8 | 1 |
月 | 月 |
1 | 月8月10月10月10 |
1 | 月10月 |
10 | 月10 |
月12月12 | 月 |
12月12 | 月 |
12 | 月12月 |
通过使用string_split
,row_number
SELECT shortmonth,
fullname
FROM (SELECT NAME,
alias,
months,
shortmonths,
a.value AS shortmonth,
Row_number()
OVER (
ORDER BY (SELECT NULL)) rn
FROM (SELECT NAME,
alias,
months,
shortmonths
FROM sys.syslanguages
WHERE NAME = 'us_english') b
CROSS apply String_split(shortmonths, ',') a) t1
JOIN (SELECT NAME,
alias,
months,
shortmonths,
c.value fullName,
Row_number()
OVER (
ORDER BY (SELECT NULL)) rn
FROM (SELECT NAME,
alias,
months,
shortmonths
FROM sys.syslanguages
WHERE NAME = 'us_english') b
CROSS apply String_split(months, ',') c) t2
ON t1.rn = t2.rn
在cte
中使用上述查询,并与您的表一起使用前三个左
wargin和然后使用eomonth
和正确的
函数如下所示,
SELECT t.*,
m.fullname,
RIGHT(Eomonth(( '01-' + m.fullname + '-2010' )), 5)
FROM test t
JOIN monthname1 m
ON LEFT(t.month, 3) = m.shortmonth
但是使用适当的年份不应忽略leap年的适当年份。
这里有多个问题。 要点
将尝试突出 1的 进行了反应性API的重构?
。从第一个外观看,您的应用程序是IO绑定的,并且反应性应用程序通常更有效地 反应性应用程序不会更快,但是您需要更少的资源来解决唯一的警告是,为了从反应性API中获得所有收益,您的应用程序应该是反应性的端到端(DB的反应驱动程序,反应性网络电机,…) 。所有反应性逻辑均在
schedulers.parallel()
上执行,并且您需要少量线程(默认情况下,CPU内核数)才能执行非阻滞逻辑。通过将它们“卸载”到schedulas.boundedelastic()
中,仍然可能使用阻止API,但是应该是一个例外(不是规则),以提高您的应用程序效率。有关更多详细信息,请检查磁通3的飞行 - 跳线和调度程序。2。
看起来像是对阻止API有些误解。这不是关于响应时间,而是关于强调API。默认情况下,Spring WebFlux使用反应堆Netty作为基础HTTP客户端库,它本身就是Netty客户端的反应性实现,该实现使用事件循环而不是每个请求模型。即使请求需要30-60秒才能获得响应,也不会阻止线程,因为所有IO操作都是异步。对于此类API,反应性应用程序的行为会好得多,因为对于非反应性(每个请求线程),您将需要大量线程,并且结果更多的内存才能处理相同的工作负载。
为了量化效率,我们可以应用 Little's Ward 来计算A“传统”中所需的线程数量线程每个请求模型
工人&gt; = totup x延迟
,其中工人
- 线程数量例如,要处理具有30秒延迟的100 QP,我们需要100 x 30 = 3000个线程。在反应性应用程序中,相同的工作负载只能由几个线程处理,因此,内存更少。为了伸缩性,这意味着对于IO绑定的反应应用程序,通常您通常会通过CPU使用和“传统”进行扩展。
有时候,什么代码在阻止哪些代码并不明显。测试反应代码时的一个非常有用的工具是 blockhound 您可以将其集成到单元测试中。
3。如何重构?
我会逐层迁移,但只阻止一次。将远程调用转移到网络电机可能是重构应用程序的第一步,以进行反应性API。我将使用反应性API创建所有请求/响应逻辑,然后在最高级别(例如,在控制器中)阻止(如果需要)。做和不做:避免避免首次反应性程序员矿山是一个很好的概述。常见的陷阱和可能的迁移策略。
4。通量与单声道。
flux
不会帮助您提高性能。更多的是下游逻辑。如果您处理记录录制 - 使用flux&lt; t&gt;
,但是如果您分批处理数据 - 使用mono&lt; list&lt; t&gt;&gt;&gt;
。您当前的代码并不是真正的反应性,并且很难理解混合反应性API,流动API并多次阻止。作为第一步,尝试使用反应性API将其重写为单个流,并且仅阻止一次。
不太确定您的内部类型,但这里有一些骨架可以使您了解该流程。
如前所述,尝试将内部API保持反应式返回
单声道
或flux
,并且在上层中仅阻止一次。There are multiple questions here. Will try to highlight main points
1. Does it make sense refactoring to Reactive API?
From the first look your application is IO bound and typically reactive applications are much more efficient because all IO operations are async and non-blocking. Reactive application will not be faster but you will need less resources to The only caveat is that in order to get all benefits from the reactive API, your app should be reactive end-to-end (reactive drivers for DB, reactive WebClient, …). All reactive logic is executed on
Schedulers.parallel()
and you need small number of threads (by default, number of CPU cores) to execute non-blocking logic. It’s still possible use blocking API by “offloading” them toSchedulers.boundedElastic()
but it should be an exception (not the rule) to make your app efficient. For more details, check Flight of the Flux 3 - Hopping Threads and Schedulers.2. Blocking vs non-blocking.
It looks like there is some misunderstanding of the blocking API. It’s not about response time but about underlining API. By default, Spring WebFlux uses Reactor Netty as underlying Http Client library which itself is a reactive implementation of Netty client that uses Event Loop instead of Thread Per Request model. Even if request takes 30-60 sec to get response, thread will not be blocked because all IO operations are async. For such API reactive applications will behave much better because for non-reactive (thread per request) you would need large number of threads and as result much more memory to handle the same workload.
To quantify efficiency we could apply Little's Law to calculate required number of threads in a ”traditional” thread per request model
workers >= throughput x latency
, whereworkers
- number of threadsFor example, to handle 100 QPS with 30 sec latency we would need 100 x 30 = 3000 threads. In reactive app the same workload could be handled by several threads only and, as result, much less memory. For scalability it means that for IO bound reactive apps you would typically scale by CPU usage and for “traditional” most probably by memory.
Sometimes it's not obvious what code is blocking. One very useful tool while testing reactive code is BlockHound that you could integrate into unit tests.
3. How to refactor?
I would migrate layer by layer but block only once. Moving remote calls to WebClient could be a first step to refactor app to reactive API. I would create all request/response logic using reactive API and then block (if required) at the very top level (e.g. in controller). Do’s and Don’ts: Avoiding First-Time Reactive Programmer Mines is a great overview of the common pitfalls and possible migration strategy.
4. Flux vs Mono.
Flux
will not help you to improve performance. It’s more about downstream logic. If you process record-by-record - useFlux<T>
but if you process data in batches - useMono<List<T>>
.Your current code is not really reactive and very hard to understand mixing reactive API, stream API and blocking multiple times. As a first step try to rewrite it as a single flow using reactive API and block only once.
Not really sure about your internal types but here is some skeleton that could give you an idea about the flow.
As I mentioned before, try to keep internal API reactive returning
Mono
orFlux
and block only once in the upper layer.Spring WebFlux:用反应性API重构阻止API,还是我应该?