You are not logged in.
Hi Joe. Very timely thread as it seems Zed has stopped having a comments/help section on his pages. I worked through to the point where he said now go back and go through everything we've learnt so far. So here I am!
vim
If anyone wants or needs to use a non-X editor here is how I set up my vim.
Most distros come with vim-tiny so you need to install the vim or vim-basic package.
If that is working you can test your settings in vim at the command prompt eg.
: syntax enable
Once you've found the settings you like you can put them in ~/.vimrc. Here's mine:
syntax enable
set background=dark
set autoindent
autocmd FileType python setlocal expandtab shiftwidth=4 softtabstop=4
style
Amazingly Pep 8 seems to agree very well with the examples in Kernighan and Ritchie! (not boasting, I'm only on chapter one)
attitude
The very first part of Zed's guide I think really set me off in the right direction.
eg.
The one skill that separates bad programmers from good programmers is attention to detail. In fact, it's what separates the good from the bad in any profession.
I really recommend anyone to read this in a quiet moment.
Well thanks Joe and good luck everyone
Offline
Hi Joe. Very timely thread as it seems Zed has stopped having a comments/help section on his pages.
We should all take a moment of silence for this. Zed has done more this decade through his own work and the links at Programming MotherF*****r.com for freely giving out the programming skills necessary to get started than anyone else that I can think of.
Plus, he uses Mutt for e-mail, so he's okay in my book.
Offline
in case someone doesn't want to learn and set up vim, I can recommend a nice and simple python ide I tried out recently http://ninja-ide.org/
Offline
in case someone doesn't want to learn and set up vim, I can recommend a nice and simple python ide I tried out recently http://ninja-ide.org/
Thats pretty nice thanks man better than using geany ... but geany is nice heh..
Offline
swearing is not a crime.
just in case, it's the one with the dash http://programming-motherfucker.com/
Last edited by zalew (2013-06-04 10:01:07)
Offline
Boolean Logic
We've already looked at some pretty basic examples of this. It's essentially just relay logic put into word terms. Is it ON or OFF? In python, these get "True" and "False" values. You can use variables, especially global variables, to set up a "switching system" for keeping up with the state of your program. This is especially useful for programs that don't execute in a linear fashion. This is an easy concept, right? a==True, or a==False? This can actually really help us when we start to look at how python evaluates more complex statements. This is one of those issues that I was speaking of where what looks simple at the onset can really take a lot of time during troubleshooting to determine where things might not have gone exactly as expected:
a = True
b = False
c = True
d = False
print "First We print a, and then b"
print a
print b
print "############"
print "Then, we evaluate NOT a"
print not a
print "Then a AND b"
print a and b
print "Then a OR b"
print a or b
print "...this gets harder with (a AND b) or a"
print (a and b) or a
print "############"
print "Or complex compares such as..."
print "(a and b) or (c and (not d))"
print (a and b) or (c and (not d)) #complex compares
print "These are difficult to figure out mentally"
print "############"
#comparison operators
# > < >= <= == !=
s = 7 > 3
print s
x = 8
y = 5
h = x >= y
print h
f = "hello" == "hello" #string compare
print f
print "##############"
g = 20.6 <= 18.3 #can use floats, integers, strings, etc.
print g
Notice that "=" assigns that (foo IS EQUAL to foo2) where "==" is used to check (IS foo equal to foo2). For those of you totally new to programming, in the comments in the above program, I included a list for comparison operators. These are good for setting up checks during boolean operations.
Also, "foo" which I'll use all of the time is a generic term to mean "any possible variable." I often forget that this may not mean anything to non-programmers, but it's a common term used by people who code.
Offline
Thanks for info about ninja-ide great program ! Makes writing alot easier. Hey DebianJoe you think I should go ahead and continue using this tool or go back to geany to get more hands on ?
Offline
I think that IDE's have their place. You'll be far more careful using a text editor, but IDEs can work too.
I use emacs...so, uhh, take that for what it's worth.
Offline
Aaah I just found this thread. Sorry I'm late professor! Will do my best to catch up and be a good student.
I love #! more than my own kids. I told them and they sympathized.
Offline
Well fellas off to sleep I work the night shift. Gotta remind myself to bookmark the boolean logic class pretty straightforward... I am picking up more and more I think I could practice on variables and stringing things together more. So far I love the class DebianJoe might have to slow it down a bit for me since this is my first programming language ever learned lol.
Offline
Also, "foo" which I'll use all of the time is a generic term to mean "any possible variable." I often forget that this may not mean anything to non-programmers, but it's a common term used by people who code.
Sometimes you will get some spam and eggs too
Thanks DebianJoe, these are great.
Offline
Sometimes you will get some spam and eggs too
I use those when I'm working on making a shubbery.
Offline
Well jump in buddy ! DebianJoe is doing a great job just finishing up his boolean logic class above.
Offline
String Hell and String Manipulation
Everyone likes strings, because we're creatures of language and speaking comes naturally to most of us. (I have noted that we're Linux users, so we're going to include internet speech with "speaking" as there's the age old adage that we're all actually located in dark basements around the world and only come out to feed.)
Anyhow, we've been looking at how you can use substitution methods or linear methods for placing string variables, decimal variable, etc. into raw output. Let's continue to look at how we can bend strings to our will. After a bit of practice with this, you'll be a full-fledged "stringmancer."
i = "I"
n = "!"
a = "%s am" % i
m = "stringmancer"
x = "%s a %s" % (a, m)
print x + n
print x[7:13] + x[-1:-2] + n
print i[0]
print a[2:4]
print x[7:17] + x[10:13] + n
Whoa! We're now summoning strings and sections of strings to do our bidding. I want you to really absorb what's going on here, because in this example this is just fun. The implications, though, are pretty powerful. What we're doing is first using substitutions to build a fun little string. Then, once we've constructed this string, we begin to treat it more like how the computer sees it. It's not a word so much as an array of characters that are stuck together. This allows us the ability to grab individual characters or ranges of characters and put them where we want them to go.
Notes on ranges:
Counting in most cases with computer programming, and certainly here: START WITH ZERO. Your kindergarten teacher screwed you all up by trying to get you to start with one, so we're going to fix that. In the word "DOG" the d is at position [0].
When you're using ranges in python, the [2:14] tells it to grab from position 2 to but not including 14. This is important, and will show up again in future discussions.
Position [-1] means the last character in the string, array, list, whatever else we may use in the future. [-2] means the next to last one, and this holds for further progression.
Now, take this and play with it some to get a feel for how ranges and array slicing works. If you're looking for some practice, write a few short sentences and use these methods to rearrange them into something else. For bonus point, make sure that they're formatted correctly.
Edit: I also wanted to point out that in the substitutions, the spaces are kept in place in the sentence. Spaces ARE characters. If you're using concatenation (that's the "+" that we use to shove strings together) you'll notice that there isn't a space.
Last edited by DebianJoe (2013-06-05 10:50:49)
Offline
Extra Stringmancing for the lazy.
A function that's often used in some interesting ways is really for those stringmancers among us who don't like to count. I thought I'd throw this one in for those who were unfamiliar with it, as it can be used to quickly give a numerical value to the amount of objects in a string (also tuples, lists, dictionary, but I'm getting ahead of myself here.)
i = ("Foolish string, bow unto your master and tell me," +
" how many characters are you currently using?")
print i
print len(i)
Offline
Whoa.... mind blown lol I get some of it but the two big ones im lost at are...
print x[7:13] + x[-1:-2] + n
print x[7:17] + x[10:13] + n
I am not really getting how that is all coming together I see to a point but if you could break it on down for me a little better.
Offline
i = ("Foolish string, bow unto your master and tell me," + " how many characters are you currently using?")
why the parenthesis and plus?
Offline
DebianJoe wrote:i = ("Foolish string, bow unto your master and tell me," + " how many characters are you currently using?")
why the parenthesis and plus?
agreed
Offline
@savalaserg. Those two lines are chopping a string we've already created.
x = "I am a stringmancer"
So x[7:13] pulls from this x-string "I am a (string)mancer" The x[-1:-2] isn't doing jack, and was intended to make questions arise because it's ordered incorrectly (I'm asking it to index backwards from left to right....which is totally wrong. if you put the -2 first, things change to actually work; we'll get there later). If you remove the ":-2" from the array, it will actually give you the last digit. The "+n" pulls our "!" back into the string statement.
print x[7:17] + x[10:13] + n Takes our string and grabs the I am a (str{ing}manc)er out and reorders it (stringmanc){ing}. Ask if this doesn't make sense.
Offline
Would
print 'Foolish string, bow unto your master and tell me ' \
'how many characters you are currently using.'
Be different?
Edit: Other than the fact that I have it print as opposed to assigning it to a variable. (I actually didn't mean to do that )
Last edited by DebianJoe (2013-06-05 07:59:18)
Offline
Would
print 'Foolish string, bow unto your master and tell me ' \ 'how many characters you are currently using.'
Be different?
import this
explains it all
Offline
@savalaserg. Those two lines are chopping a string we've already created.
x = "I am a stringmancer"
So x[7:13] pulls from this x-string "I am a (string)mancer" The x[-1:-2] isn't doing jack, and was intended to make questions arise because it's ordered incorrectly (I'm asking it to index backwards from left to right....which is totally wrong. if you put the -2 first, things change to actually work; we'll get there later). If you remove the ":-2" from the array, it will actually give you the last digit.
The "+n" pulls our "!" back into the string statement.
print x[7:17] + x[10:13] + n Takes our string and grabs the I am a (str{ing}manc)er out and reorders it (stringmanc){ing}. Ask if this doesn't make sense.
sadly a bit still lost you may have to put it in laymans for me LOL im trying.....
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat