open dataset appending

本文介绍了一个文件操作的例子,包括打开文件进行写入、追加数据,以及读取并显示文件内容的过程。通过这个例子,读者可以了解到如何使用TRANSFER语句进行数据的写入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DATA FNAME(60) VALUE 'myfile'.

DATA NUM TYPE I.

OPEN DATASET FNAME FOR OUTPUT.
DO 5 TIMES.
   NUM = NUM + 1.
   TRANSFER NUM TO FNAME.
ENDDO.

OPEN DATASET FNAME FOR INPUT.

OPEN DATASET FNAME FOR APPENDING.
NUM = 0.
DO 5 TIMES.
   NUM = NUM + 10.
   TRANSFER NUM TO FNAME.
ENDDO.

OPEN DATASET FNAME FOR INPUT.
DO.
  READ DATASET FNAME INTO NUM.
  IF SY-SUBRC <> 0.
    EXIT.
  ENDIF.
  WRITE / NUM.
ENDDO.

The output appears as follows:

1
2
3
4
5
10
20
30
40
50

This example opens the file "myfile" for write access and fills it with the five integers 1-5 (for further information about the TRANSFER statement, refer to Writing Data to Files ). The next OPEN DATASET statement resets the position to the beginning of the file. Then, the file is opened for appending data (the position is set to the end of the file). Five integers between 10 and 50 are written into the file. Finally, the program reads the contents of the file, and displays them on the screen.

Traceback (most recent call last): File "/root/miniconda3/envs/test/bin/yolo", line 8, in <module> sys.exit(entrypoint()) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/ultralytics/yolo/cfg/__init__.py", line 394, in entrypoint getattr(model, mode)(**overrides) # default args from model File "/root/miniconda3/envs/test/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/ultralytics/yolo/engine/model.py", line 252, in predict return self.predictor.predict_cli(source=source) if is_cli else self.predictor(source=source, stream=stream) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/ultralytics/yolo/engine/predictor.py", line 189, in predict_cli for _ in gen: # running CLI inference without accumulating any outputs (do not modify) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 43, in generator_context response = gen.send(None) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/ultralytics/yolo/engine/predictor.py", line 215, in stream_inference self.setup_source(source if source is not None else self.args.source) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/ultralytics/yolo/engine/predictor.py", line 197, in setup_source self.dataset = load_inference_source(source=source, imgsz=self.imgsz, vid_stride=self.args.vid_stride) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/ultralytics/yolo/data/build.py", line 158, in load_inference_source dataset = LoadStreams(source, imgsz=imgsz, vid_stride=vid_stride) File "/root/miniconda3/envs/test/lib/python3.8/site-packages/ultralytics/yolo/data/dataloaders/stream_loaders.py", line 57, in __init__ raise ConnectionError(f'{st}Failed to open {s}') ConnectionError: 1/1: 0... Failed to open 0 Sentry is attempting to send 2 pending events Waiting up to 2 seconds Press Ctrl-C to quit
05-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值