Re: Python / Apache / MySQL

2006-02-14 Thread Kalle Anke
On Tue, 14 Feb 2006 12:04:45 +0100, Peter Hansen wrote
(in article <[EMAIL PROTECTED]>):

> SQLite.  (As but one option, but "just basic selects" is certainly 
> included in the set of suitable conditions for SQLite use.)

I've considered to use SQLite for an application but for completely different 
reasons ... hmm, I should perhaps consider SQLite for some other ideas I have 
also ...

> Don't optimize prematurely?  If you use something like SQLObject, or any 
> other means of abstracting yourself away from the details of a specific 
> datbase, you won't be particularly tied to it if you decide you need 
> improved performance, or sophistication, or whatever.


That's true ... I was thinking in general terms here (a couple of people I 
know handles huge data sets, genome data type of things, and in their case 
speed is very important)

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


Re: Python / Apache / MySQL

2006-02-14 Thread Kalle Anke
On Tue, 14 Feb 2006 11:19:11 +0100, bruno at modulix wrote
(in article <[EMAIL PROTECTED]>):

> The reason is mostly that either you need a real, full-blown, rock-solid
>  RDBMS - which MySQL is definitively not - or you dont - in which case
> SQLite is probably a much more lightweight and agile solution.


Stupid questions (I know very little about databases): 

I always thought that a SQLlite database "belonged" to a single process, can 
a database be used by several processes?

Let's say I would build a small web application that would be used by a small 
number of people/processes and it wouldn't be anything fancy just basic 
"selects". What would be the choice for this?

What about speed? I've always had the impression that while PostgreSQL is 
more complete than MySQL it's also slower.

Sorry, if these are really stupid questions but ...

jem

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


Re: Python / Apache / MySQL

2006-02-14 Thread Kalle Anke
On Tue, 14 Feb 2006 10:32:34 +0100, Sybren Stuvel wrote
(in article <[EMAIL PROTECTED]>):

> I second Bruno: swap MySQL in favour of PostgreSQL.

And the reason is ?? (apart from PostgreSQL being larger and more complete, 
what are the differences for "simple" usage?)

 jem

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


Re: getting the path in a cgi script

2005-10-14 Thread Kalle Anke
On Fri, 14 Oct 2005 18:20:10 +0200, Fredrik Lundh wrote
(in article <[EMAIL PROTECTED]>):

> import os
> path_info = os.environ.get("PATH_INFO")

Tackar ... det var nåt enkelt det mindes jag :-)

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


getting the path in a cgi script

2005-10-14 Thread Kalle Anke
I know I've done this once before ... I think ... but now I can't figure out 
how to do it

I've set my web server to use an alias similar to this

   ScriptAlias /xx/ "/Library/WebServer/CGI-Executables/xxx.cgi/"

which makes it possible for me to write

   http://127.0.0.1/xx/some/kind/of/path

my problem is that I don't know how to get the 'some/kind/of/path' part of 
the URL in my script.

I know that I can do like this in perl

   $documentRoot.path_info();

but how do I do it in python?

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


What documentation "standard" to use

2005-10-05 Thread Kalle Anke
I'm confused of how I should document my code, I've always liked being able 
to document my code directly in my source file and then to use some tool to 
extract the documentation to some other format.

My problem with Python is that there are so many tools and formats ... I 
don't know which one I should use. I've tried to figure out if there is one 
that is the "de-facto standard" but ...

Could someone advice me on what format/tool I should use?

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


Java pretty formatter

2005-10-05 Thread Kalle Anke
Does a Java "pretty formatter" exist? 

I would like to use a Python based web building tool but would like to pretty 
format Java code (for example adding color to keywords, etc).

I haven't managed to find one but have probably been looking in the wrong 
places.

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


Re: A Moronicity of Guido van Rossum

2005-09-30 Thread Kalle Anke
On Thu, 29 Sep 2005 19:44:28 +0200, Matt wrote
(in article <[EMAIL PROTECTED]>):

> OK... your post seems to indicate a belief that everyone else is
> somehow incompetent. Sounds a bit like the "I am sane, it is everyone
> else who is crazy" concept. Can you suggest a technology or
> technologist who, in your expert opinion, has gotten it right?


He has posted similar posts about other things to at least one other mailing 
list, the tone and arguments of these post were exactly the same.

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


Re: New-style classes questions

2005-09-25 Thread Kalle Anke
On Sun, 25 Sep 2005 15:24:29 +0200, Gerrit Holl wrote
(in article <[EMAIL PROTECTED]>):

> I like this. However, perhaps other people reading my source code won't
> like it, because when they see 'class Foo:', they might expect an
> old-style class. But it's so much better to type and to read, that I
> prefer this.

I personally would find this more difficult to read but it's a matter of 
taste I suppose.

> Det finns inte dåligt väder, bara dåliga kläder.

Så sant som det var sagt


jem

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


New-style classes questions

2005-09-25 Thread Kalle Anke
I'm confused by the concepts of old-style vs new-style classes, I've read 
most of the documents I found about this but it doesn't "click". Probably 
because I wasn't around before 2.2.

Anyway, the reason for new style classes are to make the whole type/object 
thing work better together. There are a number of new features etc.

I think my problem is when new-style classes are used, at first I thought 
that all classes become new-style classes when I was using 2.4, but if I 
understand things correctly I need to subclass an existing class (assuming 
that this class does the same) for it to become a new-style class.

Have I understood this correctly?

If I have, then I've got the following question:

Then I could write:

  class Foo( Object )

to make a new-style class, and 

  class FooA

to make an old-style class.


What is the reason for allowing both styles? (backwards compatibility??) 

When I make my own classes should they always be new-style objects or are 
there reasons for using old-style object?



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


Re: parsing a date

2005-09-24 Thread Kalle Anke
On Sat, 24 Sep 2005 16:06:06 +0200, Peter Hansen wrote
(in article <[EMAIL PROTECTED]>):

> Kalle Anke wrote:
>> On Fri, 23 Sep 2005 23:01:18 +0200, Larry Bates wrote:
>> 
>>> but I'm not sure it is "better".  I guess it depends
>>> on what you want to do with them after parsing.
>> 
>> Sorry, I should have been clearer. I want to parse the date and create a 
>> 'date object' that is a part of larger object (I'm parsing a text file that 
>> represents the larger object and the date is a part of it).
>> 
>> So my question should probably be: is there a better way to parse the date 
>> and generate the 'date object' than the two step 
>> 
>> w = strptime(d,'%Y-%m-%d')
>> datetime.date( w[0], w[1], w[2] )
>> 
>> Since I'm new to many things in Python I'm trying to learn if there is a 
>> "better" way of doing things.
> 
> You're still not defining what "better" means to you, so who can say?
> 
> Perhaps you think a single line would be "better"?
> 
> datetime.date(*time.strptime(d, '%Y-%m-%d')[:3])


:-) It's not my day I think

Better (in this case) =

  + Being "pythonic"

  + Avoiding going through a second representation (the tuple)
if there is some way to create a date object directly.

 jem

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


Re: parsing a date

2005-09-24 Thread Kalle Anke
On Fri, 23 Sep 2005 23:01:18 +0200, Larry Bates wrote
(in article <[EMAIL PROTECTED]>):

> but I'm not sure it is "better".  I guess it depends
> on what you want to do with them after parsing.


Sorry, I should have been clearer. I want to parse the date and create a 
'date object' that is a part of larger object (I'm parsing a text file that 
represents the larger object and the date is a part of it).

So my question should probably be: is there a better way to parse the date 
and generate the 'date object' than the two step 

 w = strptime(d,'%Y-%m-%d')
 datetime.date( w[0], w[1], w[2] )

Since I'm new to many things in Python I'm trying to learn if there is a 
"better" way of doing things.

jem

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


parsing a date

2005-09-23 Thread Kalle Anke
I want to parse a date string, for example '2005-09-23', and since I haven't 
done this before I would like to ask what is the best way to do it.

I've looked around and the dateutil seems to be what most people use, but 
unfortunately I only get an empty file when I try to download it. I also 
tried the standard modules and ended up with this

import datetime
from time import strptime

d = '2005-09-23'
w = strptime(d,'%Y-%m-%d')
print datetime.date( w[0], w[1], w[2] )

But I suspect there is a better way to do it??

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


What XML lib to use?

2005-09-13 Thread Kalle Anke
I'm confused, I want to read/write XML files but I don't really understand 
what library to use.

I've used DOM-based libraries in other languages, is PyXML the library to 
use?

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


Python on Palm??

2005-08-19 Thread Kalle Anke
Is there some implementation of Python that runs on Palm OS?

I've found "Python to Palm Pilot Port" 
 and Pippy 
 which both seem to be based on Python 
1.5

Is there some implementation that implements later versions of Python?

jem

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


Re: Migrating from Windows to OS X

2005-06-18 Thread Kalle Anke
On Sat, 18 Jun 2005 17:07:04 +0200, [EMAIL PROTECTED] wrote
(in article <[EMAIL PROTECTED]>):

> How are the development tools for the Mac?  I'll use IDLE if it's
> available, but I like Scintilla better.

Don't know ... I think that MacPython is perhaps what you're looking for.

Personally, I use BBEdit

  jem

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


Re: Python documentation problem

2005-06-18 Thread Kalle Anke
On Sat, 18 Jun 2005 11:49:38 +0200, Xah Lee wrote
(in article <[EMAIL PROTECTED]>):

> the problem is that the page essentially says nothing. Nothing that is
> relevant to programing, and such nothingness occupies a significant
> portion of the python doc. (at least a quarter) It is like reading a
> manual to operate a machinery, and in every other paragraph it offers
> the (technically-fantastically-correct) explanations of what bolt or
> material were used where.

I'm new to Python and the information that's in the docs (at least that 
example) was what I was looking for. I read this as the referece manual, not 
a cookbook or a tutorial which clearly requires another style of 
documentation.

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


Re: Migrating from Windows to OS X

2005-06-18 Thread Kalle Anke
On Sat, 18 Jun 2005 09:26:23 +0200, [EMAIL PROTECTED] wrote
(in article <[EMAIL PROTECTED]>):

> I am sitting in front of a nice new PowerBook portable which has OS
> 10.4 installed.  The Python.org web site says that Apple has shipped OS
> 10.4 with Python 2.3.5 installed.  How exactly do I access this?  I
> have searched through the Applications and Libraries folders.  I found
> the site-packages directory, but nothing other than that.

Launch Terminal (can be found in /Application/Utilities/)

type python

that's it

 jem

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


Re: Hopefully simple regular expression question

2005-06-14 Thread Kalle Anke
On Tue, 14 Jun 2005 13:01:58 +0200, [EMAIL PROTECTED] wrote
(in article <[EMAIL PROTECTED]>):

> How do I modify my regular expression to match on expressions as well
> as just single words??

import re

def createStandaloneWordRegex(word):
""" return a regular expression that can find 'peter' only if it's
written alone (next to space, start of string, end of string,
comma, etc) but not if inside another word like peterbe """

return re.compile(r'\b' + word + r'\b', re.I)


def test_createStandaloneWordRegex():
def T(word, text):
print createStandaloneWordRegex(word).findall(text)

T("peter", "So Peter Bengtsson wrote this")
T("peter", "peter")
T("peter bengtsson", "So Peter Bengtsson wrote this")
test_createStandaloneWordRegex()

Works?

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


Re: How to get/set class attributes in Python

2005-06-14 Thread Kalle Anke
On Tue, 14 Jun 2005 06:40:51 +0200, Terry Hancock wrote
(in article <[EMAIL PROTECTED]>):

> I find the biggest problem coming to Python from a language
> like C, C++, or Java is that you overthink things and try to
> do them the hard way.  A lot of times, you find out that the
> "Python way" to do the thing is so blindingly obvious that
> it just didn't occur to you that it could be that simple.

It's very possible that this is the case, I'm not experienced enough in 
Python yet to have a opinion on this yet. I tend to think in terms of larger 
systems with several programmers ... instead of what I'm actually doing 
writing code for my own pleasure.

But I'm learning new stuff every day ... so in 6 months I'll probably have an 
opinion.


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


Re: How to get/set class attributes in Python

2005-06-13 Thread Kalle Anke
On Mon, 13 Jun 2005 20:41:48 +0200, Terry Hancock wrote
(in article <[EMAIL PROTECTED]>):

> 1) Assume the variables are of a sensible type (not 
> necessarily the one you expected, though), and provide
> exception handling to catch the case where their interface
> does not match what you expect.

The problem I have with this is that I might discover an error at runtime 
instead of compile time, this means that I need to really exercise all 
possible test cases to make sure that I've covered everything (which of 
course is a good thing) but it would be easier to discover this at "compile 
time".

(note: I'm not trying to change Python, only that to me statically typing has 
it advantages also)

> Let's face it -- should it matter if you "are a programmer" 
> or only if you "can program"?  This is the difference in
> philosophy behind a dynamically-typed language like
> Python and a statically typed one like Java.

I don't really understand what you're meaning (English isn't my native 
language as you probably already have discovered)

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


Learning more about "The Python Way"

2005-06-12 Thread Kalle Anke
Those who have read my posts today have probably understood that I'm 
not a "true" Python programmer ... but I want to learn more (I think 
that Python is rather fun).

I've read "Learning Python" pretty thoroughly, I've looked at some of 
the tutorials, some of online documentation, etc. But I still miss a 
lot of pieces for writing good python code, idioms, advanced 
usage/features, etc.

I've also seen a lot of references to v3, but I haven't found any 
real documentation of what's planned for that version.

So, I'm looking for advice/information on:

+ How to write "proper" python code instead of 
  Java/Perl/C/C++/Pascal/Modula-2/etc inspired code

+ The more advanced parts/uses of Python

+ Discussions about the ideas behind different Python
  constructs

+ What's going to happen with v3

I would really appriciate some pointers to where I can find info 
about this. Web sites (I've looked at python.org but haven't manage 
to find the stuff of what I'm looking for ... but perhaps I've missed 
all the interesting parts) ? Books (I've got 'Learning Python' and 
'Programming Python')? Other things?

 jem


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


Re: How to get/set class attributes in Python

2005-06-12 Thread Kalle Anke
On Sun, 12 Jun 2005 15:35:15 +0200, John Machin wrote
(in article <[EMAIL PROTECTED]>):

> OTOH, I beseech you to consider an attitude transplant :-)

;-)

> I.e. put your effort into writing code that allows people to do useful 
> things, rather than opaque guff full of __blahblah__ that stops them 
> from doing dopey or evil things they're usually smart enough or 
> righteous enough not to do anyway.

I'm just trying to protect myself from myself :-) No, I'm playing around with 
different ways of doing things, trying to learn Python and how do things in a 
proper "pythonic" way. 

In this case I'm going to have a class with some properties that are going to 
be stored in a database, I don't want to read all the properties everytime I 
recreate the object from the database but I still want to give the impression 
that the attributes exists and is available. So my idea was to "hide" the 
actual database stuff ...

> BTW, what do you think of this:
> 
> sys.maxint = -12345

I don't really understand what you're meaning.

   jem


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


Re: How to get/set class attributes in Python

2005-06-12 Thread Kalle Anke
On Sun, 12 Jun 2005 13:59:27 +0200, deelan wrote
(in article <[EMAIL PROTECTED]>):

> the pythonic way is to use "property" (as others have already explained)
> only when is *stricly necessary*. this may clarify things up:

Thanks for the link (although Java was only one of the languages I was 
thinking of). 

Anyway, I got another "problem" (read: being used to do it like this in other 
languages). I'm used to use statically typed languages and for me one of the 
advantages is that I can be sure that a parameter is of a certain type. So in 
Java I could write

void doSomething( data : SomeClass ){ ... }

and I would be sure at compile time that I would only get SomeClass objects 
as parameters into the method.

In learning Python I've understood that I should write code in such a way 
that it can handle different data and this is fine with me. But what if I 
have a class where different attributes should only have values of a certain 
type and everything else is an error.

For example, if I have an class that defines three attributes: first and last 
name plus email address. The only valid data types for the first two are 
strings and for the last an EmailAddress class.

How should I handle this in Python? 

Should I use just don't care (but I'm going to send the data to a database so 
I need to ensure that the data is OK)? Should I use 'isinstance' and check 
manually? Or should I do something else?

(I've been trying to figure out this and other things but I haven't found 
much in books or web sites)

   jem


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


Re: How to get/set class attributes in Python

2005-06-12 Thread Kalle Anke
On Sun, 12 Jun 2005 12:20:29 +0200, tiissa wrote
(in article <[EMAIL PROTECTED]>):


> You can 'hide' you getsetters using a property attribute[1]:
> 
> [1]http://docs.python.org/lib/built-in-funcs.html

Thanks, this is exactly what I was looking for


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


How to get/set class attributes in Python

2005-06-12 Thread Kalle Anke
I'm coming to Python from other programming languages. I like to
hide all attributes of a class and to only provide access to them
via methods. Some of these languages allows me to write something
similar to this

int age( )
{
  return theAge
}

void age( x : int )
{
  theAge = x
}

(I usually do more than this in the methods). I would like to do
something similar in Python, and I've come up with two ways to do
it: The first one uses the ability to use a variable number of
arguments ... not very nice. The other is better and uses 
__setattr__ and __getattr__ in this way:

class SuperClass:
def __setattr__( self, attrname, value ):
if attrname == 'somevalue':
self.__dict__['something'] = value
else:
raise AttributeError, attrname

def __str__( self ):
return str(self.something)

class Child( SuperClass ):
def __setattr__( self, attrname, value ):
if attrname == 'funky':
self.__dict__['fun'] = value
else:
SuperClass.__setattr__( self, attrname, value )

def __str__( self ):
return SuperClass.__str__( self ) + ', ' + str(self.fun)

Is this the "Pythonic" way of doing it or should I do it in a different
way or do I have to use setX/getX (shudder)




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