
import random
import string
import os

fn = 'secret_key.txt'

def generate_key():
	return ''.join(random.choices(string.digits + string.ascii_letters + string.punctuation, k=50))

if __name__ == '__main__':

    # Ensure key file is placed in same directory as this script
    path = os.path.dirname(os.path.realpath(__file__))
    key_file = os.path.join(path, fn)

    with open(key_file, 'w') as key:
        key.write(generate_key())
        print('Generated SECRET_KEY to {f}'.format(f=key_file))

import random
import string
import os

fn = 'secret_key.txt'

def generate_key():
    options = string.digits + string.ascii_letters + string.punctuation
    key = ''.join([random.choice(options) for i in range(50)])
    return key

if __name__ == '__main__':

    # Ensure key file is placed in same directory as this script
    path = os.path.dirname(os.path.realpath(__file__))
    key_file = os.path.join(path, fn)

    with open(key_file, 'w') as kf:
        kf.write(generate_key())
        print('Generated SECRET_KEY to {f}'.format(f=key_file))
Use random.choice instead of random.choices
Use random.choice instead of random.choices

- Allows compatibility with python3.5

  
  import random
  import string
  import os
  
  fn = 'secret_key.txt'
  
  def generate_key():
- 	return ''.join(random.choices(string.digits + string.ascii_letters + string.punctuation, k=50))
+     options = string.digits + string.ascii_letters + string.punctuation
+     key = ''.join([random.choice(options) for i in range(50)])
+     return key
  
  if __name__ == '__main__':
  
      # Ensure key file is placed in same directory as this script
      path = os.path.dirname(os.path.realpath(__file__))
      key_file = os.path.join(path, fn)
  
-     with open(key_file, 'w') as key:
+     with open(key_file, 'w') as kf:
-         key.write(generate_key())
+         kf.write(generate_key())
          print('Generated SECRET_KEY to {f}'.format(f=key_file))
Use random.choice instead of random.choices
## Code Before:

import random
import string
import os

fn = 'secret_key.txt'

def generate_key():
	return ''.join(random.choices(string.digits + string.ascii_letters + string.punctuation, k=50))

if __name__ == '__main__':

    # Ensure key file is placed in same directory as this script
    path = os.path.dirname(os.path.realpath(__file__))
    key_file = os.path.join(path, fn)

    with open(key_file, 'w') as key:
        key.write(generate_key())
        print('Generated SECRET_KEY to {f}'.format(f=key_file))
## Instruction:
Use random.choice instead of random.choices
## Code After:

import random
import string
import os

fn = 'secret_key.txt'

def generate_key():
    options = string.digits + string.ascii_letters + string.punctuation
    key = ''.join([random.choice(options) for i in range(50)])
    return key

if __name__ == '__main__':

    # Ensure key file is placed in same directory as this script
    path = os.path.dirname(os.path.realpath(__file__))
    key_file = os.path.join(path, fn)

    with open(key_file, 'w') as kf:
        kf.write(generate_key())
        print('Generated SECRET_KEY to {f}'.format(f=key_file))