473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Looking for Form Feeds

Hello-
I have a file generated by an HP-9000 running Unix containing form feeds
signified by ^M^L. I am trying to scan for the linefeed to signal
certain processing to be performed but can not get the regex to "see"
it. Suppose I read my input line into a variable named "input"

The following does not seem to work...
input = input_file.readline()
if re.match('\f', input): print 'Found a formfeed!'
else: print 'No linefeed!'

I also tried to create a ^M^L (typed in as <ctrl>Q M <ctrlQ> L) but that
gives me a syntax error when I try to run the program (re does not like
the control characters, I guess). Is it possible for me to pull out the
formfeeds in a straightforward manner?

Thanks!
--greg

--
Greg Lindstrom 501 975.4859
Computer Programmer gr************@novasyshealth.com
NovaSys Health
Little Rock, Arkansas

"We are the music makers, and we are the dreamers of dreams." W.W.

Confidentiality Notice
----------------------
This email and any attachments to it are privileged and confidential and are intended solely for use of the individual or entity to which they are addressed. If the reader of this message is not the intended recipient, any use, distribution, or copying of this communication, or disclosure of all or any part of its content to any other person, is strictly prohibited. If you have received this communication in error, please notify the sender by replying to this message and destroy this message and delete any copies held in your electronic files. Thank you.

Jul 18 '05 #1
2 4429
Greg Lindstrom wrote:
I have a file generated by an HP-9000 running Unix containing form feeds
signified by ^M^L. I am trying to scan for the linefeed to signal
certain processing to be performed but can not get the regex to "see"
it. Suppose I read my input line into a variable named "input"

The following does not seem to work...
input = input_file.readline()
if re.match('\f', input): print 'Found a formfeed!'
else: print 'No linefeed!'

I also tried to create a ^M^L (typed in as <ctrl>Q M <ctrlQ> L) but that
gives me a syntax error when I try to run the program (re does not like
the control characters, I guess). Is it possible for me to pull out the
formfeeds in a straightforward manner?


What's happening is that you're using .match, so you're only checking
for matches at the _start_ of the string, not anywhere within it.

It's easier than you think actually; you're just looking for substrings,
so searching with .find on strings is probably sufficient:

if line.find('\f') >= 0: ...

If you want to look for ^M^L, that'd be '\r\f':

if line.find('\r\f') >= 0: ...

If you want to keep a running count, you can use .count, which will
count the number of substrings in the line.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
I would have liked to have seen Montana.
-- Capt. Vasily Borodin
Jul 18 '05 #2
Greg Lindstrom wrote:
Hello-
I have a file generated by an HP-9000 running Unix containing form feeds signified by ^M^L. I am trying to scan for the linefeed to signal
certain processing to be performed but can not get the regex to "see" it. Suppose I read my input line into a variable named "input"

The following does not seem to work...
input = input_file.readline()
You are shadowing a builtin.
if re.match('\f', input): print 'Found a formfeed!'
else: print 'No linefeed!'
formfeed == not not linefeed????

I also tried to create a ^M^L (typed in as <ctrl>Q M <ctrlQ> L) but that gives me a syntax error when I try to run the program (re does not like the control characters, I guess). Is it possible for me to pull out the formfeeds in a straightforward manner?


For a start, resolve your confusion between formfeed and linefeed.

Formfeed makes your printer skip to the top of a new page (form),
without changing the column position. FF, '\f', ctrl-L, 0x0C.
Linefeed makes the printer skip to a new line, without changing the
column position. LF, '\n', ctrl-J, 0x0D.
There is also carriage return, which makes your typewriter return to
column 1, without moving to the next line. CR, '\r', ctrl-M, 0x0A.

Now you can probably guess why the writer of your report file is
emitting "\r\f". What we can't guess for you is where in your file
these "\r\f" occurrences are in relation to the newlines (i.e. '\n')
which Python is interpreting as line breaks. As others have pointed
out, (1) re.match works on the start of the string and (2) you probably
don't need to use re anyway. The solution may be as simple as: if
input_line[:2] == "\r\f":

BTW, have you checked that there are no other control characters
embedded in the file, e.g. ESC (introducing an escape sequence), SI/SO
(change character set), BEL * 100 (Hey, Fred, the printout's finished),
HT, VT, BS (yeah, probably lots of that, but I mean BackSpace)?
HTH,
John

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
2
by: Patrick Olurotimi Ige | last post by:
I wanto to incorporate some feeds like weather,news and humor(funny stuff) Any links where i can get related feeds on the WEB? Thx *** Sent via Developersdex http://www.developersdex.com ***
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
5
by: Shawn | last post by:
Hi, I want to understand and follow RSS feed because many web pages provide RSS feed for updated new data(e.g. http://www.weather.gov/rss/). But I never get how to use it. The link below suppose...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
3
by: mtrcct | last post by:
Hi, I am working with a form that is unbound and has text boxes the user can type in wildcard search critera which feeds a query. If I leave all the text boxes blank all query recoors are returned,...
2
by: sbitaxi | last post by:
I have a query that performs a simple sum, a running total essentially. I want to be able to use that in a calculation in a form but I can't seem to get it to display anything beyond #Name? ...
4
by: GS | last post by:
in Windows form, I have Datagridview and detailview with the same binding data manager. upon clicking the + in the navigator, the primary key field is blank as expected, but I need to enable it...
5
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all I've got a very complex form with loads of text boxes and buttons on it. It's causing me all sorts of problems when users press the enter key and cause a postback. I need to disable...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.