from random import choice
from string import ascii_uppercase
other_four_symbols = ''.join([choice(list(ascii_uppercase)+map(str, range(0,10))) for _ in range(4)])
>>> import string
>>> import random
>>>
>>> def gen_random_chars(nrandchars):
... alpha = string.ascii_uppercase + string.digits
... chars = ''.join(random.choice(alpha) for _ in range(nrandchars))
... return chars
...
>>> def gen_name(prefix):
... return prefix + gen_random_chars(4)
...
>>> for i in range(10):
... gen_name('abcd')
...
'abcdZ5VK'
'abcdT8V4'
'abcdJJCN'
'abcd92IQ'
'abcdW0QP'
'abcdNQLB'
'abcdQ1WS'
'abcdF8SG'
'abcd7WB1'
'abcdA3X3'
>>>
import os
import tempfile
temp = tempfile.NamedTemporaryFile(prefix="456")
try:
print 'temp:', temp
print 'temp.name:', temp.name
finally:
# Automatically cleans up the file
temp.close()
print 'Exists after close:', os.path.exists(temp.name)