Foundations of Python Network Programming 2nd edition phần 9

giao diện cũng như các giao thức dịch vụ web RESTful-. Có tồn tại các máy chủ web tinh khiết Python, có thể được đặc biệt quan trọng khi viết một giao diện web cho một chương trình mà người dùng sẽ cài đặt tại địa phương. Có không chỉ có sự lựa chọn tốt có sẵn để tải về, nhưng một vài máy chủ nhỏ thậm chí | CHAPTER 16 TELNET AND SSH Do you see what has happened The operating system does not know that spaces should be special that is a quirk of shell programs not of Unix-like operating systems themselves So the system thinks that it is being asked to run a command literally named echo space hello and unless you have created such a file in the current directory it fails to find it and raises an exception. Oh I said at the beginning of this whole section that its whole premise was a lie and you probably want to know what character is in fact special to the system It turns out that it is the null character the character having the Unicode and ASCII code zero. This character is used in Unix-like systems to mark the end of each command-line argument in memory. So if you try using a null character in an argument Unix will think the argument has ended and will ignore the rest of its text. To prevent you from making this mistake Python stops you in your tracks if you include a null character in a commandline argument import subprocess echo Sentences can end 0 abruptly. TracebaCk most recent call last . TypeError execv arg 2 must contain only strings Happily since every command on the system is designed to live within this limitation you will generally find there is never any reason to put null characters into command-line arguments anyway Specifically they cannot appear in file names for exactly the same reason as they cannot appear in arguments file names are null-terminated in the operating system implementation. Quoting Characters for Protection In the foregoing section we used routines in Python s subprocess module to directly invoke commands. This was great and let us pass characters that would have been special to a normal interactive shell. If you have a big list of file names with spaces and other special characters in them it can be wonderful to simply pass them into a subprocess call and have the command on the receiving end understand you perfectly.

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.