Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Python text filter. How to not manually drag file?

Where I have to drag the file before the filter.This is my existing code: [code]input = open("first file.txt", "rt") output = open("revised.txt", "wt") for line in input: output.write(line.replace("Bob", "James").replace("Xavier", "Jake")) input.close() output.close()
Now, this works but I have to manually add "first file.txt" to python files and the program doesn't search the computers files. How would I make the program automatically search the computers files?
What exactly are you trying to do? I'm new to python but I had to create something similar.
(Nov 10, 2021 07:26 PM)Beginner1234 Wrote:  Where I have to drag the file before the filter.This is my existing code: [code]input = open("first file.txt", "rt") output = open("revised.txt", "wt") for line in input: output.write(line.replace("Bob", "James").replace("Xavier", "Jake")) input.close() output.close()
Now, this works but I have to manually add "first file.txt" to python files and the program doesn't search the computers files. How would I make the program automatically search the computers files?

Searching throughout your whole computer is a very bad idea, it's very consuming in terms of resources, and time.
Also, there might be a few files named "first file.txt" as you can have the same file name in other directories,
so if you still go on that implementation, you gotta think if you want to keep searching or stop after the first file is found ( wouldn't recommend that approach anyway.. )

Basically, your code shouldn't mess with files you don't know, so that drag and drop to the folder where the code is, is necessary. ( or specifying the path to the specific file )
Dude .


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by _redbaron_Jun 14, 2024 04:56 PM 16 658 Jun 14, 2024 04:56 PM
Last Post: secret_code
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 630 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[C] by oh9odDec 7, 2020 04:55 AM 0 171 Dec 7, 2020 04:55 AM
Last Post: oh9od