[Tutor] Paradox table
yaipa
yaipa at aol.com
Fri Sep 13 04:19:44 EDT 2002
montana <sarmxiii at knology.net> wrote in message news:<mailman.1031848942.4346.python-list at python.org>...
> Is there a good example on how to use a CSV parser in Python?
> So you have this comma seperated file, does the CSV parser break data
> up into groups based upon where they are positioned in the file or does
> it just generate a list of data or both?
>
> Is there any good sites out there that deal with CSV parsing and python
> that have some good examples or can someone on this list give some?
>
> Thanks.
>
> SA
>
> "I can do everything on my Mac I used to do on my PC, plus alot more
> ..."
> --Me
>
> On Thursday, September 12, 2002, at 09:35 AM, Derrick 'dman' Hudson
> wrote:
>
> > On Wed, Sep 11, 2002 at 03:14:30PM +0200, A wrote:
> > | Hi,
> > | Is there a module for reading Paradox database (.DB) files with
> Python?
> > | I need to run the script under Linux, so I can not use ODBC.
> > | Any suggestion would be appreciated
> >
> > One way to access the data is to export it from paradox in CSV format.
> > CSV is an open standard and several (python) parsers exist for it.
> > However, using this method won't allow you to easily access the data
> > from both paradox and from your script, instead you would need to
> > re-export it every time you modified it in paradox and you would not
> > be able to modify it using your script. If you can, it would probably
> > be easiest to migrate to a different db such as postgresql. Postgres
> > databases are much more accessible than paradox is (at least with the
> > paradox version I've seen, 3.5).
> >
> > -D
> >
> > --
> > Dishonest money dwindles away,
> > but he who gathers money little by little makes it grow.
> > Proverbs 13:11
> >
> > http://dman.ddts.net/~dman/
> > <mime-attachment>
Not sure if this is what you are looking for, but maybe this...
--- <snip> --- <snip> --- <snip> --- <snip> --- <snip> ---
#! /usr/local/bin/python
def cfgLstToLst(_cfgTags = [], tokenSeparator = None):
# Note: If tokens are separated by whitespace ONLY
# (whitespace includes newlines)
# then leave tokenSeparator == None.
_cfgTagList = []
for _i in _cfgTags:
# split the string at the newline char(s)
# while consuming the newline char
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_cfgTagList = _cfgTags.split("\n")
# Rejoin the list into one string w/o
# newline char(s).
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_cfgTags = " ".join(_cfgTagList)
# split the string once more and remove
# the commas. Presto! We now have
# a list of tags. We will strip the
# whitespace from each element next.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if None:
# do Nothing
pass
else:
_cfgTagList = _cfgTags.split(tokenSeparator)
# This is a List Comprehension.
# The function of THIS list comprehension is to
# strip each list element of whitespace.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_cfgTagList = [item.strip() for item in _cfgTagList]
if _cfgTagList:
# remove any empty list items, [''], we may have
# picked up.
_cfgTagList = [_x for _x in _cfgTagList if _x ]
del _x
return _cfgTagList
if __name__ == "__main__":
# turn a string of comma seperated tokens
# into a python list.
data = "this, that, the, other,"
print data
print cfgLstToLst(data, ",")
--- <snip> --- <snip> --- <snip> --- <snip> --- <snip> ---
Viking1% cfgLstToLst.py
>> this, that, the, other,
>> ['this', 'that', 'the', 'other']
Viking1%
More information about the Python-list
mailing list