IDLE - Python 3.1 running under XP SP3 - newline error

Discussion in 'Python' started by Badger_1610, Aug 31, 2010.

?

Is this the right forum for this question ?

Poll closed Sep 3, 2010.
  1. yes

    0 vote(s)
    0.0%
  2. no

    0 vote(s)
    0.0%
  1. Badger_1610

    Badger_1610

    Joined:
    Aug 31, 2010
    Messages:
    4
    Location:
    uk
    Help,

    when running a script, I keep getting an 'unexpected character after line continuation character' syntax error.

    I thiink this is a function of me not constructing a string correctly.

    Thanks.

    Badger

    #! /usr/bin/env python3.1...
    # this splits a file laterally

    fileout1 = open('c:/split_UPPPP1_.txt', 'w')
    fileout2 = open('c:/split_UPPPP2_.txt', 'w')

    fileIN = open('c:/UPPPP_.txt', 'r')

    line = fileIN.readline()

    while line:
    line1 = line[1:80] + '\n\r'
    line2 = line[80:160] + '\r'
    name = "hhH"
    record = str( 'r\", name, r\", ',', r\", line1, r\", ',', r\", line2, r\", \n')
    #fileout1.write(line1,line2)
    fileout2.write(record)
    line = fileIN.readline()

    fileIN.close()
    fileout1.close()
    fileout2.close()

    print ('done')
     
    Last edited: Aug 31, 2010
    Badger_1610, Aug 31, 2010
    #1
    1. Advertising

  2. Badger_1610

    Badger_1610

    Joined:
    Aug 31, 2010
    Messages:
    4
    Location:
    uk
    No worries I figured this out

    :D I figured it out ;

    solution is to format the string correctly ;
    #! /usr/bin/env python3.1...
    # this splits a file laterally

    fileout = open('c:/split_UPPPPxl_.csv', 'w')

    fileIN = open('c:/UPPPP_.txt', 'r')

    line = fileIN.readline()

    Name = " "
    num = 0
    import re

    while line:
    p = re.compile( '(\n|\r)')
    line = p.sub(' ', line)

    line1 = line[0:80]
    line2 = line[81:150]

    if line[2:6] == 'Name:':
    Name = line[1:20]

    record = '\"' + Name + '\"' + ',' + '\"' + line1 + '\"' + ',' + '\"' + line2 + '\"' + '\n'
    print (line2)
    #debug code- start
    num = num+1
    print(num)
    #debug code- end

    fileout.write(record)

    line = fileIN.readline()

    fileIN.close()
    fileout.close()

    print ('done')
     
    Badger_1610, Sep 1, 2010
    #2
    1. Advertising

  3. Badger_1610

    Badger_1610

    Joined:
    Aug 31, 2010
    Messages:
    4
    Location:
    uk
    Supplementary question....

    Hi,

    is it feasible to run Python under Windows XP Sp3 with a view to producing tools and utiliites for file and string manipulation ?

    i am looking for Unix type ;

    ls $dir > file
    for $1 in file do
    process file
    next

    type constructs...

    will i need Popen ?
    will it work under Win32 ?

    - should I stop now and use VB.. before I get to far into this and get dissapointed ?

    Any good advice appreciated .

    Thanks
    Will (aka Badger).
    :trytofly:
     
    Badger_1610, Sep 1, 2010
    #3
    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. Timo
    Replies:
    2
    Views:
    347
  2. Bo Peng
    Replies:
    1
    Views:
    482
    Bo Peng
    Jan 9, 2006
  3. j.edwards
    Replies:
    1
    Views:
    437
    Kenny M.
    Feb 13, 2006
  4. Rich Fowler
    Replies:
    2
    Views:
    1,336
    Rich Fowler
    Jan 22, 2010
  5. Roberto
    Replies:
    1
    Views:
    154
Loading...

Share This Page