Regex search to Excel

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I made this to track my variable changes while I experiment in Python. I tend to use the same variable names and fit different values to them so it's nice to be able to see what I've tried, especially if I'm constructing a huge code block.
I copy text onto my clipboard before starting this code.The code asks for the variables to track, then creates a Regex fitting my usual variable definition for each variable:
' variable_name = '
It then searches text pasted by Pyperclip with re.findall to create a list of bindings for each name, which is then written to an Excel spreadsheet for easier reading of the changes to definitions over time.
import re, pyperclip, openpyxl
wb= openpyxl.Workbook()
ws = wb.active
Setting up - importing modules, creating a new workbook
print("Please input definitions/name bindings you want to track, separated"
" by ', '")
names = input().split(', ')
Creating a list of names to track
regexlist =
for name in names:
regexlist.append(re.compile(r'(?<=s' + name + r's=s).*'))
Making a list of Regexes that will be used to search for the text following variable definitions. Note each Regex in the list should share the same index as
the name in the list 'names'.
text = pyperclip.paste()
c = 1 # column number, changes with iteration
for i, regex in enumerate(regexlist):
changelist = regex.findall(text)
ws.cell(row=1, column=c, value=names[i]) # Header is variable name
for i, binding in enumerate(changelist):
ws.cell(row=i+2, column=c, value=binding)
c += 1 # move to next column for next variable
print('variable tables created, input filename as filename.xlsx')
file = input()
wb.save(file)
The eventual goal is to move towards having it read from the files (sys.stdout? for example) but at this stage I don't have the capability to do it, nor the need so I'm just looking to fine tune this in case I've missed out any possibilities.
python python-3.x excel regex
add a comment |Â
up vote
2
down vote
favorite
I made this to track my variable changes while I experiment in Python. I tend to use the same variable names and fit different values to them so it's nice to be able to see what I've tried, especially if I'm constructing a huge code block.
I copy text onto my clipboard before starting this code.The code asks for the variables to track, then creates a Regex fitting my usual variable definition for each variable:
' variable_name = '
It then searches text pasted by Pyperclip with re.findall to create a list of bindings for each name, which is then written to an Excel spreadsheet for easier reading of the changes to definitions over time.
import re, pyperclip, openpyxl
wb= openpyxl.Workbook()
ws = wb.active
Setting up - importing modules, creating a new workbook
print("Please input definitions/name bindings you want to track, separated"
" by ', '")
names = input().split(', ')
Creating a list of names to track
regexlist =
for name in names:
regexlist.append(re.compile(r'(?<=s' + name + r's=s).*'))
Making a list of Regexes that will be used to search for the text following variable definitions. Note each Regex in the list should share the same index as
the name in the list 'names'.
text = pyperclip.paste()
c = 1 # column number, changes with iteration
for i, regex in enumerate(regexlist):
changelist = regex.findall(text)
ws.cell(row=1, column=c, value=names[i]) # Header is variable name
for i, binding in enumerate(changelist):
ws.cell(row=i+2, column=c, value=binding)
c += 1 # move to next column for next variable
print('variable tables created, input filename as filename.xlsx')
file = input()
wb.save(file)
The eventual goal is to move towards having it read from the files (sys.stdout? for example) but at this stage I don't have the capability to do it, nor the need so I'm just looking to fine tune this in case I've missed out any possibilities.
python python-3.x excel regex
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I made this to track my variable changes while I experiment in Python. I tend to use the same variable names and fit different values to them so it's nice to be able to see what I've tried, especially if I'm constructing a huge code block.
I copy text onto my clipboard before starting this code.The code asks for the variables to track, then creates a Regex fitting my usual variable definition for each variable:
' variable_name = '
It then searches text pasted by Pyperclip with re.findall to create a list of bindings for each name, which is then written to an Excel spreadsheet for easier reading of the changes to definitions over time.
import re, pyperclip, openpyxl
wb= openpyxl.Workbook()
ws = wb.active
Setting up - importing modules, creating a new workbook
print("Please input definitions/name bindings you want to track, separated"
" by ', '")
names = input().split(', ')
Creating a list of names to track
regexlist =
for name in names:
regexlist.append(re.compile(r'(?<=s' + name + r's=s).*'))
Making a list of Regexes that will be used to search for the text following variable definitions. Note each Regex in the list should share the same index as
the name in the list 'names'.
text = pyperclip.paste()
c = 1 # column number, changes with iteration
for i, regex in enumerate(regexlist):
changelist = regex.findall(text)
ws.cell(row=1, column=c, value=names[i]) # Header is variable name
for i, binding in enumerate(changelist):
ws.cell(row=i+2, column=c, value=binding)
c += 1 # move to next column for next variable
print('variable tables created, input filename as filename.xlsx')
file = input()
wb.save(file)
The eventual goal is to move towards having it read from the files (sys.stdout? for example) but at this stage I don't have the capability to do it, nor the need so I'm just looking to fine tune this in case I've missed out any possibilities.
python python-3.x excel regex
I made this to track my variable changes while I experiment in Python. I tend to use the same variable names and fit different values to them so it's nice to be able to see what I've tried, especially if I'm constructing a huge code block.
I copy text onto my clipboard before starting this code.The code asks for the variables to track, then creates a Regex fitting my usual variable definition for each variable:
' variable_name = '
It then searches text pasted by Pyperclip with re.findall to create a list of bindings for each name, which is then written to an Excel spreadsheet for easier reading of the changes to definitions over time.
import re, pyperclip, openpyxl
wb= openpyxl.Workbook()
ws = wb.active
Setting up - importing modules, creating a new workbook
print("Please input definitions/name bindings you want to track, separated"
" by ', '")
names = input().split(', ')
Creating a list of names to track
regexlist =
for name in names:
regexlist.append(re.compile(r'(?<=s' + name + r's=s).*'))
Making a list of Regexes that will be used to search for the text following variable definitions. Note each Regex in the list should share the same index as
the name in the list 'names'.
text = pyperclip.paste()
c = 1 # column number, changes with iteration
for i, regex in enumerate(regexlist):
changelist = regex.findall(text)
ws.cell(row=1, column=c, value=names[i]) # Header is variable name
for i, binding in enumerate(changelist):
ws.cell(row=i+2, column=c, value=binding)
c += 1 # move to next column for next variable
print('variable tables created, input filename as filename.xlsx')
file = input()
wb.save(file)
The eventual goal is to move towards having it read from the files (sys.stdout? for example) but at this stage I don't have the capability to do it, nor the need so I'm just looking to fine tune this in case I've missed out any possibilities.
python python-3.x excel regex
edited May 26 at 3:46
Jamalâ¦
30.1k11114225
30.1k11114225
asked May 26 at 3:18
Michael Khor
111
111
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f195197%2fregex-search-to-excel%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password