IDLE - Python 3.1 running under XP SP3 - newline error

Is this the right forum for this question ?

  • yes

    Votes: 0 0.0%
  • no

    Votes: 0 0.0%

  • Total voters
    0
  • Poll closed .
Joined
Aug 31, 2010
Messages
4
Reaction score
0
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:
Joined
Aug 31, 2010
Messages
4
Reaction score
0
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')
 
Joined
Aug 31, 2010
Messages
4
Reaction score
0
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:
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top