Well, I've breezed through Python Coding the Hard Way, until exercise 10. It's a bit of a doozy, in that it introduces the use of "escape sequences" that allow you to format your strings just the way you want. So the most interesting two things I've learned about are these escape sequences and format sequences.
Format sequences include: """, ''' (which does the same thing), %r, %s, %c, %n, etc. I came upon while looking up the functions of these.
while the escape sequences are all listed in the exercise. In particular, I'm not sure of what \a, known as ASCII Bell; and \r, known as carriage return do. My best guess is that carriage return starts the program over again. This could be useful if you needed to take a limit approaching some value, I suppose. You could place the \r in an If-then statement, so that the program would eventually end.
I'm also not sure what the difference is between \f, known as ASCII form-feed; and \v, known as ASCII vertical tab. Both seem to do the same thing.
While looking for an answer, I also found a way to manipulate existing strings by listing the variable representing the string followed by the range of characters I'd like to cut out of it (where the first character is 0, second 1, etc.). This tutorial has been helpful in elucidating many different format sequences.
Tuesday, March 5, 2013
Monday, March 4, 2013
Mac OS 10.8.2: Saving An Executable Python Program
I've heard that coding is a useful skill to have. Recently, I tutored a student taking a Number Theory class. While I was able to assist him with the mathematical portion of his course, I was next to helpless in aiding him in his coding (in a version of Python 2 as it happens). Ultimately, I lost the student because I was unable to assist him in this area, which became more and more crucial as tasks became too complex to perform without automation through programming.
And so a flame was lit: I wanted to learn how to program, still do in fact. I spent all of this afternoon trying to get set up with a working Python platform that I could write and save Python programs in, and then run them. This was surprisingly difficult on my Mac OS 10.8.2, a.k.a. Mountain Lion. First I downloaded Python 3.3, but this proved difficult to implement, as I could not find a way to write and save programs.
So I turned back to the internet. At first I tried to make the 3.3 version work, but I gave up and settled for Python 2.7.2, which comes prepackaged with my Macbook Pro. Maybe, I'll figure out how to change this at some point, but for now, I press on with a slightly outdated version of Python. To get the platform to write, save and run programs, I watched and followed the directions of this Youtube video, which basically walked me through how to install and use a program called TextWrangler, that does the above-mentioned tasks quite well.
In case the video dies, basically, you go to http://www.barebones.com, download the TextWrangler program installer, install it, and write a simple program, remembering to save your program as a .py file. After you do that, the text will adopt colors depending on the nature of the characters in the code, and the code will be executable by dropping down #! from the TextWrangler menu, and choosing "Run in Terminal".
The video also talks about how to interface with the Terminal that Wrangler ends up sending your code to when you ask it to run your code. So far so good. I am hoping that with the basics set up, and a program that will successfully print "Hello World" for me, I will be able to use other materials originally written by and for PC users to hone my Python skills on my Mac. I am proceeding with this challenge set called "Learn Python the Hard Way." We shall see if I am able to follow, but I am hopeful now that I have taken the first step of setting up a system to save and implement my programs. We'll see how it goes!
And so a flame was lit: I wanted to learn how to program, still do in fact. I spent all of this afternoon trying to get set up with a working Python platform that I could write and save Python programs in, and then run them. This was surprisingly difficult on my Mac OS 10.8.2, a.k.a. Mountain Lion. First I downloaded Python 3.3, but this proved difficult to implement, as I could not find a way to write and save programs.
So I turned back to the internet. At first I tried to make the 3.3 version work, but I gave up and settled for Python 2.7.2, which comes prepackaged with my Macbook Pro. Maybe, I'll figure out how to change this at some point, but for now, I press on with a slightly outdated version of Python. To get the platform to write, save and run programs, I watched and followed the directions of this Youtube video, which basically walked me through how to install and use a program called TextWrangler, that does the above-mentioned tasks quite well.
In case the video dies, basically, you go to http://www.barebones.com, download the TextWrangler program installer, install it, and write a simple program, remembering to save your program as a .py file. After you do that, the text will adopt colors depending on the nature of the characters in the code, and the code will be executable by dropping down #! from the TextWrangler menu, and choosing "Run in Terminal".
The video also talks about how to interface with the Terminal that Wrangler ends up sending your code to when you ask it to run your code. So far so good. I am hoping that with the basics set up, and a program that will successfully print "Hello World" for me, I will be able to use other materials originally written by and for PC users to hone my Python skills on my Mac. I am proceeding with this challenge set called "Learn Python the Hard Way." We shall see if I am able to follow, but I am hopeful now that I have taken the first step of setting up a system to save and implement my programs. We'll see how it goes!
Subscribe to:
Posts (Atom)