Solid resource for learning Python from a beginner perspective?

I am looking for a resource which teaches from a beginner perspective, solid programming principles and practice, good use of Python 3 syntax and constructs (idioms of Python), is well proofread, and has an appropriate learning curve.

I have been (re)learning some cursory Python from Sentdex’s Python 3 Basics Tutorial Series: https://www.youtube.com/watch?v=oVp1vrfL_w4&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

To begin with, I was looking for something shallow, and that series seems to cover it ok. It definitely has it’s issues, but I haven’t found anything that better serves the purpose. Basically, it quickly covers some Python syntax and just touches on some programming concepts and Python constructs without much detail or depth. It might be described as a get going series that could be gone through over a few days time for the purpose of just getting aquainted with the language and doing basic things with it. The value in a series like this is that it gives an overview, providing a good glimpse at what is possible, without burying the learner in details from the getgo, where an indepth series might require spending days getting a good grasp on some programming principle and Python constructs for making use of it and where the depth and detail might obscure the big picture. I think that starting with a shallow resource such as this series has value in providing a bird’s eye view, but once the honeymoon is over it’s time to get to work with a more indepth beginner resource.

In looking for a good beginner resource on programming with Python it is much the same as finding resources on any other technical topic. It’s a jungle. People will recommend resources that they haven’t really used at all, or haven’t fully gone through. People pushing their own products will recommend their products without letting on who they are. Many books (and websites and videos) will fall apart after a few chapters in (very common with technical books!). Some books are very confused about who their target audience is. Some are confused about what type of book they are (tutorial, reference). The style of some books is just dead boring. And on and on. Finding solid resources for self-learning any topic can be really tough, often involving a number of false starts, which can easily turn into hopscotching to failure. What I find is that for most subjects, the subject at hand isn’t usually so difficult to learn as is finding solid resources produced by someone who knows the subject well AND can teach well. Finding both in the same resource seems to be a rarity, no matter the subject.

With the above in mind, can you recommend a solid resource (which you have used yourself!) for learning programming with Python from a beginner perspective? The format doesn’t matter (book, site, video series), but it should meet the requirements of the first sentence in this post: I am looking for a resource which teaches from a beginner perspective, solid programming principles and practice, good use of Python 3 syntax and constructs (idioms of Python), is well proofread, and has an appropriate learning curve.

Also, if you can recommend a solid resource, I would like to know something about why you recommend it and any problems you might have ran into when using it, so as to better evaluate the possibility of using it myself. What I mean to say is that some discussion would be good here, rather than merely dropping names or links to resources. Thanks.

And if you have other thoughts on this topic, I am all ears.

general python knowledge and knowing how it fits within the bge are both a plus…it is hard to point you to a good tutorial series because knowing python alone is not the same as knowing the bge py api…but in general python is python…I think the best way is learning by doing and if you are looking for some simple(shallow) ways to get your feet wet in BGE you can check out Arsenal RSL…very quick videos that give very quick results…I stumbled upon them when I was looking for something specific once when I was just starting…can’t remember what, but it was quick and got me past my roadblock…maybe some others have some other links.

this is also good for light learning …

and I like to reference this from time to time when I think I am writing some code that could be cleaner or quicker. I think it was created by campbel??

also, as with writing in any language, a little ingenuity goes a long way…just because someone tells you to code something one way does not mean there is not a better , faster way…

That is a good point. A person could learn Python very indepth and still know nothing about the game engine api. Which raises the question, how indepth a working knowledge of Python should a person have before jumping into the game engine? Or should the two be started in parallel (keeping in mind, having limited spare time)?

Also, Python looks interesting to me in general, being something of a swiss army knife of programming and having so many available modules.

Learning by doing has it’s merrits. But I also like having resources which approach the tangles of details in a clear manner. More on that in a minute.

I will check out the game engine stuff at that link. Thanks.

I should probably explain something of where I am coming from. At one point I decided that I wanted to learn C++. I had so many false starts and dropouts using various beginner resources that I almost gave up. Then I found Bjarne Stroustrup’s book, Programming Principles and Practice using C++. I made it about halfway through the book, and I intend to get back to it at some point. Putting the book down had nothing to do with the book itself or the subject. It had to do realizing my weakness in math and refocusing my efforts and time on math before going back to the C++ book. But I digress. When I found that book I realized how much of a difference a well written book can make. The half of it that I have worked through is EXCELLENT in just about every way. It is very clear in teaching programming principles and provides useful and challenging exercises for strengthening what is learned. I think it is a great example of how a programming book (and a technical book in general) should be written. And so I suppose that I’m looking for the Programming Principles and Practice using C++ equivalent for Python.

One thought that has struck me (as I continue strengthening and building my understanding of math) is that instead of trying to find a good beginner programming book on Python, I may instead go back to the C++ book now for the programming principles and later pick up a reference style book on Python. I say this because so far I am not finding anything solid for a programming beginner using Python, which is ironic if you ask me. Maybe that sounds like a very roundabout approach, but if there are no solid beginner programing books using Python, then wading through the jungle of Python beginner books would be a waste of time, where learning solid programming principles and then learning a new langauge would not.

I guess this raises the question of, how much of working with the game engine is about scripting and how much is about programming? If it is more about scripting, then a solid understanding of programming may not even be a requirement.

But personally, I am more interested in programming in general than scripting only. So I guess for myself, having a solid foundation in programming is a given either way.

Maybe by trying to jump into the Blender game engine at this point, I am putting the cart before the horse. One path that I could take would be to continuing working with Blender on the modeling and animation side of things, while in the meantime continuing working with math and picking back up learning general programming, later learning to work with the Blender api. So little time, so many branching interests.

Scripting and programming refers to the same thing.

While programming is a term that describes an abstract way to describe behavior (by writing a program flow), scripting tells you do that by writing a script. Scripting is a subset of coding (= writing code). The term script typically means you write a code snippet with not much structure. Very often it is interpreted rather than compiled. So scripted means = write it … test it right now. Think about a change to the blender’s C++ code and how long it takes to see it working (you need to build blender first).

That is the major reason why there are “script” languages which are used to describe the game behavior. You want to see the results as fast as possible. At that layer most of the game’s business does not need the performance of native code. This does not mean you should not use efficient code when scripting.

Additionally you should know how to design your code that you can develop it further, collaborate with others and maintain existing code. You should not underestimate that aspect. Naive solution at the beginning can become big obstacles later. There are techniques ot came around that (such as testing or refactoring code). There is always something new to learn.

Finally I can’t recommend much about that topic. I learned it the hard way … long practice ;).

[Edit] I suggest to start with the “it works” approach until you know alternative solutions and how to evaluate them against your specific situation.

I agree with monster, this is why I always refer to it as ‘coding’…whether it is something in ‘C’ or in a ‘scripting language’ the priciples are the same…and if you want to just learn the fundamentals of programming I recommend ‘C’ over C++ or any other language…ofc the drawback of this is you could fall into the problems that I have had…python is not ‘C’, it can be entirely different conceptually.

here is a really good youtube channel I catch myself watching from time to time.(still python)

Another resource is probably the finished games forum…you can get a good grip of how python inside the BGE work together from snooping around others projects…there is no shame into peeking at how others might do something, if it is the vein of knowledge.

I tend to think of scripting as interfacing programs textually for automating things which might be difficult or impossible to do using a gui. Conversely, I tend to think of programming as, development of those programs which will be interfaced via arguments from a commandline, a more involved script, or a gui. Of course there is some overlap between the two, but there is a distinction. Scripting is typically working at a higher abstraction level, where the programs already exist but need to be told more specifically how to carry out their capabilities to meet a custom goal.

I would recommend this resource: http://docs.python-guide.org/en/latest/writing/structure/

I think what fails most project is a bad project structure/management. If the thing is not readable / maintainable, good luck working on it more than a month or two.

Learning how to play with the way Python handles packages / modules enables you to have your .blend file in one place, and your .py files in a neat package (folder) on the side. Then it can get easier to version the sources, if you are familiar with Git/SVN/hg etc…

Now experience is only required to solidify what you may read online, but if you want to learn about cool libraries already present in the standard lib, hence not reinventing the wheel every time, you can take a look there: https://pymotw.com/3/

If you are curious about something in the standard lib or Python’s way of doing things, the official documentation is super useful: https://docs.python.org/3/library/index.html
Each module is really well explained, even if sometimes it may look a bit overkill / a bit far fetched, most of it is in fact well thought (for instance it took me 2 months to understand all the benefits of the concurrent.futures module and why I should use it lol)

I would also recommend you to read a bit about asynchronous programming. A game is rather asynchronous by nature, and heavily relies on events (sensor bricks are one design around an event paradigm). But recently there was an asynchronous frienzy around Python and coroutines (coroutine = function that can be ran by steps instead of being entirely executed like a regular function).
The concept is really powerful, and I have been playing around with it to make use of it in the BGE, because Threads are a bad idea 95% of the time, and the multiprocess module is broken in Blender. Was left with coroutines, felt wonderful (you have to setup a little system to execute them yourself though, as most already existing frameworks using them are not easily compatible with the BGE).
Anyway, here is a wonderful explanation of coroutines: https://mdk.fr/blog/python-coroutines-with-async-and-await.html
(async programming is really gaining popularity because it fixes some problems we had with concurrency using threads/processes)

Once you have some experience and can wrap your head around general programming concepts, you can take a look at common design patterns. Most of them have been designed to adress specific problems and just might solve some of yours too :wink:
Useful patterns: Observer pattern, Entity-Component-System pattern, Dependency Injection, … lot of fun things.

Now you said you started on C/C++, good thing because Python is designed to be able to interface with compiled modules, in case you need more perfomance. Bad news is: its still tricky to do. But nothing’s impossible, depends on your needs/determination. Anyway:
https://packaging.python.org/guides/packaging-binary-extensions/#an-overview-of-binary-extensions
https://docs.python.org/3.5/extending/extending.html

Have fun I guess :stuck_out_tongue:

Thanks. I’m initially thinking that my path will be to finish sentdex’s tutorials on python, go through schafer’s tutorials, and then come back to start taking a look at the game engine and some example projects. Also, I only just noticed the coding and python section of the forum, which should be helpful.

Sounds like stuff to keep in mind for later. Thanks for the info.

This is the best resource on python I have found to date:
https://learnpythonthehardway.org/

knowledge should be free :slight_smile:

Agreed :slight_smile:

In any case, after looking a bit more online, if you are really new to Python this resource looks super solid: https://docs.python.org/3/tutorial/

If you get to complete this tutorial, I recommend again following on this one: http://docs.python-guide.org/en/latest/writing/structure/

You may have a bit of reading / practice to do :slight_smile:

hi bentzero

30 lessons on basics concepts (speedy but good level and accurate)

then pratice, practice, …

bpy and bge are good training space.

JL

I have ran into that quite a bit during my searching, and the recurring theme from reviewers seems to be that it tends to leave learners in the dark in critical areas, requiring them to search externally for information which should have been included, where instead of the hard way being about taking on the challenges of solving problems using programming (which can be very satisfying) it is instead about filling in the blanks for missing information (indicating poor pedagogy). Another recurring theme is that it expects learners will intuit programming concepts from merely typing out the examples, without adequate explanaton of what is being typed or why. That doesn’t sound like the kind of hard way that I want to subject myself to.

But on the positive side, it seems to be a rarity among python resources in that it at least attempts to teach basics of programming, rather than only being a language tutorial.

The python tutorial looks good for learning the language, and I will likely make use of it. So thanks for pointing it out.

But I’m still left wondering why there isn’t much out there in way of teaching basic general programming principles in a comprehensive way using python, especially since python is often recommended to beginner programmers. Almost all of the books and video series which I have taken a look at so far are about learning the language and maybe only touching on concepts of general programming (what is a variable, what is a loop, what are classes…). I should also say here that I have a teenage nephew who is interested in both blender and programming (he has zero programming experience), and so I am also looking for a resource with him in mind. Very oddly, the best resources for basics of general programming which I think I could point him to so far are books using C++ or C! Since python’s syntax is considerably less complex and since it has so much in way of higher level structures, I would have thought that it would be a great language for beginners to learn general programming. But the vast majority of resources which I am seeing available for beginners are either language tutorials only or look to cover general programming in a very glossed over or haphazard way, which kind of negates the benefits of python as a beginner programming language. I mean, knowing the syntax and structures of any language isn’t knowing how to approach solving problems using programming.

I’m just thinking outloud here, which may be of some use for other noobs who might be thinking about getting into python for blender. It seems that learning python for use with the blender api breaks down into at least a few aspects:

General programming (programming concepts and problem solving using those concepts). Without some skill in general programming, python scripts are going to be limited to doing simple things. Alternatively, scripts made by others may be used when available (probably without much understanding of how they work).

The python language (syntax and structures of the language). Without having a good grasp on the python language, much of the time and energy spent on writing python scripts for blender will be on troubleshooting correct usage of the language, rather than focusing on working out solutions to the problems at hand.

The blender game engine api (what each part of the api does and how to use it in general). Similarly to the above, without having a general knowledge of the blender api, much time and energy will be spent on figuring out bits of the api as needed, rather than focusing on using the api for working out solutions to the problems at hand.

While there are lots resources for learning the Python language, some of which touch on general programming concepts, the glaring problem that I am seeing here for a complete noob to programming is that there seems to be a lack of good beginner programming learning resources (general programing) which use python as the language. Knowing the language is not knowing how to program, and knowing how a programming concept works is not knowing how to implement it and combine it with other programming concepts to solve problems.

Well… I’ve been playing with Python for around 7 years now (started on Blender too, never stopped using this language lol), I’ve got a B.Sc in Computer Science (3 years) and what I can say is that this only makes me an intermediate level developer…

Programming usually requires lot of practice, no matter how you want to look at it and learn, you definitely need to go at it the hard way at some point.

I still google almost everything when I need to program, mostly for documentation on certain elements (Blender API, some Python modules, etc…)

But from what you are asking, you need to learn how Object-Oriented-Programming (OOP) works, with the way Python is, it would be a must: https://code.tutsplus.com/articles/python-from-scratch-object-oriented-programming--net-21476

Programming requires thinking, practice and time, trial and errors… Just like learning advanced maths, wonder why there are so many exercices / homework to do ? Well, because no matter how long you read about it, until you actually do it you will have difficulties…

Now of course there are methods to go at a problem, and the most used one in Python is to go with OOP: converting your problem into “objects” and abstracting (almost) everything. OOP has the advantage of making us write code in a more “human” way, more than what Python allow us to do with its syntax already.

For the Blender API you need to ask yourself “what would I want to do ?”, then “what would I use to do this ?”. Go to the documentation, do a search for the things you think you might need. If you don’t find anything (in terms of methods/functions), you can take a look through each method yourself, and read each function, what it does, and try to think about how it could help you.

Programming is a painful process in my opinion, even with experience, you always will have to implement something you never saw before, and then you will only have bits of documentation and similar-yet-not-quite-like solutions online. Its your job to take your time, sit before the code/concept and compile all of it to make your solution.

Conclusion:

  • Learn OOP, be it in pseudo-code / Python / Java / C# / C++ / whatever. Its about the way of thinking. Python has its own take on OOP implementation, so learn how to write it after understanding OOP.
  • Programming is all about calling functions to do what you want, storing things in variables, and making loops/conditionnals. The “calling functions” part requires you to look for what is available: go online and read the doc. No magic there. I still do it, everyone does it.
  • Don’t be afraid to get it wrong. If you don’t want to write shitty code at first, there is no way you will write good code after. Just learn to learn from a bad design. But if you only have a bad design in mind, and still can’t find anything else: go with it despite. Chances are you will learn something on the way.

Edit: Monster also made a lot of documentation for the BGE/Python: https://blenderartists.org/forum/showthread.php?240729

I have been learning object-oriented programming in Java over the last few weeks. I think next I will be heading toward the Python tutorial from the Python site after a bit of a break and see how that goes. I guess then I can start working with the Blender api.

It seems that there is a good opportunity for someone to create an up-to-date series (books or videos) teaching solid programming basics, using Python, and with a heavy slant toward working with Blender and the game engine. But maybe the payoff isn’t worth the time and effort for a would-be author.

I also think that despite everyone using the BGE for some time now, no one as the magic formula to make any game using it.

For me it comes from the fact that the BGE is (was) a WIP engine, yet people tried their very best to use it instead of changing it.

Nevertheless, I think the most persistent people developed a method each of their own. If I were to quote some names I would go with sdfgeoff, Monster, elmeunick9, agoose77, Blue_Print_Random, redfrost/Nicholas_A, and many more.

This can also be illustrated via the so few projects that made it commercially using the BGE. Everyone feel that it is possible, yet it would seem like looking for the Holy Graal.

Don’t expect having an easy life using the BGE. Its easy for micro-prototypes, but once you keep going, you will have to make your own solutions and it will come quite fast. Now feel free to come back on the forums, only after doing some research on your part. People will gladly try to help if one can.

This is why in my opnion there is little solid documentation on using Python/BGE.

Back at the programming concepts, it is very cool that you understand the way Java does things in regards to OOP. Java is a bit stricter than Python, so it may give you some discipline :slight_smile:

I just found this, for learning Python’s OOP: https://pythonschool.net/category/oop.html
Its based on videos from what it seems (not my cup of tea), but it could help.
(I guess you can fast forward some parts of the videos based on what you already learnt)

Then again there are the docs written by Monster: https://blenderartists.org/forum/showthread.php?240729

Hope it helps :slight_smile:

edit:
Also, when it comes to professional programming, you need to learn how to document yourself.
You can ask around from times to times, but the job of a developer is mostly to be able to read the documentation for the tools he is using, and being able to create a mind-model for his problem and documenting the source code with all the classes/concepts going on.
The most important part when you want to get results is to be able to find the resources yourself and being able to read and use it. Again come here if you have troubles even after looking.