capturing output of os.system() into a list?

Richard Jones richard at bizarsoftware.com.au
Thu Dec 13 02:30:36 CET 2001


On Thursday 13 December 2001 12:06 pm, Ron wrote:
> Is there a built-in method of doing this?  I can write a function
> to do it, but would rather use the standard method.

something like:

>>> import os
>>> os.popen('ls').readlines()
['addDataManager.dtml\n', 'addExtDataContainer.dtml\n', 
'addIdManager.dtml\n', 'CHANGES.txt\n', 'common.py\n', 'common.pyc\n', 
'dtml\n', 'help\n', '__init__.py\n', '__init__.pyc\n', 
'LowConflictConnection.py\n', 'LowConflictConnection.pyc\n', 
'manageDataManager.dtml\n', 'manageExtDataContainer.dtml\n', 
'manageIdManager.dtml\n', 'manageImpExpSessionData.dtml\n', 
'manageIntDataContainer.dtml\n', 'manageSessionData.dtml\n', 'othertests\n', 
'README.txt\n', 'SessionDataContainer.py\n', 'SessionDataContainer.pyc\n', 
'SessionDataManager.py\n', 'SessionDataManager.pyc\n', 'SessionData.py\n', 
'SessionData.pyc\n', 'SessionIdManager.py\n', 'SessionIdManager.pyc\n', 
'SessioningInterfaces.py\n', 'SessioningInterfaces.pyc\n', 
'SessioningPermissions.py\n', 'SessioningPermissions.pyc\n', 
'SessionStorage.py\n', 'SessionStorage.pyc\n', 'tests\n', 'TODO.txt\n', 
'VERSION.txt\n', 'www\n']
>>> 


     Richard




More information about the Python-list mailing list