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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:14:57+00:00 2026-06-12T13:14:57+00:00

I have the following Python script inside a directory called ‘test’ on my Linux

  • 0

I have the following Python script inside a directory called ‘test’ on my Linux desktop:

#!/usr/bin/python

f = open('test.txt','w')
f.write('testing the script')

So it’s /Home/Desktop/test/script.py

If I go inside the directory and type ./script.py it works fine and creates the test.txt file.

However for some reason I am not able to run the script from the Desktop (/Home/Desktop). I tried ./test/script.py, for instance, but didn’t work.

The file permissions on the script are 755, and on the directory 777.

Any help would be appreciated.

  • 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-12T13:14:59+00:00Added an answer on June 12, 2026 at 1:14 pm

    You can use os.path.dirname() and __file__ to get absolute paths like this:

    #!/usr/bin/python
    
    import os  # We need this module
    
    # Get path of the current dir, then use it to create paths:
    CURRENT_DIR = os.path.dirname(__file__)
    file_path = os.path.join(CURRENT_DIR, 'test.txt')
    
    # Then work using the absolute paths:
    f = open(file_path,'w')
    f.write('testing the script')
    

    This way the script will work on files placed only in the same directory as the script, regardless of the place from which you execute it.

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

Sidebar

Related Questions

I have the following simple python test script that uses Suds to call a
I have a script, called test.py , that does the following: while (1): ....print
I have the following python script which takes some inputs and puts them in
I have the following in my python script.. hostIP = sys.argv[1] hostsFileLoc = hosts.txt
i have something similar to the following... used a python script to JSON to
I have the following script for sending mails using python import smtplib from email.mime.multipart
I have the following query that I'm executing using a Python script (by using
I have a python script that invokes the following command: # make After make,
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable
I have the following python script and I would like to send fake header

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.