Re: I keep getting this error message when i try to run a program in Python
i am sorry but i can not find a way to attach an image here so you can see what i mean. Please someone tell me how to add an image here. Thanks Dan -- https://mail.python.org/mailman/listinfo/python-list
I keep getting this error message when i try to run a program in Python
Dear all I am totally new in learning Python and i am learning from a beginner's book called automate the boring stuff with Python and i downloaded the Python 64 bit version for Windows and i started writing some examples from the book. At the end whenever i try to run the program i keep getting an error message and it shows that the error is in the beginning in the version of Python. (See a pic bellow) Can someone help me and tell me what to do and why is this error showing up??? Thanks Dan -- https://mail.python.org/mailman/listinfo/python-list
Re: Confusing datetime.datetime
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: why greenlet, gevent or the stackless are needed?
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
Confusing datetime.datetime
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=DstTzInfo 'Europe/Skopje' 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=DstTzInfo 'Europe/Skopje' 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
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
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: PEP 405 vs 370
http://www.python.org/dev/peps/pep-0405/ I don't get what PEP 405 (Python Virtual Environments) brings vs what we already had in PEP 370 since Python 2.6. Obviously 405 has a tool to create virtual environments, but that's trivial for PEP 370 [1], and has support for isolation from the system-wide site patch which could've been added in addition to PEP 370. So maybe I'm missing something? My PEP 370 is about installing additional packages as an unprivileged user and for the current user. It's a simplistic approach that just adds one more site-package directory in the user's home directory. well you can have and activate several different directories (venvs) with PYTHONUSERBASE. I do use that very nicely, and haven't seen any problems with that. PEP 405 is a different beast. It adds support for isolated environment that don't share state with the site wide installation. A user can have multiple virtual envs and install different sets of packages in each env. Wouldn't it be easier to just add isolation to 370? Again, you can have multiple virtual envs with 370 too. ps. sorry for the late response, it seems my NNTP server doesn't relay all messages. I might need to switch. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
PEP 405 vs 370
http://www.python.org/dev/peps/pep-0405/ I don't get what PEP 405 (Python Virtual Environments) brings vs what we already had in PEP 370 since Python 2.6. Obviously 405 has a tool to create virtual environments, but that's trivial for PEP 370 [1], and has support for isolation from the system-wide site patch which could've been added in addition to PEP 370. So maybe I'm missing something? [1] PYTHONUSERBASE=~/my-py-venv pip install --user Whatever will create ~/my-py-venv and everything under it as needed PYTHONUSERBASE=~/my-py-venv python setup.py install --user the same without pip -- damjan -- http://mail.python.org/mailman/listinfo/python-list
How can I read streaming output of a subprocess
I want to read the stream of an external process that I start with Python. From what I've seen that's not possible with the subprocess module? I want to read the output of ip monitor neigh which will show changes in the ARP table on my Linux computer. Each change is a new line printed by ip and the process continues to run forever. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I read streaming output of a subprocess
I want to read the stream of an external process that I start with Python. From what I've seen that's not possible with the subprocess module? I want to read the output of ip monitor neigh which will show changes in the ARP table on my Linux computer. Each change is a new line printed by ip and the process continues to run forever. You can use subprocess for this. If you don't call wait() or communicate() on the Popen object, the process will happily continue running. You can call readline on the stdout pipe, which will block until the command you are running outputs (and flushes) a line. Something like this should work: p = subprocess.Popen(['ip', 'monitor', 'neigh'], stdout=subprocess.PIPE) first_line = p.stdout.readline() Buffering done by ip can ruin your day. It seems reasonable to expect, though, that something that is printing state changes on stdout will be careful to flush its output when appropriate. thanks, With your confirmation, I've rechecked again and now I see that the problem I experienced before was with some strange ssh interaction. -- http://mail.python.org/mailman/listinfo/python-list
Re: Async IO Server with Blocking DB
We are thinking about building a webservice server and considering python event-driven servers i.e. Gevent/Tornado/ Twisted or some combination thereof etc. We are having doubts about the db io part. Even with connection pooling and cache, there is a strong chance that server will block on db. Blocking for even few ms is bad. Libraries that support the event loop of your framework, be it Gevent, Tornado or Twisted, should yield to other work when the database connection (its socket) blocks. Now, database drivers that use C libraries are ussually a problem, unless designed to cooperate with event loops. One of those is psycopg2 which at least cooperates with Gevent. CouchDBkit (using restkit ie http) also cooperates with Gevent fine. MySQLdb does not cooperate with Gevent as far as I know, so one sollution would be to run queries through a Thread Pool (built-in in Gevent 1.0dev). Another is to use the pure python mysqlconn (mysql-connector-repackaged on pypi) with gevents monkey patching. Sqlite should be probably run in a ThreadPool too, since it depends on disk I/O which is not async in Gevent. You can readup on Gevent integration of Couchdbkit and Psycopg2 in their documentation. can someone suggest some solutions or is async-io is not at the prime- time yet. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
[issue14247] in operator doesn't return boolean
New submission from Damjan Košir damjan.ko...@gmail.com: In operator acts like it doesn't return a boolean value 3 in [1,2,3] == True False and even 3 in [1,2,3] == 3 in [1,2,3] False but somehow if you add ( ) it starts working (3 in [1,2,3]) == True True Tested on OSX 10.7 Python 2.7.1 -- components: None messages: 155329 nosy: Damjan.Košir priority: normal severity: normal status: open title: in operator doesn't return boolean versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14247 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
The original command python line
How can I get the *really* original command line that started my python interpreter? Werkzeug has a WSGI server which reloads itself when files are changed on disk. It uses `args = [sys.executable] + sys.argv` to kind of recreate the command line, and the uses subprocess.call to run that command line. BUT that's problematic as, when you run:: python -m mypackage --config sys.argv printed in mypackage/__main__.py will be:: ['/full/path/to/mypackage/__main__.py', '--config'] so you get:: python /full/path/to/mypackage/__main__.py --config instead of:: python -m mypackage --config the difference in the 2 cases is what the current package is, and whether you can use relative imports. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: The original python command line
How can I get the *really* original command line that started my python interpreter? Werkzeug has a WSGI server which reloads itself when files are changed on disk. It uses `args = [sys.executable] + sys.argv` to kind of recreate the command line, and the uses subprocess.call to run that command line. BUT that's problematic as, when you run:: python -m mypackage --config sys.argv printed in mypackage/__main__.py will be:: ['/full/path/to/mypackage/__main__.py', '--config'] so you get:: python /full/path/to/mypackage/__main__.py --config instead of:: python -m mypackage --config the difference in the 2 cases is what the current package is, and whether you can use relative imports. BTW, the same thing happens in Python 3.2.2. To reproduce:: mkdir /tmp/X cd /tmp/X mkdir mypackage touch mypackage/__init__.py mypackage/dummy.py cat EOF mypackage/__main__.py from __future__ import print_function, absolute_import import os, sys, subprocess def rerun(): new_environ = os.environ.copy() new_environ['TEST_CHILD'] = 'true' args = [sys.executable] + sys.argv subprocess.call(args, env=new_environ) if os.environ.get('TEST_CHILD') != 'true': Role = 'Parent' rerun() else: Role = 'Child' try: from . import dummy except: print('Exception in %s' % Role) else: print('Success in %s' % Role) EOF Both:: python2 -m mypackage or:: python3 -m mypackage will print:: Exception in Child Success in Parent -- http://mail.python.org/mailman/listinfo/python-list
Re: The original command python line
How can I get the *really* original command line that started my python interpreter? snip On Linux, you can read from: /proc/PID here/cmdline to get the null-delimited command line. After some further searching: psutil offers `Process.cmdline` cross-platform; see http://code.google.com/p/psutil/wiki/Documentation Indeed, changing for args = psutil.Process(os.getpid()).cmdline in the above example does solve the problem, at least in Linux. Sidenote: Consensus generally seems to be that relative imports are a bad idea. How come? I'm using explicit relative imports, I thought they were the new thing? -- damjan -- http://mail.python.org/mailman/listinfo/python-list
[issue8998] add crypto routines to stdlib
Changes by Damjan Georgievski gdam...@users.sourceforge.net: -- nosy: -gdamjan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8998 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8998] add crypto routines to stdlib
Damjan Georgievski gdam...@users.sourceforge.net added the comment: AFAIK, what the stdlib needs is a high-level crypto module, analogous to hashlib -- nosy: +gdamjan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8998 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: py3k s***s
To be frank, no innovation. Just changes, no progress. And yes, I am pd. anger leads to hate, hate leads to suffering Somebody compared it with MS stuff. Yes. It's not similar at all. MS will first force all your customers/users to upgrade to their newest software, at the same time suffocating the old software, and denying anyone the oportunity to maintain that old software (part because it's closed-source, part because MS will sue you if try anything close to that). -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Pystemmer 1.0.1 installation problem in Linux
mungkol wrote: Dear all, I am a newbie to Python community. For my project, I tried to install Pystemmer 1.0.1 (http://snowball.tartarus.org/wrappers/ PyStemmer-1.0.1.tar.gz) on my linux ubuntu 7.10 machine but unsuccessful. It produced the following error: you need to install the build-essential pacakge group on Ubuntu so that you can compile programs. apt-get install build-essential limits.h: No such file or directory This is probably /usr/include/linux/limits.h part of the kernel headers. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Beta testers needed for a high performance Python application server
I'm looking for beta testers for a high performance, event-driven Python application server I've developed. About the server: the front end and other speed-critical parts of the server are written in portable, multithreaded C++. ... Why not just put it on the net somewhere and tell us where it is? People aren't generally going to want to help or even look at it if you treat it like a proprietary application. So, put the documentation and code up somewhere for all to see. BTW, multiprocess web servers such as Apache can quite happily make use of multiple cores. Even within a single Apache multithread process it can still use multiple cores quite happily because all the underlying network code and static file handling code is in C and not subject to the GIL. So, as much as people like to bash up on the GIL, within Apache it is not necessarily as big a deal as people make out. BTW nginx now has a mod_wsgi too, if someone is looking for an Apache replacement. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: TheSchwartz in Python?
Cool, but sched saves job in memory... cron can't be an option. It's just a scheduler not a job queue. You could probably make lpd do what you want to do. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: virtualpython / workingenv / virtualenv ... shouldn't this be part of python
My question is, shoudn't it be enough to set PYTHONPATH and everything automagically to work then? Is there some work done on this for python 3.0 or 2.6 perhaps? I'm working on a PEP for a per user site dir for 2.6 and 3.0 great .. can't hardly wait. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
virtualpython / workingenv / virtualenv ... shouldn't this be part of python
There are several attempts to allow python to work with per user (or even per session) 'site-packages' like virtualpython / workingenv / virtualenv. But they all have their own shortcomings and quirks. My question is, shoudn't it be enough to set PYTHONPATH and everything automagically to work then? Is there some work done on this for python 3.0 or 2.6 perhaps? -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: OPLC purchase period extended
It is fairly nice for that. It's especially cool that the screen works outdoors (reflective). I don't know why regular laptops don't do that any more. I think because they can't reproduce colors correctly with reflective light. The OLPC is blackwhite (and grey) when in the reflective outdoor mode. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
[issue1427] Error in standard module calendar
New submission from Damjan Georgievski: This is LocaleTextCalendar.__init__ def __init__(self, firstweekday=0, locale=None): TextCalendar.__init__(self, firstweekday) if locale is None: locale = locale.getdefaultlocale() self.locale = locale Which can not work, obviosly ... let me hilight the important part if locale is None: locale = locale.getdefaultlocale() ??? Attached is a patch that corrects this and keeps the signature of the method with the locale=None keyword. -- components: Extension Modules files: calendar.diff messages: 57384 nosy: gdamjan severity: normal status: open title: Error in standard module calendar type: behavior versions: Python 2.5 Added file: http://bugs.python.org/file8734/calendar.diff __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1427 __ calendar.diff Description: Binary data ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Low-overhead GUI toolkit for Linux w/o X11?
PyQt and PySDL are AFAIK not much less weight. They don't use X11. That's a _lot_ less weight. Do you mean the X11 server or the libraries? The kdrive server should be fairly small (depending on features). I think it builds from the main xorg source today?? Isn't that what maemo uses. I don't know about the X11 libraries, but the xcb libraries are pretty much small too (126kb on i386 here) - there are additional libraries depending on which features you want: render, shape, screensaver, shm, randr, dri etc.. Shame the toolkits still don't use it directly. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: annoying stdin/stdout + pipes problem
I want to create a program that reads input from stdio that can prompt a user for input while doing so without getting into problems. ... As you can see I have commented out what I'd like to do but do not know how to. Can I somehow halt the previous print to stdout (cat input.txt) - if so can I then start it again, and how? The trick (which works on Linux for sure) is to open /dev/tty and ask question/get input on/from it. fp = open('/dev/tty', 'r+') fp.write('Prompt: ') answer = fp.readline().strip() I'm not usre for other *nix-es, and on Windows this will surelly not work -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: encoding problems
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
Python IMAP web-access
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: Building a Python app with Mozilla
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
Re: About Trolltech QT OpenSource license.
@ Kevin and Jarek : thanks for the enlightening of that GPL thing. So, if i understand, i create my Python software using Qt as my GUI, i earn the money for it with the obligation to release my source code and somewhere in my files i explicilty write that this software is under the GPL lisence, is that correct ?? And i am legal all the way out ?? This is correct... but you should also understand the GPL license aswell. So why these people at Trolltech have the word Commercial at their mouth all the time ?? I can understand of course that money is all about but becauce they released Qt under GPL they simply cannot prevent anyone from gaining money using it. That is a mistake, the oposite of libre software is non-libre or proprietary. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: frame of Qt program
Look at the network examples included with PyQt4. Particularly fortuneclient.py and fortuneserver.py. PyQt4 has its own network classes that are fully integrated with the event loop making it easy to write GUI/network applications. As threads also have an event loop its also easy to push the network handling out to separate threads. The next version of Qt will add support for SSL. I've always wondered how PyQT4 compares to Twisted for writing network apps. Qts signal/slot mechanisam is much easier to understand/work with than deferreds. On the other hand Twisted probably supports more protocols right now. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: I18n issue with optik
Actually rxvt, Poderosa and console have the ability to display non- ASCII characters. I use the dejavu fonts that support non-ASCII, too. But the problem is even simpler: I can't even set the standard Windows console (cmd) to Windows 1252 in Python. Although directly executing chcp 1252 works. Maybe try to use http://sourceforge.net/projects/console it's claimed to be muc better than the sucky CDM (I don't have windows to try it). -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: socket read timeout
So set a long timeout when you want to write and short timeout when you want to read. Are sockets full duplex? I know Ethernet isn't. Both are full duplex. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
PyPy for dummies
.. like me. Ok, this is what I understood why PyPy is important. Writing programing languages and implementations (compilers, interpreters, JITs, etc) is hard. Not many people can do it from scratch and create something comparable to what's available today. But we need people with new aproaches, exploring new ideas (to boldly go where no hacker has gone before). Also, evolving the current Python language and implementation is not easy either. As it becomes more complex, it's hard for newcomers to comprehend it as a whole, and as it is still harder and harder to work on details without understanding the whole. What PyPy provides is, making this easier, thus allowing for: *rapid turnaround* of language features and implementation details - this enables easier experimentation and testing of wild ideas. Most of them will fail of course, but some will succed and some will succed and suprise (NOBODY expects the Spanish Inquisition!). So that's how I see PyPy ... at the same time an interesting - let's call it - academic experiment, but also something very close to beeing usefull at the level of the current CPython. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Approaches of interprocess communication
| If a programmer decides on behalf of the user that localhost should | be treated specially, that programmer is making an error. | | Inter-process TCP/IP communication between two processes on the same | host invariably uses the loopback interface (network 127.0.0.0). | According to standards, all addresses in that network space refer to the | local host, though 127.0.0.1 is conventionally used. | | The transmit driver for the loopback interface receives a datagram from | the local network layer and immediately announces its reception back to | the local network layer. Are you saying, in that first paragraph, that if for example I telnet to my local host's external IP address, to a service that bound explicitly to the external interface -- I'll actually be going through the loopback interface anyway, invariably regardless of host network implementation? On linux at least, this is true, yes. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Wing IDE 2.1.4 Released
This is a bug fix release that among other things fixes handling of UTF-8 byte order marks, What are UTF-8 byte order marks ?!? There's only one order in the UTF-8 bytes! -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with pyzeroconf and linux
I am trying to get pyzeroconf (http://sourceforge.net/projects/pyzeroconf) running on my machine but having trouble... Running the Zeroconf.py file seems to register the service, but is unable to find it. You should be running avahi.. it also comes python support. Here's an example that registers a CNAME that points to your hostname (that avahi itself publishes) #! /usr/bin/env python import avahi, dbus from encodings.idna import ToASCII # Got these from /usr/include/avahi-common/defs.h CLASS_IN = 0x01 TYPE_CNAME = 0x05 TTL = 60 def publish_cname(cname): bus = dbus.SystemBus() server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) group = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP) rdata = createRR(server.GetHostNameFqdn()) cname = encode_dns(cname) group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), cname, CLASS_IN, TYPE_CNAME, TTL, rdata) group.Commit() def encode_dns(name): out = [] for part in name.split('.'): if len(part) == 0: continue out.append(ToASCII(part)) return '.'.join(out) def createRR(name): out = [] for part in name.split('.'): if len(part) == 0: continue out.append(chr(len(part))) out.append(ToASCII(part)) out.append('\0') return ''.join(out) if __name__ == '__main__': import time, sys, locale for each in sys.argv[1:]: name = unicode(each, locale.getpreferredencoding()) publish_cname(name) try: while 1: time.sleep(60) except KeyboardInterrupt: print Exiting -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about docutils
I'm using docutils 0.4. Is it possible to define special custom 'tags' (or something) that will invoke my own function? The function would then return the real content in the ReST document. I -think- this is what you're looking for: http://docutils.sourceforge.net/docs/howto/rst-roles.html Hope it helps. Thanks, it looks to be exactly what I need... I'm reading it now, and will try to implement it. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Question about docutils
I'm using docutils 0.4. Is it possible to define special custom 'tags' (or something) that will invoke my own function? The function would then return the real content in the ReST document. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: The reliability of python threads
and the GIL is more than an artifact. It is a central tenet of threaded python programming. If it's a central tenet of threaded python programming, why is it not mentioned at all in the language or library manual? The threading module documentation describes the right way to handle thread synchronization in Python, and that module implements traditional locking approaches without reference to the GIL. And we all hope the GIL will one day die it's natural death ... maybe... probably.. hopefully ;) -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any python-twisted tutorial or texts?
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: Mod_python vs. application server like CherryPy?
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: lxml/ElementTree and .tail
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: WSGI - How Does It Affect Me?
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: CGI - mod_python
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: Don't use regular expressions to validate email addresses (was: Ineed some help with a regexp please)
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: naming objects from string
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: CONSTRUCT - Adding Functionality to the Overall System
__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) type 'classobj' class A(UserDict): ... pass type(A) type 'classobj' __metaclass__ = type class B(UserDict): ... pass type(B) type 'classobj' 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: Is there a way to find IP address?
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?
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
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: get the en of a program running in background
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
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
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: Python newbie with a problem writing files
Code: snip 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: Broadcast server
[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: Persistent Session in CGI
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
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)
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: hide python code !
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: ImportError: libclntsh.so.10.1: cannot open shared object file: Permission denied
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
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: Need a compelling argument to use Django instead of Rails
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?
I also recommend psycopg. But make sure you use psycopg2 -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
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: How to force a thread to stop
| 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: threading+ftp+import = block
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 / program block 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
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 / program block 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
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: ImportError: libclntsh.so.10.1: cannot open shared object file: Permission denied
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: unicode html
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 = ocirc; '#%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: Chapter 9 Tutorial for Classes Not Working
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 stdin, 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: Python database access
The odbc module is part of the Python Standard Library. Since when? -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyQt v4.0 Released - Python Bindings for Qt v4
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: is a wiki engine based on a cvs/svn a good idea?
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: how to clear up a List in python?
And, if a list have 801 values, I want to get its values index from 300 to 400, could use list1[300:400],are right me? 300 will be included in your slice whereas the 400th index will be excluded. you will ultimately have 99 items in your slice. No, he'll have 100 items in the slice... 300, 301,... 399 that's 100 items. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Dumb-as-rocks WSGI serving using standard library
What I can't find is a simple recipe to serve a WSGI application with a dumb-as-rocks HTTP server, just using the standard Python library. The standard library includes BaseHTTPServer, which as far as I can tell doesn't know anything about WSGI. Everything else that I can find leads to dependencies I don't want for flexibility I don't need: cherrypy, paste, et al. Any suggestions for how to serve up a simple WSGI application with just the standard library? There's no WSGI http server in the std lib as of Python 2.4. Paste[1] provides one, wsgiref[2] (probably will be included in Python 2.5) provides a SimpleHTTPServer and CGI based WSGI servers. There's also WSGIUtils[3] that provides that. [1] http://pythonpaste.org/ [2] http://svn.eby-sarna.com/wsgiref/ http://www.artima.com/weblogs/viewpost.jsp?thread=158191 [3] http://www.owlfish.com/software/wsgiutils/ -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: enumerate() question
I have a question for the developer[s] of enumerate(). Consider the following code: for x,y in coords(dots): print x, y When I want to iterate over enumerated sequence I expect this to work: for i,x,y in enumerate(coords(dots)): print i, x, y for i, (x, y) in enumerate(coords(dots)): print i, x, y -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb - parameterised SQL - how to see resulting SQL ?
... i would be interested in seeing what the actual SQL used by the .execute looks like after the replacements have been done. Is there a way of doing this ? On my development machine I'm using the --log argument to MySQL so that it logs all queries and connections. I wouldn't recommend that on a production machine though. The logfile is stored in /var/lib/mysql/hostname.log -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Eggs Just install in *ONE* place? Easy to uninstall?
But not matter where eggs are installed they are never spread across multiple places on hard drive right? An egg is all under one node of tree right? From what I've seen, no. For example installing TurboGears will also install the tg-admin script in /usr/bin/ and there are a lot of other projects that install custom scripts. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: converting to scgi
I'm looking for a scgi modules that make it easy to convert a CGI using the standard Python CGI module. I'm hoping for something that will run my program either as scgi or cgi. I did find something called paste which purports to be some sort of CGI Bridge framework but from the documentation, it appears that the flexibility has eliminated the simplicity. If you write web application for WSGI, then you could as easilly run them in SCGI, CGI, mod_python, fast_cgi, in twisted or in a standalone HTTP server. Some resources: http://groovie.org/articles/2005/10/06/wsgi-and-wsgi-middleware-is-easy http://blog.ianbicking.org/wsgi-sample-apps-and-middleware.html http://pythonpaste.org/do-it-yourself-framework.html PythPaste of course provides a lot of tools to use with WSGI: http://pythonpaste.org Flup provides scgi, fastcgi and AJP absed WSGI servers: http://www.saddi.com/software/flup/ The WSGI specification: http://www.python.org/peps/pep-0333.html ps. It would be nice if others supplied some interesting WSGI resources too. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a Python MVC that works just as well with just CGI, or FCGI?
TurboGears? www.turbogears.com -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python + apache + winxp = nogo
to apache's httpd.conf, apache refuses to start, saying: cannot load c:/path/mod_python.so into server: the specified module could not be found which probably means that mod_python.so is not in that directory? -- http://mail.python.org/mailman/listinfo/python-list
Is there a WSGI sollutions repository somewhere
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
Because you wrote curentText - note the missing t. :) You mean the missing 'r' :) -- http://mail.python.org/mailman/listinfo/python-list
Python 2.4.2 and Berkeley DB 4.4.20 ?
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
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
Re: Problem with curses and UTF-8
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
Re: SMPP implementation in python
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: quick unicode Q
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
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? ^^
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: small inconsistency in ElementTree (1.2.6)
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
Re: small inconsistency in ElementTree (1.2.6)
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
small inconsistency in ElementTree (1.2.6)
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 = \ ?xml version=1.0 encoding=UTF-8? root p1 ascii /p1 p2 \xd0\xba\xd0\xb8\xd1\x80\xd0\xb8\xd0\xbb\xd0\xb8\xd1\x86\xd0\xb0 /p2 /root 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: Oracle 9i client for Linux
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
Re: Unicode in MIMEText
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: Unicode in MIMEText
... 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