Re: I need help with this python regex

2018-04-28 Thread Peter J. Holzer
On 2018-04-27 21:04:49 -0700, Ed Manning wrote:
> Here is the source code.
> 
> 
> import re
> 
> 
> log = open("csg.txt", "r") # Opens a file call session.txt
> regex = re.compile(r'policy id \d+') # search for the policy ID
> regex1 = re.compile(r'log count \d+') # search for the policy ID
> 
> for match in log:
> x = regex.findall(match)
> y = regex1.findall(match)
> 
> q = x + y
> print(q)
>  
> 
> The problem I am having i when it print out ti looks like this
> 
> 
> L'Policy ID 243"|
> []
> []
> []
> []
> []
> []
> []
> []
> {'log count 777,"]
> 
> 
> 
> How so I fix the code sone that it does not print empty []

Print the result only if findall actually found something.

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding pdb result

2018-04-28 Thread Rich Shepard

On Fri, 27 Apr 2018, Steven D'Aprano wrote:


What error are you referring to?


Steven,

  The menu does not display, only the frame and status bar.


Why are you using pdb in the first place?


  Because it is a debugger that allows me to process code line-by-line and
works with Python3.


If you're getting an error, the first thing to do is read the traceback.
If you're getting a traceback, tell us what it is. Don't paraphrase it,
copy and paste it.


  There is no traceback. Had there been I would have been able to find the
problem.


If you're not getting a traceback, please explain why you think you need
to use pdb and what error you think you are getting, because I have no
clue.


  See attached test.py.

Rich#!/usr/bin/env python3

import wx

#!/usr/bin/env python3

import sys, os, importlib
import pdb
import wx
import wx.grid
import sqlalchemy

class MainFrame(wx.Frame):
def __init__(self, parent, title='test'):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title = title,
  size=wx.Size(800,600), style=wx.DEFAULT_FRAME_STYLE)

self.SetSizeHints(minSize=wx.Size(300,200), maxSize=wx.Size(900,700),
  incSize=wx.Size(50,50))

# Create status bar
self.CreateStatusBar()
self.SetStatusText("This is where you'll see helpful messages")

# Prepare the menu bar
menuBar = wx.MenuBar()

# 1st menu from left (File)
fileMenu = wx.Menu()
fileMenu.Append(wx.ID_NEW, '&New', 'Create new file')
fileMenu.Append(wx.ID_OPEN, '&Open', 'Open existing file')
fileMenu.Append(wx.ID_SAVE, '&Save', 'Save this file')
fileMenu.Append(wx.ID_SAVEAS, 'S&ave as ...', 'Save file with different 
name')
fileMenu.Append(105, '&Import', 'Import a file')
fileMenu.Append(106, '&Export', 'Export this file')
fileMenu.Append(wx.ID_CLOSE, '&Quit', 'Quit')
# Add menu to menu bar
menuBar.Append(fileMenu, '&File')


if __name__ == '__main__':
edms = wx.App()
top = MainFrame(None, 'test')
top.Show()
edms.MainLoop()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding pdb result [RESOLVED]

2018-04-28 Thread Rich Shepard

On Sat, 28 Apr 2018, Rich Shepard wrote:


 The menu does not display, only the frame and status bar.


  Fixed the problem: I had neglected to attach the menu bar to the frame.

Mea culpa!

Rich
--
https://mail.python.org/mailman/listinfo/python-list