r/pythontips • • May 20 '21

Meta Challenge website

45 Upvotes

This week I discovered this coding challenge website: https://app.codility.com/programmers/lessons/1-iterations/

Do you know any other?


r/pythontips • • Apr 18 '21

Python3_Specific .py to .exe

45 Upvotes

I want to make a python program into an executable. I have heard that you have to use pyinstaller, but I just want to know if there is any other way that I can it without pyinstaller.


r/pythontips • • Apr 06 '21

Short_Video I Created This SMS OTP Verification system using Python

45 Upvotes

I have created this python program that has 2 parts first is to send an SMS with 4 Digit OTP to the registered mobile number and the second part is to check wether the user is entering the same OTP that was sent to him and all this is handled with a Tkinter GUI


r/pythontips • • Feb 07 '21

Short_Video Optimize Selenium Python tests with Setup & Teardown methods

45 Upvotes

In this video (https://youtu.be/uZ-sgPTM0eM), we will learn how we can use SeleniumBase Setup & Teardown methods to optimize our tests even further. If you are not familiar with setup & teardown concepts, essentially, it allows you to run certain steps before and after your actual test.

To learn more about Selenium Python, you can check out the full playlist here.


r/pythontips • • Jul 28 '20

Python3_Specific Trying to automate the most annoying Monday morning process

45 Upvotes

Every morning I wake up and receive 4 emails from this company.

I have to open up each email and download each attachment.

Once I have each attachment, I have to put them into the same spreadsheet. They are sent in 4 emails because the excel sheet is huge.

From there I run a simple vlookup to see if the row of data needs to be worked on or not based on the columns for that row.

I would imagine I could write a python script for this, but to be honest I’m not a master software engineer. Just a guy that knows how to dabble with this stuff.

Posting in here for any tips from the community!


r/pythontips • • Jun 04 '16

Syntax Use Properties rather than Getters & Setters in Python.

45 Upvotes

In Python, we don't like using getters and setters. People can just overwrite variables as they see fit. However, if you'd like the functionality of getters and setters without making your users have to use them. Use properties instead:

class OneNamePerson(object):
  """
  Creates an object to reflect a Person who can only have one name.
  """

  def __init__(self, name=None):
    self._name = name

  # called when someone accesses name from the object
  # example: person.name
  @property
  def name(self):
    return self._name

  # called when someone assigns a value to name
  # example: person.name = "Tom"
  @name.setter
  def name(self, new_name):
    if self._name == None:
      self._name = new_name
    else:
      raise Exception("Can't rename OneNamePerson. "
                      "Name must remain as {}.".format(self._name))

  # called when someone calls del on the name
  # example: del person.name
  @name.deleter
  def name(self):
    raise Exception("Can't delete name.")

Now lets see how this works in action:

a = OneNamePerson()
a.name = "Frank"
print a.name # Frank
a.name = "James"
# Exception: Can't rename OneNamePerson. Name must remain as Frank.
del a.name
# Exception: Can't delete name.

r/pythontips • • Sep 20 '22

Algorithms Python Stock Exchange Simulator

44 Upvotes

Hi everyone!

I wanted to share with you a repo that I just published. It basically replicates how a stock exchange works, and you can add multiple agents (traders, market-makers, HFTs), each with its own custom behavior, and analyze how they interact with each other through the pricing mechanism of an order book.

It is a pretty niche topic, and I think that its applications are mostly academic, but since some of you are at the intersection of computer science and financial markets, I thought you might be one of the few people that could be interested! Needless to say, I would really appreciate your feedback also! https://github.com/QMResearch/qmrExchange


r/pythontips • • Aug 09 '22

Short_Video 3 Must Know Python Tips in 30 Seconds

44 Upvotes

Will cover three game changing Python programming language tips in 30 seconds. The IDE used was Visual Studio Code. https://www.youtube.com/shorts/_OgcxUA-E_k

Tip 1: Swapping Two Variables

Tip 2: List Comprehension

Tip 3: Merging DIctionaires

#python #pythonprogramming #vscode


r/pythontips • • Apr 26 '22

Short_Video Learn Python through live coding games: https://delta-academy.xyz/

44 Upvotes

Friends & I are sick of online tutorials so we’re running a group for learning to code with competitive team games

Hi, we’re a group of 4 friends and want to hear what you think about what we’re working on! We’re super early so really want feedback - if you want this to exist, register interest on https://delta-academy.xyz :)

The best experiences we had when learning Python were working on projects and hackathons. We also benefited from having a peer group (e.g. at University) - the friends we made have often lasted.

Delta Academy combines these two elements - live competitive coding games with a cohort of peers. The cohort will be ~20 people. It’s the format we wanted but couldn’t find online - so we’re creating it!

We would have to charge for running cohorts (initially just to cover the prizes!), but haven’t figured out how much yet - just want to know first if this is something people want!

Really keen to hear feedback, both positive and negative! :)


r/pythontips • • Oct 31 '21

Module A small tutorial on fetching weather 🌧️☁️ ⛈️ 🌨️ information using Python and Django

44 Upvotes

I created a small tutorial which can help you to integrate weather information in your Python application: https://geekyhumans.com/get-weather-information-using-python/


r/pythontips • • Jul 24 '21

Meta My spouse paid for some python courses to get me into a hobby. But should which OS is better for me? Some details in comment.

44 Upvotes

I run all of my apps in windows...use Manjaro for gaming ... It was simple... But now coding... What is the best choice and what should I learn.

She's non-tech and just got the course because I was thinking about it after I told her I had some free time to learn something.

I need to learn something new though... It's been almost 8 years that I didn't do something new.


r/pythontips • • May 09 '21

Meta Starting to code

44 Upvotes

I want to start coding and python seems to be a promising start. Any tips? Setup config, helpful shortcuts, and the commands and their functions, etc. I know a little bit of linux but idk if that will help me learn faster


r/pythontips • • Mar 07 '21

Python3_Specific Taking the self taught route to software engineering. Where do I start?

44 Upvotes

I want to design tools for students when it comes to discrete mathematics and number theory, but I barely have any experience with code, and all of these free boot camps are often way outdated, and or useless exercises. Where can I find practical training programs designed to help self-taught individuals? Where are the real goldmines of information? I'm one of these people that has to have an over-complicated understanding of something, so I need intricate, but concise: Like that one teacher we had or wished we'd had that could explain something once, and then you knew the whole subject.


r/pythontips • • Mar 20 '20

please explain the "return" statement to me like i'm 5 yo

44 Upvotes

r/pythontips • • Aug 09 '19

Build a Password Validator without showing user's input | Getpass | String

44 Upvotes

A simple and cool project for everyone to try.

Instead of using the input function to prompt the user to enter a password, we can use the get pass library, which does pretty much the same thing, except the input is not echoed to the console like with the input method.
https://youtu.be/Wd5if91Bt3g


r/pythontips • • Mar 25 '19

Python *args and **kwargs explained with multiple examples (video)

44 Upvotes

Python *args and **kwargs explained with multiple examples

https://youtu.be/gYym32dMlUw

Enjoy!


r/pythontips • • Mar 15 '19

15+ Video series on Python Regular Expressions (advanced features included)

44 Upvotes

This is playlist I made a little while ago but I want to know if anything is missing so I can fully complete it:

https://www.youtube.com/playlist?list=PLGKQkV4guDKH1TpfM-FvPGLUyjsPGdXOg&disable_polymer=true


r/pythontips • • Jan 28 '19

Create GUI with Python using Tkinter | Youtube Playlist

44 Upvotes

In this series of 30 videos we learn how to create a Music Player from scratch using Python.

Youtube Playlist - https://www.youtube.com/playlist?list=PLhTjy8cBISEp6lNKUO3iwbB1DKAkRwutl


r/pythontips • • Nov 02 '22

Python3_Specific New Streamlit tutorial, 68 pages, 35 minimal app examples, focus on SQL+Streamlit

43 Upvotes

Hi, I made a new tutorial for Streamlit beginners. It’s currently 68 pages and contains 35 minimal app examples, with a large section about using basic SQL together with Streamlit to build simple full-stack CRUD apps:

https://streamlitpython.com

I hope it’s useful!


r/pythontips • • May 14 '22

Syntax What is wrong with this simple piece of code

43 Upvotes
li=[[0]*4]*4

for i in range(0,4):
    if(i==0):
        li[i][0]= 4
    
    
print(li)

Why is the output this

[[4, 0, 0, 0], [4, 0, 0, 0], [4, 0, 0, 0], [4, 0, 0, 0]]

and not

[[4, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]


r/pythontips • • Jan 27 '21

Short_Video EASIEST PYTHON PROJECT FOR BEGINNERS MAKE QR CODE IN 6 LINES OF PYTHON CODE

43 Upvotes

r/pythontips • • Jun 01 '20

Python3_Specific Created my first real program python program! A currency converter that checks the internet for live exchange rates. Any tips ?

43 Upvotes

from urllib.request import urlopen as uReq

from bs4 import BeautifulSoup as soup

playing = True

#Establishing a connection

my_url = 'https://ron.fxexchangerate.com'

uClient = uReq(my_url)

page_html = uClient.read()

uClient.close()

page_soup = soup(page_html, "html.parser")

# Grabbing the first set of ratings from the Currency Pair Side Table

container = page_soup.find('div', class_='sider')

numbers = container.findAll('span')

USD_EURalpha = numbers[1].text

GBP_USDalpha = numbers[2].text

USD_EUR = float(USD_EURalpha) # ~0.897

GBP_USD = float(GBP_USDalpha) # ~1.240

EUR_GBPalpha = numbers[7].text

EUR_GBP = float(EUR_GBPalpha) # ~0.897

#Grabbing the second set of ratings from the Main Table

container_two = page_soup.find('tbody',class_='project')

numbers_ron = container_two.text

RON_USD = float(numbers_ron[27:33]) # ~ 0.229

RON_EUR = float(numbers_ron[63:70]) # ~ 0.205

RON_GBP = float(numbers_ron[108:114]) # ~ 0.184

#Inverting the rates

EUR_USD = 1 / USD_EUR

USD_GBP = 1 / GBP_USD

USD_RON = 1 / RON_USD

EUR_RON = 1 / RON_EUR

GBP_RON = 1 / RON_GBP

GBP_EUR = 1 / EUR_GBP

#Setting the loop

def program():

while playing == True :

	first_input = input(" Welcome, please select the currency you want to convert from: \\n press 'd' for dollar  \\n press 'l' for lei  \\n press 'e' for euro  \\n press 'p' for pounds  ")

	second_input = input("Following the same patern as before, please select the currency you want to convert to:  ")

	suma = float(input("Please type the ammount in numbers  "))   

		

	def result():

		result = \[\]

		if first_input.lower()\[0\] == 'e' and second_input.lower()\[0\] == 'l':

result = float(suma) * EUR_RON

		elif first_input.lower()\[0\] == 'd' and second_input.lower()\[0\] == 'l':

result = float(suma) * USD_RON

		elif first_input.lower()\[0\] == 'l' and second_input.lower()\[0\] == 'e':

result = float(suma) * RON_EUR

		elif first_input.lower()\[0\] == 'l' and second_input.lower()\[0\] == 'd':

result = float(suma) * RON_USD

		elif first_input.lower()\[0\] == 'e' and second_input.lower()\[0\] == 'd':

result = float(suma) * EUR_USD

		elif first_input.lower()\[0\] == 'd' and second_input.lower()\[0\] == 'e':

result = float(suma) * USD_EUR

		elif first_input.lower()\[0\] == 'd' and second_input.lower()\[0\] == 'p':

result = float(suma) * USD_GBP

		elif first_input.lower()\[0\] == 'p' and second_input.lower()\[0\] == 'd':

result = float(suma) * GBP_USD

		elif first_input.lower()\[0\] == 'e' and second_input.lower()\[0\] == 'p':

result = float(suma) * EUR_GBP

		elif first_input.lower()\[0\] == 'p' and second_input.lower()\[0\] == 'e':

result = float(suma) * GBP_EUR

		elif first_input.lower()\[0\] == 'l' and second_input.lower()\[0\] == 'p':

result = float(suma) * RON_GBP

		elif first_input.lower()\[0\] == 'p' and second_input.lower()\[0\] == 'l':

result = float(suma) * GBP_RON

		else:

print ("Please choose between 'l','d','p' or 'e' ")

		print (f'result = {result}')

		

	result()

		

	continuare = input("Go again? 'y' or 'n'")

		

	if continuare.lower()\[0\] == 'n':

		playing == False

		break

	else:

		playing == True

program()


r/pythontips • • Mar 04 '20

Hello Pythonistas– we made our first interview prep video for our users and thought it would be helpful to share here, too. Hoping for some feedback from you guys. This video is on a simple LeetCode question (valid parentheses).

43 Upvotes

Here's the link: https://www.youtube.com/watch?v=-K6A2XP0rK8

If there are any specific questions you guys need help with, let us know and we'll make more videos.


r/pythontips • • Jan 06 '20

Standard_Lib Tip: str.splitlines() ignores the last line if it's empty

43 Upvotes

The str.splitlines() method is pretty neat. Up until a week ago I had a habit of always applying str.rstrip() before splitting lines. I thought I would otherwise get empty lines at the end of my data if it ended with a trailing newline. Turns out I did not need to:

>>> string = "Hello\nWorld!\n"
>>> string.splitlines()
['Hello', 'World!']

This is unlike .split("\n") that I see used fairly often:

>>> string.split("\n")
['Hello', 'World!', '']

If there is more than one empty trailing lines, only one is trimmed. Empty first lines are also kept. Finally, an empty line with spaces (& friends) is not considered empty.

>>> "Hello\n\n".splitlines()
['Hello', '']
>>> "\nHello".splitlines()
['', 'Hello']
>>> "Hello\n ".splitlines()
['Hello', ' ']

While on the topic of str.splitlines, it is also compatible with CRLF line ends which is essential if you care about Windows compatibility (among other things):

>>> "Hello\r\nWorld!".splitlines()
['Hello', 'World!']

The official documentation for str.splitlines() has a full list of the supported separators:
https://docs.python.org/3/library/stdtypes.html#str.splitlines

P.S.: I am posting a Python tip on r/pythontips… This is how it works, right? The vast majority of posts here suggest otherwise.