- 全局替换字符串
%s#old string#new string#g
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Net; | |
using System.IO; | |
namespace ConsoleApp1 | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import random | |
# python 3.6.1以下 | |
text = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(15)) | |
print(text) | |
# python 3.6.1 | |
text = ''.join(random.choices(string.ascii_letters + string.digits, k=15)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from difflib import SequenceMatcher | |
def similar(a, b): | |
return SequenceMatcher(None, a, b).ratio() | |
""" | |
>>> similar("Apple","Appel") | |
0.8 | |
>>> similar("Apple","Mango") | |
0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
多进程示例 | |
""" | |
import time | |
from multiprocessing import Pool | |
def run(fn): | |
time.sleep(1) | |
print(fn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5 import QtCore, QtGui, QtWidgets | |
from PyQt5.QtWidgets import * | |
# 打开文件对话框, | |
filename, filetype = QFileDialog.getOpenFileName(None, '选择文件', "", filter="txt (*.txt)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
import urllib.request | |
URLS = ['http://www.163.com/', | |
'http://www.qq.com/', | |
'http://www.baidu.com/', | |
'http://www.v2ex.com/', | |
'http://www.360.com'] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
import math | |
PRIMES = [ | |
112272535095293, | |
112582705942171, | |
112272535095293, | |
115280095190773, | |
115797848077099, | |
1099726899285419] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
def base62_encode(num, alphabet=ALPHABET): | |
"""Encode a number in Base X | |
`num`: The number to encode | |
`alphabet`: The alphabet to use for encoding | |
""" | |
if (num == 0): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# 字典列表 | |
result_list = [] | |
with open('weibo_data.csv', 'w', newline='', encoding='gbk') as csv_file: | |
# header field | |
fieldnames = result_list[0].keys() | |
writer = csv.DictWriter(csv_file, fieldnames=fieldnames) | |
writer.writeheader() | |
writer.writerows(result_list) |
OlderNewer