Re: Windows vs. Linux

2006-07-31 Thread metaperl

Andy Dingley wrote:

>
> Python is one of the best languages I've found for
> platform-independence - significantly better than Perl.

The reason I'm going with vmware is because I'm afraid that I will need
to compile a C portiion of a Python module and that will not be a
pretty picture under Windows... true or false?

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


Looking for an intellisense with good help IDE for Python

2006-08-08 Thread metaperl
Hi,

I would like an IDE that shows me all methods and functions I can call
on a particular data item. For instance, iter() can be called on any
sequence, but it is not a method.

Nonetheless, I would like for something to show me every thing that I
can call on a particular data item.

This includes % after a string.

I would also like browseable help with good examples on whatever
methods and functions and operators it pops up.

Thanks,
Terrence

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


Re: recommended general-purpose string template packages?

2006-08-14 Thread metaperl

John Machin wrote:
> Hi,
>
> In general, I'm mainly interested in a template engine for dynamic web
> pages but would like a general purpose one to avoid learning yet
> another package for generating e-mail messages, form letters, source
> code, whatever.

HTMLTemplate and texttemplate offer a somewhat uniform approach to text
versus HTML... it attempts to raise string processing up to the level
of tree/HTML processing. That stringtemplate module seems to be aiming
for the lowest common denominator.

Interesting contrast in approaches:
http://freespace.virgin.net/hamish.sanderson/index.html

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


trying to reach kevin smith, author of plastex

2006-08-15 Thread metaperl
Email to Kevin Smith regarding his plastex package failed. I hope he
read this group. The tarball that he needs to reproduce the error is
here:
http://arc.livingcosmos.org/wolfram-fruit2/wolfram-fruit.tar.gz

Hi, when attempting to type plastex wolfram-fruit.tex on the attached
latex document, I got some errors. Also, I think the default HTML font
for plastex could be "nicer" ...either that or some ready made easy to
choose CSS for some common "nicer" font choices.

Errors I got follow:

[EMAIL PROTECTED]:~/domains/org/livingcosmos/arc/wolfram-fruit2$ plastex
wolfram-fruit.tex
plasTeX version 0.6
( /home/terry/install/lib/python2.4/site-
packages/plasTeX/Packages/article.pyc
)..
( /home/terry/install/lib/python2.4/site-
packages/plasTeX/Packages/graphicx.pyc
) ( ./wrapfig.sty..
WARNING: unrecognized command/environment: z@
WARNING: Missing decimal in ./wrapfig.sty on line 32, treating as `0`.
WARNING: Missing unit (expecting pt, pc, in, bp, cm, mm, dd, cc, sp,
ex,
em) in ./wrapfig.sty on line 32, treating as `pt`
...
WARNING: unrecognized command/environment: the
WARNING: unrecognized command/environment: [EMAIL PROTECTED]
WARNING: unrecognized command/environment: @arrayparboxrestore
..
WARNING: unrecognized command/environment: string
WARNING: unrecognized command/environment: newfloatlist
...
)..


WARNING: unrecognized command/environment: @ifnextchar
INFO: Arguments of "[EMAIL PROTECTED]" don't match definition. Got "{" but was
expecting "[" ([#1]#2).
WARNING: unrecognized command/environment: [EMAIL PROTECTED]
WARNING: Missing number in ./wolfram-fruit.tex on line 327, treating as
`0`. (<[EMAIL PROTECTED] element at 0x1091752428>)
..
WARNING: Missing number in ./wolfram-fruit.tex on line 327, treating as
`0`. (< [EMAIL PROTECTED] element at 0x1091752844>)
WARNING: Missing number in ./wolfram-fruit.tex on line 327, treating as
`0`. ()
WARNING: Missing number in  on line 1, treating as `0`. ()
WARNING: Missing number in  on line 1, treating as `0`. (<@ne
element at 0x1091755052>)

WARNING: Missing number in ./wolfram-fruit.tex on line 327, treating as

`0`. (<[EMAIL PROTECTED] element at 0x1091753644>)
WARNING: Missing number in ./wolfram-fruit.tex on line 327, treating as
`0`. ()
WARNING: Missing number in ./wolfram-fruit.tex on line 327, treating as
`0`. ()
WARNING: Missing number in  on line 1, treating as `0`. ()
WARNING: Missing number in  on line 1, treating as `0`. (<@ne
element at 0x1091769420>)
..
INFO: Arguments of "[EMAIL PROTECTED]" don't match definition. Got "{" but was
expecting "[" ([#1]#2).
WARNING: Missing decimal in ./wolfram-fruit.tex on line 327, treating
as
`0`.
WARNING: Missing unit (expecting pt, pc, in, bp, cm, mm, dd, cc, sp,
ex,
em) in ./wolfram-fruit.tex on line 327, treating as `pt`
WARNING: Missing decimal in ./wolfram-fruit.tex on line 327, treating
as
`0`.
WARNING: Missing unit (expecting pt, pc, in, bp, cm, mm, dd, cc, sp,
ex,
em) in ./wolfram-fruit.tex on line 328, treating as `pt`
ERROR: An error occurred while building the document object in
./wolfram-
fruit.tex on line 328 (global name 'tok' is not defined)
Traceback (most recent call last):
File "/home/terry/install/bin/plastex", line 95, in ?
main(sys.argv)
File "/home/terry/install/bin/plastex", line 44, in main
tex.parse()
File "/home/terry/install/lib/python2.4/site-packages/plasTeX/TeX.py",
line 378, in parse
item.digest(tokens)
File
"/home/terry/install/lib/python2.4/site-packages/plasTeX/__init__.py",
line 824, in digest
item.digest(tokens)
File
"/home/terry/install/lib/python2.4/site-packages/plasTeX/Base/LaTeX/Sectioning.py",
line 267, in digest
item.digest(tokens)
File
"/home/terry/install/lib/python2.4/site-packages/plasTeX/Base/TeX/Text.py",
line 55, in digest
tokens.push(tok)
NameError: global name 'tok' is not defined
[EMAIL PROTECTED]:~/domains/org/livingcosmos/arc/wolfram-fruit2$

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


Re: recommended general-purpose string template packages?

2006-08-16 Thread metaperl

vj wrote:
> I use preppy from reportlab:
>
> http://www.reportlab.org/preppy.html

wow. thanks for the link. I second you on pretty. It is ultra-simple
and nothing but a gateway to python.

also, reportlab makes a number of high-quality open source python
wares.

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


Re: idea on how to get/set nested python dictionary values

2006-08-16 Thread metaperl

[EMAIL PROTECTED] wrote:

> | would use a recursive approach for this - given that you have a sort
> of recursive datastructure:
>
> py> def SetNewDataParam2(Data, NewData):
> ... if type(Data[Data.keys()[0]]) == type(dict()):
> ... SetNewDataParam2(Data[Data.keys()[0]], NewData)
> ... else:
> ... Data[Data.keys()[0]] = NewData
> ...

Data[Data.keys()[0]] is used 3 times in the above code. Is there some
way to factor out that usage? I'm just starting python but I'm always
on the lookout for DRY :)

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


Question on extracting doc strings from .py files

2006-08-16 Thread metaperl
If you type:
>>> import os; help(os)

Then you see the following (see below). But I don't understand where
the line
"MODULE DOCS
http://www.python.org/doc/current/lib/module-os.html
"

is encoded in os.py anywhere. If you search for the words
'module-os.html' you find
nothing. Ditto for 'MODULE DOCS'


--- output follows ---

Help on module os:

NAME
os - OS routines for Mac, DOS, NT, or Posix depending on what
system we're o
n.

FILE
/usr/lib/python2.4/os.py

MODULE DOCS
http://www.python.org/doc/current/lib/module-os.html

DESCRIPTION
This exports:
  - all functions from posix, nt, os2, mac, or ce, e.g. unlink,
stat, etc.
  - os.path is one of the modules posixpath, ntpath, or macpath
  - os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
  - os.curdir is a string representing the current directory ('.'
or ':')
  - os.pardir is a string representing the parent directory ('..'
or '::')

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


Re: Web Hosting

2006-10-16 Thread metaperl

Sir Psycho wrote:
> Hi,
>
> With web hosting, does the ISP you chose have to support the framework
> you work with as well?
>
> Im looking at making a site in Python, however, Im lost as to what ISPs
> actually support.

We support any and every thing Python and we are a not-for-profit
cooperative. Check us out:

http://www.HCOOP.net
irc://irc.freenode.org/#hcoop

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


Re: HTML Templates (Sitemesh/Tiles concept) in Python

2006-10-24 Thread metaperl

Suren wrote:


> It seems error prone as well as bad design to scatter this logic in
> each content page. Is there a template logic like Sitemesh or Tiles
> concept that can decorate a desired page just before show time?
>

Suren, you are looking for push-style templating. I list a number of
alternatives here:
http://www.livingcosmos.org/Members/sundevil/software-engineering/push-style-templating-systems/view

I use meld3 personally, but Templess looks pretty good and Webstring
also. Depends on your tastes.

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


Re: python GUIs comparison (want)

2006-11-06 Thread metaperl

[EMAIL PROTECTED] wrote:
> Paul Boddie wrote:
>
> """The figures behind the scenes are quite enlightening for that
> particular page. If you (or community experiences) don't agree with the
>
> rankings (wxPython apparently even easier to learn than PythonCard and
> Tinder, a bunch of Gtk-based toolkits having more or less "full" Linux
> scores) then you'll have some surprises, I'm sure. Nevertheless, it's
> an interesting concept. """
>
> Well, I don't know what I was thinking, exactly, when I rated
> PythonCard's ease of use...so I went back and changed it to rate it a
> lot higher. The ratings in this script were done a long time ago now

I dropped Pythoncard when I could not sort multi column lists and when
I posted to the email list and no one answered me.

But prior to that it was great.

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


Re: MemoDepot: build YOUR OWN online notes library - anything, anytime, anywhere

2006-11-06 Thread metaperl
I'll just use Plone, thanks.

ompaniess wrote:
> Just like everybody else nowadays, you are facing infinite amount of
> information everyday. how can you keep those that truly matters to you?
> MemoDepot allows you to do just that, and much more!
>
> - Capture any information, store as notes in your MemoDepot account,
> and access from anywhere
> - Organize your notes the way you like, they are always available at
> your fingertips
> - Pinpoint any notes by powerful search, just when you need it
> - Share your notes with others
> - Export your notes to local machine, so you take control, not
> MemoDepot
>
> With MemoDepot, you no longer have to throw away any useful
> information: contacts, ideas, experience, coupons, receipts, pictures,
> web pages, hard Googled-out results, programming sample codes,
> teacher's handout, scientific references, or simply favored book
> passages.. yes, ANYTHING. It is the place to deposit your
> knowledge; it is the way to extend your memory.
>
> MemoDepot is NOT merely a storage solution, a screen scraper, NOR is
> another online notebook, search engine or editor - it is an end to end
> knowledge build and management system, everyday, in the most convenient
> way.
>
> To truly appreciate why MemoDepot tool and service are so powerful,
> take a few minutes to check out:
>
> http://www.memodepot.com/noteserver/flashes/memodepot.pps  (PowerPonit)
>
> http://www.memodepot.com/noteserver/flashes/memodepot_demo.html  (Flash
> Demo)
>
> http://www.memodepot.com (Get started!)
> 
> Any comments or suggestions, send to: [EMAIL PROTECTED]

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


os x make install dies when compiling zipfile.py on 2.5 and 2.4.4

2006-11-06 Thread metaperl
I've tried both Python 2.4.4 and Python 2.5. I'm trying to build from
source and install under a local directory Swarm since OpenSwarm
requires builds of Postgres and Python under it's control.

Ok, so I did

./configure --prefix=/Users/tbrannon/Documents/Python/Swarm/Python-2.5

but during make install I get this:

Compiling
/Users/tbrannon/Documents/Python/Swarm/Python-2.5/lib/python2.5/xmlrpclib.py
...
Compiling
/Users/tbrannon/Documents/Python/Swarm/Python-2.5/lib/python2.5/zipfile.py
...
make: *** [libinstall] Error 1


and the same thing happens for Python 2.4.4 leaving me without a
platform-depedent install directory in my build.. any ideas?

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


OS X and Python - what is your install strategy?

2006-08-24 Thread metaperl
I'm about to get a new OS X box on which I will rewrite a bunch of data
munging scripts from Perl to Python. I know that there are several port
services for OS X (fink, darwin ports, opendarwin). So I am not sure
whether to use their port of Python or whether to build from scratch or
use the Python image file. Also ActivePython is something of a choice
but for some reason not a front-running one for me. I tend to like
Gentoo-style compile from source over pre-bundled all-in-one solutions
like ActivePython.

I'm not going to do much other than maybe install Plone and do some XML
and CSV processing. Most everything I need is in the Python stdlib.
Maybe down the road some graphics and web stuff (I like Clever Harold
or Pylons for that... but I still ahve not examined the 900 other web
app options in Python :)

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


Best Practices for Python Script Development?

2006-08-24 Thread metaperl
Hello, I am responsible for converting 30 loosey-goosey Perl scripts
into 30 well-documented easy to understand and use Python scripts.

No one has said anything in particular about how this should be done,
but the end product should be "professional" looking.

So, I'm looking for some books and suggestions which will help me write
high-quality scripts. I know about object-oriented programming and
application configuration and have spent 6 years doing professional
Perl but have decided that Python is the new choice of serious agile
developers. Only thing is, I only figured that out 1 month ago and
don't really know how to write good code yet :)


Documentation
=
I would like browseable HTML documentation for each script. I have
started
to get some idea of using docstrings within a file and that they can
be extracted but would like a pointer to some docs on this practice.

`Pydoc `_ seems to be
built around modules and I want to document scripts.

Configuration
==
Based on `this thread
`__
I plan to use ConfigParser to squirrel away generic information like
database connection info. The chapter "table-driven code" in Bruce
Eckels' "Thinking in Python" seems like it would've been of help but
it is not written. Any weblinks for similar articles?

The directory hierarchy is going to be /data/vendor/X where X is a
particular data vendor. In /data/vendor/config.ini will be the generic
config info along with an index.html giving an overview of the whole
shebang.

Usage
=
Most scripts will be run from cron and so should be driveable via
command-line options.

optparse looks very good to me. And I had never thought about
required versus optional arguments in the way that it does. What an
eye-opener.

Searching cheeseshop.python.org/pypi for getopt modules does not work
very well by the way.

Version Control
===
I've been using bazaar but mercurial seems to be quicker to create
forward-facing browseable web repos. And the propagation and pull
facilities seem more integrated and useable. But both are highly
desireable products.

OS X

I'm doing all this on OS X. I like Unix but am too dumb for Linux.
Windows is a great GUI but I hate the registry and hate jumping back
and forth between Windows and Cygwin and never getting the full power
of either.

I think I'll get 2 Mac Minis - one for the
actual data munging and one to back everything up on.

Which actual Python distro I will use is going to be based on the data
I get from `this thread
`_

Books
=
I think these 4 will carry me a long way, but any other suggestions ar
welcome:
* `Dive into Python `_
* `Text Processing in Python `_
* Python Cookbook
* Programming Python

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


Re: Best Practices for Python Script Development?

2006-08-30 Thread metaperl

Ant wrote:
> > `Pydoc `_ seems to be
> > built around modules and I want to document scripts.
>
> Any python script *is* a python module. So pydoc is what you are after
> here.

Yes, but Lundh's PythonDoc looks good too. I'm inclined to go with
that.

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


Any relational database design tool written in Python

2006-08-31 Thread metaperl
Hello,

I am wondering if I overlooked such a tool at freshmeat, sf.net, and
cheeseshop and google.  I prefer Python, so that I can patch and
upgrade it. Which also means I prefer opensource over commercial.

I am hoping for something that can create database deltas.  I am sort
of divided over the logical versus physical modeling issue.

While I am looking for something fairly graphical like dbSketch or
dbWrench, I am pretty impressed with Django's built-in ORM's ability to
create and update databases.

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


Re: SQLObject or SQLAlchemy?

2006-08-31 Thread metaperl

John Salerno wrote:
> Are there any major differences between these two? It seems they can
> both be used with TurboGears, and SQLAlchemy with Django. I'm just
> wondering what everyone's preference is, and why, and if there are even
> more choices for ORM.

I just finished surfing both websites last night myself and here is
what I glean

-- I dont see why SQLObject could not be used with Django

-- SQLAlchemy is not just an ORM. It can be used that way. I dont know
why you have to explicitly tell it about related tables twice though.
You do it the first time when defining table metadata:
http://www.sqlalchemy.org/docs/tutorial.myt#tutorial_schemasql_table_relationships

but when you have to make a call to relation as well:
http://www.sqlalchemy.org/docs/tutorial.myt#tutorial_orm_relationships

It would seem that one or the other is enough and having to do both is
redundant... continuing with the comparison

-- SQLObject makes it clear that it only has support for tables with a
single-column primary key

-- tha can both do self-joins

-- SQLAlchemy has support for connection pooling

-- ORMS get slow when you need to load a lot of records. SQLAlchemy has
usage modes to load massive data sets when the job calls for it.

> 
> Thanks.

Just my 2 cents.

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


Re: SQLObject or SQLAlchemy?

2006-08-31 Thread metaperl

John Salerno wrote:


> Thanks for the reply. Do you mean in the above quote that SA is a little
> more complicated than SO?

Don't be afraid to download them and try their respective tutorials.
Each one would take about an hour and then you'd have a feel for
yourself. I agree with adam that SQLAlchemy has far more features and
flexibility.

SQLObject would be very great and convenient if you were throwing up a
website that you knew would never require high volumne.

SA does have an IRC group. It's not incredibly lively but at least
there is one.

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


inheritance needed in program configuration - config module or python oo?

2006-09-02 Thread metaperl


Inheritance needed in app configuration
=

I have an ftp server that a number of vendors connect into to upload a
file to their directory. In OO terms, we would have

class OurFTP:
  server = "ftpserver.com"

class Vendor1(OurFTP)
  user, pass, directory = ("blah","blah","blah")

etc, etc

And thus when I write a Python script to go check their uploads, I need
to create a VendorN object and use the user, pass and directory from
VendorN but use the server attribute from the parent class

Now in pure OO, this is a piece of cake. However, I thought I would use
ConfigObj to configure my app because it is clean and widely used and
the authors are active people. But I don't know how to get a local
config to inherit global values.

In other words, I have a file called global.ini with the server address
in it and then each vendor has a file called local.ini with their user,
pass, directory info.

And I need to form an FTP connection URL based on this. But I really
dont want to write my code such that I explicitly hardcode where the
ftpserver is coming from. Again, in pure OO it is very simple to call a
method and have it dispatch to either the current object or it's
parent, but I am not sure that ConfigObj or any config module allows
such power.

I am starting to think that I better just do my configuration
information in Python classes to get the genericity that I want.

Program Code
===

Just in case you want to see what I'm doing, here's the relevant
section of code:

config  = ConfigObj("local.ini")
gconfig = ConfigObj("../generic.ini")


"""Curry function by Bruno Desthuilliers
http://groups.google.com/group/comp.lang.python/browse_thread/thread/b2af1cc34aab085e/c31e388ff0bb4e9c?lnk=gst&q=curry&rnum=10#c31e388ff0bb4e9c

curry() will be part of py2.5
"""

def curry(fun, *args):
   def _curried(*moreargs):
 return fun(*(args + moreargs))
   _curried.func_name = "curried(%s) of %r" % (", ".join(args), fun)
   return _curried

def getkey(k1,k2):
return config[k1][k2]

#
--
# Fetch DMS file from KE FTP
#
--


ftp_cfg_keys = "filepattern user pass cwd".split()
ftp_lambda   = curry(getkey, 'ftp_in')
ftp_cmd_vals = map(ftp_lambda, ftp_cfg_keys)
print ftp_cmd_vals
# the !!! should be filled in with the globally configured FTP server
# but I refuse to play telepathic guru and point to the source directly
# if I have to write this over and use pure Python OO instead of a
# config module then so be it
ftp_cmd  = "mget %s | ftp -i ftp://%s:[EMAIL PROTECTED]/%s" % 
tuple(ftp_cmd_vals)
print ftp_cmd
os.system(ftp_cmd)
sys.exit()


Aside


When it comes to HTML generation, every form of mini-language that I've
seen does not appeal to me. I use DOM to rewrite HTML. I hate the
limitations of mini-languages and prefer full-strength programming
languages. Now it is appearing that application configuration is yet
one more place to avoid mini-language convenience and simply use a
programming language for the task.

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


should urlparse return user and pass in separate components?

2006-09-07 Thread metaperl
The urlparse with Python 2.4.3 includes the user and pass in the site
aspect of its parse:

>>> scheme, site, path, parms, query, fid = 
>>> urlparse.urlparse("http://bill:[EMAIL PROTECTED]/lib/module-urlparse.html")

>>> site
'bill:[EMAIL PROTECTED]'


I personally would prefer that it be broken down a bit further. What
are existing opinions on this?

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


the first arg to super() must be a type, not a class obj?

2006-09-07 Thread metaperl
On p.282 of "Python Cookbook" and in the Python docs on calling super:
http://www.python.org/download/releases/2.2.3/descrintro/#cooperation

it is clear that the first argument to super is a class and not a type.
However, for the code below, I am getting an error when attempting to
provide a class as my first argument and don't understand why. Also,
since this is my first attempt at writing anything of any seriousness
in Python, any other feedback is welcome.

from ftputil import *
import re

from urlparse import urlparse

class ftputilx(FTPHost):
parms = {
'user': '',
'pass': '',
'site': '',
'path': '',
'file': '',
'action': '',
'lcd': '',
'autogo': True,
'debuglevel': 0,
'type': 'b'
}

def bindparms(self, **kwargs):
for k, v in kwargs.items():
self.parms[k] = v

def __init__(self, url, **kwargs):
_s, site, self.parms['path'], _p, _q, _f = urlparse(url)
if '@' in site:
rxs = r'(.+):(.+)@(.+)'
rxc = re.compile(rxs)
rxm = rxc.match(site)
(kwargs['user'],kwargs['pass'],kwargs['site']) =
rxm.group(1), rxm.group(2), rxm.group(3)
self.bindparms(**kwargs)
super(ftputilx, self).__init__()


if __name__ == '__main__':
ftp =
ftputilx("ftp://anonymous:[EMAIL PROTECTED]/pub/linux/")
print ftp.listdir(ftp.curdir)

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


How to get the package, file, and line of a method/function invocant?

2006-09-11 Thread metaperl
I am looking for something like the caller() routine in Perl:
   http://perldoc.perl.org/functions/caller.html

I am writing a script which needs to be allocated an object containing
a set of paths that it will use for reading and writing during it's
execution:

import os.path

class logic:
def __init__(self):
std_dirs = "in out zip arc".split()
self.root = os.path.dirname(__main__.__file__) # doesnt work
for d in std_dirs:
mkdir = "%s/%s" % (self.root, d)
os.mkdir(mkdir)
setattr(self, d, mkdir)


# Then the script can do this:

directories = data.storage.logic()
infile = "%s/%s" % (directories.in, "infile")
f = open (infile, 'r')

# Of course I could cheat and pass it, but I don't want to:

directories = data.storage.logic(__file__)

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


A Comparison of Python Class Objects and Init Files for Program Configuration

2006-09-12 Thread metaperl
A Comparison of Python Class Objects and Init Files for Program
Configuration
=

Terrence Brannon
[EMAIL PROTECTED]
http://www.livingcosmos.org/Members/sundevil/python/articles/a-comparison-of-python-class-objects-and-init-files-for-program-configuration/view



Abstract


Init files serve as a convenient mini-language for configuring
applications. The advantages of such a mini-language are

* non-technical people can edit them.
* program behavior can be configured without modifying the source

The author `has always been suspicious of mini-languages
`_, initially in the context of
dynamic HTML generation.

This document provides a comparison of two approaches to program
development, the use of `a popular Python mini-language
`_ and the use of
`Python class objects `_.

The Problem Space
-

I work for a company that takes data in various formats (e.g., CSV,
XML, Filemaker) and integrates them all into our database. The 30 or
so scripts that did this were written in Perl. I was told to rewrite
them and elected to use Python.

The Initial Rewrite Using Init Files


In the initial version using config files, I used a generic config
file and specialized/overwrote its values with a local one::

  gconfig = ConfigObj("../generic.ini")
  cnf = ConfigObj("local.ini")
  cnf.merge(gconfig)

I then proceeded to login to an FTP server and check for a certain
file and download it if it existed::

  host = ftputil.FTPHost(cnf['ke_ftp']['host'],
   cnf['ke_ftp']['user'],
   cnf['ke_ftp']['pass'])

  host.chdir(cnf['ke_ftp']['cwd'])
  found = ""
  for f in host.listdir(host.curdir):
 if f.endswith( cnf['ke_ftp']['filepattern'] ):
found = f
print "Downloading", found
host.download(f, f, 'b')

  if found == "":
 print "No file with pattern", cnf['ke_ftp']['filepattern'], "on
server"
 sys.exit()

Now lets see the object-oriented configuration
--

Instead of generic and specialized config files, one would initially
think of using inheritance when going for an OO approach. However,
each program can get configuration information from a number of
places. As a result, HAS-A will work better than IS-A in this case::

 class config(object):

   # best to use has-a because we need config info from all over the
place
   import data.config.ke

   ke = data.config.ke.ftp()
   ke.user = 'dmsdatasystems'
   ke.password = 'sredna?'
   ke.cwd  = 'DMS/companies'
   ke.filepattern = 'companies.csv.gz'

   import data.config.snap
   snap = data.config.snap.ftp()


   """
   import data.storage
   storage = data.storage.logic()
   print dir(storage)
   sys.exit()"""

 class proc(object):

   def __init__(self):
  self.cnf = config()

   def fetch_file(self):
  host = ftputil.FTPHost(self.cnf.ke.host, self.cnf.ke.user,
 self.cnf.ke.password)
  host.chdir(self.cnf.ke.cwd)

  self.downloaded_file = ""
  for f in host.listdir(host.curdir):
 if f.endswith( self.cnf.ke.filepattern ):
self.downloaded_file = f
print "Downloading", f
host.download(f, f, 'b')
print "Downloaded", f

  if self.downloaded_file == "":
 print "No file with pattern", self.cnf.ke.filepattern, "on",
self.cnf.ke.host
 sys.exit()




Evaluation
==

Appearance
--

Accessing object attributes, IMHO, is much cleaner looking. Compare::

  config['munger']['outfile']

with::

  config.munger.outfile


One takes less characters to type and lacks the noisy quote marks
(that's one of the things I miss from Perl hashes - the ability to
index into hashes using bare words without quotes).

Power
-

A mini-language is a moving target. They tend to grow and grow over
time, adding more and more ad hoc semantics and peculiarities. I'm on
the ConfigObj mailing list and they are currently discussing how to
handle multi-line config values. In Python, one simply needs to break
out """ and you are done. This epitomizes why I prefer the shortcut
of library over mini-language. The library has the full power of a
widely used, widely debugged language while the mini-language has a
smaller user community and less man hours of development behind it.

Learning Curve
--

Again, once you learn Python, you can use it for configuration as well
as programming. And Python is a very readable, clean and regular
language - it doesn't look very different from a configuration
language.

The merits of studying the syntax and semantics of a configuration
language can possibly outweigh the benefits.


Maintenance
---

It is harder to hire people with a good background in

Re: How to get the package, file, and line of a method/function invocant?

2006-09-12 Thread metaperl

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, metaperl wrote:
>
> > # Of course I could cheat and pass it, but I don't want to:
> >
> > directories = data.storage.logic(__file__)
>
> Why do you consider a plain and simple solution cheating?

Hmm, I dont know the proper software engineering term, but just on the
basis of instinct, it seems wrong for a function to use something that
it can get on its own.

It's kind of like being at a 5-star hotel. It might be very possible
for you to bring your own pop tarts and toast them, but they go to
great lengths to have a continental buffet ready for you without you
doing anything.

Good question, airheaded answer :)

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


Re: How to get the package, file, and line of a method/function invocant?

2006-09-12 Thread metaperl

Miki wrote:
> > > I am looking for something like the caller() routine in Perl:
> > >http://perldoc.perl.org/functions/caller.html
> >
> > Look at the inspect module in Python's standard library.
> Or is you're feeling lazy, have a look at the "here" function found in
> http://www.unixreview.com/documents/s=9133/ur0404e/ur0404e_listing1.htm

Thanks for the link. I would've never figured out how to use inspect on
my own.

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


Re: How to get the package, file, and line of a method/function invocant?

2006-09-12 Thread metaperl

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, metaperl wrote:
>
> > # Of course I could cheat and pass it, but I don't want to:
> >
> > directories = data.storage.logic(__file__)
>
> Why do you consider a plain and simple solution cheating?
>

Ok now I figured it out. The reason is that this function will be used
by many "client" classes. If we use the plain and simple solution, our
codebase increases in size, because each client class will supply the
function. Not only that, but they might make an error in what they
send.

By having the "server" class do the work, the code base decreases in
size and the amount of errors drops.

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


Are Python's reserved words reserved in places they dont need to be?

2006-09-12 Thread metaperl
  -->  python -i
>>> class = "algebra"
  File "", line 1
class = "algebra"
  ^
SyntaxError: invalid syntax
>>>


Why isn' t the parser smart enough to see that class followed by an
identifier is used for class definition but class followed by equals is
a simple assignment?

Also, I had a bug where I tried to set the attributes "user" and "pass"
in an object but "pass" would not work because it is a reserved word.
Again pass should be reserved in certain contexts but not others.

Is Python 3k going to fix this sort of thing?

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


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-12 Thread metaperl

Istvan Albert wrote:
> metaperl wrote:
> > -->  python -i
> > >>> class = "algebra"
> >   File "", line 1
> > class = "algebra"
> >   ^
> > SyntaxError: invalid syntax
>
> Designing a syntax to avoid all possible newbie errors is impractical
> because as soon as you are finished with one iteration the new newbies
> will start making different kinds of errors...
>
> Take solace in the fact that you've been immediately notifed of the
> error while its fix: renaming pass to passwd is trivial ...

The error message is not very explicit - "class is a reserved word"
will make far more sense to a new programmer than SyntaxError.
Especially since the expression is rather innocent looking and
correct-looking.

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


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-12 Thread metaperl

Diez B. Roggisch wrote:
> metaperl schrieb:
> >   -->  python -i
> >>>> class = "algebra"
> >   File "", line 1
> > class = "algebra"
> >   ^
> > SyntaxError: invalid syntax
> >
> >
> > Why isn' t the parser smart enough to see that class followed by an

>  the few reserved words won't matter usually.

woe be unto the ORMs who try to map database columns to Python
attributes.

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


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-12 Thread metaperl

Istvan Albert wrote:
> metaperl wrote:
> > -->  python -i
> > >>> class = "algebra"
> >   File "", line 1
> > class = "algebra"
> >   ^
> > SyntaxError: invalid syntax
>
> Designing a syntax to avoid all possible newbie errors is impractical
> because as soon as you are finished with one iteration the new newbies
> will start making different kinds of errors...

You are missing the point: the point is that the above could be
considered correct if the rules of Python were that an assignment
statement takes
IDENTIFIER '=' LVALUE

Also  "class" IDENTIFIER COLON could also be considered correct.

>
> Take solace in the fact that you've been immediately notifed of the
> error while its fix: renaming pass to passwd is trivial ...

Again in certain automatic mapping circumstances (ORMs being the most
obvious, CSV to Python data another), it is not always convenient or
desirable or semantically articulate to do so. 

> 
> i.

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


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-13 Thread metaperl
One way to avoid the issue I brought up is for the syntax to be very
regular... like Lisp or Tcl:

set class "algebra"

(setq class "algebra")

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


Re: best small database?

2006-09-14 Thread metaperl

David Isaac wrote:
> Thanks to all for the suggestions and much else
> to think about.
>
> Summarizing:
>
> Those who were willing to consider a database suggested:
> anydbm
> Gadfly
> SQLite (included with Python 2.5)
> Schevo

You missed buzhug:
http://buzhug.sourceforge.net/

A very thorough pure Python database.

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


Re: Converting a varargs tuple to a list - a definite pitfall for new comers to Python

2006-09-15 Thread metaperl

Georg Brandl wrote:
> [EMAIL PROTECTED] wrote:
> > The following program does not work if you uncomment #lis =
> > ["xmms2"] + list(args)
> >
> > Evidently Python is opting for the nullary constructor list() as
> > opposed to the other one which takes a sequence. But no newcomer would
> > know this. And the Python docs dont give a good example of dealing with
> > taking a sequence of args and converting it to a list.
>
> Evidently you overlooked having defined a list() in global scope
> yourself which takes no arguments.

MASSIVELY overlooked it. Gosh. How embarrassing.

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


Re: Converting a varargs tuple to a list - a definite pitfall for new comers to Python

2006-09-15 Thread metaperl

John Machin wrote:
> [EMAIL PROTECTED] wrote:
> > The following program does not work if you uncomment #lis =
> > ["xmms2"] + list(args)
> >
> > Evidently Python is opting for the nullary constructor list() as
> > opposed to the other one which takes a sequence. But no newcomer would know 
> > this.
>
> Are you using "the nullary constructor list()" to mean "the 0-argument
> function list() that appears later in the script", and "the other one
> which takes a sequence" to mean the builtin function list()"???

No,  I'm talking about listing 2 here:
http://www-128.ibm.com/developerworks/library/os-python4/index.html

which states:
"If you look closely at the description for the list class in Listing
2, you'll see that two different constructors are provided. One takes
no arguments, and the other takes a sequence class."

and I figured that since the lower bound on arguments to *args could
zero, that Python was
default to the nullary constructor even before the function got its
args.

paranoia will do these things to you.


>
> >  And the Python docs dont give a good example of dealing with
> > taking a sequence of args and converting it to a list.
>
> You have produced 2 perfectly good examples yourself. What's your
> point?

I just mean that this:
http://docs.python.org/tut/node6.html#SECTION00673

does not use list() at all.



> Here's a tip: when you get into a pickle like that, try running
> pychecker and/or pylint over your code. Here's what pychecker has to
> say:
>
> metaperllist.py:4: Invalid arguments to (list), got 1, expected 0
> metaperllist.py:10: (list) shadows builtin


Great suggestion. I had not heard of those. Thanks.

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


Re: new string method in 2.5 (partition)

2006-09-19 Thread metaperl
sweet thanks for the heads up.

John Salerno wrote:
> Forgive my excitement, especially if you are already aware of this, but
> this seems like the kind of feature that is easily overlooked (yet could
> be very useful):
>
>
> Both 8-bit and Unicode strings have new partition(sep) and
> rpartition(sep) methods that simplify a common use case.
> The find(S) method is often used to get an index which is then used to
> slice the string and obtain the pieces that are before and after the
> separator. partition(sep) condenses this pattern into a single method
> call that returns a 3-tuple containing the substring before the
> separator, the separator itself, and the substring after the separator.
> If the separator isn't found, the first element of the tuple is the
> entire string and the other two elements are empty. rpartition(sep) also
> returns a 3-tuple but starts searching from the end of the string; the
> "r" stands for 'reverse'.
>
> Some examples:
>
>
>  >>> ('http://www.python.org').partition('://')
> ('http', '://', 'www.python.org')
>  >>> ('file:/usr/share/doc/index.html').partition('://')
> ('file:/usr/share/doc/index.html', '', '')
>  >>> (u'Subject: a quick question').partition(':')
> (u'Subject', u':', u' a quick question')
>  >>> 'www.python.org'.rpartition('.')
> ('www.python', '.', 'org')
>  >>> 'www.python.org'.rpartition(':')
> ('', '', 'www.python.org')
>
> (Implemented by Fredrik Lundh following a suggestion by Raymond Hettinger.)

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


Application logging to screen and file - any favorite modules (no luck on cheeseshop)

2006-09-22 Thread metaperl
Hello, I am looking for a module which has
* log levels
* output to stdout and file (either/or based on config)
* nicely formatted log output (e.g., indentation when appropriate)

I tried to use cheeseshop to find such a module, but came up short. I
clicked on
Browse Tree -> Software Development but then did not see a subcategory
for logging, so did not know where to look. I then typed log into the
search box, but that didn't really turn up the modules which had login
their description so I posted here.

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


Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)

2006-09-23 Thread metaperl

Robert Kern wrote:
> metaperl wrote:
> > Hello, I am looking for a module which has

>
> You should look in the standard library before hitting the Package Index.
>
> http://www.python.org/doc/current/lib/module-logging.html
>

Very nice module. Thanks for the pointer.

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


Re: One program in different GUI Toolkits

2006-09-23 Thread metaperl

Franz Steinhaeusler wrote:
> Hello NG,
>
> I have a suggestion.
>
> For simplifying learning or switching between different GUI
> Toolkits, I could imagine to have one short clearly presented
> program in different GUI Toolkits.

>
> Anybody is interested in implementing in one other GUI?
> We could put in on one Python wiki page for example.
>

Thanks to your post, I have fallen in love with PythonCard. I would be
happy to try to implement what you want in that.

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


Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)

2006-09-23 Thread metaperl

Bjoern Schliessmann wrote:
> metaperl wrote:
>
> > Hello, I am looking for a module which has
> > * log levels
> > * output to stdout and file (either/or based on config)
> > * nicely formatted log output (e.g., indentation when appropriate)
>
> Sorry for being nosey, but how'd you use indentation in a log?

I guess I was thinking more along the lines of debugging. For example,
if you have two nested loops, you can increase the indentation level of
output as you move into each loop to show where the output is coming
from.

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


Leave the putdowns in the Perl community, the Python world does not need them

2006-09-25 Thread metaperl
I was shocked to see the personal insults hurled in this thread:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/d0758cb9545cad4b

I have been very pleased with Python developers regardless of skill
levels in both the IRC channel as well as here - no hot attitudes. No
holier than thou put ons. I was just sinking into the comradery and
cooperative nature of this new powerful community when I saw that
thread.

Well, I hope that the fact that 99% of the Python community, from Guido
von Rossum on down continues to exemplify how a language can be good
and the people can be friendly and that the other 1% get inspired by
their positivity and switch as well...

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


Re: One program in different GUI Toolkits

2006-09-25 Thread metaperl

Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
> > Actually due to lack of documentation and feedback from the mailing
> > list, I am fallen out of love with Pythoncard and in love with
> > Kiwi/Pygtk. Given the large groundswell support for pygtk, i dont think
> > I will be disappointed.
>
> >
> In and out of love in eight hours and six minutes? I'm glad I don't have
> a daughter ;-)

heheh... I am rather mercurial (oops, no pun intended). I have never
held a job in the IT industry for a year in 7 years of professional
work: http://www.metaperl.com

But I just found out I get a 4-month penalty if I break my current
condo lease, so for once, I think I will stay put for a year.

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


Re: One program in different GUI Toolkits

2006-09-25 Thread metaperl

Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
> > Actually due to lack of documentation and feedback from the mailing
> > list, I am fallen out of love with Pythoncard and in love with
> > Kiwi/Pygtk. Given the large groundswell support for pygtk, i dont think
> > I will be disappointed.
>
> >
> In and out of love in eight hours and six minutes? I'm glad I don't have
> a daughter ;-)

heheh... I am rather mercurial (oops, no pun intended). I have never
held a job in the IT industry for a year in 7 years of professional
work: http://www.metaperl.com

But I just found out I get a 4-month penalty if I break my current
condo lease, so for once, I think I will stay put for a year.

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


Re: Converting Perl Web Report to Python

2006-09-25 Thread metaperl

[EMAIL PROTECTED] wrote:
> Thanks again Dennis,
> This should do what I want with additional flexibility...  I will
> develop the code later this week.   During this excersize, I have come
> to really appreciate Python over Perl.  I love the Python command line
> interpreter that allowed me to pretest any code very quickly.  What
> Python learning resource (book web link or both) do you recommend?

I have 3 O'Reilly books that are indispensable: "Python Pocket
Reference", "Python Cookbook", and "Learning Python"

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


startswith() and endswith() for re's would be more intuitive

2006-09-28 Thread metaperl
I just finished answering a question in #python because someone tried
to match using ... well.. match()
but did not realize that match() is actually startswith() for regexps.

I suggest:
re.compile('blah').atstartof(string)
re.compile('blah').atendof(string)

But it will never happen.

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


Re: startswith() and endswith() for re's would be more intuitive

2006-09-28 Thread metaperl

Bruno Desthuilliers wrote:
> metaperl wrote:
> > I just finished answering a question in #python because someone tried
> > to match using ... well.. match()
> > but did not realize that match() is actually startswith() for regexps.
>
> Yet someone else that failed to read the Fine Manual(tm).
>
> > I suggest:
> > re.compile('blah').atstartof(string)
> > re.compile('blah').atendof(string)
>
> What's wrong with:
> re.search(r'^blah', somestring)
> re.search(r'blah$', somestring)

Nothing. There is also nothing wrong with

re.match('blah', somestring)

but it does read as well as

re.atstartof('blah', something)

and the counterpart for EOS is not there.

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


Re: for: else: - any practical uses for the else clause?

2006-09-29 Thread metaperl
Actually right after posting this I came up with a great usage. I use
meld3 for my Python based dynamic HTML generation. Whenever I plan to
loop over a tree section I use a for loop, but if there is no data to
iterate over, then I simply remove that section from the tree or
populate it with a "no data" message.

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


Re: Generating header information using ElementTree

2006-11-27 Thread metaperl
And dont forget that you can use triple quotes to get rid of all the
quote-escaping you are using:

$ python
>>> """
... 
... ho
... 
... """
'\n\nho\n\n'
>>>


Craig wrote:
> John Machin wrote:
>
> > Craig wrote:
> >
> > > Great.  Got that sorted.  The problem I have now is that some of the
> > > XML data is not copied across to the file when I have the text
> > > information included.  The number of characters that is lost is equal
> > > to the number of characters that is in the block of text I entered
> > > before.  The code I am using is:
> > >
> > > def WriteXMLRecord ( record, XMLFileBaseName, root):
> > > RecordName = SubElement(root, "Log")
> > > #iterate through all the fields in the record
> > > for key in record:
> > > # write the key and its data
> > > test = SubElement(RecordName, key)
> > > test.text = str(record[key])
> > > tree = ElementTree(root)
> > > tree.write(XMLFileBaseName)
> >
> > I'm guessing, based on reading the docs for the write method, that you
> > should be using the file handle, rather than the file name, if the file
> > is already opened. So (1) change the name of the 2nd arg to
> > XMLFileHandle or somesuch, and in the caller, use outFile (the handle)
> > instead of "record.xml".
> >
> > >
> > > def main():
> > > outFile = open("record.xml", 'w')
> > > outFile.write("""
> > > 
> > > \n\n""")
> > >
> > > root = Element("Log")
> > > WriteXMLRecord(data1, "record.xml", root)
> > > WriteXMLRecord(data2, "record.xml", root)
> > > WriteXMLRecord(data3, "record.xml", root)
> > > outFile.close()
> > >
> > HTH,
> > John
> 
> Great.  Got it.  Thanks so much for all your help.
> 
> 
> Craig

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


shell command needs whitespace characters escaped

2006-12-08 Thread metaperl
I downloaded a file which has a space in the filename. I want to run a
shell unzip on it, but it fails in my current code:

syscmd = "cd %s ; unzip %s" % (self.storage.input,
file.basename())
os.system(syscmd)

because no escaping was done.

Is there a more principled way to construct a shell command and execute
it so that all necessary characters are escaped?

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


Encapsulating conditional execution based on list membership - how do you do it?

2006-12-11 Thread metaperl
I have a series of scripts which retrieve files. None of these scripts
should continue if the file to be retrieved already exists in the
archive. Here is the code:

if f in path(self.storage.archive).files('*'):
print f, "exists in archive. Not continuing"
sys.exit()


self.storage is a class which gives me object-oriented access to the
filesystem directories that will be manipulated by the script. E.g.
self.storage.archive is a string which refers to a certain directory.
Initializing this object initializes all the members (input, archive,
output, workfiles) and makes all the correct directories.

ok, so I'm thinking of adding a method to the storage class so I can do
this:

self.storage.archive_has(f, print_msg=True) and sys.exit()

but really there is no need to hardcode which storage directory. So I'm
thinking:

self.storage.memberof('archive', f, print_msg=Tree) and sys.exit()


Is that the best solution you can think of?

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


Pythonic style involves lots of lightweight classes (for me)

2006-12-13 Thread metaperl
I find it arduous to type dictionary['key'] and also feel that any data
I create for a program deserves to have its operations tied to it. As a
result, I often create lots of lightweight classes. Here's a small
example:


vlc = '/Applications/VLC.app/Contents/MacOS/VLC'

class song(object):
def __init__(self, title, url):
self.title = title
self.url   = url



urls = [
song(title='breath',
 url='mms://ra.colo.idt.net/ginsburgh/eng/med/breath.mp3'),
song(title='waking',
 url= 'mms://ra.colo.idt.net/ginsburgh/eng/med/modeh.mp3')
]

for url in urls:
print url.title


 The above program started out as a list of dictionaries, but I
like the current approach much better.

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


Seeking author of script which generated HTML pages from pictures of them

2007-05-17 Thread metaperl
On reddit.com, many moons ago, I downloaded some code which generated
a page using HTML tables from a picture of the page you wanted.
However, I dont have any author information in the code and wanted to
stay in touch which she/he... does anyone know who wrote this code
below?

# Box geometry.

class Box(object):
def __init__(self, x, y, right, bottom):
self.x, self.y, self.right, self.bottom = x, y, right, bottom

def box_x_delimeters(boxes):
return sorted(set(box.right for box in boxes))

def box_y_delimiters(boxes):
return sorted(set(box.bottom for box in boxes))

def box_rowspans(boxes):
rowspans = dict((box, 0) for box in boxes)
for delim in box_y_delimiters(boxes):
for box in boxes:
if box.y < delim and box.bottom >= delim:
rowspans[box] += 1
return rowspans

def box_colspans(boxes):
colspans = dict((box, 0) for box in boxes)
for delim in box_x_delimeters(boxes):
for box in boxes:
if box.x < delim and box.right >= delim:
colspans[box] += 1
return colspans

def box_rows(boxes):
rows, boxes_left = [], set(boxes)
for delim in box_y_delimiters(boxes):
boxes_in_row = set(box for box in boxes_left if box.y < delim)
boxes_left -= boxes_in_row
rows.append(sorted(boxes_in_row, key=lambda box: box.x))
return rows

# Rendering and parsing tables.

def render_html_table(boxes):
rowspans, colspans = box_rowspans(boxes), box_colspans(boxes)
table = '\n'
for row in box_rows(boxes):
table += '  \n'
for box in row:
table += '%s\n' %
(rowspans[box], colspans[box], 'blank' * (box.bottom - box.y))
table += '  \n'
table += '\n'
return table

def parse_ascii_table(table):
def char(x, y):
if 0 <= y < len(grid) and 0 <= x < len(grid[y]):
return grid[y][x]
else:
return " "

def box_right(x, y):
for right in range(x, len(grid[y + 1])):
if char(right + 1, y + 1) == '|':
return right
raise RuntimeError("Unterminated box.")

def box_bottom(x, y):
for bottom in range(y, len(grid)):
if char(x + 1, bottom + 1) == '-':
return bottom
raise RuntimeError("Unterminated box.")

grid = table.splitlines()
boxes = []
for y in range(len(grid)):
for x in range(len(grid[y])):
if char(x, y) in ('-', '|') and char(x, y + 1) == '|' and
char(x + 1, y) == '-':
boxes.append(Box(x, y, box_right(x, y), box_bottom(x,
y)))
return boxes

# Tests.

table = \
"""
-
| adsafasf
| |
|
| |
|
| |
-
|
| |
|
| |
|
| |
-
|
| |
|
| |
|
| |
-
"""

open("test.html", "w").write('\n\n%s\n\n' %
(render_html_table(parse_ascii_table(table)),))

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


Re: Seeking author of script which generated HTML pages from pictures of them

2007-05-29 Thread metaperl
I found him!

http://programming.reddit.com/info/k9dx/comments


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


most complete xml package for Python?

2007-03-13 Thread metaperl
Without even checking them all out, I'm thinking the Amara XML Toolkit
must be the most feature-packed. The developers are readily available
on IRC for support and they seem to make regular releases.

As a meld3 user, I have been using ElementTree under the hood, but was
dismayed to find out that you can't find elements by attribute and I
am finding it difficult to remove elements.

So I am out shopping for a new friend to grok XML.

Input welcome.

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


Re: most complete xml package for Python?

2007-03-14 Thread metaperl
On Mar 14, 5:34 pm, "John Machin" <[EMAIL PROTECTED]> wrote:


>
> Given keywords like "Amara" and "Elementtree" and past history, it
> looked to me like a troll of one kind trying to incite a troll of
> another kind to pop out from under the bridge and chew on his
> ankle :-)

Well, I'm not a troll. And I am now even less impressed with
ElementTree. It does not preserve the document but reforms it in
certain cases.



gets rewritten as



which leads to problems when embedding Dojo Rich Text Editors.


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


ValueError from dict - some detail would be helpful

2007-01-11 Thread metaperl
  File "/sw/lib/python2.5/csv.py", line 120, in _dict_to_list
raise ValueError, "dict contains fields not in fieldnames"


--- it would be nice if it said what field it was

I know that I can do a set difference on the two myself, but since it
know what wasn't there.. why not report it and save me some time?

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


Re: PyMeld for html templates?

2007-01-19 Thread metaperl

Sean Schertell wrote:


>
> Of course I'm going to try them all but I wonder if anyone has any
> thoughts on PyMeld as a template system for churning out general
> websites?
>

meld3 evolved from pymeld. I use meld3 -
http://plope.com/software/meld3/
this whole style of templating is known as push-style (coined by
Terence Parr). Most systems are pull-style.


> sorted. But how about PyMeld, any ideas on how to do it or whether it
> will even work as I've described?
>

the meat and bread problem: each page has meat and you want to wrap it
with some standard bread. it's a basic tree rewrite and since meld3
uses ElementTree underneath, it is a piece of cake.

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


Re-thinking my if-thens - a software engineering question

2007-01-24 Thread metaperl
Ok, I have a module called textgen.py. The point of this module is to
generate a csv file from an array of dictionaries. As I iterate through
each dictionary, I "massage" the dictionary values before writing them
out to csv. Now, for one dictionary entry, I have the following code:

if dict_key == 'PCN':
fields = dict_val.split("/")
mo = re.match( '(\w{2})(\d{2})(\d{2})' , fields[1] )
if mo:
dict_val = "%s/%s%s/%s" % (fields[0], mo.group(1), 
mo.group(3),
fields[2][1:])
else:
dict_val = dict_val

Ok, so now here is what has happened. This code was based on the
assumption that dict_val would have 2 forward slashes in it. It turns
out that I need to follow a different process of massaging when no
slashes are present. A naive solution would be something like:

if dict_key == 'PCN':
fields = dict_val.split("/")
if fields == 3:
dict_val = pcn_three(fields) # where pcn_three
is the code above
else:
# new logic

But I am wondering if I should abstract the flow of control into a
class or something.

Ideas welcome.

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


"flushing"/demanding generator contents - implications for injection of control

2007-02-05 Thread metaperl
For this program:

def reverse(data):
for index in range(len(data)-1, -1, -1):
yield data[index]

r = reverse("golf")

for char in r:
print char


I'm wondering if the line:

r = reverse("golf")

"demands" the contents of the function reverse() all at once and if I
must write

for char in reverse("golf"):
print char

if I want the results streamed instead of generated complely.

** CONTEXT **

The simple example above is not what I am really doing. My real
program parses very large
data files using pyparsing. Pyparsing can generate incremental/yielded
results with no problem:

http://pyparsing.wikispaces.com/message/view/home/248539#248852

but because I believe in injection of control (pushing data around as
opposed to having
the target pull it), I get the parse and then inject it into the
generator:

parse = parsing.parse(fp.read())
txt = textgen.generate(self.storage.output, patent_key,
parse, f.basename(), debug=False)

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


Re: "flushing"/demanding generator contents - implications for injection of control

2007-02-06 Thread metaperl
On Feb 5, 3:08 pm, Jussi Salmela <[EMAIL PROTECTED]> wrote:
> metaperl kirjoitti:
>
> > For this program:
>
> > def reverse(data):
> > for index in range(len(data)-1, -1, -1):
> > yield data[index]
>
> > r = reverse("golf")
>
> > for char in r:
> > print char
>
> > I'm wondering if the line:
>
> > r = reverse("golf")
>
> > "demands" the contents of the function reverse() all at once and if I
> > must write
>
> > for char in reverse("golf"):
> > print char
>
> > if I want the results streamed instead of generated complely.
>
> > ** CONTEXT **
>
> > The simple example above is not what I am really doing. My real
> > program parses very large
> > data files using pyparsing. Pyparsing can generate incremental/yielded
> > results with no problem:
>
> >http://pyparsing.wikispaces.com/message/view/home/248539#248852
>
> > but because I believe in injection of control (pushing data around as
> > opposed to having
> > the target pull it), I get the parse and then inject it into the
> > generator:
>
> > parse = parsing.parse(fp.read())
> > txt = textgen.generate(self.storage.output, patent_key,
> > parse, f.basename(), debug=False)
>
> I don't know, I'm guessing:
>
> ... r = reverse("golf")
> ... type(r)
> 

very slick! thanks!

> ... print r.next()
> f
>
> So r is not the string 'flog', it is the generator producing it
>
> HTH,

It does!

> Jussi


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


Re: Parsing HTML

2007-02-08 Thread metaperl
On Feb 8, 2:38 pm, "mtuller" <[EMAIL PROTECTED]> wrote:
> I am trying to parse a webpage and extract information.

BeautifulSoup is a great Python module for this purpose:

http://www.crummy.com/software/BeautifulSoup/

Here's an article on screen scraping using it:


http://iwiwdsmi.blogspot.com/2007/01/how-to-use-python-and-beautiful-soup-to.html

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


Latest approach to controlling non-printable / multi-byte characters

2007-02-08 Thread metaperl
There is no end to the number of frantic pleas for help with
characters in the realm beyond ASCII.

However, in searching thru them, I do not see a workable approach to
changing them into other things.

I am dealing with a file and in my Emacs editor, I see "MASSACHUSETTS-
AMHERST" ... in other words, there is a dash between MASSACHUSETTS and
AMHERST.

However, if I do a grep for the text the shell returns this:

MASSACHUSETTS–AMHERST

and od -tc returns this:

540O   F   M   A   S   S   A   C   H   U   S   E   T
T
560S 342 200 223   A   M   H   E   R   S   T   ;   U   N
I


So, the conclusion is the "dash" is actually 3 octal characters. My
goal is to take those 3 octal characters and convert them to an ascii
dash. Any idea how I might write such a filter? The closest I have got
it:

unicodedata.normalize('NFKD', s).encode('ASCII', 'replace')

but that puts a question mark there.

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


The decentralized nature of the Python community is driving me crazy

2006-08-09 Thread metaperl . bzr
hi everyone,

I am the first of what may be hundreds of refugees from the Perl
community. Not only is Python a more productive language, with many
more nice apps, but the people are friendly as well... waaay more
friendly than the Perl crowd.

But I must say the one thing I miss about Perl is my ability to stay on
top of all the latest modules and apps in one place: CPAN. With Python,
code is EVERYWHERE - people's local boxes, sourceforge, freshmeat,
codezoo, parnassus, etc, etc. Different approaches to documentation. A
much nicer install utility (python setup.py install r0x). But I am
finding it hard to keep on top and browse all the wares that are out
there because they are literally all over the net!

And then you have discussion and yet again, there is no perlmonks.org
for Python. We have this, IRC, and what else?

So, I guess this is my way of letting you know how lost I feel about
this de-centralized community. Dont get me wrong. I'm glad to be part
but I was thinking it would be nice if there were a one-stop-shop for
all my chat and wares needs. But for now, I guess I need to just add
few more bookmarks to main places to keep on top of daily besides
pythonware.com/daily.

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


OS X and Python - wxPython has forced a rehash of my approach

2006-09-04 Thread metaperl . etc
Earlier I asked about how people installed Python on OS X, given that
one can choose from Xcode, Fink, Darwin, ActiveState and source builds:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/5c4cde4206d1fbb7/37de06a6bb6b2361?lnk=gst&q=OS+X+and+Python+-+what+is+your+install+strategy%3F&rnum=1#37de06a6bb6b2361

but before I knew it, I had been sucked in by the ease and vastness of
the Fink repository.

Now my bliss run has come to a full halt due to these instructions at
`wxPython.org `_

Note to Fink users: Versions of Python installed by Fink cannot run
wxPython (unless you install and run X11...). You need to use Apple's
Framework builds, or a third-party Framework build.

And reading a bit further:

Python 2.4 Framework builds are available for download from the
undefined.org MacPython site. ActiveState also distributes a Framework
build.

So I guess I will look into a Framework build as my starting point.

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


Re: OS X and Python - wxPython has forced a rehash of my approach

2006-09-04 Thread metaperl . etc
One other thing: the mac os x built at python.org
(http://www.python.org/download/)

does not state whether it is a Framework build or not. I'm guessing it
isn't.

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


Converting a varargs tuple to a list - a definite pitfall for new comers to Python

2006-09-14 Thread metaperl . etc
The following program does not work if you uncomment #lis =
["xmms2"] + list(args)

Evidently Python is opting for the nullary constructor list() as
opposed to the other one which takes a sequence. But no newcomer would
know this. And the Python docs dont give a good example of dealing with
taking a sequence of args and converting it to a list.

I must've spent 40 minutes looking through my ora books, googling and
irc'ing in vane on this.

import subprocess

def xmms2(*args):
#lis = ["xmms2"] + list(args)
lis = ["xmms2"] + [a for a in args]
output = subprocess.Popen(lis,
stdout=subprocess.PIPE).communicate()[0]
return output.splitlines()

def list():
lis = xmms2('list')
playtime_str = lis.pop()
(total, playtime, time_str) = playtime_str.split()
(h,m,s) = time_str.split(':')
lis.pop()
return dict( playlist = lis, playtime = (int(h), int(m), int(s)) )

if __name__ == '__main__':
list()

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


Re: One program in different GUI Toolkits

2006-09-24 Thread metaperl . etc

Franz Steinhaeusler wrote:
> Hello NG,
>
> I have a suggestion.
>
> For simplifying learning or switching between different GUI
> Toolkits, I could imagine to have one short clearly presented
> program in different GUI Toolkits.
>
> What about for example wxProject?
>
> http://wiki.wxpython.org/index.cgi/WxProject
> or some other suggestion to take as base program.
> (could contain menus, buttons, listboxes, dialogs, ...)
>
> I would be very interested how it would looks in:
> wxPython
> pyGtk

Really one thing about pyGTK is that it has KIWI, which sits on top of
PyGtk and makes it very easy to use. Not to mention that it also has 2
GUI builders built on top of it, Glade and Gazpacho.

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


Re: One program in different GUI Toolkits

2006-09-24 Thread metaperl . etc
Actually due to lack of documentation and feedback from the mailing
list, I am fallen out of love with Pythoncard and in love with
Kiwi/Pygtk. Given the large groundswell support for pygtk, i dont think
I will be disappointed.

PyQT looks ultra-slick, but the commercial nature of QT and the design
tools gives me an icky feeling.

metaperl wrote:
> Franz Steinhaeusler wrote:
> > Hello NG,
> >
> > I have a suggestion.
> >
> > For simplifying learning or switching between different GUI
> > Toolkits, I could imagine to have one short clearly presented
> > program in different GUI Toolkits.
>
> >
> > Anybody is interested in implementing in one other GUI?
> > We could put in on one Python wiki page for example.
> >
>
> Thanks to your post, I have fallen in love with PythonCard. I would be
> happy to try to implement what you want in that.

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


Finding the file referred to in a Python traceback

2006-09-26 Thread metaperl . etc
In this traceback, the path to 3 different SQL Alchemy source files is
a relative directory. However, no such directory is below my current
working directory.

This is problematic for two reasons:
1 - I cannot use XEmacs find-file-at-point to find the file in which
the error is occurring
2 - I am not really sure where the source file is that is causing
problems because tha path could be relative to anything.

--- output ---

Traceback (most recent call last):
  File "", line 1, in ?
  File "conf/__init__.py", line 34, in __init__
self.table = tables(self.metadata)
  File "conf/__init__.py", line 38, in __init__
self.users = Table('Users', metadata, autoload=True)
  File "build/bdist.darwin-8.7.1-i386/egg/sqlalchemy/schema.py", line
138, in __call__
  File "build/bdist.darwin-8.7.1-i386/egg/sqlalchemy/engine/base.py",
line 495, in reflecttable
  File
"build/bdist.darwin-8.7.1-i386/egg/sqlalchemy/databases/mssql.py", line
426, in reflecttable
TypeError: __init__() takes at most 2 arguments (3 given)
>>> import sys
>>> print sys.path
['', '/sw/lib/python2.4/site-packages/Dabo-0.6.5s-py2.4.egg',
'/sw/lib/python2.4/site-packages/SQLAlchemy-0.2.8dev_r1898-py2.4.egg',
'/sw/lib/python24.zip', '/sw/lib/python2.4',
'/sw/lib/python2.4/plat-darwin', '/sw/lib/python2.4/plat-mac',
'/sw/lib/python2.4/plat-mac/lib-scriptpackages',
'/sw/lib/python2.4/lib-tk', '/sw/lib/python2.4/lib-dynload',
'/sw/lib/python2.4/site-packages',
'/sw/lib/python2.4/site-packages/Numeric',
'/sw/lib/python2.4/site-packages/PIL',
'/sw/lib/python2.4/site-packages/gtk-2.0',
'/sw/lib/python2.4/site-packages/pythonutils',
'/sw/lib/python2.4/site-packages/wx-2.6-gtk2-unicode']
>>>

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


for: else: - any practical uses for the else clause?

2006-09-26 Thread metaperl . etc
A very old thread:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/2c5022e2b7f05525/1542d2041257c47e?lnk=gst&q=for+else&rnum=9#1542d2041257c47e

discusses the optional "else:" clause of the for statement.

I'm wondering if anyone has ever found a practical use for the else
branch?

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


Re: Roundup Issue Tracker release 1.1.3

2006-10-04 Thread metaperl . etc

Richard Jones wrote:
> I'm proud to release version 1.1.3 of Roundup.
> five database back-ends (anydbm, sqlite, metakit,
> mysql and postgresql).

That ORM is pretty impressive:
http://roundup.sourceforge.net/doc-1.0/design.html#roundup-database

I like how easy it is to specify m-to-n relations.

Is it possible to have a table with a multi-column primary key?

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