06 2017 档案
摘要:I think all of the answers here cover the core of what the lambda function does in the context of sorted() quite nicely, however I still feel like a d
阅读全文
摘要:I think all of the answers here cover the core of what the lambda function does in the context of sorted() quite nicely, however...
阅读全文
摘要:声明动态数组 ArrayList objectArray = new ArrayList(); 添加数组元素 objectName.add(new ClassName()); 提前设定数组大小 如果提前知道或预测到数组大小,可以使用ensure...
阅读全文
摘要:声明动态数组 添加数组元素 提前设定数组大小 如果提前知道或预测到数组大小,可以使用 : 这样在添加前 100 个元素不会触发动态数组重新分配数组大小的功能(节省内存时间), 但这个数组仍然是动态的 ,可以包含不止100个元素。 返回数组大小 注意和普通数组的 区分。 固定数组大小 如果确定当前数组
阅读全文
摘要:`src New Package`
阅读全文
摘要:src->New->Package
阅读全文
摘要:Calling Another Constructor if the first statement of a constructor has the form this(...), then the constructor calls another ...
阅读全文
摘要:Calling Another Constructor if _the first statement of a constructor_ has the form , then the constructor calls another constructor of the same class.
阅读全文
摘要:If a class supplies at least one constructor but does not supply a no argument constructor, it is illegal to construct objects without supplying argum
阅读全文
摘要:If a class supplies at least one constructor but does not supply a no-argument constructor, it is illegal to construct objects w...
阅读全文
摘要:Instead, object references are passed by value! A method cannot modify a parameter of a primitive type.A method can change the ...
阅读全文
摘要:Instead, object references are passed by value ! A method cannot modify a parameter of a primitive type. A method can change the state of an object pa
阅读全文
摘要:Every class can have a main method. That is a handy trick for unit testing of classes. For example, you can add a main method to the Employee class: _
阅读全文
摘要:Every class can have a main method. That is a handy trick for unit testing of classes. For example, you can add a main method to...
阅读全文
摘要:The main Method You can call static methods without having any objects. For example, you never construct any objects of the Mat...
阅读全文
摘要:The main Method You can call static methods without having any objects. For example, you never construct any objects of the Math class to call Math.po
阅读全文
摘要:The static factory method pattern is a way to encapsulate object creation. Without a factory method, you would simply call the class's constructor dir
阅读全文
摘要:The static factory method pattern is a way to encapsulate object creation. Without a factory method, you would simply call the c...
阅读全文
摘要:If you define a field as static, then there is only one such field per class. In contrast, each object has its own copy of al...
阅读全文
摘要:If you define a field as static , then there is only one such field per class. In contrast, each object has its own copy of all instance fields. For e
阅读全文
摘要:` a`, append Add the user to the supplementary group(s). Use only with the G option. , groups GROUP1[,GROUP2,...[,GROUPN]]] A list of supplementary gr
阅读全文
摘要:-a, --append Add the user to the supplementary group(s). Use only with the -G option. -G, --groups GROUP1[,GROUP2,...[,G...
阅读全文
摘要:import java.util.*;public class BookTest{ public static void main(String[] args) { //Book book = new Book("A Tale of Two Cities...
阅读全文
摘要:```
import java.util.*; public class BookTest
{ public static void main(String[] args) { //Book book = new Book("A Tale of Two Cities", 1895); Book book = new Book("A Tale of Two Cities"); Sy...
阅读全文
摘要:http://www.javaworld.com/article/2979739/learn java/java 101 classes and objects in java.html?page=3 This example declares a count integer field that
阅读全文
摘要:http://www.javaworld.com/article/2979739/learn-java/java-101-classes-and-objects-in-java.html?page=3 class Book{ // ... ...
阅读全文
摘要:public class multiarraysExample1{ public static void main(String[] args) { int[][] magicSquare = { {16,3,2,13}, {5,10,1...
阅读全文
摘要:``` public class multiarraysExample1 { public static void main(String[] args) { int[][] magicSquare = { {16,3,2,13}, {5,10,11,8}, {9,6,7,12 }, {4,15,1
阅读全文
摘要:public class Understand_String_args{ public static void main(String[] args) { System.out.printf("args[0] = %s\n", args[0]); Sy...
阅读全文
摘要:Do NOT use the `==`` operator to test whether two strings are equal! It only determines whether or not the strings are stored in...
阅读全文
摘要:Do _NOT_ use the operator to test whether two strings are equal! It only determines whether or not the strings are stored in the same location. Sure,
阅读全文
摘要:Array Initialization = `a[]`的值会被初始化为0 `int[] smallPrimes = {2, 3, 5, 7, 11, 13}; 在不新建数组的情况下重新初始化一个数组变量 Array Copying
阅读全文
摘要:Array Initialization int[] a; = int a[]; int[] a = new int[100]; a[]的值会被初始化为0 `int[] smallPrimes = {2, 3, 5, 7, 11, 13}; new...
阅读全文
摘要:
阅读全文
摘要:
阅读全文
摘要:
阅读全文
摘要:
阅读全文
摘要:add PPA sudo add-apt-repository ppa:jonathonf/vim Update and Install sudo apt-get updatesudo apt-get instrall vim ...
阅读全文
摘要:add PPA Update and Install
阅读全文
摘要:```
:set number
``` ```
:set nonumber
```
阅读全文
摘要:myarray = <- array (vector, dimensions, dimnames) 例如,生成一个2*3*4的数组: dim1 <- c("A1","A2")dim2 <- c("B1","B2","B3")dim3 <- c("C1"...
阅读全文
摘要:mymatrix <- matrix(vector, nrow=number_of_rows, ncol=number_of_columns,byrow=logical_value,dimnames=list(char_vector_rownames,ch...
阅读全文
摘要:http://landoflinux.com/linux_usermod_command.html Append Additional Groups to an exiting account usermod -a -G group1,gro...
阅读全文
摘要:http://landoflinux.com/linux_usermod_command.html Append Additional Groups to an exiting account Change a Users Home Directory Change a Users Default
阅读全文
摘要:SSH -N -p port -D 7070 username@server
阅读全文
摘要:SSH N p port D 7070 username@server
阅读全文
摘要:https://atech.blog/viaduct/mysql indexes primer What are Indexes? Every time your web application runs a database query containing a WHERE statement,
阅读全文
摘要:https://atech.blog/viaduct/mysql-indexes-primer What are Indexes? Every time your web application runs a database query c...
阅读全文
摘要:http://www.python-course.eu/ https://www.tecmint.com/35-practical-examples-of-linux-find-command/ https://onlinec...
阅读全文
摘要:http://www.python-course.eu/python3_properties.php Our new class means breaking the interface. The attribute x is not avai...
阅读全文
摘要:http://www.python course.eu/python3_properties.php Our new class means breaking the interface. The attribute x is not available anymore. That's why in
阅读全文
摘要:Variables can be private which can be useful on many occasions. A private variable can only be changed within a class method and not outside of the cl
阅读全文
摘要:Variables can be private which can be useful on many occasions. A private variable can only be changed within a class method ...
阅读全文
摘要:class Liar(list): def __len__(self): return super().__len__() + 3 # 直接写 super().__len__() 而没有 return 不会返回 length ...
阅读全文
摘要:```
class Liar(list): def __len__(self): return super().__len__() + 3 # 直接写 super().__len__() 而没有 return 不会返回 length ! a = Liar(['a','b'])
```
阅读全文
摘要:先来看一段代码: 输出结果: 1. 执行的顺序是先 后`__init__ __new__ __init__ __init__`中的 _self_ 。 再来看一段代码: 输出结果: 这里 并没有被调用。这是因为与之前不同,这次 _override_ 了父类的 之后,没有使用 继承父类其他创建 _ins
阅读全文
摘要:先来看一段代码: class A(object): # -> don't forget the object specified as base def __new__(cls): print ("A. __new__ called...
阅读全文
摘要:class NumString: def __init__(self, value): self.value = str(value) def __str__(self): return self.value ...
阅读全文
摘要:```
class NumString: def __init__(self, value): self.value = str(value) def __str__(self): return self.value def __int__(self): return int(self.value) def _...
阅读全文
摘要:先来看一段代码: class First(object): def __init__(self): print ("first")class Second(object): def __init__(self): ...
阅读全文
摘要:先来看一段代码: 这段代码的输出结果是: 也就是说,在 中的 override了父类(classes: First, Second, Third, Forth)的 。 输出结果是: 也就是说, 先继承了父类 _First_ 的 ,然后执行自己重新定义的 。 如果在所有父类中也使用 ,事情变得有趣:
阅读全文
摘要:An Easy Introduction to CUDA C and C++ This post is the first in a series on CUDA C and C++, which is the C/C++ interface to the CUDA parallel computi
阅读全文
摘要:An Easy Introduction to CUDA C and C++ This post is the first in a series on CUDA C and C++, which is the C/C++ interface to th...
阅读全文
摘要:class Inventory: def __init__(self): self.slots = [] def add_item(self, item): self.slots.append(item)class ...
阅读全文
摘要:```
class Inventory: def __init__(self): self.slots = [] def add_item(self, item): self.slots.append(item) class SortedInventory(Inventory): def add_item(self, item): ...
阅读全文
摘要:This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value. The string may name an existing attribute or a new
阅读全文
摘要:This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value. The string may name an exist...
阅读全文
摘要:def test_var_args(f_arg, *argv): print("first normal arg:", f_arg) for arg in argv: print("another arg through *arg...
阅读全文
摘要:```
def test_var_args(f_arg, *argv): print("first normal arg:", f_arg) for arg in argv: print("another arg through *argv:", arg) test_var_args('yasoob', 'python', 'eggs', 'test')
```
...
阅读全文
摘要:if end1 <= val <= end2 or end2 <= val <= end1: return Trueelse: return False 等于 return end1 <= val <= end2 or end2 <= va...
阅读全文
摘要:apt-get install r-base r-base-dev
阅读全文
摘要:```
apt-get install r-base r-base-dev
```
阅读全文
摘要:Find the unique elements of an array. Returns the sorted unique elements of an array. There are three optional outputs in addition to the unique eleme
阅读全文
摘要:Find the unique elements of an array. Returns the sorted unique elements of an array. There are three optional outputs in add...
阅读全文
摘要:>>> a = np.arange(6).reshape((3, 2))>>> aarray([[0, 1], [2, 3], [4, 5]]) >>> np.reshape(a, (2, 3)) # C-like index o...
阅读全文
摘要:One shape dimension can be 1. In this case, the value is inferred from the length of the array and remaining dimensions.
阅读全文
摘要:conda install anaconda-cleananaconda-clean --yes Anaconda 安装的时候在 .bash_profile中添加了变量: export PATH="/Users/jsmith/anaconda3/bin...
阅读全文
摘要:创建环境 conda create --name bunnies python=3 astroid babel 列出所有环境 conda info --envs 或 conda env list 克隆环境 conda create --nam...
阅读全文
摘要:Plotting numpy arrays as images Colormap 加上 相当于颜色 _reverse_ 。
阅读全文
摘要:import matplotlib.pyplot as pltplt.imshow(digits.images[-1], cmap = plt.cm.gray_r) .imshow() Plotting numpy arrays as image...
阅读全文
摘要:import matplotlib.pyplot as plt 绘制好图像之后,需要使用plt.show()才会显示出图片。
阅读全文
摘要:!!!_Anaconda_ 和 _Jupyter Notebook_ 在 _zsh_ 环境下不能正常使用! 启动建立的 Anaconda 环境 安装 :`conda install nb_conda` 在该环境下的 _Terminal_ 中启动 _Jupyter Notebook_ : _ Jupy
阅读全文
摘要:!!!Anaconda 和 Jupyter Notebook 在 zsh 环境下不能正常使用! 启动建立的 Anaconda 环境安装 nb_conda:conda install nb_conda在该环境下的 Terminal 中启动 Jupyter ...
阅读全文
摘要:```
>>> ",".join(["a", "b", "c"])
'a,b,c'
```
阅读全文
摘要:```
# import itertools
#
# my_list = [1, 2, 3, 4, 5, 6]
#
# combinations = itertools.combinations(my_list, 3)
# permutations = itertools.permutations(my_list, 3) import itertools word = 'sample'
my_...
阅读全文
摘要:# import itertools## my_list = [1, 2, 3, 4, 5, 6]## combinations = itertools.combinations(my_list, 3)# permutations = itertools....
阅读全文
摘要:import timeef_cache = {}def expensive_func(num): if num in ef_cache: return ef_cache[num] print ("Computing {}..."....
阅读全文
摘要:```
import time ef_cache = {} def expensive_func(num): if num in ef_cache: return ef_cache[num] print ("Computing {}...".format(num)) time.sleep(1) result = num*num ef_c...
阅读全文
摘要:``` employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam'] output = '\n' for employee in employees: output += '\t{}>/li>\n'.format(employee) print ('Address of output is {}'.format(i...
阅读全文
摘要:employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam']output = '\n'for employee in employees: output += '\t{}>/li>\n'...
阅读全文
摘要:import sqlite3from employee import Employeeconn = sqlite3.connect(':memory:') #for testingc = conn.cursor()c.execute("""CREATE T...
阅读全文
摘要:```
import sqlite3
from employee import Employee conn = sqlite3.connect(':memory:') #for testing c = conn.cursor() c.execute("""CREATE TABLE employees( first text, last tex...
阅读全文
摘要:file settings colors&fonts save as (save the current scheme as your own) font change size
阅读全文
摘要:file->settings->colors&fonts-> save as (save the current scheme as your own)-> font- >change size
阅读全文
摘要:{"shell_cmd" : "gcc $file_name -o ${file_base_name}","working_dir" : "$file_path","variants": [ { "name": "Run", "...
阅读全文
摘要:保存为`~/.config/sublime text 3/Packages/User/GCC.sublime build`
阅读全文
摘要:https://stackoverflow.com/a/2588667/8189120 In short, it sets free magical ponies. In long, Python 2.2 and earlier used "old style classes". They were
阅读全文
摘要:https://stackoverflow.com/a/2588667/8189120 In short, it sets free magical ponies. In long, Python 2.2 and earlier used "old...
阅读全文
摘要:编译语言一边执行每条语言一边翻译程序,而编译语言一次性将整个程序翻译成机器语言。 解释语言不生成中间文件,编译语言会生成中间文件。 解释语言会持续翻译程序直到遇到第一个错误,编译语言在检查完整段程序之后才会输出错误。 编译语言一次编译之后可以被重复...
阅读全文
摘要:编译语言一边执行每条语言一边翻译程序,而编译语言一次性将整个程序翻译成机器语言。 解释语言不生成中间文件,编译语言会生成中间文件。 解释语言会持续翻译程序直到遇到第一个错误,编译语言在检查完整段程序之后才会输出错误。 编译语言一次编译之后可以被重复执行,解释语言每次运行都要重新翻译源程序。 条件控制
阅读全文
摘要:第一阶段 使用编辑器编写的源代码 (.txt) 文件 _hello.c_。经过 _Pre processor_ 进行前处理。在前处理阶段,当 _pre processor_ 读到代码中的 时,会读取头文件 ,并将其直接插入源代码中。最后得到经过修改后的源代码文件 _hello.i_。 第二阶段 编译
阅读全文
摘要:第一阶段 使用编辑器编写的源代码 (.txt) 文件 hello.c。经过 Pre-processor 进行前处理。在前处理阶段,当 pre-processor 读到代码中的#include时,会读取头文件stdio.h,并将其直接插入源代码中。最后得到...
阅读全文
摘要:假设有这么一个 _class_ 现在要把一个字符串 _11 09 2012_ 作为变量,方法一: 但是每次初始化一个 _class_ 的 _instance_ 都要重复操作一次。所以,方法二: 和`classmethod`类似,区别在于不接收变量。例如在 _class_ 加入一个判断: @stati
阅读全文
摘要:假设有这么一个 class class Date(object): def __init__(self, day=0, month=0, year=0): self.day = day self.month = mont...
阅读全文
摘要:There will be a file named uninstall.sh in /usr/local/netbeans-x.x if you installed netbeans with root privilege. If you inst...
阅读全文
摘要:There will be a file named uninstall.sh in /usr/local/netbeans x.x if you installed netbeans with root privilege. If you installed it with a normal us
阅读全文
摘要:A Python decorator is a specific change to the Python syntax that allows us to more conveniently alter functions and methods (and possibly classes in
阅读全文
摘要:A Python decorator is a specific change to the Python syntax that allows us to more conveniently alter functions and methods ...
阅读全文
摘要:def logger(msg): def log_message(): print('Log:', msg) return log_message # 返回的是函数log_hi = logger('Hi!') # 此时`log_h...
阅读全文
摘要:``` def logger(msg): def log_message(): print('Log:', msg) return log_message 返回的是函数 log_hi = logger('Hi!') 此时 相当于 ,`Hi msg` log_hi() def html_tag(tag
阅读全文
摘要:和`sort()` 输出结果: Sorted Variable: [1, 2, 3, 4, 5, 6, 7, 8, 9] Original Variable: [1, 2, 3, 4, 5, 6, 7, 8, 9] 如果: 输出的结果是: None _Tuple_ 不能使用 ,只能定义一个新的变量
阅读全文
摘要:sorted和sort() li = [9, 1, 8, 2, 7, 3, 6, 4, 5]s_li = sorted(li)print ('Sorted Variable: \t', s_li)li.sort()print ('Original Var...
阅读全文
摘要:def outer(): x = 'outer x' def inner(): x = 'inner x' print(x) inner() print(x) # 这里的`x`与`x = 'outer x...
阅读全文
摘要:``` def outer(): x = 'outer x' def inner(): x = 'inner x' print(x) inner() print(x) 这里的 与`x = 'outer x'`处在同一个Enclosing outer() 运行结果: inner x outer x 使
阅读全文
摘要:使用 到Github网站的时候提示: push declined due to email privacy restrictions 原因 在Github设置里有一个隐私选项 Block command line pushes that expose my email 所以如果本地的 里email地
阅读全文
摘要:使用git push到Github网站的时候提示: push declined due to email privacy restrictions 原因 在Github设置里有一个隐私选项 Block command line pu...
阅读全文
摘要:假设目录下面有这样一系列命令杂乱的文件: OPENFOAM -TRAINING- PART- #1.pdf OPENFOAM - TRAINING- PART- #2.pdf OPENFOAM- TRAINING- PART-#3 .pdf 不仅序...
阅读全文
摘要:假设目录下面有这样一系列命令杂乱的文件: OPENFOAM TRAINING PART 1.pdf OPENFOAM TRAINING PART 2.pdf OPENFOAM TRAINING PART 3 .pdf 不仅序号被放在最后,而且还有许多多余的空格。现在批量将这些文件重命名,去掉 ,并把
阅读全文
摘要:``` print(os.environ.get('HOME')) 打印 这个环境变量 file_path = os.environ.get('HOME') + '/text.txt' 拼贴文件路经,注意不要漏掉 print(file_path) file_path = os.path.join(o
阅读全文
摘要:print(os.environ.get('HOME')) # 打印`HOME`这个环境变量 /Users/ file_path = os.environ.get('HOME') + '/text.txt' # 拼贴文件路经,注意不要漏掉`/...
阅读全文
摘要:import os print(os.stat('my_module.py')) 输出: os.stat_result(st_mode=33188, st_ino=7348222, st_dev=16777220, st_nlink=1, st_...
阅读全文
摘要:输出: os.stat_result(st_mode=33188, st_ino=7348222, st_dev=16777220, st_nlink=1, st_uid=501, st_gid=20, st_size=198, st_atime=1497418897, st_mtime=14974
阅读全文
摘要:```
import os os.rename('original_name.txt','new_name.txt')
```
阅读全文
摘要:import osos.rename('original_name.txt','new_name.txt')
阅读全文
摘要:import osos.rmdir('OS-Demo-2')os.removedirs('OS-Demo-3/sub-Dir-1') os.removedirs()会自动将上一级文件夹也删除,谨慎使用!
阅读全文
摘要:和`os.makedirs() os.makedirs()`能 自动创建上一级文件夹 ,如果不存在的话。
阅读全文
摘要:import osos.mkdir('OS-Demo-2')os.makedirs('OS-Demo-3/sub-Dir-1') os.mkdir()和os.makedirs()都可以新建文件夹,区别在于,os.makedirs()能自动创建上一级文件...
阅读全文
摘要:import osprint(os.getcwd()) # 打印当前工作目录os.chdir('/Users//Desktop/') # 将当前工作目录改变为`/Users//Desktop/` 以 list 的形式列出当前目录下的文件和目录 prin...
阅读全文
摘要:``` import os print(os.getcwd()) 打印当前工作目录 os.chdir('/Users//Desktop/') 将当前工作目录改变为 print(os.listdir()) ```
阅读全文
摘要:打开macOS的 文件夹: 双击其中的 : 把下载的字体解压后的_文件夹_ 拖进来,字体就安装好了。
阅读全文
摘要:打开macOS的Applications文件夹: 双击其中的Font Book: 把下载的字体解压后的_文件夹_ 拖进来,字体就安装好了。
阅读全文
摘要:Command+Shift+3: 全屏幕截屏,并自动保存在桌面 Command+Shift+4: 手动截屏,并自动保存在桌面 Command+Shift+4, + Space, 之后点击程序的窗口,实现窗口截屏,并自动保存在桌面。 上面所有命令如...
阅读全文
摘要:+`Shift 3`: 全屏幕截屏,并自动保存在桌面 +`Shift 4`: 手动截屏,并自动保存在桌面 +`Shift 4`, + , 之后点击程序的窗口,实现窗口截屏,并自动保存在桌面。 上面所有命令如果加上 键,截屏将保存在剪切板而不是以文件的形式保存在桌面。
阅读全文
摘要:The simplest explanation for the variable (imho) is the following: Create the following files. Running them will get you this output: As you can see,
阅读全文
摘要:The simplest explanation for the __name__ variable (imho) is the following: Create the following files. # a.pyimport b # b.py...
阅读全文
摘要:Mounty for Mac brew cask install mounty
阅读全文
摘要:```
"""
import my_module as mm courses = ['History','Math','Physics','CompSci'] index = mm.find_index(courses, 'Math')
print (index)
""" """
from my_module import find_index courses = ['History','...
阅读全文
摘要:"""import my_module as mmcourses = ['History','Math','Physics','CompSci']index = mm.find_index(courses, 'Math')print (index)""""...
阅读全文
摘要:继承 class Character(object): def __init__(self, name): self.health = 100 self.name = name def printName(self...
阅读全文
摘要:命令 systemctl list units 列出所有jobs/serviceList all units (where unit is the term for a job/service) systemctl start [NAME...] 启动 systemctl stop [NAME...
阅读全文
摘要:systemctl命令 systemctl list-units - 列出所有jobs/serviceList all units (where unit is the term for a job/service)systemctl start ...
阅读全文
摘要:Finally, we'll want a way to test whether a file we've opened is closed. Sometimes we'll have a lot of file objects open, and if...
阅读全文
摘要:Finally, we'll want a way to test whether a file we've opened is closed. Sometimes we'll have a lot of file objects open, and if we're not careful, th
阅读全文
摘要:Programming is all about getting the computer to do the work. Is there a way to get Python to automatically close our files for us? Of course there is
阅读全文
摘要:Programming is all about getting the computer to do the work. Is there a way to get Python to automatically close our files for ...
阅读全文
摘要:We keep telling you that you always need to close your files after you're done writing to them. Here's why! During the I/O proc...
阅读全文
摘要:We keep telling you that you always need to close your files after you're done writing to them. Here's why! During the I/O process, data is buffered:
阅读全文
摘要:====== rstrip ====== Description Returns a copy of the string with trailing characters removed. Syntax str . rstrip([chars]) chars Optional. String sp
阅读全文
摘要:====== rstrip Description Returns a copy of the string with trailing characters removed. Syntax str. rstrip([chars]) chars ...
阅读全文
摘要:这几天研究了一下OpenFOAM里的MapFields和并行计算,总结一下。 Case 1 先进行并行计算 SetFields 初始化流场decomposePar 把初始化好的流场分块mpirun -np N Solver -parallelrecon...
阅读全文
摘要:这几天研究了一下OpenFOAM里的 和并行计算,总结一下。 Case 1 先进行并行计算 1. 初始化流场 2. 把初始化好的流场分块 3. 4. 把并行计算的结果拼接 Case 2 导入 Case 1 的计算结果 1. 导入 Case 1 计算好的结果(默认好像是自动导入最后一个计算步) 2.
阅读全文
摘要:假设自己写的 _class_ 文件 放在当前目录的子目录 下,在 中定义了一个 _class_ 叫 。现在要调用 这个 _class_ : : class Pet(object): ''' object is a special variable in Python that you should
阅读全文
摘要:假设自己写的 class 文件myPets.py放在当前目录的子目录/myClasses下,在myPets.py中定义了一个 class 叫Pet。现在要调用Pet这个 class : from myClasses.myPets import Petgi...
阅读全文
摘要:Ubuntu的图形界面容易死机,如果正在跑程序的话又不能重启。这时候可以通过终端来_重启_图形界面。 首先按Alt+Ctrl+F1进入终端界面。查看图形界面的进程: ps -t tty7 查看到名为Xorg的进程,记下前面的PID,然后: kill...
阅读全文
摘要:Ubuntu的图形界面容易死机,如果正在跑程序的话又不能重启。这时候可以通过终端来_ 重启 _图形界面。 首先按 +`Ctrl F1`进入终端界面。查看图形界面的进程: 查看到名为Xorg的进程,记下前面的PID,然后: 这时候图形界面的进程就被杀掉了。系统会自动重启这个图形界面进程,这时候按 +`
阅读全文
摘要:+`Alt F1`可以从图形界面切换到终端界面。 +`Alt F7`可以从终端界面退出来,重新回到图形界面
阅读全文
摘要:直接下载deb包安装失败,具体原因不明。通过官网提供的添加repository的方式安装成功: 之后, 就可以安装成功了。
阅读全文
摘要:直接下载deb包安装失败,具体原因不明。通过官网提供的添加repository的方式安装成功: curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > micros...
阅读全文
摘要:Ctrl+Alt+F1可以从图形界面切换到终端界面。Ctrl+Alt+F7可以从终端界面退出来,重新回到图形界面
阅读全文
摘要:如果有一个文件夹目录很深/home/user/aaa/bbb/ccc/ddd/eee/fff/ggg,但是经常要跳转到这个文件夹。一个简单的办法就是给这个文件夹建立一个类似$PATH那样的环境变量,如$mydir,这样只要在终端输入cd $mydir就会快...
阅读全文
摘要:为了提高效率,减少使用鼠标,有时候想直接通过终端的命令打开一个图片进行查看。可以使用的命令有: eog filenamedisplay filename 再使用Alt+F4就可以关闭窗口,尽量达到手不离键盘。
阅读全文
摘要:为了提高效率,减少使用鼠标,有时候想直接通过终端的命令打开一个图片进行查看。可以使用的命令有: 再使用 就可以关闭窗口,尽量达到手不离键盘。
阅读全文
摘要:import time as tfrom os import pathdef createFile(dest): date = t.localtime(t.time()) name = '%d_%d_%d.txt' %(date[1],date...
阅读全文
摘要:查看当前目录下所要创建的 文件是否已经存在,如果不存在就创建,并写入30个换行( ) 要点: 所要读写的文件名可以是_变量_
阅读全文
摘要:基本用法: Dictionary 使用 不能返回一个list,需要使用 或`sorted(D)`,会返回 Dictionary 的 keys,并存入 list。
阅读全文
摘要:基本用法: .keys.values.items >>> D = dict(a=1,b=2,c=3)>>> D{'a': 1, 'b': 2, 'c': 3}>>> D.keys>>> D.keys()dict_keys(['a', 'b', 'c']...
阅读全文
摘要:range 不是 iterator >>> R = range(3)>>> next(R)Traceback (most recent call last): File "", line 1, in TypeError: 'range' object ...
阅读全文
摘要:1. _range_ 不是 iterator 2. _range_ 允许 multiple iterators,并且能记住每个iterator的位置。 ,`map filter`都不允许 multiple iterators。它们的 iter 就是它们本身,因为不需要专门使用 iter 函数。
阅读全文
摘要:要注意 _zip_ 也是_one pass iterator !被遍历一次之后会自动_消失_。 zip类型支持list,next等:
阅读全文
摘要:>>> z = zip((2,3,4),(33,44,55))>>> z>>> list(z)[(2, 33), (3, 44), (4, 55)] 要注意 ** zip 也是_one-pass iterator** !被遍历一次之后会自动_消失_。 ...
阅读全文
摘要:Ctrl + a – go to the start of the command line Ctrl + e – go to the end of the command line Ctrl + k – delete from cursor to ...
阅读全文
摘要:Ctrl + a – go to the start of the command line Ctrl + e – go to the end of the command line Ctrl + k – delete from cursor to the end of the command li
阅读全文
摘要:Map map(function_to_apply, list_of_inputs) 设有以下代码: 这段代码实现的功能用map函数可以两行完成: 高级一点地,可以用一列函数作为输入: Filter _Filter_ creates a list of elements for which a fu
阅读全文
摘要:Map map(function_to_apply, list_of_inputs) 设有以下代码: >>> items = [1, 2, 3, 4, 5]>>> squared = []>>> for i in items:... s...
阅读全文
摘要:在list comprehension中加入if条件判断: >>> lines = [line.rstrip() for line in open('script2.py') if line[0] == 'p']>>> lines['print(sys....
阅读全文
摘要:在list comprehension中加入if条件判断: 这段代码相当于: 在list comprehension中加入嵌套循环: 这段代码相当于:
阅读全文
摘要:list comprehension使代码变得简洁。下面这种常用的方法则显得过时: 事实上在使用list comprehension时,代码内部相当于执行下面操作: 在可以的使用的地方尽可能使用list comprehension,是一种地道的Python写法。另外,相比 循环, list comp
阅读全文
摘要:>>> L = [1,2,3,4,5]>>> L = [x+10 for x in L]>>> L[11, 12, 13, 14, 15] list comprehension使代码变得简洁。下面这种常用的方法则显得过时: >>> L = [1,2,3...
阅读全文
摘要:>>> E=enumerate('spam')>>> E>>> I=iter(E)>>> next(I)(0, 's')>>> next(I)(1, 'p')>>> list(enumerate('spam'))[(0, 's'), (1, 'p'), (...
阅读全文
摘要:和`iter(f)`类型相同,因为file object是它自身的iterator。 ` f.__next__() 'import sys\n' ` list则不是它自身的iterator,所以不能直接使用 ,必须使用一次 函数:
阅读全文
摘要:>>> f=open('script2.py')>>> f>>> iter(f) f和iter(f)类型相同,因为file object是它自身的iterator。 ` f.next() 'import sys\n' ` ...
阅读全文
摘要:>>> for line in open('script2.py'):... print(line.upper())... IMPORT SYSPRINT(SYS.PATH)X = 2PRINT(X ** 32) >>> for line in op...
阅读全文
摘要:由于line strings每行本身都有 ,而 函数又会自动添加 ,所以加入参数 来suppress。
阅读全文