Re: Connecting to Firebird database using Kinterbasdb+Python
Maurice LING wrote: > I've been using FB1.5 and access the database using Kinterbasdb + > Python. My connection is established using kinterbasdb.connect() method > and the parameters host, dns, database, user, password are all defaulted > to 'None'. > > On my own machine running Mac OSX 10.3, I can connect using the following: > host = 'localhost' > database = '' > user = '' > password = '' > > At the same time, I can also connect if I set host=None on my machine. > > However, I cannot use 'localhost' on a shared Linux machine (not > allowed. Don't ask why, system admin's mandate. And the Linux machine is > without inetd). So when I set host=None, I get this error: Just for my understanding: if you start your script on the machine hosting the DB you're able to connect. If you start it on a different machine, you are not able to connect without giving a hostname? Whats wrong with offering the the name (or IP-address) of your MacOS-box instead of 'localhost' to the script? Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: Connecting to Firebird database using Kinterbasdb+Python
Maurice LING wrote: > What I am trying to do is "port" a workable program from my own machine > (Mac OSX) to a larger machine (Linux). So, the DB and the program are > also on the same Linux machine. > > On the Linux machine, I cannot use localhost, so I set host parameter in > kinterbasdb.connect() method to None, which is the default kinterbasdb > uses. On Linux machine, I get the error as posted. On my Mac OSX > machine, initiating host parameter to 'localhost' or None has no > difference, it works. How do you connect to the Linux-DB using tools like isql? Check you firebird config (most likely in /etc/firebird2/firebird.conf) for the parameters "RemoteServicePort" and "RemoteBindAddress". And at least try "netstat -alp | grep fbserv" (as root) to check if the firebird is running properly. If you're running the classic server you can simply follow Grig's advice and connect "directly" to the db files. Mathias -- http://mail.python.org/mailman/listinfo/python-list
Web-Forms
Hi, I need to access some information from a web site which are only accessible through a form. Thus for each bucket of data you have to fill out the form, submit it and wait for an answer. Very easy - if you don't have to check some hundred times. Of course this site requires cookies, it is not directly accessible by URL and so on. All that nice stuff used to make a web site more professional;) But now the question: how can this be solved by using Python? Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: Web-Forms
Michele Simionato wrote: > Use twill:http://www.idyll.org/~t/www-tools/twill.html I'll do so. Twill is great, anyway thanks for all other responses too. Mathias -- http://mail.python.org/mailman/listinfo/python-list
64 bit Python
Hi, one of my colleagues got some trouble with a program handling large amounts of data. I figured out that a 32 bit application on HP-UX cannot address more than 1 GB of memory. In fact (I think due to the overhead of memory management done by python) a python application cannot use much more than 500 MB of "real" data. For this reason I've created a 64 bit version of python 2.3.5. I've tested a simple C program before to make sure its able to address the whole available memory (8 GB main memory and about 12 GB swap). The simple example in C works, but the python script didn't. I was able to create only 2 GB of python objects. The application occupied approximately 2.2 GB of memory. After that, python failed with a memory error. Is there any internal restriction on the size of the heap? Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: 64 bit Python
Ivan Voras wrote: > Mathias Waack wrote: >> amounts of data. I figured out that a 32 bit application on HP-UX >> cannot address more than 1 GB of memory. In fact (I think due to >> the overhead of memory management done by python) a python >> application cannot use much more than 500 MB of "real" data. For >> this reason > > I don't thik this is likely. Don't know about HP-UX but on some > platforms, FreeBSD for example, there is a soft memory-cap for > applications. By default, a single application on FreeBSD cannot > use more than 512MB of memory, period. The limit can be modified by > root (probably involves rebooting). As I stated I wrote a simple C-program before. The c-program was able to allocate a bit more than 900MB in 32 bit mode. My python script allocates a bunch of strings each of 1024 characters and writes it in a cStringIO. And it fails after writing 512K of strings. Don't know how python restricts the heap size - but I'm fairly sure its not a restriction of the OS. But thats not the point, I don't want to talk about one or two megabytes - I'm just missing some GB of heap;) Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: 64 bit Python
Mike C. Fletcher wrote: > Mathias Waack wrote: > ... > >>My python script allocates a bunch of strings each of 1024 >>characters and writes it in a cStringIO. And it fails after writing >>512K of strings. Don't know how python restricts the heap size - >>but I'm fairly sure its not a restriction of the OS. >> >> > Does cStringIO require contiguous blocks of memory? I'm wondering > if maybe there's something going on where you just can't allocate > more than > a GB of contiguous space? That was the problem. I've used cStringIO to reduce the overhead by the python memory management. But now I know - that was a bad idea in this case. > What happens if you just store the > strings in > a list (or use StringIO instead of cStringIO)? It consumed 10 GB really fast, another GB really slow, some hundred MB much slower and then it died;) Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: StringIO objects sharing a buffer
Thomas Lotze wrote: > Is there a way for multiple StringIO objects to share a buffer of > data, or do I have to give up on subclassing StringIO for this > purpose? (An alternative would be a tokenizer class that has a > StringIO instead of being one and do the file pointer housekeeping > in there.) I'm not sure if I understand the problem right, but there is a rule of thumb: Prefer delegation to inheritance. If you can use delegation, avoid inheritance. Esp. on python, where (from the point of view of usage) there is no distinction between delegation or inheritance. Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple initialization methods?
alex wrote: > it is possible to define multiple initialization methods so that > the method is used that fits? > > I am thinking of something like this: > > def __init__(self, par1, par2): > self.init(par1, par2); > > def __init__(self, par1): > self.init(par1, None) > > def init(self, par1, par2): > ... > ... > > So if the call is with one parameter only the second class is > executed (calling the 'init' method with the second parameter set > to 'None' or whatever. But this example does not work. > > How to get it work? You have to do the method dispatching by yourself. For variable length parameter list you could choose this solution: def __init__(self, *args): if len(args) == 1: self.__setup1(*args) elif len(args) == 2: self.__setup2(*args) ... def __setup1(self, arg1): print "setup1" def __setup2(self, arg1, arg2): print "setup2" Or for different parameter lists which may have the same length my suggestion would be: def __init__(self, **kw): self.__dict__.update(kw) Mathias PS: anyone working on a patch for multimethod dispatching for python? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to wrap a class's methods?
Grant Edwards wrote: > I want to subclass an IMAP connection so that most of the > methods raise an exception if the returned status isn't 'OK'. > This works, but there's got to be a way to do it that doesn't > involve so much duplication: > > class MyImap4_ssl(imaplib.IMAP4_SSL): > > def login(*args): > s,r = imaplib.IMAP4_SSL.login(*args) > if s!='OK': > raise NotOK((s,r)) > return r > > def list(*args): > s,r = imaplib.IMAP4_SSL.list(*args) > if s!='OK': > raise NotOK((s,r)) > return r > > def search(*args): > s,r = imaplib.IMAP4_SSL.search(*args) > if s!='OK': > raise NotOK((s,r)) > return r > > [and so on for another dozen methods] How about using a delegator: class Wrapper: funcs = ("login", "list", "search") def __init__(self, classobj): self.__wrapped = classobj() def __getattr__(self, attr): if attr in Wrapper.funcs: def f(*args): f1 = getattr(self.__wrapped, attr) s,r = f1(args) if s != 'OK': raise NotOk((s,r)) return r return f # raise some exception here imap = Wrapper(imaplib.IMAP4_SSL) If you wrap all methods you can ignore the if-test. Instead of the class object you can pass instances to the wrapper if you need special arguments for initialization. I don't like subclassing;) Mathias PS: note that we're wrapping the instance's methods, not the class's methods! -- http://mail.python.org/mailman/listinfo/python-list
Re: Start new process by function ?
George Sakkis wrote: > Is it possible to start a new process by specifying a function call > (in similar function to thread targets) instead of having to write > the function in a separate script and call it through os.system or > os.spawn* ? That is, something like > > def foo(): pass > os.spawn(foo) Just starting is easy: def spawn(f): if os.fork() == 0: f() sys.exit(0) But I'd expect you would like to get some return values from f... Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get database metadata information (i.e. existing tables and columns in tables)
Chris Brat wrote: > Is it possible to retrieve details about the database, specifically a > list of the tables in the database; and then to retrieve the columns > and their types for the tables? Yes. > Is this dependant on the database? Yes. Real databases usually store meta-data (list of tables, list of columns, list of indexes aso...) in system tables which can be queried in the same manner as common tables or view. Just read your database handbook... HTH Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: 10GB XML Blows out Memory, Suggestions?
[EMAIL PROTECTED] wrote: > I wrote a program that takes an XML file into memory using Minidom. I > found out that the XML document is 10gb. > > I clearly need SAX or something else? More memory;) Maybe you should have a look at pulldom, a combination of sax and dom: it reads your document in a sax-like manner and expands only selected sub-trees. > Any suggestions on what that something else is? Is it hard to convert > the code from DOM to SAX? Assuming a good design of course not. Esp. if you only need some selected parts of the document SAX should be your choice. Mathias -- http://mail.python.org/mailman/listinfo/python-list
Illegal instruction or undefined symbol from import
Hi, I've embedded python into a legacy application. It works - most of the time. In some special situations the app crashes executing the "import random". There are two different situations: 1. the sources compiled with gcc 4.1.2 crash with illegal instruction error: (running my application) Python 2.3.5 (#1, Jun 9 2006, 11:49:02) [GCC 4.1.2 20060604 (prerelease) (Debian 4.1.1-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. dlopen("/usr/lib/python2.3/lib-dynload/readline.so", 2); import readline # dynamically loaded from /usr/lib/python2.3/lib-dynload/readline.so >>> import random import random # from /usr/lib/python2.3/random.py # can't create /usr/lib/python2.3/random.pyc dlopen("/usr/lib/python2.3/lib-dynload/math.so", 2); import math # dynamically loaded from /usr/lib/python2.3/lib-dynload/math.so Illegal instruction Running python itself works. 2. the sources compiled with 4.0.3 give me an undefined symbol error: >>> import random # /usr/lib/python2.3/random.pyc matches /usr/lib/python2.3/random.py import random # precompiled from /usr/lib/python2.3/random.pyc dlopen("/usr/lib/python2.3/lib-dynload/math.so", 2); Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.3/random.py", line 42, in ? from math import log as _log, exp as _exp, pi as _pi, e as _e ImportError: /usr/lib/python2.3/lib-dynload/math.so: undefined symbol: PyFPE_jbuf >>> It gives the same traceback in both python itself and the embedded version. My main problem is the first error. I've found some older postings describing this behaviour and pointing at a compiler error (http://mail.python.org/pipermail/python-dev/2003-May/035386.html). But I'm not able to verify this error with gcc 4.1.2. Google finds some postings describing the same error - but it looks like nobody ever got an answer:( Would be nice to have more success... Regards Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: Illegal instruction or undefined symbol from import
Continuing my monologe;) Mathias Waack wrote: > I've embedded python into a legacy application. It works - most of the > time. In some special situations the app crashes executing the "import > random". There are two different situations: > > 1. the sources compiled with gcc 4.1.2 crash with illegal instruction > error: > > (running my application) > > Python 2.3.5 (#1, Jun 9 2006, 11:49:02) > [GCC 4.1.2 20060604 (prerelease) (Debian 4.1.1-2)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > dlopen("/usr/lib/python2.3/lib-dynload/readline.so", 2); > import readline # dynamically loaded > from /usr/lib/python2.3/lib-dynload/readline.so >>>> import random > import random # from /usr/lib/python2.3/random.py > # can't create /usr/lib/python2.3/random.pyc > dlopen("/usr/lib/python2.3/lib-dynload/math.so", 2); > import math # dynamically loaded from > /usr/lib/python2.3/lib-dynload/math.so Illegal instruction > > Running python itself works. The error occurred in calls to math.log(). I've patched mathmodule.c and call log1p(x-1) instead of log. It works as a first workaround. BTW, does anybody know why the c-lib offers both log and log1p? Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: Illegal instruction or undefined symbol from import
Richard Brodie wrote: > "Mathias Waack" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> BTW, does anybody know why the c-lib offers both log and log1p? > > So you can get a sensible answer computing log(1 + 10 ^ -30). Ok, that make sense to me. > There's > a lot of somewhat obscure mathematical stuff that got into the standard > C lib. How often do you need Bessel functions? Maybe each day. What is a Bessel function?;) Mathias -- http://mail.python.org/mailman/listinfo/python-list
Compiling python extension on amd64 for 32 bit
After switching my development environment to 64 bit I've got a problem with a python extension for a 32 bit application. Compiling the app under Linux results in the following error: g++ -m32 -Wall -g -O2 -I. -Idb -DPYTHON=25 -o mappy.o -c mappy.cpp In file included from /usr/include/python2.5/Python.h:57, from mappy.cpp:29: /usr/include/python2.5/pyport.h:732:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." My gcc is: Using built-in specs. Target: x86_64-suse-linux Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.1.2 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --program-suffix=-4.1 --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=x86_64-suse-linux Thread model: posix gcc version 4.1.2 20061115 (prerelease) (SUSE Linux) So I've checked this magic LONG_BIT define: #:/tmp cat t.c #include #include int main() { printf("%d\n",sizeof(long)); printf("%d\n",LONG_BIT); return 0; } #:/tmp gcc t.c #:/tmp ./a.out 8 64 #:/tmp gcc -m32 t.c #:/tmp ./a.out 4 32 Ok, thats fine. So why is python complaining? Or even more interesting, what do I have to do to compile the code? Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling python extension on amd64 for 32 bit
Andrew MacIntyre wrote: > Mathias Waack wrote: >> After switching my development environment to 64 bit I've got a >> problem with a python extension for a 32 bit application. > > {...} > >> Ok, thats fine. So why is python complaining? Or even more >> interesting, what do I have to do to compile the code? > > Is the Python your toolchain is referencing 32 or 64 bit? Based on > what I can see in pyport.h, I'd guess that you're finding a 64 bit > Python (ie SIZEOF_LONG == 8). There is no such thing as "the Python". A biarch environment offers both the 32 bit and the 64 bit versions of each library. And unique headers, because its assumed that the headers are independent of the architecture. Because of the -m32 Flag the pyport.h is used within a 32 bit env. Mathias -- http://mail.python.org/mailman/listinfo/python-list
optparse option prefix
We've integrated python into a legacy application. Everything works fine (of course because its python;). There's only one small problem: the application reads the commandline and consumes all arguments prefixed with a '-' sign. Thus its not possible to call a python module from the commandline with a parameter list containing options prefixed by '-' or '--' signs. Thats not a major problem, but it prevents us from using th optparse module. Is there a way to change to prefix, so one could use a '+' (for instance) to mark command line options for optparse? Regards Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse option prefix
Diez B. Roggisch wrote: >> (3) Create a filter module that reads sys.argv, replaces leading "+" >> signs with "-" signs, and then stuffs it back into sys.argv before >> optparse gets to see it. > > That's not even necessary, the optparser will work on a passed argument > list. No need to alter sys.argv. Sounds nice, I'll do so. Thanks! Mathias -- http://mail.python.org/mailman/listinfo/python-list
SIGILL importing random
Hi all, I've embedded python into an older application and created some extensions to interact with the old data structures. Everythings works like a charm - beside a simple "import random". During import the whole process crashes with a SIGILL. I've found some older mails describing just the same problem: http://mail.python.org/pipermail/python-dev/2003-May/035386.html Unfortunately I'm not able to read x86 assembler code:( I'm using gcc version 4.0.3 (Debian 4.0.3-1) and python: Python 2.3.5 (#2, Mar 6 2006, 10:12:24) [GCC 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)] on linux2 Everything out of the box from Debian unstable. Anybody with any idea about this? Mathias -- http://mail.python.org/mailman/listinfo/python-list
Re: AJAX Widget Framework
Laszlo Nagy wrote: > I'm looking for an open source, AJAX based widget/windowing framework. > Here is what I need: > > - end user opens up a browser, points it to a URL, logs in > - on the server site, sits my application, creating a new session for > each user that is logged in > - on the server site, I create windows(frames), put widgets on them, > write event handlers etc. Just like with wx or pygtk. > - However, windows are created in the user's browser, and events are > triggered by Javascript, and sent back to server through AJAX. > - the server side would be - of course - written in Python. > > I was looking these projects: > > http://www.uize.com/ > http://pyjs.org/ > > There are many frameworks listed here which I did not check: > http://internetmindmap.com/javascript_frameworks. I have no idea which > has Python support, and probably there are only a few that worth looking > at. I wonder if you could tell me which are the pros and contras for > these frameworks. If there is a comparison available on the NET, > pointing me to the right URL would help a lot. > > The bottom line... > > My main goal is to develop enterprise class OLTP database applications. > I'll need grid widget to display data in tabular format, and I'll use > events heavily for data manipulation, live search, tooltips etc. I'm > familiar with wxWidgets, pygtk and other toolkits, but not with AJAX. I > have never used a system like that. Of course I don't know which is the right way for you. I'm very happy with pyjamas. It allows you the create client applications in the same manner as standalone toolkits like wxWidgets. The message passing between client and server is simple done by exchanging json strings (its ajax based of course, but this stuff works silently in the background). On the server side there are many python toolkits, I prefer cherrypy, others are django and web.py. Hope this helps you. Mathias -- http://mail.python.org/mailman/listinfo/python-list