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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:03:04+00:00 2026-06-15T02:03:04+00:00

I have a code that writes a bunch of lines to csv files. It

  • 0

I have a code that writes a bunch of lines to csv files. It writes what i want, but… it inserts brackets in each column…
The code is:

    root_text_csv = "C:/Users/s/Desktop/text/knife"+numarul_folderelor+".csv"
    fisier_text_knife = csv.writer(open(root_text_csv,'wb'))
    row_test = []
    for filenames in os.listdir(foldere_prrra):
        knife = filenames.replace("<SP>", " ").replace(".sys", "")
        test = ['cut '+knife+' off for fuged,', 'cut '+knife+' off,', 'cut '+knife+' fool alabala,', 'cut '+knife+' nieh,', 'prrra '+knife+' alabala,',
                'cut '+knife+' fuged streaming,', 'cut '+knife+' alabala fuged,', 'cut '+knife+' off alabala,', 'prrra '+knife+' fool alabala,',
                'cut '+knife+' off fuged,', 'prrra '+knife+' niether alabala,', 'cut off '+knife+' for fuged,' 'cut '+knife+' fuged fool alabala,',
                'cut '+knife+' off niether,', 'where to cut '+knife+',', ''+knife+' fool alabala off,', 'steel '+knife+' off fuged,', 'cut '+knife+' fuged niether,',
                ''+knife+' fool alabala off,', 'fuged streaming '+knife+',', 'cut '+knife+' niether,', 'cut '+knife+' fuged,', 'red '+knife+' off,', ''+knife+' off,',
                'red '+knife+',', 'cut '+knife+',', ''+knife+' fuged,', 'fuged '+knife+',', ''+knife+' off,', 'off '+knife+',', ''+knife+',']
        random.shuffle(test)
        scris = [x for x in test if len(x) <= 30]
        row_test.append(scris) #row_test.append(scris[0])
    fisier_text_knife.writerow(row_test)

If i replace the row_test.append(scris[0:7]) with row_test.append(scris[0]) it writes only one string off them all(but writes it without the brackets –>[ ]<–).

I want to write 7 or 8 lines. I wasted my brain on this code.

Thank you for the time.

  • 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-15T02:03:05+00:00Added an answer on June 15, 2026 at 2:03 am

    The reason this is happening is because scris is a list.

    instead of:

    row_test.append(scris[0:7])
    

    do this rather:

    row_test += scris[0:7]
    

    This works too (see comment below):

    row_test.extend(scris[0:7])
    

    If it still doesn’t make sense open a console and type in the example stuff below. Every time you change l print it out.

    the example below should show you why this works:

    l = [1,2,3]          #    l = [1,2,3]
    l.extend([4,5])      #now l = [1,2,3,4,5]
    l.append([6,7])      #now l = [1,2,3,4,5,[6,7]]
    l.extend('hi there') #raises an exception
    

    When you call some_list.append(some_item) it puts some_item inside some_list. So if some_item is also a list then you get a list inside a list.

    When you call some_list.extend(some_item) it joins some_item to the end of some_list. So if some_item is not a list then this will error.

    EDIT I think i see what you want now…

    So given a list like [['1','2','3'],['4','5','6'],['7','8','9']] you want the csv to look like: 123,456,789, right?

    Instead of:

    fisier_text_knife.writerow(row_test)
    

    Try this out:

    csv_friendly = [''.join(l) for l in row_test]
    fisier_text_knife.writerow(csv_friendly)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have third-party C code that writes data to a file. I want to
I have code that generates a List<string[]> variable but can't quite figure out how
I have code that looks more or less like the code below but it
I have code that sends web requests through two parallel for each loops. Will
So, I have this code that grabs a bunch of data from the database,
I have certain code that I want to optimize. It looks like this: function
I have a bunch of legacy code for encoding raw emails that contains a
I have R code (using ggplot2) that pumps out a bunch of charts to
I have a file with a bunch of text that I want to tear
Sometimes I have to write code that alternates between doing things and checking for

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.