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

The Archive Base Latest Questions

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

Ok, the code I have is the following: for shidx in xrange(0, book.nsheets): print

  • 0

Ok, the code I have is the following:

for shidx in xrange(0, book.nsheets):
print shidx
sheet = book.sheet_by_index(shidx)
d = sheet.col_values(0,2)
D = sheet.col_values(1,2)
dim = sheet.row_values(0,2)
if shidx == 0:
    #numLine = sheet.row_values(2)
    rs = sheet.col_values(6,2)
    for i in range(4):
        BB = sheet.col_values(2 + i, 2)
        if BB != 0:
            #print repr(d).rjust(2), repr(D).rjust(3), repr(BB).rjust(4), repr(rs).rjust(5)
            file = open("C:\\calcul\\SimX18_VitesseLimite\\Documents\\ncapa-20111116\\ncapa\\resources\\output.txt", "w")
            #file.write(str(table) + '\n')
            file.write(str(d) + '\n')
            file.write(str(D) + '\n')
            file.write(str(BB) + '\n')
            file.write(str(dim) + '\n')
            file.write(str(rs) + '\n')
            file.close()

I’ve commented out the print towards the end as I’ve been trying a few different things.

My aim is to write to a text file with each line corresponding to a column in a table.
My problem here is splitting the list for d, D, dim and BB. Here is what I would like to do:

The ROW of dim and COLUMN of d:

dim = [17.0, 27.0, 37.0, 47.0, u'17-47'] (see table below for the first row and to what it corresponds)
d = [0.59999999999999998, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 15.0, 17.0, 20.0, 22.0, 25.0, 28.0, 30.0, 32.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0, 105.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0]

Table1
1

And the first and second ROW of BB:

BB = [0.8, 0.0, 0.0, 0.0]
BB = [1.0, 0.0, 0.0, 0.0]

I want to be able to write into the text file (the equivalent of a table as below):

Table2
2

However for the third ROW of BB:

BB = [1.0, 0.0, 1.8, 0.0]

I need to be able to obtain the following (i.e. there are two ‘dim’ options):

Table3
3

When I say that BB isn’t equal to 0.0, I want to be able to write that ONE single value for d, D, BB and dim into the table but I can’t get away from all the lists…

I really hope this makes sense to someone as I’m a bit stuck!

  • 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:41:02+00:00Added an answer on May 27, 2026 at 4:41 am

    Your requirement is eventually ascertainable after multiple readings. However your code has several problems:

    The indentation as displayed is botched. Presumably you are using tabs in your editor. Don’t do that with Python source files. Set it up to use 4 spaces per indent level.

    You are iterating over sheets but ignoring all but the first sheet; why?

    You are using d, D, and rs to refer to lists of values but not iterating over the lists.

    Even if d refers to a scalar as it should, doing file.write(str(d) + '\n') etc is no way of attaining your goal of a file with 5 values per line.

    Opening/closing your output file once per output line would be grossly inefficient if opened in append mode, and is grossly inefficient and completely wrong as you have it, opened in write mode — you would only ever get the last line written.

    You need to give some thought to who/what is going to read/consume your output file, and the format that they/it would prefer.

    Enough of that. Here is what you ought to do (pseudocode):

    open your workbook
    open your output file
    for each sheet:
        get dim # a list
        for each data row:
            get d, D, and rs # three scalars
            for each bb value in the BB zone of the current row:
                if bb is non-zero:
                    get the corresponding dim value (e.g. 27)
                    write d, D, bb, dim_value, rs as 1 line to the output file
    close your output file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code import imp from my_module import MyClass import my_module imp.reload(my_module) print(MyClass
I have following code #file 1 a.pm package a; @Export=(test); print test; #hashing this
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code for loading image from url in xml parsing endElement method
I have following code for inserting data into database using PDO. It inserts data
I have following code. ASPX Page <a href=AnyASPXPageOfWebsite.aspx onclick=javascript:CallJQuery(); > Set Price </a> JS
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code using hibernate to throw a custom exception on error and

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.