PEP 350: Codetags

2005-09-26 Thread Micah Elliott
Please read/comment/vote.  This circulated as a pre-PEP proposal
submitted to c.l.py on August 10, but has changed quite a bit since
then.  I'm reposting this since it is now "Open (under consideration)"
at <http://www.python.org/peps/pep-0350.html>.

Thanks!

-- 
Micah Elliott 


PEP: 350
Title: Codetags
Version: $Revision: 1.2 $
Last-Modified: $Date: 2005/09/26 19:56:53 $
Author: Micah Elliott 
Status: Draft
Type: Informational
Content-Type: text/x-rst
Created: 27-Jun-2005
Post-History: 10-Aug-2005, 26-Sep-2005


Abstract


This informational PEP aims to provide guidelines for consistent use
of *codetags*, which would enable the construction of standard
utilities to take advantage of the codetag information, as well as
making Python code more uniform across projects.  Codetags also
represent a very lightweight programming micro-paradigm and become
useful for project management, documentation, change tracking, and
project health monitoring.  This is submitted as a PEP because its
ideas are thought to be Pythonic, although the concepts are not unique
to Python programming.  Herein are the definition of codetags, the
philosophy behind them, a motivation for standardized conventions,
some examples, a specification, a toolset description, and possible
objections to the Codetag project/paradigm.

This PEP is also living as a wiki_ for people to add comments.


What Are Codetags?
==

Programmers widely use ad-hoc code comment markup conventions to serve
as reminders of sections of code that need closer inspection or
review.  Examples of markup include ``FIXME``, ``TODO``, ``XXX``,
``BUG``, but there many more in wide use in existing software.  Such
markup will henceforth be referred to as *codetags*.  These codetags
may show up in application code, unit tests, scripts, general
documentation, or wherever suitable.

Codetags have been under discussion and in use (hundreds of codetags
in the Python 2.4 sources) in many places (e.g., c2_) for many years.
See References_ for further historic and current information.


Philosophy
==

If you subscribe to most of these values, then codetags will likely be
useful for you.

1. As much information as possible should be contained **inside the
   source code** (application code or unit tests).  This along with
   use of codetags impedes duplication.  Most documentation can be
   generated from that source code; e.g., by using help2man, man2html,
   docutils, epydoc/pydoc, ctdoc, etc.

2. Information should be almost **never duplicated** -- it should be
   recorded in a single original format and all other locations should
   be automatically generated from the original, or simply be
   referenced.  This is famously known as the Single Point Of
   Truth (SPOT) or Don't Repeat Yourself (DRY) rule.

3. Documentation that gets into customers' hands should be
   **auto-generated** from single sources into all other output
   formats.  People want documentation in many forms.  It is thus
   important to have a documentation system that can generate all of
   these.

4. The **developers are the documentation team**.  They write the code
   and should know the code the best.  There should not be a
   dedicated, disjoint documentation team for any non-huge project.

5. **Plain text** (with non-invasive markup) is the best format for
   writing anything.  All other formats are to be generated from the
   plain text.

Codetag design was influenced by the following goals:

A. Comments should be short whenever possible.

B. Codetag fields should be optional and of minimal length.  Default
   values and custom fields can be set by individual code shops.

C. Codetags should be minimalistic.  The quicker it is to jot
   something down, the more likely it is to get jotted.

D. The most common use of codetags will only have zero to two fields
   specified, and these should be the easiest to type and read.


Motivation
==

* **Various productivity tools can be built around codetags.**

  See Tools_.

* **Encourages consistency.**

  Historically, a subset of these codetags has been used informally in
  the majority of source code in existence, whether in Python or in
  other languages.  Tags have been used in an inconsistent manner with
  different spellings, semantics, format, and placement.  For example,
  some programmers might include datestamps and/or user identifiers,
  limit to a single line or not, spell the codetag differently than
  others, etc.

* **Encourages adherence to SPOT/DRY principle.**

  E.g., generating a roadmap dynamically from codetags instead of
  keeping TODOs in sync with separate roadmap document.

* **Easy to remember.**

  All codetags must be concise, intuitive, and semantically
  non-overlapping with others.  The format must also be simple.

* **Use not required/imposed.**

  If you don't use codetags already, there's no obligation to start,
  and no risk of affecting code (but s

Re: PEP 350: Codetags

2005-09-28 Thread Micah Elliott
s to do a proper scan to
address/remove/alert them.  I won't argue that the interpreter should
adopt codetags, but it would at least benefit from lint recognition.

Phillip> You still need a tracking system.

Agreed, for most projects, and I think Trac is great.  But some might
want to use codetags as a way to track anything that is not a
full-blown bug.  And how many times have you seen small projects that
say, "We don't have a bug tracker yet.  Please just send bugs to
<[EMAIL PROTECTED]>"?

Josiah> Some even count exclamation points as an indicator of severity.

Michael> I prefer TODO SMELL STINK STENCH VOMIT to indicate TODO priority.

These seem useful.  But I personally prefer a single TODO with a
numeric priority, and I feel that the p: field is the simplest way to
get that (easier to remember numbers 0..3 than contaminations or
!-counts).  I think the example you gave could be done with a "#
FIXME: ..." and still be obvious, or even "# FIXME:
...", assuming you have mapped your bletcherosity level to
numbers.  This also assumes Terry's whitespace idea is used so the
fields could show up at the front.  Note that the PEP has separated
TODO from FIXME semantics.

Josiah> an unofficial spec is sufficient.  See koders.com and search
Josiah> for 'fixme' to see some common variants.

But that's the problem -- there are already a bunch of "unofficial"
specs, which don't serve much purpose as such.  It's a cool site.  I
spent some time browsing and I do see a lot of codetags in use (many
thousands in Python code alone; I'm not sure if the number represented
strings or files).  But I'll argue that this just reinforces the need
for an *official* spec/guideline, so that the tools can do something
with them.

Paul> Such a PEP should not be approved unless there's
Paul> already an implementation (e.g. PyChecker patch)

Phillip> implement some tools, use them for a while, and come back
Phillip> with more focused use cases

Phillip> It seems like a spec in search of an application.  The
Phillip> Motivation is sorely lacking 

My two main motivations are avoiding duplication (for documentation)
and organizing tasks.  I'm presently using it on a smallish project (5
KLOC) to generate manpage sections (fed to help2man) for BUGS,
GLOSSARY, and RFE.  These should arguably be dumped to a
BUGS/BUGFIX/ChangeLog file.  I haven't yet figured out how to make
Trac or SourceForge do a nice creation of such a file, though it's
essential IMO to provide one with a source package.  BUGS files are
also non-standardized, though I've seen some pretty nice (yet wildly
different) ones, and a tool could help here.

The other current use (for me) is as a grep replacement.  The tools
(just ctdoc right now) are limited (pre-alpha) but really help me
address the right tasks in the right order.  See
<http://tracos.org/codetag/wiki/ScreenShots> for a little comparison
to grepping.  I do think that the health-o-meter is also valuable (I
see that pylint already does a nice job of this).

I agree that proof of value is necessary.  Without a spec though it
will be hard to get people to know about a convention/toolset, so it's
a bit of a chicken-egg problem -- I can't have a pep until the tools are
in use, but the tools won't be used until programmers have
means/motivation to use them, a pep.

But now that I have your feedback/ideas I (and maybe the lint folks)
can do better job of expanding flexible tools that can prove this
paradigm useful (or useless).

I will continue development on the tools and encourage anyone
interested in using a standard set of codetags for documentation and
tracking purposes to give them a try (and provide more feedback!) as
they mature.

-- 
Micah Elliott
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python getopt functionality

2005-10-03 Thread Micah Elliott
On Oct 03, M.N.A.Smadi wrote:
> It is not clear to me if i can define `mandatory' options? That sounds
> strange but let say that the command `requires ' a value for -z or
> --zoo (either or should be find but one and only one of them MUST be
> present).  Can i do that with resorting to using if statements?

Optik (optparse) adheres to a "Tao of Option Parsing"
<http://optik.sourceforge.net/doc/1.5/tao.html>, which discusses
required option arguments.

-- 
Micah Elliott
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie regular expression ?

2005-10-04 Thread Micah Elliott
On Oct 04, len wrote:
> I have the following statement and it works fine;
> 
> list1 = glob.glob('*.dat')
> 
> however I now have an additional requirement the the string must begin
> with any form of "UNQ,Unq,unq,..."
> 
> as an example if I had the following four files in the directory:
> 
> unq123abc.dat
> xy4223.dat
> myfile.dat
> UNQxyc123489-24.dat
> 
> only unq123abc.dat and UNQxyc123489-24.dat would be selected

If glob is your preferred means, one option is:

   $ touch unq1.dat UnQ1.dat unQ1.dat UNQ1.dat foo.dat
   $ python -c '
   - import glob
   - print glob.glob("[uU][nN][qQ]*.dat")
   - '
   ['unq1.dat', 'UnQ1.dat', 'unQ1.dat', 'UNQ1.dat']
   $ man 3 fnmatch

-- 
Micah Elliott

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie regular expression ?

2005-10-04 Thread Micah Elliott
On Oct 04, Micah Elliott wrote:
>$ man 3 fnmatch

Actually "man 7 glob" would be better (assuming you've got *nix). Also
note that globs are not regular expressions.  "pydoc glob" is another
reference.

-- 
Micah Elliott

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mantain IDE colors and paste them in an HTML page

2005-10-04 Thread Micah Elliott
On Oct 04, billie wrote:
> I need to insert a Python source in an HTML page mantaining to 
> coloration gives by the IDE.

Do you care what IDE?

> I tried the export function of scite but it does not generate a proper
> HTML code that permit me to copy and paste it into another HTML page.
> Does anyone got any suggestion?

If you're just trying to get copy/paste-able-from-browser html that has
pretty colors, you might start up vim and use the default colors.  You
might have to say ":syntax enable".  Then just type ":TOhtml" and you'll
have a colorized version of your "IDE" display.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python

2005-10-05 Thread Micah Elliott
On Oct 05, Tuvas wrote:
> I am looking for a good tutorial on how to extend python with C
> code. I have an application built in C that I need to be able to use
> in Python. I have searched through various sources, starting of
> course with the Python site itself, and others, but I felt a bit
> lacking from the Python site, it seems it was only made for those
> who installed the source distribution, as for the other people...
> Anyways, thanks for the help!

I have no experience with this, but I see that Alex Martelli's "Python
In A Nutshell" has quite a few pages on the subject.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What documentation "standard" to use

2005-10-05 Thread Micah Elliott
On Oct 05, Kalle Anke wrote:
> I'm confused of how I should document my code, I've always liked being
> able to document my code directly in my source file and then to use
> some tool to extract the documentation to some other format.

> My problem with Python is that there are so many tools and formats ...
> I don't know which one I should use. I've tried to figure out if there
> is one that is the "de-facto standard" but ...

You don't need to do any marking up to use pydoc -- just put your
comments in the right place so that they become docstrings.  Just try
"pydoc pydoc" for more info.  It is distributed with Python, and
generates nicely colored html or opens your PAGER.

Or you could install epydoc <http://epydoc.sourceforge.net/>, which has
similar features (and more).  It supports "reStructuredText"
<http://docutils.sourceforge.net/rst.html> and it's own markup (epytext,
I think).  RST is the de-facto Python markup, AFAICT.  You'll need
something like "__docformat__ = 'restructuredtext'" in your modules.
RST is great for non-Python-source code, too.

Those are the two I am aware of.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile as static

2005-10-06 Thread Micah Elliott
On Oct 06, [EMAIL PROTECTED] wrote:
> Has anyone had any luck with this? Im trying to compile python 2.4.2 on
> Slackware 10.1 into one large executable. One which contains everything
> required to run python (as static). So python doesn't look for
> dynamically shared objects like libpthread.so.0.
> 
> I have tried ./configure --disable-dynamic
>  --enable-dynamic=NO
>  --enable-static
> 
> However the executable size is always the same :/ Please assist.

ldd is your friend for seeing the dependencies.  I see what you mean,
though.  I'm no autoconf expert, but AFAICT this was not an intended
feature.  My attempted grok of the Makefile also supports this theory.
And I don't see any of the options you specified as being valid.  Using
"--disable-shared" also doesn't affect "python", but does appear to make
libpython static, but I think it is regardless.  You can force the issue
with:

   $ ../configure ...
   $ make LDFLAGS=-static
   $ ls -l ./python
   -rwxr-xr-x  1 mdelliot support 218 Oct  6 08:06 ./python
   $ ldd ./python
   not a dynamic executable

But this gives some import warnings, and running has some problems...

Then I found these, indicating that it is easy ;-)

http://groups.google.com/group/comp.lang.python/browse_frm/thread/9407982ad24b62ec/5018f9abebaa285a?lnk=st&q=build+python+static&rnum=3&hl=en#5018f9abebaa285a

http://groups.google.com/group/comp.lang.python/browse_frm/thread/1ac371489ed4040b/076580464204cd79?lnk=st&q=build+python+static&rnum=5&hl=en#076580464204cd79

http://groups.google.com/group/comp.lang.python/browse_frm/thread/c532cc6469e29488/c6fcc1afbd7c41b0?lnk=st&q=build+python+static&rnum=17&hl=en#c6fcc1afbd7c41b0

It might be nice to have an autoconf option to make this more obvious
for guys like us.  Maybe this is just a rare need.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far (about editing tools)

2005-10-06 Thread Micah Elliott
On Oct 06, Kenneth McDonald wrote:
> The only _real_ problem is the eclipse learning curve.

The only real *advantage* of Eclipse (over other suggested tools) is its
highly hyped automatic refactoring.  Admittedly, I have not used it for
Python development, but I'm skeptical of the feasibility of
auto-refactoring in general, and therefore acknowledge *no* advantage.
Furthermore, Eclipse requires java and is thusly not provided on any
linux distro I'm familiar with, which I consider a huge roadblock.  And
as mentioned, it's bloated.

> But, given  that eclipse will be around for a _long_ time, and given
> how nicely  PyDev is coming along, I actually expect this to become
> the de facto  standard Python editor (though it will take a while).

Was this a troll??  If so, you got me to bite.  I haven't heard a
feature mentioned in this thread that can't be done at least as easily
with a capable text editor like vim or emacs.

I'm not trying to start another editor war here.  They tend to have a
steeper learning curve than IDEs, but in my experience are largely worth
the learning investment.  I just wanted to say that I really doubt the
possibility of Eclipse becoming anywhere near standard, given any amount
of time.

I would suspect that the majority of Python programmers write in one of
vim or emacs. Anyone got stats?

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do I get an import error on this?

2005-10-07 Thread Micah Elliott
On Oct 07, Steve wrote:
> I have a simple program:
> 
> 
> #! /home/fergs/python/bin/python
> import sys, os
> import cx_Oracle
> 
> 
> If I run it through the Python interpreter, this way:
> 
>  >> python test.py
> 
> it runs fine.
> 
> But if I try to run it as an executable script, this way:
> 
>  >> test.py
> 
> I get an import error that says it can't find cx_Oracle.

Are "which python" and "/home/fergs/python/bin/python" the same?  If
not, it appears that "which python" can see cx_Oracle, but the latter
cannot.  You could mess with PYTHONPATH or get /home/.../python into the
front of your PATH.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [regex] case-splitting strings in unicode

2005-10-08 Thread Micah Elliott
On Oct 09, John Perks and Sarah Mount wrote:
> I have to split some identifiers that are casedLikeThis into their
> component words. In this instance I can safely use [A-Z] to represent
> uppercase, but what pattern should I use if I wanted it to work more
> generally? I can envisage walking the string testing the
> unicodedata.category of each char, but is there a regex'y way to
> denote "uppercase"?

Not sure what your output should look like but something like this could
work:

>>> import re
>>> re.sub(r'([A-Z])', r' \1', 'theFirstTest theSecondTest')
'the First Test the Second Test'

This can be adapted for multiline, etc, but maybe '[A-Z]' is
sufficiently general.  The regex module does have an understanding of
unicode (but I don't, sorry); you could add (?u) make it unicode aware.
For programming language identifiers I wouldn't think that unicode
should be an issue.  Sorry I'm no help with unicode specifics.

Some useful links:

http://www.python.org/doc/2.4.2/lib/module-re.html
http://www.amk.ca/python/howto/regex/regex.html

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to check if file is in use?

2005-10-10 Thread Micah Elliott
On Oct 10, Stefan Siegel wrote:
> can anybody give me (a python newbie) give a hint how to check in
> python wether a file is in use by another program?

This was previously discussed on c.l.py.  In short, "you can't".  A
detailed answer is in this thread:

http://mail.python.org/pipermail/python-list/2003-May/165908.html

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Profiling Python using gprof

2005-10-11 Thread Micah Elliott
On Oct 11, Dave wrote:
> I would like to profile a Python program using gprof. I already
> rebuilt Python with CC="gcc -pg" ./configure. So, I should be able to
> use gprof. How do I do that? Should I first run Python and then gprof?
> What are the steps?

Note that it is much more common to use Python's profiling facilities to
"profile a Python program".  So if you really want to profile the
interpreter running your modules, then go ahead with gprof and follow
Jeff's advice; otherwise see
<http://www.python.org/doc/2.4.2/lib/profile.html>.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Well written open source Python apps

2005-10-13 Thread Micah Elliott
On Oct 13, Ben wrote:
> Could anyone suggest an open source project that has particularly well
> written Python?  I am especially looking for code that people would
> describe as "very Python-ic".  (Not trying to start any kind of war -
> just wanted some good examples of a well written Python app to read.)

The Python Package Index (PyPI, or cheeseshop)
<http://www.python.org/pypi> has pointers to a lot of packages that are
likely mostly pythonic.

I don't know if this is spelled out more precisely somewhere, but here
is my notion of a pythonic distribution:

* Has modules grouped into packages, all are cohesive, loosely
  coupled, and reasonable length

* Largely follows PEP <http://www.python.org/peps/> conventions

* Avoids reinventing any wheels by using as many Python-provided modules
  as possible

* Well documented for users (manpages or other) and developers
  (docstrings), yet self-documenting with minimal inline commenting

* Uses distutils for ease of distribution

* Contains standard informational files such as:
  BUGS.txt  COPYING.txt  FAQ.txt  HISTORY.txt  README.txt  THANKS.txt

* Contains standard directory structure such as:
  doc/  tools/ (or scripts/ or bin/)  packageX/  packageY/  test/

* Clean UI, easy to use, probably relying on optparse or getopt

* Has many unit tests that are trivial to run, and code is structured to
  facilitate building of tests

The first example of a pythonic package that comes to my mind is
docutils <http://docutils.sourceforge.net/>.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Well written open source Python apps

2005-10-13 Thread Micah Elliott
On Oct 13, Grig Gheorghiu wrote:
> This is really synchronicity in action! I started to think yesterday
> about putting together a project that measures the 'goodness' of Python
> packages in the PyPI Cheese Shop repository. I call it the "Cheesecake"
> project. I took the liberty of citing Micah's post in a blog entry that
> I just posted:
> <http://agiletesting.blogspot.com/2005/10/cheesecake-how-tasty-is-your-code.html>

Grig, I think you're onto something here; good idea.  I have no
experience with CPANTS, and I'm not sure how many of my ideals could be
checked programmatically.  But if your Cheesecake tool comes into
fruition, here are some things that I would personally find useful:

* A command-line version that I could easily run on my projects.

* An output that gives more than just an index/score; maybe a bunch of
  stats/indicators like pylint.  I.e., it would be say "pypkglint" or
  "pydistchecker", a higher level lint that operates on packages instead
  of just source files.

* Some checks that might be useful

   - Module and package naming conventions. (PEP-8 describes
 module-naming, but I see this broken more often than followed in
 practice.  And it is silent on package names, but the tutorial uses
 capitalized names.)  Some consistency here would be nice.

   - Existence of standard files.  ESR goes into detail on this in his
 "Art of UNIX Programming" book (pp 452).

   - Existence of standard directories (those I mentioned before).

   - Output of checkee "--help" should satisfy some standards.  I presently
 check my own tools by running "help2man" which forces me to setup
 optparse to follow a strict format.  I have some active RFEs on
 optik (optparse) to address this.

   - Use of distutils.  Maybe just a check for setup.py ?

   - Consistency of module length.  Not sure about this one, but you
 might lower the score if some package modules are 10 lines while
 others are 10KLOC.

   - Number of modules per package.  Maybe 4..20 is a good amount?

   - Extra points for existence of something like "api.html", which
 indicates that epydoc/pydoc generated API info.

   - Extra points for .svn/CVS/RCS directories indicating that version
 control is in place.  Maybe even glarking of version numbers where
 high numbers indicate that code is checked in frequently.

   - Use of ReST in documentation, or even in docstrings.

   - Count of unit tests.  Do module names map to test_ in
 test directory?  How many testXXX functions exist?

   - A summary calculation of pylint/pychecker scores for each module.

   - Point deduction (or fail!) if any .doc/.xls, etc. files included in
 distribution.

   - Extra points for use of modules that indicate extra usability was
 incorporated, such as: gettext (multi-language), optparse (clean
 UI), configparser (fine control), etc.

* A PEP describing the conventions (though some will argue that PEPs
  should be enforcable by the compiler, so maybe just a "Cheesecake
  Convention" document).

* And of course anything that CPANTS offers :-)

I'm sure people here have more ideas for quality indicators...

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return Text from popen

2005-10-15 Thread Micah Elliott
On Oct 15, Casey Bralla wrote:
> How do I return text from a standard Linux command?
> 
> For example:  I want to read the stdout results of a typical linux
> command (such as "df") into a Python variable.

>>> from os import popen
>>> p = popen("df")
>>> p

>>> df_out = p.read()
>>> p.close()
>>> p

>>> print df_out

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Run process with timeout

2005-10-17 Thread Micah Elliott
On Oct 17, Alex Martelli wrote:
> Natan <[EMAIL PROTECTED]> wrote:
> > I have a python script under linux where I poll many hundreds of
> > interfaces with mrtg every 5 minutes. Today I create some threads and
> > use os.system(command) to run the process, but some of them just hang.
> > I would like to terminate the process after 15 seconds if it doesn't
> > finish, but os.system() doesn't have any timeout parameter.
> 
> Use the subprocess module.  With a subprocess.Popen object, you can
> ... kill it (use its .pid attribute).

The problem I've run into with this approach is the inability to kill
the pid's children.  Most often I'm not so fortunate to be able to
depend on the process to not be doing its own forking.  So here's a
simplified use case:

   $ cat sleep10.sh
   #! /bin/bash
   sleep 10  # does not get killed
   $
   $ cat to3.py
   #! /usr/bin/env python

   from subprocess import Popen
   from time import sleep
   from os import kill
   from signal import SIGTERM

   p = Popen(['./sleep10.sh'])
   sleep(3)
   kill(p.pid, SIGTERM) # Oops, won't kill p.pid's children.
   ##kill(-p.pid, SIGTERM)  # Won't work since not group leader,
#  and I'd rather avoid fork/dup/exec.
   $
   $ ./to3.py
   $ # to3.py finished but sleep 10 still running 

If you try this you will see that sleep10.sh gets killed, but its 
"sleep 10" subprocess does not, and runs for an additional 7 seconds.

I presently rely on an ugly script to do this properly.  It uses low
level calls such as pipe, close, dup2, fork, exec, setpgrp, etc.  I
won't post that here for brevity's sake (unless requested).  For this
case it would fork/exec sleep10.sh, make it a group leader, and the
parent would kill its group.

Is there any way to enable Python's subprocess module to do (implicit?)
group setup to ease killing of all children?  If not, is it a reasonable
RFE?

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vim IS a capable IDE [was Re: Vim capable IDE?]

2005-10-19 Thread Micah Elliott
On Oct 19, Chris Lasher wrote:
> Where do you guys go to learn all the capabilities of Vim? Just
> browsing through vim.org?

Just type:
   :h
to see extensive info from the "User Manual", "Reference Manual", and
any plugins.

The near-comprehensive doc list:
   http://vimdoc.sourceforge.net/
I don't see the "Reference Manual" there.

The User Manual in PDF (which I printed really small on 14 pages and
now carry in my backpack):
   http://www.eandem.co.uk/mrw/vim/usr_doc/index.html

And the Vim Book (which I have only scanned):
   http://www.truth.sk/vim/vimbook-OPL.pdf

-- 
_  _ ___
|\/|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
"  " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie]Is there a module for print object in a readable format?

2005-10-19 Thread Micah Elliott
On Oct 20, Steven D'Aprano wrote:
> That's not what I get. What are you using?
> 
> py> pprint.pprint([1,2,3,4,[0,1,2], 5], width=1, indent=4)
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: pprint() got an unexpected keyword argument 'width'

I find it useful to have all relevant python versions (as listed on
http://www.python.org/download/) installed on my primary test
machines.  It really helps me with portability testing:

   $ ls /usr/local/bin/python*
   /usr/local/bin/python
   /usr/local/bin/python2.0
   /usr/local/bin/python2.1
   /usr/local/bin/python2.2
   /usr/local/bin/python2.3
   /usr/local/bin/python2.4

Then I see that v2.3 didn't have 'width':

   $ python2.3 -c 'import pprint; pprint.pprint([1,2,3,4,[0,1,2], 5],
   width=1, indent=4)'
   Traceback (most recent call last):
 File "", line 1, in ?
 TypeError: pprint() got an unexpected keyword argument 'width'

But v2.4 does:

   $ python2.4 -c 'import pprint; pprint.pprint([1,2,3,4,[0,1,2], 5],
   width=1, indent=4)'
   [   1,
   2,
   3,
   4,
   [   0,
   1,
   2],
   5]

-- 
_  _ ___
|\/|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
"  " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parser question

2005-10-19 Thread Micah Elliott
On Oct 19, Daniel Sch�le wrote:
> I have one format with this structure
> 
> A {
> x=1
> y=3
> B {
> z  = "something here"
> }
> }
> 
> C {
> }
> 
> A {
> x=0
> y=0
> B {
> z  = "other"
> }
> }
> 
> are there parsers for this kind of structure?
> specially I am interested in all A blocks
> 
> just now, I am trying to solve it with re,

You might be able to tackle this easily enough with REs if your
structures don't nest arbitrarily.  It's hard to tell if this deserves
a formal grammar based on the example.  If it does, you could try PLY
 (which I've had a pleasant experience
with in the past) or any of the other parsers listed on the PLY site's
"Other Python Parsing Tools".

-- 
_  _ ___
|\/|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
"  " """
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: question about timestamp and MySQLdb

2005-10-19 Thread Micah Elliott
On Oct 19, Sean Berry wrote:
> I am using MySQLdb to connect to a database and retrieve a timestamp
> from a table.  The problem is I want the timestamp as a long,
> unformatted and all.
> 
> In the table I have a timestamp like this
> 20051019111617
> 
> But, when I retrieve the value and print it I get
>  2005-10-19 11:16:17
> 
> I want the numeric version, not the converted date.  Any suggestions? 

Without giving any thought to MySQLdb or datetime, the simplest thing
that comes to mind is

>>> import re
>>> re.sub('( |-|:)', '', ' 2005-10-19 11:16:17')
'20051019111617'

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to organize Python files in a (relatively) big project

2005-10-19 Thread Micah Elliott
On Oct 19, Jarek Zgoda wrote:
> How to install this structure eg. on Linux? What layout do you
> recommend? It's tempting to use /opt hierarchy for installation
> target (as it gives relatively much freedom within application
> directory), but many administrators are reluctant to use this
> hierarchy and prefer more standarized targets, such as /usr or
> /usr/local.

Read about (and use) the Python-provided distutils, and let it do the
work for you.  In particular,

discusses installation location.  The file name is a misnomer; it's
equally applicable to linux.

It allows users to easily specify the installation prefix.  The
default should be the value of "sys.prefix".

Note that your modules/packages will be installed within your python
installation under its site-packages/ directory.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to organize Python files in a (relatively) big project

2005-10-19 Thread Micah Elliott
On Oct 19, Jarek Zgoda wrote:
> Micah Elliott napisał(a):
> 
> >>How to install this structure eg. on Linux? What layout do you
> >>recommend? It's tempting to use /opt hierarchy for installation
> >>target (as it gives relatively much freedom within application
> >>directory), but many administrators are reluctant to use this
> >>hierarchy and prefer more standarized targets, such as /usr or
> >>/usr/local.
> > 
> > Read about (and use) the Python-provided distutils, and let it do the
> > work for you.  In particular,
> > <http://www.python.org/doc/2.4.2/inst/alt-install-windows.html>
> > discusses installation location.  The file name is a misnomer; it's
> > equally applicable to linux.
> 
> I think that installing *application* (not misc. library) modules in
> site-packages is at least stupid idea...

They're not.

> ...as it makes a special filesystem inside other, much more
> standarized filesystem (Windows, FHS, etc.). Why not to do this
> usual way: libraries to $prefix/lib/$appname-$version, binary to
> $prefix/bin, shared files to $prefix/share/$appname, etc -- and
> appropriately on Windows.

It is done more the FHS way than you might realize.  Assuming
sys.prefix is '/usr', then using distutils my manpages go to
'/usr/share/man', my tools/scripts that I want my users to access go
to '/usr/bin' (and I could even put my config files in '/usr/../etc'
or maybe just '/etc' but I haven't had to do that).  So only your
modules end up in '/usr/lib/python', but that seems appropriate
anyway.  It is the simplest way for '/usr/bin/python' to locate your
modules, since it already knows to look in '/usr/lib/python' for
modules.  If you put your modules in say /usr/lib/fooapp then how
would python know where to look for your modules?  You would have
users messing with something called PYTHONPATH or you would end up
with boilerplate or custom install logic to set sys.path according to
special user needs.  But why go through the trouble?  Just let
distutils do the work for you.

I don't want my users to know anything about my *modules* that end up
in /usr/lib/python or that such a thing as PYTHONPATH even exists.

If you prefer the /opt route (or /tmp or $HOME or whatever), then
distutils can create your filesystem structure beneath that
accordingly.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: best way to replace first word in string?

2005-10-20 Thread Micah Elliott
On Oct 20, [EMAIL PROTECTED] wrote:
> I am looking for the best and efficient way to replace the first word
> in a str, like this:
> "aa to become" -> "/aa/ to become"
> I know I can use spilt and than join them
> but I can also use regular expressions
> and I sure there is a lot ways, but I need realy efficient one

Of course there are many ways to skin this cat; here are some trials.
The timeit module is useful for comparison (and I think I'm using it
correctly :-).  I thought that string concatenation was rather
expensive, so its being faster than %-formatting surprised me a bit:

$ python -mtimeit '
  res = "/%s/ %s"% tuple("a b c".split(" ", 1))'
10 loops, best of 3: 3.87 usec per loop

$ python -mtimeit '
  b,e = "a b c".split(" ", 1); res = "/"+b+"/ "+e'
10 loops, best of 3: 2.78 usec per loop

$ python -mtimeit '
  "/"+"a b c".replace(" ", "/ ", 1)'
10 loops, best of 3: 2.32 usec per loop

$ python -mtimeit '
  "/%s" % ("a b c".replace(" ", "/ ", 1))'
10 loops, best of 3: 2.83 usec per loop

$ python -mtimeit '
  "a b c".replace("", "/", 1).replace(" ", "/ ", 1)'
10 loops, best of 3: 3.51 usec per loop

There are possibly better ways to do this with strings.

And the regex is comparatively slow, though I'm not confident this one
is optimally written:

$ python -mtimeit -s'import re' '
  re.sub(r"^(\w*)", r"/\1/", "a b c")'
1 loops, best of 3: 44.1 usec per loop

You'll probably want to experiment with longer strings if a test like
"a b c" is not representative of your typical input.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute C code through Python

2005-10-21 Thread Micah Elliott
On Oct 21, Grant Edwards wrote:
> I'm guessing you're using Windows based on the question.

+1 QOTW.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions between these two books

2005-10-26 Thread Micah Elliott
On Oct 26, John Salerno wrote:
> Hi all. I'm fairly new to programming and I thought I'd like to try 
> Python. I'm trying to decide between these two books:
> 
> Learning Python (O'Reilly)
> Beginning Python: From Novice to Professional (APress)

Consider first reading the tutorial.  If you prefer to read from paper
there is a PDF version
.

There is also the "Python in a Nutshell" book which only covers Python
2.2 but has a very concise language intro, and will become an
invaluable reference.  I wish I had started with this book; then I
wouldn't have needed to buy some of the others.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distutils - distributing non-python data files

2005-10-26 Thread Micah Elliott
On Oct 25, RickMuller wrote:
> I really appreciate the ease that the distutils make distributing
> Python modules. However, I have a question about using them to
> distribute non-Python (i.e. text) data files that support Python
> modules.

It's not clear from your questions whether this is user-configuration
data for your program, or just data files that your program generates.

If the latter, you might look into pickle'ing.  Often the best place
to look for examples is in your Python distribution itself.  My
cursory scan didn't show much this time, but the Ft module might be
worthy of note.  It installs a Share directory
(.../site-packages/Ft/Share) that contains some XML files.

> Currently when I have data of this type, I parse it into
> python objects and make a python module from it.

Sometimes this is a reasonable approach, and you might get away with
just storing it as Python code with no conversion.  Mailman (and one
of my projects) uses config files that are actually treated as Python
modules.  For configuration data Python is such a readable language
that even users unfamiliar with it can often safely edit a config
file.

> In other words,
> given a data file like
> 
> % cat grocery_list.txt
> eggs
> spam
> cheese
> 
> I would make a data structure like
> grocery_list = ['eggs', 'spam', 'cheese']
> which can be easily imported from a python file, and which the
> distutils installation programs make it easy for me to find on the
> Python path.
> 
> Of course, the data I'm using is much more complex than this, but
> you get the idea.

Then you might consider going to an XML format, and let
SAX/DOM/whatever do the work for you.  Or maybe use the Configuration
Parser ,
depending on your needs.

> I'm starting to feel like this is a Bad Thing, because if the data
> file is distributed as a plain text file (e.g. data values in
> columns), I'm putting a barrier to updating the data if I have to
> parse a new file into Python.

Text, binary, columnar, XML... whatever the format, if it changes you
will always be susceptible to changing your parser.

> But I don't know whether there is a better way to include a file
> like 'grocery_list.txt' in my python distutils-distributed module so
> that I can get it from my other python modules?

If it's configuration data not stored within your distribution, you
could have some places to auto-check, e.g.: $HOME/somerc.py,
/etc.  And/or you could support an environment variable.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: syntax question - if 1:print 'a';else:print 'b'

2005-10-27 Thread Micah Elliott
On Oct 27, Gregory Piñero wrote:
> 
>my goal really was to do:
>try:something(1);except:pass
>try:something(2);except:pass
>try:something(3);except:pass
>...
>for about 20 lines.

If you just want to ignore the exceptions while saving space/typing,
you could equivalently do::

try:
something(1)
something(2)
# ...
except:
pass

or::

try:
something(1); something(2); # ...
except:
pass

or::

try:
for i in range(yourlimit):
something(i)
except:
pass

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rename files with numbers

2005-10-31 Thread Micah Elliott
On Oct 31, [EMAIL PROTECTED] wrote:
> I have one folder containing mp3 files, the folder is:
> C:\My Shared Folder\Rubber Soul
> 
> And the files are:
> 03 you won't see me.mp3
> .
> 
> I'm trying to rename files to:
> The Beatles - You Won't See Me.mp3
> .

My first suggestion is that you make better changes while you're
taking the effort to rename.  I.e., don't use spaces or apostrophes
(or other shell-unfriendly characters) in file names (though some
might disagree with me on this religious issue).  So for your case a
more parse-able/useful translation might be:

The_Beatles_-_You_Wont_See_Me.mp3

> So I need to change the file number to "The Beatles -"

You'll probably want to use "re" for this.  In a loop over
your glob'd files, something like:

re.sub(r'^\d\d\s', r'The Beatles - ', ...)

> and Capitalize the name.

If you avoid the apostrophe, then 'you wont see me'.title() will do
the Right Thing.

> I was trying to create a function and using glob and rename, but i
> had no sucsses... Could somebody help me please,

You should post the solution you've attempted to write if you want help
fixing it.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rename files with numbers

2005-10-31 Thread Micah Elliott
On Oct 31, [EMAIL PROTECTED] wrote:
> ...
> obs: the file names came this way(with spaces or apostrophes) from
> the cd i imported.

So remove them first.  Here's a possible solution::

#! /usr/bin/env python

import glob, os.path

uglies = glob.glob("*.mp3")
print 'uglies:', uglies
pretties = []

for ugly in uglies:
song, ext = os.path.splitext(ugly)
song = song.replace("'", "")
song = song.replace(" ", "_")
song = song.title()
song = "The_Beatles_-_" + song[3:]
song_ext = song + ext
pretties.append(song_ext)

print 'pretties:', pretties 

# rename uglies to pretties...

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rename files with numbers

2005-10-31 Thread Micah Elliott
On Oct 31, [EMAIL PROTECTED] wrote:
> but my focus is to learn how to acess a folder and rename all files in
> this folder.

This is a little more flexible than my last post, and it does the
whole job::

#! /usr/bin/env python

import glob, os, string

def fix_ugly_song_names(songdir, band, spacerepl='_'):
"""Rename an ugly MP3 file name to a beautified shell-correct
name.  Only works for files named like "03 song name.mp3".
Use `spacerepl` to alter space replacement character.
WARNING: no error-handling!
"""
# Begin working in specified `songdir`.
os.chdir(songdir)
# Shell-unfriendly characters made into a string.
badchars = ''.join( set(string.punctuation) - set('-_+.~') )
# Identity table for later translation (removal of `badchars`).
tbl = string.maketrans('', '')
# MP3 files in `songdir` having ugly characters.
uglies = glob.glob("*.mp3")
# Make some step-by-step changes to build `pretties` list.
pretties = []
for ugly in uglies:
song, ext = os.path.splitext(ugly)
song = song.translate(tbl, badchars)
song = song.replace(" ", spacerepl)
song = song.title()
song = band+spacerepl+"-"+spacerepl+song[3:]
songext = song + ext
pretties.append(songext)
# Rename each file from ugly to pretty.
for ugly, pretty in zip(uglies, pretties):
if __debug__:
print ugly, '-->', pretty
else:
os.rename(ugly, pretty)

So for you to use spaces, just call with something like this::

fix_ugly_song_names('/var/mp3/pop/The_Beatles/Rubber_Soul',
'The Beatles',
spacerepl=' ')

I used the __debug__ gate to allow you to just see what it will do::

$ ls -1
01 drive my car.mp3
02 norwegian wood.mp3
03 you won't see me.mp3
04 nowhere man.mp3
mvmp3.py
$ python ./mvmp3.py
01 drive my car.mp3 --> The Beatles - Drive My Car.mp3
02 norwegian wood.mp3 --> The Beatles - Norwegian Wood.mp3
03 you won't see me.mp3 --> The Beatles - You Wont See Me.mp3
04 nowhere man.mp3 --> The Beatles - Nowhere Man.mp3

And then to actually do it with the non-__debug__ path::

$ python -O ./mvmp3.py
$ ls -1
mvmp3.py
The Beatles - Drive My Car.mp3
The Beatles - Norwegian Wood.mp3
The Beatles - Nowhere Man.mp3
The Beatles - You Wont See Me.mp3

If you want to keep the `badchars` in the file names, then you will
have to do *more* work since `song.title()` won't be able to do the
work for you.

Now I need to go beautify my collection.  :-)

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rename files with numbers

2005-10-31 Thread Micah Elliott
On Oct 31, Micah Elliott wrote:
> Now I need to go beautify my collection.  :-)

While a fun exercise, there are probably already dozens (or
thousands?) of utilities in existence that do this and much more.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically creating a HOME environ variable on Windows?

2005-11-01 Thread Micah Elliott
Maciej Dziardziel wrote:
> > ...there is a group of path related functions in os.path (or
> > ntpath), including expanduser, and its better to use function...

On Nov 01, [EMAIL PROTECTED] wrote:
> Having a function is definitely cleaner. Creating a HOME environment
> variable where one does not exist in the calling shell is
> misleading.
> ...
> It would be nice to start of with having a standard way to find out
> what the home directory is.

I think that is what Maciej has already pointed out.

Just to clarify then:

os.path.expanduser('~') is the universal/portable means to find a
user's home directory, regardless of platform.  So use of HOME or
USERPROFILE or whatever in scripts should be discouraged.

Someone please correct me if the above is wrong.  I haven't tried on a
mac, but linux and windows seem to behave well; i.e., linux looks for
HOME, and windows appears to combine HOMEDRIVE and HOMEPATH if HOME is
not set.  Details are in the 2.4.2 sources' "Python24/Lib/posixpath.py"
if you're curious.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Flat file, Python accessible database?

2005-11-01 Thread Micah Elliott
On Nov 01, Karlo Lozovina wrote:
> I've been Googling around for _small_, flat file (no server
> processes), SQL-like database which can be easily access from
> Python. Speed and perforamnce are of no issue, most important is
> that all data is contained within single file and no server binary
> has to run in order to use the dbase. Oh, and I'm using Python under
> Cygwin.
> 
> Ofcourse, ease of use and simplicity is most welcomed :). I'm
> currently playing around SQLite+PySQLite and BerkeleyDB, but those
> two seem like an overkill :(.

Not sure about "SQL-like", but the conf/ini file type could be
considered a reasonable database format for simple needs, and is
easy to parse/write.  The ConfigParser is documented here:

http://www.python.org/doc/current/lib/module-ConfigParser.html

And Fredrik Lundh's examples usage is here:

http://effbot.org/librarybook/configparser.htm

And the Initialization File format is described here:

http://en.wikipedia.org/wiki/INI_file

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's website does a great disservice to the language

2005-11-01 Thread Micah Elliott
On Nov 01, CppNewB wrote:
> First comment; "I hope the language is designed better than the
> site."  The site is readable, but is amateurish.

That's flaim bait if I ever saw it!

I find the site quite lovely: very readable, no ads, well organized,
nice colors, simple, easy to maintain (uses ht2html with ReST).  What
are you comparing it to?  Have a look at homepages for ruby, java,
tcl, and perl. I consider python.org superior to all of them.  It is
my personal benchmark for webpage usability.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers from a file, excluding words

2005-11-01 Thread Micah Elliott
On Nov 01, Mike Meyer wrote:
> Kristina Kudriaðova <[EMAIL PROTECTED]> writes:
> 
> > 1 Nov 2005 09:19:45 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> >> Hi, I have a file with this content:
> >>
> >>  z zzz z
> >> ...
> >> xxx xx x 34.215
> >> zzz zz 
> >> ...
> >>
> >
> > Hi,
> >
> > I'd suggest doing this:
> >
> > f = file('...')
> > for line in f:
> > if 'xxx xx x' in line:
> > var = float(line[len('xxx xx x'):].strip())
> > f.close()
> 
> Alternatively:
> 
> start = len('xxx xx x')
> for line in f:
> if line.startswith('xxx xx x'):
>var = float(line[start:].strip())

To refine this even further, I'll add that 'xxx...' is an ugly pattern
to repeat, and prone to mistyping, so add a tempvar and apply DRY::

pattern = 'xxx xx x'
start = len(pattern)
for line in f:
if line.startswith(pattern):
   var = float(line[start:].strip())

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


File renaming recipe (was: Rename files with numbers)

2005-11-02 Thread Micah Elliott
On Nov 01, Dudu Figueiredo wrote:
> I wrote a simpler script based in Micah Elliott's help...

I expanded my code from this thread to be a Cookbook recipe.  It has
no specificity for MP3 renaming, but is generic to files with
shell-unfriendly names.  It should usable as-posted if anyone needs to
cleanup a filesystem.

Any comments/improvements are appreciated.

Title: Fix ugly file names to be UNIX shell-friendly.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442517

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which feature of python do you like most?

2005-11-08 Thread Micah Elliott
[EMAIL PROTECTED] wrote:
> What do you use in your dairy work with python?

Cows hate snakes!

> which feature of python do you like most?

Various success stories:
http://pythonology.org/success

Eric Raymond:
http://pythonology.org/success&story=esr

Bruce Eckel:
http://www.artima.com/intv/aboutme.html
(and see follow-on conversations)

Wingware (nice list):
http://wingware.com/python/benefits

Kevin Altis' link collection:
http://altis.pycs.net/stories/2003/04/16/whatIsPythonAndWhyPython.html

If Python doesn't already maintain an official "list of benefits",
maybe it should.  Probably many in this group have a personal laundry
list.  Here's mine:

- Interactive interpreter for various testing of expressions before
  inserting into actual source code file.

- Built-in types have powerful default functionality.

- Portability via virtual machine. No need to build for multiple
  architectures/platforms.  And already installed on any platform
  worth caring about.

- Can write code at many levels of quality: robust (using classes,
  exceptions, data protection, etc.) or rapid (a script with no
  hierarchical constructs). Scales very well for large projects.

- No proprietary lock-in.

- Libraries such as optparse, logging, ply, etc. allow for reusable
  components in very few lines of code.

- Automatic memory management.

- Lack of static typing.

- Built-in documentation/help system.

- Adheres to UNIX philosophy.

- Intuitive process management.

- Robust/powerful regular expression engine.

- Syntax is very clean and readable/maintainable: executable
  pseudocode. Language is compact; can hold entire language in head:
  idioms and library routines. Only a couple books required to be
  completely up-to-speed on language.

- Strong integration with other languages (even though I don't use
  this... yet).

- Ease of introspection/meta-programming.

- Fast GUI building.

- Only one (sometimes two) way to do things right.

- Rapid creation of unit tests (pyunit, doctest, hybrid).

- Very simple exception handling (automatic propagation) makes usage
  more common, manageable.

- String-handling features better than other languages.

- Many fewer lines of code necessary to accomplish a task than with
  other languages.

- Very supportive and active community.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse data

2005-11-09 Thread Micah Elliott
On Nov 09, Dennis Benzinger wrote:
> Use the re module:
> 
> import re
> your_data = """person number 1
> 
> Name: bob
> Age: 50
> 
> 
> person number 2
> 
> Name: jim
> Age: 39"""
> 
> names = []
> for match in re.finditer("Name:(.*)", your_data):
>  names.append(match.group(1))
> print names

Dennis' solution is correct.  If you want to avoid REs, and concision
and speed are premiums, then you might refine it to:

names = [line[5:].strip() for line in your_data.split('\n')
 if line.startswith('Name:')]

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonising the vim (e.g. syntax popups)

2005-11-09 Thread Micah Elliott
On Nov 09, Christoph Haas wrote:
> I'm an addicted vim user and don't really use the IDLE for anything
> more than calculations where I'm too lazy to start KCalc. But one
> feature is very pretty: the built-in help for function calls while
> you type. Like you enter...
> 
> var1,var2=mystring.split(
> ...and the IDLE shows me a popup saying...
> "S.split([sep [,maxsplit]]) -> list of strings

The PIDA IDE  claims
to be able to do something like this.  I have not used PIDA, but I too
am a vim zealot and I think wrapping vim with extra functionality is a
great idea, and I'll try it out when I get a chance.

> Is there a decent way to get that help into vim? Or like showing
> docstrings or help that I get through pydoc on request?

You can set 'keywordprg' to something like "pydoc" to enable "K" to
pull up the help.  Its default setting is to open manpages for words
under the cursor.  I don't use it since I've got an interpreter shell
sitting in the corner of most virtual desktops -- doesn't everyone?

And ctags features are excessively prevalent in vim, and ctags works
fine with python IME.  You can create a tags file of your whole
python installation.

> I've been working myself through a pile of vim macros/plugins but
> couldn't find even one which simplifies programming in Python.

Matchit is a good one for %-matching:
http://www.vim.org/scripts/script.php?script_id=39

> Further issues would be handling the indentation

Eric McSween wrote a python indenter:
http://www.vim.org/scripts/script.php?script_id=974

> - maybe a plugin which syntax colors

Sure, that's builtin.  But Dmitry Vasiliev wrote some useful
enhancements:
http://www.vim.org/scripts/script.php?script_id=790
Note that you'll have to enable some variables in the macro.

> syntax colors different levels of indentation so I don't have to use
> my plastic ruler on the screen.

That's kind of a nice idea, and it should be an easy one to write (but
I'm not volunteering).  You could write it (:h syntax-highlighting) or
maybe post a request to the vim mailing list <[EMAIL PROTECTED]>.

Otherwise, folding would be useful for this.  Pyfold might be helpful,
though I haven't tried it:
http://www.vim.org/scripts/script.php?script_id=781

I like the ruler idea!  Usually when I find myself straining to figure
out what level I'm at it means it's time to refactor.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonising the vim (e.g. syntax popups) -> vimpst

2005-11-10 Thread Micah Elliott
On Nov 10, [EMAIL PROTECTED] wrote:
> vim... I'll try to get it more polished/functional and put it up on
> sourceforge or somewhere.

Change "sourceforge or somewhere" to:
http://www.vim.org/scripts/add_script.php

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Countdown

2005-11-11 Thread Micah Elliott
On Nov 11, john boy wrote:
>I am running the following program from the example in "how to
>think like a computer scientist"
>...
>When I set "n"= 1000 the program runs in interpreter and stops
>counting down at 14 instead of running all the way to "Blastoff".
>Why  is this program only counting to 986Anybody have an
>answer??

Did you notice the error:

...
RuntimeError: maximum recursion depth exceeded

You can't recurse forever!

>>> import sys
>>> sys.getrecursionlimit()
1000

You can set it a little higher (sys.setrecursionlimit) if you want to
make this particular example work, but you'll see many disclaimers on
doing this.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacing multiple instances of commas beginning at specific position

2005-11-14 Thread Micah Elliott
On Nov 14, striker wrote:
> I have a comma delimited text file that has multiple instances of
> multiple commas.  Each file will contain approximatley 300 lines.
> For example:
> 
> one, two, threefour,fivesix
> one, two, three,four,,eighteen,   and so on.
> 
> There is one time when multiple commas are allowed.  Just prior to
> the letters ADMNSRC there should be one instance of 4 commas. (
> ,eightADMNSRC,thirteen, ).  The text ADMNSRC is NOT in the same
> place on each line.
> 
> What would be the best approach to replace all instances of multiple
> commas with just one comma, except for the 4 commas prior to
> ADMNSRC?

One possible approach:

#! /usr/bin/env python

import re

# This list simulates the actual opened file.
infile = [
'one, two, three,four,,ADMNSRCeighteen,',
'one, two, three,four,five,six'
]

# Placeholder for resultant list.
result = []

for item in infile:
# Use a regex to just reduce *all* multi-commas to singles.
item = re.sub(r',{2,}', r',', item)
# Add back the desired commas for special case.
item = item.replace('ADMNSRC', ',,,ADMNSRC')
# Remove spaces??
item = item.replace(' ', '')
# Add to resultant list.
result.append(item)

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Background process for ssh port forwarding

2005-11-15 Thread Micah Elliott
On Nov 15, Jesse Rosenthal wrote:
> Whatever I do, though, I'll need to use pexpect to spawn the
> processes, since I'll need to log in to ssh servers with a password.

You might save yourself this effort by setting up ssh for
non-interactive use with keys instead of password authentication:

   $ cd ~/.ssh
   $ chmod 700 .
   $ ssh-keygen -t rsa  # just keep pressing 
   $ cp id_rsa.pub authorized_keys2

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function - Empty list as default parameter - not acting local?

2005-11-15 Thread Micah Elliott
On Nov 15, Gregory Piñero wrote:
>Hey guys, could anyone explain this behavior to me.  It doesn't
>seem right :-(
>def testfunc(parm1,parm2={}):
>print 'parm2',parm2
>parm2['key1']=5
>>>testfunc('greg')
>parm2 {}
>>>testfunc('greg')
>parm2 {'key1': 5}

http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating package question

2005-11-16 Thread Micah Elliott
On Nov 16, [EMAIL PROTECTED] wrote:
> I have a package directory structure as follows
> 
> root-
> |
> Common (contains __init__.py file)
> WindowsComponents (contains __init__.py file)
> ...
> 
> I would like modules in the WindowsComponents directory to be able
> to import some modules from the Common directory.

So you now have a "Common" package.  And it might contain a "mustard"
module.

> In my first pass, I was able to append sys.path (
> sys.path.append('../Common') ) in each module that wants to import
> from Common, but this feels "clunky".

Agreed.  You probably want to avoid messing with sys.path whenever
possible.

> Is there a "standard"/"best" way to accomplish this?  

So "root" should already be on your sys.path/PYTHONPATH.

Then in say file "root/WindowsComponents/spam.py":

from Common import mustard
...
mustard.attr

More import info from Fredrik:
http://effbot.org/zone/import-confusion.htm

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: readline vi mode in python interactive shell

2005-11-16 Thread Micah Elliott
On Nov 16, [EMAIL PROTECTED] wrote:
> Hi comp.lang.python:
> New to the group and new to python, so don't tear me up too much ...
> I installed the GNU readline support in python2.4, and it is working,
> but there is one annoying behaviour that I am hoping to squash ...
> 
> Namely, when I hit  to go to edit mode, then hit 'k' to go up
> in the command history, the prompt is put at the start of the line.

Amazing that you brought this up right now; I was just thinking about
whether or not to bother posting my own annoyance (invisible last
history command) with readline 4.3-5 (default with Fedora Core 3) and
Python 2.4.2.  Since you brought it up, here's my test case:

My ~/.inputrc simply contains "set editing-mode vi".  When I start
python I type "print 'a'".  Then "k" to recall the last
command -- but the line is invisible!  If I start editing the
blank/invisible line the text magically appears.  Or if I press
"k" twice I have visible history again.  So now I have in muscle
memory "kkj" to get my last command :-(

This is not a problem on the same machine with older versions of python
that are installed.  Is this worth filing a bug against python?  I
didn't find anything reported on sf.net/projects/python.

> Other places I use vi mode command line editing (e.g., zsh),  the
> cursor is at the end of the previous command. More often than not, I
> am wanting to edit the latter part of the previous command, not the
> start.

In bash "k" puts me at the *beginning* of the line.  Of course $
puts you where you want to be then, but I'm not sure how to affect the
behavior you're asking for; "help bind" might be useful, and "bind -P"
shows some mappings.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is parameter an iterable?

2005-11-17 Thread Micah Elliott
On Nov 17, Duncan Booth wrote:
> Steven D'Aprano wrote:
> > What should I do when I can't rely on functions that 
> > don't exist in older versions of Python?

>   sys.exit('Archaic Python not supported, please upgrade')

+1 QOTW.

I recently gave up on trying to support (backport to) pre-2.2 in my
projects.  It's been ~3 years since 2.2 released and that seem like a
pretty reasonable support window.  I wound up with HACK and
PORTABILITY comments all over the place and too much boilerplate.  Now
I go with a startup check on sys.hexversion, and exit with similar
wording.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: install python2.4 on FreeBSD and keep using python2.3

2005-11-17 Thread Micah Elliott
On Nov 17, Ksenia Marasanova wrote:
> I have python2.3, installed from port /lang/python long time ago. The
> current version is 2.4, but I'd rather have two python versions,
> instead of upgrading.
> Is there maybe a way to somehow link installed python to
> /lang/python2.3 port, and then upgrade ports and install /lang/python
> as a new (2.4) version, without upgrading?
> Or am I missing something and the things are much easier? I am not a
> FreeBSD guru and it's my first python upgrade... thanks!

Just pass "configure" an option like "--prefix /wherever/you/want".
Then make and make install.  Do this with as many Pythons as you like.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get just one character

2005-11-17 Thread Micah Elliott
On Nov 17, Sinan Nalkaya wrote:
> how can i just get 1 character ? i`ve done a search but just found
> getch() for windows, i need same for unix and raw_input has any
> option that is not documented ?

Get all the characters one at a time:

>>> inp = raw_input('enter a string> ')
enter a string> this is a string
>>> for ch in inp: print ch
...
t
h
i
s

i
s

a

s
t
r
i
n
g

Or just get a single character:

>>> inp[3]
's'
>>>   

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choose meaningful subjects for posts [was: Re: newb ?]

2005-11-18 Thread Micah Elliott
On Nov 18, [EMAIL PROTECTED] wrote:
> Grant> Obligatory aside: I'm completely baffled why anybody would choose
> Grant> the mailing list format over Usenet.  I don't even read mailing
> Grant> lists via mailing lists.  I recommend gmane.org's NNTP server for
> Grant> all your mailing list needs.
> 
> For the same reason I don't like web forums as a means of
> communication.  I would much rather operate in an interrupt-driven
> mode than have to remember to poll some external service to get my
> daily helping of information.

Agreed!

I notice that a lot of people post here from google.  I did it too
before I discovered the mailing list, which I now use because I
haven't found a news reader that I like nearly as much as mutt.  It's
quite nice to combine email and news into one.

If you have any suggestions for console-based newsreaders, I'm all
ears.  I have tried to setup "tin" in the past but the voluminosity of
its documentation made me give up.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choose meaningful subjects for posts [was: Re: newb ?]

2005-11-18 Thread Micah Elliott
On Nov 18, Grant Edwards wrote:
> There is an NNTP patch to allow you to use mutt to read Usenet
> via an NNTP server.

Yes, I'm aware of it; it's last (alpha) update was in 1999 and
it probably has some fleas. :-)

> Mutt users who don't do that seem to like slrn -- it has a very
> similar look and feel.

Cool!  Thanks for the info.  I might give it a try.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding through recursion

2005-11-18 Thread Micah Elliott
On Nov 19, Ben Finney wrote:
...
> This is just one of many reasons why I advocate always having a
> *single* return statement, at the *end* of the function.

Agreed that it's a good *general* practice, but sometimes early exit
is useful and clear.

This is somewhat of a religious topic.  A good discussion is:
http://c2.com/cgi/wiki?SingleFunctionExitPoint

pychecker warns of fall-off-the-end functions.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best cumulative sum

2005-11-20 Thread Micah Elliott
On Nov 21, David Isaac wrote:
> What's the good way to produce a cumulative sum?

>>> import operator
>>> x = 1,2,3
>>> reduce(operator.add, x)
6

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Underscores in Python numbers

2005-11-21 Thread Micah Elliott
On Nov 19, Steven D'Aprano wrote:
> Perhaps Python should concatenate numeric literals at compile time:
> 
> 123 456 is the same as 123456.

+1 for readability.

But in support of no change, When was the last time you looked at long
sequences of python digits outside of your editor/IDE?  You probably
don't deal with them interactively (and if you do you probably paste
them in).

So reasonable editors could just color groups differently. E.g.:

123456789012345
^^^
red  blue red

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: after sorted from the lists

2005-11-22 Thread Micah Elliott
On Nov 22, Ben Bush wrote:
> I have a list:
> [[1,2],[2,1],[3,1],[1,4],[3,3],[1,4]]
> How to remove all the duplicate or same after sorted from the lists?
> That is, [1,2] and [2,1] are the same after sorting them.
> I want the result to be:
> [[1,2],[3,1],[1,4],[3,3]]

You've described the code in words.  Next time show the code you
tried.  Here's one possible solution.

First sort each sublist.

>>> L1 = [[1,2],[2,1],[3,1],[1,4],[3,3],[1,4]]
>>> for i in L1:
... i.sort()
...
>>> L1
[[1, 2], [1, 2], [1, 3], [1, 4], [3, 3], [1, 4]]

Then add L1's unique items to a new list L2.

>>> L2 = []
>>> for i in L1:
... if i not in L2:
... L2.append(i)
...
>>> L2
[[1, 2], [1, 3], [1, 4], [3, 3]]

This is not identical to your said output, but it sounds like 
[1,3] == [3,1] for your purposes.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting documentation for user relevant functions only?

2005-11-28 Thread Micah Elliott
On Nov 28, Anton81 wrote:
> I've written a python script and added short docstrings. Now I'd
> like to create a short overview of commands the user can use.
> However I don't want the internal stuff that I also commented. Is
> there a way to create a fancy documentation (e.g. pydoc) of certain
> functions only?

You can use the leading underscores convention
http://docs.python.org/ref/id-classes.html> to "hide" the
intended invisible names.  pydoc and epydoc both honor this...

$ cat foo.py
"""Foo test mod.
"""

def spam():
"Like ham."
pass

def _secret():
"Can't see this docstring."
pass

class Mustard(object):
__name1 = 1
_name2  = 2
name3   = 3


$ pydoc foo
Help on module foo:

NAME
foo - Foo test mod.

CLASSES
...
class Mustard(__builtin__.object)
 ...
 |  name3 = 3

FUNCTIONS
spam()
Like ham.


-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question concerning formatted output

2005-11-29 Thread Micah Elliott
On Nov 29, Fredrik Lundh wrote:
> inp = open("xyplan.nobreaks","r")
> data = inp.read()
> 
> import textwrap
> for line in textwrap.wrap(data, 15):
> print line

Right -- if the data is that regular then every 15th item is the
split-point.  A variation on this theme then is:

for i in range(0, len(data), 15):
print data[i:i+15]

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested loop

2005-11-30 Thread Micah Elliott
On Nov 29, viewcharts wrote:
> I am reading two text files comparing the values in one to the other, 
> this requires two loops.

Or you could have a look at difflib.

http://docs.python.org/lib/differ-examples.html

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import Excel csv - files

2005-11-30 Thread Micah Elliott
On Nov 30, Jürgen Kemeter wrote:
>My actual Problem:
>The Excel workbook contains several spreadsheets. These are
>linked through Hyperlinks, and contain several cell comments. How
>can I export these comments and Hyperlinks using Python?

Are you just wanting read a .xls file with Python?  pyExcelerator 
http://sourceforge.net/projects/pyexcelerator> can
do that job.  Documentation is non-existent AFAICT, but the tools
directory has good examples.

I don't know how comments/hyperlinks are treated but you can try and
find out.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested loop

2005-11-30 Thread Micah Elliott
> Micah Elliott wrote:
> > On Nov 29, viewcharts wrote:
> >>I am reading two text files comparing the values in one to the other, 
> >>this requires two loops.
> > 
> > Or you could have a look at difflib.
> > http://docs.python.org/lib/differ-examples.html

On Nov 30, Steve Holden wrote:
> Indeed, but I personally don't see a way to persuade difflib to
> compare the lines of one file with the fourth field of lines in
> another.

Right.  I was just pointing out the possibility (I don't know the
OP's data format) since no one had mentioned it yet.  If there are
multiple "fields" per line, then pre-massaging into one field per line
might be a reasonable approach.  But then you might end up doing more
work than the nested loop idea.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get current function name

2005-12-01 Thread Micah Elliott
On Dec 02, Joe Wong (Mango) wrote:
> Is this possible for a function to obtain its own name ?
> 
>eg.
>def func1():
>print "my name is " + get_my_name()
> 
>the result will show "my name is func1"

This very question was discussed recently:
http://groups.google.com/group/comp.lang.python/msg/cdc1f03ceabf2c79

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Micah Elliott
On Dec 02, Dave Hansen wrote:
> Python recognizes the TAB character as valid indentation.  TAB
> characters are evil.  They should be banned from Python source code.

AGREE!  AGREE!  AGREE! 

> The interpreter should stop translation of code and throw an
> exception when one is encountered.

You could file a "Parser/Compiler" Feature Request for this (Hmm,
sf.net appears to have just renamed "Request For Enhancment" to
"Feature Request").  Seems the present enformencement of
disallowing tab/space mixing is with -t and -tt.  From PEP-8
http://www.python.org/peps/pep-0008.html>:

...
Tabs or Spaces?

Never mix tabs and spaces.  The most popular way of indenting
Python is with spaces only.  ... Code indented with a mixture
of tabs and spaces should be converted to using spaces
exclusively. ... When invoking the python command line
interpreter with the -t option, it issues warnings about code
that illegally mixes tabs and spaces.  When using -tt these
warnings become errors. These options are highly recommended!

For new projects, spaces-only are strongly recommended over
tabs. Most editors have features that make this easy to do.

If your "FR" is approved, -t and -tt could apply to any use of tabs.
+1 from me.

-- 
_ _ ___
|V|icah |- lliott <>< [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


Pre-PEP Proposal: Codetags

2005-08-10 Thread Micah Elliott
I also have this living as a wiki <http://tracos.org/codetag/wiki/Pep>
if people would like to add comments there. I might try to capture there
feedback from this group anyway. First try at a PEP -- thanks for any
feedback!


Please add **NOTE:** comments to the bottom of this wiki document
using `WikiRestructuredText`:trac:.

===
 Codetag PEP (*or* Tao of Codetagging)
===

PEP: XXX
Title: Codetags
Version: $Revision$
Last-Modified: $Date$
Author: Micah Elliott 
Status: Active
Type: Informational
Content-Type: text/x-rst
Created: 27-Jun-2005
Post-History: XXX


Abstract


This informational PEP aims to provide guidelines for consistent use
of Codetags, which would enable the construction of standard utilities
to take advantage of the Codetag information, as well as making Python
code more uniform across projects. Codetag is a also a very
lightweight programming micro-paradigm and becomes useful for project
managment, documentation, change tracking, and project health
monitoring. This is submitted as a PEP because I feel its ideas are
Pythonic, although the concepts are not unique to Python programming.
Herein are the definition of a Codetag, a philosophy rant, a
motivation for standardized conventions, a specification, a toolset
description, and possible objections to the Codetag project/paradigm.


What's a Codetag?
=

Programmers widely use ad-hoc code comment markup conventions to serve
as reminders of sections of code that need closer inspection or
review.  Examples of markup include ``FIXME``, ``TODO``, ``XXX``,
``BUG``, but there many more in wide use in existing software.  Such
markup will be henceforth referred to as a *Codetag*. These Codetags
may show up in application code, unit tests, scripts, general
documentation, or wherever suitable.


Philosophy
==

NOTE: **I'm not certain Philosophy_ belongs in the PEP, but it
somewhat explains the usefulness of Codetags** 

If you subscribe to most of these values, then Codetags will likely be
useful for you.

1. As much information as possible should be contained **inside the
   source code** (application code or unit tests). This along with use
   of Codetags impedes duplication. Most documentation can be
   generated from that source code Eg, by using help2man, man2html,
   docutils, epydoc/pydoc, ctdocgen, etc.

2. Information should be almost **never duplicated** -- it should be
   recorded in a single original format and all other locations should
   be automatically generated from the original, or simply be
   referenced.  This is the *SPOT* rule.

3. Documentation that gets into customers' hands should be
   **auto-generated** from single sources into whatever output formats.
   People want documentation in many forms. It is thus important to
   have a documentation system that can generate all of these.

4. Whatever information is subject to (and suited for) user
   feedback/input should be contained in a **wiki** (or maybe usenet or
   maillists). Eg, FAQ, RFC, PEP.

5. There should not be a dedicated, disjoint **documentation team**
   for any non-huge project.  The developers writing the code know the
   code best, and should be the ones to describe it.

6. **Plain text** (with non-invasive markup) is the best form of writing
   anything. All other formats are to be generated from the plain
   text.

7. **Revision control** should be used for almost everything. And
   modifications should be checkin'd at least daily.


Motivation
==

**Various productivity tools can be built around Codetags.**
See `Toolset Possibilities`_.

**Encourages consistency.**
Historically, a subset of these Codetags has been used informally in
the majority of codes in existence, whether Python or some other
language.  Tags have been used in an inconsistent manner with
different spellings, semantics, format, and placement. Eg, some
programmers might include datestamps and/or user identifiers, limit to
a single line or not, spell the Codetag differently than others, etc.

**Encourages adherence to SPOT/DRY principle.**
Eg, generating a roadmap dynamically from Codetags instead of keeping
TODOs in sync with separate roadmap document.

**Easy to remember.**
All Codetags must be concise, intuitive, and semantically
non-overlapping with others. Format is also simple.

**Use not required/imposed.**
If you don't use Codetags already, there's no obligation to start, and
no risk of affecting code (but see Objections_). A small subset can be
adopted and the Tools_ will still be useful (a few are already
implicitly adopted anyway). Also very easy to identify and remove if a
Codetag is no longer deemed useful. Then it is effectively *completed*
and recorded by revision control simply by checkin'ing.

**Gives a global view of code.**
Use tools to generate documentation and reports.

**A logical location for capturing CRCs/Stori

Building Python statically on linux

2007-12-27 Thread Micah Elliott
Are there instructions somewhere on how to build Python (on linux)
statically?  This seems like a common thing to do want to do, but my
searching isn't turning up much.  If it is common, it would be nice to
see a configure option like I've seen in other tools:

  --enable-all-static Build completely static (standalone)
binaries.

I'm ./configure-ing with "--disable-shared" (because this must mean
"enable static", right?), and (based on some other posts here) tried
adding "*static*" near the top of Modules/Setup.  I'd like to see ldd
tell me "not a dynamic executable", but alas, it's presently:

$ ldd /path/to/new/bin/python
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x008e9000)
libdl.so.2 => /lib/libdl.so.2 (0x007f)
libutil.so.1 => /lib/libutil.so.1 (0x00df6000)
libm.so.6 => /lib/tls/libm.so.6 (0x007cb000)
libc.so.6 => /lib/tls/libc.so.6 (0x0069f000)
/lib/ld-linux.so.2 (0x00682000)

Do I just need to be passing something like LDFLAGS="-static ???" to
configure?  I just tried that and got a bunch of "symbol rename"
warnings during the compilation, and then "make install" mysteriously
failed.

Thanks for any pointers.
--
Micah
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Building Python statically on linux

2007-12-27 Thread Micah Elliott
On Dec 27, 8:32 am, Zentrader <[EMAIL PROTECTED]> wrote:

> I think you can just add -static to the gcc Flag line in the
> makefile.

Doing that (or CFLAGS=-static, or LDFLAGS=-static, or other Makefile
tweaks) gets me linker errors.  Sounds like there's not a simple
prescribed means to do this (that anyone has documented).  So now I'm
open to hearing about other hacks people have done to get this to
work.  (Hopefully a config weenie heard my plea for --enable-all-
static)

--
Micah
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Building Python statically on linux

2007-12-28 Thread Micah Elliott
On Dec 28, 5:44 am, Christian Heimes <[EMAIL PROTECTED]> wrote:

> Can you work on the topic and write a small howto for your wiki
> (http://wiki.python.org/moin/)?

Good idea.  I've created a placeholder (with what I know so far, not
much) to track this:

  http://wiki.python.org/moin/BuildStatically

I'll plan to be updating it today if I can get it working.  Anyone
else is welcome to add their knowledge/experience.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to store config or preferences in a multi-platform way.

2008-05-01 Thread Micah Elliott
On 2008-05-01 Carl Banks wrote:

> If you don't intend to write a GUI to do that, write a simple
> text file parser (if the options are simple), use ConfigParser,
> or use a Python file that you exec.

INI is great for so many things.  It is also extremely
commonplace, regardless of platform.  The biggest challenge might
be choosing which one to adopt:

http://wiki.python.org/moin/ConfigParserShootout

-- 
Micah Elliott | [EMAIL PROTECTED] | http://MicahElliott.blogspot.com


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: os.open and O_EXCL

2008-05-06 Thread Micah Elliott
On 2008-05-01 Ethan Furman wrote:

> I am trying to lock a file so no other process can get read nor
> write  access to it.

This looks promising:

http://pypi.python.org/pypi/lockfile/0.2

-- 
Micah Elliott | [EMAIL PROTECTED] | http://MicahElliott.blogspot.com


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: open filename with spaces in path

2008-05-06 Thread Micah Elliott
On 2008-05-06 Michael Robertson wrote:

> I'm having trouble opening a file in linux, whose path has
> spaces in it.
>
> $ mkdir my\ test
> $ echo test > my\ test/test.txt
> $ python
>
> >>> open('./my test/test.txt')
> Exception

That's funny.  These exact steps work fine for me on Linux, with
Python 2.5.2, and even 1.5.2.

Does 'os.path.normpath' have anything interesting to say about
what you're passing it?

> but yet...
>
> >>> import os
> >>> os.chdir('./my test')
> >>> open('./test')
>
> works just fine.

How doctored up is this example?  In the above ./test should not
actually exist.  Did the chdir actually work?  Or did you remove
the .txt?

-- 
Micah Elliott | [EMAIL PROTECTED] | http://MicahElliott.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list