├── 10. basic Functions intro.py ├── 11. Function Parameters.py ├── 12. Function Parameter Defaults.py ├── 13. Global and Local Vars.py ├── 14. modules.py ├── 15. common errors.py ├── 16. writing to a file.py ├── 17. appending to a file.py ├── 18. readingFiles.py ├── 19. classes.py ├── 2. simple print function and string rules.py ├── 20. user input.py ├── 21. more math.py ├── 22. understanding imports.py ├── 23. understanding imports 2.py ├── 23.-doc- examplemod.py ├── 24. python lists vs tuples.py ├── 25. python lists.py ├── 26. python list dimension.py ├── 27. reading CSV files.py ├── 27.-doc-example.csv ├── 28. multi line print.py ├── 29. dictionaries.py ├── 3. simple maths.py ├── 30. built in functions.py ├── 31. stdlib Standard Library - OS.py ├── 32. systut.py ├── 33. urllibtutorialvid.py ├── 34. regularexpression - video.py ├── 35. regular expressions and urllib for parsing.py ├── 36. tkinter basics 1 - Intro.py ├── 37. tkinter basics 2 - buttons.py ├── 38. tkinter basics 3 - Event Handling.py ├── 39. tkinter basics 4 - Menu bar.py ├── 4. variables.py ├── 40. tkinter basics 5 - Images, text.py ├── 41. threadingtutvid.py ├── 42. cx_Freeze ├── build │ └── exe.win-amd64-3.4 │ │ ├── _bz2.pyd │ │ ├── _hashlib.pyd │ │ ├── _lzma.pyd │ │ ├── _socket.pyd │ │ ├── _ssl.pyd │ │ ├── library.zip │ │ ├── python34.dll │ │ ├── reandurllib.exe │ │ └── unicodedata.pyd ├── reandurllib.py └── setup.py ├── 43. subprocess.py ├── 44. matplotlib 1 - intro.py ├── 45. matplotlib 2 - dynamic plotting and labels.py ├── 46. matplotlib 3 - styles.py ├── 47. matplotlib 4 - legends.py ├── 48. matplotlib 5 - bar charts and scatter.py ├── 49. matplotlib 6 - Plotting from a csv file.py ├── 5. while loop.py ├── 50. ftplibtutorialvid.py ├── 6. for loop.py ├── 7. if statement.py ├── 8. if else.py ├── 9. if elif else.py ├── LICENSE └── README.md /10. basic Functions intro.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello everyone and welcome to another python 3 basics video. In this video we 3 | will be discussing the basics of a function. 4 | 5 | The idea of a function is to assign a set of code, and possibly variables, 6 | known as parameters, to a single bit of text. You can think of it a lot like 7 | why you choose to write and save a program, rather than writing out the 8 | entire program every time you want to execute it. 9 | ''' 10 | 11 | # To begin a function, the keyword 'def' is used to notify 12 | # python of the impending function definition, which is what def 13 | # stands for. 14 | 15 | # from there, you type out the name you want to call your function. 16 | # it is important to choose a unique name, and also one that wont conflict 17 | # with any other functions you might be using. For example, you wouldn't 18 | # want to go calling your function print. 19 | 20 | 21 | # so here we've called our function example. After the name of the function, 22 | # you specify any parameters of that function within the parenthesis 23 | # parameters act as variables within the function, they are not necessary 24 | # to create a function, so first let's just do this without any parameters. 25 | 26 | def example(): 27 | # functions just run whatever code is encased with them. 28 | print('this code will run') 29 | z = 3 + 9 30 | print(z) 31 | 32 | # now if we just run this, we see nothing happens. We have to actually call 33 | # this function to execute, because all we've done so far is just define the 34 | # function and what it does. To run it, you can either type out the function in 35 | # the console like so: 36 | 37 | # or you can add it to the actual script itself: 38 | 39 | example() 40 | 41 | -------------------------------------------------------------------------------- /11. Function Parameters.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Welcome to another python 3 basics video, in this video we will carryon with 3 | functions. In the last video you were shown a very basic function, without 4 | any parameters 5 | 6 | In this video, lets include a parameter, and give this function more... 7 | functionality. 8 | ''' 9 | 10 | 11 | # changed name to simple math, to better describe our intentions 12 | ''' 13 | Now we've specified 2 parameters for our function, calling them num1 14 | and num2, for number 1 and number 2. 15 | 16 | Now, we carry on writing our function, where we can specify what we 17 | desire to do with num1 and num2. 18 | 19 | in our case, we want to do simple addition. 20 | ''' 21 | def simple_addition(num1,num2): 22 | answer = num1 + num2 23 | print('num1 is', num1) 24 | # so here the answer variable will be filled with whatever 25 | # num 1 plus num 2 is. 26 | print(answer) 27 | # then at the end, we want to print out the answer to the client 28 | 29 | 30 | ''' 31 | so now we run this, and when we want to do some simple_addition... 32 | ''' 33 | 34 | simple_addition(5,3) 35 | # here we will do 5 + 3, for an answer of 8 36 | 37 | ''' 38 | There is no limit to the amount of variables you can have. The only thing 39 | you will want to look out for at this point is the order of the variables, 40 | 41 | as well as the quantity. 42 | 43 | You can protect yourself from order by doing the following in your calling: 44 | ''' 45 | 46 | simple_addition(num1=3,num2=5) 47 | # or more clearly # 48 | simple_addition(num2=3,num1=5) 49 | 50 | # in this case, if you are clear in your specification, it does not matter 51 | # the order. Most people, however, do not write out the variables like that, 52 | # they just maintain the order. 53 | 54 | 55 | #finally, it is important to use the proper quantity of variables. 56 | 57 | # will not work, too many vars 58 | simple_addition(3,5,6) 59 | 60 | # will not work, too few vars 61 | simple_addition(3) 62 | 63 | 64 | 65 | 66 | ''' 67 | That's it for this video, in the next video I willbe covering default variable 68 | assignments. 69 | 70 | ''' 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /12. Function Parameter Defaults.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello again and welcome to another python 3 basics video. In this video we 3 | will be covering default function parameters 4 | ''' 5 | 6 | # so normally, you write a function like so: 7 | def simple(num1,num2): 8 | pass 9 | 10 | # What you can do, however is: 11 | 12 | def simple(num1, num2=5): 13 | # what this does is specify a "default parameter" just in case 14 | # one is not specified. 15 | # this is useful so all parameters dont need to be called 16 | # every single time. Generally, this is used for modules. 17 | # an example would be a module that makes windows for users. 18 | pass 19 | 20 | 21 | # so here, the user must specifiy width and height, but a font of times 22 | # new roman, for example, is the default so they dont have to say that 23 | # every single time. 24 | 25 | def basic_window(width,height,font='TNR'): 26 | # let us just print out everything 27 | print(width,height,font) 28 | 29 | 30 | 31 | # now, when we call basic_window, we can break a rule we established 32 | # earlier: 33 | 34 | # see, only two parameters, when we require 3 35 | basic_window(350,500) 36 | 37 | # we can do this because there is a default if font is not specified. Should 38 | # a user wish to specify however, they can do 39 | 40 | basic_window(350,500,font='courier') 41 | 42 | # here, it is just important that you place any parameters with default values 43 | # at the very end, to avoid trouble when calling the function down the road. 44 | -------------------------------------------------------------------------------- /13. Global and Local Vars.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Welcome to another python 3 basics video, in this video we're going to now 3 | discuss the concept of global and local variables. 4 | 5 | When users begin using functions, they can quickly become confused when it comes 6 | to global and local variables... getting a the dreaded variable is not defined 7 | even when they clearly see that it is... or so they think. 8 | 9 | These terms of global and local 10 | correspond to a variable's reach within a script or program. 11 | 12 | A global variable is one that can be accessed anywhere 13 | 14 | A local variable is the opposite, it can only be accessed within its frame. 15 | 16 | The difference is that global variables can be accessed locally, but not modified 17 | locally inherently. 18 | 19 | A local variable cannot be accessed globally, inherently. 20 | Now, dont worry about committing 21 | that to memory right now, I think it makes a lot more sense when you just 22 | see and do it, so let's do that. 23 | 24 | ''' 25 | # this variable has no parent function, but is actually NOT a global variable. 26 | # it just so happens that it is committed to memory before the function is called 27 | # so we are able to iterate, or call it out, but we cannot do much else. 28 | 29 | x = 6 30 | 31 | def example(): 32 | # z, however, is a local variable. 33 | z = 5 34 | # this works 35 | print(z) 36 | 37 | example() 38 | # this does not, which often confuses people, because z has been defined 39 | # and successfully even was called... the problem is that it is a local 40 | # variable only, and you are attempting to access it globally. 41 | 42 | print(z) 43 | 44 | # next up is an example that i've seen cause even more trouble, and that's 45 | # the attempt to play with a global variable locally. The reason why this 46 | # is so troubling is because you can access it... you just cannot play 47 | # with it, and this often frustrates people for a while. 48 | 49 | 50 | x = 6 51 | 52 | def example2(): 53 | # works 54 | print(x) 55 | print(x+5) 56 | 57 | # but then what happens when we go to modify: 58 | x+=6 59 | 60 | # so there we attempted to take the x var and add 6 to it... but now 61 | # we are told that we cannot, as we're referencing the variable before 62 | # its assignment. 63 | 64 | ''' 65 | So now you know the rules, what can we do about it? 66 | ''' 67 | x = 6 68 | 69 | def example3(): 70 | # what we do here is defined x as a global variable. 71 | global x 72 | # now we can: 73 | print(x) 74 | x+=5 75 | print(x) 76 | 77 | 78 | 79 | 80 | ''' 81 | So that is all for global and local, though I will show 1 last thing. 82 | 83 | Sometimes you want a sort of global variable as a starting point, but 84 | you do not actually wish to modify the "global" variable outside of the 85 | functions themselves. You can just do the following: 86 | ''' 87 | 88 | def example4(): 89 | globx = x 90 | # now we can: 91 | print(globx) 92 | globx+=5 93 | print(globx) 94 | 95 | 96 | # and that's it! 97 | 98 | # hopefully that will help some of you from pulling your hair out for 30 minutes 99 | # trying to figure out what the heck is going on to reality. This is something 100 | # that snagged me pretty good when i was starting out. 101 | -------------------------------------------------------------------------------- /14. modules.py: -------------------------------------------------------------------------------- 1 | ''' 2 | At this point, you've got all the basics necessary to start employing modules. 3 | 4 | We still have to teach classes, among a few other necessary basics, but now 5 | would be a good time to talk about modules. 6 | 7 | 8 | IF you are using linux, installing python modules is incredibly stupid easy. 9 | For programming, linux is just lovely when it comes to installing packages 10 | for just about whatever. I believe mac allows similar treatment, though I've 11 | not done it myself. 12 | 13 | When I was first starting out with python, installing modules was one of the 14 | most difficult things, for a few reasons. 15 | 16 | mainly, with windows, there are quite a few methods for installation of modules. 17 | you've got pip install setuptools, download and click'n'drag, or setup.py 18 | 19 | At the time of starting python, a large part of my troubles was that I didn't 20 | actually understand the process of getting a module, and this is obviously very 21 | frustrating. 22 | 23 | Python is going to look in a few places for modules. 24 | 25 | That's going to be site-packages and the script's directory for the most part. 26 | There are some other places you can use, but let's leave them out of it. Knowing 27 | this allows you yourself to make your own modules, in the form of just a script 28 | if you want, putting that in the same directory as your main script, and then 29 | using import to bring it on board, you can also place multiple scripts in a dir 30 | and use that. Once you begin to familiarize yourself with this, and understand 31 | how and why things work, it will help you a lot. 32 | 33 | Enough on that though, let's install stuff. 34 | 35 | So I will show linux installation first, because it takes about 10 seconds to 36 | show 37 | 38 | 39 | 40 | 41 | now for python, the accepted method these days is setup.py 42 | 43 | So when you download a python module, 44 | 45 | http://www.pyqtgraph.org/ 46 | 47 | 48 | 49 | ... now finally, you can use downloaders, here is a large stash 50 | of easy to use python installers for windows: 51 | http://www.lfd.uci.edu/~gohlke/pythonlibs/ 52 | 53 | ''' 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /15. common errors.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to another python 3 basics video. 3 | 4 | In this video we'll be discussing some of the basics to 5 | debugging. In my videos, I get a lot of questions for 6 | help where people have errors and are not sure what 7 | the problem is. If they used some extremely simple debugging, 8 | they'd realize how obvious the answer is. 9 | 10 | Most of the time, the problem is a typo, followed closely by 11 | a misunderstanding of indentation and standards. 12 | 13 | so standards how are how organize your code. With python, 14 | unlike most languages, you define blocks of code like 15 | functions by indentation. Most python editors will automatically 16 | indent for you where it is necessary. With this, if you are ever 17 | coding along and find python automatically indenting you where 18 | you don't think it should, this should raise a flag for you to 19 | figure out. 20 | 21 | 22 | (show a basic function... ) 23 | 24 | There are some more in-depth common-issues that you'll 25 | find from time to time, you can find more debugging videos 26 | by searching for debuggin in my channel. For now I will just 27 | keep these ones basic. 28 | 29 | The first error we'll discuss is the NameError: is not defined 30 | 31 | ''' 32 | 33 | ''' 34 | As obvious as this might appear to you, this gets people amazingly 35 | frequently. Just learn to recognize the "is not defined" 36 | 37 | chances are you typoed the definition of the variable or when you 38 | are referring to it. 39 | ''' 40 | variable = 55 41 | #print(varaible) 42 | 43 | 44 | ''' 45 | Next up, we have indentation issues. 46 | 47 | You will see "expected an indented block" as a 48 | popup when you never enter an indented block for 49 | something that requires it, like a function. 50 | ''' 51 | 52 | ''' 53 | def task1(): 54 | 55 | 56 | def task2(): 57 | print('more tasks') 58 | 59 | ''' 60 | 61 | 62 | ''' 63 | unexpected indent... 64 | ''' 65 | 66 | def task(): 67 | print ('stuff') 68 | 69 | print('more stuff') 70 | 71 | print('stuff') 72 | 73 | 74 | 75 | ''' 76 | EOL while scanning string literal 77 | ''' 78 | 79 | 80 | def task(): 81 | print('some people find themselves committing this too 82 | 83 | 84 | print('ouch...') 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /16. writing to a file.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to another python 3 basics tutorial video. 3 | 4 | In this video we're going to cover the basics of writing to a file. 5 | 6 | It should be noted that there are two methods for saving data to a file, and 7 | those are writing and appending. Writing to a file will write that bit 8 | of data, whatever it is, solely, to the file. This means if there was anything 9 | there before, it will be gone if you use write. 10 | 11 | If you use append, then you will basically add to whatever is previously there. 12 | 13 | I will be showing both methods, but write first. 14 | ''' 15 | 16 | 17 | # so here we have some simple text, but we also threw in a \n to 18 | # denote a new line, this will start a newline in the file that we write to 19 | text = 'Sample Text to Save\nNew line!' 20 | 21 | # notifies Python that you are opening this file, with the intention to write 22 | saveFile = open('exampleFile.txt','w') 23 | # actually writes the information 24 | saveFile.write(text) 25 | # It is important to remember to actually close the file, otherwise it will 26 | # hang for a while and could cause problems in your script 27 | saveFile.close() 28 | 29 | 30 | -------------------------------------------------------------------------------- /17. appending to a file.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Alright, so now we get to appending a file in python. I will just state again 3 | that writing will clear the file and write to it just the data you specify in 4 | the write operation. Appending will simply take what was already there, and add 5 | to it. 6 | 7 | That said, when you actually go to add to the file, you will still use 8 | .write... you only specify that you will be appending instead of writing 9 | when you open the file and specify your intentions. 10 | 11 | ''' 12 | 13 | 14 | # so here, generally it can be a good idea to start with a newline, since 15 | # otherwise it will append data on the same line as the file left off. 16 | # you might want that, but I'll use a new line. 17 | # another option used is to first append just a simple newline 18 | # then append what you want. 19 | appendMe = '\nNew bit of information' 20 | 21 | appendFile = open('exampleFile.txt','a') 22 | appendFile.write(appendMe) 23 | appendFile.close() 24 | 25 | -------------------------------------------------------------------------------- /18. readingFiles.py: -------------------------------------------------------------------------------- 1 | ''' 2 | So now that you know how to write and append files, we can learn how 3 | to read from files! 4 | ''' 5 | 6 | # similar syntax as you've seen, 'r' for read. You can just throw a .read() at 7 | # the end, and you get: 8 | readMe = open('exampleFile.txt','r').read() 9 | print(readMe) 10 | 11 | 12 | ''' 13 | Now that is great and useful, but a lot of times people want to read by line. 14 | There are a few things you can do here, but probably the easiest is to: 15 | ''' 16 | 17 | # this will instead read the file into a python list. 18 | readMe = open('exampleFile.txt','r').readlines() 19 | print(readMe) 20 | 21 | -------------------------------------------------------------------------------- /19. classes.py: -------------------------------------------------------------------------------- 1 | class calculator: 2 | 3 | def addition(x,y): 4 | added = x + y 5 | print(added) 6 | 7 | def subtraction(x,y): 8 | sub = x - y 9 | print(sub) 10 | 11 | def multiplication(x,y): 12 | mult = x * y 13 | print(mult) 14 | 15 | def division(x,y): 16 | div = x / y 17 | print(div) 18 | 19 | 20 | 21 | 22 | 23 | 24 | ''' 25 | >>> calculator.subtraction(5,8) 26 | -3 27 | >>> calculator.multiplication(3,5) 28 | 15 29 | >>> calculator.division(5,3) 30 | 1.6666666666666667 31 | >>> calculator.addition(5,2) 32 | 7 33 | >>> 34 | 35 | ''' 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /2. simple print function and string rules.py: -------------------------------------------------------------------------------- 1 | print('This is an example of the print function') 2 | 3 | # while we are here, let's talk a bit about strings # 4 | 5 | print("double quotes") 6 | 7 | print('or single...') 8 | 9 | print('concatena'+'tion') 10 | 11 | print('can do this',5) 12 | #print('cannot do this:'+5) 13 | 14 | #print('Can't do this') 15 | print('you\'ll have success here') 16 | print("you'll have sucess here too") 17 | 18 | 19 | 20 | ''' 21 | These are just the basics of strings for now, you can also pass 22 | variables and do all sorts of neat things. 23 | ''' 24 | -------------------------------------------------------------------------------- /20. user input.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Sometimes in basic gui, or graphical user interphase, applications, 3 | some input from a user might be wanted. To do this, we use the 4 | built-in input functionality with python 3. If you are familiar with Python 2.7, 5 | the python 3 input function acts like the python 2 raw_input function. 6 | ''' 7 | 8 | 9 | x = input('test:') 10 | 11 | print(x) 12 | 13 | 14 | # simple enough 15 | -------------------------------------------------------------------------------- /21. more math.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Python is a very popular programming language for data processing of many types 3 | With data processing, a lot of math is used often times. So, besides the basic 4 | math, we should cover some more in depth operations. Luckily for us, python 3 5 | has some great built in modules that we can utilize. 6 | ''' 7 | 8 | import statistics 9 | 10 | example_list = [5,2,5,6,1,2,6,7,2,6,3,5,5] 11 | 12 | x = statistics.mean(example_list) 13 | print(x) 14 | 15 | y = statistics.median(example_list) 16 | print(y) 17 | 18 | z = statistics.mode(example_list) 19 | print(z) 20 | 21 | a = statistics.stdev(example_list) 22 | print(a) 23 | 24 | b = statistics.variance(example_list) 25 | print(b) 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /22. understanding imports.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Now that we've used a module, statistics, it would be a good time to 3 | explain some import practices. As with many things in programming, there 4 | are many ways to import modules, but there are certainly some best 5 | practices. 6 | 7 | So first, when you import a module, you are basically loading that 8 | module into memory. Think of a module like a script. Many if not most modules 9 | are just a single python script. So, when you go to import it, you use the file 10 | name. This can help keep code clean and easy to read. Many python developers 11 | just program everything in 1 script. Other developers, say from a language like 12 | java are going to be very used to doing lots of imports with a file for each 13 | type of job that's happening. Just like there are many ways to import, there 14 | are many more ways to program. 15 | 16 | So let's talk about basic importing: 17 | ''' 18 | 19 | # here, we have imported the entire statistics module, and we can reference 20 | # any of the functions within it. 21 | # this loads that entire module, and will run any code that is 22 | # set to run in the module 23 | # remember if name == main? Again, that's what we use to stop code 24 | # from running when we just want to import. 25 | import statistics 26 | 27 | example_list = [5,2,5,6,1,2,6,7,2,6,3,5,5] 28 | 29 | # now, to use our import above, since we just imported statistics, 30 | # we must preceed any funciton wi thin statistics with a statistics. 31 | # so, for example, to access the mean() function within statistics: 32 | 33 | print(statistics.mean(example_list)) 34 | 35 | 36 | # and that's it. Let's look briefly at the statistics module and the mean 37 | # function...c:/python34/lib/statistics (not in site-packages) 38 | # take note of the package's location, we will talk more on that soon. 39 | # so now you see that statistics is just a python script, and mean is 40 | # just another function. 41 | 42 | # sometimes, you will see people who import things "as". This 43 | # helps to keep typing to a minimum. For example 44 | 45 | import statistics as s 46 | 47 | # above we've imported statistics as s, so when we want to reference something 48 | # within statistics, we just need to do s. now. 49 | 50 | print(s.mean(example_list)) 51 | 52 | # What if you don't even want to type that S though? Well there's an app for that! 53 | # you can just import all of the functions like so: 54 | 55 | from statistics import mean 56 | 57 | # so here, we've imported the mean function only. 58 | 59 | print(mean(example_list)) 60 | 61 | # and again we can do as 62 | 63 | from statistics import mean as m 64 | 65 | print(m(example_list)) 66 | 67 | # what if we want to import other functions? 68 | 69 | from statistics import mean, median 70 | 71 | # here we imported 2 functions. 72 | 73 | print(median(example_list)) 74 | 75 | # what if we want to use the as as well???? 76 | 77 | from statistics import mean as m, median as d 78 | 79 | print(m(example_list)) 80 | print(d(example_list)) 81 | 82 | 83 | # What if we want to just import everything from statistics like we did initially 84 | # but we dont want to type the statistics because we have 85 | # fat fingers and this will just slow us down?. 86 | 87 | from statistics import * 88 | 89 | print(mean(example_list)) 90 | -------------------------------------------------------------------------------- /23. understanding imports 2.py: -------------------------------------------------------------------------------- 1 | import examplemod 2 | 3 | examplemod.ex('test') 4 | -------------------------------------------------------------------------------- /23.-doc- examplemod.py: -------------------------------------------------------------------------------- 1 | 2 | def ex(data): 3 | print(data) 4 | -------------------------------------------------------------------------------- /24. python lists vs tuples.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Lets compare python lists and tuples. They are often confused. 3 | 4 | A python tuple is immutable, meaning you cannot change it. That said, 5 | less space is going to be required to generate a tuple, and you can use it 6 | for things where you don't want the tuple to change. To define a tuple, you 7 | either use round brackets, or no brackets. A popular use for this is multiple 8 | variable assignments from a function return. 9 | 10 | For example, you might see something like: 11 | ''' 12 | 13 | def example(): 14 | return 15, 12 15 | 16 | x, y = example() 17 | print(x,y) 18 | 19 | # in the above case, we have used a tuple and cannot modify it... and 20 | # we definitely do not want to! 21 | 22 | 23 | 24 | ''' 25 | A python list is mutable, and can contain just about any python data. to 26 | define a list, you use square brackets. 27 | 28 | ''' 29 | 30 | x = [1,3,5,6,2,1,6] 31 | 32 | ''' 33 | You can then reference the whole list like: 34 | ''' 35 | print(x) 36 | 37 | # or a single element by giving its index value. 38 | # index values start at 0 and go up by 1 each time 39 | 40 | print(x[0],x[1]) 41 | 42 | 43 | 44 | ''' 45 | So again, a python tuple is a colleciton of data that is immutable. 46 | Generally the only time you will use this is when it is extremely 47 | important that the tuple is immutable. 48 | 49 | Then you have a python list, which is mutable and highly malleable. 50 | 51 | A tuple is defined by no containing brackets, or round brackets. A list 52 | is defined by square brackets. 53 | ''' 54 | -------------------------------------------------------------------------------- /25. python lists.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Since lists are mutable, this means that we will be using lists for 3 | things where we might intend to manipulate the list of data, so how 4 | can we do that? Turns out we can do all sorts of things. 5 | 6 | We can add, remove, count, sort, search, and do quite a few other things 7 | to python lists. 8 | ''' 9 | 10 | # first we need an example list: 11 | 12 | x = [1,6,3,2,6,1,2,6,7] 13 | 14 | # lets add something. 15 | 16 | # we can do .append, which will add something to the end of the list, like: 17 | 18 | x.append(55) 19 | 20 | print(x) 21 | 22 | 23 | # what if you have an exact place that you'd like to put something in a list? 24 | 25 | x.insert(2,33) 26 | 27 | print(x) 28 | 29 | # so the reason that went in the 3rd place, again, is because we start 30 | # at the zero element, then go 1, 2.. .and so on. 31 | 32 | # now we can remove things... .remove will remove the first instance 33 | # of the value in the list. If it doesn't exist, there will be an error: 34 | 35 | x.remove(6) 36 | 37 | print(x) 38 | 39 | #next, remember how we can reference an item by index in a list? like: 40 | 41 | print(x[5]) 42 | 43 | # well we can also search for this index, like so: 44 | 45 | print(x.index(1)) 46 | 47 | # now here, we can see that it actually returned a 0, meaning the 48 | # first element was a 1... when we knew there was another with an index of 5. 49 | # so instead we might want to know before-hand how many examples there are. 50 | 51 | print(x.count(1)) 52 | 53 | # so we see there are actually 2 of them 54 | 55 | # we can also sort the list: 56 | x.sort() 57 | 58 | print(x) 59 | 60 | 61 | # what if these were strings? like: 62 | 63 | y = ['Jan','Dan','Bob','Alice','Jon','Jack'] 64 | 65 | y.sort() 66 | print(y) 67 | 68 | # noooo problemo! 69 | 70 | 71 | # You can also just reverse a list, but, before we go there, we should note that 72 | # all of these manipulations are mutating the list. keep in mind that any 73 | # changes you make will modify the existing variable. 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /26. python list dimension.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Lists that we have covered so far have all been 1 dimensional, 3 | but you can have lists within lists within lists within lists if you want. 4 | 5 | Often times, if you want to have lists within lists, your superior choice 6 | will be something like dictionaries, which we'll get to, but 7 | there will be times when a multi dimensional list is the best choice. 8 | ''' 9 | 10 | x = [[2,6],[6,2],[8,2],[5,12]] 11 | 12 | # so we already know how to reference elements in a list, we can do: 13 | 14 | print(x[2]) 15 | 16 | # but we can also take this deeper since we have more dimensions now: 17 | 18 | print(x[2][1]) 19 | 20 | # this can go on indefinitely with very thick lists. 21 | # you might see how this can quickly get messy, let's consider 22 | # how to properly display lists in code that have multiple dimensions. 23 | # you might not typically hard code multi dimensional lists, 24 | # but it's good to know how to do it: 25 | 26 | 27 | y = [[5,2], 28 | [6,2], 29 | [3,1], 30 | [12,6] 31 | ] 32 | 33 | # this is slightly cleaner, and python automatically understands it: 34 | 35 | print(y) 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /27. reading CSV files.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Next up, let us cover the reading of CSV files into memory. 3 | 4 | One of the more popularly requested file types for reading into 5 | memory is csv files, so let us cover them. 6 | 7 | here I will just create a simple example.csv file 8 | 9 | 10 | 11 | 12 | ''' 13 | import csv 14 | 15 | with open('example.csv') as csvfile: 16 | readCSV = csv.reader(csvfile, delimiter=',') 17 | for row in readCSV: 18 | print(row) 19 | print(row[0]) 20 | print(row[0],row[1],row[2],) 21 | 22 | 23 | #### next part.... 24 | 25 | import csv 26 | 27 | with open('example.csv') as csvfile: 28 | readCSV = csv.reader(csvfile, delimiter=',') 29 | dates = [] 30 | colors = [] 31 | for row in readCSV: 32 | color = row[3] 33 | date = row[0] 34 | 35 | dates.append(date) 36 | colors.append(color) 37 | 38 | print(dates) 39 | print(colors) 40 | 41 | 42 | #### now you want to maybe ask some questions with data... 43 | # what day was the color green let's ask? 44 | 45 | import csv 46 | 47 | with open('example.csv') as csvfile: 48 | readCSV = csv.reader(csvfile, delimiter=',') 49 | dates = [] 50 | colors = [] 51 | for row in readCSV: 52 | color = row[3] 53 | date = row[0] 54 | 55 | dates.append(date) 56 | colors.append(color) 57 | 58 | print(dates) 59 | print(colors) 60 | 61 | # now, remember our lists? 62 | 63 | whatColor = input('What color do you wish to know the date of?:') 64 | coldex = colors.index(whatColor) 65 | theDate = dates[coldex] 66 | print('The date of',whatColor,'is:',theDate) 67 | 68 | 69 | #but..................... what if we enter something that is non-existent? 70 | # oh noes, an error! 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /27.-doc-example.csv: -------------------------------------------------------------------------------- 1 | 1/2/2014,5,8,red 2 | 1/3/2014,5,2,green 3 | 1/4/2014,9,1,blue -------------------------------------------------------------------------------- /28. multi line print.py: -------------------------------------------------------------------------------- 1 | ''' 2 | So now I just briefly want to cover multi line print outs. 3 | I remember making beautiful print outs as sort of guis, but I would do 4 | print and then print out the line, then another print... and so on, 5 | but you can actually do multi line prints with just 1 print. So let's see: 6 | ''' 7 | 8 | 9 | 10 | print( 11 | ''' 12 | This 13 | is 14 | a 15 | test 16 | ''' 17 | ) 18 | 19 | print( 20 | ''' 21 | So it works like a multi-line 22 | comment, but it will print out. 23 | 24 | You can make kewl designs like this: 25 | 26 | ============== 27 | | | 28 | | | 29 | | BOX | 30 | | | 31 | | | 32 | ============== 33 | ''' 34 | ) 35 | -------------------------------------------------------------------------------- /29. dictionaries.py: -------------------------------------------------------------------------------- 1 | ''' 2 | One of the most useful data types in python is the python 3 | dictionary. 4 | 5 | If you are familiar with other languages, think of it like an associative 6 | array. 7 | 8 | The idea of the dictionary is to have what are called keys and values. Despite 9 | being ordered if you print a dictionary out, there is no actual 10 | order to dictionaries. 11 | 12 | All keys are unique 13 | 14 | So before we used two lists and assumed their association, searched for index, 15 | and found information about 1 item in 1 list from another. 16 | 17 | Now here, everything is contained in the same location, and makes more sense 18 | 19 | Let us show an example: 20 | 21 | ''' 22 | 23 | # Dictionary of names and ages. 24 | exDict = {'Jack':15,'Bob':22,'Alice':12,'Kevin':17} 25 | 26 | print(exDict) 27 | 28 | # How old is Jack? 29 | 30 | print(exDict['Jack']) 31 | 32 | 33 | # We find a new person that we want to insert: 34 | 35 | exDict['Tim'] = 14 36 | 37 | print(exDict) 38 | 39 | # Tim just had a birthday though! 40 | 41 | exDict['Tim'] = 15 42 | 43 | print(exDict) 44 | 45 | 46 | # Then Tim died. 47 | 48 | del exDict['Tim'] 49 | 50 | print(exDict) 51 | 52 | # next we want to track hair color 53 | 54 | exDict = {'Jack':[15,'blonde'],'Bob':[22, 'brown'],'Alice':[12,'black'],'Kevin':[17,'red']} 55 | 56 | print(exDict['Jack'][1]) 57 | 58 | 59 | -------------------------------------------------------------------------------- /3. simple maths.py: -------------------------------------------------------------------------------- 1 | 1+3 2 | 4*4 3 | 5-2 4 | 5/2 5 | 6 | 7 | 8 | #exponents 9 | 4**4 10 | 11 | 4.5*2 12 | 13 | #Integers whole numbers 14 | 15 | 16 | -------------------------------------------------------------------------------- /30. built in functions.py: -------------------------------------------------------------------------------- 1 | # Some of the built in functions # 2 | 3 | ''' 4 | I cannot cover them all in 1 video, but there are quite a few that I find 5 | myself needing semi-regularly. Also, some we've already covered, 6 | or are fairly complex, so I will cover them later. 7 | 8 | I will post a link in the description to the list of all built in functions. 9 | 10 | https://docs.python.org/3/library/functions.html 11 | 12 | With that, we'll go alphabetically. 13 | ''' 14 | 15 | ### absolute value ### 16 | 17 | ''' 18 | Absolute value bars just turn anything into the distance it is from 0. Basically, 19 | it will take your negative numbers, if you have any, and make them positive. 20 | 21 | I find myself using this for % change, esp when negative numbers are in question. 22 | So say you go from -6 to -9. Typical % change will say this is a -33.33% change.. 23 | even though this was a positive movement. 24 | 25 | There are many other uses for it though. 26 | ''' 27 | 28 | exNum1 = -5 29 | exNum2 = 5 30 | 31 | print(abs(exNum1)) 32 | 33 | if abs(exNum1) == exNum2: 34 | print('True!') 35 | 36 | 37 | ### Help ### 38 | 39 | ''' 40 | Probably one of the most under-utilized commands in Python, most people 41 | do not even know it exists.... HELP! Here, you can 42 | just type help() empty params... or put something in there. 43 | ''' 44 | 45 | 46 | ''' 47 | With empty parameters, it begins an interactive session, where you can 48 | just type in the name of the function that you are looking for 49 | ''' 50 | help() 51 | 52 | ''' 53 | Or... 54 | ''' 55 | 56 | import time 57 | help(time) 58 | 59 | 60 | ### Max and Min ### 61 | 62 | ''' 63 | How to find the maximum or highest number in a list... 64 | or how to find the lowest or minimum number in a list. 65 | ''' 66 | 67 | exList = [5,2,1,6,7] 68 | 69 | largest = max(exList) 70 | print(largest) 71 | 72 | smallest = min(exList) 73 | print(smallest) 74 | 75 | 76 | ### Rounding ### 77 | ''' 78 | This will round to the nearest whole. There are other commands 79 | like ceiling and floor, if you require rounding up or down... but 80 | for now, let's just round: 81 | ''' 82 | 83 | x = 5.622 84 | x = round(x) 85 | print(x) 86 | 87 | y = 5.256 88 | y = round(y) 89 | print(y) 90 | 91 | 92 | ### Converting data types! ### 93 | 94 | ''' 95 | Many times, like reading data in from a file, you might find 96 | the datatype is incorrect, like when we mean to have integers, 97 | but they are currently in string form, or visa versa. 98 | ''' 99 | 100 | intMe = '55' 101 | intMe = int(intMe) 102 | print(intMe) 103 | 104 | 105 | stringMe = 55 106 | stringMe = str(stringMe) 107 | print(stringMe) 108 | 109 | floatMe = 55 110 | floatMe = float(floatMe) 111 | print(floatMe) 112 | 113 | ''' 114 | You can also convert floats to strings, strings to floats... and more. Just make sure you do a valid operation. 115 | You still cannot convert 'h' to a float. 116 | ''' 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /31. stdlib Standard Library - OS.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Now we're going to cover the standard library, or stdlib 3 | 4 | First up, os 5 | ''' 6 | 7 | import os 8 | 9 | ''' 10 | os can be used mostly for directory operations. Operations like 11 | finding out where you are, changing that, making directories, and more. 12 | 13 | Let's see some examples: 14 | ''' 15 | 16 | # current working directory 17 | 18 | curDir = os.getcwd() 19 | print(curDir) 20 | 21 | 22 | 23 | # make another directory: 24 | 25 | os.mkdir('newDir') 26 | 27 | # remove: 28 | # 29 | 30 | import time 31 | 32 | time.sleep(2) 33 | os.rename('newDir','newDir2') 34 | time.sleep(2) 35 | os.rmdir('newDir2') 36 | 37 | 38 | ''' 39 | There are more things you can do, but these are some of the more basics. 40 | ''' 41 | -------------------------------------------------------------------------------- /32. systut.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | #sys.stderr.write('This is stderr text\n') 4 | #sys.stderr.flush() 5 | #sys.stdout.write('This is stdout text\n') 6 | 7 | #print(sys.argv) 8 | def main(arg): 9 | print(arg) 10 | 11 | 12 | main(sys.argv[1]) 13 | -------------------------------------------------------------------------------- /33. urllibtutorialvid.py: -------------------------------------------------------------------------------- 1 | 2 | import urllib.request 3 | import urllib.parse 4 | 5 | #x = urllib.request.urlopen('https://www.google.com') 6 | #print(x.read()) 7 | ''' 8 | url = 'http://pythonprogramming.net' 9 | values = {'s':'basic', 10 | 'submit':'search'} 11 | 12 | data = urllib.parse.urlencode(values) 13 | data = data.encode('utf-8') 14 | req = urllib.request.Request(url,data) 15 | resp = urllib.request.urlopen(req) 16 | respData = resp.read() 17 | 18 | print(respData) 19 | ''' 20 | 21 | try: 22 | x = urllib.request.urlopen('https://www.google.com/search?q=test') 23 | print(x.read()) 24 | 25 | except Exception as e: 26 | print(str(e)) 27 | 28 | 29 | try: 30 | url = 'https://www.google.com/search?q=test' 31 | 32 | headers = {} 33 | headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17' 34 | req = urllib.request.Request(url, headers=headers) 35 | resp = urllib.request.urlopen(req) 36 | respData = resp.read() 37 | 38 | saveFile = open('withHeaders.txt','w') 39 | saveFile.write(str(respData)) 40 | saveFile.close() 41 | 42 | except Exception as e: 43 | print(str(e)) 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /34. regularexpression - video.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Identifiers: 3 | \d any number 4 | \D anything but a number 5 | \s space 6 | \S anything but a space 7 | \w any character 8 | \W anything but a character 9 | . any character, except for a newline 10 | \b the whitespace around words 11 | \. a period 12 | 13 | Modifiers: 14 | {1,3} we're expecting 1-3 15 | + Match 1 or more 16 | ? Match 0 or 1 17 | * Match 0 or more 18 | $ match the end of a string 19 | ^ matching the beginning of a string 20 | | either or 21 | [] range or "variance" [1-5a-qA-Z] 22 | {x} expecting "x" amount 23 | 24 | White Space Characters: 25 | \n new line 26 | \s space 27 | \t tab 28 | \e escape 29 | \f form feed 30 | \r return 31 | 32 | DONT FORGET!: 33 | . + * ? [ ] $ ^ ( ) {} | \ 34 | ''' 35 | 36 | import re 37 | 38 | exampleString = ''' 39 | Jessica is 15 years old, and Daniel is 27 years old. 40 | Edward is 97, and his grandfather, Oscar, is 102. 41 | ''' 42 | 43 | ages = re.findall(r'\d{1,3}', exampleString) 44 | names = re.findall(r'[A-Z][a-z]*', exampleString) 45 | 46 | print(ages) 47 | print(names) 48 | 49 | 50 | ageDict = {} 51 | 52 | x = 0 53 | for eachName in names: 54 | ageDict[eachName] = ages[x] 55 | x+=1 56 | 57 | print(ageDict) 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /35. regular expressions and urllib for parsing.py: -------------------------------------------------------------------------------- 1 | import urllib.request 2 | import urllib.parse 3 | import re 4 | 5 | url = 'http://pythonprogramming.net' 6 | values = {'s':'basics', 7 | 'submit':'search'} 8 | data = urllib.parse.urlencode(values) 9 | data = data.encode('utf-8') 10 | req = urllib.request.Request(url, data) 11 | resp = urllib.request.urlopen(req) 12 | respData = resp.read() 13 | 14 | #print(respData) 15 | 16 | paragraphs = re.findall(r'

(.*?)

',str(respData)) 17 | 18 | for eachP in paragraphs: 19 | print(eachP) 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /36. tkinter basics 1 - Intro.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to a basic intro to TKinter, which is the Python 3 | binding to TK, which is a toolkit that works around the Tcl language. 4 | 5 | The tkinter module purpose to to generate GUIs, like windows. Python is not very 6 | popularly used for this purpose, but it is more than capable of being used 7 | 8 | ''' 9 | 10 | 11 | # Simple enough, just import everything from tkinter. 12 | from tkinter import * 13 | 14 | 15 | # Here, we are creating our class, Window, and inheriting from the Frame 16 | # class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__) 17 | class Window(Frame): 18 | 19 | # Define settings upon initialization. Here you can specify 20 | def __init__(self, master=None): 21 | 22 | # parameters that you want to send through the Frame class. 23 | # self, and this is the parent widget 24 | 25 | # if you are wondering what self is... it is the object 26 | # created from the class. You can actually call it anything 27 | # you want... people just use "self" 28 | Frame.__init__(self, master) 29 | 30 | #reference to the master widget, which is the tk window 31 | self.master = master 32 | 33 | #with that, we want to then run init_window, which doesn't yet exist 34 | #self.init_window() 35 | 36 | #Creation of init_window 37 | #def init_window(self): 38 | 39 | # changing the title of our master widget 40 | # self.master.title("GUI") 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | # root window created. Here, that would be the only window, but 49 | # you can later have windows within windows. 50 | root = Tk() 51 | 52 | #///root.geometry("250x150+300+300") 53 | 54 | #creation of an instance 55 | app = Window(root) 56 | 57 | #mainloop 58 | root.mainloop() 59 | 60 | -------------------------------------------------------------------------------- /37. tkinter basics 2 - buttons.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to a basic intro to TKinter, which is the Python 3 | binding to TK, which is a toolkit that works around the Tcl language. 4 | 5 | The tkinter module purpose to to generate GUIs, like windows. Python is not very 6 | popularly used for this purpose, but it is more than capable of being used 7 | 8 | ''' 9 | 10 | 11 | # Simple enough, just import everything from tkinter. 12 | from tkinter import * 13 | 14 | 15 | # Here, we are creating our class, Window, and inheriting from the Frame 16 | # class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__) 17 | class Window(Frame): 18 | 19 | # Define settings upon initialization. Here you can specify 20 | def __init__(self, master=None): 21 | 22 | # parameters that you want to send through the Frame class. 23 | Frame.__init__(self, master) 24 | 25 | #reference to the master widget, which is the tk window 26 | self.master = master 27 | 28 | #with that, we want to then run init_window, which doesn't yet exist 29 | self.init_window() 30 | 31 | #Creation of init_window 32 | def init_window(self): 33 | 34 | # changing the title of our master widget 35 | self.master.title("GUI") 36 | 37 | # allowing the widget to take the full space of the root window 38 | self.pack(fill=BOTH, expand=1) 39 | 40 | # creating a button instance 41 | quitButton = Button(self, text="Quit")#,command=self.quit) 42 | 43 | # placing the button on my window 44 | quitButton.place(x=0, y=0) 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | # root window created. Here, that would be the only window, but 53 | # you can later have windows within windows. 54 | root = Tk() 55 | 56 | root.geometry("400x300") 57 | 58 | #creation of an instance 59 | app = Window(root) 60 | 61 | #mainloop 62 | root.mainloop() 63 | 64 | -------------------------------------------------------------------------------- /38. tkinter basics 3 - Event Handling.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to a basic intro to TKinter, which is the Python 3 | binding to TK, which is a toolkit that works around the Tcl language. 4 | 5 | The tkinter module purpose to to generate GUIs, like windows. Python is not very 6 | popularly used for this purpose, but it is more than capable of being used 7 | 8 | ''' 9 | 10 | 11 | # Simple enough, just import everything from tkinter. 12 | from tkinter import * 13 | 14 | 15 | # Here, we are creating our class, Window, and inheriting from the Frame 16 | # class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__) 17 | class Window(Frame): 18 | 19 | # Define settings upon initialization. Here you can specify 20 | def __init__(self, master=None): 21 | 22 | # parameters that you want to send through the Frame class. 23 | Frame.__init__(self, master) 24 | 25 | #reference to the master widget, which is the tk window 26 | self.master = master 27 | 28 | #with that, we want to then run init_window, which doesn't yet exist 29 | self.init_window() 30 | 31 | #Creation of init_window 32 | def init_window(self): 33 | 34 | # changing the title of our master widget 35 | self.master.title("GUI") 36 | 37 | # allowing the widget to take the full space of the root window 38 | self.pack(fill=BOTH, expand=1) 39 | 40 | # creating a button instance 41 | quitButton = Button(self, text="Exit",command=self.client_exit) 42 | 43 | # placing the button on my window 44 | quitButton.place(x=0, y=0) 45 | 46 | 47 | 48 | 49 | def client_exit(self): 50 | exit() 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | # root window created. Here, that would be the only window, but 59 | # you can later have windows within windows. 60 | root = Tk() 61 | 62 | root.geometry("400x300") 63 | 64 | #creation of an instance 65 | app = Window(root) 66 | 67 | #mainloop 68 | root.mainloop() 69 | 70 | -------------------------------------------------------------------------------- /39. tkinter basics 4 - Menu bar.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to a basic intro to TKinter, which is the Python 3 | binding to TK, which is a toolkit that works around the Tcl language. 4 | 5 | The tkinter module purpose to to generate GUIs, like windows. Python is not very 6 | popularly used for this purpose, but it is more than capable of being used 7 | 8 | ''' 9 | 10 | 11 | # Simple enough, just import everything from tkinter. 12 | from tkinter import * 13 | 14 | 15 | # Here, we are creating our class, Window, and inheriting from the Frame 16 | # class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__) 17 | class Window(Frame): 18 | 19 | # Define settings upon initialization. Here you can specify 20 | def __init__(self, master=None): 21 | 22 | # parameters that you want to send through the Frame class. 23 | Frame.__init__(self, master) 24 | 25 | #reference to the master widget, which is the tk window 26 | self.master = master 27 | 28 | #with that, we want to then run init_window, which doesn't yet exist 29 | self.init_window() 30 | 31 | #Creation of init_window 32 | def init_window(self): 33 | 34 | # changing the title of our master widget 35 | self.master.title("GUI") 36 | 37 | # allowing the widget to take the full space of the root window 38 | self.pack(fill=BOTH, expand=1) 39 | 40 | # creating a menu instance 41 | menu = Menu(self.master) 42 | self.master.config(menu=menu) 43 | 44 | # create the file object) 45 | file = Menu(menu) 46 | 47 | # adds a command to the menu option, calling it exit, and the 48 | # command it runs on event is client_exit 49 | file.add_command(label="Exit", command=self.client_exit) 50 | 51 | #added "file" to our menu 52 | menu.add_cascade(label="File", menu=file) 53 | 54 | 55 | # create the file object) 56 | edit = Menu(menu) 57 | 58 | # adds a command to the menu option, calling it exit, and the 59 | # command it runs on event is client_exit 60 | edit.add_command(label="Undo") 61 | 62 | #added "file" to our menu 63 | menu.add_cascade(label="Edit", menu=edit) 64 | 65 | 66 | def client_exit(self): 67 | exit() 68 | 69 | 70 | # root window created. Here, that would be the only window, but 71 | # you can later have windows within windows. 72 | root = Tk() 73 | 74 | root.geometry("400x300") 75 | 76 | #creation of an instance 77 | app = Window(root) 78 | 79 | #mainloop 80 | root.mainloop() 81 | 82 | -------------------------------------------------------------------------------- /4. variables.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to my variables tutorial video. In this video I will teach 3 | you about variables, which you will quickly find yourself using extremely 4 | frequently. 5 | 6 | Variables act as a placeholder for whatever you place in them, and, can be 7 | changed... so they are... you guessed it... VARIABLE! 8 | ''' 9 | 10 | 11 | exampleVar = 55 12 | print(exampleVar) 13 | 14 | #cannotDo = Hey! 15 | 16 | canDo = 'Hey!' 17 | print(canDo) 18 | 19 | canContainOperations = 5/4 20 | print(canContainOperations) 21 | 22 | #canEvenContainFunctions = # but more on that later.... 23 | -------------------------------------------------------------------------------- /40. tkinter basics 5 - Images, text.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hello and welcome to a basic intro to TKinter, which is the Python 3 | binding to TK, which is a toolkit that works around the Tcl language. 4 | 5 | The tkinter module purpose to to generate GUIs, like windows. Python is not very 6 | popularly used for this purpose, but it is more than capable of being used 7 | 8 | ''' 9 | 10 | 11 | # Simple enough, just import everything from tkinter. 12 | from tkinter import * 13 | 14 | 15 | #download and install pillow: 16 | # http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow 17 | from PIL import Image, ImageTk 18 | 19 | 20 | # Here, we are creating our class, Window, and inheriting from the Frame 21 | # class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__) 22 | class Window(Frame): 23 | 24 | # Define settings upon initialization. Here you can specify 25 | def __init__(self, master=None): 26 | 27 | # parameters that you want to send through the Frame class. 28 | Frame.__init__(self, master) 29 | 30 | #reference to the master widget, which is the tk window 31 | self.master = master 32 | 33 | #with that, we want to then run init_window, which doesn't yet exist 34 | self.init_window() 35 | 36 | #Creation of init_window 37 | def init_window(self): 38 | 39 | # changing the title of our master widget 40 | self.master.title("GUI") 41 | 42 | # allowing the widget to take the full space of the root window 43 | self.pack(fill=BOTH, expand=1) 44 | 45 | # creating a menu instance 46 | menu = Menu(self.master) 47 | self.master.config(menu=menu) 48 | 49 | # create the file object) 50 | file = Menu(menu) 51 | 52 | # adds a command to the menu option, calling it exit, and the 53 | # command it runs on event is client_exit 54 | file.add_command(label="Exit", command=self.client_exit) 55 | 56 | #added "file" to our menu 57 | menu.add_cascade(label="File", menu=file) 58 | 59 | 60 | # create the file object) 61 | edit = Menu(menu) 62 | 63 | # adds a command to the menu option, calling it exit, and the 64 | # command it runs on event is client_exit 65 | edit.add_command(label="Show Img", command=self.showImg) 66 | edit.add_command(label="Show Text", command=self.showText) 67 | 68 | #added "file" to our menu 69 | menu.add_cascade(label="Edit", menu=edit) 70 | 71 | def showImg(self): 72 | load = Image.open("chat.png") 73 | render = ImageTk.PhotoImage(load) 74 | 75 | # labels can be text or images 76 | img = Label(self, image=render) 77 | img.image = render 78 | img.place(x=0, y=0) 79 | 80 | 81 | 82 | 83 | def showText(self): 84 | text = Label(self, text="Hey there good lookin!") 85 | text.pack() 86 | 87 | 88 | def client_exit(self): 89 | exit() 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | # root window created. Here, that would be the only window, but 98 | # you can later have windows within windows. 99 | root = Tk() 100 | 101 | root.geometry("400x300") 102 | 103 | #creation of an instance 104 | app = Window(root) 105 | 106 | 107 | #mainloop 108 | root.mainloop() 109 | 110 | -------------------------------------------------------------------------------- /41. threadingtutvid.py: -------------------------------------------------------------------------------- 1 | import threading 2 | from queue import Queue 3 | import time 4 | 5 | print_lock = threading.Lock() 6 | 7 | def exampleJob(worker): 8 | time.sleep(0.5) 9 | 10 | with print_lock: 11 | print(threading.current_thread().name, worker) 12 | 13 | def threader(): 14 | while True: 15 | worker = q.get() 16 | exampleJob(worker) 17 | q.task_done() 18 | 19 | 20 | q = Queue() 21 | 22 | for x in range(10): 23 | t = threading.Thread(target = threader) 24 | t.daemon = True 25 | t.start() 26 | 27 | start = time.time() 28 | 29 | for worker in range(20): 30 | q.put(worker) 31 | 32 | q.join() 33 | 34 | print('Entire job took:',time.time()-start) 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/_bz2.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/_bz2.pyd -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/_hashlib.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/_hashlib.pyd -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/_lzma.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/_lzma.pyd -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/_socket.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/_socket.pyd -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/_ssl.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/_ssl.pyd -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/library.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/library.zip -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/python34.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/python34.dll -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/reandurllib.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/reandurllib.exe -------------------------------------------------------------------------------- /42. cx_Freeze/build/exe.win-amd64-3.4/unicodedata.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonProgramming/Python-3-basics-series/a89a50898c8af450257202fc87b8e6949075bafe/42. cx_Freeze/build/exe.win-amd64-3.4/unicodedata.pyd -------------------------------------------------------------------------------- /42. cx_Freeze/reandurllib.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Identifiers: 3 | \d = any number 4 | \D = anything but a number 5 | \s = space 6 | \S = anything but a space 7 | \w = any letter 8 | \W = anything but a letter 9 | . = any character, except for a new line 10 | \b = space around whole words 11 | \. = period. must use backslash, because . normally means any character. 12 | Modifiers: 13 | {1,3} = for digits, u expect 1-3 counts of digits, or “places” 14 | + = match 1 or more 15 | ? = match 0 or 1 repetitions. 16 | * = match 0 or MORE repetitions 17 | $ = matches at the end of string 18 | ^ = matches start of a string 19 | | = matches either/or. Example x|y = will match either x or y 20 | [] = range, or “variance” 21 | {x} = expect to see this amount of the preceding code. 22 | {x,y} = expect to see this x-y amounts of the precedng code 23 | White Space Charts: 24 | \n = new line 25 | \s = space 26 | \t = tab 27 | \e = escape 28 | \f = form feed 29 | \r = carriage return 30 | Characters to REMEMBER TO ESCAPE IF USED! 31 | . + * ? [ ] $ ^ ( ) { } | \ 32 | Brackets: 33 | [] = quant[ia]tative = will find either quantitative, or quantatative. 34 | [a-z] = return any lowercase letter a-z 35 | [1-5a-qA-Z] = return all numbers 1-5, lowercase letters a-q and uppercase A-Z 36 | ''' 37 | 38 | import urllib.request 39 | import urllib.parse 40 | import re 41 | import time 42 | 43 | 44 | url = 'http://pythonprogramming.net' 45 | values = {'s' : 'basics', 46 | 'submit' : 'search'} 47 | 48 | data = urllib.parse.urlencode(values) 49 | data = data.encode('utf-8') # data should be bytes 50 | req = urllib.request.Request(url, data) 51 | resp = urllib.request.urlopen(req) 52 | respData = resp.read() 53 | 54 | paragraphs = re.findall(r'

(.*?)

',str(respData)) 55 | 56 | for eachParagraph in paragraphs: 57 | print(eachParagraph) 58 | 59 | 60 | time.sleep(15) 61 | -------------------------------------------------------------------------------- /42. cx_Freeze/setup.py: -------------------------------------------------------------------------------- 1 | # https://pypi.python.org/pypi?:action=display&name=cx_Freeze&version=4.3.3 2 | 3 | # from command window, now you would go to the dir, run python setup.py build... 4 | # this makes a build directory, within which you can find your new .exe! 5 | 6 | 7 | from cx_Freeze import setup, Executable 8 | 9 | setup(name = "reandurllib" , 10 | version = "0.1" , 11 | description = "" , 12 | executables = [Executable("reandurllib.py")]) 13 | -------------------------------------------------------------------------------- /43. subprocess.py: -------------------------------------------------------------------------------- 1 | ''' 2 | The subprocess module lets you do any commands that you would normally do 3 | via your shell. If you recall before, the sys module let us communicate 4 | from the shell to our script, now we can communicate from our script to the 5 | shell, besides with just simple error msgs. 6 | ''' 7 | 8 | 9 | # This tutorial is best followed in a shell / command prompt. 10 | # Open yours up, type python, or python3, and then follow. 11 | import subprocess 12 | 13 | # Say you are on windows: 14 | # module call command in the shell 15 | # you can change that if you'd like, eventually. 16 | # IF YOU ARE NOT IN A SHELL, YOU WILL SEE NO OUTPUT! 17 | subprocess.call('dir', shell=True) 18 | 19 | 20 | subprocess.call('echo dir', shell=True) 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /44. matplotlib 1 - intro.py: -------------------------------------------------------------------------------- 1 | # easiest to use: http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib 2 | 3 | 4 | #importing pyplot 5 | from matplotlib import pyplot as plt 6 | 7 | #plotting to our canvas 8 | plt.plot([1,2,3],[4,5,1]) 9 | 10 | #showing what we plotted 11 | plt.show() 12 | -------------------------------------------------------------------------------- /45. matplotlib 2 - dynamic plotting and labels.py: -------------------------------------------------------------------------------- 1 | # easiest to use: http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib 2 | 3 | 4 | #importing pyplot 5 | from matplotlib import pyplot as plt 6 | 7 | x = [5,8,10] 8 | y = [12,16,6] 9 | 10 | plt.plot(x,y) 11 | 12 | plt.title('Epic Info') 13 | plt.ylabel('Y axis') 14 | plt.xlabel('X axis') 15 | 16 | plt.show() 17 | -------------------------------------------------------------------------------- /46. matplotlib 3 - styles.py: -------------------------------------------------------------------------------- 1 | from matplotlib import pyplot as plt 2 | from matplotlib import style 3 | 4 | style.use('ggplot') 5 | 6 | x = [5,8,10] 7 | y = [12,16,6] 8 | 9 | x2 = [6,9,11] 10 | y2 = [6,15,7] 11 | 12 | 13 | # can plot specifically, after just showing the defaults: 14 | plt.plot(x,y,'g',linewidth=5) 15 | plt.plot(x2,y2,'c',linewidth=5) 16 | 17 | plt.title('Epic Info') 18 | plt.ylabel('Y axis') 19 | plt.xlabel('X axis') 20 | 21 | plt.show() 22 | -------------------------------------------------------------------------------- /47. matplotlib 4 - legends.py: -------------------------------------------------------------------------------- 1 | from matplotlib import pyplot as plt 2 | from matplotlib import style 3 | 4 | style.use('ggplot') 5 | 6 | x = [5,8,10] 7 | y = [12,16,6] 8 | 9 | x2 = [6,9,11] 10 | y2 = [6,15,7] 11 | 12 | 13 | # can plot specifically, after just showing the defaults: 14 | plt.plot(x,y,'g',label='line one', linewidth=5) 15 | plt.plot(x2,y2,'c',label='line two',linewidth=5) 16 | 17 | plt.title('Epic Info') 18 | plt.ylabel('Y axis') 19 | plt.xlabel('X axis') 20 | 21 | # adding a legend: 22 | plt.legend() 23 | 24 | #grid toggle.... 25 | plt.grid(True,color='k') 26 | 27 | 28 | plt.show() 29 | -------------------------------------------------------------------------------- /48. matplotlib 5 - bar charts and scatter.py: -------------------------------------------------------------------------------- 1 | from matplotlib import pyplot as plt 2 | from matplotlib import style 3 | 4 | style.use('ggplot') 5 | 6 | x = [5,8,10] 7 | y = [12,16,6] 8 | 9 | x2 = [6,9,11] 10 | y2 = [6,15,7] 11 | 12 | 13 | # can plot specifically, after just showing the defaults: 14 | plt.scatter(x, y)#, align='center') 15 | 16 | plt.scatter(x2, y2, color='g')#, align='center') 17 | 18 | 19 | plt.title('Epic Info') 20 | plt.ylabel('Y axis') 21 | plt.xlabel('X axis') 22 | 23 | 24 | 25 | plt.show() 26 | -------------------------------------------------------------------------------- /49. matplotlib 6 - Plotting from a csv file.py: -------------------------------------------------------------------------------- 1 | from matplotlib import pyplot as plt 2 | from matplotlib import style 3 | #### 4 | import numpy as np 5 | 6 | 7 | 8 | style.use('ggplot') 9 | 10 | x,y = np.loadtxt('exampleFile.csv', 11 | unpack=True, 12 | delimiter = ',') 13 | 14 | plt.plot(x,y) 15 | 16 | plt.title('Epic Info') 17 | plt.ylabel('Y axis') 18 | plt.xlabel('X axis') 19 | 20 | 21 | 22 | plt.show() 23 | -------------------------------------------------------------------------------- /5. while loop.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | condition = 1 4 | 5 | while condition < 10: 6 | print(condition) 7 | condition += 1 8 | 9 | 10 | condition = '2' 11 | 12 | while condition > 5: 13 | print 'test' 14 | 15 | # Another favorite of many people... the infinite loop # 16 | 17 | while True: 18 | print('doing stuff!!') 19 | 20 | 21 | 22 | # control+c to break script! 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /50. ftplibtutorialvid.py: -------------------------------------------------------------------------------- 1 | from ftplib import FTP 2 | 3 | ftp = FTP('domainname.com') 4 | ftp.login(user='username', passwd='password') 5 | ftp.cwd('/specificdomain-or-location/') 6 | 7 | def grabFile(): 8 | filename = 'fileName.txt' 9 | localfile = open(filename, 'wb') 10 | ftp.retrbinary('RETR ' + filename, localfile.write, 1024) 11 | ftp.quit() 12 | localfile.close() 13 | 14 | def placeFile(): 15 | filename = 'fileName.txt' 16 | ftp.storbinary('STOR '+filename, open(filename, 'rb')) 17 | ftp.quit() 18 | 19 | -------------------------------------------------------------------------------- /6. for loop.py: -------------------------------------------------------------------------------- 1 | #! python3 2 | 3 | ''' 4 | Hey everyone and welcome to another python 3 tutorial. This tutorial will be 5 | covering the for loop. The for loop is used for many of the same tasks as the 6 | while loop. 7 | 8 | Typically, you will see the while loop being used for finite tasks that have 9 | predetermined length, and the for loop being used for tasks that have uncertain 10 | and variable timeframes. 11 | 12 | That said, the for loop can be used for the exact same tasks as the while loop. 13 | 14 | for this reason, I prefer the for loop myself, but again, it comes down to 15 | personal preference. I will show you why here. 16 | 17 | ''' 18 | import time 19 | 20 | exampleList = [1,5,6,6,2,1,5,2,1,4] 21 | 22 | for x in exampleList: 23 | print(x) 24 | 25 | 26 | 27 | # usually people use for loops to iterate through something, 28 | # and you can iterate for the same purposes as the previous 29 | # while loop did, as more of a counter: 30 | 31 | 32 | for x in range(1,11): 33 | print(x) 34 | 35 | 36 | # Range is a built in python function, and it literally will make a range 37 | # of numbers for you. In python 2.7, Python's 3.3 is the equivalent of 38 | # 2.7's xrange... so this range is a generator function and will not 39 | # blow out your memory like python 2.7's range. 40 | 41 | time.sleep(555) 42 | -------------------------------------------------------------------------------- /7. if statement.py: -------------------------------------------------------------------------------- 1 | x = 5 2 | y = 10 3 | z = 22 4 | 5 | if x > y: 6 | print('x is greater than y') 7 | elif x == z: 8 | print('x is less than z') 9 | elif 5 == 2: 10 | print('5 is greater than 2') 11 | else: 12 | print('if and elif(s) never ran') 13 | -------------------------------------------------------------------------------- /8. if else.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | hello everyone and welcome to my if else basics tutorial. 4 | 5 | The idea of the if else pairing is to add 1 more layer of logic to the 6 | usage of your if statement here. The else statement can actually be used 7 | in quite a few other ways, like with while, for, and except. 8 | 9 | Here, the idea is to ask if something is the case, like we did before... 10 | ... and, if it is not the case, then do something else. In this case, 11 | 12 | we will just print something basic. 13 | 14 | 15 | ''' 16 | 17 | 18 | x = 5 19 | y = 8 20 | 21 | if x < y: 22 | print('x is greater than y') 23 | if x > 55: 24 | print('x is greater than 55') 25 | else: 26 | print('x is not greater than y or 55') 27 | 28 | -------------------------------------------------------------------------------- /9. if elif else.py: -------------------------------------------------------------------------------- 1 | ''' 2 | What is going on everyone welcome to my if elif else tutorial video. 3 | 4 | The idea of this is to add yet another layer of logic to the pre-existing if else statement. 5 | 6 | See with our typical if else statment, the if will be checked for sure, and the 7 | 8 | else will only run if the if fails... but then what if you want to check multiple ifs? 9 | 10 | You could just write them all in, though this is somewhat improper. If you actually desire to check every single if statement, then this is fine. 11 | 12 | There is nothing wrong with writing multiple ifs... if they are necessary to run, otherwise you shouldn't really do this. 13 | 14 | Instead, you can use what is called the "elif" here in python... which is short for "else if" 15 | 16 | 17 | ''' 18 | 19 | x = 5 20 | 21 | y = 10 22 | 23 | z = 22 24 | 25 | # first run the default like this, then 26 | # change the x > y to x < y... 27 | 28 | # then change both of these to an == 29 | if x > y: 30 | print('x is greater than y') 31 | elif x < z: 32 | print('x is less than z') 33 | 34 | else: 35 | print('if and elif never ran...') 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PythonProgramming.net 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-3-basics-series 2 | http://pythonprogramming.net/introduction-to-python-programming/ 3 | --------------------------------------------------------------------------------