read file to a dictionary

R

rohit

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
 
L

Larry Bates

rohit said:
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
 
J

James Stroud

rohit said:
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
 
R

rohit

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
 
G

Gabriel Genellina

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(".")))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top