python run redis error when crontab shell
Question: i install redis-2.7.1 in my folder,and run my python code,it worked.

    
    
    COMMON_MODEL_DIR="/data/aa/redis-2.7.1"
    sys.path.append(COMMON_MODEL_DIR)
    import redis
    

And when i set up crontab ,

    
    
    */10 1-23 * * * (cd /data3/aa/; python step.py 2 >> /data3/aa/2.log 2>&1)
    

But it won't worked it will report

    
    
    Traceback (most recent call last):
      File "step.py", line 11, in ?
        import redis
      File "/data/aa/redis-2.7.1/redis/__init__.py", line 1, in ?
        from redis.client import Redis, StrictRedis
      File "/data/aa/redis-2.7.1/redis/client.py", line 157
        response = [nativestr(i) if i is not None else None for i in response]
                                  ^
    SyntaxError: invalid syntax
    

How will i fix it?


Answer: Obviously the user account under which your cron job is running is using
another (and quite old) Python version that doesn't support ternary
expressions. Find out which Python _you_ are using and pass the full path in
your crontab.

