6

how can I store in a variable, a string containing the EOF character? In other words, how can I represent EOF in a python string?

Thanks in advance

Throoze
  • 3,988
  • 8
  • 45
  • 67
  • 2
    EOF isn't a real thing. There's no such character in a file, only an absence of any more data. EOF is an API construct in some languages, but not Python. – Jonathon Reinhart Mar 07 '15 at 09:25
  • What do you mean by "end of file" character? Do you mean the null character `\0`, or maybe you mean the visible end-of-transmission Unicode character ␄ ([Unicode 2404](http://www.fileformat.info/info/unicode/char/2404/index.htm))? Voting to close as unclear what you're asking until you clarify what you're asking about. – jpmc26 Mar 07 '15 at 09:32
  • i want to force an exception. I want to programmatically pass EOF to raw_input, for testing purposes. I guess i didn't type the right words in google, since i didn't get an answer before coming here... that costed me a downvote :/ – Throoze Mar 07 '15 at 09:46
  • @Throoze In Python 3.4 using input() instead of the depreciated raw_input(), when prompted for input if you press Ctrl+Z on Microsoft Windows you will generate a EOFError exception. – DevPlayer Jun 24 '15 at 12:11

1 Answers1

3

There is no EOF character.... Usually it is just when you run out of data. If you really want one, you could just make some arbitrary string combination up, but you are probably better off just reading each line until the file is out of data.

John
  • 1,677
  • 4
  • 15
  • 26
  • 1
    i want to force an exception. I want to programmatically pass EOF to raw_input, for testing purposes. Thanks for your answer. – Throoze Mar 07 '15 at 09:43