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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:40:36+00:00 2026-06-04T20:40:36+00:00

I am generating random edges from a graph and printing them, but every time

  • 0

I am generating random edges from a graph and printing them, but every time I try to save it to a text file, I end up with errors like TypeError: expected a character buffer object. The code is below:

import re
import md5
import pickle
import networkx as nx
import itertools
from random import choice

ff=open("testfile.txt","r+")
G=nx.read_gpickle("authorgraph_new.gpickle")
for nodes in G:
    random_edge=choice(G.edges())
    ff=open("testfile.txt","a")
    ff.write(random_edge)

I need to save the outputs of random_edge in a text file preferably in columns, as the value of random_edge is in the form (abcdef, pqrstu). I want to put the two in separate column in the same line and the next value in the same columns. I know I can use the "\n" to get the outputs to newline but when I used

ff.write(random_edge + "\n")

I get an error TypeError: can only concatenate tuple (not "str") to tuple.

  • 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-04T20:40:38+00:00Added an answer on June 4, 2026 at 8:40 pm

    In that case you may have a try to do it in 2 lines like:

    for nodes in G:
        ff.write(random_egde)
        ff.write('\n')
    

    hope this would work for your case.
    here first line writes your data while the second line adds a new line to the data.

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

Sidebar

Related Questions

I'm looking for tools for generating random but realistic text. I've implemented a Markov
I am generating Random Geometric Graph and storing node and edges information using write_adjlist
Possible Duplicate: generating random numbers from skewed normal distribution i expect a long array
I’m generating multiple, random sized, circular elements using the Raphael JavaScript library but because
For generating random string i written code like this But if the function is
i am generating random password. but i want to get phonetic string of the
Is there any way of generating random text which satisfies provided regular expression. I
I am generating random fireballs, but my problem that it's generating much number of
Possible Duplicate: Generating random integer from a range I just started learning C++ and
I am playin around with generating random numbers, and I can get them to

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.