小编Agm*_*nor的帖子

为什么我会收到错误"TypeError:coercing to Unicode:need string or buffer,int found"?

运行这个小程序后:

#!/usr/bin/env python2.7
# -*-coding:utf-8 -*
a = 1
b = 2
c = 3
title = u"""a=""" + a + u""", b=""" + str(b) + \
    u""", c=""" + str(c)
print(title)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

u""", c=""" + str(c)
TypeError: coercing to Unicode: need string or buffer, int found
Run Code Online (Sandbox Code Playgroud)

但以下运行就好了!

#!/usr/bin/env python2.7
# -*-coding:utf-8 -*
a = 1
b = 2
c = 3
title = u""", b=""" + str(b) + \
    u""", c=""" + str(c)
print(title)
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下发生了什么事吗?

python unicode

19
推荐指数
1
解决办法
8万
查看次数

如何在Python中将函数作为子进程运行?

我希望我的Python脚本能够将其中一个函数作为子进程运行.我该怎么办?

这是我的意图的模拟脚本:

#!/urs/bin/env python

def print_mynumber(foo):
    """This function is obviously more complicated in my script.
    It should be run as a subprocess."""
    print(foo)

for foo in [1,2,3]:
    print_mynumber(foo) # Each call of this function should span a new process.
    # subprocess(print_mynumber(foo))
Run Code Online (Sandbox Code Playgroud)

谢谢你的建议.我正确地制定问题并因此进行适当的网络搜索有点困难.

python subprocess

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

标签 统计

python ×2

subprocess ×1

unicode ×1