r/learnpython • • May 17 '21

I know the basics of Python. What to learn next to be employable in 2 years?

592 Upvotes

I've completed freecodecamp's 5 hr video on Basics of Python. I didn't binge through it. I completed it in 20 days doing problems on what topic was being covered. Now I have a fairly decent understanding of Python even though I still don't understand what's being said in this subreddit sometimes.

Now I want to pursue a particular stream in Python and be employable in 2 years right when I graduate. I thought of going into data science and Machine Learning but browsing through those subs I realised that they are very vague on where to start learning them. They also seem very math intensive and boring.

I am willing to spend very long hours learning something but I want it to be relevant enough to the techscape so that I can be employable with a good salary.


r/learnpython • • Dec 10 '22

2,000 free sign ups available for the "Automate the Boring Stuff with Python" online course. (Dec 2022)

590 Upvotes

If you want to learn to code, I've released 2,000 free sign ups for my course following my Automate the Boring Stuff with Python book (each has 1,000 sign ups, use the other one if one is sold out):

https://udemy.com/course/automate/?couponCode=DEC2022FREE

https://udemy.com/course/automate/?couponCode=DEC2022FREE2

Udemy has changed their promo code and severely limited the number of sign ups I can provide each month, so only sign up if you are reasonably certain you can eventually finish the course. The first 15 of the course's 50 videos are free on YouTube if you want to preview them.

YOU CAN ALSO WATCH THE VIDEOS WITHOUT SIGNING UP FOR THE COURSE. All of the videos on the course webpage have "preview" turned on. Scroll down to find and click "Expand All Sections" and then click the preview link. You won't have access to the forums and other materials, but you can watch the videos.

NOTE: Be sure to BUY the course for $0, and not sign up for Udemy's subscription plan. The subscription plan is free for the first seven days and then they charge you. It's selected by default. If you are on a laptop and can't click the BUY checkbox, try shrinking the browser window. Some have reported it works in mobile view.

Sometimes it takes an hour or so for the code to become active just after I create it, so if it doesn't work, go ahead and try again a while later.

Some people in India and South Africa get a "The coupon has exceeded it's maximum possible redemptions" error message. Udemy advises that you contact their support if you have difficulty applying coupon codes, so click here to go to the contact form. If you have a VPN service, try to sign up from a North American or European proxy.

I'm also working on another Udemy course that follows my recent book "Beyond the Basic Stuff with Python". So far I have the first 15 of the planned 56 videos done. You can watch them for free on YouTube.

Side note: My latest book, Python Programming Exercises Gently Explained is a set of 42 programming exercises for beginners for free or as a 99 cent ebook.

Frequently Asked Questions: (read this before posting questions)

  • This course is for beginners and assumes no previous programming experience, but the second half is useful for experienced programmers who want to learn about various third-party Python modules.

  • If you don't have time to take the course now, that's fine. Signing up gives you lifetime access so you can work on it at your own pace.

  • This Udemy course covers roughly the same content as the 1st edition book (the book has a little bit more, but all the basics are covered in the online course), which you can read for free online at https://inventwithpython.com

  • The 2nd edition of Automate the Boring Stuff with Python is free online: https://automatetheboringstuff.com/2e/

  • I do plan on updating the Udemy course for the second edition, but it'll take a while because I have other book projects I'm working on. If you sign up for this Udemy course, you'll get the updated content automatically once I finish it. It won't be a separate course.

  • It's totally fine to start on the first edition and then read the second edition later. I'll be writing a blog post to guide first edition readers to the parts of the second edition they should read.

  • I wrote a blog post to cover what's new in the second edition

  • You're not too old to learn to code. You don't need to be "good at math" to be good at coding.

  • Signing up is the first step. Actually finishing the course is the next. :) There are several ways to get/stay motivated. I suggest getting a "gym buddy" to learn with. Check out /r/ProgrammingBuddies


r/learnpython • • Feb 08 '21

FINALLY Deployed a Model to production, it only took 11 Months!!!!!

590 Upvotes

I've been programming in python for about 2 years now, and I wanted to learn how to deploy a machine learning model in a production system. I thought how hard could it be???? It should only take me about 3 weeks, at the most, to learn how to do it, and boy was I wrong!!!!!! I didn't just want to take a course, I wanted to do something from scratch, and learn it myself since that's the advice the sub often preaches.

The project that I decided to focus on using a machine to live stream audio from the web browser and generate predictions. Specifically wanted to generate predictions on gender, age, and country of origin.

When I started this project I had no idea how to do it, along the way I ended up learning about:

  • Machine Learning Pipeline, and experimentations

  • Containerization and deployment using Docker, and Kubernetes

  • Continuous deployment and integration with Circle CI

  • Web Design

  • Javascript, HTML, and CSS

  • Socket programming and API

  • Flask

  • DNS and Cloudflare

  • NGINX

  • Bash scripting

  • Google Cloud

  • Digital Ocean

  • Heroku

  • Unit Testing, Integration testing

  • Linux

Who knew there was so much involved in a deployment. I'm not going to lie, it was very painful, and it took me a full 11 months to get it to work. I was stuck on 1 problem: how to stream audio in real-time and pass it through a socket API in real-time, for 5 months. I did feel like giving up, especially since it wasn't a requirement for my job, but my ego wouldn't let me. I'm so glad that I persevered, I spent so many nights researching and reading about how to complete this project.

I gained a lot of hard skills in this project but the most important one was how to google error messages, and I learned the importance of thinking through the architecture before you begin the project, I changed the architecture, at least 4 times, and if I had spent time on it before I would have finished earlier.

I couldn't have done it without a Reddit, specifically: r/learnprogramming, r/docker, r/learnpython, r/flask, r/learnmachinelearning, r/googlecloud, r/devops I asked so many questions on here, and thank you to all the people that took the time to help a brother out. I really appreciate it.

If you are curious about the site it's called commvoice I know that the HTML isn't the best right now, I still need to do some work on the CSS component.

I'm so glad it works. My next steps:

  • Make the home page more pretty

  • Add more metadata about the model, and remove the model from GitHub

  • Create the model for age and Let me know your thoughts.

Github


r/learnpython • • Nov 07 '16

Python 101 Book FREE for 48 hours!

585 Upvotes

Today I am releasing my first book, Python 101, for free for 48 hours. Python 101 was written as an introduction to the Python programming language. While it is intended for beginners, some have claimed that they needed more hand-holding than this book provided for them. So I currently recommend it as an introductory and intermediate book for developers that are looking to learn Python.

When I originally wrote the book, I noticed that there were few or no books available that described how to create executables of your code or distribute your code via Python’s Package Index (PyPI). Python 101 covers these topics as well as introducing the reader to Python’s standard library, how to install 3rd party packages and an introduction to some of the most popular 3rd party packages for Python, such as SQLAlchemy, requests and virtualenv.

Python 101 has 5 sections, 44 chapters and 295 pages.

You can get Python 101 for free on Leanpub using the following link: http://leanpub.com/python_101/c/48hours

If you happen to have a Gumroad account, then you’ll be able to get the book free there as well by using the following offer code: 48hours

You will get the PDF, epub and mobi versions of the book. You can see a full table of contents on the Leanpub site

If you like my first book, you can get its sequel, Python 201: Intermediate Python for 50% off here: http://leanpub.com/python201/c/50percent

I also write a fun Python blog that has many other tutorials on it.


r/learnpython • • Mar 19 '20

Just a quick thank you

580 Upvotes

I've never asked a question here but I've learnt so much from reading and lurking so thank you to everyone.


r/learnpython • • Apr 05 '23

2,000 free sign ups available for the "Automate the Boring Stuff with Python" online course. (April 2023)

578 Upvotes

EDIT: The sign ups are all used up. Remember that the Free Preview is enabled for all videos, so you can still watch them all on the course home page. And the first 15 videos are also on YouTube.

If you want to learn to code, I've released 2,000 free sign ups for my course following my Automate the Boring Stuff with Python book (each has 1,000 sign ups, use the other one if one is sold out):

https ://udemy .com/course/automate/?couponCode=APR2023FREE

https ://udemy .com/course/automate/?couponCode=APR2023FREE2

Udemy has changed their promo code and severely limited the number of sign ups I can provide each month, so only sign up if you are reasonably certain you can eventually finish the course. The first 15 of the course's 50 videos are free on YouTube if you want to preview them.

YOU CAN ALSO WATCH THE VIDEOS WITHOUT SIGNING UP FOR THE COURSE. All of the videos on the course webpage have "preview" turned on. Scroll down to find and click "Expand All Sections" and then click the preview link. You won't have access to the forums and other materials, but you can watch the videos.

NOTE: Be sure to BUY the course for $0, and not sign up for Udemy's subscription plan. The subscription plan is free for the first seven days and then they charge you. It's selected by default. If you are on a laptop and can't click the BUY checkbox, try shrinking the browser window. Some have reported it works in mobile view.

Sometimes it takes an hour or so for the code to become active just after I create it, so if it doesn't work, go ahead and try again a while later.

Some people in India and South Africa get a "The coupon has exceeded it's maximum possible redemptions" error message. Udemy advises that you contact their support if you have difficulty applying coupon codes, so click here to go to the contact form. If you have a VPN service, try to sign up from a North American or European proxy.

I'm also working on another Udemy course that follows my recent book "Beyond the Basic Stuff with Python". So far I have the first 15 of the planned 56 videos done. You can watch them for free on YouTube.

Side note: My latest book, Python Programming Exercises Gently Explained is a set of 42 programming exercises for beginners for free or as a 99 cent ebook.

Frequently Asked Questions: (read this before posting questions)

  • This course is for beginners and assumes no previous programming experience, but the second half is useful for experienced programmers who want to learn about various third-party Python modules.

  • If you don't have time to take the course now, that's fine. Signing up gives you lifetime access so you can work on it at your own pace.

  • This Udemy course covers roughly the same content as the 1st edition book (the book has a little bit more, but all the basics are covered in the online course), which you can read for free online at https://inventwithpython.com

  • The 2nd edition of Automate the Boring Stuff with Python is free online: https://automatetheboringstuff.com/2e/

  • I do plan on updating the Udemy course for the second edition, but it'll take a while because I have other book projects I'm working on. If you sign up for this Udemy course, you'll get the updated content automatically once I finish it. It won't be a separate course.

  • It's totally fine to start on the first edition and then read the second edition later. I'll be writing a blog post to guide first edition readers to the parts of the second edition they should read.

  • I wrote a blog post to cover what's new in the second edition

  • You're not too old to learn to code. You don't need to be "good at math" to be good at coding.

  • Signing up is the first step. Actually finishing the course is the next. :) There are several ways to get/stay motivated. I suggest getting a "gym buddy" to learn with. Check out /r/ProgrammingBuddies


r/learnpython • • Dec 15 '19

What is the point of __name__ == '__main__' in Python programs?

577 Upvotes

When I look at other peoples code, I frequently see

if __name__ == '__main__':

What exactly does this do and mean?


r/learnpython • • Jan 26 '23

I’m so excited, and most of the people in my life “Don’t get it.”

575 Upvotes

Sorry if this doesn’t belong here, but…

I’ve been an IT professional for 11 years. I’ve taught myself how to do many many things.

Today, I was able to finally make the pieces click to understand how to write, organize, and understand Python. I am so excited to begin my journey through this language and begin using it to make things start working better for me, my company, my family etc.

I had to share with some people who understood.

Thanks, that’s all.


r/learnpython • • Nov 10 '20

Just completed my first job on Upwork!

575 Upvotes

Holy shit, that was a wild ride.

So, I've just completed my first job on upwork and, jesus god, was it harder than I thought. The actual job wasn't very difficult although I totally suck at programming so it took way longer than it should have. I learn an absolute ton from it and wanted to share it with all you guys as a way of paying back for all the good advice I've been given.

The job

The job was to scrape financial data from a bunch of websites which the client had already compiled. The data was structured as an excel spreadsheet with hyperlinks embedded in text.

Initial thought process

  • Cycle through the spreadsheet, parse all hyperlinks into a list for later.

  • As all the data is from the same website, I'm going to scrape one page and get all the relevant data, then loop over it for the rest.

  • I'm going to add these values as I go along into excel through Python.

  • This will be fairly easy.

What actually happened

  • I spent about 30 minutes trying this in vscode, setting up a virtual environment and after running my program a few times, I realise I couldn't see shit. At this point, I got annoyed and transitioned into a Jupyter Notebook. This made seeing what I was doing a lot easier and I'd recommend any data-centric projects to be done in Juypter.

  • I spent about an hour having trouble with list comprehension and loops. Turns out if you run a loop within a loop, you're going to get it running twice and I wanted to run two loops parallel to each other. I solved this by using for x,y in zip(list1, list2):

  • I've always said I hated parsing text because everything seems so complex. Today, I overcame my fear using ' '.join, split(), and strip(). This probably isn't much to a lot of people, although it all came together for me today and it's something I'm really happy with.

  • When it came to webscraping, I got really lazy and paid the price for it. I used list slicing on elements incorrectly and ended up having it so it worked for my sample size (first two websites in list), although when it got to the latter ones, it started to do funky stuff so I had to start all over again.

  • Before that, I deleted all my code to start again because I thought I was parsing data incorrectly. Turns out it was just the unicode symbols for Euro signs :( Check it's actually wrong before rage-quitting.

  • Sometimes, plans don't go the way you want. I was originally hoping to fire off a load of numbers from juypter into excel in this beautiful streamlined vision. After spending so much time parsing text from beautifulsoup, I decided to give up on that dream for today and, instead, think outside the box. I ended up printing data to a text file, importing it via excel, cleaning it in excel (EDIT: I say "clean", it was deleting some punctuation marks and unwanted letters from the numbers), and then copy and pasting it. I think it's also only fair for me to mention this took about 40 minutes - I spent so long printing formatted output in Jupyter and really enjoying it that I forgot about the task. I spent a while getting the data to save horizontally with the right delimiter so I could copy and paste it into the clients spreadsheet.

  • There's a lot of stop-start, especially as a non-professional, self taught person which feels fairly natural. I think if you know what you want to do, you can Google through it with some persistence but if you can't say how you'd approach the problem it's infinitely harder (like when I wanted to make my streamline dream) so you might have to just give up on a fancy idea and stick to what you know sometimes.

Hope you enjoyed reading!

EDIT: Thank you for all the awards! Really kind of you.


r/learnpython • • Aug 25 '25

I’m 70. Is it worth learning Python?

571 Upvotes

I don’t work in computers at all, but enjoying doing some coding. Taught myself 8086 assembly language in 1984. Later on I learnt C, up to a lower-intermediate level. Now at 70 is it worth learning Python? 🐍 I don’t have any projects in mind, but it might be cool to know it. Or should I develop further my knowledge of C?


r/learnpython • • Nov 26 '20

I just want to say thanks, man.

571 Upvotes

This is by far the best community ive ever seen on reddit and ive been a long time lurker of reddit before i ever made an account. Im a photographer on the side and I thought that was the best subreddit but nope, you guys take the virtual cake. Thank you for all you do!

Sincerely,

a noob in the programming world.

P.s. your kindness goes a LONG way and it makes me hopeful that together we can create something amazing. Keep being you Kings and Queens. You dont get enough credit.


r/learnpython • • Jan 24 '21

For everyone who's wondering what they're getting into with programming

567 Upvotes

I've been lurking here for a while and haven't really posted much, but I've seen a few themes and I thought I'd leave something maybe some would find useful. I've been a developer professionally for a long time and I've been writing code for as long as I could see code doing something interesting for me, from 8 years old on my Commodore 64 to my 40s. If you're just getting started or you're losing direction or getting stuck in the weeds, read on and maybe I'll be interesting.

First, at every level of my growth I've run into walls and doubted whether I should be doing this for a living. Definitely in the last year. I get frustrated and angry. But I've learned (as a few folks have echoed here) that it's part of the game. That doesn't automatically make my frustration go away, but it helps to understand that the sheer volume of information in this field is staggering. You're not ever going to learn 10% of it. Start with computer architecture and work your way up and out and it never ends. Programming touches every aspect of it - networking, firewalls, filesystems, memory, processes and threads, UX, security, it goes on and on. You might be thinking that once you get syntax and some patterns memorized you're good to go, but trust me, the longer you stick with it, the more you see. I felt golden maybe five years ago, and then my job at the time got me into containerization and now I'm all in Kubernetes and AWS and I was completely lost for a bit there. The only skill that really matters is persistence. And confidence. I would include humility in the list but that's really not a requirement. (You can be a jerk programmer and totally get away with it, but don't)

The other post I see here a lot is asking what to do with Python or what to learn. For what to learn, see above. Learn enough to get a job. Maybe I'll do another post on that sometime. But the what to do is interesting. In my experience there are two kinds of programmers - nine-to-fivers and tinkerers. I am personally a tinkerer. I have a dozen projects sitting around in various stages of progress and a few raspberry pis running halfway broken code. The project that's been getting the most attention lately is a media player of sorts. I originally wanted a way to have my music collection be more accessible and portable. I'm not very friendly with these cloud music services, I wanted my own thing. So it started as an interface to check in and out music files to my phone, library book style. Then I started adding things on, like a friendly search page for when I'm at the record shop and I want to flag an album I'm looking for or to see what I already own. Other projects are an invoice generation add-on for a popular bug tracker that I was using at one time for side gigs. Then there's the one that sorts old digital pictures by file timestamp or tagged date into month/year folders. If you look around you'll find support for whatever you want to get into. I was curious if I could serve up my library of home videos via Roku, and bam, they have a developer portal. IMDb has a developer portal. Wikipedia has an API. The sky is the limit. Basically, put your head in the clouds and wonder what would be super cool and fun to write and you'll find a project with built-in support on the internet. If it sounds too advanced, here's another skill: breaking big problems down into little problems. Have no idea how to get started calling some third party API? Look it up, find some samples, make them work. You'll see that "how to call an API" is really just "what's the difference between GET and POST" plus "best logging practices" plus "how to do exponential backoff". Every problem leads to a bunch of questions that are themselves smaller problems, each filled with questions that lead to more problems.

So if problems and questions aren't your jam, I hate to say it, you may be getting into the wrong hobby/career. It's fun though, serious fun. So stick with it and see where it takes you for a while.

update: u/baubleglue correctly notes that there's more to getting into programming than persistence and confidence, and I promote their take on it. In my context I meant this as what's important when you're in the game and you hit a wall.


r/learnpython • • Jul 16 '22

What does it mean "int' object is not callable"?

562 Upvotes

I'm trying to do a function but every time I get a "Type Error".

The code is:

10*((1)**3)-35*((1)**2)+50(1)-24

Thanks so much!


r/learnpython • • Aug 02 '19

PSA: To all beginners, learn how to use unit tests early in the learning process

562 Upvotes

I'm the last person who ever wants to write unit tests but, when you know you have to write unit tests you become a better engineer. You write smaller functions, you have less bugs and realizing how difficult it is to write a high coverage unit test the better you design your functions and ultimately your program.

edit: How to test hello world!


r/learnpython • • Jul 12 '18

2000+ free programming books on github

562 Upvotes

I just stumbled upon this gargantuan collection of 2000+ programming books. Many of them are Python, too: link. I guess filtering out the relevant information is more important than ever...


r/learnpython • • Apr 08 '21

6 months in and my 1st Python App is up and Running!

557 Upvotes

I know there are a lot of people on here like me who recently took up coding in one form or another. COVID flattened my industry and as I looked around for other directions to turn, studying python eventually seemed like the most open-ended and feasible choice.

After many months of studying I was watching a coding interview on youtube where a prospect was asked to construct a number to roman numeral converter function. I stopped the video and decided I would try to build my own. It took longer than it should have, and I'm sure it's not the best way to do it but I got it working in python and eventually (like 5 minutes ago) online as a Flask app.

I just want to shout out beginner programmers young and old. I'm a 43 year old composer/musician and while no one is really in need of a new number to roman numeral converter, the process helped solidify what I have learned in 6 months and then some.

There were many obstacles along the way, a lot of head scratching and error handling, but man, even if this is the lowest fruit... It is wildly satisfying to have a program I wrote from scratch up and running.

A year ago I couldn't print "Hello World" if my life depended on it. Stick with it!

My thanks to the community as well!

-- UPDATE April 9 2021--

People's interest and encouragement has gotten me to get my act together on Github, thanks guys!

For anyone interested:

https://github.com/AviGranite/NumToRoman

Here's a working Flask app I made out of it:

https://avigranite.pythonanywhere.com/

Like I said, it's nothing fancy but it works. I originally had it working both ways, roman to integer, integer to roman but I found a bug so I'm working to add that functionality.


r/learnpython • • Apr 18 '20

Where do people get data to "play" with?

554 Upvotes

I see a lot of projects online, sometimes even on /r/Python that use data they parsed to make cool graphs, statistics, etc.

Where do people get that data? Is there a website for most subjects in life? What do I search for to find the average price of a car, for salaries, for the best TVs of 2019, Laptop prices for the past few years and plenty other subjects? I just threw a bunch of random stuff that popped into my head, but you get the idea.

Thanks in advance :)


r/learnpython • • May 27 '19

"Automate the Boring Stuff" author is live streaming Python programming on Monday evening 5/27, 6pm Pacific

554 Upvotes

Hi Reddit! I'll be live streaming myself working on a few different text-based games in Python on Monday, 5/27 at 6pm Pacific:

https://www.twitch.tv/alsweigart/

I'm creating a collection of short, complete, text-based Python games. The idea is to create several examples for beginner/intermediate programmers to look at to see how programming concepts come together into a complete program (while still being small enough to understand). The current collection is on GitHub at: https://github.com/asweigart/PythonStdioGames/tree/master/src/


r/learnpython • • Aug 18 '18

When I'm coding, I don't feel stupid anymore

553 Upvotes

I was diagnosed with Asperger syndrome when I was little (so i'm literally autistic), and while i don't 100% accept this diagnosis, I'm not completely convinced it's not correct either. I'm able to manage the worst of my depression and anxiety through routine and lifestyle, and have memorized enough do's and don'ts to navigate most but not all social interactions without upsetting people, but I have trouble focusing, remembering to do things, not offending people, and occasional bouts of crippling depression with self loathing and suicidal thoughts. At 27 years of age, I have dozens of moments per day where I think or even say out loud "being retarded sucks". When i'm coding though, I don't feel autistic anymore.

When i'm coding, I get into a flow state and I don't feel anxious, don't think about suicide, and don't feel the need to drink. Even when I get frustrated, as all people who code do, I'm excited to find a solution. There is always a logical reason that the computer does what it does (not always the case with people), even if I haven't yet figured out what that reason is, and it is possible to find a rational solution by breaking down the problem into smaller and smaller components. Unlike the rules that dictate social interaction, which seem to update frequently, without warning and everyone but me understands these rules and I get penalized for breaking them, the 'rules' that dictate a computer's behavior stay the same even if software updates make it sometimes seem like they don't. Most importantly though, when I am learning something new with Python and it 'clicks', or when I figure out how to do something better than I was doing it before, I feel like a f***ing genius. I feel like "Even though you are a complete (fornicating imbecile) in every other area of life, it looks like you have finally found something you are good at, Douchabag_Dan!"

I am so grateful to live in an age where this exists. I'm so grateful that Python has such a helpful community that makes it easy to learn and get started. Just wanted to share my gratitude. Thanks for reading.


r/learnpython • • Apr 27 '21

I finally built something!

546 Upvotes

I am so freaking pumped right now. I finally built something that I did not copy directly from a video tutorial and it feels freaking amazing!

This is just a simple program that pulls data from the International Space Station API Where the ISS at? and it tells you the Altitude, Longitude, Latitude and Velocity (mph) of ISS in 3 second intervals.

There is a bit more I would like to do like add a timestamp but this is my first real program I've put together myself.

Any thoughts on what/where to improve?

import requests
import time


def get_iss_data():
    iss_api = 'https://api.wheretheiss.at/v1/satellites/25544'
    request = requests.get(iss_api).json()
    iss_latitude = request['latitude']
    iss_longitude = request['longitude']
    iss_altitude = request['altitude']
    iss_velocity = request['velocity']

    print(f'''
---------------------------
Real-time ISS Location:
---------------------------
Altitude: {iss_altitude}
Latitude: {iss_latitude}
Longitude: {iss_longitude}
Velocity MPH: {iss_velocity}
---------------------------
    ''')


def iss_current_data():
    i = 1
    while i <= 5:
        get_iss_data()
        time.sleep(3)
        i += 1


iss_current_data()

r/learnpython • • Nov 15 '20

I really enjoy automating processes with python, is there a job opportunity for that?

546 Upvotes

I’ve struggled for a long time with what I actually enjoy doing. I started learning python a couple months ago and started writing scripts to automate some processes at my job and I really enjoy It! I want to continue doing this to help companies scale as they grow. Is there a job title that handles this? Or are there other skills/languages I should learn to be able to continue to do this?

I’m new to this industry so that may be a dumb question but I have no one to really ask except this community.


r/learnpython • • Aug 21 '20

How Do I Actually Build Something With Python?

546 Upvotes

I've been programming in Python for a while now. I'm familiar with all the basic functionalities and have been working on algorithms for a while as well. My question is, how do I actually build something solid with Python (say, an application, or a program that automatically replies to all my emails with a pre-written message)? I simply have no clue how to do that. I'm only familiar with the "logic" of Python, but I can't "build" anything with it. Where do I start? What do I learn?


r/learnpython • • Mar 17 '16

Beginner's Python cheat sheets

545 Upvotes

I recently made a set of cheat sheets aimed at beginners, and thought they might be useful to some people here.

The first sheet provides an overview of many basic concepts in Python. Individual sheets cover lists, dictionaries, if statements and while loops, functions, and classes. You can download individual sheets, or download a pdf that includes all the sheets in one document.

Cheat sheets have been really helpful to me at times when learning a new language or framework, and I hope these are useful to some people as well.


r/learnpython • • Dec 13 '21

How I became the most powerful padawan

544 Upvotes

This is a 101 example of an automated task I wrote yesterday and I wanted to share it as an example for those who are thinking whether learning Python is worth it or not.

I purchased "StarWars The Fallen Order" this weekend. In the game, the main character is a padawan and you need to unlock the different powers by leveling up. Well, I wanted them all as soon as possible.

1 hour into the game I found a meditation point (where you can rest, save and enemies respawn) close to an entrance where a Stormtrooper with a machine gun appears. You can kill him easily by just reflecting the laser blasts.

So I thought: "hey, I could meditate, go to the entrance, kill him, and go back to the meditation point again and again until I reach level 50". Problem is, you need to do that 4000 times.

Python has a very easy to use library to control your keyboard and mouse named pyautogui. It takes 5 minutes to read how to use the keyboard and 5 more how to use the mouse.

So, each iteration should do this:

  1. Walk from the meditation point to the entrance

  2. Reflect the blasts

  3. Walk back to the meditation point

  4. Meditate and exit the menu

Points 1 and 3 are the same except for the direction. I just need to hold 'w' and 's' for the same amount of time (hold, not just press). Here is the code:

walk_time = 2.5

def walk_to_the_enemy():
    pyautogui.keyDown('w') 
    time.sleep(walk_time)
    pyautogui.keyUp('w') 


def walk_back():
    pyautogui.keyDown('s') 
    time.sleep(walk_time)
    pyautogui.keyUp('s') 

For point 2, reflect the blasts, I just need to click the right button of the mouse very fast. This is easy because you can define how many clicks and the interval between them:

def attack(interval=.05, duration=6):
    clicks = int(duration / interval)
    pyautogui.click(button='right', clicks=clicks, interval=interval)

Finally, the menu. You need to click 'E' to enter the menu, 'R' to actually meditate and 'ESC' to exit. Keep in mind that between these actions you need to wait some seconds until the action is performed:

def meditate(time_menu_transition=4):
    pyautogui.press('e')
    time.sleep(time_menu_transition)
    pyautogui.press('r', presses=5, interval=.2)
    time.sleep(time_menu_transition)
    pyautogui.press('esc', presses=3, interval=.5)
    time.sleep(time_menu_transition)

As a note for this last function, I pressed several times each button because the time each step needed was not consistent. Maybe sometimes 2.5 seconds, and others 3.5 seconds.

Once I had all this, I put them together:

def levelup_iteration():
    walk_to_the_enemy()
    attack()
    walk_back()
    meditate()

And the main function, with an offset time and a counter. The offset time was 5 seconds so I had time to switch windows (from the terminal to the actual game):

def main():
    time.sleep(5)
    count = 0
    while True:
        levelup_iteration()
        count += 1
        str_count = f"       {count}"[-5:]
        print(f"Count: {str_count}")

12 hours and 4000 troopers later I'm level 50 in the beginning of the game.

I like this example because is one of the most simple ones with a real wide application many people will like to use in other games, but it doesn't end there. I used autogui to automate some tasks I had to do with Photoshop and 700 pictures to remove some errors... and that's just a library to control the keyboard and mouse. I use Python everyday at work even when the task is not necessarily software related. It will increase your efficiency dramatically.

Hope you enjoyed it.