0

Windows 環境で作成したいくつかの Python スクリプトを Unix (Red Hat 5.4) で実行するように変換していますが、ファイルパスを処理する行の変換に問題があります。Windows では、通常、次のような方法でディレクトリ内のすべての .txt ファイルを読み込みます。

pathtotxt = "C:\\Text Data\\EJC\\Philosophical Transactions 1665-1678\\*\\*.txt"
for file in glob.glob(pathtotxt):

Unix でも glob.glob() メソッドを使用できるようです。そのため、このメソッドを実装して、次のコードを使用して「source」という名前のディレクトリ内のすべてのテキスト ファイルを検索しようとしています。

#!/usr/bin/env python
import commands
import sys
import glob
import os

testout = open('testoutput.txt', 'w')
numbers = [1,2,3]
for number in numbers:
    testout.write(str(number + 1) + "\r\n")
testout.close

sourceout = open('sourceoutput.txt', 'w')
pathtosource = "/afs/crc.nd.edu/user/d/dduhaime/data/hill/source/*.txt"
for file in glob.glob(pathtosource):
    with open(file, 'r') as openfile:
        readfile = openfile.read()
        souceout.write (str(readfile))
sourceout.close

このコードを実行すると、testout.txt ファイルは期待どおりに出力されますが、sourceout.txt ファイルは空です。行を変更すれば問題が解決するかもしれないと思った

pathtosource = "/afs/crc.nd.edu/user/d/dduhaime/data/hill/source/*.txt"

pathtosource = "/source/*.txt"

/hill ディレクトリからコードを実行しましたが、問題は解決しませんでした。ソース ディレクトリ内のテキスト ファイルを読み取る方法を他の人は知っていますか? 他の人が提供できる洞察に感謝します。

編集: 関連する場合、上記のディレクトリの /afs/ ツリーは、Putty 経由で ssh 接続しているリモート サーバーにあります。上記の Python スクリプトを qsub するために、test.job ファイルも使用しています。(これはすべて、SGE クラスター システムでジョブを送信するための準備です。) test.job スクリプトは次のようになります。

#!/bin/csh
#$ -M dduhaime@nd.edu
#$ -m abe
#$ -r y
#$ -o tmp.out
#$ -e tmp.err
module load python/2.7.3
echo "Start - `date`"
python tmp.py 
echo "Finish - `date`"
4

2 に答える 2