でのみ動作します。ここに私のコードです。それは、ソースディレクトリの内容をコピー先のディレクトリに移動するだけです。最後に、先のディレクトリPythonのHDFS毒ヘビにかまれた傷:メソッドは、私は</p> <p><a href="https://github.com/spotify/snakebite" rel="nofollow">https://github.com/spotify/snakebite</a></p> <p>から毒ヘビにかまれた傷のクライアントを使用していますし、私はディレクトリを作るか、HDFS内のファイルを動き回るしようとしたとき、私は奇妙な行動に気づいプリント
def purge_pending(self,source_dir,dest_dir):
if(self.hdfs_serpent.test(path=self.root_dir+"/"+source_dir, exists=True, directory=True)):
print "Source exists ",self.root_dir+source_dir
for x in self.hdfs_serpent.ls([self.root_dir+source_dir]):
print x['path']
else:
print "Source does not exist ",self.root_dir+"/"+source_dir
return
if(self.hdfs_serpent.test(path=self.root_dir+"/"+dest_dir, exists=True, directory=True)):
print "Destination exists ",self.root_dir+dest_dir
else:
print "Destination does not exist ",self.root_dir+dest_dir
print "Will be created"
for y in self.hdfs_serpent.mkdir([self.root_dir+dest_dir],create_parent=True):
print y
for src in self.hdfs_serpent.ls([self.root_dir+source_dir]):
print src['path'].split("/")[-1]
for y in self.hdfs_serpent.rename([src['path']],self.root_dir+dest_dir+"/"+src['path'].split("/")[-1]):
print y
for x in self.hdfs_serpent.ls([self.root_dir+dest_dir]):
print x['path']
、ここでの内容を表示することは先が
Source exists /root/source
/root/source/208560.json
/root/source/208571.json
/root/source/208574.json
/root/source/208581.json
/root/source/208707.json
Destination does not exist /root/dest
Will be created
{'path':'/research/dest/'}
208560.json
{'path':'/research/dest/208560.json'}
208571.json
{'path':'/research/dest/208571.json'}
208574.json
{'path':'/research/dest/208574.json'}
208581.json
{'path':'/research/dest/208581.json'}
208707.json
{'path':'/research/dest/208707.json'}
存在しなかったときの出力例であると奇妙な部分は、私はそれらのprint文を入れなければならないことですそうでなければ何も働かない。だから、
self.hdfs_serpent.mkdir([self.root_dir+dest_dir],create_parent=True)
は動作しませんが、
for y in self.hdfs_serpent.mkdir([self.root_dir+dest_dir],create_parent=True):
print y
はありません!上記のように
self.hdfs_serpent.rename([src['path']],self.root_dir+dest_dir+"/"+src['path'].split("/")[-1])
についても同じことが動作しませんが、以下が
for y in self.hdfs_serpent.rename([src['path']],self.root_dir+dest_dir+"/"+src['path'].split("/")[-1]):
print y
これはバグであるのか?何か間違っているのですか?
ありがとう、彼らがジェネレータとしてメソッドの戻り値の型を保持していた理由を知っていますか? – AbtPst
私は完全にはわかっていませんが、パフォーマンスの理由から可能性が高いと思われます。ジェネレータは反復処理中にのみアクションを実行します。 –