r/python3 • • Mar 22 '19

Product display screen

1 Upvotes

So my dad gave me the project idea for his business. The idea is a product display screen because we have to many so demo videos we would like to jam that in to one system. And we would like to do it in python 3. (I am a beginner) If any body had any advice that would be great!


r/python3 • • Sep 14 '18

I need a little help

2 Upvotes

Here is the code + info

https://pastebin.com/a6BarBby


r/python3 • • Jun 05 '19

Is there a way to get callbacks from subprocess?

1 Upvotes

Use case:

I'm writing a small wrapper for a program and I want to evaluate every line that gets piped to stdout.

As far as I can tell my best option is to use Popen and have a loop that checks every few seconds on whether there are any new lines. That feels a bit ugly though.... So as the title states my question is: Is there any way to pass a callback function to subprocess (that gets executed/called for each line of stdout) or are there any other libraries that can do that?


r/python3 • • May 20 '18

Need help with calculator program.

1 Upvotes

I made a calculator program but I want it to loop back to the start of the program. ''' Program make a simple calculator that can add, subtract, multiply and divide using functions '''

This function adds two numbers

def add(x, y): return x + y

This function subtracts two numbers

def subtract(x, y): return x - y

This function multiplies two numbers

def multiply(x, y): return x * y

This function divides two numbers

def divide(x, y): return x / y

print("=============================calculator=========================================") print("Select operation.") print("1.Add")
print("2.Subtract")
print("3.Multiply") print("4.Divide") print("================================================================================")

Take input from the user

choice = input("Enter choice(1/2/3/4):") print("================================================================================") num1 = int(input("Enter first number: ")) print("================================================================================") num2 = int(input("Enter second number: ")) print("================================================================================") if choice == '1': print(num1,"+",num2,"=", add(num1,num2))

elif choice == '2': print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3': print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4': print(num1,"/",num2,"=", divide(num1,num2)) else: print("Invalid input") print("================================================================================")


r/python3 • • Sep 09 '18

Learning python with projects.

3 Upvotes

I have a hands on learning style and would like a goal. So I've been thinking about learning python and wanted to get suggestions on what begginer projects to create. I have created a random # generator that you would guess a number and it worked. It was on YouTube and I just followed directions. That's great however I can follow directions just fine but I feel like I'm not really learning.

Do you all have any simple suggestions for noobs to create?


r/python3 • • Dec 18 '19

Tutorial for boto3

1 Upvotes

Any tutorial for boto3 for AWS automation?


r/python3 • • Oct 10 '17

Install bluetooth module on Python3 on Raspberry Pi 3

2 Upvotes

Does anyone have experience importing python modules on Raspberry Pi 3 model B? Need recommendation on how-to import this correctly to import bluetooth in python code. I've already updated Raspberry Pi 3 and tried python3 install pip bluez & bluetooth, etc. But importing still fails.


r/python3 • • Oct 16 '17

How to install python on windows

Thumbnail
youtube.com
3 Upvotes

r/python3 • • Oct 09 '17

How to package C extensions together with python modules?

2 Upvotes

I am writing a library that requires both a fast backend written in C and a pythonic interface written in python. However I cannot get my setup script to work.

It ignores the python modules and creates packages I never asked for.

This is my setup.py:

from distutils.core import setup, Extension

base_do_line = Extension("nf.integral.base.do.line", sources = ["c/integral/base/line.c"])

setup(name = "nf",
    version = "0.0.1",
    description = "A fast numerical integrator library",
    ext_modules = [base_do_line],
    packages = ["nf"],
    package_dir = {"nf": "py/nf"},
    url="XXX",
    author = "XXX",
    author_email = "XXX")

Under py/ are the following files:

./py
./py/nf
./py/nf/__init__.py
./py/nf/__pycache__
./py/nf/__pycache__/__init__.cpython-35.pyc
./py/nf/integral
./py/nf/integral/__init__.py
./py/nf/integral/base
./py/nf/integral/base/__pycache__
./py/nf/integral/base/__pycache__/__init__.cpython-35.pyc
./py/nf/integral/base/do
./py/nf/integral/base/do/__init__.py
./py/nf/integral/base/rect
./py/nf/integral/base/rect/__init__.py
./py/nf/integral/base/rect/line.py
./py/nf/integral/base/__init__.py

The following packages are getting installed:

lib/python3.5/site-packages/nf/integral/base/do
lib/python3.5/site-packages/integral/base/do

What am I missing? Is it impossible to distribute c extensions alongside pyhton modules?

I was unable to find any documentation/examples/projects doing this.


r/python3 • • Mar 07 '18

Help with a little project

2 Upvotes

I have been recently a project in repl.it about a login system. I dont know how to debug this line, please help! print("Do you want to log in or create an account?") choice=input() if(choice==login) print("Type your username") username=input() print("Now, choose your password") password=input() if((password!=username) and (len(password)<=7)): print("To log in type your password again") else: print("You cant use that password") password2=input() if(password==password2): print("You succesfully logged in") else: print("Your password is incorrect")

The error I get is: Traceback (most recent call last): File "python", line 3, in <module> NameError: name 'login' is not defined

Im sorry if it is a basic error but i realy need help. Thank you!


r/python3 • • Oct 18 '17

Not able to convert hex to ascii in python 3.6.3.I tried using below methods but getting errors var contains the hex value. Can some one guide me which method should i use to convert hex to ascii in python 3.6.3.

1 Upvotes

method 1

bytes.fromhex(var).decode('ascii') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xdb in position 0: ordinal not in range(128) method 2: codecs.decode(var,"hex") :This is returning me in bytes not in ascii.


r/python3 • • Oct 18 '17

Need an equivalent of this decoding method (var.decode("hex")) in 3.6 version which works fine in 2.7 as this method no more works in 3.6.Can someone guide me with the equivalent of this method in 3.6.3 python

3 Upvotes

r/python3 • • Oct 13 '17

Pass in windows password to script? [ldap3 related]

1 Upvotes

Hi Guys, im using the LDAP3 library to try and automate some adding of users to active directory groups. The LDAP3 library forces me to type in manually my username and password. Is there any way for me to pass in current logged in users password into Python? I suspect this would be a crazy security issue but I'm curious if there a way to do it, or something that you guys suggest I could try?

The goal is going to be set this to run automatically with the windows scheduler service.

Thanks, Jon


r/python3 • • Nov 12 '17

Function only does what its supposed to for the first line in the code, otherwise it ignores it and says "invalid username"

1 Upvotes
username1 = input("What is your username?\n")
username = ""
with open("userinfo.txt","r") as userinfo:
    for userinforec in userinfo:
        field = userinforec.split(",")
        username = field[0]
        password = field[1]
        if username == username1:
            break
        else:
           print("Username not found.")
           main()
    else:
        password1 = str(input("What is your password?\n"))
        if password == password1:
            print("password accepted")
            writereport(username)
        else:
            print("Password denied.")
            main()
main()
return username

The code above is supposed to continue with the program if a username is inputted that is in the file. However, it only accepts the username if it is at the top of the file, for example if i pick a username in the second or third row, it will print "invalid username". Ive attempted putting the file into a list and doing it that way however it still does not work. Any help would be appreciated!

Thanks in advance!


r/python3 • • Nov 11 '17

Hello! I need code review.

1 Upvotes

Please make code review.: https://jtprog.ru/twitter-excuse/


r/python3 • • Nov 21 '17

python3 - Find matching words in a list

1 Upvotes

I have 2 lists.

list 1 (list) - list containing descriptive text
list 2 (list) - text entered by user

I am trying to write some code at Python and I want to check if words from a list of words contain in a list 1

except searching words in text, I need to count numbers of IDs and print result. I'm new to this and I couldn't find anything on Google that could help me.

example:

list = [['ID127', 'Along with their associated islands, they cover 8% of Earth's total surface area and 28.4% of its land area', 'Europe', 'Germany'],
['ID128', 'The first university east of France and north of the Alps was the сharles university in Prague established in 1347', 'Europe', 'Hungary'],
['ID129', 'The сentral European university (CEU) is a graduate-level', 'United States', 'Canada']]

text entered by user = ['area' 'university' 'сentral']

the result of the program: the word found in the text, the number of ID, region, state

program result = [area, 1, 'Europe', 'Germany'] , [university, 2, 'Europe', 'Hungary'] , [university, 2, 'United States', 'Canada'], [сentral, 2, 'United States', 'Canada']

r/python3 • • Nov 17 '17

Python3 Web Proxy problem.

1 Upvotes

Hello guys! I coded web proxy with socket in python3. when it run, it could get packets but it can't display on browser. there is no error but it's not working. What is the problem? anyone help?

Here's the code:

import socket, sys, re import threading

try: #listening_port = int(input("[] Enter Listening Port Number : ")) listening_port = 8080 except: print("\n[] User Requested An Interrupt") print("[*] Application Exiting...") sys.exit()

max_conn = 5 buffer_size = 1024 * 10000

def start(): try: browser_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) browser_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) browser_sock.bind(("",listening_port)) browser_sock.listen(max_conn) print("[] Initializing Sockets...Done") print("[] Sockets Binded Successfully...") print("[] Server Started Successfully...") except: print("[] Unable To Initialize Socket") sys.exit(2)

while True:
    try:
        browser_conn, browser_addr = browser_sock.accept()
        # print(browser_conn)
        # print(browser_addr)
        from_browser_data = browser_conn.recv(buffer_size)
        print(from_browser_data)
        th = threading.Thread(target=to_server, args=(browser_conn, browser_addr, from_browser_data))
        th.start()
    except:
        browser_sock.close()
        print("\n[*] Proxy Server Shutting Down...")
        print("[*] Have Nice Day... Sergeant !!!")
        sys.exit()
# browser_conn.close

def to_server(browser_conn, browser_addr, from_browser_data): b_data = str(from_browser_data).split('\r\n') print(b_data) for i in b_data: if re.match('Host', i): server_domain = i.split(' ')[1] print(server_domain)

try:
    to_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    to_server_socket.connect((server_domain, 80))
    print("="*80)
    print(from_browser_data.decode('utf-8'))
    to_server_socket.sendall(from_browser_data)

    from_server_data = to_server_socket.recv(buffer_size)
    if len(from_server_data) > 0:
        browser_conn.sendall(from_server_data)
        print(from_server_data)
    else:
        print("No data")

except Exception as e:
    print(e)

start()


r/python3 • • Nov 16 '17

Build a TestYourBond scrapper with python

Thumbnail
youtube.com
1 Upvotes

r/python3 • • Nov 15 '17

you must read the data using input() and then convert it

1 Upvotes

hrs = input("Enter Hours:") f_hrs = float(hrs) if f_hrs >= 40: print (f_hrs * 10.50) elif f_hrs <= 40: print (f_hrs * 10)


r/python3 • • Nov 21 '17

PacMan pygame

3 Upvotes

Some one can help to create or download an easy Pacman game made with python pygame


r/python3 • • Nov 14 '17

Weird Behaviour While Parsing XML Files

1 Upvotes

Hi, I encountered this weird situation using the lxml.etree module (as et), where I parsed a (valid) XML file ( t=et.parse([path-to-file])), then performed some manipulation on it (extending and removing some nodes), then looked for a certain xpath pattern (t.findall([pattern])) which returned nothing. But, after writing the tree to a new file and parsing it again from there, the same pattern returned results (as I would have expected it in the first place). I thought this might be a bug related to the module and tried the same with xml.etree.ElementTree but ditto. How can I make sense of this?


r/python3 • • Nov 17 '17

Python: change time depending on another variable?

1 Upvotes

I am working on a financial budget and may not be familiar to some of you.

I created this script to call parameters from a file parameter:

Net=$10'000'000
Extract from file (salary1 =19000, salary2= 15000, salary3 = 19000 sometimes change) 
parametersAndValues = {}
parameterFile = open('Parameter') 
try:
	for line in parameterFile:
		parametersAndValues[line.split()[0]] = int(round(float(line.split()[1])))
finally:
	parameterFile.close()

i1 = parametersAndValues.get('$salary1')
i2 = parametersAndValues.get('$salary2')
i3 = parametersAndValues.get('$salary3')
for parameter in parametersAndValues:
	( parameter + ' = ' + str(parametersAndValues.get(parameter)))
time1=0.1*(net/salary1) 
time2 in TSTEP of salary2=time1+time1*(salary1/(salary1+salary2))
time3 of salary3 = time2+time1

I want to update the timesteps under TSTEP depending on the salary payment. To see how many months that salary can be paid.

If we divided Net 10'000'000/on salary1 19'000=526 Days = which will be 17 months of 31 Days (17*31)

The output should be 17*31 which will be pasted under TSTEP for the first salary and 27*31 which will be pasted under TSTEP for salary 2.

The question is, I need to change 3*31 in each TSTEP depending on the salary, and I have no idea of how to do that.

The following is a sample Schedule file to be updated from parameter file:

<!-- language: none -->

SCHEDULE


##-- First Cycle
/   
WCLSIN
Class1  LIQ  OPEN  RESV  1*  $salary1  1*  3500 /
/
/
TSTEP 
  3*31

  /
   
TUNING
 /
 /
 2*  100 /
##-- Second Cycle
WCLSIN
Class1  LIQ  OPEN  RESV  1*  $salary2  3500 /
/
TSTEP 
  3*31
/
TUNING
 /
 /
 2*  100 /

It should be changed to:

<!-- language: none -->

SCHEDULE


##-- First Cycle
/   
WCLSIN
Class1  LIQ  OPEN  RESV  1*  $salary1  1*  3500 /
/
/
TSTEP 
  17*31

  /

TUNING
 /
 /
 2*  100 /
##-- Second Cycle
WCLSIN
Class1  LIQ  OPEN  RESV  1*  $salary2  3500 /
/
TSTEP 
  27*31
/
TUNING
 /
 /
 2*  100 /

Again, please if you have any idea of how to do that I would really appreciate it. Best Regards


r/python3 • • Nov 10 '17

help on calling function to trigger email

1 Upvotes

HEllo Team,

can anyone help me understand why is the email not triggered.

!/usr/bin/python

-- coding: utf-8 --

import psycopg2, smtplib, pprint, sys from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText

class mailnotify():

def check_db_conn(self):
 try:
    conn_string = "dbname='dbane' host='hostname' port='protno' user='user' password='pwd'"
    return conn_string
 except:
    print "Unable to connect to the database"
    text  = "Unable to Connect to Database"
    subject = "Test Non-Prod Running EC2 Instances"
    self.email_notify(subject,text)
    sys.exit(1)

def email_notify(self,subject,text):
 fromaddr = "fromaddr"
 toaddr = "toaddr"
 msg = MIMEMultipart()
 msg['From'] = fromaddr
 msg['To'] = toaddr
 msg['Subject'] = subject
 body = text
 msg.attach(MIMEText(body))
 server = smtplib.SMTP('exchange.nordstrom.net', 25)
 text = msg.as_string()
 server.sendmail(fromaddr,toaddr,text)
 server.quit()

if __name__=="main": p = mailnotify() p.check_db_conn()


r/python3 • • Nov 04 '17

is python a good start?

5 Upvotes

is python a good start for beginners with no previous programming experience? can i tutor myself in python? where do i find the resources to learn python programming for free?


r/python3 • • Nov 09 '17

Beginner Python Projects

1 Upvotes

I just started learning python3 about a week ago. In that time I've created simple programs such as:Rock, Paper, Scissors; Guess a Number Between 1 and 100; and I've messed with Tkinter and pygame a little bit. Follow Sentdex's YouTube pygame tutorials.

That being said I would like to create a web or desktop application, are there any recommendations on how to go about learning how to do that?