Unique Example: words_to_check = ['dog', 'cat', 'bird chirp'] full_word_list = ['doggy dog cat', 'meow cat purr', 'bird chirp tweet tweet', 'chirp bird'] for word in words_to_check: print(list(map(lambda x: re.findall(word, x), full_word_list))) Aft ...
Here is some sample data: name1|name2|name3|name4|combined test|data|here|and test|information|343|AND ",3|record|343|and My coding solution: import csv import StringIO storedoutput = StringIO.StringIO() fields = ('name1', 'name2', 'name3', 'name4', ' ...
My goal is fairly straightforward - I want to have two options that are mutually exclusive: -p and -c. These options may or may not include an argument. The objective is to do th...is with an optional argument or do th...at without one. This is the code sn ...
I've been grappling with a certain problem that ultimately boils down to calculating the value of https://i.stack.imgur.com/ovS3p.png (n+m-2 Combinations m-1). Here's what I have so far. In situations where the result exceeds 10^9+7, I must output my_ans ...
Assistance required in retrieving the value from a specific tag. Provided below is the element along with its xpath The element: <a href="/pages/viewpage.action?pageId=37129112">Sprint1 AC/AT's</a> xpath: .//*[@id='content']/div[5]/ul/li/ul ...
Currently, my code is designed to perform a sequence of actions: open a window, navigate to a link on the page, extract some data from that page, and then close the tab. However, I am encountering an issue with closing the tab after completing these step ...
If I have a collection of lists: [[0,0,0,1,2,3],[0,0,0,4,5,6],[0,0,0,0,7,8],[0,0,0,0,0,9]] I am looking to create a new list where common null, zero, or specific values are removed from each inner list to achieve the desired output: [[1,2,3],[4,5,6],[0, ...
When working on my Python code, I utilized various libraries such as pathos, arcpy, and numpy. However, I have noticed that each time I run the code, approximately 0.5 GB of free space on my C drive decreases, even though the Python file itself is located ...
import json def serialize_json(name, type, filepath): data = [] data.append({ 'name': name, 'type': type }) with open(filepath, "w") as file: json.dumps({'profile_info': data}, file) ...
My program is designed to take user input and search a specific webpage. Once the desired link is located, I want it to navigate to that page and download the file available there. For example: The webpage: The search term: "1AW0" After performing a se ...
Currently, I am attempting to create a script that will log into a website and click a button without the need for opening a browser. However, every time I try to set up my selenium remote case, I encounter an error stating 'module' object is not callable. ...
I wrote a python script that takes a .txt file as input and produces another .txt file as output. My goal is to create a bash script that I can simply click on from my desktop to run the python script. This is what I have done so far: #!/bin/bash cd /Des ...
I am working with a series of dynamically updated chaco plots using a timer object. My goal is to set the Y (referred to as "value" in chaco) limits when the data changes. Upon initializing the plot object, I call: obj.alldata = ArrayPlotData(frequency=f ...
After creating a Python file with multiple functions, I am now working on designing a web page where I aim to trigger one of the functions mentioned earlier by clicking a button. However, I am unsure about how to go about this process. Is there anyone who ...
After crafting a Python script to format a text file for SQL importation, I discovered that it perfectly runs with python 3.5. However, when attempting to execute the script with python 2.7 (as required), an error is thrown which reads: TypeError: 'newline ...
I am attempting to retrieve all the UserStories associated with a specific Project (let's say project 'Bolt' in workspace 'ABC'). Once I establish the connections (using username, password, and server) and set my workspace to the ...
I am planning to share my Python program with others and I would like to convert it into a .exe file using py2exe. However, I encountered an issue while using Selenium. chrome_path = r"C:UsersViktorDesktopchromedriver.exe" If users do not have the sa ...
Trying to learn Python and utilizing urllib to download tweets, I encountered a recurring error while following a tutorial. Here is the code snippet causing the issue: import urllib import json response = urllib.urlopen("https://twitter.com/search?q=Micro ...
Currently, I am utilizing Sublime Text 2 as my primary editor to develop a brand new Google App Engine project. UPDATE: While testing this code via localhost, I encountered an issue when accessing the app on appspot: Status: 500 Internal Server Error ...
I am in need of assistance with scraping a JavaScript generated table and saving specific data to a csv file. The tools available to me are limited to python 2.7, Beautiful Soup, and/or Selenium. Although I have referred to the code provided in question 14 ...
I need help extracting specific data from an HTML table. I want to extract the information from the columns with the text "Total" and the value "93" only, rather than extracting all column data as my current code does. For example, the current output is: ...
For example, let's say I have a dictionary: >>> gtf['mykey1'] {'name': {'apple': '20', 'eat': ['Leo', 'Amy', 'Lily', 'Lucy']} I am looking to save th ...
I am facing an issue with my code that uses XPath to search through text. The problem arises when the text being searched contains special Latin characters like ñ or í. After encoding the text, it displays correctly when printed. However, the issue occu ...
I'm attempting to learn how to handle JSON POST data in Python 2.7 with a cherrypy setup that can serve both html and json content Here is the script I'm using to send a sample JSON request: import urllib2 import json def mytest(): d = { ...
Here is the HTML code I am working with: <ul aria-hidden="false" aria-labelledby="resultsPerPage-button" id="resultsPerPage-menu" role="listbox" tabindex="0" class="ui-menu ui-corner-bottom ui-widget ui-widget-content" aria-activedescendant="ui-id-2" a ...
I am currently working on comparing two lists that have varying sublists sizes, and I need to find pairs (enclosed in round brackets) that are present in one list but not the other. Check out the code snippet below: s1 = [ [('RESOLVED - DUPLICAT ...
Is it possible that there are concealed files lingering around? And is a re-installation of Python 2.7 necessary in order to use it? Appreciate your help! ...
My current project involves setting up a FlaskSocketIO with socket.io.js application to facilitate real-time communication between the frontend and my web socket server. Here is a snippet of the frontend code: $(document).ready(function() { name ...
I am currently working with Weasyprint to showcase some Jinja templates within a Flask Web App. Here is the JSON data I am using: value=["1","2","3","4"] My goal is to pass the 'value' variable to another Jinja template within an if statement. {% if (v ...
How can I adjust my python unittest module to execute specific actions depending on the outcome of the test? My scenario involves running automated selenium webdriver tests, and I want to be able to take a screenshot in case of any failures or errors. ...
I am encountering difficulties in parsing a JSON array I created into a Python list. Despite my efforts, I have not been successful in achieving this. Is there a way to convert my JSON array into a Python list? The structure of the json data I want to pa ...
I'm utilizing Selenium to automate a task on a website, and I'm facing a challenge in selecting an item using the following: select = driver.find_element_by_*whatever* Unfortunately, the available whatevers like find_element_by_id, by name, by tag name, ...
When I need to verify if different parts of a string are in a value, it seems that I must specify the value for each part of the string in order for it to work correctly within an if statement. It appears that the correct method is the one utilized in my ...
I've recently started delving into the realm of Python coding, and I have a question for you: Code def Foo(): pass def Bar(): return None Usage a = Foo() print(a) # None b = Bar() print(b) # None Question: 1. Despite having return None, ...
Currently, I am developing a Django CMS plugin that includes a model choice field dependent on another field in the form. To update the choices in the model choice field based on the trigger field selection, I am using AJAX. However, when submitting the fo ...
I have developed a Python command line program that is open source and compatible with Python 2.7, Python3+, and works across different platforms. My goal now is to package this program into an executable for my Windows users in a more user-friendly way. ...
Imagine having a Python dictionary with nested dictionaries to any level and a mix of keys representing boolean choices and others that don't. For example: {'Key1': 'none', 'Key2': {'Key2a': True, 'Key2b& ...
Recently, I've begun exploring Python and am interested in using a Parser for handling command line options, arguments, and subcommands. I want my command structure to resemble the following: If storing in S3 or Swift: $snapshotter S3 [-h] [-v] --a ...
I am encountering an issue while trying to create a tarfile that contains Turkish characters like "ö". I am currently working with Python 2.7 on a Windows 8.1 system. Below is the code snippet causing the error: # -*- coding: utf-8 -*- import tarfile im ...
I'm currently working on solving a challenge in TalentBuddy using Python Here is the problem statement: Given an integer N, you need to find the total number of subsets that can be created using the set {1,2..N}, ensuring that none of the subsets conta ...
Currently, I am working on coding in IronPython and facing an issue while attempting to send an HTTP POST request to the server with JSON in the request body. To achieve this, I am utilizing the C# method: HttpWebRequest. Despite knowing that there are mor ...
I am facing an issue where my code does not display any output when using isinstance. This problem is highlighted at the end of the code snippet. I attempted to input year 1 and tla_2=1, yet no output was generated. Could the issue lie with my isinstance s ...
I'm working on a project to calculate the distance between Voyager 1 and Earth. NASA has detailed information available on their website at this link: ... I've been struggling to access the data within the specified div element. Here's the code for the div ...
Is there a way to force my interpreter (2.7) to import a module from site packages in case of a conflict? Let's say you are working with a directory structure like this: top_level ----cool_mod ----init.py ----sweet_module.py You already have swee ...
Recently, I've been delving into the world of OOP in Python and trying to grasp some basic concepts. One question that popped up was related to subclassing a class like list and how to properly invoke the parent constructor. After experimenting a bit, ...
I attempted the following approach but it appears to be ineffective. If numpy is not an option, what would be the correct alternative? Appreciate your help. y = [[1]*4 for _ in range (4) for _ in range(4)] Thank you in advance, Alice ...
I am currently going through the O'Reilly book "Exploring Everyday Things in R and Ruby" and my task is to convert all of the Ruby code into Python. I started with a model that determines the number of bathrooms required for a building, and here's the code ...
Hi there, I'm having some trouble with my Selenium Python regression test script. My HTMLTestRunner isn't working as expected for generating the test report, so I decided to give the Nose plugin a try instead. I've gone ahead and installed Nose, as well a ...
I have a list of URLs to crawl. ['','', ''] Here is the code snippet: prev_domain = '' while urls: url = urls.pop() if base_url(url) == prev_domain: urls.append(url) continue else: cr ...
Consider an array with 5 elements: [4, 8, 1, 7, 3]. These elements need to be inserted into a max-priority queue. Starting with an empty priority queue, the first element inserted is 4. Next, when 8 is inserted, it becomes the new front element since it is ...
Presently, my Python 2.7 code is set up to handle <str> objects received over a socket connection. Throughout the codebase, we heavily rely on <str> objects for various operations and comparisons. Transitioning to Python 3 has revealed that soc ...
I currently have 3 different lists. >>> list1 = [1,2,3,4,5] >>> list2 = ['a','b','c','d'] >>> list3 = ['x','y','z'] Is there a Python function that can zip these lists together without leaving any elements out? I am looking for ...
https://i.stack.imgur.com/jOSgE.png Can someone assist me in resolving this issue with my code: "I'm getting an error message saying 'TypeError: 'list' object is not callable'" ...
Encountering challenges while trying to mock a method, as the mock function is actually overwriting it. In app/tests/test_file.py we currently have the following unit test: @mock.patch('app.method', return_value='foo') def test(self, ...
Create a program that extracts specific data subsets from the target.csv file related to stock market information. Load the contents of target.csv into a variable named 'target'. From the 'target' data, create a new dataframe called &ap ...
I attempted to scrape data from this webpage using the python-requests library. import requests from lxml import etree,html url = 'http://www.amazon.in/b/ref=sa_menu_mobile_elec_all?ie=UTF8&node=976419031' r = requests.get(url) tree = etree.HTML(r.te ...
I'm feeling quite perplexed as to why my script is not functioning properly. This particular script is designed to search for servers with port 19 open (CHARGEN). You need to input a list of IPs in the following format: 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4 5 ...
My goal is to impress my colleagues at work by creating a spreadsheet (.xlsx) using Python, even though I am still relatively new to the language. Can someone help me figure out how to format specific cells in my code using xlsxwriter? In the snippet bel ...
I have a collection of 1000 .txt files, each containing data that I need to process using the following code. My goal is to identify the largest value associated with ENSG in each file and remove any other occurrences of ENSG with values lower than the hig ...
Seeking a way to automatically download a file from a website, as the current manual process is cumbersome. Each time involves logging in, navigating to the file, and clicking download. If anyone has advice on automating this task using tools like MS DOS ...
Why is the loop not functioning correctly after opening the initial element based on the xpath? I keep receiving the following exception: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Una ...
When opening a workbook using openpyxl, I typically use the following code: wb = load_workbook(r'seven.xlsx', data_only=True) However, there are times when the name of the spreadsheet is not known in advance, requiring me to modify the hardcoding to acco ...
I am currently working on a project where I need to capture screenshots from multiple websites using a Python script. To accomplish this task, I am utilizing the following tools: - PhantomJS with Selenium - Python - Windows PC Initially, I trie ...
Not sure what to title this, but look at the example below: def example(): """ Good """ pass If I were to print example.__doc__, it would display " Good ". Is it possible to create additional 'variables' like this for other purposes? ...
Using Windows 10, x64, and Python 2.7.8. I'm trying to implement the code below: class TrabGraph: def __init__(self): self.radius = 1.0 def circle(self, rad=self.radius): print(rad) test = TrabGraph() test.circ ...
I have multiple sets of coordinates and I am looking to calculate the distance between each pair. Despite being able to compute the distances, I am struggling to display the corresponding coordinate pairs in my program. import itertools import math point1 ...
I tried implementing this code in Python 2.7 to generate a new number: def Algorithm(num): num = ((num**2) - 1)/4 return num However, it resulted in the following error message: TypeError: unsupported operand type(s) for ** or pow(): 'NoneT ...
I currently have two functional test classes set up for testing. class VehicleTest(unittest.TestCase): def setUp(self): self.browser = webdriver.Firefox() def test_math(self): self.assertEqual(1+1, 2) class VehicleTestCa ...
In my application, I am working on creating multiple widget orders using a list of dictionaries to create a list of widgets. I have implemented a mouse release event for clickable widgets, but I am facing issues in identifying the clicked widget index. C ...
I need assistance with importing the foo function from the mod.py file. In an attempt to resolve this, I have created a new empty file called init.py within the directory C/Users/me/Desktop/NF. I also tried using __init__.py My understanding was that hav ...
I have successfully created a Treestore in pygtk, but I am facing an issue with a checkbox that I do not want to appear. It can be seen in the image below. Computer1 [ ]-----This checkbox is unwanted C drive [ ] D drive [ ] E drive [ ] Here i ...
Why is the python autobahn example code using yield sleep(1) rather than simply sleep(1)? class Component(ApplicationSession): """ An application component that publishes an event every second. """ @inlineCallbacks def onJoin(self, d ...
Is there a way to efficiently remove all duplicate items in a list? For instance: a = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2] I'm looking to eliminate all occurrences of the value 1, resulting in: a = [2, 2, 2, 2, 2, 2] While I attempted using a.remo ...
Is it possible to navigate a table on a web page using mechanize if the table uses __doPostBack functions? Here is my code snippet: import mechanize br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U ...
I am struggling with dynamic substrings. My list can vary in size, containing anywhere from 20 to 1000 elements. I want to create a new list based on a variable number that includes elements starting from -10 up to that variable. For instance (using pseudo ...