day19 module

Regex #
# character group [the character]
# membered character
# \ W \ D \ S
# \ W is \ D \ S
#. In addition, any character that newline
# \ n-\ T
# \ B
# ^ $ matching string start and end
# () grouping is a multiple character sets overall time constraints quantifier used
#re modules: packet is priority
# findAll
# Split
# | matches left to right, as long as the match can not continue the match . So it should be put in front of the long
# [^] Among other match in the group of characters
# quantifier
# 0 *
# + 1 ~
#? ~. 1 0
# {} n-n-
# n-{,} ~ n-
# {n-, n-m} m ~

Escape # question
# Import Re
# the re.findall (R & lt '\\ S', R & lt '\ S')

# Inert match
# quantifier behind a question mark
#. *? Abc abc has stopped taking experience

Module # re
# Import Re
# the re.findall ( '\ D', 'awir17948jsdc', re.S)
# Return Value: list to the list of all matching entries

Search RET = # ( '\ D (\ W) +', 'awir17948jsdc')
# Search RET = ( '\ D (? P <name> \ W) +', 'awir17948jsdc')
# find the entire string, the case of the return to the match, it never quite None
# if the return value ret.group () can be taken to a value of
# take the contents of the packet: ret.group (1) / ret.group ( 'name')

Match #
# scratch match, on the return match, the match is not None
# If the values match on .group

# Split Split
# replace sub and subn
# finditer returns an iterator
# compile compiler: long and regular expressions to be used multiple times

import re

# RET = the re.search ( "<(? P <the tag_name> \ W +)> \ W + </ (? P = the tag_name)>", "<h1 of> Hello </ h1 of>")
# # may also be in the packet ? using <name> is a name in the form of a packet
## can obtain it directly to the matching result corresponding to the value group ( 'name')
# Print (ret.group ( 'the tag_name')) # results: h1 of
# Print ( ret.group ()) # results: <h1> hello </ h1 >

# RET = the re.search (R & lt "<(\ W +)> \ W + </ \. 1>", "<h1 of> Hello </ h1 of>")
# # if not to set a name, or \ sequence number find the corresponding group, the group represents the contents of the previous contents looking consistent
results matching ## can get the acquired value corresponding directly group (ID)
# Print (ret.group (. 1))
# Print (ret.group ()) # results: <h1> hello </ h1 >

import re

# ret=re.findall(r"\d+\.\d+|(\d+)","1-2*(60+(-40.35/5)-(-4*3))")
# print(ret) #['1', '2', '60', '40', '35', '5', '4', '3']
# ret.remove('')
# print(ret)
# ret=re.findall(r"-?\d+\.\d*|(-?\d+)","1-2*(60+(-40.35/5)-(-4*3))")
# print(ret) #['1', '-2', '60', '', '5', '-4', '3']
# ret.remove("")
# print(ret) #['1', '-2', '60', '5', '-4', '3']

First, get a string #
# go blank
# is no space string
# the first count innermost parentheses: Find brackets, parentheses and brackets are no other
# get a expressions without parentheses: only addition, subtraction from left to the right to find the first multiplication and division - repeat
# All multiplication and division are done
# calculated addition and subtraction - addition and subtraction
# only one number on the can end

 

# List, Ganso
# dictionary
# collection, frozenset
# String
# Stack: last-out
# queue: FIFO FIFO

# from collections import namedtuple
# Point = namedtuple('point',['x','y','z'])
# p1 = Point(1,2,3)
# p2 = Point(3,2,1)
# print(p1.x)
# print(p1.y)
# print(p1,p2)

And a digital color #
# = namedtuple Card ( 'Card', [ 'Suits', 'Number'])
# C1 = Card ( 'hearts', 2)
# Print (C1)
# Print (c1.number)
# Print ( c1.suits)

#队列
# import queue
# q = queue.Queue()
# q.put([1,2,3])
# q.put(5)
# q.put(6)
# print(q)
# print(q.get())
# print(q.get())
# print(q.get())
# print(q.get()) # 阻塞
# print(q.qsize())

Collections from the deque Import #
# = DQ the deque ([1,2])
# dq.append ( 'A') # discharge data [1,2, 'a'] from the rear
# dq.appendleft ( 'b') # from put in front of data [ 'B', 1,2, 'A']
# dq.insert (2,3) # [ 'B', 1,3,2, 'A']
# Print (dq.pop ()) fetching data from the back #
# print (dq.pop ()) # fetch data from the back
# print (dq.popleft ()) # fetch data from the front
# print (dq)

Ordered dictionary #
# Import from Collections OrderedDict
# OrderedDict OD = ([( 'A',. 1), ( 'B', 2), ( 'C',. 3)])
# Print (OD) # Key is the OrderedDict ordered
# Print (OD [ 'a'])
# K in for OD:
# Print (K)

# from collections import defaultdict
# d = defaultdict(lambda : 5)
# print(d['k'])

 

#计算时间差
import time
true_time = time.mktime(time.strptime('2019-06-11 09:30:00','%Y-%m-%d %H:%M:%S'))
now_time = time.mktime(time.strptime('2019-06-12 12:00:00','%Y-%m-%d %H:%M:%S'))
print(true_time,now_time)
dif_time = now_time - true_time
struct_time = time.gmtime(dif_time)
stf_time = time.strftime('%Y-%m-%d %H:%M:%S',struct_time)
print(stf_time)
print('过去了%d年%d月%d天%d小时%d分钟%d秒'%(struct_time.tm_year-1970,struct_time.tm_mon-1,
struct_time.tm_mday-1,struct_time.tm_hour,
struct_time.tm_min,struct_time.tm_sec))
#生成随机验证码
import time,random
def choice():
code = ''
for i in range(5):
R = random.randint(0,9)
S = chr(random.randint(65,90))
add = random.choice([R,S])
code = "".join([code,str(add)])
return code
print(choice())


import os
# print(os.getcwd())
# os.chdir(r'C:\Users\Administrator\PycharmProjects')
# print(os.getcwd())

# os.chdir('..')
# print(os.getcwd())
# os.makedirs('dirname1/dirname2')
# os.removedirs('dirname1/dirname2')

# os.mkdir('dirname1/dirname')

# print(os.listdir(r'C:/Users/Administrator/PycharmProjects/s9'))

# Print (os.stat ( '1. Review .py'))

# Print (os.sep) # python code is cross-platform: Linux Windows
# / the User / bin /

# os.system("dir")
# ret = os.popen("dir").read()
# print(ret)

# Print (os.environ)

# print(os.getcwd())
# print(os.path.split(os.getcwd()))

# print(os.path.join(r'C:\Users\Administrator','user','local'))
# print(os.getcwd())
# print(os.path.getsize(os.path.join(os.getcwd(),'1.复习.py')))

 

import sys
# print(sys.platform)
# print(sys.version)


# print(sys.path.clear())


= sys.argv RET
name = RET [1]
pwd = RET [2]
IF name == 'alex' and pwd == 'alex3714':
Print ( 'successful landing')
the else:
Print ( "wrong user name and password." )
sys.exit ()
Print ( 'you can use the calculator')



Guess you like

Origin www.cnblogs.com/Murraya/p/11026464.html