I am making a python project for scraping and downloading data, in one part I am…
- User
I am making a python project for scraping and downloading data, in one part I am extracting stable diffusion text-to-image prompts from a json containing prompt metadata, I am at the point of getting the positive prompt and putting it in the variable
posPrompt, once I verify that the prompt has a len() > 0, I can then work on it.What I want to do, and what I need your help with, is using re to find and replace ALL newlines in the posPrompt, simply removing them is enough, as I want to ensure all posPrompts I extract are one contiguous line, to be placed into a .txt file, where 1 line in the file = 1 prompt, for use when using prompt wildcards.
- Assistant
To accomplish the task of removing all newline characters from a string in Python using the
remodule, you can use the following approach. This will ensure that your variableposPrompttransforms into a continuous line without any newline breaks, making it suitable for storage in a single-line format within a .txt file.Here's how you can do it:
- User
Ok, I have this method in my CivitaiGet class:
def sha256(self, filename): with open(filename, "rb") as f: import hashlib hash_object = hashlib.sha256() for chunk in iter(lambda: f.read(4096), b""): hash_object.update(chunk) return hash_object.hexdigest()What I want to do is use tqdm to create a very useful progress bar in the console of the hashing progress, I need to see the filename it is processing(remove the path if there is one, just want the filename + extension), and an appropriate display of the progress
- Assistant