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

  • Home
  • SEARCH
  • 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 246057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:08:26+00:00 2026-05-11T21:08:26+00:00

I’m not particularly experienced with python, so may be doing something silly below. I

  • 0

I’m not particularly experienced with python, so may be doing something silly below. I have the following program:

import os
import re
import linecache

LINENUMBER = 2

angles_file = open("d:/UserData/Robin Wilson/AlteredData/ncaveo/16-June/scan1_high/000/angles.txt")

lines = angles_file.readlines()

for line in lines:
    splitted_line = line.split(";")
    DN = float(linecache.getline(splitted_line[0], LINENUMBER))
    Zenith = splitted_line[2]
    output_file = open("d:/UserData/Robin Wilson/AlteredData/ncaveo/16-June/scan1_high/000/DNandZenith.txt", "a")
    output_file.write("0\t" + str(DN) + "\t" + Zenith + "\n")
    #print >> output_file, str(DN) + "\t" + Zenith
    #print DN, Zenith

output_file.close()

When I look at the output to the file I get the following:

0   105.5     0.0

0   104.125  18.0

0   104.0    36.0

0   104.625  54.0

0   104.25   72.0

0   104.0    90.0

0   104.75  108.0

0   104.125 126.0

0   104.875 144.0

0   104.375 162.0

0   104.125 180.0

Which is the right numbers, it just has blank lines between each line. I’ve tried and tried to remove them, but I can’t seem to. What am I doing wrong?

Robin

  • 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-11T21:08:27+00:00Added an answer on May 11, 2026 at 9:08 pm

    For a GENERAL solution, remove the trailing newline from your INPUT:

    splitted_line = line.rstrip("\n").split(";")
    

    Removing the extraneous newline from your output “works” in this case but it’s a kludge.

    ALSO: (1) it’s not a good idea to open your output file in the middle of a loop; do it once, otherwise you are just wasting resources. With a long enough loop, you will run out of file handles and crash (2) It’s not a good idea to hard-wire file names like that, especially hidden in the middle of your script; try to make your scripts reusable.

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

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In big-iTunes, find the song your want and select Copy… May 12, 2026 at 3:07 pm
  • Editorial Team
    Editorial Team added an answer int value = int.Parse(txtByteValue.Text); int len = fi[i].Length; switch (cmboCompareType.SelectedText)… May 12, 2026 at 3:07 pm
  • Editorial Team
    Editorial Team added an answer IME, they usually define their own key constants and place… May 12, 2026 at 3:07 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.