Re: [Tutor] converting all files in a directory with subprocess
"Tim Michelsen" <[EMAIL PROTECTED]> wrote in below is some code that works ### convert all t2t docs in a directory. for file in os.listdir(documentation_directory): if fnmatch.fnmatch(file, '*.t2t'): You might be able to do this more succinctly using the glob.glob() function... Just a thought, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] converting all files in a directory with subprocess
Hello, just for the records: below is some code that works ### convert all t2t docs in a directory. #!/usr/bin/env python # -*- coding: utf-8 -*- import os import subprocess import fnmatch documentation_directory = './doc/' for file in os.listdir(documentation_directory): if fnmatch.fnmatch(file, '*.t2t'): ### assemble file name filepath = documentation_directory+file ### run txt2tags #subprocess.call(['txt2tags', '--target=html', '--toc', documentation_directory+file]) subprocess.call(['txt2tags', '--target=html', '--toc', filepath]) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] converting all files in a directory with subprocess
Tim Michelsen wrote: Hello, I am working on a automatic documentation program to convert my txt2tags based documentations sources into HTMl files. I want to use txt2tags via command line. Here's my code: # #!/usr/bin/env python # -*- coding: utf-8 -*- import os import subprocess import fnmatch documentation_directory = './doc/' for file in os.listdir(documentation_directory): if fnmatch.fnmatch(file, '*.t2t'): print file subprocess.call('txt2tags', '-t html', '--toc') # END When I run the script it exits with the following error message: START OUTPUT python ./make_documentation.py index.t2t Traceback (most recent call last): File "./make_documentation.py", line 12, in subprocess.call('txt2tags', '-t html', '--toc') File "/usr/lib/python2.5/subprocess.py", line 444, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.5/subprocess.py", line 545, in __init__ raise TypeError("bufsize must be an integer") TypeError: bufsize must be an integer END OUTPUT Whenever you're running subprocess.call and you see this error, say to yourself: "Have I passed the command line as one parameter in a list; or have I passed it as a series of parameters?" Because I can't remember the number of times I've made that mistake myself. Basically, subprocess.call expects either a string or a list of strings as the first param, and then the second one is the bufsize, an integer. And then there are others (check the params to subprocess.Popen). You're passing a string -- your second param -- as the second parameter, and it's not an integer. So you get a TypeError. Simple, no? TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] converting all files in a directory with subprocess
Hello, I am working on a automatic documentation program to convert my txt2tags based documentations sources into HTMl files. I want to use txt2tags via command line. Here's my code: # #!/usr/bin/env python # -*- coding: utf-8 -*- import os import subprocess import fnmatch documentation_directory = './doc/' for file in os.listdir(documentation_directory): if fnmatch.fnmatch(file, '*.t2t'): print file subprocess.call('txt2tags', '-t html', '--toc') # END When I run the script it exits with the following error message: START OUTPUT python ./make_documentation.py index.t2t Traceback (most recent call last): File "./make_documentation.py", line 12, in subprocess.call('txt2tags', '-t html', '--toc') File "/usr/lib/python2.5/subprocess.py", line 444, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.5/subprocess.py", line 545, in __init__ raise TypeError("bufsize must be an integer") TypeError: bufsize must be an integer END OUTPUT I am stuck here. Why would the script not let txt2tags convert every file in my directory? like txt2tags -t html --toc THEFILE I already tried subprocess.call('txt2tags', '-t html', '--toc', file) But without success. I'd appreciate any pointer here. Thanks and regards, Timmie ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor