Skip to content

Tag: file

python string not writing to a file

this function is being called by the way the file is correct ‘paragraphs.txt’ but when it runs it finishes with no errors but doesn’t write anything to the file git files file with problem: write to file test: i have wrote a script separately to test writing to a file and it worked so i don’t know why

Remove text lines and strip lines with condition in python

I have a text file in this format: I want to remove the lines that don’t have a [number1,number2,number3,number4,1] or [number1,number2,number3,number4,5] ending and also strip the text line and remove the [blocks] -> [number1,number2,number3,number4,number5] that don’t fulfill this condition. The above text file should look like this in the end: My code: I have tried something like this and it

Creating sets of specific extracted values from a .txt file (Python)

I have a .txt file that says “NAMES,” “POINTS” and “SUMMARY” in capital letters, each followed by lines containing data. Each of these three groups is separated by an empty line: My goal is to create three separate sets of names, points and summary. I already created a set of names using the following code (which outputs a set of

valid and corrupt lines from file

As you can read, the function validate_data should check the imported file for corrupt and valid lines, then append them to the correct list, and print them. It works, except that, as you can probably see, the lines will not print in a single line. I’m sure I have to make two other lists to append the correct data into

Manipulating files using Python

My old friend and I have been trying to save our chat histories recently for the nostalgia and the memories. Google chat history saves in a latest-oldest order. I’d like to make it to oldest-latest as well as change the pattern of the text. Any idea how I can implement this in Python? For reference this is the Hangouts file.

Variable file name breaks excel sheet creation

I’ve a code which creates an excel in a specific field with 3 sheets: I need the file name to become a varaible and I’ve done this: Even though the file_name is variable now, I get an error with the sheets creation and It’s blowing my mind. Any other way to make it variable? Thanks Answer Using fr’ instead of