当前的答案
可以通过将Discord.py更新为至少 ,通过使用 pip install git+https://github.com/rapptz/discord.py.py
在终端中。
过时的答案
说明
看起来似乎有一个错误。Py.py会导致此错误。在 _CHECK_CAN_RUN
的混合命令中,它使用互动。_baton
作为命令上下文。 Interaction._baton
设置为缺少的前哨值,因此当 discord.py.py.py
试图像常规上下文>上下文> Object一样,它会陷入错误。 。
尽管我不确定任何意外的副作用,但可以简单地修补这一点。只需设置互动。我在两个测试用例中都对其进行了测试,并且它们有效:
代码
@bot.tree.command(name="help", guild=discord.Object(id=703732969160048731))
async def help_command(interaction: discord.Interaction, parameter: str = None):
embed = discord.Embed(title="Test")
cmd = bot.get_command(parameter)
ctx: commands.Context = await bot.get_context(interaction)
interaction._baton = ctx # sketchy, but it works
try:
await cmd.can_run(ctx)
embed.add_field(name="Usable by you:", value="Yes")
except commands.CommandError as exc:
embed.add_field(name="Usable by you:", value=f"No:\n{exc}")
await ctx.send(embed=embed)
我正在寻找比这更好的解决方案:
import sys
import logging
class SomeClass:
def __init__(self) -> None:
self.logger = logging.getLogger(__name__)
H = logging.StreamHandler(sys.stdout)
H.setLevel(logging.INFO)
H.setFormatter(
logging.Formatter(
fmt="[%(asctime)s] %(levelname)s: %(message)s",
datefmt="%d/%m/%Y ( %H:%M:%S )"
))
self.logger.addHandler(H)
def foo(self) -> None:
self.logger.warning("foooo ...")
c = SomeClass()
c.foo()
中有3个条件检查如果名称==“ kevin”或“ jon”或“ inbar”:
- name ==“ kevin”
- “ jon”
- “ inbar”
,此if语句等同于
if name == "Kevin":
print("Access granted.")
elif "Jon":
print("Access granted.")
elif "Inbar":
print("Access granted.")
else:
print("Access denied.")
自<<代码> elif“ jon” 将始终是正确的,因此可以访问任何用户的
解决方案,
下使用任何一种方法
您可以在 fast> fast
if name in ["Kevin", "Jon", "Inbar"]:
print("Access granted.")
else:
print("Access denied.")
slow> slow
if name == "Kevin" or name == "Jon" or name == "Inbar":
print("Access granted.")
else:
print("Access denied.")
slow + slow + 不必要的代码
if name == "Kevin":
print("Access granted.")
elif name == "Jon":
print("Access granted.")
elif name == "Inbar":
print("Access granted.")
else:
print("Access denied.")
您没有指定任何停止条件,无论是内部编码还是在行为空间设置中。
我从您最初发布的有关BhaviorSpace设置的图像中看到,您包含了时间限制
1000。我想您到达了那里,因为默认值为0,行为空间实验将永远运行。只有实验仅在达到指定的时间限制后停止,您的买家
继续做他们所说的事情的时间比仅5个重复的时间更长 - 因此,很长的列表。
在您的情况下,由于您已经告诉NetLogo要执行 go
的次数(通过使用 repot
),并基于代码的布置(即<<代码> tick 仅在发生所有期望的重复之后才会发生),以下任何一个停止条件都将实现您想要的东西:
- in CaveniorSpace:
ticks = 1
; - 在代码中:
to go
repeat 5 [
...
]
tick
stop
end
在这两种情况下,您都可以返回到0 <代码>时间限制 0(即无时间限制)。
有几种方法可以解决差距。
1:使用 sns.catplot
:
这可能需要将数据加倍,尽管如果您要在每个子图中绘制不同的变量,则可以
import pandas as pd
import seaborn as sns
# Load the dataset twice
tips_a = sns.load_dataset("tips")
tips_b = sns.load_dataset("tips")
# Add a dummy facet variable
tips_a["col"] = "A"
tips_b["col"] = "B"
# Concat them
tips = pd.concat([tips_a, tips_b])
# Use the dummy variable for the `col` param
g = sns.catplot(x="day", y="total_bill", hue="sex", data=tips, kind="bar", col="col")
# Remove the titles and move the legend
g.set_titles("")
sns.move_legend(g, loc="upper center", ncol=2, title=None, frameon=False)
。
> AutoScale 轴
仍然需要一点 bbox_to_anchor
弹奏,您可能想更改正确的y轴标签(以及ticks/ticklabels)。
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(1, 2, figsize=(7, 4))
sns.barplot(x="day", y="total_bill", hue="sex", data=tips, ax=ax[0])
ax[0].legend_.remove()
sns.barplot(x="day", y="total_bill", hue="sex", data=tips, ax=ax[1])
sns.move_legend(
ax[1],
loc="upper center",
bbox_to_anchor=(-0.1, 1.1),
ncol=2,
title=None,
frameon=False,
)
ax[0].autoscale()
ax[1].autoscale()
您的代码中有两个简单的错误,可以轻松修复。
- 函数的括号前有一个额外的点。由于
querySelector
是一个函数,因此带有属性的括号直接出现在其之后,如下所示。
document.querySelector('.box').style.color = 'pink';
- 没有任何东西可以触发onclick事件。解决此问题的最简单方法是将
onClick
属于您的按钮,如下所示:
<button class="pink" onclick="changeColor()">Pink</button>
我希望这可以帮助您。
-
我希望将用户的数据保存在云上。我个人喜欢Google的Firebase,它可以帮助使用实时数据库进行身份验证和存储。将用户的数据同步到DB非常容易,甚至使用缓存存储数据,以防用户离线并在设备在线后同步到DB。您可以找到有关Firebase及其产品的更多信息在这里。
-
Flutter是一个非常好的框架,可以通过其跨平台兼容性即可一次完成多个平台的应用程序!如果您不想花时间为多个设备创建应用程序,那么Flutter就是要走的路。我个人认为Flutter Web尚未增长,但是它将加班,毕竟是Google的OpenSource框架。我建议这个想法8.5/10
-
flutter文档写得很好,初学者也可以通过一些视频示例(包括文档中)来完成它。如果您想使用的东西在较新版本的Flutter中不支持,则文本编辑器将在代码上显示一条线,这意味着它被弃用了,不支持它。总是有一个替代方案,您可以使用Flutter Docs或YouTube找到它。 Flutter文档已针对初学者进行优化9/10
我能够使用像Hive这样的Hive在我的应用程序中的缩略图上在Flutter Web上完成此操作:
在我的Hive Service中,
static const _thumbnailsKey = 'thumbnails';
static late Box<List<int>> _thumbnailsBox;
HiveService._();
static Future<void> initialize() async {
await Hive.initFlutter();
_thumbnailsBox = await Hive.openBox(_thumbnailsKey);
}
static Future<void> addThumbnailData({
required String key,
required List<int> data,
}) async {
await _thumbnailsBox.put(key, data);
}
static Uint8List getThumbnailData({required String key}) {
final bytes = _thumbnailsBox.get(key);
if (bytes == null) return Uint8List.fromList([]);
return Uint8List.fromList(bytes);
}
我的Image Downloader Service
import 'dart:typed_data';
import 'package:http/http.dart' as http;
class ImageService {
ImageService._();
static Future<Uint8List> getImageData(String url) async {
Uri uri = Uri.parse(url);
final response = await http.get(uri);
return response.bodyBytes;
}
}
在我的Widget的ViewModel(或您喜欢的任何地方)
我都在使用 getx 所以我用_imagedata.value = ...
Future<void> _getThumbnailData() async {
final cachedThumbnailData = HiveService.getThumbnailData(key: 'someKey');
// This is where the magic happens
if (cachedThumbnailData.isNotEmpty) {
_imageData.value = cachedThumbnailData;
return;
}
// Otherwise fetch the image data
// In my case it's from a url
final imageData = await ImageService.getImageData(thumbnailUrl);
if (imageData.isEmpty) return;
// Update Hive for the next time you need the image
// You could also put this wherever you fetch your images
await HiveService.addThumbnailData(
key: reactionReportGroup.timestampNameKey,
data: imageData,
);
_imageData.value = imageData;
}
现在您可以使用 memoryImage(_viewmodel.imodel.imodagegageata)或 image.memory(_viewModel.imagedata)
我通过执行以下操作解决了它:
reminder_list = [sms_df, upi_df, flash_df, email_df, ivr_df]
for n,df in enumerate(reminder_list):
for min_date in df.cycle_end_date.unique():
max_date = datetime.strptime(min_date, '%Y-%m-%d %H:%M:%S') + timedelta(days=75)
days = pd.date_range(datetime.strptime(min_date, '%Y-%m-%d %H:%M:%S'),max_date,freq='d')
event_date_df = pd.DataFrame(days.values).rename(columns={0:'event_date'}).drop_duplicates()
event_date_df['cycle_end_date'] = min_date
event_date_df['event_date'] = event_date_df['event_date'].apply(lambda x : x.strftime('%Y-%m-%d %H:%M:%S'))
reminder_list[n] = df
df = df.append(event_date_df.merge(df[df.cycle_end_date == min_date], on=['cycle_end_date','event_date'], how='left'))
是的,通过使用拥有的实体,这在EF核心中可能是可能的。 docs ,您可以拥有这样的:
[Owned]
public class StreetAddress
{
public string Street { get; set; }
public string City { get; set; }
}
public class Order
{
public int Id { get; set; }
public StreetAddress ShippingAddress { get; set; }
}
或者,如果您喜欢使用Fluent API:
modelBuilder.Entity<Order>().OwnsOne(p => p.ShippingAddress);
它会给您这样的表:
我设法找到了一个解决方案,但是我不得不切换到 selenium-wire
,
from seleniumwire import webdriver
wd = webdriver.Firefox()
res=wd.get("https://portal.azure.com/")
input("Press Enter to continue...") # After loggin in
for request in wd.requests:
print("HEADERS: "+ str(request.headers)) # The bearer can be found here
此解决方案不是最佳的,因为我仍然可以隔离我知道承载者的请求,但是尽管有生锈,但确实有效。
在此答案中,我将考虑以下实际示例:
-
pandas。 dataframe.merge
从一个和另一个列的索引合并数据框。
我们将在每种情况下使用不同的数据框。
1。 a>
使用以下 dataframes
具有相同的列名:
-
price2018 带尺寸
(8784,5)
P>年度每日小时价格 0 2018 1 1 1 6.74 1 2018 1 1 2 4.74 2 2018 1 1 3 3.66 3 2018 1 1 4 2.30 4 2018 1 1 5 2.30 5 2018 1 1 6 2.06 6 2018 1 1 7 2.06 7 2018 1 1 8 2.06 8 2018 1 1 9 2.30 9 2018 1 1 10 2.30
-
Price2019 带尺寸 (8760,5)
年度每日小时价格 0 2019 1 1 1 66.88 1 2019 1 1 2 66.88 2 2019 1 1 3 66.00 3 2019 1 1 4 63.64 4 2019 1 1 5 58.85 5 2019 1 1 6 55.47 6 2019 1 1 7 56.00 7 2019 1 1 8 61.09 8 2019 1 1 9 61.01 9 2019 1 1 10 61.00
可以使用 pandas.concat
,简单地
import pandas as pd
frames = [Price2018, Price2019]
df_merged = pd.concat(frames)
从中导致具有size (17544,5)的数据框架
如果一个人想清楚地了解发生的事情,它可以像这样起作用
(源)
2。 代码>
在本节中,我们将考虑一个特定情况:合并一个数据框的索引和另一个数据框的列。
假设一个人具有 geo
,带有 54
列,是 date
type dateTime64 [NS ]
。
Date 1 2 ... 51 52 53
0 2010-01-01 00:00:00 0.565919 0.892376 ... 0.593049 0.775082 0.680621
1 2010-01-01 01:00:00 0.358960 0.531418 ... 0.734619 0.480450 0.926735
2 2010-01-01 02:00:00 0.531870 0.221768 ... 0.902369 0.027840 0.398864
3 2010-01-01 03:00:00 0.475463 0.245810 ... 0.306405 0.645762 0.541882
4 2010-01-01 04:00:00 0.954546 0.867960 ... 0.912257 0.039772 0.627696
和dataFrame Price
具有一列,其价格为 Price>
,索引对应于日期( date
),
Price
Date
2010-01-01 00:00:00 29.10
2010-01-01 01:00:00 9.57
2010-01-01 02:00:00 0.00
2010-01-01 03:00:00 0.00
2010-01-01 04:00:00 0.00
以便合并它们,一个人可以使用 .merge 如下所示
df_merged = pd.merge(Price, Geo, left_index=True, right_on='Date')
,其中 geo
和 Price
是以前的数据框架。
这将导致以下数据框架
Price Date 1 ... 51 52 53
0 29.10 2010-01-01 00:00:00 0.565919 ... 0.593049 0.775082 0.680621
1 9.57 2010-01-01 01:00:00 0.358960 ... 0.734619 0.480450 0.926735
2 0.00 2010-01-01 02:00:00 0.531870 ... 0.902369 0.027840 0.398864
3 0.00 2010-01-01 03:00:00 0.475463 ... 0.306405 0.645762 0.541882
4 0.00 2010-01-01 04:00:00 0.954546 ... 0.912257 0.039772 0.627696
您可以从每个组中删除最后一个bezier,用L线L更改中间的M命令,然后用z这样的路径关闭路径:
svg{width:90vh}
<svg viewBox="300 100 150 150">
<path fill="red" d="
M 326 147
C 329 135 345 130 355 137
C 376 150 385 188 362 197
L 381 222
C 418 214 408 157 385 127
C 370 108 340 96 326 115
z
">
</path>
需要注意的几件事:
您目前可以将此JSON划分为简单收集的类对象,这很好。如果您想过滤和排序此集合,它可能会变得更加复杂,因为一个简单的
list&lt; t&gt;
本身不支持它。绑定清单也不是。您应该实现 ibindinglistview 处理对象列表,并且很可能还很可能还处理基类中的接口(您的当前
用户
类)。或者使用ORM / Mini-orm。
已经建立了一种已经实现所有这些功能的已经建立的(和测试)类型noreferrer“> datatable class。
如前所述,您的JSON实际上是一个表( Records 的数组),因此将其列为数据表非常简单。只是:
数据级类已经允许过滤,设置其属性和排序,设置其 DefaultView.Sort 属性。
尽管如此,我建议使用介体在数据词和UI之间。
该工具非常有用,因为它提供了过滤和分类数据源的常用方法,但只要数据源实际上具有这些功能。
使用BindingSource,无论数据源是什么。
它还生成了一些有用的事件,如, , currentchanged 活动等等。
ListChanged
事件还提供了指定更改类型的参数。使用BindingSource,以序列化回JSON,如果数据发生了变化:
在示例代码中,使用这些对象(请参阅视觉示例):
usersSource
:bindingsource对象tboxfilteruser < /code>:文本框控件,使用
用户名
propertytboxFilterTitle
:一个文本框控件,使用title> title> title
property过滤dgv
:dataGridView控件这是其工作方式:
A few things to note:
You're currently deserializing this JSON to simple collection a class objects, which is perfectly fine. It may become a little more complex if you want to filter and sort this collection, since a simple
List<T>
doesn't support it by itself. Nor does a BindingList.You should implement the IBindingListView interface in a class that handles the List of objects and most probably also the INotifyPropertyChanged interface in the base class (your current
Users
class).Or use an ORM / Mini-ORM instead.
There's an already built (and tested) Type that already implements all these features, the DataTable class.
Since, as mentioned, your JSON IS actually a Table (an array of records), deserializing it to a DataTable is quite straightforward. It's just:
The DataTable class already allows filtering, setting its DefaultView.RowFilter property and sorting, setting its DefaultView.Sort property.
Nonetheless, I suggest to use a BindingSource as mediator between the DataTable and the UI.
This tool is quite useful, since it provides common methods to filter and sort a source of data, provided that the source of data actually has these capabilities.
Using a BindingSource, you always use the same methods, no matter what the source of data is.
It also generates some useful events, as the ListChanged, AddingNew, CurrentChanged events and more.
The
ListChanged
event also provides arguments that specify the type of change.With a BindingSource, to serialize back to JSON, if the the data has changed:
In the sample code, these objects are used (see the visual example):
UsersSource
: the BindingSource objecttBoxFilterUser
: a TextBox Control, filters the data using theUserName
PropertytBoxFilterTitle
: a TextBox Control, filters the data using theTitle
PropertybtnRemoveFilter
: a Button Control used to remove the current filtersdgv
: a DataGridView ControlThis is how it works:
在DataGridView中搜索带有输出的JSON文件的内容