Reputation: 21237
I have to reference a file that exists in a different directory. This is just a text file, not a python module. I've read countless posts, most of which are about including modules. Nothing that I read is giving me a successful answer. Out of many attempts, this is my latest:
import os
REMOTE_FILE = open(os.path.join('/Users/me/Dropbox/otherfolder', 'text.txt'), "r")
decrypted = subprocess.check_output(['openssl', 'aes-128-cbc', '-d', '-in', REMOTE_FILE, '-base64', '-pass', key])
The program doesn't fail on this line immediately, but when I attempt to reference this file I get:
TypeError: Can't convert '_io.TextIOWrapper' object to str implicitly
What am I doing wrong? Thanks!
Upvotes: 1
Views: 2166
Reputation: 1662
Use REMOTE_FILE = os.path.join('/Users/me/Dropbox/otherfolder', 'text.txt')
instead to get only the file path as a string and not an file object.
Upvotes: 2
Reputation: 15157
Your REMOTE_FILE
is a file object, not a string. Given your code, you probably meant to do:
import os
REMOTE_FILE = os.path.join('/Users/me/Dropbox/otherfolder', 'text.txt')
decrypted = subprocess.check_output(['openssl', 'aes-128-cbc', '-d', '-in', REMOTE_FILE, '-base64', '-pass', key])
Keeping REMOTE_FILE
as a string, not an object.
Upvotes: 1