- 博客(27)
- 收藏
- 关注
原创 python中的__str__()和__repr__()
实习代码:>>>p=Pair(3,4)>>>pPair(3,4)>>>print(p)(3,4)>>>p=Pair(3,4)>>>print('p is {0!r}'.format(p))p is Pair(3,4)>>>print('p is
2018-04-06 19:04:18
263
原创 如何用closure实现stack
class Stack2: def __init__(self): self.item=[] def push(self, item): self.item.append(item) def pop(self): return self.items.pop() def __len__(self): return len(sel...
2018-04-03 14:02:48
252
原创 关于python函数
question 1:complete the code:import htmldef make_element(name, value, **attrs): """ """make_element('item', 'Albatross', size='large', quantity=6)# Creats '<item size="large" quantity =...
2018-03-31 21:18:19
203
原创 pyhton IO
#向文件中读取和写入数据with open('cookbook_p142.txt','wt') as f: f.write('text1\n') f.write('text2\n') print('text3',file=f)with open('cookbook_p142.txt','rt') as f: # print(f.read()) # pr...
2018-03-15 17:05:25
162
原创 python3运用*表达式
#第一题records = [ ('foo', 1, 2), ('bar', 'Hello'), ('foo', 3, 4)]def do_foo(x,y): print('foo',x,y)def do_bar(s): print('bar',s)#编写一个for循环,遍历records的元组#对应执行do_foo和do_barf...
2018-03-14 16:30:42
391
原创 python3如何解包一个元组序列字符串文件迭代器
#如何解包一个元组或者数组data = ['ACME',50,91.1,(2012,12,21)]s='Hello'a,b,c,d=data_,_,_,_,e=sprint(a,b,c,d,e)结果ACME 50 91.1 (2012, 12, 21) o
2018-03-14 15:59:13
407
原创 python如何获得文件的元数据
元数据就是文件的大小与修改日期等信息。D:\pythonWork>pythonPython 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more informati...
2018-03-14 08:50:00
4435
原创 如何扁平化处理嵌套的序列 使用和不使用yield from
from collections import Iterableitems = [1,2,[3,4,[5,6],7],8]def flatten(items, ignore_types=(str, bytes)): for i in items: if isinstance(i, Iterable) and not isinstance(i, ignore_types): ...
2018-03-13 09:39:10
223
原创 对象包含在不同的容器,如何迭代
from itertools import chaina = [1,2,3,4]b = ['x','y','z']for x in chain(a, b): print(x)for x in a+b: print(x)
2018-03-13 08:46:09
118
原创 python zip 要迭代的元素在多个不同的序列,如何对其迭代
#the values we want to iterate is in different lists#use zip to pack them from itertools import zip_longestxpts = [1,5,4,2,17]ypts = [101, 78, 37, 15, 62, 99]for x, y in zip(xpts, ypts): temp = ...
2018-03-13 08:41:04
351
原创 python文件IO,练习运用os.path.exists().
tgao@tgao-IdeaPad-U430p:~$ lsDesktop Downloads Music Public TemplatesDocuments examples.desktop Pictures pythonPractice Videostgao@tgao-IdeaPad-U430p:~$ cd pythonPractic...
2018-03-12 09:32:12
13934
原创 python3用写入s = io.StringIO()文本,并取出
import ios = io.StringIO()s.write('Hello World\n')print('this is a test\n', file = s)print(s.getvalue())s = io.StringIO('Hello\nWorld\n')print(s.read(4))print(s.read())输出:Hello Worldthis is a...
2018-03-12 09:01:59
7903
原创 用generator打印前n个素数与这n个素数的和sum,使得sum是大于10000的最小的数
1、用generator2、for i in range(start,end,jump)中jump不能为float类型。如何解决这个问题3、用generator打印前n个素数与这n个素数的和sum,使得sum是大于10000的最小的数import decimaldef is_prime(number): for i in range(2,int(number/2)+1): ...
2018-03-10 15:17:01
247
原创 python数学运算练习
1、产生一个随机数矩阵import randomimport syssys.path.append(r'c:\users\brill\appdata\roaming\python\python36\site-packages')import numpy as npgrid = np.zeros(shape=(1000,1000),dtype=float)print(grid)print...
2018-03-08 09:29:10
465
原创 python数字练习
1、x=1234.5678打印:The value is 1,234.572、x=1234打印转换成2,8,16进制。有无0b的情况3、获得一个无穷小的数。一个nan。如果两个数相等。产生分数1/4和5/4,相加,否则相乘,最后转换为小数。...
2018-03-07 10:28:01
269
转载 解决Vim/Gvim插入模式下backspace按键无法删除字符的问题
去掉有关Vi的一致性模式,避免之前版本的Bug,在命令模式下: set nocompatible 设置backspace的工作方式: set backspace=indent,eol,start
2018-02-20 15:26:45
808
转载 vi/vim中输入方向键有时被转化为A B C D
在某些情况下, vi/vim中的编辑会出现一些很不愉快的情况, 比如在vi/vim中输入方向键有时被转化为A B C D, 或者按个Enter键, 却被转为为其他字母, 恼人得很, 该怎么办呢? 方法如下(在命令行中执行): 1. echo "set nocp" >> ~/.vimrc (千万要注意,是>>, 而不是>, 否则把.vi...
2018-02-20 15:16:12
497
转载 如何在linux创建python虚拟环境
1、大多数系统模块安装在sys.prefix 环境变量指定的目录tgao@tgao-Latitude-E6410:~$ python3Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or "license" for more ...
2018-02-19 23:01:46
1644
转载 在linux中使用apt-get install文件在哪里
举例:在shell中输入:sudo apt install rpm接着执行:dpkg -L rpm显示:/./usr/usr/share/usr/share/doc/usr/share/doc/rpm/usr/share/doc/rpm/buildroot/usr/share/doc/rpm/hregions/usr/share/doc/rpm/macros.gz/usr/share/doc/rp...
2018-02-19 18:18:48
27004
1
转载 如何在ubuntu用sublime配置写python3
Step1:下载sublime(自行搜索)Step2:找到python3安装路径在终端输入:type -a python3显示:python3 is ×××××××Step3:配置sublime打开sublime->Tools->build system->new build system将窗口内容修改为:{ “cmd”:["之前得到的python3安装路径",”-u“,”...
2018-02-17 21:56:12
948
2
转载 ubuntu如何把应用链接到桌面
问题:进入/usr/share/applications 直接拖拽应用到桌面提示没有权限解决办法:在终端键入:sudo nautilus这个命令让你用root权限打开文件管理器接着找到/usr/share/applications选择需要修改的程序,右键,属性,权限,勾选允许以程序执行文件最后把该程序启动器复制到桌面...
2018-02-17 21:46:10
1377
转载 如何安装ubuntu(4)
问题:如何用shell安装chrome解决办法:输入:cd /tmdwget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.debsudo dpkg -i google-chrome*;sudo apt-get -f install然后在unity dash中搜索chrome即可使用...
2018-02-17 19:04:18
452
转载 如何安装ubuntu(3)
问题:如何安装搜狗输入法解决办法:Step1:https://pinyin.sogou.com/linux/到上述链接下载对应版本Step2:至终端,输入:cd ~/Downloads/Step3:执行:sudo dpkg -i sogoupinyin_2.1.0.0002_amd64.debStep4:在System settings中找到Language supportStep5:把langu...
2018-02-17 18:58:25
661
转载 整理如何安装ubuntu(2)
问题: 安装ubuntu搜索不到wifi信号原因:没有安装网卡驱动(吐槽:那种sudo update,sudo install,或者让下载驱动的答案。。让人非常无语。。这不是连不上网嘛)解决办法: Step1:想办法把iso拷贝到ubuntu系统任意磁盘,eg:mkdir /tempStep2:把该iso解压缩Step3:找到ubuntu-16.04-desktop-ad64->pool-&...
2018-02-17 18:42:37
211
转载 整理如何安装ubuntu系统(1)
具体教程自己搜索。注意点:1、如果用u盘,用16g以下的。一来避免浪费。二来可以用FAT32格式化(如果不使用FAT32或者FAT,写入硬盘映像会有麻烦)。2、用u盘刻盘iso,教程自己找。该刻盘iso的u盘为u盘1,最好准备一个u盘2,里面保存有iso映像。u盘2的用处,在后续整理...
2018-02-17 18:10:38
175
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人