猫史档案馆


我应该做些神马啊啊啊啊!

用户:wrmdcxywrmdcxy查看:57 回复:14 评论:57 创建时间:2020-02-24T14:23:35


最近非常无聊,每天都是逛逛论坛,看看代码岛,实在太无聊了…………emotion_雷电猴_摇椅子

可是,我又能怎么样?网站都爬遍了……emotion_编程猫_冷漠

我本想搞一喵的,却因为个人水平有限,无法坚持下去emotion_雷电猴_疑问

我又想搞个函数包,却没有灵感……emotion_编程猫_翻白眼

马上就要开学了,我希望能在这最后几天搞到什么有趣的、奇妙的……emotion_雷电猴_哇噻

谁能提供一下灵感?谢谢咯emotion_编程猫_谢谢老板

或者,你也有相似的情况,可以在下面举爪emotion_雷电猴_举手,咱们一起想想做些神马……

 

(附:本人只会Pythonemotion_笑cry。如果你是JS,C,C++......的大佬,请不要用其它编程语言评论,谢谢合作emotion_喵喵)


回复

上一页1 页 / 共 1下一页
liuzhiyuliuzhiyu

emotion_雷电猴_举手

点赞0


评论


QBZ_QBZ_

喵呜,可以用爬虫和pyecharts结合起来做一个疫情实时分析图

点赞0


评论


TobylaiTobylai

Ftp超好玩
不过你要先在本地建ftp服务器,你百度搜一下就ok了,劝你把那个ip设为127.0.0.1,这样连的Wi-Fi不同也能访问本机的

点赞0


评论


wrmdcxywrmdcxy

我的FileProcessing模块(都要变成库了)正在不断地扩张

center_image

点赞1


评论


桃花岛主黄药师桃花岛主黄药师

更文

点赞0


评论


wrmdcxywrmdcxy

我还搞了Errors库,内容就是提供其它类型的错误

center_image

点赞0


评论


游侠已退游侠已退

emotion_雷电猴_举手

点赞0


评论


wrmdcxywrmdcxy

代码:

def deleteLinesbyContents(path,contents,encoding='utf-8'):
    from Errors import FindError
    import time
    try:
        with open(path,'r',encoding=encoding) as file1:
            file=''
            for x in file1:
                file+=x
            lines=file.splitlines()
            lineNumber=1
            line='j'
            while line!='':
                line=file1.readline()
                print(line)
                time.sleep(3)
                if line==contents:
                    isFind=0
                    break
                elif line.strip()=='':
                    print('BlankLine')
                    continue
                else:
                    print(lineNumber)
                    lineNumber+=1
                    print(line=='')
                    time.sleep(3)
            try:
                isFind+=1
            except UnboundLocalError:
                file1.close()
                raise FindError('There is no "%s" in this file'%(str(contents)))
            del lines[lineNumber-1]
            file1.close()
        with open(path,'w',encoding=encoding) as file1:
            for x in lines:
                file1.write(str(x)+'\n')
            file1.close()
    except Exception as e:
        raise e

deleteLinesbyContents('F:\\ll.txt','DEl')

文件内容:

look!
There!
delete!
ready!
This is delete
go!
DEl
DEL
DEl!!!!

运行结果:

Traceback (most recent call last):
  File "G:\AllFunctions\FileProcessing.py", line 174, in <module>
    deleteLinesbyContents('F:\\ll.txt','DEl')
  File "G:\AllFunctions\FileProcessing.py", line 172, in deleteLinesbyContents
    raise e
  File "G:\AllFunctions\FileProcessing.py", line 144, in deleteLinesbyContents
    isFind
UnboundLocalError: local variable 'isFind' referenced before assignment

就这样,不要在意颜色

点赞0


评论


TobylaiTobylai

我也无聊,最近搞了个IDE

贴图:

center_image

点赞0


评论


wrmdcxywrmdcxy

问题已解决,最终代码为:

def deleteLinesbyContents(path,contents,encoding='utf-8'):
	from Errors import FindError
	try:
		with open(path,'r',encoding=encoding) as file1:
			file=''
			for x in file1:
				file+=x
			lines=file.splitlines()
			lineNumber=1
			file1.seek(0,2)
			size=file1.tell()
			file1.seek(0,0)
			sizeNow=file1.tell()
			while sizeNow<size:
				line=(file1.readline()).strip()
				sizeNow=file1.tell()
				if line==contents:
					isFind=0
					break
				elif line.strip()=='':
					continue
				else:
					lineNumber+=1
			try:
				isFind+=1
			except UnboundLocalError:
				file1.close()
				raise FindError('There is no "%s" in this file'%(str(contents)))
			del lines[lineNumber-1]
			file1.close()
		with open(path,'w',encoding=encoding) as file1:
			for x in lines:
				file1.write(str(x)+'\n')
			file1.close()
	except Exception as e:
		raise e

deleteLinesbyContents('F:\\ll.txt','This is delete')

文件内容:

look!
There!
delete!
ready!
This is delete
go!
DEl
DEL
DEl!!!!

运行结果:

[Finished in 0.4s]

运行后文件内容:

look!
There!
delete!
ready!
go!
DEl
DEL
DEl!!!!

点赞0


评论


lsk666666lsk666666

unicode转换程序

点赞0


评论


TobylaiTobylai

帖子好像被顶了起来

点赞0


评论


wrmdcxywrmdcxy

晒日常——点名器开发中

center_image

点赞0


评论


wrmdcxywrmdcxy

日常——FileProcessing包(没错!它正式地成为了一个包!)添加新方法——findValuesByKey!

center_image

点赞0


评论