小编mkr*_*er1的帖子

如何从GIt中删除特定的提交?

我想从我的远程存储库中删除一些提交.在我的回购中我几乎没有这样的提交:

commits    messages

abcd123    some message
xyze456    another commit message
98y65r4    this commit is not required
987xcrt    this commit is not required
bl8976t    initial commit
Run Code Online (Sandbox Code Playgroud)

我想删除提交 98y65r4987xcrt我的回购.怎么实现呢?

git

10
推荐指数
1
解决办法
2万
查看次数

Gradle 构建失败,新的导入规则

我将 android studio 更新到 3.6 版后遇到错误。当我尝试导入Scenceform资产时,它在下图中显示警告,无论我点击什么,它都会返回

java.lang.RuntimeException: java.lang.NoSuchMethodError: com.android.tools.idea.templates.recipe.RecipeExecutor.append(Ljava/io/File;Ljava/io/File;)

警告图片和选择选项后的错误

我怎样才能解决这个问题?

android-studio

10
推荐指数
1
解决办法
3934
查看次数

为什么 asyncio.sleep(0) 使我的代码更快?

如果我从扫描仪中删除这一行,

await asyncio.sleep(0)
Run Code Online (Sandbox Code Playgroud)

工作时间从5秒增长到400秒。

为什么会发生这种情况?

我的代码:

import os
import asyncio
import time

async def rl(response):
    await asyncio.sleep(0)
    return response.readlines()  

async def scan_Ip(addr):
    print(addr)
    response = os.popen("ping -n 1 " + addr)
    data = await rl(response)
    for line in data:
        if 'TTL' in line:
            print(data)

async def scan():
    tasks=[]
    for ip in range(0, 256):
        tasks.append(asyncio.create_task(scan_Ip(f'192.168.8.{ip}')))
    await asyncio.wait(tasks)

if __name__ == '__main__':
    start_time = time.time()
    asyncio.run(scan())
    print(f"--- {time.time() - start_time} seconds ---")
Run Code Online (Sandbox Code Playgroud)

python python-asyncio

10
推荐指数
2
解决办法
8721
查看次数

如果我不重置 Python 的 ContextVars 会发生什么?

这是Python中的内存泄漏吗?

import contextvars

contextvar = contextvars.ContextVar('example')

while True:
   string = 'hello world'
   token = contextvar.set(string)
Run Code Online (Sandbox Code Playgroud)

contextvar 是一个随着你向它推送的次数越多而不断增长的堆栈吗?

如果我从不打电话怎么办contextvar.reset(token)

或者一切都通过引用计数来处理?

python python-contextvars

10
推荐指数
1
解决办法
1885
查看次数

与目标“binary:logistic”一起使用的默认评估指标已从“error”更改为“logloss”

在使用 optuna 进行超参数调整后,我尝试将 XGBClassifier 适合我的数据集,但我不断收到此警告:

与目标“binary:logistic”一起使用的默认评估指标从“error”更改为“logloss”

下面是我的代码:

#XGBC MODEL
model = XGBClassifier(random_state = 69)

cross_rfc_score = -1 * cross_val_score(model, train_x1, train_y,
                           cv = 5, n_jobs = -1, scoring = 'neg_mean_squared_error')
base_rfc_score = cross_rfc_score.mean()
Run Code Online (Sandbox Code Playgroud)

但如果我使用 Optuna 然后拟合获得的参数,它会给我警告。下面是代码:

def objective(trial):
    learning_rate = trial.suggest_float('learning_rate', 0.001, 0.01)
    n_estimators = trial.suggest_int('n_estimators', 10, 500)
    sub_sample = trial.suggest_float('sub_sample', 0.0, 1.0)
    max_depth = trial.suggest_int('max_depth', 1, 20)

    params = {'max_depth' : max_depth,
           'n_estimators' : n_estimators,
           'sub_sample' : sub_sample,
           'learning_rate' : learning_rate}

    model.set_params(**params)

    return np.mean(-1 * cross_val_score(model, train_x1, train_y,
                            cv …
Run Code Online (Sandbox Code Playgroud)

mse xgboost optuna

10
推荐指数
1
解决办法
9995
查看次数

Python 3.9:在 __anext__ 中使用 Yield 时,“async_generator 不能在 'await' 表达式中使用”

我正在尝试以下操作:

class Payload_Session_Generator:
    def __init__(self):
        pass

    async def __anext__(self):
        async for payload in generate_fb_payload():
            if type(payload) != str:
                yield payload
            else:
                StopAsyncIteration

    def __aiter__(self):
        return self
Run Code Online (Sandbox Code Playgroud)

然后将其作为实例传递给不同的函数,并__aiter__显式调用该方法,并且该方法_iter是上述类的对象:

chunk = await self._iter.__anext__()
Run Code Online (Sandbox Code Playgroud)

这会产生以下错误:

类型错误:对象 async_generator 不能在“await”表达式中使用

python generator python-3.x python-asyncio

10
推荐指数
2
解决办法
2万
查看次数

为什么 x*x 和 x**2 会返回不同的结果?

x = 1.5 * 10 ** 156
print(x * x)
print(x ** 2)
Run Code Online (Sandbox Code Playgroud)

x * x并且x ** 2在数学上是等价的。但当x较大时,前者可以返回 的结果inf,而后者会引发溢出错误。

x = 1.5 * 10 ** 156
print(x * x)
print(x ** 2)
Run Code Online (Sandbox Code Playgroud)

为什么会这样呢?

python floating-point

10
推荐指数
1
解决办法
197
查看次数

使用Python和Click创建shell命令行应用程序

我正在使用click(http://click.pocoo.org/3/)来创建命令行应用程序,但我不知道如何为此应用程序创建shell.
假设我正在编写一个名为test的程序,我有一个名为subtest1subtest2的命令

我能够从终端工作,如:

$ test subtest1
$ test subtest2
Run Code Online (Sandbox Code Playgroud)

但我在考虑的是一个shell,所以我可以这样做:

$ test  
>> subtest1  
>> subtest2
Run Code Online (Sandbox Code Playgroud)

点击可以实现吗?

python command-line-interface python-click

9
推荐指数
1
解决办法
4110
查看次数

Python中带条件的对象过滤列表

我有一个这样的列表结构:

listpost =
[
   {
      "post_id":"01",
      "text":"abc",
      "time": datetime.datetime(2021, 8, 5, 15, 53, 19),
      "type":"normal",
   },
   {
      "post_id":"02",
      "text":"nothing",
      "time":datetime.datetime(2021, 8, 5, 15, 53, 19),
      "type":"normal",
   }
]
Run Code Online (Sandbox Code Playgroud)

如果只有 [text] 具有“abc”,我想按 [text] 键中的文本过滤列表

所以这个例子看起来像这样

listpost =
[
   {
      "post_id":"01",
      "text":"abc",
      "time": datetime.datetime(2021, 8, 5, 15, 53, 19),
      "type":"normal",
   }
]
Run Code Online (Sandbox Code Playgroud)

我的代码:

from facebook_scraper import get_posts

listposts = []

for post in get_posts("myhealthkkm", pages=1):
    listposts.append(post)
print(listposts)


Run Code Online (Sandbox Code Playgroud)

python

9
推荐指数
2
解决办法
1万
查看次数

e^x 没有 math.h

我试图在不使用 math.h 的情况下找到 e x 。当x大于或小于 ~\xc2\xb120时,我的代码给出错误的答案。我尝试将所有双精度类型更改为长双精度类型,但它在输入上产生了一些垃圾。

\n

我的代码是:

\n
#include <stdio.h>\n\ndouble fabs1(double x) {\n    if(x >= 0){\n        return x;\n    } else {\n        return x*(-1);\n    }\n}\n\ndouble powerex(double x) {\n    double a = 1.0, e = a;\n    for (int n = 1; fabs1(a) > 0.001; ++n) {\n        a = a * x / n;\n        e += a;\n    }\n    return e;\n}\n\nint main(){\n    freopen("input.txt", "r", stdin);\n    freopen("output.txt", "w", stdout);\n    int n;\n    scanf("%d", &n);\n    for(int i = 0; i<n; i++) {\n        double …
Run Code Online (Sandbox Code Playgroud)

c math numerical-methods

9
推荐指数
1
解决办法
955
查看次数