473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

May 23 '07 #1
5 4513
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
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
On May 23, 6:46 pm, James Stroud <jstr...@mbi.ucla.eduwrote:

lol

May 24 '07 #4
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Yang Li Ke | last post by:
Hi guys! I have some datas that I must check everytime a visitor comes to my site What is better to do: 1- Read data from a file or 2- Read data from a mysql db Thank you
2
by: David Thomas | last post by:
Hi there, I am trying to store data in a text file and output it to the browser using PHP. All very easy - if I was using English! the problem is, I want to use Japanese and I'm finding it a tad...
5
by: Karthikesh Raju | last post by:
Hi All, i am wondering about the best way to read in a configuration file that goes like: ########### source_dir = '/home/karthik/Projects/python' data_dir =...
3
by: Jon Perez | last post by:
Is it safe to not put a lock on an object if it will always be read-only in other threads and will only ever be written to in just one and always the same one thread?
12
by: teoryn | last post by:
I've been spending today learning python and as an exercise I've ported a program I wrote in java that unscrambles a word. Before describing the problem, here's the code: *--beginning of file--*...
6
by: py | last post by:
I want to serialize an object in jython and then be able to read it in using python, and vice versa. Any suggestions on how to do this? pickle doesnt work, nor does using ObjectOutputStream...
18
by: gregpinero | last post by:
It seems like this would be easy but I'm drawing a blank. What I want to do is be able to open any file in binary mode, and read in one byte (8 bits) at a time and then count the number of 1 bits...
0
GTXY20
by: GTXY20 | last post by:
Hi all, I currently have a CSV file like so 1,a 1,b 1,c 2,a 2,b 2,b
11
beacon
by: beacon | last post by:
Hi everybody, I created a database that links one table from an ODBC data source. I saved my password and UID to the data source so neither myself nor anyone else would have to login each time...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.