r/pythonhelp • • Sep 17 '22

Active screen recording.

2 Upvotes

Hello! I am trying to get a script that will actively view a changing screen while searching for certain colors or textures. I am very open to doing my own research but thought to come here for ideas first. Ultimately what I'd like Is a script that locates the "texture" some time multiples will be on screen, brings the mouse over it and interacts with a key press. Any suggestions?


r/pythonhelp • • Aug 21 '22

re.findall( regex ) find every parentheses with remix, mix or edit inside

2 Upvotes
re.findall( r"\(.*?\) title )

this prints every parentheses, so far so good.

re.findall( r"\(.*?remix.*?\) title )
( bla bla ) ( bla bla remix )

this matches matches multiple parentheses

re.findall( r"\(.*?(remix|mix|edit).*?\) title )

only prints the word remix, mix or edit but not the rest of inside.


r/pythonhelp • • Aug 16 '22

problem with Fibonacci sequence stuck on zeros??

2 Upvotes

def series(n):
  n1 = 0
  n2 = 1
  count = 0
if n <= 0:
print("enter a posotive integer")
if n >= 0:
while count <= n:
print(n1)
      nth=n1+n2
      n2 = n1
      nth = n2
      count+=1
series(5)


r/pythonhelp • • Jul 24 '22

Save GMAIL Attachments (images) on the Linux Server

2 Upvotes

Hello,

i want to receive Emails (GMAIL) on my Server.

The Mails have Image-Attachments in it. The Attachments should be saved in my folder /var/www/mail/.

Now the clue:

I send image to the following email account using the gmail filter:

[email protected]

[email protected]

[email protected]

(its always the same account [email protected] but its "filtered" with the +food +flowers2 etc.)

The Script should save the files then in filtered-folders:

/var/www/mail/user1/image1.jpg

/var/www/mail/flowers2/image1.jpg

/var/www/mail/food/image1.jpg


r/pythonhelp • • Jul 20 '22

HOMEWORK Just starting out in python, having trouble with for loop

2 Upvotes

Trying to keep the highest value from a final result of inputs. The value does not change and just states that the highest value so far is the current result even if it is lower. My code looks like this:

     largest = None
     if largest is None or finalAvg > largest:
                largest = final Available
     print("Highest value so far is:",largest)

As this is new to me, I am sure I made a simple error but I can't seem to figure it out.


r/pythonhelp • • Jul 14 '22

Databases and Tables

2 Upvotes

Hi all, I am a newbie Python user, and I'm dumb as hell. I can't figure out how to figure out the assignment, which I will post here:

  1. Read in Student_Grade_Prediction2.csv as Students_df and create a database called Students.
    Remember that you also need to create a cursor to execute the commands below.

  2. Select all the students who scored less than or equal to 12 on the first exam (G1) ordered in
    descending order by the first exam scores.

As you can see, I am supposed to read in a csv file, create a database, and then a table with a cursor? I don't know really, this is where I get lost. Here is my code:

import sqlite3

con = sqlite3.connect('Students_df')

cursor = conn.cursor()

import pandas as pd

Students = pd.read_csv(

'Student_Grade_Prediction2.csv')

Students.to_sql("Student_records", con, if_exists = "replace")

cursor.execute("CREATE TABLE IF NOT EXISTS students (ID INT PRIMARY KEY, school TEXT, sex TEXT, age INT, address TEXT, famsize TEXT, Pstatus TEXT, Medu INT, Fedu INT, Mjob TEXT, Fjob TEXT, reason TEXT, guardian TEXT, traveltime INT, studytime INT, failures INT, schoolsup TEXT, famsup TEXT, paid TEXT, activities TEXT, nursery TEXT, higher TEXT, internet TEXT, romantic TEXT, famrel INT, freetime INT, goout INT, Dalc INT, Walc INT, health INT, absences INT, G1 INT, G2 INT, G3 INT;))"

I'm getting an "unexpected EOF while parsing" error

Sorry if this is against rules, I just really need help. Thanks in advance


r/pythonhelp • • Jul 13 '22

why sometimes my code doesnt work?

2 Upvotes

sport_list = ["weight","bike","soccer ball"]

food_list = ["coffee","pasta","tofu"]

import random

while len(sport_list) != 0 or len(food_list) != 0:

lists_list = [sport_list,food_list]

randomed_list = random.choice(lists_list)

if len(randomed_list) == 0:

if lists_list[0] == randomed_list:

randomed_list = lists_list[1]

else:

randomed_list = 0

randomed_product = random.choice(randomed_list)

print(randomed_product)

randomed_list.remove(randomed_product)

it says: Traceback (most recent call last):

File "C:\Users\ohadb\PycharmProjects\pythonProject3\main.py", line 16, in <module>

randomed_product = random.choice(randomed_list)

File "C:\Users\ohadb\AppData\Local\Programs\Python\Python310\lib\random.py", line 378, in choice

return seq[self._randbelow(len(seq))]

TypeError: object of type 'int' has no len()


r/pythonhelp • • Jun 30 '22

Getting TypeError: 'str' object is not callable when calling run on Context object from contextvars.copy_context()

2 Upvotes

I'm new to using contextvars, and I'm having trouble using the copy_context() function to get the current context. When I call run on the object returned from copy_context() I get TypeError: 'str' object is not callable.

I can reproduce the issue with just a couple of lines of code. Here is the entire file I'm running:

import contextvars
currentContextObject = contextvars.copy_context()
currentContextObject.run("echo test")

Running with Python 3.7.6 from the anaconda prompt, here is the output I get:

Traceback (most recent call last):
  File "contextvar_test.py", line 4, in <module>
    currentContextObject.run("echo test")
TypeError: 'str' object is not callable

What I'm doing matches the example syntax I've seen for the copy_context() function, so I'm not sure what's going wrong.


r/pythonhelp • • Jun 24 '22

HOMEWORK how do I print both a variable as well as text in the same line

2 Upvotes

basically what the title says,

I thought this might work but I cant get it to work

print("Dat is dan:" + echteOppervlakeInSquareFoot + " m2")


r/pythonhelp • • Jun 01 '22

Using a dictionary to specify which parameter to be sent to a function

2 Upvotes

I have a function which has three arguments that do different things but take the same input. They change the way that the parameter is dealt with.

Easy way of explaining is a function like this

def Func(arg1=None, arg2=None, arg3=None):
    chosen = [arg for arg in [arg1, arg2, arg3] if arg is not None]
    print(chosen)

It's a *VERY* simplified version of what the function does but that's not what is important (I think)

What I'm trying to do is, in a class, have an attribute that specifies which argument to be given the input.

class Class:
    def __init__(self, whichArg="arg1"):
        self.whichArg = whichArg

Then, later on in the class, when the function is called, only pass that specific argument.

I know that it's possible to do this using an if statement, but I'm really into branchless programming and efficiency so I was wondering if there was a way I could use a dictionary to specify it.

For example:

arguments = {"arg1": arg1,
             "arg2": arg2,
             "arg3": arg3
             }

Hopefully that makes sense?


r/pythonhelp • • May 26 '22

Replace text in a file

2 Upvotes

Homework assignment. I have to open a file from a user input as read only. Close the file. Replace the text from the other user inputs. Open the file to write. Close it again. Then open and print.

file = input('Enter file name:')
old_word = input('Enter a string to be replaced: ')
new_word = input('Enter a string to be added: ')

with open(file, 'r') as infile:
    file = infile.read()
    
infile.close()

with open(file, 'w') as infile:
    file = infile.write()

file = file.replace(old_word, new_word)

I keep getting an "OSError: [Errno 22]" when it tries to open 'file' again. Any help would be appreciated.


r/pythonhelp • • May 17 '22

Pull data from another table if contains ...

2 Upvotes

Hello - I have 2 csv files each containing a data . I would like python to read in the files, then if any value from file 1 is found in file2, it will add that value to file2 in a new column. When completed, it will save new file file3 as csv.

file1

NAME
word1
word2
word3
word4
word5
word6

file2

SNNAME
1083word1 and other text
1099word6 with more text
1146text with word2
1171more with word2
1329word4
1446word5 blah blah
1662here is word3
1777word3 again

file3

SNNAMEFOUND
1083word1 and other textword1
1099word6 with more textword6
1146text with word2word2
1171more with word2word2
1329word4word4
1446word5 blah blahword5
1662here is word3word3
1777word3 againword3

r/pythonhelp • • May 09 '22

How is "B, C, D" printed?

2 Upvotes

class B(Exception):

____pass

class C(B):

____pass

class D(C):

____pass

for cls in [B, C, D]:

____try:

________raise cls()

____except D: print("D")

____except C: print("C")

____except B: print("B")

The underscores are spaces.


r/pythonhelp • • Apr 30 '22

PYTHON PROJECT: py_match

2 Upvotes

Hello, I was having trouble with my python project for school and I was wondering if someone can help me do it please. I can send the file for the requirements and everything.


r/pythonhelp • • Apr 29 '22

SOLVED Is there a way to read an LED using a Pi and Breadboard

2 Upvotes

I know you can CONTROL the LED but is there a way to take a read of the LED instead?


r/pythonhelp • • Apr 27 '22

Python code beginner

2 Upvotes

i have a code im working on and I need help if anyone can help please,

where im defining a function:

def function(sentence, stop_words):

in which i am trying to remove all the words in the string stop_words that are present in the sentence.

I am writing this for output:

simple_sentence = stop_word_removal("This is some sentence and I know it is a long one", "and is I") print(simple_sentence)

And I need this for output:

This some sentence know it a long one


r/pythonhelp • • Apr 24 '22

So I'm making an analytical solution on python for the journey of a bouncing ball. I cannot get the code to plot the journey properly and also I get this issue " next(b, None) TypeError: 'float' object is not iterable". guidance would be appreciated!

2 Upvotes

r/pythonhelp • • Apr 19 '22

Python package problems

2 Upvotes

I guys, i try to run some script from github on my PC on w11 ( i know linux is better) and i think i do the right installation with the right packages but i still have an error to built 'setup.py' if you have any idea it will be greatfull.

here is a copy of the error : Can not execute 'setup.py' since setuptools is not available in the built environnement.

I try pip install -U setuptools , and pip install openupgradelib but the same error apears. Thanks for the help

version : Python 3.10.4


r/pythonhelp • • Apr 19 '22

PyQt5 taking text from a QLineEdit and transfering that text into a Table

2 Upvotes

Hi, so what I'm trying to do is have the user input something into a text box on a stackedWidget then when the 'save' button is pressed, I want to switch to the next widget with the text that was inputted on the last widget to be put into a table on the current widget. If someone could help that would be awesome.


r/pythonhelp • • Apr 18 '22

Assignment advice

2 Upvotes

Hi! I have been having trouble with this assignment problem. If anyone can help me with this I would greatly appreciate it.

The program says to write a function that accepts a string of arbitrary length as an argument and it should print out a list where each character in the original string is repeated and capitalized.

Call the function upper(my_string)

Example upper(“hi”)

[‘HH’, ‘II’]


r/pythonhelp • • Apr 07 '22

How to call a variable from a loop of another function

2 Upvotes

Hi! Just for practice purposes, I tried to call the variable "num" from one function to another, but I could not figure it out. Whatever I tried, the variable stayed not defined in the second function. Here is the code:

def main():
    try:
        num = int(input("Enter an integer: "))
        if isinstance(num, int):
            print(f"You inserted an integer {num}.")
    except ValueError:
        print("It is not an integer.")
        main()


def second():
    print(num)


main()
second()

Also, could you please explain, why doesn't the following code work:

        if isinstance(num, int):
            print(f"You inserted number {num}.")
            return num

Thank you!


r/pythonhelp • • Mar 31 '22

HOMEWORK Condensing try except block

2 Upvotes

Is there a way to condense these into one block? They do the same thing and I'm trying to learn how to condense them.

    try:
        try:
            b = int(b2)
        except ValueError as e:
            raise InvalidInput(str(e))
        try:
            g = int(g2)
        except ValueError as e:
            raise InvalidInput(str(e))
        s = (int(g2)) - int(b2) / 2
    except InvalidInput as e:
        return str(e), 400

r/pythonhelp • • Mar 29 '22

How to keep running code after a data type is failed

2 Upvotes

When i specify a data type before an input

age = float(input("What is you name ?")

If i enter a string format aka a letter of the alphabet, How do i create a while loop and ask for the age again and again till a decimal is entered.


r/pythonhelp • • Mar 24 '22

issue turning pypy to exe with pyinstaller.

2 Upvotes

(English is not my main language so if my writing seems offensive or weird please forgive me.)

well, after using pypy as a replacement of python for about 4 months or more, I just realized that pyinstaller doesn't work with pypy, or at least for me, if anyone knows how can I fix it or if there is any replacement of pyinstaller that works with pypy please tell me!

screenshot of the problem:
https://prnt.sc/6nOl87gj8-HH

thanks to all the readers and commenters!.