Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.

Learn More!


Download to Enter
| Contest Rules

Tutorials | Forums

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 9th, 2012, 03:24 AM
desktoppc desktoppc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 23 desktoppc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 25 m 55 sec
Reputation Power: 0
Fetching Columns from Table

hi ,

i am trying to fetch all column from a database table , but i am only able to fetch 1 column from table , here is a part of code which is fetching one column from table , i want to know ho can i display multiple columns
Code:
db += [(row ['fname'],str(row[ 'userid' ]), False),] 


suppose i want to fetch other column say lname , how can do that.
thanks

Reply With Quote
  #2  
Old February 9th, 2012, 10:17 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2011
Posts: 1,075 b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
provide more information

We need more information to answer this question.

What sort of object is row? It's __getattribute__ method, for instance, might take funky behind-the-scene action.

Likewise, what is your db object? It might have some sort of weird (custom) __add__ method.

What's the database format?

Post a small example.

Reply With Quote
  #3  
Old February 10th, 2012, 12:49 PM
desktoppc desktoppc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 23 desktoppc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 25 m 55 sec
Reputation Power: 0
thanks

Reply With Quote
  #4  
Old February 10th, 2012, 01:39 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2011
Posts: 1,075 b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
Progress.

I think that we should not have to install psycopg2 or read the psycopg2 documents to answer your question.

We know now that db is a standard python list object.

result_set is probably an iterable collection of somethings.

row is those somethings, one at a time.

I suggest next you insert a few statements into your program to help. Run this modified program and report the output:

Code:
import pprint################################################################

def values_from_db():
    pkg_resources.require( "psycopg2" )
    engine = create_engine('postgresql://postgres:@127.0.0.1:5432/users')
    connection = engine.connect()
    result_set = connection.execute( "select * from concatenation(5,10,20)" )
    print(type(result_set))##################################################
    pprint.pprint(result_set)################################################
    db = []
    for row in result_set:
        db += [(row ['start'],str(row[ 'userdatadetailid' ]), False),]

    connection.close()

    return db

def __main__():
    values_from_db()#########################################################

if __name__ == "__main__": __main__()

Reply With Quote
  #5  
Old February 10th, 2012, 02:03 PM
desktoppc desktoppc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 23 desktoppc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 25 m 55 sec
Reputation Power: 0
over

Reply With Quote
  #6  
Old February 10th, 2012, 02:35 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2011
Posts: 1,075 b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
What is the error message? I cannot test my program. I don't have access to that web address.

concatenation

summary: + operator joins string, tuple, list types. The mutable types have additional choices, and dictionaries use the update method.

Code:
>>> ################################################################
>>> a='a'  # strings
>>> b='b'
>>> a+b
'ab'
>>> ''.join((a,b,))
'ab'
>>> ################################################################
>>> a=(1,) # tuples
>>> b=('B',)
>>> a+b
(1, 'B')
>>> ################################################################
>>> a = list(range(3))  # lists
>>> b=[c for c in 'cat']
>>> a+b
[0, 1, 2, 'c', 'a', 't']
>>> a.extend(b)      # (modifies a)
>>> a
[0, 1, 2, 'c', 'a', 't']
>>> ################################################################
>>> a = {1:'one','one':2}  # dictionary
>>> b = {i:j for (i,j,) in enumerate('KIT')}
b = {i:j for (i,j,) in enumerate('KIT')}
>>> a
{1: 'one', 'one': 2}
>>> b
{0: 'K', 1: 'I', 2: 'T'}
>>> a.update(b)  # alters a
>>> a
{0: 'K', 1: 'I', 2: 'T', 'one': 2}
>>> 

Reply With Quote
  #7  
Old February 11th, 2012, 04:03 AM
desktoppc desktoppc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 23 desktoppc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 25 m 55 sec
Reputation Power: 0
thanks

Reply With Quote
  #8  
Old February 11th, 2012, 04:04 AM
desktoppc desktoppc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 23 desktoppc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 25 m 55 sec
Reputation Power: 0
thanks for helping

Reply With Quote
  #9  
Old February 11th, 2012, 04:06 AM
desktoppc desktoppc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 23 desktoppc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 25 m 55 sec
Reputation Power: 0
thank you so much

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Fetching Columns from Table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap