open file and create file .

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ephhabte
    New Member
    • Nov 2007
    • 1

    #1

    open file and create file .

    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 ():
  • luke14free
    New Member
    • Apr 2007
    • 79

    #2
    Try with:
    Code:
    tofind="some"
    f=open ("your_db.db","r)
    f=f.read().split('\n')  #change \n with your divisor...
    found=False
    for i in f:
        if i==tofind:
             found=i
             break
    if not found:
            ##no entry has been found, write your code here
    else:
            ##found an entry, write your code here

    Comment

    Working...