read file to a dictionary

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rohit

    #1

    read file to a dictionary

    i want to implement a dictionary in python
    the query is :
    without explicitly doing the following steps
    1. reading from file to list
    2. processing list to dictionary
    is there a module or a built in function that helps me "read" a file
    directly into a dictionary
    or any module that implements the above 2 steps

    thanks
    rohit

  • Larry Bates

    #2
    Re: read file to a dictionary

    rohit wrote:
    i want to implement a dictionary in python
    the query is :
    without explicitly doing the following steps
    1. reading from file to list
    2. processing list to dictionary
    is there a module or a built in function that helps me "read" a file
    directly into a dictionary
    or any module that implements the above 2 steps
    >
    thanks
    rohit
    >
    csv module will read individual lines into a dictionary with keys
    being the field names. You can then do something with that. It
    is unclear what the keys, values are for your dictionary when read
    from a file. More info will be required to help more.

    -Larry

    Comment

    • James Stroud

      #3
      Re: read file to a dictionary

      rohit wrote:
      i want to implement a dictionary in python
      the query is :
      without explicitly doing the following steps
      1. reading from file to list
      2. processing list to dictionary
      is there a module or a built in function that helps me "read" a file
      directly into a dictionary
      or any module that implements the above 2 steps
      >
      thanks
      rohit
      >
      No one can actually figure out exactly what you want because you speak
      in partial thoughts and vagaries. However, my amazing mind-reading
      abilities are picking up the following paranormal conveyances:

      ConfigParser
      cPickle
      shelve

      I leave it to you to interpret them as I am just a messenger.

      James

      Comment

      • 7stud

        #4
        Re: read file to a dictionary

        On May 23, 6:46 pm, James Stroud <jstr...@mbi.uc la.eduwrote:

        lol

        Comment

        • rohit

          #5
          Re: read file to a dictionary

          ohh i think i forgot to include intricate details
          in dictionary i use the following:
          value: name of a file existing on disk
          Key : a unique number assigned to each file ,with no. assigned in
          increasing order to file appearing earlier in the "english dictionary"
          thanks
          rohit

          Comment

          • Gabriel Genellina

            #6
            Re: read file to a dictionary

            En Thu, 24 May 2007 05:08:57 -0300, rohit <rohitsethidce@ gmail.com>
            escribió:
            ohh i think i forgot to include intricate details
            in dictionary i use the following:
            value: name of a file existing on disk
            Key : a unique number assigned to each file ,with no. assigned in
            increasing order to file appearing earlier in the "english dictionary"
            So you don't have to read any file at all - just scan all file names.
            dict(enumerate( os.listdir(".") ))

            --
            Gabriel Genellina

            Comment

            Working...