当看到不知道的包时,可以去pypi.org找
比如找easydict https://pypi.org/project/easydict/
Python os.getcwd() 方法
os.getcwd() 方法用于返回当前工作目录。
Python os.listdir() 方法
os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表。
os.path.join()函数:连接两个或更多的路径名组件
1.如果各组件名首字母不包含’/’,则函数会自动加上
2.如果有一个组件是一个绝对路径,则在它之前的所有组件均会被舍弃
3.如果最后一个组件为空,则生成的路径以一个’/’分隔符结尾
torch.FloatTensor
权重衰减(weight decay)与学习率衰减(learning rate decay)
关于for i, data in enumerate(train_loader, 1):中的1的意思
str.format()方法的基本用法如下所示:
>>> print 'We are the {} who say "{}!"'.format('knights', 'Ni')
We are the knights who say "Ni!"
花括号及其中的字符(称为格式字段)将被替换为传递给str.format()方法的对象。括号中的数字指传递给str.format()方法的对象的位置。
>>> print '{0} and {1}'.format('spam', 'eggs')
spam and eggs
>>> print '{1} and {0}'.format('spam', 'eggs')
eggs and spam
Python zfill() 方法返回指定长度的字符串,原字符串右对齐,前面填充0。
zfill()方法语法:
S.zfill(width)
os.path.join()函数:连接两个或更多的路径名组件
1.如果各组件名首字母不包含’/’,则函数会自动加上
2.如果有一个组件是一个绝对路径,则在它之前的所有组件均会被舍弃
3.如果最后一个组件为空,则生成的路径以一个’/’分隔符结尾
Demo1
import os
Path1 = 'home'
Path2 = 'develop'
Path3 = 'code'
Path10 = Path1 + Path2 + Path3
Path20 = os.path.join(Path1,Path2,Path3)
print ('Path10 = ',Path10)
print ('Path20 = ',Path20)
输出
Path10 = homedevelopcode
Path20 = home\develop\code
Demo2
import os
Path1 = '/home'
Path2 = 'develop'
Path3 = 'code'
Path10 = Path1 + Path2 + Path3
Path20 = os.path.join(Path1,Path2,Path3)
print ('Path10 = ',Path10)
print ('Path20 = ',Path20)
输出
Path10 = /homedevelopcode
Path20 = /home\develop\code
os.listdir(path) 返回指定路径下所有文件和文件夹的名字,并存放于一个列表中。