-1

I am trying, in Python 3, to append some data to a file, like this:

prueba = open(streamingResultFile, "a")

... when I previously declare:

streamingResultFile = time.asctime().replace('  ', ' ').replace(' ', '_') + '.txt'

... to get a file whose name will be the current time and date, in this format:

Tue_Apr_4_03:08:55_2017.txt

But I run it, and I get the message in the title complaining about the name of my file not being correct. But if I put something else, like "hello.txt" it works. Why can't I put that text as the name of my output file?

David F.
  • 31
  • 1
  • 1
  • 3
  • 2
    Please paste the error message. – Paul Back Apr 04 '17 at 01:15
  • What operating system are you running, and what kind of filesystem are you trying to write to? Please [edit] your question to include these details (as well as what Paul Back has asked for), and add tags for your OS and filesystem. – Kevin J. Chase Apr 04 '17 at 03:26

1 Answers1

3

Check the allowed filename characters for your operating system.

For example, characters like \, :, >, ... are not allowed in Windows filenames.

See What characters are forbidden in Windows and Linux directory names? for details on forbidden characters in Windows/Linux filenames.

Regarding your specific problem: Replacing the colons : with other characters should solve the error.

Community
  • 1
  • 1
Felix
  • 6,131
  • 4
  • 24
  • 44
  • Yes, I was so busy in the other parts of the program that I didn' t realize the semicolons were the problem. Thanks for pointing out – David F. Apr 04 '17 at 09:19