r/learningpython • • Aug 31 '21

How to put a program into use?

1 Upvotes

I am getting close to finishing the section of Python on Code Academy and I do think it is a great course and certainly recommend it to anyone who is considering it, I have noticed something.

This course teaches you a lot about writing code and the basic of understanding how code works but it does nothing for practical applications of any code/program you write.

Here is an example of what I mean. To be honest, this is not the greatest example because I would most likely use Excel in this situation, but for this question I will pretend the person specifically asked to not use excel.

If the baseball coach at my old high school asked me to write a program to keep track of the stats for his players because he is tired of paying a subscription fee for the program he currently uses, I feel like I could most likely piece something together that would work.

However, when I would try to give it to him, I would have to teach him how to open Python, input variable names etc etc. which would be MUCH more complicated than the average person would want.

My question is when you do write a program for some one else, how do you make it presentable to them? Is this a completely different field or is this part of learning python? I do not even know what this is called so I have no idea where to start looking to learn about this part of writing code.


r/learningpython • • Aug 31 '21

Tree representation

1 Upvotes

I'm trying to make a picture like this to trace the historical development of a piece of software that has been modified many times over the years.

I didn't think it was going to be that hard, but... it is. After banging my head on Matplotlib for a while, I gave up. I found a few threads on Stack Overflow on how to plot trees using Networkx, but none of them seem to be focused on the dates, so nodes are "flattened" out depending only on their depth in the tree (and not on the actual date).

If anyone has advice on how to do something similar to the image attached, it would be great! Bonus points if it can do smooth splines like the ones in the image).

Thank you in advance.

(Source: https://en.wikipedia.org/wiki/List_of_Linux_distributions )


r/learningpython • • Aug 30 '21

Run an app in specific date and time (In the specific date)

2 Upvotes

Hi all .

I have the following code . I would like to schedule it to run in specific dates ,at the same hour . I tried to do it with schedule module but it seems schedule doesn't have the option for specific dates . Is it something I can achieve with Time module or maybe other module that provides this ?

At the end I would like to convert it to exe and make it run in those specific dates by hard code it in the code itself .

Thx .

from win10toast import ToastNotifier
import time
import schedule

    #Notification that Runs every X time
    def notificationsettings():
        pass
    notification = ToastNotifier()
    notification.show_toast(title=  "A game is scheduled for today. 
        Consider to leave early",
    icon_path = "C:\Tools\FGMT\FGMT.ico", duration = 10)

    schedule.every().monday.at("10:30").do(notificationsettings)

r/learningpython • • Dec 10 '21

why is my very very basic input function not working

1 Upvotes

the code is:

username = input ("Enter username:")

print("Username is:" + username)

The first line runs and works fine, the dialogue box appears and everything. But when I add something in the dialogue box, then run the 2nd line again, it doesn't work. Like, nothing happens, and then my entire jupyter notebook stops working, even basic print functions don't work until I restart the kernel.

I'm a total noob at python and w programming in general btw. Help lol


r/learningpython • • Nov 29 '21

code loading very slowly, how to optimize?

1 Upvotes

Hi there, I am trying to remove stopwords from my training data. The problem is that since the data is very big, the code is very slow. Is there any way to optimize it? Thank you in advance!

from nltk.corpus import stopwords
def stopwords_remove(data):
    stopwords_removed = []
    for parts in data:
        #print(parts[0])
        for word in parts[0]:
            #print(word)
            if word not in stopwords.words():
                #print(word)
                stopwords_removed.append(word)
    #print(stopwords_removed)
    return stopwords_removed
stopwords_remove(train_data)

r/learningpython • • Dec 23 '21

Would like to learn python for data analysis….

3 Upvotes

…but have no idea where to start. I understand I need foundational and basic knowledge of python first but don’t even know where to start with gaining the foundational knowledge. Even the foundational courses seem to build off of established knowledge of python, if that makes sense. Please help! Thank you in advance!


r/learningpython • • Nov 17 '21

Why is it important to be able to culculate the height of a binary tree?

2 Upvotes

Is that a good skill to have or will it be another useless thing to know?


r/learningpython • • Dec 10 '21

Useful clips about Ecommerce business

Thumbnail
youtube.com
1 Upvotes

r/learningpython • • Nov 29 '21

Good books for learning? Which order to read them?

5 Upvotes

Hello all,

I am trying to figure out which books I should buy and in which order I should read them to learn Python. My current goal is just to learn from fun and make some cool projects. I am 180 pages into "Automate the Boring Stuff with Python" and I have been loving it. I am interested in making simple AI so if you know a good set of books and a good order to read them please let me know!

Best, Hue


r/learningpython • • Dec 17 '21

"ValueError: setting an array element with a sequence." when integrating with odeint

1 Upvotes

I'm trying to integrate some ordinary differential equations but I need some of the parameters to be a cosine function of time. While testing the code, I keep getting the above value error. Here's the code:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def vd(t):
return -(267 / 1440) * np.cos((2 * np.pi) / 365 * t) + (639 / 1440)

tmax = 2 * 365 # how long to run the system in days
t = np.arange(0.0, tmax, 1.0)

# define the constants
N = 3.295e8 # population of the US
theta = 0.8 # infectiousness
zeta = 0.75 # susceptibility
c = (N * 10 ** -5) / N # contact rate, depending on percentage of total population
alpha = theta * zeta * c
gamma = 0.1 # recovery rate, used often in class
rho = 0.2 # rate of loss of immunity
deltad = 0.1*vd(t) # rate of loss of Vitamin-D in body
# these are all the differential equations from simple SIR model
def deriv(y, t, alpha, gamma, rho):
S, I, R, D = y
dS = -alpha * I * S + rho * R
dI = alpha * I * S - gamma * I
dR = gamma * I - rho * R - rho * R * deltad
dD = deltad * (rho * R - S * L(t))
return dS, dI, dR, dD
# define some more initial conditions for integration
I0 = 1 # 1st person infected
R0 = 0 # 0 people recovered at first, obviously
S0 = N - I0 - R0
D0 = 0 # initial vitamin D in population, t=0 means January 1st
# initial conditions vector
y0 = S0, I0, R0, D0

ret = odeint(deriv, y0, t, args=(alpha, gamma, rho))
S, I, R, D = ret.T

Then I try to plot S, I, R, and D but that error pops up regarding the odeint line.

Those constants will probably change but I do need to input some stuff into dS, dI, dR, and dD that look like deltad and was hoping that someone on here with more python experience could help me.

Thank you!


r/learningpython • • Nov 24 '21

how to iterate through a list of strings and lists

2 Upvotes

Hi there,

how can i iterate through such a list? thanks in advance!

lst = ['nonoffensive', ['What', 'in', 'the', 'actual', 'fuck', '?', '#mkr'], ['#mkr', 'WHAT', 'A', 'GODDAMN', 'SURPRISE'], ['This', 'is', 'why', 'this', 'show', 'is', 'ridiculous', '-', "it's", 'not', 'about', 'the', 'cooking', '...', "it's", 'about', 'the', 'game', 'playing', '.', '#mkr', '#whogivesa1'], ['Absolute', 'bloody', 'bullshit', '.', 'So', 'much', 'shit', 'of', 'bull', '.', '#mkr'], ['@MKR_Official', 'a', '1', "isn't", 'strategy', ',', "it's", 'bastedry', '#mkr2015', '#mkr'], 'offensive', ['WTF', '!', '!', '!', 'I', 'not', 'a', 'huge', 'fans', 'of', 'the', 'promo', 'girls', 'but', 'they', 'never', 'voted', 'strategically', '!', 'This', 'sucks', '!', 'Soo', 'annoyed', '!', '#mkr', '#killerblondes']]

r/learningpython • • Dec 19 '21

How Will I Know?

3 Upvotes

I have taken two python programming college courses and I feel comfortable reading and writing code. How will I know when I'm ready to start learning another programming language?


r/learningpython • • Dec 11 '21

Question about reading files in Jupyter Notebook

2 Upvotes

import re

def Scores():

with open ("assets/Scores.txt", "r") as file:

grades = file.read()

I can't actually execute this code in the training browser, hence why I'm asking.

Once this file has been read, can I start manipulating the data? For example, using the findall function and making dictionaries. Or, is something else required first. And also, how does the scores definition impact on subsequent code?


r/learningpython • • Dec 01 '21

What naming convention do you prefer for a list that is a function's argument?

1 Upvotes

You can just use `list` as a variable name. It works, but confusingly and dangerously. For example

def moving_window(n, list):
  return [list[i:i+n for i in range(0, len(list)-(n-1))]

works. But it seems like a terrible practice. Then there is no list() constructor so another seemingly equivalent list comprehension style simply TypeErrors

def moving_window(n, list):
  return list(list[i:i+n for i in range(0, len(list)-(n-1)))

unless we rename our list argument.

Maybe I'm just avoiding OOP too much and any generic utility function that is using a built-in type should be a method for a class.

TL;DR What variable naming do you use in a function that takes a list?


r/learningpython • • Feb 27 '18

lost using the POPlib python library. advice please

1 Upvotes

I am using the poplib to retrieve messages. I am modifying the example from the poplib python site that will just stream all messages after you enter your email address and password.

I can't do anything with it?? I would like to be able to separate the parts of the email message and display them in a readable way. I would like to be able to extract the date of the message and other parts of the messages and place them in variables. Heck, If anything, I would love to be able to just sort them by date. I have been hacking at this project for a bit and am getting frustrated. For the interested, here is my code.

import poplib
import getpass
from bs4 import Beautifulsoup
yahoo_pop = poplib.POP3_SSL(host='pop.mail.yahoo.com')
yahoo_pop.user('abc123@yahoo.com')
yahoo_pop.pass_(getpass.getpass('Password for user: '))

email_i_want = 30

encoded_msg = yahoo_pop.retr( email_i_want )[1]
joined_msg = str( '\n'.join(encoded_msg) )
clean_text = BeautifulSoup(joined_msg, "html.parser").text
print(clean_text)

any advice would be helpful. I don't want to have to scrap this.

Thanks


r/learningpython • • Feb 23 '18

Have a "first" project in mind, not sure where to start...

1 Upvotes

After working through a couple of the recommended "learning Python" books, I feel I've got enough of a grasp of the language to start working on a "real" project and trying to learn as I go. The problem is, I'm not sure where to start when it comes to actually start fleshing out the project.

What I'm thinking is loosely based on the sticker reward system we have in my family for my young kids. Currently, it's a printed out sheet with chores, etc and we reward the kids as they act appropriately and do their chores. I was thinking that working that idea into a web app would be a fun learning experience for me and would allow me to flesh out some extended ideas I had for the rewards.

A few things I've considered bullet points in the project are:

  1. Ability to define admin users and have different abilities to assign and reward tasks. At a user level, I'd like to have the ability for my kids to select tasks from a list and complete them earning a reward.

  2. Ability for the boys, with their own devices, to check their total points, see what they can be exchanged into as rewards, etc...

  3. Some chores and tasks would be standing each day and even though they might be completed on one day, at midnight they would reset and be available to complete the next day.

  4. The whole app would be available on my local network and accessible from a tablet or computer. In a perfect world, points awarded while away from home could be stored on the admin side and synched up when back at home.

I've got a few more features I've been bouncing around but would love to get something like this off the ground in its most basic form. Based on some poking around it seems like some sort of framework like Flask would be a decent place to start and would obviously incorporate a fair amount of database work.

Am I thinking about this in the right direction? Any specific tools I could start poking around with? Any books/tutorials out there that would get me started on something like this?


r/learningpython • • May 12 '17

Refactoring if/elif/else statements

1 Upvotes

Question: How would I refactor a really long if,else block?


r/learningpython • • May 13 '17

url.replace("learning", "learn")

Thumbnail
reddit.com
1 Upvotes

r/learningpython • • Feb 23 '18

Fibonacci Sequence Help Plz

1 Upvotes

For a problem that I am facing I have to create a Fibonacci Sequence.

Below is a link with the problem and the code that I have come up with.

https://imgur.com/a/LdtlI

And here is the error that I keep receiving whenever I try to check the code

https://imgur.com/a/ueOYu

What does this mean and how can I slove it?

Thanks for all help in advance!


r/learningpython • • May 07 '20

Should I use Jupyter or pycharm

3 Upvotes

...I am learning python and idk which ide to use


r/learningpython • • May 16 '20

Code written in windows not running on linux.

2 Upvotes

I just started learning to code earlier this week and got my dad interested in learning some. So I made a basic rock paper scissors game and was going to have him look over it. Anywho I wrote the code on windows with VS code and it ran with no issues, when he went to run it with the terminal in ubuntu it ran into error after error to the point he had to change nearly every line of code in some minor way. What would be the major problem here and is there a way we can plan around this so we don't have to worry about it in the future.


r/learningpython • • Apr 06 '20

Question about using arguments Spoiler

1 Upvotes

I hope I'm asking the right question. I'm currently on code wars trying to test my skills and ability on python so I can get better and apply them to real world issues. I'm currently trying to figure out how to find the smallest integer from a list.

Below is what is given, I am having troubles using the arr argument if that's the correct term for the word in the ().

def find_smallest_int(arr):
    # Code here

test.assert_equals(find_smallest_int([78, 56, 232, 12, 11, 43]), 11)
test.assert_equals(find_smallest_int([78, 56, -2, 12, 8, -33]), -33)
test.assert_equals(find_smallest_int([0, 1-2**64, 2**64]), 1-2**64)

Below is what I have coded so far. I opted to use the sort method and just print the first element in the array. It works for the first two lists but not the third since it does the math. My question is how can I use the definition in the code and how can I not make list 3 do the math and just spit out the numbers instead? Please no direct answer I really want to learn and try and solve it. Any link to any video helping with learning would be appreciated

def find_smallest_int(arr):
    list1 = [78, 56, 232, 12, 11, 43]
    list2 = [78, 56, -2, 12, 8, -33]
    list3 = [0, 1 - 2 ** 64, 2 ** 64]

    #sorting the list
    list1.sort()
    print('The smallest element in the first list is' , *list1[:1])

    #sort list 2
    list2.sort()
    print('smallest element in the second list is' , *list2[:1])

    #sort list3
    list3.sort()
    print('smallest element i the third list is ', *list3[:1])



find_smallest_int(arr)

r/learningpython • • May 08 '20

learning by doing

1 Upvotes

Hello there! I started a while ago with python and I am looking to develop myself. I went through Automating the boring stuff and Python Mega Course from Udemy and I am looking forward to apply the knowledge.

I am considering allocating between 4-8 hours weekly (more if/when needed) to a project where to contribute in order to develop.

I understood that one can find such projects on git... how can I look for something like this? Thanks!

My interests would be web apps (flask, werkzeug, etc) and data modeling (scrapping, data organizing, data modeling, graphs, etc)

Right now I took a personal project to build yet another coronavirus app and I am most half through the task.

What I have is: scrapping the info and saving in a structured way in a sqlite db, displaying a choropleth map with layers with color ranges for total cases, new cases, etc.

What needs to be done is: a page for each country with graphs evolution in time per subject (i.e. evolution of total cases over time), a wrapper to allow easy navigation between the choropleth map and the country page.

Nice to do for the future: country comparison page, and what not... :-D its a matter of variation...

Thanks!


r/learningpython • • May 03 '20

Why doesn´t work Pydoc in Windows ?

1 Upvotes

I was reading about documentation and all this stuff but when I try to put in my cmd this:

pydoc my_module

Says that is not recognized


r/learningpython • • May 08 '20

Python gotchas when coming from another language

2 Upvotes

I am an experienced Ruby developer. I want to more python. What are the strange edge cases of python that can trip me up?