[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
DESCRIPTION This module provides access to some objects used or maintained by the interpreter and to functions that interact str ...
pass a number to the numlines argument (e.g., the last line in Example 2-1 passes 10 to the numlines argument of the more functi ...
True >>> 'Ni' in mystr # when not found False >>> mystr.find('Ni') -1 >>> mystr = '\t Ni\n' >>& ...
>>> chars = list('Lorreta') # convert to characters list >>> chars ['L', 'o', 'r', 'r', 'e', 't', 'a'] >> ...
Really, though, 3.X has two additional string types that support most str string oper- ations: bytes—a sequence of short integer ...
As we’ll see in a moment, these calls can also be applied to shell commands in Python to read their output. File objects also ha ...
if __name__ == '__main__': import sys # when run, not imported more(open(sys.argv[1]).read(), 10) # page contents of file on cmd ...
If you can’t find the manuals on your computer, you can always read them online. Go to Python’s website at http://www.python.or ...
>>> sys.platform, sys.maxsize, sys.version ('win32', 2147483647, '3.1.1 (r311:74483, Aug 17 2009, 17:02:12) ...more del ...
Changing sys.path directly like this is an alternative to setting your PYTHONPATH shell variable, but not a very permanent one. ...
We might use such a hook to write programs that display or otherwise process all the modules loaded by a program (just iterate o ...
Other sys Module Exports The sys module exports additional commonly-used tools that we will meet in the con- text of larger topi ...
until you’ve learned what each name means (I’ve let this line-wrap and removed most of this list to save space—run the command o ...
The input filename argument here is given without an explicit directory path (though you could add one to page files in another ...
(False, False) >>> os.path.exists(r'c:\Users\Brian') False >>> os.path.exists(r'c:\Users\Default') True >&g ...
The last join call require individual arguments (hence the *) but doesn’t insert a first slash because of the Windows drive synt ...
part of the book, let’s take a quick first look at the basics here. Two os functions allow scripts to run any command line that ...
is some Python code that runs the two DOS shell commands typed at the shell prompt shown previously: C:\...\PP4E\System> pyth ...
in the os.popen example above unnecessary in most programs, except to display the list interactively as we did here (see also “s ...
Notice the shell=True in the last command here. This is a subtle and platform- dependent requirement: On Windows, we need to pa ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf