相关疑难解决方法(0)

为什么在这个python片段中允许使用分号?

Python不保证使用分号来结束语句.那么为什么这个(下面)允许?

import pdb; pdb.set_trace()
Run Code Online (Sandbox Code Playgroud)

python

148
推荐指数
9
解决办法
11万
查看次数

Python线程字符串参数

我遇到Python线程问题并在参数中发送字符串.

def processLine(line) :
    print "hello";
    return;
Run Code Online (Sandbox Code Playgroud)

.

dRecieved = connFile.readline();
processThread = threading.Thread(target=processLine, args=(dRecieved));
processThread.start();
Run Code Online (Sandbox Code Playgroud)

其中dRecieved是连接读取的一行字符串.它调用一个简单的函数,到目前为止只有一个打印"hello"的工作.

但是我收到以下错误

Traceback (most recent call last):
File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "C:\Python25\lib\threading.py", line 446, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: processLine() takes exactly 1 arguments (232 given)
Run Code Online (Sandbox Code Playgroud)

232是我试图传递的字符串的长度,所以我猜它会将其分解为每个字符并尝试传递这样的参数.如果我只是正常调用函数,它工作正常,但我真的想将它设置为一个单独的线程.

python multithreading

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

Python:分号是做什么用的?

我在线获得了一个函数来帮助我完成当前的项目,它在某些行上有分号.我想知道为什么?是打破这个功能吗?

def containsAny(self, strings=[]):
    alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
    for string in strings:
        for char in string:
            if char in alphabet: return 1;
    return 0;
Run Code Online (Sandbox Code Playgroud)

我上网的功能很少修改:

for string in strings:
    for char in string:
        if char in alphabet: return 1;
Run Code Online (Sandbox Code Playgroud)

这是^说以下?

if char in alphabet:
    return 1
    break
Run Code Online (Sandbox Code Playgroud)

python if-statement function break

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

标签 统计

python ×3

break ×1

function ×1

if-statement ×1

multithreading ×1