Grab the information swiftly

When running a presto command, I received the following result:

  a| b| c  
 --+--+------
 1 | 3| 6 
 2 | 4| 5 

I am aware of cursor.fetchall() to retrieve all data and cursor.fetchone() for a single row.

Now, I am interested in extracting data from a specific column such as column 'a' [1, 2].

Is there a method to achieve this?

Answer №1

Spotted an issue and implemented a solution

class data(object):
 def __init__(self, cursor, row):
    for (attribute, value) in zip((d[0] for d in cursor.description), row):
        setattr(self, attribute, value)

Then used a loop to retrieve the columns

for row in cursor.fetchall():
  info = data(cursor, row)
  print info.a

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strategies for Resolving StaleElementReferenceException While Iterating Through Elements in Selenium

My current project involves web scraping a soccer match website for information, using Python's Selenium library. In order to achieve this, I have stored the clickable HTML elements of all necessary matches in a list named "completed_matches." To iter ...

utilizing duplicate attributes in jinja2 template on Google App Engine

Recently I started working with GAE in Python and have encountered a little difficulty in accomplishing a certain task despite searching through the documentation and online resources: My goal is to access the first value in a repeated string property wit ...

Arrange the values in a dictionary in ascending order while arranging the keys in descending order

I am attempting to organize a dictionary in a specific order. I would like the dictionary to be arranged first in ascending order based on values, and if there are two or more keys with equal values, then I want them to be sorted by the keys in descending ...

Is the turtle graphics module no longer available in Python 3.6 on CentOS 7?

After scouring Google and various websites, I couldn't find any information related to my specific issue. Here's a quick summary: During the Christmas holidays, I decided to repurpose a machine by installing Centos 7 on it for development purpo ...

Locate the span element within the button using Python Selenium

I've spent a significant amount of time trying to understand why the driver refuses to click on this button. I am hopeful that someone can assist me in resolving this issue. see image here The button in question is labeled "Enter password". I am fee ...

The variable "display" in the global scope was not located

Currently working on a troubleshooting code, I've encountered an issue. When I select "other" and try to input data into the form, upon hitting continue, an error is displayed: Exception in Tkinter callback Traceback (most recent call last): File &quo ...

Troubleshooting the "PytestDeprecationWarning: pytest.config global is no longer supported" issue

I'm currently conducting tests on a website called . As part of this process, I am working on developing my own framework. Within the utils/create_driver section, I have written code that allows the browser to open based on user input. For example, i ...

Remove rows from a pandas dataframe based on a specified list

I need assistance with filtering a dataframe that contains a column of countries and other irrelevant variables. I have provided a sample dataset below: data = {"country": ["AA", "BB", "AA", "CC", "DD", "AA", "BB", "AA", "CC", "DD"], "other variable": ["f ...

extracting information with beautifulsoup

Currently, I am diving into BS4 to enhance my skills and expertise. My goal is to scrape various tables, lists, and other elements from well-known websites in order to grasp the syntax. However, I am encountering difficulties when it comes to formatting a ...

selenium in python may not always return every element with `find_elements_by_css_selector`

I have been using find_elements_by_css_path() in my Python script to retrieve all elements from a table. However, I am facing an issue where only a portion of the list is being returned. Why might this be happening and how can I ensure that all elements ar ...

top method for generating a dictionary from the provided string in Python

Can anyone help me figure out the most effective way to convert this string into a dictionary of values? 'idle (images=green:200, inpadoc=green:60, other=green:1000, retrieval=green:200, search=green:30)' Desired output: {'images':[& ...

Is it possible to locate a specific column name within an Excel spreadsheet using Pandas?

When using pandas to read an excel sheet and gather data from it in order to create a new excel document, there is a challenge. The current code only works if the user selects a sheet with the exact column name specified. It is necessary to verify that the ...

Transforming a for loop into a sliced operation on a NumPy array

I am working on a loop to calculate the elements of a 3D numpy array. The code looks like this: A = np.zeros((N - 2, N - 2, N - 2)) for i in range(1, N - 1): for j in range(1, N - 1): for k in range(1, N - 1): A[i - 1, j - 1, k - 1] ...

Error: the function's name has not been identified

Currently, I am in the process of developing a Python module using Python 2.7.6 with IPython 1.2.1 for running the program effectively. This particular module is focused on performing various mathematical function evaluations through power series computat ...

What steps can be taken to resolve the error message "AttributeError: 'WebElement' object does not have the attribute 'find_element_class_name'?"

try: main = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "main")) ) articles = main.find_elements_by_tag_name("article") for article in articles: header = article.find_element_c ...

A guide to resolving a problem in a basic TR Tkinter application

Greetings from a beginner programmer seeking assistance on stackoverflow! My current project involves creating a time reaction tester with a basic Tkinter GUI interface. Below is the code snippet: #!/usr/bin/env python import tkinter as tk import time i ...

Execute a shell script when a button is pressed and terminate it when pressed again

I’m having trouble figuring out how to terminate a script in Python once it has been executed. Any suggestions? "Party.py": #!/usr/bin/python import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.IN, pull_up_down=GPIO.PUD_UP) inp ...

Mastering HtmlUnitDriver with Selenium in Python: A Step-by-Step Guide

Currently, I am utilizing selenium-4.1.0 and my quest is to find the most lightweight webdriver for optimal speed. I came across HtmlUnitDriver, however, when working with python, it is a necessity to initiate a selenium server before attempting to use t ...

Encountering a coding issue in Arabic when utilizing the requests RESTful client

Below is a Python code snippet for a RESTful client: import requests; s= 'This is the message to be sent'; resp = requests.post('http://localhost:8080/MyApp/webresources/production/sendMessage', json={'message': s,} ) This c ...

Guide on automatically populating login data in an html5 form using a python script

I'm currently attempting to create a script that can automatically populate the values of an HTML5 form (specifically Name and Password fields). However, I am struggling with how to actually input these values. After searching various sites, I have y ...