[Tutor] Getting started with Python
I can't. >>> import file.py is all very well if the interpreter knows where file.py is. I want to do this : >>> import /directory1/directory2/file.py Is this not possible ? -- View this message in context: http://www.nabble.com/Getting-started-with-Python-tp17273337p17273337.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] sys.path.append
I can do this : >>> sys.path.append ( 'C:\dump1' ) but not : >>> x = 'C:\dir1' >>> sys.path.append(x) or : but not : >>> x = ['C:\dir1'] >>> sys.path.append(x) Can I append variables to the path, rather than explicit strings ? -- View this message in context: http://www.nabble.com/sys.path.append-tp21054555p21054555.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Equivalent of grep in python
The following works : file1 = open (file0, "r") re.findall ( 'some_text', file1.readline() ) But this doesn't : re.findall ( 'some_text', file1.readlines() ) How do I use grep for a whole text file, not just a single string ? -- View this message in context: http://www.nabble.com/Equivalent-of-grep-in-python-tp2356p2356.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Equivalent of grep in python
file1.read() works. What do I do if I want line numbers ? I found this code : http://snippets.dzone.com/posts/show/1638 src = open('2.htm').read() pattern = '([^<]+)' # or anything else for m in re.finditer(pattern, src): start = m.start() lineno = src.count('\n', 0, start) + 1 offset = start - src.rfind('\n', 0, start) word = m.group(1) print "2.htm(%s,%s): %s" % (lineno, offset, word) Is there not a simpler way than this ? ppaarrkk wrote: > > The following works : > > file1 = open (file0, "r") > > re.findall ( 'some_text', file1.readline() ) > > > But this doesn't : > > re.findall ( 'some_text', file1.readlines() ) > > > > How do I use grep for a whole text file, not just a single string ? > -- View this message in context: http://www.nabble.com/Equivalent-of-grep-in-python-tp2356p21118578.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor