Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:41:01+00:00 2026-06-15T13:41:01+00:00

I have a function, table() , that reads a csv file and returns the

  • 0

I have a function, table(), that reads a csv file and returns the rows in individual lists. I want to map these lists to create a dictionary, with field headers being the keys and the underlying rows being the values. I cannot seem to do this however. When I try to call only the first element within the list of lists I created from the function ( l) in the command prompt, it returns all the lists up to ‘N’, the first letter in the word ‘None’, despite me breaking (return) if reader is None. When I do the same with a sys.stdout to a text file, it does the same, but the ‘N’ is replaced with <type 'list'>. Does anyone know what I’m doing wrong, and how I can go about creating a dictionary (or a list of columns, for that matter) from a CSV file given my table() function?

import csv

def table():
    with open('C:\\Python27\\test.csv', 'rb') as f:
        reader = csv.reader(f)
        for row in reader:
            print row
        if reader is None:
            return

l = list(str(table()))
keys = l[0]
print keys

Output text file:

['Field1', 'Field2', 'Field3', 'Field4']
['a', '1', 'I', 'access']
['b', '2', 'II', 'accessing\n']
['c', '3', 'III', 'accommodation']
['d', '4', 'IIII', 'basically']
<type 'list'>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:41:02+00:00Added an answer on June 15, 2026 at 1:41 pm

    You don’t actually return anything from the table function. Try it like this:

    def table():
        with open('C:\\Python27\\test.csv', 'rb') as f:
            lines = []
            reader = csv.reader(f)
            if reader:
                for row in reader:
                    lines.append(row)
                return lines
            else:
                return []
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that updates a MySQL table from a CSV file. The
We have a table value function that returns a list of people you may
I have a function that returns a table. The returned table contains (among other
I have a javascript function that toggles the display for rows in a table.
I have a function that converts a .csv file to a datatable. One of
I have a function that I need to create that reads in the value
Assume I have a function that reads data from a MySQL table, manipulates it
I have a function that allows users to edit a row in a table
I have a function that is to run through each row of a table,
I have an user defined table function in SQL Server that aggregate data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.