import sys, os try: raise NotImplementedError("No error") except Exception, e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
import sys, os try: raise NotImplementedError("No error") except Exception, e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
Regex Expression: |
Syntax: pattern1|pattern2
Search for both of them, if either is found it is true.
Example:
re.findall("(the|top|coder)", "Marius is one of the topcoders.") ['the', 'top', 'coder']
Regex Expression: ^
Syntax: ^pattern
This would return True only if pattern is at the starting of the given text.
Example:
re.findall("^http", "http://www.google.co.in.") ['http']
Regex Expression: $
Syntax: pattern$
Returns True if pattern is in the end of given text
Example:
re.findall("in$", "http://www.google.co.in") ['in']
Regular Expression: .
Syntax: pattern.
Use to match a single character.
>>> re.findall("htt.", "http://www.google.co.in") ['http'] >>> re.findall("ht..", "http://www.google.co.in") ['http']</p><p>
Regular Expression: { }
Syntax: Pattern{number of times pattern must repeat continuously}
It multiplies the pattern number of times given within the braces and then search for it in the given text. In the following example it multiplies ‘t’ twice thus pattern to be searched is ‘tt’
Example:
>>>re.findall("t{2}", "http://www.google.co.in") ['tt']
Regular Expression: { ,}
Syntax: Pattern{n,}
Matches n or more occurrences of preceding expression.
Example:
>>> re.findall("t{2}", "http://www.google.co.in" ['tt']
We have the responsibility to develop something similar for generations to come -:)