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

open file and create file .

P: 1
I am learning to python programming and i have some questions about python code .
i have tried to write some codes for reading a file from a different database and creating a file if the file doesn,t exsit on database. I have to look 3 databases before I create the file. Can anyone help me how to solve this problem ? I need a datastruktur to look up the file fro 3 different databases.what can i do?help.


For example.

I think I have to use this
dbm= open('dbm.fil','r'):
for line in dbms.xreadlines():
Nov 26 '07 #1
Share this Question
Share on Google+
1 Reply


luke14free
P: 79
Try with:
Expand|Select|Wrap|Line Numbers
  1. tofind="some"
  2. f=open ("your_db.db","r)
  3. f=f.read().split('\n')  #change \n with your divisor...
  4. found=False
  5. for i in f:
  6.     if i==tofind:
  7.          found=i
  8.          break
  9. if not found:
  10.         ##no entry has been found, write your code here
  11. else:
  12.         ##found an entry, write your code here
  13.  
Nov 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.