Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:38:11+00:00 2026-06-04T17:38:11+00:00

Hello I need your help on the following problem. I am parsing the file

  • 0

Hello I need your help on the following problem.
I am parsing the file that looks like this

@<TRIPOS>MOLECULE
NAME123
line3
line4
line5
line6
@<TRIPOS>MOLECULE
NAME434543
line3
line4
line5
@<TRIPOS>MOLECULE
NAME343566
line3
line4

I currenly have this code that is working ok…

mols = [] 
with open("test2.mol2", mode="r") as molfile: 
    for line in molfile: 
        if line.startswith("@<TRIPOS>MOLECULE"): 
            mols.append(line) 
        else: 
            mols[-1] += line
#
for i in range(len(mols)): 
    out_filename = "file%d.mol2" % i 
    with open(out_filename, mode="w") as out_file: out_file.write(mols[i]);

but whem I tried to save the files with name according to the second field of array, the one after @MOLECULE (NAME….) with code like this – it doesn’t work. Please, help me to fix the code. Thank’s!

for i in mols:
    out_filename = str(i.split()[1]) + ".mol2" % i
    with open(out_filename, mode="w") as out_file: out_file.write(mols[i]);

The error is

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: not all arguments converted during string formatting
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:38:12+00:00Added an answer on June 4, 2026 at 5:38 pm

    I recommend using a more structured list:

    for line in molfile:
        if line.startswith("@"):
            mols.append([])
            mols[-1].append(line) # Keep first line
        else:
            mols[-1].append(line)
    

    then:

    for i in mols:
        out_filename = i[0].strip() + ".mol2"
        with open(out_filename, mode="w") as out_file:
            out_file.write(''.join(i));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have the this problem, i need your help to figure out what
Hello :) I realy need your help here. I dynamically generate list of items
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
Hello i am in desperate need of help on this i have an image
Hello guys I'm stucked in a point and I need your help. I want
I need your help :/ I have a register that points to one memory
Hello all and thanks for your time reading this. I need to verify certificates
hello all i really need your help its my final project in university i
Hello I would like to ask your help regarding javascript code, how do I
I'm using excel 2007 and i'm adding a macro that looks something like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.