How to read and write multiple files in Python?
Goal:
I want to write a program for this:
In a folder I have =n= number of files;
first read one file and perform some operation then store result in a separate file.
Then read 2nd file, perform operation again and save result in new 2nd file.
Do the same procedure for n number of files.
The program reads all files one by one and
stores results of each file separately.
solution:
#+BEGIN_SRC Python
import sys
#argv is your commandline arguments, argv[0] is your program name, so skip it
for n in sys.argv[1:]:
print(n) #print out the filename we are currently processing
input=open(n,"r")
output=open(n,+".out","w")
# do some processing
input.close()
output.close()
#+END_SRC
- syn :: system-specific parameters and functions
- module :: a file contains Python code
why python module?
Python module is used to group related functions, classes, and variables
for better code management and avoiding name clash
https://stackoverflow.com/questions/208120/how-to-read-and-write-multiple-files
最新文章
- swift 学习笔记
- mysqll底层分享(一):MySQL索引背后的数据结构及算法原理
- ecshop 配送方式支持";货到付款";
- HTML 5 Canvas 参考手册
- LINQ找出重复和不重复的元素及linq OrderBy 方法 两个字段同时排序有关问题
- shell脚本例子集锦(习题总结)
- transform的使用
- zoj 3761
- IE兼容问题
- [android]android开发中的运行错误之:adb.exe
- Android系统Root原理初探(转)
- html5学习(一) video字段
- PowerShell 异常处理
- Photoshop给人像加上个性裂纹肌肤
- JavaScript(JS)之Javascript对象BOM,History,Location,Function...(二)
- python语法_算数运算+赋值运算符+比较运算符+逻辑运算符
- linux 修改centos7的网卡ens33修改为eth0
- hadoop-2.7.3完全分布式部署
- vue tab切换
- [日常] HEOI 2019 退役记
热门文章
- 10.05FZSZ Day2模拟总结
- [CF348B]Apple Tree
- nodejs常用命令
- LVS集群体系和调度算法
- 使用 script 的 module 属性实现 es6 以上的兼容
- native2ascii命令详解
- git Eclipse项目不显示当前分支
- django.db.utils.OperationalError: (1050, ";Table '表名' already exists)解决方法
- Android 知识Tips
- viewpager滑动时页面不能刷新