May-28-2018, 10:11 AM
Hello fellow Python Trekkers,
So, this program is a kind of prelude to a program involving SQLite. I'm not looking for help on that. At least not yet. I want to be able to take some fairly raw data from text files and turn them into rows and columns, as a next step.
But with that in mind, should I be trying to combine all of the findall expressions into a single list of lists, or is the approach I took going to be easier to handle ultimately? Some files that this program will be sorting through when I have the db program working properly may be MB long. So I am worried that if I do add them separately, I will take a big performance hit. Whether or not that's important, I don't really know. I am still very much a beginner.
Without further ado, here is the program:
So, this program is a kind of prelude to a program involving SQLite. I'm not looking for help on that. At least not yet. I want to be able to take some fairly raw data from text files and turn them into rows and columns, as a next step.
But with that in mind, should I be trying to combine all of the findall expressions into a single list of lists, or is the approach I took going to be easier to handle ultimately? Some files that this program will be sorting through when I have the db program working properly may be MB long. So I am worried that if I do add them separately, I will take a big performance hit. Whether or not that's important, I don't really know. I am still very much a beginner.
Without further ado, here is the program:
import re def test(input_data): # extracts strings from the test strings input_data = str(input_data) f_server = re.findall(r'^(![\w|d]+)', input_data) add_server(f_server) f_name = re.findall(r'^![\w|d]+\s([a-zA-Z|\(|\)|\'|\"|\&|\.|\s|\d|\w|\-|,]+)', input_data) add_file_name(f_name) f_size = re.findall('([\d\.]+KB|MB)$', input_data) add_file_size(f_size) def add_server(f_server): # adds all server hits to a list server_list.append(f_server) def add_file_name(f_name): # adds all file name hits to a list f_string = str(f_name[0]) f_string = f_string.rstrip() file_name_list.append(f_string) def add_file_size(f_size): # adds all file sizes to a list file_size.append(f_size) server_list = [] file_name_list = [] file_size = [] # Sample data for testing test("!FlipMoran 100 Best Science Fiction Novels - David Pringle.txt ::INFO:: 14.9KB") test("!dragnbreaker Aldiss, Brian W - SSC 21 - Man in His Time-The Best Science Fiction Of.jpg ::INFO:: 24.8KB") test("!dragnbreaker Aldiss, Brian W - SSC 21 - Man in His Time-The Best Science Fiction Of.rtf ::INFO:: 840.4KB") test("!pondering42 Bleiler, EF & Dikty, TE - Year's Best Science Fiction Novels - 1953 (html).rar ::INFO:: 348.0KB") print("Server list: ", server_list) print("File name list: ", file_name_list) print("File size list: ", file_size)Regards and thanks in advance.