Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 13 results for
patternmatching
- Page 1
The problem with duck typing
Programming
Software Development
15 Years Ago
by Fuse
…'s a better solution. [code=Python]import re def
patternMatching
(pattern, string): matchList = re.findall(pattern, string) print…in matchList]) [/code] If you run that function as
patternMatching
(r'The (fox)', 'The fox'), it gives you '…is ['fox']. But what if you run it as
patternMatching
(r'(The) (fox)', 'The fox')? You get an…
Re: The problem with duck typing
Programming
Software Development
15 Years Ago
by Fuse
…;623253]I think you have to write it this way:
patternMatching
(r"The|fox", 'The little brown fox')[/QUOTE… figured surely something more elegant would exist. [code=Python]def
patternMatching
(self, event): matchList = re.findall(self.patternArea.GetValue(), self.inputArea…
File IO and pictures
Programming
Software Development
15 Years Ago
by Fuse
…, label = 'Go!') self.goBtn.Bind(wx.EVT_BUTTON, self.
patternMatching
) self.inputArea = wx.TextCtrl(self.background, style = wx.TE_MULTILINE…'rb') self.inputArea.SetValue(target.read()) target.close() def
patternMatching
(self, event): matchList = re.findall(self.patternArea.GetValue(), self…
Re: The problem with duck typing
Programming
Software Development
15 Years Ago
by Ene Uran
I think you have to write it this way:
patternMatching
(r"The|fox", 'The little brown fox')
Re: The problem with duck typing
Programming
Software Development
15 Years Ago
by paddy3118
Try re.finditer as in: [CODE=python] def
patternMatching
(pattern, string): print '\n'.join(string[matchobj.start():matchobj.end()] for matchobj in re.finditer(pattern, string)) [/CODE] - Paddy.
Re: The problem with duck typing
Programming
Software Development
15 Years Ago
by bumsfeld
It is only a duck if it acts, looks and sounds like one. Processed duck is not a duck.
Re: The problem with duck typing
Programming
Software Development
15 Years Ago
by Fuse
Actually, it it [i]is[/i] looking, acting and sounding like a duck. It's a 1-tuple, so it's still a tuple. Python seems to think a 1-tuple is better expressed simply as the element within the 1-tuple, however, which causes this problem.
Re: The problem with duck typing
Programming
Software Development
15 Years Ago
by slate
Help on function findall in module re: findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern [B]has more than one group[/B]. Empty matches are …
Re: The problem with duck typing
Programming
Software Development
15 Years Ago
by slate
The title of the forum is about duck typing. The problem at hand has nothing to do with it IMHO. I agree. Re.findall function is not so well suited for taking a user input regular expression, because it changes the output type depending on the input regexp. This design decission can be argued against. A pro argument would be, that most of …
Re: File IO and pictures
Programming
Software Development
15 Years Ago
by woooee
You want to search for wxpyton file dialog [url]http://www.wxpython.org/docs/api/wx.FileDialog-class.html[/url]
Re: File IO and pictures
Programming
Software Development
15 Years Ago
by Fuse
Cheers mate! That's ace. Sorry if the OP is a jumble; I haven't had sleep. (I repeated myself about the image grabber script.)
Re: File IO and pictures
Programming
Software Development
15 Years Ago
by Fuse
I discovered what the problem was, and I will not (can't) fix it. It is the chr(0) character. [url]http://python-forum.org/pythonforum/viewtopic.php?f=3&t=8298&sid=074fe5da17f88c7b625d5792f9bff2ac#p38443[/url]
Re: File IO and pictures
Programming
Software Development
15 Years Ago
by woooee
If you just want to display the pictures, use the Python Imaging Library (PIL). [url]http://www.pythonware.com/library/pil/handbook/index.htm[/url]
Search
Search
Forum Categories
Hardware/Software
Programming
Digital Media
Community Center
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Forums
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2024 DaniWeb® LLC