惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
V
V2EX
T
Tailwind CSS Blog
N
News | PayPal Newsroom
The Cloudflare Blog
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
C
Cyber Attacks, Cyber Crime and Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
V
Vulnerabilities – Threatpost
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Threat Research - Cisco Blogs
云风的 BLOG
云风的 BLOG
阮一峰的网络日志
阮一峰的网络日志
T
Threatpost
U
Unit 42
T
The Exploit Database - CXSecurity.com
I
Intezer
爱范儿
爱范儿
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - Franky
Spread Privacy
Spread Privacy
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News and Events Feed by Topic
Google Online Security Blog
Google Online Security Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recorded Future
Recorded Future
The Register - Security
The Register - Security
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
H
Help Net Security
Schneier on Security
Schneier on Security
P
Proofpoint News Feed
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
K
Kaspersky official blog
C
Check Point Blog
小众软件
小众软件
A
About on SuperTechFans
博客园 - 【当耐特】
IT之家
IT之家

博客园 - zzuCharles

Qwen-Max 8G 内存本地部署方案(轻量化可用版) MFC中使用多线程 高性能 Flink SQL 优化 Flink 时间概念 EventTime 和 Watermark SQL 优化(来源平时总结及网络分享) hadoop 查询优化 python 读取csv多编码兼容读取 Mysql 调优笔记 Python 输出菱形 Python 读取目录,office文件分类 Python 猜数小程序(练习) Mysql 字符串日期互转 MaxCompute 语句笔记 数据仓库架构 Python 比较两个字符串的相似度 Python print Python简单计算器 用户价值模型 CITE :https://www.jianshu.com/p/34199b13ffbc 用户生命周期模型
文件拆分-python
zzuCharles · 2021-04-29 · via 博客园 - zzuCharles
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 12 17:28:30 2019

@author: **********
"""

import sys,os

kilobytes = 1024
megabytes = kilobytes*1000
chunksize = int(200*megabytes)#default chunksize

def split(fromfile,todir,chunksize=chunksize):
    if not os.path.exists(todir):#check whether todir exists or not
        os.mkdir(todir)          
    else:
        for fname in os.listdir(todir):
            os.remove(os.path.join(todir,fname))
    partnum = 0
    inputfile = open(fromfile,'rb')#open the fromfile
    while True:
        chunk = inputfile.read(chunksize)
        if not chunk:             #check the chunk is empty
            break
        partnum += 1
        filename = os.path.join(todir,('data%04d'%partnum))
        fileobj = open(filename,'wb')#make partfile
        fileobj.write(chunk)         #write data into partfile
        fileobj.close()
    return partnum
if __name__=='__main__':
        fromfile  = input('File to be split?')
        todir     = input('Directory to store part files?')
        chunksize = int(input('Chunksize to be split?'))
        absfrom,absto = map(os.path.abspath,[fromfile,todir])
        print('Splitting',absfrom,'to',absto,'by',chunksize)
        try:
            parts = split(fromfile,todir,chunksize)
        except:
            print('Error during split:')
            print(sys.exc_info()[0],sys.exc_info()[1])
        else:
            print('split finished:',parts,'parts are in',absto)