我需要使用负动态索引([: - index])对列表进行切片.这很容易,直到我意识到如果我的动态索引的值为0,则没有返回任何项目,而是返回整个列表.我怎样才能以索引为0的方式实现它,它返回整个字符串?我的代码很长很复杂,但基本上这个例子显示了问题:
arr='test text'
index=2
print arr[:-index]
>>'test te' #Entire string minus 2 from the right
index=1
print arr[:-index]
>>'test tex' #Entire string minus 1 from the right
index=0
print arr[:-index]
>>'' #I would like entire string minus 0 from the right
Run Code Online (Sandbox Code Playgroud)
注意:我使用的是Python 2.7.
我正在尝试创建一个线程使用std::async,但我不断收到错误"没有匹配函数来调用' async(std::launch, <unresolved overloaded function type>, std::string&)''就行了
ConnectFuture = std::async(std::launch::async, Connect_T,ip);
Run Code Online (Sandbox Code Playgroud)
以下是产生此行为的代码:
#include <future>
class libWrapper
{
public:
void Connect(std::string ip);
void Connect_T(std::string ip);
private:
std::future<void> ConnectFuture;
};
void libWrapper::Connect(std::string ip){
auto status = ConnectFuture.wait_for(std::chrono::seconds(0));
if (status != std::future_status::timeout)
{
ConnectFuture = std::async(std::launch::async, Connect_T,ip);
}
}
void libWrapper::Connect_T(std::string ip)
{
}
int main(int argc, char** argv) {
libWrapper lW;
lW.Connect("192.168.3.1");
return 0;
}
Run Code Online (Sandbox Code Playgroud)