[Tutor] Unit-testing advice

2010-03-08 Thread mhw
Dear All,

Quick UT question. I am working on a CSV processing script. I want to write 
some tests. The tests will need to read in, manipulate and write out some CSV 
files. 

My instinct is to manually construct some small data files, and consider them 
as part of the test suite. The other option would be to programatically 
construct them (? As a set-up).

Which is better? 

Thanks,

Matt


Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding duplicates entry in file

2010-03-21 Thread mhw
Plain text definitely better for small devices - I read the tutor list on my 
blackberry on the way to work (and hence Top -p - apologies).

Matt
Sent from my BlackBerry® wireless device

-Original Message-
From: Luke Paireepinart 
Date: Sat, 20 Mar 2010 23:00:03 
To: Steven D'Aprano
Cc: 
Subject: Re: [Tutor] Finding duplicates entry in file

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Multipane windows using curses

2010-04-27 Thread mhw
Dear All,

I am looking for some advice about a design decision. I want to write a 
curses-based editor (for OWL ontologies). This should then be usable via ssh, 
etc. Ontology files may be large, and quite complex. Current editors (e.g. 
Protege) have multiple tabs to cope with this.

The simplest option would seem to be to have a single appliction, running 
through a single terminal. However, the data is often complex, and so it would 
be nice to have multiple terminals showing different bits of the ontologies at 
the same time. However, doing this with multiple instances of the app would be 
difficult, as each window would have to load the whole ontolog, etc.

My next thought was then to run a simple server that loads the data file and 
returns bits of it. Then one could open multiple ssh terminals, and each could 
run a client to allow one to view the data. However, this is obviously more 
complex.

Am I missing something simpler?

Thanks,

Matt
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using Regex to produce text

2010-04-27 Thread mhw
Dear All,

Quick question:

Is there an way of using the regex patterns to produce text, instead of 
matching it?

E.g.:
pat = re.compile("ab?d")
pat.getListofPossibleText()

Thanks,

Matt


Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Regex to produce text

2010-04-28 Thread mhw
While some patterns are infinite, other's aren't (e.g. The example I gave). 

Using a subset of Regex syntax to produce a set of strings has the advantage of 
using a well understood and documented form, and if you could hook into the 
existing API, at minimal coding effort.

In addition, it allows a nice symmetry between search and production of 
resource names.

E.g.

Source some data (containing resources)
Label res 1 to res n using re.pattern(p1) 
Add this data to the larger data lump

 do some stuff...

Find the data items you had again:
DataGroup1 = AllData.search(re.pattern(p1))

I suspect it's not that easy, as I don't think we can get to the internals of 
the regex FSM. However, I thought it would be worth asking.

Matt
Etc.


--Original Message--
From: Luke Paireepinart
To: m...@doctors.net.uk
Cc: Python tutor
Subject: Re: [Tutor] Using Regex to produce text
Sent: 28 Apr 2010 07:51

On Wed, Apr 28, 2010 at 1:27 AM,   wrote:
> Dear All,
>
> Quick question:
>
> Is there an way of using the regex patterns to produce text, instead of 
> matching it?
>
> E.g.:
> pat = re.compile("ab?d")
> pat.getListofPossibleText()
>

There's no end to the length of many patterns so this would be fairly pointless.
For example, what would getListofPossibleText do for the pattern ".*" ?

I think the better question is: what are you trying to do?
Or perhaps: Why do you think you need to solve your problem this way?

-Luke


Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Getting an object's attributes

2010-06-26 Thread mhw
Dear Tutors,

I have an object to which I dynamically add attributes. My question is how I 
can inspect and display them at run-time?

Class a():
pass

Obj1 = a()

Obj1.name = "Bob"
Obj1.age = 45

dir(a) returns a tuple which contains name and age, but also other things 
(includings methods, etc.) I could filter this tuple (checking for callable(), 
etc.)  but I just wondered if there was an existing way of getting just name 
and age.

Thanks,

Matt
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting an object's attributes

2010-06-26 Thread mhw
Apol. For TP:

This is perfect - thanks.
Matt
Sent from my BlackBerry® wireless device

-Original Message-
From: Evert Rol 
Date: Sat, 26 Jun 2010 11:13:16 
To: 
Cc: Python tutor
Subject: Re: [Tutor] Getting an object's attributes

> I have an object to which I dynamically add attributes. My question is how I 
> can inspect and display them at run-time?
> 
> Class a():
>pass
> 
> Obj1 = a()
> 
> Obj1.name = "Bob"
> Obj1.age = 45

First off, a few suggestions:
- you probably mean 'class', not 'Class' (sorry, but it's just that correct 
actual code helps: copy-paste from the Python prompt when you can. If you have 
a text-editor in your mail program that capitalises things, be careful when 
pasting code).
- use capitalisation (or CamelCase) for class names, lowercase for instances: 
class A, obj1 = A(). This is the usual Python convention.
- I would use new-style classes, ie, inherit from object:
>>> class A(object):
...   pass
... 
>>> obj1 = A()



> dir(a) returns a tuple which contains name and age, but also other things 
> (includings methods, etc.) I could filter this tuple (checking for 
> callable(), etc.)  but I just wondered if there was an existing way of 
> getting just name and age.

Normally, you know which attributes you want to access, so you wouldn't have 
this problem. Better yet, you wrap things in a try-except clause and see if 
that works:
>>> try:
... obj1.name
... except AttributeError:
... print "not there"
... 
not there

 
But for this case, when using new-style classes, obj1.__dict__ can help you (or 
obj1.__dict__.keys() ). 
>>> obj1.name = "Bob"
>>> obj1.age = 45
>>> obj1.__dict__
{'age': 45, 'name': 'Bob'}

Or, perhaps somewhat silly: set(dir(obj1)) - set(dir(A)).
>>> set(dir(obj1)) - set(dir(A))
set(['age', 'name'])

but I wouldn't recommend that.

See eg http://docs.python.org/library/stdtypes.html#special-attributes


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Implementing sets of user-defined objects

2010-07-23 Thread mhw
Dear Tutors,

I am tring to deal with some repeated data, and hence repeated objects (I 
construct objects from the data).

I had hoped to use a set to uniquify the objects. However, I am having problems 
with defining uniqueness.

I have googled/ looked at the Python docs/ read DITP and Alan's website, but 
I'm still not clear how the set() determines object uniqueness. There seem to 
be some references to __cmp__() and __eq__(), but I'm not clear what I should 
be using.

Any pointers very welcome.

Matt
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] JOB AD PROJECT

2010-11-21 Thread mhw
(Apologies for TP-ing)

I'd second Alan's comments about not taking this as a first piece of work.

Otherwise, Django seems a good choice - reasonably simple to get started, and 
well documented. This is the Python tutor list, so sort of assumes you are 
doing it in Python.

This list tends to work best with "how do I do X?", or even better "I've 
written X, but it doesn't work/ doesn't work well enough"

If you are going to use Django, then you should join their mailing list.

HTH,

Matt
Sent from my BlackBerry® wireless device

-Original Message-
From: delegb...@dudupay.com
Sender: tutor-bounces+mhw=doctors.net...@python.org
Date: Sun, 21 Nov 2010 03:34:29 
To: 
Reply-To: delegb...@dudupay.com
Subject: Re: [Tutor] JOB AD PROJECT

Hi People,
I am afraid only Alan has said something to me. Is it that solution would never 
come or u guys are waiting to gimme the best?

Please help. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: "Alan Gauld" 
Sender: tutor-bounces+delegbede=dudupay@python.org
Date: Sat, 20 Nov 2010 09:00:52 
To: 
Subject: Re: [Tutor] JOB AD PROJECT


 wrote

> I have done some extensive reading on python.
> i want to design a classifieds site for jobs.

Have you done any extensive programming yet?
Reading alone will be of limited benefit and jumping into
a faurly complex web project before you have the basics
mastered will be a painful experience.

I'm assuming you have at least some experience of
web programming in other languages for you to take
such a bold step?


> I am taking this as my first project and would appreciate any help.
> I am looking in the direction of python, maybe django.

The choice of tools is fine, but its a big task for a first
ever Python project!

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Processing rows from CSV

2009-11-17 Thread mhw
Dear Tutors,

A rather general question, I'm afraid. I have found myself writing some python 
code to handle some CSV data, using the csv. DictReader that generates a dict 
for each row with the key as the column heading and the value in the file as 
the item. Most operations involve code of the form: (Apologies for incorrect 
caps)

For row in reader:
If row['foo'] == 'something' :
do this etc.

Typically I'm checking some form of consistency, or adding an element to the 
row based on something in the row.

I know about the existence of awk/ sed etc. Which could do some of this, but I 
ran into some problems with date manipulation, etc that they don't seem to 
handle very well.

I wanted to ask if anyone knew of anything similar, as I'm worried about 
re-inventing the wheel. One option would be to use (e.g.) sqlite and then use 
select/ insert commands, but personally I'd much rather write conditions in 
python than sql.

My other question was about how I do this more efficiently: I don't want to 
read the whole thing into memory at once, but (AFAIK) csv.DictReader doesn't 
support something like readline() to deliver it one at a time.

Any comments gratefully received.

Matt
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor