number.txt
文件,内容如下:123456789
number.txt
。如下图所示:
3_StoreMapping.py
文件# custom (Change to your info)imageId = "img-m4q71qnf"Application = {"DeliveryForm": "PACKAGE","Command": "python ./codepkg/sumnum.py","PackagePath": "http://batchdemo-xxxxxxxxx.cos.ap-guangzhou.myqcloud.com/codepkg/codepkg.tgz"}StdoutRedirectPath = "your cos path"StderrRedirectPath = "your cos path"InputMapping = {"SourcePath": "cos://batchdemo-xxxxxxxxx.cos.ap-guangzhou.myqcloud.com/input/","DestinationPath": "/data/input/"}OutputMapping = {"SourcePath": "/data/output/","DestinationPath": "your output remote path"}
配置项 | 描述 |
Application | Command 改为执行 sumnum.py。 |
InputMapping | 输入映射。 SourcePath 远程存储地址:修改为前置准备里 input 文件夹的地址,请参见 获取 COS 相关访问域名。 DestinationPath 本地目录:暂不修改。 |
OutputMapping | 输出映射。 SourcePath 本地目录:暂不修改。 DestinationPath 远程存储地址:修改为前置准备里 output 文件夹的地址,请参见 获取 COS 相关访问域名。 |
input/number.txt
,并把每一行的数字相加,然后把结果写到 output/result.txt
里。import osinputfile = "/data/input/number.txt"outputfile = "/data/output/result.txt"def readFile(filename):total = 0fopen = open(filename, 'r')for eachLine in fopen:total += int(eachLine)fopen.close()print "total = ",totalfwrite = open(outputfile, 'w')fwrite.write(str(total))fwrite.close()print("Local input file is ",inputfile)readFile(inputfile)
python 3_StoreMapping.py
{"RequestId": "8eaeb01e-94a6-41a1-b40f-95f15417c0b4","JobId": "job-97smiptb"}
3_StoreMapping.py
的执行结果保存在 result.txt
中,result.txt
将自动同步到 COS 中。
result.txt
内容如下所示:45
本页内容是否解决了您的问题?