Re: how to remove BR using replace function?
Works for me. txt = an unfortunate br in the middle print txt.replace(br, ) an unfortunate in the middle Though I don't like the 2 spaces it gives ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way of finding terminal width/height?
It didn't insert an EOF, it just caused read() to return prematurely. You should call read() again until it receives a _real_ EOF and returns ''. Copy that. Point taken. There appear to be a couple problems with this description: 1) It says that read() in blocking mode without a size parameter it will read until EOF. This is not what happens when reading a terminal that receives SIGWINCH, so you're right: read() it isn't working as described. 2) It also says that it makes sense to continue to read a tty after you get an EOF. That's not true. Once you get an EOF on a tty, there's no point in reading it any more: you'll continue to get an EOF forever. Should I post a bug about this? /Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.path and unicode folder names
If few people use file names not in their respective CP_ACP as you say, why did Microsoft bother to make Windows XP a unicode OS? It does not make any sense. The existence of such bugs is the source of the problem itself. It is because of this situation that people in non-English speaking countries prefer to install English Windows XP. After all why should they get all messed up with incompatible software? And from my experience a considerable percent of these stay-on-the-safe-side users have their CP_ACP pages setup incorrectly. My software installs per-user Python modules in a sub-folder of the User's Application-Data folder. The software itself resides under Program-Files. The User's Application-Data folder will contain unicode characters if the User's account name contains unicode characters. You can argue that the design is good or wrong or can be altered to work around the problem, but the fact remains: Python is Broken. Martin v. Löwis wrote: Nir Aides wrote: Actually, I already managed to make a Patch for this problem. I will post it soon on my website and in this group. But I find it strange that this problem even exists, and that I could not find any workarounds on the Internet. Very few people use file names not in their respective CP_ACP (why do you need such filenames?), and virtually nobody wants to put such a file name on Python's sys.path (why do you want to? - just rename the directory and be done). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way of finding terminal width/height?
I realised there was funny indentation mishap in my previus email. My mail prog indented the following line signal.signal(signal.SIGWINCH, report_terminal_size_change) while in fact in IDLE it's unindented, which makes a lot more sense: signal.signal(signal.SIGWINCH, report_terminal_size_change) Sorry about that. /Joel Joel Hedlund wrote: You might want to try just setting a flag in the signal handler to see if that prevents the I/O operations on stdin/stdout from being interrupted. Tried this: source import signal, os, sys from terminal_info import get_terminal_size terminal_size = get_terminal_size() _bTerminalSizeChanged = False def report_terminal_size_change(signum, frame): global _bTerminalSizeChanged _bTerminalSizeChanged = True def update_terminal_size(): global _bTerminalSizeChanged, terminal_size terminal_size = get_terminal_size() _bTerminalSizeChanged = False signal.signal(signal.SIGWINCH, report_terminal_size_change) while True: # Do lots of IO (I'm trying to provoke exceptions with signal) open('/a/large/file').read() #raw_input() #sys.stdin.read() #print open('/a/large/file').read() if _bTerminalSizeChanged: update_terminal_size() print terminal_size /source As before, the only IO case above that doesn't throw exceptions is the uncommented one. Yup, that's the exception. Standard practice is to catch it and retry the I/O operation. Hmm... I guess it's not that easy to retry IO operations on pipes and streams (stdin/stdout in this case)... And I tend to lean pretty heavily on those since I usually write UNIX style text filters. So in case I haven't missed something fundamental I guess my best option is to accept defeat (of sorts :-) and be happy with picking a terminal width at program startup. But anyway, it's been really interesting trying this out. Thank you Grant (och Jorgen) for all help and tips! /Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: Natural Language Date Processing.
Andrew Gwozdziewycz schrieb: You may take a look at http://labix.org/python-dateutil Have fun Michael Looks like it does a good job parsing dates, but doesn't seem to do english dates. I found a javascript implementation of a few functions that will probably be relatively easy to port to python. Whether or not it'll perform well is another story... Thanks for the help. -- Andrew Gwozdziewycz [EMAIL PROTECTED] http://ihadagreatview.org http://plasticandroid.org from dateutil.parser import parse parse(April 16th, 2003) datetime.datetime(2003, 4, 16, 0, 0) parse(4/16/2003) datetime.datetime(2003, 4, 16, 0, 0) Aren't these english dates? Michael -- http://mail.python.org/mailman/listinfo/python-list
Inserting record with Microsoft Access
Hi, I am developing a python script which add records to a microsoft access tables. All my tables have autogenerated number fields. I am trying to capture the number generated from the insert but I am not exactly sure how to do that after an insert. Thanks, Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: by reference
dirvine: I would like to create a dictionary based on a variable [...] And what seems to be the problem? -- René Pijlman -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to get PIL to load jpeg images
Thanks for that tip Following a dialogue in that discussion group it is now working. The problem was that I didn't have the right jpeg library installed (although what I had was enough to show jpegs in gThumb, GIMP and the Gnome and KDE desktops so I don't understand why it wasn't). I had to also install a jpeg development library, which fortunately was available on my Fedora Core 3 installation disc. A final glitch was that the previous broken build interfered with the linking of PIL to the libraries. I went for overkill, and deleted all the PIL installation and site-packages directories, then reinstalled from the original tarball. This gave a curious glitch, in that the first time I ran it it failed to load Tkinter with some obscure error message, but on a retry everything was fine. This worries me slightly, as I don't know what happened and there is always a chance it could happen again, but until it does I can't investigate it. Slightly off topic, but I think my experience here is typical of any installation on a Linux system, and illustrates why, despite huge improvements over the last few years, Linux is not yet really suitable for non expert use. Thanks to everyone who's helped me over the last few months. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing curses (Was: Re: Problem with curses and UTF-8)
The code for handling window resizing isn't jumping out at me but I'll keep looking. (...jumping out, rather unexpectedly!) You might be interested in an ongoing discussion that I and Grant Edwards are holding in this newsgroup on the subject Best way of finding terminal width/height?. Thread summary: There's a function that Chuck Blake wrote for detecting the current terminal size, available here: http://pdos.csail.mit.edu/~cblake/cls/cls.py You'll only need the first two functions for this task (ioctl_GWINSZ and terminal_size). To monitor changes in window size, have a look at the signal module (in standard library). You can attach a monitor function to the signal signal.SIGWINCH, like so: signal.signal(signal.SIGWINCH, report_terminal_size_change) or, in context: --- #!/usr/bin/python from cls import terminal_size current_terminal_size = terminal_size() _bTerminalSizeChanged = False def report_terminal_size_change(signum, frame): global _bTerminalSizeChanged _bTerminalSizeChanged = True def update_terminal_size(): global _bTerminalSizeChanged, current_terminal_size current_terminal_size = terminal_size() _bTerminalSizeChanged = False signal.signal(signal.SIGWINCH, report_terminal_size_change) while True: if _bTerminalSizeChanged: update_terminal_size() print current_terminal_size -- Take care! /Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove BR using replace function?
Rinzwind wrote: Works for me. txt = an unfortunate br in the middle print txt.replace(br, ) an unfortunate in the middle Though I don't like the 2 spaces it gives ;) Although I generally advise against overuse of regular expressions, this is one situation where regular expressions might be useful: the situation is simple enough not to warrant a parser, but apart from the whitespace a br tag could have attributes or be written in xhtml style br /. Also judging by the inconsistency between the OP's subject line and his original question he doesn't seem sure whether the tag is br or BR or even Br. import re nobr = re.compile('\W*br.*?\W*', re.I) nobr.sub(' ', an unfortunate br / in the middle) 'an unfortunate in the middle' nobr.sub(' ', an unfortunate BR in the middle) 'an unfortunate in the middle' -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove BR using replace function?
Rinzwind wrote: Works for me. txt = an unfortunate br in the middle print txt.replace(br, ) an unfortunate in the middle Though I don't like the 2 spaces it gives ;) so use regex and replace both the double spaces and the br cheers albert -- http://mail.python.org/mailman/listinfo/python-list
OT: Another try at Python's selfishness
DH [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Frithiof Andreas Jensen wrote: [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Having read previous discussions on python-dev I think I'm not the only Python programmer who doesn't particularly like python's self parameter: Ok, there might be five programmers and one imam. The imam does not like anything more recent than 700 A.D ... You Danes and your Muslim jokes :) ;-) A culture thing, that: They are now accepted as part of society, so we treat them equally to the people from Århus, Copenhagen, West-Jutland, Sout-Jutland, Bornholm and Mols (a tiny area 30 km from Århus). If we did not care for them, we would not poke fun at them occasionally. So far, I think the integration has really improved a lot because this affair has clearly shown that the Danish muslims are pretty much like everyone else here. The ethnic kiosks still sell Jyllands Posten, the Danish still buy groceries in ethnic shops e.t.c. Like Normal. No riots, looting and threats from hooded cowards and bullies. What we instead have learned are that the Imams - some of which have been given asylum - are blatantly lying and falsifying evidence in order to slander the country that pay their social security when the very first opportunity arises. Maybe those people should not be here in the first place. We have also learned that there is no point in getting involved in dialogue, export grants (i.e. bribes) and foreign aid money (more bribes) with dictatorships and defunct states. The effort should be directed elsewhere, where it is actually any use. Finally we can take comfort in knowing that the lunatic segment in the population is clearly less than 1500 out of 5,000,000 people - although the loonies do get 80% of the media coverage (like f.ex. the 300 autonomen that just *had* to be the only violent segment in a media-hyped confrontational demo with 30(!) neo-nazis, 200 muslims and about half the Danish police force present in riot gear - Great Plan Einstein; ). The TeeVee news should be relabeled Fools Hour - their mantra seems to be that if you want the opinion of any large group, go seek out the village idiot and ask him. The conclusion is that the *real* threat to democracy does *not* come from the lunatic segment but from connected people with nice suits and vested interests such as the Danish Industri Association that are clearly willing to take in a used Sharia as part of a trade. They worked for Hitler too and has clearly learned nothing!! PS: If one was trying to detect fanatics of any creed, a certain indicator would be that they have absolutely no sense of humour - they suffer from a yet-to-be-described variant of autism I.M.O. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove BR using replace function?
[EMAIL PROTECTED] wrote: i have some html that looks like this address style=color:#34 main,br Boston, MA/address and i am trying to use the replace function to get rid of the Br that i scrape out using this code: for oText in incident.fetchText( oRE): strTitle += oText.strip() Why concatening ? strTitle = string.replace(strTitle,'br','') Use strTitle.replace('br', '') instead. And BTW, hungarian notation is evil, so: for text in incident.fetchText(...): title = text.strip().replace('br', '') but it doesn't seem to remove the br it does : Python 2.4.2 (#1, Feb 9 2006, 02:40:32) [GCC 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type help, copyright, credits or license for more information. s = 'address style=color:#34 main,br Boston, MA/address' s.replace('br', '') 'address style=color:#34 main, Boston, MA/address' The problem is obviously not with str.replace(), as you could have figured out by yourself very easily. any ideas? yes: post the minimal *running* code that exhibit the problem. Your problem is probably elsewhere, and given some of previous posts here ('problems writing tuple to log file' and 'indentation messing up my tuple?'), I'd say that a programming101 course should be your first move. -- 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: PyGTK
Well I have just started using Python and have found wxPython to be pretty good, it is built upon the WxWindows framework.It is also cross-platform. You can find it at www.wxpython.org. It appears to be easy to understand and there are a few GUI builder tools around for it as well. Rod -- http://mail.python.org/mailman/listinfo/python-list
Using ioctl
Hello, I am writing an app that records from the soundcard using ossaudiodev. In the OSS programmer's guide they recommend when reading data fragments from the soundcard to use the fragment size as it is requested by the driver. According to the programmer's guide the ioctl call to determine the requested fragment size is: int frag_size; if ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, frag_size) == -1) error(); Unfortunately this procedure is not implemented in the ossaudiodev module, so I tried to write it myself. From reading the fcntl module's docs, I came to the following solution: try: f = array.array('h', [0]) fcntl.ioctl(audio_fd, ossaudiodev.SNDCTL_DSP_GETBLKSIZE, f, 1) frag_size = f.tolist()[0] except: frag_size = -1 if frag_size = 0: frag_size = 4096 This *seems* to work, I tried several soundcards and got frag_size values like 4096, 8192 or 16384 . However I am not really sure about what I am doing there, so I would feel more confident if anyone could explain how ioctl is supposed to be used ( I also felt that I should use the try...except block for the call in case it fails, but I don't have an idea except *what*). Any hints are much appreciated. thanks in advance Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: module with __call__ defined is not callable?
Op 2006-02-08, Steve Holden schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Op 2006-02-08, Steve Holden schreef [EMAIL PROTECTED]: Why should a module be callable? What's the advantage? Should we be able to add two modules together, yielding a module that contains all the code of both modules? What happens if I multiply a module by two - presumably the result should be the same as adding a module to itself? Perhaps we should be able to divide a module by a function? The pursuit of orthogonality, while admirable, can lead to insanity if pushed too far. This is not an argument. This doesn't give a clue about where to stop this pursuit en when to go on. Well, let's say we should stop short of unsane behavior. That's a phrase you should understand. I don't agree, what some consider insane is a stroke of genius by someone else. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: module with __call__ defined is not callable?
Op 2006-02-08, Scott David Daniels schreef [EMAIL PROTECTED]: Steven D'Aprano wrote: On Wed, 08 Feb 2006 13:58:13 +1100, Delaney, Timothy (Tim) wrote: adam johnson wrote: Hi All. I was wondering why defining a __call__ attribute for a module doesn't make it actually callable. For the same reason that the following doesn't work [snip example] The __call__ attribute must be defined on the class (or type) - not on the instance. A module is an instance of type 'module'. That's not a _reason_, it is just a (re-)statement of fact. We know that defining a __call__ method on a module doesn't make it callable. Why not? The answer isn't because defining a __call__ method on a module or an instance doesn't make it callable, that's just avoiding the question. You missed it. Steven D'Aprano was telling you why, and all you heard was the no. He stated a more general principal which controls why modules in particular are not callable. It is not a design decision about modules; it is a design decision about classes and instances. class SomeClass(object): def __call__(self): return 'Text' class AnotherClass(object): def __repr__(self): return 'Missive' name = SomeClass()() # this works name = AnotherClass()() # this doesn't obj = AnotherClass() # build an instance def fun(*args): return 'more text' # *args so nearly any call works obj.__call__ = fun# tack a function onto an instance obj() # note this doesn't call the function. Now, if you think the last _should_ do the call, then let's step back to classes. class SomeClass(object): def __call__(self): return 'Text' Now the SomeClass object (which is a subclass of object) has an attribute named __call__. Should that define how the expression SomeClass() is evaluated? Should that return the string 'Text' or create a new instance of SomeClass? This make me wonder. Would it be possible to do something with metaclasses so that after class SomeClass(MetaClass): ... SomeClass() will be equivalent to MetaClass.__call__(SomeClass) Just curious. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: module with __call__ defined is not callable?
Steve Holden [EMAIL PROTECTED] writes: Right. While we're at it, why don't we make strings callable. Calling a string could call the function whose name (in some namespace or other) was in the string. Making a string subclass callable works fine: class f(str): ... def __call__(self): print len(self) ... z=f('foo') z 'foo' z() 3 Why should a module be callable? What's the advantage? I've wanted to be able to say import frotz x = frotz(23) instead of having to say from frotz import frotz or x = frotz.frotz(23). That kind of cruft pervades code that uses the standard library and callable modules could clean a lot of it up. No more random.random, sha.new, etc. Just call the module to make an instance of the class it defines. Should we be able to add two modules together, yielding a module that contains all the code of both modules? What happens if I multiply a module by two - presumably the result should be the same as adding a module to itself? Perhaps we should be able to divide a module by a function? There should be no built-in definitions of those operations but if you're a duck-typing believer, it's clear what __add__ etc. should do. -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted book opinions?
Jay Parlar [EMAIL PROTECTED] writes: I was hoping to get some c.l.p. opinions on O'Reilly's new Twisted book. Well I certainly felt that I understood it better after reading the book. OTOH I haven't tried to put that knowledge into practice yet. I think calling it a cookbook is misleading, it shows how to do essential tasks using fairly complete examples. Eddie -- http://mail.python.org/mailman/listinfo/python-list
Re: module with __call__ defined is not callable?
Antoon Pardon wrote: This make me wonder. Would it be possible to do something with metaclasses so that after class SomeClass(MetaClass): ... SomeClass() will be equivalent to MetaClass.__call__(SomeClass) I think that's already what happens. IIUC type.__call__ implements the standard class creation calling __new__ and __init__. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK
Huy wrote: What I am curious to know is whether anyone has come across any noteworthy gui development platforms. Cross compatibility is not a must, but a bonus. Good documentation and clarity is essential for me. Also, I imagine I can use modules for image manipulation in tandem with the GUI interface? Any comments or speculations are looked forward to. Just thought I'd see if there's anything out there the community knows I may not be currently aware of. PyQt is very easy to use and Qt is well documented, see http://www.riverbankcomputing.co.uk/pyqt/ The main issue is whether the licence of your code is compatible with the GPL licensing of Qt and PyQt. If not you will need a commercial license. I've used it in combination with numarray for image manipulation (however NumPy is probably better than numarray now). I suppose it depends on what sort of image manipulation you need. Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting record with Microsoft Access
jeffhg582003 wrote: Hi, I am developing a python script which add records to a microsoft access tables. All my tables have autogenerated number fields. I am trying to capture the number generated from the insert but I am not exactly sure how to do that after an insert. Thanks, Jeff I had to do something similiar in sql server and the experts back then told me that the only way is to write a stored procedure. aparently sql server does not have sequences and I am guessing that access is the same. cheers albert -- Albert Leibbrandt Data Manager CompuScan Holdings (Pty) Ltd Brandwacht Office Park Stellenbosch. South Africa. Tel;+27 (0)21-8886000 Fax;+27 (0)21-8832336 National: 0861 51 41 31 E-Mail : [EMAIL PROTECTED] www.compuscan.co.za - reducing credit risk and fraud, at the same time protecting the consumer against over-indebtedness and reckless borrowing www.techtonic.co.za - a software design and development, information management and internet solutions company www.csti.co.za - a skills training and development provider to the Micro Finance sector (BANKSETA accredited) Confidentiality: The information contained in this e-mail and any attachments thereto is private and confidential and is intended for the eyes of the addressees only. Access to this e-mail by any other person or any attachment is not authorized and accordingly prohibited. If you are not the authorized and intended recipient, any disclosure, copying, dissemination or distribution, any other action of omission by you with respect to the information in this e-mail and attachments is prohibited and unlawful. -- http://mail.python.org/mailman/listinfo/python-list
thread dump
I'm using Fedora core 3 and python 2.4.2, is there any way to obtain the linux pid of a python thread? I need it because I want to know CPU usage per thread. Thanks -- http://mail.python.org/mailman/listinfo/python-list
line wrapping problem
Hello, I am parsing text from one document to another. I have a scheme similar to: for x in myfoobar: print mytextfile, %s % mydictionary[x], #all on same line print mytextfile, '\n' #new line I am getting line breaks before my explicit line break. Am I unwittingly copying '\n' characters from the original file? How should I fix this(What is the 'Pythonic' solution)? thanks, -S -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted book opinions?
Eddie Corns wrote: Jay Parlar [EMAIL PROTECTED] writes: I was hoping to get some c.l.p. opinions on O'Reilly's new Twisted book. Well I certainly felt that I understood it better after reading the book. OTOH I haven't tried to put that knowledge into practice yet. I think calling it a cookbook is misleading, it shows how to do essential tasks using fairly complete examples. It's really more of an example based tutorial book than cookbook. What it does do really well is 'networking programming essentials'. I found it quite a good book and managed to write a distributed ssh cron tool in an evening after reading the sections on SSH. What I'd really like now is a 'Web Application Development with Twisted/Nevow' book that takes off where this 'network protocol' oriented book leaves off. Tim Parkin -- http://mail.python.org/mailman/listinfo/python-list
Thread Dump of a python process
Hi, I would to know if there're some way to have a dump of all the threads started by a python process. I want to see the TID corresponding of each thread because I need them to get the CPU time of each thread by the command top. Thanks -- View this message in context: http://www.nabble.com/Thread-Dump-of-a-python-process-t1089322.html#a2840609 Sent from the Python - python-list forum at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing curses
Ian Ward [EMAIL PROTECTED] wrote: I'm going to look at the Mined text editor for some terminal behavior mined_2000 (there's more than one program named mined, and the other doesn't do UTF-8). detection code. Mined is able to produce good UTF-8 output on a variety of terminals, and it links agains ncurses, not ncursesw... Interesting. It's probably using termcap (and the wide-character functions declared in wchar.h). -- Thomas E. Dickey http://invisible-island.net ftp://invisible-island.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted book opinions?
Jay Parlar wrote: I was hoping to get some c.l.p. opinions on O'Reilly's new Twisted book. I think it's a good book to get. I know a fair amount about Twisted but it still made for interesting reading. Tommi Virtanen (aka tv) posted a great review of the book shortly after it was published. http://tv.debian.net/articles/review-snakeball/. - Matt -- http://mail.python.org/mailman/listinfo/python-list
LovePython
http://www.lovepython.com/ (a reaction to loveperl.com) This is going to be a weekend project for me. Development not yet started. Still looking for good ideas! I welcome your suggestions. -- Sridhar Ratna | [EMAIL PROTECTED] | http://www.24dot1.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting record with Microsoft Access
I can't remember the detail right now but look at SELECT @@IDENTITY. Cheers, Davy M -- http://mail.python.org/mailman/listinfo/python-list
Re: line wrapping problem
S Borg wrote: Hello, I am parsing text from one document to another. I have a scheme similar to: for x in myfoobar: print mytextfile, %s % mydictionary[x], #all on same line print mytextfile, '\n' #new line You are using the print command to output the text to your file. This will always put a '\n' at the end of lines (as well as your explicit) one. The only time it doesn't do this is if the line ends with a trailing comma, in which case it just adds a space. The usual way is to write to yhour file object using : mytextfile.write( mytextfile, %s % mydictionary[x],) All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml I am getting line breaks before my explicit line break. Am I unwittingly copying '\n' characters from the original file? How should I fix this(What is the 'Pythonic' solution)? thanks, -S -- http://mail.python.org/mailman/listinfo/python-list
Hi reliability files, writing,reading,maintaining
Hello, help/advice appreciated. Background: I am writing some web scripts in python to receive small amounts of data from remote sensors and store the data in a file. 50 to 100 bytes every 5 or 10 minutes. A new file for each day is anticipated. Of considerable importance is the long term availability of this data and it's gathering and storage without gaps. As the remote sensors have little on board storage it is important that a web server is available to receive the data. To that end two separately located servers will be running at all times and updating each other as new data arrives. I also assume each server will maintain two copies of the current data file, only one of which would be open at any one time, and some means of indicating if a file write has failed and which file contains valid data. The latter is not so important as the data itself will indicate both its completeness (missing samples) and its newness because of a time stamp with each sample. I would wish to secure this data gathering against crashes of the OS, hardware failures and power outages. So my request: 1. Are there any python modules 'out there' that might help in securely writing such files. 2. Can anyone suggest a book or two on this kind of file management. (These kind of problems must have been solved in the financial world many times). Many thanks, John Pote -- http://mail.python.org/mailman/listinfo/python-list
Breadth first problem
Hi, I would like to implement a breadth first serach with Python and read data from a text file with following file format File structure description First line contains number of node Second line containsnode id(s) and distance between node id Last line is -1 number of node N1N2W1 Each node or distance is separated by space -1 For the example below, first line represent number of node is 10, second line contains first node id 0, second node id 1, distance between node id 0 and node id 1 is 2 0 is the root (starting node), the aim of the searching programis to find out the shortest path from 0 to a leaf node and print out the node path and value the path distance Could you give me any idea how to implement this search program with Python? Example: 100 1 20 5 31 2 21 3 42 1 32 3 15 6 35 7 16 8 17 8 17 9 29 5 3-1 Outcome:Possible solution:Path=0,1,2,3length=5Path=0,5,6,8length=5Path=0,5,7,8length=5 Thank you foryour help. I attached program part that I implemented, however, I am not sure what's wrong of the program logic that I cannot get the correct answer. Nicky. If you have any idea, could you please reply me at [EMAIL PROTECTED] tes3 Description: Binary data -- http://mail.python.org/mailman/listinfo/python-list
Re: line wrapping problem
S Borg wrote: Hello, I am parsing text from one document to another. I have a scheme similar to: for x in myfoobar: print mytextfile, %s % mydictionary[x], #all on same line print mytextfile, '\n' #new line I am getting line breaks before my explicit line break. Am I unwittingly copying '\n' characters from the original file? How should I fix this(What is the 'Pythonic' solution)? thanks, -S mytextfile.write(%s % mydictionary[x]) should work. IMO file.write() is self-explanatory but print file is a bit obscure. -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting record with Microsoft Access
Albert Leibbrandt wrote: jeffhg582003 wrote: Hi, I am developing a python script which add records to a microsoft access tables. All my tables have autogenerated number fields. I am trying to capture the number generated from the insert but I am not exactly sure how to do that after an insert. I had to do something similiar in sql server and the experts back then told me that the only way is to write a stored procedure. aparently sql server does not have sequences and I am guessing that access is the same. Well the experts were wrong, I suspect. Try SELECT @@IDENTITY to return the autonumber key created by the most recent INSERT. I believe this works for both SQL Server and Access (doesn't anyone use Google any more?). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
importing maple into python
Hello, Is there for a python program to call maple? Walter Kehowski -- -- http://mail.python.org/mailman/listinfo/python-list
Curios issues with Editors
I recently wrote a program in IDLE and it runs perfectly. However when the same application is executed within SPE I receive errors saying that certain socket items are not callable, in particular AF_INET. I am new to Python, is there a reason why somethings will run in IDLE and not SPE? I could post the source code but it is changing quite a bit, so this is more of a general question than one about a specific bug or issue. Best, Rod -- http://mail.python.org/mailman/listinfo/python-list
Re: Curios issues with Editors
rodmc wrote: I recently wrote a program in IDLE and it runs perfectly. However when the same application is executed within SPE I receive errors saying that certain socket items are not callable, in particular AF_INET. I am new to Python, is there a reason why somethings will run in IDLE and not SPE? I could post the source code but it is changing quite a bit, so this is more of a general question than one about a specific bug or issue. I think you are fooling yourself about this error. import socket type(socket.AF_INET) type 'int' You would appear to have some code that reads something like socket.AF_INET( ... ) which is clearly wrong, since AF_INET is an integer intended to indicate the address family required at the creation of a socket. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: removing characters before writing to file
As mentioned in the thread, it makes sense to build the desired output you want from the tuple, rather than converting the tuple to a string and then doing replace operations on the string. If you do want to go the replace route, you don't need the power of regex substitutions for what you are interested in. Just try the replace method: foo = ('sometext1', 1421248118, 1, 'P ') foo.replace(\', ).replace((, ).replace(), ) 'sometext1, 1421248118, 1, P ' or, more elegantly: .join([x for x in foo if x not in ['(',')','\''] ]) 'sometext1, 1421248118, 1, P ' However, all of these replace-based solutions are bad because they will not only replace the apostrophes and parentheses between the strings, but also within them; what if sometext1 is actually John's Text? You are much better off building your desired output from the actual tuple data yourself. [EMAIL PROTECTED] wrote: hi i have some output that returns a lines of tuples eg ('sometext1', 1421248118, 1, 'P ') ('sometext2', 1421248338, 2, 'S ') and so on I tried this re.sub(r '() ,'',str(output)) but it only get rid of the ' and not the braces. I need to write the output to a file such that sometext1, 1421248118, 1, P sometext2, 1421248338, 2, S I also tried escaping , re.sub(r '\(\) ,'',str(output)) but also did not work How can i get rid of the braces before writing to file? thanks -- http://mail.python.org/mailman/listinfo/python-list
problems opening IDLE
I'm having trouble with opening the IDLE and running programs. Every time I try to open it, it says: 1. Socket error: Connection refused 2. IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection. Point is, I allready entered python as an exception to my firewall and when I disable it, the messages keep apearing. Can anyone help? Bennie Tilma _ Een audiogesprek? Pak Messenger, niet de telefoon http://www1.imagine-msn.com/Messenger/Video.aspx -- http://mail.python.org/mailman/listinfo/python-list
Re: line wrapping problem
S Borg wrote: print mytextfile, '\n' #new line Wouldn't this print two line breaks--the one you specify in the string, plus the one always added by print if there is no comma at the end of the statement? -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK
On 2006-02-08, Huy [EMAIL PROTECTED] wrote: Hi, I'm new to Python, and GUI development, but am no novice to backend programming. Aside from mastering the standard language, I will eventually be developing applications dealing with images and controls. Thus forth I have been testing out PyGTK it appears to be quite robust (that and I like the fact of cross-platform compatibility). This article may be of interest http://pygtk.org/articles/bitpodder/BitPodder.htm particularly the last section on how to create an EXE from your pygtk program. Found at http://pygtk.org Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: Number Format function
Rick Zantow [EMAIL PROTECTED] wrote: print number_format( 2312753.4450, 2 ) 2,312,753.44 print number_format( 2312753.4451, 2 ) 2,312,753.45 I would expect the first to produce the same results as the second, but, I suppose because of one of floating point's features, it doesn't work that way. 2312753.4450 2312753.444998 2312753.4451 2312753.445101 So, yeah, the nature of floating points is going to make that first one round unexpectedly. -- \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: Curios issues with Editors
As I said I am most likely to have made an error, being a newbie and all that. Here is the offending function. I said i would not post source code but there you go... As I said I plan to change this function, so it will no doubt be out of date quite soon. def senddata(msg): host = localhost port = 21568 buf = 1024 addr = (host,port) UDPSock = socket(AF_INET,SOCK_DGRAM) UDPSock.sendto(msg,addr) UDPSock.close() cheers, rod -- http://mail.python.org/mailman/listinfo/python-list
Re: problems opening IDLE
Bennie Tilma wrote: I'm having trouble with opening the IDLE and running programs. Every time I try to open it, it says: 1. Socket error: Connection refused 2. IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection. Point is, I allready entered python as an exception to my firewall and when I disable it, the messages keep apearing. Can anyone help? Call idle with the -n option idle-python2.4 -n idle.py -n ... -- http://mail.python.org/mailman/listinfo/python-list
Re: line wrapping problem
Ciao, Juho Schultz! Che stavi dicendo? should work. IMO file.write() is self-explanatory but print file is a bit obscure. is obscure only if you have never used a shell :) -- Evangelion e' la storia yaoi di un angelo che vuole portarsi a letto un ragazzo che si intreccia con la storia di un maturo professionista con il complesso delle lolite... fatte in casa. -- Lennier, 2006 -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove BR using replace function?
Duncan Booth [EMAIL PROTECTED] wrote: Although I generally advise against overuse of regular expressions, this is one situation where regular expressions might be useful: [ ... ] nobr = re.compile('\W*br.*?\W*', re.I) Agreed (on both counts), but r'\s*br.*?\s*' might be better (consider what happens with an unfortunate... br in the middle if you use \W rather than \s). -- \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: apostrophe or double quote?
Terry Hancock [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Just to present a complete picture, not mentioned in this thread are triple-quoted strings: [ ... ] Also in the mode of beating a dead horse ... ;-) Some people prefer to use single quotes for 'labels' (i.e. a name which is meaningful to the program, but not to the user), and reserve either double-quotes or triple-double-quotes for text to be shown to the user. [ ... ] Hmm, I made both these points a couple of posts upthread, but it didn't appear to get through the news-mail gateway. -- \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: removing characters before writing to file
[EMAIL PROTECTED] wrote: i have some output that returns a lines of tuples eg ('sometext1', 1421248118, 1, 'P ') ('sometext2', 1421248338, 2, 'S ') and so on I tried this re.sub(r '() ,'',str(output)) but it only get rid of the ' and not the braces. I need to write the output to a file such that sometext1, 1421248118, 1, P sometext2, 1421248338, 2, S I also tried escaping , re.sub(r '\(\) ,'',str(output)) but also did not work How can i get rid of the braces before writing to file? thanks I'd use a csv.writer: import csv, sys data = [ ... ('sometext1', 1421248118, 1, 'P '), ... ('sometext2', 1421248338, 2, 'S ') ... ] w = csv.writer(sys.stdout) w.writerows(data) sometext1,1421248118,1,P sometext2,1421248338,2,S Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: line wrapping problem
S Borg wrote: I am parsing text from one document to another. I have a scheme similar to: for x in myfoobar: print mytextfile, %s % mydictionary[x], #all on same line print mytextfile # minimal fix I am getting line breaks before my explicit line break. Am I unwittingly copying '\n' characters from the original file? How should I fix this(What is the 'Pythonic' solution)? The trailing spaces are probably an artifact of your implementation. Here's one way to avoid them: print mytextfile, .join(str(mydictionary[x]) for x in myfoobar) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: module with __call__ defined is not callable?
Kent Johnson wrote: Antoon Pardon wrote: This make me wonder. Would it be possible to do something with metaclasses so that after class SomeClass(MetaClass): ... SomeClass() will be equivalent to MetaClass.__call__(SomeClass) I think that's already what happens. IIUC type.__call__ implements the standard class creation calling __new__ and __init__. You are a layer of abstraction off. class SomeClass(MetaClass): ... creates a subclass of MetaClass, (the superclass of SomeClass). SomeClass is still an instance of type (assuming new-style classes). class FunnyType(type): ... defines a new metaclass, which can affect how instances of FunnyType behave. For a ridiculous example: class FunnyType(type): def __call__(self, *args, **kwargs): if 'please' in kwargs and kwargs['please']: kwargs.pop('please') return super(FunnyType, self).__call__(*args, **kwargs) print 'Nope, use your words:', args, kwargs class SomeClass: __metaclass__ = FunnyType def __repr__(self): print 'Lucky_%s' % id(self) OK, now: v = SomeClass(please=True) print v works, but v = SomeClass() doesn't, nor does: v = SomeClass(please=False) Think aboutwhat this code should do before running it, the mental exercise is fun. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: removing characters before writing to file
[EMAIL PROTECTED] wrote: hi i have some output that returns a lines of tuples eg ('sometext1', 1421248118, 1, 'P ') ('sometext2', 1421248338, 2, 'S ') and so on I tried this re.sub(r '() ,'',str(output)) but it only get rid of the ' and not the braces. I need to write the output to a file such that sometext1, 1421248118, 1, P sometext2, 1421248338, 2, S I also tried escaping , re.sub(r '\(\) ,'',str(output)) but also did not work How can i get rid of the braces before writing to file? thanks If it is as uniform as shown, may be you can strip them. ('something', 1234, 1, 'P ').strip( ()) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using ioctl
[EMAIL PROTECTED] wrote: From reading the fcntl module's docs, I came to the following solution: try: f = array.array('h', [0]) fcntl.ioctl(audio_fd, ossaudiodev.SNDCTL_DSP_GETBLKSIZE, f, 1) frag_size = f.tolist()[0] except: frag_size = -1 if frag_size = 0: frag_size = 4096 I would feel more confident if anyone could explain how ioctl is supposed to be used ( I also felt that I should use the try...except block for the call in case it fails, but I don't have an idea except *what*). Fairly normal practice is to wait for a failure (or try to instigate one) _without_ the try: ... except: ..., and then use the one you get. Or, you could go for IOError, which sounds right to me. remember your current except: is catching any attempt at KeyBoardEscape (Control-C, Control-Break, and such like). --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Parsing XML scheme (xsd) to python objects
I have a XML scheme (xsd) from which I have created with xjc (a java binding compiler (JAXB)) my java objects with all the get and set methods. Now I have to use this scheme and do the same in python but I can't find a tool which can read the scheme. I already tried generateDS.py but it couldn't parse the data. Does anyone know a tool which compiles my scheme and creates an object library in python? Regards, Matthias -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
Bryan Olson wrote: The original question was about idioms and understanding, but there's more to the case for list.clear. Python is duck typed. Consistency is the key to polymorphism: type X will work as an actual parameter if and only if X has the required methods and they do the expected things. Emptying out a collection is logically the same thing whether that collection is a list, set, dictionary, or user-defined SortedBag. When different types can support the same operation, they should also support the same interface. That's what enables polymorphism. I agree that emptying is logically the same thing for all of these types. Beyond that, they don't seem to have a lot in common. It's quite possible to support a duck typing approach that works for all sorts of sequences, but it's fairly meaningless to use ducktyping for conceptually different types such as dicts, lists and sets. Do you really have a usecase for this? It seems to me that your argument is pretty hollow. For lists, which are mutable sequences, you add new data with .insert, .append or .extend. You replace or remove existing data using indexing l[x] or slicing l[x:y] in del or assignment statements. You can also remove data with .pop or .remove. These overlapping methods have specific use. l.remove(x) is short for del l[l.index(x)] (it's also faster, and that sometimes matter) and .pop() is there to support a stack-like behaviour. Dicts use indexing d[x] or .update to either add new data or to replace existing data. There is no distinction between these operations in dicts, since dicts are semantically so different from sequences. They have content, but no order, no specific positions. You can delete one item at a time with del d[x], but since slices don't make sense for dicts, there is a d.clear() method to achieve this common task quickly. One could imagine that it was allowed to write del d[] or something like that, but then we also expect x = d[] and d[] = x to work... We probably don't want that. Sets are also semantically different, and thus use a different set of operations. They share the lack of order with dicts, but they aren't pairs, so the semantics is naturally different. They don't support indexing at all, since they neither have order nor keys. As far as I understand, the only operation which is currently used by all three collections is .pop, but that takes a different number or parameters, since these collections are conceptually different! Then we have Queues. They have a different purpose, and again, a different API, since they provide features such as blocking or non- blocking reads and writes. -- http://mail.python.org/mailman/listinfo/python-list
Re: by reference
Rene Pijlman wrote: dirvine: I would like to create a dictionary based on a variable [...] And what seems to be the problem? I think that this is his problem: 'somename'={} SyntaxError: can't assign to literal But I'm puzzled why he wants that route, while I'm still pretty new to programming, I usually smell a design fault when I want to try to squeeze a literal name into a object variable (am I'm saying this correct?). Most of the time nesting dictionaries will do the trick for me: sharedDict=dict() sharedDict['somename']=dict() sharedDict['someothername']=dict() sharedDict {'somename': {}, 'someothername': {}} -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: Curios issues with Editors
How do you run your code in SPE? I advise you to run it with ToolsRun/Stop (Ctrl+R) There would be no reason why it wouldn't work. Stani -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting Tkinter Text contents before destruction
On Mon, 6 Feb 2006 20:11:28 -0700, Bob Greschke [EMAIL PROTECTED] wrote: Hi! I want to grab the contents of a Text widget when the frame it's on gets destroyed. I tried TextWidget.bind(Destroy... , but the widget is gone before the call gets made, and I'd really hate to do something with the function that gets called with TextWidgetsFrame.bind(Destroy, ..., since that one function handles all of the frames in the program...or would that even work? How can I do this? One way is to define the deletion callback for the text's parent window to get the text before the widget gets deleted. To do that, you can use text.winfo_toplevel() to get the parent Toplevel for your text widget, then define the callback via wdw.protocol('WM_DELETE_WINDOW', ...). Here is a detailed example: - from Tkinter import * root = Tk() txt = None def openWdw(): global txt wdw = Toplevel() frm = Frame(wdw) frm.pack(expand=1) txt = Text(frm) txt.pack() print txt.winfo_toplevel(), frm, root txt.winfo_toplevel().protocol('WM_DELETE_WINDOW', getText) def getText(): print txt.get(1.0, END) txt.winfo_toplevel().destroy() Button(root, text='Go', command=openWdw).pack() root.mainloop() - This will of course only work if the only reason for which the text widget can be destroyed is if its parent window is closed. HTH -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to get PIL to load jpeg images
[EMAIL PROTECTED] wrote: The problem was that I didn't have the right jpeg library installed (although what I had was enough to show jpegs in gThumb, GIMP and the Gnome and KDE desktops so I don't understand why it wasn't). I had to also install a jpeg development library, which fortunately was available on my Fedora Core 3 installation disc The problem is in the name chosen by _lots_ of distributions. A jpeg developer library or any other of the development libraries are not just for those who intend to develop jpeg, but really for those who develop programs -- that is run compilers and linkers. If you need to compile and link a program that uses one of these libraries, you need the developer library. Even if the only sense in which you are a developer is that you are rebuilding Fredrik's code. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: email questions
On Thu, 2006-02-09 at 00:50, Dennis Lee Bieber wrote: On Wed, 8 Feb 2006 10:49:27 -0800, Scott Frankel [EMAIL PROTECTED] declaimed the following in comp.lang.python: mail.ispname.net Not sure why you feel you need to hide it -- I'm presuming it is the same ISP in your email address... However, I'm currently finding a dead access to it... C:\Documents and Settings\Dennis Lee Biebertracert smtp.pacbell.net Unable to resolve target system name smtp.pacbell.net. C:\Documents and Settings\Dennis Lee Biebertracert mail.pacbell.net Tracing route to mail.pacbell.net [207.115.57.20] over a maximum of 30 hops: 1 1 ms1 ms1 ms 192.168.1.1 217 ms13 ms14 ms user-11fa401.dsl.mindspring.com [66.245.16.1] 313 ms13 ms15 ms cor02-vl-10.ca-sanfranc0.ne.earthlink.net [209.165.103.65] 416 ms13 ms16 ms bor01-ge-6-1.ca-sanfranc0.ne.earthlink.net [209.165.103.17] 522 ms22 ms22 ms bor02-so-3-1.ca-pasadena0.ne.earthlink.net [209.165.109.154] 623 ms27 ms31 ms bor01-ge-1-1-0.ca-losangel4.ne.earthlink.net [209.165.107.182] 728 ms21 ms22 ms ex1-g8-1s1.eqlaca.sbcglobal.net [206.223.123.79] 824 ms22 ms23 ms ex2-p3-0.eqlaca.sbcglobal.net [151.164.191.226] 925 ms24 ms24 ms bb1-p6-0.crrvca.sbcglobal.net [151.164.41.34] 1023 ms24 ms27 ms core2-p4-0.crrvca.sbcglobal.net [151.164.41.1] 1158 ms61 ms59 ms core2-p3-0.crhstx.sbcglobal.net [151.164.241.125] 1288 ms89 ms81 ms core1-p9-0.cratga.sbcglobal.net [151.164.191.192] 1383 ms82 ms84 ms core2-p1-0.cratga.sbcglobal.net [151.164.241.82] 1482 ms82 ms83 ms core2-p6-0.crhnva.sbcglobal.net [151.164.41.206] 1588 ms89 ms90 ms core2-p3-0.crnyny.sbcglobal.net [151.164.188.197] 1691 ms88 ms89 ms bb2-p3-0.nycmny.sbcglobal.net [151.164.240.221] 1788 ms90 ms87 ms ded2-g8-3-0.nycmny.sbcglobal.net [151.164.41.181] 1893 ms90 ms98 ms 66.10.112.6 19 *** Request timed out. 20 *** Request timed out. 21 *** Request timed out. 22 *** Request timed out. 23 *** Request timed out. This does not necessarily mean that the server is down. Routers can filter traceroute and ping. Telnet to mail.pacbell.net on port 25 works just fine. If the server had been down, the OP would not have gotten connection refused, he would have gotten a connection timeout. The OP's problem is most likely that he's doing this: s = smtplib.SMTP(mail.pacbell.net) # This already connects s s.connect() # This reconnects s to localhost and is refused when he should do this: s = smtplib.SMTP() # make an unconnected SMTP instance s.connect(mail.pacbell.net) # and connect it. or simply this: s = smtplib.SMTP(mail.pacbell.net) -Carsten -- http://mail.python.org/mailman/listinfo/python-list
cursesw+setlocale fixes it! (was: Re: Problem with curses and UTF-8)
Damjan wrote: import curses, locale locale.setlocale(locale.LC_ALL, '') s = curses.initscr() Hey, that works for me. Combined characters and wide characters are working too. Now the real problem.. how do I convince the python higher-ups to link against cursesw by default? At the very least all distros that use UTF-8 as their default encoding should switch to cursesw. Ian Ward -- http://mail.python.org/mailman/listinfo/python-list
CGI Python FTP
I know PHP has support for uploading files from the browser to the server, but does python (not mod_py) have any modules for going about this? If not post your ideas on how I should do this. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting Tkinter Text contents before destruction
Bob Greschke wrote: I want to grab the contents of a Text widget when the frame it's on gets destroyed. I tried TextWidget.bind(Destroy... , but the widget is gone before the call gets made, and I'd really hate to do something with the function that gets called with TextWidgetsFrame.bind(Destroy, ..., since that one function handles all of the frames in the program...or would that even work? How can I do this? in what ways can the frame be destroyed ? assuming that you're talking about user-initiated actions, the most reasonable way to do this is to implement a WM_DELETE_WINDOW handler on the toplevel window that the frame is located in, and deal with the text widget in there. see: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm#protocols /F -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI Python FTP
[EMAIL PROTECTED]: I know PHP has support for uploading files from the browser to the server, but does python (not mod_py) have any modules for going about this? http://www.python.org/doc/2.3.2/lib/node403.html http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844 -- René Pijlman -- http://mail.python.org/mailman/listinfo/python-list
Re: line wrapping problem
ZeD wrote: Ciao, Juho Schultz! Che stavi dicendo? Moro, ZeD! Kunhan pulisen. Should we stick to English? should work. IMO file.write() is self-explanatory but print file is a bit obscure. is obscure only if you have never used a shell :) (I have used the shell a bit. I started using Linux at work when 2.2 series kernels did not exist.) Assume a newbie plays around with a piece code. If the code has f.write(x) or print f,x - in which case the newbie is more likely to break the code by rebinding f to something non-file? And in which case he will more likely understand the error message, something like f has no write attribute? I am sure the can be useful - it is quick to add after a simple print when you want less chatter and more logfiles. But IMO it is not self-documenting. Having to very different uses for an operator in the same language is sort of confusing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Dump of a python process
Shanon wrote: I would to know if there're some way to have a dump of all the threads started by a python process. I want to see the TID corresponding of each thread because I need them to get the CPU time of each thread by the command top. threading.enumerate() will return a list of all threading.Thread objects that have been created (including the main one), but Thread's do not currently store the identified of the underlying thread (created by a call to thread.start_new_thread(). You could easily subclass Thread to provide your own .start() which does that, and perhaps modify __repr__ to output that instead of the id() value. Check the source in threading.py if this approach sounds useful. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: removing characters before writing to file
[EMAIL PROTECTED] wrote: hi i have some output that returns a lines of tuples eg ('sometext1', 1421248118, 1, 'P ') ('sometext2', 1421248338, 2, 'S ') and so on If the braces are always at the begining and at the end of the string, you could also use: ('sometext1', 1421248118, 1, 'P ')[1:-1] 'sometext1', 1421248118, 1, 'P ' cheers Stefan pgpEdJ9SLHXXB.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
Terry Reedy wrote: The OP did not specify whether all of his if-tests were sequential as in your test or if some were nested. I vaguely remember there being an indent limit (40??). Most of the if statements are nested. Almost all of them fall under a central 'for xxx in range(x,x,x)', (this is the statement that checks thorugh each of the saved configuration files). Under that 'for' statment are the bulk of the 'if' statements - some nested and some not - some also fall under other 'for' statements. The indent level does not exceed 10.. Delaney, Timothy (Tim) wrote: I'm pretty sure the OP has hit the python script line limit (32767?). The script is 4903 lines long. Slightly off topic; I am just a Network Engineer that can write some code that accomplishes what I need to get done. I'm learning something new everyday but I am really blown away by the responses to this thread. I could not buy support this good. Thanks for your responses. -- http://mail.python.org/mailman/listinfo/python-list
Re: thread dump
jsuch wrote: I'm using Fedora core 3 and python 2.4.2, is there any way to obtain the linux pid of a python thread? I need it because I want to know CPU usage per thread. Not sure if you were the same person that posted this request not six minutes earlier under a thread titled Thread Dump of a python process (a much better subject that this one, by the way)... In any case, see my reply in that thread. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Test indexers...how do they work?
Raja Raman Sundararajan wrote: Hello guys, I was investigating how one can use the text indexers in python and I stumbled across several ones. eg., pylucene I wanted to know how the algorithm of indexers look like. I have heard people talking about B-Trees. But this info. is simply know enough. I would like to know exactly each part of the indexing flow and the algorightm behind it work. Info pls, are you talking about how Analyszers do stopwords and stemming / lemmatization? or how queries are handled, or how indexes (bitfields) are built / queried? I think Hatcher's book is the best place to start, tho doesn't focus intensively on lucene's implementation http://lucenebook.com/blog/ http://divmod.org/trac/wiki/WhitherLupy This *was* a pure python port, Lupy which i remember being pretty easy to follow, maybe you can get them to send it to you -- http://mail.python.org/mailman/listinfo/python-list
super(...).__init__() vs Base.__init__(self)
Are there any best practice guidelines for when to use super(Class, self).__init__() vs Base.__init__(self) to call a base class __init__()? The super() method only works correctly in multiple inheritance when the base classes are written to expect it, so Always use super() seems like bad advice. OTOH sometimes you need super() to get correct behaviour. ISTM Only use super() when you know you need it might be the best advice. Is there any conventional wisdom on this? The question arises from a naive use of super() in a post on the tutor list. This code gives an AttributeError because Base.__init__() is never called: import threading class Base(object): def __init__(self): self.x = 1 class Derived(threading.Thread, Base): def __init__(self): super(Derived, self).__init__() d=Derived() d.x If the order of base classes is reversed, the reference to d.x works but of course threading.Thread.__init__() is never called. 1. One way to fix the code is to call Base.__init__() and threading.Thread.__init__() explicitly in Derived.__init__(). 2. Another fix is for Base.__init__() to call super(Base, self).__init__() and to list Base first in the list of base classes. This is fragile - it depends on the order of base classes and adding another base class would break it. 3. A third fix might be to change both Base and threading.Thread() to call super(...).__init__(). This might break existing code that is written in the style of fix 1 (calling both base class __init__() methods explicitly). I prefer the first fix, it is explicit and fairly robust - it works if the order of bases is changed, and it's pretty clear from the body of Derived.__init__() that if you add another base class, you should change __init__(). Any other opinions? Any consensus about the best way to do this? BTW I understand what super() does, I know why the original code is broken, I'm not asking for help with that. I'm wondering what others think best practices are. Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing curses
Ian Ward wrote: I'll have to deal with that anyway, since I'm doing all my own wrapping, justification and clipping of text. In general it's impossible to know how many display positions some random Unicode character might use. For example, Chinese characters normally take two display positions, but the terminal your using might not support them and display a single width replacement character. Hopefully, you're limitted in the character set you actually need to support and the terminals that your applicaiton will be using. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way of finding terminal width/height?
On 2006-02-09, Joel Hedlund [EMAIL PROTECTED] wrote: It didn't insert an EOF, it just caused read() to return prematurely. You should call read() again until it receives a _real_ EOF and returns ''. Copy that. Point taken. There appear to be a couple problems with this description: 1) It says that read() in blocking mode without a size parameter it will read until EOF. This is not what happens when reading a terminal that receives SIGWINCH, so you're right: read() it isn't working as described. 2) It also says that it makes sense to continue to read a tty after you get an EOF. That's not true. Once you get an EOF on a tty, there's no point in reading it any more: you'll continue to get an EOF forever. I should qualify comment 2) with the disclaimer that that's how tty devices on Unix/Linux work -- I don't know about windows. Should I post a bug about this? Sure. I was going to do that yesterday, but I realized that I didn't know how/where to do it. I assume there's a link somewhere at www.python.org, but I haven't had a chance to look yet. -- Grant Edwards grante Yow! I wish I was on a at Cincinnati street corner visi.comholding a clean dog! -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
Alan Morgan [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Bryan Olson [EMAIL PROTECTED] wrote: Alan Morgan wrote: slogging_away wrote: Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script works fine but it appears that I may have hit a wall with 'if' statements. I generated files with 1, 25000, and 5 simple if statements and ran them. 1 was okay, 25000 gave a bizarre internal error, and 5 segfaulted and died. My system has plenty of memory and it isn't obvious to me why python should be so bothered about this. I'm not sure why I can have 10x the number of if statements that cause you trouble. There might be some overall limitation on the number of statements in a file. I made a script with 100,000 if's, (code below) and it appears to work on a couple systems, including Python 2.4.2 on Win32-XP. So at first cut, it doesn't seem to be just the if-count that triggers the bug. Mine was a simple #!/usr/local/bin/python zot=24999 if zot == 0: print It's 0 if zot == 1: print It's 1 if zot == 24999: print It's 24999 generated (I'm ashamed to admit) by a perl script. Is there any good reason why it is failing? I'd prefer a Too many silly walks in your program. Reduce! to a crash. I could experiment with putting the matching 'if' at the beginning rather than at the end, but I'm not sure what that would tell me. Here[1] it works with 40 (with 50 it starts swapping too much) if-statements generated by == #!/usr/bin/env python print #!/usr/bin/env python zot=24999 for i in range(0, 40): print if zot == %d: print It's %d %(i,i) [1] Python 2.4.2 (#2, Sep 30 2005, 21:19:01) [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] Florian -- No no no! In maths things are usually named after Euler, or the first person to discover them after Euler. [Steven D'Aprano in [EMAIL PROTECTED]] -- http://mail.python.org/mailman/listinfo/python-list
Problem using epydoc with python2.4 and restructured text
I wish to document my project written in python2.4 with restructured text syntax. From the various python documentation tools it seems only epydoc supports rst as the documentation format. It seems however that epydoc, the last version being 2.1 released in 2004, doesn't support python2.4 well. I tried on the file example statemachine.py given on docutils.sourceforge.net, and below is the result: rhodium:~# epydoc --docformat restructuredtext statemachine.py Importing 1 modules. [.] Building API documentation for 1 modules. [.] /usr/lib/python2.4/site-packages/epydoc/markup/restructuredtext.py:174: DeprecationWarning: docutils.utils.Reporter.set_conditions deprecated; set attributes via configuration settings or directly document.reporter.set_conditions('', 1, 1, None) === /root/statemachine.py In statemachine docstring (line 7): --- - Error: Internal error: 'int' object is not callable === /root/statemachine.py In statemachine.string2lines docstring (line 1459): --- - Error: Internal error: 'int' object is not callable === /root/statemachine.py In statemachine._exception_data docstring (line 1478): --- - Error: Internal error: 'int' object is not callable -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn -- http://mail.python.org/mailman/listinfo/python-list
Re: Pulling all n-sized combinations from a list
On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote: Hi there, I've got a reasonably sized list of objects that I'd like to pull out all combinations of five elements from. Right now I have a way to do this that's quite slow, but manageable. I know there must be a better way to do this, but I'm not sure what it is. Here's what I've got so far: import probstat # http://probstat.sourceforge.net for (a, b, c) in probstat.Combination(range(9), 3): # 0..9, pick 3 print a, b, c It is a C extension that does permutations combinations and is about 10x faster than doing it in pure python [I'm the author]. It is also the 3rd result for python combination and 5th for python permutaiton but every month someone posts to c.l.py asking for something similar. Go figure. -jackdied -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted book opinions?
Andrew Gwozdziewycz wrote: What I'd really like now is a 'Web Application Development with Twisted/Nevow' book that takes off where this 'network protocol' oriented book leaves off. I thought the O'Reilly book was pretty decent at describing how to setup a web application. It's not entirely complete, but I was able to piece together an application with a somewhat complex web application on top of it. Twisted made it quite easy. OK perhaps I wasn't as clear as I could have been. It discusses the use of Twisted with web protocols but doesn't really go into the current, recommended way to build web applications (because at the time of writing the possibility of api changes for nevow/twistedweb2 was quite high?). In fact it does say in the book that ..if you are really interested in building a web application you should be using nevow.. (paraphrased). Tim Parkin -- http://mail.python.org/mailman/listinfo/python-list
Finding the public callables of self
Is there any better way to get a list of the public callables of self other than this? myCallables = [] classDir = dir(self) for s in classDir: attr = self.__getattribute__(s) if callable(attr) and (not s.startswith(_)): myCallables.append(s) #collect the names (not funcs) I don't mean a shorter list comprehension or something that just drops the line count, but whether or not I need to go at it through dir and __getattribute__. This seems a bit convoluted and with python it often seems there's something already canned to do stuff like this when I do it. At first I thought self.__dict__ would do it, but callable methods seem to be excluded so I had to resort to dir, and deal with the strings it gives me. Thanks, Russ -- http://mail.python.org/mailman/listinfo/python-list
Re: random playing soundfiles according to rating.
I think of it this way: you randomly pick a entry out of a dictionary, then roll a 100-side die to see if the pick is good enough. Repeat until you find one, or give up. import random def rand_weighted_pick(weighted_picks): for i in range(100): name, prob = random.choice(weighted_picks) if prob = random.randint(0,100): return name # Give up and return a random choice return random.choice(weighted_picks)[0] if __name__ == __main__: test_vals = [(A,50),(B,30),(C,20)] dist = dict() for name, prob in test_vals: dist[name] = 0 for x in xrange(1000): dist[rand_weighted_pick(test_vals)] += 1 print Expected: A = 500, B = 300, C = 200 print Actual : A = %d, B = %d, C = %d%(dist['A'], dist['B'], dist['C']) -- http://mail.python.org/mailman/listinfo/python-list
Re: super(...).__init__() vs Base.__init__(self)
I remember there was somewhere a page called super considered harmful, some googling should find it. It was discussing the issue you are alluding to, as well others. Also google in the newsgroup, there are lots of threads about super and its shortcomings. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the public callables of self
import inspect myCallables = [name for name, value in inspect.getmembers(self) if not name.startswith('_') and callable(value)] Instance methods aren't in self.__dict__ because they're a part of the class. To made a comprehensive list of all the attributes available to an instance, you have to traverse the attribute dictionaries of the instance, its class, and all of the base classes in the right order. (inspect.getmro returns the base classes in method resolution order) -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.path and unicode folder names
Nir Aides wrote: If few people use file names not in their respective CP_ACP as you say, why did Microsoft bother to make Windows XP a unicode OS? Because it simplifies their implementation, in the long run. It is because of this situation that people in non-English speaking countries prefer to install English Windows XP. After all why should they get all messed up with incompatible software? I see. Why do these people then refuse to change the code page of their system (which *is* possible, even in English XP)? Python is Broken. I agree. Please contribute a patch. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: line wrapping problem
S Borg wrote: Hello, I am parsing text from one document to another. I have a scheme similar to: for x in myfoobar: print mytextfile, %s % mydictionary[x], #all on same line print mytextfile, '\n' #new line I am getting line breaks before my explicit line break. Am I unwittingly copying '\n' characters from the original file? Where does mydictionary[x] come from? If it is from reading lines from a file it may contain trailing newlines. Also print mytextfile, '\n' will print two newlines, one explicit and one implicit in the print. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: cursesw+setlocale fixes it!
Ian Ward wrote: Hey, that works for me. Combined characters and wide characters are working too. Now the real problem.. how do I convince the python higher-ups to link against cursesw by default? That's very easy. Contribute a working patch. That patch should support all possible situations (e.g. curses is ncurses, and ncursesw is available, curses is ncurses, and ncursesw is not available, curses is not ncurses), and submit that patch to sf.net/projects/python. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the public callables of self
Russell Warren wrote: Is there any better way to get a list of the public callables of self other than this? myCallables = [] classDir = dir(self) for s in classDir: attr = self.__getattribute__(s) if callable(attr) and (not s.startswith(_)): myCallables.append(s) #collect the names (not funcs) I don't mean a shorter list comprehension or something that just drops the line count, but whether or not I need to go at it through dir and __getattribute__. This seems a bit convoluted and with python it often seems there's something already canned to do stuff like this when I do it. Use getattr(self, s) instead of self.__getattribute__(s). You could streamline it a bit with a list comprehension: myCallables = [ s for s in dir(self) if not s.startswith('_') and callable(getattr(self, s)) ] At first I thought self.__dict__ would do it, but callable methods seem to be excluded so I had to resort to dir, and deal with the strings it gives me. The callables are attributes of the class and its base classes, not of self. self.__dict__ just contains instance attributes. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
slogging_away wrote: Terry Reedy wrote: The OP did not specify whether all of his if-tests were sequential as in your test or if some were nested. I vaguely remember there being an indent limit (40??). Most of the if statements are nested. Almost all of them fall under a central 'for xxx in range(x,x,x)', (this is the statement that checks thorugh each of the saved configuration files). Under that 'for' statment are the bulk of the 'if' statements - some nested and some not - some also fall under other 'for' statements. The indent level does not exceed 10.. Has anyone considered that this may be part of the issue? If he is stepping through a range this is not just X if statements but n * x where n is the number of loops. Possibly some variables that are not getting freed between loops? (my guess would be that it is related to logging) Anyways, no expert here, just wanted to point that out. -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the public callables of self
Russell Warren [EMAIL PROTECTED] wrote: Is there any better way to get a list of the public callables of self other than this? myCallables = [] classDir = dir(self) for s in classDir: attr = self.__getattribute__(s) if callable(attr) and (not s.startswith(_)): myCallables.append(s) #collect the names (not funcs) I don't mean a shorter list comprehension or something that just drops the line count, but whether or not I need to go at it through dir and __getattribute__. This seems a bit convoluted and with python it often seems there's something already canned to do stuff like this when I do it. At first I thought self.__dict__ would do it, but callable methods seem to be excluded so I had to resort to dir, and deal with the strings it gives me. This last sentence suggests to me something like: attrs = set(s for s in dir(self) if not s.startswith('_')) myCallables = attrs.difference(a.__dict__) return list(myCallables) (which you can get down to one line if you want). -- \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
newbie needs serious help
OK. Never used python. I need it to install the Google Sitemap program on our WindowsServer2003(SE) server. I cannot for the life of me figure out how to configure this thing. Please keep in mind that I do not know ANYTHING about servers. What I did: I downloaded the Python 2.4.2 msi file, and installed it. All went well. Now, I have no idea what to do. I read the documentation, README files, etc., and it looks like Im supposed to configure it with a ./configure command,and then a magical make command. Where do I type these in? Im assuming its not through a command line, as that didnt work. And I tried to launch the python.exe, and type it in there but that doesnt work either. Where is this is supposed to go? Help? -- http://mail.python.org/mailman/listinfo/python-list
Rethinking the Python tutorial
While the official Python Tutorial has served its purpose well, keeping it up to date is hardly anyones top priority, and there are others who passionately create really good Python tutorials on the web. I think 'A Byte of Python' by Swaroop C H is a good beginners tutorial, and 'Dive Into Python' by Mark Pilgrim is a good tutorial for more experienced programmers. My radical idea is that we mirror these at diveinto.python.org and byteof.python.org, and simply remove the old tutorial from the Python 2.5 (or 2.6?) docs. Give these two good texts an official status as the Python tutorials. Just as we want to adopt best of breed packages for the standard library, I think we should use best of breed documentation, and I think there are less backward compatibility issues with tutorials than with libraries. :) I think this change would give us better docs as well as a smaller maintenance burden. If a day comes when Mark Pilgrim or Swaroop C H don't want to maintain these texts, I strongly suspect that there are other tutorials we can replace them with if noone else steps in to keep them up to date. -- http://mail.python.org/mailman/listinfo/python-list
New editions of several Python books.
While I work at a company that uses Python a lot (and would have had a hard time finding such a place a few years ago) I don't really have a clear opinion on whether Python's marketshare (or mindshare) is growing significantly. Perl seems to be in decline, but on the other hand, Ruby is attracting a lot of people. One interesting thing I noticed when I visited Amazon.com today, was that several publishers are busy making new editions of their Python books. These classics are in the pipeline: Python Essential Reference (3rd Edition) by David M. Beazley (Paperback - February 24, 2006) I have the 1st ed. Just as with Martelli's Nutshell-book, this is a really good reference book. (Or was in previous editions at least.) Python, Second Edition : Visual QuickStart Guide (2nd Edition) by Chris Fehily (Paperback - April 14, 2006) In my opinion one of the best beginner books. Straight forward and also affordable. Programming Python, 3rd edition by Mark Lutz (Paperback - July 2006) Never a favourite of mine really, but a popular book... And this is already reissued it seems: Python Programming for the Absolute Beginner, Second Edition by Michael Dawson (Paperback - November 8, 2005) Finally... Beginning Python: From Novice to Professional by Magnus Lie Hetland (Paperback - September 26, 2005) ...was more or less a 2nd edition of Magnus' Practical Python. There is also a Python for Dummies on its way at last. (I'm not sure Python *is* for dummies though. Despite being so easy to learn and use, it mainly seems to attract smart and experienced people, why else would Python programmers be among the best paid programmers?) Somehow, the fact that so many books are reissued in a fairly short period, makes me feel that the publishers feel that the winds are blowing our way... Any thoughts on this? I don't see any similar republish trends among the other scripting languages. (Although Ruby on Rails seems to attract some attention -- four books in the pipeline.) -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie needs serious help
I downloaded the Python 2.4.2 msi file, and installed it. All went well. Now, I have no idea what to do. I read the documentation, README files, etc., and it looks like I'm supposed to configure it with a ./configure command,and then a magical make command. I suspect you were reading installation instructions for multiple OS platforms. The ./configure; make song-and-dance is a common way to do an install on *nix platforms. I suspect that all you needed to do on Win32 was to run the MSI file and you're good to go. I don't know about the Google Sitemap side of things, but I suspect you've already successfully installed Python. -tkc (PS: You wouldn't happen to have attended Messiah College...I knew a Joy Hunsberger who attended there and wondered if you're the self-same person. Otherwise, feel free to disregard this PS :) -- http://mail.python.org/mailman/listinfo/python-list
Re: importing maple into python
walter kehowski wrote: Hello, Is there for a python program to call maple? http://sage.sourceforge.net -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie needs serious help
On 2/9/06, Hunsberger, Joy [EMAIL PROTECTED] wrote: OK. Never used python. I need it to install the Google Sitemap program on our WindowsServer2003(SE) server. I downloaded the Python 2.4.2 msi file, and installed it. All went well. Now, I have no idea what to do. And I tried to launch the python.exe, and type it in there but that doesn't work either. As already mentioned, you were confusing instructions for unix platforms with the Windows instructions. Installing with the msi and following the prompts is all that's needed. You say you launched python.exe and tried to type 'configure' in it? If by launching python.exe means you next saw a command-line like prompt that started with some info about python, then the prompt characters, that means you've installed Python and you're done (except for installing Sitemap). That black window is an interactive shell -- a place to type Python commands and see a result. You don't have to do that if all you need is Python installed to support the Google application. -- http://mail.python.org/mailman/listinfo/python-list
Form1.show()
hi ! iam newbie on python. how i can make form1 visible ? form just crated by pyqt class Form1(QMainWindow): def __init__(self,parent = None,name = None,fl = 0): QMainWindow.__init__(self,parent,name,fl) self.statusBar() if self.MenuBar.findItem(1): self.MenuBar.findItem(1).setText(self.__tr(File)) if self.MenuBar.findItem(2): self.MenuBar.findItem(2).setText(self.__tr(Edit)) if self.MenuBar.findItem(3): self.MenuBar.findItem(3).setText(self.__tr(Help)) def fileNew(self): print Form1.fileNew(): Not implemented yet .. def __tr(self,s,c = None): return qApp.translate(Form1,s,c) -- http://mail.python.org/mailman/listinfo/python-list
Re: super(...).__init__() vs Base.__init__(self)
Kent Johnson wrote: Are there any best practice guidelines for when to use super(Class, self).__init__() vs Base.__init__(self) to call a base class __init__()? [snip] 3. A third fix might be to change both Base and threading.Thread() to call super(...).__init__(). This might break existing code that is written in the style of fix 1 (calling both base class __init__() methods explicitly). Personally, I'd call the lack of the super calls in threading.Thread and Base bugs. So code relying on that behavior needs to be fixed when the bug is fixed. But __init__() is definitely a tricky case since the number of arguments tends to change in the __init__() methods of classes... STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the public callables of self
Sion Arrowsmith wrote: Russell Warren [EMAIL PROTECTED] wrote: (snip) At first I thought self.__dict__ would do it, but callable methods seem to be excluded so I had to resort to dir, and deal with the strings it gives me. This last sentence suggests to me something like: attrs = set(s for s in dir(self) if not s.startswith('_')) myCallables = attrs.difference(a.__dict__) err... s/a.__dict__/self.__dict__/ return list(myCallables) Won't work as expected: class Tricky(object): ... class_attrib = 42 ... def __init__(self, attr): ... self.attr = attr ... def doit(self): ... if callable(self.attr): ... return self.attr(self) ... t = Tricky(lambda obj: obj.__class__.__name__) t __main__.Tricky object at 0x2ab28ed0 def getcallables(obj): ... attrs = set(s for s in dir(obj) if not s.startswith('_')) ... callables = attrs.difference(obj.__dict__) ... return list(callables) ... getcallables(t) ['doit', 'class_attrib'] t.attr(t) 'Tricky' t.class_attrib() Traceback (most recent call last): File stdin, line 1, in ? TypeError: 'int' object is not callable There are 2 reliable ways to know if an object is callable: - using callable() - trying to call it -- 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: 450 Pound Library Program
BTW - I can't find any code examples of how to interrupt a beast like this. A regular ctrl-c doesn't work, since the separate threads just keep executing. Is this a case where you need to iterate through all threads and stop each one individually? How would that look? -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the public callables of self
Ha! I didn't realize that was getmembers' implementation. What a hack ;-) In fact, your way is faster, since getmembers is taking the time to sort its results (presumably so that repeated calls to the same object will yield the same list; I don't think dir has a guaranteed ordering) -- http://mail.python.org/mailman/listinfo/python-list
Re: Form1.show()
errmaker schrieb: hi ! iam newbie on python. how i can make form1 visible ? form just crated by pyqt class Form1(QMainWindow): def __init__(self,parent = None,name = None,fl = 0): QMainWindow.__init__(self,parent,name,fl) self.statusBar() if self.MenuBar.findItem(1): self.MenuBar.findItem(1).setText(self.__tr(File)) if self.MenuBar.findItem(2): self.MenuBar.findItem(2).setText(self.__tr(Edit)) if self.MenuBar.findItem(3): self.MenuBar.findItem(3).setText(self.__tr(Help)) def fileNew(self): print Form1.fileNew(): Not implemented yet .. def __tr(self,s,c = None): return qApp.translate(Form1,s,c) Look at teh examples of PyQt - you need to have an application instanced and calle its event-loop. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Test indexers...how do they work?
Raja Raman Sundararajan wrote: I wanted to know how the algorithm of indexers look like. I have heard people talking about B-Trees. But this info. is simply know enough. I would like to know exactly each part of the indexing flow and the algorightm behind it work. Get the book Managing Gigabytes: Compressing and Indexing Documents and Images. -- http://mail.python.org/mailman/listinfo/python-list