我正在使用macports来安装各种模块.一般来说这很好用,但下面是我得到的错误,我不容易解决:
$ python
Python 2.6.6 (r266:84292, Feb 12 2011, 16:57:53)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns
>>> import opcode
>>> from dns import resolver
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/resolver.py", line 26, in <module>
import dns.message
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/message.py", line 28, in <module>
import dns.opcode
ImportError: No module named opcode
Run Code Online (Sandbox Code Playgroud)
这可能是路径问题吗?
>>> import sys
>>> sys.path
['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', …Run Code Online (Sandbox Code Playgroud) 我是Python的新手,想知道是否有人会将一个相当简单的Perl脚本示例转换为Python?
该脚本采用2个文件,并通过比较散列键仅输出第二个文件中的唯一行.它还将重复的行输出到文件.我发现使用Perl这种重复删除方法非常快,并且希望看到Python如何比较.
#! /usr/bin/perl
## Compare file1 and file2 and output only the unique lines from file2.
## Opening file1.txt and store the data in a hash.
open my $file1, '<', "file1.txt" or die $!;
while ( <$file1> ) {
my $name = $_;
$file1hash{$name}=$_;
}
## Opening file2.txt and store the data in a hash.
open my $file2, '<', "file2.txt" or die $!;
while ( <$file2> ) {
$name = $_;
$file2hash{$name}=$_;
}
open my $dfh, '>', "duplicate.txt";
## …Run Code Online (Sandbox Code Playgroud)