Re: Database intensive application
On Sun, Aug 12, 2007 at 05:08:26AM -, Rohit wrote: I am a novice. I want to know whether Python can be used to develop client/server database and web applications like .NET. http://pylonshq.com/ http://www.djangoproject.com/ http://turbogears.org/ Which is the best book/source to learn Python? http://wiki.python.org/moin/PythonBooks Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Berkely Db. How to iterate over large number of keys quickly
On Thu, Aug 02, 2007 at 07:43:58PM -, lazy wrote: I have a berkely db and Im using the bsddb module to access it. The Db is quite huge (anywhere from 2-30GB). I want to iterate over the keys serially. I tried using something basic like for key in db.keys() but this takes lot of time. I guess Python is trying to get the list of all keys first and probbaly keep it in memory. Is there a way to avoid this, since I just want to access keys serially. Does db.iterkeys() work better? Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Why PHP is so much more popular for web-development
On Wed, Jul 25, 2007 at 12:34:08PM -0700, walterbyrd wrote: When I posted Python I meant the Python web-developement world. In particular, python frameworks, like CherryPy, have requirements that are not realistic for most shared hosting plans. It's true that the requirements are higher than what the old-school CGI/PHP web hosters offer. But with todays virtual root servers it's really inexpensive to run such a server. And using frameworks allows you to control all aspects of the web serving like URL dispatching, error handling and is probably even faster than PHP because necessary resources (like database connections) are initalized upon startup of the web application. PHP and CGIs do this everytime they get called. Maybe I'm wrong, but I often get the idea that those who develop python frameworks don't give a thought to the realities of shared hosting. They seem to think that everybody has complete control over the server. Things are very different in the PHP universe. Without wanting to sound arrogant: it's my belief that web hosters just offering htdocs/PHP will probably just be useful for the noob-customers who have no idea of operating systems but just want their blinking personal homepage online. There are good PHP applications and I wouldn't want to give up phpmyadmin or squirrelmail. But with today's demand for fully controllable interactive (you will never hear me propagate that bullshit buzzword Web x.0) web sites a framework seems to be a viable way. For me PHP has a bitter taste of easy enough for every noob to use it which makes it the language the most insecure applications are written in. The point is: PHP framework makers are very considerate of the realities of shared hosting. Python framework makers don't seem to give it a thought. Just maybe, that's something that Python could learn from PHP. Perhaps. But the hosting market changes. And I believe that PHP suits the simpler applications better. I would point a beginner in web programming more likely to PHP than torture them with frameworks. It's just too heavy. OTOH full-featured frameworks are way more complicated and have eviler requirements but there are hardly any limitation on the kinds of sites you can power with them. EO2¢ Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Lazy for line in f ?
On Sun, Jul 22, 2007 at 09:10:50AM -0700, Alexandre Ferrieux wrote: I'm a total newbie in Python, but did give quite a try to the documentation before coming here. Sorry if I missed the obvious. The Tutorial says about the for line in f idiom that it is space- efficient. Short of further explanation, I interpret this as doesn't read the whole file before spitting out lines. Correct. It reads one line at a time (as an iterator) and returns it. In other words, I would say lazy. Which would be a Good Thing, a much nicer idiom than the usual while loop calling readline()... The space-efficiency is similar. The faux pas would rather to read the whole file with readlines(). But when I use it on the standard input, be it the tty or a pipe, it seems to wait for EOF before yielding the first line. Standard input is a weird thing in Python. Try sending two EOFs (Ctrl-D). There is some internal magic with two loops checking for EOF. It's submitted as a bug report bug the developers denied a solution. Otherwise it's fine. In a pipe you shouldn't even notice. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python newbie ask a simple question
On Fri, Jul 13, 2007 at 06:35:16PM -, [EMAIL PROTECTED] wrote: what does the statement choice = raw_input(prompt)[0] mean? I don't know why there is a '[0]' in the statement. It calls the raw_input function with the argument of prompt. That function returns a list and you are getting the first ([0]) value from that list. Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: web development without using frameworks
On Tue, Jun 05, 2007 at 03:01:01PM -0400, Chris Stewart wrote: I'm interested in learning web based python without the use of fancy frameworks that are out there. I'm having a hard time coming up with resources and examples for this. Does anyone have anything that could be helpful? I'd say the only decent ways are either using a full-featured framework (I favor Pylons) or write plain CGIs. Even for the later a look into http://wiki.python.org/moin/WebFrameworks might be useful (I wouldn't say that web.py is really a framework - and it's listed there). Or you write plain-old CGIs with Python's cgi module. I have also started like that but currently only use frameworks because the cgi module is pretty limited (compared to what Perl offers) and for serious applications not really the way to go. My 2¢ Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Real globals inside a module
On Sun, May 13, 2007 at 11:41:12AM +0200, Jorgen Bodde wrote: I am wrestling with some architecture inside my app. Let's say I have a tunings collection, which contains e.g. 23 types of guitar tunings. In my song object I want to restore a relation between one of the tuning objects inside the tunings module. I already figured out I need somethign like a global collection inside the tunings module,. but how global is it? When I am inside my app object, and import the tunings module, can I access the same global class as when I am inside my songs module and load the tunings module? You are on the right way. If you import the same module a second time in another place of your application you get access to the exact same data. That is called a singleton. I often use such a singleton for global configuration data. So basically I want to access the same global list in both modules, but not re-create the list in every module since it should be restored by the database layer once. Import your global module and just run the initalisation once. That should do it. Thanks for any advice, I do not want to make a global manager object that I need to pass around all the time, that would be silly.. Indeed. That would suck. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: N00b question on Py modules
On Mon, May 07, 2007 at 12:00:38AM -0700, [EMAIL PROTECTED] wrote: Hi. Sorry to sound like a noob but that's what I am when it comes to Python. I just wrote the below module and it behaves funny. My python module: _exitcode = 0 def setExitCode(): _exitcode = 1 if __name__ == '__main__': print _exitcode setExitCode() print _exitcode Actual O/P: 0 0 I expected to see an output of 0 followed by 1. But it turns out that the _exitcode variable is not changed at all. It seems that setExitCode() might be editing a local copy of the _exitcode variable. But then, how do I tell it to change the value of the module variable and not its local variable. _exitcode is a global variable in your program. In functions (def) you can read global variables. But if you change or reassign them the change will be only local to the function. If you want to change the global variable your def needs to be: def setExitCode(): global _exitcode _exitcode = 1 Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: More newbie help required with dictionaries
On Mon, Apr 16, 2007 at 06:43:37AM -0700, loial wrote: The following code only returns the last row(22) added to the machines dictionary. presumably I need some additional syntax to add rows to the dictionary rather than overwrite. What do I need to add? machinekey = 11 machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] } machinekey = 22 machines = { machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] } You redefine the machines dictionary here. So it just contains one entry. What you mean: machines.update({ machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] }) Or: machines[machinekey] = [0,1,0,0,0,0,0,0,0,0,0,0,0] Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Python editor/IDE on Linux?
On Fri, Apr 13, 2007 at 11:20:23AM -0700, Jack wrote: I wonder what everybody uses for Python editor/IDE on Linux? I use PyScripter on Windows, which is very good. Not sure if there's something handy like that on Linux. I need to do some development work on Linux and the distro I am using is Xubuntu. We should do a weekly poll. :) Seriously - this question is coming up very frequently and everybody has their preference. Large list: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments My (current) favorite: pida (exists as a ready package on Debian as derivates like Xubuntu) pida because it embeds the 'vim' editor which I love and adds useful features without really getting in my way. And it's the only IDE I found that supports bazaar-ng (bzr) repositories. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Sharing Objects in Python
On Friday 16 March 2007 12:41, Clement wrote: Can a object sharable by two different python programs... If so can you please explain... because my project needs two programs to access nearly 45GB file Symentaniously... What kind of information is that? Can you put it into a database? Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiline code - trailing slash usage
On Thursday 15 March 2007 15:57, abcd wrote: When do I need to use a trailing slash to separate code over multiple lines. For example: x = hello world, this is my multiline + \ string Needed. Although you can omit the +. x = {'name' : \ 'bob'} Not needed because you are inside the curly brackets {} and it's clear where the statement ends. Do I need to use the \ in the above examples? When do i need to use it? Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on indexing
On Friday 01 December 2006 17:21, Tartifola wrote: I would like to obtain the position index in a tuple when an IF statement is true. Something like a=['aaa','bbb','ccc'] [ ??? for name in a if name == 'bbb'] 1 What about: [ x for x,y in enumerate(a) if y == 'bbb' ] Or if there is only one element 'bbb': a.index('bbb') Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Pimping the 'cgi' module (was: Re: python gaining popularity according to a study)
On Thursday 23 November 2006 21:29, robert wrote: When a LAMP programmer comes to Python, there are so many different confusing things. It starts with a 'non-documented' cgi module - a 'High-Level-Interface', that cannot even iterate over the form items. A name ZOPE in focus which reveals to be a monster system with 2-year learning-curve, ready for running an article editorial system for TOP-10 newspaper companies, but unable to make simple things simple. A handful of different Djangos - choose one for each weekday and programmer ... And Ruby made it with this single-known simple URL-to-method-router (And possibly when coming from PHP Perl one recognizes ::@$_$%§§%/... and the old namespace dirt) If there would have been a good cgi-system and a somewhat comfortable advanced URL-to-OO-router (beyond the socket wrapper HTTPServer) well exposed in the Python standard lib, the numbers would be probably very different today ... I can fully second that. Coming from Perl and being used to the CGI module that is de-facto standard and already doing things much better than Python's equivalent my first thought was: Does Python really expect me to re-invent the wheel to write basic CGIs? So I started creating cookie-based session handlers, form field handling etc. The reason of my posting it not only to complain though. My Python skills are average but I would really like to help contribute some code on this topic. I don't know Ruby-on-Rails myself but I have worked with CGIs for ten years both in C (yuk) and Perl (Perl=semi-yuk / Perl-CGI=yum) and think I know what people coming from Perl expect. And I'm not speaking of Zope or Django or huge frameworks. I try to avoid frameworks wherever I can (I want to write Python - not Zope or Django). I rather rely on the standard library unless it's really saving me time and worth learning another language. Are frameworks perhaps even telling that the standard library is still lacking in some way? I'm thinking of features like: - cookie handling - cookie-session handling (similar to PHP or Perl's CGI::Session; combined with database backends or simple text files) - handling of form fields (Perl's CGI class can easily redisplay what has been entered in the fields when they got submitted through a FORM) - accessing parameters (honestly I haven't yet understood why I need to use .value on FielStorage dictionaries - why isn't it just a plain dictionary?) - state keeping (storing the contents of all form fields on disk to retrieve it later) - creating form elements easily (option lists for example from dictionaries and lists like in Perl) - creating standard HTML elements (or do you remember how DOCTYPE looks without looking it up?) - handling of file uploads (which is just a recipe on ActivePython at the moment) - controlling HTTP headers (expires, redirections, charset) - convenience functions e.g. for getting the client IP address without needing to read ENV['REMOTE_ADDR'] Well, of course there are modules like 'cgi' or 'cookielib' and others may argue that everything is already there. And there is a 'Web.py' already (I assume every CGI programmer has written their own Web.py already). But can't we come closer to what other scripting languages provide? Something common? Can't a simple form-based CGI just be a matter of a dozen lines? When it comes to CGIs Python loses its elegance for no reason. I'm ready to invest work and ideas if anyone else is interested. Perhaps some day it makes it into the standard library or at least gives us something between the features of the standard library and huge framework monsters - something people can be pointed at when starting with Python and CGIs. I'll probably do that anyway because my web projects all use their own reinvented wheel and I'm losing the overview. And even Perl has come that route - it started with a cgi-lib.pl which later became the 'CGI' standard module. Is it just a matter of lacking resources or interest? Even if there is no interest I'll probably read man CGI and man CGI::Session again and start implementing something nifty for ex-perlies like myself. Hmmm, batteries included even for CGI programmers, a man can dream. :) Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Email headers and non-ASCII characters
On Thursday 23 November 2006 16:31, Max M wrote: Christoph Haas skrev: Hello, everyone... I'm trying to send an email to people with non-ASCII characters in their names. A recpient's address may look like: Jörg Nørgens [EMAIL PROTECTED] My example code: = def sendmail(sender, recipient, body, subject): message = MIMEText(body) message['Subject'] = Header(subject, 'iso-8859-1') message['From'] = Header(sender, 'iso-8859-1') message['To'] = Header(recipient, 'iso-8859-1') s = smtplib.SMTP() s.connect() s.sendmail(sender, recipient, message.as_string()) s.close() = However the Header() method encodes the whole expression in ISO-8859-1: =?iso-8859-1?q?=22J=C3=B6rg_N=C3=B8rgens=22_=3Cjoerg=40nowhere=3E?= However I had expected something like: =?utf-8?q?J=C3=B6rg?= =?utf-8?q?_N=C3=B8rgens?= [EMAIL PROTECTED] Of course my mail transfer agent is not happy with the first string Why offcourse? Because my MTA doesn't care about MIME. It just transports the email. And it expects an email address in ... but doesn't decode =?iso...? strings. But it seems that you are passing the Header object a utf-8 encoded string, not a latin-1 encoded. You are telling the header the encoding. Not asking it to encode. Uhm, okay. Let's see: u'Jörg Nørgens [EMAIL PROTECTED]'.encode('latin-1') = 'J\xc3\xb6rg N\xc3\xb8rgens [EMAIL PROTECTED]' So far so good. Now run Header() on it: = '=?utf-8?b?IkrDtnJnIE7DuHJnZW5zIiA8am9lcmdAbm93aGVyZT4=?=' Still nothing like ... in it and my MTA is unhappy again. What am I missing? Doesn't anyone know how mail clients handle that encoding? Desperately, Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Pimping the 'cgi' module
On Friday 24 November 2006 13:08, robert wrote: well, note, for that they have named it Ruby-On-Rails, so its still the language - leveraged. While it is Zope/Django/Ego-on-Python ... ? If by that you mean that neither Zope nor Django are exactly pythonic I think I concur. Unless a Guido'ed version of such thing is not _selected_ into the stdlib or at least promoted single-mindedly and prominently by far before high-tech-but-low-number names like Zope and Django, Python will continue to bleed out heavily on numbers vs. Ruby. Guido seems to have been confused about the rank growth of web based frameworks himself. So it's even less likely one of them gets included as part of the standard library in finite time. First need of course: an update of that cgi module. Oh, yeah. I just joined the Web SIG and found out that WSGI seems the way to go. At a first look it seems horrible if you just want to provide a CGI module. But there must be some reason for its existence. :) Looking further through http://wiki.python.org/moin/WebFrameworks my head starts to spin. Somehow I sadly feel I would just add another incomplete framework to that pile. I'm especially unsure whether it's good or bad to create another I'm sick of the standard library-style module. I've just become a bit less confident to actually contribute something useful there. Overwhelming. python-dev is fully occupied with top-notch inner life. Of course that is the basis. But key issues in libtools were simply forgotten - left to a random community. Which doesn't match the batteries included fuss at all. Of course the basis has to be good, too. And there are so many paradigms today that no core-python developer can really be expected to provide good standard modules for everyone. Go for a start. In order to realize that essential batteries in good quality within time - even after 10 years now - it is necessary, to hook python-dev for even requesting it actively. Just adding to http://wiki.python.org/moin/WebProgramming and http://wiki.python.org/moin/WebFrameworks is not the task. It requires some organization and somewhat a selection process in addition to good (probably existing) code v0.1xxx material. I think it would not be overly complex. Both, a new cgi and possibly included snake rails (vs oil) Oil is deprecated anyway. :) I'll see if I can find my way into the SIG. And - yes - adding another framework will surely not help us out of the divergence. The more frameworks there are the more people seem to feel urged to say heck, it will be easier to write my own framework than evaluate all 30 packages on that page. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Email headers and non-ASCII characters
Hello, everyone... I'm trying to send an email to people with non-ASCII characters in their names. A recpient's address may look like: Jörg Nørgens [EMAIL PROTECTED] My example code: = def sendmail(sender, recipient, body, subject): message = MIMEText(body) message['Subject'] = Header(subject, 'iso-8859-1') message['From'] = Header(sender, 'iso-8859-1') message['To'] = Header(recipient, 'iso-8859-1') s = smtplib.SMTP() s.connect() s.sendmail(sender, recipient, message.as_string()) s.close() = However the Header() method encodes the whole expression in ISO-8859-1: =?iso-8859-1?q?=22J=C3=B6rg_N=C3=B8rgens=22_=3Cjoerg=40nowhere=3E?= However I had expected something like: =?utf-8?q?J=C3=B6rg?= =?utf-8?q?_N=C3=B8rgens?= [EMAIL PROTECTED] Of course my mail transfer agent is not happy with the first string although I see that Header() is just doing its job. I'm looking for a way though to encode just the non-ASCII parts like any mail client does. Does anyone have a recipe on how to do that? Or is there a method in the email module of the standard library that does what I need? Or should I split by regular expression to extract the email address beforehand? Or a list comprehension to just look for non-ASCII character and Header() them? Sounds dirty. Hints welcome. Regards Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Email headers and non-ASCII characters
On Thursday 23 November 2006 15:12, I wrote: My example code: = def sendmail(sender, recipient, body, subject): message = MIMEText(body) message['Subject'] = Header(subject, 'iso-8859-1') message['From'] = Header(sender, 'iso-8859-1') message['To'] = Header(recipient, 'iso-8859-1') s = smtplib.SMTP() s.connect() s.sendmail(sender, recipient, message.as_string()) s.close() = Just for completeness - of course I imported the Header methods from here: from email.MIMEText import MIMEText from email.Header import Header Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: web-based SSH
On Wednesday 25 October 2006 11:59, Astan Chee wrote: I was looking for a web-based SSH client (something like www.port42.com..but for some reason it doesnt work..can anyone verify this)..does anyone know any other alternative to other websites that offer this? If you're gonna scream 'security!security!' well, its for testing purposes and the box im ssh-ing into is expandable and disposeable Cheers Perhaps Ajaxterm helps. But how is that connected to Python? Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: question: script to input data into a webpage and then retrieve the result?
On Sunday 22 October 2006 08:06, mxywp wrote: Could someone help me with this or share an example script with me? Here is what I want to accomplish: (1) input 3 values into 3 boxes on a web page (2) there is an authentication code each time you access this page and I have to write this code into the fourth box on the same page (3) click submit button (4) this web page will turn into a page with a table having a value calculated from my inputs (5) extract this value into a local file (6) repeat the above for 12000 times. I would really appreciate it if someone can tell me how to do it using python script. I am new to python web programming. Dark side way: http://www.idyll.org/~t/www-tools/twill.html Christoph P.S.: One posting is usually sufficient to get a reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE?
On Saturday 14 October 2006 00:40, [EMAIL PROTECTED] wrote: Ahmer wrote: What do you guys use? vim Like: Built-in python interpreter so you can do any editor customizations in Python Good multilanguage support (Python, but also C, C++, Java, HTML, XML, SQL, and dozens of others) FAST Good code navigation via smart tags Does intelligent completion of module members, methods, etc Python syntax checking on the fly (e.g. typing if a=1: and hitting enter flags the error immediately) Class browsing support (whatever I'm editing, there's a class menu to either pop up to the parent(s), down to children, or jump around various methods within the class) Automatically show function/method docstrings/leading comments (and documentation for standard functions), synopsis in the status bar or full text in a popup window if you hit F1 Configurable project support so for large projects it is smart about which parts of the source tree might be relevant to what I'm working on right now Runs in text-mode or GUI, so I can use the same editor making quick edits over ssh that I use in my on-desktop development Hate: Required a lot of customization to get all of the above I have browsed many vim plugins. Still I couldn't find everything you gush about. I would love to have the comfort of vim with the smartness of ipython. Could you give a few pointers to a curious geek with too much spare time on how you did all this? I couldn't even get ctags working satisfyingly. Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Linting python code...
On Tuesday 10 October 2006 14:06, Andrew Markebo wrote: Are there any python-code linter out there PyLint (http://www.logilab.org/projects/pylint) PyChecker (http://pychecker.sf.net) Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie - Stuck
On Sunday 08 October 2006 14:09, [EMAIL PROTECTED] wrote: The perl version of this code works but not the python version. What am I doing wrong? message = abc password = z12 scrambled = message ^ password abc XOR z12? Strings don't have an __xor__ method. I also wondered why this errored as well... int(messege) Is it not meant to convert a string to a number? If you were Python how would you convert abc to a number? :) Yes, I know Perl makes 0 from anything that doesn't look like a number but Python's principle is to never hide errors while Perl makes certain assumptions. So Python prefers to complain. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Looping over a list question
On Tuesday 03 October 2006 19:50, [EMAIL PROTECTED] wrote: I found myself writing: for f in [i for i in datafiles if '.txt' in i]: print 'Processing datafile %s' % f but I was wishing that I could have instead written: for f in in datafiles if '.txt' in f: print 'Processing datafile %s' % f What about: import glob for filename in glob.glob('*.txt'): print Processing file, filename ... Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Global module variables as default parameters
Thanks to all who answered. On Friday 22 September 2006 17:28, Marc 'BlackJack' Rintsch wrote: Christoph Haas wrote: TestModule.py globalvar = 0 def def1(): print globalvar def def2(foo=globalvar): print foo Running the test.py script prints 123 and 0. So accessing the globalvar in def1() works. But if I try to use the global variable as a default parameter in def2() it uses the default 0. What is the difference between these two? Are there contexts of default parameters? Default parameters are evaluated *once* when the ``def`` is executed. So in `def2` the value of `foo` won't be looked up when calling the function as it is already bound to the value 0. Now that you point me to it it's pretty obvious indeed. I always forget that the 'def's are executed at load time, too. Peter/John: in fact I already used a sentinel like you proposed as a workaround. So there is just one sensible way to do it. Again. Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Global module variables as default parameters
Hi, list... I wondered if it's possible to use global (module) variables as default parameters. A simple working example: #!/usr/bin/python globalvar = 123 def test(foo=globalvar): print foo test() Running this script prints 123. That's what I expected. Now I'm trying the same thing in a module context. A non-working example: test.py #!/usr/bin/python import TestModule TestModule.globalvar = 123 TestModule.def1() TestModule.def2() TestModule.py globalvar = 0 def def1(): print globalvar def def2(foo=globalvar): print foo Running the test.py script prints 123 and 0. So accessing the globalvar in def1() works. But if I try to use the global variable as a default parameter in def2() it uses the default 0. What is the difference between these two? Are there contexts of default parameters? Thanks for any enlightenment. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythondocs.info : collaborative Python documentation project
On Sunday 17 September 2006 04:31, Brad Allen wrote: Here is an idea for improving Python official documentation: Provide a tab-based interface for each entry, with the overview/summary at the top-level, with a row of tabs underneath: 1. Official documentation, with commentary posted at the bottom (ala Django documentation) 2. Examples wiki 3. Source code browser with a folding/docstring mode 4. Bugs/To-Do I like your idea. The MySQL documentation site just came up to my mind. Users can write comments to articles there. And the documentation team can pick them up and include them in the official documentation. What annoys me most about the Python documentation is that it may be technically complete but a human being will never figure out how to solve the puzzle of 50 class methods without getting a proper example. It's like showing some non computer scientists a syntax diagram to get them started with something. For today I plan to check out the SVN repository containing the official Python documentation and see how well I can contribute. But since many people are probably good Python programmers but less good in maintaining complex documentation structures (especially in LaTeX) it might help to allow more direct contributions. Ubuntu's Launchpad for example contains a component where anyone can help translate docstrings for Debian/Ubuntu packages. No more knowledge needed. At least it doesn't appeal to me if Python's documentation team says just open up a bug report on sourceforge - we will deal with the rest. Perhaps this is a decent approach considering the quality of contributions. I can't tell. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythondocs.info : collaborative Python documentation project
On Saturday 16 September 2006 19:16, [EMAIL PROTECTED] wrote: I am a bit disapointed with the current Python online documentation. I have read many messages of people complaining about the documentation, it's lack of examples and the use of complicated sentences that you need to read 10 times before understanding what it means. That's why I have started a collaborative project to make a user contributed Python documentation. The wiki is online here: http://www.pythondocs.info This is a fresh new website, so there's not much on it, but I hope to make it grow quickly. Help and contributions are welcome; Please register and start posting your own documentation on it. I like your enthusiasm but it appears that what you plan is similar to the Python Quick Reference at http://rgruet.free.fr/ I second that the Python documentation is lacking. There is no software that is adequately documented anyway. Show me a man page of a Perl module and it takes me minutes to use it. The same in Python often means Google to find some examples on how to use a module. Many parts of the standard library are badly documented IMHO. There is often no way to know how to use a certain module without looking at its source. But why don't you and I rather provide patches to the current documentation rather than writing yet another incomplete resource. IMHO python.org should be completed. And at least you motivated me to look for ways to contribute to python.org. :) Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question about import tools
On Sunday 20 August 2006 21:39, [EMAIL PROTECTED] wrote: i have just downloas python and trying to import tools module C:\Documents and Settings\totopython Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v Type help, copyright, credits or license import tools Traceback (most recent call last): File stdin, line 1, in ? ImportError: No module named tools import os print os module 'os' from 'C:\Python24\lib\os.pyc' import code print code module 'code' from 'C:\Python24\lib\code.py' do i need to download tools.pyc ? There is no such thing as tools in the standard library (http://www.python.org/doc/current/lib/lib.html). Why do you expect something like that? Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI script running not completely in HTML
On Thursday 17 August 2006 21:50, Yong Wang wrote: I have written a python CGI script to run in html web page. When I access to the html page, it only runs part of the script, then abort because the late part of the script is involved in database access, it is slow. I wonder whether there is a way to control html running speed so that it can wait for CGI script to complete execution, then write the results to html page ? You could use output = '' output += 'Something else to print' instead of print 'Something else to print' And finally use print output Or to use that more efficiently use a list of strings and append to that list. That's probably faster than creating another immutable string time and again. And finally you just ' '.join(outputlist) and print that. Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Running queries on large data structure
On Friday 04 August 2006 15:23, Amit Khemka wrote: Though some sugggested maintaining data in some XML structures, I was wondering that if you considered using some native XML database like BDB XML. 1. It allows you to retain hierarchical structure of data. 2. It also has support for precompiled queries. 3. You can open a persistent connection. Also an interesting approach. Unfortunately my XML knowledge is limited to some basic DocBook/XML. And actually I don't understand why XML is such a hype. Parsing and handling of XML files is slow and IMHO ugly. At least when compared to DBMSs. The only drawback of DBMSs is the relational design. Otherwise it's simple and lightning fast. But I have bookmarked an XQuery tutorial already and will see whether I enjoy playing with it. Thanks for the pointer. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Running queries on large data structure
On Wednesday 02 August 2006 22:24, Christoph Haas wrote: I have written an application in Perl some time ago (I was young and needed the money) that parses multiple large text files containing nested data structures and allows the user to run quick queries on the data. [...] I suppose my former posting was too long and concrete. So allow me to try it in a different way. :) The situation is that I have input data that take ~1 minute to parse while the users need to run queries on that within seconds. I can think of two ways: (1) Database (very quick, but the input data is deeply nested and it would be ugly to convert it into some relational shape for the database) (2) cPickle (Read the data every now and then, parse it, write the nested Python data structure into a pickled file. The let the other application that does the queries unpickle the variable and use it time and again.) So the question is: would you rather force the data into a relational database and write object-relational wrappers around it? Or would you pickle it and load it later and work on the data? The latter application is currently a CGI. I'm open to whatever. :) Thanks for any enlightenment. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Running queries on large data structure
On Thursday 03 August 2006 17:40, jay graves wrote: Christoph Haas wrote: The situation is that I have input data that take ~1 minute to parse while the users need to run queries on that within seconds. I can think of two ways: What is the raw data size? The file containing the objects is 2.3 MB. The rules that I parse are 3.8 MB. Both files contain different objects and properties/settings of each objects one per line. Are there any effciencies to be gained in the parsing code? The currently working application is still Perl. I have started to rewrite the parser in Python. However an import of the objects alone takes ~5 seconds. The rules probably take at least as long. I'm already using regular expressions very rarely and try to make it as efficient as possible (without implementing parts in C). (1) Database (very quick, but the input data is deeply nested and it would be ugly to convert it into some relational shape for the database) Depending on your tolerance for this ugliness. You could use a SQLite 'memory' database. _Might_ be faster than the PostgreSQL but you can't tell until you profile it. The current application uses PostgreSQL and parsing all the data and moving them into the database takes ~30 seconds at the moment. Since that's done every 5 minutes in the background nobody has to wait for it. (2) cPickle (Read the data every now and then, parse it, write the nested Python data structure into a pickled file. The let the other application that does the queries unpickle the variable and use it time and again.) How hard would it be to create this nested structure? Not hard. Instead of doing INSERT INTO I would add values to a dictionary or list. That's even simpler. I've found pickling really large data structures doesn't really save a huge amount of time when reloading them from disk but YMMV and you would have to profile it to know for sure. Okay, that takes a bit of pickle's magic away. :) So the question is: would you rather force the data into a relational database and write object-relational wrappers around it? Or would you pickle it and load it later and work on the data? The latter application is currently a CGI. I'm open to whatever. :) Convert your CGI to a persistant python webserver (I use CherryPy but you can pick whatever works for you.) and store the nested data structure globally. Reload/Reparse as necessary. It saves the pickle/unpickle step. Up to now I have just used CGI. But that doesn't stop me from looking at other web frameworks. However the reparsing as necessary makes a quick query take 10-30 seconds. And my users usually query the database just once every now and then and expect to have little delay. That time is not very user-friendly. It makes me feel bad to (ab)use PostgreSQL for just throw-away data. The database would just be needed for the persistance. It's not even needed for querying the data because it shows that SQL is not mighty enough for the kind of queries I need. That's where I thought that some other persistant storage would come handy. Up to now my mind just knew the equation persistence==database. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Running queries on large data structure
On Thursday 03 August 2006 17:45, hiaips wrote: Christoph, Several possibilities come to mind... From your description, maybe something like Postgres, MySql, or sqlite would not be the best option. (However, I'm wondering what your query requirements are Imagine this example firewall rule: | Source | Destination | Service | Action | | 10.0.0.1| 192.168.51.9 | tcp/22 | allow | | group_internal | | tcp/23 | | | 10.2.0.0/16 | | | | | 10.4.0.0-10.4.9.255 | | | | Where e.g. group_internal is a group consisting of several IPs. And '10.4.0.0-10.4.9.255' is a range of IP addresses. SQL doesn't really know such criteria (although a network match is possible with PostgreSQL's inet data type). So I would probably need to read the rule from the database and for each type (IP, network, group, IP range) run some subroutine to determine whether a searched for IP address is part of it. -- for example, if you really need the power of SQL, maybe you should just bite the bullet and map to an RDBMS schema, as painful as that may be. That's how I do it now (in the old Perl program). I don't allow IP ranges and expand the groups (like group_internal) to all the members contained within. Here the optimization lies in the database but it's just doing the easy parts and not supporting the hard parts (e.g. IP ranges). A couple of other possibilities: 1. What about storing your data in XML and using XQuery to facilitate queries? If your data is deeply nested, as you say, this may be a good match. I assume that XQuery can't to weird queries like IP ranges, or can it? 2. What about storing your data in the same syntax as a Python dictionary? Is that possibile? (If it is, then your data *is* your code, and you don't have to worry about parsing it.) Oh, yes, that's perfect. Perhaps a bit slower because I do the query code myself. But I would like that. Just how do I keep the dictionary somewhere on disk so that another process can use it? Thanks for the ideas. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Running queries on large data structure
On Thursday 03 August 2006 19:54, hiaips wrote: Well, if you format the data as a Python dictionary and give the data file a .py extension, it becomes a Python module that you can load and reload dynamically. That's sort of what I was thinking. Ah, okay. You mean like just using expr() on the object and writing that to a file. I had expected pickling to be more efficient in that case. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Running queries on large data structure
Hi, list... I have written an application in Perl some time ago (I was young and needed the money) that parses multiple large text files containing nested data structures and allows the user to run quick queries on the data. (For the firewall admins among you: it's a parser and web-based query tool for CheckPoint firewall rulebases. The user can search for source and destination IPs and get the matching rules.) The current application consists of two parts: (1) An importing process that reads and parses the large text files and writes the data in different PostgreSQL tables. (2) A web (CGI) interface that allows the user to query the collected data from the PostgreSQL database by different criteria. (I don't like PostgreSQL much due to the lack of decent tools like phpmyadmin. Pgadmin3 and Phppgadmin don't give me the feeling that I control the database. More the other way round. But PostgreSQL has a nice 'inet' data type that allows for quick matches in tables of IP addresses and networks.) However the information in the (relational) database was stored in a horribily artificial way. The SQL query is a 20-line monster with UNIONs and LEFT JOINs and negations. It's lightning fast (0.5 seconds to search over a 500 set consisting of complex rules) but neither the source code nor the database is easy to handle any more. And I'd like to have more flexibility in the kind of queries I run. So I'd like to trade the good speed by some readability and a simpler - more object-oriented - data structure. I'm currently thinking of different ways to handle that but would like to get some opinions about that: (a) See what sqlalchemy can do for me to handle the object-relational transformation and basically stay with PostgreSQL. (b) Parse the input files into one large nested Python data structure. Then write this structure to a file using marshal or repr. Then I have a very clean source code like for rule in rules: for src in sources: if searched_for_src == src... (c) ...? What makes PostgreSQL less suited is the fact that CheckPoint rule bases can contain several complex objects: - Hosts (easy, they are just one IP address and can easily be compared) - Networks (nearly as easy - just see if the IP is part of the network) - Groups (slightly harder; can even be nested and contain other groups and hosts or networks) - IP ranges (10.0.0.50-10.5.25.100; not easy to parse either) I would even like to allow the users more complex queries like multiple search conditions. The query would be something like show me all matching firewall rules where 10.0.0.5 matches the source column and 192.168.42.1 matches the destination column OR any rule where the group 'internal hosts' is mentioned in the destination column. It sounds like a database is the right job. But somehow a database is also not flexible enough. And the data is small enough (1 MB probably) that it can be read into memory. What do you think would be the right tool for the job? Thanks for sharing your thoughts. Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to log into web site
On Tuesday 18 July 2006 17:46, david brochu jr wrote: I have been browsing around the net looking for a way (hopefully an easily implemented module) to log into a web site using python. The site I wish to log into is an internal site which requires email address and password for authentication. Does anyone have any suggestions or links that might point me in the right direction? Is http://twill.idyll.org/ perhaps something for you? Regards Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb and dictcursor
On Monday 24 July 2006 14:06, borris wrote: doesn anyone know a good reference, tute or examples of MySQLdb's dictCursor I want to pass dictionaries into the sql exec statements. I could only succeed with text as values A german linux magazin has an article about passing a *list* of items at http://www.linux-magazin.de/Artikel/ausgabe/2002/06/python-api/python-api.html For those who don't understand german here comes an example on how to pass lists: cursor.execute(INSERT INTO Adressen (Name, Strasse, PLZ, Ort) VALUES (%s, %s, %s, %s), [ ('Dr. Hans Mustermann', 'Musterstraße 13', 50823, 'Köln'), ('Peter Lustig', 'Im Bauwagen 2', 50827, 'Porz'), ('Edmund Stoiber', 'Spendensumpf 1', 47011, 'Bimbesdorf'), ('Onkel Hotte', 'Im Siff 42', 57072, 'Siegen'), ('Gerhard Schröder', 'Großmaulweg 2', 11901, 'Worthülsen') ] ) However the DictCursor is helpful for *returning* dictionaries of values instead of just tuples. I always use DictCursor because it makes it clearer which rows I want to access in the result. But DictCursor can't pass dictionaries in a cursor.execute AFAIKT. But with dict.iteritems that shouldn't be hard to send dictionary items to the SQL database in a loop either. Regards Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
sys.stdin and two CTRL-Ds
Hi... I encountered a problem that - according to my google search - other people have found, too. Example code: import sys for line in sys.stdin: print line Running this code in Python 2.3 or 2.4 has the problem that I need to send two EOFs (Ctrl-D) to break out of that loop. Use case is a piped Python script that I run as a CustomLog pipe for an Apache web server. I want to run all the log output through that pipe but haven't had much luck. First it takes ages until the script processes the input (even though I ran Python with -u to make it unbuffered) and then the script needs one EOF to do something with the input and a second EOF to break out of the loop. Is this a bug? I'm close to write a Perl script for this case. :( Regards Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Correctly reading stdout/stderr from subprocess
On Thu, Jun 15, 2006 at 10:37:18AM +0200, Maric Michaud wrote: Le Mercredi 14 Juin 2006 19:56, Christoph Haas a écrit : Quite interesting. I dived into /usr/lib/python2.4/subprocess.py and found out that the communicate() method actually works similarly. I might even prefer your version You should'nt IMO, the former 'run2' was quite short compared to this one. Also Popen.communicate is maintained by experienced folks, your function (mine in this case :) ) is not. This is just more job. Indeed. Still it's interesting to see that your solution was similar. because I get the returncode from run.wait() what communicate() does not. What the problem with getting it from an attribute (returncode) ? communicate() does not return it. Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging to a file and closing it again properly (logging module)
On Wed, Jun 14, 2006 at 12:29:22PM +0530, Amit Khemka wrote: On 6/13/06, Christoph Haas [EMAIL PROTECTED] wrote: I have an application that is running in an endless loop processing an incoming queue. Every run is supposed to write a log file about the run and then close it again. While the 'logging' module is generally working well (even though the documentation makes me miss some proper examples how everything works together) I can't seem to close the log file again to open a new one. This is basically what I'm doing: log = logging.getLogger(myapplication) log.addHandler(logging.FileHandler(/tmp/testfile)) log.setLevel(logging.INFO) log.info(foo) Now I'm missing a way to tell this handler to go away. Through 'ipython' I found out there is a log.handlers array that contains all the handlers. Perhaps I could delete all of them but I'm sure there is a more proper way to close files again. Googling found me: . logging._handlers.clear() . logging.root.handlers = [] . for l in logging.Logger.manager.loggerDict.values(): . l.handlers = [] You can close the logger by just removing the handler from the logging object # first creater a logger and file handler fooLogger = logging.getLogger('FOO') fooLogger.setLevel(logging.INFO) fl = logging.FileHandler('foo.txt) fl.setLevel(logging.INFO) fooLogger.addHandler(fl) # remove the handler once you are done fooLogger.removeHandler(fl) Thanks. That works great. I was looking for a way to close the log file using logging.basicConfig but it appears that it's too much magic. logging.getLogger() isn't really much more work but gives better control. Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Correctly reading stdout/stderr from subprocess
On Wed, Jun 14, 2006 at 03:56:16PM +0200, Maric Michaud wrote: I did it just to validate my point and because i don't use threads very often in python, some exercises can't hurt :) Since you are familiar with threads I believe that my excercises are a tad bit more low-level compared to yours. :) def run(command): import subprocess run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Wait for the process to return import thread, threading out, err = [], [] out_ended, err_ended = threading.Event(), threading.Event() def getOutput(output, lines, ended_event) : for i in output.readlines() : lines.append(i.rstrip('\n')) ended_event.set() out_thread = thread.start_new_thread(getOutput, (run.stdout, out, out_ended)) err_thread = thread.start_new_thread(getOutput, (run.stderr, err, err_ended)) out_ended.wait() err_ended.wait() returncode = run.wait() return returncode, out, err Quite interesting. I dived into /usr/lib/python2.4/subprocess.py and found out that the communicate() method actually works similarly. I might even prefer your version because I get the returncode from run.wait() what communicate() does not. Great work. Thanks for your time. Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Correctly reading stdout/stderr from subprocess
Evening, I'm having trouble with running a process through Python 2.4's subprocess module. Example code: def run(command): run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Wait for the process to return returncode = run.wait() stdout = run.stdout.readlines() stderr = run.stderr.readlines() # Strip newlines at the end of each line stdout = [line.rstrip('\n') for line in stdout] stderr = [line.rstrip('\n') for line in stderr] return returncode,stdout,stderr Unfortunately this def fails when it runs programs that do a lot of output. I believe this problem has also been described in Bug #1162428. It says: You must read away the data before wait() on the process. Easier said than done. If I put the readlines() call before the run.wait() then the process hangs, too, waiting for further lines. Then I read about the communicate() call which handles both stdout/stderr reading and also waiting for the process to end. Unfortunately it returned the output char-wise instead of line-wise. I could certainly re-join the lines. But somehow I feel I'm missing something simple. Any ideas? Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Logging to a file and closing it again properly (logging module)
Evening, I have an application that is running in an endless loop processing an incoming queue. Every run is supposed to write a log file about the run and then close it again. While the 'logging' module is generally working well (even though the documentation makes me miss some proper examples how everything works together) I can't seem to close the log file again to open a new one. This is basically what I'm doing: log = logging.getLogger(myapplication) log.addHandler(logging.FileHandler(/tmp/testfile)) log.setLevel(logging.INFO) log.info(foo) Now I'm missing a way to tell this handler to go away. Through 'ipython' I found out there is a log.handlers array that contains all the handlers. Perhaps I could delete all of them but I'm sure there is a more proper way to close files again. Googling found me: . logging._handlers.clear() . logging.root.handlers = [] . for l in logging.Logger.manager.loggerDict.values(): . l.handlers = [] But this looks really really ugly. I don't like to mess with the gears in the 'logging' module. Ideas? Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Save data to a file thru a http connection
On Wed, May 31, 2006 at 11:37:47AM -0700, [EMAIL PROTECTED] wrote: I am new to python. I read an example here about how to fetch data thru a HTTP connection: http://diveintopython.org/http_web_services/review.html, My question is how can i save the data to a file after reading it from a http connection. Usually HTTP is read-only. There are extensions like WebDAV though that may do what you need. Google for python webdav and see how far you get. Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Save data to a file thru a http connection
On Wed, May 31, 2006 at 08:58:53PM +0200, Christoph Haas wrote: On Wed, May 31, 2006 at 11:37:47AM -0700, [EMAIL PROTECTED] wrote: I am new to python. I read an example here about how to fetch data thru a HTTP connection: http://diveintopython.org/http_web_services/review.html, My question is how can i save the data to a file after reading it from a http connection. Usually HTTP is read-only. There are extensions like WebDAV though that may do what you need. Google for python webdav and see how far you get. Misunderstanding on my side. Ignore me. :) Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting of list containing tuples
On Thu, May 18, 2006 at 12:38:55PM -0700, Paul Rubin wrote: Ronny Mandal [EMAIL PROTECTED] writes: And now I want to sort l reverse by the second element in the tuple, i.e the result should ideally be: l = [(6,5),(2,3),(3,2)] sorted(l, key = lambda a: -a[1]) Or in Python 2.4: l.sort(lambda x,y: x[1]-y[1]) (Although that's not technically perfect. Sort expect a function that returns -1, 0 or 1. Here we get positive integers and negative integers. YMMV.) Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting of list containing tuples
On Thu, May 18, 2006 at 09:52:39PM +0200, Christoph Haas wrote: On Thu, May 18, 2006 at 12:38:55PM -0700, Paul Rubin wrote: Ronny Mandal [EMAIL PROTECTED] writes: And now I want to sort l reverse by the second element in the tuple, i.e the result should ideally be: l = [(6,5),(2,3),(3,2)] sorted(l, key = lambda a: -a[1]) Or in Python 2.4: l.sort(lambda x,y: x[1]-y[1]) (Although that's not technically perfect. Sort expect a function that returns -1, 0 or 1. Here we get positive integers and negative integers. YMMV.) Crap... why do I always forget about cmp()? :) This should be it: l.sort(lambda x,y: cmp(x[1],y[1])) Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: installing numpy
On Tue, May 09, 2006 at 09:03:31PM +1000, Gary Wessle wrote: I am trying to install NumPy in my debian/testing linux 2.6.15-1-686. with no numpy for debian/testing, I am left alone, since the experimental version available by debian will result in a dependency nightmares, What about python-numeric? Found through apt-cache search numpy. Kindly Christoph -- Please reply to the list - not to me personally. Personal replies are ignored. -- http://mail.python.org/mailman/listinfo/python-list
Re: installing numpy
On Tue, May 09, 2006 at 09:43:50PM +1000, Gary Wessle wrote: Christoph Haas [EMAIL PROTECTED] writes: On Tue, May 09, 2006 at 09:03:31PM +1000, Gary Wessle wrote: I am trying to install NumPy in my debian/testing linux 2.6.15-1-686. with no numpy for debian/testing, I am left alone, since the experimental version available by debian will result in a dependency nightmares, What about python-numeric? Found through apt-cache search numpy. is no longer maintained, notice my previous post titled Numerical Python Tutorial errors Are you sure? The last update of the Debian package was slightly over a month ago (http://packages.qa.debian.org/p/python-numeric.html). And the description text reads: Description: Numerical (matrix-oriented) Mathematics for Python The Numeric Extensions to Python (NumPy) ... And finally the /usr/share/doc/python-numeric/copyright.Debian reads: It was downloaded from http://numpy.sourceforge.net/; Kindly Christoph P.S.: Your mail client seems break the references. Your reply doesn't show up as a proper followup to my posting. -- Please reply to the list - not to me personally. Personal replies are ignored. -- http://mail.python.org/mailman/listinfo/python-list
Re: installing numpy
(Replying to my own posting... how I hate that...) On Tue, May 09, 2006 at 02:07:15PM +0200, Christoph Haas wrote: On Tue, May 09, 2006 at 09:43:50PM +1000, Gary Wessle wrote: Christoph Haas [EMAIL PROTECTED] writes: On Tue, May 09, 2006 at 09:03:31PM +1000, Gary Wessle wrote: I am trying to install NumPy in my debian/testing linux 2.6.15-1-686. with no numpy for debian/testing, I am left alone, since the experimental version available by debian will result in a dependency nightmares, What about python-numeric? Found through apt-cache search numpy. is no longer maintained, notice my previous post titled Numerical Python Tutorial errors Are you sure? The last update of the Debian package was slightly over a month ago (http://packages.qa.debian.org/p/python-numeric.html). Yes, you are right. python-numeric refers to NumPy but contains the Numeric version of it (24-2). It's pretty misleading. I'll ask the package maintainer about the status of python-numpy in Debian and hopefully come back with news. Kindly Christoph -- Please reply to the list - not to me personally. Personal replies are ignored. -- http://mail.python.org/mailman/listinfo/python-list
Re: multiline strings and proper indentation/alignment
On Tue, May 09, 2006 at 05:38:52PM +, John Salerno wrote: How do you make a single string span multiple lines, but also allow yourself to indent the second (third, etc.) lines so that it lines up where you want it, without causing the newlines and tabs or spaces to be added to the string as well? Example (pretend this is all on one line): self.DTD = '!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN\nhttp://www.w3.org/TR/html4/strict.dtd;\n\n' I want it to read: self.DTD = '''!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN\n http://www.w3.org/TR/html4/strict.dtd;\n\n''' Or anything like that, but I don't want the extra newline or tabs to be a part of the string when it's printed. My favorite way: self.DTD = '''!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN ''' '''http://www.w3.org/TR/html4/strict.dtd;\n\n''' Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: How to recast integer to a string
On Tue, May 09, 2006 at 12:17:34PM -0700, James wrote: How to recast an integer to a string? something like n = 5 str = str + char(n) str(n) Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: How to recast integer to a string
On Tue, May 09, 2006 at 12:34:05PM -0700, James wrote: Christoph Haas wrote: On Tue, May 09, 2006 at 12:17:34PM -0700, James wrote: How to recast an integer to a string? something like n = 5 str = str + char(n) str(n) Kindly Christoph In python2,4, I 've got TypeError: 'str' object is not callable What I meant was: string_from_number = str(n) Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Global utility module/package
Evening, I'm currently working on a larger Python project that consists of multiple programs and packages. As I need a few utility functions time and again I moved them all into a Utility package and created a class there. Like this: Util.py: class Util: def __init__(self, debugFlag=False, vibranceLevel='good'): self.debugFlag = debugFlag self.vibranceLevel = vibranceLevel def function1(self): do this do that main.py: import Util util = Util.Util() util.function1(whatever) def some_function(): global util util.function1(dingdong) However this feels like I'm abusing classes because I don't really need several instances of an object. I just need one instance. Even worse is that I'm starting to use global util to get access to the alibi instance I created. (I'm not sure whether I could even omit it due to scoping rules.) As I know that importing packages from multiple modules always keeps it a singleton I thought of something like this: Util.py: debugFlag = False vibranceLevel = 'good' def function1(): global debugFlag print debugFlag main.py: import Util Util.debugFlag = True Util.function1(whatever) def doThis(): Util.function1(42) Here I don't use classes any longer. Good. But to access the package variables I probably need to use global again which just moved the ugliness to another position. What would be a good practice here? All I want is a utility package that I can import from everywhere (as a singleton) and that I can use even in subroutines (def) without needing to write global here. (The global could probably even be omitted because unless I define a variable in a def scope the global variable should be visible.) Please enlighten me. :) Kindly Christoph P.S.: Code parts untested. More a schema than something that would actually run. -- Please reply to the list - not to me personally. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Perl programmers
On Thu, May 04, 2006 at 12:02:52PM -0400, A.M wrote: Is there any efficient online resource or book that help experienced Perl programmers to Python? I've been using Perl for a decade and had a hard start into Python. Mainly because I used those phrasebooks and tried to convert my Perl syntax statement-by-statement. However Python doesn't just have another syntax but also other concepts. It's worth working yourself through the diveintopython tutorial. Or if you want to spend money I strongly recommend the book Beginning Python: From Novice to Professional (ISBN 159059519X) because you learn a lot about daily problems and gotchas, too. Besides from the I'm cool because I'm the only one who can read my code factor that Perl delivers Python has everything you need. :) Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Active Directory Authentication
On Fri, May 05, 2006 at 05:39:08AM -0700, D wrote: Is it possible to have Python authenticate with Active Directory? Specifically what I'd like to do is have a user enter a username/password, then have Python check the credentials with AD - if what they entered is valid, for example, it returns a 1, otherwise a 0.. Thanks! Can't you query the AD through LDAP? Then http://python-ldap.sourceforge.net/ might help. Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python?
On Fri, May 05, 2006 at 04:50:11PM +0100, Doug Bromley wrote: I have a Python IDE review I did a few months back you may want to view: http://www.straw-dogs.co.uk/blog/python-ide-review Sounds interesting. Could you fix the screenshots? I just get a 404 here. Kindly Christoph P.S.: [Rant about TOFU posting suppressed.] -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing files on server through CGI
On Sun, Apr 09, 2006 at 12:35:21AM -0700, [EMAIL PROTECTED] wrote: I have a CGI script on server which process a form and writes its content on a file like fp = open(fname, 'w') fp.write('HTMLHEADTITLECool list/TITLE/HEADBODYH2CENTER%s/CENTER/H2BRH3center%s/center/h3/body/html Its working fine, but will it work if the script recieves thousands of request simultaneously. I assume that's a question. No, it won't. If you open a file for writing no other program can write to it. Can this script writes files simultaneusly or will all the request queued and processed one by one. Sorry, no. What is your intent? Usually you either have CGIs that output HTML directly or scripts that update an HTML file. But CGIs that write to a HTML file... that looks pretty uncommon. Don't worry about updating a static HTML file though. If you are using a decent web server like Apache it will have the file cached and try to read it once you are done changing it. But don't use CGIs for that. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: a somewhat off-topic question about linux
On Sat, Mar 25, 2006 at 03:09:53PM -0500, John Salerno wrote: I'm interested in trying out Linux, probably Ubuntu, but I was wondering which distribution you guys like to use (because it's a pain trying to decide!) and you guys are smart. We had this discussion a couple of time during the last months already. :) I believe the most frequently recommended distribution was Ubuntu (or Debian which Ubuntu is based upon). And to keep it Python related, I'll also ask, is there anything special I need to know about using Python on Linux? Do any things change, or can it be used just as I use it on Windows? Some issues are platform-dependant. You will not be able to read the registry or start a Microdoze-based program of course. Otherwise most parts of Python are working the same way unless the documentation tells otherwise in certain details. Christoph (Hoping to prevent a huge thread discussing pros/cons of distributions) -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: nested for loops
On Tue, Mar 21, 2006 at 09:54:21PM +, John Salerno wrote: Can someone tell me why 'n' in this example isn't 2? for n in range(2, 10): for x in range(2, n): print 'x =', x, 'n =', n x = 2 n = 3 Assume n=2. Then the first inner loop will run in a range(2,2) which is an empty list. So nothing will happen. Next outer loop: n=3... Actually n becomes 2. But you don't do anything with it. :) Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: No more then 1 Instance of Application..
On Monday 13 March 2006 18:31, Math wrote: Does anybody know what I have to do to run only 1 instance of my Python Application? How do I check if I'm running more instances of a Application? I would use lockfiles for that purpose. Like this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/193488 I'm surprised that this is not in the standard library. If you are not familiar with lockfiles: http://en.wikipedia.org/wiki/File_locking Kindly Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Class attributes newbie question (before I join a cargocult)
Am Sonntag, 12. März 2006 19:36 schrieb EP: This is likely a stupid question, but I am confused about what is going on with class attributes as far as whether they stick. I ran across this in a program I am writing, but have reproduced the behavoir below - can someone point me in the right direction (thanks): class AttStickiness(object): def __init__(self, myname=, mysex=): self.name=myname self.sex=mysex ^--- sex def changeSex(self, newsex=): self.mysex=newsex ^--- mysex You are not altering the same attribute. Cheers Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: inserting into a list
On Tuesday 07 March 2006 16:18, John Salerno wrote: Let me apologize in advance for what I'm sure is an achingly simple question, but I just can't find the answer in either of my Python books. I've tried a few tests with the interactive prompt, but they don't work either. All I'm trying to do is insert an item into a list, like so: L = [1, 2, 4] and I want to insert the integer 3 into the position L[2], so that the list reads [1, 2, 3, 4] Either L[2:2]=[3] or L.insert(2,3) Kindly Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie question
On Sunday 26 February 2006 22:44, [EMAIL PROTECTED] wrote: I am new to python, can you please tell me how can I convert my python script into an executable on linux? i.e. instead of typing 'python myscript.py abc', I just need to do 'myscript.py abc'? Use the shebang syntax. Use this as a first line in your script: #!/usr/bin/python Some people rather prefer an env approach. Remember to make your script executable (chmod +x scriptname). and how can I get the input argument from my script , in my example, how can I read 'abc'? import sys print sys.argv[1] Kindly Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Open Relay Test
On Friday 17 February 2006 05:31, D wrote: Hi all .. how could one test to see if an open relay exists on a specific email server? My simple favorite... run: telnet relay-test.mail-abuse.org from the mail server in question (and be patient). Kindly Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: preserving POST data
On Thursday 16 February 2006 22:35, Steve Young wrote: Lets say that I'm filling out a form and the information gets sent to another server first for some processing(before the one that it should go to). But from there, I want that intermediate server to be able to preserve this POST data using python so it can still retrieve the page that was originally requested (with some modifications from the intermediate server). Is there a way to do this with python? That's less a python-specific question. The general solution is to store the information on your server and remember who the user was. Many web programmers use a cookie based authentication/identification with a database backend. Which means: - User comes to your website - You send the user a cookie - You create an entry in your database with that cookie - User enters data - You add the data to the database (referring to the cookie) - User comes back later - You can look up the data in your database according to the user's cookie I use that scheme in a more complex way for cookie based authentication (http://workaround.org/pysessions). Kindly Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: simple perl program in python gives errors
On Monday 30 January 2006 17:52, [EMAIL PROTECTED] wrote: I am a little annoyed at why such a simple program in Perl is causing so much difficulty for python, i.e: $a += 20 * 14; print $a; a = 0 a += 20 * 14 print a Seems to be more a problem for you than for Python. Christoph P.S.: Xah, is that you? P.P.S.: You should have told what's going wrong. P.P.P.S.: Variables are not automatically initialised in Python. And you shouldn't even rely on that in Perl. -- Never trust a system administrator who wears a tie and suit. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic website content
On Saturday 21 January 2006 20:42, sophie_newbie wrote: To give you a better explaination of what I want, you could visit www.pat2pdf.org. Type in 123456 as the patent number, you see what it does? It tells the user that it is requesting the various TIFF images and then displays the link to the PDF file that it has created. Ah, so you are trying to get the page displayed while your CGI is still running? Try flushing stdout after you print something. Otherwise the output will only be sent when the CGI ends or the buffer is full. Kindly Christoph -- Never trust a system administrator who wears a tie and suit. -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling out forms with python
On Friday 30 December 2005 06:30, Steve Young wrote: Hi, I was wondering if there's a way to fill out forms online using python. Say for example if you wanted to make a search on some search engine without having to actually open a browser or something like that. Try twill: http://www.idyll.org/~t/www-tools/twill/ Christoph -- Never trust a system administrator who wears a tie and suit. -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite flavor of Linux? (for python or anything else)
On Sunday 04 December 2005 15:01, Ivan Shevanski wrote: Looking to replace my older flavor of linux with something new. . .What are some of your favorites for python programming and anything else? The operating system/distribution is not connected to the application (Python). It will probably run everywhere. But we recently had this topic and a majority seemed to vote for Ubuntu. I personally prefer Debian. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite flavor of Linux? (for python or anything else)
On Sunday 04 December 2005 19:56, Aahz wrote: Christoph Haas [EMAIL PROTECTED] wrote: The operating system/distribution is not connected to the application (Python). It will probably run everywhere. But we recently had this topic and a majority seemed to vote for Ubuntu. I personally prefer Debian. Ubuntu *is* Debian, just repackaged. I know. :) (Would be bad if I wouldn't.) I used to prefer Debian until stable wouldn't work with my newest machine because it was two years out of date (this was *not* a machine with bleeding-edge components). The delay until Sarge was very long. But the release schedule has been tightened. Etch will be released next year. So if you prefer having a stable environment and can live with a (at max) two year old distribution then it should be okay. (Besides: the hardware support is done by the Linux kernel - not the GNU distribution. So that's likely not Debian's fault.) Of course, one can use Debian-testing, but that isn't packaged, and I want a packaged OS. You probably mean that Testing (the upcoming Etch stable release) is not yet available as a stable release. But actually that doesn't make much difference. From my personal experience most of the time 'testing' is hardly less stable than any Ubuntu stable release. Ubuntu is just easier to install and maintain because it has less bells and whistles and provides a ready environment without needing much knowledge. However the same packages that are currently in 'testing' will be 'stable' later. You are just dealing with brand-new packages that may be buggier. And you don't get reliable security support yet. (I even run 'unstable' on my desktop. Not just because I need it for development but also because it's mostly stable enough to work with. I wouldn't run critical public services on it though. Python development has never been a problem here.) Regards Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonising the vim (e.g. syntax popups) - vimpst
Hi, Roman et al... On Thursday 10 November 2005 00:52, Roman Roelofsen wrote: The last 5 days I´ve been working on a code-completion/calltips plugin for vim. It´s working pretty good but not finished yet. I will anounce the first beta version on this mailling list. I hope during the next week. I recorded a swf-video so that you can take a look at the current status. Link: http://www.tuxed.de/vimpst/video.tar.gz That is very impressive. I saw a similar plugin which had a big drawback: it didn't know the object type you need context help for. E.g. it offers you help for the .split method even though you are dealing with an object which does not have this method assigned. The great advantage of the IDLE is that it really understands Python. So it knows about object types you work with. I'm curious how you handle that. Perhaps the python features in Vim have that built-in. But Vim scripting looked even evil for me... and I've been working with Perl for a decade. :) Thanks for your contribution. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Pythonising the vim (e.g. syntax popups)
Evening, I'm an addicted vim user and don't really use the IDLE for anything more than calculations where I'm too lazy to start KCalc. But one feature is very pretty: the built-in help for function calls while you type. Like you enter... var1,var2=mystring.split( ...and the IDLE shows me a popup saying... S.split([sep [,maxsplit]]) - list of strings Is there a decent way to get that help into vim? Or like showing docstrings or help that I get through pydoc on request? I've been working myself through a pile of vim macros/plugins but couldn't find even one which simplifies programming in Python. Further issues would be handling the indentation - maybe a plugin which syntax colors different levels of indentation so I don't have to use my plastic ruler on the screen. ;) Perhaps some more experienced Python/Vim users have a tip which macro sets help most here. Thanks, Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expressions and Dividing Strings
On Tuesday 08 November 2005 23:59, James Colannino wrote: Hey everyone, I have a file containing the following type of data (only an example): root:root What I want to do is take this line and divide it into two separate strings (the ':' character would divide the two strings, so the result of the example above would be root and root.) The names will vary in length (this refers to username/group ownerships.) I'm probably missing something extremely basic. I found the module re to do the regular expression matching I need, but I'm not quite sure how I can actually split this line up into two separate variables. You probably mean: a=root:root b,c = a.split(:) b and c contain both sides of the colon. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: So, Which Version is Suitable for Beginners
On Sunday 06 November 2005 13:29, [EMAIL PROTECTED] wrote: I m actually a Novice in Python as well as Linux, When i look up things on the internet about Linux Flavours, They are written so complex that it is difficult for me to understand, i am asking if anyone here know of a Linux Distribution that is for beginners (I am a new user of linux, therefore, i dont know what linux will do.) also the flavour must have python so i can work on it too. I will use Vmware Workstation, because Linux and Windows on a Dual-boot Dont work well, Linux works fine, but Windows Shows Problems, So, i will summarize it as: A) Linux Distribution which is intended for beginners, and contains Python Ubuntu (see below). B) I need it to work on VMware Workstation 5 Most do. C) Do not Recommend Fedora ,Debian (the Original). Debian is clean and powerful but perhaps not suited well for complete novices. So I would recommend a Debian-based distribution like Ubuntu to you. It will not bother you with all the gears and give you a working desktop environment which - of course - includes Python. If you like KDE over Gnome (I do) you can use Kubuntu. If you haven't heard of Gnome or KDE yet... just try Ubuntu. Christoph -- |\ _,,,---,,_Famous last words of a sysadmin: /,`.-'`'-. ;-;;,_We'll do the backup tomorrow. |,4- ) )-,_..;\ ( `'-' '---''(_/--' `-'\_) -- http://mail.python.org/mailman/listinfo/python-list
Re: simple send only command line jabber client in python?
On Tuesday 25 October 2005 23:32, fuzzylollipop wrote: I want to be able to send jabber messages from an subversion post-commit hook script. All I need is a simple library to connect to a server and send a message. I looked at all the half-finished and overly complex projects and can't find anything that fits the bill. What I did find I can't get to work correctly, probably because everything is 2 years old and out of date. Try http://xmpppy.sourceforge.net/ Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: testing '192.168.1.4' is in '192.168.1.0/24' ?
On Monday 24 October 2005 10:21, [EMAIL PROTECTED] wrote: thanks, that is basically what I am doing and since it is a recipe, I would assume there is no standard library module for it. Well, http://py.vaults.ca/~x/parnassus/apyllo.py/126307487 lists a few. I had used IPy in the past. But somehow nothing so far was a decent substitute for Perl's Net::IP. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: New User
On Sunday 23 October 2005 03:46, thatchmatic wrote: I just downloaded and I think installed python. I am not sure if I did cause it does'nt respond to the commands that the read me file told me to use. Also can someone suggest a trial program I can maybe write for fun? Try http://diveintopython.org/installing_python/shell.html Otherwise please provide more information so we can help. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: difference after remove
On Monday 24 October 2005 15:02, Shi Mu wrote: Is there any difference if I remove the '/' from the following statement? You probably mean '\' instead of '/'. intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\ [1,2,5,3,9,1,1,1,9,1],\ [0,0,5,1,1,1,9,7,7,7]] print intMatrix2 I removed one '\' and it still works. So what is the use of '\'? It's a line continuation character. But you can omit it if it's clear to the interpreter that the line must continue - like when using brackets. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: get a copy of a string leaving original intact
On Thursday 20 October 2005 22:43, Bell, Kevin wrote: I need to copy a file, say abc-1.tif to another directory, but if it's in there already, I need to transfer it named abc-2.tif but I'm going about it all wrong. What a coincidence... I stepped about this today: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442460 Looks close to what you are trying. Kind Regards Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a Python mentor
On Friday 14 October 2005 21:35, billie wrote: Nir Aides wrote Hello Len, You should try the #python IRC room. It is always very active and helpful. Nir Do you mean efnet #Python chan? It's not too much active... I believe he meant irc.freenode.net :) Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle cgi sessions
On Friday 14 October 2005 21:22, Derek Perriero wrote: What would be the best way to create a cgi session that contains the basic elements of a cookie and can also hold secure data, such as a username/password. I've explored the possibilities of using SmartCookie, but that doesn't encrypt my parameters. Encrypting the parameters is probably not the best way. Usually you store the information you need in your own database and just pass the client (web browser/user) a handle (session ID). That way you temporarily identify the user through the session ID but can store data in your database that the user cannot even see. There are a few things you need to take care of like: - only pass a new session cookie if necessary (otherwise the user may be prompted to accept the same cookie time and again) - expire the session if the user hasn't been using it - check if the session ID fits the IP address you recorded - create unique session IDs A link from my list of bookmarks about session handling: http://starship.python.net/~davem/cgifaq/faqw.cgi?req=showfile=faq02.011.htp We have recently developed such a session handler for a Debian-related web site which uses a MySQL table to store session information. If there is interest I'll tidy it up a bit and make it publicly available. Cheers Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle cgi sessions
On Friday 14 October 2005 21:22, Derek Perriero wrote: What would be the best way to create a cgi session that contains the basic elements of a cookie and can also hold secure data, such as a username/password. [...] Said. Done. I just tidied up a module we will be using for a web site here. It uses the promised session-cookie handling (with a lot of security checks) and a MySQL database backend. I tried to document as well as possible so I hope it will even help you if you use it or not. To try it out just grab the two files from http://workaround.org/pysessions/ and copy them into a cgi-bin/ directory. Create a database and the two tables following the scheme described on top of the MySessions.py module. Then access the /cgi-bin/mypage CGI. Hope to have helped. Everyone: This is my first bigger Python script. I would really like to hear comments on it. If it's deemed to be decent I could use some help making it a package that can be used by others as well. There is probably a bit of perlishness that I'd like to get rid of to make it look more snake-like. Regards Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Printing and prompting adds a mysterious extra space
Evening... I'm writing a simple interactive program to maintain a database. The goal was to print at the beginning of the line, wait for user input and then deal with it. Minimal test program: import sys; print , ; print sys.stdin.readline() However when I run the program and enter foobar it looks like this: ./test.py foobar foobar ^--- where does this space come from? I wonder where the space comes from in the line where I print what the user typed. Does it have to do with the , after the print which I use to suppress the newline? Any ideas? Regards Christoph -- I'm still confused - just on a higher level now. ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing and prompting adds a mysterious extra space
On Sat, Oct 01, 2005 at 01:17:41PM -0700, [EMAIL PROTECTED] wrote: Christoph Haas wrote: I'm writing a simple interactive program to maintain a database. The goal was to print at the beginning of the line, wait for user input and then deal with it. Minimal test program: import sys; print , ; print sys.stdin.readline() However when I run the program and enter foobar it looks like this: ./test.py foobar foobar ^--- where does this space come from? Another question you could ask is: why is there NO space after the ''? Have a look at this. [...] So it looks like the space was sitting in the output buffer. Yes, probably. But how do I get that buffer flushed? I tried sys.stdout.flush() after the print statement but it wasn't printed, either. I probabl need something like... print + instead of print , How could I solve that decently? Christoph -- I'm still confused - just on a higher level now. ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing and prompting adds a mysterious extra space
On Sat, Oct 01, 2005 at 05:09:48PM -0500, [EMAIL PROTECTED] wrote: Use sys.stdout.write instead of print. It will solve these problems you are having. If you really want to know what's going on, read the language manual, http://docs.python.org/ref/print.html It explains the behavior of this extra space, which is output by a successive 'print' statement. The implementation uses an attribute called 'softspace', which is described in http://docs.python.org/lib/bltin-file-objects.html Thank you for the technical explanation. print a,b is nice to read in simple Python programs. But when you need to get more control of I/O it's better to know what's really happening inside. So the softspace is always added after a print a, statement but only printed if Python thinks it is not at the beginning of a terminal line. Interesting. Again, thanks. I'll rest my case. Christoph -- I'm still confused - just on a higher level now. ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Best practices for dynamically loading plugins at startup
On Sun, Sep 25, 2005 at 11:33:03PM -0400, Jeff Schwab wrote: I recently came up against this exact problem. My preference is to have the plugin writer call a method to register the plugins, as this allows him the most control. Something along these lines: class A_plugin(Plugin): ... class Another_plugin(Plugin): ... register( A_plugin ) register( Another_plugin, optional_custom_registration_parameters ) I like the idea. And supybot seems to do just that. What would the def register: do? Maintain a global list of registered plugins? I didn't like the idea of having global variables. Or would register be a method of some main class? How would I access that? Thanks to everybody else who posted ideas on my problem. I'm trying all the proposals to get an idea of which approach works best. Regards Christoph -- ~ ~ ~ .signature [Modified] 3 lines --100%--3,41 All -- http://mail.python.org/mailman/listinfo/python-list
Best practices for dynamically loading plugins at startup
Dear coders... I'm working on an application that is supposed to support plugins. The idea is to use the plugins as packages like this: Plugins/ __init__.py Plugin1.py Plugin2.py Plugin3.py When the application starts up I want to have these modules loaded dynamically. Users can put their own plugin modules into the Plugins/ directory and the application should know about it. Since I don't know which plugins have been put into that directory I cannot just import Plugin1, Plugin2, Plugin3 in the __init__.py. So I need to find out the *.py there and load them during startup. I could do that with a walk over that directory. Each plugin is supposed to be a class derived from a general Plugin superclass. I just don't know how to 'register' every plugin. The main application needs to know which plugin classes there are. On IRC I was recommended walking through all objects and finding out if the class is a subclass of Plugin. Another person recommended using metaclasses to automatically register the plugin in a global list. Since I have only little real-life Python knowledge I wonder what the best practice for this kind of problem is. I looked at the supybot IRC bot to get an idea how plugins are handled there. Unfortunately it was still a bit over my (python) head. Regards Christoph -- ~ ~ ~ .signature [Modified] 3 lines --100%--3,41 All -- http://mail.python.org/mailman/listinfo/python-list
Re: services on linux
On Tue, Sep 20, 2005 at 02:57:26AM -0500, pt python wrote: im moving from the windows world to the linux world and i need to make a python script to see if a service is instaled (ex: apache), if it is running or stoped and to start/stop a service like apache or mysql. Theres an API on windows to manage services and i need to know how to do that on linux. Can anyone help me with the module and API to work with services on linux? Unless you really want to do that in Python. It's just a matter of ps and grep. Simple shell stuff. Example: ps ax | grep apache by the way, im developing a app, maybe multi-plataform, to install and manage several open source packages like apache, mySQL, phpwebadmin, phpnuke, etc... if anyone have nice ideais i apreciate that.. That's usually the Linux distribution's job to handle the installed packages. Some distributions do that better than others (coughDebiancough). ;) Or what did you mean when you said install and manage? Regards Christoph -- ~ ~ ~ .signature [Modified] 3 lines --100%--3,41 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a database. Sugestions?
On Thu, Sep 15, 2005 at 11:00:46PM +0200, ionel wrote: I'm looking for a thread-safe database. Preferably an embedded, sql database. What are the best choices in terms of speed ? Sqlite may be a good choice. It doesn't have network overhead, operates on simple files on the disk (nothing to configure) and is often faster than MySQL Co. Regards Christoph -- ~ ~ ~ .signature [Modified] 3 lines --100%--3,41 All -- http://mail.python.org/mailman/listinfo/python-list