Python Tutorial
if True: print "true" else: print "false"
#!/usr/bin/python import random import time import threading def display_message(count): random_sec = random.randint(1,4) print "thread %d is going to sleep for %d seconds" % (count, random_sec) time.sleep(random_sec) print "thread %d is resuming back" % count for count in range(5): thr = threading.Thread(target=display_message, args=(count,)) thr.start()Output:
$ python thread_test1.py thread 0 is going to sleep for 2 seconds thread 1 is going to sleep for 3 seconds thread 2 is going to sleep for 3 seconds thread 3 is going to sleep for 2 seconds thread 4 is going to sleep for 1 seconds thread 4 is resuming back thread 0 is resuming back thread 3 is resuming back thread 1 is resuming back thread 2 is resuming back
if True: print "line1" print "line2" else: print "line3" print "line4"
#!/usr/bin/python import random import time import threading def display_message(count): #indentation is not same in all lines of this method. random_sec = random.randint(1,4) print "thread %d is going to sleep for %d seconds" % (count, random_sec) time.sleep(random_sec) print "thread %d is resuming back" % count for count in range(5): thr = threading.Thread(target=display_message, args=(count,)) thr.start()Python interpreter error:
$ python thread_test1.py File "thread_test1.py", line 9 print "thread %d is going to sleep for %d seconds" % (count, random_sec) ^ IndentationError: unexpected indent
$ . venv/bin/activate [venv]$cd project-folder [venv]$tox -e pep8Output will be displayed like below,
pep8 develop-inst-nodeps: folder@4e65b339c7cf303269ceef34b1e550c0eafa9dae#egg=project-folder,typing==3.6.2,unicodecsv==0.14.1,unittest2==1.1.0,urllib3==1.22,warlock==1.2.0,websocket-client==0.44.0,wrapt==1.10.11 pep8 runtests: PYTHONHASHSEED='2009495220' pep8 runtests: commands[0] | flake8 pep8 runtests: commands[1] | bash -c tools/check_duplicate_jinja_blocks.sh _____________________________________________________________________________________________________ summary _____________________________________________________________________________________________________ pep8: commands succeeded congratulations :)
Python Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page