Re: How to find the type ...

2005-12-09 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Lad" == Lad  <[EMAIL PROTECTED]> writes:
Lad> How can I find out in Python whether the operand is integer or a
Lad> character and change from char to int ?

In Python, the canonical way of doing this would be to simply assume
that the argument can be converted to an integer and catch any errors
that occur:

def f(x):
try:
x = int(x)
except ValueError:
# It's a non-number string.
do stuff
except TypeError:
# It's neither a number nor a string.
do some other stuff

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOZwtkACgkQYu1fMmOQldXEzACgqdDVvx29UBVSIfQWnGRiAAk9
xPsAn0yN5jWrUN+6SKIHdwtILRBVyQwR
=HZQq
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggesion for an undergrad final year project in Python

2005-02-13 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Sridhar" == Sridhar  <[EMAIL PROTECTED]> writes:
Sridhar> I am doing my undergrade CS course.  I am in the final year,
Sridhar> and would like to do my project involving Python.  Our
Sridhar> instructors require the project to have novel ideas.  Can the
Sridhar> c.l.p people shed light on this topic?

I'm arriving a bit late in this discussion, but might as well throw in
my bit anyway.

I did my master's thesis implementation thingy in Python, and still
managed, from what I can tell from available research material, to
make the fastest RDBMS search engine of its kind. :-)

But really, implementation language is, or should be, a fairly minor
issue compared to what exactly it is that you want to do. For some
things, your choice of language might be very important, but until you
know what you're going to do, there's really very little need to worry
about it, at least in my opinion.

Martin

- -- 
Homepage:   http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkIPhtoACgkQYu1fMmOQldVWRACgxSDK80tc5iSFrqnHdi/Ydwg9
qmwAoOk4wiQ9LNUhteuTtbZrrzo6CJfh
=yO5X
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multi threading in multi processor (computer)

2005-02-15 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Irmen" == Irmen de Jong <[EMAIL PROTECTED]> writes:
Irmen> Naah.  What about: http://www.razorvine.net/img/killGIL.jpg

Some people have too much spare time and too weird senses of
humour...

Fortunately for the rest of us. :-) This one actually made me laugh
out loud.

Martin

- -- 
Homepage:   http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkISBcwACgkQYu1fMmOQldUg2QCgq1ATLCJWqAS7SBsHpcXTduma
xjMAoII+AzDwkp2F2NZvw4PUrBUx+GDh
=Yqjf
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting milliseconds in Python

2005-02-17 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Brian" == Brian Beck <[EMAIL PROTECTED]> writes:
Brian> Despite a millisecond being a thousandth of a second [...]

A math teacher! A math teacher! My kingdom for a math teacher!

Martin

- -- 
Homepage:   http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkIUxPkACgkQYu1fMmOQldXH3QCdGcw3grK/R17kfakMBhxU1Io/
4ukAoJl+gysL9q/6j1G8LYPZz7NawEV+
=1CNL
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question - iterating through dictionary object

2005-02-17 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Miranda" == mirandacascade  <[EMAIL PROTECTED]> writes:
Miranda> 1) Is there any advantage to use the
Miranda> y = a.keys()
Miranda> for z in y:

While you're at it, you could save y altogether and just use

for z in a.keys():
...

Miranda> looping technique rather than the
Miranda> for x in a:
Miranda> looping technique?

I certainly don't see any advatages.

Miranda> 2) What are the tradeoffs for using each of the techniques?

'for x in a:' is prettier to look at. :-) As you can see, it's also
slightly faster (at least for very small dictionaries), but unless
you're doing a _lot_ of them, it won't matter.

% python2.4 -m timeit -c "a = {1:1, 2:2, 3:3, 4:4, 5:5}" "for x in a: pass"
100 loops, best of 3: 1.63 usec per loop
% python2.4 -m timeit -c "a = {1:1, 2:2, 3:3, 4:4, 5:5}" "for x in a.keys(): 
pass"
10 loops, best of 3: 2.1 usec per loop


Martin

- -- 
Homepage:   http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkIUyPwACgkQYu1fMmOQldWV8ACdEZOgwwtOyp7c+hDVtQe+0LX1
yRoAoITJGZA6zA0iE9G4lp2cP/GinlZC
=njlP
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting milliseconds in Python

2005-02-17 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Brian" == Brian Beck <[EMAIL PROTECTED]> writes:
Brian> Man, this is the hottest topic on c.l.py since that Lazaridis
Brian> guy...

... which was really the point of my joke, even if it did belly flop
somewhat. This whole discussions brought to mind a cartoon where a
group of doctors were performing open heart surgery. One of them says,
"Okay, how many of us believe that the heart has _four_ chambers?,"
and a few of the others raise their hands. I intended it as a 'let's
call in the professors to determine if 2+2=4', but, well... :-)

Martin

- -- 
Homepage:   http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkIUyzAACgkQYu1fMmOQldWVdACdHLxtUi4TtFCl0ZW6wf65Hu9M
ioMAoMWAHrkS5lhQw5V0cJXVO1nk76MO
=6MXl
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO in Python? ^^

2005-12-10 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Matthias" == Matthias Kaeppler <[EMAIL PROTECTED]> writes:
Matthias> sorry for my ignorance, but after reading the Python
Matthias> tutorial on python.org, I'm sort of, well surprised about
Matthias> the lack of OOP capabilities in python. Honestly, I don't
Matthias> even see the point at all of how OO actually works in
Matthias> Python.

It's very common for Python newbies, especially those with backgrounds
in languages such as C++, Java etc. to not really 'get' the Python way
of handling types until they've had a fair amount of experience with
Python. If you want to program Pythonically, you must first unlearn a
number of things.

For instance, in e.g. the Java tradition, if a function needs a
triangle object, it'll take a triangle object as an argument. If it
can handle any type of shape, it'll either take a shape base class
instance as an argument or there'll be some kind of shape interface that
it can take. Argument types are strictly controlled. Not so with
Python. A Python solution will typically take any type of object as an
argument so long as it behaves as expected, and if it doesn't, we deal
with the resulting exception (or don't, depending on what we're trying
to accomplish). For instance, if the function from before that wants a
shape really only needs to call an area method, anything with an area
method can be used successfully as an argument.

Some have dubbed this kind of type check 'duck typing': if it walks
like a duck and quacks like a duck, chances are it'll be a duck. To
those who are used to (more or less) strong, static type checks, this
will seem a reckless approach, but it really works rather well, and
subtle type errors are, in my experience, as rare in Python as in any
other language. In my opinion, the tricks the C*/Java people
occasionally do to get around the type system, such as casting to the
fundamental object type, are worse because they're seldom expected and
resulting errors thus typically more subtle.

In my very first post on this news group a number of years ago, I
asked for an equivalent of Java's interfaces. The only reply I got was
that I didn't need them. While the reason was very obvious, even with
what I knew about Python, it still took a while to sink in. From what
I can tell, you're in somewhat the same situation, and the two of us
are far from unique. As I said in the beginning, Python newbies with a
background in statically typed languages typically have a lot to
unlearn, but in my opinion, it's well worth it.


Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOba8oACgkQYu1fMmOQldXzcgCg0JEGTEG7xC/yAx8C1VFO8H1R
LWwAnRJ8AxHBe8YoHcDC5oGRfYaPHTfX
=HdTR
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want a Python Puppy !

2005-12-13 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Diez" == Diez B Roggisch <[EMAIL PROTECTED]> writes:
Diez> In the current c't there is an article how to customize
Diez> knoppicilin, the knoppix-based antivirus distribution. I didn't
Diez> have a deeper look so far, but I'm eager to see if that couldn't
Diez> be used to create special distriubutions for e.g. gnome-meeting
Diez> based vid-conferencing, or a python-super-developer-distribution
Diez> :)

I'll shortly be announcing the public availability of Pynux... :-)

Seriously, though, I can see the sense in having 'live' CD distros
specialised for antivirus (or general rescue/sysadmin work), video
conferencing and stuff like that, but what would be the reasoning for
a Python specific distro, or indeed any special development needs? To
me it seems that a general-purpose distro with whatever development
tools the individual programmer needs is going to be a perfect fit.
Any specialised development distro sounds like specialisation for its
own sake to me.

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOevbkACgkQYu1fMmOQldWE6gCcDGcwD3mm1ucRgOEYS+N8NmWQ
w9MAnixGhwJYvSU1jp4pk3Dnm7jaQC45
=+E+a
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Still Loving Python

2005-12-14 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Bengt" == Bengt Richter <[EMAIL PROTECTED]> writes:
Bengt> De gustibus non disputandum, or whatever ;-)

Yeah, and quidquid latine dictum sit, altum viditur. :-)

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOgIuoACgkQYu1fMmOQldULYwCgjZovLw/gTJ8I/z/Wem203aca
DUUAoJ7GNNn2QOrmFINrgw58OkRnBmJU
=mUHX
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PHP = Perl Improved

2005-12-14 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Tin" == Tin Gherdanarra <[EMAIL PROTECTED]> writes:

Tin> Xah Lee wrote:
>> recently i got a project that involves the use of php. In 2 days, i
>> read almost the entirety of the php doc. Finding it a breeze
>> because it is roughly based on Perl, of which i have mastery.

Tin> I suspect that you are a computer program posing as a human
Tin> usenet correspondent.

Tin> Please answer these questions: [...]

Will you accept a solution in Perl? He has mastery of that language,
you know. You might have better luck if you phrase your questions in
Perl, too, since he doesn't seem to understand it when people tell him
to bugger off in plain English.

Say, there's a thought...

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOg0CUACgkQYu1fMmOQldVP9ACfSzQBq7S1QX0jA2/nA2JaC+BB
4ZoAoMOn5Qe9oJHGtINWKNBQsz879R6r
=bp6G
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Kent" == Kent Johnson <[EMAIL PROTECTED]> writes:
Kent> [Karrigell is GPL'ed] Unfortunately this makes it impossible for
Kent> me to consider using Karrigell in my work. I recently needed a
Kent> stand-alone web server for a small in-house project that might
Kent> possibly be distributed to business partners or become a product
Kent> some day. I chose CherryPy in part because its license allows
Kent> this. I would have considered Karrigell if it had a different
Kent> license.

None of this really matters, you know. The GPL only requires that you
share your source code if you _distribute_ your modifications. Since
you make your modifications exclusively for your own (your company's)
use, you are not required to share anything. Thus the whole debate is
pretty much moot if I am not much mistaken.

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOpbaUACgkQYu1fMmOQldUR/QCffOi9bYnmUeEcT8zdvF60voah
cy4AoIb69dAv6dr6WmpaIZPipq1xZbF0
=/eTj
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Ben" == Ben Sizer <[EMAIL PROTECTED]> writes:
Ben> Unfortunately, that doesn't really satisfy the GPL's concerns.
Ben> The work arguably "contains or is derived from" Karrigell, which
Ben> is explicitly covered in section 2b of the GPL. If you start
Ben> excluding key clauses from the GPL, then there's little point
Ben> using it.

You will also notice that section 2b of the GPL only applies to works
that are published or distributed, and if a company bases its web site
on Karrigell or any other GPL'ed web framework but does not share the
code with anyone, it cannot be considered to be published nor
distributed. Hence the GPL is a perfectly fine license for this kind
of use.

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOpb34ACgkQYu1fMmOQldUApQCgxPvp3ozRGo+/J5kJlY+htd4T
F/IAoLBlMz0Z9eamIDqsInaa4bPyxgyd
=UXUa
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Kent" == Kent Johnson <[EMAIL PROTECTED]> writes:
Kent> In the text you quoted I said, "a small in-house project that
Kent> might possibly be distributed to business partners or become a
Kent> product some day." Sounds like distribution to me.

My bad. I somehow managed to miss that.

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOplbwACgkQYu1fMmOQldXsSwCg0TRh98gcr+0xzhN4mKFCq3y8
SScAoICVaFIStF6PWfo+DZKo/v+WRicc
=69ov
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I reduce the number of queries to my PostgreSQL database?

2006-04-08 Thread Martin Christensen
> "SR" ==   <[EMAIL PROTECTED]> writes:
SR> Scenario: I have a python script which creates web page listing
SR> all books in the database, and all authors for each book. My
SR> python script does essentially three things:

SR> 1. retrieve a list of all book_ids and book_titles.

SR> 2. for each book_id, query the bookauthors table and retrieve all
SR> author names for that book_id.

SR> 3. display it all out as an html table on a web page.

That's one query, if you're willing to make it advanced enough,
although you need to make an aggregate to enable PostgreSQL to
concatenate and comma separate author names. However, this aggregate
will typically need more than one database function. Such an aggregate
could be as follows:

CREATE OR REPLACE FUNCTION author_agg_sfunc(TEXT, authors.name%TYPE)
RETURNS TEXT AS '
SELECT $1 || '', '' || $2;
' LANGUAGE sql;

CREATE OR REPLACE FUNCTION author_agg_ffunc(TEXT)
RETURNS TEXT AS '
SELECT trim(trailing '', '' from $1);
' LANGUAGE sql;

CREATE AGGREGATE author_agg (
  basetype  = VARCHAR(100),
  sfunc = author_agg_sfunc,
  stype = TEXT,
  finalfunc = author_agg_ffunc,
  initcond  = ''
);

Then you could use it as follows:

SELECT author_agg(authors.name),
   foo,
   bar
  FROM authors, writes, books
 WHERE authors.id = writes.author_id
   AND writes.book_id = books.id
 GROUP BY foo, bar;

This is the solution that I would use after working nearly a decade
with databases. It is neither simple nor obvious to the novice, but
it's the Right Way To Do It. For a learning exercise, this is way over
the top, but I thought you might benefit from seeing that - so long as
you only need information that would reasonably fit in one table on a
web page or the equivalent - one query is always enough. Or perhaps
that should be One Query Is Always Enough. :-) Learn at your own pace,
though, but you might want to keep this in mind for future reference.

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


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread Martin Christensen
> "Jay" == Jay  <[EMAIL PROTECTED]> writes:

Jay> when i seperate things up into classes i carnt get one class to
Jay> tell the other class somthing. it just opens another coppy of the
Jay> class. i am confused.

I'm sorry, it's very difficult to understand what you mean. You'll
have to be a lot more precise, and it would probably help if you
posted code examples and tell us what you expect from the code you're
making.

Jay> oh and i carnt fathem out how to run to loops at the same time.
Jay> EG . Ball Blaster i wanted to permenetly run the ball with a loop
Jay> well my main loop ran the bat.

Erm... it _could_ sound as if you're looking for multi-threading, i.e.
running several things at the same time. This, however, is pretty
difficult, especially for a beginner. Maybe you should try to
structure your program differently so that you only need one thread of
execution. Then you can proceed to multi-threading when you have more
experience.

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