When I first tried Python, I stepped on some pitfalls ~

Source: Internet
Author: User

[Escape Character]

OS. path. isdir (targetPath) always reports an error. If the string is not valid, it is converted to the file type. After trying many methods, it still does not solve the problem. Finally, we found that, escape characters in the path strings in windows (the examples are copied online, misleading, and low-level errors ).

[Indent]

Python is sensitive to indentation. Working with Notepad ++, examples of copying are space indentation, but Notepad ++ always uses tab indentation, so running always runs wrong indentation error. After unified solution.

[Line Break]

The strings read from the file are line breaks (I cannot try Linux in win) and can be processed by str1.rstrip.

Write () for writing a file does not add line breaks, nor does it specifically add line breaks. The most pitfall is that I add '\ n' to the string, but it turns out to be CRLF, but I only want LF... It seems that there is no solution. Let the next shell solve the problem (tr-d' \ R ').

[Close after file is written]

After the file is written, close () is required to create and save the file. This is common sense.

[Sftp connection]

After checking, the paramiko module is usually used and the GCC dependency is required... If it is used by yourself, the problem is that the script is well written and it is too difficult to transplant it to other machines. Therefore, we call the dos console to run winscp in a very simple way.

 

The winscp connection script and the folder operations in Linux are not expanded. The string operations in Linux shell are still quite pitfall. The following is a good reference.

Http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.