羅雙樹

文章 评论 浏览 31

羅雙樹 2025-02-20 23:30:14

您可以使用 sessionaffition:clientip ,它将从K8S服务管理会话。

kind: Service
apiVersion: v1
metadata:
  name: example
spec:
  selector:
    app: example
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 1800

仅适用于参考: WS WebSocket服务器库在加载平衡器后面使用时是否需要粘性会话?

You can use the sessionAffinity: ClientIP, which will manage the session from K8s service.

kind: Service
apiVersion: v1
metadata:
  name: example
spec:
  selector:
    app: example
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 1800

just for ref : Does the ws websocket server library requires sticky session when it is used behind a load balancer?

Kubernetes中的插座IO保持断开连接

羅雙樹 2025-02-20 00:22:11

控制台所说的问题(感谢您指出我检查OmnishArp的控制台),您没有 OmnishArp 插件期望的.NET版本。

我通过安装旧版本的扩展名来解决问题,因为MU项目正在使用.NET 5,并且该扩展程序的更新版本正在搜索.NET 6。

我不确定您是否可以设置每个项目的.NET版本 - 可能是可能但是找不到方法。

The problem as the console says (thanks for pointing me to check omnisharp's console) is that you don't have the version of .NET which the omnisharp plugin expects.

I solved the issue by installing older version of the extension as mu project was using .NET 5 and the updated version of the extension was searching for .NET 6.

I am not sure if you can set the .NET version per project - probably but didn't find a way.

全曲未正确加载 - 视觉工作室代码和统一性

羅雙樹 2025-02-19 21:40:02

我想不可能订购测试中的类执行。他们随机执行。

我确定您可以订购类中的测试方法的执行。

也就是说,我在一个应用程序中使用了一种策略,我需要开始一个过程作为测试的第一步

在我的测试包中,我使用 applicationscoped 创建了一个类,并使用@observes创建了一种方法@observes startupevent startupevent startupevent parameter。

当我执行 MVN测试时,此方法是第一个执行的方法。

使用方法开始我的初始化流程的方法,

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;

@ApplicationScoped
public class AcceptorStarter {

    private static final Logger LOG = LoggerFactory.getLogger(AcceptorStarter.class.getName());

    @Inject
    AcceptorServer acceptorServer;

    // Starts automatically with application
    public void onStart(@Observes StartupEvent StartupEvent) {
        LOG.info("Starting FIX Acceptor to allow tests");
        acceptorServer.init();
    }

    // Ends automatically with application
    public void onStop(@Observes ShutdownEvent shutdownEvent) {
        LOG.info("Finishing FIX Acceptor");
        acceptorServer.stop();
    }

}

以订购方法执行

您可以订购测试方法的执行,例如:

import static io.restassured.RestAssured.given;

import javax.inject.Inject;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class PropertiesRestTest {

    @Test
    @Order(1)
    public void getQuickfixSessionSettings() {
        given()
          .when()
          .get("/properties/quickfix-session-settings")
          .then()
             .statusCode(200);
    }

    @Test
    @Order(2)
    public void putQuickfixSessionSettings() {
        given()
          .body(appProperties.getQuickfixSessionSettings())
          .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
          .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
          .when().put("/properties/quickfix-session-settings")
          .then()
             .statusCode(200);
    }

    @Test
    @Order(3)
    public void restauraQuickfixSessionSettings() {
        given()
          .when()
          .put("/properties/restaura-quickfix-session-settings-original")
          .then()
             .statusCode(200);
    }

}

I guess it's not possible to order the execution of the Classes in tests. They execute randomly.

I know for sure that you can order the execution of the test methods inside a class.

That said, I used one strategy in one application where I needed to start a process as the first step of my tests.

Inside my test package, I created one class with ApplicationScoped and created one method with the @Observes StartupEvent StartupEvent parameter.

When I execute mvn test, this method is the first to be executed.

Class with a method to start my initializing process

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;

@ApplicationScoped
public class AcceptorStarter {

    private static final Logger LOG = LoggerFactory.getLogger(AcceptorStarter.class.getName());

    @Inject
    AcceptorServer acceptorServer;

    // Starts automatically with application
    public void onStart(@Observes StartupEvent StartupEvent) {
        LOG.info("Starting FIX Acceptor to allow tests");
        acceptorServer.init();
    }

    // Ends automatically with application
    public void onStop(@Observes ShutdownEvent shutdownEvent) {
        LOG.info("Finishing FIX Acceptor");
        acceptorServer.stop();
    }

}

Ordering the execution of methods

You can order the execution of the test methods, like this:

import static io.restassured.RestAssured.given;

import javax.inject.Inject;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class PropertiesRestTest {

    @Test
    @Order(1)
    public void getQuickfixSessionSettings() {
        given()
          .when()
          .get("/properties/quickfix-session-settings")
          .then()
             .statusCode(200);
    }

    @Test
    @Order(2)
    public void putQuickfixSessionSettings() {
        given()
          .body(appProperties.getQuickfixSessionSettings())
          .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
          .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
          .when().put("/properties/quickfix-session-settings")
          .then()
             .statusCode(200);
    }

    @Test
    @Order(3)
    public void restauraQuickfixSessionSettings() {
        given()
          .when()
          .put("/properties/restaura-quickfix-session-settings-original")
          .then()
             .statusCode(200);
    }

}

@quarkustest中Quarkus注射的优先级

羅雙樹 2025-02-19 15:36:27

在您的模板中尝试一下:

{{ post.l_auctions.get.current_bid_cmp }}

更新

我对您的模型进行了一些修改,以便它们对我更有意义。您可能需要基本模型是有充分理由的,因此请随时修改您的需求。我也更改了一些名称。我看到的事情仍然没有很多意义,但我会把它留给你。

model.py.py

from django.db import models
from django.conf import settings

class BaseModel(models.Model):
    pass

class Category(models.Model):
    name = models.CharField(max_length=20)

class Listing(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    title = models.CharField('Title of the auction', max_length=150, unique=True)
    description = models.TextField('Description')
    starting_bid = models.FloatField(default=False)
    content = models.TextField('Content of auction')
    image = models.ImageField('Referential Image', null=True,
                              upload_to='images_auctions', max_length=255, default='noimage.png')

    def __str__(self):
        return self.title

class Bid(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='offer_user')
    listing = models.ForeignKey(Listing, null=True, on_delete=models.CASCADE, related_name='bids')
    initialized_bid = models.BooleanField(default=False)
    amount = models.FloatField('Current Bid', blank=True, null=True)
    offer = models.FloatField(default=0, null=True, blank=True)

    def __str__(self):
        return str(self.amount)

    class Meta:
        get_latest_by = 'amount'

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
{% for listing in object_list %}
    <div class=" col-md-4 mt-4 ">

        <div class="card " style="width: 18rem;">
            <a href="#">
                <img class="card-img-top img-fluid" src="{{ listing.image.url }}" alt="Card image cap">
            </a>

            <div class="card-body">
                <a class="darklink" href="#">
                    <h5 class="card-title">{{ listing.title }}</h5></a>
                <h5>Starting bid: $ {{ listing.starting_bid }}</h5>
                <h5>Current bid: $ {{ listing.bids.latest }}</h5>
                <p class="card-text">{{ listing.content | truncatechars:700 }}</p>
                <a href="#" class="btn btn-danger btn-block">Show Auction</a>
            </div>
        </div>

    </div>
{% endfor %}

</body>
</html>

这是来自Shell的交互式会话:

from django.contrib.auth import get_user_model
User = get_user_model()
admin = User.objects.get_or_create(username='admin')[0]
steve = User.objects.get_or_create(username='steve')[0]
jenny = User.objects.get_or_create(username='jenny')[0]
almond = User.objects.get_or_create(username='almond')[0]
from auctions.models import Category, Listing, Bid
c = Category.objects.get_or_create(name='General')[0]

l1 = Listing.objects.get_or_create(user=admin, category=c, title='Some title', description='description', starting_bid=1.00, content='content')[0]

b1 = Bid.objects.get_or_create(user=steve, listing=l1, amount=1.00)[0]
b2 = Bid.objects.get_or_create(user=jenny, listing=l1, amount=1.01)[0]
b3 = Bid.objects.get_or_create(user=almond, listing=l1, amount=1.02)[0]

>>> l1.bids.all()
<QuerySet [<Bid: 1.0>, <Bid: 1.01>, <Bid: 1.02>]>

您可以通过:

将其添加到您的类中:

    class Meta:
        get_latest_by = 'amount'

以及使用 listing.bids。最新() ...

或使用汇总:

from django.db.models import Max
>>> l1.bids.aggregate(max=Max('amount'))
{'max': 1.02}

要注意的关键是, listing.bids 返回a “相关manager” 。这只是意味着您可以使用熟悉的QuerySet方法,例如 .all() .get() .filter()。 last() .latest()等。

在您的情况下,您应该首先在。然后决定您要如何进行。在上面的示例中,我将类Meta 放在 bid 模型上,该模型使您可以根据金额恢复最新对象。假设最新金额始终是最高的,这可能对您的情况不正确。

您可以做的另一件事是将 @property 添加到您的 listing 模型。

class Listing(models.Model):

    ...

    @property
    def max_bid(self):
        from django.db.models import Max
        max_bid = self.bids.aggregate(max=Max('amount'))
        if max_bid.get('max'):
            return max_bid['max']
        return ""

在您的模板中使用:

<h5>Current bid: $ {{ listing.max_bid }}</h5>

Try this in your template:

{{ post.l_auctions.get.current_bid_cmp }}

Update

I modified your models a bit so they make more sense to me. You might need your BaseModel for a good reason so feel free to modify to your needs. I also changed some names. There's still things I see that don't make a lot of sense in them but I'll leave that to you.

models.py

from django.db import models
from django.conf import settings

class BaseModel(models.Model):
    pass

class Category(models.Model):
    name = models.CharField(max_length=20)

class Listing(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    title = models.CharField('Title of the auction', max_length=150, unique=True)
    description = models.TextField('Description')
    starting_bid = models.FloatField(default=False)
    content = models.TextField('Content of auction')
    image = models.ImageField('Referential Image', null=True,
                              upload_to='images_auctions', max_length=255, default='noimage.png')

    def __str__(self):
        return self.title

class Bid(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='offer_user')
    listing = models.ForeignKey(Listing, null=True, on_delete=models.CASCADE, related_name='bids')
    initialized_bid = models.BooleanField(default=False)
    amount = models.FloatField('Current Bid', blank=True, null=True)
    offer = models.FloatField(default=0, null=True, blank=True)

    def __str__(self):
        return str(self.amount)

    class Meta:
        get_latest_by = 'amount'

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
{% for listing in object_list %}
    <div class=" col-md-4 mt-4 ">

        <div class="card " style="width: 18rem;">
            <a href="#">
                <img class="card-img-top img-fluid" src="{{ listing.image.url }}" alt="Card image cap">
            </a>

            <div class="card-body">
                <a class="darklink" href="#">
                    <h5 class="card-title">{{ listing.title }}</h5></a>
                <h5>Starting bid: $ {{ listing.starting_bid }}</h5>
                <h5>Current bid: $ {{ listing.bids.latest }}</h5>
                <p class="card-text">{{ listing.content | truncatechars:700 }}</p>
                <a href="#" class="btn btn-danger btn-block">Show Auction</a>
            </div>
        </div>

    </div>
{% endfor %}

</body>
</html>

Here's an interactive session from a shell:

from django.contrib.auth import get_user_model
User = get_user_model()
admin = User.objects.get_or_create(username='admin')[0]
steve = User.objects.get_or_create(username='steve')[0]
jenny = User.objects.get_or_create(username='jenny')[0]
almond = User.objects.get_or_create(username='almond')[0]
from auctions.models import Category, Listing, Bid
c = Category.objects.get_or_create(name='General')[0]

l1 = Listing.objects.get_or_create(user=admin, category=c, title='Some title', description='description', starting_bid=1.00, content='content')[0]

b1 = Bid.objects.get_or_create(user=steve, listing=l1, amount=1.00)[0]
b2 = Bid.objects.get_or_create(user=jenny, listing=l1, amount=1.01)[0]
b3 = Bid.objects.get_or_create(user=almond, listing=l1, amount=1.02)[0]

>>> l1.bids.all()
<QuerySet [<Bid: 1.0>, <Bid: 1.01>, <Bid: 1.02>]>

You could get the max by:

Adding this to your class:

    class Meta:
        get_latest_by = 'amount'

and using listing.bids.latest()...

Or using aggregate:

from django.db.models import Max
>>> l1.bids.aggregate(max=Max('amount'))
{'max': 1.02}

The key thing to note is, listing.bids returns a "RelatedManager". This just means you can use familiar queryset methods like .all(), .get(), .filter(), .last(), .latest(), etc. Many more.

In your case, you should first review this article on how to get the max of a queryset. Then decide how you want to proceed. In the example above, I put a class Meta on the Bid model which lets you get the latest object back based on the amount. This assumes the latest amount is always the highest, which might not be true for your situation.

One other thing you could do is add a @property to your Listing model.

class Listing(models.Model):

    ...

    @property
    def max_bid(self):
        from django.db.models import Max
        max_bid = self.bids.aggregate(max=Max('amount'))
        if max_bid.get('max'):
            return max_bid['max']
        return ""

Use in your template like this:

<h5>Current bid: $ {{ listing.max_bid }}</h5>

模型关系Django

羅雙樹 2025-02-19 03:41:45

除非您完成了 git fetch (直接或通过 git lupl ),否则您本地存储库中没有其他人推动的更改。这些文件位于远程存储库中。

当您使用 git提取获取上游更改时,远程分支将更新为最新的提交。

您的本地更改是在跟踪远程分支的 local 分支上,因此您在该分支上看不到这些更改。

例如,如果远程存储库称为 Origin ,并且分支为 Master ,则远程分支为 onect> Origin/Master >主是指本地分支。

您可以使用 git日志和其他工具检查远程更改。例如,如果远程分支被称为 Origin/Master ,则可以 git log oint/master 列出您在 git fet fet

要结合两者,您必须 rebase MERGE

git rebase 下,您所承诺的所有本地更改首先将其存放在某个地方,然后您的分支被更新以匹配远程分支。然后,您的更改将樱桃挑选回您当地的分支。自动合并发生,但是可能会出现您必须手动修复的冲突。有一个工作流程,重新构想停止,使您遭受了所有挑剔的更改的情况,除了冲突文件外,您必须进行编辑以删除冲突标记,然后使用添加到舞台上。 git add ;然后 git rebase - continue

除非基于当前远程分支(即具有远程分支作为祖先的当前提交),否则您的本地分支不能将其推向远程存储库(至少没有 - 强制)。为了推动您的变化,您会有提取,重新弹力和推动。如果推动被拒绝是因为其他人在重新审视时推了一些新东西,则必须重复获取,反弹和推动。

There are no changes in your local repository that have been pushed by someone else unless you have done a git fetch (directly or via git pull). Those files are in a remote repository.

When you fetch the upstream changes with git fetch, the remote branch is updated to the most recent commit.

Your local changes are on the local branch which tracks the remote branch, and therefore you don't see those changes on this branch.

For instance, if the remote repository is called origin and the branch is master, then the remote branch is origin/master, and master refers to the local branch.

You can inspect the remote changes with git log and other tools. E.g. if the remote branch is called origin/master, you can git log origin/master to list the new changes you've picked up after git fetch.

To combine the two, you must either rebase or merge.

Under git rebase, all your local changes that you have committed are first stowed away somewhere, and then your branch is updated to match remote branch. Your changes are then cherry-picked back into your local branch, one by one. Automatic merging takes place, but conflicts may arise that you have to manually repair; there is a workflow for that whereby the rebase stops, leaving you with a situation where all the cherry-picked changes are staged, except for the conflicted files, which you must edit to remove conflict markers and then add to the stage with git add; then git rebase --continue.

Your local branch cannot be pushed (at least not without --force) to the remote repository unless it is based on the current remote branch (i.e. has the current commit of the remote branch as an ancestor). To push your change you have fetch, rebase and push. If the push is rejected because someone else pushed something new while you were rebasing, you must repeat fetch, rebase and push.

如何区分需要在git中提取的文件,以及在本地提交并准备推送的文件

羅雙樹 2025-02-18 19:25:42

尝试以下操作:

with cte as(
Select A.Postal_Code As UpdateTo,B.Postal_Code As ToBeUpdated, 
Row_Number() Over (Partition By B.Postal_Code Order By Abs(A.Postal_Code-B.Postal_Code)) as rn
From Postals A , Clients B 
)

Update Clients C Set C.Postal_Code = (Select D.UpdateTo From cte D 
                                      where C.Postal_Code=D.ToBeUpdated and D.rn=1);
select * from Clients

请参阅

Try the following:

with cte as(
Select A.Postal_Code As UpdateTo,B.Postal_Code As ToBeUpdated, 
Row_Number() Over (Partition By B.Postal_Code Order By Abs(A.Postal_Code-B.Postal_Code)) as rn
From Postals A , Clients B 
)

Update Clients C Set C.Postal_Code = (Select D.UpdateTo From cte D 
                                      where C.Postal_Code=D.ToBeUpdated and D.rn=1);
select * from Clients

See a demo from db-fiddle.

更新具有最近值的表

羅雙樹 2025-02-18 00:21:31

使用Grid,您需要为所有DIV指定开始/端列和行,因为它们具有突出边缘的方式。您将需要的最小行数为5。我设置了估计的固定列和粗糙尺寸以匹配您的图像;您必须进行调整才能使他们响应迅速。

.outerCard {
  display: grid;
  grid-template-columns: 50px 20px 200px 30px 60px;
  grid-template-rows: 60px 40px 300px repeat(2, 40px);
  width: 360px;
  background-color: LightGoldenRodYellow;
}

.mainCard { 
  grid-area: 2 / 2 / 4 / 4;
  background-color: LightGrey;
}

.sideCard { 
  grid-area: 3 / 4 / 4 / 5;
  background-color: LightPink;
}

.bottomCard { 
  grid-area: 4 / 3 / 5 / 5;
  background-color: LightCoral;
}
<div class="outerCard">
  <div class="mainCard">
    <h2 class="title">title</h2>
  </div>
  <div class="sideCard"></div>
  <div class="bottomCard">
    <h5 class="subtitle">subtitle</h5>
  </div>
</div>

With grid you will need to specify the start/end columns and rows for all of the divs because of the way they have jutting edges. The minimum number of rows and columns you will need is 5 each. I set estimated fixed column and rough dimensions to match your image; you'll have to adjust in order for them to be responsive.

.outerCard {
  display: grid;
  grid-template-columns: 50px 20px 200px 30px 60px;
  grid-template-rows: 60px 40px 300px repeat(2, 40px);
  width: 360px;
  background-color: LightGoldenRodYellow;
}

.mainCard { 
  grid-area: 2 / 2 / 4 / 4;
  background-color: LightGrey;
}

.sideCard { 
  grid-area: 3 / 4 / 4 / 5;
  background-color: LightPink;
}

.bottomCard { 
  grid-area: 4 / 3 / 5 / 5;
  background-color: LightCoral;
}
<div class="outerCard">
  <div class="mainCard">
    <h2 class="title">title</h2>
  </div>
  <div class="sideCard"></div>
  <div class="bottomCard">
    <h5 class="subtitle">subtitle</h5>
  </div>
</div>

需要帮助使用网格CSS创建此响应式堆叠卡的外观。下面的代码

羅雙樹 2025-02-17 20:23:34
    var mockedQuery = mockk<Query<Any>>()
    var mockSessionFactory = mockk<SessionFactory> {
        every { openSession() } returns mockk {
            every { get(any(), any()) } returns null
            every { createQuery("delete from SaveableObject where expiration < getdate() ") } returns mockedQuery
        }
    }

我认为这里的问题是您使用的是供应商功能而不是实际值。

供应商,如 ,是具有签名() - &gt的函数; t ,如果您在卷曲括号中放置一个值,则分配了供应商,而不是实际值。

想象一下,

var helloWorld = { "Hello World" }

您不能将其作为 helloworld.lowercase()(),您需要首先调用函数 helloworld().lowercase()

以同样的方式,createquery想要查询&lt; any&gt; 返回,而不是() - &gt;查询&lt; any&gt;

我更改的另一件事是我称 mockk() plocy of 文档对于未注入任何行为的对象模拟。

    var mockedQuery = mockk<Query<Any>>()
    var mockSessionFactory = mockk<SessionFactory> {
        every { openSession() } returns mockk {
            every { get(any(), any()) } returns null
            every { createQuery("delete from SaveableObject where expiration < getdate() ") } returns mockedQuery
        }
    }

I think the problem here is that you are using Supplier functions instead of the actual value.

A Supplier, as in Java, is a function with a signature () -> T and if you place a value in curly braces, you are assigning a Supplier, not the actual value.

Imagine

var helloWorld = { "Hello World" }

You cannot lowerCase it as helloWorld.lowerCase(), you need to call the function first helloWorld().lowerCase().

In the same way, createQuery wants Query<Any> returned, not () -> Query<Any>

The other thing I changed is that I called mockk() for the query following one of the ways mentioned in the documentation for object mocks which don't get any behavior injected.

单位测试kotlin用于Hibernate.sessionFactory.sessession.secreatequery使用Mockk,这是什么意思?

羅雙樹 2025-02-17 20:08:26

我不完全理解您的问题(您可以做一个例子吗?),特别是当您说

喜欢我们如何使用内置算法运行培训工作

,但基本上您可以在容器中做任何您想做的事情,就像您已经做过一样,您在容器中有一个适当的 train 文件,这是一个该sagemaker称为入口点。在该文件中,您可以调用外部脚本(也位于容器中),也可以将参数传递给您的容器(例如,请参见如何传递超参数)。有一个很明显的文档在这里

I don't fully understand your question (can you make an example please?), specially when you say

like how we run training jobs using in-built algorithms

But basically you can do whatever you want in your container, as probably you already did, you have a proper train file in your container, which is the one that sagemaker calls as the entrypoint. In that file you can call external script (which are in your container too) and also pass parameters to your container (see how for example hyperparameters are passed). There is a quite clear documentation here.

在运行SageMaker培训工作时,在自定义容器中运行自定义脚本

羅雙樹 2025-02-17 19:36:05

要明确。分开逻辑并自行处理每个文件。

def read_file(filename):
    with open(filename) as f:
        return f.read()

list_of_files = ["File_1.txt", "File_2.txt", "File_3.txt"]:
files_content = []

for filename in list_of_files:
    try:
        files_content.append(read_file(filename))
    except OSError:
        continue

with open("Final.txt", 'a+') as f:
    f.writelines(files_content)
    f.write('\n')

有些人可能更喜欢处理 read_file 中的异常,但这不是这里的重点。

Be explicit. Separate the logic and handle every file on its own.

def read_file(filename):
    with open(filename) as f:
        return f.read()

list_of_files = ["File_1.txt", "File_2.txt", "File_3.txt"]:
files_content = []

for filename in list_of_files:
    try:
        files_content.append(read_file(filename))
    except OSError:
        continue

with open("Final.txt", 'a+') as f:
    f.writelines(files_content)
    f.write('\n')

Some people might prefer to handle the exception inside read_file but that is not the point here.

即使缺少一些文件,如何合并多个文件?

羅雙樹 2025-02-17 11:25:52

您从哪里运行代码? CSV文件是否与Python文件相同的目录,如果是,则控制台路径与Python脚本和CSV文件相同?

where are you running the code from? Is the CSV file in the same directory as your python file, if yes is the console path the same as the python script and the CSV file?

可以查找和读取.csv文件

羅雙樹 2025-02-17 06:58:49

更改事件应如下所示,预计将有新价值作为参数:

fireEvent.change(beneficiaryValue, {
  target: { value: "Changed Value" }
});

请参阅React测试库文档以获取更多详细信息。

Change event should be fired as below, it expects new value as an argument:

fireEvent.change(beneficiaryValue, {
  target: { value: "Changed Value" }
});

Please refer to React testing library documentation for more details.

与Jest一起测试Onchange事件。任何建议

羅雙樹 2025-02-17 06:02:12

尝试使用链接参数传递您的URL。

如果我修改您的代码,则应给出类似的内容:

def post(self, article):
  print(f"\n\n[FacebookPoster] Posting on Facebook:\n\n{article.post}\n\n")
  self.graph.put_object(parent_object="me", connection_name="feed", message=article.post, link=article.link)

Try to use the link parameter to pass your URL.

If I modify your code, it should give something like:

def post(self, article):
  print(f"\n\n[FacebookPoster] Posting on Facebook:\n\n{article.post}\n\n")
  self.graph.put_object(parent_object="me", connection_name="feed", message=article.post, link=article.link)

通过Facebook Graph API发布URL不会嵌入URL,只是将其作为URL插入

羅雙樹 2025-02-17 04:28:36

我需要发布在重新开放Visual Studio后已解决此问题的问题,不是因为我没有选择目标分支。我将其称为打ic,因为它没有再次发生。感谢您的帮助

I need to post that this problem has been solved after I re-opened Visual studio, and no it wasn't that I didn't have the target branch selected. I would call this a hiccup since it didn't happen again. Thanks for the help

Visual Studio 2022 Git“管理分支机构”不起作用

羅雙樹 2025-02-16 15:00:36

我终于找到了为什么它不起作用的原因!

如果 admin/base.html (在 admin.base.base_site.html 中扩展)中有很多)几个变量。

为了显示右上方面板,必须将变量 has_permissions 设置为 true ,并具有查看站点链接, site_url 应设置为网站的URL。

现在,要显示导航栏, is_nav_sidebar_enabled 需要将设置为 true able_apps 必须包含要显示的所有应用程序。

通过将所有这些添加到模板的上下文中,所有这些都像管理面板的其余部分一样正确地呈现。

我的代码现在看起来像:

class MyAdminSite(admin.AdminSite):    
    def get_app_list(self, request):
        app_list = super().get_app_list(request)
        app_list += [
            {
                "name": "Documentation",
                "app_label": "documentation",
                "models": [
                    {
                        "name": "Scripts modification",
                        "object_name": "Scripts modification",
                        "admin_url": "/admin/documentation/modif/",
                        "view_only": True,
                    }
                ],
            }
        ]
        return app_list
    
    
    def get_urls(self):
        urls = super().get_urls()
        my_urls = [
            path('documentation/modif/', self.admin_view(self.modif)),
        ]
        return my_urls + urls
    

    def modif(self, request):
        context = {
            'title':"Documentation",
            'has_permission': True,
            'site_url': reverse('scripts:scripts'),
            'is_nav_sidebar_enabled': True,
            'available_apps': self.get_app_list(request),
        }
        return render(request, "documentation/scripts_modification.html", context)

I finally found the reason why it wasn't working!

There are a lot of if clauses in admin/base.html (which is extended in admin.base_site.html) that check the values of several variables.

In order to display the top right panel, the variable has_permissions must be set to True, and to have the view site link, the site_url should be set to the url of the site.

Now, to display the navigation bar, is_nav_sidebar_enabled need to be set to True and available_apps must contains all the apps to display.

By adding all of that to the context of the template, everything is rendered correctly like on the rest of the admin panel.

And my code now looks like that :

class MyAdminSite(admin.AdminSite):    
    def get_app_list(self, request):
        app_list = super().get_app_list(request)
        app_list += [
            {
                "name": "Documentation",
                "app_label": "documentation",
                "models": [
                    {
                        "name": "Scripts modification",
                        "object_name": "Scripts modification",
                        "admin_url": "/admin/documentation/modif/",
                        "view_only": True,
                    }
                ],
            }
        ]
        return app_list
    
    
    def get_urls(self):
        urls = super().get_urls()
        my_urls = [
            path('documentation/modif/', self.admin_view(self.modif)),
        ]
        return my_urls + urls
    

    def modif(self, request):
        context = {
            'title':"Documentation",
            'has_permission': True,
            'site_url': reverse('scripts:scripts'),
            'is_nav_sidebar_enabled': True,
            'available_apps': self.get_app_list(request),
        }
        return render(request, "documentation/scripts_modification.html", context)

在管理面板中添加与其他设计相同设计的视图

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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