More free, effective python tutorials

Tutorials & Guides
Post Reply
jachin99
Experienced User
Posts: 557
Joined: Sat Feb 13, 2016 8:39 pm

More free, effective python tutorials

Post by jachin99 » Fri Nov 09, 2018 5:36 pm

I have been searching for cheap or free resources that I can use to learn python. I have tried a few different coding websites, including Udemy but these seem to be the most promising so far. With most of other classes I have tried, I either get to a point where I have to start paying, or the classes don't hold my attention. These videos seem to explain a lot of small things I have gotten hung up on during the past.

https://www.youtube.com/watch?v=YYXdXT2l-Gg&t=517s

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: More free, effective python tutorials

Post by kgschlosser » Sat Nov 10, 2018 10:26 am

if you get stuck. you can always ask me. if I have the answer I will more then gladly give it.

Also if you have an Android device. I would recommend the Learn Python app. It is going to seem almost like you are back in kindergarten But I will guarantee you will learn and also retain.

most of Python learning for me was/is trial and error. The thing that helped me learn was actually helping people out on these forums. You have to remember that I do not poses specific devices that people are using when they encounter an issue. I had to do a lot of reading. and a very large amount of trial and error.

Python is an object oriented dynamic language. the short definition of that is you do not have to worry about memory management or declaring variables and variable sizes. these things are handled behind the scenes. so it takes a whole mess of complexity out of the equation.

hardest thing I think to really grasp is that anything that is not a compiler specific command is actually the same. compiler specific commands would be things similar to
if, elif, else, not, with, or, and

operators are also compiler commands
+, -, /, *, >, <, >=, <=, ==, =, <<, >>, |, &, !

as an example if i do

Code: Select all

var1 = 1
var1 = 'some string'
they are both the same as doing

Code: Select all

class SomeClass(object):
    def __init__(self, value):
        self.value = value


var1 = SomeClass(1)
var2 = SomeClass('some string')
this is an over simplified example but it gives the general idea.

so if you run this code

Code: Select all

var1 = 1
var2 = 'some string'
print dir(var1)
print dir(var2)
it is going to print out all of the available methods, properties, and instance variables that are available
you will notice they are close to identical in nature. there are going to be some available for var1 that are not in var2 and vice versa. that is ebcause of the data being contained in the variable.

now when i mentioned the dynamic abilities of Python.

Code: Select all

var1 = 1
var2 = 'some string'
print dir(var1)
print dir(var2)
# this is going to flip what the variables are holding
var1, var2 = var2, var1
print dir(var1)
print dir(var2)
now you can see that they have simply flip flopped. This is something that cannot be done in a low level language like C or C++, C# on the other hand is a dynamic language as is java.

now this one is going to spin the bean some

Code: Select all

class SomeClass(object)

    def some_method(self):
        pass

print SomeClass.some_method.__name__

print dir(SomeClass.some_method)

def some_function():
    pass
    
print some_function.__name__
print dir(some_function)
even functions and methods are also objects all derived from the same base class

if you run this from inside of a python interpreter and not in EG.
you can do this by saving the code to a text file and rename the file to test.py. save the file into your EG installation folder.
open a command prompt in the EG folder and key in py27.exe test.py

Code: Select all

TEST_VARIABLE = 1
import sys

print TEST_VARIABLE

#This grabs the module that is currently running. which would be this code
module = sys.modules[__name__]

print module.TEST_VARIABLE
module.TEST_VARIABLE = 2

print TEST_VARIABLE
HOLY COW even the thing that the code is running in is an object also.

Code: Select all

import sys
module = sys.modules[__name__]
print dir(module)
looks almost the same as the functions and the integer and string. that's because the base level of it is the same.

There are specific methods that are used for specific data types. some of these are called magic methods. they will begin and end with double underscores. Not all __*__ items that you see when using dir() will be methods they can actually be anything. here is a list of specific magic methods that are used when specific data types are stored


__iter__: list, dict, tuple --- by using this magic method you object is considered an iterable. and it can be used in thing like for loops
__contains__: str, list, dict, tuple --- using this will allow you to use "in" to check if something is "in" your data
__add__: int, float, list, tuple, str --- the + operator
__sub__: int, float, list, dict, tuple, str --- the - operator
__div__: int, float --- the / operator
__mul__: int, float --- the * operator

these next few are a bit tricky. these are for operators +=, -=, /=, *=
the r is the right side and the i is for the left side.

x = myobj
y = 4

x += y
x = x.__iadd__(y)

__iadd__: int, float, list, tuple, str
__isub__: int, float, list, tuple, str
__idiv__: int, float
__imul__: int, float


now think about this in reverse. in the above example myobj would be the class you made
and we want to add the number 4 to it. we know what the data is that is coming in and how to handle it properly

but if the code read

x = 4
y = myobj

x += y
x = x.__iadd__(y)

it would fail. because the compiler is typing to do

4.__iadd__(myobj)

the class that represents the number 4 has no clue how to handle myobj it was never taught how.
when this happens it will then call the right hand

myobj.__radd__(4)

and in your code you will properly take care of this debockle that can occur. in respect with subtraction and division you need to make sure you place the data on the proper side of the operator.

__radd__: int, float, list, tuple, str
__rsub__: int, float, list, tuple, str
__rdiv__: int, float
__rmul__: int, float

these are just to name a few.

basically what defines a data object is not the data. it is the methods that are available to use to manipulate the data. all data stored is always the same kind of data, it is all a bunch of 1's and 0's we use markers in order to flag what methods need to be added. "", '' for strings, a . for float, {} for dict, [] for list and () for tuple. the compiler looks for these special identifiers to know what needs to be done.

idk if that helps some with understanding how python classifies who is what.

dir() is your friend. if you do not know what is available to do things to a specific kind of data you can do a dir() and it will list the methods.

or you can do help(str), help(float), help(dict)
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 129
Joined: Thu Dec 10, 2015 12:09 am

Re: More free, effective python tutorials

Post by loveleejohn » Wed Nov 14, 2018 4:47 pm

Just want to take a quick second to say a huge thank you to jachin99 and kg! I watched the video and read kg's tips and it started me on a path of understanding. I'm still not the sharpest on these things but I'm definitely learning. I was even able to figure out that the reason why I couldn't get the pip installer to work in Python 2.7.12 was because the darn thing was hidden in a subfolder! :lol: So yeah I'm a superstar now after that 3 hour discovery! LOL. Anyways, these tips definitely help us newbs to start learning how to piece together the parts of this really neat software to make something pretty cool. Thank you both!

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: More free, effective python tutorials

Post by kgschlosser » Wed Nov 14, 2018 6:53 pm

if you copy and paste the code below into the python interperter or save it to a file and run it with python from a command prompt it will fix the issues you are having with your environment variables not being set properly for the python installation.

be forewarned if you have more then a single installation of python this will over write any setting with ones from the python version you run this code from

python some_file.py

only run this script one time

Code: Select all

import sys
import os
from subprocess import Popen

var1 = 'setx PATH "{python};{python}\\Scripts;%PATH%"'
var2 = 'setx PYTHONPATH "{python};{python}\\lib;{python}\\Scripts"'
var3 = 'setx PYTHON "{python}"'

python = os.path.dirname(sys.executable)

p = Popen(var1.format(python=python))
p.communicate()

p = Popen(var2.format(python=python))
p.communicate()

p = Popen(var3.format(python=python))
p.communicate()
and then you will be able to run PIP or easy_install. and even python from any location in the CMD window.
If you like the work I have been doing then feel free to Image

Post Reply