随笔分类 - Python / 代码片段
摘要:# coding=utf-8 phone = ['iPhone', 'HuaWei', 'Mi'] number = [1, 2, 3] color = ['白', '黑'] for p in phone: for n in number: for c in color: print(f'{p}{n
阅读全文
摘要:import pypinyin # 不带声调的(style=pypinyin.NORMAL) def pinyin(word): s = '' for i in pypinyin.pinyin(word, style=pypinyin.NORMAL): s += ''.join(i)+ " " re
阅读全文
摘要:def digital_to_chinese(digital): str_digital = str(digital) chinese = {'1': '壹', '2': '贰', '3': '叁', '4': '肆', '5': '伍', '6': '陆', '7': '柒', '8': '捌',
阅读全文
摘要:import keyboard import time while True: if keyboard.is_pressed('w'): print('Forward') elif keyboard.is_pressed('s'): print('Backward') elif keyboard.i
阅读全文
摘要:对VAT.exe软件操作,按esc杀掉python.exe进程 # -*- coding:utf8 -*- import datetime import os import random import time from threading import Thread from pynput.key
阅读全文
摘要:脚本目的是小时候暑假看过一个韩剧,看了一半没看见结局,不记得剧名了,有点遗憾。在网上搜索那几年有哪些剧,然后百度,主角长啥样还是有点印象的,最终找到了!!! # -- coding:UTF-8 -- import re from selenium import webdriver from sele
阅读全文
摘要:# -*- coding: utf-8 -*- import os import pandas as pd def split_csv(src_file_name, num, flag, file_encoding): df = pd.read_csv(src_file_name, encoding
阅读全文
摘要:# -*- coding:utf8 -*- import pandas as pd file_name = '查询银行汇总_20w.xlsx' file_name_prefix = file_name.split('.')[0] df = pd.DataFrame(pd.read_excel(fil
阅读全文
摘要:# 第一步:调用pandas包 import pandas as pd # 第二步:读取数据 iris = pd.read_excel('./test1.xlsx', None) # 读入数据文件 keys = list(iris.keys()) # iris.keys()得到test.xls的sh
阅读全文
摘要:# with import random import pysnooper def print_upper_mid_lower(): lst = [] for i in range(10): lst.append(random.randrange(1, 1000)) with pysnooper.s
阅读全文
摘要:from math import * def getDistance(latA, lonA, latB, lonB): ra = 6378140 # radius of equator: meter rb = 6356755 # radius of polar: meter flatten = (r
阅读全文
摘要:import inspect import sys def demo1(): f_name = inspect.getframeinfo(inspect.currentframe().f_back)[3][0] print(f_name) def demo2(): f_name = sys._get
阅读全文
摘要:# encoding='UTF-8' import urllib.request import urllib.parse import json def get_data(words): data = {} data["type"] = "AUTO" data["i"] = words data["
阅读全文
摘要:# -*- coding: utf-8 -*- import os # 字节b转化kb\m\g def format_size(b): try: b = float(b) kb = b / 1024 except: print("传入的字节格式不对") return "Error" if kb >=
阅读全文
摘要:import heapq a_list = [3, 4, 2, 5, 1, 6] c_dict = {'A': 3, 'B': 4, 'C': 5} topNum = 2 print(heapq.nlargest(topNum, a_list)) print(heapq.nlargest(topNu
阅读全文