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.

Converting selected div classes into a structured dataframe

When using BeautifulSoup, I am attempting to extract data from the paths below: <div class="col-md-8 queryResponseBodyValue">2023-02-02</div> <div class="col-md-8 queryResponseBodyValue">2003-12-26</div> <div ...

Difficulty accessing the link in India using Selenium with Python

I have been attempting to automate the process of accessing a website using Python, but the catch is that it only works when accessed from India. Unfortunately, my current code isn't getting the job done. The existing code, complete with the website link, ...

What are the best methods for converting LSTMs into vectors?

I'm currently puzzled by the concept of an LSTM layer having a specific number of cells, like 50 in this example. Let's analyze the following LSTM block excerpted from a fascinating blog post: https://i.stack.imgur.com/y91nY.png Assuming my inp ...

What is the most effective method for locating a specific string within a text file using Python?

Exploring methods to search for a string in a text file using Python, what is the most efficient approach? (considering speed and resource utilization) My initial attempt was as follows. file = open('/home/socfw/src/edl/outbound_monthly.txt') inputIP = ...

analyzing a snippet of HTML script using BeautifulSoup

As I attempt to gather data from a particular website, I have successfully identified the exact location of the required information. When inspecting the site in Chrome, I can see the specific data I need - in this case, the time. Here is an example of how ...

How to locate an element in Webdriver/Selenium when it lacks a class name, id, or css selector?

Within the search results displayed in groups of 7, you can find the address and phone number for each entry on the right side as follows: I need to extract both the address and phone number for each result. The challenge lies in how these elements are st ...

Tips for transforming gridded temperature data in CSV format (organized by latitude and longitude) into a raster map

Recently, I acquired a dataset that shows the average temperature change across the entire US, but it is formatted with lat/long range. The original csv file can be found here: original csv I am attempting to convert this data into a raster for visualizat ...

Reduce all dimensions in pixels by half in Python 2.x regex ("10px" is modified to become "5px" and others accordingly)

Within an XML file, there are multiple measurements in pixels such as "12px" and "20px". My goal is to reduce all these measurements by half. For example, replacing "12px" with "6px" and so on. Is it possible to accomplish this using regex? In the case of ...

Comparing Data in Django Form Validation

Seeking help with forms and validation in Django using Python. I have a form with a single field where users can input names. However, I need to ensure that only names supported by a third-party website can be entered. Here is my current forms.py: class ...

Troubleshooting a character encoding problem when applying word2vec in Python

I'm currently working on my debut Python app which utilizes a word2vec model. Below is the code snippet I have implemented: import gensim, logging import sys import warnings from gensim.models import Word2Vec logging.basicConfig(format='%(ascti ...

Looking for a Solution to Secure Files Using Selenium Webdriver During Threading?

Implementing multiple threads to initialize PhantomJS or Chromedriver with the following code: Driver= webdriver.PhantomJS('C:phantomjs.exe',desired_capabilities=dcap, service_args=service_args) or Driver= webdriver.Chrome(executable_path='C:/chromedr ...

Configuring Dash application testing with webdriver-manager by setting the local path for Chromedriver

I am currently exploring testing Dash applications using the method outlined in this guide: However, I have encountered an issue with specifying the path of Chromedriver for the webdriver-manager used in dash testing. Below is a snippet of what I attempt ...

Error message: Python code using an invalid Bybit API key

Recently, I attempted to develop a Bybit Trading bot. However, during testing, it suddenly stopped working and kept displaying the error message (10003) Invalid API key. Despite verifying the accuracy of the API key multiple times, the issue persisted. C ...

Is it possible to accept a file as a form-field input in Django without the need to declare it as a Model?

I recently developed a straightforward API for Tax Analysis by processing a ZIP file received from our supplier using the FastAPI framework. However, due to some technical constraints, I have now decided to migrate my APIs to Django. I have been exploring ...

Can one navigate through every if statement within the function?

def CalculateShortestDistance(maps, i, j, short, k): x = 0 y = 0 for a in range(0, len(maps)): for b in range(0, len(maps[0])): if maps[a][b] == 2: x = a y = b if (i == x) and (j == y): ...

What causes the inconsistency in single quote escaping when reading files in Python?

When I open two similar text files on MacVim and read them into Python variables, I notice that their content behaves differently. Can someone explain why this happens and suggest a solution to ensure consistent behavior? Here is an example, where f1.txt ...

Trying to validate HTML5 using Selenium with Python? Here's how to do it

I am currently attempting to validate a specific input field, which can be found at the following link: https://groups.google.com/forum/#!topic/webdriver/sUy6IKpQsHw. Although this link is not my own creation, I am interested in validating the text "Please ...

Struggling to find a specific element on a website with Xpath in Selenium using Python

Attempting to retrieve data from a website named: , specifically targeting the element: /html/body/div[1]/div/main/div/div[2]/div/div[2]/div/div/div[1]/div[4]/div[2]/div[1]/div[1]/div[2]/span[2] which displays volume as a number on the webpage. The code I ...

Discovering the conversion of the camera matrix

Here is another inquiry regarding computer vision. The concept of a camera matrix, also known as a projection matrix, involves the mapping of a 3D point X from the real world to an image point x in a photograph using the equation: l **x** = P **X** Esse ...

When using Selenium webdriver, the function find_elements_by_X sometimes results in an empty list being

My objective is to compile a list of the names of all newly posted items on within a 24-hour period. After some research, I've discovered that Selenium is the ideal tool for this task as the website I am scraping is dynamic and loads more content as the ...

Tips for locating and interacting with a specific element using Selenium

I am delving into the realm of Python and honing my skills by creating practical applications for daily use. I recently embarked on automating a routine task, but hit a roadblock when attempting to utilize selenium to click on a specific element that dynam ...

How can you compare two dataframes of equal size and generate a fresh dataframe that eliminates rows with identical values in a specified column?

In developing a data acquisition device, I am tasked with fetching sensor data from an API every 5 minutes and storing it in CSV files. To reduce the file size, I plan to only save data when there is a change in value. My strategy involves storing all dat ...

Having difficulty installing streamlit via pip through the command prompt

I am encountering an issue while attempting to install streamlit on Windows 10 using pip. After the installation of build dependencies, I receive the following error message: C:\Users\Admin\AppData\Local\Temp\pip-install-c7t4b ...

Adding information to a MySQL database table with Python

As a Python beginner, I am attempting to insert JSON file data into my database table using Python. However, despite not encountering any errors, I only receive the message: Tweet number 49634 is uploading to the server I'm struggling to identify where t ...

The Django query for Freelancers using get() resulted in three matches being returned instead of just one

I encountered an issue when trying to assign a freelancer to a specific gig, as the get() method returned more than one Freelancer - in fact, it returned 3! I attempted to retrieve the logged-in freelancer who is creating the gig by using freelancer = get_ ...

Is it possible to retrieve values from my model when working with Django Templates and incorporating them in the JavaScript header?

With Django, I have managed to successfully retrieve and display data from my model in the content section of the template. However, I am facing issues retrieving data from the model in the header section of the template. Below is the code --> view.py: ...

Deploying Django 1.5 with FastCGI: A Comprehensive Guide

Looking for instructions on deploying Django 1.5 with FastCGI? I'm struggling to locate the flup package for Python3! ...

Failed to find the element using Selenium

Can anyone help me find the username input section on the following website: ? I've included the code snippet I used below: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import ...

Retrieve the nested dictionary

I have extracted a series of elements from an excel datarow: 'Ars','Cr','Assl','Burg','Consp' My goal is to organize them into a nested dictionary as shown below: data_dict.update({'name':'Ars','children':[{ 'name':'Cr','children':[ ...

random.random function was called with an unexpected argument (1 given)

Having trouble understanding how random.random selects from a list of functions in cmd_advice (assuming that's the correct method)? My debugger is throwing a TypeError: random() takes no arguments (1 given). I'm still learning, so please excuse any mistak ...

Configuring Proxies in Scrapy

I'm having trouble configuring the proxy in my Scrapy project. Every time I try to run it, I encounter the following error: Error 2019-05-09 19:36:50 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023 2019-05-09 19:36:50 [scrapy. ...

Obtaining pairs within a Python list: one element and the remaining items

I am interested in this task: from some_cool_library import fancy_calculation arr = [1,2,3,4,5] for i, item in enumerate(arr): the_rest = arr[:i] + arr[i+1:] print(item, fancy_calculation(the_rest)) [Expected output:] # The fancy results from t ...

How to transform HTML input type with identical names into key-value pairs using jQuery

When the addmorefield button is clicked on this form, two more fields with the same name are appended: <form method="post" id="sampleform" action="#"> <div class="input_fields" style="text-align:center"> <input type="text" name="first_name ...

What effect does increasing the height of a floatLayout have on where subsequent blocks are positioned on the screen?

I've encountered an issue with my Kivy code where the Float Layout is adding its children from the bottom up instead of top down. I'm trying to figure out how to make it go back to adding items from top down. from kivy.app import App from kivy.l ...

What is the correct way to utilize the --step-size parameter within the crepe module?

For my Python project, I have decided to use crepe. The module's documentation states that there is a --step-size command available for adjusting the frequency at which pitch analysis is performed. ...

What strategies are most effective for handling secret keys when deploying Django projects using Fabric?

Currently, I am attempting to securely store my SECRET_KEY in an environment variable: # settings/base.py def get_env_variable(var_name): """ Retrieve the environment variable or return an exception """ try: return os.environ[var_name] ...

Enter into a namespace

Recently, I added a new folder to my project in order to utilize methods from files in another project. The process involved adding just the first 3 lines: import sys import os sys.path.insert(0, '/path/to/another/dir') from file_methods import load_obje ...

pyodbc connection makingit through direct pyodbc connnection but not working with sqlalchemy

Why is there a difference in how these two methods establish a connection to the SQL Server? sql_server = 'myserver.database.windows.net' sql_database = 'pv' sql_username = 'sqladmin' sql_password = 'password1' sql_driver= '{ODBC Driver 17 for SQL Serve ...

Using Python's Selenium to automate tasks on Instagram

Currently, I am attempting to perform web scraping on Instagram using Selenium. Specifically, my aim is to log in using the following address with Selenium. On this particular page, the input field for 'username' is structured as shown below: ...

Converting JSON to parquet format or not converting at all, the choice

We have encountered a situation where converting a JSON file to parquet results in the creation of numerous small parquet files. How can we prevent this from happening? What is the most effective and efficient approach to managing this transformation? Bel ...

Converting Matlab Code to Python: A Comprehensive Guide

I'm in the process of converting a MATLAB .m source code file to a Python script. The initial lines of the .m file are as follows: clear all close all clc Here is my Python equivalent code for: clear all: def clearall(): """Clear all global variabl ...

Tips on assigning html actions/variables to a flask submit button

I am facing an issue with my Flask app where the form submission process takes a while for the backend to process. In order to prevent users from refreshing or resubmitting, I want to display a loading gif during this time. The current HTML code for my fl ...

Error encountered: "Flask API deployed on Heroku - <Response [503]> - JSONDecodeError: Expecting value at line 1 and column 1 (character 0)"

Having issues deploying my flask app on Heroku. It runs perfectly fine on my local system, but when deployed and tested on Heroku, I am getting a Response <503>. Sharing the code snippet below import requests import json import time url = 'https ...

Having trouble displaying text within a span element after using execute_script with Selenium?

After numerous attempts to insert text into an input box that functions as a span element, I decided to seek guidance on the proper approach. In my quest, I turned to utilizing the execute_script() method, but disappointingly, no progress was made. Below ...

Breaking Down Arrays in Pyspark: Unraveling Multiple Array Columns into Individual

I need to transform a dataframe with one row and multiple columns into a new format. Some columns contain single values, while others contain lists of the same length. My goal is to split each list column into separate rows while preserving the non-list co ...

What is the best way to fetch the path of a module when I possess a class from within that module?

When working with Python, if you have a class named foo, you can use the foo.__module__ method to retrieve a string containing the name of the module it belongs to. Similarly, if you have a module called bar, you can use the bar.__file__ method to obtain ...

"Validating input options with argparse in Python before specifying data type

Looking to allow a user to input a function name. However, it appears that argparse conducts the type check/conversion prior to checking the choices. Is this a bug? Any recommendations on how to handle this? import argparse def foo(): return 'foo& ...

How can we transform the input for the prediction function into categorical data to make it more user-friendly?

To verify my code, I can use the following line: print(regressor.predict([[1, 0, 0, 90, 100]])) This will generate an output. The first 3 elements in the array correspond to morning, afternoon, and evening. For example: 1, 0, 0 is considered as morning 0 ...

Combining data tables by matching two keys

My current project involves merging two tables: one containing a dataset and the other providing detailed test results based on specific keys from the first table. The data table is as follows: results_items: Test ID | Vehicle ID | Test Class ID | Test R ...

What is the presence of the term "sort" in this JSON document from elasticsearch?

While working on indexing data into Elasticsearch, I encountered a puzzling issue related to the appearance of the ""sort"" attribute. Interestingly, this attribute was not included in my mapping nor in the data being indexed. This instance prom ...

Transforming a PIL image into a MIMEImage

I want to generate an image using PIL and send it through email without the need to save it on the disk. Here's a method that involves saving the image to disk: from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart msg = ...

Guide to extracting data from multiline catalina logs using regex in Python

Looking at the Catalina log provided: oct 21, 2016 12:32:13 AM org.wso2.carbon.identity.sso.agent.saml.SSOAgentHttpSessionListener sessionCreated WARNING: HTTP Session created without LoggedInSessionBean oct 21, 2016 3:03:20 AM com.sun.jersey.spi.containe ...

Tips for adjusting QTextTable to span the entire width of the document

I'm seeking a way to make the QTextTable within QTextDocument take up 100% or full width of the document. Unfortunately, there doesn't seem to be a method in the QTextTableFormat class that allows for formatting the QTextTable to have 100% width. ...

How can one best tackle the solution of a differential equation at each interval of time?

Is there a suitable equation solver for a timestep scenario? I have tried using ODEint, Solve_ivp, and even sympy to solve a first order differential equation like this: dTsdt = Ts* A - B + C # Defined in a function. This is the mathematical model. wh ...

Eliminating Inferior Strategies in Competitive Games

The Challenge Utilizing Gambit's Python API, I am faced with the task of streamlining a game tree by eliminating strictly dominated strategies. The issue arises when my tree becomes too large for the Gambit UI to handle efficiently and save after tri ...

What is the best way to broadcast messages to multiple clients using Flask-SocketIO?

Currently, I am diving into the world of Flask-SocketIO with a simple chat application in mind. However, I've encountered an issue where messages are not being received by anyone except for the user in the browser. Here's the Python/Flask code sn ...

Creating a formatted string list using values from a pandas DataFrame: A step-by-step guide

Issue Looking for a way to generate a list of strings with placeholders (similar to "f-strings") by leveraging the values in a pandas DataFrame. Scenario Consider the following dataframe: import pandas as pd data = [ ['Alice', 13, &apos ...

Updating values within a column by finding a corresponding match

I am dealing with a Pandas DataFrame that includes the names of Brazilian universities, which can sometimes be listed in both short and long forms (e.g., Universidade Federal do Rio de Janeiro may also appear as UFRJ). Here is an example of how the DataFra ...

Is it feasible to streamline the process of obtaining a tuple value using an if statement within a for loop?

Is there a more efficient way to simplify this code by using enumerate instead? list1 = ('c_test1', 'c_test2', 'test3', 'c_test4', 'test5', 'test6', 'c_test7') tuple1 = ['list1', 'list2', 'list3', 'list4'] i = 0 for i, x in enumerate(list(list1)): ...

Generating Multiple Rows from Pipe-Delimited Column in Pandas

Can you help me with a Python problem I'm having? I need to split a column into multiple rows, like this: A B ABC|XYZ|PQR 123 And turn it into: A B ABC 123 XYZ ...

Guide on clicking a label element with Python and Selenium

I have been working on a web scraping bot using Python and Selenium, but I've encountered an issue. The website I'm trying to scrape has a fieldset HTML tag with 4 label tags inside it. All these labels have the same class name and I need to click on one o ...

Django REST FrameWork JWT prohibits the provision of data and self-decoding

I currently have these API endpoints set up: urlpatterns += [ path('api-token-auth/', obtain_jwt_token), path('api-token-verify/', verify_jwt_token), path('api-token-refresh/', refresh_jwt_token), path('api/', include(router.urls)), ] For ...

Saving a Python list to a CSV file will empty the list

I'm currently experimenting with lists, the enumerate() method, and CSV files. In my process, I am using the writerows() method to store an enumerate object in a .csv file. However, once the writing is complete, the list/enumerate object ends up empt ...

There seems to be a glitch with the Flask flash messaging feature, as

My Flask application includes login and register routes where I aim to display flash messages when username passwords are not matched. Specifically, this issue arises in my index and login routes: @app.route('/') @login_required def index(): return 'He ...

Issue with updating Selenium ChromeDriverManager through a proxy network

I am trying to use selenium and Chrome with Python to access a website. Below is a snippet of my code: from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service # PROXY='h ...

Every conceivable permutation of lists derived from a given list

I am seeking to generate all possible combinations of lists with a specific size. For instance, let's consider a list K, where K = [3, 5, 2]. The code snippet below accomplishes this task for the given list. However, I am interested in finding a way to m ...

Selenium in Python producing unpredictable outcomes when retrieving data

driver = webdriver.Chrome(driver_path, options=chrome_options) wait = WebDriverWait(driver, 20) driver.get('https://%s/' % asset_id) wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id='dev_diaginfo_fid']"))) prin ...

Effortless content extraction between HTML tags using BeautifulSoup in Python

My Weather Data Extraction Project: I'm currently developing a webpage scraper to collect weather information. This is the progress I have made so far: import urllib.request from bs4 import BeautifulSoup # opening the webpage and storing the content in ...

What is the best way to implement a function in a discord.py command that restricts the use of a command to only once per minute?

What is the best way to ensure a command in discord.py can only be used once every minute? @bot.command() async def busk(ctx): member = ctx.message.author.id #gets the user ID, which i use as the _id in pymongo because everyones is different. ...

Creating CSV files in Python

As part of a D&D game, you find yourself in a battle area with a list of monsters. To enhance your gaming experience, you decide to develop a program that can read and process information about these creatures. You have been provided with an input file na ...

How to retrieve tab titles using Playwright in Chrome

I've been attempting to retrieve the tab name using playwright. However, my code is only displaying the page URL. For instance, I am aiming to visit and extract the name displayed on the browser tab: Rotten Tomatoes: Movies/ Tv Shows/ Movie Trailers... ...

Step-by-step guide on correctly plotting the image after converting it to an array using the img_to_array function

I'm trying to figure out how to plot an image that has been converted into an array using keras.preprocessing.image.img_to_array. Here's my approach. To provide a simple example, I downloaded a picture of a duck from the internet: import urllib.request ...

Openerp, please assist me in getting rid of this

Hello all, I am looking for assistance in removing the "manyone" option from specific pop up fields, not all of them. Some fields still require this feature, but I have noticed that when using widget="selection", my domain filter stops functioning properly ...

Changing between TABS (rather than windows) using selenium in python

Is there a way to switch between tabs (not windows) using Python Selenium? Here's the scenario: I need to log in to capital.com with Google. The script first clicks on "login", then selects "login with Google", which opens a new tab where I have to ...

Calculate the sum of each column in a pandas dataframe using user-defined functions in Python

Showing my dataset: df = [{'id': 1, 'name': 'bob', 'apple': 45, 'grape': 10, 'rate':0}, {'id': 1, 'name': 'bob', 'apple': 45, 'grape': 20, ...