Code: Alles auswählen
module_names = ["BaseHTTPServer","Bastion","CGIHTTPServer","ConfigParser",
"Cookie","DocXMLRPCServer","HTMLParser","MimeWriter","Queue",
#...
"timeit","toaiff","token","tokenize","tputil","trace","tty","urllib",
"urllib2","urlparse","user","uu","uuid","webbrowser","whichdb","xdrlib",
"xmllib","xmlrpclib","zipfile"
]
print(module_names)
def format(l, indent=1, width=80):
pos = 0
indent_txt = " "*(indent*4)
txt = indent_txt
for i, item in enumerate(l):
if len(txt)-pos > width:
txt += "\n%s" % indent_txt
pos=len(txt)
txt += '"%s",' % item
txt = txt.rstrip(",")
return txt
module_names_txt = "module_names = [\n%s\n]" % (
format(module_names)
)
print(module_names_txt)
Code: Alles auswählen
['BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'ConfigParser', 'Cookie', 'DocXMLRPCServer', 'HTMLParser', 'MimeWriter', 'Queue', 'timeit', 'toaiff', 'token', 'tokenize', 'tputil', 'trace', 'tty', 'urllib', 'urllib2', 'urlparse', 'user', 'uu', 'uuid', 'webbrowser', 'whichdb', 'xdrlib', 'xmllib', 'xmlrpclib', 'zipfile']
module_names = [
"BaseHTTPServer","Bastion","CGIHTTPServer","ConfigParser","Cookie","DocXMLRPCServer",
"HTMLParser","MimeWriter","Queue","timeit","toaiff","token","tokenize","tputil","trace",
"tty","urllib","urllib2","urlparse","user","uu","uuid","webbrowser","whichdb","xdrlib",
"xmllib","xmlrpclib","zipfile"
]
Aber meine Art das zu machen, erscheint mir umständlich... Verbesserungsvorschläge?
Normalerweise wäre das was für pprint. Aber da kommt das raus:
Code: Alles auswählen
>>> import pprint
>>> pprint.pprint(module_names)
['BaseHTTPServer',
'Bastion',
'CGIHTTPServer',
'ConfigParser',
'Cookie',
'DocXMLRPCServer',
'HTMLParser',
'MimeWriter',
'Queue',
'timeit',
'toaiff',
'token',
'tokenize',
'tputil',
'trace',
'tty',
'urllib',
'urllib2',
'urlparse',
'user',
'uu',
'uuid',
'webbrowser',
'whichdb',
'xdrlib',
'xmllib',
'xmlrpclib',
'zipfile']