[Q] Is there a way to minimize a Tkinter application to the system tray?
Hello folks, I already found some answers on the net, which said that the Tk library that Tkinter wraps does not offer functionality to minimize an application to the system tray. But I hope there are some wizards in here that might tell me that how it (possibly) could be done. Thomas -- http://mail.python.org/mailman/listinfo/python-list
os.path.basename() - only Windows OR *nix?
Hello, I have a cgi script that handles fileuploads from windows and *nix machines. i need os.path.basename(filename) to get the pure filename. For *nix, thats not a problem, but for windows, it always returns the full path: #/usr/bin/env python import cgi, os import cgitb; cgitb.enable() form = cgi.FieldStorage() filename = os.path.basename(form['uploadfile'].filename) print 'Content-Type: text/html\n\n' print filename - For 'C:\text\text.txt', the output is 'C:\text\text.txt', which should be 'text.txt', the same happens for 'C:\\text\\text.txt'. I think its the escapes that makes python not splitting it. All Unix style paths get converted the right way. Is there an easy way around this, or do I really have to write a parser including _all_ Python escapes? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.basename() - only Windows OR *nix?
Steve Holden schrieb: Clearly if form['uploadfile'] is returning the client's path information you do have to remove that somehow before further processing, which also means you need to deduce what the client architecture is to correctly remove path data. Of course this also leaves open the question what does a Mac client return?, and you might want to cater for that also. I tested from linux and Mac OS, and on both os.path.basename() works as expected (since the server it runs on is a UNIX one). That brings me to the question, how Do I a) get the cients architecture and b) send the architecture of the client through cgi.FieldStorage()? I suspect you will also find that there are at least some circumstances under which a Unix browser will also include path information. Which ones should that be? Since os.path.basename() _is_ doing the right thing on *nix style paths (Mac OS is not different there), I cant think of other circumstances. I presume you are looking to use the same filename that the user provided on the client? Does this mean that each user's files are stored in different directories? Otherwise it's not always a good idea to use filenames provided by the user for files on the server anyway. Yes, each User has his own directory. Files get timestamped and then put into the corresponding directory. It is just that having 'C:\a\very\long\path\file.ext' as a filename on the server is not nice. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.basename() - only Windows OR *nix?
Bruno Desthuilliers schrieb: Let me guess : your cgi script is running on *n*x ?-) Pretty hard to get this one, heh? :-D Probably. Good that you decided I was worth the information. fnames = C:\\dir\\data.ext, /dir/data.txt, dir:data import ntpath, posixpath, macpath def basename(filename): ... for m in ntpath, posixpath, macpath: ... if m.sep in filename: ... return m.basename(filename) ... else: ... # XXX ... raise SomeException('could not do the job') ... for f in fnames: ... print f, basename(f) ... C:\dir\data.ext data.ext /dir/data.txt data.txt dir:data data Thnaks a lot. :) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Device Drivers in python(kernel modules)
rishi pathak schrieb: I am not much of a kernel programmer , I have a requirement to shift a python code to work as a kernel module. So I was just wondering whether we can write a kernel module in python. A thought is that if we can somehow convert python code into a C object code then it can be done. Can some one suggest something..anything http://wiki.python.org/moin/elmer This tool is able to run Python Code as if it was written in C. Perhaps this might help you, but I am not pretty sure since it had to be included in the kernel tree. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Which Object Database would you recommend for cross platform application?
Hello folks, I am currently developing an open source Event Managment software (events in real-life, like concerts, exhibitions etc. :-) ) using wx for the GUI, and I need an Object database. Since this is the first time I actually need doing this, I wondered if anybody here could recommend one. It can be fairly simple. It doesn't need threading support and will only host one client (the application, but I am thinking about making this database accessible via the web, but this is still far in the future), although the database might get big (around 1GiB). It should be available for linux, mac os and windows. I looked into ZODB, but thats totally overloaded for my purpose. I looked into Durus (a re-implementation of ZODB, but without this overloaded stuff, but the documentation is very thin). Both of them don't really appeal. So I wondered if any of you could recommend one that (more or less) best fits the described conditions. Thanks in advance, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Rational Numbers
Simon Brunning schrieb: On 12 Jan 2007 15:55:39 GMT, Nick Maclaren [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Carsten Haese [EMAIL PROTECTED] writes: | but there are more use | cases for Decimal than for Rational. That is dubious, but let's not start that one again. Decimals are good for holding financial values. There's a whole lot of software out there that deals with money. Do not forget: - Time - Personal Data (like birthdays, age) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write temporary data to file?
Laszlo Nagy schrieb: Thomas Ploch írta: Hi folks, I have a data structure that looks like this: d = { 'url1': { 'emails': ['a', 'b', 'c',...], 'matches': ['d', 'e', 'f',...] }, 'url2': {... } This dictionary will get _very_ big, so I want to write it somehow to a file after it has grown to a certain size. How would I achieve that? How about dbm/gdbm? Since urls are strings, you can store this dict in a database instance and actually use it from your program as it were a dict? Laszlo Well, but how do I save the nested dict values? I don't want to eval them, so this is no option for me. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write temporary data to file?
Thomas Ploch schrieb: Laszlo Nagy schrieb: Thomas Ploch írta: Hi folks, I have a data structure that looks like this: d = { 'url1': { 'emails': ['a', 'b', 'c',...], 'matches': ['d', 'e', 'f',...] }, 'url2': {... } This dictionary will get _very_ big, so I want to write it somehow to a file after it has grown to a certain size. How would I achieve that? How about dbm/gdbm? Since urls are strings, you can store this dict in a database instance and actually use it from your program as it were a dict? Laszlo Well, but how do I save the nested dict values? I don't want to eval them, so this is no option for me. Thomas I just saw shelve is the module to go for. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Question: Best Practice? (module 'shelve')
Hello fellows, I just wanted to know, if there is any best practice concerning following code: import re, shelve class TextMatcher: def __init__(self, patterns, email=False, dbName='textmatch.db'): self._initPatterns(patterns) self.email = email self.dbName = dbName if self.email: self.emailList = [] self.emailList.append( re.compile(r'[EMAIL PROTECTED]')) def match(self, src, url): self.matchDict = {} self.matchDict[url] = {} # The next 2 functions just add stuff to self.matchDict if self.email: self._addEmails(src, url) self._addPatterns(src, url) # Is it good practice to open, write and close the db straight # away? Or is it better to leave it open until the whole program # has finished, and close it then? self.openDB(self.dbName) self.db[url] = self.matchDict[url] self.db.close() # I want to del the matchDict each time so it can't grow big. # Is this good, or should it be left open, too? del self.matchDict def openDB(self, dbName=None, modeflag='c'): if dbName == None: self.db = shelve.open('textmatch.db', flag=modeflag) else: self.db = shelve.open(dbName, flag=modeflag) -- http://mail.python.org/mailman/listinfo/python-list
Re: Question: Best Practice? (module 'shelve')
Thomas Ploch schrieb: Hello fellows, I just wanted to know, if there is any best practice concerning following code: import re, shelve class TextMatcher: def __init__(self, patterns, email=False, dbName='textmatch.db'): self._initPatterns(patterns) self.email = email self.dbName = dbName if self.email: self.emailList = [] self.emailList.append( re.compile(r'[EMAIL PROTECTED]')) def match(self, src, url): self.matchDict = {} self.matchDict[url] = {} # The next 2 functions just add stuff to self.matchDict if self.email: self._addEmails(src, url) self._addPatterns(src, url) # Is it good practice to open, write and close the db straight # away? Or is it better to leave it open until the whole program # has finished, and close it then? self.openDB(self.dbName) self.db[url] = self.matchDict[url] self.db.close() # I want to del the matchDict each time so it can't grow big. # Is this good, or should it be left open, too? del self.matchDict def openDB(self, dbName=None, modeflag='c'): if dbName == None: self.db = shelve.open('textmatch.db', flag=modeflag) else: self.db = shelve.open(dbName, flag=modeflag) s/del self.matchDict/self.matchDict.clear() and ignore the second question. When I read the sent message, it came to my mind. :-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
How to write temporary data to file?
Hi folks, I have a data structure that looks like this: d = { 'url1': { 'emails': ['a', 'b', 'c',...], 'matches': ['d', 'e', 'f',...] }, 'url2': {... } This dictionary will get _very_ big, so I want to write it somehow to a file after it has grown to a certain size. How would I achieve that? Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: private variables
belinda thom schrieb: Hello, In what version of python were private variables added? Thanks, --b With this question you stepped into a bee hive. :-) Read the 'Why less emphasis on private data?' thread. But I can't tell you, when this so called 'private variables' were added. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write temporary data to file?
Ravi Teja schrieb: Thomas Ploch wrote: Hi folks, I have a data structure that looks like this: d = { 'url1': { 'emails': ['a', 'b', 'c',...], 'matches': ['d', 'e', 'f',...] }, 'url2': {... } This dictionary will get _very_ big, so I want to write it somehow to a file after it has grown to a certain size. How would I achieve that? Thanks, Thomas Pickle/cPickle are standard library modules that can persist data. But in this case, I would recommend ZODB/Durus. (Your code example scares me. I hope you have benevolent purposes for that application.) Ravi Teja. Thanks, but why is this code example scaring you? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write temporary data to file?
Ravi Teja schrieb: Thomas Ploch wrote: Ravi Teja schrieb: Thomas Ploch wrote: Hi folks, I have a data structure that looks like this: d = { 'url1': { 'emails': ['a', 'b', 'c',...], 'matches': ['d', 'e', 'f',...] }, 'url2': {... } This dictionary will get _very_ big, so I want to write it somehow to a file after it has grown to a certain size. How would I achieve that? Thanks, Thomas Pickle/cPickle are standard library modules that can persist data. But in this case, I would recommend ZODB/Durus. (Your code example scares me. I hope you have benevolent purposes for that application.) Ravi Teja. Thanks, but why is this code example scaring you? Thomas The code indicates that you are trying to harvest a _very_ (as you put it) large set of email addresses from web pages. With my limited imagination, I can think of only one group of people who would need to do that. But considering that you write good English, you must not be one of those mean people that needed me to get a new email account just for posting to Usenet :-). Ravi Teja. Oh, well, yes you are right that this application is able to harvest email addresses. But it can do much more than that. It has a text matching engine, that according to given meta keywords can scan or not scan documents in the web and harvest all kinds of information. It can also be fed with callbacks for each of the Content-Types. I know that the email matching engine is a kind of a 'grey zone', and I asked myself, if it needs the email stuff. But I mean you could easily include the email regex to the text matching engine yourself, so I decided to add this functionality (it is 'OFF' by default :-) ). Thomas P.S.: No, I am a good person. -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to learn
[EMAIL PROTECTED] schrieb: Hi, I have been programming in the .net environment and ide for a few years and I am looking to make the switch over to python. I have absolutely no python experience whatsoever. I am looking for a python guru who has instant messenger or gtalk or whatever who can meet me online in the mornings, give me some direction for the day and then answer some questions here and there online throughout the day. So you are looking for a person (no, a guru), that stays by your side the whole day, gives you answers and helps you learning python. This is a ridiculous request. If you want to learn python, you should start with visiting http://www.diveintopython.org/ and read it. If you have previous programming experience, this is the place to start. Sorry to interrupt the group but since all python gurus appear to be happily at work on the next level apps at google nobody responded to my craigslist ads. You can always ask your questions here on the list, there are enough people that are willing to help. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Jorgen Grahn schrieb: On 06 Jan 2007 17:38:06 -0800, Paul Rubin http wrote: BJörn Lindqvist [EMAIL PROTECTED] writes: It is given that emphasizing private data (encapsulation) leads to more internal complexity and more lines of code because you have to write getters and setters and stuff. You can have public variables in Java if you choose to. Writing private variables with public setters and getters is just a style choice. Privates with getters/setters are (as I think someone else hinted) pretty pointless. The interesting stuff is the private data that *is* private, i.e. not meant for users at all. Not really pointless, since you can hide your data structures that you don't want to be fiddled around with (which for me is almost the only point to use it). But yes, I don't mind not having 'private:' in Python. I don't have compile-time type checking anyway. In fact, I don't always know what the attributes of my objects /are/ until runtime. Me neither, although I have to say that the '__' prefix comes pretty close to being 'private' already. It depends on the definition of private. For me, private means 'not accessible from outside the module/class'. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Paul Rubin schrieb: Thomas Ploch [EMAIL PROTECTED] writes: Me neither, although I have to say that the '__' prefix comes pretty close to being 'private' already. It depends on the definition of private. For me, private means 'not accessible from outside the module/class'. class A: __x = 3 class B(A): __x = 4 # ok class C(B): __x = 5 # oops! Consider that the above three class definitions might be in separate files and you see how clumsy this gets. I don't understand why this should be oops, even if they are in different files. a = A() print a._A__x 3 b = B() print b._B__x 4 c = C() print c._C__x 5 dir(c) ['_A__x', '_B__x', '_C__x', '__doc__', '__module__'] print c._A__x 3 print c._B__x 4 -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
W. Watson schrieb: As I understand it, there are two files I'm after: 1. python interpreter, and 2. a python editor. It's #2 that I'm having trouble downloading. The link is broken. This is the python interpreter for windows: http://www.python.org/ftp/python/2.5/python-2.5.msi Here you can check for editors: http://wiki.python.org/moin/PythonEditors Here you will get the pywin32 package (also including the Win32 API, COM support, and Pythonwin): http://sourceforge.net/projects/pywin32/ I am not sure if you actually read any of our posts, because there is no 404 whatsoever. On none of the posted links in the whole thread. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
sturlamolden schrieb: [EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? The designers of Java, C++, C#, Ada95, Delphi, etc. seem to think that if an object's 'internal' variables or states cannot be kept private, programmers get an irresistible temptation to mess with them in malicious ways. But if you are that stupid, should you be programming in any language? The most widely used language is still C, and there is no concept of private data in C either, nor is it needed. There is a kind of this concept in C with 'static' declarations. As mentioned in other replies, it is not rocket science to access a class private data. In C++ you can cast to void*, in Java and C# you can use reflection. C++ is said to be an unsafe language because programmers can, using a few tricks, mess with the vtables. But how many really do that? Exactly, if they were available, a lot more would do that. I think this is the point. Programmers who can do that normally are sensible towards that people who have designed this or that knew what they were doing. But there are enough people that don't have a clue and _will_ fiddle around and then flame all kind of mailing lists with requests for help cause they did it wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Sebastian 'lunar' Wiesner schrieb: Those people deserve to fail for being just extraordinary stupid... Yes, but there are a lot of them around... Thomas P.S.: I don't mean they are around here. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python re expr from Perl to Python
Florian Diesch schrieb: Michael M. [EMAIL PROTECTED] wrote: In Perl, it was: ## Example: Abc | def | ghi | jkl ## - Abc ghi jkl ## Take only the text betewwn the 2nd pipe (=cut the text in the 1st pipe). $na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g; ## -- remove [ and ] in text $na =~ s/\[//g; $na =~ s/\]//g; # print DEB: \$na\\n; # input string na=Abc | def | ghi | jkl [gugu] # output na=Abc ghi jkl gugu How is it done in Python? import re na=Abc | def | ghi | jkl [gugu] m=re.match(r'(\w+ )\| (\w+ )\| (\w+ )\| (\w+ )\[(\w+)\]', na) na=m.expand(r'\1\2\3\5') na 'Abc def ghi gugu' I'd rather have the groups grouped without the whitespaces import re na=Abc | def | ghi | jkl [gugu] m=re.match(r'(\w+) \| (\w+) \| (\w+) \| (\w+) \[(\w+)\]', na) na=m.expand(r'\1 \3 \4 \5') na 'Abc ghi jkl gugu' Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find the longst element list of lists
Michael M. schrieb: How to find the longst element list of lists? I think, there should be an easier way then this: s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] if len(s1) = len(s2) and len(s1) = len(s3): sx1=s1 ## s1 ist längster if len(s2) = len(s3): sx2=s2 sx3=s3 else: sx2=s3 sx3=s2 if len(s2) = len(s3) and len(s2) = len(s1): sx1=s2 ## s2 ist längster if len(s3) = len(s1): sx2=s3 sx3=s1 else: sx2=s1 sx3=s3 if len(s3) = len(s1) and len(s3) = len(s2): sx1=s3 ## s3 ist längster if len(s1) = len(s2): sx2=s1 sx3=s2 else: sx2=s2 sx3=s1 After, the list ist sorted: sx1 = [a, b, c, d] sx2 = [q, e, d] sx3 = [a, b] I don't really get that. You have three lists, you want to sort them after their length. You should put them into one list. I think you should rather implement this as: list = [a1, s2, s3] list.sort(lambda x,y: cmp(len(y), len(x))) list [['a', 'b', 'c', 'd'], ['q', 'e', 'd'], ['a', 'b']] Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find the longst element list of lists
Michael M. schrieb: Err... this makes three distinct lists, not a list of lists. Sure. Logically spoken. Not in Python code. Or a number of lists. Sure not [[ bla... ] [bla.]] etc. ??? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
W. Watson schrieb: The wiki site lead to a link to download pythonwin, but the download is broken. Googling invariably leads back to that link. I found http://www.python.org/download/releases/binaries-1.4/pythonwin/, which has two files listed: oadist.exe and win32dbg.exe. Do I need both or is just the latter one? A google query 'pythonwin' directly brings me here: https://sourceforge.net/projects/pywin32/ I think this is the place to go Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Dividing integers...Convert to float first?
Beliavsky schrieb: If the C or Fortran committees tried to change the meaning of int/int, they would be shot. Or hanged... If you want to be confident that your code will run, unchanged, 10 years from now on the hardware and OS that will then be common, Python 2.x is not the language to use, unfortunately. From what I have read, Python 3 will break things more fundamental than int/int. Yes, but until then we have to use python 2.x. And I think that python 2.x will be around quite a while after python 3000 has been released if it breaks so much. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
[EMAIL PROTECTED] schrieb: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? Thanks any insight. Python doesn't prefer public data in classes. It leaves the choice to the programmer. You can define your own private instance variables (or functions) by using a '__' prefix: example: class Foo: def __init__(self, data): self.__data = data def get_data(self): return self.__data f = Foo('bar') f.__data Traceback (most recent call last): File stdin, line 1, in module AttributeError: Foo instance has no attribute '__data' f.get_data() 'bar' -- http://mail.python.org/mailman/listinfo/python-list
Re: program deployment
Grant Edwards schrieb: On 2007-01-05, king kikapu [EMAIL PROTECTED] wrote: Python code is normally deployed as straight source code. But isn't this a problem of its own? I mean, many people do not feel good if the know that their source code is lying around on other machines... Are they embarassed by their code? hehehe, but what I am thinking: Is it somehow possible to _really_ hide the source from being viewed by other persons when using python? Not that I want to do that ( I am an Open Source friend ), but that might get others that rely on that (commercial) to use python for more projects as it is done now. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Dividing integers...Convert to float first?
[EMAIL PROTECTED] schrieb: I'm still pretty new to Python. I'm writing a function that accepts thre integers as arguments. I need to divide the first integer by te second integer, and get a float as a result. I don't want the caller of the function to have to pass floats instead of integers. How do I convert the arguments passed to the function into floats before I do the division? Is this necessary, or is their a better way? Thanks, Scott Huey Yes, it is necessary. If you divide two integers, the result will be an integer. 1/2 0 You need the function float() - float because a division between integers and floats will have floats as their results float(1)/2 0.5 -- http://mail.python.org/mailman/listinfo/python-list
Re: Dividing integers...Convert to float first?
Jonathan Smith schrieb: Thomas Ploch wrote: [EMAIL PROTECTED] schrieb: I'm still pretty new to Python. I'm writing a function that accepts thre integers as arguments. I need to divide the first integer by te second integer, and get a float as a result. I don't want the caller of the function to have to pass floats instead of integers. How do I convert the arguments passed to the function into floats before I do the division? Is this necessary, or is their a better way? Thanks, Scott Huey Yes, it is necessary. If you divide two integers, the result will be an integer. 1/2 0 You need the function float() - float because a division between integers and floats will have floats as their results float(1)/2 0.5 from __future__ import division 1/2 0.5 -smithj aahh, I have been tought so many things about python that are actually so old, that I am starting to feel embarrassed. That brings me to the point, that learning a language X at university always brings you to a point where you know (almost) everything, but in reality know nothing because course material is too old... Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Dividing integers...Convert to float first?
Grant Edwards schrieb: On 2007-01-05, Jonathan Smith [EMAIL PROTECTED] wrote: from __future__ import division 1/2 0.5 $ python Python 2.4.3 (#1, Dec 10 2006, 22:09:09) [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type help, copyright, credits or license for more information. from __future__ import LotteryNumbers File stdin, line 1 SyntaxError: future feature LotteryNumbers is not defined Damn. I guess it's back to work then. You are working as an oracle? :-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGreSQL Install
goodepic schrieb: I successfully installed postgresql and pygresql from source on my MacBook 2ghz Intel core duo running os x 10.4.8. However, pygresql installed under the defualt python 2.3 installation, while I've been upgrading and working in 2.5, and have invested too much time to go back to 2.3. I definitely don't know where every file is, but I know that the site-packages folder where I need pgdb to be is /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages. This is where I have pypar, pynum, numeric, etc. PyGreSQL installed in the default /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages. Anyone know where I can edit setup.py or what flags I can use to force the install onto 2.5? Thanks! You should try: $ python2.5 setup.py install Normally it gets installed into the directory of the python version you use when running setup.py. Is python 2.3 still the default on MAC OS X 10.4? I thought they switched to python 2.4. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Best way to implement a timed queue?
Hello folks, I am having troubles with implementing a timed queue. I am using the 'Queue' module to manage several queues. But I want a timed access, i.e. only 2 fetches per second max. I am horribly stuck on even how I actually could write it. Has somebody done that before? And when yes, how is the best way to implement it? Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: What is proper way to require a method to be overridden?
jeremito schrieb: I am writing a class that is intended to be subclassed. What is the proper way to indicate that a sub class must override a method? Thanks, Jeremy What do you mean by 'indicate'? Writing it to the docstring of the class/method? Writing a comment? class Foo: When inheriting from Foo, method foo must be overridden. Otherwise SPAM. def foo(self): print 'bar' class Bar(Foo): def __init__(self): Foo.__init__(self) # Has to be defined to override the base class's method # when inheriting from class Foo. Otherwise: SPAM def foo(self): print 'foo' I don't know any other way. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: What is proper way to require a method to be overridden?
Gabriel Genellina schrieb: At Thursday 4/1/2007 23:52, jeremito wrote: I am writing a class that is intended to be subclassed. What is the proper way to indicate that a sub class must override a method? If any subclass *must* override a method, raise NotImplementedError in the base class (apart from documenting how your class is supposed to be used). I learn so much from this list. I didn't even know this error existed. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: What is proper way to require a method to be overridden?
Grant Edwards schrieb: On 2007-01-05, Thomas Ploch [EMAIL PROTECTED] wrote: I am writing a class that is intended to be subclassed. What is the proper way to indicate that a sub class must override a method? If any subclass *must* override a method, raise NotImplementedError in the base class (apart from documenting how your class is supposed to be used). I learn so much from this list. I didn't even know this error existed. And remember: even if it didn't, you could have created your own: Erm, it wasn't me who asked. I just wanted to say that I didn't know that there is a NotImplementedError. Havn't seen it before. :-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: C/C++, Perl, etc. to Python converter
Matimus schrieb: I don't know of a converter, one may exist. I have seen similar requests though and will give you a similar response to what I have seen. A converter, if it exists, may be able to produce working code but _not_ readable code. Python is a language whose strength comes from, among other things, its readability and conventions. Learning python is best done by using the online documentation (http://docs.python.org/tut/tut.html) and reading existing code (take a look at the built in modules). My biggest fear of teaching someone to program by using a program to convert perl to python is that they will end up writing python that still looks like perl. I don't know if it helps, but I know others will give you similar advice. -Matt I think that it *is* possible to do it, but a whole lot of work had to be done to achieve this. It is all about how many rules (like how to convert this block of unreadable code of language X into a readable python block) you are willing to find/program (and these are a lot). It is a almost gigantic task to make this work proper, but it definitely *is* possible. Something like this doesn't exist yet, but people (especially Computational Linguists) are working on this. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: static object
meelab schrieb: Dear All, I am looking for a way to create a static object or a static class - terms might be inappropriate - having for instance: class StaticClass: . . and then staticObject1 = StaticClass() staticObject2 = StaticClass() so that staticObject1 and staticObject2 refers exactly to the same instance of object. In other words, that is a class which would result in only 1 instance always the same no matter how many times I will instantiate it. My purpose is to permit this class to initialize a massive amount of data that I need to access from different points of my program without duplicating this data in memory and without loosing time in reloading it each time I need it. I noticed the staticmethods, and the __new__ method which could , but I always get stuck in actually creating static DATA without having global data. Does anyone have a start of a clue to this ? Many thanks in advance Emmanuel. class DataStorage: def __init__(self, data): self.data = data dataVault = DataStorage(data) dataVault1 = dataVault dataVault2 = dataVault ... but why not use a static_data.py (put your data in there) file and do: from static_data.py import DATA This way you only load it once and it will be accessible throughout your program. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list [WebCrawler]
Marc 'BlackJack' Rintsch schrieb: In [EMAIL PROTECTED], Thomas Ploch wrote: Alright, my prof said '... to process documents written in structural markup languages using regular expressions is a no-no.' (Because of nested Elements? Can't remember) So I think he wants us to use regexes to learn them. He is pointing to HTMLParser though. Problem is that much of the HTML in the wild is written in a structured markup language but it's in many cases broken. If you just search some words or patterns that appear somewhere in the documents then regular expressions are good enough. If you want to actually *parse* HTML from the wild better use the BeautifulSoup_ parser. .. _BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/ Yes, I know about BeautifulSoup. But as I said it should be done with regexes. I want to extract tags, and their attributes as a dictionary of name/value pairs. I know that most of HTML out there is *not* validated and bollocks. This is how my regexes look like: import re class Tags: def __init__(self, sourceText): self.source = sourceText self.curPos = 0 self.namePattern = [A-Za-z_][A-Za-z0-9_.:-]* self.tagPattern = re.compile((?Pname%s)(?Pattr[^]*) % self.namePattern) self.attrPattern = re.compile( r\s+(?PattrName%s)\s*=\s*(?Pvalue\[^\]*\|'[^']*') % self.namePattern) You are probably right. For me it boils down to these problems: - Implementing a stack for large queues of documents which is faster than list.pop(index) (Is there a lib for this?) If you need a queue then use one: take a look at `collections.deque` or the `Queue` module in the standard library. Which of the two would you recommend for handling large queues with fast response times? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: WebCrawler (was: 'Question concerning this list')
Marc 'BlackJack' Rintsch schrieb: In [EMAIL PROTECTED], Thomas Ploch wrote: This is how my regexes look like: import re class Tags: def __init__(self, sourceText): self.source = sourceText self.curPos = 0 self.namePattern = [A-Za-z_][A-Za-z0-9_.:-]* self.tagPattern = re.compile((?Pname%s)(?Pattr[^]*) % self.namePattern) self.attrPattern = re.compile( r\s+(?PattrName%s)\s*=\s*(?Pvalue\[^\]*\|'[^']*') % self.namePattern) Have you tested this with tags inside comments? No, but I already see your point that it will parse _all_ tags, even if they are commented out. I am thinking about how to solve this. Probably I just take the chunks between comments and feed it to the regular expressions. You are probably right. For me it boils down to these problems: - Implementing a stack for large queues of documents which is faster than list.pop(index) (Is there a lib for this?) If you need a queue then use one: take a look at `collections.deque` or the `Queue` module in the standard library. Which of the two would you recommend for handling large queues with fast response times? `Queue.Queue` builds on `collections.deque` and is thread safe. Speedwise I don't think this makes a difference as the most time is spend with IO and parsing. So if you make your spider multi-threaded to gain some speed go with `Queue.Queue`. I think I will go for collections.deque (since I have no intention of making it multi-threaded) and have several queues, one for each server in a list to actually finish one server before being directed to the next one straight away (Is this a good approach?). Thanks a lot, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list [WebCrawler]
John Nagle schrieb: Very true. HTML is LALR(0), that is, you can parse it without looking ahead. Parsers for LALR(0) languages are easy, and work by repeatedly getting the next character and using that to drive a single state machine. The first character-level parser yields tokens, which are then processed by a grammar-level parser. Any compiler book will cover this. Using regular expressions for LALR(0) parsing is a vice inherited from Perl, in which regular expressions are easy and get next character from string is unreasonably expensive. In Python, at least you can index through a string. John Nagle I take it with LALR(0) you mean that HTML is a language created by a Chomsky-0 (regular language) Grammar? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Question concerning this list
Hello fellow pythonists, I have a question concerning posting code on this list. I want to post source code of a module, which is a homework for university (yes yes, I know, please read on...). It is a web crawler (which I will *never* let out into the wide world) which uses regular expressions (and yes, I know, thats not good, too). I have finished it (as far as I can), but since I need a good mark to actually finish the course, I am wondering if I can post the code, and I am wondering if anyone of you can review it and give me possible hints on how to improve things. So is this O.K.? Or is this a blatantly idiotic idea? I hope I am not the idiot of the month right now... Thanks in advance, Thomas P.S.: I might give some of my Christmas chocolate away as a donation to this list... :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list
Steven D'Aprano wrote: On Sun, 31 Dec 2006 02:03:34 +0100, Thomas Ploch wrote: Hello fellow pythonists, I have a question concerning posting code on this list. I want to post source code of a module, which is a homework for university (yes yes, I know, please read on...). So long as you understand your university's policy on collaborations. Well, collaborations are wanted by my prof, but I think he actually meant it in a way of getting students bonding with each other and establishing social contacts. He just said that he will reject copy paste stuff and works that actually have nothing to do with the topic (when we were laughing, he said we couldn't imagine what sometimes is handed in). It is a web crawler (which I will *never* let out into the wide world) If you post it on Usenet, you will have let it out into the wide world. People will see it. Some of those people will download it. Some of them will run it. And some of them will run it, uncontrolled, on the WWW. Out of curiosity, if your web crawler isn't going to be used on the web, what were you intending to use it on? It's a final homework, as I mentioned above, and it shouldn't be used anywhere but our university server to test it (unless timing of requests (i.e. only two fetches per second), handling of 'robots.txt' is implemented). But you are right with the Usenet thing, havn't thought about this actually, so I won't post the whole portion of the code. which uses regular expressions (and yes, I know, thats not good, too). Regexes are just a tool. Sometimes they are the right tool for the job. Sometimes they aren't. Alright, my prof said '... to process documents written in structural markup languages using regular expressions is a no-no.' (Because of nested Elements? Can't remember) So I think he wants us to use regexes to learn them. He is pointing to HTMLParser though. I have finished it (as far as I can), but since I need a good mark to actually finish the course, I am wondering if I can post the code, and I am wondering if anyone of you can review it and give me possible hints on how to improve things. It probably isn't a good idea to post a great big chunk of code and expect people to read it all. If you have more specific questions than how can I make this better?, that would be good. Unless the code is fairly short, it might be better to just post a few extracted functions and see what people say about them, and then you can extend that to the rest of your code. You are probably right. For me it boils down to these problems: - Implementing a stack for large queues of documents which is faster than list.pop(index) (Is there a lib for this?) - Getting Handlers for different MIME/ContentTypes and specify callbacks only for specific Content-Types / MIME-Types (a lot of work and complex checks) - Handle different encodings right. I will follow your suggestions and post my code concerning specifically these problems, and not the whole chunk. Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Merry Christmas and a happy new year!
I wish everybody a merry Christmas and a happy new year. Have a good and beautiful new year. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating all permutations from a regexp
Fredrik Lundh wrote: Nick Craig-Wood wrote: A regular expression matcher uses a state machine to match strings. unless it's the kind of regular expression matcher that doesn't use a state machine, like the one in Python. /F How is the matching engine implemented then? I thought regular languages can be described by deterministic / non-deterministic finite state machines. I am just curious ... Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Fall of Roman Empire
Delaney, Timothy (Tim) wrote: Hendrik van Rooyen wrote: naaah - you don't have to worry - for real control He uses assembler. with jump statements. so the loops are closed. Unfortunately its not open source. Yet. People are working hard on reverse-engineering it though. I hope no one slaps them with a DMCA-style lawsuit ... Tim Delaney I heard Steve Ballmer recently made an offer to the pope for purchasing the license for an apple and an egg (Apfel und Ei). Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Fall of Roman Empire
Ben Finney schrieb: John Machin [EMAIL PROTECTED] writes: Ben Finney wrote: \ ...one of the main causes of the fall of the Roman Empire was | `\that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs. -- Robert Firth | An amusing .sig, but it doesn't address the root cause: As they had no way of testing for the end of a string, in many cases successful termination of their C programs would have been unlikely. Yet historically proven: the 'imperium' process they were running terminated many centuries ago. Or did it fork and exec a different process? And what about the C-Programs running in the middle of the sun or earth making them spinning around or having nuclear reactions controlled. I hope they won't terminate in the near future with exit status != 0 -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp
Mark Schoonover schrieb: You have to pay for this one, but I do like Komodo just for the regex feature. I'm rather new to Python, coming over from 10 years of Perl, and it's nice to have Komodo stay consistant. Can't wait for 4.0, so I can get back to having VI key commands Back into Learning Python, and DIP... Yes, I love that, too. The Komodo Rx Toolkit is really good for people who are new to regular expressions just to try them out, to get to know grouping, to see how MULTILINE and other flags work. I can recommend this to anyone who is new to regexes. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Fall of Roman Empire
Ben Finney schrieb: John Machin [EMAIL PROTECTED] writes: Ben Finney wrote: \ ...one of the main causes of the fall of the Roman Empire was | `\that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs. -- Robert Firth | An amusing .sig, but it doesn't address the root cause: As they had no way of testing for the end of a string, in many cases successful termination of their C programs would have been unlikely. Yet historically proven: the 'imperium' process they were running terminated many centuries ago. Or did it fork and exec a different process? I rather stay with the metaphysics: #include metaphysics.h static metaPower God; universe *makeUniverse(metaPower God) { if (!God) { printf(Oops, no God available at the moment.Try again later!); return NULL; } universe *everything; if (!(everything = malloc(sizeof(universe { God.mood = REALLY_BORED; printf(God has no time to create a universe.); return NULL; } else { return universe; } } :-) Sorry, somehow had to do this. Please slap me (i like it, don't worry) if it's totally stupid -- http://mail.python.org/mailman/listinfo/python-list
Re: Fall of Roman Empire
Felix Benner schrieb: Thomas Ploch schrieb: Ben Finney schrieb: John Machin [EMAIL PROTECTED] writes: Ben Finney wrote: \ ...one of the main causes of the fall of the Roman Empire was | `\that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs. -- Robert Firth | An amusing .sig, but it doesn't address the root cause: As they had no way of testing for the end of a string, in many cases successful termination of their C programs would have been unlikely. Yet historically proven: the 'imperium' process they were running terminated many centuries ago. Or did it fork and exec a different process? I rather stay with the metaphysics: #include metaphysics.h static metaPower God; universe *makeUniverse(metaPower God) { if (!God) { printf(Oops, no God available at the moment.Try again later!); return NULL; } universe *everything; if (!(everything = malloc(sizeof(universe { God.mood = REALLY_BORED; printf(God has no time to create a universe.); return NULL; } else { return universe; } } :-) Sorry, somehow had to do this. Please slap me (i like it, don't worry) if it's totally stupid s totally stupid! You forgot the main function! (not to mention you returned universe instead of everything) Argh, I need some serious slapping (but I changed everything and universe, and just forgot to change it all the way through (...good that I am _not_ God) static int main(int argc, char **argv) { char *god_name; if (argc) god_name = argv[1]; else god_name = YHWH; metaPower God = getGodByName(god_name); universe *everything = makeUniverse(God); while (simulatePhysics(everything)); return 0; } You forgot to check if God wasn't too bored. ;-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: perl better than python for users with disabilities?
Martin P. Hellwig schrieb: Quite punny title though I assume you are really serious and mean people with a physical disability, I won't comment any further on this subject :-), if I already offended anyone, please excuse me, since I'm original from Germany I'm not supposed to be funny. Argh, I am writing to President Horst Köhler to take away your German citizenship. You _need_ to stay true to German attributes (like not being funny, what you have been...)! This is the last warning! :-D Regarding the topic: I can't see where Perl should be more accessible than Python. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Does any one know of any good folder/directory modules
[EMAIL PROTECTED] schrieb: Hi Does any one know of any good folder/directory modules. I need to be able to see what files and directories are in a folder, I also need to be able to see the size of the directory content. Thanks You should have a look here: http://docs.python.org/lib/os-file-dir.html#os-file-dir Thomas (This could have been done by yourself, but I am in a christmasly mood) -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expression
Asper Faner schrieb: I seem to always have hard time understaing how this regular expression works, especially how on earth do people bring it up as part of computer programming language. Natural language processing seems not enough to explain by the way. Why no eliminate it ? Erm, I am a student of Computational Linguistics and _NO_ , they should _NOT_ be eliminated since they are an important part of language processing in python. Read this: http://www.amk.ca/python/howto/regex/ -- http://mail.python.org/mailman/listinfo/python-list
Re: A Call to Arms for Python Advocacy
Roy Smith schrieb: In article [EMAIL PROTECTED], Jeff Rush [EMAIL PROTECTED] wrote: As the Python Advocacy Coordinator, I've put up some wiki pages on the Python website for which I'm soliciting ideas, writing and graphics. Some of the material exists scattered about and just needs locating and organizing. http://wiki.python.org/moin/Advocacy I think it also appears to need faster hardware. It's running glacially slow. I hope you are _not_ using IE... (Sorry, I didn't want to offend you, but it's fine with me ,too.) :-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: A Call to Arms for Python Advocacy
Thomas Ploch schrieb: Roy Smith schrieb: In article [EMAIL PROTECTED], Jeff Rush [EMAIL PROTECTED] wrote: As the Python Advocacy Coordinator, I've put up some wiki pages on the Python website for which I'm soliciting ideas, writing and graphics. Some of the material exists scattered about and just needs locating and organizing. http://wiki.python.org/moin/Advocacy I think it also appears to need faster hardware. It's running glacially slow. I hope you are _not_ using IE... (Sorry, I didn't want to offend you, but it's fine with me ,too.) :-) Thomas Well, I should have not answered right the first of 107 messages without reading further... Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: About the 79 character line recommendation
Hello, for me the 80 (or 79) char border when writing code is a fundamental rule. Being at University and having to document each project on paper, it is a must do. i.e. I get code from fellow scolars, that have 160 chars per line, and to get that on paper is disgusting, especially in C/C++. So please, stay true to that. And don't forget those, who actually view source code in a terminal. :-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
stdazi wrote: Usually, when I make some coding mistake (index out of range - in this case) I just care to fix the mistake and I usually don't mind to inspect by how much the index was overflowed. It really seems like a feature that should be embedded in some Python debugger than a feature in the interpreter itself. I read the whole thread and this is more or less the first post which actually has a good thing to say without saying any bad thing about anyone. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: python vs java eclipse
Thomas Ploch schrieb: Amir Michail schrieb: Hi, It seems to me that measuring productivity in a programming language must take into account available tools and libraries. Eclipse for example provides such an amazing IDE for java that it is no longer obvious to me that one would be much more productive in python for medium sized projects. Sure, all that Java static typing can be painful, but Eclipse takes some of that pain away. Moreover, static typing can result in better on-the-fly error detection and refactoring support. Any thoughts on this? Amir Yes, thats true, but since eclipse is resource monster (it is still using java), and some people (like me) don't have a super fresh and new computer, and have to run other services to test their work locally (like mysql and apache servers), it gets pretty harsh with eclipse. I personally tried eclipse on my laptop (which I work most with), and I had quite a system resource problem. So I switched back to vim and console and it hasn't been too bad, since if you know how to use a powerful editor, it can be as productive. But in the end, it is up to anyone to find the best solutiion for themselves. Thomas Yes, thats true, but since eclipse is resource monster (it is still using java), and some people (like me) don't have a super fresh and new computer, and have to run other services to test their work locally (like mysql and apache servers), it gets pretty harsh with eclipse. I personally tried eclipse on my laptop (which I work most with), and I had quite a system resource problem. So I switched back to vim and console and it hasn't been too bad, since if you know how to use a powerful editor, it can be as productive. But in the end, it is up to anyone to find the best solutiion for themselves. Thomas -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
Amir Michail schrieb: krishnakant Mane wrote: just used the py dev plugin for eclipse. it is great. But isn't support for java better because the eclipse ide can take advantage of explicit type declarations (e.g., for intellisense, refactoring, etc.)? Amir Obviously, since eclipse _is_ a full blown Java application, so support for Java is excellent. It was actually developed for being a Java IDE but (as far as I know) people were liking it so much, so they decided to make it expandable (and PyDev is actually a good thing, it supports PyLint and PyChecker, manages the python path when new modules are added, but can be improved (as can everything :-) )). But as I said, often my system hangs when having quite a few files opened, so that brought me off using it too often. Thomas -- Ein Herz für Kinder - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht! -- http://mail.python.org/mailman/listinfo/python-list
Re: SPE refuses.
SPE - Stani's Python Editor schrieb: On 30 nov, 10:50, egbert [EMAIL PROTECTED] wrote: On Wed, Nov 29, 2006 at 03:15:45PM -0800, SPE - Stani's Python Editor wrote: Do you have python-wxversion installed? $sudo apt-get install python-wxversionThat helped. But why isn't it included in the wxPython download ? I was surprised as well. I filed a bug report at debian MOTU that spe depends as well on python-wxversion, so that it is automatically installed together with spe in the future. Anyway, the first screen looks great. I will explore spe. Thanks. You're welcome! Stani ell, when reading these posts about SPE, I wanted to try it as well. I am running the newest version of wxpython with python2.4. I installed it, all went fine with the setup.py script. When I tried to open the program, a window appears for about a second, displaying a traceback. So I ran the SPE.py debug tool as you have recommended earlier. here's the output: Spe is running in debugging mode with this configuration: - platform : darwin - python: 2.4.4 - wxPython : 2.7.1.3. - interface : default - encoding : mac-roman Launching application... Create: Framework: menu. Create: Framework: toolbar. Create: Framework: statusbar. Traceback (most recent call last): File SPE.py, line 209, in ? style = style) File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/sm/wxp/smdi.py, line 1278, in __init__ wx.App.__init__(self,redirect=not debug) File //Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/wx-2.7.1-mac-unicode/wx/_core.py, line 7480, in __init__ self._BootstrapApp() File //Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/wx-2.7.1-mac-unicode/wx/_core.py, line 7080, in _BootstrapApp return _core_.PyApp__BootstrapApp(*args, **kwargs) File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/sm/wxp/smdi.py, line 1297, in OnInit style = self.style, File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/sm/wxp/smdi.py, line 801, in __init__ Parent.__init__(self,app=app,page=page,**options) File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/sm/wxp/smdi.py, line 595, in __init__ parentFrame = self, File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/sm/wxp/smdi.py, line 325, in __init__ self.__statusBar__() File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/sm/wxp/smdi.py, line 417, in __statusBar__ self.statusBar = self.app.StatusBar(parent=self,id=wx.ID_ANY) File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/Menu.py, line 727, in __init__ self.throbber = Throbber(self,'throbber_still.gif') File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/Menu.py, line 733, in __init__ GIFAnimationCtrl.__init__(self,statusBar,-1,info.imageFile(fileName)) File //Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/wx-2.7.1-mac-unicode/wx/animate.py, line 242, in __init__ self.LoadFile(filename) File /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/_spe/Menu.py, line 746, in LoadFile if fileName != self._fileName and not self._running: AttributeError: 'Throbber' object has no attribute '_fileName' Thanks for any help. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Worship
Nick schrieb: http://www.sciencedaily.com/releases/2006/11/061130081347.htm World's Oldest Ritual Discovered -- Worshipped The Python 70,000 Years Ago Nick That's really interesting since there is an indio tribe in the amazonas jungle which also worships python. That just tells me Python is right. Whatever angle you look at it. :-D Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: failure building python 2.5 on mac os x 10.3.9
Markus Rosenstihl schrieb: On 2006-11-19 15:50:14 +0100, Thomas Ploch [EMAIL PROTECTED] said: Hello, I followed the instructions in the Mac/README file. I ran ./configure --enable-framework But when I try to build from source with gcc 4.0.2, following happens: [snip] libtool: can't locate file for: -lSystemStubs libtool: file: -lSystemStubs is not an object file (not allowed in a library) make: *** [Python.framework/Versions/2.5/Python] Error 1 What does that mean? Thanks, Thomas I had the same problem (why do you have gcc-4.0.2?). -lSystemStubs is in Tiger First of all, try to install the 10.4 SDK as it will keep you away of a lot of linking problems and such stuff. (yes, it will install on 10.3.9 and since then i had no compile problems, i found this as an answer in a post in the apple discussions) Then try to compile it again after you have deleted the python source tree (or make clean). If that is still not working you have to edit the Makefile from Python and remove the -lSystemStubs (i think both ways work, but i am not sure) Make sure you have either a patched readline 5.1 or better a readline 5.2. Otherwise you will get segmentation faults when you are using ipython. If it is still not working, Good luck! Thank you, has been quite a while since I asked, almost forgot about that one. :-) I have been using static python for a while, because I couldn't get around the problem. But after a while I needed the dynamic linker for some extensions so I thought about what it could be. I ran into the Mac OS 10.3.9 Python (the shipped one) Bug, and remembered not having fixed it with the fixmacpython.py (or whatever it's called) script. So I tried building python framework again, and whoohoo, it worked. I dunno if it was that or that I updated libtool, gettext and all that stuff, but hey, I have to admint, I don't care anymore. :-) But it's nice to know that the Tiger Dev Tools run on Panther as well. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Automatic increment
Gheorghe Postelnicu schrieb: Hi, I have a situation of the following type: for line in lineList: for item in line.split() myArray[counter, itemCounter] itemCounter = itemCounter + 1 counter = counter +1 Is there a way to get rid of the manual incrementation of the 2 counters? Thanks, for counter in xrange(len(lineList)): for itemCounter in xrange(len(lineList[counter].split())) myArray[counter, itemCounter] Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry schrieb: If I have a list of say, 10 elements and I need to slice it into irregular size list, I would have to create a bunch of temporary variables and then regroup them afterwords, like: # Just for illustration. Alist can be any existing 10 element list a_list=(,)*10 (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list alist=(a,) blist=(b,) clist=(c1,c2,c3) dlist=(d2,d3,d4,d5) That obviously work but do I *really* have to do that? BTW: I know you can do: alist=a_list[0] blist=a_list[1] clist=a_list[2:5] dlist=a_list[5:] but I don't see that it's any better. Can I say something to the effect of: (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work ?? I am asking this because I have a section of code that contains *lots* of things like this. It makes the code very unreadable. Thanks, Nothing in your code actually __is__ a list. they are all tuples... A list is: aList = [a,b,c1,c2,c3,d1,d2,d3,d4,d5] Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry schrieb: If I have a list of say, 10 elements and I need to slice it into irregular size list, I would have to create a bunch of temporary variables and then regroup them afterwords, like: # Just for illustration. Alist can be any existing 10 element list a_list=(,)*10 (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list alist=(a,) blist=(b,) clist=(c1,c2,c3) dlist=(d2,d3,d4,d5) That obviously work but do I *really* have to do that? BTW: I know you can do: alist=a_list[0] blist=a_list[1] clist=a_list[2:5] dlist=a_list[5:] but I don't see that it's any better. Can I say something to the effect of: (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work ?? I am asking this because I have a section of code that contains *lots* of things like this. It makes the code very unreadable. Thanks, I had a little bit of fun while writing this: itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. def getSlices(aCount, bCount, cCount, dCount, items): a,b,c,d = (items[0:aCount], items[aCount:aCount+bCount], items[aCount+bCount:aCount+bCount+cCount], item[aCount+bCount+cCount:aCount+bCount+cCount+dCount]) return list(a),list(b),list(c),list(d) a,b,c,d = getSlices(1,1,3,5,itemList) print a,b,c,d ['a'] ['b'] ['c1', 'c2', 'c3'] ['d1', 'd2', 'd3', 'd4', 'd5'] a,b,c,d = getSlices(3,1,1,0,itemList2) print a,b,c,d ['a1', 'a2', 'a3'] ['b'] ['c'] [] %-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry schrieb: Thomas Ploch wrote: snip I had a little bit of fun while writing this: itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. Huh? What's a,b,d5? John Henry schrieb: Thomas Ploch wrote: snip I had a little bit of fun while writing this: itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. Huh? What's a,b,d5? Can be any object, as you had in your example in your mail: If I have a list of say, 10 elements and I need to slice it into irregular size list, I would have to create a bunch of temporary variables and then regroup them afterwords, like: # Just for illustration. Alist can be any existing 10 element list a_list=(,)*10 (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list alist=(a,) blist=(b,) clist=(c1,c2,c3) dlist=(d2,d3,d4,d5) def getSlices(aCount, bCount, cCount, dCount, items): a,b,c,d = (items[0:aCount], items[aCount:aCount+bCount], items[aCount+bCount:aCount+bCount+cCount], item[aCount+bCount+cCount:aCount+bCount+cCount+dCount]) You meant items here, right? return list(a),list(b),list(c),list(d) a,b,c,d = getSlices(1,1,3,5,itemList) print a,b,c,d ['a'] ['b'] ['c1', 'c2', 'c3'] ['d1', 'd2', 'd3', 'd4', 'd5'] a,b,c,d = getSlices(3,1,1,0,itemList2) print a,b,c,d ['a1', 'a2', 'a3'] ['b'] ['c'] [] %-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
Robert R. schrieb: Hello, i would like to write a piece of code to help me to align some sequence of words and suggest me the ordered common subwords of them s0 = this is an example of a thing i would like to have.split() s1 = another example of something else i would like to have.split() s2 = 'and this is another example but of something ; now i would still like to have'.split() ... alist = (s0, s1, s2) result should be : ('example', 'of', 'i', 'would', 'like', 'to', 'have' but i do not know how should i start, may be have you a helpful suggestion? a trouble i have if when having many different strings my results tend to be nothing while i still would like to have one of the, or maybe, all the best matches. best. As far as I can see, you want to have the words, that all three lists have in common, right? s0 = this is an example of a thing i would like to have.split() s1 = another example of something else i would like to have.split() s2 = 'and this is another example but of something ; now i would still like to have'.split() def findCommons(s0, s1, s2): res = [] for word in s0: if word in s1 and word in s2: res.append(word) return res print findCommons(s0,s1,s2) ['example', 'of', 'i', 'would', 'like', 'to', 'have'] -- http://mail.python.org/mailman/listinfo/python-list
Open and closing files
Is it defined behaviour that all files get implicitly closed when not assigning them? Like: def writeFile(fName, foo): open(fName, 'w').write(process(foo)) compared to: def writeFile(fName, foo): fileobj = open(fName, 'w') fileobj.write(process(foo)) fileobj.close() Which one is the 'official' recommended way? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: working with files and directories
halex2000 schrieb: Hi all, I'm new with Python, and I thought to use it to automatically rename some files in a directory, but I don't know where should I search the functions: to get all the files of a directory, to rename the files and so on. Thank you. Have you actually even tried to find some documentation? Have you placed a google search python directories rename files? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: synching with os.walk()
os.walk() is a nice generator for performing actions on all files in a directory and subdirectories. However, how can one use os.walk() for walking through two hierarchies at once? I want to synchronise two directories (just backup for now), but cannot see how I can traverse a second one. I do this now with os.listdir() recursively, which works fine, but I am afraid that recursion can become inefficient for large hierarchies. I've run into wanting to work with parallel directory structures before, and what I generally do is something like: for root, dirs, files in os.walk( dir1 ): dir2_root = dir2 + root[len(dir1):] for f in files: dir1_path = os.path.join( root, f ) dir2_path = os.path.join( dir2_root, f ) Wouldn't it be better to implement tree traversing into a class, then you can traverse two directory trees at once and can do funny things with it? Thomas -- http://mail.python.org/mailman/listinfo/python-list
failure building python 2.5 on mac os x 10.3.9
Hello, I followed the instructions in the Mac/README file. I ran ./configure --enable-framework But when I try to build from source with gcc 4.0.2, following happens: [snip] libtool: can't locate file for: -lSystemStubs libtool: file: -lSystemStubs is not an object file (not allowed in a library) make: *** [Python.framework/Versions/2.5/Python] Error 1 What does that mean? Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Understanding Python Source Code - where to start?
Hello folks, I am thinking about reading and understanding the Source Code of Python, but where would it be best to start? Possibly someone can give me a little hint. I am getting into socketmodule.c a little bit at the moment, but thats not what I want. Greetz, Thomas -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Python 2.5 Problems on MAC OS 10.3.9
Hello folks, Since this is my first post on the list, a brief introduction of myself. My name is Thomas, I am 26 years old, I am a student of Computational Linguistics and I am a python user. :-) Now my problem: I have Tcl/Tk 8.4.4 installed: iPimpG4:~ profipimp$ tclsh % info patchlevel 8.4.4 % But when I try to import Tkinter import Tkinter Traceback (most recent call last): File stdin, line 1, in module File /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py, line 38, in module import _tkinter # If this fails your Python may not be configured for Tk ImportError: dlcompat: dyld: /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python can't open library: /Library/Frameworks/Tk.framework/Versions/8.4/Tk (No such file or directory, errno = 2) ...this happens. Why? Tkinter worked perfectly with 2.3 and 2.4... Cheers, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Python 2.5 Problems on MAC OS 10.3.9
Kevin Walzer schrieb: Thomas Ploch wrote: Hello folks, Since this is my first post on the list, a brief introduction of myself. My name is Thomas, I am 26 years old, I am a student of Computational Linguistics and I am a python user. :-) Now my problem: I have Tcl/Tk 8.4.4 installed: iPimpG4:~ profipimp$ tclsh % info patchlevel 8.4.4 % But when I try to import Tkinter import Tkinter Traceback (most recent call last): File stdin, line 1, in module File /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py, line 38, in module import _tkinter # If this fails your Python may not be configured for Tk ImportError: dlcompat: dyld: /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python can't open library: /Library/Frameworks/Tk.framework/Versions/8.4/Tk (No such file or directory, errno = 2) ...this happens. Why? Tkinter worked perfectly with 2.3 and 2.4... Cheers, Thomas Where is your installation of Tcl/Tk? It sounds like Python can't find it. Were you using the standard MacPython builds previously, or Unix-based builds from Fink or DarwinPorts? I built python from source using gcc 4.0.1, but I have solved it by installing a version of Tcl/TkAqua, now everything runs fine. Still I dont know why that has happened. The fink directories are in searchpath... Thanks for your help, Thomas -- http://mail.python.org/mailman/listinfo/python-list