help you fix your problem You are starting with a blank line, so it prints a blank line. If you want a blank line as a separator, include it at the end:
fout.write(seq_record.description + '\n') # no more leading newline
# fout.write('\n') # moved to above
for i in range(0,len(sequence),3):
if sequence[i:i+3] in CONST_CODON:
amino_acid = CONST_CODON[str(sequence[i:i+3])]
I wish did fix the issue. Use the Write method instead of WriteLine. The WriteLine method is the one adding a blank 0 length line to the file because it is terminating the "Hello World" string with a newline.
Removing Empty Line in a file without Removing Indentation Python
it helps some times Well I have a python code named "remove_empty_line.py" that delete Empty line from a file "a.py", the problem is that code, delete all Indentation which affect "a.py" execution. So my question is how to solve this problem, I mean deleting Empty lines with Indentation conserving. , You can use this.
open('a_mod.py','w').write(''.join(l for l in open("a.py") if l.rstrip()))
how to insert an specific line before another line, into a text file with python and without inserting any empty lines b
Any of those help I want to extract the element stiffness matrix from Abaqus input file. the contents of the last lines of the file are as follows: , This code will do exactly what you need:
with open('Input8.inp', 'r+') as f:
_text = ''
for line in f:
if line.startswith('*End Step'):
_text += '*ELEMENT MATRIX OUTPUT,ELSET=m,STIFFNESS=YES,MASS=NO,OUTPUTFILE=USER\n'
_text += line
how to replace one line in text file without removing empty lines in batch
I hope this helps . I am posting this without testing, as I do not have the environment to test as we speak. But to explain your issue, cmd will ommit empty lines as it is built that way. It is the same as setting a variable to nothing and expecting it to return a result, so we simply assign values to each line by sort of simulating a detection of line breaks (Don't know exactly how to explain that one) but nevertheless, we will add some additional characters to the lines to ensure we get line breaks, the just get rid of them once we have them, So here goes:
set _strfind=old "data"
set _strinsert=new "data";
for /f "tokens=*" %%a in ('type "%inputfile%" ^| find /v /n "" ^& break ^> "%inputfile%"') do (
if "!str!"=="%_strfind%" set "str=%_strinsert%"