Franz
Franz

Reputation: 5

Why doesn't this script run like it should?

I tried to write a script which reads the cells in a .xlsx file (result is the name of an .eml) and check if the .eml is in the directory /vagrant/E-Mails. It executes a shell script which puts all .eml files in the directory into the eml.txt file.

If I do:

>> python optest.py 

it still says:

E-Mail not found

...but there are those .eml files in the directory.

Can you help me to solve this please?

from openpyxl import load_workbook
import subprocess

testcases = load_workbook('/vagrant/Excel/testcases.xlsx')
testcases_ws = testcases.active
profil = testcases_ws['A2']
print profil.value


testmails = load_workbook('/vagrant/Excel/testmails.xlsx')
testmails_ws = testmails.active
eml = testmails_ws['A2']
eml = eml.value
print eml
path = "/vagrant/E-Mails/"

subprocess.Popen(['sh', "/vagrant/test.sh"])

if eml in open("eml.txt", "r"):
        print "E-Mail ´found"
else:
        print "E-Mail not found."

Upvotes: 0

Views: 56

Answers (1)

Kevin
Kevin

Reputation: 76254

if eml in open("eml.txt", "r"):

Here, you're using the in operator on the file object returned by open. This will only succeed if eml exactly matches a complete line in the file, including a terminating newline. For a more lenient matching approach, try using in on the string contents of the file instead.

if eml in open("eml.txt", "r").read():

Upvotes: 1

Related Questions