Questions tagged [python]

Python, a versatile and dynamic programming language, offers a multitude of functionalities. Known for its easy comprehensibility and efficient syntax enforcement, Python has gained popularity among developers. However, it's important to acknowledge that Python 2 is no longer supported since January 1, 2020. If you have questions regarding specific versions of Python, kindly include the [python-2.7] or [python-3.x] tag. Additionally, when utilizing alternate Python variations such as Jython or PyPy, or incorporating libraries like Pandas or NumPy, please remember to include relevant tags.

Issue with function argument types is causing failure of Sphinx autodoc extension for python versions higher than 3.5

Recently, I've been working on setting up autodoc to automatically generate documentation for my Python 3.7 module. The specific file that needs documenting is the init.py file within a single module. This particular file contains functions with docst ...

Efficient Rotation with AWS Proxy in Conjunction with Amazon API Gateway and Selenium

Looking to scrape websites using selenium. Successfully implemented selenium on ec2, but since ec2 is tied to a specific IP, I'm interested in incorporating Amazon API Gateway rotating proxy into my python selenium script. Came across this helpful t ...

What is the best way to replace a segment of a pandas dataframe with another?

Suppose I have two DataFrames, df_a and df_b. I am looking to swap lines 42 through 51 of df_a with the corresponding rows from df_b (same number of rows, but more columns than df_a). The code I am currently using is df_a.loc[45:52,:] = df_b.loc[45:52," ...

Tips for utilizing Scrapy and Selenium to extract information from a website employing javascript and php features

I've been trying to collect data from a website that provides details on accidents. I attempted using Scrapy and Selenium for this task, but unfortunately, it's not working as expected. As a beginner in this field, I'm struggling to grasp wh ...

Capturing Screenshots as Numpy Arrays Using Selenium WebDriver in Python

Can selenium webdriver capture a screenshot and transform it into a numpy array without saving it? I plan to use it with openCV. Please keep in mind that I'm looking for a solution that avoids saving the image separately before using it. ...

Getting a 400 Bad Request error while trying to send JSON data to a PHP page via socket

Currently, I am in the process of developing a program that can gather temperature and humidity data from a Pysense device and then store this information in a database on my laptop. To accomplish this, I have set up a socket to send Json data via POST to ...

Pandas encountered a ValueError while attempting to add a new column, as it cannot reindex from a duplicate axis

Here is the information I have: Inv Dt Due Dt 22 2020-10-31 2020-11-15 181 2020-10-01 2020-11-15 182 2020-10-01 2020-11-15 1845 2020-10-30 2020-11-14 2185 2020-10-14 2020-10-16 ... ... ... 308085 ...

Statistics Sweden SCB API call was made, but unfortunately, no data was retrieved

I am having trouble accessing the actual values of the data in my table, as all I can see is the dates in the JSON output generated. The specific link I am using is: "http://api.scb.se/OV0104/v1/doris/en/ssd/START/FM/FM5001/FM5001A/FM5001SDDSPM" ...

Unable to establish TCP port connection from an external host

Seeking assistance desperately! I've been grappling with this issue for hours now. I'm at my wit's end, exhausted from scouring every possible resource with still no solution in sight. The predicament I find myself in involves a Python scri ...

Opening Selenium Chrome is a one-time deal

I have encountered an issue with running two Selenium files simultaneously to perform different tasks. When I attempt to run these files individually, they work fine. However, if I try to execute both at the same time or sequentially, the second file cras ...

Can Ansible convert integers into MAC addresses?

Currently, I am facing a challenge where I have an integer that needs to be converted into a MAC address. I attempted using the hwaddr in Ansible but it did not provide the desired result. Any assistance with this would be highly appreciated. I also explo ...

Using Python's Selenium for Page Object Model (POM) implementation

As a newcomer to automation testing, I am currently learning how to automate tests using Selenium with Python and the page object model. While watching tutorials on YouTube, I noticed that logging in is being done for every test case, which seems redundant ...

Tips for successfully sending the caret sign (^) to the send_keys() method in Selenium WebDriver

I'm working on automated tests with Python and Selenium WebDriver, and I need to log in to a website using a complex password. When trying to pass special characters, including the caret sign (^), to the send_keys method, it doesn't seem to work as expect ...

Rendering nested data structures in Django using a tree view

My backend server sends me a JSON response structured as follows: { "compiler": { "type": "GCC", "version": "5.4" }, "cpu": { "architecture": "x86_64", "count": 4 } } I am looking to represent this response ...

Which is better for a web automation bot in Python: Multithreading or Multiprocessing?

I have a script that continuously monitors the prices of specific products on nike.com. Once the price drops, it will automatically initiate multiple instances to log in and purchase the item from different accounts. While I already have the scraping and ...

"Encountering a MoveTargetOutOfBoundsException error while using Selenium with Python

My Accounts Menu has a feature where the sub menus appear when the mouse hovers over it. Check out the screenshot below. I am trying to click on 'Accounts Summary' using my Selenium code shown below. def test_accounts(self): self.login(self.driver,pr ...

Opera and Robotframework integration on Windows system

I am currently experiencing difficulty using Opera for website testing in Robotframework with SeleniumLibrary. I have discovered that the issue lies in the code's inability to handle Windows paths correctly. (On Windows, the default approach is to use ...

How to incorporate a personalized widget into a QTableWidget using PySide6

I've been attempting to incorporate my custom widgets into a QTableWidget, and while they are being added, they're not displaying correctly. The issue seems to be related to spacing within the cell boundary and the QWidget itself. Below is the sn ...

The Mxnet datatype presents as float64, yet consistently insists that it is actually float32

Being a user of both PyTorch and TensorFlow, I recently discovered Mxnet while exploring AWS Sagemaker's elastic inference feature. I found that Mxnet's Gluon dataset API bears a striking resemblance to PyTorch's dataset setup. class CustomDataset(mxnet. ...

How can I obtain a standard Python REPL through JetBrains?

I'm currently working on a project to simplify a classic drinking song using Python, but I'm encountering some odd behavior from the interpreter. My code looks like this: def lines(): bottles = 99 while bottles > 0: yield str ...

Attempting to display sums in lists alongside strings in the output

Recently, I've been immersed in a Python project that involves analyzing data from a CSV file. However, I'm encountering an issue where the output only displays lists of numbers without summing them up alongside strings. Here's the code snippet I'm curren ...

Unable to interact with Selenium button element (type=button)

I am facing an issue with clicking a button on a specific website: The site in question is: Although the program successfully opens the website, it does not allow me to click on the "Load All" button to display all data. Upon inspecting the HTML code, I ...

Waiting for a tweet to load before scraping a website using BeautifulSoup, Python, and Selenium

I am currently facing a challenge in scraping a website to extract tweet links, specifically from DW. The issue I'm encountering is that the tweets do not load immediately, causing the request to execute before the page has fully loaded. Despite trying opt ...

Separate nested lists into individual lists

Here is a sample list: list1=[['xx', 'xx', 'xx', 'xx', 'xx'], ['yy', 'yy', 'yy', 'yy', 'yy'], ['zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz'], ['tt', 'tt', 'tt', 'tt', 'tt'] . . . n] I am looking for a function to convert the nes ...

Query a string in MongoDB using Python3

I am faced with the challenge of creating a dynamic query in MongoDB without prior knowledge of how many variables I will have. The goal is to eliminate duplicates by using the $or operator. def findRecipes(IngredientsHome): #Query and return all the alte ...

group and apply operations to all remaining keys

If I have a pandas dataframe called df, I can find the average reading ability for each age by using the code df.groupby('Age').apply(lambda x: x['ReadingAbility'].mean()). But what if I want to find the average reading ability for all ages except one, sa ...

Exploring the correlation between the number of nodes on AWS EMR and the execution time of

I am a newcomer to Spark. Recently, I attempted to run a basic application on Amazon EMR (Python pi approximation found here) initially with 1 worker node and then in a subsequent phase with 2 worker nodes (m4.large). Surprisingly, the elapsed time to co ...

Transforming values in a dataframe into a one-dimensional list

Here is the dataframe I'm dealing with: V Out[58]: P1 P2 P3 V1 a b c V2 f g h V3 k l m I am looking to store all values in a list L as follows: L=[a,b,c,f,g,h,k,l,m] I need a way to iterate from one row to another. Does anyone ...

Tips for organizing a dataframe with numerous NaN values and combining all rows that do not begin with NaN

Below is a df that I have: df = pd.DataFrame({ 'col1': [1, np.nan, np.nan, np.nan, 1, np.nan, np.nan, np.nan], 'col2': [np.nan, 2, np.nan, np.nan, np.nan, 2, np.nan, np.nan], 'col3': [np.nan, np.nan, 3, np.nan, np.nan, np.nan, 3, np.nan], ' ...

Using Django to redirect to the parent of an iframe from a view

I have a web page displayed through an iframe. When I submit the form within the iframe successfully, I used the following code: return HttpResponseRedirect("www.google.com") However, the target page is also being loaded within the iframe. How can I spe ...

Unable to configure Luminati proxy with Selenium using Python 3

Currently, I am in the process of configuring a proxy for the Firefox driver using Selenium on Python. To set up the proxy, I followed the guidelines provided in this instruction: https://github.com/luminati-io/api/blob/master/python/3.x/simple.py userna ...

Python 3 - Locating overlooked tuple intervals

Suppose I have an integer range starting from 0 and ending at 48. How can I identify the missing inclusive sequences in the given arrays? Given: [(10, 12), (12, 37)] Output: [(0,10),(37,48)] Given: [(9, 15)] Output: [(0,9),(15,48)] Given: [(0, 15), ...

What is the best way to initiate a Casperjs script using Python?

Having trouble using Subprocess. When trying to run the Casperjs file in the command prompt, I typically use this command: casperjs.bat test.js Unfortunately, Subprocess is failing because the script is not an executable file. This issue is occurring wit ...

What is the best way to extract a particular value from a text that consistently appears a few lines below another value?

This is my method for extracting data from a JSON file: import json json_file = json.load(open('Bla_Bla_Bla.json')) master_data = json_file['messages'] for unique_message in master_data: print(unique_message['text']) Here is the structure of the JS ...

Issue: TemplateNotFound when accessing /app/index.html

Having trouble resolving this error message despite trying various solutions. Whenever I start the server, I encounter the following error: TemplateDoesNotExist at /app/index.html Here is a snapshot of my app structure In the 'settings.py' file within th ...

Troubleshooting problems with SQLite3 when multiple users are accessing the database concurrently

I am encountering difficulties with data reads in my SQLite3 database. Scenario: I have created a python program that runs two scripts simultaneously: Script1: Constantly retrieves messages from an MQTT broker at intervals of 30 seconds and writes data t ...

Is SimpleHTTPServer included in the package?

Lately, I've been experimenting with the Python SimpleHTTPServer in Mac OS X Bash instead of MAMP to assist with front-end templating. I appreciate its user-friendly nature, but I'm curious if there is a method to incorporate includes for repeated sections ...

Create a Python class decorator that displays the integer variables within the adorned class

Currently, I am enrolled in a python course and one of the assignments is to develop a decorator for this particular class that will list all integer variables. @classDecorator class MyNewClass: def __init__(self): self.x = 5 self.y = ...

In Python, use a loop to assign different values to various index positions within a list

In my current project, I am working with a variety of data types including Lists, float values, and a NumPy array. dt = list(range(1, 12)) c = 18 limit = 2.75 Energy = np.zeros(len(dt)) My goal is to assign the value c = 18 in the NumPy array Energy. ...

Navigating the Zeppelin: A Guide to Understanding DataFrames via SQL

I am new to using Python with Zeppelin and I am trying to import a dataframe into Zeppelin through SQL. However, I have only found materials about PySpark in Zeppelin so far. %python import pandas as pd #To work with dataset import numpy as np #Math l ...

Ensuring visibility remains unaffected by updates in PySimpleGUI

I'm currently facing an issue while attempting to make a GUI element invisible by setting visible=False. It seems that the update function is functioning properly for all attributes and values as shown in the provided code snippet, except for the visi ...

Storing a JSON as a cookie in a Django response

Is there a way to store a dictionary/json object in a client-side cookie from Django and retrieve it as a JavaScript object? response = HttpResponseRedirect(reverse('app:home')) response.set_cookie('cookiekey', 'value') retu ...

Elementary Mathematics / straightforward encryption techniques

Currently, I am in the process of developing a relatively simple encryption method. However, I have encountered a problem that I cannot seem to solve. During the encryption process, I take a string as input and convert it into binary for some calculations ...

How can you give a block a unique name using a variable in Jinja2?

In the template "base.html" that I have, there is a set of ids called list_of_ids. The template contains a for loop that goes through each id in this list and outputs a specific block of content for each one. {% set list_of_ids = ['id1', 'id2', 'id3'] %} ...

A method for iterating through rows of a table

I attempted to create a table that displays the temperature in celsius and fahrenheit, starting from 0 to 100 degrees celsius with 10-degree increments. However, my initial attempt resulted in generating 10 separate tables. Here is the code snippet I use ...

Deliver a whopping one million messages to the queue within sixty seconds

I'm currently utilizing rabbitMQ for message reception. I have a million messages that need to be sent to the queue within a minute. Using multiprocessing in Python, my code is taking more than 5 minutes to send them all out. Is it feasible to achieve ...

Guide on converting the names of weekdays and months in a Django calendar into different languages

I am looking to change the language of the days and months displayed in a Django calendar from English to Polish. I have tried adjusting the settings and using LocalHTMLCalendar without success. Below is my utlis.py file: class Calendar(LocaleHTMLCalendar ...

Python encountering errors while attempting to load JSON file

I have a text file containing the following json: { "data sources" : [ "http://www.gcmap.com/" ] , "metros" : [ { "code" : "SCL" , "name" : "Santiago" , "country" : "CL" , "continent" : "South America" , "timezone" : -4 , "coordinates" : {"S" : 33, "W" : ...

Changing a string into an already present variable (pandas)

When working with a dataframe df and trying to access the unique values of a specific factor (e.g. ID), you can use the following code: UniqueFactor = df['ID'].unique() However, if you want to convert this into a function that allows you to acce ...

Python code: Attempting to retrieve the hour, minute, and second values from a datetime object

As a newcomer to the Python environment, I am working on manipulating datetime objects by using the method replace(hour=...,minute=...,second=...) in an iterative manner and storing the results at each step in a pd.Series. The objective is to have a pd.Ser ...

Executing a for loop asynchronously on an AsyncGenerator

When working with an asynchronous generator, the expectation is to be able to iterate through it asynchronously. However, after running the code below, a synchronous for loop is produced instead: import asyncio async def time_consuming(t): print(f"G ...

Using Selenium to Extract Data from Complex HTML Structure

I am seeking assistance in web scraping using Selenium with Python. The page I am trying to scrape requires a paid account to access, making it difficult to create a reproducible example. Here is the page I am attempting to scrape Specifically, I am tryi ...

What is the best way to retrieve the most recent information from APScheduler using sqlalchemy?

I am working on using Advanced Python Scheduler to access data from a MySql database using Flask SQLAlchemy every five seconds. However, despite my efforts, I am facing an issue where I am unable to retrieve the latest modified data from APScheduler throu ...

Python script to extract product information from Walmart search results

Attempting to gather search results from Walmart has been a challenge for me. For instance, let's navigate to the website "" Then, try to extract only the text from the element identified by the class name search-product-result, using python. ...

Every time I attempt to create an instance of the Font class in Tkinter, I encounter an error

When running this line: my_font = tk.font.Font(size=20) I encounter the error below: The module tkinter does not have the attribute font Any suggestions on how to resolve this issue? ...

generate a graph for the top 20 most common words in the

Currently, I am attempting to display the most frequently used words in a plot, however, I am encountering an issue due to the language being Arabic which does not align with the format. fig, ax = plt.subplots(figsize=(12, 10)) sns.barplot(x="word", y="fr ...

Generate additional smaller DataFrameS by using a groupby function on the original DataFrame

I've got a dataset structured like this: Index Amount Currency 01.01.2018 25.0 EUR 01.01.2018 43.5 GBP 01.01.2018 463.0 PLN 02.01.2018 32.0 EUR 02.01.2018 12.5 GBP 02.01.2018 123.0 PLN 03.01.2018 10 ...

Storing a collection in redis-py

Attempting to save a list created from a dictionary into my redis database, I am running the following script: x = {'TLV-IST#2022-12-27~2023-01-04': '252', 'TLV-IST#2022-12-27~2023-01-17': '300'} for key, value in x.items(): client.lpush(key[:7], key[ ...

Mastering the art of list comprehension in Python: avoiding the common pitfall of getting stuck with a list of booleans

My goal is to eliminate periods, commas, single and double quotes from the end of each string within a list. Each string is part of a larger list of strings. string_list= ["cars." , "red" , "orange," , "man'" , "thus:"] desired_output --->["cars" , "r ...

Tips for arranging a secondary list according to the order of the first list?

Struggling to sort an ordered list based on the order of an unordered list? I attempted to do so by manipulating the indexes of each element in both lists without success. If anyone has faced a similar challenge or knows the right function to use, I'd appr ...

Python and Selenium: Mastering the Art of Drop-Down Menus

I am currently on the hunt for a dropdown element in order to select an option from it. I know that Selenium has a built-in class specifically for handling select drop-downs, but I'm having trouble locating the actual element. Could someone point out ...

Tips for combining cells partially in a vertical direction within the pandas library

Here is the dataframe I am working with: index Flag Data 0 1 aaaa 1 0 bbbb 2 0 cccc 3 0 dddd 4 1 eeee 5 0 ffff 6 1 gggg 7 1 hhhh 8 1 iiii I want to obtain a merged vertical data where it's divided by Flag 1. index Flag Dat ...

What is the significance of including a "sleep" function in order to achieve a successful constant time attack?

On the webpage , the author provides an explanation of what a constant time attack is and how to protect against it. However, when looking at the code created by the author: # secret.py from time import sleep # Used to exaggerate time difference. from sys ...

Converting a whole number into a timestamp using Python

After struggling with converting the list l: l = [0, 1] into timestamps corresponding to the indexes of dataframe df: dt val 2017-11-13 00:00:00 8 2017-11-13 01:00:00 17 Ideally, I want the result to be: l = [2017-11-13 00:00:00, 2 ...

From Jquery to Python: Converting Query Dict in Django

My method of sending an array using JQuery is as follows: var items = []; items.push({ "item":someItem0, "quantity": someQuantity0, "category": someCategory0}) }); it ...

Would you be able to assist me in automating the clicking of the Postcode Checker Search button using selenium

Struggling with my Selenium tutorial in Python as I can't get the postcode search button to click. Using: Python v3.9 Chrome v87 The URL for practice is: This is the code snippet I'm currently working with: # Selenium Tutorial #1 from selenium import ...

Determining confidence levels in association rules

supportData = {('ELF'): 0.75, ('CAT'): 0.75, ('BAT', 'CAT', 'ELF'): 0.5, ('ARK', 'BAT'): 0.25, ('ARK', 'ELF'): 0.25, ('CAT', 'ELF'): 0.5, (&apo ...

problem encountered while executing python on the command line

Upon attempting to run Python in my terminal, I encountered the following error: -bash: /Users/steve/Library/Enthought/Canopy_64bit/User/bin/python: No such file or directory The issue arose because I had initially installed Anaconda and then mistakenly ...

Extracting specific information from named entities using Python 2.7

I have a string that is formatted as follows: "<ENAMEX TYPE="PERSON">Edward R. Kimmel</ENAMEX>, one of Admiral <ENAMEX TYPE="PERSON">Jack</ENAMEX>'s two surviving sons and..." I am looking for an output similar to this: PERSON Ed ...

python creating a copy of a pandas dataframe with assigned missing values

I'm currently attempting to establish the mean value for a group of products within my dataset. My goal is to iterate through each category and fill in any missing data as needed. df.loc[df.iCode == 160610,'oPrice'].fillna(value=df[df.iCode == 160610].oPr ...

Clicking the "OK" Button in an Alert Box with Python and Selenium: A Step-by-Step Guide

My goal is to interact with the "OK" button within a pop-up dialog https://i.stack.imgur.com/QFoLu.jpg I attempted the following code: driver.switchTo().alert().accept(); Unfortunately, this approach was unsuccessful ...

Exploring pytest integration: mastering the art of importing modules

My current setup involves using py.test to test my python code within the following project structure: -myproject file.py file2.py -test/ input.txt input2.dat test_part.py -regress/ file2_old.py __ini ...

What are some methods for incorporating the test_proportion dataset into a machine learning algorithm?

I have a dataset containing 4000 CNN features for a binary classification problem. The only information I have about the test data is the proportions of labels 1 and 0. How can I instruct my model to predict test labels based on these proportions? Is there ...

CSV reader is generating additional empty entries

I am working with an input csv file that has a varying number of columns which I am trying to convert into a list. The issue I am facing is that my test is parsing the csv file and creating a list with additional elements around the csv columns. Ideally, I ...

What is the reason that pygame.mixer.Sound().play() doesn't return a value?

As per the pygame documentation, calling pygame.mixer.Sound().play() is expected to return a Channel object, and indeed it does. However, on certain occasions, it appears to return None causing an error to occur immediately after: NoneType has no attribut ...