View Full Version : [SOLVED] Reading from file issues
JeremiahS
November 11th, 2010, 01:17 AM
Im writing an encryption program in Python 3.1.2. But when i use f.read() it uses escape characters(ex. \n) and that interferes with my encryption. Now if I could get it to read like this '''My name's Jeremiah''' instead of 'My name\'s Jeremiah'. It'd be perfect. Thx
cipherboy_loc
November 11th, 2010, 01:23 AM
Read: http://diveintopython3.org/regular-expressions.html
If I under stand it correctly:
s = 'This is a test: \' for the \' character...'
s.replace('\', '')
But I am not sure, not having worked in Python a lot.
Cipherboy
JeremiahS
November 11th, 2010, 01:41 AM
That looks right... I'll try it out. I didnt think of using regular expressions..
cipherboy_loc
November 11th, 2010, 03:20 AM
The only reason I thought about using them was because my native language is Perl. Not English, Perl. (It actually is English, but Perl is better ;) ). Perl has easy-to-use Regular Expressions. Unlike other languages where you have to import a library or some other things...
Cipherboy
trent.josephsen
November 11th, 2010, 04:09 AM
What do you mean? read() should yield the exact text read from the file. Escape sequences are only used for display purposes and not stored with the string.
Should you actually need to interpret escape sequences, look into the eval built-in. Removing '\' everywhere it occurs will bite you.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.