> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Alan Gauld > Sent: Tuesday, May 15, 2007 1:44 AM > To: tutor@python.org > Subject: Re: [Tutor] File access by os.system > > > "lohith madireddy" <[EMAIL PROTECTED]> > > > I have files named 'x.pdb', 'y.pdb',..... in one directory. I am > > using python to read the files in that directory and do a system > > operation on each of the file using os.system. When I use this, it > > always gives an error saying 'could not read the file'. > > There are several likely problems. > The first is that the files might not have security pernissions set > for you to manipulate - can you do the system() command from > the OS prompt oK? > > Second, you are only passing the name of the file not the full > path so the system command can't find the file. > > Third you could be passing something other than a > file - eg another directory - to the command. > > > import sys,os,tempfile,shutil > > Pdbs = os.listdir(os.getcwd()) > > temp1=tempfile.TemporaryFile() > > for Pdb in Pdbs: > > You probably need to use stat here to check that the item > really is a file and that it has permissions. > > Alternatively use a try except clause and if an exception > is raised simply use continue to start the next loop iteration. > (possibly after printing an error message with the pdb name > in it so you can check why it failed later) > > > print(type(Pdb)) > > os.system("dsspcmbi -v Pdb temp1")
Should the os.system command be something like command = "dsspcmbi -v %s %s" %(Pdb, temp1) os.system(command) ? Mike _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor