Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours
The match() and search() regular expression functions return either a True Boolean value if the text string matches the regular ...
>>> pattern = re.compile('[ch]at') After you store the compiled regular expression, you can use it directly in a match( ...
this example: Click here to view code image >>> re.search('test', 'This is a test') <_sre.SRE_Match object at 0x015F ...
regular expression pattern that matches multiple contiguous spaces, like this: Click here to view code image >>> re.sea ...
The caret character (^) defines a pattern that starts at the beginning of a line of text in the data stream. If the pattern is l ...
in order for the pattern to match. Combining Anchors There are a couple common situations when you can combine the start and end ...
characters from the character class is in the data stream, it matches the pattern. To define a character class, you use square b ...
>>> re.search('^[0123456789][0123456789][0123456789][0123456789][0123456789]$' , '123456') >>> re.search('^[01 ...
The new pattern, [c-h]at, only matches words where the first letter is between the letter c and the letter h. In this case, the ...
Because Python supports extended regular expressions, you have a few more tools available to you. The following sections show wh ...
The Pipe Symbol The pipe symbol allows you to specify two or more patterns that the regular expression engine uses in a logical ...
Working with Regular Expressions in Your Python Scripts It helps to actually see regular expressions in use to get a feel for ho ...
After the phone exchange number, you must again match either a space, a dash, or a dot: ( |-|\.) Then to finish things off, you ...
consists of a combination of standard text characters and special characters. The regular expression engine uses the special cha ...
Hour 17. Exception Handling What You’ll Learn in This Hour: What exceptions are How to handle exceptions How to handle multiple ...
print function. The error generated in Listing 17.1 came from issuing a single syntactically incorrect statement in the Python i ...
18 # ... Using the cat -n command causes Python to display line numbers on the screen for each line in your script. In Listing 1 ...
3: >>> num2=4 4: >>> zero=0 5: >>> result=num1/num2 6: >>> print (result) 7: 0.75 8: >> ...
pi@raspberrypi ~ $ cat py3prog/my_errors.py 1: # my_errors.py - Demonstrates various Python errors 2: # Written by Blum and Bres ...
exception. This is done in script1701.py. LISTING 17.7 A try except Statement Block Click here to view code image 1: pi@raspberr ...
«
10
11
12
13
14
15
16
17
18
19
»
Free download pdf