diff options
author | Steven Myint <git@stevenmyint.com> | 2013-10-08 19:46:16 -0700 |
---|---|---|
committer | Steven Myint <git@stevenmyint.com> | 2013-10-08 19:46:16 -0700 |
commit | a34cfbdde75d8d0aa276afeeb824522fe82a7b34 (patch) | |
tree | e1d41ea40131dcc927906b67cdcf4cbc6a156688 /examples/uptime.py | |
parent | 1141915a17bd446d330de0c8fe3a017ebc6b2e06 (diff) | |
download | pexpect-git-a34cfbdde75d8d0aa276afeeb824522fe82a7b34.tar.gz |
Add note about unicode_literals and spawnu
Diffstat (limited to 'examples/uptime.py')
-rwxr-xr-x | examples/uptime.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/examples/uptime.py b/examples/uptime.py index 2c1e481..659edfc 100755 --- a/examples/uptime.py +++ b/examples/uptime.py @@ -48,8 +48,12 @@ import re # OpenBSD box3 2.9 GENERIC#653 i386 # 6:08PM up 4 days, 22:26, 1 user, load averages: 0.13, 0.09, 0.08 -# This parses uptime output into the major groups using regex group matching. +# Note that, for Python 3 compatibility reasons, we are using spawnu and +# importing unicode_literals (above). spawnu accepts Unicode input and +# unicode_literals makes all string literals in this script Unicode by default. p = pexpect.spawnu('uptime') + +# This parses uptime output into the major groups using regex group matching. p.expect('up\s+(.*?),\s+([0-9]+) users?,\s+load averages?: ([0-9]+\.[0-9][0-9]),?\s+([0-9]+\.[0-9][0-9]),?\s+([0-9]+\.[0-9][0-9])') duration, users, av1, av5, av15 = p.match.groups() |