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

  • 相关阅读:
    LeetCode 485. Max Consecutive Ones
    LeetCode 367. Valid Perfect Square
    LeetCode 375. Guess Number Higher or Lower II
    LeetCode 374. Guess Number Higher or Lower
    LeetCode Word Pattern II
    LeetCode Arranging Coins
    LeetCode 422. Valid Word Square
    Session 共享
    java NIO
    非阻塞IO
  • 原文地址:https://www.cnblogs.com/eleni/p/11101173.html
Copyright © 2011-2022 走看看