txt

How do I write all my BeautifulSoup data from a website to a text file? Python

How do I write all my BeautifulSoup data from a website to a text file? Python Question: I am trying to read data from open insider and put it into an easy to read text file. Here is my code so far: from bs4 import BeautifulSoup import requests page = requests.get("http://openinsider.com/top-insider-purchases-of-the-month") ”’print(page.status_code) checks to see …

Total answers: 1

From text file to JSON file with python

From text file to JSON file with python Question: Suppose I have a txt file that looks like this (indentation is 4 spaces): key1=value1 key2 key2_1=value2_1 key2_2 key2_2_1=value2_2_1 key2_3=value2_3_1,value2_3_2,value2_3_3 key3=value3_1,value3_2,value3_3 I want to convert it into any VALID json, like this one: { ‘key1′:’value1’, ‘key2’: { ‘key2_1′:’value2_1’, ‘key2_2’:{ ‘key2_2_1′:’value2_2_1’ }, ‘key2_3’:[‘value2_3_1′,’value2_3_2′,’value2_3_3’] }, ‘key3’:[‘value3_1′,’value3_2′,’value3_3’] } I …

Total answers: 1

How to create a pandas dataframe from a txt file with comments?

How to create a pandas dataframe from a txt file with comments? Question: I need to create a pandas dataframe based on 4 txt files with comments (to skip while reading) based on the following structure: # Moteur conçu par le Poly Propulsion Lab (PPL) nom=Tondeuse # Propriétés générales hauteur=0.5 masse=20.0 prix=110.00 # Propriétés du …

Total answers: 2

Python – Search a list of a group strings in text file

Python – Search a list of a group strings in text file Question: I want to search a list of group of strings inside a text file (.txt or .log). it must include group A or B (or CDE..). group A OR B each words need in the same line but not near by. (eg. …

Total answers: 3

.txt file opened in python won't itterate properly

.txt file opened in python won't iterate properly Question: The following contains abridged version of the code for a text card game I am trying to run. It should get a random string for a card from a random line in "cards.txt", and add it to a user’s collection at "user.txt" (user would be the …

Total answers: 1

How do I print a .txt file line-by-line?

How do I print a .txt file line-by-line? Question: I am making my first game and want to create a score board within a .txt file, however when I try and print the score board it doesn’t work. with open("Scores.txt", "r") as scores: for i in range(len(score.readlines())): print(score.readlines(i + 1)) Instead of printing each line …

Total answers: 2

How to optimize reading and cleaning file?

How to optimize reading and cleaning file? Question: I have a file, which contains strings separated by spaces, tabs and carriage return: one two three four I’m trying to remove all spaces, tabs and carriage return: def txt_cleaning(fname): with open(fname) as f: new_txt = [] fname = f.readline().strip() new_txt += [line.split() for line in f.readlines()] …

Total answers: 2

Convert txt file to csv, separation specific lines to column

Convert txt file to csv, separation specific lines to column Question: I am currently try to have the data like this (The … just means there are more lines, no need to post the entire file here.) 376 932 noms sommets 0000 Abbesses 0001 Alexandre Dumas 0002 Alma Marceau … 0375 Étienne Marcel coord sommets …

Total answers: 3

How to get the real number after a string in a file

How to get the real number after a string in a file Question: I have files that contain both strings and floats. I am interested in finding the floats after a specific string. Any help in writing such a function that reads the file look for that specific string and returns the float after it …

Total answers: 3

How to combine every 4 lines in a txt file?

How to combine every 4 lines in a txt file? Question: I have a txt.file that looks like this: data1 data2 data3 data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 data17 data18 data19 data20 data21 data22 data23 data24 . . . and I want to rearrange my txt file so …

Total answers: 3