WebFaction
Community site: login faq

I had this working very simply a couple years ago, but at some time since then it stopped working, perhaps due to a server migration.

The code that is no longer working is: open('aff.py', mode = 'r') where aff.py is the running program. The file aff.py used to be found, but now the 'open' statement above causes a file-not-found error.

How can I restore this function, and make the code more robust?

asked 10 Feb '14, 02:39

RepliCounts_org
112
accept rate: 0%


In linux a file can be opened by multiple processes simultaneously, so this functionality that you were using before has probably not broken.

More likely, your script is simply in the wrong directory when issuing the open call. Try doing something like:

with open(os.path.expanduser('~/DEBUGOUTPUT.txt'), 'w') as fp:
    fp.write(os.getcwd() + '\n')

Then "cat ~/DEBUGOUTPUT.txt" and make sure this code is running from the directory that contains aff.py.

If that is the problem, then os.chdir() to the correct directory first. Hope that helps!

permanent link

answered 10 Feb '14, 02:55

ryans ♦♦
5.0k93160
accept rate: 43%

edited 10 Feb '14, 02:57

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×19
×2

question asked: 10 Feb '14, 02:39

question was seen: 1,215 times

last updated: 10 Feb '14, 02:57

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM