By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

read file to a dictionary

P: n/a
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

May 23 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
May 23 '07 #2

P: n/a
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
May 24 '07 #3

P: n/a
On May 23, 6:46 pm, James Stroud <jstr...@mbi.ucla.eduwrote:

lol

May 24 '07 #4

P: n/a
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

May 24 '07 #5

P: n/a
En Thu, 24 May 2007 05:08:57 -0300, rohit <ro***********@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

May 24 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.