Can't access a file in another directory using python object
<p>I wanted to implement a classification application using python 2 and before classification done text should be preprocessed. Classifier and Preprocessor are in different packages. Then I created a object of <code>preprocessing class</code> in class in classification package.</p>

<p>here is my project explorer</p>

<p><a href="http://i.stack.imgur.com/sWSOE.png" rel="nofollow"><img src="http://i.stack.imgur.com/sWSOE.png" alt="enter image description here"></a></p>

<pre><code>preprocessing class
</code></pre>

<blockquote>
  <p>class preprocessing:</p>

<pre><code>def preprocess(self, file):


    inputFile = "text"
    outputFile = "plainText.txt"

    # infile = io.open(inputFile, "r", encoding='utf-8').read()
    outfile = io.open(outputFile, "w", encoding='utf-8')

    text = unnecessaryCharsObj.removeChars(file)
    text = stopWrdsObj.removeStopwords(text)

    text = text.lower()
    plain = text.split()
    stemmObj.stemminig(plain)

    for x in plain:
        outfile.write(x)
        outfile.write(u'\u0020')
    # plaintext = " ".join(str(x) for x in plain)

    # outfile.write(plaintext)
    return outfile
    outfile.close()
</code></pre>
</blockquote>

<p>preprocessing class object that created in classidier package,</p>

<blockquote>
<pre><code>def classify(self):

    dao = DAO();
    procc = preprocessing();
    # Get IDs of uncatergerized news to uncatNewsList
    uncatNewsList = dao.selectUncategerizedNews();

    for news in uncatNewsList:

        description = dao.getDescriptionById(news[0])

        wf = io.open('news.txt', 'w', encoding='utf-8')
        x = description[0][0]
        wf.write(x)
        rf = io.open('news.txt', 'r', encoding='utf-8').read()

        txt = procc.preprocess(rf)

        category = MultinomialNBClassifier().classifier(txt)
        dao.updateNews(news[0],category[0])
</code></pre>
</blockquote>

<p>But in preprocessing class, it uses a text file in same preprocess package. So I can't do the job as I wished since it return error <code>"No such file or directory: 'stopWordList.txt'"</code></p>

<p>what can I do for solving this?</p>

<p>Please check that the file is in the same path as path of the current executed file.
Here is idea:
<a href="http://stackoverflow.com/questions/2632199/how-do-i-get-the-path-of-the-current-executed-file-in-python">How do I get the path of the current executed file in python?</a></p>

python utf-8