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?

David Planella
  • 15,420
  • 11
  • 77
  • 141
Xerz
  • 4,591
  • 3
  • 23
  • 37
  • 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: http://askubuntu.com/questions/154129/how-can-i-publish-my-project-code-online-so-someone-can-help-me-with-it – David Planella Jul 06 '12 at 06:41
  • Is there an `__init__.py` in your `virtuam` folder? – mhall119 Jul 05 '12 at 20:05
  • I removed it, but I have a backup. Why? – Xerz Jul 06 '12 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! :) – David Planella Jul 06 '12 at 17:00
  • Oh! I didn't think that... :P Thanks one more time! – Xerz Jul 06 '12 at 17:53

2 Answers2

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 *
  • Not working: `Traceback (most recent call last): File "/usr/bin/virtuam", line 15, in import vui ImportError: No module named vui` – Xerz Jul 05 '12 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

Xerz
  • 4,591
  • 3
  • 23
  • 37
  • 1
    A better approach would be to copy your code to the `` folder instead of `_lib`, which is for private and common modules and should generally not be modified unless you know what you're doing. – David Planella Jul 08 '12 at 07:04
  • 1
    I like it. Maybe that should be Quickly's slogan: `simple (but not obvious)`. – bcbc Nov 14 '12 at 17:18