Re: Mandrake 10.1 and Python 2.3.4

2005-05-15 Thread John Ridley
"Joal Heagney" wrote:

> Hi everyone. I've been getting this error message in python, and it's

> really driving me up the wall.
> 
> 
> [EMAIL PROTECTED] joal]$ python
> 'import site' failed; use -v for traceback
> Python 2.3.4 (#1, Apr 18 2005, 19:03:06)
> [GCC 3.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more
information.
>  >>>
> 
> Here's the relevant line when i run python in verbose mode:
> 
> 
> 'import site' failed; traceback:
> Traceback (most recent call last):
>File "/usr/lib/python2.3/site.py", line 169, in ?
>  sys.lib,
> AttributeError: 'module' object has no attribute 'lib'
> 
> Is this a Mandrake or a Python mistake?
> And does anyone know how to fix it?
> 
> I think this is the reason why I'm getting errors when it comes to 
> importing other python packages.

I have both python 2.3.4 and 2.4.1 installed on Mandrake 10.1 - and
only 2.4.1 gives the error.

So - have you tried to install python 2.4 recently?

Also, are you using a pythonrc.py startup file which is trying to
import the sys module? Have a look to see if a PYTHONSTARTUP
environment variable has been set to the path of such a file.

HTH

John Ridley



___ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xmlrpclib and decoding entity references

2005-05-03 Thread John Ridley
Chris Curvey wrote on Tue, 03 May 2005 08:10:50 -0700:

> Can anyone give me a lead on how to convert the entity references
> into something that will make it through to my method call?

The xmllib module has a function for doing this:

>>> import xmllib
>>> xmllib.XMLParser().translate_references(your_xml_sample)

xmllib is now obsolete, but you could copy and paste the relevant parts
to your project as they only amount to a fifty-line function and few
regular expressions.

HTH

John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gtk/qt scintilla help !

2005-05-01 Thread John Ridley
fabien wrote on Sun, 01 May 2005 05:40:05 -0700:

> Hi,

Hello Fabien

> I am writing a POV-RAY editor with Python using
> either QT or GTK as GUI 'wrapper'. ( I am still trying both )
>
> [snip]
>
> I have also downloaded qscintilla-1.62-gpl-1.5.1.
> As for GTK, I also found the LexPOV.cpp file, with
> no POV keywords in it and with no POV keywords in
> any of the file in the package.
> The compilation builds then move the library
> libqscintilla.so to /usr/lib/qt3/lib.
> 
> How do I link the newly built library to the folling qt script :
>
> [snip]

QScintilla is a port to Qt of the Scintilla editor control, and PyQt
provides the python bindings for it. Scintilla has several dozen lexers
(including one for POV), and QScintilla currently provides class
wrappers for a small selection of them - but not POV, as you will see
from the documentation:

http://www.river-bank.demon.co.uk/docs/qscintilla/hierarchy.html

Given this, there are two routes you can go down. You could ask the
developer of QScintilla to provide support for POV by making a request
via the mailing list:

http://www.riverbankcomputing.co.uk/pyqt/mailinglist.php

Or you could write your own POV lexer class in python using the
existing QScintilla APIs. This is not particularly difficult, but it
does take some working out. As you already know, a list of POV keywords
is required. You will then need to look at the source (LexPOV.cpp and
SciLexer.h) to see how the keywords are used and how the lexical states
tie up with the SCE_POV enum. QScintilla's lexer classes are mainly
wrappers around this information, so once you've worked it out, writing
a python class based on QextScintillaLexer is fairly straightforward:

>>> class LexerPOV(QextScintillaLexer):
>>> def __init__(self, parent, name):
>>> QextScintillaLexer.__init__(self, parent, name)
>>> def lexer(self):
>>> return "pov"
>>> def color(self, style):
>>> # styles map to (SCE_POV enum)
>>> # return your own QColor
>>> # or return the base class default
>>> return QextScintillaLexer.color(self, style)
>>> def keywords(self, set):
>>> # if set == 0:
>>> # return 
>>> # elif ...
>>> return 0
>>> def description(self, style):
>>> # if style == 0:
>>> # return self.tr("Default")
>>> # elif ...
>>> return QString.null

Of course, this is a minimal lexer class - it is possible to be a lot
more sophisticated than what is suggested here.


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: kdialog and unicode

2005-04-28 Thread John Ridley
Matt wrote:
> Interesting - this displays correctly when I run the above code from
a
> python shell.  However, when I run it as a superkaramba theme (which
is
> a wrapper interface to some kde functions, but allegedly passes
> straight python functions direct to the python interpreter), it shows
> up as letters, with &nnn (where nnn is a number) instead of the \xc4
> etc.  I need to do some more investigating of this with the
> superkaramba developers, and my own machine to see where the problem
> lies - clearly it's not in the code I'm using - there's either
> something wrong on my machine, or wrong with the way superkaramba
> passes this code to the python interpreter.

If xml character escapes are showing up in the output, it suggests the
input is being treated as plain-text, rather than as rich-text (i.e.
markup). In order for kdialog to guess that the input is markup, it
needs to find some sort of tag before the first line-break. That is why
I used P tags to enclose the polish text in my example - you didn't
leave these off when you tried it out with superkaramba, did you? What
exactly *is* the code you are running?

BTW, if you want more details on kdialog's markup handling, try this
reference from the qt docs:

http://doc.trolltech.com/qstylesheet.html

HTH

John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: kdialog and unicode

2005-04-27 Thread John Ridley
dmbkiwi wrote:

> I'm trying to get python, unicode and kdialog to play nicely
together.
> This is a linux machine, and kdialog is a way to generate dialog
boxes in
> kde with which users can interact (for example input text), and you
can
> use the outputted text in your script.
> 
> Anyway, what I'm doing is reading from a utf-8 encoded text file
using the
> codecs module, and using the following:
> 
> data = codecs.open('file', 'r', 'utf-8')
> 
> I then manipulate the data to break it down into text snippets.
> 
> Then I run this command:
> 
>>>> test = os.popen('kdialog --inputbox %s' %(data))
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u017a' in
> position 272: ordinal not in range(128)
> 
> I would really like kdialog display the text as utf-8.  However, it
seems
> that python is trying to pass the utf-8 encoded data as ascii, which
> obviously fails because it can't deal with the utf-8 encoded text. 
Is it
> possible to pass the text out to kdialog as utf-8, rather than ascii?

kdialog will accept a limited form of markup as text, including xml
character escapes. so you should be able to display polish text
correctly using this method:

>>> import os
>>> s = """Wszyscy ludzie rodz\xc4\x85 si\xc4\x99
...  wolni i r\xc3\xb3wni pod wzgl\xc4\x99dem
...  swej godno\xc5\x9bci i swych praw. S\xc4\x85
...  oni obdarzeni rozumem i sumieniem i powinni
...  post\xc4\x99powa\xc4\x87 wobec innych w duchu
...  braterstwa."""
>>> s = s.decode('utf-8').encode('ascii','xmlcharrefreplace')
>>> k = os.popen('kdialog --inputbox "%s"' % s)


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check instace already running...

2005-04-10 Thread John Ridley

--- Fabio Pliger <[EMAIL PROTECTED]> wrote:
> Yeah, but how can i retrieve my PID number?And how do i check if the
> process
> who has written the file is still alive?If there a way to have the
> list of
> the precesses running?

This subject has come up before. The thread starts here:

http://mail.python.org/pipermail/python-list/2004-September/243294.html

But see in particular this post:

http://mail.python.org/pipermail/python-list/2004-September/243379.html

There is also a cookbook recipe here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252495

HTH

John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python 2.4 on Linux

2005-04-09 Thread John Ridley
* Edward Diener wrote:
> I need python to be python2.3 else many utilities no longer work.

Then leave your 2.3 installation exactly as it is (so that python is a
link to python2.3) and run python2.4 where needed.

To specifically use python 2.4 to run IDLE, simply type in a shell:

[user]$ python2.4 /usr/bin/idle

Alternatively, create your own (executable) idle or pydoc with a
shebang that points permanently at python2.4. For example:

file: $HOME/bin/idle2.4
---
#!/usr/bin/python2.4

from idlelib.PyShell import main
if __name__ == '__main__':
main()
---

Then if $HOME/bin is on your PATH, you can simply run: idle2.4

> The problem is then using IDLE and pydoc for Python2.4 since neither
> are .py scripts

Really?! What are they on Fedora, then?


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the date string into timestamp

2005-04-09 Thread John Ridley
> praba kar wrote:
> 
> > In Php strtotime() will change a date
> > string into timestamp.  I want to know which 
> > python function will  change a date string
> > into timestamp.
> 

To convert a date-string *to* a timestamp (as you asked):

>>> import time, calendar
>>> date_string = time.strftime('%c', time.gmtime(1112952134))
>>> print date_string
Fri Apr  8 09:22:14 2005
>>> calendar.timegm(time.strptime(date_string))
1112952134


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python 2.4 on Linux

2005-04-05 Thread John Ridley

--- Edward Diener <[EMAIL PROTECTED]> wrote:
[snip]
> I do not know whether this is a Python problem or a Fedora 3 problem
> but 
> I thought I would ask here first and see if anybody else had the same
> 
> problem. I imagine the problem might exist on other Linux systems.

On my Mandrake 10.1 system I have the default python 2.3 installation
plus a separate python 2.4 installation which I compiled from source.
There are two executables (python2.3 and python2.4) in /usr/bin, plus a
hard-link (from python2.4) named python. If necessary, I could switch
back to the default setup by replacing the hard-link with one from
python2.3 - so the system would then have its preferred python version
and I could selectively run python2.4 whenever appropriate. So far,
Mandrake has not complained about using python 2.4 exclusively, so I
might try removing the old installation eventually. (Then again, it's
always handy to keep it for compatibility testing).

Note that if compiling and installing from source there is an option of
'make altinstall' which will leave the existing python executables (and
man pages) as they are and just create a new python2.4 executable - by
default the library is installed in '/usr/local/lib/python2.4'. See the
README for details.


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re module non-greedy matches broken

2005-04-05 Thread John Ridley

--- lothar <[EMAIL PROTECTED]> wrote:
> a non-greedy match is implicitly defined in the documentation to be
> one such
> that there is no proper substring in the return which could also
> match the regex.
> 

If I understand this correctly, what you are asking is for re to look
for, or rather, anticipate, over-lapping matches (e.g. tags nested
inside tags). But the module documentation at "4.2.3 Module Contents"
specifically states that functions like re.findall do not do this. So I
think it's not that the regex engine is not up to the task - rather
that you may need to take into account the behaviour of some of the
module functions when composing your regexes. I'm sure it's possible to
do what you want using a regex alone - however, it may also be worth
looking at rolling your own search functions in order to get finer
control over the strategy of searching.


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Super Newbie Question

2005-04-04 Thread John Ridley

--- John Ridley <[EMAIL PROTECTED]> blurted:
> I suppose the simplest thing to do would be to write an empty string
> to the file:
> 
> >>> f = open('tmpfile.txt', 'w')
> >>> f.write('')
> >>> f.close()   # or f.flush(), if keeping open

Apologies - this is, of course, nonsense.

Time for me to hit the sack, I think...


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Super Newbie Question

2005-04-04 Thread John Ridley

--- [EMAIL PROTECTED] wrote:

> In short, how might I go about deleting just the contents of a file?
> I tried several methods with my limited knowledge but had no luck.

I suppose the simplest thing to do would be to write an empty string to
the file:

>>> f = open('tmpfile.txt', 'w')
>>> f.write('')
>>> f.close()   # or f.flush(), if keeping open

HTH

 

John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Eric3 under WinXP

2005-04-04 Thread John Ridley

* Franz Steinhäusler wrote:

> I have successfully installed pyqt, but not
> qtext, which I need to run Eric3.
> The PyQT demo files run fine.
> 
> I've downloaded QScintilla, compiled via MS-VC,
> but (I suppose I need the SIG), to translate or provide
> the Python interface with pyd Files.
> 
> Eric complains, that qtext is not found.
> 
> Has anyone success with getting this to work and how?

Hi Franz.

If you don't get any help here, please try the mailing list at:

http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re module non-greedy matches broken

2005-04-04 Thread John Ridley

--- lothar <[EMAIL PROTECTED]> wrote:
> no - in the non-greedy regex
>   <1st-pat>*?
> 
> <1st-pat>,  and  are arbitrarily complex
> patterns.

Could you post some real-world examples of the problems you are trying
to deal with, please? Trying to come up with general solutions for
arbitrarily complex patterns is a bit to hard for me :)

> with character classes and negative character classes you do not need
> non-greediness anyway.

And yet in the simple case you supplied it does make a difference:

>>> newdoc = "V1WVVV2WWW"
>>> vwre = re.compile("V[^V]*W")
['V1W', 'V2WWW']
>>> vwre = re.compile("V[^V]*?W")
>>> vwre.findall(newdoc)
['V1W', 'V2W']

Not exactly rocket-science, but it gets the job done...


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with python-devel!!!

2005-04-04 Thread John Ridley
* Michele Simionato wrote:
> Just give (as root)
>
> # urpmi python-devel

The OP mentioned that urpmi couldn't find a package by that name. So it
might be worth querying for "libpython" if that fails:

[EMAIL PROTECTED] urpmq libpython
The following packages contain libpython:
libpython2.3
libpython2.3-devel


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re module non-greedy matches broken

2005-04-04 Thread John Ridley

--- lothar <[EMAIL PROTECTED]> wrote:
> how then, do i specify a non-greedy regex
>   <1st-pat>*?
> 
> that is, such that non-greedy part *?
> excludes a match of <1st-pat>
> 
> in other words, how do i write regexes for my examples?
 
Not sure if I completely understand your explanation, but does this get
any closer to what your looking for?

>>> vwre = re.compile("V[^V]*?W")
>>> newdoc = "V1WVVV2WWW"
>>> re.findall(vwre, newdoc)
['V1W', 'V2W']

That is: , then  as few times as possible, then 


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list