×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    Frankfurt, Germany
    Posts
    35

    problem ith reading & writing text-files

    hi...
    i'm having difficulties handling textfiles...
    there's a function to read each line of a textfile, and then append all lines to another textfile...

    that's the code:
    Code:
    file_var = open(base_dir+filename)
    data = file_var.readlines()
    file_var.close()
    db = file(other_dir+second_filename,'a')
    db.writelines(data)
    db.close()
    basically everything's working fine... the second file looks (in my windows notepad) exactly as the file from where the data is copied from.

    but:
    there's another function in the code, which takes values from the textfile and calculates something. and even though the content looks exactly the same, the function doesn't calculate the values from the second file.
    if i replace the second file with the original file, everything is working fine.

    any ideas why the second file doesn't work?

    btw:
    if i execute the same script on my pc, the second file is working. so i really don't know why it's not working on my cell-phone...

  2. #2
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Tempe, AZ
    Posts
    411

    Re: problem ith reading & writing text-files

    Hi szallah,
    it would have been better if you could show the code which wasn't working.

    P.S.:- While appending in a file, if file is already existing then copied things appear on second line of file. Else if file does exist then copied things appear on first line of this file.

    I never noticed that before.
    IDEAS is all they need but still they think only Genius can give them that.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    Frankfurt, Germany
    Posts
    35

    Re: problem ith reading & writing text-files

    EDIT:
    problem is solved now. i just mixed up two values. collumn 1 was written in collumn 2 and vice versa. no wonder the calculation didn't work...

    original post:
    before data is appended, the target always get's cleared. therefore, appending always starts in line 1.
    i got it working now, by writing the file in binary mode. so simply copying the file is now working.

    unfortunately, i want to create another file, which contains only some of the data of the already copied file. getting all the data in the thrid file is working fine. but again, the programm can't read from that file. and in this case, writing in binary-mode is not working.

    basically what want to do is (from the beginning):
    1. copy the content of multiple text-files on drive e to one file on drive c... working now with binary mode...
    2. copy lines matching a defined criteria from created file on drive c to another file.
    3. use data from created file for further calculations

    basically the filecontent looks like this:
    123,123,text1
    456,456,text2
    789,789,text3

    i've built some functions, which combined together:
    - build a list where every element contains a string of the corresponding line of the textfile
    - split the strings at the ',' to build another list which would look like this:
    Code:
    print list[0][0]+' '+list[0][1]+' '+list[0][2]
    -> 123 123 text1
    - the content of the list is then used for calculations etc., and the list-elements with certain results are merged together in another list, looking like the first one.
    - the content of this last list gets written in the new text-file.
    - the content of the new file should be used again for calculations. but this time it's nor working.

    unfortunately the code is a real mess right now, so i can't really just post a few functions...
    i guess i'll have to figure it out myself...
    Last edited by szallah; 2008-05-26 at 01:20.

Similar Threads

  1. Problem while Reading text file in Nokia3650
    By lalithunt in forum Mobile Java General
    Replies: 5
    Last Post: 2008-07-30, 17:19
  2. J2ME Reading and Writing Files.
    By underoath_nz in forum Mobile Java General
    Replies: 3
    Last Post: 2007-05-02, 10:57
  3. problem linking more than 23 C++ files
    By Corfa in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 4
    Last Post: 2005-09-16, 14:26
  4. Problem about Reading Chinese Text file?
    By goeast in forum Mobile Java General
    Replies: 0
    Last Post: 2002-09-18, 03:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×