python with open invalid argument windows
<pre><code>import datetime
import os
import sys
import time

if "ZLOG_FILE" not in globals():
    global ZLOG_FILE
    script_dir = os.path.realpath(sys.argv[0]).replace(sys.argv[0], "")
    ZLOG_FILE = os.path.join(script_dir, "log", datetime.datetime.fromtimestamp(time.time()).strftime("%m-%d-%Y %H:%M:%S"))
    with open(ZLOG_FILE, "w"):
        pass

def log(level, msg):
    with open(ZLOG_FILE, "a") as f:

        # Fix colors
        if level == "INFO":
            msg = "ESC[37m[INFO] " + msg

        elif level == "WARN":
            msg = "ESC[33m[WARN] " + msg

        elif level == "ERROR":
            msg = "ESC[31m[ERROR] " + msg

        if level != "ERROR":
            print(msg)
        else:
            sys.stderr.write(msg)
        f.write(msg)
</code></pre>

<p>I made this simple logging library that on the first import makes a new file with current time and date in a log directory in the same location as the main script being run. I get the following error however:</p>

<pre><code>Traceback (most recent call last):                                              
  File "test.py", line 1, in &lt;module&gt;                                           
    import zlog                                                                 
  File "C:\Users\zane\Desktop\zlog.py", line 10, in &lt;module&gt;                    
    with open(ZLOG_FILE, "w"):                                                  
OSError: [Errno 22] Invalid argument: 'C:\\Users\\zane\\Desktop\\log\\09-12-2016
 20:02:26'                                                                      
</code></pre>

<p>What am I doing wrong?</p>

<p>EDIT: Got rid of the script name with the script_dir variable, and fixed the formatting on the if statements. Im still getting an error though</p>

<p>Windows cant use colons in file names, and I forgot to remove the main script from the path once I got the directory it was in</p>

python windows file