Confusing datetime.datetime

2012-07-05 Thread Damjan
I've been struggling with an app that uses 
Postgresql/Psycopg2/SQLAlchemy  and I've come to this confusing 
behaviour of datetime.datetime.



First of all, the "Seconds since Epoch" timestamps are always in UTC, so 
shouldn't change with timezones. So I'd expect that a round trip of a 
timestamp through datetime.datetime, shouldn't change it.



Now, all is good when I use a naive datetime.datetime


-- TZ=UTC python
>>> from datetime import datetime
>>> dt = datetime.fromtimestamp(1341446400)
>>> dt
datetime.datetime(2012, 7, 5, 0, 0)
>>> dt.strftime('%s')
'1341446400'


-- TZ=Asia/Tokyo python
>>> from datetime import datetime
>>> dt = datetime.fromtimestamp(1341446400)
>>> dt
datetime.datetime(2012, 7, 5, 9, 0)
>>> dt.strftime('%s')
'1341446400'



But when I use an timezone aware datetime.datetime objects, the 
timestamp roundtrip is destroyed. I get 2 different timestamps.
Am I missing something here, I've been reading the datetime 
documentation several times, but I can't understand what is the intended 
behaviour.



-- TZ=UTC python
>>> from datetime import datetime
>>> import pytz
>>> tz = pytz.timezone('Europe/Skopje')
>>> dt = datetime.fromtimestamp(1341446400, tz)
>>> dt
datetime.datetime(2012, 7, 5, 2, 0, tzinfo=CEST+2:00:00 DST>)

>>> dt.strftime('%s')
'1341453600'


-- TZ=Asia/Tokyo python
>>> from datetime import datetime
>>> import pytz
>>> tz = pytz.timezone('Europe/Skopje')
>>> dt = datetime.fromtimestamp(1341446400, tz)
>>> dt
datetime.datetime(2012, 7, 5, 2, 0, tzinfo=CEST+2:00:00 DST>)

>>> dt.strftime('%s')
'1341421200'



Python 2.7.3, pytz 2012c

--
damjan

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


Re: Confusing datetime.datetime

2012-07-05 Thread Damjan

On 05.07.2012 16:10, Damjan wrote:

I've been struggling with an app that uses
Postgresql/Psycopg2/SQLAlchemy  and I've come to this confusing
behaviour of datetime.datetime.



Also this:

#! /usr/bin/python2
# retardations in python's datetime

import pytz
TZ = pytz.timezone('Europe/Skopje')

from datetime import datetime

x1 = datetime.now(tz=TZ)
x2 = datetime(x1.year, x1.month, x1.day, tzinfo=TZ)

assert x1.tzinfo == x2.tzinfo


WHY does the assert throw an error???

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


Re: Confusing datetime.datetime

2012-07-05 Thread Damjan

from datetime import datetime, timedelta, tzinfo
ZERO = timedelta(0)
HOUR = timedelta(hours=1)

class UTC(tzinfo):
 def utcoffset(self, dt):
 return ZERO
 def tzname(self, dt):
 return "UTC"
 def dst(self, dt):
 return ZERO

utc = UTC()
t1 = datetime.now(tz=utc)
t2 = datetime(t1.year, t1.month, t1.day, tzinfo=utc)
assert t1.tzinfo == t2.tzinfo


No assertion error at all.

This makes me think that the "retardation" as you put it is not in
Python's datetime module at all, but in pytz.

What does TZ == TZ give? If it returns False, I recommend you report it
as a bug against the pytz module.


It returns True, so it seems to be changed in the datetime object??

I tried both 2.7 and 3.2

--
damjan

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


Re: why greenlet, gevent or the stackless are needed?

2012-07-07 Thread Damjan

On 07.07.2012 09:09, self.python wrote:

(I'm very new to this coroutine part
so It's not supposed to attack these modules,
just I don't know the differences)

atfer version 2.5, python officially support coroutine with yield.
and then, why greenlet, gevent, Stackless python are still useful?

it there somthing that "yield" can't do
or just it is easier or powerful?


The greenlet site has some very simple examples what it can provide.
For example jumping from one function in another, and back

http://greenlet.readthedocs.org/en/latest/index.html


Gevent then uses greenlet to do lightweight "processes" (greenlets) that 
are I/O scheduled. This allows for a simple model of programming that 
scales to a large number of concurrent connections. You could do that 
with threads but you can't start as many threads as greenlets, since 
they have a much larger memory address space footprint.


There's one function, called the gevent hub, that waits for any I/O 
event and then switches to the function that "blocked" on that I/O.





--
damjan

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


Re: Confusing datetime.datetime

2012-07-08 Thread Damjan

Because x1 and x2 have different time zones.

The tzinfo field in x2 is equal to TZ and has a UTC offset of 1 hour.
The tzinfo field in x1 contains the DST version of that timezone,
with a UTC offset of 2 hours, because Skopje is currently on DST.

I think you want:

x2 = TZ.localize(datetime(x1.year, x1.month, x1.day))

That produces a datetime with the year, month and day set as indicated
and tzinfo set to the correct UTC offset for that date, at 00:00 hours.

Or maybe you need:

x2 = TZ.localize(datetime(x1.year, x1.month, x1.day, 12))
x2 = x2.replace(hour=0)

That determines whether DST should be on at noon, and then resets the
hour field to zero.  This produces the same outcome as the one liner,
except on days when DST is switched on or off.



Thanks, I think this will help me.

Although these issues seem very much underdocumented in the datetime 
documentation. Are there any good references of using good times in Python?




--
damjan

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


Re: 1 Million users.. I can't Scale!!

2005-09-28 Thread Damjan
> If you want to use a multithreaded design, then simply use a python
> Queue.Queue for each delivery channel. If you want to use a
> multi-process design, devise a simple protocol for communicating those
> messages from your generating database/process to your delivery channel
> over TCP sockets.

Is there some python module that provides a multi process Queue?

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


Re: Confused on Kid

2005-10-25 Thread Damjan
> I was
> investigating each subproject individually and could not, for the life
> of me figure out how Kid worked.  I understand that it takes a
> well-formed XML document and transforms it, but I could not figure out
> where it transforms it, or how to transform a document.  They have
> plenty of template examples, but I'm left say, "What do I do with this?"
> I know I can't just pop in it a browser because it has no sort of style
> sheet or anything so it would just render as an XML document.  What do
> you do after you have a kid template?

KID is a pythonic template system. The KID templates are well-formed XML
files but the generated document can be HTML or even plain text (this
should be supported in some of the latest versions).

The KID templates have some simple control structures like 'if' and 'for'
which are modeled to be similar to python. The way it works is you feed the
template some data and it generates HTML documents. The document can have a
reference to a CSS file just like any other HTML page.

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


cx_Oracle, is anything selected?

2005-10-31 Thread Damjan
Is there a way to see if the SELECT in cx_Oracle didn't return anything?
I want to optimize the situation when the number of selected rows is zero.
Is select count(*) the only option, seems inefficient?

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


Re: cx_Oracle, is anything selected?

2005-11-01 Thread Damjan
>> Is there a way to see if the SELECT in cx_Oracle didn't return anything?
>> I want to optimize the situation when the number of selected rows is
>> zero. Is select count(*) the only option, seems inefficient?
> 
> I don't understand your problem - if your select doesn't return
> anything, the fetch* methods on the cursor will tell you if there is any
> data to expect at all. Additionally there is teh rowcount-property that
> holds the number of rows the last execute* yielded.

This is a simplification of the program

c = db.cursor()
while 1:
c.execute('select ')
smtp = SMTP(MAIL_HOST, 25, 'localhost')
for address, subject, body in c:
smtp.sendmail()
smtp.quit()
time.sleep(60)

now if the select doesn't return any rows, there's no need to connect to the
mail server. I'd like to avoid that unnecessary step.

c.rowcount will not give me the number of rows selected, it will only give
me the number of rows already fetched.


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


Re: cx_Oracle, is anything selected?

2005-11-01 Thread Damjan
> Apart from that: what harm does the connection to the smpt do? If it
> works - keep it that way.

I worry about being banned from the server.

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


Re: how to write a blog system with Python

2005-11-08 Thread Damjan
> I am a fresh here , and I have no idea of it.
> Do you have any comments?

Take a look at aether, a single CGI script and it's easy to understand.
http://www.logarithmic.net/pfh/aether


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


mod_python web-dav management system

2005-11-11 Thread Damjan
Apache2 comes with builtin Web-dav support, but authorization is limited to
Apache's methods, which are not very flexible.

Now I've been thinking that it might be pretty easy to implement a
authorization layer with mod_python (but living handling of the web-dav
protocol to apache)... So, has anyone already done something similar?

A management web-ui would be nice too.


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


Re: mod_python web-dav management system

2005-11-14 Thread Damjan
> Zope has WebDAV support and is written in Python.  You could
> use Zope or perhaps use "parts" of it (since it is open source).

I wouldn't use Zope as file storage. The ZODB is inefficient for storing big
files.


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


Re: HTML generation vs PSP vs Templating Engines

2005-11-16 Thread Damjan
> After some thought I decided to leave the various frameworks
> aside for the time being and use mod_python.publisher along with some
> means of generating HTML on the fly.

I kind of like KID templates the most, you can easyly work with them in any
HTML authoring software, they are easy to use (prety much pythonic).


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


Re: python-mysqldb__debian_to_freebsd

2005-11-16 Thread Damjan
>   Is there any at all chance that this will work
>   with the proper configs or should I go ahead
>   and beg the host for an installation ?

It seems to me very unlikely that a program compiled for FreeBSD would link
to a library compiled for Debian Linux which in turn was linked to a Debian
libmysql but now has to work with the FreeBSD libmysql... I just don't
beleive you can make this work.

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


Unicode in MIMEText

2005-11-23 Thread Damjan
Why doesn't this work:

from email.MIMEText import MIMEText
msg = MIMEText(u'\u043a\u0438\u0440\u0438\u043b\u0438\u0446\u0430')
msg.set_charset('utf-8')
msg.as_string()
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/email/Message.py", line 129, in as_string
g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib/python2.4/email/Generator.py", line 82, in flatten
self._write(msg)
  File "/usr/lib/python2.4/email/Generator.py", line 113, in _write
self._dispatch(msg)
  File "/usr/lib/python2.4/email/Generator.py", line 139, in _dispatch
meth(msg)
  File "/usr/lib/python2.4/email/Generator.py", line 180, in _handle_text
payload = cset.body_encode(payload)
  File "/usr/lib/python2.4/email/Charset.py", line 366, in body_encode
return email.base64MIME.body_encode(s)
  File "/usr/lib/python2.4/email/base64MIME.py", line 136, in encode
enc = b2a_base64(s[i:i + max_unencoded])
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-7:
ordinal not in range(128)

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


Re: Unicode in MIMEText

2005-11-23 Thread Damjan
> Why doesn't this work:
> 
> from email.MIMEText import MIMEText
> msg = MIMEText(u'\u043a\u0438\u0440\u0438\u043b\u0438\u0446\u0430')
> msg.set_charset('utf-8')
> msg.as_string()
...
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-7:
> ordinal not in range(128)

It's a real shame that unicode support in the python library is very weak
sometimes...

Anyway I solved my problem by patching email.Charset

--- Charset.py~ 2005-11-24 04:20:09.0 +0100
+++ Charset.py  2005-11-24 04:21:02.0 +0100
@@ -244,6 +244,8 @@
 """Convert a string from the input_codec to the output_codec."""
 if self.input_codec <> self.output_codec:
 return unicode(s, self.input_codec).encode(self.output_codec)
+elif isinstance(s, unicode):
+return s.encode(self.output_codec)
 else:
 return s





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


Re: ANNOUNCE: Mod_python 3.2.5 Beta

2005-11-23 Thread Damjan
> The Apache Software Foundation and The Apache HTTP Server Project are
> pleased to announce the 3.2.5 Beta release mod_python.
http://www.modpython.org/live/mod_python-3.2.5b/doc-html/hand-pub-alg-auth.html

says "Since functions cannot be assigned attributes,..."

But that's not true (at least in 2.3 and 2.4):

>>> def f():
...   return 'a'
...
>>> f.__auth__ = {1:'one'}


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


Re: Unicode in MIMEText

2005-11-25 Thread Damjan
> ... and being concerned to improve the library you logged this patch in
> Sourceforge for consideration by the developers?
> 
> That's the only way to guarantee proper consideration of your fix.

Ok I will, can you confirm that the patch is correct?
Maybe I got something wrong?


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


Any way to change files in a ZIP archive?

2005-11-25 Thread Damjan
I am looking for a way to change a file that is inside a zip archive, in
python of course.

The thing is, I'm doing a CGI script that accepts a zip file (an OpenOffice
document), I need to make some transformations to one of the files in the
ZIP archive, but not touch any of the other files in it, and then send the
result back.

I've made the most of my script, but I can't find a way to replace (freshen)
the file that's already in the archive?


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


Re: Unicode in MIMEText

2005-11-28 Thread Damjan
patch submitted... 

> Thanks for taking the time to improve the quality of the Python library.

Do you think it would be possible to do some kind of an automatic 
comprehensive test of compatibility of the standard library with unicode
strings?


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


Re: Oracle 9i client for Linux

2005-11-30 Thread Damjan
This is a list of files I use to compile cx_Oracle, php-oci amd perl
DB::OCI on Linux.
I set ORACLE_HOME to /usr/lib/oracle and symlink the *.so files in
/usr/lib so that I don't need to set LD_LIBRARY_PATH.
I guess this list can be reduced some more... but I got tired of
experimenting

And the instant client 10.0 will work with a 9i database, but will not
work with some 8.0 and 8.1 databases.

/usr/lib/oracle/lib/classes12.jar
/usr/lib/oracle/lib/libclntsh.so.10.1
/usr/lib/oracle/lib/libnnz10.so
/usr/lib/oracle/lib/libocci.so.10.1
/usr/lib/oracle/lib/libociei.so
/usr/lib/oracle/lib/libocijdbc10.so
/usr/lib/oracle/lib/ojdbc14.jar
/usr/lib/oracle/lib/libclntsh.so
/usr/lib/oracle/lib/libocci.so
/usr/lib/oracle/rdbms/
/usr/lib/oracle/rdbms/public/
/usr/lib/oracle/rdbms/public/nzerror.h
/usr/lib/oracle/rdbms/public/nzt.h
/usr/lib/oracle/rdbms/public/occi.h
/usr/lib/oracle/rdbms/public/occiAQ.h
/usr/lib/oracle/rdbms/public/occiCommon.h
/usr/lib/oracle/rdbms/public/occiControl.h
/usr/lib/oracle/rdbms/public/occiData.h
/usr/lib/oracle/rdbms/public/occiObjects.h
/usr/lib/oracle/rdbms/public/oci.h
/usr/lib/oracle/rdbms/public/oci1.h
/usr/lib/oracle/rdbms/public/oci8dp.h
/usr/lib/oracle/rdbms/public/ociap.h
/usr/lib/oracle/rdbms/public/ociapr.h
/usr/lib/oracle/rdbms/public/ocidef.h
/usr/lib/oracle/rdbms/public/ocidem.h
/usr/lib/oracle/rdbms/public/ocidfn.h
/usr/lib/oracle/rdbms/public/ociextp.h
/usr/lib/oracle/rdbms/public/ocikpr.h
/usr/lib/oracle/rdbms/public/ocixmldb.h
/usr/lib/oracle/rdbms/public/odci.h
/usr/lib/oracle/rdbms/public/oratypes.h
/usr/lib/oracle/rdbms/public/ori.h
/usr/lib/oracle/rdbms/public/orid.h
/usr/lib/oracle/rdbms/public/orl.h
/usr/lib/oracle/rdbms/public/oro.h
/usr/lib/oracle/rdbms/public/ort.h
/usr/lib/oracle/rdbms/public/xa.h
/usr/lib/oracle/rdbms/demo/
/usr/lib/oracle/rdbms/demo/cdemo81.c
/usr/lib/oracle/rdbms/demo/demo.mk
/usr/lib/oracle/rdbms/demo/occidemo.sql
/usr/lib/oracle/rdbms/demo/occidemod.sql
/usr/lib/oracle/rdbms/demo/occidml.cpp

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


small inconsistency in ElementTree (1.2.6)

2005-12-08 Thread Damjan
Attached is the smallest test case, that shows that ElementTree returns
a
string object if the text in the tree is only ascii, but returns a
unicode
object otherwise.

This would make sense if the sting object and unicode object were
interchangeable... but they are not - one example, the translate method
is
completelly different.

I've tested with cElementTree (1.0.2) too, it has the same behaviour.

Any suggestions?
Do I need to check the output of ElementTree everytime, or there's some
hidden switch to change this behaviour?

from elementtree import ElementTree

xml = """\


   ascii 
   \xd0\xba\xd0\xb8\xd1\x80\xd0\xb8\xd0\xbb\xd0\xb8\xd1\x86\xd0\xb0


"""

tree = ElementTree.fromstring(xml)
p1, p2 = tree.getchildren()
print "type(p1.text):", type(p1.text)
print "type(p2.text):", type(p2.text)

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


Re: small inconsistency in ElementTree (1.2.6)

2005-12-09 Thread Damjan
>> Do I need to check the output of ElementTree everytime, or there's some
>> hidden switch to change this behaviour?
>
> no.
>
> ascii strings and unicode strings are perfectly interchangable, with some
> minor exceptions.

It's not only translate, it's decode too... probably other methods and
behaviour differ too.
And the bigger picture, string objects are really only byte sequences,
while
text is consisted of characters and that's what unicode strings are
for,
strings-made-of-characters.

It seems to me more logical that an et.text to be a unicode object
always.
It's text, right!

> if you find yourself using translate all the time
> (why?), add an explicit conversion to the translate code.

I'm using translate because I need it :)

I'm currently just wrapping anything from ElementTree in unicode(), but
this
seems like an ugly step.

> (fwiw, I'd say this is a bug in translate rather than in elementtree)

I wonder what the python devels will say? ;)

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


Re: small inconsistency in ElementTree (1.2.6)

2005-12-10 Thread Damjan
>>> ascii strings and unicode strings are perfectly interchangable, with
>>> some minor exceptions.
>>
>> It's not only translate, it's decode too...
>
> why would you use decode on the strings you get back from ET ?

Long story... some time ago when computers wouldn't support charsets
people
invented so called "cyrillic fonts" - ie a font that has cyrillic
glyphs
mapped on the latin posstions. Since our cyrillic alphabet has 31
characters, some characters in said fonts were mapped to { or ~ etc..
Of
course this ,,sollution" is awful but it was the only one at the
time.

So I'm making a python script that takes an OpenDocument file and
translates
it to UTF-8...

ps. I use translate now, but I was making a general note that unicode
and
string objects are not 100% interchangeable. translate, encode, decode
are
especially problematic.

anyway, I wrap the output of ET in unicode() now... I don't see
another, better, sollution.

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


Python curses wizard

2005-01-24 Thread Damjan
Is there some tool that can help me design a simple curses wizards,
preferably one that uses Python, but if there's some other sollution I'd be
happy to hear. The important requirement is that its curses based (or
similar text based UI).


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


Re: execute python code from db

2005-01-26 Thread Damjan
> for python_code in c.fetchall():
> execute (python_code)
> 
> Maybe feed python with stdin??.

eval

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


Re: importing a package

2005-06-22 Thread Damjan
> I developed a package with a structure like this
> src/
> tesfile.py
> dir1/
> __init__.py
> file1.py
> dir2/
> __init__.py
> file2.py

Importing dir2/file2 from dir1/file1.py works here, because when yuo started
the testfile script the src/ directory was added to the sys.path list.

If you relocate dir1/ and dir2/ in a "package" directory here it will not
work.


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


MySQLdb reconnect

2005-06-22 Thread Damjan
Does MySQLdb automatically reconnect if the connection to the database is
broken?

I'm asking this since I have a longrunning Python precess that is connected
to Mysql-4.1.11, and I execute "set names utf8" when I connect to it.

But after running a day the results from the python program were displayed
as if the "set names utf8" was not executed i.e. I got question marks where
utf-8 cyrillics should've appeared. After restarting the Python program
everything was ok, just as when I first started it.

The long running Python process is actually a scgi quixote web application.


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


Re: importing a package

2005-06-22 Thread Damjan
> Indeed, when i do this, then it works
> import sys
> sys.path.append('package')
> 
> However, why is it that package isn't added automatically to the pad?

When you execute a python program the directory where the program is is
automatically added to sys.path. No other directory is added to the default
builtin sys.path.

In you case (the second case), you can import package.dir2.file2.


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


Re: MySQLdb reconnect

2005-06-29 Thread Damjan
> Does MySQLdb automatically reconnect if the connection to the database is
> broken?

It seems so.

> I'm asking this since I have a longrunning Python precess that is
> connected to Mysql-4.1.11, and I execute "set names utf8" when I connect
> to it.
> 
> But after running a day the results from the python program were displayed
> as if the "set names utf8" was not executed i.e. I got question marks
> where utf-8 cyrillics should've appeared. After restarting the Python
> program everything was ok, just as when I first started it.

This is the sollution I've come to:

try:
# This will fail on MySQL < 4.1
db = MySQLdb.connect(godot.dbhost, godot.dbuser, godot.dbpass,
godot.dbname, use_unicode=1, init_command="set names utf8")
except MySQLdb.OperationalError:
db = MySQLdb.connect(godot.dbhost, godot.dbuser, godot.dbpass,
    godot.dbname, use_unicode=1)
db.charset = 'utf8'


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


Re: ANN: CherryPy-2.1.0-beta released

2005-07-15 Thread Damjan
> I am happy to announce the first beta release of CherryPy-2.1

Can you briefly compare CherryPy to Quixote2 (+session2)?

> unicode decoding/encoding,

This especially interesting to me. 
Is CherryPy completelly unicode (and UTF-8) ready. 
The thing that frustrates me about quixote2 is that it has a lot of
assumptions that text is a str object in the latin1 encoding. 
I succeded to patch quixote to be usable but that may not be enough.

My quixote application works with unicode objects all the time, and the only
place I want UTF-8 is when the content is sent to the client... (or when
its stored in a database or file which I handle myself fine).

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


Re: Python scripts wont run - HELP

2005-07-18 Thread Damjan

> I'm a fairly literate windoz amateur programmer mostly in visual basic. I
> have switched to SuSE 9.2 Pro and am trying to quickly come up to speed
> with Python 2.3.4.  I can run three or four line scripts from the command
> line but have not been able to execute a script from a file.
> 
> I have used EMACS and JEDIT to create small test routines.  I would right
> click the file and set properties to executable.  I would then click the
> icon, the bouncy ball would do its thing then a dialog box would flash on
> the screen for a fraction of a second.  I could tell it had a progress bar
> on it but could not catch anything else on it.  Then nothing else would
> happen.
> 
> If I could execute a script the world would once again be my playground...
> PLEASE HELP.

Open a terminal program like "konsole". 
change the directory to where your files are ("cd /path/to/files/").
execute them ("python my-script.py').


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


Re: python image thumbnail generator?

2005-08-29 Thread Damjan
Chris Dewin wrote:

> Hi. I run a website for my band, and the other guys want an image gallery.
> 
> I'm thinking it would be nice and easy, if we could just upload a jpg into
> a dir called "gallery/". When the client clicks the "gallery" link, a
> cgi script could search the gallery/ dir, and create thumbnails of any
> jpeg images that don't already have a thumbnail associated with them. The
> script could then generate a page of clickable thumbnails.

Once I made an example mod_python handler, that resized images on the fly.
For example:
 http://server/folder/image.jpg - would give you the original image, served
directly by apache without any performance hit.

 http://server/folder/image.jpg?thumbnail  - would resize the picture (and
cache the result on disk) and return that, on a second request it would
return the cached image very fast by calling an apache.send_file function.

see
http://www.modpython.org/pipermail/mod_python/2004-September/016471.html

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


Re: Python on WWW - beginners question: what to choose?

2005-02-07 Thread Damjan
> I'm satisfied with concept of mps, however It's fine that author hate
> writing HTML, but I want to; or better, I want to use Cheetah Templates -
> i think they are better for bigger sites (then homepage) as the one I want
> to write.

Also, check out simpletal (http://www.owlfish.com/software/simpleTAL/) 


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


Re: Big development in the GUI realm

2005-02-07 Thread Damjan
> For all you GUI developers, things just got a little more interesting.
> Trolltech will soon be offering the QT GUI toolkit for Windows under
> the GPL license.  That means that PyQt may become a much more popular
> option in the near future.  

This  applies to QT-4 only. 
I wonder how much of PyQT is ready for QT4?

Anyway its time for a PyQT based VB-killer [ a GPL one :) ].


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


Re: Big development in the GUI realm

2005-02-07 Thread Damjan
> Isn't this just the same thing with a different spin. There was always
> an available distribution for linux for non-commercial use. Windows was
> always the problem. You still can't use it for windows without knowing
> how to compile the thing on windows.
 
There'll be people that know how to compile :), and they'll be able to
release & distibute binaries... Previously you couldn't even compile the
GPL QT on windows, since it lacks the low-level win32 api calls that do all
the work.

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


Re: Big development in the GUI realm

2005-02-08 Thread Damjan
> However, imagine simple situation:
> 1. I write proprietary program with open plugin api. I even make the api
> itself public domain. Program works by itself, does not contain any
> GPL-ed code.
> 2. Later someone writes plugin using the api (which is public domain so
> is GPL compatible), plugin gets loaded into my software, significantly
> affecting its functionality (UI, operations, file formats, whatever).
> 3. Someone downloads the plugin and loads it into my program

I don't think it is legal to distribute the plugin in binary form. 
OTOH it should be legal to distribute it as source code.
 
> Am I bound by GPL? Certainly not, I did not sign or agree to it in way.

correct


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


Re: Reportlab and Barcodes

2005-02-09 Thread Damjan
> One of the users on the Reportlabs mailing list was kinda enough to
> offer me the solution.. A simple call to the drawOn function, e.g.:
> 
> bc = code39.Standard39("123",xdim = .015*inch)

whats code39 in this example?

> x = 6*inch
> y = -5*inch
> bc.drawOn(canvas,x,y)

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


Re: Big development in the GUI realm

2005-02-11 Thread Damjan
> The problem with this is what I've called the "patch hole" in another
> context [1]. The problem with this definition is that I can *always*
> distribute GPL'ed parts separately and re-combine them arbitrarily upon
> execution, and it's not even particularly hard. Write your code with the
> GPL'ed code embedded. At the end, before you distribute, extract it and
> record the extraction so your program can "rewind it"; you're left with
> nothing in your code that is GPLed. Later, the user will go get the GPL
> software, and you software "rewinds" the extraction process, and the user
> is left with something that is byte-for-byte identical to what you weren't
> allowed to distribute by the GPL so what good was the GPL?

What you described is not ok according to the GPL - since you distributed a
binary thats derived from GPL software (and you didn't publish it source
code under the GPL too).

> Nobody really knows what the GPL means when it gets down to it; 

If you don't know, you should ask the person whose GPL code you are using.

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


ElementTree, how to get the whole content of a tag

2005-03-16 Thread Damjan
Given the folowing XML snippet, I build an ElementTree instance with
et=ElementTree.fromstring(..). Now et.text returns just '\n  text\n  some
other text'. 
Is there any way I could get everything between the  and  tag?


  text
  some other text
  and then some more



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


Re: I can do it in sed...

2005-03-16 Thread Damjan
Or, much nicer

> if line[:5]=='start': printing=1

if line.startswith('start'): printing=1

> if line[:3]=='end':  printing=0

if line.endswith('end'):  printing=0

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


Re: ElementTree, how to get the whole content of a tag

2005-03-16 Thread Damjan
>> Is there any way I could get everything between the  and  tag?
>>
>> 
>>  text
>>  some other text
>>  and then some more
>> 

>>>> gettext(et)
> '\n  text\n  some other text\n  and then some more\n'

I acctually need to get 
'\n  text\n  some other text\n  and then some more\n'

And if there were attributes in  I'd want them too where they were. 
Can't I just get ALL the text between the  tags?

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



Re: MySQLdb problem with mod_python, please help

2004-11-30 Thread Damjan
> MySQLdb is working fine at command line, however when I tried to use
> it with mod_python, it give me a "server not initialized" error.

Maybe its this problem?
http://www.modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp

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


Re: cross platform use of set locale

2005-03-23 Thread Damjan
> SUS has added numeric grouping
> 
>For  some  numeric conversions a radix character (`decimal
>point') or thousands'  grouping  character  is  used.  The
>actual  character  used  depends on the LC_NUMERIC part of
>the locale. The POSIX locale uses `.' as radix  character,
>and does not have a grouping character.  Thus,
>printf("%'.2f", 1234567.89);
>results   in   `1234567.89'   in   the  POSIX  locale,  in
>`1234567,89' in the nl_NL locale, and in `1.234.567,89' in
>the da_DK locale.

Hmm, this C code on my system (mk_MK locale)
#include 
#include 
int main (void) {
setlocale(LC_ALL,"");
printf("%'.2f\n", 1234567.89);
return 0;
}
Outputs: 1 234 567,89 as expected.

But this Python program (2.3.4 [GCC 3.3.3] on linux2)
 import locale
 locale.setlocale(locale.LC_ALL, "")
 print locale.format("%'.2f", 1234567.89, grouping=True)

complains about the ' in the format
ValueError: unsupported format character ''' (0x27) at index 1
without the ' it outputs: 1234567,89

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


Re: escape single and double quotes

2005-03-24 Thread Damjan
> I'm working with a Python program to insert / update textual data into a
> PostgreSQL database. The text has single and double quotes in it, and I
> wonder: What is the easiest way to escape quotes in Python, similar to
> the Perlism "$str =~ s/(['"])/\\$1/g;"?
> 
> I tried the re.escape() method, but it escapes far too much, including
> spaces and accented characters. I only want to escape single and double
> quotes, everything else should be acceptable to the database.

You don't need to escape text when using the Python DB-API. 
DB-API will do everything for you.
For example:
 SQL = 'INSERT into TEMP data = %s'
 c.execute(SQL, """ text containing ' and ` and all other stuff we might 
  read from the network""")

You see, the SQL string contains a %s placeholder, but insetad of executing
the simple string expansion SQL % """""", I call the execute method
with the text as a second *parametar*. Everything else is magic :).





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


Re: string join() method

2005-03-24 Thread Damjan
> but perhaps the webserver sanitizes the output of CGI script and converts
> plain "\n" into "\r\n" 

Yes apache does this, since it adds its own headers anyway it will replace
all '\n' in the headers with '\r\n' and '\n\n' with '\r\n\r\n'.


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


Re: non-ascii charater image gereration with PIL

2005-04-11 Thread Damjan
> PIL has 'text(position, string, options)' method in its ImageDraw module.
> Does this work with unicode or other 2byte encoded string?
> It seems not working on my python2.3.5 with PIL 1.1.5.

Yes, just tried and it works (python-2.4/PIL 1.1.5), but you also need a
font that supports your characters, see this script:

text = unicode('some cyrillic text: ÐÐÑÐÐÐ', 'utf-8')
from PIL import ImageFont, ImageDraw, Image
image = Image.new('RGB',(400,300))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(".fonts/dejavu-ttf/DejaVuSans.ttf", 12)
draw.text((10, 10), text, font=font)
image.save('wow.jpg')

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


Re: PyChart into web site error

2005-04-13 Thread Damjan
>>>AttributeError: 'module' object has no attribute 'argv'
>>>
>>>Why my script doesn't have sys.argv?
...
>> How are you serving the pages?
> 
> Apache 2.0.48, mod_python 3.1.3 and Python 2.3.3
> on my mdk 10.0

Obviosly when using mod_python there's no sys.argv (and what would it
contain if it existed??).

Now the real question is why PyChart needs sys.argv?

OTOH, maybe you can make a dummy sys module in your script that provides
sys.argv??


BTW, I tested with Apache 2.0.53, mod_python 3.1.4 and Python 2.4 to confirm
there's no sys.argv in the mod_python environment.

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


Re: using locales

2005-04-20 Thread Damjan
> Is there some sort of tutorial on locales or the locale module?
> 
> I can't seem to find a list showing all possible locales. 

I think this depends on the platform

> Anyway, I'd love to have a method called get_available_locales to tell
> me what I can use on my machine, or something like that.
> 
> Can anyone tell me how I *do* get these names?

In linux (glibc) you can see all locales with "locale -a".


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


Re: quick unicode Q

2005-12-15 Thread Damjan
>> Read it as a string, and then decode it with the .decode method.  You
>> specify what encoding it's in.
>
> Most probably, the OP is asking what to do with an UTF-8 encoded string.
>
> To decode that, just use:
>
> s.decode("utf-8")

I prefer:

unicode(s, 'utf-8')

That way it's more clear that what you get is a unicode object.

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


Re: SVG rendering with Python

2005-12-15 Thread Damjan
Do you want to create a SVG file or display a SVG file?

SVG files are just XML so maybe you can create them easyly?

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


Re: OO in Python? ^^

2005-12-15 Thread Damjan
> sorry for my ignorance, but after reading the Python tutorial on
> python.org, I'm sort of, well surprised about the lack of OOP
> capabilities in python. Honestly, I don't even see the point at all of
> how OO actually works in Python.

> For one, is there any good reason why I should ever inherit from a
> class? ^^ There is no functionality to check if a subclass correctly
> implements an inherited interface and polymorphism seems to be missing
> in Python as well. I kind of can't imagine in which circumstances
> inheritance in Python helps. For example:

Python IS Object Oriented, since everything is an object in Python,
even functions, strings, modules, classes and class instances.

But Python is also dynamically typed so inheritance and polymorphism,
ideas coming from other languages, are not that much important.

> Please give me hope that Python is still worth learning

Python is different than C/C++, Java and co.
If you can pass over it, you'll see for yourself if it's worth learning.

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


Re: SMPP implementation in python

2006-01-17 Thread Damjan
You can see some code here http://pysmpp.sourceforge.net/ but it's not
complete... it need much more work.

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


Re: unicode html

2006-07-17 Thread Damjan
> Hi, I've found lots of material on the net about unicode html
> conversions, but still i'm having many problems converting unicode
> characters to html entities. Is there any available function to solve
> this issue?
> As an example I would like to do this kind of conversion:
> \uc3B4 => ô

'&#%d;' % ord(u'\u0430')

or

'&#x%x;' % ord(u'\u0430')

> for all available html entities.


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


Re: ImportError: libclntsh.so.10.1: cannot open shared object file: Permission denied

2006-07-20 Thread Damjan
> I am using RedHat Linux 4. and I developed an oracle 10g based
> application by using cx_Oracle (cx_Oracle-4.1-10g-py23-1.i386.rpm) and
> Python 2.3.4.
> 
> When I run the application through direct console connection, It works
> perfect.
> 
> But, when I schedule a crontab job to run the application, It logs this
> error:
> 
> Traceback (most recent call last):
>   File "/home/nsm1/NSM1/NSM1.py", line 5, in ?
> import cx_Oracle
> ImportError: libclntsh.so.10.1: cannot open shared object file:
> Permission denied
...
> I have the following settings in my /etc/profile file:
> 
> #---
> ORACLE_BASE=/home/oracle/oracle/product
> ORACLE_HOME=$ORACLE_BASE/10.2.0/db_1
> LD_LIBRARY_PATH=$ORACLE_HOME/lib
> PATH=$PATH:$ORACLE_HOME/bin
> ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
> export ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH PATH
> #---

These environment variables are important for running any programs that use
the oracle client libraries. The problem you have is that when you run the
script from cron these environment variables are not set.

Now, there are several ways how to handle this:
1. create a shell script that you call from cron, and it it set the
environment variables and then call you python program

2. modify the environment in your python program (via os.environ) and then
import cx_Oracle

3. modify your system so that no environment variables are neccesseary -
actually this is not possible, but what I have is, symbolic links
in /usr/lib to the libraries in $ORACLE_HOME/lib, thus I don't need the 
LD_LIBRARY_PATH variable, and the only other variable I need is the
ORACLE_HOME, which is /usr/share/oracle on my system and it contains 
bin/  install/  lib/  network/  ocommon/  oracore/  rdbms/  sqlplus/




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


Re: threading+ftp+import => block

2006-07-25 Thread Damjan
Panard wrote:

> Hi,
> I'm experiencing a strange problem while trying to manage a ftp connection
> into a separate thread.
> 
> I'm on linux, python 2.4.3
> 
> Here is a test :
> -- ftp_thread.py --
> import ftplib
> import threading
> import datetime
> 
> class test( threading.Thread ) :
> ftp_conn = ftplib.FTP("localhost","user","pass")
> def run( self ) :
> print self.ftp_conn.pwd()
> self.ftp_conn.dir("/")
> print datetime.date.today()
> def t() :
> t = test()
> t.start()
> t.join()
> t()
> ---
> 
> If I do :
> $ python ftp_thread.py
> /
> drwxrwsr-x   2 panard   ftp  4096 Jul 24 12:48 archives
> 2006-07-24
> ==> Works perfectly
> 
> But :
> $ python
>>>> import ftp_thread
> /
> 

This has been documented in the blog posts titled "How well you know Python"
(find it on google)

The problem is that, once you run "import ftp_thread" a lock is set in the
Python interpreter, so then you can't start a new thread... (this from the
back of my mind).



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


Re: threading+ftp+import => block

2006-07-25 Thread Damjan
Damjan wrote:

> Panard wrote:
> 
>> Hi,
>> I'm experiencing a strange problem while trying to manage a ftp
>> connection into a separate thread.
>> 
>> I'm on linux, python 2.4.3
>> 
>> Here is a test :
>> -- ftp_thread.py --
>> import ftplib
>> import threading
>> import datetime
>> 
>> class test( threading.Thread ) :
>> ftp_conn = ftplib.FTP("localhost","user","pass")
>> def run( self ) :
>> print self.ftp_conn.pwd()
>> self.ftp_conn.dir("/")
>> print datetime.date.today()
>> def t() :
>> t = test()
>> t.start()
>> t.join()
>> t()
>> ---
>> 
>> If I do :
>> $ python ftp_thread.py
>> /
>> drwxrwsr-x   2 panard   ftp  4096 Jul 24 12:48 archives
>> 2006-07-24
>> ==> Works perfectly
>> 
>> But :
>> $ python
>>>>> import ftp_thread
>> /
>> 
> 
> This has been documented in the blog posts titled "How well you know
> Python" (find it on google)
> 
> The problem is that, once you run "import ftp_thread" a lock is set in the
> Python interpreter, so then you can't start a new thread... (this from the
> back of my mind).

Actually, testing with
class test( threading.Thread ) :
def run( self ) :
print 'Hello'

instead of your test class, didn't show this anomally... actually the
problem is that "import ftp_thread" sets a lock on *importing* other
modules and I thing that the call to "self.ftp_conn.dir("/")" deep down in
the ftplib module tries to "import re" and that's where it hangs.

You could try to move the "import re" in ftplib to the top of the module,
and submit a patch to the Python bug system.



Here's a simpler test class that hangs:

import threading
class test(threading.Thread):
import string
print 'Step one'
def run(self):
import re
print 'Hangs before this when this file is imported'

def t() :
t = test()
t.start()
t.join()
t()



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


Re: Need a compelling argument to use Django instead of Rails

2006-07-25 Thread Damjan
> A few months ago I had to choose between RoR and a Python framework
> (TurboGears in that case). I picked TurboGears because of the language
> maturity and all the third party libs. i.e. I can do PDF reporting with
> reportLab, control OpenOffice with Python..

This is a good argument, you should make a list of all the greatest python
libraries that you could use for your projects, for ex. reportlab, PIL,
doctools, elementtree, sqlalchemy etc etc and try to "sell" that.

BTW I'd choose TurboGears for it's flexibility, but I guess Django could be
nice when more rapid results are needed (and the problem doesn't fall too
far from the Django sweet spot).

>> "Nah, we're not interested in Python."

This is a hard attitude, but I have the same feeling about Ruby, I like
Python and just don't see a reason to invest any time in Ruby (Rails or
not).. and from that little I've seen from it.. I didn't like it. 
OTOH Ruby surelly is not that bad either.

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


Re: How to force a thread to stop

2006-07-29 Thread Damjan
> | A common recovery mechanism in embedded systems is a watchdog timer,
> | which is a hardware device that must be poked by the software every
> | so often (e.g. by writing to some register).  If too long an interval
> | goes by without a poke, the WDT hard-resets the cpu.  Normally the
> | software would poke the WDT from its normal periodic timing routine.
> | A loop like you describe would stop the timing routine from running,
> | eventually resulting in a reset.
> 
> *grin* - Yes of course - if the WDT was enabled - its something that I
> have not seen on PC's yet...

The intel 810 chipset (and all after that) has a builtin watchdog timer -
unfortunetally on some motherboards it's disabled (I guess in the BIOS).

How do I know that?
Once I got Linux installed on a new machine and although the install
went without a problem, after the first boot the machine would reboot on
exactly 2 minutes. 
After a bit of poking around I found that hotplug detected the WDT support
and loaded the driver for it (i8xx_tco), and it seems the WDT chip was set
to start ticking right away after the driver poked it. 



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


Re: Windows vs. Linux

2006-07-30 Thread Damjan
> Right now I run Windows as my main operating system.  On my old
> laptop I ran Ubuntu, and liked it very much; however, my new laptop has
> a Broadcom wireless card, and it's not very Linux friendly.

of topic: that Broadcom wireless card has a driver included in the latest
kernel 2.6.17, and probably you could easily make it work if you make some
upgrades to Ubuntu.


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


Re: Need a compelling argument to use Django instead of Rails

2006-08-05 Thread Damjan
>> I didn't realize you could do shared hosting with mod_python, because
>> of the lack of security barriers between Python objects (i.e. someone
>> else's application could reach into yours).  You really need a
>> separate interpreter per user.
> 
> mod_python uses sub-interpreters - can be per virtual server, per
> directory etc, cf
> http://www.modpython.org/live/current/doc-html/dir-other-ipd.html
> http://www.modpython.org/live/current/doc-html/dir-other-ipdv.html
 
Yes, but your mod_python programs still run with the privileges of the
Apache process, as are all the other mod_python programs. This means that
my mod_python program can (at least) read files belonging to you -
including your config file holding your database password.

PHP solves this problem by using it's safe mode and basedir restrictions.
Mod_python nor Python itself don't have this feature.

There are sollutions for Apache that run each virtual host under a different
uid but they have quirks:

 Metux MPM - http://www.metux.de/mpm/en/
 mod_suid  - for apache 1.3.x
http://www.palsenberg.com/index.php/plain/projects/apache_1_xx_mod_suid
 mod_suid2 - for apache 2.0.x
http://bluecoara.net/item24/cat5.html
 mod_ruid  - seems to be an improvement of mod_suid2
http://websupport.sk/~stanojr/projects/mod_ruid/

But I see mod_python more as a way to extend Apache itself, than for running
Python applications. A lot of the Apache mod_auth_* modules could be
replaced with mod_python scripts.

OTOH SCGI or FastCGI seem better sutied for python web (WSGI) applications.

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


Re: Which Python API for PostgreSQL?

2006-08-05 Thread Damjan
> I also recommend psycopg.

But make sure you use psycopg2

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


Re: ImportError: libclntsh.so.10.1: cannot open shared object file: Permission denied

2006-08-08 Thread Damjan
> I have a similar question (importing cx_Oracle, but not related to
> cron).  I would like to use solution #2 below and it does not work.  If
> I set LD_LIBRARY_PATH before running python, it works.  If I try to set
> it via os.environ, it does not work.
> 
> I have tried this in an interactive Python shell.  I can print the
> value of os.environ["LD_LIBRARY_PATH"] and it is correct, but the
> import fails.  The cx_Oracle.so file is found, but when it tries to
> load the necessary Oracle library (libclntsh.so.9.0), I get the
> message:
> 
>   ImportError: libclntsh.so.9.0: cannot open shared object file: No
> such file or directory
> 
> Is there something else I have to do when changing os.environ before
> trying the import?

Well, all the oracle stuff is installed in /usr/lib/oracle  on my computers
(or /usr/share/oracle ... depends when and how I installed it), 
but I also always make the symbolic links in /usr/lib too.

I guess once Python is started (and the C level library loader) you can't
change LD_LIBRARY_PATH anymore.

What I ussually set in os.environ is ORACLE_HOME because the oracle library
still needs to find some additional files too.


BTW cx_Oracle seems to only need  /usr/lib/libnnz10.so
and /usr/lib/libclntsh.so.10.1 but I also have these links in /usr/lib:
 libclntsh.so -> oracle/lib/libclntsh.so* 
   (this is a link to the .so.10.1 file)
 libclntsh.so.10.1 -> oracle/lib/libclntsh.so.10.1*
 libnnz10.so -> oracle/lib/libnnz10.so*
 libocci.so -> oracle/lib/libocci.so* 
   (this is a links to the .so.10.1 file
 libocci.so.10.1 -> oracle/lib/libocci.so.10.1*
 libociei.so -> oracle/lib/libociei.so*

This is with oracle instant client 10 libraries.



>> These environment variables are important for running any programs that
>> use the oracle client libraries. The problem you have is that when you
>> run the script from cron these environment variables are not set.
>>
>> Now, there are several ways how to handle this:
>> 1. create a shell script that you call from cron, and it it set the
>> environment variables and then call you python program
>>
>> 2. modify the environment in your python program (via os.environ) and
>> then import cx_Oracle
>>
>> 3. modify your system so that no environment variables are neccesseary -
>> actually this is not possible, but what I have is, symbolic links
>> in /usr/lib to the libraries in $ORACLE_HOME/lib, thus I don't need the
>> LD_LIBRARY_PATH variable, and the only other variable I need is the
>> ORACLE_HOME, which is /usr/share/oracle on my system and it contains
>> bin/  install/  lib/  network/  ocommon/  oracore/  rdbms/  sqlplus/
>> 
>> 
>> 
>> 
>> --
>> damjan

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


Re: Need a compelling argument to use Django instead of Rails

2006-08-08 Thread Damjan
>> Yes, but your mod_python programs still run with the privileges of the
>> Apache process, as are all the other mod_python programs. This means that
>> my mod_python program can (at least) read files belonging to you -
>> including your config file holding your database password
> 
> I think a standard solution to this is to
> associate each virtual host server to a
> different port and have the main apache
> redirect to the port.  Inetd makes sure
> that the vserver apache instance only
> stays alive while it's needed.  It might be
> complicated to set up, but it works.
> Again, something like this is probably
> advisable anyway to limit the ways one
> vserver can damage another generally
> speaking.

Starting a new Apache process with python included (trough mod_python) is
even worse than CGI.

But it seems AppArmor supports secureing mod_python (and mod_php and
mod_perl) with a special Apache module (and the AppArmor support in the
Linux kernel - yes this is Linux only).

http://developer.novell.com/wiki/index.php/Apparmor_FAQ#How_do_AppArmor_and_SELinux_compare_with_regard_to_webserver_protection.3F

Now that it's GPL AppArmor seems to get a lot of supporters.

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


Re: hide python code !

2006-08-14 Thread Damjan
> Imagine if you were the single-person developer of a small application
> that did something quite innovative, and charged a small fee for your
> product. Now imagine you were practically forced to make your algorithm
> obvious - a couple of months later, Microsoft bring out a freeware
> version and destroy your business in an instant. Sure, they and others
> can (and have) done that with closed-source products, but you increase
> your chances of survival 10-fold if the key algorithms are not obvious.

I think you increase your chances of Microsoft not even being in the same
room with your software 100-fold if you release it under.. say GPL.

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


Re: WSGI - How Does It Affect Me?

2006-10-08 Thread Damjan
> So I keep hearing more and more about this WSGI stuff, and honestly I
> still don't understand what it is exactly and how it differs from CGI
> in the fundamentals (Trying to research this on the web now)
> 
> What I'm most confused about is how it affects me.  I've been writing
> small CGI programs in Python for a while now whenever I have a need
> for a web program.  Is CGI now considered "Bad"?  

Well, mostly "yes" :)

> I've just always 
> found it easier to write something quickly with the CGI library than
> to learn a framework and fool with installing it and making sure my
> web host supports it.
> 
> Should I switch from CGI to WSGI?  What does that even mean?  What is
> the equivalent of a quick CGI script in WSGI, or do I have to use a
> framework even for that?  What do I do if frameworks don't meet my
> needs and I don't have a desire to program my own?

def simple_app(environ, start_response):
"""Simplest possible application object""" 
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
return ['Hello world!\n']

To serve it as a CGI just:
from wsgiref.handlers import CGIHandler
CGIHandler().run(simple_app)

It's not that complicated isn't it... and later you might want to move to
mod_python, scgi or fastcgi or IIS... you will not have to modify
simple_app a bit.

OR... you might want to use the EvalException middleware... just wrap your
simple_app like this:
app = EvalException(simple_app)

(well, due to it's simplicity EvalException can only work in single-process,
long running WSGI servers like not in CGI) so:

s = wsgiref.simple_server.make_server('',8080, app)
s.server_forever()

More info at
http://wsgi.org/wsgi/Learn_WSGI

> 3. Using IIS at all for that matter, does WSGI work on IIS, do any
> frameworks?

There's an IIS server gateway (WSGI server) but you can always run WSGI
applications with CGI, as seen above.



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


Re: is a wiki engine based on a cvs/svn a good idea?

2006-05-31 Thread Damjan
> I'm planning to wite a fully featured wiki in Python in one of
> frameworks. I've seen some notes about wiki/documentation management
> scripts that use SVN as a data storage/versioning.

Cool

> I've been using SVN a bit but I don't know if it's a good idea to use
> it in a wiki engine. Pro: versioning / diffs, Cons: you need your own
> svn/cvs repository, can pyLucene or Xapwrap index this?

You can certanly index the svn checkout if nothing else.

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


Re: ANN: PyQt v4.0 Released - Python Bindings for Qt v4

2006-06-12 Thread Damjan
> QtNetwork
> A set of classes to support TCP and UDP socket programming and higher
> level protocols (eg. HTTP).

Since QtNetwork is asynchronous how does it compare to twisted?
I find Qt's signals and slots easier to understand and work with than
twisted deferreds.



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


Re: Python database access

2006-06-27 Thread Damjan
> The odbc module is part of the Python Standard Library. 

Since when?


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


Re: Chapter 9 Tutorial for Classes Not Working

2006-06-30 Thread Damjan
> class MyClass:
> "A simple example class"
> i = 12345
> def f(self):
> return 'hello world'
> 
> 
>  From here I run:
> x = MyClass

Did you mean x = MyClass()

> xf = x.f
> while True:
>print xf()
> 
> This gives the following error:
> 
> Traceback (most recent call last):
>   File "", line 2, in ?
> TypeError: unbound method f() must be called with MyClass instance as
> first argument (got nothing instead)
> 
> Please help...this is killing me!

What you are really calling is MyClass.f without any arguments.


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


Re: Persistent Session in CGI

2006-08-30 Thread Damjan

> I have started a new small web project, and was wondering if there are
> any good guides on how to do Persistent Sessions and Authentication
> using python and CGI. I don't really want too use Zope, because It's
> probably overkill for my tiny project.

Since you only mention Zope...
Why not use TurboGears or Pylons or CleverHarold ... or anything WSGI based.
Or if you want to make something minimal you could try Paste with
(optionally) RhubarbTart. 

But.. WSGI is the new CGI (the lowest common denominator) in Python web
development. So use it. 
The benefits:
You can run your app as CGI, in mod_python, as a standalone http server,
with SCGI/FastCGI.
You'll benefit from authentication and session middleware. Middleware is a
great WSGI concept, there are also caching middlewares etc..



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


Re: Persistent Session in CGI

2006-08-30 Thread Damjan
> But.. WSGI is the new CGI

Let me give you a minimal example using RhubarbTart (it depends on Paste)

from rhubarbtart import request, response, expose
from rhubarbtart import TartRootController

class Root(TartRootController):
@expose
def index(self, msg="Hello world!"):
response.headers['Content-type'] = 'text/plain'
return msg

app = Root()

#
# Now to serve it as a CGI script, just:
#
from wsgiref.handlers import CGIHandler
CGIHandler().run(app)

#
# or to server it in a long running python-based HTTP server
#
from paste import httpserver
httpserver.serve(app)

# END of example

Now this is just the begining to show you that it's not hard.
But when you see what EvalException can do for you, you'll beg for more :)

Hint:
from paste.evalexception.middleware import EvalException
app = EvalException(app)
# then serve the app in the paste httpserver ... 
# but make some error in your python code to see it's results


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


Re: Egg problem (~/.python-eggs)

2006-08-30 Thread Damjan

>> I'm trying to install a program that uses Durus on a server.  It
>> appears that if a Python program uses eggs, it creates a
>> ~/.python-eggs/ directory, so the home directory must be writeable.
>> This conflicts with server environments where you want to run a daemon
>> with minimum privileges.  Second, it appears to use the real user ID
>> rather than the effective user ID to choose the home directory.  In
>> this case I'm trying to use start-stop-daemon on Linux to start my
>> Python program, switching from user 'root' to user 'apache'.
> 
> I solved the immediate problem by reinstalling Durus as a directory egg
> rather than a compressed egg.  So is the answer just not to use
> compressed eggs?

If the .egg file contains binary modules, those must be unpacked out of
the .egg (a Zip file actually) so that the kernel/lib-loader can map them.
If your .egg package doesn't have any binary modules, then it doesn't need
to unpack anything.


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


Re: Broadcast server

2006-08-31 Thread Damjan
[EMAIL PROTECTED] wrote:

> I would like to write a server with the low level API of python (
> socket+select and/or socket+thread ) that allow me to register client
> and update them every X seconds ( could be the time, the temperature, a
> stock quote, a message , ... ).
> 
> How to write the server that keep hot connections with clients and
> update them when events are trigerred. I don't know how to begin this ,
> i look at the python doc but the doc is more related to client updating
> the server and i am not sure of the right design that could be use
> here.

I'd suggest to find the Richard W. Stevens book "Unix Network Programing".
You'll learn a lot about networking from that book. It's based on C, but
you'll see that the concepts can be easily used with Python too.

Find that book, and don't forget the stdlib docs:
http://docs.python.org/lib/module-socket.html
http://docs.python.org/lib/module-select.html

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


Re: Python newbie with a problem writing files

2006-09-04 Thread Damjan
> Code:

> xml_output.write = (feed_title)

How did you come up with that "=" there??!
The correct line is:
xml_output.write(feed_title)


> Traceback (most recent call last):
>   File "C:/My_Blogroll/JJ_Blogroll2", line 11, in ?
> xml_output.write = (feed_title)
> AttributeError: 'file' object attribute 'write' is read-only

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


Re: get the en of a program running in background

2006-09-11 Thread Damjan

> It works when a click on a button launches a program P.
> Now, I want that a click on another button launches another program P'
> 
> In this case there is only one signal for two events : the end of P and
> the end of P'.
> How can distinct the two cases.

Remember the PIDs of the forked procesess and in your signal handler use
os.wait() to see which one has died. 
BTW os.wait() can work in non-blocking mode .


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


Re: egg and modpython

2006-09-11 Thread Damjan
> I applaud you for studying the traceback in more depth than I can find
> the motivation for, Bruno. ;-) However, this looks like a program using
> some package installed by setuptools/easy_install needs to unpack that
> package when running.

See news:[EMAIL PROTECTED]

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


Re: BaseHTTPServer weirdness

2006-09-11 Thread Damjan
>> But basically, you aren't providing a CGI environment, and that's why
>> cgi.parse() isn't working.
> 
> Clearly.  So what should I be doing? 

Probably you'll need to read the source of cgi.parse_qs (like Steve did) and
see what it needs from os.environ and then provide that (either in
os.environ or in a custom environ dictionary).

BUT why don't you use WSGI?

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


Re: Is there a way to find IP address?

2006-09-17 Thread Damjan
>> Normaly I can log user's IP address using os.environ["REMOTE_ADDR"] .
>> If a user  is behind a proxy, I will log  proxy's IP address only.
>> Is there a way how to find a real IP user's address?
> 
> os.environ["HTTP_X_FORWARDED_FOR"]
> 
> (but that can easily be spoofed, and is mostly meaningless if the user
> uses local IP addresses at the other side of the proxy, so you should
> use it with care)

Yep, you should only use "HTTP_X_FORWARDED_FOR" if you trust the proxy and
you check that the request is indeed coming from it 
(if environ["REMOTE_ADDR"] in proxy_list).


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


Re: Is there a way to find IP address?

2006-09-17 Thread Damjan

>> > Normaly I can log user's IP address using os.environ["REMOTE_ADDR"] .
>> > If a user  is behind a proxy, I will log  proxy's IP address only.
>> > Is there a way how to find a real IP user's address?
>>
>> os.environ["HTTP_X_FORWARDED_FOR"]
>>
>> (but that can easily be spoofed, and is mostly meaningless if the user
>> uses local IP addresses at the other side of the proxy, so you should
>> use it with care)

> How can be HTTP_X_FORWARDED_FOR easily  spoofed? I thought that  IP
> address is not possible change.

I can setup my browser to always send you a fake HTTP_X_FORWARDED_FOR
header.



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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-17 Thread Damjan

>> I understand that I can use __metaclass__ to create a class which
>> modifies the behaviour of another class.
>> 
>> How can I add this metaclass to *all* classes in the system?
>> 
>> (In ruby I would alter the "Class" class)
> 
> You'd have to set
> 
> __metaclass__ = whatever
> 
> at the top of each module whose classes are to get the new behavior.

I think '__metaclass__ = whatever' affects only the creation of classes that
would otherwise be old-style classes?
 
> You can't alter classes which you don't control or create in your code.

I remeber I've seen an implementation of import_with_metaclass somewhere on
IBM's developerworks. I didn't quite undersntad it though.



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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Damjan
>>> __metaclass__ = whatever
>>> 
>>> at the top of each module whose classes are to get the new behavior.
>> 
>> I think '__metaclass__ = whatever' affects only the creation of classes
>> that would otherwise be old-style classes?
> 
> Wrong.
> 
> If you set __metaclass__ = type, every class in that module will be
> new-style.

 >>> from UserDict import UserDict
 >>> type(UserDict)
 
 >>> class A(UserDict):
 ...   pass
 >>> type(A)
 
 >>> __metaclass__ = type
 >>> class B(UserDict):
 ...   pass
 >>> type(B)
 

It seems that NOT every class in my module will be a new style class,
especially those that inherit from other old-style classes in other
modules.



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


Re: naming objects from string

2006-09-20 Thread Damjan
manstey wrote:

> Hi,
> 
> But this doesn't work if I do:
> 
> a=object()
> x='bob'
>  locals()[x] = a
>
> How can I do this?

try
sys.modules[__name__].__dict__[x] = a

But what's the point?


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


Re: Don't use regular expressions to "validate" email addresses (was: Ineed some help with a regexp please)

2006-09-22 Thread Damjan
>> you'd create something to allow anyone to
>> potentially spam the hell out of a system...
> 
> I'm sorry, but I fail to see how validating (or not) an email address
> could prevent using a webmail form for spamming. Care to elaborate ?

The best way would be to implement some limiting features. Try two times
from the same IP address in less than 10 minutes and you are banned for the
day. Or some such.


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


RE: CGI -> mod_python

2006-10-03 Thread Damjan
> I'm confused.
> 
> is WSGI only a specification, or are there implementations, and if so
> which ones

WSGI is only a specification.
There are a lot of implementations: servers, middleware and almost all new
Python web apps and frameworks are WSGI applications.

Here is a list of WSGI servers (server gateways)
http://wsgi.org/wsgi/Servers

Start from here to learn more:
http://wsgi.org/wsgi/Learn_WSGI

Then come back, we'll discuss

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


Re: lxml/ElementTree and .tail

2006-11-19 Thread Damjan
> sure, the computing world is and has always been full of people who want
> the simplest thing to look a lot harder than it actually is.  after all,
> *they* spent lots of time reading all the specifications, they've bought
> all the books, and went to all the seminars, 

and have been sold all the expensive proprietary tools

> so it's simply not fair when others are cheating.

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


Re: Mod_python vs. application server like CherryPy?

2006-12-08 Thread Damjan
> For example, consider an extreme case such as WSGI. Through a goal of
> WSGI being portability it effectively ignores practically everything
> that Apache has to offer. Thus although Apache offers support for
> authentication and authorisation, a WSGI user would have to implement
> this functionality themselves or use a third party WSGI component that
> does it for them. 

OTOH 
WSGI auth middleware already supports more auth methods than apache2 itself.

> Another example is Apache's support for enabling 
> compression of content returned to a client. The WSGI approach is again
> to duplicate that functionality. 

the gzip middleware is really just an example... nobody would use that in
production.

> Similarly with other Apache features 
> such as URL rewriting, proxying, caching etc etc.

Well, not everybody can use Apache ... and again there's already WSGI
middleware that's more flexible than the Apache modules for most of the
features you mention.

It's not that I think mod_python doesn't have uses.. I just think it's not
practical to make python web applications targeted solely to mod_python.



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


Re: Is there any python-twisted tutorial or texts?

2006-12-21 Thread Damjan
>>  I want to study twisted of python . But I donot know how to start.
>>  Any suggistions?
>>
> 
> There is a book about using Twisted. It's called 'Twisted Network
> Programming Essentials.' It is an entry-level book at best, but it does go
> over quite a lot of things that the Twisted library is capable of.

Well, the book is not that good. It completely fails to explain deferreds
which are a central concept in Twisted. I only understood deferreds when
watching Bob Ippolitos screencast about Mochikit which implements the same
API as Twisted... Then I got back to the Twisted book.

I think it needs more work.

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


Re: Problem with curses and UTF-8

2006-02-08 Thread Damjan
I just recompiled my python to link to ncursesw, and tried your example
with a little modification:

import curses, locale
locale.setlocale(locale.LC_ALL, '')
s = curses.initscr()
s.addstr(u'\u00c5 U+00C5 LATIN CAPITAL LETTER A WITH RING
ABOVE\n'.encode('utf-8') )
s.addstr(u'\u00f5 U+00F5 LATIN SMALL LETTER O WITH
TILDE\n'.encode('utf-8'))
s.refresh()
s.getstr()
curses.endwin()

And it works ok for me, Slackware-10.2, python-2.4.2, ncurses-5.4 all
in KDE's konsole.
My locale is mk_MK.UTF-8.

Now it would be great if python's curses module worked with unicode
strings directly.

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


Python 2.4.2 and Berkeley DB 4.4.20 ?

2006-02-13 Thread Damjan
This is from the Slackware-current changelog:

d/python-2.4.2-i486-1.tgz: Upgraded to python-2.4.2.
   The bsddb module didn't build against the new 4.4.x version of
   Berkeley DB. Does anyone care? Or perhaps have a patch? :-)

Does anyone have a suggestion?

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


Re: ANNOUNCE: Mod_python 3.2.7

2006-02-13 Thread Damjan
Just upgraded from 3.1.4 / Apache-2.0.55, and I can confirm that both
moin-1.5 and trac-0.9.3 continued to work without problems.

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


Is there a WSGI sollutions repository somewhere

2006-03-04 Thread Damjan
It seems that WSGI support starts to flourish is there some document or
a web site that tracks what's out there, some place to pick and choose
WSGI components?

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


Re: PyQt issue

2006-03-04 Thread Damjan
> Because you wrote curentText - note the missing t.

:)

You mean the missing 'r'

:)

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


a cx_Oracle ORA-01036 problem

2005-05-05 Thread Damjan
I'm using Python 2.4, cx_Oracle-4.1 on Linux with Oracle instant client
10.1.0.3. This is the sql string:

SQL = """insert into D.D_NOTIFY values (:CARDREF, :BANKKEY, :OK1, :OK2 \
:DEBTEUR, :DEBTDEN, to_date(:INVOICE_DATE,'DD.MM.YY'),
to_date(:PAYMENT_DEADLINE,'DD.MM.YY'), :POINTS)"""

And I'm trying to execute it as:
c = db.cursor()
c.execute(SQL, CARDREF=id, BANKKEY=dc_kluc, OK1=okd, OK2=okc,   

  DEBTEUR=iznos_eur, DEBTDEN=iznos_mkd, INVOICE_DATE=datum_g,   
  PAYMENT_DEADLINE=datum_d, POINTS=bodovi)

And I get an ORA-01036 exception.

I also have tried
args = dict(CARDREF=id, BANKKEY=dc_kluc, OK1=okd, OK2=okc,   
  DEBTEUR=iznos_eur, DEBTDEN=iznos_mkd, INVOICE_DATE=datum_g,
  PAYMENT_DEADLINE=datum_d, POINTS=bodovi)
c = db.cursor()
c.execute(SQL, **args)
Same thing.

Everything works If I use python string substituion, like this sql:
SQL = """insert into D.D_NOTIFY values (%s,'%s','%s','%s','%s','%s', \
to_date('%s','DD.MM.YY'),to_date('%s','DD.MM.YY'),'%s')""" % fields

Any ideas?


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


Re: a cx_Oracle ORA-01036 problem

2005-05-05 Thread Damjan
vincent wehren wrote:
> |c = db.cursor()
> |c.execute(SQL, **args)
> 
> 
> Shouldn't that be c.execute(SQL, args) (no **-unpacking of the
> dictionary)?

Actually I tried that too, I still get the same error.

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


Re: a cx_Oracle ORA-01036 problem

2005-05-12 Thread Damjan
>> SQL = """insert into D.D_NOTIFY values (:CARDREF, :BANKKEY, :OK1, :OK2 \
>> :DEBTEUR, :DEBTDEN, to_date(:INVOICE_DATE,'DD.MM.YY'),
>> to_date(:PAYMENT_DEADLINE,'DD.MM.YY'), :POINTS)"""
>> 

> Try using a variable name other than "id" for the CARDREF variable... say
> "card_id".  id is a built in function name; I suspect your problem may be
> that you are assiging that function to the variable rather than your
> intended value...

I changed it to 'cardref' but I'm still getting the same error.


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


Re: Building a Python app with Mozilla

2007-07-10 Thread Damjan
> Last I looked (3.1-ish), Qt didn't use the Aqua widgets

Qt is now up to 4.3 and they use native Aqua

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


Python IMAP web-access

2007-08-01 Thread Damjan
Is there some project that implements web access to an IMAP store?

Maybe something AJAXy like http://roundcube.net/??


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


Re: encoding problems

2007-08-29 Thread Damjan
> 
> is there a way to sort this string properly (sorted()?)
> I mean first 'a' then 'à' then 'e' etc. (sorted puts accented letters at
> the end). Or should I have to provide a comparison function to sorted?

After setting the locale...

locale.strcoll()


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

  1   2   >