我在Windows上安装了Python2.7和3.3,在Linux上安装了Python2.7和3.2mu.如何使用2.X或3.X版本编写既能在Windows上使用又能在Linux上使用的Python脚本?
我正在寻找几行代码,它们将检查当前的操作系统是什么,并在脚本的其余部分中使用Python3.x。
我想的大概是:
if operating_system == Windows:
run rest of script with C:\python_directory3.X\python
elif operating_system == Linux:
run rest of sc
在Python2.6.8中,编写unicode字符串时会出现以下错误:
Traceback (most recent call last):
File "test.py", line 10, in <module>
f.write(bytearray(u, 'utf_8'))
TypeError: argument 1 must be string or pinned buffer, not bytearray
在Python2.7.8中运行代码时,所有操作都很好,字符串将被正确打印和编写。
这是代码:
#!/usr/bin/python
我正在尝试使用Python DNS库(dnspython)编写一些脚本。我使用包管理器(apt-get install)安装了它(python-dns和python-dnspython)。
我试图在shell上以交互方式编写脚本,但它总是说找不到库。
>>> import dns
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named dns
有趣的是,当我在Eclipse (pydev)上