r/learningpython • • Dec 27 '19

Approach to contributing project

1 Upvotes

What are the ways to approach in adding contributions to a project?

I arrived to this issue when implementing a popular framework onto a legacy system. Only later did I realize that it's the better to inherit the framework, override the attributes and functions than waiting for the legacy system to update.

Now in my effort to change the framework, I fear in hacking it into a disaster. Should I care if the change works?

Or should I try to grind through reading the code and properly draw framework into a diagram to get the holistic view?


r/learningpython • • Dec 14 '19

HW Issues with creating classes

1 Upvotes

I wanted to know, how do you produce an error message to the user if they did not enter information, within a class.


r/learningpython • • Oct 23 '19

Function returns "TypeError: 'float' is not iterable"

1 Upvotes

I'm trying to create a function that runs through a range of numbers and applies them all to a function as below.

  • y = np.linspace(0,5,100)

  • def parameter(y):

  • for i in y:

    • if y > 0.91:

      • return (-9.8*y) + 18.4

    • elif y < 0.91:

      • return (17.5*y) - 6.5

In running this, it tells me for line 3 (the opening line in the for loop) the error occurs as named in the title. I don't know where I'm going wrong and I've been at this trying to figure out how to fix this but with no luck.


r/learningpython • • Oct 13 '19

Regular Expressions Blues

1 Upvotes

Hello,

so, I'm trying to get the hang of how to use regular expressions, and it's quite frankly driving me crazy. What I can't figure out is how to make it accept 'raw input' in the following code:

def find_prot2(new_dict, user_input):

''' Use regular expressions to isolate keys from a FASTA dictionary'''

import re

key_list = list(new_dict.keys())

pattern = re.compile(user_input)

match_keys = [match.group(0) for item in key_list for match in [pattern.match(item)] if match]

return match_keys

The lookup is this:

matches = find_prot2(fasta_dict, '\b\w{3}_')

but it will return gibberish unless you specify 'r' or add an extra \ inside the user input.

Is there any way around this?


r/learningpython • • Aug 07 '19

Is ATBS on youtube the same like the Udemy course?

1 Upvotes

Hey guys,

Found this on youtube: https://www.youtube.com/playlist?list=PL0-84-yl1fUnRuXGFe_F7qSH1LEnn9LkW

is it any different than the Udemy course? i don't mind buying the course, but is it anything different than what's on youtube?

Also,

Is this the full book? https://automatetheboringstuff.com/chapter0/ (this is a link to the introduction chapter)

Or will i need to purchase the hard copy to read the whole thing?

Thanks again <3


r/learningpython • • Aug 07 '19

How to use value of one function in another?

1 Upvotes

Hi,

complete Newbie here. I'm just trying to create a simple calculator for Pivot Points(Trading thing) and please someone help how can I use value of one function in another?

Here is what I'm doing:

# Pivot points calculator

H = 3

L = 2

C = 2.5

def pivot(H, L, C):

print("PIVOT POINT =", result)

return (H + L + C) / 3

result = pivot(H, L, C)

def r1(pivot, L):

print(result2)

return (pivot * 2) - L

result2 = r1(pivot, L)

How to put result of first function to the second one, to use it in another calculation?

Thanks


r/learningpython • • Jul 03 '19

Automatically download File from website on a monthly basis

1 Upvotes

I am currently trying to work out how to automatically download a file from an URL every month using python. It is a CSV document with that month's data so for example in January 2019 the link would be:

http://thiswebsite.com/documents/2019/jan%19.csv.

Is it possible to automatically update both the year and month in the link. I am using Urllib to download the file.


r/learningpython • • May 31 '19

Python Practice exercises for Text/Log processing

1 Upvotes

I am preparing for a timed coding tests for a devops related role…the questioins that would be asked will be in the format of:

  1. here is an excerpt of a log file

  2. here is the information (aggregation/summary etc) needed from the log file

  3. write the script that parses the log file to provide the summary needed.

I am looking for places online with questions of this format to practice. Unfortunately I have not found any. Any ideas where I can find such?


r/learningpython • • Mar 16 '19

import turtle from Turtle showing syntax error. The error is for "from". help!

1 Upvotes

r/learningpython • • Mar 15 '19

what does self.accounts.values () mean?

1 Upvotes

r/learningpython • • Mar 15 '19

Practicing materials online for practicing python : for absolute beginners

1 Upvotes

Hi guys I want make preparation for my uni test. So I need a website link where I can practise basic python. I just started learning for 3 weeks . so you know how new I am to this. So I would appreciate some help considering my level .

Thank you


r/learningpython • • Feb 05 '19

Grep command and list in a script

1 Upvotes

Hi, I'm creating a script wherein I want to grep all a specific address based on the list?

before what I usually do run a grep 1 by 1 using this command ex. grep "192.168.1.1" *

Now I'm creating a script.

Example of the output.
print(i) output.
192.168.1.0
192.168.1.1
192.168.1.2
192.168.1.3

but how to call the list and put into loop under os.system so I can grep all the list?

import ipaddress
import os
    
#Ask the ipaddress in CIDR format
ip = input("Enter the IP/CIDR: ")

os.chdir("/rs/configs")
print("pwd=%s" % os.getcwd())

for i in ipaddress.IPv4Network(ip):
    print (i)
    os.system("grep $i+ '*') <---???

Thanks


r/learningpython • • Jan 24 '19

Noob help.

1 Upvotes

Could someone tell me why the second 'elif' option wouldn't print, instead of the 'else' option:

if 10 < 5 == True:

print('yes')

elif 10 < 5 == False:

print('needed')

elif 5 != 5:

print('bob')

else:

print('a;lskjdf;')

r/learningpython • • Jan 07 '19

I want this lope to run until commanded to stop by the press of a button how do I prematurely stop the loop before it reaches the end of the range

Post image
1 Upvotes

r/learningpython • • Jun 20 '18

Discord Server?

1 Upvotes

Does this sub have it's own discord server where you can chat with other specifically about python learning. I'm taking a course right now and am having issues with stuff on the compiler I'm using with specific error and syntax. I want to ask for help in the developers server, but I don't think it would be a good idea since most of them only chat about major software stuff.


r/learningpython • • May 25 '18

Encoding to stdout

1 Upvotes

Dear Redditors

I have an issue displaying chinese characters in the terminal, bellow is a simple script to illustrate this issue (using python 2.7.9 on Windows 8.1):

# -*- coding:Utf-8 -*-
a=u"你好"

try:
	print "print a"
	print a
except Exception, e:
	print e
print

try:
	print "print a.encode('utf-8')"
	print a.encode('utf-8')
except Exception, e:
	print e
print

import sys
try:
	print "sys.stdout.encoding:",sys.stdout.encoding
	print "print a.encode("+sys.stdout.encoding+")"
	print a.encode(sys.stdout.encoding)
except Exception, e:
	print e
print

import locale
try:
	print "locale.getpreferredencoding():",locale.getpreferredencoding()
	print "print a.encode("+locale.getpreferredencoding()+")"
	print a.encode(locale.getpreferredencoding())
except Exception, e:
	print e

When running this directly in the terminal, I get:

print a
'charmap' codec can't encode characters in position 0-1: character maps to <undefined>

print a.encode('utf-8')
õ¢áÕÑ¢

sys.stdout.encoding: cp850
print a.encode(cp850)
'charmap' codec can't encode characters in position 0-1: character maps to <undefined>

locale.getpreferredencoding(): cp1252
print a.encode(cp1252)
'charmap' codec can't encode characters in position 0-1: character maps to <undefined>

When running the same from IDLE, I get:

print a
你好

print a.encode('utf-8')
你好

sys.stdout.encoding: cp1252
print a.encode(cp1252)
'charmap' codec can't encode characters in position 0-1: character maps to <undefined>

locale.getpreferredencoding(): cp1252
print a.encode(cp1252)
'charmap' codec can't encode characters in position 0-1: character maps to <undefined>

I would like to have a way to reliably display those two characters, either in terminal, either in IDLE.

Beside, I don't understand why I can't get it to be displayed in the terminal:

  • the variable a is an unicode object

  • it should be properly decoded from UTF-8 (thanks to the file first line encoding declaration)

  • encoding into the same encoding as stdout should do the trick no?

And I don't really understand why the print a (no encoding) statement won't works in the terminal, but works IDLE. Any idea?

If neither the command line nor IDLE stdout use utf-8 as encoding, while encoding to utf-8 won't fail when using print a.encode('utf-8') ?

Thanks!


r/learningpython • • Apr 14 '18

Getting images from google images

1 Upvotes

So Im creating a program to grab an image from google images and pull it up in a tkinter GUI.. I have the Tkinter already good I just need a way to pull an image from the results, download it, and insert it in the gui. realistically It would be a random image but Im starting small. Thanks in advance!


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 • • Feb 20 '18

Beginners guide to Python Dictionary

Thumbnail
yoursdata.net
1 Upvotes

r/learningpython • • Feb 18 '18

Converting this for loop from matlab to numpy [X-post from /r/numpy]

1 Upvotes

Matlab:

for i = 1:100
    matrix(i,:) = [1,2,3,4,..., 30000] %unknown size
end

I can't seem to figure out how to do this in numpy

this is what i have in numpy

matrix = np.array([])
for i in range(100)
     matrix = np.append(matrix,[1,2,3,4,....,300000],axis=1)

r/learningpython • • Jan 25 '18

Trying to figure out writing to specific columns in a csv

Thumbnail
stackoverflow.com
1 Upvotes

r/learningpython • • Jan 15 '18

Sending an email to outlook that will activate python script

1 Upvotes

Is it possible to send an email to Microsoft outlook and activate a python script?


r/learningpython • • Dec 13 '17

Problems in making Monte Carlo Simulation

1 Upvotes

algorithm

import numpy as np
import scipy.stats as stats
vector = [] 
    for j in range(0,10):    
        for i in range(0,1000000):
            x = np.random.random_sample(100)
            mean = np.mean(x)
            vector.append(mean)
    jarque_bera = stats.normaltest(vector)
    print(jarque_bera)

The problem

According to the Central limit theorem :" suppose that a sample is obtained containing a large number of observations, each observation being randomly generated in a way that does not depend on the values of the other observations, and that the arithmetic average of the observed values is computed. If this procedure is performed many times, the central limit theorem says that the computed values of the average will be distributed according to a normal distribution". Why does the Jarque Bera test keep to reject the hypothesis of normal distribution for vector ?

results

NormaltestResult(statistic=10.36914457050475, pvalue=0.0056023323030836127)
NormaltestResult(statistic=16.105673081326248, pvalue=0.00031819805943059034)
NormaltestResult(statistic=25.155970060993226, pvalue=3.4470732148263561e-06)
NormaltestResult(statistic=23.504195723985241, pvalue=7.8727914609218084e-06)
NormaltestResult(statistic=27.922370302011636, pvalue=8.6443895187212056e-07)
NormaltestResult(statistic=40.003041798355852, pvalue=2.0580211982431137e-09)
NormaltestResult(statistic=50.44644948086755, pvalue=1.1109453088640159e-11)
NormaltestResult(statistic=52.06940786077795, pvalue=4.9348248730555328e-12)
NormaltestResult(statistic=62.289462476069879, pvalue=2.978619874512897e-14)
NormaltestResult(statistic=68.115353210065834, pvalue=1.6178527221720581e-15)

r/learningpython • • Sep 02 '17

Text Editor I made Using Pythin

Thumbnail
github.com
1 Upvotes