I am using the following code to create a dynamic file editor from any point on the SSD the problem is the last line of code is never executed so the editor is never called although the program does correctly find the file to be edited. Any ideas?
print("----------------File Editor-------------------")
import subprocess
import os
print()
filename = input("Enter the File Name to Edit: ")
def find_files(filename, search_path):
result = []
for root, dir, files in os.walk(search_path):
if filename in files:
result.append(os.path.join(root, filename))
print("--------working---------")
return result
print(find_files(filename,"/"))
subprocess.call = (['sudo' , 'nano' , filename])
Thanks I did remove the = sign and the editor now loads asking for the sudo password, but the intended file is not loaded into the editor it tries to create a blank file by that name
By Brett Bojanoski via Discussions on Python.org at 06Aug2022 01:57:
Thanks I did remove the = sign and the editor now loads asking for the
sudo password, but the intended file is not loaded into the editor it
tries to create a blank file by that name
Let’s review your code:
filename = input("Enter the File Name to Edit: ")
def find_files(filename, search_path):
result = []
for root, dir, files in os.walk(search_path):
if filename in files:
result.append(os.path.join(root, filename))
print("--------working---------")
return result
print(find_files(filename,"/"))
subprocess.call(['sudo' , 'nano' , filename])
You’ve invoking:
sudo nano filename
but filename is the originalfilename you read from input()
earlier. What you likely want is one of the files located by find_files().
You run find_files but do not store or use its result.
Thanks for the idea I entered your code after mine and now the program does nothing more that ask for the filename and say command not found and then exits. Is this where I was supposed to enter your code?
By Brett Bojanoski via Discussions on Python.org at 06Aug2022 15:07:
Thanks for the idea I entered your code after mine and now the program
does nothing more that ask for the filename and say command not found
and then exits. Is this where I was supposed to enter your code?
It was meant as a replacement of the bottom part of your code. But it
would help to see your current code and the output from running it.
Preferably as text pasted into a post between backticks: