1

I'm learning python so I may get my foot in the door for a programming career. I'm using the gedit text editor to write the code, however I don't know how to execute the code on ubuntu. If anyone is able to help, I would greatly appreciate as much help as I'm able to get.

Kaz Wolfe
  • 33,802
  • 20
  • 111
  • 168
Sean Kirkland
  • 11
  • 1
  • 1
  • 3
  • Do you know how to use the terminal? Commands like `cd`, `ls`, etc.? – muru Sep 09 '14 at 23:09
  • I'm still learning linux. I've been using it on and off for about 7 years but I don't have that much familiarity with it just yet. But I am always willing to learn – Sean Kirkland Sep 09 '14 at 23:12
  • I swear it's not a duplicate. I read that persons question. My question is not related to it. – Sean Kirkland Sep 09 '14 at 23:20
  • @wxl we haven't got around to actually running the program, so no errors yet. :) – muru Sep 09 '14 at 23:21
  • 1
    @muru despite the weird name, it does actually explain how to run the program, i.e. as referred to in the OP "execute the code." – wxl Sep 09 '14 at 23:23
  • @JacobVlijm I strongly recommend making a habit of using the versioned name - in case you ever move to Arch Linux. – muru Sep 10 '14 at 12:25
  • @muru Ah, I see, in Arch Linux, python is not python2? – Jacob Vlijm Sep 10 '14 at 12:48
  • @JacobVlijm [It is `python3`](https://www.archlinux.org/news/python-is-now-python-3/). They broke the status quo and I think forced [this recommendation](http://legacy.python.org/dev/peps/pep-0394/). Fedora also intend to migrate soon, I think. – muru Sep 10 '14 at 12:56
  • @muru Thanks! that is useful information. I think I will replace my comment. – Jacob Vlijm Sep 10 '14 at 12:58
  • I really suggest using Idle (python2) or Idle 3 (python3), then you can test your code with pressing F5. – Jacob Vlijm Sep 10 '14 at 12:59

1 Answers1

4

Open a terminal by pressing CtrlAltT. If you remember where you saved the Python code file (say as first.py in the Desktop folder), use the following command to run it:

python2 ~/Desktop/first.py

If you're using Python 3.X replace python2 with python3 in the above command. On Ubuntu, python2 and python are the same, but it's always good practice to explicitly specify which version you're using.

You can also simply run python2 or python3 to get to an interactive shell. Another option is to use IPython Notebooks.

muru
  • 193,181
  • 53
  • 473
  • 722