Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I add my custom .py file to a quickly project? I'm porting my actual, from scratch project and I have two Python scripts: virtuam and vui.py. I copied vui.py to the virtuam folder and tried this:

from virtuam import vui

but not working. So, where can I copy it? And how do I import it?

share|improve this question
    
Is there an __init__.py in your virtuam folder? –  mhall119 Jul 5 '12 at 20:05
    
If you could give us some more information, we'd be able to better help you. Could you show us your current code? You can do it like this if you want: askubuntu.com/questions/154129/… –  David Planella Jul 6 '12 at 6:41
    
I removed it, but I have a backup. Why? –  espectalll123 Jul 6 '12 at 13:42
    
OK, thanks! I'm modifying the source code... –  espectalll123 Jul 6 '12 at 14:46
    
There is no need for the 'NOTE: THIS QUESTION WAS ANSWERED BY MYSELF, SO PLEASE DON'T POST' note. It's perfectly valid to have multiple answers. Who knows, perhaps someone can offer an even better answer! :) –  David Planella Jul 6 '12 at 17:00
show 1 more comment

2 Answers

If you copy, for example your vui.py script to /quickly/project_name/project_name folder, where is stored python code generated initialy from quickly, for example project_nameWindow.py and others ,then you can import with

import vui

or

from vui import *
share|improve this answer
    
Not working: Traceback (most recent call last): File "/usr/bin/virtuam", line 15, in <module> import vui ImportError: No module named vui –  espectalll123 Jul 5 '12 at 17:13
add comment
up vote 0 down vote accepted

The solution is simple (but not obvious):

  1. Copy the script into the <project>_lib folder.
  2. Add the script functions in the __init__.py file:

    from . <script> import <function>

  3. Now add the function in the main script:

    from <project>_lib import <function>

    If you want to call the function, just type <function>(<options>)

Thanks to @mhall119 for his question/answer! :P

share|improve this answer
1  
A better approach would be to copy your code to the <project> folder instead of <project>_lib, which is for private and common modules and should generally not be modified unless you know what you're doing. –  David Planella Jul 8 '12 at 7:04
1  
I like it. Maybe that should be Quickly's slogan: simple (but not obvious). –  bcbc Nov 14 '12 at 17:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.