This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(){ | |
FILE * fp; | |
char ch; | |
char str[10]; | |
if((fp = fopen("test.csv", "r"))==NULL){ | |
printf("文件打开失败!\n"); | |
exit(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
for filenames in os.listdir(): | |
if filenames.endwith('png'): | |
os.rename(filename, filename[:-3]+'jpg') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('OceanCoder_SNSD_P2 (5).jpg', 'rb') as f: | |
pic1 = f.read() | |
for i in range(1000): | |
with open('1'+str(i), 'wb') as f: | |
f.write(pic1) | |
with open('OceanCoder_SNSD_P2 (133).jpg', 'rb') as f: | |
pic2 = f.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 日志模块,带滚动策略 | |
def create_logger(): | |
if not os.path.exists('./log/'): | |
os.makedirs('./log/') | |
# 日志文件 | |
rotateHandler=RotatingFileHandler('./log/log.log', maxBytes=100*1024*1024, backupCount=2) # 单个文件100M | |
rotateHandler.setLevel(logging.INFO) | |
rotateHandler.setFormatter(logging.Formatter("%(asctime)s %(filename)s [line:%(lineno)d] [%(levelname)s'] %(message)s")) | |
# 屏幕输出 | |
consoleHandler=logging.StreamHandler() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 生成时间戳 | |
def get_timestamp(string, mode=1): | |
if mode==1: | |
return int(time.mktime(time.strptime(string,"%Y%m%d"))) | |
elif mode==2: | |
return int(time.mktime(time.strptime(string,'%Y-%m-%d %H:%M:%S'))) | |
# 时间戳转换为日期 mode1:‘年月日’,mode2:'年-月-日 小时:分钟:秒' | |
def get_dateString(timestamp,mode=1): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dict | |
def greet_me(**kwargs): | |
for key, value in kwargs.items(): | |
print("{0} = {1}".format(key, value)) | |
# list | |
def test_var_args(f_arg, *argv): | |
print("first normal arg:", f_arg) | |
for arg in argv: | |
print("another arg through *argv:", arg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# join strings | |
letters = ['h', 'e', 'l', 'l', 'o'] | |
''.join(letters) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# filter in a list | |
a = next((i for i in range(1, 10) if not i % 4), -1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace too many == | |
foo = 'bar' | |
if foo in ('bar1', 'bar2', 'bar3'): | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PY2 = sys.version_info[0] == 2 | |
if PY2: | |
text_type = unicode | |
string_types = (unicode, str) | |
from cStringIO import StringIO as NativeBytesIO | |
else: | |
text_type = str | |
string_types = (str,) | |
from io import BytesIO as NativeBytesIO |
NewerOlder