箜明

文章 评论 浏览 28

箜明 2025-02-07 23:35:58

是的,您正在误解什么是浅副本。这并不意味着它是原始列表的一种“视图”。这是一个新列表,其内容是从原始内容中复制的。

“浅”是指将参考文献复制为原始列表中包含的任何内容,而不必关心该参考点。

“ Deep”副本将创建列表中包含的每个项目的新副本。

class Item():
    def __init__(self, num):
        self.num = num
    def copy(self):
        return Item(self.num)
    def __eq__(self, other):
        return self.num == other.num

itemList = [Item(1), Item(2), Item(3)]

shallowCopy = [item for item in itemList]
deepCopy = [item.copy() for item in itemList]

print([id(sh) == id(dp) for sh, dp in zip(shallowCopy, deepCopy)])
# [False, False, False]
# comparison by id
print([sh == dp for sh, dp in zip(shallowCopy, deepCopy)])
# [True, True, True]
# comparison by value

Yes, you are misunderstanding what a shallow copy is. It does not mean that it's a sort of "view" for the original list. It is a new list with the with it's contents copied over from the original.

"Shallow" means that it copies the references for whatever is contained in the original list without care for what that reference points too.

"Deep" copy would create a new copy of each item contained in the list.

class Item():
    def __init__(self, num):
        self.num = num
    def copy(self):
        return Item(self.num)
    def __eq__(self, other):
        return self.num == other.num

itemList = [Item(1), Item(2), Item(3)]

shallowCopy = [item for item in itemList]
deepCopy = [item.copy() for item in itemList]

print([id(sh) == id(dp) for sh, dp in zip(shallowCopy, deepCopy)])
# [False, False, False]
# comparison by id
print([sh == dp for sh, dp in zip(shallowCopy, deepCopy)])
# [True, True, True]
# comparison by value

切成薄片是否会产生浅或深拷贝?

箜明 2025-02-07 19:25:10

如果您只想在将Dozer用于DTO映射的情况下避免获取关联,则可以通过扩展 Dozerconverter 来忽略 products 字段并使用该字段自定义转换器。

我也觉得这也许意味着您的目标类型并不需要
产品开始,因为您不会填充它。

如果您的代码库中有很多这样的位置,请考虑使用预测以获取目的目的所需的属性。

@fella7ena提出了一个关于 @transactional的观点,但是这实际上是无关的 - 您仍然可以在交易中遇到LazyInitialization Exception。发生这种情况是因为Hibernate失去了Java Bean的持久状态与数据库状态之间的关系。如果您实际上想从数据库中获取产品关联,则必须使用急切的fetchType(导致N+1期),批处理或EntityGraphs。

If you only want to avoid fetching the association in cases where you use Dozer for DTO mapping, you could configure it to ignore products field in source object by extending DozerConverter and using that custom converter.

I also feel that maybe that means your target type doesn't really need to have
a products field to begin with, since you're not going to populate it.

If there's many places like this in your codebase, consider using projections to only fetch the properties necessary for the purpose at hand.

@fella7ena brings up a point about @Transactional, however this is actually unrelated - you can still come across LazyInitializationException within a transaction. This happens because Hibernate loses track of the relation between the java bean's persistence state and the database state. If you actually wanted to fetch products association from the database, you would have to use eager fetchtype (leads to n+1 issue), batching, or entitygraphs.

当此集合懒惰时,返回空收藏

箜明 2025-02-06 17:28:03

在这种情况下要寻找的关键词是“自我托管”。这意味着您的流程托管可以从客户端访问的HTTP服务器,例如在您的情况下进行测试工具。

文档显示了使用ASP.NET 4.x的样本。

为了仅在需要时启动服务器,您可以添加配置设置。

The key word to look for in this context is "self-hosting". This means that your process hosts a HTTP server that can be accessed from clients - e.g. a test tool as in your case.

This documentation shows a sample that uses ASP.NET 4.x.

In order to only start the server when needed, you could add a configuration setting.

桌面应用程序中的Web API

箜明 2025-02-06 15:24:10

您可以做到这一点:

sentence2 = ' ' + sentence[:-1]
starts = [i for i in range(len(sentence))if sentence[i] == '_' and sentence2[i] != '_' ]
ends = [i - 1 for i in range(len(sentence)) if sentence2[i] == '_' and sentence[i] != '_']
pairs = list(zip(starts, ends))
print(pairs)

输出:

[(15, 21), (23, 28), (30, 32), (34, 40), (42, 45), (47, 51), (53, 59), (61, 71)]

这将在一个或多个连续符号字符的子弦中给出第一个也是最后一个实例的符号索引。如果您需要使用Python slice语义的结果(在连续的子字符串中启动==符号的第一个实例的索引,则在该基因符号的最后一个实例之后立即结束==索引),则可以更改 i -1 i -1 < /code> to i 结束的初始化行中。

You can do this:

sentence2 = ' ' + sentence[:-1]
starts = [i for i in range(len(sentence))if sentence[i] == '_' and sentence2[i] != '_' ]
ends = [i - 1 for i in range(len(sentence)) if sentence2[i] == '_' and sentence[i] != '_']
pairs = list(zip(starts, ends))
print(pairs)

Output:

[(15, 21), (23, 28), (30, 32), (34, 40), (42, 45), (47, 51), (53, 59), (61, 71)]

This will give the index of the first and last instances of symbol in a substring of one or more contiguous symbol characters. If you need results that use python slice semantics (start == index of first instance of symbol in a contiguous substring, end == index immediately following the last instance of symbol in that substring), you can change i - 1 to i in the initialization line for ends.

符号在字符串中的启动和结尾位置

箜明 2025-02-06 14:06:24

除了答案外,我们知道您必须将属性设置

timeout=None 

discord.ui.ui.view

class MainView(discord.ui.View):
    def __init__(self):
        print("init")
        super().__init__(timeout=None)

为 添加准备就绪的视图应为:

async def on_ready(self):
    self.add_view(MainView())

如果不仅适用于“超时”属性

In addition to the answer, we know that you must set a property

timeout=None 

to discord.ui.View

But also you should add this ui.View in your main Client "on_ready" if you defined a class with your custom view like:

class MainView(discord.ui.View):
    def __init__(self):
        print("init")
        super().__init__(timeout=None)

an example to add the view on ready should be:

async def on_ready(self):
    self.add_view(MainView())

If not will not work with only the "timeout" property

Discord.py按钮响应互动在一定时间后失败

箜明 2025-02-06 10:21:25

我设法找到了自己的错误,我必须承认这是一个愚蠢的错误,但花了我很多时间来弄清楚。问题在行 var ss = modelmapper.map&lt; apimodel&gt;(settings.settings);
看到我有 profile 这样的:

CreateMap<DbModel, ApiModel>()
                .ConstructUsing((source, context) => 
                {
                    var res = JsonConvert.DeserializeObject<ApiModel>(source.Settings);
                    return new ApiModel
                    {
                        Colors = res.Colors
                    };
                });

它希望源是 dbmodel 对象,但实际上我传递了该对象的属性,实际上是字符串。而且我没有定义这种映射,这就是为什么我会遇到错误的原因。

正确的用法必须为: var ss = modelmapper.map&lt; apimodel&gt;(设置);

,因此请感谢您的所有建议!

问候,
朱利安

I managed to find my mistake, and I have to admit it is a silly one, but took me a lot of time to figure. The problem is in the line var ss = modelMapper.Map<ApiModel>(settings.Settings);
See I have the Profile like this:

CreateMap<DbModel, ApiModel>()
                .ConstructUsing((source, context) => 
                {
                    var res = JsonConvert.DeserializeObject<ApiModel>(source.Settings);
                    return new ApiModel
                    {
                        Colors = res.Colors
                    };
                });

It expects the source to be a DbModel object, but in fact I pass a property of this object which is in fact a string. And I do not have defined that kind of mapping, that is why I get the error.

The right usage have to be: var ss = modelMapper.Map<ApiModel>(settings);

So thanks for all your suggestions!

Regards,
Julian

自定义转换从源到目的地的自定义转换的汽车问题

箜明 2025-02-06 10:07:45

找到了另一种方法:

def add(l,n=2):
    return [item for sublist in [(e,) if i % n == 0 or i == 0 else (e, 0.0) for i, e in enumerate(l)] for item in sublist]

[1.0、2.0、0.0、3.0、4.0、0.0、5.0、6.0、0.0]

Found another way to do it:

def add(l,n=2):
    return [item for sublist in [(e,) if i % n == 0 or i == 0 else (e, 0.0) for i, e in enumerate(l)] for item in sublist]

[1.0, 2.0, 0.0, 3.0, 4.0, 0.0, 5.0, 6.0, 0.0]

在每2个元素之后插入列表中的元素

箜明 2025-02-06 04:22:40

只是为了告知其他访客,有几种解决方案解决此问题。
最著名的解决方案是需要配置的工人。最近,CloudFlare添加了一个功能,该功能自动将用户的地理位置信息添加到请求 。要设置该设置,请按照以下步骤进行操作:

  • Go Go CloudFlare仪表板
  • 选择一个域
  • ,转到规则 - &gt;变换规则 - &GT; 托管转换
  • 启用添加访问者位置标题

然后您可以从php中的$ _server global访问这些元数据,您可以使用以下变量对我有用的变量:

[REMOTE_ADDR] => ****
[HTTP_CF_IPLONGITUDE] => ****
[HTTP_CF_IPLATITUDE] => ****
[HTTP_CF_IPCOUNTRY] => ****
[HTTP_CF_IPCONTINENT] => ****
[HTTP_CF_IPCITY] => ****
[HTTP_CF_CONNECTING_IP] => ****
[HTTP_USER_AGENT] => ****

Just to inform other visitors, there are several solutions for this issue.
The most famous solution is the worker, which needs configurations. Recently, the Cloudflare added a feature that automatically adds the user's geolocation information to the request. To set that up, follow the below steps:

  • Go the the Cloudflare dashboard
  • Select a domain
  • Go to the Rules -> Transform Rules -> Managed Transform
  • Enable the Add visitor location headers

Then you can access these meta data from $_SERVER global in PHP, you can use the below variables that was useful for me:

[REMOTE_ADDR] => ****
[HTTP_CF_IPLONGITUDE] => ****
[HTTP_CF_IPLATITUDE] => ****
[HTTP_CF_IPCOUNTRY] => ****
[HTTP_CF_IPCONTINENT] => ****
[HTTP_CF_IPCITY] => ****
[HTTP_CF_CONNECTING_IP] => ****
[HTTP_USER_AGENT] => ****

enter image description here

从CloudFlare Worker发送向标头发送区域名称,然后用PHP获取

箜明 2025-02-05 15:06:57

解决了。问题在于资产目录不包括在构建中。因此,我必须将其添加到PubSpec.yaml文件中:

flutter:
  assets:
      - assets/

比构建/Web/Assets中的资产目录还包括在生产中。奇怪的是,index.html是被采用的。

Solved it. The problem was that the assets directory was not included in the build. Therefore I had to add this to the pubspec.yaml file:

flutter:
  assets:
      - assets/

Than the assets directory is included in build/web/assets and the JSON is available on production. Strange that the index.html was taken instead though.

flutter json语法仅在生产中,不在调试模式下

箜明 2025-02-05 07:31:37

我发现一条评论说是用 ml /c /cx /coff替换旧的构建命令“%(fullPath)” < /code> < /code> ml /c /c /cx /coff /safeseh“%(fullPath) “ (请注意添加/safeseh ),该问题解决了问题。

I found a comment saying to replace the old build command from ml /c /Cx /coff "%(FullPath)" to ml /c /Cx /coff /safeseh "%(FullPath)" (notice the addition of /safeseh), which resolved the issue.

Visual Studio“模块不安全的SAFESEH图像”在汇编/c&#x2b;&#x2b;

箜明 2025-02-05 05:56:33

您可以使用捕获组并防止匹配,并且如果不想匹配,也可以排除在内。

$s = "uniqueMember: uid=n039833,ou=people,ou=networks,o=test,c=us\nuniqueMember: uid=N019560, ou=people, ou=Networks, o=test, c=Us"
[regex]::Matches($s,'uid=([^,]+)') | Foreach-Object {$_.Groups[1].Value}

输出

n039833
N019560

请注意,在当前模式中应该存在尾随逗号。如果不是这种情况,您可以从模式中省略匹配。如果您只想排除匹配逗号,则模式将是:

uid=([^,]+)

You can use a capture group and prevent matching , and if you don't want to match % you can also exclude that.

$s = "uniqueMember: uid=n039833,ou=people,ou=networks,o=test,c=us\nuniqueMember: uid=N019560, ou=people, ou=Networks, o=test, c=Us"
[regex]::Matches($s,'uid=([^,]+)') | Foreach-Object {$_.Groups[1].Value}

Output

n039833
N019560

Note that in the current pattern there should be a trailing comma present. If that is not ways the case, you can omit matching that from the pattern. If you only want to exclude matching a comma, the pattern will be:

uid=([^,]+)

Powershell Regex Match语句

箜明 2025-02-04 21:52:03

我相信您可以尝试 scroll-snap-align 是CSS来实现它。
这是一个可以帮助您了解 scroll-snap-align 的链接。 https://css-tricks.com/almanac/almanac/properties/ss/almanac/properties/ss ss/almanac/properties/ss /scroll-snap-align/

I believe you can try something like scroll-snap-align is css to achieve it.
Here is a link that can help you understand scroll-snap-align. https://css-tricks.com/almanac/properties/s/scroll-snap-align/

保留内容中心的屏幕,但请在滚动时进行更改

箜明 2025-02-04 13:56:33

SimpleHttPoperator确实返回XCOM。但是,命令气流任务测试不再创建XCOM,whe

the SimpleHttpOperator does return a XCOM. However, the command airflow tasks test does NOT create XComs anymore, whe

气流SimpleHttpoperator没有推到XCOM

箜明 2025-02-04 13:38:54

如果您可以使用变量

DECLARE @StartDate DATETIME, @EndDate DATETIME
SET @StartDate = DATEADD(MONTH, DATEDIFF(MONTH, 0, getdate()) - 13, 0)
SET @EndDate = DATEADD(mm, 1, @StartDate)

SELECT * FROM TABLE b
WHERE b.invoice_date >= @StartDate                         
AND b.invoice_date < @EndDate

If you can use variables

DECLARE @StartDate DATETIME, @EndDate DATETIME
SET @StartDate = DATEADD(MONTH, DATEDIFF(MONTH, 0, getdate()) - 13, 0)
SET @EndDate = DATEADD(mm, 1, @StartDate)

SELECT * FROM TABLE b
WHERE b.invoice_date >= @StartDate                         
AND b.invoice_date < @EndDate

去年上一个月

箜明 2025-02-04 10:19:19

idata 对于此用例似乎太通用了。您可以推出 iuserdata
这只会负责处理用户的数据访问。

然后,您的设置将看起来像这样:

public interface IUserData
{
  Task<IEnumerable<string>> GetUsers();
}

public class UserData: IUserData
{
  public async Task<IEnumerable<string>> GetUsers()
  { ... }
}

public interface IEmailer
{
  Task Send();
}

public class Emailer : IEmailer
{
  private readonly IUserData _userData;

  public Emailer(IUserData userData)
  {
    _userData = userData;
  }

  public async Task Send()
  {
    var users = await _userdata.GetUser();
  }
} 

另外,您可以拥有3层,其中包含一个通用数据类,负责所有数据访问操作,并且具有 userData 类fine-code> class fine fine-grain它。当然,这取决于此数据服务可以多大和难以管理。我个人更喜欢为每个数据访问用例提供量身定制的服务。

IData seems too generic for this use case. You can instead introduce IUserData
which would be only responsible for handling data access for the User.

Then your setup will look like this:

public interface IUserData
{
  Task<IEnumerable<string>> GetUsers();
}

public class UserData: IUserData
{
  public async Task<IEnumerable<string>> GetUsers()
  { ... }
}

public interface IEmailer
{
  Task Send();
}

public class Emailer : IEmailer
{
  private readonly IUserData _userData;

  public Emailer(IUserData userData)
  {
    _userData = userData;
  }

  public async Task Send()
  {
    var users = await _userdata.GetUser();
  }
} 

Alternatively, you can have 3 layers with a generic Data class in charge of all the data access operations and have the UserData class fine-grain it. This of course depends on how large and unmanageable can this data service become. I personally prefer to have tailor-made services for each data access use case.

C#:辅助方法中的辅助方法依赖性注入

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文