Like function in Python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 2
Reputation: nsandestin is an unknown quantity at this point 
Solved Threads: 0
nsandestin nsandestin is offline Offline
Newbie Poster

Like function in Python

 
0
  #1
Apr 24th, 2008
Is there something similar to a LIKE function in python? What I'm trying to accomplish is to search inside a string, if it finds specific criteria it sets another variable to a specific value.

In other scripting languages I have used a LIKE function to do this but I can't find anything comparable in Python.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 8
Reputation: bgeddy is an unknown quantity at this point 
Solved Threads: 1
bgeddy's Avatar
bgeddy bgeddy is offline Offline
Newbie Poster

Re: Like function in Python

 
0
  #2
Apr 24th, 2008
Check out regular expressions in the re module.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Like function in Python

 
0
  #3
Apr 24th, 2008
The simplest functions to search a string are find() and index().
Should you find Irony, you can keep her!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 33
Reputation: paddy3118 is an unknown quantity at this point 
Solved Threads: 8
paddy3118 paddy3118 is offline Offline
Light Poster

Re: Like function in Python

 
0
  #4
Apr 24th, 2008
what functions in other languages did you use?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Like function in Python

 
0
  #5
Apr 24th, 2008
If it's like the like() function in VB, then you can do it with module re, which does have wildcard and characterlist patterns.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Re: Like function in Python

 
0
  #6
Apr 24th, 2008
  1. >>> string = "A simple example string."
  2. >>> if 'example' in string:
  3. print 'the word \'%s\' is in: "%s"' % ('example', string)
  4.  
  5.  
  6. the word 'example' is in: "A simple example string."
  7. >>>
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 2
Reputation: nsandestin is an unknown quantity at this point 
Solved Threads: 0
nsandestin nsandestin is offline Offline
Newbie Poster

Re: Like function in Python

 
0
  #7
Apr 24th, 2008
That's exactly what I needed! Thanks for all of your help!!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC