I have all this files each file has big information I need code to find all blan
ID: 3898523 • Letter: I
Question
I have all this files each file has big information I need code to find all blank (spaces) and replace to (_) By python or c++ GcA 0009593MS1 GCA 000959365.1 CCA 00099 CCA 000959425.1 CCA0009594451 CCA 000959465.1 CCA 000959485.1 GCA 000959505.1 GCA 0009595251 CCA00959605.1 ASM95952vt protein11.faa 00095962ss_ GCA,000961515.1- protein faa CCA,000963553.1- CCA 000971sas. 1- ASM97156t proteinAchsfaa CA,00101ores.1· ccA00102ses 1- ASM1010761ASM102866e1ASM102914v1 GCA 00104329st- ASM104329v1 co-0010454151- ASM104541v1 COA 00047635 t- ASM104763v1, CA 001029as 1- protein Fas proteinBAB846. proteinTsY216faaproteinPa GCAO 10476SSI- CCA 0012401SI- ASM124431v1 CCA 00126201S1. CCA 00127787St- GCA 00127mst_ prateinwgh 1ewfas CCA-00127797$1, protein 982 ???-001290045 1- ASM129304v1 ??? 00128166.1. CCA 001250 est_ ???-29eses , proteinfa protein fa ASM14444ov1 protein2023e.raa proteinFORC 004... proteinFORC 009. protein faa ASM130477V ASM 1305391 ASM131811 ASM131824v1 protein faa proteinBp1651 faa proteinfaa GCA 00146S29S 1. protein raa CCA 001462jest_ protein faa GCA 001aeest_ ??? 001 Stra CCA_001esirs."- proteinJKY 60,faa s.1- CCA-001455325.1. CCA-001444465.1- protein faa ???-001456065 2- protein0? Les las GCA-00140075 ,-CCA 001449 ASM1444461 ASM14470 SM144901 protein.faa protein faa ASM155849v2 ASM?SS8Sm2 ??? 10001 ASM165377v1 ASM155189 ASM155841v2 prcteins33 faa . protein.faa CCA,00soas625.1- ca001 715425.1- CCA-001718515. 1. CCA 00171889S 1. CCA_00172954S 1. GCA,00t854425 ,. GCA,0 ??- IH. ???,00 ares ,. ???,001603415.1- proteincS.Faa proteinCRC711faa protelnCRC110e.r A544188761 proteinE.50s.fea proteine1ie2.raa proceincrcs3 CCA-00211720£1. ASM211720v1 GCAoooooos.1 ?A,00201 19252, ASM201 1922 cc-00207)3352. ASM2073332Explanation / Answer
import os
# getting the current working directory
cwd = os.getcwd()
# getting the names of all the files in the working directory
files = os.listdir(cwd)
# iterating through all the files
for filename in files:
# skipping this python file
if filename == "directory.py":
continue
try:
print "Working on " + filename
# r+ mode for reading and writing
f = open(filename, "r+")
# reading all the data of the file
data = f.read()
# replacing blank space by underscore
data = data.replace(" ", "_")
# f.read changed the file pointer to the end of the file
# f.seek(0) brings it to the beginning of the file
f.seek(0)
# writing the new data
f.write(data)
# closing the file pointer
f.close()
# except for if it's not a file, maybe a directory
except:
continue
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.