pythonprintingsyntax

Syntax error on python


I'm trying to do a simple function to delete some cache files. But I'm getting an syntax error, and I dont know why...

Code:

import xml.etree.ElementTree as ET
import os
import filecmp
import urllib
import shutil

def clean ():
    shutil.rmtree('/apks')
    os.remove('apk_cache')
    os.remove('info.xml')
    os.makedirs('apks')
    print "Cache - Clear"

    return menu ()

Error:

 File "C:\Users\Joao Carreira\ownCloud\Development\Python\Aptoide_Utils\utils.p
", line 14
   print "Cache - Clear"
                       ^

Thanks for the help! :)


Solution

  • If you use Python 3.x, you should write it as follow:

    print("Cache - Clear")
    

    print is a function in Python 3.x.


    >>> print "Cache - Clear"
      File "<stdin>", line 1
        print "Cache - Clear"
                            ^
    SyntaxError: invalid syntax
    >>> print("Cache - Clear")
    Cache - Clear
    >>> print
    <built-in function print>