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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:50:18+00:00 2026-06-17T18:50:18+00:00

I am experiencing an odd problem that I’m not quite sure how to tackle.

  • 0

I am experiencing an odd problem that I’m not quite sure how to tackle. I have a Python-selenium script that uses relative paths to log results to a text-file.

Here is the part of the script which sets up the log-file:

log_file = './demo-logfiles/log_file_template.txt'
sys.stdout = open('log_file_template.txt', 'a',)

As you can see, it uses a relative path to a folder. If I run this script as:
python demo.py firefox MAC, it runs flawlessly and the logfile gets sent to the proper folder.

If I run this exact Python script from within a larger shell-script, it returns an error that the './demo-logfiles/log_file_template.txt' doesn’t exist.

I have found that if I change the script to '../demo-logfiles/log_file_template.txt' it works in the larger shell script, but stops working if I run it normally.

It either works in one, or the other. What is the reason for the relative directories being interpreted in different ways? I would not like to have two separate scripts for running in Python/shell.

The original python script is in the directory /blah/blah/DEMO/demo.py, and the the shell script that runs it is in /blah/blah/DEMO/demo-autotest/autotest_logger.sh

I have confirmed that this problem occurs for any script I try to run. I shouldn’t have to change the original Python code to make it work with the shell script. I already accounted for it in the shell script, and it successfully runs the file.

Thanks.

  • 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-17T18:50:19+00:00Added an answer on June 17, 2026 at 6:50 pm

    You should never use a “.” (or any relative path) in a directory path in a script unless you really mean you want to refer to the directory that the user is running the script from. If you want to refer to a location relative to the script that’s running, you can do the following:

    import os
    import sys
    directory = os.path.dirname(os.path.abspath(__file__))
    sys.stdout = open(os.path.join(directory, "demo-logfiles", "log_file_template.txt"), "a")
    

    Best practices side note: you should probably use the logging module rather than reassigning sys.stdout.

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

Sidebar

Related Questions

I'm experiencing a problem with my <ul> <li> tags, and i'm not sure if
I'm experiencing the strangest problem. I have a development site page that for some
I am experiencing a odd problem. My OnItemSelectedListener seems only works one time, i
I'm experiencing something odd here, that I don't recall ever running into. I'm doing
I have an odd TFS issue that no one else on my team seems
This is a bit of unusual problem that I'm experiencing, but recently one of
I've got this odd problem. If I make a call on that function through
I'm experiencing an odd problem where my page's SSL breaks in firefox if I
I've been experiencing this very odd problem lately in Heroku. I develop and test
I'm experiencing a very odd problem with a Java application running under Tomcat. We

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.