61. Print “aaa” : substitute(aaa= “haha”) : substitute(aaa= “haha”) : substitute is a strict tuple. Double loop for both item and index: for I, C in enumerate(” abcd “): Print c, I for loop filter aaa=[x**2 for x in range(4)] for I in aaa print I obj.doc Redirects output to standard error output: import sys sys.stderr, ‘Fatal error:invalid input! Logfile =open(‘/TMP /mylog.txt ‘, ‘a’) print >> logfile, ‘Fatal error:invalid input! ‘logfile.close() 64

Os.mknod (” test.txt “) # Create empty files in windos environment where OS.getcwd () cannot be used — get the current working directory. Os.remove () — delete specified file os.rmdir() — delete specified directory — delete multiple directories: os.removedirs os.mkdir() — Create directory Os.makedirs () os.path.isfile() — Determines whether the specified object is a file. Returns True if True, False otherwise os.path.isdir() — checks whether the specified object is a directory. Is True, otherwise False. Os.path.split () — Returns the directory and filename of the path. Os.path.exists () — Checks whether the specified object exists os.system() — executes the shell command. Such as: Os.system (” echo ‘hello world’ “) os.chdir() — Change the directory to the specified directory os.path.getsize() — Get the size of the file os.path.abspath() os.path.join(path, Name) — Connection directory and file name. Os.path.basename (path) — Returns the file name os.path.dirname(path) — returns the file path os.listdir() — specifies all files and directory names in all directories os.name() — Determines which platform is being used, Windows returns’ nt; Linux returns’ posix ‘to verify that the given path is a file: os.path.isfile() To verify that the given path is a directory: Os.path.isdir () Reads and sets environment variables :os.getenv() and os.putenv() Obtain file properties: os.stat (file) Modify file permissions and timestamps: os.chmod (file)

65. Unified line break: ls=os.linesep ls is the line stop

Fp = open(” test.txt “,w) # Open a file directly, create a file if it does not exist w: open in write mode, a: open in append mode (starting from EOF, create a new file if necessary) r+ : open in read/write mode w+ : Open in read/write mode (see w) A + : open in read/write mode (see a) rb: open in binary read mode WB: open in binary write mode (see w) AB: open in binary append mode (see a) rb+ : open in binary read/write mode (see R +) WB + : Open in binary read/write mode (see w+) ab+ : Open in binary read/write mode (see a+) fp.read([size]) #size indicates the length of the read, in bytes. Fp.readline ([size]) # Fp.readlines ([size]) # treat each line of the file as a member of a list and return the list. It’s actually done internally by calling readline() in a loop. If size is provided, size is the total amount of content read, which means that only a portion of the file may be read. Fp. write(STR) # write STR to a file. Write () does not add a newline character to STR. Fp. writq (seq) # Write the contents of seQ to a file. This function also writes faithfully, without adding anything after each line. Fp.close () # Close the file. Python automatically closes a file when it is no longer in use, but this feature is not guaranteed, so it’s best to get in the habit of closing it yourself. ValueError fp.flush() # write the contents of the buffer to disk fp.fileno() # Return a long integer “file label” fp.isatty() # Is the file a terminal device file (on Unix) Fp.tell () # returns the current position of the file action mark, starting at the beginning of the file fp.next() # returns the next line and moves the file action mark to the next line. When a file is used in a statement like for… In file, the next() function is called to iterate. Fp.seek (offset[,whence]) # move the file to offset. This offset is usually calculated relative to the start of the file and is usually a positive number. If whence is provided, however, this is not necessarily the case. whence can be 0 to start the calculation, and 1 to start the calculation from the current position. 2 indicates that the calculation starts from the end of the file. Note that if the file is opened in A or A + mode, the file operation flag automatically returns to the end of the file each time a write operation is performed. Fp. truncate([size]) # Truncate the file to the specified size, the default is to the current file operation mark position. If the size is larger than the size of the file, depending on the system, the file may not be changed, the file may be filled to the corresponding size with 0, or it may be added in some random way.

1. Create a directory os.mkdir(” file “) 2. Copy files: Shutil. copyfile(” oldfile “, “newfile”) #oldfile and newfile can only be files shutil.copy(” oldfile “, “newfile”) #oldfile can only be folders, Newfile can be a file or target directory 3. Shutil. copytree(” olddir “, “newdir”) # both olddir and newdir must be directories, and newdir must not exist 5. Rename files (directories) os.rename(” oldname “, “newname”) # Rename files or directories using this command 6. Move file (directory) shutil.move(” oldpos “, “newpos”) 7. Remove file os.remove(” file “) 8. Delete directory os.rmdir(” dir “) # Delete only empty directory shutil.rmtree(” dir “) # Delete both empty directory and content directory 9. Chdir (” path “) # Change path

Sleep (1) try: el.send_keys(kees.enter) except: print u “Click done”

Aotuit can be used to operate win32 controls 70. Import methods (functions) from other files import method name 71. String. Strip () is a built-in function for deleting strings. From the beginning and the end. If the parentheses are empty, whitespace characters such as \n\r\t are removed. .lstrip is from the beginning. Rstrip is from the end 72. Comparison: empty and error retrieved lists. self.verificationErrors = [] self.assertEqual([], self.verificationErrors) 73. Open other programs, such as Notepad os.system(‘ notepad ‘) 74. When writing Excel operations, initialize Sheet1, etc., inside the for loop. 75. Can be adapted to a variety of platform OS module characters: Linesep String used to separate lines in a file sep String used to separate file paths pathSep String used to separate file paths curdir String name of the current working directory pardir String name of the parent directory 76. Truncate () : Truncate () File object. Truncate () receives a size, truncate to the size, if not written, truncate to the current position of the file, that is, 0. The file object method file.close() closes the file.fileno() returns the file descriptor.flush() flusses the internal buffer of the file.isatty() checks whether the file isatty device.next () returns the next line, Iterator function. Read (size=-1) reads size bytes. When size is 0 or negative, read the remaining bytes. Readinto (buf,size) reads size bytes into the BUF buffer (invalid). Readline (size=-1) reads from the file and returns a line(including line terminator), or returns the maximum size of characters .readlines(sizhint) reads all lines and returns them as a list (with all line terminators); The value of sizhint is a line that returns approximately sizhint bytes, depending on the buffer, Only multiples of buffers.xreadlines() can be used for iteration and can replace readlines() with a more efficient method.seek(x,0) to move the cursor.tell() returns the current position in the file.truncate(size=file.tell()) Write (STR) Write strings to a file. Writq (seq) Write a sequence of strings to a file. Seq should be an iterable and the return value should be string 78. Closed flag variable. Closed indicates whether closed, true indicates that closed. Encoding Specifies the encoding used in the file. A list of all line terminators. Softspace 0 means that a line is output followed by a space 1 means that 79 is not added. Multithreaded queue module. You can wait for user behavior for unlimited time. Q = queue.queue (maxsize): first in, first out q= queue.lifoqueue (maxsize): first in, first out 80. Remove () /.unlink() deletes a file.rename() /.renmaes() renames a file.stat() returns file information. Symlink () creates a symbolic link .utime() updates timestamp.tmpFile () creates and opens (‘ w+b ‘) a new temporary file.walk () generates a directory tree of all file names folder/director.chdir ()/.fchdir() Change the current working directory/Change the current working directory with a file descriptor.chroot() Change the root directory of the current process.listdir() lists files in the specified directory.getcwd()/.getcwdu() Returns the current working directory.mkdir()/.makedirs() Rmdir ()/.removedirs() Delete a directory or delete a multilayer directory 81. Chmodj () changes the permission mode. Chown ()/lchown() changes the owner and group ID.umask () sets the default permission mode 82. File descriptor operator.open () The underlying operating system open.read ()/.write() reads/writes data from the file descriptor.dup ()/.dup2 () copies the file descriptor 83. Device number.makedev () creates a primitive device number from major and minor. Major ()/.minor() obtains the major/minor device number from the primitive device number Os.path.basename () removes the directory path and returns the file name.. Dirname () removes the file name and returns the directory path.. Join () groups the separated parts into a pathname.. Split () returns the (dirname(),basename()) tuple.. Splitdrive () returns the (dirvename, pathName) tuple.. Splitext () returns the (filename,extension) tuple 85. Information.. Getatime () returns the last access time.. Getctime () returns the file creation time.. Getmtime () returns the last file modification time.. Getsize () returns the file size in bytes 86. Query.. Exists () Specifies whether a path file or directory exists.. Isabs () specifies whether the path is an absolute path.. Isdir () specifies whether the path exists and is a directory.. Isfile () specifies whether the path exists and is a file.. Islink () specifies whether the path exists and is a symbolic link.. Ismount () specifies whether the path exists and is a mount point.. Samefile () whether two pathnames point to the samefile

Import Tkinter from functools import partial root = tkinter.tk () MyButton = Partial (tkinter. Button,root,fg= ‘white’,bg= ‘blue’) b1 = MyButton(text= ‘button1’) b2 = MyButton(text= ‘button2’) qb = MyButton (text = ‘quit’, bg = “red”, the command = root. Quit) b1. The pack (b2). The pack () qb. Pack (fill = Tkinter. X, expand = True) Root. Title (‘ PFAs! ‘) root. Mainloop ()