[Tutor] Dumb question on emacs and python ...

hcohen2 hcohen2 at comcast.net
Sun Dec 28 17:18:39 EST 2003


Danny Yoo wrote:

>Hi Herschel,
>
>'getopt' is actually a little dated --- if you're trying to read option
>flags from the command line, you may want to use the 'optparse' module
>instead:
>
>    http://www.python.org/doc/lib/module-optparse.html
>  
>
Looked at this - appears interesting, certainly more pertinent that what 
I read about getopt!

>Hmmm... What kind of problem are you trying to solve?
>
>
>>From your previous question, it sounded like you were trying to write a
>'grep' string searching program.  If so, you may want to look at the
>regular expression library ('re'):
>
>    http://www.python.org/doc/lib/module-re.html
>
>A.M. Kuckling has written a small "howto" tutorial on regular expressions
>that you may find useful:
>
>    http://www.amk.ca/python/howto/regex/
>
The program is more word count than regular expression matching. Sorry I 
delayed in responding - my code for catching multiple instances of 
matching on a single line was flawed. Finally it came down to a single 
critical typo. Works and counts correctly!!

The need for the optget was a suggestion by the author to do the 
simplier program but using a case insensitive search. Suspect it will 
take more that simply using optparse to solve. Somewhat at a lose at how 
to begin. Attaching the code for the unalterted file.

Thanks both of these are now links for python documentation. One aside: 
why is this link so usless?

http://aspn.activestate.com/ASPN/docs/ActivePython/2.2/python/api/api.html

Must one become a member to have the search utitlity work? Failed at 
every search, even 'if', string.find(), find and others.

>
>The option parsing libraries are meant to be used when we want to define
>what kind of flags the user can set for us at the command line.  In our
>last email, I asked if you could do this at the command line:
>
>   ls -l some_filename
>
>If we were to write our own version of th 'ls' command, then an option
>parsing library would be responsible for looking at that '-l' section and
>tell us that the user's requesting a "long" output.
>
>So optparse/getopt is a command-line user interface thing.  Are you trying
>to parse command line arguments?  Tell us more about the problem you're
>trying to solve.
>
>  
>
I think you have it exactly correct, in this latest case I included the 
'*' as part of the file name and since it probably just denotes an 
executable file it was my mistake.

>>From reading the thread, my best guess at the moment was that your file
>had a literal asterisk at the end of the filename.  The file extension of
>your program, then, was perhaps literally something like:
>
>    .py*
>
>There's a section in your .emacs configuration that tells Emacs the file
>extensions it should use to detect Python source files.  That extension is
>'.py', not '.py*', so renaming the file to have no asterisk fixed the
>problem, and allowed Emacs to recognize the file as Python source code.
>
>(In any case, having an asterisk in there is probably a bad idea in Unix,
>because the shell treats unescaped asterisks as 'globbing' metacharacters
>that can stand for anything.)
>
>
>Anyway, I hope this helps!  Please feel free to ask more questions.
>
>
>  
>
Dan,

You are magnificent - and a great help. See comments above. Have any 
idea where the expected .emacs file might be hidden? There is a: 
.emacs-places that is NOT the expected emacs configuration file. 
Moreover, no sign of .xemacs that seems to tag along with the .emacs 
file I have on UNIX. The 'find' command did not help much either. There 
were some links, but did not appear useful.

Have to attend to some for 'pay' work that requires my attention.

I will be back, and for everyones sake I hope more informed about python 
behaviour and syntax under Linux.

Thanks again,
Herschel





More information about the Tutor mailing list