La Boina Roja

The struggles off a future RHCE….


Leave a comment

Struggling through chapter 9, Reading Word Lists

So yeah, I am still struggling through “Think Python”. In chapter 9 you are supposed to download a document called “word.txt” from here. And then you are supposed to open the darn thing by typing this in the Python Shell (I use IDLE) fin = open(‘words.txt’). But of course when I typed it, I had to get a God darn error photo piangry.gif!

This was the error IOError: [Errno 2] No such file or directory: ‘words.txt’.

Since I wasn’t satisfied with what I learned from google, I decided to fiddle around myself, a known recipe for disaster photo loveit.gif  But when it hit me what the problem was, the Python Shell was looking for the file in the wrong place, I solved this issue in a minute.

How to check Python Shell’ s current working directory (the directory in which the Python Shell looks for data/programs). Go to File and then select Path Browser

selectpath

The Path Browser will open

pathbrowser

As you can see the path of the current working directory is /home/Roja, but I had the file saved in /home/Roja/thinkpython.

What did I do? I quickly found out I couldn’t move to the /thinkpython directory in the Path Browser. So I copied the file from /home/Roja/thinkpython to /home/Roja. It is not the most elegant solution I’ll admit  photo puh2.gif but it worked and I was able to continue with the book.

Remember, you can always do the cliccie for larger piccie!

(This is what the Python Shell looks like when it can’t find the file

cantfindfile

and this when it can

foundfile)

Advertisements


2 Comments

How to install IDLE in Fedora

This tutorial is for Python versions 2.****!

If you are going to clown around in Python, you’ ll need an interpreter. An interpreter is basically, a piece of software that translates the code you’ve written (source code) into something a computer can read(machine language).

interpret

(output = computer)

The interpreter I currently use is IDLE, it’s light, simple in use and ideal for beginners. IDLE stands for “Integrated DeveLopment Environment” and is written in and exclusively for python. This means you can’t write code for another language, like C in IDLE!

How to install IDLE:

  • open terminal
  • log in as root
  • type “yum install python-tools” (without the quotation marks) if you are using versions  of Fedora untill 21 or type “dnf install python-tools” (without the quotation marks) if you are using versions from Fedora 22

installatianIDLE
After the installation, you’ ll notice something interesting, unlike most programs IDLE can’t be found in the application menu (i.e. there is no Desktop icon to click on).  IDLE can only be opened through terminal and it, depending on your settings of course, doesn’t require you to be root to execute it.

How to open IDLE:

  • open terminal
  • type “idle”

idleterminal

The following screen will open:
pythonshell

WARNING: Do not close terminal while working in IDLE, if you do so IDLE will close too!!

Remember, you can do the cliccie for larger piccie and the first picture came from here.


2 Comments

How to install Swampy using Easy Install in Fedora

If you are going through “Think Python” you’ ll see that in chapter 4, you will be asked to install Swampy. What disappoints me about this is, there are no clear instructions on how to get the darn thing installed Photobucket Making this book, not really aimed at novices imo,  other than that it is a great book.

Before you do anything, I suggest to check which version of python you have running right now. You do this by opening the terminal and simply typing “python” without the quotation marks. It looks like this.

pythonversion

As you can see I am running python 2.7.3, the ”3″ isn’t important for this tutorial.

Now, we are going to get “Easy Install” , go to this site and scroll all the way down until you see this.

setuptoolversion

Click and download the version of setup tools which correspondents with the current version of python you have ( in my case it is setuptools-0.6c11-py2.7.egg). Make sure to download it into your downloads folder.

Open terminal  (if you are still in python, press “ctrl” and “d” at the same time to exit) and move to the downloads folder. You do this by typing “cd ~/Downloads”,  I also suggest logging in as root after you are in the downloads folder.

changedirectory

After you have logged in as root, you have to run the file you downloaded as a script, you do this by typing ” sh setuptools-0.6c11-py2.7.egg” .

easyinstall

After the installation is done, return to your home directory by typing “cd ~”. Now you are ready to install Swampy, finally! Type in terminal “easy_install Swampy”.

swampy

And you are done!

(If you want to be sure whether Swampy is installed or not, just type ” import swampy.TurtleWorld” in python. If you don’t get a message it’s installed, it will look like this:

check swampy

If it is not installed, you’ ll get some scary message Photobucket)

Remember you can always do the cliccie for a larger piccie!


1 Comment

Free online Python 2 courses!

As you know I am struggling to learn Python 2. In case you wonder why Python 2 and not Python 3? For me it was just a matter of convenience really, I couldn’t point out the differences between those 2 even if it could save my life Photobucket I started with “Learn Python the Hard Way” and it suggested to install Python 2, as you know I ru(i)n Linux on my Desktop and it had Python 2 pre- installed, so that was easy.

  1. Learn Python the Hard Way
  2. Code Academy
  3. Udacity , (CS101 Introduction to Computer Science)
  4. LearnPython.org
  5. The Python Tutorial (official tutorial by http://www.python.org)

 

“Learn Python the Hard Way” and the  require no registration Photobucket for the others you can use your Google account to log in. As you know I’m doing the first two courses right now and yes I am planning to the last 2 too! I like to listen to Sal Khan his voice and when you finish the course at Udacity, you’ll get a certificate with a picture of a robot on it Photobucket!

I would like to point out that “Learn Python the Hard Way” doesn’t seem to require much mathematical insight as far as I can see (I am at exercise 25 at the moment of writing), if you can think logical you’re fixed Photobucket The Code Academy’ s Python course is a different story though, this is a screen shot of 1 of their exercises:

cliccie for larger piccie

Photobucket

If your math is a bit rusty or you aren’t the most gifted mathematician around,  it might help to look at Khan Academy’s math curriculum.