Re: problem when reading file



On Thu, 31 Jul 2008 23:44:33 +1000, shrimpy wrote:

hi every one, i am new to python,
and coz i want to write a handy command for my linux machine, to find
a word in all the files which are under the current folder.

the code is half done, but when i run it, it complain, and i don`t know why???

can anyone help me have a look at it?


here is the message it complain
=======================================
file is : qt_plugins_3.3rc

Traceback (most recent call last):
File "./python_script/svn_grep.py", line 34, in <module>
searPatten(file,'are','no')
File "./python_script/svn_grep.py", line 8, in searPatten
openFile = open(file, 'r')
IOError: [Errno 2] No such file or directory: 'qt_plugins_3.3rc'


here are the code i wrote
---------------------------------------------------------------code begin
<snip>

for root, dirs, files in os.walk(os.getcwd()):
for file in files:
print "======================================="
print "file is : " + file + "\n"
searPatten(file,'are','no')

---------------------------------------------------------------code end

Try changing that last line to:

searPatten(os.path.join(root, file), 'are', 'no')


You'll have to import os.path too...
.



Relevant Pages

  • Re: delete harddrive backup file from harddrive
    ... Thanks, Twayne. ... Time to revert to your backups & do a restore to just before you did ... If, with any luck, it all went into a new folder and subfolders, ... BTW, if the backup included system folders, XP delete may complain ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Unable to see custom "internet link"
    ... stay away from porono and you wont have anything to hide...If a "fspro labs" ... product messed you up you should complain to them. ... Today I tried to use Hide Folder XP and my "customize favorite link" were ...
    (microsoft.public.windowsxp.general)
  • Re: CFileDialog dialog doesnt release program folder untill the app exits.
    ... but I am still going to defend any program right to deny ... deletion of a folder that it is using. ... complain about the file no longer existing and go back to Save ...
    (microsoft.public.vc.mfc)
  • Re: New user account can not login
    ... Then when the user next logs on a new profile will be created from an image ... the user does not | have access to the profile folder created for him at login. ... no one | has access privilege over that folder. ... The complain is domain | error. ...
    (microsoft.public.win2000.setup)