Dynamically creating properties?

2011-10-27 Thread Andy Dingley
I have some XML, with a variable and somewhat unknown structure. I'd
like to encapsulate this in a Python class and expose the text of the
elements within as properties.

How can I dynamically generate properties (or methods) and add them to
my class?  I can easily produce a dictionary of the required element
names and their text values, but how do I create new properties at run
time?

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


Re: SVN access with pysvn under Cygwin (Installation problems)

2008-07-31 Thread Andy Dingley
On 30 Jul, 20:30, Jason Tishler [EMAIL PROTECTED] wrote:

 You need to build (and install) pysvn under Cygwin.  The pre-built
 Windows version will not work under Cygwin.

Thanks. Presumably this same problem would affect anything that uses
a .pyd under Cygwin?
--
http://mail.python.org/mailman/listinfo/python-list


SVN access with pysvn under Cygwin (Installation problems)

2008-07-30 Thread Andy Dingley
I'm building Python tools to wrap up access to our Subversion / SVN
source control system. It's to run on my desktop (Cygwin under Windows
XP) and then later under Redhat.

Trying to install the pysvn module I'm running into problems getting
it to work under Cygwin. Works fine from a Windows command prompt,
with both the svn_cmd.py example and my own Python code. Under Cygwin
though I just get import failures. pysvn/__init__.py   seems to be
invoked happily enough, but then fails when it tries to import
_pysvn_2_5.pyd

$ python svn_cmd.py
Traceback (most recent call last):
  File svn_cmd.py, line 10, in module
import pysvn
  File /usr/lib/python2.5/pysvn/__init__.py, line 104, in module
import _pysvn_2_5
ImportError: No module named _pysvn_2_5

Is there some trick to getting .pyd to work under Cygwin?  I've tried
the obvious twiddling with environment variables (and regedit), but
I'm just guessing blindly.

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


Using doctest with simple text files ?

2007-06-08 Thread Andy Dingley
I have a problem involving lots of simple text files (Java properties
files), for which I'm building Python tools to manage their contents.

I'm also writing lots of Python modules and using doctest to embed
unit tests within them. Maintenance and shhared code ownership is an
issue here.

What's the best way to test my file modification operations, within
the context of doctest-like testing?  I like the simple immediacy of
doctest and it's working well for my in-Python testing, but I can't
seem to find a simple way of integrating it with the resultant text
files (e.g. something like diff)

Thanks

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Andy Dingley
On 26 Mar, 14:20, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 what are the advantages of using Python for
 creating number crunching apps over Fortran??

If you have to ask, you've not experienced enough Fortran to know its
sheer horror.

You can write programs in Python that do usefully complicated things,
and you can get them to work in a reasonable time. Fortran can't do
this, for anything more than the trivial. Classic Fortran tasks of
the past are now seen as trivial. OK, so they did it to a lot of data,
but they really didn't do anything very complex to it.

You can also write Python that other people can read and maintain. You
can't do this in Fortran, without a truly insane amount of trouble. As
Fortran programs have historically been authored and hacked on by
successive generations of grad students, this is the most vital
feature of all.

Finally we're no longer so interested in number crunching. Number
crunching used to consist of simple operations over vast arrays of
data, although this was data with remarkably simple structure by
today's standards. These just aren't the major class of problems of
interest today. There's a massive difference between old-school FEA
(bashing Newton and Hooke into tinier and tinier cells) and
bioinformatics or anything involving the representation of big data
graphs.

 Python is a tad slower than Fortran

If the Fortran program turns out to have been broken all along, then
who cares?

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


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Andy Dingley
On 16 Feb, 21:22, [EMAIL PROTECTED] wrote:
 I am VB6 programmer and wants to start new programming language

Why?  What is causing you to do this, and what do you need to achieve
by doing it?

 i want to go through with GUI based programming language like VB.net

GUI-based is fairly unimportant as it's just how you build your
programs, not what they do afterwards. VB is GUI-based, Python can be
GUI-based but is usually fairly text-based.

What's probably more significant here is whether the resulting program
runs in a GUI or not. VB obviously does, on the Windows desktop. Java
also has a sizable market for cross-platform GUI applications. In many
ways Java is more capable than VB, but also far less easy to work with
for rapid simple applications (I'd take 10 year old VB over GridBag
any time!).

GUI programs are less important now than they were a few years ago,
owing to the huge importance of the web and HTML. Although HTML can
still be seen as GUI, it really needs to be worked with at the raw
HTML source level (at least for quality work). This doesn't need any
sort of GUI built into the language, so Python (or Ruby or Perl) are
ideal.

With the rise of AJAX toolkits, we're finally seeing HTML as a GUI
turn into a workable choice for building sophisticated GUI apps in a
sensible amount of time. Finally!  The tools used here depend
significantly on the toolkits used and it's still early days to pick
winners.

If I had to write Windows-only desktop GUI apps, then I'd stick with
VB6 (which I wrote for years) or whatever M$oft decree to be its moral
successor. Actually I'd probably stick with VB6

If I had to write cross-platform GUI desktop apps, then I'd be looking
at whatever the favoured toolkit for Java is this week. Maybe Swing,
if I wanted to get a paid job using it. Java Web Start needs looking
at too.

If I just had to make a sophisiticated GUI app appear on a lot of
corporate desktops, then it would probably be based on Java Server
Faces.


For nearly all of the choices above, the language part of the task
is minor in comparison to tiresome GUI building. That's just the way
commerce works, and why we don't all get to write everything in Scheme
or Haskell.


If I had a free hand in writing better shell scripts, or in writing
moderately complex algorithms with no visible UI, then I have chosen
Python. It beats the hell out of Perl and is (AFAICS) better than
Ruby.

For building web reporting apps that generate HTML, then I'm also
choosing to use my sparse Python knowledge rather than my substantial
Java / JSP knowledge. Seems to be working so far.

For web-hosted GUI apps, I don't know enough about Python to say.
Doesn't look like it beats JSF though.


There's also the question of what OOP means. For the mainstream
languages, then classic statically-typed OO is done best by writing in
Java. This has a cleaner OOP language design than C++, the benefit of
a decade's hindsight and a clean slate.

Dynamically or duck-typed languages like Python and Ruby are quite
different from this. It's still OOP, but not how your uncle Bjarne
knew it. Quite a culture shock too.

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


Re: rot13 in a more Pythonic style?

2007-02-16 Thread Andy Dingley
On 14 Feb, 20:06, Beej [EMAIL PROTECTED] wrote:

 http://linuxgazette.net/109/pramode.html

Thanks, that's a _really_ interesting link   (Oh, I need to learn
Scheme!)

My code now looks like this, which I'm starting to feel much happier
about in a functional sense.


c_rot = lambda c, chars : (chr((ord(c) - ord(chars[0]) +
(len(chars) // 2)) % len(chars) + ord(chars[0])))

c_rot13 = lambda c : (((c, \
c_rot(c, string.ascii_uppercase)) [c in string.ascii_uppercase]),
\
c_rot(c, string.ascii_lowercase)) [c in string.ascii_lowercase]

rot13 = lambda s : string.join([ c_rot13(c) for c in s ],'')



I also considered this, but don't trust it as it relies on the two
sets being mutually disjoint between their inputs and outputs.

qc_rot = lambda c, chars : (c, c_rot(c, chars)) [c in chars]
c_rot13 = lambda c : (qc_rot( qc_rot(c, string.ascii_lowercase),
string.ascii_uppercase))


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


Re: rot13 in a more Pythonic style?

2007-02-15 Thread Andy Dingley
On 14 Feb, 21:59, Paul Rubin http://[EMAIL PROTECTED] wrote:

 Why don't you describe the actual problem instead of the rot13 analogy.

I don't know what the actual problem is! I need to perform a complex
mapping between old style structured identifiers and new style
structured identifers. As the original specification was never thought
through or written down anywhere, I'm now having to try and reverse-
engineer from 5 years of collected inconsistent practice. So far I
have about four pages of BNF to describe things and I'm still not sure
what's accurate, what's inaccurate spec and what's merely an error in
practice. Hopefully there's a neat little structure underlying it all
and a few typos I can merely ignore, but probably it really is just an
inconsistent structure that needs a lot of explicit tests around the
corner-cases to make sense of.

rot13 isn't the issue here, and I already know how to use .translate()
What I'm after is a tutorial of my Python coding style for an example
that's quite similar to the rot13 case.  Your previous posting was
very helpful here.

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


Re: rot13 in a more Pythonic style?

2007-02-15 Thread Andy Dingley
On 15 Feb, 17:55, Dennis Lee Bieber [EMAIL PROTECTED] wrote:

 Sounds more like a case for a parser/lexer wherein the emitted code
 tokens are the new style identifiers...

8-(I'm trying not to think about that

Fortunately I don't think it's _quite_ that bad.

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


rot13 in a more Pythonic style?

2007-02-14 Thread Andy Dingley
I'm trying to write rot13, but to do it in a better and more Pythonic
style than I'm currrently using. What would  you reckon to the
following pretty ugly thing?   How would you improve it?  In
particular, I don't like the way a three-way selection is done by
nesting two binary selections. Also I dislike stating the same
algorithm twice, but can't see how to parameterise them neatly.

Yes, I know of .encode() and .translate().
No, I don't actually need rot13 itself, it's just a convenient
substitute example for the real job-specific task.
No, I don't have to do it with lambdas, but it would be nice if the
final function was a lambda.


#!/bin/python
import string

lc_rot13 = lambda c : (chr((ord(c) - ord('a') + 13) % 26 + ord('a')))

uc_rot13 = lambda c : (chr((ord(c) - ord('A') + 13) % 26 + ord('A')))

c_rot13 = lambda c : (((c, uc_rot13(c)) [c in
'ABCDEFGHIJKLMNOPQRSTUVWXYZ']), lc_rot13(c) )[c in
'abcdefghijklmnopqrstuvwxyz']

rot13 = lambda s : string.join([ c_rot13(c) for c in s ],'')


print rot13( 'Sybevk Tenohaqnr, Fcyhaqvt ihe guevtt' )

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


Re: rot13 in a more Pythonic style?

2007-02-14 Thread Andy Dingley
On 14 Feb, 16:23, Neil Cerutti [EMAIL PROTECTED] wrote:

 str.translate is what I'd do.

That's what I hope to do too, but it might not be possible (for the
live, complex example). It looks as if I have to make a test, then
process the contents of the code differently depending. There might
well be a translation inside this, but I think I still have to have an
explicit 3-way switch in there.



 How would it being a lambda help you?

I'm going to use it in a context where that would make for cleaner
code. There's not much in it though.

I still don't understand what a lambda is _for_ in Python. I know what
they are, I know what the alternatives are, but I still haven't found
an instance where it permits something novel to be done that couldn't
be done otherwise (if maybe not so neatly).

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


Re: How can I access data from MS Access?

2007-02-06 Thread Andy Dingley
On 5 Feb, 19:40, Sells, Fred [EMAIL PROTECTED] wrote:

 Years ago we used to get our FORTRAN card decks back from the DP center
 with a piece of scrap paper saysing She No Work.  top that.

I used to use a cross-compiler (targetting some obscure single-chip
hardware) that had just a single error message

Diddley-squat somewhere near here

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


Re: How can I access data from MS Access?

2007-02-05 Thread Andy Dingley
On 3 Feb, 15:43, [EMAIL PROTECTED] wrote:
 How to access data from MS Access?

Can you access Access from Access ?  from Excel / Visual Basic / SQL
Query? First of all check that the DSN is working and connects to the
back end MDB. This might not be Python's problem.

Secondly check whatever errors you're being returned.

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


Python tools to manipulate JARs ?

2007-01-31 Thread Andy Dingley
I run build processes for a Java shop using Python (and some Ant).

Would anyone care to suggest favoured tools for manipulating the
innards of JARs? Or do I just treat them as plain zipfiles and get
stuck right in there?

Mainly I'm trying to query lists of classes and their embedded
versions and do some library dependency reporting. Performance speed
is starting to be an issue, as there's 1500+ classes in this bucket
and it's an interactive query.

Thanks for any suggestions

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


Re: program deployment

2007-01-05 Thread Andy Dingley
king kikapu wrote:

   Are they embarassed by their code?

 hehehe...no, just worried about stealing their ideas...

Ever heard of Open Source ?  I do better by letting other people
steal my ideas (and stealing theirs too) than I'd ever do by keeping
things secret.

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


Re: One module per class, bad idea?

2006-12-12 Thread Andy Dingley

Matias Jansson wrote:

 I come from a background of Java and C# where it is common practise to have
 one class per file in the file/project structure.

Don't confuse packages and files.  Java commonly splits a package
across many files, Python binds a module to a single file. If you see
Java package as more comparable to Python module then the
difference in how many classes are in a file becomes unimportant.

Java also puts many classes in the same source file, if they're tightly
coupled (e.g. Swing UI). It spits them out into separate .class files
though.

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


Re: dict.has_key(x) versus 'x in dict'

2006-12-06 Thread Andy Dingley

Paul Melis wrote:
 I've always been using the has_key() method to test if a dictionary
 contains a certain key. Recently I tried the same using 'in', e.g.

I've found using the set type to be the quickest way to do many of
these tasks. That leads me to another problem: how to cast / convert
sets as something else afterwards


What's the best (i.e. Pythonic) way to do this?
I need to generate a set (lots of intersections involved), but then I
need to display it sorted

lstBugsChanged = [ bugId for bugId in setBugsChanged ]
lstBugsChanged.sort()

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


Re: dict.has_key(x) versus 'x in dict'

2006-12-06 Thread Andy Dingley

Roberto Bonvallet wrote:

 lstBugsChanged = [ bugId for bugId in setBugsChanged ]

 In Python  2.4:

Hmmm. Thanks. Another reason to twist the admin's arm and get them to
upgrade the last 2.3.4 boxen


 sorted(setBugsChanged)

Out of interest, whats the Pythonic way to simply cast (sic) the set to
a list, assuming I don't need it sorted?  The list comprehension?

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


Re: rdf, xmp

2006-12-04 Thread Andy Dingley

Imbaud Pierre wrote:

 I have to add access to some XMP data to an existing python
 application.
 XMP is built on RDF,

I'm just looking at the XMP Spec from the Adobe SDK. First impressions
only, as I don't have time to read the whole thing in detail.

This spec doesn't inspire me with confidence as to its accuracy and
consistency. I think I've already seen some obscure conditions where
developers will be unable to unambiguously interpret the spec. Compared
to MPEG-7 however, at least it's not 700 pages long!

The spec does state that property values can be structured, which is
one of the best reasons to start using RDF for storing metadata.
However I think actual use of these would be minimal in typical XML
applicaations. At worst it's a simple data typing exercise of a
two-valued tuple for dimensions, rather than separate height and
width properties. These are no problem to process.

In particular, the XMP data model is a single-rooted tree, i.e. there
is an external model of a resource (i.e. one image file) and an XMP
document only addresses a single resource at a time.

A major restriction in XMP is that it has no concept of shared
resources between properties (and it can't, as there's no rdf:ID or
rdf:about allowed). This is always hard to process, but it's also very
valuable for doing metadata. Imagine a series of wildlife images that
all refer to a particular safari, national park and species. We might
be able to share a species reference between images easily enough by
referring to a well-known public vocabulary, but it would also be
useful (and concise) to be able to define one expedition in a subject
property on one image, then share that same resource to others. As it
is, we'd have to duplicate the full definition. Even in XMP's separate
document for each image resource model we still might wish to do
something similar, such as both photographer and director being the
same person.  When you start having 20MB+ of metadata per video
resource (been there, done that!) then this sort of duplication is a
huge problem. Not just because of the data volume, but because we need
to identify that referenced resources are identical, not merely havingg
the same in their property values (i.e. I'm the same John Smith, not
just two people with the same name).

There is no visible documentation of vocabularies, inetrnal or
external. Some pre-defined schemas are given that define property sets,
but there's nothing on the values of these, or how to describe that
values are being taken from a particular external vocabulary (you can
do this with RDF, but they don't describe it).  This isn't widely seen
as important, except by people who've already been through large media
annotation projects.

It's RDF-like, not just XML. However it's also a subset of RDF - in
particular rdf:about isn't supported, which removes many of the graph
structure constructs that make RDF such a pain to process with the
basic XML tools. Read their explicit not on which RDF features aren't
supported -- they're enough to make XMP easily processable with XSLT.

The notes on embedding of XMP in XML and XML in XMP are both simplistic
and ugly.

I still don't see much _point_ in XMP.  I could achieve all this much
with two cups of coffee, RDF and Dublin Core and a whiteboard pen.
Publishing metadata is good, publishing new _ways_ of publishing
metadata is very bad!


Overall, it could be far better, it could be better without being more
complicated, and it's at least 5 years behind industry best practice
for fields like museums and libraries. It's also a field that's still
so alien to media and creative industries that the poor description and
support of XMP will cause them to invent many bad architectures and
data models for a few years to come.

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


Re: rdf, xmp

2006-12-02 Thread Andy Dingley

Imbaud Pierre wrote:
 I have to add access to some XMP data to an existing python
 application.
 XMP is built on RDF, RDF is built on XML.

RDF is _NOT_  built on top of XML. Thinking that it is causes a lot of
trouble in the architecture of big RDF projects. RDF is a data model,
not a serialisation. The data model is also a graph (more than XML can
cope with) and can span multiple documents. It's only RDF/XML that's
the serialisation of RDF into XML and good architectures start from
thinking about the RDF data model, not this RDF/XML serialisation.

As to RDF handling, then the usual toolset is Jena (in Java) and
Redland has a Python binding although Redland is fairly aged now.

I'm unfamiliar with XMP and won't have a chance to look at it until
Monday. However if XMP is strongly XML like despite claiming to be
RDF, then you might find that handling a pure XMP problem is quite
easily done with XML tools.

Famously RDF/XML is unprocessable with XSLT if it's sophisticated, but
quite easy if it's restricted to only a simple XML-like RDF model. XMP
could well be similar.

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


Re: Printing Barcodes from webapp?

2006-12-02 Thread Andy Dingley

Burhan wrote:

   Is there an easy way to generate barcodes using Python

Easy way for any application or language to generate barcodes is to
install a barcode font on the client machine, then just generate a
suitable text string for it. This is _very_ easy, if you can get the
font deployed.  I usually find myself using Code 39 and printing them
from a HTML document. There are plenty of free code 39 fonts around and
the string mangling to get the barcode structured correctly is just a
trivial prefix / suffix.

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


Re: Python v PHP: fair comparison?

2006-11-15 Thread Andy Dingley

walterbyrd wrote:

 I don't know if this is a fair comparison or not.

Who cares?  Anything involving PHP is a billion flies can't be wrong
type of statement.

I agree completely with your observation about PHP's lower cost of
access. This is ostensibly a good thing, but it also means that every
software-ignorant newbie dives straight into PHP and ten minutes later
they're a guru.  The average quality of PHP developers is rock-bottom
and the average quality of PHP code is about the same. I don't like the
language either, but it's the use PHP is put to that spoils most of it,
more than language features itself.

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


Re: HTML Parsing and Indexing

2006-11-13 Thread Andy Dingley

[EMAIL PROTECTED] wrote:

 I am involved in one project which tends to collect news
 information published on selected, known web sites inthe format of
 HTML, RSS, etc

I just can't imagine why anyone would still want to do this.

With RSS, it's an easy (if not trivial) problem.

With HTML it's hard, it's unstable, and the legality of recycling
others' content like this is far from clear.  Are you _sure_ there's
still a need to do this thoroughly awkward task?  How many sites are
there that are worth scraping, permit scraping, and don't yet offer RSS
?

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


Re: Book about database application development?

2006-10-16 Thread Andy Dingley
Paul Rubin wrote:
 http://philip.greenspun.com/sql/

There was a time (some time in the mid 90s) when I thought that Philip
Greenspun had a Clue. Then I realised just how wrong he was (he started
off reasonably right, he just didn't keep up when the world moved on).
The highlight of this process was seeing him booed during a conference
keynote speech -- by angry librarians and museum curators  (he deserved
it too).

I can't imagine any topic, except possibly dog grooming, where I'd
listen to his advice.

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


Re: Where is Python in the scheme of things?

2006-10-05 Thread Andy Dingley

gord wrote:

 As a complete novice in the study of Python, I am asking myself where this
 language is superior or better suited than others.

I use it, and see it primarily, as a Perl killer. It also does for Ruby
and our infernal shell scripts.

I've never considered using Python instead of VB. As a VB developer of
many years, I'd see thhe Python language itself as infinitely superior
to VB in almost every aspect, except that of building event driven
Windows GUIs with easy form layout. Maybe there's some wonderful Python
toolkit for doing this, but it's news to me.

I'm undecided as to whether Python beats JSP for web development. So
far I'm still inclined to Java, but that's probably because I know Java
and Java has a huge amount of beyond Java the language development
attached to it for web work.

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


Re: does anybody earn a living programming in python?

2006-09-26 Thread Andy Dingley

walterbyrd wrote:

 If so, I doubt there are many.

I currently earn my living programming in Python.

This is particularly amusing given that it's a Java shop and I don't
even know Python!

I've only been using it for a few months as a replacement for the
previous shell scripts and instead of Perl (which I know, but never
liked). I'm nominally the release manager which is half tiresome
monkey work and half is building vast Python-powered scripts to
automate the aforementioned monkey work. I don't think I've written
more than a line of actual Java since I've been there.

One thing is sure though - I wouldn't have been _recruited_ as a Python
coder. Supposedly they hired me on the strength of all-round experience
and as a Java hack.

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


Re: Looking for a regexp generator based on a set of known string representative of a string set

2006-09-08 Thread Andy Dingley

[EMAIL PROTECTED] wrote:

 I am looking for python code that takes as input a list of strings
 [...] and outputs the python regular expression

(s1|s2|s3|s4|s5)
for strings of s1 etc.

Regex compilers are themselves quite good at optimising beyond this

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


Re: python vs java

2006-09-06 Thread Andy Dingley

Aravind wrote:

 some of my friends told that python and java are similar in the idea of
 platform independency.

Similar in goal, but quite different in approach.

Python supports lots of platforms and goes to great lengths to offer
facades around whatever  features a platform does have, so as to offer
the same benefits as Unix.  Java lives in a virtualised environment
where it pretends there aren't any platforms. Perl pretends everything
_is_ Unix and falls flat when it isn't.

If you can cope with this, Java is simpler and less platform-bound.

If you actually need to get OS-level work done, Python is wonderful.
You can write stuff that hooks in at a fairly deep level, yet really is
portable.

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


Newbie - How to iterate list or scalar ?

2006-08-08 Thread Andy Dingley
I seem to be writing the following fragment an awful lot, and I'm sure
it's not the best and Pythonic way to do things. Any advice on better
coding style?

pluginVersionNeeded is a parameter passed into a method and it can
either be a simple scalar variable, or it can be a list of the same
variables.  My problem is how to iterate it, whether it's a a list or
not.

I can't simply throw it into the for...in loop -- if the scalar
variable were to be a string (which is considered to be atomic in my
application) then Python sees this string as iterable and iterates over
the characters in it!


versionsNeeded = pluginVersionNeeded
if isinstance( versionsNeeded, list):
versionsToTest = versionsNeeded
else:
versionsToTest = [ versionsNeeded ]
for versionNeeded in versionsToTest:
pass


Thanks for any advice

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


Re: do people really complain about significant whitespace?

2006-08-08 Thread Andy Dingley

Thomas Guettler wrote:

 I like python, but sometimes i don't like that python allows
 spaces and tabs. It would be easier if you had less choice and
 must use four spaces.

That's the nice thing about Python. It doesn't care about indentation
distance, it just wants some and consistent.

I like the idea that humans see the whitespace as significant anyway,
so document the fact and use it  (I presume this came from Occam).
What I don't like so much is that the _ends_ of blocks are less
visually obvious.

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


Re: Newbie - How to iterate list or scalar ?

2006-08-08 Thread Andy Dingley

Bruno Desthuilliers wrote:

 there's really no reason to
 assume it should be a list - any iterable could - and IMHO should - be
 accepted... expect of course for strings (royal PITA case, duh).


 2/ test for pluginVersionsNeeded.__iter__ (an attribute of most
 iterables except strings...):

strings don't have __iter__ ?!?!

I'm never going to get my head round this language   8-(

I can understand strings and tuples being iterable, if you take a
sufficiently first-class view of things, but why shouldn't everything
that is iterable support the function that makes iteration work?

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


Re: Windows vs. Linux

2006-08-01 Thread Andy Dingley

[EMAIL PROTECTED] wrote:

 Python and Ubuntu rock...go fot it.

That's nice.  I've just burned myself a new Ubuntu f*ck-a-duck release
CD intending to rebuild a flakey old Deadrat box with it. Once it's
done I'd like to be running Python with some USB to Dallas one-wire
hardware on it, re-plugged from an old Windows box. Nice to know I have
a hope of getting somewhere.

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


Re: Windows vs. Linux

2006-07-31 Thread Andy Dingley
[EMAIL PROTECTED] wrote:

 Is Windows
 an okay enviornment in which to program under Python, or do you
 recommend that I run a dual-boot of Linux or maybe a VMWare install to
 program under Python?

Python is one of the best languages I've found for
platform-independence - significantly better than Perl.  Right now I'm
coding Python that runs happily under Redhat, Windows /Cygwin and
Windows native. It also integrates closely with command line tools like
subversion, including piping their output into Python-based XML
parsers. This really wouldn't be easy with Perl.

Find yourself an editor that's pretty similar under both Unix and
Windows. jEdit is a good place to start.

You might also like to look at running Cygwin under Windows. It's a
Unix-like command shell that provides nearly every command-line Unix
tool you could want on a Windows box. Can be a little awkward at times,
but it's a huge advantage over raw Windows.

I'd never recommend dual-boot for anything!
Hardware is cheap, time and trouble is expensive.

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


Re: range() is not the best way to check range?

2006-07-18 Thread Andy Dingley

[EMAIL PROTECTED] wrote:

 it seems that range() can be really slow:

 if i in range (0, 1):

RTFM on range()

You're completely mis-using it here, using it with an if ... in ...
test. The purpose of range() in Python is as loop control, not
comparisons!  It's not a SQL BETWEEN statement.

Although you _can_ do this (you've done it!) you've also found that
it's slow. Many people would argue that even using range() for loop
control is unusably slow.

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


Re: list comprehension

2006-06-30 Thread Andy Dingley [EMAIL PROTECTED]

Simon Forman wrote:

 There's more to it, but that's the basic idea.

This much I knew, but _why_ and _when_ would I choose to use list
comprehension (for good Python style), rather than using a simple
traditional loop ?

If I want to generate something that's simply ( [1] + [2] + [3]+... )
then list comprehension is obviously the tool of choice. I suspect
though that there's more to it than this. Is list comprehension also
treatable as a sneaky concise formulation for nested lists, where
they're as much about selection of individual elements, so much as
concatenation of the sequence?

What happens if a comprehension has side effects, such as from calling
a function within it? Is this regarded as good or bad coding style? Is
it evil (as structured programming would claim) or is it  a concise
formulation for an iterator or visitor pattern ?

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


Re: Python in HTML

2006-06-23 Thread Andy Dingley [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:

 Python, like it's (evil?) cousin Perl,

Isn't that evil cousin Ruby?  Perl's the mad old grandmother in the
attic, spewing out incomprehensible [EMAIL PROTECTED]% swearing all day.

 can be used as a CGI. If you
 don't have one already, go download Apache server to play with on your
 own machine and Google Python CGI and Python module cgi.

Or if you're cursed with IIS for Windows, then PythonScript does the
job.

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


[newbie] Iterating a list in reverse ?

2006-06-21 Thread Andy Dingley [EMAIL PROTECTED]
Python newbie:  I've got this simple task working (in about ten
different ways), but I'm looking for the favoured and most Python
like way.

Forwards I can do this
for t in listOfThings:
print t

Now how do I do it in reverse?   In particular, how might I do it if I
only wanted to iterate part-way through (with a conditional test and a
break), or if I had a large list ?

reverse( listOfThings )
for t in listOfThings:
print t

As reverse() operates in-place I often can't do this. I'm also
(slightly) concerned about possible inefficiency issues of manipulating
a big list just to scan a peek at its tail.

Currently I'm doing this:

for i in range( len( listOfThings )-1, 0, -1):
t = listOfThings  [i]
print t

Is this the optimum ?   Would xrange() be a better choice (and when is
it a big list) ?



Thanks for any guidance

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


Re: Iterating a list in reverse ?

2006-06-21 Thread Andy Dingley [EMAIL PROTECTED]
Fredrik Lundh wrote:

 for item in reversed(listOfThings):

Thanks! I was staring so hard at reverse() that I'd completely missed
reversed()

I think I prefer this to listOfThings[::-1]:  as it's a little more
readable.
Not that I'm reacting to past bad experience of Perl, you understand
8-)

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


Re: Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations

2006-03-19 Thread Andy Dingley
On Fri, 17 Mar 2006 11:22:06 +0100, Timo Stamm [EMAIL PROTECTED]
wrote:

Xah's posting was properly encoded and will display fine in every decent 
newsreader.

Well mine killfiled it straight off, which I think is entirely proper
rendering for one of Xah Lee's kookery lessons.
-- 
http://mail.python.org/mailman/listinfo/python-list