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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:49:43+00:00 2026-05-17T19:49:43+00:00

Quite embarassing issue, though i come from web development and rarely have to deal

  • 0

Quite embarassing issue, though i come from web development and rarely have to deal with files i/o.

I wrote a simple config updater for use on my shared hosting. It scans the directory for subdirectories, and then writes config lines to a file – one line for each subdirectory. The problem is, when it detects there are config lines but no subdirectories, it’s supposed to leave config empty – which doesn’t work! Coming here with this because docs aren’t mention it and google isn’t helpful either. Its Python 2.6.6 on Debian Lenny.

file = open('path', 'r+')
config = file.read()
## all the code inbetween works fine
## config is .split()-ed, hence the list
if config == ['']:
    config = ''
file.write(config)
file.close()

In this case, file isn’t changed at all. The funny thing is, making it forget config and just do file.write(”) doesn’t empty the file either, but puts \n in seemingly random positon of the line.

  • 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-17T19:49:44+00:00Added an answer on May 17, 2026 at 7:49 pm

    You’re using the r+ read-write mode. All reads and all writes update the file’s position.

    Try:

    file = open('path', 'r+')
    config = file.read()
    ## all the code inbetween works fine
    ## config is .split()-ed, hence the list
    if config == ['']:
        config = ''
    file.seek(0)    # rewind the file
    file.write(config)
    file.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
Quite a simple question. In SQL 2008 if I have a stored procedure (see
Quite a simple problem here and not sure why it's being so complicated. Have
Quite simple, but it's driving-me crazy I have a div inside a div that
Quite simple really. I have two ContentPanes that I load content into dynamically. The
Quite embarrassing really, but I tested creating a database from a spreadsheet with a
Quite some time i`ve learnt MVC. I have seen various techniques to post data
Quite often, I find myself wanting a simple, dump object in Python which behaves
Quite a simple question. Is it possible to notice vibrations in the Android emulator?
Quite simple: <a4j:commandButton id=bob action=#{MyBacking.doAction} image=/img/btn.png reRender=stuff oncomplete=#{not empty MyBacking.myCondition ? #{rich:component('myModelPanel')}.show() : <do

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.