6

I have a Python script that is working fine from Processing->Toolbox->User Scripts. However, I have put some user defined functions in "my_functions.py" that I can call from "Timing_Advance.py".

The problem is, when I edit the functions in "my_functions.py" in the QGIS script editor, I have to restart QGIS for the changes to take effect. This is perhaps because, when I restart QGIS, it makes a "my_fucntions.pyc" file and keeps it in the same location. The .pyc file is not update when I edit the user defined functions in "my_functions.py".

How can I update the my_functions.pyc file after editing, without having to restart QGIS?

UPDATE 24th Jan 2017 Looks like including the following lines isn't making any difference either

import sys
sys.path.append(r'C:\Users\EDEYARI\.qgis2\processing\scripts')
import py_compile
py_compile.compile(r'C:\Users\EDEYARI\.qgis2\processing\scripts\my_functions.py')
import my_functions

If I add some dummy lines like a "print" and re-run the script, the print doesn't give the desired output, till I re-start QGIS

asked Jan 23, 2017 at 6:34

1 Answer 1

3

Try using the following:

import py_compile
py_compile.compile('path/to/my_functions.py')
answered Jan 23, 2017 at 11:29
6
  • i added the suggested lines and then I added a dummy piece of code print "hi" in my_functions.py. if the code worked then I would have seen the response in the python console, but nope Commented Jan 23, 2017 at 14:37
  • 1
    @Arindam - Hmm, perhaps this post might help: Re-import custom functions without restarting QGIS Commented Jan 24, 2017 at 12:37
  • I must be missing something elementary. I added these lines import imp, my_functions imp.reload(my_functions) from my_functions import * but now I get the error "See log for Details" Commented Jan 26, 2017 at 4:31
  • 1
    Thanks for the tip. I just removed "imp" and it worked like a charm. Found the answer here <stackoverflow.com/questions/1517038/python-refresh-reload> Commented Jan 27, 2017 at 7:38
  • @Arindam - Ahh well done for solving your problem! You should post it as an answer and accept it by clicking the green-faded tick :) Commented Jan 27, 2017 at 9:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.