Like the file says I am executing a python script from a PHP file sitting on my apache webserver. The example I have is extremely basic.
PHP file -- test.php
<?php
echo "hello";
echo exec("/usr/local/bin/python2.7 test1.py");
?>
python script -- test1.py
print "world"
fh = open ('testtest' ,'r')
for line in fh:
print line
contents of -- testtest
abcdefg
'world' prints when I don't have the bottom 2 lines of test1.py but it stops printing as soon as I add for line in file: Thank you.
Edit: I'm trying to print the contents of testtest.
test.php, you forgot to close parenthesis.AttributeErrorif open returnsNone. Also,'r'is implied byopen, so you can just dofor line in open('testtest'):, or even better, make use of thewithkeyword.hello