r/learnpython • • Dec 08 '20

Could someone explain the use of "self" when it comes to classes.

418 Upvotes

Ik this is a basic question but I'm just learning to code and I'm learning about classes. For whatever reason I cannot understand or grasp the use of the self variable in fictions of classes. Hopefully someone's explanation here will help me...


r/learnpython • • Jun 04 '20

Finally used Python at work for something useful

418 Upvotes

I'm a policy consultant and deal with a lot of basic statistics at work, particularly when we create city indexes on various topics (SDG compliance, competitiveness, Sustainable mobility...). We're refining our criteria to make sure indicators on one index do not correlate negatively to each other to make sure they all "row in the same direction". I started ATBS a few weeks ago because there's a lot of Boring Stuff in my work with the idea being to move on to statistics and PyQGIS after that (I'm the official 'Guy Who Does Maps'). So today I did a few searches and created correlation matrices for our past indexes with this code.

import pandas as pd

df = pd.read_excel (r'Path where the Excel file is stored\File name.xlsx')

#df = pd.read_excel (r'Path where the Excel file is stored\File name.xlsx', sheet_name='your Excel sheet name')

#this imports only one sheet

corrMatrix = df.corr()

#print(corrMatrix)

import seaborn as sn

import matplotlib.pyplot as plt

sn.heatmap(corrMatrix, annot=True)

plt.show() #this is if you want the image

df.to_excel("output.xlsx") #this exports the excel

Boom. I'd probably have spent a long, long time in Excel dealing with missing values and whatnot and this was done in 10 minutes max.


r/learnpython • • Jun 12 '21

What is the difference between "is" and ==?

417 Upvotes

5 is 5 returns True, just as 5 == 5 returns True. What is the difference?


r/learnpython • • Feb 20 '21

What are you having difficulty learning or are currently struggling to learn?

417 Upvotes

I'm curious what the community here has difficulty with when it comes to learning Python. Partly because I want to see if the more experienced community here (or myself) can help point you into the right direction. . . but also because I'm trying to come up with video tutorial ideas for future content and would love to hear from Python learners what would be most useful to dedicate our time on.

I'm looking forward to hearing what you guys have to say!


r/learnpython • • Sep 21 '18

I made a cheatsheet for a co-worker thought it could be of use here.

417 Upvotes

I made a cheatsheet for beginner to intermediate Python users about concepts I think everyone should know. Check it out and let me know what you'd want to see. Suggestions are more than welcome.

https://github.com/gpetepg/python_tips/blob/master/python_tips_1.ipynb

Edit: Added a couple string formats! Let me know how I should name the files... Also working on itertools, collections and functools for sheet 2.

Edit 2: Use this link https://github.com/gpetepg/python_tips


r/learnpython • • Dec 03 '22

Good Python Exercises?

416 Upvotes

What's a good exercise for me to try? I've been learning Python for a bit over a month now and I wanna test what I've learned.


r/learnpython • • May 13 '21

Sharing my win.

415 Upvotes

I work in global supply chain and logistics for a project management group of a global apparel company. I’m considered the tech guy on the team and the data nerd. I manage projects and handle all reporting, automation, etc. pretty fun stuff.

Well, today I did something that saved us 12 hrs of delay in execution in our supply chain by writing a script that pulls data from GCP out to an oracle db and then execute sequential sql statements to transform the data and refresh tables that feed tableau dashboards. It all now takes less than 20 minutes via a batch file in the background.

Millions of rows of data for three specific tables, tons of calculations, etc.

Python confidence is way up folks and it’s due to the knowledge sharing that is to be had in this group and others dedicated to the art of Python.

Felt like I should share my lessons learned.

  1. I need to get better at testing

  2. CLOB sucks so utilize sqlalchemy types for varchar

  3. Tnsnames are not hard

  4. 64 bit memory usage trumps 32 bit on large datasets

  5. Chunk size is a godsend.

Cheers to you.


r/learnpython • • Dec 15 '20

Thank you :3

414 Upvotes

Honestly, I just wanted to give a massive thank you towards everyone on this subreddit. After struggling through ruts, confusions, and a horrid professor-- I had my state Python final today, and I actually passed!

A huge reason for me being able to pass is because, well, all of you guys! Anytime I had a question I posted here, it was always answered in no time at all. Most people would even go above and beyond, taking the time to sit down and explain why something worked the way it did or generally go into greater detail than what my professor did. And that helped me out so much during my exam, because you all had such wonderful and easy-to-understand ways to teach it.

I know it's short and small but- I wanted to do something atleast. Thank you everyone, I appreciate you all more than I can even say for helping me so much.

Edit: This is the first time I've ever gotten awards, thank you so much oh my goodness. I didn't think this would get much attention at all

Edit2: Wow-- I wasnt expecting to get more than 10 likes, much less nearly 400. Thank you everyone!!


r/learnpython • • Mar 23 '20

Why do all programming languages start with "Hello World"?

414 Upvotes

like, it can be anything. it can be print("Hi") but no, every teacher, every lesson, every website, teaches you "Hello World". why?? is it just a programmer meme or smth?


r/learnpython • • Dec 30 '16

I fixed a bug in an open-source project for the first time ever today!

414 Upvotes

I was installing a Django plugin that crashed when I attempted to migrate the database during installation. I had no idea what caused it. First I searched google and stack exchange. Then I almost posted an issue on the github, but I decided I should dig a little further before posting. After 20-30 minutes of floundering around (and reinstalling from scratch a couple times) I finally nailed down where exactly in the code the error was coming from (traceback wasn't super helpful). Turns out, someone fixed a bunch of tests 6 days ago and one of the tests on a migration was not updated along with the model that was updated. So I fixed it and ran it locally, and it worked!

So all I did was change the name of a Model from testmodel to tmodel and I'm sure it would have been caught by someone within a few more days, but it just feels cool to finally be able to track that stuff down on my own and fix it rather than asking for questions and throwing my hands up all the time.

Anyways, it feels pretty good, and none of my friends would get it so I figured I'd share with you guys. Hope everyone is having a happy New Year's Eve's Eve!


r/learnpython • • Apr 10 '19

My recent interview experience on Python.

412 Upvotes

Role: Automation Test Developer.

Questions asked:

1: Basics of Linux, few tricky commands, what are inodes, setting up networking etc etc.

2: Python:

Given a file, write a function which accepts a version 
number, date and returns pass or fail. 

 EDIT:
 the file structure is basically a test result log file which contains lines of information.
 Each line has a version and date, tests run and results. 
 I was supposed to return results which are pass fail based on the version number and date given.:)


Reverse a sentence without using slicing.

List comprehension basics. 

What I did right: I wrote enough code solving pythonic interview problems, and I was comfortable writing the code in the interview.

what I did wrong: Focused too much on interview type problems, like Coin change, linked list etc etc. Should have also focused on some real use cases of python. For example, how to test a code with different inputs, how to parse few lines from a file, how to schedule a cron job etc etc.

TLDR; Don't just bust your head trying to solve interview challenges from cracking the coding interview. Also learn to make some real world programs.


r/learnpython • • Aug 09 '20

Which Website is good for solving questions for Python 3 ?

411 Upvotes

except HackerRank pls.


r/learnpython • • May 01 '20

Am i still a python programmer if use stack overflow a lot and finish projects?

411 Upvotes

so i am sort of a python developer, i am an automation developer, my job is to automate tests, create framework etc.

but i find that i keep using stackoverflow a lot, question is am i still a programmer if i keep using stack overflow a lot?


r/learnpython • • Jan 16 '21

So, how can I use classes in Python?

410 Upvotes

I'm currently studying OOP, but every video I watch the guy teaching will give an example like "Dog", or "Car" and I still have no idea of in which way I can use Classes.

I imagine it can be useful to create forms, didn't think of anything else tho (I'm looking for some examples).


r/learnpython • • Jun 03 '20

what is the deal with python purists?

410 Upvotes

Hi, as a new programmer i often find myself browsing r/ learnpython and stackexhange and whilst im very thankful of the feedback and help ive been given, i can't help but notice things, especially on stackechange where this phenomena seems most rampant.

What does it mean for your code to be unpythonic? and why do certain individuals care so much?

forgive me, i may be a beginner but is all code not equal? why should i preference "pythonic" code to unpyhtonic code if it all does the same thing. i have seen people getting scolded for the simple reason their code isnt, pythonic, so whats the deal with this whole thing?


r/learnpython • • Apr 10 '20

This sub should really be enforcing proper code formatting

410 Upvotes

I know we don’t want to be as anal as SO but, getting new programmers used to paying attention to how their code is formatted and understanding how to ask good questions was a big learning point for me as a self taught programmer.

Just giving answers to people after having to spend 10 minutes deciphering their problem isn’t really helping them at all.

IMO giving people keywords to google is much more impactful. And if they don’t have the desire to sift through the results then they won’t ever enjoy programming.


r/learnpython • • Apr 11 '20

A recommendation for people with projects that they're really proud of!

409 Upvotes

Upload it to github, create a README with some explanation and instructions, then post it in r/python with the flair "I Made This". When I did this myslef (check my post on my profile) I got a lot of constructive criticism and encouragment!

It doesn't only feel great getting "nice job OP" and similar stuff but you also get a lot of ideas and improvements that you can work on.


r/learnpython • • Sep 01 '21

I did it! Finally made my first program for work :)

407 Upvotes

I finally managed to make my first program in python! So happy right now, it cost a lot of frustration, uncertainty and learning but now it works.

It's just a simple program to create a new project folder at work every time a new project starts. But I wanted it to also place the necessary files in the folders with the corresponding project name, be simple to use by work-colleagues through a GUI and be available as an exe program for said colleagues.

Am looking forward to decide my next automation project.

Some tips for fellow beginners: What helped me was starting simple and then expand what the script does. So first I created a script that creates new folders. Then those folders have to be renamed based on user input. Next step was also copying some files from other locations, place those in the right folders and rename the files etc...

Google is your friend!

Edit: I used pysimplegui as GUI


r/learnpython • • Nov 19 '19

My first application!

407 Upvotes

In October I started my Python-journey, with a full time job and a 2yo kid the spare time is scarce.
I've been following a Udemy-course and also used some android-apps to just study something every day.
2 weeks ago I made my first real script from scratch, I had a idea of automating / helping with a tedious task at work. I'm a train driver, and every train we start we fill a paper form, check some values from 2 different paper lists and enter some of that data into the control computer.

The script were terminal based and did all the calculations I wanted, checked up the values from those 2 lists (one which is short, so I just made an elseif of it, the other is long so I made a .txt with the values) and gave a summarized result.

Now 2 weeks later I've deployed it on the web with Flask to be able to share with my colleges!
With dropdowns, forms to fill and a button to run the scripts and show the result.

Thanks to inspiration from this subreddit (and others) I made it working! It's plain ugly, but the functionality is there. Guess I'll come back and sort the design with bootstrap or at least some css'ing next time I feel a dip in the studying.

I dno if there's a better way to post a image, but here's one:
Image of the result with explanations


r/learnpython • • May 18 '20

What type of questions can I expect in an interview for a Python Developer ?

405 Upvotes

Hey all,

I have an interview post 2 days for the position of a python developer hence I wanted to know what type of questions can I expect in the following areas :-

  1. Multi-threading and Multiprocessing (process, pool) in Python

  2. OOP Concepts: Metaclasses, Operator Overloading, Inheritance, different types of methods, magic methods

  3. Decorators and Generators

  4. Pytest: Fixtures and Mocks

  5. Profiling in Python

  6. Using Pickle and Customizing Pickle

I would be grateful if y'all can throw some light on this. Its my first python-dev interview kind of clueless on what to expect in the above areas.

Thanks

Stay safe and Take Care


r/learnpython • • Apr 13 '22

What is difficult in excel but easy in Python?

404 Upvotes

If you were to introduce an established excel user [non VBA] to Python, what would you suggest?

What would amaze them? In as few a lines as possible?


r/learnpython • • Oct 09 '20

Fucked up by not learning how to properly set up environment

404 Upvotes

Hello,

I have used Python for about 3 years or so now. However, I have made a huge mistake....

I always just pip install libraries from the command-line without setting up or using a virtual environment. I have used virtual environments at work before (for ML, to access my school's GPUs, etc.), I just never bothered to use one for my python projects.

Well, now I am going to start trying to make Python applications that will actually be used in a work environment, so I want to do it right. I want to abide by best practices for this sort of thing. I want to start using environments the correct way. I was going to completely uninstall Python from my computer, and then reinstall it, however I do not know if this is the best way to start. All I know is that I have like 50 libraries installed on my system itself, and those need to go.

Any help with what I should do? Also don't want to lose any of my old programs, but I know that just uninstalling Python should not directly affect this. Thank you in advance!


r/learnpython • • May 29 '20

Embarrassing question about constructing my Github repo

404 Upvotes

Hello fellow learners of Python, I have a sort of embarrassing question (which is maybe not Python-specific, but w/e, I've been learning Python).

When I see other people's Git repos, they're filled with stuff like: setup.py, requirements.txt, __init__.py, pycache, or separate folders for separate items like "utils" or "templates".

Is there some sort of standard convention to follow when it comes to splitting up my code files, what to call folders, what to call certain files? Like, I have several working programs at this point, but I don't think I'm following (or even aware of) how my Git repository should be constructed.

I also don't really know what a lot of these items are for. All that to say, I'm pretty comfortable actually using Git and writing code, but at this point I think I am embarrassingly naive about how I should organize my code, name files/folders, and what certain (seemingly) mandatory files I need in my repo such as __init__.py or setup.py.

Thanks for any pointers, links, etc and sorry for the silly question.

---

Edit: The responses here have been so amazingly helpful. Just compiling a few of the especially helpful links from below. I've got a lot of reading to do. You guys are the best, thank you so so much for all the answers and discussion. When I don't know what I don't know, it's hard to ask questions about the unknown (if that makes sense). So a lot of this is just brand new stuff for me to nibble on.

Creates projects from templates w/ Cookiecutter:

https://cookiecutter.readthedocs.io/en/1.7.2/

Hot to use Git:

https://www.git-scm.com/book/en/v2

git.ignore with basically everything you'd ever want/need to ignore from a Github repo

https://github.com/github/gitignore/blob/master/Python.gitignore

Hitchhiker's Guide to Python:

https://docs.python-guide.org/writing/structure/

Imports, Modules and Packages:

https://docs.python.org/3/reference/import.html#regular-packages


r/learnpython • • Sep 28 '19

Automate The Boring Stuff 2ND EDITION

404 Upvotes

https://nostarch.com/automatestuff2

Did you get the first edition? what are your thoughts on it and what what great books you recommend written in latest Python syntax and features?