Python Forum
Executing func() from a different folder
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Executing func() from a different folder
#1
Hi,

I've a test.py containing a func(x) in my /home/pi directory.

I need to execute the func(x) from /var/www/html directory with the code "python3 test 0". Said code works within the pi directory but not from outside of it.

I've given the www-data group permissinon to test.py but cannot solve the path '/home/pi' issue.

Any help is appreciated.
Reply
#2
Did you also give permissions for the /home/pi directory?

Also do you need to run it exactly with this line?
python3 test 0
You should specify the path:
python3 /home/pi/test.py 0
Reply
#3
Thanks. Not sure if it's the right way but I solved my issue by creating a local file point to the original located in a different folder as such:

#!/usr/bin/env python

import sys
sys.path.insert(0, '/home/pi/.')

from gpio import ledsOn

if __name__ == '__main__':
  n = int(sys.argv[1])
  print(ledsOn(n))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 466 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  How to output one value per request of the CSV and print it in another func? Student44 3 1,278 Nov-11-2022, 10:45 PM
Last Post: snippsat
  Function not executing each file in folder mathew_31 9 2,166 Aug-22-2022, 08:40 PM
Last Post: deanhystad
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,390 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,434 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  Func Animation not displaying my live graph jotalo 0 1,523 Nov-13-2020, 10:56 PM
Last Post: jotalo
  Trying to write func("abcd") -> "abbcccdddd" omm 8 3,983 Oct-24-2020, 03:41 AM
Last Post: bowlofred
  Python Cut/Copy paste file from folder to another folder rdDrp 4 4,944 Aug-19-2020, 12:40 PM
Last Post: rdDrp
  call func from dict mcmxl22 3 2,820 Jun-21-2019, 05:20 AM
Last Post: snippsat
  About [from FILE import FUNC] Nwb 7 3,522 Apr-21-2019, 02:46 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020