1

I have a file called myFile.py on my desktop. This is the file:

class Node:
    def __init__(self, data, next):
        self.data = data
        self.next = next

    def __str__(self):
        self = node
        while node.next:
            print(node.data)
            node = node.next
        return node.data

I normally edit the file in IDLE. In IDLE I can click Run->Run Module (F5) to run the file. After clicking "Run Module" in IDLE, it opens up the python shell and I can create a Node and work with the current file.

I don't use IDLE any more (I use GVim to type / edit code). Is it possible with GVim to run the current open file in the python shell?

I tried doing

:!python3 %

but when I do this, GVim just says:

Press ENTER or type command to continue

and when I press enter, nothing happens.

Note: I am using Python3.

1 Answer 1

3

When you do :!python3 & you are actually running a shell that executes the command python3 myFile.py. That will run your program non-interactively and, as is, your program does nothing, it just defines a class and ends.

You can force the interactive mode with :!python3 -i %.

Alternatively you can do :!python3 without arguments: it will launch an interactive python shell. There you can write import myFile or from myFile import * and then create your Node objects.

Sign up to request clarification or add additional context in comments.

2 Comments

hm, interesting. My file is called "LinkedList.py". When I do :!python3 without arguments, and then "import LinkedList" it says "ImportError: No module named 'LinkedList'". Same with if I do "import LinkedList.py". Any idea why? ":!python3 -i %" works though, so thanks for that.
@user2719875: That's probably because the current directory where GVim is running is not the directory where the file is. You'd need to move there (cd) or import the full path of the module. The % already includes the full path of the file, so it just works.

Your Answer

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.