Home > other >  [pathlib rgrob strange problems] a great god, please help to see programs have what problem, Pycharm
[pathlib rgrob strange problems] a great god, please help to see programs have what problem, Pycharm

Time:09-22

A simple small program, strange problems

Purpose: use pathlib Path method to "/A/B/C/D/E/F/G/H/" all" QAM_MCS_8150. TXT "and" RI_Layers_8150. TXT "two folders in the replace part of the field for operation, and maintain the name,

Problem: Pytharm run zero error, but Pycharm always prompt all fields with the File the yellow (not into the logic), strange,
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#! The/usr/bin/env python3
# _ * _coding: utf-8 _ * _
# Author: [email protected]
# time: 31/3/2020
The import OS
The import re
The import pathlib

The from pathlib import Path
P=Path ('/A/B/C/D/E/F/G/H/')
For file in p.r glob (' *.txt) :
If 'QAM_MCS_8150. TXT file in:
With the open (file, 'r') as filereader1:
With the open (the file. The replace ('. TXT ', '_new. TXT'), 'w') as filewriter1:
For the row in filereader1:
If "256 qam" in a row:
The row=row. Replace (' 256 qam ', '8')
Elif "64 qam" in a row:
The row=row. Replace (' 64 qam ', '6')
Elif "16 qam" in a row:
The row=row. Replace (' 16 qam ', '4')
Elif "QPSK" in a row:
The row=row. The replace (' QPSK ', '2')
Elif, "31," in a row:
Row=row. Replace (', 31, 'and', ')
Elif ", 30, "in a row:
Row=row. Replace (', 30, 'and', ')
Elif ", 29, "in a row:
Row=row. Replace (', 29, 'and', ')
Elif ", 28, "in a row:
Row=row. Replace (', 28, 'and', ')
Filewriter1. Write (row)
Print (' QAM and retransmission have replaced the done... ')
OS. Remove (file)

If 'RI_Layers_8150. TXT file in:
With the open (file, 'r') as filereader2:
With the open (the file. The replace ('. TXT ', '_new. TXT'), 'w') as filewriter2:
For the row in filereader2:
If "Rank" in a row:
The row=row. Replace (' Rank ', ')
Filewriter2. Write (row)
Print (' Rank has replaced the done... ')
OS. Remove (file)

For file in p.r glob (' * _new. TXT) :
OS. Rename (file, the file. The replace (' _new. TXT ', '. TXT '))
Print (" Rename the done ")
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

CodePudding user response:

Your top up
  • Related