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

  • SEARCH
  • Home
  • 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 6877853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:39:03+00:00 2026-05-27T04:39:03+00:00

So I wanted to make an arff reader (similar to csv file format). And

  • 0

So I wanted to make an arff reader (similar to csv file format).

And I wanted to use yield to make an iterator but also to add attributes to this iterator.

eg:

data = arff.reader(my_fname)
print data.relation
for row in data:
    print row

but in the reader definition:

def reader(fname):
    reader.relation = fname # this is assigned to the function, not the generator
    yield 1
    yield 2

Is there a way to do this using yield or am I stuck with the iterator api?

  • 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-05-27T04:39:03+00:00Added an answer on May 27, 2026 at 4:39 am

    You can make it a class.

    class Reader(object): # Assuming Python <= 2.7
        def __init__(self, fname):
            self.fname = fname
    
        def __iter__(self):
            yield 1
            yield 2
    
    r = Reader("some file")
    print r.fname ## 'some file'
    for line in r:
        print line ## 1 then 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to make some simple file recovery software, where I want to try
I'm using Zend FW and wanted to make a feed reader. I did the
This might be a stupid question but I just wanted to make sure... If
i wanted to make a double border but with no space in between and
I wanted to make mysql dump files using a batch file and an app
i've always wanted to make some of our companies products open-source..but we have a
Just out of curiosity i wanted to make something similar to what pretty much
I wanted to make this script work somehow, but i find that after you
I wanted to make a dictionary using BST but I did not have any
i just wanted to make a test, i'm used to work on jQuery but

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.