RELEASED Python 2.5 (beta 3)
On behalf of the Python development team and the Python community, I'm happy to announce the third BETA release of Python 2.5. This is an *beta* release of Python 2.5. As such, it is not suitable for a production environment. It is being released to solicit feedback and hopefully discover bugs, as well as allowing you to determine how changes in 2.5 might impact you. If you find things broken or incorrect, please log a bug on Sourceforge. In particular, note that changes to improve Python's support of 64 bit systems might require authors of C extensions to change their code. More information (as well as source distributions and Windows and Universal Mac OSX installers) are available from the 2.5 website: http://www.python.org/2.5/ There's been over 50 fixes since the second beta. This large number of changes meant we felt more comfortable cutting a third beta release, rather than charging ahead to the release candidate. As of this release, Python 2.5 is now in *feature freeze*. Unless absolutely necessary, no functionality changes will be made between now and the final release of Python 2.5. The plan is that this will be the final beta release (no, really, this time for sure (probably)). We should now move to one or more release candidates, leading to a 2.5 final release early August. PEP 356 includes the schedule and will be updated as the schedule evolves. At this point, any testing you can do would be greatly, greatly appreciated. The new features in Python 2.5 are described in Andrew Kuchling's What's New In Python 2.5. It's available from the 2.5 web page. Amongst the language features added include conditional expressions, the with statement, the merge of try/except and try/finally into try/except/finally, enhancements to generators to produce a coroutine kind of functionality, and a brand new AST-based compiler implementation. New modules added include hashlib, ElementTree, sqlite3, wsgiref and ctypes. In addition, a new profiling module cProfile was added. Enjoy this new release, Anthony Anthony Baxter [EMAIL PROTECTED] Python Release Manager (on behalf of the entire python-dev team) pgpf3nEJ6XxU3.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: exception handling; python program that interacts with postgresql db
damacy [EMAIL PROTECTED] wrote: hi, there. i have this question which might sound quite stupid to some people, but here we go anyway. i have written a python program which interacts with a postgresql database. what it does is simply drops an existing database called 'mytempdb'. the code looks like below; link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) link.communicate(password) link.wait() where command looks like psql -h 127.0.0.1 -U postgres -W -f filename and filename is the name of the file which contains a single SQL command which is drop database mytempdb. hiaips is right. The right way to do this is to use a Postgres module. psycopg is my favorite, but there are several alternatives. import psycopg db = psycopg.connect( dbname=template1 user=postgres password=%s % password ) c = db.cursor() c.execute( drop database mytempdb; ) -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the best way to print the usage string ?
Leonel Gayard [EMAIL PROTECTED] writes: import sys args = sys.argv[1:] if args == []: print Concat: concatenates the arguments with a colon (:) between them Usage: concat arg1 [arg2...] Example: concat a b c prints \a.jar:b.jar:c/\ sys.exit(1) print reduce(lambda x, y: x + ':' + y, sys.argv[1:]) Notice that the string messes the indentation in my script. The indentation is correct, and if the script is invoked without arguments, the usage string is printed correctly. Many people have pointed you to the 'textwrap' standard library module, which is the right general solution to be able to wrap and dedent text. For this particular use case, you may also want to investigate the standard library 'optparse' module, which provides a way of defining options as objects that contain everything the parser needs to know, including a help message for each option which it then uses to automatically construct a program usage message. URL:http://docs.python.org/lib/module-optparse -- \ I cannot conceive that anybody will require multiplications at | `\the rate of 40,000 or even 4,000 per hour ... -- F. H. Wales | _o__) (1936) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
Christopher Weimann wrote: On 08/02/2006-08:06AM, [EMAIL PROTECTED] wrote: From a WinXP command prompt: C:\ C:\cd /windows/system32 C:\WINDOWS\system32 This doesn't work the way you think it does. C:\cd /windows C:\WINDOWScd /system32 C:\WINDOWS\system32 C:\WINDOWS\system32cd /windows The system cannot find the path specified. It IGNORES a leading / char. Ah, yes, I see. As Gerhard Fiedler pointed out, they use '/' elsewhere on command lines to introduce options, so it could be ambiguous as the first character of a path name. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: OS independent files
Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Thu, 03 Aug 2006 21:55:21 +0200, Jarek Zgoda [EMAIL PROTECTED] declaimed the following in comp.lang.python: crystalattice napisa?(a): If I want to make sure the file/directory is made in a user's home directory (e.g. /home/users/path/to/file) but also compatible w/ Windows, how would I rewrite this (if required)? On Windows, there's no notion of user's home directory, there is a directory for user's profile that is treated as $HOME but isn't (%USERPROFILE%), something that looks like $HOME, bot in fact is not (%HOMEDRIVE% + %HOMEPATH%) and many other mess. Microsoft suggests using %USERPROFILE%, but they do not specify desired behaviour, when %USERPROFILE% == c:\. There is also the registry entry HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal which, on my machine, contains the value E:\UserData\Dennis Lee Bieber\My Documents According to this: http://blogs.msdn.com/oldnewthing/archive/2003/11/03/55532.aspx the Shell Folders key shouldn't be relied upon. You can retrieve user directories using SHGetFolderPath or SHGetSpecialFolderPath, both of which are wrapped by win32com.shell. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: [Linux] What toolkit for a good grid/spreadsheet widget?
Hi, Thx for the two pointers. Are those widgets more than just tables, ie. can I edit the contents, including displaying a combo box, can items be grouped or hierarchized, or are they just basic, read-only tables to display results? I need this kind of widget to build a 2+ column interface to let users type entries into the application as an alternative to MS Access-style complicated entry masks. Wx have got an excellent one. I was succesful to use it with editable cells and to include a choice in a cell. However, it was pretty hard to reach that, ie to extract a working sample from the demo. Once done that, no more problems with it. What I suggest you is to have a look on the demo, in the chapter Core Windows/Controls - Grid - wx.Grid showing Editors and Renderers. Rgds, jm -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
On 2006-08-03 04:53:11, Sybren Stuvel wrote: Pretty much every production cost increase gets in the end paid by the consumer. With some localized changes, you may be lucky and don't buy any products that are affected, but with such a widespread change as this would be, it is more likely that almost everybody is affected close to average. You still don't tell me how I could be affected by a production cost increase at a company I'm buying nothing from. You don't buy your gas as crude from Saudi Arabia oil well, do you? :) Their production cost increases may affect you nevertheless. There are very few products you buy that are only affected by costs generated in one company. Usually that's dozens, if not hundreds of companies in the chain. (That's not to say that all of them are relevant, price-wise, but it's more than one that's relevant, usually.) Take your pick, anything, and try to find out the price building chain. You may be surprised. Besides, you probably don't know whether it's not one of your direct suppliers who's affected. You're sure you don't buy from anybody running a Windows system? I'd bet against that, and I only bet when I know I win :) I'm not talking about something obvious like a 10% increase. An overall (average) 1% increase is easy to dismiss as not relevant -- but it's still 1%, if you add it up. (I'm not claiming it would be 1% though. Just an example number.) With that is also mostly the pressure gone to not increase -- because so many are affected that the few who are not happily increase the prices with the others. Either my English isn't as good as I thought, or that's simply incomprehendable. Possibly the latter... I'll try again :) When there's a change in the cost structure of some companies, they try to pass that on through their prices. That's just natural. If the cost structure of a whole sector changes, that's easy, because all of them will want to increase by the same margin, and the cost structure of the whole sector remains the same. (See gas prices.) If almost all of a sector are affected, this still doesn't change (usually): the ones who are not affected often just go with the crowd and increase nevertheless, figuring they can gain more by increased margins than they would gain by increased market share due to lower prices. (There are all kinds of factors that affect this; not always a lower price gets reflected in a higher market share.) But they (or some of them) could also decide to stay at their lower price to gain market share. But if the production cost for 80% of a sector goes up, it may be that the 20% who don't have that cost increase stay low, but the average price of that sector still will go up. (Not everybody will move to the suppliers now with lower cost.) With that, the average production cost for companies that depend on that sector will go up. So there's an average hike anyway, even if some or all of the ones who don't have to increase actually don't. Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
Bryan Olson wrote: Duncan Booth wrote: [EMAIL PROTECTED] wrote: From a WinXP command prompt: C:\ C:\cd /windows/system32 C:\WINDOWS\system32 Not from my Windows XP command prompt it doesn't. Do you have anything strange installed on your system? Tons of strange stuff, yes, but I just tried it on a couple machines on display at BestBuy, and it worked as I showed it. Maybe a recent change. As other postings to this thread have shown it is simply that Windows is taking the forward slash as introducing an option and then ignoring it entirely if the next letter doesn't match one of the options it knows about. So for example (/D being an option to CD): C:\cd /Documents and settings The system cannot find the path specified. C:\cd /DDocuments and settings C:\Documents and Settings -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Question
Gerhard Fiedler wrote: Rather than downloading and zipping in the same thread, you could run multiple threads like you're doing that only download files, and one zip-it-all-up thread. After downloading a file, the download threads place a message in a queue that indicates the file they have downloaded, and the zip-it-all-up thread takes messages out of that queue, one at a time, and zips the files. I was using this approach earlier. The problem with this approach is too much temporary disk usage. Say I'm downloading 2 GB of data which is a combination of, say 600 files. Now following this approach, I'll have to make sure that I have 4 GB of disk space available on my hard drive. Where as downloading in pieces, adding them to the archive, and then unlinking the downloaded file helps proper utilization of disk resource. Thanks, Ritesh -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Question
Carl Banks wrote: If you have multiple threads trying to access the same ZIP file at the same time, whether or not they use the same ZipFile object, you'll have trouble. You'd have to change download_from_web to protect against simultaneous use. A simple lock should suffice. Create the lock in the main thread, like so: ziplock = threading.Lock() Thanks. This looks to be the correct way to go. I do have access to all the source code as it is under GPL. Then change the zipping part of download_from_web to acquire and release this lock; do zipfile operations only between them. ziplock.acquire() try: do_all_zipfile_stuff_here() finally: ziplock.release() I hope while one thread has acquired the lock, the other threads (which have done the downloading work and are ready to zip) would wait. If you can't change download_from_web, you might have no choice but to download sequentially. OTOH, if each thread uses a different ZIP file (and a different ZipFile object), you wouldn't have to use a lock. It doesn't sound like you're doing that, though. It shouldn't be a problem if one thread is zipping at the same time another is downloading, unless there's some common data between them for some reason. Thanks, Ritesh -- http://mail.python.org/mailman/listinfo/python-list
Re: non-blocking PIPE read on Windows
placid wrote: What i need to do is, create a process using subprocess.Popen, where the subprocess outputs information on one line (but the info continuesly changes and its always on the same line) and read this information without blocking, so i can retrieve other data from the line i read in then put this in a GUI interface. readline() blocks until the newline character is read, but when i use read(X) where X is a number of bytes then it doesnt block(expected functionality) but i dont know how many bytes the line will be and its not constant so i cant use this too. I wrote something for this the other day. The class has a getline() method, which either returns a line or raises an exception instead of blocking. It also raises an exception instead of returning EOF. My use case had me reading from multiple processes at once; since select() doesn't work on files in win32, I had to get a little cheesy. I've appended the function that implements that use case, for reference. The central idea is to use PeekNamedPipe to figure out what's in the pipe. You can then read that data without fear of blocking. I wrote it quickly, therefore the code is a little embarassing, but... hopefully useful all the same. . class NoLineError(Exception): pass . class NoMoreLineError(Exception): pass . class liner(object): . Helper class for multi_readlines. . def __init__(self, f): . self.fd = f.fileno() . self.osf = msvcrt.get_osfhandle(self.fd) . self.buf = '' . . def getline(self): . Returns a line of text, or raises NoLineError, or NoMoreLineError. . try: . data, avail, _ = win32pipe.PeekNamedPipe(self.osf, 0) . except pywintypes.error: . # Pipe closed: give up what we have, then that's it . if self.buf: . ret, self.buf = self.buf, None . return ret . else: . raise NoMoreLineError . if avail: . self.buf += os.read(self.fd, avail) . . idx = self.buf.find('\n') . if idx = 0: . ret, self.buf = self.buf[:idx+1], self.buf[idx+1:] . return ret . else: . raise NoLineError . . . def multi_readlines(fs): . Read lines from |fs|, a list of file objects. . The lines come out in arbitrary order, depending on which files . have output available first. . if type(fs) not in (list, tuple): . raise Exception(argument must be a list.) . objs = [liner(f) for f in fs] . for i,obj in enumerate(objs): obj._index = i . while objs: . for i,obj in enumerate(objs): . try: . yield (obj._index, obj.getline()) . except NoLineError: . pass . except NoMoreLineError: . del objs[i] . break # Because we mutated the array -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there any AOP project in python community?
Le 02-08-2006, steve [EMAIL PROTECTED] nous disait: I mean Aspect-Oriented Programming. If any please give me some of links. Thanks a lot. You may want to look at http://www.logilab.org/projects/aspects -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations Développement logiciel sur mesure: http://www.logilab.fr/services Python et calcul scientifique: http://www.logilab.fr/science -- http://mail.python.org/mailman/listinfo/python-list
Re: [Linux] What toolkit for a good grid/spreadsheet widget?
On Friday 04 August 2006 2:24 am, Vincent Delporte wrote: On Thu, 3 Aug 2006 22:07:04 +0100, Phil Thompson [EMAIL PROTECTED] wrote: PyQt4 has QTableWidget... Thx for the two pointers. Are those widgets more than just tables, ie. can I edit the contents, including displaying a combo box, can items be grouped or hierarchized, or are they just basic, read-only tables to display results? I need this kind of widget to build a 2+ column interface to let users type entries into the application as an alternative to MS Access-style complicated entry masks. Yes you can edit cells. QTableWidget implements it's own data model. QTableView does the same but you supply the model - either a standard one or one you have written. A standard one is QSqlDataModel so creating a table that allows you to maintain the contents of an SQL table is about a dozen lines of Python. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Running queries on large data structure
Christoph Haas [EMAIL PROTECTED] wrote | 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 Not sure if this is of any use - but I have noticed that dict lookups in Python is blindingly fast - but it seems to me to use them would be as much trouble to you as converting the data into a shape for the database in third normal form... Unless of course your parser is already doing something like that... There are also some fancy packages for tree structures around, but I don't know anything useful about them. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: How to force a thread to stop
Carl J. Van Arsdall [EMAIL PROTECTED] wrote: | Alex Martelli wrote: | H J van Rooyen [EMAIL PROTECTED] wrote: | | | Paul Rubin http://[EMAIL PROTECTED] Writes: | | | H J van Rooyen [EMAIL PROTECTED] writes: | | *grin* - Yes of course - if the WDT was enabled - its something that | | I have not seen on PC's yet... | | | | They are available for PC's, as plug-in cards, at least for the ISA | | bus in the old days, and almost certainly for the PCI bus today. | | That is cool, I was not aware of this - added to a long running server it will | help to make the system more stable - a hardware solution to hard to find bugs | in Software - (or even stuff like soft errors in hardware - speak to the | Avionics boys about Neutrons) do you know who sells them and what they are | called? - | | | When you're talking about a bunch of (multiprocessing) machines on a | LAN, you can have a watchdog machine (or more than one, for | redundancy) periodically checking all others for signs of health -- and, | if needed, rebooting the sick machines via ssh (assuming the sickness is | in userland, of course -- to come back from a kernel panic _would_ | require HW support)... so (in this setting) you _could_ do it in SW, and | save the $100+ per box that you'd have to spend at some shop such as | http://www.pcwatchdog.com/ or the like... | | | | Yea, there are other free solutions you might want to check out, I've | been looking at ganglia and nagios. These require constant | communication with a server, however they are customizable in that you | can have the server take action on various events. | | Cheers! | | -c Thanks - will have a look - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an obvious way to do this in python?
Bruno Desthuilliers [EMAIL PROTECTED]wrote: | H J van Rooyen wrote: | Bruno Desthuilliers [EMAIL PROTECTED] wrote: | (snip) | | If my original post was unclear I am sorry - the point I want answered, if | | possible, is how to make the client code effectively updateable on the fly - | | because the answer to this will influence the whole design of the rest of the | | system... | | | |This is something I have been thinking about... IMHO what you want is | |not to update client code on the fly, but to make the client mostly a | |kind of interpreter for what the server sends in. That is, the client | |code itself doesn't contain any application logic, it gets it from the | |server and execute it. This can certainly be done with Pyro. | | | |Now while this may be an interesting project, I'm not really sure it's | |worth the effort when we already have HTTP, HTML and AJAX... | | You may be right and it might not be worth the trouble - but what you mention | above is closer to the sort of thing I have in mind - it is essentially using | python to create a script language, and moving scripts around - but hey - python | is already a script language... | | Yes, but it's not (alas) supported by browsers... | | so if Pyro is for 'moving the scripts around' - Then that is what I must look at | very hard... | | It's not for moving the scripts around, it's for remote objects - kind | of like Java's RMI, but, well, much more pythonic !-). Now the point is | that Python being very powerful when it comes to dynamism and | introspection, it should be possible to have a common client that | basically just knows how to connect to the application server (using | pyro). Once connected, the client asks the server for a set of objects | (forms, menus etc) and the corresponding data. These objects then use | the same mechanism to interact with the server. It's basically similar | to the interaction between a browser and a web app - in that the client | is potentially able to run any application sent by the server -, but | with much more specialized client and app server and another protocol - | and no other language than Python. | This is getting more and more interesting - its not the simple minded mechanism I had in mind, but it will achieve the same thing, and it exists already - and I can imagine it to be a very powerful mechanism, if I understand you correctly - I am going to have to cry time out! to go and do some reading... Thank you. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an obvious way to do this in python?
Dennis Lee Bieber [EMAIL PROTECTED] wrote: | On Thu, 3 Aug 2006 09:17:41 +0200, H J van Rooyen | [EMAIL PROTECTED] declaimed the following in comp.lang.python: | | Can I not use the ssl module for encrypting the connections? - Please also | understand that the system is aimed at small to medium companies, in ouse - | From my perspective the only valid reason to use a database would be for the | ease of reporting - the files are not large - and the speed of a dict lookup in | python is hard to beat for normal transaction processing... | | You might want to read the Kode Vicious column in a recent issue | of Queue (probably last months issue -- it's been in my carry-bag for a | few weeks). | | For an in house effort, encrypting the LAN traffic is probably not | the most meaningful focus. Securing the data /storage/ is more important | -- why secure the LAN traffic if someone can walk off with a backup of | unsecured database. And who'd want to even spend time with a LAN sniffer | on unencrypted traffic if that same backup is available for filching. | This makes sense - message is - lock your server room... | NO! the last thing on my mind - want a dynamic process similar to banking | terminals - see my response to Simon please | | ? ATMs? Or internal clerk consoles? Semantics - sorry - neither - thinking of credit card terminals - in which area I have dabbled in a bit... These things have horrendously complex terminal management systems and elaborate mechanisms to download all manner of parameters to change their behaviour... - most have their internal state controlled by the server, sometimes formally, sometimes just via param download... | Pretty much everything is already in the terminal software -- what | the operator has access to, and sees, is dependent upon the privileges | defined for their account. No dynamic loading of code (for security, | I'd not even permit remote updates -- I'd require a floppy or CD from | inside the secure box to change operating software; as soon as you | permit updates to be pushed from outside you expose the risk of a | cracker pushing a customized code set). | I was not aiming for this paranoid level of security - when I said secure or reliable I was just looking for something that would work and that I could trust not to fall over all the time... On the small boxes, the loading of software mechanism varies from manufacturer to manufacturer - some allow, others disallow the download and activation of new apps - likewise for the update of existing ones - but most banks don't use these mechanisms, even if they are available - they all tend to bring the device in to a trusted facility. I don't know one of them that actually use the mechanism on a per transaction basis, because it would be, amongst other things, too slow - but most of the systems can force the terminal into a reload of at least its set of parameters the next time it logs in - and this mechanism is used by for instance AMEX to vary the messages displayed on their terminals - not quite code update - but the user can't tell the difference. I used the example because this sort of facility is the kind of thing I want to find out if Python could do, in a more dynamic way than what the terminals that can use it, actually use it - little thinking that I was sowing confusion - sorry... If you are familiar with the sort of Terminal Management Systems I am talking about, that control the behaviour of the remote box via parameter download - then what I want find out is how to do that in Python, but with the added proviso that I must also be able to download pieces of the application - where download in this sense is just to a PC in the next office on the local LAN - So far the Pyro package that Bruno has steered me towards sounds the most promising way of doing this - but I still haven't been able to research it ... Thanks for the input and sorry about the confusion. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an obvious way to do this in python?
Dennis Lee Bieber [EMAIL PROTECTED] wrote: | On Thu, 3 Aug 2006 14:05:19 +0200, H J van Rooyen | [EMAIL PROTECTED] declaimed the following in comp.lang.python: | | What I mean by this is that the server does stuff that I think belongs on the | client - | like getting involved in the nitty gritty of what the client should display - | I want the client to be smart enough to do the assembly of the elements of a | transaction | by itself, going back to the server for data only when its needed - remember | | One thing to consider: Where is the separation between the database | and the client. I believe most textbooks these days tend recommend: | | [db-server] - [app-server] - [client] | | (db-server and app-server can be the same hardware; the idea is that | clients do not have direct access to the database system, and hence the | back-end can be changed out without affecting any client... also, | clients don't need to handle database errors, etc.) Agreed - I would also need this application server to do the server end of my terminal management system | | so I see the client interacting with the server quite a lot, eventually to be | able do things like auto completion of things like stock codes and descriptions, | customer details, etc. - but I don't want every keystroke flying over the LAN | and | being handled by the server... | | And where did you see the client obtaining the completion data -- | direct access to some other database tables or did you intend to | download /all/ possible data. no just a framework of more or less static stuff like document types, name and address data, and account names and codes that is not subject to continous change... *grin* I would have to apply *some* skull sweat to the problem... | | Typical web-based applications may have a minimal bit of data | validation running on the client (JavaScript ... things like making sure | /something/ has been entered into required fields, but not verifying | that it makes sense), and only when the user clicks on a submit is | everything sent to the application server, which then generates the | needed SQL from the data fields for submittal to the database server. | | transaction is completed - like in a banking system, I envisage ways for the | client to 'poll' the server to get the state of the last transaction, to make | this possible. | | Bad choice... Upon submittal to the server, there should be a | mandatory good/bad return code... Here I take umbrage - not bad, good choice - let me elucidate - the return code you are talking about is the normal thing, and it is the dead wrong way to operate if that is all you do - what I am talking about is the failure scenario - the way to make any transactionally based system robust is to have a GetTranResult transaction that is routinely used before starting a new transaction, to see if the previous one has completed properly - that way, the client can either - continue with the new transaction, or - resubmit the old one to try to get it to work or fail, or thirdly - advise the user that the previous transaction has failed - it is, when you have thought about the flows and all the possible ways in which they can fail - truly the only way to operate reliably. The above is the simple minded way to use such a facility - You could also argue that the time to use this polling transaction is after submitting the transaction, but if your return code is to be trusted, its not needed - if the flows complete normally, its not needed - it is just needed for built in recovery, and it works like a charm if both the server and the client try to keep state over power failures and other disastrous events like losing comms halfway through - especially for multi flow transactions that must update different things on the server... And it does no harm to ask the server the result of your last transaction when you come up after power failure - you can then set the screens and stuff up to the point where the server knows about them and have the user just curse a bit, instead of a lot... And most importantly, the data is safe (unless the database is corrupted, in which case the likelyhood is high that yer screwed in any case) - and on this note - if you have the reversed transaction too - i.e. a kind of GetPreviousLoggedTransactionResult from the server to the client, you can make recovery less painful, even in the case of database corruption... Bad choice indeed! *snorts* ;-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
Duncan Booth wrote: Bryan Olson wrote: Duncan Booth wrote: [EMAIL PROTECTED] wrote: From a WinXP command prompt: C:\ C:\cd /windows/system32 C:\WINDOWS\system32 Not from my Windows XP command prompt it doesn't. Do you have anything strange installed on your system? Tons of strange stuff, yes, but I just tried it on a couple machines on display at BestBuy, and it worked as I showed it. Maybe a recent change. As other postings to this thread have shown it is simply that Windows is taking the forward slash as introducing an option and then ignoring it entirely if the next letter doesn't match one of the options it knows about. Not quite. The first slash is ambiguous and apparently ignored, but latter slashes are taken as a path separators. Have you determined why it didn't work on your XP box as it did on mine and on the machines at BestBuy? -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
RE: encoding of a file
[Thomas Thomas] | how can I find the encoding to use to open a file.. I have a | file with £ chararcter.. | is there some utility function in python that I can use | | how can I know which encoding to use [This is going to be a longer answer than you really want. The short answer is probably iso-8859-1 but there's no way of being certain without trying it out.] The general answer to how can I know which encoding to use for an arbitrary text file? is that: you can't. The more helpful answer is that there are various heuristics (polite term for good guessing algorithms) which will help you out. I believe that the latest BeautifulSoup has one: http://www.crummy.com/software/BeautifulSoup/ and I'm sure there are others. To be certain, though, you need to be told -- somehow -- what encoding was in use when the file was saved. However, that's not quite what you're asking. You say you have a file with a £ character. But what does that mean? Ultimately, that you have some text in a file, one character of which you expect to display as a pound sign (that's a British pound sign, not the # which Americans bizarrely call a pound sign ;). Someone, somewhere, got this pound sign into a file. Maybe it was from a text editor, maybe through a database. However it happened, the application saved its data to disk using some encoding. If it was a naive tool (non-unicode-aware) then it was probably ASCII with some kind of extension above the 7-bit mark. iso-8859-1 / latin-1 (same thing) often cope with that. If the app was unicode-aware, it'll be a specific unicode encoding. Quite possibly utf-8. To experiment, pick the necessary byte/bytes out of your text stream and compare with a few encodings: dump import sys from unicodedata import name # # This is, for example, your original pound sign # bytes = \x9c # # This is what we're aiming for: what unicode # thinks of as a pound sign # print name (u£) # - POUND SIGN # # Let's try ascii # print name (bytes.decode (ascii)) # # Whoops! # - UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 0: ordinal not in range(128) # # iso-8859-1 / latin-1 # print name (bytes.decode (iso-8859-1)) # # Still not right # - ValueError: no such name # # Cheating, slightly... # print name (bytes.decode (sys.stdin.encoding)) # # Bingo! # - POUND SIGN print sys.stdin.encoding # - cp437 print sys.stdout.encoding # - cp437 /dump So in this case it was cp437 (since I got the bytes from typing £ into the interpreter, something I can do on my keyboard. You might well find it was some other encoding. If this doesn't take you anwhere -- or you don't understand it -- try dumping a bit of your data into an email and posting it. If nothing else, someone will probably be able to tell you what encoding you need! TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Which KDE IDE for Python?
Hi, Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both have drawbacks. KDevelop is a multilanguage IDE, and doesn't really have anything special for Python. There's no Python debugger, no PyDOC integration, it's class browser doesn't display attributes. On the other side there's Eric, which is made just for Python. But.. it doesn't integrate with KDE, doesn't support remote files (fish://, ftp:// etc.). Does anyone know a better IDE for Python, that'll integrate nicely with KDE? -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
Bryan Olson wrote: Not quite. The first slash is ambiguous and apparently ignored, but latter slashes are taken as a path separators. I'm not sure ambiguity enters into it. I think perhaps the bad detection of the option happens because the CD command can ignore spaces in its argument. Since it is ignoring spaces they don't actually require a space after the option strings. Any other Microsoft commands I try all complain about 'invalid switch'. Have you determined why it didn't work on your XP box as it did on mine and on the machines at BestBuy? Simply that I hadn't changed to the root directory first so there was no subdirectory named 'windows'. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
Duncan Booth wrote: Bryan Olson wrote: Not quite. The first slash is ambiguous and apparently ignored, but latter slashes are taken as a path separators. I'm not sure ambiguity enters into it. I think perhaps the bad detection of the option happens because the CD command can ignore spaces in its argument. Since it is ignoring spaces they don't actually require a space after the option strings. You lost me. Spaces are significant in file names, and slashes within the path are used as path separators, as far as I can tell. Try cd'ing several subdirectories deep on XP with forward slashes. It works for me, and it could not if slashes were ignored as you suggested. Any other Microsoft commands I try all complain about 'invalid switch'. The first I noticed were their build tools. Their version of make, called nmake, and their visual studio tools will accept either forward or backward slashes in paths. Have you determined why it didn't work on your XP box as it did on mine and on the machines at BestBuy? Simply that I hadn't changed to the root directory first so there was no subdirectory named 'windows'. Ah, my example showed a particular root: C:\. Does your system work the same if you set the current directly as shown? -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Which KDE IDE for Python?
Bart Ogryczak schrieb: Hi, Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both have drawbacks. KDevelop is a multilanguage IDE, and doesn't really have anything special for Python. There's no Python debugger, no PyDOC integration, it's class browser doesn't display attributes. On the other side there's Eric, which is made just for Python. But.. it doesn't integrate with KDE, doesn't support remote files (fish://, ftp:// etc.). Does anyone know a better IDE for Python, that'll integrate nicely with KDE? I bet you can try and convince Detlev Offenbach (eric developer) to add that - he already has _some_ KDE-specific stuff in there, and I presume supporting IO-Slaves might not be too hard. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: karrigell and multi-threading
You have a specific discussion group for all Karrigell topics: http://groups.google.com/group/karrigell?lnk=li It's active and followed by the author of Karrigell. Shalyd wrote: Hello, Here is my problem :-) : i am actually using karrigell, and i use Karrigell.py server, i have a page running a script (which takes around 5 min to execute), when i launch this script (by the page) then, i cant acces to any other page of the site until the script ends. so i tried the karrigell-ThreadingSocketServer.py and i have the same problem, exept that i can access the pages but they are blank until the script ends. i just want to allow different users to launch the script even if the script isnt multi-threaded. for example, 1 launch the script, then another launches i,t goes take a cofee and then when the first script ends, the second is proceeded. Any idea to solve that? Thanks by advance :-) . -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
On Tue, Aug 01, 2006 at 05:31:01PM +0200, Sybren Stuvel wrote: James Stroud enlightened us with: its better to use: os.path.join('my', 'favorite', 'dir') than \\.join(['my', 'favorite', 'dir']) because the latter will bonk on linux. Ehm... replace that with the latter with bonk on every OS except Microsoft Windows. Windows is the weird one in OS-land, because they are the only one that use the most widely used escape-character (the backslash) as path separator. OS/2 (and eComStation) also uses the backslash as the path separator. -- http://mail.python.org/mailman/listinfo/python-list
Re: regex question
Gabriel Murray gabriel.murray at gmail.com writes: Hello, I'm looking for a regular expression which will match strings as follows: if there are symbols a, b, c and d, then any pattern is valid if it begins with a and ends with d and proceeds in order through the symbols. However, at any point the pattern may reset to an earlier position in the sequence and begin again from there. For example, these would be valid patterns:aabbbaabbcccbbbcccdddaabcabcdabcdBut these would not:aba (goes straight from a to d)aaabccc (does not reach d)Can anyone think of a concise way of writing this regex? The ones I can think of are very long and awkward.Gabriel Your cirteria could be defined more simply as the following: * must start with an 'a' and end with a 'd' * an 'a' must not be followed by 'c' or 'd' * a 'b' must not be followed by 'd' Therefore the regexp can more simply be written as: regexp = re.compile(r'''a ( a(?!c|d) | b(?!d) | c | d )* d''', re.VERBOSE) Test code: tests = [ ('abcd', True), ('aaabccc', False), ('aabbccaabbccabcdddcabababbb', True), ('aabbccaabbccabcabababbbabcd', True), ('aba', False), ('aabbccaabbccacabababbb', False), ('abdd', True), ('abcdcd', True), ('aabbbaabbcccbbbcccddd', True), ('aabbccaabbccabcabababbb', True), ('abdd', True), ('aabcabcd', True) ] def checkit(regexp, tests=tests): for test, expected in tests: matched = regexp.match(test) is not None if matched == expected: print PASSED: %s with %s % (test, expected) else: print FAILED: %s with %s % (test, expected) checkit(regexp, tests) PASSED: abcd with True PASSED: aaabccc with False PASSED: aabbccaabbccabcdddcabababbb with True PASSED: aabbccaabbccabcabababbbabcd with True PASSED: aba with False PASSED: aabbccaabbccacabababbb with False PASSED: abdd with True PASSED: abcdcd with True PASSED: aabbbaabbcccbbbcccddd with True PASSED: aabbccaabbccabcabababbb with True PASSED: abdd with True PASSED: aabcabcd with True - Tal -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
Bryan Olson wrote: Duncan Booth wrote: I'm not sure ambiguity enters into it. I think perhaps the bad detection of the option happens because the CD command can ignore spaces in its argument. Since it is ignoring spaces they don't actually require a space after the option strings. You lost me. Spaces are significant in file names, and slashes within the path are used as path separators, as far as I can tell. Sorry I was unclear. It isn't that spaces are ignored, it is that they do not count as delimiters in the CD command. In all other DOS commands they count as argument delimiters unless they are inside quotes. Any other Microsoft commands I try all complain about 'invalid switch'. The first I noticed were their build tools. Their version of make, called nmake, and their visual studio tools will accept either forward or backward slashes in paths. Ok, pedantically I meant the commands that come as part of the system. Most external tools such as Microsoft's compilers have always accepted forward slashes interchangeably with backslashes. They also usually accept '-' as an option character interchangeably with '/'. The 'standard' commands though seem to go to a lot of effort to reject forward slashes in paths, and the CD command seems to be the only one where this usage gets through the net. -- http://mail.python.org/mailman/listinfo/python-list
Re: help - iter dict
aking at mappi.helsinki.fi writes: CDSitdict = {28.473823598317392: '2.48699832', 40.06163037274758: '0.2912', 27.756248559438422: '2.83499964', 33.2299196586726: '1.12499962', 29.989685187220061: '1.91399677', 31.502319473614037: '1.4909983', 28.487341570327612: '2.4809983', 30.017763818271245: '1.90499681', 32.94343842266: '1.17899943', 30.520103712886584: '1.75199736', 31.453205956498341: '1.50299826', 29.484222697359598: '2.0849968', 28.413513489228706: '2.51399842', 28.314852455260802: '2.5589986', 28.652931545003508: '2.40899803'} heres the error i get after entering Cpcb Traceback (most recent call last): File elementalDS.py, line 156, in ? CDS = findClosest(CDSitdict, Cpcb) File elementalDS.py, line 142, in findClosest distance = (target - v) ** 2 TypeError: unsupported operand type(s) for -: 'float' and 'str' alicat at linux:~/Desktop The Python interpreter is being friendly and explaining exactly what the problem is and where it occured. It's telling you that it can't subtract a string from a float, in line 142 of your code (in the findClosest function). So the problem is that 'target' is a float while 'v' is a string. 'v' should be a float as well, but it's a string since the values in your dictionary are strings instead of numbers. Try removing the quotes around the values in your dict (both the double-quotes and the single-quotes). -- http://mail.python.org/mailman/listinfo/python-list
Re: help - iter dict
Simon Forman wrote: [EMAIL PROTECTED] wrote: Dear Python people, im a newbie to python and here...so hello! Hi Ali, and welcome. Im trying to iterate through values in a dictionary so i can find the closest value and then extract the key for that valuewhat ive done so far: def pcloop(dictionary, exvalue): z = dictionary.itervalues() y = z - exvalue v = (y*y)**1/2 if v 0.001: u = dictionary.get[z] return u ive been working off a couple of books and this is the best i can get it in short time. I was trying to define a function (its my first!) so that i could apply to several 'dictionary's and 'exvalue's. The best ive been able to come up with is iterating over the dictionary values, subtracting the exvalue, squaring then root squaring to render positive and applying an error (0.001) which is not the ideal solution i want. Is there any easy way to iterate through dictionary values and return the key for the minimum. Or can someone tell me where im going wrong with this def loop. regards all Ali You're doing many interesting things wrong here. :-) I'm going to take them slightly out of order. First, very ingenious way to get the absolute value of a number, but there are a few issues with this that you should know about. For instance, just as multiplication and division take precedence over addition and subtraction, the power operator ** take precedence over division, so what you're really doing above is ((y*y)**1)/2 rather than (y*y)**(1/2) However, the above still wouldn't work correctly because of the way python handles integer division. 1/2 == 0 in python, try it at the interactive prompt and you'll see. So, you'd have to change at least one of the division's operands to float to get the proper result you desire. (y*y)**(1./2) Except that you should actually use the (built in) abs() function, v = abs(y) :-) Next, the itervalues() method of dicts does not return a number, but rather a dictionary-valueiterator object, as you can see from this: | d = {} | z = d.itervalues() | z dictionary-valueiterator object at 0xb6f23c00 In order to get values out of it you need to iterate over it like so: for z in d.itervalues(): # Do something with z's here... You could also get both the keys and values at the same time by iterating like so: for k, z in d.iteritems(): # Do something with k's and z's here... (I'll come back to that.) Now, a little further down in your function, you seem to want to use the z value with the get() method of the dict to retrieve the key. This won't work. First, you're not *calling* the get method (that uses ()'s) you're *subscripting* it (that uses []'s.) If your code got this far, it would break here. | In fact, there is no easy way to get the key from a dict given a value. Dicts work the other way around. (You basically have to iterate through the values *and* keys, one pair at a time, testing each value as you go. This is very slow, compared to getting the value given a key.) value = d[key] This is extremely fast. It's pretty much the whole point of a dictionary that this is very fast. So, when you build the dict that you pass in to your function, you might want to build it the other way round, i.e. make the keys the values and the values keys. However, you might not and here's why: Dicts can only have one key of any given value of key. Look: | d = {1: 'a', 1: 'b'} | d {1: 'b'} | d = {'a': 1, 'b': 1} | d {'a': 1, 'b': 1} So, if you're running a mathematical function on a range of input (x's) and storing the results (y's) as values in a dict, then you *do* want the x's to be the keys and the y's to be the values. I'm guessing that's what you're doing, and if so, you're doing it correctly. [this is what i want but am not sure its correct] So, given a dict and an exvalue, how to return the key corresponding to the value that's closest to exvalue? here goes... thanks simon for this, it seems a little easier to understand for me but i still get the error when i run the script: #here is a sample dictionary from the 1000 key:values normally in it. they are all non zero and values to 15 decimal places CDSitdict = {32.030822391220937: '1.36799874', 29.150765445901769: '2.20799727', 27.930109636681877: '2.7449993', 28.590095427450688: '2.43599813', 27.595161357952588: '2.9217', 29.961761413410386: '1.92299674', 36.311798000222424: '0.66348', 34.358611987430052: '0.93372', 41.199188199569292: '0.20413', 29.560651138651014: '2.0579967'} #i have tried to format the numerical key into the dictionary to give a string using %s but it didnt work so eventually i used # #itera = \' + `DSit` + \' #CDSitdict[Cpcmax] = itera # #i am now wondering if i have been trying to
Re: How to force a thread to stop
Gerhard Fiedler [EMAIL PROTECTED] wrote: | On 2006-08-03 06:07:31, H J van Rooyen wrote: | | Thanks - will check it out - seems a lot of money for 555 functionality | though | | Especially if like I, you have to pay for it with Rand - I have started | to call the local currency Runt... | | Depending on what you're up to, you can make such a thing yourself | relatively easily. There are various possibilities, both for the | reset/restart part and for the kick-the-watchdog part. | | Since you're talking about a 555 you know at least /some/ electronics :) *grin* You could say that - original degree was Physics and Maths ... | Two 555s (or similar): | - One wired as a retriggerable monostable and hooked up to a control line | of a serial port. It needs to be triggered regularly in order to not | trigger the second timer. | - The other wired as a monostable and hooked up to a relay that gets | activated for a certain time when it gets triggered. That relay controls | the computer power line (if you want to stay outside the case) or the reset | switch (if you want to build it into your computer). | | I don't do such things with 555s... I'm more a digital guy. There are many | options to do that, and all a lot cheaper than those boards, if you have | more time than money :) Like wise - some 25 years of amongst other things designing hardware and programming 8051 and DSP type processors in assembler... The 555 came to mind because it has been around for ever - and as someone once said (Steve Circia ?) - My favourite programming language is solder... - a dumb state machine implemented in hardware beats a processor every time when it comes to reliability - its just a tad inflexible... The next step above the 555 is a PIC... then you can steal power from the RS-232 line - and its a small step from PIC to PIG... Although this is getting bit off topic on a language group... ;-) Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested function scope problem
On Thu, 03 Aug 2006 17:27:26 -0300 Gerhard Fiedler [EMAIL PROTECTED] wrote: # But seriously, for my comment this seems off-topic. Well, you wrote but it's not really understandable with a C++ concept of variable. It is perfectly understandable to me. That's all I said (or, at least, all I wanted to say). # I did not say that you can't create Python behavior with C (of # course you can, you can do /everything/ in C :). You can build # constructs made up of C variables that simulate everything that any # Python construct does. That's not the point. The point is how the # simple, built-in language variable behaves. I agree. For me, Python variable behaves just like a C++ variable (a pointer, sure, but that's minor point to me... YMMV). # # You also don't expect the identity of a and b to be the same # # after assigning one to the other. # # Don't I? # # I don't know. Try replacing your printf statements with something # like printf(%x %i %i\n,a,a,*a); and watch the first column. # The address operator is probably for a C programmer the closest to # what the id() function is to a Python programmer. I disagree. At least in my understanding, which, up to now, was perfectly enough to explain everything about how Python variables behave: The address operator in C is what textual representation (i.e. what you type, like a) is in Python. Equivalent of id() is a dereference operator. Of course, there are probably other ways to look at this. But I still do not see why people claim that there is a significant difference between what variables are in Python and in C++. -- Best wishes, Slawomir Nowaczyk ( [EMAIL PROTECTED] ) If at first you don't succeed, redefine success. -- http://mail.python.org/mailman/listinfo/python-list
Re: help - iter dict
taleinat wrote: aking at mappi.helsinki.fi writes: CDSitdict = {28.473823598317392: '2.48699832', 40.06163037274758: '0.2912', 27.756248559438422: '2.83499964', 33.2299196586726: '1.12499962', 29.989685187220061: '1.91399677', 31.502319473614037: '1.4909983', 28.487341570327612: '2.4809983', 30.017763818271245: '1.90499681', 32.94343842266: '1.17899943', 30.520103712886584: '1.75199736', 31.453205956498341: '1.50299826', 29.484222697359598: '2.0849968', 28.413513489228706: '2.51399842', 28.314852455260802: '2.5589986', 28.652931545003508: '2.40899803'} heres the error i get after entering Cpcb Traceback (most recent call last): File elementalDS.py, line 156, in ? CDS = findClosest(CDSitdict, Cpcb) File elementalDS.py, line 142, in findClosest distance = (target - v) ** 2 TypeError: unsupported operand type(s) for -: 'float' and 'str' alicat at linux:~/Desktop The Python interpreter is being friendly and explaining exactly what the problem is and where it occured. It's telling you that it can't subtract a string from a float, in line 142 of your code (in the findClosest function). So the problem is that 'target' is a float while 'v' is a string. 'v' should be a float as well, but it's a string since the values in your dictionary are strings instead of numbers. Try removing the quotes around the values in your dict (both the double-quotes and the single-quotes). yes i now the key and values are swapped and the solutions work fine, i cant let the numerical key be involved in the iteration as in some cases there may be an exvalue below 3. the only solution i could come up with is to put single quotes round it but unfortunately i couldnt even to that thanks a -- Dr. Alistair King Research Chemist, Laboratory of Organic Chemistry, Department of Chemistry, Faculty of Science P.O. Box 55 (A.I. Virtasen aukio 1) FIN-00014 University of Helsinki Tel. +358 9 191 50429, Mobile +358 (0)50 5279446 Fax +358 9 191 50366 -- http://mail.python.org/mailman/listinfo/python-list
Re: threads, file access and stuff
[EMAIL PROTECTED] wrote: Hi, i'm trying to make a download manager (getright, flashget, etc..) for linux (pygtk), i'm using pyCurl, so the thing is.. the app need to be able to use mirrors, like : i download the first 400 kb from X, and the second 200 kb from Y and the rest from Z. i've plan to do this with threads and using Locks (This question has been here before, so i have an idea..) but the thing is, What if the app don't download a complete file in a session (the user close the app, etc) and wants to complete the download? Ok, i can seek the file and start to download again. but where or how can i store that info?(where i left the download). Where : the convention on *n*x is to store this kind of stuff in a .appname file or directory in the users's home. How : this is up to you, but I'd start with the simplest solution, ie an ini file (ConfigParser is your friend here). HTH -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Which KDE IDE for Python?
Diez B. Roggisch wrote: Bart Ogryczak schrieb: Hi, Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both have drawbacks. KDevelop is a multilanguage IDE, and doesn't really have anything special for Python. There's no Python debugger, no PyDOC integration, it's class browser doesn't display attributes. On the other side there's Eric, which is made just for Python. But.. it doesn't integrate with KDE, doesn't support remote files (fish://, ftp:// etc.). Does anyone know a better IDE for Python, that'll integrate nicely with KDE? I bet you can try and convince Detlev Offenbach (eric developer) to add that - he already has _some_ KDE-specific stuff in there, and I presume supporting IO-Slaves might not be too hard. Actually I doubt it. For example on question why doesn't Eric use katepart as editor, he responded: Because it is actually written using PyQt and is meant to work on Win... and Mac OS X as well. Therefore it must not depend on KDE (or any other non-portable or non-ported toolkit). -- http://mail.python.org/mailman/listinfo/python-list
Re: [Linux] What toolkit for a good grid/spreadsheet widget?
On 2006-08-04, Vincent Delporte [EMAIL PROTECTED] wrote: Thx for the two pointers. Are those widgets more than just tables, ie. can I edit the contents, including displaying a combo box, can items be grouped or hierarchized, or are they just basic, read-only tables to display results? You can display combo boxes in cells in pygtk, as well as edit cells. But both pyqt and wxpython also offer that. Try running the demos for each. Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an obvious way to do this in python?
Nick Vatamaniuc [EMAIL PROTECTED] wrote: | Hendrik, | | ---snip--- | Now part of the reason I would like to go the transaction type route | instead of the per user route is robustness and maintainability, and | the ability it would give me to introduce new transaction types easily | - as I see it if say an invoice's GUI code is stable I would never have | to touch it again even if I combine it with anything else, as it would | have been designed from the start to combine with others of it's own | ilk, under a kind of communications controller that is standard... | ---snip--- | | It could be possible to separate your GUI into various modules. So you | could have for example: | BillingGUI.py | InvoicingGUI.py | QueryGUI.py | and so on. | Then your central control application (Application.py) would get the | set of module names allowed for that client to run during login. So | after the user logs in, the next thing would be to SELECT ... all | the GUI modules from the database to be downloaded. The client won't | know which ones are there, only the server. | | So the set of possible GUIs will be sent over to the client (preferable | in a zipped form). They are unzipped in some temporary folder (here you | can do some caching to only download if the set changed). | | Then it would be imporant for you to create some nameing rule or some | interface so the Application.py will know what GUI modules look like. | For example you could have the pattern [Capitalizedname]GUI.py be a | GUI module. The Application.py will then inspect the folder, and create | a button and label for each possible GUI module and present that to the | user. When the user clicks on the Button, the Application.py window | gets hidden and the [Modulename]GUI.py module is executed. When done, | the Application.py will be shown again and the user can either continue | with another module they are allowed to use or quit. | | How does that sound? This is the sort of thing I am looking for, thanks - its a bit rough as it depends on magic gui names, but hey - I think it would be easy to implement, even not using magic names - the server could tell the core app the names of the files explicitly during the logon type dialog... *grin* that will move the magic out of the client and on to the server... | Also, you mentioned that you won't have more than a couple of simple | fill-in forms and with drop-down options and so on. HTML then might be | the way to go. If that's all there will ever be just try to do HTML | (see Cherrypy, Turbogears and others). If your GUI will be more | complicated in the future, just stick with what you know (Tkinter for | example). | | Good luck, | Nick Vatamaniuc | Thank you for the support - now I would like to call Time out - I have a lot of reading to do... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an obvious way to do this in python?
Dennis Lee Bieber [EMAIL PROTECTED] wrote: | On Thu, 3 Aug 2006 16:50:15 +0200, H J van Rooyen | [EMAIL PROTECTED] declaimed the following in comp.lang.python: | | | This is broadly what I had in mind, yes - but sort of down to a transaction | level - this user does invoicing, this one enters cheques, this one does credit | notes, and their supervisor can do all three, and in a different department its | different because the jobs are different, but the invoicing GUI module is the | same for wherever its used... | | Confusing use of transaction... Many are probably looking at | transaction in terms of DBMS -- eg: a sequence of SQL operations | (inserts/updates/deletes) that ALL must be successful (and committed) | or, if any operation fails, ALL operations will be undone (rolled back) | as if none had been performed. | | What you describe is something I'd refer to as different operator | tasks. Sorry - I have spent too long in an environment where a transaction is something you built, shipped, and got an answer for... | | For this control, and presuming you do NOT want to use a web | interface, I'd still build all capability (ie, all menu and form | definitions) into the client that is installed on all user stations. | THEN I'd use the application server (since I still feel you want to | control access to the database to one central point, not have to create | a user account in the DBMS for each employee using the clients) to | handle a login from the client -- the login would be used to access a | privilege table from the DBMS. This privilege table is essential a long | record of booleans -- one for each menu/form/task in the client. The | privilege record is sent to the client; the client uses the record to | enable and disable the relevant menu/form/task so that the user can only | activate the functions valid for them. | *grin* this is the easy - cop out route - there is of course nothing intrinsically wrong with it - I was just trying to find out how to do the harder bits in Python - namely to dynamically present different things... | Otherwise you have a situation where, say a lowly data-entry clerk | has been using the application, maybe makes a mistake that requires | supervisor override, and the supervisor then has to wait for their | modules to be downloaded and started to correct the mistake. (Note: one | menu entry that should be on the all-in-one client is an ability to | change login without having to shut down the client -- basically the | client does a log-off of the application server, then a fresh log-in | with new parameters and gets a new privilege record with which to | reconfigure all the menu/form/task GUI). | This is a disadvantage that I had not thought about - I was not yet this far down the track | If you go the web application route, each login would use a cookie | to control session, so the application server can determine what | functions to present to the user. You might even be able to use | something like Plone to build the application server; it already has | capability to present different views based upon login. Know squat about Plone - another thing to add to my list of reading *sigh* | | My thinking is simpler than this, because you are already thinking in data base | speak - now dont get me wrong - I realise that I will have to use a database - | but for me to start thinking in terms of views and stuff is kind of premature | when I dont even have a clear picture in my head of the kind of data the said | management system should keep, as I am not sure of what can, and cannot be done. | | We're talking computer software -- enough money and time and you | could have the sun, moon, and stars (granted, a decade ago I /was/ | involved with swapping out one satellite ephemeris package for another, | so it was literally sun, moon, and stars G) | sounds like it was fun... | You need to determine | | 1) architecture partitioning (DBMS - thick client; DBMS - | application server - thick client, DBMS - application/web server - | thin client) [Thick client: Python program that handles GUI and talks to | application server or DBMS; Thin client: web browser forms with some | Javascript/AJAX]. I am kind of egregious - despite all the sound advice I am getting - I am still thinking (from the back end) of: dbms app server thick client (python) | | 2) Database schema (done without care of the final DBMS); take into | account things you may not think of as the main data of the application | -- things like the above privilege control (in the case of the | DBMS-thick client, it means using the grant tables and managing client | accounts per user, in the application server model you only have one | DBMS user that is the application server, but still have client user | accounts to manage as application data). If the DBMS has stored | procedures, you may need some of those... Heck, in the DBMS-thick | client model, you could let any client access ANY
Re: Which KDE IDE for Python?
On Friday 04 August 2006 11:52 am, Bart Ogryczak wrote: Diez B. Roggisch wrote: Bart Ogryczak schrieb: Hi, Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both have drawbacks. KDevelop is a multilanguage IDE, and doesn't really have anything special for Python. There's no Python debugger, no PyDOC integration, it's class browser doesn't display attributes. On the other side there's Eric, which is made just for Python. But.. it doesn't integrate with KDE, doesn't support remote files (fish://, ftp:// etc.). Does anyone know a better IDE for Python, that'll integrate nicely with KDE? I bet you can try and convince Detlev Offenbach (eric developer) to add that - he already has _some_ KDE-specific stuff in there, and I presume supporting IO-Slaves might not be too hard. Actually I doubt it. For example on question why doesn't Eric use katepart as editor, he responded: Because it is actually written using PyQt and is meant to work on Win... and Mac OS X as well. Therefore it must not depend on KDE (or any other non-portable or non-ported toolkit). There is a huge difference between depending on something and being able to use something if it is available. Eric can't depend on katepart, but it can use the KDE standard dialogs if they are available. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
On 2006-08-04 05:30:00, Sybren Stuvel wrote: Besides, you probably don't know whether it's not one of your direct suppliers who's affected. You're sure you don't buy from anybody running a Windows system? I'd bet against that, and I only bet when I know I win :) Good point. I don't buy much software, though. The only things I buy are some games every now and then. No food? No clothes? No furniture? No household supplies? No transportation? No bike/bicycle/car? They all (well, most of them) use computers in their administration; /that's/ the cost I was talking about, not the cost for the software industry :) Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: How to force a thread to stop
On 2006-08-04 02:33:07, H J van Rooyen wrote: The next step above the 555 is a PIC... then you can steal power from the RS-232 line - and its a small step from PIC to PIG... I see... you obviously know what to do, if you want to :) But I'm not sure such a device alone is of much help in a typical server. I think it's probably just as common that only one service hangs. To make it useful, the trigger process has to be carefully designed, so that it actually has a chance of failing when you need it to fail. This probably requires either code changes to the various services (so that they each trigger their own watchdog) or some supervisor program that only triggers the watchdog if it receives responses from all relevant services. Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem reading/writing files
Ok, now I'm very confused, even though I just solved my problem. I copied the entire contents of the original file (evil2.gfx) from my hex editor and pasted it into a text file. When I read from *this* file using my original code, everything worked fine. When I read the 21st byte, it came up as the correct \x00. Why this didn't work in trying to read from the original file, I don't know, since the hex values should be the same, but oh well... -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the best way to print the usage string ?
There's been a good lot of response to the problem originally stated, but no-one's pointed out that: print reduce(lambda x, y: x + ':' + y, sys.argv[1:]) is a confusing (and slow) way of writing: print ':'.join(sys.argv[1:]) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG Python Extension winth C++ Problematic
I have been working getting my C++ code to be used in Python ( Basically Extending ) This is the problem i am facing rite now. I have a function that returns a Pointer to a class in my C++ Code It looks like this ... I have used SWIG to get the Glue code. When i call this function ( in python ) and it eventually returns ( when it gets a connection in this case ) it crashes ! I get a SEG FAULT ! Is it some thing that cannot be done ? I'm certainly no SWIG expert, however: 1. Is your SLSocket class wrapped with SWIG? Do you maybe need a typemap? Can you explicitly create one from Python? If so, does that work? 2. What does your SWIG .i file look like? 3. Finally, have you tried asking on the SWIG mailing list ([EMAIL PROTECTED])? There are probably many more SWIG experts there than here. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: regex question
On Thu, 03 Aug 2006 22:10:55 +0100 Gabriel Murray [EMAIL PROTECTED] wrote: # Hello, I'm looking for a regular expression Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems. -- Jamie Zawinski Therefore: def test(data): format, index = 'abcd', 0 for c in data: i = format.index(c) if i index+1: return False index = i return index==format.index('d') Could be made faster if format was made a dictionary or if one wanted to compare characters directly. Writing (and profiling) left as an exercise for a reader. -- Best wishes, Slawomir Nowaczyk ( [EMAIL PROTECTED] ) A mind is like a parachute. It doesn't work unless it's open. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need a compelling argument to use Django instead of Rails
[EMAIL PROTECTED] wrote: Paul Rubin wrote: A typical shared hosting place might support 1000's of users with ONE apache/php instance (running in a whole bunch of threads or processes, to be sure). You just need to run multiple apache instances, which is advisable anyway. The hosting service formerly known as python-hosting has been doing this for years. Would you need one instance per user? Is it practical to run 1000s of Apache instances on one server? -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem reading/writing files
[EMAIL PROTECTED] schreef: f = open('evil2.gfx','rb') i1 = open('img1.jpg','wb') i2 = open('img2.png','wb') i3 = open('img3.gif','wb') i4 = open('img4.png','wb') i5 = open('img5.jpg','wb') for i in range(0,67575,5): i1.write(f.read(1)) i2.write(f.read(1)) i3.write(f.read(1)) i4.write(f.read(1)) i5.write(f.read(1)) f.close() i1.close() i2.close() i3.close() i4.close() i5.close() I first noticed the problem by looking at the original file and img1.jpg side by side with a hex editor. Since img1 contains every 5th byte from the original file, I was able to find many places where \x00 should have been copied to img1.jpg, but instead a \x20 was copied. What caused me to suspect the read method was the following: f = open('evil2.gfx','rb') s = f.read() print repr(s[19:22]) '\xe0 \r' Now, I have checked many times with a hex editor that the 21st byte of the file is \x00, yet above you can see that it is reading it as a space. I've repeated this with several different nulls in the original file and the result is always the same. As I said in my original post, when I try simply writing a null to my own file and reading it (as someone mentioned earlier) everything is fine. It seems to be only this file which is causing issue. Very weird. I tried your code on my system (Python 2.4, Windows XP) (but using a copy of evil2.gfx I still had on my system), with no problems. Are you sure that you don't have 2 copies of that file around, and that your program is using the wrong one? Or is it possible that some module imported with 'from blabla import *' clashes with the builtin open()? -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python for my web site
Cliff Wells wrote: On Mon, 2006-07-31 at 22:25 -0700, Luis M. González wrote: IMHO the best way of using mod_python is with its publisher handler. It let's you code your applications in a MVC (model view controller) style. While I agree (or at least consider the point moot) that this is possibly the best way to use plain mod_python, I'd disagree that it's a good way to develop modern web applications in Python. By the time you've decided on every bit of framework to use, and made all the little decisions that go into turning a fresh, clean spot on your hard drive into an application, what you've done is reinvent TurboGears rather than develop your application. However, at least whatever you come up with would be better documented than TurboGears. ;) (I reserve the right to amend this jocular opinion after TurboGears hits version 1.0.) -- Ben Sizer -- 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
wxPython font color
hey everybody, i cant seem to find a way to create a font with a non-default color using the wx.Font constructor. anybody know how to change hte color? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: programming is hard
placid wrote: [EMAIL PROTECTED] wrote: placid wrote: Alas, all good arguments. I rest my case. After you've just been proven wrong? I wouldn't want you for my lawyer. Aha, lucky i wont be a lawyer. lawyering is hard too ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested function scope problem
On Fri, 04 Aug 2006 10:10:45 -0300 Gerhard Fiedler [EMAIL PROTECTED] wrote: # On 2006-08-04 07:36:25, Slawomir Nowaczyk wrote: # # # The address operator is probably for a C programmer the closest to # # what the id() function is to a Python programmer. # # I disagree. At least in my understanding, which, up to now, was # perfectly enough to explain everything about how Python variables # behave: # # The address operator in C is what textual representation (i.e. what # you type, like a) is in Python. Equivalent of id() is a dereference # operator. # # But then you are not talking about C variables. I am. The fact that Python variables behave like C pointers isn't overly relevant. A pointer is perfectly good C variable to me. # Using a normal C variable, this doesn't work: # # int c = 5; # printf( id(c)=%x, *c ); Depends on what do you expect. The above is kind of equivalent to, say: locals()[5] in Python. Of course, there is no object at memory address 5 (in C) and no object in locals() named 5 (in Python). I agree there is a difference between getting a segfault and getting an exception, but it doesn't have much to do, IMHO, with what a variable is. # You can hardly claim that what gets printed is the id of the variable c. # (Well, you can claim, but few C programmers would follow you.) That's possible. I wouldn't expect too many C programmers to have any notion of id of a variable. I, for example, never thought about such thing before this thread. # What would be analogous in Python to the textual representation of # the variable in C? The address operator in C in analog to the # textual representation in Python. The textual representation in C # is analog to ??? in Python? There is no textual representation of variables in C -- at least not at runtime. Why should there be? There is, after all, no equivalent to eval('a=1') so why would anybody care what was variable named? # You may be talking about C pointers and call the locations they point to # variables. Yes, I am talking about C pointers, but I call *them*, not what they point at, variables. # That's a big difference; those are /not/ C variables. I agree, the locations are not variables. # And they still are not the same. OK, sure, there is a number of things that you can do to/with C variable that you cannot to/with Python variable, so they are not the same. I just feel the differences are not large enough to warrant # What is analog in Python (using your analogy) to the address of the pointer # variable in C (a in your example)? Well, how about x='a'? It allows you to do locals()[x], # Note that in standard C/C++ language, a and b in your example are variables # (in fact the only variables), not *a and *b. Agreed. # (three and four should have been declared as constants, to be # analogous to Python.) True, but I didn't think it matters. # So the only variables in your example (a and b) don't really behave # according to your analogy. Sorry, I do not follow. # What behaves somewhat like your analogy are *a and *b -- neither of # which are C/C++ variables. (Well, they are in your example, but # only because of sloppily applying your analogy. I never said *a is a variable. # And they are not in the general case: pointers don't care whether # they point to actual C/C++ variables, or to any other memory # location.) I think I lost you, but Python names do? Does a in your *.py file care whether they are bound to any object? I just noticed that part of our disagreement comes from the fact that I am talking about C variables as they look at runtime, while you seem to also consider the source code to be relevant. Am I correct? -- Best wishes, Slawomir Nowaczyk ( [EMAIL PROTECTED] ) Science is a differential equation. Religion is a boundary condition. -- Alan Turing -- http://mail.python.org/mailman/listinfo/python-list
Re: [Linux] What toolkit for a good grid/spreadsheet widget?
jean-michel bain-cornu wrote: Hi, Thx for the two pointers. Are those widgets more than just tables, ie. can I edit the contents, including displaying a combo box, can items be grouped or hierarchized, or are they just basic, read-only tables to display results? I need this kind of widget to build a 2+ column interface to let users type entries into the application as an alternative to MS Access-style complicated entry masks. Wx have got an excellent one. I was succesful to use it with editable cells and to include a choice in a cell. However, it was pretty hard to reach that, ie to extract a working sample from the demo. Once done that, no more problems with it. What I suggest you is to have a look on the demo, in the chapter Core Windows/Controls - Grid - wx.Grid showing Editors and Renderers. Rgds, jm Yes, I can also select which cell can be edited on the cell level. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need a compelling argument to use Django instead of Rails
Ben Sizer wrote: [EMAIL PROTECTED] wrote: Paul Rubin wrote: A typical shared hosting place might support 1000's of users with ONE apache/php instance (running in a whole bunch of threads or processes, to be sure). You just need to run multiple apache instances, which is advisable anyway. The hosting service formerly known as python-hosting has been doing this for years. Would you need one instance per user? Is it practical to run 1000s of Apache instances on one server? I'm almost certain Apache spawns instances as needed. If they are all active at the same time you will need at least that many threads anyway and I don't think processes are really much more expensive than threads usually. But I'm not an expert on virtual hosting or apache or even thread/process internals. However when I do a ps -aef on my shared server (http://www.xfeedme.com) I only see the apache instances that are active, and not the 50 dormant ones, if I recall. -- Aaron Watters === She was flirty, dirty, musta been about thirty -- 70's stones lyrics She was nifty, shifty musta been about fifty -- 90's stones lyrics -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem reading/writing files
Well, now I tried running the script and it worked fine with the .gfx file. Originally I was working using the IDLE, which I wouldn't have thought would make a difference, but when I ran the script on its own it worked fine and when I ran it in the IDLE it didn't work unless the data was in a text file. Weird. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem reading/writing files
[EMAIL PROTECTED] schreef: Well, now I tried running the script and it worked fine with the .gfx file. Originally I was working using the IDLE, which I wouldn't have thought would make a difference, but when I ran the script on its own it worked fine and when I ran it in the IDLE it didn't work unless the data was in a text file. Weird. Weird indeed: I ran the script under IDLE too... -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested function scope problem
On 2006-08-04, Slawomir Nowaczyk [EMAIL PROTECTED] wrote: On Fri, 04 Aug 2006 10:10:45 -0300 Gerhard Fiedler [EMAIL PROTECTED] wrote: # You can hardly claim that what gets printed is the id of the variable c. # (Well, you can claim, but few C programmers would follow you.) That's possible. I wouldn't expect too many C programmers to have any notion of id of a variable. I, for example, never thought about such thing before this thread. But even in Python we don't speak of id of a variable. It is not the variable that has an id. It is the object that is currently attached to the variable that has an id. Yes we can use id of a variable as a shortcut for the correct formulation as long as you keep in mind that it is not the variable itself that has an id. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython font color
Fonts don't have colors. You need to either change the text color in whatever widget the test is going or change the wx.Brush in your Paint method. Kiran wrote: hey everybody, i cant seem to find a way to create a font with a non-default color using the wx.Font constructor. anybody know how to change hte color? thanks -- http://mail.python.org/mailman/listinfo/python-list
new Python release date (Sept. 12)
just in case you don't check the PEP obsessively like i do (i'm really excited for 2.5!), the new release dates are: rc 1:August 18, 2006 [planned] final: September 12, 2006 [planned] although in the Abstract it still shows August 19...where can that be reported? -- http://mail.python.org/mailman/listinfo/python-list
Re: [Linux] What toolkit for a good grid/spreadsheet widget?
On Fri, 04 Aug 2006 10:58:42 GMT, Dave Cook [EMAIL PROTECTED] wrote: But both pyqt and wxpython also offer that. Try running the demos for each. Thx everyone! -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWeek #3 in September!
I'll be out of the office until approximately August 20th. If you have any questions, please email [EMAIL PROTECTED] -- David Wahler -- http://mail.python.org/mailman/listinfo/python-list
Re: python-dev Summary for 2006-06-16 through 2006-06-30
I'll be out of the office until approximately August 20th. If you have any questions, please email [EMAIL PROTECTED] -- David Wahler -- http://mail.python.org/mailman/listinfo/python-list
Re: How to force a thread to stop
Gerhard Fiedler [EMAIL PROTECTED] wrote: | On 2006-08-04 02:33:07, H J van Rooyen wrote: | | The next step above the 555 is a PIC... then you can steal power from the | RS-232 line - and its a small step from PIC to PIG... | | I see... you obviously know what to do, if you want to :) | | But I'm not sure such a device alone is of much help in a typical server. I | think it's probably just as common that only one service hangs. To make it | useful, the trigger process has to be carefully designed, so that it | actually has a chance of failing when you need it to fail. This probably | requires either code changes to the various services (so that they each | trigger their own watchdog) or some supervisor program that only triggers | the watchdog if it receives responses from all relevant services. | | Gerhard This is true - its trivial to just kill the whole machine like this, but its kind of like using a sledgehammer to crack a nut - and as you so rightly point out - if the process that tickles the watchdog to make it happy is not (very) tightly coupled to the thing you want to monitor - then it may not work at all - specially if interrupts are involved - in fact something like a state machine that looks for alternate occurrences of (at least) two things is required - the interrupt gives it a kick and sets a flag, the application sees the flag and gives it the alternate kick and clears the flag, and so on, with the internal tasks in the machine passing the ball in this (or some other) way - that way you are (relatively) sure the thing is still running... but it needs careful design or it will either kill the machine for no good reason, (when something like disk accesses slow the external (user) processes down ) , or it will fail to fire if it is something that is driven from a call back - the app may be crazy, but the OS may still be doing call-backs and timing stuff faithfully - you cant be too careful... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
On Fri, Aug 04, 2006 at 02:01:58PM +0200, Sybren Stuvel wrote: OS/2 (and eComStation) also uses the backslash as the path separator. You mean OS/2 is still in actual use? 'fraid so. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python open a named pipe == hanging?
Thank you for your advise. So, it turns out that fifos are quite useless in Python programming then, which is quite disappointing to me :-( I am not saying that I _have to_ use fifo, afterall it is a rather odd thingy not in fasion since the last iceage... I am just disappointed by the fact that the old plain Bash seems to excel Python in this special aspect. I am new to Python and much more comfortable in Bash programming. A simple Bash script like this would take the advantage of a fifo, hence reduce the overhead of unneccesarry temporary files creation: #!/bin/bash mkfifo my_fifo echo this is a string in my fifo! my_fifo cat my_fifo rm my_fifo Isn't it neat? Anyway, I think every scripting language has its pros and cons. Bash is probably more flexible in dealing with fifos and multiway pipes (through the magic menchanism of process substitution). Thank you! On Thu, 03 Aug 2006 22:13:56 -0400, Alex Martelli [EMAIL PROTECTED] wrote: -- http://mail.python.org/mailman/listinfo/python-list
web searching scripts
Does anyone know of a freely available script that can take a given URL and follow every link within it? Ideally, I would like to start with this to build a quick application to grab all the content off a website to publish it to a CD. Thanks, jul -- http://mail.python.org/mailman/listinfo/python-list
Re: Python open a named pipe == hanging?
In article [EMAIL PROTECTED], Rochester [EMAIL PROTECTED] wrote: I just found out that the general open file mechanism doesn't work for named pipes (fifo). Say I wrote something like this and it simply hangs python: #!/usr/bin/python import os os.mkfifo('my fifo') open('my fifo', 'r+').write('some strings.') x = os.popen('cat my fifo').read() print x I believe your problem is that, by the time you open the pipe for read, it has already been closed by its writer. If you contrive to keep the file pointer around until after the reader has opened it, then you can read some data from it. (You can't read all the data, though - since you still have the file open, it has no end of file - so you can't solve the problem exactly as stated above.) And the odds are fair that when you get this working, you will run into some other inconvenient behavior. Named pipes are a little tricky. I know I could use a tempfile instead of a fifo in this very simple case, I just want to know is there a standard way of handling fifos withing python. Especially the non-trivial case when I want to call a diff like system program which takes two files as input. Say I have two python string objects A and B, I want to call diff to see what is the different between those two strings, and return the finding as a string obj C back to python. This certainly can be done in this way: open('tmpfile1', 'w').write(A) open('tmpfile2', 'w').write(B) C = os.popen('diff tmpfile1 tmpfile2').read() But that's kinda awkward isn't it? :-) The Bash way of doing this would be (suppose A is the stdout of prog2, B is the stdout of prog3): diff (prog2) (prog3) C What is the best way of doing this in Python? Version 1. That's also how shell programmers do it, as far as I know. That bash thing is a neat gimmick, borrowed from Plan 9's rc, but not a standard shell feature and not needed for conventional UNIX programming. That's my opinion. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the best way to print the usage string ?
Ben Finney wrote: Leonel Gayard [EMAIL PROTECTED] writes: import sys args = sys.argv[1:] if args == []: print Concat: concatenates the arguments with a colon (:) between them Usage: concat arg1 [arg2...] Example: concat a b c prints \a.jar:b.jar:c/\ sys.exit(1) print reduce(lambda x, y: x + ':' + y, sys.argv[1:]) [snip] For this particular use case, you may also want to investigate the standard library 'optparse' module, which provides a way of defining options as objects that contain everything the parser needs to know, including a help message for each option which it then uses to automatically construct a program usage message. URL:http://docs.python.org/lib/module-optparse FWIW, here's what the optparse code might look like: parser = optparse.OptionParser( usage='%prog arg1 [arg2...]', description='concatenates the arguments with a colon (:) ' 'between them') options, args = parser.parse_args() if not args: parser.error('wrong number of arguments') print ':'.join(args) The optparse module doesn't do anything for positional arguments, so you have to check them afterwards and issue an error as necessary. It also doesn't know how to construct your usage message, so you have to write this by hand. To handle these two things automatically, see my other post on the argparse module[1]. STeVe [1] http://mail.python.org/pipermail/python-list/2006-August/354792.html -- http://mail.python.org/mailman/listinfo/python-list
Re: web searching scripts
[EMAIL PROTECTED] wrote: Does anyone know of a freely available script that can take a given URL and follow every link within it? Ideally, I would like to start with this to build a quick application to grab all the content off a website to publish it to a CD. Thanks, jul If you just want to download websites (i.e. not necessarily writing a program yourself to do that), you may try Httrack, it might suite your needs. http://www.httrack.com/ There even seem to be some sort of python bindings ... http://www.satzbau-gmbh.de/staff/abel/httrack-py/ But there might be some more pythonic solution around ... i would start looking at twisted or cherrypy, but i never used them myself ... HIH regards Avell -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
On 2006-08-04 09:58:34, Sybren Stuvel wrote: They all (well, most of them) use computers in their administration; /that's/ the cost I was talking about, not the cost for the software industry :) Good point. Time more people started using Open Source :) Definitely. But don't hold your breath :) Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested function scope problem
On 2006-08-04 12:12:44, Antoon Pardon wrote: That's possible. I wouldn't expect too many C programmers to have any notion of id of a variable. I, for example, never thought about such thing before this thread. But even in Python we don't speak of id of a variable. It is not the variable that has an id. It is the object that is currently attached to the variable that has an id. Yes we can use id of a variable as a shortcut for the correct formulation as long as you keep in mind that it is not the variable itself that has an id. This sounds a bit like saying yes we can use the term 'variable' as a shortcut for the correct formulation (object associated to a name) as long as we keep in mind that it is not actually a variable :) Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: web searching scripts
On Fri, 04 Aug 2006 18:11:18 +0200, Avell Diroll [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Does anyone know of a freely available script that can take a given URL and follow every link within it? Ideally, I would like to start with this to build a quick application to grab all the content off a website to publish it to a CD. ... If you just want to download websites (i.e. not necessarily writing a program yourself to do that), you may try Httrack, it might suite your needs. The well-known Gnu wget is what I always use. (IMHO, this is a situation where it's a /good/ idea to glue together existing software, rather than joining many bits of code to a mirror-from-http-to-cdr application.) /Jorgen -- // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu \X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Need help building boost python on mac os x.
Could someone point me to step by step instructions on building boost python on mac os x? I have bjam running.. I have the boost source... but the tests are failing.. Probably something to do with environement variables... Anyone with time? -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
On Tue, 1 Aug 2006 14:47:59 -0300, Gerhard Fiedler [EMAIL PROTECTED] wrote: On 2006-08-01 12:31:01, Sybren Stuvel wrote: ... Is that really true? From what I know, it's more like this: - Unix-type systems: '/' - Windows-type systems: '\' - Mac OS: ':' - OpenVMS: '.' - ... Maybe someone else can fill in some of the missing OSes. AmigaDOS: '/'. (On the other hand, it didn't understand '.' and '..' without third-party patches, and it didn't have the '/' directory.). It doesn't seem to look like Windows is the odd man out; it rather seems that every type of OS uses its own separator. In the 1980s, MS-DOS /was/ an ugly bastard child; lots of other systems existed that I have never heard about. As for what path separator they used and why, I'm afraid you'd have to ask on alt.folklore.computers ... /Jorgen -- // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu \X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested function scope problem
On 2006-08-04 11:41:03, Slawomir Nowaczyk wrote: # I disagree. At least in my understanding, which, up to now, was # perfectly enough to explain everything about how Python variables # behave: # # The address operator in C is what textual representation (i.e. what # you type, like a) is in Python. Equivalent of id() is a dereference # operator. # # But then you are not talking about C variables. I am. The fact that Python variables behave like C pointers isn't overly relevant. A pointer is perfectly good C variable to me. Let me try to make myself clear... Using your example, we have int*a. a is a pointer to int. a is a C variable. *a is treated as an int; it may be a C variable (of type int or not), but it often (maybe even more often than not) is /not/ a C variable. When you request memory from the heap, you don't get a C variable from the heap, you get a requested number of bytes. This is not a C variable, it's only memory that gets written to using a pointer. You can say that in the context of your application logic, that is an application variable. But it is not a C language variable. The pointer itself (a) is of course a C variable. But you're not basing your analogy on C pointer variables (a), you are basing it on whatever C pointer variables point to (*a), which is in the general case not a C variable (even though it can be one). To better understand what I'm talking about, try to make a consistent analogy. One side Python terms, on the other side the analogous C terms. You said previously: The address operator in C is what textual representation (i.e. what you type, like a) is in Python. Equivalent of id() is a dereference operator. Python === C Textual representation a === Address operator (a) id(a) === Dereference operator (*a) I think I didn't quite translate what you meant, but you get the idea. I don't think you can come up with a working analogy. The differences are just too many -- if you consider the C language on the right side, not a custom application you developed in C. # Using a normal C variable, this doesn't work: # # int c = 5; # printf( id(c)=%x, *c ); Depends on what do you expect. The above is kind of equivalent to, say: locals()[5] No. You said that in your analogy, the Equivalent of id() is a dereference operator. I took a C variable (c) and applied to it what you say is the equivalent of id() in C: the dereference operator. Python: c = 5 id(c) C: int c = 5; printf( id(c)=%x,*c); If that is not correct according to your analogy, your analogy doesn't seem to be worded in the way you mean it. That's possible. I wouldn't expect too many C programmers to have any notion of id of a variable. I, for example, never thought about such thing before this thread. I'm not sure how much C you did. But the address of a variable is a quite important concept in C; something that identifies the variable. For example, it is important to distinguish between static, heap and stack variables, and one of the main differences is their address space and the different ways these address spaces get managed. There is no textual representation of variables in C -- at least not at runtime. Why should there be? There is, after all, no equivalent to eval('a=1') so why would anybody care what was variable named? I wasn't aware that you were talking only about runtime. Yes, I am talking about C pointers, but I call *them*, not what they point at, variables. Not really. Try to make your analogy more explicit. Your analogy only works (kind of) if you treat (in C) *a as the equivalent of a Python variable, not a. # What is analog in Python (using your analogy) to the address # of the pointer variable in C (a in your example)? Well, how about x='a'? It allows you to do locals()[x], Now you're in a different example. It would be easier to follow if we stood with one. # So the only variables in your example (a and b) don't really behave # according to your analogy. Sorry, I do not follow. You said that the address operator [of a C variable] in C is what textual representation is in Python. We agree that the pointer variable 'a' is a C variable. So is 'a' in C the equivalent to 'id(a)' in Python? Your code seemed to indicate that you meant 'a' to be the equivalent to 'id(a)' -- which is not consistent with your own definition of the equivalence. Check out your example code; you didn't even include 'a'. I never said *a is a variable. But you treated it as such in your example code. I just noticed that part of our disagreement comes from the fact that I am talking about C variables as they look at runtime, while you seem to also consider the source code to be relevant. Am I correct? You're correct in that I considered the source. But that's not really important. I could leave the C source and go to the C runtime. However, then we don't really have anymore a C variable 'a', we only have a memory location. That's
Re: Nested function scope problem
On 2006-08-04, Gerhard Fiedler [EMAIL PROTECTED] wrote: On 2006-08-04 12:12:44, Antoon Pardon wrote: That's possible. I wouldn't expect too many C programmers to have any notion of id of a variable. I, for example, never thought about such thing before this thread. But even in Python we don't speak of id of a variable. It is not the variable that has an id. It is the object that is currently attached to the variable that has an id. Yes we can use id of a variable as a shortcut for the correct formulation as long as you keep in mind that it is not the variable itself that has an id. This sounds a bit like saying yes we can use the term 'variable' as a shortcut for the correct formulation (object associated to a name) A variable is not an object associated to a name. It is not the object that is the variable. as long as we keep in mind that it is not actually a variable :) Variable is a term that comes from mathematics. No language variable is exactly like the mathematical notion, but if I had to choose I would say that lisp, smalltalk and python variables come closer than C, ada or pascal variables. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Need a compelling argument to use Django instead of Rails
Paul Rubin wrote: Ben Sizer [EMAIL PROTECTED] writes: Another perfectly good reason is that PHP pages are much simpler to deploy than any given Python application server. Just add the code into your HTML pages as required and you're done. Python could come close to this if something like the Python Server Pages implementation in mod_python was to become widely available and well known, but that still requires overcoming the first problem. I didn't realize you could do shared hosting with mod_python, because of the lack of security barriers between Python objects (i.e. someone else's application could reach into yours). You really need a separate interpreter per user. mod_python uses sub-interpreters - can be per virtual server, per directory etc, cf http://www.modpython.org/live/current/doc-html/dir-other-ipd.html http://www.modpython.org/live/current/doc-html/dir-other-ipdv.html -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python open a named pipe == hanging?
In article [EMAIL PROTECTED], Rochester [EMAIL PROTECTED] wrote: Thank you for your advise. So, it turns out that fifos are quite useless in Python programming then, which is quite disappointing to me :-( I am not saying that I _have to_ use fifo, afterall it is a rather odd thingy not in fasion since the last iceage... I am just disappointed by the fact that the old plain Bash seems to excel Python in this special aspect. Not by a very great margin, but it is indeed very convenient for process creation and redirection, so when that's the nature of the task, it's likely the right choice. I am new to Python and much more comfortable in Bash programming. A simple Bash script like this would take the advantage of a fifo, hence reduce the overhead of unneccesarry temporary files creation: #!/bin/bash mkfifo my_fifo echo this is a string in my fifo! my_fifo cat my_fifo rm my_fifo Isn't it neat? If you like it, good for you. Do you understand why it works, when your Python one didn't? You put the output in a background process; did it occur to you to try that in Python? Anyway, I think every scripting language has its pros and cons. Bash is probably more flexible in dealing with fifos and multiway pipes (through the magic menchanism of process substitution). Multiway pipes? Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Why do I require an elif statement here?
Could somebody tell me why I need the elif char == '\n' in the following code? This is required in order the pick up lines with just spaces in them. Why doesn't the else: statement pick this up? OLD_INDENT = 5 # spaces NEW_INDENT = 4 # spaces print 'Reindent.py:' print '\nFrom file %s' % infile print 'Change %i space indentation to %i space indentation.' % ( OLD_INDENT, NEW_INDENT) print 'And place revised file into %s' % outfile whitespace = ' ' n = 0 nline = 0 for line in input.readlines(): nline += 1 # Only look at lines that start with a space. if line[0] == whitespace: i = 0 for char in line: i += 1 if char == whitespace: pass elif char == '\n': # Why do I need this for a blank line with only spaces? output.write(line) break else:# Why doesn't the blank line get picked up here? x = line.count(whitespace*OLD_INDENT,0,i) # Reindent lines that have exactly a multiple of OLD_INDENT. if x 0 and (i-1)%OLD_INDENT == 0: output.write(whitespace*NEW_INDENT*x+line.lstrip()) n += 1 break else: output.write(line) break else: output.write(line) input.close() output.close() print 'Total number of %i lines reindented out of %i lines.' % (n, nline) -- http://mail.python.org/mailman/listinfo/python-list
Re: Pydev with Eclipse on OSX Q
On 8/4/06, Michiel Sikma [EMAIL PROTECTED] wrote: Hey guys. I'm trying to run Pydev on Eclipse on OSX, but I've got aproblem that prevents me from making new projects in it. It seemsthat I cannot add my Python interpreter to the list of interpreters(it seems to do _something_ when I select it, but then ends up not adding it to the list).Are any of you guys familiar with this? Is there something I need todo before I can add my interpreter to that list? I'm on a G5 iMac andhave the latest version of both programs. Have you checked your error log? (when adding an interpreter, there might be problems if you don't specify your real interpreter, but a link for it... (see bug http://sourceforge.net/tracker/index.php?func=detailaid=1523582group_id=85796atid=577329 for details) or have spaces in your eclipse path (see bug http://sourceforge.net/tracker/index.php?func=detailaid=1228027group_id=85796atid=577329 for details). Cheers, Fabio -- http://mail.python.org/mailman/listinfo/python-list
Re: Python open a named pipe == hanging?
On 2006-08-04, Rochester [EMAIL PROTECTED] wrote: Thank you for your advise. So, it turns out that fifos are quite useless in Python programming then, which is quite disappointing to me :-( I am not saying that I _have to_ use fifo, afterall it is a rather odd thingy not in fasion since the last iceage... I am just disappointed by the fact that the old plain Bash seems to excel Python in this special aspect. It doesn't. I am new to Python and much more comfortable in Bash programming. A simple Bash script like this would take the advantage of a fifo, hence reduce the overhead of unneccesarry temporary files creation: #!/bin/bash mkfifo my_fifo echo this is a string in my fifo! my_fifo cat my_fifo rm my_fifo Isn't it neat? Look you put the echo in the background, because otherwise your script would block. Nothing stops you from starting a thread in python to open the fifo in write mode, the thread would block but the main program could still continue. There also is the os.pipe and os.popen calls that may be more usefull in specific cases. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
An interesting way to implement an abstract base class
This one made me smile. From: http://aima.cs.berkeley.edu/python/utils.html#Queue class Queue: Queue is an abstract class/interface. There are three types: Stack(): A Last In First Out Queue. FIFOQueue(): A First In First Out Queue. PriorityQueue(lt): Queue where items are sorted by lt, (default ). Each type supports the following methods and functions: q.append(item) -- add an item to the queue q.extend(items) -- equivalent to: for item in items: q.append(item) q.pop() -- return the top item from the queue len(q) -- number of items in q (also q.__len()) Note that isinstance(Stack(), Queue) is false, because we implement stacks as lists. If Python ever gets interfaces, Queue will be an interface. def __init__(self): abstract def extend(self, items): for item in items: self.append(item) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do I require an elif statement here?
Could somebody tell me why I need the elif char == '\n' in the following code? This is required in order the pick up lines with just spaces in them. Why doesn't the else: statement pick this up? Following through with the below code: if the line consists of only a newline, it gets ignored due to the if line[0] == whitespace line. However, if the line consists of only whitespace followed by a newline you *do* successfully get to the else in question. There's no other place for you to go. However, what happens then? If you fall into you the top half of your if x 0 ... statement: you strip **all** *true* whitespace from the line with your lstrip() call. Since there's nothing between your whitespace (simple spaces) and the \n, the \n gets swallowed by the lstrip() call. Thus, you output.write() an empty string. I recommend a few judiciously placed print repr(thing) lines as you try to debug to see where things aren't what you expect them to be. As another sidelight, rather than using the i=0, i+= 1 aspect, you can use the more pythonic idiom of for i, char in enumerate(line): (taking into consideration that i becomes zero-based). This will automatically update i on each pass. -tkc OLD_INDENT = 5 # spaces NEW_INDENT = 4 # spaces print 'Reindent.py:' print '\nFrom file %s' % infile print 'Change %i space indentation to %i space indentation.' % ( OLD_INDENT, NEW_INDENT) print 'And place revised file into %s' % outfile whitespace = ' ' n = 0 nline = 0 for line in input.readlines(): nline += 1 # Only look at lines that start with a space. if line[0] == whitespace: i = 0 for char in line: i += 1 if char == whitespace: pass elif char == '\n': # Why do I need this for a blank line with only spaces? output.write(line) break else:# Why doesn't the blank line get picked up here? x = line.count(whitespace*OLD_INDENT,0,i) # Reindent lines that have exactly a multiple of OLD_INDENT. if x 0 and (i-1)%OLD_INDENT == 0: output.write(whitespace*NEW_INDENT*x+line.lstrip()) n += 1 break else: output.write(line) break else: output.write(line) input.close() output.close() print 'Total number of %i lines reindented out of %i lines.' % (n, nline) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do I require an elif statement here?
Jim, what you wrote should work correctly. I'm curious as to why you are doing it this way though. An easier way would be to take out all this character processing and use the builtin string processing. See this code: --- whitespace = old_indent = 3 new_indent = 5 x =starts with 3 spaces x = x.replace(whitespace*old_indent, whitespace*new_indent) --- In this example though, it will replace the 3 spaces no matter where they are at, not just in the beginning... still, it's probably more practical for most use cases. Jim wrote: Could somebody tell me why I need the elif char == '\n' in the following code? This is required in order the pick up lines with just spaces in them. Why doesn't the else: statement pick this up? OLD_INDENT = 5 # spaces NEW_INDENT = 4 # spaces print 'Reindent.py:' print '\nFrom file %s' % infile print 'Change %i space indentation to %i space indentation.' % ( OLD_INDENT, NEW_INDENT) print 'And place revised file into %s' % outfile whitespace = ' ' n = 0 nline = 0 for line in input.readlines(): nline += 1 # Only look at lines that start with a space. if line[0] == whitespace: i = 0 for char in line: i += 1 if char == whitespace: pass elif char == '\n': # Why do I need this for a blank line with only spaces? output.write(line) break else:# Why doesn't the blank line get picked up here? x = line.count(whitespace*OLD_INDENT,0,i) # Reindent lines that have exactly a multiple of OLD_INDENT. if x 0 and (i-1)%OLD_INDENT == 0: output.write(whitespace*NEW_INDENT*x+line.lstrip()) n += 1 break else: output.write(line) break else: output.write(line) input.close() output.close() print 'Total number of %i lines reindented out of %i lines.' % (n, nline) -- http://mail.python.org/mailman/listinfo/python-list
Re: Web Crawling/Threading and Things That Go Bump in the Night
Rem, what OS are you trying this on? Windows XP SP2 has a limit of around 40 tcp connections per second... Remarkable wrote: Hello all I am trying to write a reliable web-crawler. I tried to write my own using recursion and found I quickly hit the too many sockets open problem. So I looked for a threaded version that I could easily extend. The simplest/most reliable I found was called Spider.py (see attached). At this stage I want a spider that I can point at a site, let it do it's thing, and reliable get a callback of sorts... including the html (for me to parse), the url of the page in question (so I can log it) and the urls-found-on-that-page (so I can strip out any ones I really don't want and add them to the seen-list. Now, this is my question. The code above ALMOST works fine. The crawler crawls, I get the data I need BUT... every now and again the code just pauses, I hit control-C and it reports an error as if it has hit an exception and then carries on!!! I like the fact that my spider_usage.py file has the minimum amount of spider stuff in it... really just a main() and handle() handler. How does this happen... is a thread being killed and then a new one is made or what? I suspect it may have something to do with sockets timing out, but I have no idea... By the way on small sites (100s of pages) it never gets to the stall, it's on larger sites such as Amazon that it fails This is my other question It would be great to know, when the code is stalled, if it is doing anything... is there any way to even print a full stop to screen? This is my last question Given python's suitability for this sort of thing (isn't google written in it?) I can't believe that that there isn't a kick ass crawler already out there... regards tom http://www.theotherblog.com/Articles/2006/08/04/python-web-crawler-spider/ -- http://mail.python.org/mailman/listinfo/python-list
using an already running COM object with Dispatch
Greetings. with the following code, olApp = Dispatch(Outlook.Application) I am capable of getting a new instance of Outlook running. I would like to be able to use the instance that is already running, if exists, otherwise open a new one. Has anyone being able to do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do I require an elif statement here?
Jim wrote: Could somebody tell me why I need the elif char == '\n' in the following code? This is required in order the pick up lines with just spaces in them. Why doesn't the else: statement pick this up? No idea. Look at the profile of your program: for.. if.. for.. if.. else.. if.. This is NOT good. The reason why you are having trouble getting it to work is that you are not writing it in a way that is easy to debug and test. If one block of code ends up being indented halfway across the screen it means you are doing something wrong. This program should be split up into a handful of small functions that each do one thing. The following is slightly longer, but immensely simpler. Most importantly, it can be imported from the python shell and each function can be tested individually. def leading_spaces(line): Return the number of leading spaces num = 0 for char in line: if char != ' ': break num += 1 return num def change_indent(line, old, new): Change the indent of this line using a ratio of old:new ws = leading_spaces(line) #if there was no leading whitespace, #or it wasn't a multiple of the old indent, do nothing if ws == 0 or ws % old: return line #otherwise change the indent new_spaces = ws/old*new new_indent = ' ' * new_spaces return new_indent + line.lstrip(' ') def reindent(ifname, ofname, old, new): f = open(ifname) o = open(ofname, 'w') for line in f: line = change_indent(line, old, new) o.write(line) f.close() o.close() if __name__ == __main__: try : ifname, ofname, old, new = sys.argv[1:] old = int(old) new = int(new) except ValueError: print blah sys.exit(1) reindent(ifname, ofname, old, new) -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG Python Extension winth C++ Problematic
Hi skipthanks for replying I made a small test case that fails with a similar problem This is how it looks 1. Two simple classes A and B , each holds an integer.2. A has a function getB() that returns pointer to B. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\#ifndef __AB_H__#define __AB_H__class B{ public: int b; B( int num = 0 ){b = num; } ~B(){}}; class A{ public: int a; A( int a = 0 ){this-a = a; } ~A(){} B* getB(){ B* temp = new B(a); return temp; }};#endif __AB_H__ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\The swig file is as follows%module testcase%{#include AB.h%}%include AB.h/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\ Compilation commandsswig-1.3 -c++ -python -o swig.cc swig.ig++ -c -fPIC swig.cc -o swig.o -I /usr/local/include/python2.1/g++ -shared swig.o -o _testcase.so/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\ Python Filefrom testcase import *a = A() # works fineb = B() # works finec = a.getB() # crashes ( Segmentation Fault )/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\See if you can makeout something out of that --shekharOn 8/4/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have been working getting my C++ code to be used in Python ( Basically Extending ) This is the problem i am facing rite now. I have a function that returns a Pointer to a class in my C++ Code It looks like this... I have used SWIG to get the Glue code. When i call this function ( in python ) and it eventually returns ( when it gets a connection in this case ) it crashes ! I get a SEG FAULT ! Is it some thing that cannot be done ? I'm certainly no SWIG expert, however:1. Is your SLSocket class wrapped with SWIG?Do you maybe need a typemap?Can you explicitly create one from Python?If so, does that work? 2. What does your SWIG .i file look like?3. Finally, have you tried asking on the SWIG mailing list ([EMAIL PROTECTED])?There are probably many more SWIG experts there than here.Skip-- --shekhar -- http://mail.python.org/mailman/listinfo/python-list
Extending/Embedding Confusion
I am trying to learn how to extend and/or embed Python. I have looked at the document Extending and Embedding the Python Interpreter and also Python/C API Reference Manual. In the examples shown in Extending... there are some things I ma not familiar with so I turn to the index in the Reference Manual, but they are not listed. For example, PyEval_CallObject and PyDict_GetAttrString. My question is this: Is the documentation out of date or is the index not complete? Where can I get information about these things? Secondly, I am really struggling with understanding how to Extend/Embed Python. The examples given in the documentation are not as helpful as I would hope. Does anyone know of additional examples on the web that will shed some light on this issue? I have tried Google, but haven't yet been successful in finding additional examples that help. Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows vs. Linux
Duncan Booth wrote: Bryan Olson wrote: Duncan Booth wrote: Any other Microsoft commands I try all complain about 'invalid switch'. The first I noticed were their build tools. Their version of make, called nmake, and their visual studio tools will accept either forward or backward slashes in paths. Ok, pedantically I meant the commands that come as part of the system. Most external tools such as Microsoft's compilers have always accepted forward slashes interchangeably with backslashes. They also usually accept '-' as an option character interchangeably with '/'. The 'standard' commands though seem to go to a lot of effort to reject forward slashes in paths, and the CD command seems to be the only one where this usage gets through the net. That seems right, though I don't think Microsoft is deliberately being difficult. They never put much effort into the command line; they were trying to imitate the the Mac GUI more than the Unix shell. I just tried, and on XP the explorer will accept forward slashes, immediately re-displaying them as backslashes. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help building boost python on mac os x.
KraftDiner wrote: Could someone point me to step by step instructions on building boost python on mac os x? I have bjam running.. I have the boost source... but the tests are failing.. Probably something to do with environement variables... Anyone with time? You might also ask on the boost python list: http://www.boost.org/more/mailing_lists.htm HTH, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Which Python API for PostgreSQL?
I have been working with PostgreSQL for a while, and have just made the move to Python a couple of months ago. I noticed that there are at least 2 Python API's to PostgreSQL. I have looked at PygreSQL and PostgrePy. What are the advanatages and disadvantages of each? Which one do you use? What do you like about it? I appreciate any information that will help me to choose the best API. I plan on designing some data-entry applications in PyGTK that work with Python. My server will be running on a Linux box, but most of the clients will be connecting on MS Windows boxes. Thanks, Scott Huey -- http://mail.python.org/mailman/listinfo/python-list
paramter passing question
I wrote a small app in wxPython using wxGlade as designer tool. wxGlade brings and writes a lot of code by itself and thats where my confusion started. Its about parameter passing. Here is my little confusion. ***CODE BEGINS class MyFrame1(wx.Frame): def __init__(self, *args, **kwds): . . def OnEdit(self, event): sim_name = 'some_string' win = MyFrame2(self, -1, ) win.Show(True) class MyFrame2(wx.Frame): def __init__(self, *args, **kwds): . . def onLaunch(self, event): ## This function needs to use the parameter sim_name which is in class MyFrame1--OnEdit ***CODE ENDS I want to pass sim_name parameter to MyFrame2 in def OnEdit function but I don't know how to do it. I tried couple of things but always got some error. I have done some parameter passing in normal Python code but *args and **kwds is a little confusing. Could you please tell me how to send parameter sim_name from MyFrame1(in OnEdit function) and how to recieve it in MyFrame2 so that I can use that parameter in MyFrame2 namespace. Every help is appreciated. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Programming Games with python, I know this subject was disccused need help
HI I would like to start to program games, with python, where to start? What packages I need,? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Games with python, I know this subject was disccused need help
Well, with these libraries you won't need much else. http://www.pygame.org/news.html and http://sourceforge.net/projects/pyallegro/ Over G wrote: HI I would like to start to program games, with python, where to start? What packages I need,? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
super quick question
is there a prettier way to do this? string[:len(string)-1] thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Python API for PostgreSQL?
On 2006-08-04, Redefined Horizons [EMAIL PROTECTED] wrote: What are the advanatages and disadvantages of each? Which one do you use? What do you like about it? I would use psycopg: http://www.initd.org I believe it's the most full-featured postgres module. There's a windows installer. Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Games with python, I know this subject was disccused need help
Goalie_Ca wrote: Well, with these libraries you won't need much else. http://www.pygame.org/news.html and http://sourceforge.net/projects/pyallegro/ Over G wrote: HI I would like to start to program games, with python, where to start? What packages I need,? Thanks. Thanks ofr the very quick answer! Still can you shad more light on the second link, what is project allegro ? thanks/ -- http://mail.python.org/mailman/listinfo/python-list
Re: super quick question
Chris wrote: is there a prettier way to do this? string[:len(string)-1] thanks! string[:-1] Negative indices count from the end of the string! beautiful isn't it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pydev with Eclipse on OSX Q
On Aug 4, 2006, at 7:39 PM, Fabio Zadrozny wrote: On 8/4/06, Michiel Sikma [EMAIL PROTECTED] wrote: Hey guys. I'm trying to run Pydev on Eclipse on OSX, but I've got a problem that prevents me from making new projects in it. It seems that I cannot add my Python interpreter to the list of interpreters (it seems to do _something_ when I select it, but then ends up not adding it to the list). Are any of you guys familiar with this? Is there something I need to do before I can add my interpreter to that list? I'm on a G5 iMac and have the latest version of both programs. Have you checked your error log? (when adding an interpreter, there might be problems if you don't specify your real interpreter, but a link for it... (see bug http://sourceforge.net/ tracker/index.php? func=detailaid=1523582group_id=85796atid=577329 for details) or have spaces in your eclipse path (see bug http://sourceforge.net/ tracker/index.php? func=detailaid=1228027group_id=85796atid=577329 for details). Cheers, Fabio Hi Fabio, Thanks for your quick response! I was able to solve this. It seems I still wasn't using the right file; however, I didn't expect that I needed a 12 KB Unix executable. It didn't seem like the right file to me before. Looks like I'm in business. :) Michiel Sikma [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list