zoukankan      html  css  js  c++  java
  • COMP9021--6.27

    1. automagic

    IPython中提供了一些以%开头的特殊命令,我们称这些命令为Magic Command。它可以认为是IPython系统中的命令行程序,使用?可以查看其选项。if automagic is on, Magic Command也可以不带百分号直接使用,只要没有定义与其同名的变量就可以,这个技术叫做 automagic ,可以通过 %automagic 打开或关闭。输入%magic可以在IPython中查看相关文档

    %timeit: 测试脚本的运行时间,多次执行以获得代码的平均执行时间

    %lsmagic: 快速获得所有可用魔法函数的列表

    2. import random

    random.randrange ([start,] stop [,step])

    3. sum(iterable[, start])对系列进行求和计算, iterable指可迭代对象,如:列表、元组、集合;start为指定相加的参数,默认值为0

    4. from sys import getsizeof

    可以知道对象占用了多少内存,当我们向列表中append一个元素时,所得到的空间其实多于这一个元素所需要的,所以占用空间的生长曲线会有缓冲区,即append新元素但是不需要腾出新的空间。when we wanna append a range of something,占用空间的生长曲线呈直线增长

    5. os.path 模块主要用于获取文件的属性

    6. Linux ls命令用于显示指定工作目录下之内容

    file_name.exists()退出文件

    os.mkdir() 方法用于以数字权限模式创建目录。默认的模式为八进制(creat a director names with what inside(  ))
    mkdir can not creat once, os.rmdir can help to delete the first one and redo again

    7. when we naming we can not say gender/male in windows, we need to use gender/Path('males),so we need to seperate the name only and the directory

    8. os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表。这个列表以字母顺序。 它不包括 '.' 和'..' 即使它在文件夹中。只支持在 Unix, Windows 下使用。

    for file in os.listdir(names)

    so if we do not wanna pdf:
      if file.endswith('pdf'):

    9. dir(str) get all the funtion names of str

    10. with open(file) as--- or open( file,'w'), in this way, if file exist then open, otherwise create and open it

    11. glob是python自己带的一个文件操作相关模块,用它可以查找符合自己目的的文件,类似于Windows下的文件搜索

    ls yobs* will get all the thins start with yob, so *means 0个或多个字符

    ?代表一个字符

    [3-7]means a range

    12. import csv

    reader=csv.reader(file)

    for row in reader:

    同理用writer可以写入文件,写入的方法是writerow

       

    reference: UNSW Eric Martin

    http://www.ituring.com.cn/book/tupubarticle/19702

    https://www.cnblogs.com/cocowool/p/8119126.html

  • 相关阅读:
    Oracle 查询出来的数据取第一条
    如何将Oracle 当前日期加一天、一分钟
    Oracle 增加修改删除字段
    asp.net,简单权限。存取读XML
    SQL中使用update inner join和delete inner join
    防止浏览器记住用户名及密码的简单实用方法
    vb.net 接口POST方式传参数提交返回值
    导入EXCEL表时,提示"找不到可安装的ISAM"怎么办
    vb.net读取EXCEL
    导入excel错误:外部表不是预期的格式 解决方案
  • 原文地址:https://www.cnblogs.com/eleni/p/11101173.html
Copyright © 2011-2022 走看看