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
#!/usr/bin/python
import os
import string
def searPatten(file, patten, isCaseSensitive):
openFile = open(file, 'r')
lines = openFile.readlines()
lineNum = 1
for text in lines :
words = text.split()
existed = 0
for word in words :
if isCaseSensitive == 'yes' :
if word.lower() == patten.lower():
existed = 1
break
else:
if word == patten :
existed = 1
break
if existed == 1:
print "line : " + str(lineNum) + " " + text
lineNum += 1
openFile.close()
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 1 1559
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... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: fabrice |
last post by:
Hello,
I've got trouble reading a text file (event viewer dump) by using the
getline() function...
After 200 - 300 lines that are read correctly, it suddenly stops
reading the rest of the...
|
by: Brandon McCombs |
last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm
trying here.
I have a C++ book by Deitel and Deitel that says I can use fstream
File("data.dat", ios::in | ios::out |...
|
by: Thomas Sourmail |
last post by:
Hi,
I hope I am missing something simple, but.. here is my problem:
I need my program to check the last column of a file, as in :
a b c d target ref
0 0 0 0 1 a
1 0 0 0 1.5 b
2 0 0 0 2 c
|
by: Abhishek |
last post by:
I have a problem transfering files using sockets from pocket pc(.net compact
c#) to desktop(not using .net just mfc and sockets 2 API). The socket
communication is not a issue and I am able to...
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: IkBenHet |
last post by:
Hello,
I use this script to upload image files to a folder on a IIS6 server:
******************* START UPLOAD.ASPX FILE **********************
<%@ Page Language="VB" Debug="true" %>
|
by: tvin |
last post by:
Hi all
I brought a string from a .txt file which was saved like utf-8.
In the .txt file i have this string "frédéric".My problem is that when i
read this file .txt,the bytes of é are like...
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
|
by: efrenba |
last post by:
Hi,
I came from delphi world and now I'm doing my first steps in C++. I'm
using C++builder because its ide is like delphi although I'm trying to
avoid the vcl.
I need to insert new features...
|
by: oktayarslan |
last post by:
Hi all;
I have a problem when inserting an element to a vector. All I want is
reading some data from a file and putting them into a vector. But the
program is crashing after pushing a data which...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |