Thonny version 4.1.6
https://thonny.org/
https://github.com/thonny/thonny/releases
安装包的两种方式:
第一钟
第二种:
pip国内源推荐
、
设置python 的版本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | # encoding:utf-8 import sys import io import os import math import pandas # pip3.10 install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple/ import re class Pepole( object ): """ 人 """ def __init__( self ): """ :param name: :param age: """ self ._name = '' #公有属性 self .__age = 0 #私用属性,需要通过(函数)setter,getter 设置和访问 @property # @property装饰getter方法 get ,set 名字相符 def Age( self ): """ :return: """ return self .__age @Age .setter def Age( self ,age): #@方法名.setter 设置 """ :param age: :return: """ if age> 0 : self .__age = age @property def Name( self ): """ """ return self ._name @Name .setter def Name( self ,name): """ """ self ._name = name def modify(filepath, from_, to_): """ edit 全文修改,不是一行修改 :param from_: 源字符 :param to_:修改后的字符 """ file = open (filepath,mode = "r+" ,encoding = "utf-8" ) text = file .read() pattern = from_ splitted_text = re.split(pattern,text) modified_text = to_.join(splitted_text) with open (filepath, mode = 'w' ,encoding = "utf-8" ) as file : file .write(modified_text) def load_record(): """ read data """ f = open ( "data/phonebook.txt" ,mode = "r" ,encoding = "utf-8" ) global record #set global variable record = f.readlines() for i in range ( 0 , len (record)): record[i] = record[i].replace( "\n" ,"") record[i] = record[i].split( "," ) f.close() def print_record(): """ print list """ for i in range ( 0 , len (record)): for j in range ( 0 , len (record)): print (record[i][j],end = "\t" ) print ("") def search_recordByFirstname(firstname): """ search firestname """ for i in range ( 0 , len (record)): for i in range ( 0 , len (record)): #print(record[i][1]) if record[i][ 1 ] = = firstname: return i return - 1 if __name__ = = "__main__" : """ main export """ print ( "hello" ); p = Pepole() p.Name = 'geovindu' p.Age = 20 print (p.Name,p.Age) load_record() print_record() pos = search_recordByFirstname( "Rose" ) print ( 'search:' ) print (pos,record[pos][ 1 ] + ' ' + record[pos][ 2 ]) filename = '1.txt' if os.path.exists( "data/" + filename): #存在追加 with open ( "data/" + filename,mode = "a" ,encoding = "utf-8" ) as f: f.write( '\n2,du,sibo,136555888' ) f.seek( 0 , 0 ) f.close() print ( 'add' ) else : #不存在创建 with open ( "data/" + filename,mode = "w+" ,encoding = "utf-8" ) as f: f.write( 'id,first name,last name,mobile' ) f.write( '\n1,du,geovin,13824350518' ) f.seek( 0 , 0 ) f.close() print ( "create new" ) if os.path.exists( "data/" + filename): with open ( "data/" + filename,mode = "r" ,encoding = "utf-8" ) as f: txt = f.read() print (txt) f.close() with open ( "data/" + filename,mode = "r" ,encoding = "utf-8" ) as f: text = f.read() print ( "Before modification:\n" ,text) f.close() modify( "data/" + filename, "du" , "Du" ) with open ( "data/" + filename,mode = "r" ,encoding = "utf-8" ) as f: text = f.read() print ( "After modification:\n" ,text) f.close() |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2023-09-21 python: Bubble Sort
2023-09-21 python and CSharp: Essential Algorithms
2022-09-21 CSharp: Bridge Pattern
2022-09-21 Java: Immutable Pattern
2016-09-21 csharp: Oracle Stored Procedure DAL using ODP.NET
2014-09-21 Create a soft keyboard
2012-09-21 SQL 生成公曆和農曆對照數據續--创建萬年曆查找各種周期性節日數據