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 9162577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:14:38+00:00 2026-06-17T14:14:38+00:00

Just a fundamental question regarding python and .join() method: file1 = open(f1,r) file2 =

  • 0

Just a fundamental question regarding python and .join() method:

file1 = open(f1,"r")
file2 = open(f2,"r")
file3 = open("results","w")

diff = difflib.Differ()
result = diff.compare(file1.read(),file2.read())
file3.write("".join(result)),

The above snippet of code yields a nice output stored in a file called “results”, in string format, showing the differences between the two files line-by-line. However I notice that if I just print “result” without using .join(), the compiler returns a message that includes a memory address. After trying to write the result to the file without using .join(), I was informed by the compiler that only strings and character buffers may be used in the .join() method, and not generator objects. So based off of all the evidence that I have adduced, please correct me if I am wrong:

  1. result = diff.compare(file1.read(),file2.read()) <—- result is a generator object?

  2. result is a list of strings, with result itself being the reference to the first string?

  3. .join() takes a memory address and points to the first, and then iterates over the rest of the addresses of strings in that structure?

  4. A generator object is an object that returns a pointer?

I apologize if my questions are unclear, but I basically wanted to ask the python veterans if my deductions were correct. My question is less about the observable results, and more so about the inner workings of python. I appreciate all of your help.

  • 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-17T14:14:39+00:00Added an answer on June 17, 2026 at 2:14 pm

    join is a method of strings. That method takes any iterable and iterates over it and joins the contents together. (The contents have to be strings, or it will raise an exception.)

    If you attempt to write the generator object directly to the file, you will just get the generator object itself, not its contents. join “unrolls” the contents of the generator.

    You can see what is going with a simple, explicit generator:

    def gen():
        yield 'A'
        yield 'B'
        yield 'C'
    
    >>> g = gen()
    >>> print g
    <generator object gen at 0x0000000004BB9090>
    >>> print ''.join(g)
    ABC
    

    The generator doles out its contents one at a time. If you try to look at the generator itself, it doesn’t dole anything out and you just see it as “generator object”. To get at its contents, you need to iterate over them. You can do this with a for loop, with the next function, or with any of various other functions/methods that iterate over things (str.join among them).

    When you say that result “is a list of string” you are getting close to the idea. A generator (or iterable) is sort of like a “potential list”. Instead of actually being a list of all its contents all at once, it lets you peel off each item one at a time.

    None of the objects is a “memory address”. The string representation of a generator object (like that of many other objects) includes a memory address, so if you print it (as above) or write it to a file, you’ll see that address. But that doesn’t mean that object “is” that memory address, and the address itself isn’t really usable as such. It’s just a handy identifying tag so that if you have multiple objects you can tell them apart.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting used to Subversion and I have a fundamental question about versioning.
I know this is just a fundamental question but still somewhere I am missing
Just a knowledge question which I would like to ask: For example, I have
Okay, here is a very simple and fundamental question. If I have an application
This is a pretty fundamental question when using NHibernate in a web application, but
This is probably a fundamental question for an experienced iOS developer, but coming from
I'm may be just misunderstanding something fundamental here but... Senario: I call System.Net.Sockets.NetworkStream 's
This is probably a really fundamental question, but I'm afraid I don't know much
I know this is a fundamental java question, but i am relatively new to
this is more of a fundamental question at how apache/threading works. in this hypothetical

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.