何以畏孤独

文章 评论 浏览 28

何以畏孤独 2025-02-17 02:52:31

谢谢你!
将apps.py

from django.apps import AppConfig


class app1Config(AppConfig):
    name = 'Project0.app1'

和设置修改为

Project0.app1.apps.app1Config

runserver工作!

Thank you Lain!
Modified the apps.py to

from django.apps import AppConfig


class app1Config(AppConfig):
    name = 'Project0.app1'

and the settings.py as

Project0.app1.apps.app1Config

runserver worked!

ModulenotFoundError:No模块名为' app1'

何以畏孤独 2025-02-16 18:57:31

您可以使用 difflib.Sequecemecematcher 并从下面的两个列表中找到每个两个单词之间的相似性:(输出仅显示两个具有相似性> 70%的单词)

from difflib import SequenceMatcher
TotalTags = ["citrus", "orange", "vitamin-C", "sweet", "yellow", "vitamin-A"]
LikedTags = ["citrus", "orange", "vitamin-D"]
for a in LikedTags:
    for b in TotalTags:
        sim = SequenceMatcher(None, a, b).ratio()
        if sim > 0.7:
            print(f'similarity of {a} & {b} : {sim}')

输出:

similarity of citrus & citrus : 1.0
similarity of orange & orange : 1.0
similarity of vitamin-D & vitamin-C : 0.8888888888888888
similarity of vitamin-D & vitamin-A : 0.8888888888888888

You can use difflib.SequenceMatcher and find similarity between each two word from two list like below: (Output only shows two words that have similarity > 70%)

from difflib import SequenceMatcher
TotalTags = ["citrus", "orange", "vitamin-C", "sweet", "yellow", "vitamin-A"]
LikedTags = ["citrus", "orange", "vitamin-D"]
for a in LikedTags:
    for b in TotalTags:
        sim = SequenceMatcher(None, a, b).ratio()
        if sim > 0.7:
            print(f'similarity of {a} & {b} : {sim}')

Output:

similarity of citrus & citrus : 1.0
similarity of orange & orange : 1.0
similarity of vitamin-D & vitamin-C : 0.8888888888888888
similarity of vitamin-D & vitamin-A : 0.8888888888888888

如何查看两个字符串列表的匹配百分比?

何以畏孤独 2025-02-16 11:18:58

您在这里拥有的是 种族条件 。在Java的特殊情况下,我们可以从 JLS

两个访问(读取或写入)同一变量被认为是相互冲突,如果至少一个访问是写入。

您有一个变量,并且有两个线程同时访问它,其中其中一个线程正在写入其中。要保护此数据,您需要 synchronize 两次访问。通常,建议在类型对象的私有实例变量上同步,以便没有其他人对该变量进行引用。 (同步方法的默认行为是在 this 上同步,如果有参考 此同步的其他人,它可能会引起问题同样),

private boolean running;
private Object lock;

public MyClass() {
  lock = new Object();
}

...

@Override
public void run() {
  startTime = System.currentTimeMillis();
  synchronized (lock) {
    running = true;
  }
  while (isRunning()) {}
}

public boolean isRunning() {
  synchronized (lock) {
    return running;
  }
}

@Override
public void interrupt() {
  synchronized (lock) {
    running = false;
  }
}

而且,正如评论中已经指出的那样,当您做这样的事情时,通常会皱眉 thread 。考虑在 Runnable 子类中制作 Run(),然后只需使用 thread 构造函数即可。

What you have here is a race condition. In the particular case of Java, we can read a direct definition from the JLS

Two accesses to (reads of or writes to) the same variable are said to be conflicting if at least one of the accesses is a write.

You have a single variable and you have two threads accessing it at the same time, where one of those threads is writing to it. To protect this data, you need to synchronize both accesses. Generally, it's advised to synchronize on a private instance variable of type Object, so that no one else has a reference to that variable. (The default behavior of synchronized methods is to synchronize on this, which can cause problems if someone else who has a reference to this synchronizes on it as well)

private boolean running;
private Object lock;

public MyClass() {
  lock = new Object();
}

...

@Override
public void run() {
  startTime = System.currentTimeMillis();
  synchronized (lock) {
    running = true;
  }
  while (isRunning()) {}
}

public boolean isRunning() {
  synchronized (lock) {
    return running;
  }
}

@Override
public void interrupt() {
  synchronized (lock) {
    running = false;
  }
}

And, as has already been pointed out in the comments, it is generally frowned upon to subclass Thread when you're doing things like this. Consider making your run() in a Runnable subclass and simply use the Thread constructor.

线程扩展,访问方法与提交的值

何以畏孤独 2025-02-15 19:09:44

好吧,我认为问题是来自编译器的想法,我尝试使用 viewModels()与list而不是viewModel这样的android函数,我也遇到了相同的问题,这个想法不会显示任何错误:

但是,当您编译代码时,您会收到一个错误:

“在此处输入图像描述”

这样您就可以忽略这个想法,这只是这个想法的问题,您的代码中也有一些错误

,代码> val组件:list<设备> 这应该是 val组件:list<组件>

return components.firstornull {它是t ,这应该是 retode> retocer components.firstornull {它是t?,因为您是因为您无法将NULL类型施放为非零类型,

因此您的代码应该看起来像这样:

open class Component
class ComponentA: Component()

class Equipment(val components: List<Component>) {

    inline fun <reified T> getComponent(): T? {
        return components.firstOrNull { it is T } as T?
    }

    val ca: ComponentA by find<ComponentA>()  //this is what I intend to do
    // val ca1: List<ComponentA> by find()       //no error or warning
    // val ca2 by find<List<ComponentA>>()       //Error: Type argument is not within its bounds
}

inline fun <reified T> find(): ReadOnlyProperty<Equipment, T> where T : Component {
    return ReadOnlyProperty { ref, _ -> ref.getComponent<T>() ?: throw Exception("Not found") }
}

well I think the problem is from IDEA with the compiler, I tried using android functions like viewModels() with List instead of ViewModel and I had the same problem, the IDEA will not show any error:

enter image description here

but when you compile the code you will get an error:

enter image description here

so you can ignore this, it's just a problem with the IDEA, also you have some mistakes in your code,

val components: List<Equipment> this should be val components: List< Component >

return components.firstOrNull { it is T } as T and this should be return components.firstOrNull { it is T } as T? because you cannot cast a null type to a non-null type

so your code should look like this:

open class Component
class ComponentA: Component()

class Equipment(val components: List<Component>) {

    inline fun <reified T> getComponent(): T? {
        return components.firstOrNull { it is T } as T?
    }

    val ca: ComponentA by find<ComponentA>()  //this is what I intend to do
    // val ca1: List<ComponentA> by find()       //no error or warning
    // val ca2 by find<List<ComponentA>>()       //Error: Type argument is not within its bounds
}

inline fun <reified T> find(): ReadOnlyProperty<Equipment, T> where T : Component {
    return ReadOnlyProperty { ref, _ -> ref.getComponent<T>() ?: throw Exception("Not found") }
}

ReadOnlyProperty-类型参数自动推断未验证界限

何以畏孤独 2025-02-15 13:28:27

这可能对您有用(GNU SED):

sed -E '/#/{x;s/^/x/;x};/#/,/\$/{x;/^x{2}$/{x;d};x}' file

在保持空间中设置一个计数器,并使用它来确定要删除哪个范围。

这具有能够删除一系列范围的额外优势,例如,

sed -E '/#/{x;s/^/x/;x};/#/,/\$/{x;/^x{2,3}$/{x;d};x}' file

这将删除第二和第三范围。

This might work for you (GNU sed):

sed -E '/#/{x;s/^/x/;x};/#/,/\$/{x;/^x{2}$/{x;d};x}' file

Set up a counter in the hold space and use it to determine which range to delete.

This has the added advantage of being able to delete a range of ranges e.g.

sed -E '/#/{x;s/^/x/;x};/#/,/\$/{x;/^x{2,3}$/{x;d};x}' file

This will delete the second and third ranges.

使用SED,仅删除某个匹配的地址范围

何以畏孤独 2025-02-14 21:03:17

使用以下任何一个 groupby agg 配方。

# Setup
df = pd.DataFrame({
  'a': ['A', 'A', 'B', 'B', 'B', 'C'],
  'b': [1, 2, 5, 5, 4, 6],
  'c': ['x', 'y', 'z', 'x', 'y', 'z']
})
df

   a  b  c
0  A  1  x
1  A  2  y
2  B  5  z
3  B  5  x
4  B  4  y
5  C  6  z

要汇总多列作为列表,请使用以下任何一个:

df.groupby('a').agg(list)
df.groupby('a').agg(pd.Series.tolist)

           b          c
a                      
A     [1, 2]     [x, y]
B  [5, 5, 4]  [z, x, y]
C        [6]        [z]

要组合单列,请将groupby转换为 seripergroupby 对象,然后调用 seripergroupby.agg 。使用,

df.groupby('a').agg({'b': list})  # 4.42 ms 
df.groupby('a')['b'].agg(list)    # 2.76 ms - faster

a
A       [1, 2]
B    [5, 5, 4]
C          [6]
Name: b, dtype: object

Use any of the following groupby and agg recipes.

# Setup
df = pd.DataFrame({
  'a': ['A', 'A', 'B', 'B', 'B', 'C'],
  'b': [1, 2, 5, 5, 4, 6],
  'c': ['x', 'y', 'z', 'x', 'y', 'z']
})
df

   a  b  c
0  A  1  x
1  A  2  y
2  B  5  z
3  B  5  x
4  B  4  y
5  C  6  z

To aggregate multiple columns as lists, use any of the following:

df.groupby('a').agg(list)
df.groupby('a').agg(pd.Series.tolist)

           b          c
a                      
A     [1, 2]     [x, y]
B  [5, 5, 4]  [z, x, y]
C        [6]        [z]

To group-listify a single column only, convert the groupby to a SeriesGroupBy object, then call SeriesGroupBy.agg. Use,

df.groupby('a').agg({'b': list})  # 4.42 ms 
df.groupby('a')['b'].agg(list)    # 2.76 ms - faster

a
A       [1, 2]
B    [5, 5, 4]
C          [6]
Name: b, dtype: object

如何将dataframe行分组为pandas groupby中的列表

何以畏孤独 2025-02-13 23:03:28

对我来说,还有另一个问题。如果您尝试添加一个过去的文件夹,该文件夹在过去有一个 .idea 文件夹,但是您当前的项目具有自己的 .idea 文件夹,您的pycharm可能会因为某种原因而感到困惑 - - 即使您拥有合适的Python/Conda Env。对我而言,删除另一个项目的 .idea 文件夹修复了可以找到明显正确安装的pkgs的混乱。然后,就可以在Pycharm编辑Gui SNF中找到它们,不再以红色为基础。

For me there is also another issue. If you try to add a folder that in the past had a .idea folder, but your current project has it's own .idea folder your pycharm might get confused for some reason -- even if you have the right python/conda env. For me deleting the .idea folder of the other project fixed the confusion that it could find the obviously correctly installed pkgs. Then it was it was able to find them in the pycharm editor GUI snf stopped underlyinging them in red.

如何在Pycharm中使用已安装的软件包?

何以畏孤独 2025-02-13 16:32:49

当然。我假设您想回答“视图引用什么对象?”的问题。您可以在以下查询中找到:

select referenced_schema_name, referenced_entity_name
from sys.sql_expression_dependencies
where referencing_id = object_id('HumanResources.vEmployee');

显然, humanResources.vemployee 在您的视图中(我使用了Ventailing AdventureWorks2019数据库作为测试)。

Sure. I'm assuming that you want to answer the question "what objects does the view reference?". You can find that with the following query:

select referenced_schema_name, referenced_entity_name
from sys.sql_expression_dependencies
where referencing_id = object_id('HumanResources.vEmployee');

Obviously replace HumanResources.vEmployee with your view (I used the venerable AdventureWorks2019 database as a test).

从快照数据库中检查查看依赖项

何以畏孤独 2025-02-13 15:25:40

要在Apache2 phpinfo()中更改PHP版本(PHP版本之间的切换)

解决方案:
我已经通过几个步骤完成了这个解决方案,您可以尝试。
假设我试图将活动版本php8.1更改为php7.4:

step1:第一个停止/禁用活动版本

sudo a2dismod php8.1
systemctl restart apache2

步骤2:首先启动/启用目标版本

sudo a2enmod php7.4

步骤3:restart apache2

systemctl restart apache2

sudo service apache2 restart

step4:手动设置位置:或设置位置:

sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phar /usr/bin/phar7.4
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4


您也可以尝试以下方法

sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar

步骤6:

systemctl restart apache2

现在已解决,眉毛

phpinfo

示例:
在本地服务器中创建一个名为phpinfo.php的页面。

<?php 

echo phpinfo();

?>

http://localhost/phpinfo.php

To change php version in Apache2 phpinfo() (Switch between php version)

Solution:
I have done this solution by few steps, you can try.
suppose i am trying to change the active version php8.1 to php7.4:

Steps1: First stop/disable the active version

sudo a2dismod php8.1
systemctl restart apache2

Steps2: First start/enable the targeted version

sudo a2enmod php7.4

Steps3: Restart apache2

systemctl restart apache2

OR

sudo service apache2 restart

Step4: Set manually the location:

sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phar /usr/bin/phar7.4
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4

Or
You can also try your below method

sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar

Step6:

systemctl restart apache2

Now Solved, brows

phpinfo

Example:
create a page named phpinfo.php into the local server.

<?php 

echo phpinfo();

?>

http://localhost/phpinfo.php

更改phpinfo()中的PHP版本

何以畏孤独 2025-02-13 13:09:58

您不能仅仅将一堆代码转载到类文件中。类文件定义了行为 - 本身不是“您可以运行的东西”。 censored.add(“ example1”)是一个语句,它必须在方法,构造函数或初始化器块中。

错误:

class Example {
  ArrayList<String> censored = new ArrayList<String>();
  censored.add("example1");
}

正确:

class Example {
  ArrayList<String> censored = new ArrayList<String>();

  // This is a constructor
  Example() {
    censored.add("example1");
  }
}

这是极其基本java。如果这将您扔给您足以开始提出问题的循环,那么您就可以在走路之前尝试运行。找到一个Java教程,仔细浏览它。现在忘了在《我的世界》上骇客,请先学习一些Java。然后回到它。

You can't just dump a bunch of code in a class file. A class file defines behaviours - it isn't, itself, 'a thing you can run'. censored.add("example1") is a statement, it has to be in a method or constructor or initializer block.

Wrong:

class Example {
  ArrayList<String> censored = new ArrayList<String>();
  censored.add("example1");
}

correct:

class Example {
  ArrayList<String> censored = new ArrayList<String>();

  // This is a constructor
  Example() {
    censored.add("example1");
  }
}

This is extremely basic java. If this is throwing you for a loop sufficient to start asking questions on SO, you're trying to run before you can walk. Find a java tutorial and go through it carefully. Forget about hacking on minecraft for now, learn some java first. Then get back to it.

Java列表/字符串的Arraylist

何以畏孤独 2025-02-12 19:15:14
H = {1: [1, 6, 3, 4, 5], 2: [1, 3, 2, 4, 5], 3: [1, 6, 3, 4, 5]}
occurences = dict()
for i in H.keys() :
    k = 0
    for j in H.keys():
        if H[j] == H[i] :
            k += 1 
    if i not in occurences.keys():
        occurences[i] = k
H = {1: [1, 6, 3, 4, 5], 2: [1, 3, 2, 4, 5], 3: [1, 6, 3, 4, 5]}
occurences = dict()
for i in H.keys() :
    k = 0
    for j in H.keys():
        if H[j] == H[i] :
            k += 1 
    if i not in occurences.keys():
        occurences[i] = k

Python:如何在字典中汇总和计数相同的值

何以畏孤独 2025-02-12 15:44:48

创建一个滚动控制器,如下所示,

final ScrollController _scrollController = ScrollController();

将其设置为列表视图,如下所示,

  child: ListView.builder(
          
          controller: _scrollController,
.....

当您想将其滚动到顶部时,请添加以下代码。

   _scrollController.animateTo(
                    _scrollController.position.minScrollExtent,
                    duration: Duration(milliseconds: 500),
                    curve: Curves.fastOutSlowIn);

在您的示例中,您可以喜欢

 else if (snapshot.hasData) {
_scrolltoTop();
            return Expanded(
              child: ListView(
                padding: const EdgeInsets.all(0.0),
                scrollDirection: Axis.vertical,
                children: snapshot.data!.map((word) => Padding(...)).toList(),
              ),
            );
          }

void _scrolltoTop(){
Future.delayed(const Duration(milliseconds: 1000), () {
 _scrollController.animateTo(
                        _scrollController.position.minScrollExtent,
                        duration: Duration(milliseconds: 500),
                        curve: Curves.fastOutSlowIn);
});
}

Create a scroll controller like as below

final ScrollController _scrollController = ScrollController();

Set it to the list view like as below

  child: ListView.builder(
          
          controller: _scrollController,
.....

When you want to scroll it to top, please add below code.

   _scrollController.animateTo(
                    _scrollController.position.minScrollExtent,
                    duration: Duration(milliseconds: 500),
                    curve: Curves.fastOutSlowIn);

In your example, you can do like,

 else if (snapshot.hasData) {
_scrolltoTop();
            return Expanded(
              child: ListView(
                padding: const EdgeInsets.all(0.0),
                scrollDirection: Axis.vertical,
                children: snapshot.data!.map((word) => Padding(...)).toList(),
              ),
            );
          }

void _scrolltoTop(){
Future.delayed(const Duration(milliseconds: 1000), () {
 _scrollController.animateTo(
                        _scrollController.position.minScrollExtent,
                        duration: Duration(milliseconds: 500),
                        curve: Curves.fastOutSlowIn);
});
}

如何创建滚动到顶部的列表视图?

何以畏孤独 2025-02-12 14:26:30

您也可以尝试使用 scrollto() 看法。

如果我正确理解您的请求,您应该做这样的事情:

const ListPage = () => {
    const itemSize = 400
    const items = [{ name: 'a' }, { name: 'b' }, { name: 'c' }]

    const scrollView = useRef(null)

    return (
        <View style={{ flex: 1 }}>
            <View
                style={{
                    padding: 20
                }}
            >
                {items.map((item, index) => (
                    <TouchableOpacity
                        key={`head-${index}`}
                        style={{
                            backgroundColor: 'red'
                        }}
                        onPress={() => {
                            scrollView.current.scrollTo({ x: 0, y: itemSize * index, animated: true })
                        }}
                    >
                        <Text style={{ fontSize: 20 }}>{item.name}</Text>
                    </TouchableOpacity>
                ))}
            </View>
            <ScrollView ref={scrollView}>
                {items.map((item, index) => (
                    <View
                        key={`body-${index}`}
                        style={{
                            height: itemSize,
                            backgroundColor: 'green'
                        }}
                    >
                        <Text>{item.name}</Text>
                    </View>
                ))}
            </ScrollView>
        </View>
    )
}

You might also try to use scrollTo() method of React Native's Scroll View.

If I understand your request correctly you should do something like this:

const ListPage = () => {
    const itemSize = 400
    const items = [{ name: 'a' }, { name: 'b' }, { name: 'c' }]

    const scrollView = useRef(null)

    return (
        <View style={{ flex: 1 }}>
            <View
                style={{
                    padding: 20
                }}
            >
                {items.map((item, index) => (
                    <TouchableOpacity
                        key={`head-${index}`}
                        style={{
                            backgroundColor: 'red'
                        }}
                        onPress={() => {
                            scrollView.current.scrollTo({ x: 0, y: itemSize * index, animated: true })
                        }}
                    >
                        <Text style={{ fontSize: 20 }}>{item.name}</Text>
                    </TouchableOpacity>
                ))}
            </View>
            <ScrollView ref={scrollView}>
                {items.map((item, index) => (
                    <View
                        key={`body-${index}`}
                        style={{
                            height: itemSize,
                            backgroundColor: 'green'
                        }}
                    >
                        <Text>{item.name}</Text>
                    </View>
                ))}
            </ScrollView>
        </View>
    )
}

如何滚动到React Native中的列表元素?

何以畏孤独 2025-02-12 04:08:02

您可以使用其他 - 如果进行这项工作。以下是TradingView建议使用Else-If的官方语法。交易视图不允许将值分配给变量多次。

根据您的查询:

Inst = if syminfo.tickerid == "BINANCE:ATOMUSDT"
    "BTCUSDTPERP_OI"
else if syminfo.tickerid == "BINANCE:AVAXUSDT"
    "AVAXUSDTPERP_OI"

You can use ELSE-IF for making this work. Below is the official syntax recommended by tradingview for using else-if. Trading view doesn't allow assigning value to a variable more than once.

Based on your query:

Inst = if syminfo.tickerid == "BINANCE:ATOMUSDT"
    "BTCUSDTPERP_OI"
else if syminfo.tickerid == "BINANCE:AVAXUSDT"
    "AVAXUSDTPERP_OI"

当我更改符号(货币)时,是否可以使我的指标自动更改其输入选项?

何以畏孤独 2025-02-12 02:49:13

这是获取与它们相关的分类法和ACF领域的一种方法。也应该在自定义分类法上工作。

<?php

$categories = get_terms( array(
    'taxonomy'   => 'categories',// any term
    'hide_empty' => false,
) );

if ($categories) {
    foreach ($categories as $cat) {
        $term_fields = get_fields('term_'.$cat->term_id);
        if ($term_fields) {
            $image = $term_fields['image'];
            //you have access to all image sizes
    ?>
    <img src="<?=$image['sizes']['large'];?>" alt="" />
  <?php
           
        }
    }
?>

上面的代码将在WordPress&gt; 5.5.0

要以不同的方式获取术语字段,您可以关注

Here is a way to get taxonomies and acf fields related to them. Should work on Custom taxonomies too.

<?php

$categories = get_terms( array(
    'taxonomy'   => 'categories',// any term
    'hide_empty' => false,
) );

if ($categories) {
    foreach ($categories as $cat) {
        $term_fields = get_fields('term_'.$cat->term_id);
        if ($term_fields) {
            $image = $term_fields['image'];
            //you have access to all image sizes
    ?>
    <img src="<?=$image['sizes']['large'];?>" alt="" />
  <?php
           
        }
    }
?>

Above code will work on wordpress > 5.5.0

To get term fields in different way you can follow acf doc

获取所有分类学术语及其ACF图像字段

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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