Regex search to Excel

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question



























    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.







    share|improve this question























      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.







      share|improve this question













      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.









      share|improve this question












      share|improve this question




      share|improve this question








      edited May 26 at 3:46









      Jamal♦

      30.1k11114225




      30.1k11114225









      asked May 26 at 3:18









      Michael Khor

      111




      111

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Python Lists

          Aion

          JavaScript Array Iteration Methods