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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:39:49+00:00 2026-06-01T13:39:49+00:00

If I have the following data that is printed seperated by tabs using print

  • 0

If I have the following data that is printed seperated by tabs using

print str(z).translate(None,"([]){},\"'").replace(' ','\t')

0.016611783537845426    0.5728972505882961  0.1723653381777387   0.44730982873820446    10  11  10  0.016611783537845426     0.5728972505882961 0.2526385373738682  0.03281263933004819 10  12  10  0.016611783537845426    0.5728972505882961  0.509414248773428

How can i write to a new txt file but start new line every say 4 tabs. so to get 4 columns.

have tried many variations of \n but im rubbsih.

for example:

 open("file.txt", "w").write('\n'.join(str(z).translate(None,"([]){},\"'").replace(' ','\t')))

returns a newline for every character.

  • 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-01T13:39:50+00:00Added an answer on June 1, 2026 at 1:39 pm

    You can use the grouper recipe from the itertools documentation:

    import itertools as it
    def grouper(n, iterable, fillvalue=None):
        "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
        args = [iter(iterable)] * n
        return it.izip_longest(fillvalue=fillvalue, *args)
    

    Then you can generate the output as:

    values = str(z).translate(None,"([]){},\"'").split()
    output = '\n'.join('\t'.join(x for x in g if x) for g in grouper(4, values))
    

    Or if you want to write it to a file, use f.writelines:

    f.writelines('\t'.join(x for x in g if x) + '\n' for g in grouper(4, values))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data set that I am trying to plot with ggplot2,
I have the following data model: I am writing a WCF service that needs
I have a column that has the following data: PersonId=315618 LetterId=43 MailingGroupId=1 EntityId=551723 trackedObjectId=9538
I have the following connection string: Data Source=localhost\\SQLEXPRESS; , it complains that '' is
I have this following setup, a textarea named with some data in it that
I have multiple data entries that contain the following information: id_number name1 date name2
I have a data file that looks like the following example. I've added '%'
I have the following situation: I have an application that collects some data from
I have the following table template that is rendered through knockout: <table class=gv data-bind=visible:
I am writing C# application that need to print data to POS STAR printer

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.