Simple use of regular expressions, common use of OS modules, and regular expression of OS modules

Source: Internet
Author: User

Simple use of regular expressions, common use of OS modules, and regular expression of OS modules

Simple use of regular expressions

 

1 import re 2 origin = "3-5*6 + (20-3-4 * (30/5-5) * 6) + (5*6-7 * (20-2)-(8*8) + 195 "3 def f (str): 4 ss = eval (str) 5 return ss 6 while True: 7 res = re. split ("\ ([^ ()] +) \)", origin, 1) 8 if len (res) = 3: 9 befor, mid, after = res10 ret = f (mid) 11 print (type (befor), type (mid), type (after) 12 origin = str (befor) + str (ret) + str (after) 13 print (origin, type (origin) 14 else: 15 rr = f (origin) 16 print (int (rr) 17 break

Common OS modules

OS. stat ('path/filename ') to get the file/directory information
OS. path. dirname (path) returns the path directory
OS. path. exists (path) If path exists, True is returned. If path does not exist, False is returned.
OS. path. join (path1, path2,...) returns the results after combining multiple paths. The parameters before the first absolute path are ignored.

 

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.