还在原地等你

文章 评论 浏览 29

还在原地等你 2025-02-05 03:00:01

根据 [python.docs]:class ctypes.pypes.pydll(name,mode = default = default_mode = default_mode = default_mode = default_mode = default_mode = default_mode = default_mode = default_mode = default_mode = default_mode ,hander = none)强调是我的):

此类实例的行为就像 cdll python gil是 在函数调用过程中发布的,在函数执行后,检查了python错误标志。如果设置了错误标志,则提出了一个python异常。

因此,这仅对呼叫Python C API函数直接有用

因此,您应该用 pydll pydll )替换 cdll cdll )。
我加强了您的示例。

dll00.c

#include <stdio.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#if defined(_WIN32)
#  define DLL00_EXPORT_API __declspec(dllexport)
#else
#  define DLL00_EXPORT_API
#endif


#if defined(__cplusplus)
extern "C" {
#endif

DLL00_EXPORT_API PyObject* createList(unsigned int size, int *pValues);

#if defined(__cplusplus)
}
#endif


PyObject* createList(unsigned int size, int *pValues)
{
    PyObject *pList = PyList_New(size);
    for (unsigned int i = 0; i < size; ++i) {
        PyList_SetItem(pList, i, Py_BuildValue("i", pValues[i]));
    }
    return pList;
}

code00.py

#!/usr/bin/env python

import ctypes as ct
import sys


DLL_NAME = "./dll00.{:s}".format("dll" if sys.platform[:3].lower() == "win" else "so")
IntPtr = ct.POINTER(ct.c_int)


def main(*argv):
    
    dll00 = ct.PyDLL(DLL_NAME)
    create_list = dll00.createList
    create_list.argtypes = (ct.c_uint, IntPtr)
    create_list.restype = ct.py_object

    dim = 5
    int_arr = (ct.c_int * dim)(*range(dim, 0, -1))  # Intermediary step: create an array
    res = create_list(dim, ct.cast(int_arr, IntPtr))
    print("\n{:s} returned: {:}".format(create_list.__name__, res))


if __name__ == "__main__":
    print("Python {:s} {:03d}bit on {:s}\n".format(" ".join(elem.strip() for elem in sys.version.split("\n")),
                                                   64 if sys.maxsize > 0x100000000 else 32, sys.platform))
    rc = main(*sys.argv[1:])
    print("\nDone.")
    sys.exit(rc)

输出

  [cfati@cfati-5510-0:e:\ work \ work \ dev \ stackoverflow \ q072231434]&gt; Sopr.Bat
###设置较短的提示,在粘贴stackoverflow(或其他)页面###时,以更好地适应

[提示]&gt; “ c:\ install \ pc032 \ microsoft \ visualstudiocommunity \ 2019 \ vc \ auxiliary \ build \ vcvarsall.bat” x64&gt; nul

[提示]&gt; dir /b
code00.py
dll00.c

[提示]&gt;
[提示]&gt; cl /nologo /md /ddll /i "c: \ install \ pc064 \ python \ pypython \03.09 \ include“ dll00.c /link /link /nologo /nologo /dll /out:dll00.dll 00.dll /libpath: \ python \ python \ 03.09 \ libs'
dll00.c
   创建库dll00.lib和对象dll00.exp

[提示]&gt;
[提示]&gt; dir /b
code00.py
dll00.c
dll00.dll
dll00.exp
dll00.lib
dll00.obj

[提示]&gt;
[提示]&gt; ”
Python 3.9.9(标签/v3.9.9:CCB0E6A,2021,18:08:50)[MSC V.1929 64 BIT(AMD64)] 064BIT


造物主义者返回:[5,4,3,2,1]

完毕。
 

According to [Python.Docs]: class ctypes.PyDLL(name, mode=DEFAULT_MODE, handle=None) (emphasis is mine):

Instances of this class behave like CDLL instances, except that the Python GIL is not released during the function call, and after the function execution the Python error flag is checked. If the error flag is set, a Python exception is raised.

Thus, this is only useful to call Python C api functions directly.

So, you should replace cdll (CDLL) by pydll (PyDLL).
I enhanced your example a bit.

dll00.c:

#include <stdio.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#if defined(_WIN32)
#  define DLL00_EXPORT_API __declspec(dllexport)
#else
#  define DLL00_EXPORT_API
#endif


#if defined(__cplusplus)
extern "C" {
#endif

DLL00_EXPORT_API PyObject* createList(unsigned int size, int *pValues);

#if defined(__cplusplus)
}
#endif


PyObject* createList(unsigned int size, int *pValues)
{
    PyObject *pList = PyList_New(size);
    for (unsigned int i = 0; i < size; ++i) {
        PyList_SetItem(pList, i, Py_BuildValue("i", pValues[i]));
    }
    return pList;
}

code00.py:

#!/usr/bin/env python

import ctypes as ct
import sys


DLL_NAME = "./dll00.{:s}".format("dll" if sys.platform[:3].lower() == "win" else "so")
IntPtr = ct.POINTER(ct.c_int)


def main(*argv):
    
    dll00 = ct.PyDLL(DLL_NAME)
    create_list = dll00.createList
    create_list.argtypes = (ct.c_uint, IntPtr)
    create_list.restype = ct.py_object

    dim = 5
    int_arr = (ct.c_int * dim)(*range(dim, 0, -1))  # Intermediary step: create an array
    res = create_list(dim, ct.cast(int_arr, IntPtr))
    print("\n{:s} returned: {:}".format(create_list.__name__, res))


if __name__ == "__main__":
    print("Python {:s} {:03d}bit on {:s}\n".format(" ".join(elem.strip() for elem in sys.version.split("\n")),
                                                   64 if sys.maxsize > 0x100000000 else 32, sys.platform))
    rc = main(*sys.argv[1:])
    print("\nDone.")
    sys.exit(rc)

Output:

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q072231434]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###

[prompt]> "c:\Install\pc032\Microsoft\VisualStudioCommunity\2019\VC\Auxiliary\Build\vcvarsall.bat" x64 > nul

[prompt]> dir /b
code00.py
dll00.c

[prompt]>
[prompt]> cl /nologo /MD /DDLL /I"c:\Install\pc064\Python\Python\03.09\include" dll00.c  /link /NOLOGO /DLL /OUT:dll00.dll /LIBPATH:"c:\Install\pc064\Python\Python\03.09\libs"
dll00.c
   Creating library dll00.lib and object dll00.exp

[prompt]>
[prompt]> dir /b
code00.py
dll00.c
dll00.dll
dll00.exp
dll00.lib
dll00.obj

[prompt]>
[prompt]> "e:\Work\Dev\VEnvs\py_pc064_03.09_test0\Scripts\python.exe" code00.py
Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] 064bit on win32


createList returned: [5, 4, 3, 2, 1]

Done.

python在c dll中

还在原地等你 2025-02-04 09:29:59

一个词答案:异步性

前言

这个话题在堆栈溢出中至少迭代了几千次。因此,首先,我想指出一些非常有用的资源:


手头问题的答案

让我们首先追踪共同行为。在所有示例中,outerscopevar函数内进行了修改。该功能显然不会立即执行;它是作为参数分配或通过的。这就是我们所说的 回调

现在的问题是,该回调是什么时候打来的?

这取决于情况。让我们尝试再次追踪一些常见的行为:

  • img.onload可以在将来的某个时候称为何时(以及如果)已成功加载图像。
  • settimeout可以在将来的某个时候称为 过期,并且未通过clear> clear> clear> cleartimeout取消超时。注意:即使使用0作为延迟,所有浏览器也具有最小超时延迟帽(在HTML5规格中指定为4ms)。
  • jQuery $。POST的回调可以在将来的某个时候称为何时(以及IF)AJAX请求已成功完成。
  • Node.js的fs.ReadFile在将来的某个时候可以称为 成功读取文件或丢弃错误。

在所有情况下,我们都有一个回调,可以在以后的某个时候运行。我们将这种“将来的某个时候”称为异步流

异步执行将从同步流中推出。也就是说,在同步代码堆栈执行时,异步代码将永远不会执行。这就是JavaScript被单线读取的含义。

更具体地说,当JS引擎闲置时 - 不执行(a)同步代码的堆栈 - 它将对可能触发异步回调的事件进行轮询(例如,过期的超时,接收到网络响应)并又一次地执行它们。这被认为是事件loop

也就是说,手绘红色形状中突出显示的异步代码只有在其各自的代码块中的所有剩余同步代码执行后才能执行:

“

简而言之,回调函数是同步创建但异步执行的。您不能依靠执行异步函数,直到您知道它已被执行,以及如何做到这一点?

真的很简单。取决于异步函数执行的逻辑应从此异步函数内部启动/调用。例如,在回调函数中移动警报 s和console.log s将输出预期的结果,因为结果在此点可用。

通常,实现自己的回调逻辑,

您需要通过异步功能的结果做更多​​的事情,或者根据调用异步功能的位置,而将结果做不同的事情。让我们解决一个更复杂的示例:

var outerScopeVar;
helloCatAsync();
alert(outerScopeVar);

function helloCatAsync() {
    setTimeout(function() {
        outerScopeVar = 'Nya';
    }, Math.random() * 2000);
}

注意:我正在使用settimeout随机延迟作为通用异步函数;同一示例适用于Ajax,ReadFileonload和任何其他异步流。

这个示例显然与其他示例相同的问题;直到异步函数执行之前,它才等待。

让我们通过实现自己的回调系统来解决它。首先,我们摆脱了那个丑陋的outerscopevar,在这种情况下是完全无用的。然后,我们添加一个接受函数参数的参数,即我们的回调。当异步操作完成时,我们将调用此回调,通过结果。实现(请按顺序阅读评论):

// 1. Call helloCatAsync passing a callback function,
//    which will be called receiving the result from the async operation
helloCatAsync(function(result) {
    // 5. Received the result from the async function,
    //    now do whatever you want with it:
    alert(result);
});

// 2. The "callback" parameter is a reference to the function which
//    was passed as an argument from the helloCatAsync call
function helloCatAsync(callback) {
    // 3. Start async operation:
    setTimeout(function() {
        // 4. Finished async operation,
        //    call the callback, passing the result as an argument
        callback('Nya');
    }, Math.random() * 2000);
}

上述示例的代码段:

// 1. Call helloCatAsync passing a callback function,
//    which will be called receiving the result from the async operation
console.log("1. function called...")
helloCatAsync(function(result) {
    // 5. Received the result from the async function,
    //    now do whatever you want with it:
    console.log("5. result is: ", result);
});

// 2. The "callback" parameter is a reference to the function which
//    was passed as an argument from the helloCatAsync call
function helloCatAsync(callback) {
    console.log("2. callback here is the function passed as argument above...")
    // 3. Start async operation:
    setTimeout(function() {
    console.log("3. start async operation...")
    console.log("4. finished async operation, calling the callback, passing the result...")
        // 4. Finished async operation,
        //    call the callback passing the result as argument
        callback('Nya');
    }, Math.random() * 2000);
}

在实际用例中,大多数情况下,DOM API和大多数库已经提供了回调功能(在此示例示例中Hellocatasync实现)。您只需要传递回调函数,并了解它将从同步流中执行并重组代码以适应它。

您还会注意到,由于异步性质,不可能返回从异步流回到定义回调的同步流中的值,因为异步回调是在同步之后执行的,代码已经完成执行。

您必须使用回调模式或...承诺,而不是返回从异步回调中获得值。

承诺

虽然有多种方法可以保持“ noreferrer”> callback地狱与Vanilla JS一起在BAY中,承诺正在越来越受欢迎,目前正在标准化在ES6中(请参见 promise -promise -promise -mdn )。

承诺(又名期货)提供了对异步代码的更线性,因此令人愉悦的阅读,但是解释它们的整个功能不超出此问题的范围。取而代之的是,我将为有兴趣的人留下这些优质的资源:


性的更多阅读材料

  • 有关JavaScript异步 >使用香草JS示例和node.js代码很好地说明异步代码和回调。

注意:我将这个答案标记为社区Wiki。因此,至少有100个声誉的人都可以编辑和改进它!如果您愿意,请随时提高此答案或提交全新的答案。

我想将这个问题变成一个与Ajax无关的异步问题的规范主题(有因此,从Ajax的电话中?

One word answer: asynchronicity.

Forewords

This topic has been iterated at least a couple of thousands of times here in Stack Overflow. Hence, first off I'd like to point out some extremely useful resources:


The answer to the question at hand

Let's trace the common behavior first. In all examples, the outerScopeVar is modified inside of a function. That function is clearly not executed immediately; it is being assigned or passed as an argument. That is what we call a callback.

Now the question is, when is that callback called?

It depends on the case. Let's try to trace some common behavior again:

  • img.onload may be called sometime in the future when (and if) the image has successfully loaded.
  • setTimeout may be called sometime in the future after the delay has expired and the timeout hasn't been canceled by clearTimeout. Note: even when using 0 as delay, all browsers have a minimum timeout delay cap (specified to be 4ms in the HTML5 spec).
  • jQuery $.post's callback may be called sometime in the future when (and if) the Ajax request has been completed successfully.
  • Node.js's fs.readFile may be called sometime in the future when the file has been read successfully or thrown an error.

In all cases, we have a callback that may run sometime in the future. This "sometime in the future" is what we refer to as asynchronous flow.

Asynchronous execution is pushed out of the synchronous flow. That is, the asynchronous code will never execute while the synchronous code stack is executing. This is the meaning of JavaScript being single-threaded.

More specifically, when the JS engine is idle -- not executing a stack of (a)synchronous code -- it will poll for events that may have triggered asynchronous callbacks (e.g. expired timeout, received network response) and execute them one after another. This is regarded as Event Loop.

That is, the asynchronous code highlighted in the hand-drawn red shapes may execute only after all the remaining synchronous code in their respective code blocks have executed:

async code highlighted

In short, the callback functions are created synchronously but executed asynchronously. You can't rely on the execution of an asynchronous function until you know it has been executed, and how to do that?

It is simple, really. The logic that depends on the asynchronous function execution should be started/called from inside this asynchronous function. For example, moving the alerts and console.logs inside the callback function would output the expected result because the result is available at that point.

Implementing your own callback logic

Often you need to do more things with the result from an asynchronous function or do different things with the result depending on where the asynchronous function has been called. Let's tackle a bit more complex example:

var outerScopeVar;
helloCatAsync();
alert(outerScopeVar);

function helloCatAsync() {
    setTimeout(function() {
        outerScopeVar = 'Nya';
    }, Math.random() * 2000);
}

Note: I'm using setTimeout with a random delay as a generic asynchronous function; the same example applies to Ajax, readFile, onload, and any other asynchronous flow.

This example clearly suffers from the same issue as the other examples; it is not waiting until the asynchronous function executes.

Let's tackle it by implementing a callback system of our own. First off, we get rid of that ugly outerScopeVar which is completely useless in this case. Then we add a parameter that accepts a function argument, our callback. When the asynchronous operation finishes, we call this callback, passing the result. The implementation (please read the comments in order):

// 1. Call helloCatAsync passing a callback function,
//    which will be called receiving the result from the async operation
helloCatAsync(function(result) {
    // 5. Received the result from the async function,
    //    now do whatever you want with it:
    alert(result);
});

// 2. The "callback" parameter is a reference to the function which
//    was passed as an argument from the helloCatAsync call
function helloCatAsync(callback) {
    // 3. Start async operation:
    setTimeout(function() {
        // 4. Finished async operation,
        //    call the callback, passing the result as an argument
        callback('Nya');
    }, Math.random() * 2000);
}

Code snippet of the above example:

// 1. Call helloCatAsync passing a callback function,
//    which will be called receiving the result from the async operation
console.log("1. function called...")
helloCatAsync(function(result) {
    // 5. Received the result from the async function,
    //    now do whatever you want with it:
    console.log("5. result is: ", result);
});

// 2. The "callback" parameter is a reference to the function which
//    was passed as an argument from the helloCatAsync call
function helloCatAsync(callback) {
    console.log("2. callback here is the function passed as argument above...")
    // 3. Start async operation:
    setTimeout(function() {
    console.log("3. start async operation...")
    console.log("4. finished async operation, calling the callback, passing the result...")
        // 4. Finished async operation,
        //    call the callback passing the result as argument
        callback('Nya');
    }, Math.random() * 2000);
}

Most often in real use cases, the DOM API and most libraries already provide the callback functionality (the helloCatAsync implementation in this demonstrative example). You only need to pass the callback function and understand that it will execute out of the synchronous flow and restructure your code to accommodate for that.

You will also notice that due to the asynchronous nature, it is impossible to return a value from an asynchronous flow back to the synchronous flow where the callback was defined, as the asynchronous callbacks are executed long after the synchronous code has already finished executing.

Instead of returning a value from an asynchronous callback, you will have to make use of the callback pattern, or... Promises.

Promises

Although there are ways to keep the callback hell at bay with vanilla JS, promises are growing in popularity and are currently being standardized in ES6 (see Promise - MDN).

Promises (a.k.a. Futures) provide a more linear, and thus pleasant, reading of the asynchronous code, but explaining their entire functionality is out of the scope of this question. Instead, I'll leave these excellent resources for the interested:


More reading material about JavaScript asynchronicity


Note: I've marked this answer as Community Wiki. Hence anyone with at least 100 reputations can edit and improve it! Please feel free to improve this answer or submit a completely new answer if you'd like as well.

I want to turn this question into a canonical topic to answer asynchronicity issues that are unrelated to Ajax (there is How to return the response from an AJAX call? for that), hence this topic needs your help to be as good and helpful as possible!

为什么我的变量在函数内部修改后不变? - 异步代码参考

还在原地等你 2025-02-04 04:15:28

设置mapred.max.split.size = 2560000000;
增加单个地图处理的文件的大小,从而减少地图的数量

set mapred.max.split.size=2560000000;
Increase the size of the file processed by a single map, thereby reducing the number of maps

HDFS产生的Hive提取太慢,因为太多的映射任务,当执行Hive SQL查询时,我该如何合并查询结果

还在原地等你 2025-02-03 19:40:38

您的注册标题菜单带有标头键,并试图通过Top-Menu的钥匙将其获取,这是不可能的。您必须使用标头键键添加并获取标头菜单。我们已经更新了代码。您可以使用此代码。

<?php 
wp_nav_menu( array(
     'theme_location' => 'header-menu',
     'container' => 'ul',
     'menu_class'=> 'd-flex main-menu'
    ) ); 
?>

You have register header menu with header-menu key and trying to get it by key of top-menu which is not possible. You have to use the header-menu key to add and get a header menu. we have updated the code. you can use this code.

<?php 
wp_nav_menu( array(
     'theme_location' => 'header-menu',
     'container' => 'ul',
     'menu_class'=> 'd-flex main-menu'
    ) ); 
?>

如何使用WP_NAV_MENU在WordPress中显示自定义链接?

还在原地等你 2025-02-03 08:04:08

仅通过公式,尝试

=QUERY({arrayformula(eomonth(DataAllMonths!A1:A,0)),DataAllMonths!B1:B}, "SELECT (Col1), COUNT(Col1) WHERE LOWER(Col2) LIKE '%no empathy%' GROUP BY (Col1) LABEL (Col1) 'Month', COUNT(Col1) 'Total'", True)

“在此处输入图像描述”

并将列的格式更改为mmm

“在此处输入图像说明”

参考

eomonth

By formula only, Try

=QUERY({arrayformula(eomonth(DataAllMonths!A1:A,0)),DataAllMonths!B1:B}, "SELECT (Col1), COUNT(Col1) WHERE LOWER(Col2) LIKE '%no empathy%' GROUP BY (Col1) LABEL (Col1) 'Month', COUNT(Col1) 'Total'", True)

enter image description here

and change format of column to MMM

enter image description here

reference

EOMONTH

用查询()中的月份名称替换月号

还在原地等你 2025-02-03 04:26:07

不确定这是否是修复的,但是我通过为ComboBox设置图标大小来解决它。我认为出了问题是,无论添加项目时图标的大小如何,可能都有一些默认的大小。我的图标尺寸为50x15,因此我添加了以下几行:

QSize size(50, 15);
ui.comboBox->setIconSize(size);

现在它正确完成并提供了正确的视图。

“正确视图”

Not sure if this is the go to fix, but I solved it by setting an icon size for the combobox. What I think goes wrong is that there is probably some default size set, no matter the size of the icons when adding items. My icons were of size 50x15 and so I added the following lines:

QSize size(50, 15);
ui.comboBox->setIconSize(size);

Now it is done correctly and gives the correct view.

the correct view

QT对齐最重要的内容在Combobox中

还在原地等你 2025-02-02 16:34:11

运行命令:

pip install jupyter

它对我有用。

Run command:

pip install jupyter

It worked for me.

jupyter笔记本安装在python 3.8中的ubuntu 20.04

还在原地等你 2025-02-02 14:47:30

我不习惯在PHP中进行编码的方式,但是对我来说,您的功能名称索引是您无法获得所需的原因。尝试将返回$ data将其添加到您的代码中,这样看起来像这样:

public function index(){     

            $posts = $this->blogModel->getPosts();

            $data = [
                'posts' => $posts
            ];

            $this->view('pages/blog', $data);
            return $data;
        }

I am not used to this way of coding in php, but to me it looks like your function named index is reason you can't get what you need. Try adding return $data to your code so it looks like this:

public function index(){     

            $posts = $this->blogModel->getPosts();

            $data = [
                'posts' => $posts
            ];

            $this->view('pages/blog', $data);
            return $data;
        }

问题检索PHP中HTML视图的帖子列表

还在原地等你 2025-02-02 14:14:09

尝试一下

_getImage(BuildContext context) async {
    var picture = await ImagePicker().pickImage(source: ImageSource.gallery);
    setState(() {
      imageFile = File(picture!.path);
      dirPath = picture.path;
      print('path');
      print(dirPath);
    });
  }

Try this

_getImage(BuildContext context) async {
    var picture = await ImagePicker().pickImage(source: ImageSource.gallery);
    setState(() {
      imageFile = File(picture!.path);
      dirPath = picture.path;
      print('path');
      print(dirPath);
    });
  }

可以通过扑来中的图像选择器获取图像文件

还在原地等你 2025-02-02 07:29:23

尝试此操作时,

df.drop('Unnamed: 0', axis = 1, inplace = True)

请始终使用Inplace = true当您更改数据框架中的某些内容或如果您不更改源dataframe,则尝试将其存储在不同的数据框架中,

new_df = df.drop('Unnamed: 0', axis = 1)

Try this

df.drop('Unnamed: 0', axis = 1, inplace = True)

Always use inplace = True when you are changing something in place in a dataframe or try to store in the different dataframe like this if you are not changing the source dataframe,

new_df = df.drop('Unnamed: 0', axis = 1)

为什么可以从Python中导入的CSV删除列/字段?

还在原地等你 2025-02-02 01:40:27

如果您只想知道拦截器是否正在返回正确的响应,则可以创建一个正在限制拦截器的类,并为handlemyException提供公共包装方法。然后,您实例化了新课程,请致电包装器并断言返回的响应。

If you just want to know if the interceptor is returning the correct response, you could create a class which is extenting the interceptor and provides an public wrapper method for handleMyException. Then you instantiate that new class, call the wrapper and assert on the returned response.

如何使用Mockito测试异常处理程序,而没有真实的控制器调用(春季)

还在原地等你 2025-02-01 15:49:35

我不得不将所有应用都位于PythonPath环境变量的文件夹附加到这样的文件夹:
pythonpath =“ $ {pythonpath}:/project_name/project_name”

I had to append the folder where all my apps lie to the PYTHONPATH environment variable like so:
PYTHONPATH="${PYTHONPATH}:/project_name/project_name"

Daphne ModulenotFoundError:No模块名为&#x27; app_name&#x27;

还在原地等你 2025-02-01 13:42:07

cstring包含lpctstr的隐式转换操作员。它是为此精确使用而设计的。

这是您传递const字符串的事实,无法修改使其安全。

CString contains an implicit conversion operator for LPCTSTR. It was designed for this exact usage.

It's the fact that you're passing a const string that can't be modified that makes it safe.

用Cstring替换LPCTSTR安全吗?

还在原地等你 2025-02-01 10:06:01

我可能没有一种更好的方式。但是,我们可以通过

假设您有一个屏幕b,您想向后滑动以转到屏幕home,然后将params传递给home from b在该滑动动作上。然后,您可以如下实现这一目标。

function B({navigation}) {

  React.useEffect(() => navigation.addListener('beforeRemove', (e) => {
         
        // the navigation.navigate will fire beforeRemove which causes an infinite loop. we guard this here
        if (e.data.action.type === "NAVIGATE") {
          return
        }
        // Prevent default behavior of leaving the screen
        e.preventDefault();
        
        // navigate manually
        navigation.navigate({
            name: 'Home',
            params: { post: postText },
            merge: true,
        });        
        
   }), [navigation]);

  return ( ... )
}

编辑: navigation.navigate很明显,beforeRemove事件再次引起无限循环。我们可以如上图所示。

There might be a better way that I am unaware of. However, we can achieve this manually by preventing the default back action and handling this ourselves.

Suppose that you have a screen B and you want to swipe back to go to a screen Home and pass params to Home from B on that swipe action. Then, you can achieve this as follows.

function B({navigation}) {

  React.useEffect(() => navigation.addListener('beforeRemove', (e) => {
         
        // the navigation.navigate will fire beforeRemove which causes an infinite loop. we guard this here
        if (e.data.action.type === "NAVIGATE") {
          return
        }
        // Prevent default behavior of leaving the screen
        e.preventDefault();
        
        // navigate manually
        navigation.navigate({
            name: 'Home',
            params: { post: postText },
            merge: true,
        });        
        
   }), [navigation]);

  return ( ... )
}

Edit: The navigation.navigate fires the beforeRemove event again, obviously, which causes an infinite loop. We can guard this as shown above.

将参数传递到滑动/手势上的上一个屏幕

还在原地等你 2025-01-31 11:07:28

使用您正在查看的指定列分组的CTE和ROW_NUMBER可以干净地删除重复值,因为ROW_NUMBER逐步计数,并通过汇总的分区的重复值进行了重复计数。当订购时发现新的分组时,它将ROW_NUMBER重置为1,从下一个不同分组值的记录开始。

 WITH CTE AS (
 SELECT *,
 ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col1) AS RN
 FROM #temp
 )

 DELETE FROM CTE WHERE RN<>1

Using a CTE and ROW_NUMBER grouped by the specified column you are looking at can cleanly remove duplicate values, as ROW_NUMBER counts incrementally with duplicate values of the PARTITION BY aggregation. When a new grouping is found when ordered, it resets the ROW_NUMBER to 1 starting at that next record of different grouped values.

 WITH CTE AS (
 SELECT *,
 ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col1) AS RN
 FROM #temp
 )

 DELETE FROM CTE WHERE RN<>1

有没有办法从SQL Server中使用单列的表中删除重复?

更多

推荐作者

佚名

文章 0 评论 0

今天

文章 0 评论 0

゛时过境迁

文章 0 评论 0

达拉崩吧

文章 0 评论 0

呆萌少年

文章 0 评论 0

孤者何惧

文章 0 评论 0

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