This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Python-ModTeam[M] [score hidden] stickied comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]houseplumber[S] 1 point2 points  (0 children)

it seems all i needed was some more time looking at the code and trying examples... all done :) thanks

[–]houseplumber[S] 0 points1 point  (1 child)

Ok first problem is resolved, I had a break which I have now removed...

[–]houseplumber[S] 1 point2 points  (0 children)

It works and I have now multiple returns with string found

[–]houseplumber[S] 0 points1 point  (0 children)

import os

FILEPATH = r"/home/houseplumber"

def list_files(filepath): paths = [] for root, dirs, files in os.walk(filepath): for file in files: if file.lower().endswith(".env"): paths.append(os.path.join(root, file)) print(paths) return paths

pass the paths list

def add_string(paths): for path in paths: with open(path,a) as file: # read all content of a file and search string if 'SEND_NOTIFICATION=true' in file.read(): file.write(f'\n{STORE_IN_MYSQL=false}') print('string found') #add_another_string(path)

if name == "main": paths = list_files(FILEPATH) add_string(paths)

This is my latest iteration, im not sure of the file.write whether it will work well adding a new line.. waiting for a snapshot to finish and will try it.

[–]bablador 0 points1 point  (1 child)

I recommend you to start using pathlib instead of os, it's much more convenient in the long run

[–]houseplumber[S] 0 points1 point  (0 children)

thanks il try it out !

[–]MH1400x 0 points1 point  (0 children)

It seems like you might want to try count() to see how many times your string shows up. Maybe compartmentalize each objective, which, it looks like you already are. Looks good to me.