随笔分类 - Python
摘要:像下图这样的蛇如何拐弯?绿点是新蛇头,红点是旧蛇尾。 搜了下,有用JavaScript写的,有用Python写的,好像都是把蛇身用一系列的点来表示。这样比我原先想的用若干根线段表示简单清晰多了,最前面加一个点,最后面删一个点即可,不用把一根线段折/拆成两根。几百个点速度也很快。当把蛇身画成一系列椭圆
阅读全文
摘要:python - What do * and ** before a variable name mean in a function signature? - Stack Overflow # * collects all the positional arguments in a tuple.
阅读全文
摘要:如题,x是32位unsigned integer. 有Quake公式,(n+1)**2 - n**2 = 2n + 1, 即1+3=4, 4+5=9, 9+7=16 ... [说错了:Babbage difference and Quake's Fast Inverse Square Root -
阅读全文
摘要:def tab2space(s, ts=4): out = ''; i = 0 for c in s: if c == '\t': j = ((i + ts) // ts) * ts out += (j - i) * ' ' i = j else: out += c; i += 1 return o
阅读全文
摘要:Math for Programmers, 3D graphics, machine learning, and simulations with Python, Version 10, Copyright 2020 Manning Publications My (fictional) frien
阅读全文
摘要:请看代码: from html.parser import HTMLParser # pip install html-parser from htmldom import htmldom # pip install htmldom import urllib.request import time
阅读全文
摘要:D:\>t.py 4 variables A B C D 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1
阅读全文
摘要:D:\Python39\Lib\site-packages>md zzD:\>python>>>import zz# 目录zz可以当module import,__init__.py不是必需的。 D:\Python39\Lib\site-packages\zz>type m.pydef p(): p
阅读全文
摘要:有时我们想把自己的"网站"copy给别人,它有一大堆小文件,很不清爽。给人一个httpd.py和data.zip不好吗?下面的代码能做到: import os import sys from zipfile import ZipFile zf = ZipFile('fliplot.zip', 'r'
阅读全文
摘要:用ctypes模块是可以的。但是也可以去system("getopenfilename.exe"): tdm-gcc-10.3.0.exe 61,647KB. 自带了Windows的头文件和库。 #define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #de
阅读全文
摘要:全部文件在这里。无需上网即可使用,自带了jquery.min.js等。页面最下面有作者信息, 不是我做的, 我只是下载删减压缩了一番。不好意思少了行 port = int(sys.argv[1]) What is a Value Change Dump (VCD) file? 博客园 python可
阅读全文
摘要:# sys.path -- module search path. sys.path.append(os.path.join(here, '..')) from fliplot.core import parseFileapp = Flask('fliplot') 今天改一个程序,在原先的文件夹里好
阅读全文
摘要:补充: 今天干别的事情时发现D:\Python39\Lib\site-packages\Verilog_VCD\下没有__init__.py,我当初from Verilog_VCD import *咋work的?目前合理的解释是:当初把Verilog_VCD.py复制到当前目录下了。不是因为发现找不
阅读全文
摘要:Automate Debugging with GDB Python API | Interrupt (memfault.com) 事前: 事后: D:\gcc\gdb32\bin>gdb32 GNU gdb (GDB) 10.2 Copyright (C) 2021 Free Software F
阅读全文
摘要:''' N = 2097152 0.0455327033996582 0.9995155334472656 0.9995260238647461 0.9997577667236328 起因是做推箱子游戏,想把箱子们的坐标hash下。如6个箱子,每个的x和y 都是0~31(一个字节有10位就好了)。上
阅读全文
摘要:# -*- coding: utf-8 -*- # 94个区,每个区94个汉字/符号/python会throw exception的东东 # 内码 := <区码+0xa0> <位码+0xa0>, little endian. 0xa0+94=0xfe # 汉字从1601(啊)开始,它的内码是B0 A
阅读全文
摘要:脑袋发懵走了点弯路,记下来: import subprocessengine = subprocess.Popen([wd + 'ELEEYE.EXE',]) ... from subprocess import *engine = subprocess.Popen([wd + 'ELEEYE.EX
阅读全文
摘要:# Numba translates Python functions to optimized machine code at runtime using the industry-standard LLVM compiler library. # Numba-compiled numerical
阅读全文
摘要:import bdb import linecache class Cdb(bdb.Bdb): def __init__(m, skip=None): print('''<html><style> *{font: 10pt "Source Code Pro", Hack, mono} b{color
阅读全文
摘要:# -*- coding: gbk -*- # 1. 到www.runoob.com/python/python或www.w3school.com.cn/python/index.asp学基本语法 # 2. 到这里(不定期更新)学中级语法,让程序更有python味。 # 3. 算法+数据结构=程序,
阅读全文