[Tutor] Invisible Characters in Fortran/Python

Steven D'Aprano steve at pearwood.info
Sun Apr 10 01:34:34 CEST 2011


Tyler Glembo wrote:

> The problem I am having is with hidden/invisible character.  In the fortran
> code, there are line indents which are denoted with an invisible character
> ^I.  When I write with python, there is no ^I at the beginning of the line

^I is a tab character, which you can include in Python strings using \t


> and the fortran code no longer compiles.  I know how to put in the invisible
> line return character (\n), but how can I put in other invisible characters?

In byte strings:

\a	ASCII BEL
\b	ASCII BACKSPACE
\0	ASCII NULL
\n	linefeed
\v	vertical tab
\t	horizontal tab
\r	carriage return
\f	formfeed
\xDD	character with hexadecimal value DD
\XDD	same as above
\0DD	character with octal value DD

In Unicode strings, all of the above, plus:

\uDDDD	unicode character with hex value DDDD (four bytes)
\UDDDDDDDD
	unicode character with hex value DDDDDDDD (eight bytes)
\N{NAME}
	unicode character named NAME


Note that in Python 3, octal escape sequences no longer use \0 
(backslash-zero), but \o (backslash-o).

See http://docs.python.org/reference/lexical_analysis.html#strings for 
more details.




-- 
Steven


More information about the Tutor mailing list