appending file

Discussion in 'Python' started by Kuo, Jun 29, 2007.

  1. Kuo

    Kuo Guest

    Hi,
    I'm trying to read a file (fileA) and append to another file(fileB).
    However, I always get "^M" at the end. Does anyone know why ? Here is my
    code ?

    os.system("../syn/pin_assign.pl customer_netlist.txt")
    shutil.copy("../fileB", "fileB")
    ucf = open("fileB", "a")
    pin = open("fileA", "r")
    ucf.write(pin.read())
    ucf.close;
    pin.close;
    sys.exit(0);

    Here is what I get.

    # FPGA CLOCK^M
    NET "SYSCLK_A" loc = N16 | TNM_NET = SYSCLK_A;^M
    NET "SYSCLK_AN" loc = M16 | TNM_NET = SYSCLK_A;^M


    Note that if I don't do "ucf.write(pin.read())", everything is ok.

    Thanks for any help.
     
    Kuo, Jun 29, 2007
    #1
    1. Advertising

  2. On Friday 29 June 2007, Kuo wrote:
    > Hi,
    > I'm trying to read a file (fileA) and append to another file(fileB).
    > However, I always get "^M" at the end. Does anyone know why ? Here is my
    > code ?


    I can't help you on your problem, but

    > ucf.close;
    > pin.close;


    these statements don't do anything. You'll want

    ucf.close()
    pin.close()

    > sys.exit(0);
    >
    > Here is what I get.
    >
    > # FPGA CLOCK^M
    > NET "SYSCLK_A" loc = N16 | TNM_NET = SYSCLK_A;^M
    > NET "SYSCLK_AN" loc = M16 | TNM_NET = SYSCLK_A;^M
    >
    >
    > Note that if I don't do "ucf.write(pin.read())", everything is ok.
    >
    > Thanks for any help.




    --
    Regards, Thomas Jollans
    GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu
    Hacker key <http://hackerkey.com/>:
    v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQBGhW7TJpinDvQhQ0sRAteYAJ4mL/r41f6YzLlOcjUNQHkZGzpbtgCfZ6+7
    wXmCdnqtL0UR5gE4FNUddWk=
    =Skye
    -----END PGP SIGNATURE-----
     
    Thomas Jollans, Jun 29, 2007
    #2
    1. Advertising

  3. Kuo

    Falcolas Guest

    On Jun 29, 1:04 pm, Kuo <> wrote:
    > # FPGA CLOCK^M
    > NET "SYSCLK_A" loc = N16 | TNM_NET = SYSCLK_A;^M
    > NET "SYSCLK_AN" loc = M16 | TNM_NET = SYSCLK_A;^M


    I see those bloody ^M's anytime I have to deal with a DOS file (since
    it's the carrage return \r character). Is 'pin' a DOS generated file?
    If you want to deal with a file which contains them, look for and get
    rid of the \r character.
     
    Falcolas, Jun 29, 2007
    #3
  4. Kuo a écrit :
    > Hi,
    > I'm trying to read a file (fileA) and append to another file(fileB).
    > However, I always get "^M" at the end. Does anyone know why ? Here is my
    > code ?
    >
    > os.system("../syn/pin_assign.pl customer_netlist.txt")
    > shutil.copy("../fileB", "fileB")
    > ucf = open("fileB", "a")
    > pin = open("fileA", "r")
    > ucf.write(pin.read())
    > ucf.close;
    > pin.close;
    > sys.exit(0);
    >
    > Here is what I get.
    >
    > # FPGA CLOCK^M
    > NET "SYSCLK_A" loc = N16 | TNM_NET = SYSCLK_A;^M
    > NET "SYSCLK_AN" loc = M16 | TNM_NET = SYSCLK_A;^M
    >


    Looks like a problem with newline format. Googling for "universal
    newline" may be a good start.
     
    Bruno Desthuilliers, Jun 30, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. scopp
    Replies:
    3
    Views:
    448
    Guest
    Jan 22, 2004
  2. Marcelo
    Replies:
    5
    Views:
    10,550
    Gordon Beaton
    Oct 25, 2005
  3. Red Ogden
    Replies:
    0
    Views:
    1,119
    Red Ogden
    Jul 16, 2003
  4. Thomas Heller

    appending data to an xml file

    Thomas Heller, Jan 11, 2005, in forum: Python
    Replies:
    1
    Views:
    369
    Peter Hansen
    Jan 12, 2005
  5. Greg McIntyre
    Replies:
    0
    Views:
    469
    Greg McIntyre
    Sep 12, 2005
Loading...

Share This Page