r/learnpython • • Mar 30 '21

How are you ‘planning’ your code?

349 Upvotes

There’s a thousand videos on Youtube on how to code Python - but they seem to be more like function references - which you can look up in the documentation?

How you guys and girls think through what you’re about to write?

Should I write 90 lines of code then reorganise it into functions? Or start writing functions and then finally ‘use’ the functions at the bottom of your code/script?

Is there a best practice way of doing this? I’m trying to make it easier for myself so everything works like ‘lego’ - otherwise I find I get really confused

Should I write down the steps as comments and then fill in the code after?

‘’’ getjson() Function will accept json string and return TSV def getjson():

‘’’ getinputs() function will read argv[1:] and return the first parameter, or exit with error message if none specified def getinputs():

‘’’ writetosql() function will accept TSV and write it to final.db def writetosql():

‘’’ Run the functions inputs=getinputs() tsv=getjson(inputs) writetosql(tsv)


r/learnpython • • Jan 22 '21

Stuck in beginner hell

349 Upvotes

As the title suggests, I've stagnated my progress and am feeling a little frustrated. How do I break out of beginner hell and move on to more complex programming? Thank you for your time!


r/learnpython • • Jul 26 '19

I am exactly 30 days into learning and this first thing I ever made, seriously thank you to this sub.

349 Upvotes

I have zero programming experience and 30 days ago I picked up Automate the Boring stuff. I am subbed to over 700 subs and I hop between accounts a lot. I decided to write something that would help me subscribe to all my subs every time I pick up a new account. I read here that PRAW is the way to mess around with reddit.

I know this has probably been made here a billion times, but its the first thing I've ever created by myself and I am so incredibly happy.

Thank you to everyone on this sub for all the encouragement, never posted before but I lurk heavy.

Please let me know if there is anyway I can improve/cleanup.

import praw
import openpyxl
import os

# open Reddit instance: Log in
reddit = praw.Reddit(client_id='youridhere',
client_secret='secretkeyhere',
user_agent='agentname',
username='username',
password='redditpassword')
# Change directory to where your file is located
os.chdir('/Users/path')
# Confirm you're in the right directory
os.getcwd()
# Open the excel file where subs are stored
workbook = openpyxl.load_workbook('allsubs.xlsx')
# Specify sheet that data is on
sheet = workbook['Sheet1']
# Read data in each cell one by one
# Range of Cells that contain the subs
for subs in sheet['A1':'A732']:
for cell in subs:
# Subscribe to each 'cell value' which is a sub's name
# Try/Except: For subs that are invite only or are currently quarantined
# Keep going if an exception is raised.
try:
print(reddit.subreddit(cell.value).subscribe())
print('You have subscribed to: ' + cell.value)
except Exception:
pass
print("\nAll done")


r/learnpython • • May 10 '21

Can I learn Python solely for data science and statistics?

348 Upvotes

I've been learning Python during my free time for a while now and I only just realized how helpful its statistics and data science applications will be for me as an undergrad. I would just like to know if its a viable choice to focus on studying how to use the matplotlib, numpy, pandas, folium and similar libraries and Jupyter Notebook without having to take a Python programming class? I already know the fundamentals, but will I be missing something important by not learning from the very "start", so to say?


r/learnpython • • Dec 23 '19

What are some creative small programs that you have coded using Python?

348 Upvotes

I am a beginner at coding with Python, so I am curious about learning what small programs or projects you all have created. I am hoping to develop my skills using Python, so I figured looking at actual code for various programs would greatly help.

Please include a short description of what the program does and the code itself in the comments below. Thank you!


r/learnpython • • Dec 11 '20

My first project: Made a COVID 19 bot using selenium, pytesseract and tweepy

347 Upvotes

Posting here to get general advice, coding tips, and how to further improve my skills

Hello! I am a self taught "programmer" been learning on and off these past 7 months. Finally, after the basics, learning version control and using APIs I was inspired to do a twitter bot that tweets COVID 19 data specifically for my city.

This is my first proper project using Git and GitHub (my previous ones were just one .py files for practice)

Twitter

GitHubRepo

This is my webscraper bot to get data from this website/tableau dashboard. I have been up several nights trying to figure out how to do a requests.get but failing every time since I have recently found out this is a dynamic website using js, which I am totally unfamiliar with. Thanks to this sub and r/learnprogramming by posting questions there I tried to learn selenium and take a screenshot of the data I need then using pytesseract, an optical character recognition module in python, to convert the image to a string so that I can tweet the data using the Twitter API.

Currently, I am very fascinated with the ease of use of APIs and I have been day dreaming of future projects using APIs. :)

EDIT: Thank you for the awards! Means a lot and gives me motivation to keep going. Currently, I have added more functionality to the bot where I can check the data before tweeting and being able to edit it. Also it can retweet now. Hehe.


r/learnpython • • Sep 22 '20

What is learning GIT?

347 Upvotes

I saw in a post that you have to learn git for most programming jobs, what exactly is git? and where can i learn it, i always just assumed its just uploading your stuff to github. not too sure if this is the right place to post this


r/learnpython • • Jan 19 '20

I am starting to think not everyone can become a programmer.

347 Upvotes

As this title implies this may come off as a more of a vent/rant than intentional. For the last 4 years, since I was in college, I have been trying to learn to program in my free time. I did "learn" HTML in a sense of now type this, this sets this up for this part of your page, etc... After that class I have since forgot many aspects of HTML and I'm starting to feel the same with using Python.

I started with Codecademy in 2016-ish when almost everything was still free. I have finished the Python modules of that as well as with SoloLearn. I have read Automate the Boring Stuff and Python Crash Course as well as following along with the examples cover to cover. Now I am re-reading Automate, Crash Course, and Mark Lutz Learning Python, 5th edition. To add to these books I have: Complete Guide For Python Programming Deep Learning with Python, Fluent Python, Learning Python Network Programming, Rapid GUI Programming with Python and Qt, Python High Performance Programming.

 

With all these resources and feeling this lost still with trying to learn a new skill. I feel with these books (with some of them being in the 1000s of pages per book) that I'm more or less wasting my time now. Granted I've been off and on learning for a few years I feel like I should be completely on another level than still at the beginning stages. It just seems like nothing has really clicked together.

I've taught myself many other skills, but this one seems to repeatedly kick my ass time and time again. I understand syntax, can usually fix an error and debug, but to actually sit down and program anything of any real value eludes me. Printing prompts asking for information and storing input variables really doesn't cut as being a programmer I feel like.

 

 

 

Mobile Edit: Thanks to all for taking time out to voice your opinions and advice. I'm understanding that I've got too much material to the point it is counter productive to coding. This is true that I have not written much of my own scripts/programs and making slight changes in the examples in my material is not productive.

As for those that have asked why I want to program, it is not for a career change but for something that I want to do. I don't want to reinvent the wheel. My background is in electrical and automation as well as PLC implementation. Currently there is one machine that has integrated C++ code for much more complex logic than that is possible with branch programming common with PLCs. I find this very interesting and was not aware of this integration until I started working here. So with some programming background it has given me quite a bit of an edge over my coworkers and most of the Engineering support which is a bonus. I eventually want programming to be a move to a more "prestigious" engineering position but not any time soon but mostly to be another hobby that I can come to enjoy and not be worried about wasting my time.

 

As of now, I will continue to try to improve my understanding with just structuring out projects I've been holding off because my fear of inadequacy (perhaps could use a better word) and sense of being overwhelmed. I'll start with a simple electrical pocket reference and eventually make it into a GUI compatible with android and see how it goes.

Much thanks again guys. This is an awesome sub by the way and quite more active than I was originally anticipating.

 

 

 

Edit #2 for formatting.


r/learnpython • • Dec 25 '19

How do you stay disciplined in learning Python?

346 Upvotes

I'm honestly curious for those of you who've stayed on track learning Python: how do you stay disciplined and consistent?

It feels like whenever I have schoolwork in the way, I can't be bothered to pick up the Automate the Boring Stuff book I've had on my shelf for nearly a few months now, or keep practicing. It's winter break now and I'm still struggling to make it a priority.


r/learnpython • • Jul 22 '18

[Meta] PSA: Please don't delete your 'Help me with XY' threads.

346 Upvotes

I sometimes see a thread with Python newbie asking a question and after getting the answer, he/she deletes the thread and doesn't even thank the commenters. Guys, you have nothing to be ashamed for, everyone was a beginner once! That's what /r/learnpython is for. If you delete your thread, not only it is rude to people who went out of their way to answer you, but you are kinda ruining it for other people who might benefit from reading the thread.

Case in point: https://www.reddit.com/r/learnpython/comments/90ya6i/why_doesnt_this_work/

/rant


r/learnpython • • Apr 16 '21

I am a proficient Python coder whose learning has plateaued. Any really useful libraries I should look into learning? Taking recommendations.

344 Upvotes

Machine learning engineer here. I love learning Python, but I'm already quite proficient, so my learning has plateaued lately. I can pretty much do whatever I need to without difficulty.

That said, Python is vast. It's totally possible that there are great tools out there which could help me improve further, and I've just never heard of them. For example, I used to think I'd seen it all, then I learned about itertools, and that was a game-changer. It helped me greatly simplify code that I had originally thought was as simple as it could get. It was exhilarating.

So what I'm looking for are things like that, general purpose utilities that can help keep code clean and efficient, and/or provide ready-made objects for common operations. Nice little nuggets like itertools.groupby, or functools.reduce, or collections.namedtuple. Why write some convoluted function to tally the elements in an array when collections.Counter does it for you in one line? Why spell out an item-getting operation explicitly every time when I could just use operator.itemgetter to define it in one place and use that everywhere else? Little niceties like these can improve your code a lot but have to be discovered, and I just feel like I haven't discovered any in a long time.

Non-niche (meaning non-ML-specific) libraries I already use very often include:

  • argparse

  • collections

  • itertools

  • json

  • logging / loguru

  • matplotlib

  • numpy

  • pandas

  • pathlib

  • random

  • re

  • sys

... there are doubtless others, but that's all I can think of for now. Am I missing any major players? Bonus point if they're already in the standard library!

Edit: If you can also provide a short one-liner about what each package does/is for/how you use it/why you're including it/etc., rather than just a bulleted list of package names, that would be extra useful in helping me to prioritize. Thanks again guys, this is great, keep 'em coming!


r/learnpython • • Dec 12 '20

Hi, can you guys suggest me any platform where I can practice various problem starting from beginner level loop, functions, classes?

344 Upvotes

It would be really helpful, I know hackathon is great way to learn but would be a bit overkill given my knowledge with this language, it's been 2 months since I've started learning but I still feel there is a lot of gaps in my learning which I want to reduce by practicing.

Edit: Guys, Thanks for such a great response. This is actually the best sub I know of, you guys are gem. I was losing hope of doing good with python but you have overwhelmed and motivated me. I am starting some of these links

I am sharing the summary of all the links you could get started with:

https://edabit.com/ - Intermediate

www.codewars.com- Bit advanced

hackerrank.com- Advanced

https://leetcode.com/- Advanced

https://runestone.academy/runestone/static/fopp/index.html- Intermediate

https://csmastersuh.github.io/data_analysis_with_python_2020/

https://www.py4e.com

https://www.pythonmorsels.com/accounts/signup/

https://cscircles.cemc.uwaterloo.ca/

https://projecteuler.net/

checkio.org

www.Codingbat.com- Medium

https://codingame.com


r/learnpython • • Sep 17 '20

For any programming language, how far can you go by just knowing the basics? How more advanced does it get?

343 Upvotes

So I’ve had a bit of experience using JavaScript as I worked as a web developer for experience. I didn’t go too far into it before I left and got a new job where I learn Python now. But what I’ve realised is, all the languages of course do all the basic foundations like arithmetic, lists, loops. And I was wondering, how much further on in terms of learning does it go? Because I found in my web developer role that most of my tasks were solved by just using these basics they teach you at the start. And the only “advancedness” of it was just how creatively you could think about how to manipulate the code to solve your problem.

Is this really all there is and any new code you learn is really just a step forward in these basics? Or is it a whole new area that I’ve not even scratched the surface of yet?


r/learnpython • • May 12 '20

Discovered that I really like Python. What should I do next?

342 Upvotes

Long story short, I've been learning web development for a while, and kept getting tripped up by JavaScript. I keep getting to a point with JS where I start thinking that programming just might not be for me. But then I came across At Sweigart's 'Automate the Boring Stuff' Udemy course, and I'm halfway through and REALLY ENJOYING IT.

Python makes a long more sense to me than JS, and while I always thought I'd be wanting to get into front-end development, I'm wondering if this is more suited to me.

SO my question is, where should I go from here? I'd love to hear your suggestions for books, other courses, resources to look into once I'm done with this course, or any websites you like that have projects where I can practice my Python coding. This might be a ridiculous question, but what do you actually... do... with Python?! I wanna do stuff! :)

EDIT: WOAH this thread blew up, thank you all SO MUCH!!! I'm so grateful for everyone's suggestions and links. I've saved lots of bookmarks and now I have lots more things to consider when this course is done. I really appreciate all the support, and I look forward to spending more time in this sub while adventuring in Python!


r/learnpython • • Mar 06 '20

Made a YouTube downloader that can download intervals of a video

342 Upvotes

Hi all

This is my first real project that I did. I made the program to help my friend in his workplace. He would have to parse text for YouTube links and intervals (and jpgs), download the whole video, trim it and repeat for the 3-5 others that day. This program accomplishes all of that and can also download full length videos (don't supply a valid interval). The frontend is build using flask.

All you need to get it to work is download, install the dependencies, install ffmpeg and then run the webserver.

Link to code on GitHub

If you have any constructive criticism or ideas for future features please don't hold back.


r/learnpython • • Mar 22 '23

What do you even code?

341 Upvotes

I am a beginner to python and all coding. I don't know much. All the recommendations are "code everyday". Practice every day is great but what do I practice? Do I open up an empty IDE and code what? I don't know how to do any projects on my own. Do I just YouTube crap and copy them or what? What do I actually code?


r/learnpython • • Mar 08 '22

Python project ideas for upper beginner/intermediate

341 Upvotes

Does anyone have some projects ideas to recommend or some kind of sites/resource to get inspired?


r/learnpython • • Oct 20 '20

Okay, now I know how to create graphs and do data analysis in Python. Now I want to know how are these things usually applied IRL in Data Analytics jobs?

341 Upvotes

I dedicated my last week learning about data viz in python. I used and learned matplotlib, seaborn, pyplot for creating graphs and doing data analyses using pandas.

My question is how are these things usually applied in Data Analysts job? Do they just create 1 python script per graph? Do they make functions for different types of graphs and export it on their presentations?

I'm asking because I've been in the reports development field for the past 5 years but sadly I've been only using pure SQL for data processing, SSIS/Informatica for ETL, then SSRS for reports and Excel for graphs.

i've never applied python on these apart from some automations here and there. I hope I can get feedback from people who worked in Data Analytics positions before and tell me how are these things applied in their day to day job.

Thank you!


r/learnpython • • Sep 23 '20

Python : is it the most enjoyable language?

341 Upvotes

very subjective and opinion driven question but in your opinion what is the most enjoyable programming langauge, I've been programming in C++ for about 3 years now. From what I have observed, people say python allows you to think more freely especially with not being bogged down with features such as a language like Java or C++ does. So I'm thinking of learning Python as a second language, is Python the most enjoyable language you have programmed in?


r/learnpython • • Nov 25 '19

Is it okay to google if you're stuck in a problem?

341 Upvotes

I have a habit of Googling every problem After trying to do it myself but I do it for the concepts and to get the logic not just copy paste.. what's on your experience how to tackle problems in coding if you're stuck in it?


r/learnpython • • May 31 '19

My first Python project: command line application that copies all files with given extension from a directory and its subfolders to another directory showing progress bar and remaining files counter.

340 Upvotes

This project was inspired by the task from Chapter 9 of Automate the Boring Stuff but I tried to push it a little bit further by adding a possibility of preservation source folder structure, log creation, progress bar, remaining files counter and command line interface.

Here is my code on GitHub.

I am new to programming and GitHub, so any feedback either on the code itself or design of README.md and so on is highly appreciated!


r/learnpython • • Jan 13 '21

How can I safely web scrape and not get blocked/banned/blacklisted?

339 Upvotes

I attempted to re-create a web scrape using the example in the Automate the Boring Stuff Udemy video, which scrapes Amazon, and I got an error.

In another thread, I was informed about "User Agents", and how apparently Amazon doesn't like mine. I don't recall the concept of user agents being mentioned during the tutorial. It definitely wasn't part of the web scrape video.

If you don't have a programming background, learning these kinds of things "after the fact" can be frustrating.

  1. Are there resources that I should consider using that might help with certain fundamental Python concepts that tutorials may not cover? Perhaps my understanding or expectations of learning code is unrealistic, however I was thinking that any video or learning material should exactly be able to be replicated as is.

  2. Is there a way to know who might block/ban you for not using an appropriate user agent/header?

I read that Amazon blacklists accounts that web scrape, and I can't imagine how people would even know this.

As I experiment, I don't want to compromise my ability to shop or access information because I violated a rule that I didn't even know about.

I was hoping to experiment with web scraping to track prices for retailers also. Not a complex project or anything, but I would like to write programs to see if I could keep pace with prices from time to time without risk of being blocked.


r/learnpython • • Nov 11 '19

Holy shit is QT Designer useful

339 Upvotes

I love to do UI design. I love to make UIs. And I like to add functionality to things. Thats literally what I can do now. Why did I not know about this sooner. Like a weekend long project could be done in a day or so. Just wanted to come here to express my love for this wonderful program


r/learnpython • • Jul 01 '20

Why do people use .format() method when f string literal exists?

338 Upvotes

Hello all,

I seem to encounter a lot of documentation and tutorials that use .format() method instead of f string literals.

Personally,

print("I can't seem to {} of a {} why someone {} {} {}".format('think', 'reason', 'would', 'prefer', 'this'))

versus

easily = "easily"
sentence = "sentence"
this = "this"
print(f"A much more {easily} readable {sentence} such as {this}")

F string literal is always much easier to decipher and thus avoid errors.

Perhaps there's some benefit of .format() that I'm unaware of. Googling hasn't brought up much on the debate.

Cheers!