自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(32)
  • 资源 (2)
  • 收藏
  • 关注

原创 python 中 with 的用法,以及 python 读写文件

python 中 with 的用法with 的目的是从流程图中把 try, except, finally 关键字和资源分配释放相关代码统统去掉,简化 try, except, finally 的处理流程。with 语句适用于对资源进行访问的场合,确保不管使用过程中是否发生异常都会执行必要的“清理”操作,释放资源,比如文件使用后自动关闭、线程中锁的自动获取和释放等。with 语句的基本...

2019-12-31 16:07:55 500

原创 java / js 里的 st1.indexOf( str ) > -1,在 python 里得用 st1.find( str ) > -1 来实现

java / js 里的 st1.indexOf( str ) > -1,在 python 里得用 st1.find( str ) > -1 来实现name = 'text1'str = ' xt'# python indexOfif( name.find( str ) > -1 ): return True else: return False...

2019-12-31 14:12:14 230

原创 python3 把类似这样的 '\xe5\xae\x9d\xe9\xb8\xa1\xe5\xb8\x82' 转换成汉字

python3 把类似这样的 '\xe5\xae\x9d\xe9\xb8\xa1\xe5\xb8\x82' 转换成汉字:str1 = b'\xe5\xae\x9d\xe9\xb8\xa1\xe5\xb8\x82'print( str1.decode( 'utf8' ) ) # 打印: 宝鸡市

2019-12-30 19:05:22 1550

原创 python 没有 null

在 python 中没有 null,取而代之的是 None。它的含义是空。但要注意和空列表与空字符串的区别。None 的类型是 Nonetypea = None type(a) 打印: <class 'Nonetype'> 另外,None 没有像 len,size 等属性,要判断一个变量是否为 None,直接使用if a == None: 注意 None 与...

2019-12-26 17:32:31 411

原创 java 的 try catch finally 对应 python3 的 try except finally

java 的 try catch finally 对应 python3 的 try except finallypython3 写成这样:try: # 1 / 0except Exception as e: print( "Exception: ", e ) # 打印 Exception: division by zerofinally: print(...

2019-12-26 17:03:19 465

原创 python 查看系统默认编码;获得 python 内置的编码、解码方式

要用到 locale 模块,以下为 windows 上的演示import localeprint(locale.getpreferredencoding())print(locale.getdefaultlocale())#输出cp936('zh_CN', 'cp936')CP936 就是 GBK,IBM 在发明 Code Page 的时候将 GBK 放在第 936 页,所以叫...

2019-12-26 16:34:01 1787

原创 原来可以在没安装 python 环境的 windows 上,用 pyinstaller 生成一个 py 对应的 exe,运行这个 py 程序。附 pyinstaller 编译脚本

今天才知道,原来可以在没安装 python 环境的 windows 上,用 pyinstaller 生成一个 py 对应的 exe,双击它来运行 py 程序。pyInstaller 的下载页: http://www.pyinstaller.org/downloads.html编译方法:在 cmd 里,进入 d:\pyStuff\PyInstaller-3.5 文件夹,运行...

2019-12-25 22:27:57 1285

原创 python 的 charAt 功能,得用 string[ index ] 来实现

python 没有 charAt 函数,得用 string[ index ] 来实现这个功能例子:theStr = 'd:\\syndicate\\11'print( theStr[ 1 ] ) # 打印结果 :

2019-12-24 12:25:44 5969

原创 python 也没有 replaceAll,需要自己写一个

# python 的 replaceAlldef replaceAll( input, toReplace, replaceWith ): # while ( input.find( toReplace ) > -1 ): input = input.replace( toReplace, replaceWith ) return input...

2019-12-24 11:53:09 2317

原创 python 拼接字符串时报错 Can't convert 'int' object to str implicitly

发现拼接字符串时,有一个参数是 int 型的,所以报这个错,比如 typeStr + " " + size,其中 size 是一个 int 。这时需要用 str( int ) 把它转成 string 后再拼接,就不报错了: typeStr + " " + str( size )...

2019-12-23 19:47:52 1801

原创 python 截取 url 最后一个 / 后的字符串;截取倒数第二个 / 后的字符串

python 需要用 rindex() 来实现 lastIndexOf() 功能。# 截取 url 最后一个 / 后的字符串:str = "tttt/aaa/123";print( str[ str.rindex( '/' ) + 1 : len( str ) ] ); # 打印 123# 截取 url 倒数第二个 \ 后的字符串:str = "qq/ttt...

2019-12-23 19:24:09 6783 1

原创 python 实现 substring 截取子字符串

python 没有类似 substr() 或 subString() 的方法。不过可以用 string[ indexA: indexB ] 来截取字符串。str = "this is a string example";print( str.startswith( 'this' ) );print( str.endswith( 'example' ) );print( str...

2019-12-23 14:30:59 11278

原创 python 代码报错:unorderable types: str() > int()

一句 python 代码报错:unorderable types: str() > int()if folderLayerCount > layer : # print( "123132" );#发现 layer 是一个字符串,而 folderLayerCount 整数。那就把 layer 转成 int ,再比较,就不报错了:if folderLaye...

2019-12-21 21:27:37 750

原创 python 统计字符串中某个字符出现的次数

# 统计字符串中某个字符出现的次数ss = 'abc\\acad\\afa'list1 = list( ss )count1 = list1.count( "\\" ) # 统计字符串中 \\ 出现的次数print( count1 )

2019-12-20 17:09:50 4037

原创 python 报错 UnboundLocalError: local variable 'xxxx' referenced before assignment

在 python 的函数中定义了和全局变量同名的变量,如果在函数中修改这个变量的值,python 就会认为它是局部变量,在函数中对这个变量的引用自然就会被认为是没定义。如果确定要在函数中引用全局变量,并且要对它修改,应该加上 global 关键字。count = 23 def printFileName(strFileName): # global count # 不加...

2019-12-20 16:32:52 1187

原创 python 判断某个路径是否是一个文件;判断某个路径是否是一个目录 --- 参数都需要传入绝对路径

path = 'd:\\test'for x in os.listdir( 'd:\\test' ): # # 判断某个路径是否是一个目录 if os.path.isdir( os.path.join( 'd:\\test', x ) ): # isdir 参数需要传入绝对路径 print( 'dir: ', os.path.join('d:\\test'...

2019-12-20 09:18:10 665

原创 python 删除目录 及其中的 内容;删除一个文件

import shutil# 删除目录 及其中的 内容shutil.rmtree( ‘d:\\test’ )# 删除文件os.remove( "d:\\pythonTest.txt" )

2019-12-19 15:51:34 321

原创 python 将文件夹打成 tar 包

import os, tarfile# 将文件夹打成 tar 包,空子目录会被打包# "w:gz" = 打包并且压缩 "w" = 打包但不压缩def makeTar(outputFileName, sourceDir): # with tarfile.open( outputFileName, "w" ) as tar: # w:gz tar.add(s...

2019-12-19 14:38:56 2480

原创 python 打印当前时间; 获得当前的时间戳

# 打印当前时间print( time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime( time.time() ) ) );# 获得当前的时间戳,是公元开始到现在的秒数print( time.time() );

2019-12-19 13:43:59 2046

原创 python 清空文本内容

import os# 清空文本内容file = open( "d:\\qq.txt", "w+" ) # 文件如果不存在就创建file.truncate()file.close()

2019-12-19 11:22:54 4395

原创 python open() 操作文件的 mode 参数;python 追加文本内容

python open() 操作文件的 mode 参数:‘r’:读‘w’:写‘a’:追加‘r+’ = r+w(可读可写,文件如果不存在就报错(IOError))‘w+’ = w+r(可读可写,文件如果不存在就创建)‘a+’ = a+r(可追加可写,文件如果不存在就创建)如果是二进制文件,对应的都加一个 b: ‘rb’ ‘wb’ ‘ab’ ‘rb+’ ‘wb+’ ‘ab+...

2019-12-19 10:27:48 1119

原创 python 判断一个文件夹是否存在,如果不存在,就创建;判断一个文件是否存在,不存在就创建

python 判断一个文件夹是否存在,如果不存在,就创建import os# 判断文件夹是否存在,不存在,就创建if os.path.exists( 'c:\\temp' ) == False: # os.makedirs( 'c:\\temp' )#判断一个文件是否存在,不存在就创建import os# 判断文件是否存在,不存在就创建if os.path.e...

2019-12-19 09:30:15 4220

原创 鼠标滚轮失灵了,最后换了鼠标编码器,才算修好。

鼠标滚轮失灵了。拆开鼠标,往滚轮上滴点酒精,然后滚轮恢复正常了几天,又坏了。最后,从某宝买了一个 鼠标编码器,寄给咸鱼上的师傅给换上,才算修好了鼠标滚轮失灵。赛睿 kinzu 用 10mm 的鼠标编码器。...

2019-12-18 19:20:45 2465

原创 python 字符串判空

#python 字符串 判空mystr1 = ' ' if mystr1.strip() == '': # strip() 会去掉字符串两边的空字符 print( 123 ) 如果对空值判断的次数比较多,可以自己封装适合自己的函数。提高效率。...

2019-12-18 17:51:31 1181

原创 python 逐行读取文本,for 和 while 实现

for 实现:import os;# python 逐行读取文本for line in open( "c:\\testLineCount.txt", encoding = "utf-8" ): # print( line );#while 实现:path = "C:\\testLineCount.txt"file1 = open( path, "r",...

2019-12-18 17:14:38 1226

原创 python 三目运算符的两种写法

python 三目运算符 的 两种写法a = 8b = 5# 写法 一:c = a if a > b else b # 为真时,放 if 前 ----- 这种写法,和 java js 的 三目运算符 还不一样print( c )# 写法 二:c = ( a > b and a or b ) # 这种写法,和 java js 的 ...

2019-12-18 11:09:25 547

原创 python 获得 windows 系统里文件/文件夹的所有者

先安装 python3.5, 再安装 pywin32-227.win32-py3.5.exe (对应32位 python)或 pywin32-227.win-amd64-py3.5.exe(对应64位 python)获得 文件 的 所有者,运行:import win32apiimport win32conimport win32security# 获得登陆用户的名字pri...

2019-12-17 19:21:42 1294 1

原创 解决 python 输出/写中文到 txt 打开看是乱码的问题

当尝试进行中文输出的时候,基本打印出来的情况都是乱码,这个时候应该怎么解决?网上非常多版本的解决方法都是老旧没有更新,大家尝试过后相信都会报这样一个错误:TypeError: __init__() got an unexpected keyword argument ‘encoding'这个原因就是在 python3 中,json.dumps() 中压根就没有 encoding 这个参数...

2019-12-16 17:28:43 12024

原创 sql --- 按分类,统计每类的数量

比如有一个 profession (职业表),按它的分类,统计每类的数量:按分类,统计每类的数量:SELECT p.type, COUNT( * ) from profession pwhere p.isDelete = 0GROUP BY p.type或SELECT p.type, COUNT( p.professionId ) from profession pwh...

2019-12-16 09:46:37 20728

原创 jquery 的 prev, next, find 的用法

find() 是用来查找后代元素,prev(),next() 用来查找同级元素。 find() 可以查找后代任意一个元素,但需要进行匹配。 next() 只能查找后一个同级元素,如果想查找下下个元素,就多用一个next()。 prev 和 next 相对转自: https://blog.csdn.net/lmp5023/article/details/88386461...

2019-12-13 09:19:59 486

原创 Jquery 获得 select 的所有 option 键值对

// Jquery 获得 select 的所有 option 键值对var data;$("#select1 option").each( function() { var value = $(this).val(); var text = $(this).text().trim(); data += '<option value="' + valu...

2019-12-11 17:08:15 468

原创 java 使用 java.util.Collections.addAll( list, array ) 将数组转成 list

// java 使用 java.util.Collections 将 数组 转成 listList<String> list1 = new ArrayList<String>(); boolean addAll1 = java.util.Collections.addAll(list1, new String[]{"M.Salah", "Crisitiano", ...

2019-12-06 14:35:53 1100

easyui demo .zip

easyui 的例子

2020-05-16

MASM 8.0 安装程序

x86 汇编语言的编译器MASM 8.0。也可以直接从这页下载 http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64

2009-08-02

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除