2

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?

5
  • Is there an __init__.py in your virtuam folder?
    – mhall119
    Jul 5, 2012 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/… Jul 6, 2012 at 6:41
  • I removed it, but I have a backup. Why?
    – Xerz
    Jul 6, 2012 at 13:42
  • 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! :) Jul 6, 2012 at 17:00
  • Oh! I didn't think that... :P Thanks one more time!
    – Xerz
    Jul 6, 2012 at 17:53

2 Answers 2

0

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 *
1
  • Not working: Traceback (most recent call last): File "/usr/bin/virtuam", line 15, in <module> import vui ImportError: No module named vui
    – Xerz
    Jul 5, 2012 at 17:13
0

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

2
  • 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. Jul 8, 2012 at 7:04
  • 1
    I like it. Maybe that should be Quickly's slogan: simple (but not obvious).
    – bcbc
    Nov 14, 2012 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .