Early Bird Registration closes Tuesday - Leipzig Python Workshop
Early bird workshop registration closes Tuesday (August 15th). Late registration will be available until the workshop starts, but at a greater cost. === Workshop Python im deutschsprachigen Raum === Der letzte Termin für den Frühbucherrabatt ist Dienstag, der 15. August. Danach sind Anmeldungen noch bis zum Beginn des Workshops möglich, die Anmeldegebühr ist aber etwas höher. Anmeldungen unter: http://www.python-academy.de/workshop/anmeldung.html === Workshop-Details === Am 8. September 2006 findet in Leipzig der Workshop Python im deutschsprachigen Raum statt. Der Workshop ist als Ergänzung zu den internationalen und europäischen Python-Zusammenkünften gedacht. Die Themenpalette der Vorträge ist sehr weit gefasst und soll alles einschließen, was mit Python im deutschsprachigen Raum zu tun hat. Eine ausführliche Beschreibung der Ziele des Workshops, der Workshop-Themen sowie Details zu Organisation und Anmeldung sind unter http://www.python-academy.de/workshop nachzulesen. === Wichtige Termine === 15.08.2006 Letzter Termin für Frühbucherrabatt 08.09.2006 Workshop 15.09.2006 Letzter Termin für die Einreichung der publikationsfähigen Beiträge Dezember 2006 Veröffentlichung des Tagungsbandes === Bitte weitersagen === Der Workshop soll auch Leute ansprechen, die bisher nicht mit Python arbeiten. Wer mithelfen möchte den Workshop bekannt zu machen, kann einen Link auf http://www.python-academy.de/workshop setzen. Auch außerhalb des Internets kann der Workshop durch den Flyer http://www.python-academy.de/download/programm.pdf bekannt gemacht werden. Einfach doppelseitig ausdrucken oder kopieren und ein paar Exemplare am Schwarzen Brett von Universitäten, Firmen, Organisationen usw. aushängen. Wir freuen uns auf eine rege Teilnahme, Mike Müller Stefan Schwarzer -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Drawing a grid on a picture
I also found a reference to something called PIL. Maybe that's the ticket. If so, where can I find it (with documentation)? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tk not working in Linux
In [EMAIL PROTECTED], BinnyVA wrote: Some distributions move the `Tkinter` stuff into an own package. Search for a package called `python-tk` or `python-tkinter` or similar. I could use a 'python-tk' package - but the problem is the latest version of python may not be available. That's always the problem with packaged software. But you gain fast and easy installation via the package system. I am going to download Tcl/Tk and install it. Then I would try to install Python once again. Just install the necessary development packages for your installed Tcl/Tk and compile the Python sources. Unless you really want to compile everything yourself. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing a grid on a picture
Jive Dadson wrote: I also found a reference to something called PIL. Maybe that's the ticket. If so, where can I find it (with documentation)? Thanks. The will likely do what you want. And you can find it the same way that you would find anything online i.e. with google. But here is the link: http://www.pythonware.com/products/pil/ Cheers, Brian -- http://mail.python.org/mailman/listinfo/python-list
PIL and solaris
Hi all, I am trying to install PIL with python 2.3 on solaris X86, but I get this error message : building '_imaging' extension creating build/temp.solaris-2.10-i86pc-2.3 creating build/temp.solaris-2.10-i86pc-2.3/libImaging /sgnome/tools/x86-solaris/forte/SOS8/SUNWspro/bin/cc -i -xO4 -xspace -xstrconst -xpentium -mr -DANSICPP -D__STDC_VERSION__=199409L -DNDEBUG -O -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/sfw/include/freetype2 -IlibImaging -I/usr/sfw/include -I/usr/local/include -I/usr/include -I/usr/sfw/include/python2.3 -c libImaging/Antialias.c -o build/temp.solaris-2.10-i86pc-2.3/libImaging/Antialias.o unable to execute /sgnome/tools/x86-solaris/forte/SOS8/SUNWspro/bin/cc: No such file or directory error: command '/sgnome/tools/x86-solaris/forte/SOS8/SUNWspro/bin/cc' failed with exit status 1 [EMAIL PROTECTED] # pwd /export/home/lmtansu/Imaging-1.1.6b1 It works fine with python 2.2 however Do you have any recommendation? Advices? -- http://mail.python.org/mailman/listinfo/python-list
Re: access abook addressbook with curses
Hi Ben, * Ben C [EMAIL PROTECTED] wrote: On 2006-08-08, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi Ben, * Ben C [EMAIL PROTECTED] wrote: On 2006-08-06, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi Ben, * Ben C [EMAIL PROTECTED] wrote: On 2006-08-05, Fabian Braennstroem [EMAIL PROTECTED] wrote: Hi, I want to get access to my abook address file with python. Does anyone have some python lines to achive this using curses? If not, maybe anybody has small python program doing it with a gui!? You can just parse the abook addressbook with the ConfigParser, try this: import os from ConfigParser import * abook = ConfigParser() abook.read(os.environ[HOME] + /.abook/addressbook) for s in abook.sections(): print abook.items(s) Thanks! I found a different example too: import ConfigParser import string config = ConfigParser.ConfigParser() config.read(/home/fab/.abook/addressbook) # print summary print for number in [2,200]: print string.upper(config.get(str(number), email)) print string.upper(config.get(str(number), name)) print string.upper(config.get(str(number), city)) print string.upper(config.get(str(number), address)) but the problem seems to be that abook does not write every field, so I get an exception when there is a field missing: Traceback (most recent call last): File configparser-example-1.py, line 13, in ? print string.upper(config.get(str(number), city)) File /usr/lib/python2.4/ConfigParser.py, line 520, in get raise NoOptionError(option, section) ConfigParser.NoOptionError: No option 'city' in section: '2' Section 2 looks like: [2] name=Andrs Gzi [EMAIL PROTECTED] nick=oz Is there a workaround? You can construct the parser with a dictionary of defaults: config = ConfigParser.ConfigParser({city : unknown, zip : unknown}) that kind of thing. Or catch the exceptions. Or use config.options(2) to see what options exist in section 2 before you try to read them. Thanks! I will try it out! Looking at the bigger picture here, though, I may be giving you the wrong advice. Mutt just invokes abook to get the addresses I think, that's why you put set query_command=abook --mutt-query '%s' So you could do the same (if what you're trying to do is write a mutt clone in Python): import subprocess name = Andrs subprocess.Popen(abook --mutt-query + name, stdout=subprocess.PIPE, shell=True).communicate()[0] The difference is that this leverages abook to do the search, not just to store the data, which is a logical approach. On the other hand, this way, you require that abook is installed on the machine, which is no good if the object of the exercise is a portable Python-only solution. The biggest problem is a missing and not allowed abook installation. But thanks for your tips! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing a grid on a picture
Sybren Stuvel wrote: Jive Dadson enlightened us with: I also found a reference to something called PIL. Maybe that's the ticket. If so, where can I find it (with documentation)? Thanks. Just google for PIL and Python. Sybren Thanks Brian and Sybren. PIL did the trick. Real easy. -- http://mail.python.org/mailman/listinfo/python-list
Re: selecting base class from user input
Thanks for the reply. danielx wrote the following on 2006-08-13 19:49: Is your declaration of ABC supposed to have some_super as one of the base classes? Your constructor has some_super as a parameter. What is this supposed to mean in light of the declaration for ABC? Indeed, my goal is to have the base class of ABC determined dynamically via a parameter passed into the constructor. If you are trying to customize the base class of ABC by passing an argument to the constructor of ABC, you should probably reconsider. If constructing one instance of ABC can change ABC (the class) itself, then the behavior of other instances will be affected as well. No programmer can stay sane if he creates instances of a class that could suddenly change its behavior (due to someone else's code). Fortunately, the ABC class is not very useful. In fact, it was mostly just to be used to store particular examples of the user-specified base class. So all method calls would be from the base class only. What you could do instead is to create a function which constructs classes based on the arguments it recieves. Then, you'll be able to create instances of the generated classes (all this meta-thinking is huring my brain ;). I am talking about something like this: def createClass(name, base): exec class %s(%s): pass % (name, base) return eval( name ) In fact, this is exactly what I ended up doing. def example(base): if base == SomeClass: # call SomeClass.__init__(self) # build example as it would look in SomeClass elif base == SomeOtherClass: # call SomeOtherClass.__init__(self) # build example as it would in SomeOtherClass Can you please tell us why you are doing this? My curiosity is killing me! So here is a good example: I have 4 classes: Lion(Animal): Ant(Animal): Bee(Animal): Human(Animal): which are all subclasses of some superclass called Animal. Now I want to define an occupation. For example, Worker. A worker can exist as any of the 4 classes above. Their constructors are different and I might want to add certain features. My first thought was to create a class called Worker and have the base class determined by a variable which is passed into the constructor. Most of the method calls will come from the Animal superclass anyway, but some method calls might come from the Lion class, for example. Now I realize this would drive a programmer crazy...because a Lion might have a roar() method whereas a Human might have a holler() method. But so long as the user knew which argument they passed in, it shouldn't be too difficult to keep track of it. So for example (again, I know what I am typing doesn't actually work)... Worker(some_animal): def __init__(self,some_animal): # change the base class to some_animal if some_animal == Lion: # give the lion a big mane if some_animal == Ant: # make the ant dumb if some_animal == Bee: # make the bee know how to dance if some_animal == Human # give the human a hardhat def work(self, hours): # tell the animal to work for the specified number of hours if some_animal == Lion: self.cat_nap(hours) if some_animal == Ant: self.walk_back_and_forth(hours) if some_animal == Bee: self.buzz_and_dance(hours) if some_animal == Human: self.use_hammer_on_coworker(hours) # notice, a Human does not have a cat_nap method def take_lunch(location): and so on. So the thought is that a Worker can exist in many different forms: as a lion, as an ant, as a bee, and as a human. And I might want a single worker class that represents them all. Hopefully this makes sense. Another meta-thought: Hopefully I've beaten everyone else to the punch about that question. Is it just me, or will a reply with such a question always tell the original poster that what he wants to do MUST be flawed? I hope I have been gentler than this. :-) There is no need to be too gentle. We are all here to learn (or help). So I am fairly happy with the def solution...any comments on this? But a Worker is an noun, and it seems like the proper way to do this is to make the Worker into a class...so that I can define methods like work, take_lunch, etc. However, I have no idea how I should do this. Perhaps someone can recommend a procedure. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Strange problem with Tkinter... photos don't show on first iteration.
Hi all. Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a forward and back button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the first page of results shows up. When I click the search again button, and have more than the original results page to toggle between, the images __do__ show up on the first page of results. (and on the second, etc, etc.) Which is to say, there's no error messages, and on the first page, the first time it's shown, the Toplevel formats correctly, and there are spaces where the images should be that are the correct size, just... no images. It's baffling me. Perhaps someone can help. Cheers, Al. Script attached (apologies for it not being as neat as it probably should be... :) from Tkinter import * import sys import cPickle #opens gui and displays returned image thumbnails class Im_Res1: def __init__(self, master, lof, pageno): self.master = root root.withdraw() nav_child(master, lof, pageno) self.master.mainloop() # the child window class class nav_child: def __init__(self, master, lof, pageno): self.slave = Toplevel(master) self.slave.grid() self.slave.title(Image Results) self.picts = [] lif = lof[pageno] lenlif = len(lif) for r in range(lenlif): j = lif[r] f = j[2] self.img = PhotoImage(file = f) self.picts.append(self.img) print self.picts = , self.picts for g in range(lenlif): text = (lif[g])[1]# label text def callback(text=text): x=win32com.client.Dispatch('InternetExplorer.Application.1') x.Visible=1 x.Navigate(text) p = open(VerRes.txt, 'w') p.write(text) p.close() root.destroy() if 0= g 6: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=3, column=g) Label(self.slave, text=((lif[g])[0])).grid(row=2, column=g) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=1, column=g) elif 6= g 12: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=6, column=(g-6)) Label(self.slave, text=((lif[g])[0])).grid(row=5, column=(g-6)) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=4, column=(g-6)) elif 12= g 18: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=9, column=(g-12)) Label(self.slave, text=((lif[g])[0])).grid(row=8, column=(g-12)) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=7, column=(g-12)) elif 18= g 24: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=12, column=(g-18)) Label(self.slave, text=((lif[g])[0])).grid(row=11, column=(g-18)) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=10, column=(g-18)) def search_again(lof=lof, pageno=pageno): p = open(VerRes.txt, 'w') pageno = pageno + 1 reslist = [pageno, 1, lof] cPickle.dump(reslist, p) p.close() root.destroy() SearchAgain = Button(self.slave, text='Search Again.', fg=blue, command=search_again) SearchAgain.grid(row=13, column=2, columnspan=2) if pageno 0: def Back_Cmd(lof=lof, pageno=pageno): pageno = pageno - 1 nav_child(master, lof, pageno) self.slave.destroy() backbutton = Button(self.slave, text=Previous Page, height=1, width=23, command=Back_Cmd) backbutton.grid(row=13, column=0) if pageno (len(lof) - 1): def Fwd_Cmd(lof=lof, pageno=pageno): pageno = pageno + 1 nav_child(master, lof, pageno) self.slave.destroy() fwdbutton = Button(self.slave, text=Next Page, height=1, width=23, command=Fwd_Cmd) fwdbutton.grid(row=13, column=5) def Quit_Search(): root.destroy() sys.exit(0) quitbutton = Button(self.slave, text='QUIT', fg=red, command=Quit_Search) quitbutton.grid(row=14, column=2, columnspan=2) # lof is nested lists 'cos there's more than one page of more than one image- Images don't show on the first results page... *sigh* Obviously,
Re: Looking for a text file based wiki system written in Python
The base of moinmoin is called piki.It provides the simplest functions as a wiki system And there are lots of other wiki system based on piki. If I try to developed one,I'll make the text data compatible with compatible. Jack wrote: Thanks! Because it was so well known, I thought it was database-based :) http://moinmoin.wikiwikiweb.de/ Any good and simple text file-based blog system in Python? -- http://mail.python.org/mailman/listinfo/python-list
Best IDE for Python
Hi All, What do you find the best IDE for creating web applications in Python is? Preferably FOS IDE. Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: selecting base class from user input
Le lundi 14 août 2006 09:33, Jackson a écrit : Now I realize this would drive a programmer crazy...because a Lion might have a roar() method whereas a Human might have a holler() method. But so long as the user knew which argument they passed in, it shouldn't be too difficult to keep track of it. There are many problems if you go that way. One implementation could be : In [28]: class Animal(object) : : _types = {} : : In [29]: class Worker(object) : : def work(self) : print 'hard' : : In [30]: def createLion(*classes) : : def roar(self) : print roar : if not classes in Animal._types : : Animal._types[classes] = type('Lion', (Animal,) + classes, {'roar' : roar}) : return Animal._types[classes]() : In [31]: In [31]: createLion().roar() roar In [32]: type(createLion()) Out[32]: class '__main__.Lion' In [33]: type(createLion()) is type(createLion()) Out[33]: True In [34]: createLion(Worker).roar() roar In [35]: createLion(Worker).work() hard In [36]: type(createLion(Worker)) Out[36]: class '__main__.Lion' In [37]: type(createLion(Worker)) is type(createLion(Worker)) Out[37]: True In [38]: Animal._types Out[38]: {(): class '__main__.Lion', (class '__main__.Worker',): class '__main__.Lion'} In [39]: type(createLion(Worker)) is type(createLion()) Out[39]: False The main problems are : first, your classes definition are hidden, second there is no real Lion class to test, say isinstance(createLion(toto), Lion), this can be misleading. What you are trying to achieve is more commonly done by agregation and delegation : In [47]: class Lion(Animal) : : def __init__(self, *classes) : : self._objects = tuple(c() for c in classes) : def isA(self, class_) : : return class_ in (type(o) for o in self._objects) : def __getattr__(self, name) : : for obj in self._objects : : try: return getattr(obj, name) : except: pass : raise AttributeError('not defined or found in objects %s' % name) : : In [48]: Lion().work() --- exceptions.AttributeErrorTraceback (most recent call last) /home/maric/ipython console /home/maric/ipython console in __getattr__(self, name) AttributeError: not defined or found in objects work In [49]: Lion().isA(Worker) Out[49]: False In [50]: Lion(Worker).isA(Worker) Out[50]: True In [51]: Lion(Worker).work() hard -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie doing lengthy initialization with Tkinter gui
Le dimanche 13 août 2006 16:01, [EMAIL PROTECTED] a écrit : No neep for thread or Tix modules...! Module thread is always available (at less on platforms where Tkinter is available), while Tix in my example is just intended to use the Meter widget (a progress bar). # this will *sleep* one millisec before calling # your doInitOne function and continue # with the rest of the code during that sleep time # in this case just the mainloop root.after(1, doInitOne) root.mainloop() hum, this has not exactly the same effect, after, after_cancel, etc. are for scheduling actions in the future, and when the action start, it will block the mainloop and user interaction (this is why you need to call explicitly the update method), so the gui will not respond anymore. Finally why do you differ the call of your function after the mainloop since it will block ? That's said, I remember now that there isn't anything in Tkinter (no events or callbacks) to get the 'mainloop started' hook, so you must start the thread before the mainloop, probably like this : class myApp(Toplevel) : def mainloop(self) : start_new_thread(initFunc, params) Toplevel.mainloop(self) -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested if and expected an indent block
[EMAIL PROTECTED] wrote: Simon Forman wrote: I got rid of the triple quote string at the start of the function, and that cleared up the problem, though I don't know why. Ah, yes. The docstring for a function (or at least its first triple-quote) must be indented to the same degree as its statements. (If you're using IDLE it should have indented it for you when you hit return after the def statement.) HTH, ~Simon Hi Simon: Thanks. I code in VB / VBA, and use indented structure, but it's not enforced they way it is in Python - still getting used to that. Also, I got goofed up editing some of the code in VIM, indenting with tabs, and then switching to IDLE, with space indentation. Whoops... Thanks for all the help everyone, my first Python program is now working! Keith Tips: if you're coding with VIM, put set expandtab in your config file. That way, each tab will be expanded into the corresponding number of spaces ... Whatever the language, I find it always a bad idea to mix spaces and tabs, and I prefer spaces ... Pierre -- http://mail.python.org/mailman/listinfo/python-list
Re: selecting base class from user input
Jackson wrote: I have 4 classes: Lion(Animal): Ant(Animal): Bee(Animal): Human(Animal): which are all subclasses of some superclass called Animal. Now I want to define an occupation. For example, Worker. A worker can exist as any of the 4 classes above. Their constructors are different and I might want to add certain features. My first thought was to create a class called Worker and have the base class determined by a variable which is passed into the constructor. Most of the method calls will come from the Animal superclass anyway, but some method calls might come from the Lion class, for example. Here are a couple of thoughts that *might* help: (1) mix-in i.e. a class can have multiple base classes: class AntWorker(Animal, Worker): (2) you can create classes on the fly using the 3-argument form of the built-in type() function: new_cls = type(name_of_class, base_classes_tuple, dict_of_methods_etc) so you can have just one base class (i.e. object) and populate the dict with methods and/or you can have pre-packaged base-classes each already containing relevant methods ... so when the order for a new tailored class comes in you just rush about your virtual warehouse throwing packaged base-classes into a tuple and extra methods into a dict, attach a name tag and then type() gift-wraps it for you. You need to read up on method resolution order aka mro before planning what methods go in what mixin classes and what methods are optional add-ons and what order you specify the classes in the tuple. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python
By FOS, do you mean FOSS (Free and Open Source Software)? I've never seen the acronym FOS used. I personally use Eclipse with PyDev. http://www.eclipse.org/ http://pydev.sourceforge.net/ Michiel Op 14-aug-2006, om 9:50 heeft [EMAIL PROTECTED] het volgende geschreven: Hi All, What do you find the best IDE for creating web applications in Python is? Preferably FOS IDE. Cheers -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: hide python code !
On Fri, 11 Aug 2006 06:16:26 -0700, Fuzzyman wrote: What you can do with Python is almost certainly *good enough* for most people who ask this question - and that fact never seems to be included in the 'reality' propogated by the knee jerk reactionists... :-p The Original Poster *explicitly* stated that he was aware of the .pyc files, and rejected that strategy because .pyc files can be decompiled. He was asking for something which can't be decompiled, which is not possible since machine code can also be decompiled -- in fact, there are probably lots more disassemblers and decompilers for C than there are for Python. I'd rather educate him so he stops wasting his time rather than reinforce his ignorance by pretending that there are ways of distributing code without it also being decompilable. You suggested that it does harm to Python to give developers a realistic understanding of what Python is capable of, and that it's better to give them a misleading answer. I reject that idea utterly. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list
Re: hide python code !
On Fri, 11 Aug 2006 09:18:12 -0700, Ben Sizer wrote: Imagine if you were the single-person developer of a small application that did something quite innovative, And imagine that you found a money-tree in your back yard... How about a more likely scenario? Imagine you're using a boring, run-of-the-mill algorithm, the same as 99.9% of all software out there, and that it's neither non-obvious nor innovative in any way at all. Statistically, I'd say it is ten thousand times more likely that this is the case than that the algorithm is at all valuable. Everybody thinks their algorithm is special. They almost never are. Even this is more likely than the semi-mythical algorithm that needs to be kept secret: the reason you (generic you) want to keep your software secret is because you've copied source code -- from books, from your friends, from Open Source projects, maybe even from stolen copies of Windows source code you've downloaded from the darker corners of the Internet, and you don't want people to know. That's more likely than you hitting upon an amazing new innovative AND valuable algorithm. Valuable algorithms are rare. Most software is not valuable for the algorithm, which is hidden in the source code, but for the functionality, which is obvious. Algorithms are a dime a dozen. It may not matter if some console game or other doesn't work after 20 years... Certainly; yet this is a valid example of software that requires a degree of protection since some of the algorithms employed truly are 'worth stealing'. Yes, and for every algorithm worth stealing, there are ten thousand that aren't. Play the odds, and you too will poo-poo the idea that some random developer on Usenet has discovered a valuable innovative algorithm. More likely he's just ashamed of his code, or wants to hide backdoors in it. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another noob question
Jason Nordwick schrieb: Or without filter: from operator import add def pr(x): print x def cross(x,y): return reduce(add, [[a+b for b in y] for a in x]) x=map(pr, reduce(cross, [map(str,range(1,6))]*5)) [...] reduce(add, list) is the same as sum(list) and is only half as fast as sum: from timeit import Timer sum(Timer(sum(range(500))).repeat(200, 1000))/200 0.055693786500798058 sum(Timer(reduce(add, range(500)), from operator import add).repeat(200, 1000))/200 0.10820861031220445 Also note that reduce will be removed in Python 3000. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python
[EMAIL PROTECTED] writes: Hi All, What do you find the best IDE for creating web applications in Python is? Preferably FOS IDE. I don't know what a FOS IDE is, but my preferred free software development environment for making web applications is: - GNU screen URL:http://www.gnu.org/software/screen/ - Powerful editor; lately I prefer Emacs with python-mode URL:http://www.gnu.org/software/emacs/ URL:http://www.emacswiki.org/cgi-bin/wiki/PythonMode - Standards-compliant browser, such as Firefox; the web developer toolbar extension is a must. URL:http://www.mozilla.com/firefox/ URL:http://chrispederick.com/work/webdeveloper/ Separate 'screen' windows for: - VCS interaction - Continuous unit test running - Emacs session - Python interactive session Many of the above could be in Emacs windows instead, but I already know how to work 'screen'. The wonderful part about using 'screen' as my IDE is that any of the tools can be interchanged as I like. -- \ The WWW is exciting because Microsoft doesn't own it, and | `\ therefore, there's a tremendous amount of innovation | _o__) happening. -- Steve Jobs | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange problem with Tkinter... photos don't show on first iteration.
[EMAIL PROTECTED] wrote: Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a forward and back button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the first page of results shows up. When I click the search again button, and have more than the original results page to toggle between, the images __do__ show up on the first page of results. (and on the second, etc, etc.) Which is to say, there's no error messages, and on the first page, the first time it's shown, the Toplevel formats correctly, and there are spaces where the images should be that are the correct size, just... no images. It's baffling me. Perhaps someone can help. this is explained in the Python FAQ, and also in the note at the bottom of this page: http://effbot.org/tkinterbook/photoimage.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Which KDE IDE for Python?
Bart Ogryczak napisał(a): Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both have drawbacks. KDevelop is a multilanguage IDE, and doesn't really have anything special for Python. There's no Python debugger, no PyDOC integration, it's class browser doesn't display attributes. On the other side there's Eric, which is made just for Python. But.. it doesn't integrate with KDE, doesn't support remote files (fish://, ftp:// etc.). Does anyone know a better IDE for Python, that'll integrate nicely with KDE? No, I don't know *the exactly one*. I used to use Eric3, but it was a bit of overkill, as I never needed things like interactive debugger. Kate is good editor with some basic IDE features (interactive console, project management), but in no way it can be called an integrated development, it's just advanced editor. There are some good integrated environments focused on Python development (Wing IDE, Komodo, PyDev for Eclipse), but none of them is integrated with KDE, AFAIK. As a side note, Eric3 has no KDE integration because it's pure PyQt application. -- Jarek Zgoda http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Which KDE IDE for Python?
As a side note, Eric3 has no KDE integration because it's pure PyQt application. Not fully true. While it certainly doesn't aim to be a fully integrated ide, it has some kde-support. Which you can disable using the --nokde argument, btw. It will then use kde color-dialogs, file-dialogs and the like. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another noob question
Stargaming: Also note that reduce will be removed in Python 3000. Then let's use it until it lasts! :-) bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another noob question
mike_wilson1333 wrote: I would like to generate every unique combination of numbers 1-5 in a 5 digit number and follow each combo with a newline. So i'm looking at generating combinations such as: (12345) , (12235), (4) and so on. What would be the best way to do this? So, basically i'm looking for a list of all combinations of 1-5 in a 5 digit unique number. Also, when I send the list to print there can't be any duplicates of the combos. Thanks, Mike Hi Mike mod5 = ['1','2','3','4','5'] X = [ ''.join([a,b,c,d,e]) for a in mod5 for b in mod5 for c in mod5 for d in mod5 for e in mod5 ] assert len(X) == 5**5 assert len(set(X)) == 5**5#no duplicates Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another noob question
Gerard Flanagan: mod5 = ['1','2','3','4','5'] X = [ ''.join([a,b,c,d,e]) for a in mod5 for b in mod5 for c in mod5 for d in mod5 for e in mod5 ] A modified version of your one is the faster so far: v = 12345 r = [a+b+c+d+e for a in v for b in v for c in v for d in v for e in v] Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python
I think SPE is a terrible complete and efficient IDE! -- http://mail.python.org/mailman/listinfo/python-list
help parsing this
mx.DateTime.RangeError at /podcasts Failed to parse 31 Apr 2006 20:19:00 -0400: day out of range: 31 Python /usr/lib/python2.4/site-packages/mx/DateTime/Parser.py in DateTimeFromString, line 608 how to parse this date thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: proxy for xmlrpc calls
Xavier wrote: I'm attempting to write a proxy for xmlrpc calls. why not use the one in the standard library? I want to expand this to do something like; a=MagicObject() x = a.b.c.d Then on the last __getattr__ send a call over xmlrpc. How do I determine when the last __getattr__ will be? you can't determine that. (and XML-RPC doesn't support attribute access either, so this sounds like a rather pointless exercise) I thought about getting the source code from the correct frame, but I don't think thats a good solution. getting the source won't help, unless you're willing to violate Python's execution model. Any ideas? stick to the standard. /F -- http://mail.python.org/mailman/listinfo/python-list
NRIEvents - Independence Day Contest :
Hello Friend, Kindly spare 2 minutes to celebrate INDIA's Independence Day with us. Host INDIA'S tri-color flag at your desk-top to show your love support to INDIA. Its specially designed for you. (Home page) Participate in the event win a gift for your brother or friend in INDIA. Click: http://www.nrievents.com Thanks for taking time in participating the event. Regards, NRIEVENTS Team -- http://mail.python.org/mailman/listinfo/python-list
Re: help parsing this
a [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] mx.DateTime.RangeError at /podcasts Failed to parse 31 Apr 2006 20:19:00 -0400: day out of range: 31 Python /usr/lib/python2.4/site-packages/mx/DateTime/Parser.py in DateTimeFromString, line 608 how to parse this date thanks There isn't a 31st of April. -- http://mail.python.org/mailman/listinfo/python-list
Re: help parsing this
a wrote: mx.DateTime.RangeError at /podcasts Failed to parse 31 Apr 2006 20:19:00 -0400: day out of range: 31 Python /usr/lib/python2.4/site-packages/mx/DateTime/Parser.py in DateTimeFromString, line 608 how to parse this date parse it into what? there is no such thing as April 31st. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: help parsing this
how to parse this date parse it into what? there is no such thing as April 31st. I think somebody's chain is getting pulled...thus the right thing to do is to wrap around and return April 1st ;-) -Loof Lirpa -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange problem with Tkinter... photos don't show on first iteration.
Yup, That's the problem. Can't thank you enough. I'd read about Tkinter garbage collection, but, like car crashes and lung cancer, you never think it's going to happen to you... thanks once again. Cheers, Al. Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a forward and back button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the first page of results shows up. When I click the search again button, and have more than the original results page to toggle between, the images __do__ show up on the first page of results. (and on the second, etc, etc.) Which is to say, there's no error messages, and on the first page, the first time it's shown, the Toplevel formats correctly, and there are spaces where the images should be that are the correct size, just... no images. It's baffling me. Perhaps someone can help. this is explained in the Python FAQ, and also in the note at the bottom of this page: http://effbot.org/tkinterbook/photoimage.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange problem with Tkinter... photos don't show on first iteration.
And I say once again: I can't thank you enough. YOU ROCK! cheers, al. (Just changed the code in my main program, and it WORKS! The previous thankyou was only a preliminary.) ps I really like python, too. :) [EMAIL PROTECTED] wrote: Yup, That's the problem. Can't thank you enough. I'd read about Tkinter garbage collection, but, like car crashes and lung cancer, you never think it's going to happen to you... thanks once again. Cheers, Al. Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a forward and back button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the first page of results shows up. When I click the search again button, and have more than the original results page to toggle between, the images __do__ show up on the first page of results. (and on the second, etc, etc.) Which is to say, there's no error messages, and on the first page, the first time it's shown, the Toplevel formats correctly, and there are spaces where the images should be that are the correct size, just... no images. It's baffling me. Perhaps someone can help. this is explained in the Python FAQ, and also in the note at the bottom of this page: http://effbot.org/tkinterbook/photoimage.htm /F -- http://mail.python.org/mailman/listinfo/python-list
sending mailing list with smtplib
Hi all, I tried to send a small mailing list using python today (2036 emails). For that purpose I looked in the doc for some code examples (I had never done it before). And I ended up writing and running this little script: # list.txt is a text file container an email per line fp=open('list.txt','r') list=fp.readlines() fp.close() # message.txt is the plaine text message to send textfile='message.txt' subject='[xsbar] alive and kicking' me='[EMAIL PROTECTED]' # rom and example in the doc import smtplib from email.MIMEText import MIMEText fp = open(textfile, 'rb') msg = MIMEText(fp.read()) fp.close() # ... but the actual message sending in a loop to send one email each (didn't work) for line in list: you=line[:-1] msg['Subject'] = subject msg['From'] = me msg['To'] = you s = smtplib.SMTP() s.connect() s.sendmail(me, [you], msg.as_string()) s.close() but it copied all the recipients in the header (To:) which I don't understand? Can someone help me understand what I did wrong? Thanks, EuGeNe -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Dennis Lee Bieber wrote: On Sun, 13 Aug 2006 20:21:26 -0400, John Salerno [EMAIL PROTECTED] declaimed the following in comp.lang.python: Yes, I'm using Ubuntu. But I checked this log file and I'm a bit confused. It has a lot of listings for 5-31-06, but I didn't even install Linux until last Saturday. The next date after 5-31 is 8-5-06, and I know I installed things between last Saturday and Aug. 5. Pardon, between when? Wow, I can't believe how time goes. Aug. 5 *was* the first day! I knew I had installed it a week ago, but I was thinking it was the last Saturday in July, not Aug. 5 already! August 5 was last Saturday if you ignore yesterday (well, since my watch says it is now Monday... day before last). I'd guess the May 31 entries are those that were snapshots of the OS installer date. August 5, first Saturday in the month, might be the first non-standard installed package. Hmm, interesting. I figured I could do this with a bash script, but I don't know bash at all and I'm trying to stick with Python. I don't quite understand your bash script (not familiar with the $@ syntax). Well, I don't do shell scripts either, but... looking at the sample... $@ is likely the shell equivalent of Python's sys.argv -- or *sys.argv if passed down -- http://mail.python.org/mailman/listinfo/python-list
python-list@python.org
I'll be out of the office until approximately August 20th. If you have any questions, please email [EMAIL PROTECTED] -- David Wahler -- http://mail.python.org/mailman/listinfo/python-list
=?utf-8?Q?Re:_Toronto_Area_Python_User's_group_meeting_this_Tuesday, _6:30pm, _Linux=0A=09Caffe?=
I'll be out of the office until approximately August 20th. If you have any questions, please email [EMAIL PROTECTED] -- David Wahler -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python
I'm assuming that FOS = free open source... In any case, what operating system do you run? If you're on OS X, I highly recommend TextMate. It's not free, but it has good support (either via built-in or third-party plugins) for Python as well as HTML, SQL, XML, Django templates, and the like. A lot of Rails folks use it (as well as Django and TurboGears developers, I might add). The best general-purpose IDE for Python, IMO, is WingIDE. Again, it's not free (personal license will cost you $30). It runs on each of the major platforms - Windows, Linux, OS X - and has some nice features, including code completion, syntax highlighting, a built-in Python shell, etc. I don't think it has any features built-in specifically for web dev, however; if you have to do lots of HTML, XML, and SQL as part of your project, you might want something a bit more general-purpose. If you're determined to go the FOSS route, you can always use VIM, Emacs, Eric, or SPE. Just my two cents... --dave -- http://mail.python.org/mailman/listinfo/python-list
Re: recommended general-purpose string template packages?
John Machin wrote: Hi, In general, I'm mainly interested in a template engine for dynamic web pages but would like a general purpose one to avoid learning yet another package for generating e-mail messages, form letters, source code, whatever. HTMLTemplate and texttemplate offer a somewhat uniform approach to text versus HTML... it attempts to raise string processing up to the level of tree/HTML processing. That stringtemplate module seems to be aiming for the lowest common denominator. Interesting contrast in approaches: http://freespace.virgin.net/hamish.sanderson/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: hide python code !
Paul Boddie wrote: Ben Sizer wrote: Imagine if you were the single-person developer of a small application that did something quite innovative, and charged a small fee for your product. Now imagine you were practically forced to make your algorithm obvious - a couple of months later, Microsoft bring out a freeware version and destroy your business in an instant. Sure, they and others can (and have) done that with closed-source products, but you increase your chances of survival 10-fold if the key algorithms are not obvious. This point is fairly comprehensively answered in the following article: http://radar.oreilly.com/archives/2006/08/apple_eats_whiners.html I don't believe so. That talks about copying of ideas, which is quite distinct from copying of implementations. The distinction may be meaningless in your typical desktop app where implementation is usually obvious from the interface. However in more high-tech systems such as multimedia or AI, the same is far from true. I read an article where various aging popular musicians were lobbying the British government to extend the period of copyright beyond 50 years because their first works would soon fall into the public domain and that they'd no longer earn royalties on those works. But in what percentage of the many other jobs that exist do you still get paid for a day at work that happened over 50 years ago? However, in most of those jobs you get paid properly at the time. Aside from the 1% of musicians who are pop stars, musicians generally do not. I'm not saying I agree with extending the copyright period, however I do think you can't just compare it to 'a day at work'. It's a totally different set of circumstances which requires a different set of rules to both encourage artists to continue creating while benefitting society in the long run too. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a text file based wiki system written in Python
Jack wrote: I'd like to set up a wiki system for a project I'm working on. Since I'm not good at databases, and there's really not much stuff to put into the wiki, I hope it is text file-based. I used DokuWiki before, which is very nice but it's written in PHP. Is there a similar system that's written in Python? I found pwyky but it's functionality is a bit too simple. A TiddlyWiki with a python backend. http://www.cs.utexas.edu/~joeraii/pytw/ -- Marcel -- http://mail.python.org/mailman/listinfo/python-list
Re: hide python code !
Steven D'Aprano wrote: On Fri, 11 Aug 2006 09:18:12 -0700, Ben Sizer wrote: Imagine if you were the single-person developer of a small application that did something quite innovative, And imagine that you found a money-tree in your back yard... How about a more likely scenario? Imagine you're using a boring, run-of-the-mill algorithm, the same as 99.9% of all software out there, and that it's neither non-obvious nor innovative in any way at all. Statistically, I'd say it is ten thousand times more likely that this is the case than that the algorithm is at all valuable. Everybody thinks their algorithm is special. They almost never are. I work in game development, where new algorithms and processes are being discovered all the time. Sure, they're not going to cure cancer or end poverty but there are most definitely some algorithms devised by many developers which other companies have no idea how to emulate until years down the line; long enough for the first company to enjoy a little commercial benefit based on their individual implementation. Valuable algorithms are rare. Most software is not valuable for the algorithm, which is hidden in the source code, but for the functionality, which is obvious. Algorithms are a dime a dozen. True, however, most is not all, and I think it's unfair to categorise all software as being so trivial. Yes, and for every algorithm worth stealing, there are ten thousand that aren't. Play the odds, and you too will poo-poo the idea that some random developer on Usenet has discovered a valuable innovative algorithm. More likely he's just ashamed of his code, or wants to hide backdoors in it. Play the odds, and pretty much everything is unlikely. Of all the names in the world, what was the chance of this language being called Python? Yet these things occasionally happen. I have no opinion on why the original poster wants to hide code, only an opinion on there definitely being a few applications where it is very useful. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
[Announce] p-gal: photo gallery generator with templating support
Hi, I'm writing a software in python to generate html photo gallery. It is called p-gal and is GPL licensed. It is written in python [With the invaluable help of this list :)] and it has a templating system based on Cheetah. Currently it works under Linux (and maybe other UNIX-like OSs) The main idea of p-gal is to provide a framework to allow image gallery generation, but letting the user as free as possible about the style of the gallery. P-gal features for now only one template (or theme), but adding new ones is very simple. I would anyone to take a look at my piece of code, and give me his feedback about what is good and what should be improved. Thnx PAolo Pantaleo -- http://mail.python.org/mailman/listinfo/python-list
A little assistance with os.walk please.
The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root # print dirs # print files -- http://mail.python.org/mailman/listinfo/python-list
Re: can wxpython checkbox use the fill in marker instead of the check?
jean-michel bain-cornu a écrit : i just like the look of the fill-in instead of the checkmark I'm just realizing it's a good idea ! I'm going to use it. Thanks ! Actually, there is a problem when one generates an exe application with py2exe. In that case, the 3rd style checkmark looks 'disabled'... which is not what we want ! The best solution I can find at the moment is to switch back to the regular style (it allways happens when you are about to deliver your stuff...), but if you are still there, you'd better think about of it... Rgds, jm -- http://mail.python.org/mailman/listinfo/python-list
Re: A little assistance with os.walk please.
On Mon, 14 Aug 2006 07:44:39 -0700, KraftDiner wrote: The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root # print dirs # print files print os.walk.__doc__ Directory tree generator. For each directory in the directory tree rooted at top (including top itself, but excluding '.' and '..'), yields a 3-tuple dirpath, dirnames, filenames dirpath is a string, the path to the directory. dirnames is a list of the names of the subdirectories in dirpath (excluding '.' and '..'). filenames is a list of the names of the non-directory files in dirpath. Note that the names in the lists are just names, with no path components. To get a full path (which begins with top) to a file or directory in dirpath, do os.path.join(dirpath, name). If optional arg 'topdown' is true or not specified, the triple for a directory is generated before the triples for any of its subdirectories (directories are generated top down). If topdown is false, the triple for a directory is generated after the triples for all of its subdirectories (directories are generated bottom up). When topdown is true, the caller can modify the dirnames list in-place (e.g., via del or slice assignment), and walk will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, or to impose a specific order of visiting. Modifying dirnames when topdown is false is ineffective, since the directories in dirnames have already been generated by the time dirnames itself is generated. By default errors from the os.listdir() call are ignored. If optional arg 'onerror' is specified, it should be a function; it will be called with one argument, an os.error instance. It can report the error to continue with the walk, or raise the exception to abort the walk. Note that the filename is available as the filename attribute of the exception object. Caution: if you pass a relative pathname for top, don't change the current working directory between resumptions of walk. walk never changes the current directory, and assumes that the client doesn't either. Example: from os.path import join, getsize for root, dirs, files in walk('python/Lib/email'): print root, consumes, print sum([getsize(join(root, name)) for name in files]), print bytes in, len(files), non-directory files if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories -- http://mail.python.org/mailman/listinfo/python-list
Re: A little assistance with os.walk please.
The os.walk function walks the operating systems directory tree. Yup. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root # print dirs # print files As cheesy as it may sound, try uncommenting the two commented lines. For a more explicit variant: print repr(dirs) print repr(files) You'll notice that they're lists. In the directory root, you'll find the subdirectories given in the list dirs and you'll find the files given in the list files. -tkc -- http://mail.python.org/mailman/listinfo/python-list
why the method get() of python Queue is hang on there?
Hi, I am using Queue from python2.4. Here is what happen to me: import Queue b = Queue.Queue(0) b.put() b.get() # this is ok, it pops out b.get() # this one does not return anything and is hang on there Anybody knows what is going on with the second b.get()? ouyang -- http://mail.python.org/mailman/listinfo/python-list
Re: A little assistance with os.walk please.
KraftDiner wrote: The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root # print dirs # print files Actually returns two tuples: dirs and files root - is the directory branch you are currently walking dirs - are the directory branches that are subdirectories of this directory branch files - are the files that live in this directory branch To process all the files here you do something like: for afile in files: # resist the urge to call it 'file' fullpath=os.path.join(root, afile) # # Do something with fullpath # Hard to figure out item - If you wish to NOT process some of the dirs, you can delete them from the dirs list here and they won't get walked. You MUST delete them in place with del dirs[n] or dirs.pop or some other function that deletes in-place. You might want to type: help(os.walk) to get some more info. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: why the method get() of python Queue is hang on there?
zxo import Queue zxo b = Queue.Queue(0) zxo b.put() zxo b.get() # this is ok, it pops out zxo b.get() # this one does not return anything and is hang on there zxo Anybody knows what is going on with the second b.get()? Queue objects are meant to be used in a multithreaded application. By default, when the Queue is empty, a consumer calling get() will block until a producer put()s something else into it. From the documentation: get([block[, timeout]]) Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: why the method get() of python Queue is hang on there?
import Queue b = Queue.Queue(0) b.put() b.get() # this is ok, it pops out b.get() # this one does not return anything and is hang on there Anybody knows what is going on with the second b.get()? help(Queue.Queue) : : | get(self, block=True, timeout=None) | Remove and return an item from the queue. | | If optional args 'block' is true and | 'timeout' is None (the default), block if | necessary until an item is available. If | 'timeout' is a positive number, it blocks | at most 'timeout' seconds and raises the | Empty exception if no item was available | within that time. Otherwise ('block' is | false), return an item if one is | immediately available, else raise the | Empty exception ('timeout' is ignored in | that case). | | get_nowait(self) | Remove and return an item from the queue | without blocking. | | Only get an item if one is immediately | available. Otherwise raise the Empty | exception. : : Notice that by default, get() will block until there's something to read. You can use either b.get(block=False) or b.get_nowait() In either case, an exception will be raised when the Queue is empty, to let you know as much. Just trap for the exception and do as you please. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: why the method get() of python Queue is hang on there?
zxo102 wrote: Hi, I am using Queue from python2.4. Here is what happen to me: import Queue b = Queue.Queue(0) b.put() b.get() # this is ok, it pops out b.get() # this one does not return anything and is hang on there Anybody knows what is going on with the second b.get()? the documentation has the answer: get( [block[, timeout]]) Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. /.../ http://docs.python.org/lib/QueueObjects.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: why the method get() of python Queue is hang on there?
On Mon, 14 Aug 2006 17:10:13 +0200, zxo102 [EMAIL PROTECTED] wrote: Hi, I am using Queue from python2.4. Here is what happen to me: import Queue b = Queue.Queue(0) b.put() b.get() # this is ok, it pops out b.get() # this one does not return anything and is hang on there Anybody knows what is going on with the second b.get()? What did you expect? Since you've done only one put in the Queue, there's nothing left in it. Since queues are meant to communicate between threads - and also often to synchronize them -, the default behaviour for the get when the queue is empty is to wait for something to be put in it. If you want your second get to fail, use the get_nowait method. HTH -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
Re: [Announce] p-gal: photo gallery generator with templating support
Paolo Pantaleo [EMAIL PROTECTED] writes: I would anyone to take a look at my piece of code, and give me his feedback about what is good and what should be improved. url? -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy to use distributed system?
Jim Jones wrote: I am looking for a system in Python that will easily allow me to distribute processes across multiple systems?So, if I have a function 'foo', I'd like to be able to call something along the lines of distribute(foo(x)) And have the system figure out which node is available for process, and then have the results returned in some sort of callback fashion. Any insight is greatly appreciated. I did a little research on this subject not too long ago. From what I've seen, OpenMosix appears to be about the easiest one for Linux Operating Systems. Here's the url: http://openmosix.sourceforge.net/ -- -- There are several things that I will never be: * I will never be attracted to females. * I will never enjoy the company of others. Exactly how these realities bode for my enemy, is not of my concern. -- http://mail.python.org/mailman/listinfo/python-list
Re: why the method get() of python Queue is hang on there?
Thanks for your guys. I got it. I thought Queue can be used anywhere in the code and the second b.get() would return a None. Ouyang zxo102 写道: Hi, I am using Queue from python2.4. Here is what happen to me: import Queue b = Queue.Queue(0) b.put() b.get() # this is ok, it pops out b.get() # this one does not return anything and is hang on there Anybody knows what is going on with the second b.get()? ouyang -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling wxPython app for Windows; Single EXE
Satya wrote: Vincent Delporte wrote: snip - there's no way to build a single EXE, to make deployment easier (if multiple files, I need to build an installer with eg. NSIS or InnoSetup)? I am using InnoSetup. The included example script (I believe in py2exe) is adequate for simple applications. I just modified a few lines and I had a neat Windows Installer. Satya +1 on the Inno Installer solution. I use it a lot and it is both easy to use and flexible for distributing Python apps on Windows. While just compressing into self-extracting .exe works for simple apps, there always seem to be other things you want to do. Things like modifying .ini files, setting up shortcuts and icons on user's desktop, start list, quickstart list. Registering dlls, starting services, ... Inno Installer can help you with all these things. The combination of py2exe and Inno Installer is hard to beat. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a simple way to load a program from another python program..
[EMAIL PROTECTED] wrote: I was looking for a simple way to load a simple python program from another python program. I tried os.system(cabel) The file name is cabel.py a csound instrument editor.. The error I am getting is Traceback (most recent call last): File C:\Python24\Lib\site-packages\boa-constructor\test of snake\Frame1.py, line 212, in OnCabelItems0Menu os.system(cabel) NameError: global name 'cabel' is not defined Localisation of messages is disabled, using default language. time resolution is 279.365 ns This is with cabel in the current directory. I have managed to use import to run it but it will only do it once. I may be able to use the exec commands but I don't want to exit the program I am using only to run other programs and then exit. I would also perfer that cabel is in it's own directory. thanks in advance for any help http://www.stormpages.com/edexter/csound.html I am new to Python coding myself, but I've found that the easiest way to start another script from within a script, is to use the execfile('filename.py') command. There may be better ways of loading other Python scripts -- better ways that I'm not yet aware of -- but execfile() works for me. -- -- There are several things that I will never be: * I will never be attracted to females. * I will never enjoy the company of others. Exactly how these realities bode for my enemy, is not of my concern. -- http://mail.python.org/mailman/listinfo/python-list
Re: hide python code !
Ben Sizer wrote: Paul Boddie wrote: Ben Sizer wrote: Imagine if you were the single-person developer of a small application that did something quite innovative, and charged a small fee for your product. Now imagine you were practically forced to make your algorithm obvious - a couple of months later, Microsoft bring out a freeware version and destroy your business in an instant. Sure, they and others can (and have) done that with closed-source products, but you increase your chances of survival 10-fold if the key algorithms are not obvious. This point is fairly comprehensively answered in the following article: http://radar.oreilly.com/archives/2006/08/apple_eats_whiners.html I don't believe so. Well, it talks about competing against some large business who will eventually emulate your work. The advantage of small businesses competing against anyone with a fairly rigid schedule and an arguably non-agile internal organisation is that there will be a certain amount of time before that large business firstly gets round to dismantling your product (as opposed to that of the other small competitors), secondly manages to produce something which does more or less the same thing, and thirdly is able to bring it to market with the same level of quality/branding that its customers expect. Successful software businesses are not merely founded on the process of having ideas and implementing them - they might also need to be effective at delivering those ideas and going through the whole process again and again. Writing a neat utility for Windows is not by itself the foundation of a successful business - other factors are critical, whether they be continuous improvements, service, support, or a number of other things. That talks about copying of ideas, which is quite distinct from copying of implementations. The distinction may be meaningless in your typical desktop app where implementation is usually obvious from the interface. However in more high-tech systems such as multimedia or AI, the same is far from true. Well, let's say that algorithms are a step up from mere ideas, and let's also say that actual code is a step up from mere descriptions of algorithms (since actual code serves to verify the behaviour of those algorithms). The article I mention states that people shouldn't expect to be rewarded forever for dreaming up some idea, and I extend that point by stating that people shouldn't expect to be rewarded forever for describing an algorithm - both of these things being patentable in various permissive patent regimes, which (in conjunction with a few other factors) really is quite harmful for anyone actually doing work in any of the affected lines of work. So, if we decide to ignore people waving pieces of paper around which make some claim to an idea or some way of solving some problem, instead investigating the actual code, others have pointed out already that if you provide just a binary and there exist people who want to know what you've done, those people will find it out whether you make it easy for them or not. Now, if we sidestep the issue of decompiling binaries and cast the affected work as some kind of service, the question can now be expressed as whether you should expect to be rewarded forever for providing such a service. This brings in a number of issues that are suddenly more apparent than in the case where the end-user has some binary - notably the issue of control over the activity that the service performs - and such issues could possibly increase competitive pressure rather than enhance any supposed competitive advantage if people felt that the market wasn't providing enough in the way of choice in that area. I read an article where various aging popular musicians were lobbying the British government to extend the period of copyright beyond 50 years because their first works would soon fall into the public domain and that they'd no longer earn royalties on those works. But in what percentage of the many other jobs that exist do you still get paid for a day at work that happened over 50 years ago? However, in most of those jobs you get paid properly at the time. Aside from the 1% of musicians who are pop stars, musicians generally do not. The article I read was in the paper edition of the newspaper in question, but here's a fairly similar electronic version: http://www.telegraph.co.uk/news/main.jhtml?xml=/news/2006/03/29/nroyal29.xmlsSheet=/news/2006/03/29/ixhome.html I don't doubt that sessions musicians are paid badly, but multiplying every musician's income by a certain factor doesn't necessarily represent a just solution to that issue. I'm not saying I agree with extending the copyright period, however I do think you can't just compare it to 'a day at work'. It's a totally different set of circumstances which requires a different set of rules to both encourage artists to continue creating while benefitting society in
Re: A little assistance with os.walk please.
Larry Bates wrote: KraftDiner wrote: The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root # print dirs # print files Actually returns two tuples: dirs and files root - is the directory branch you are currently walking dirs - are the directory branches that are subdirectories of this directory branch files - are the files that live in this directory branch To process all the files here you do something like: for afile in files: # resist the urge to call it 'file' fullpath=os.path.join(root, afile) # # Do something with fullpath # Hard to figure out item - If you wish to NOT process some of the dirs, you can delete them from the dirs list here and they won't get walked. You MUST delete them in place with del dirs[n] or dirs.pop or some other function that deletes in-place. You might want to type: help(os.walk) to get some more info. Yep done that. Thanks. Two things.. 1) there seems to be an optional topdown flag. Is that passed to os.walk(path, topdownFlag) 2) I only want to process files that match *.txt for example... Does that mean I need to parse the list of files for the .txt extention or can I pass a wildcard in the path parameter? -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: [Announce] p-gal: photo gallery generator with templating support
14 Aug 2006 08:31:06 -0700, Paul Rubin http://phr.cx@nospam.invalid: Paolo Pantaleo [EMAIL PROTECTED] writes: I would anyone to take a look at my piece of code, and give me his feedback about what is good and what should be improved. url? -- http://mail.python.org/mailman/listinfo/python-list Sorry... www.sf.net/projects/ppgal -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
John Salerno wrote: Here's my new project: I want to write a little script that I can type at the terminal like this: $ scriptname package1 [package2, ...] where scriptname is my module name and any subsequent arguments are the names of Linux packages to install. Running the script as above will create this line: sudo aptitude install package1 package2 ... It will run that line at the terminal so the package(s) will be installed. Now, the extra functionality I want to add (otherwise I would just install them normally!) is to save the package names to a text file so I can now the names of programs I've manually installed, if I ever want to check the list or remove packages. So creating the proper bash command (sudo aptitude install ...) is easy, and writing the names to a file is easy. But I have two questions: 1. First of all, does Linux keep track of the packages you manually install? If so, then I won't have to do this at all. 2. Assuming I write this, how do output the bash command to the terminal? Is there a particular module that Python uses to interact with the terminal window that I can use to send the install command to the terminal? I don't know the answer to the first bit here, but I think the following should get you most of what you want as far as the second bit is concerned: scriptname.py import argparse # http://argparse.python-hosting.com/ import subprocess import sys def outputfile(filename): return open(filename, 'w') if __name__ == '__main__': # parse the command line arguments parser = argparse.ArgumentParser() parser.add_argument('packages', metavar='package', nargs='+', help='one of the packages to install') parser.add_argument('--save', type=outputfile, default=sys.stdout, help='a file to save the package names to') namespace = parser.parse_args() # call the command command = ['sudo', 'aptitude', 'install'] + namespace.packages subprocess.call(command) # write the package name file for package_name in namespace.packages: namespace.save.write('%s\n' % package_name) --- $ scriptname.py -h usage: scriptname.py [-h] [--save SAVE] package [package ...] positional arguments: package one of the packages to install optional arguments: -h, --help show this help message and exit --save SAVE a file to save the package names to STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling wxPython app for Windows; Single EXE
Vincent Delporte wrote: - py2exe is still the best tool in town to compile Python scripts to run on a Windows host that doesn't have Python installed, including wxWidgets/wxPython Hi Vincent and c.l.p-ers I'm using PyInstaller (http://pyinstaller.hpcf.upr.edu/) precisely to compile a wxPython-based program. So I'm curious about what makes py2exe the best tool..., because I'm about to miss that due to my ignorance. I learned PyInstaller for something else and laziness kept me from trying py2exe. Now, the blurb on py2exe's site doesn't sound better than what I have with PyInstaller. FWIW, PyInstaller (NB: it's an exe-maker, not an installer) can compress your binaries using UPX, create single file executables and works cross-platforms too. It'll even include w9xpopen.exe and allow custom icons for the executable. It doesn't need setup.py. My buildtest.bat is: python Makespec.py -X -F -o ecoz ecotools.py grid.py similarity.py diversity.py python -O Build.py ecoz\ecotools.spec pyinstaller_log.txt ecoz\ecotools.exe test I've notice that application start time (or rather, 're-start', as it's more noticeable for the subsequent runs) is much better for the single directory method, because single file will always decompress to a temporary directory. All the best, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: A little assistance with os.walk please.
1) there seems to be an optional topdown flag. Is that passed to os.walk(path, topdownFlag) Yes. 2) I only want to process files that match *.txt for example... Does that mean I need to parse the list of files for the .txt extention or can I pass a wildcard in the path parameter? for path, dirs, files in os.walk(.): ... for f in files: ... if not f.lower().endswith(.txt): continue ... print os.path.join(path, f) If you want to be more complex: from os.path import splitext allowed = ['.txt', '.sql'] for path, dirs, files in os.walk(.): ... for f in files: ... if splitext(f)[1].lower() not in allowed: continue ... fn = os.path.join(path, f) ... print do something with %s % fn Just a few ideas, -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: A little assistance with os.walk please.
Tim Chase wrote: 1) there seems to be an optional topdown flag. Is that passed to os.walk(path, topdownFlag) Yes. 2) I only want to process files that match *.txt for example... Does that mean I need to parse the list of files for the .txt extention or can I pass a wildcard in the path parameter? for path, dirs, files in os.walk(.): ... for f in files: ... if not f.lower().endswith(.txt): continue ... print os.path.join(path, f) If you want to be more complex: from os.path import splitext allowed = ['.txt', '.sql'] for path, dirs, files in os.walk(.): ... for f in files: ... if splitext(f)[1].lower() not in allowed: continue ... fn = os.path.join(path, f) ... print do something with %s % fn Just a few ideas, -tkc Many thanks all. B. -- http://mail.python.org/mailman/listinfo/python-list
tkinter: Button color Solaris/Linux
I have a GUI where the background of the GO button, for example, turns green while the associated action is running. On Windows it works fine, but on Solaris and Linux the button background turns white (or whatever) when the mouse pointer enters the button, the background stays that color while Button-1 is being held down, and the background continues to stay that color when Button-1 is released. The background only turns green when the user moves the pointer off of the button. Can that be fixed, or is that an X-Windows thing? Thanks! Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Steven Bethard wrote: John Salerno wrote: Here's my new project: I want to write a little script that I can type at the terminal like this: $ scriptname package1 [package2, ...] where scriptname is my module name and any subsequent arguments are the names of Linux packages to install. Running the script as above will create this line: sudo aptitude install package1 package2 ... It will run that line at the terminal so the package(s) will be installed. Now, the extra functionality I want to add (otherwise I would just install them normally!) is to save the package names to a text file so I can now the names of programs I've manually installed, if I ever want to check the list or remove packages. So creating the proper bash command (sudo aptitude install ...) is easy, and writing the names to a file is easy. But I have two questions: 1. First of all, does Linux keep track of the packages you manually install? If so, then I won't have to do this at all. 2. Assuming I write this, how do output the bash command to the terminal? Is there a particular module that Python uses to interact with the terminal window that I can use to send the install command to the terminal? I don't know the answer to the first bit here, but I think the following should get you most of what you want as far as the second bit is concerned: scriptname.py import argparse # http://argparse.python-hosting.com/ import subprocess import sys def outputfile(filename): return open(filename, 'w') if __name__ == '__main__': # parse the command line arguments parser = argparse.ArgumentParser() parser.add_argument('packages', metavar='package', nargs='+', help='one of the packages to install') parser.add_argument('--save', type=outputfile, default=sys.stdout, help='a file to save the package names to') namespace = parser.parse_args() # call the command command = ['sudo', 'aptitude', 'install'] + namespace.packages subprocess.call(command) # write the package name file for package_name in namespace.packages: namespace.save.write('%s\n' % package_name) --- $ scriptname.py -h usage: scriptname.py [-h] [--save SAVE] package [package ...] positional arguments: package one of the packages to install optional arguments: -h, --help show this help message and exit --save SAVE a file to save the package names to STeVe yikes! I'll have to take some time to study this! I appreciate it. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy to use distributed system?
I've been using Pyro and it does what I needs it to do for me. I don't know if it's as fancy as other packages but the price is right. Jim Jones wrote: I am looking for a system in Python that will easily allow me to distribute processes across multiple systems?So, if I have a function 'foo', I'd like to be able to call something along the lines of distribute(foo(x)) And have the system figure out which node is available for process, and then have the results returned in some sort of callback fashion. Any insight is greatly appreciated. -- Jim http://www.runfatboy.net - Exercise for the rest of us. -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Dennis Lee Bieber wrote: Well, I don't do shell scripts either, but... looking at the sample... $@ is likely the shell equivalent of Python's sys.argv -- or *sys.argv if passed down Yeah, kinda equivalent to *sys.argv[1:]. -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Steven Bethard wrote: import argparse # http://argparse.python-hosting.com/ import subprocess import sys Why not the standard lib's optparse? -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
John Salerno wrote: Steven Bethard wrote: scriptname.py import argparse # http://argparse.python-hosting.com/ import subprocess import sys def outputfile(filename): return open(filename, 'w') if __name__ == '__main__': # parse the command line arguments parser = argparse.ArgumentParser() parser.add_argument('packages', metavar='package', nargs='+', help='one of the packages to install') parser.add_argument('--save', type=outputfile, default=sys.stdout, help='a file to save the package names to') namespace = parser.parse_args() # call the command command = ['sudo', 'aptitude', 'install'] + namespace.packages subprocess.call(command) # write the package name file for package_name in namespace.packages: namespace.save.write('%s\n' % package_name) --- $ scriptname.py -h usage: scriptname.py [-h] [--save SAVE] package [package ...] positional arguments: package one of the packages to install optional arguments: -h, --help show this help message and exit --save SAVE a file to save the package names to yikes! I'll have to take some time to study this! I appreciate it. :) For just calling the command, the important lines are:: command = ['sudo', 'aptitude', 'install'] + namespace.packages subprocess.call(command) where you could have probably used ``sys.argv[1:]`` instead of namespace.packages. For writing the file, as I'm sure you've already figured out, the important lines are:: for package_name in namespace.packages: namespace.save.write('%s\n' % package_name) where again, if you weren't using argparse, you could have used ``sys.argv`` to determine the package names (namespace.packages) and the file to write to (namespace.save). The remaining lines involving the ``parser`` object are basically defining a command line interface in a similar way to what optparse in the stdlib does. Sure, you could do all of this by fiddling with sys.argv, but the argparse module will do all the parsing and conversions for you, and give your script a meaningful usage message. And I'm a firm believer in meaningful usage messages. =) STeVe P.S. Thank *you* for posting this. As a result, I've been convinced that argparse should grow a 'outfile' type, something I've been debating with myself about for a while now. -- http://mail.python.org/mailman/listinfo/python-list
Re: recommended general-purpose string template packages?
Ravi Teja wrote: Most Python templating engines are general purpose. Choice between them however is sometimes a matter of preference, like editors. I settled down on Cheetah for most part. I second Cheetah. It's suitable for most text templates. Many others are specific for XML or HTML documents. -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy to use distributed system?
Hi allWe are using Pyro, too, for our Multi-Agent System framework Spyse (http://spyse.sf.net). We support mobile agents, distributed environments, various threading models and a lot more. Just ask if you are interested, but use the svn version, mot the 0.1 download. Our 1.0 release should be coming with a month.kind regardsAndre -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter: Button color Solaris/Linux
Bob Greschke [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a GUI where the background of the GO button, for example, turns green while the associated action is running. On Windows it works fine, but on Solaris and Linux the button background turns white (or whatever) when the mouse pointer enters the button, the background stays that color while Button-1 is being held down, and the background continues to stay that color when Button-1 is released. The background only turns green when the user moves the pointer off of the button. Can that be fixed, or is that an X-Windows thing? Thanks! Bob activebackground. At least this time it was a couple of minutes after the Return key was pressed. :) Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: p-gal: photo gallery generator with templating support
Paolo Pantaleo wrote: www.sf.net/projects/ppgal Ciao Paolo! The homepage (http://paolopan.freehostia.com/p-gal/ ) looks weird in my SeaMonkey 1.0.4, contents appear below GoogleAds instead of at the right. Some feedback and a couple of questions at http://tinyurl.com/qgbth (points to http://sourceforge.net/tracker/index.php?func=detailaid=1540122group_id=169372atid=850133 ) Best regards, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Steven Bethard wrote: P.S. Thank *you* for posting this. As a result, I've been convinced that argparse should grow a 'outfile' type, something I've been debating with myself about for a while now. Heh heh. I'm glad my ignorance can inspire those around me. ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Yu-Xi Lim wrote: Steven Bethard wrote: import argparse # http://argparse.python-hosting.com/ import subprocess import sys Why not the standard lib's optparse? The page referenced above gives a variety of reasons, but the two most important things in this example are: argparse supports parsing of both positional and optional arguments, and argparse generates better usage messages. Since argparse supports positional arguments, I can write something like:: parser.add_argument('packages', ..., nargs='+', ...) and then the arparse module will enforce that at least one positional argument was given. With optparse, you'd do something like: options, args = parser.parse_args() if not args: parser.error('wrong number of arguments') Basically, with optparse, anything that involves positional arguments has to be handled by the user. It's also worth pointing out the better usage messages. Notice that the output looked like:: $ scriptname.py -h usage: scriptname.py [-h] [--save SAVE] package [package ...] positional arguments: package one of the packages to install optional arguments: -h, --help show this help message and exit --save SAVE a file to save the package names to With the optparse, you'd get something like:: $ scriptname.py -h usage: scriptname.py [OPTIONS] options: -h, --help show this help message and exit --save SAVE a file to save the package names to The argparse module knows how to create a meaningful usage message instead of just %prog [OPTIONS], and the argparse module knows about positional arguments, so you can have help messages for them too. Ok, enough propaganda for now. ;-) STeVe -- http://mail.python.org/mailman/listinfo/python-list
TypeError: 'module' object is not callable (newby question)
Why does this work from the python prompt, but fail from a script? How does one make it work from a script? #! /usr/bin/python import glob # following line works from python prompt; why not in script? files=glob.glob('*.py') print files Traceback (most recent call last): File ./glob.py, line 2, in ? import glob File /home/cdr/python/glob.py, line 5, in ? files=glob.glob('*.py') TypeError: 'module' object is not callable -- http://mail.python.org/mailman/listinfo/python-list
Boost Build Warning
Hi, I am trying to run the Hello World example in Boost.Python from the Building Hello World documentation. I believe that I have everything set up right but I get these three warnings, warning: no toolsets are configured. warning: you won't be able to build C++ programs. warning: please consult the documentation. Not sure how to set up the toolsets or what documentation is being refered to here. To compile I do,( from the example, for using VS2005) bjam -s VC80_ROOT=vc-8_0 not totally sure if that is right so I have tried a few others like, bjam -sTOOLS=vc-8_0 Any help would be appreciated. Thanks Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python
Michiel Sikma wrote: By FOS, do you mean FOSS (Free and Open Source Software)? I've never seen the acronym FOS used. Maybe he was trying for Free Open Source IDE without the semi-redundant Software I personally use Eclipse with PyDev. http://www.eclipse.org/ http://pydev.sourceforge.net/ Eclipse+PyDev has the advantage over emacs when it comes to big projects, IMO. It has features like refactoring, better project management, code coverage. emacs has the advantage of being faster and smaller, and if all you need is a syntax-aware (smart indentation, syntax highlighting) editor and integrated debugger, emacs is more than enough. I've tried the other free IDEs like IDLE, SPE, eric3, TruStudio (for Eclipse), Boa, Komodo, WingIDE. I have various issues with them, including instability, poor automatic indentation, bad GUI (too many subwindows or uncustomizable), costly, no refactoring, and no project management. It's strangely ironic. I consider Eclipse to be a lousy Java IDE especially compared to commercial offerings and yet that's what the project started out as. -- http://mail.python.org/mailman/listinfo/python-list
Re: selecting base class from user input
Maric Michaud wrote the following on 2006-08-14 01:26: In [28]: class Animal(object) : : _types = {} : : In [29]: class Worker(object) : : def work(self) : print 'hard' : : [snip] What you are trying to achieve is more commonly done by agregation and delegation : In [47]: class Lion(Animal) : : def __init__(self, *classes) : : self._objects = tuple(c() for c in classes) : def isA(self, class_) : : return class_ in (type(o) for o in self._objects) : def __getattr__(self, name) : : for obj in self._objects : : try: return getattr(obj, name) : except: pass : raise AttributeError('not defined or found in objects %s' % name) : : In [48]: Lion().work() --- exceptions.AttributeErrorTraceback (most recent call last) /home/maric/ipython console /home/maric/ipython console in __getattr__(self, name) AttributeError: not defined or found in objects work In [49]: Lion().isA(Worker) Out[49]: False In [50]: Lion(Worker).isA(Worker) Out[50]: True In [51]: Lion(Worker).work() hard This is exactly what I am looking for. However, I am not sure how to implement different Worker methods. For example, a Lion might work differently than an Bee. In my example, the Lion would take a cat-nap while the Bee might do a dance. It seems that I would need to what kind of class called the work() method. Is there a way to do that? Even if I could do that, it seems these various definitions of work should probably go into the class of the animal---so that Lion actions are all within the Lion class. Thus, the Lion class should have its own work method, and the Bee class should have its own work method as well. The problem with this is that every Lion can use the work method, when I really only work Workers to use the work method. I can picture another way of achieving this...have a list of occupations...which are booleans for each instance of the class. Then the work() method will call only if the Worker boolean is True. This should be sufficient...and the differing work methods would be in their respective classes. However, now the actual method names are not uniform---that is, it becomes a bookkeeping exercise to remember that when Worker is True, then the method to create is work(), that when Student is True, then the method to create is study(). So this procedure has its own problems too. It seems like I am trading off hardships now. So here is what I am looking for: A single Worker class with a standardized set of method names. The methods in the Worker class are dependent on the superclass (via aggregation and delegation, as shown above) of the worker. That is, a Bee performs different actions when working than a Lion or a Human. And finally, the occupations such that not every Bee is a worker and there are some Workers which are Bees. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: A little assistance with os.walk please.
allowed = ['.txt', '.sql'] for path, dirs, files in os.walk(.): ... for f in files: ... if splitext(f)[1].lower() not in allowed: continue Additionally, if you really do want to specify wildcards: allowed = ['*.txt', 'README*', '*.xml', '*.htm*'] from glob import fnmatch import os for path, dirs, files in os.walk(.): ... good_files = [] ... for pat in allowed: ... good_files.extend(fnmatch.filter(files, pat)) ... if good_files: break ... for f in good_files: ... print doing something with %s % os.path.join(path, f) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another noob question
Somehow my other response to the list got lost. I'm still learning Python, but this seems much better than my first attempt: def pr(x): print x def cross(x,y): return [a+b for a in x for b in y] x=map(pr, reduce(cross, [map(str,range(1,6))]*5)) -j Stargaming wrote: Jason Nordwick schrieb: Or without filter: from operator import add def pr(x): print x def cross(x,y): return reduce(add, [[a+b for b in y] for a in x]) x=map(pr, reduce(cross, [map(str,range(1,6))]*5)) [...] reduce(add, list) is the same as sum(list) and is only half as fast as sum: from timeit import Timer sum(Timer(sum(range(500))).repeat(200, 1000))/200 0.055693786500798058 sum(Timer(reduce(add, range(500)), from operator import add).repeat(200, 1000))/200 0.10820861031220445 Also note that reduce will be removed in Python 3000. -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another noob question
Stargaming wrote: Also note that reduce will be removed in Python 3000. What will replace it? -j -- http://mail.python.org/mailman/listinfo/python-list
Re: selecting base class from user input
John Machin wrote the following on 2006-08-14 01:45: Here are a couple of thoughts that *might* help: (1) mix-in i.e. a class can have multiple base classes: class AntWorker(Animal, Worker): (2) you can create classes on the fly using the 3-argument form of the built-in type() function: new_cls = type(name_of_class, base_classes_tuple, dict_of_methods_etc) This seems like it should work. The only problem I have with it is that there are a _lot_ of classes to define (and remember). For 256 different animals, we'd have to create 256 more animal-worker classes. Obviously this works, but it seems not to be in the spirit of classes and subclasses in that it doesn't (in some central way) highlight that there is just one occupation: a worker. As another example, suppose we had Shakespeare's Romeo and Juliet. What I mean is that we have the idea (the storyline, themes, etc) of Romeo and Juliet. Further, suppose that we have various ways of expressing the piece: poem, book, movie, broadway. It is true, we could do: a = RaJPoem() a = RaJBook() a = RaJMovie() a = RaJBroadway() but it would be nice if we could do something like this: a = RaJ(Poem) a = RaJ(Book) a = RaJ(Movie) a = RaJ(Broadway) And then a method call to RaJ might do something different for each media. For example, a.get_opening() should fetch the opening of each media(first stanza, first chapter, first scene, etc). Thus, Poem, Book, Movie, and Broadway should probably have a get_opening() method, and the RaJ class should pass this call onto the respective class. Notice, get_opening() is not exclusive to RaJ. Maric's method works nicely for this. Additionally, I might want some methods which are exclusive to RaJ. For example, a.get_love() would fetch elements of love from each type of media. Clearly this method depends on the type of media. And there is not one method that each media class could call. For a poem, the RaJ class might look for a specific way that love can be expressed (specific to RaJ). Studpid example, look for the word 'love' at the end of each line. For a movie, we might look for any scenes where the couple kisses. The point is that there are methods for which the set of calls will differ depending on the media type (poem, book, movie, etc). This seems like a fun idea to me, and I'd like to think that things like this are done frequently. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: p-gal: photo gallery generator with templating support
14 Aug 2006 10:16:37 -0700, ajaksu [EMAIL PROTECTED]: Paolo Pantaleo wrote: www.sf.net/projects/ppgal Ciao Paolo! The homepage (http://paolopan.freehostia.com/p-gal/ ) looks weird in my SeaMonkey 1.0.4, contents appear below GoogleAds instead of at the right. Well... I designed the site for Firefox... anyway I used CSS float directives and no tables. I don't know if I made something wrong, or if it is a [not so unlikely] standard compliance problem. Well Firefox too has some problems with floats. I copied the layout from http://www.topolinux.org/ - can you see this properly? -- if you have a minute to spend please visit my photogrphy site: http://mypic.co.nr -- http://mail.python.org/mailman/listinfo/python-list
Re: Boost Build Warning
On 14 Aug 2006 10:29:08 -0700, Hoop [EMAIL PROTECTED] wrote: Hi, I am trying to run the Hello World example in Boost.Python from the Building Hello World documentation. I believe that I have everything set up right but I get these three warnings, warning: no toolsets are configured. warning: you won't be able to build C++ programs. warning: please consult the documentation. Not sure how to set up the toolsets or what documentation is being refered to here. To compile I do,( from the example, for using VS2005) bjam -s VC80_ROOT=vc-8_0 not totally sure if that is right so I have tried a few others like, bjam -sTOOLS=vc-8_0 Any help would be appreciated. Try to run vcvars32.bat ( if exists or something similar ) before you invoke bjam from the same cmd. I am not sure, but this could help. Thanks Jeff -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'module' object is not callable (newby question)
works for me. do you do anything in your script besides that? Charles Russell wrote: Why does this work from the python prompt, but fail from a script? How does one make it work from a script? #! /usr/bin/python import glob # following line works from python prompt; why not in script? files=glob.glob('*.py') print files Traceback (most recent call last): File ./glob.py, line 2, in ? import glob File /home/cdr/python/glob.py, line 5, in ? files=glob.glob('*.py') TypeError: 'module' object is not callable -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another noob question
Jason Nordwick: Stargaming wrote: Also note that reduce will be removed in Python 3000. What will replace it? Nothing, I presume. You will have to write a function to find another way to solve problems. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
John Salerno wrote: Yu-Xi Lim wrote: I assume you're using a Debian-based distro with aptitude as the front end. In which case, all dpkg operations should be logged in /var/log/dpkg.log Yes, I'm using Ubuntu. But I checked this log file and I'm a bit confused. It has a lot of listings for 5-31-06, but I didn't even install Linux until last Saturday. The next date after 5-31 is 8-5-06, and I know I installed things between last Saturday and Aug. 5. (But this is OT, so don't worry about it.) I'm wondering about the need to output the bash command to the terminal. It would probably suffice if your Python script just spawned an instance of the shell with the necessary command line. Take a look at the subprocess module. But this really calls for a bash script: #!/bin/bash echo $@ /path/to/manual_install.log sudo aptitude install $@ Shorter than the equivalent Python code. You could probably declare this as a function in your bash initialization files too, if you know how to do this. Hmm, interesting. I figured I could do this with a bash script, but I don't know bash at all and I'm trying to stick with Python. I don't quite understand your bash script (not familiar with the $@ syntax). I think I'll take a look at the subprocess module, just for fun. :) Hey John, Yu-Xi Lim's right. This is one of those (thankfully few) cases where bash makes more sense to use than python (at least IMHO.) To figure out about that $@, fire up your teminal and type man bash (!man bash in IPython) (BTW, apropos of nothing, man bash is one of my all time favorite commands ever. I always think of some comic-book hero/monster shouting it, MAN BASH!! lol. Anyway...) So, now you're looking at the man page for bash. It's very very long and ubergeeky. Deep and amazing mysteries are contained (and kind of explained) within it. You want information on $@ so we'll use the search incantation to find and reveal it. Type /\$@ without the quotes, then press return. (What this means/does: / is the manpage search command, it uses a regular expression syntax not dissimilar to python's own. \ escapes the next character ($, in this case) and we need to do that because $ is regular expression syntax for end of line. The $@ will now match, um, $@ correctly.) Once you press return, man will scroll to put the first occurance of $@ at the top of your terminal and highlight it. On my system it's this line (I narrowed my terminal so that quoted portions wouldn't wrap badly in this posting): $@ as explained below under Special Parameters. So far so good, '$@ as explained below' looks promising. Rather than scrolling down to find this Special Parameters section, let's keep using the search. Press n to scroll to the next occurance of our pattern $@. On my system this brings me to: separate word. That is, $@ is equivalent to $1 $2 ... If the double-quoted expansion Ah ha! Scrolling up a few lines, we see: @ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, $@ is equivalent to $1 $2 ... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, $@ and $@ expand to nothing (i.e., they are removed). Not extraordinarily enlightening, maybe, but better than sitting in the dark, lighting your farts. :-D (Hit q to exit man.) Basically what this means is that $@ will become the positional arguments that you pass to your script. You can play with this by writing a simple bash script like this #!/bin/bash echo $@ and passing it args to see what it echos. (Remember to chmod +x it..) So, long story short, Yu-Xi Lim's bash script echos your package names to the /path/to/manual_install.log file ( in bash means append the output of the command to the left to the file on the right,) then it calls aptitude with those same package names. It's simple, short, and to-the-point. The equivalent python script would be much longer, for no appreciable gain. I write most of my tiny little helper scripts in python, but in this case, bash is the clear winnar. (And on *nix. man pages are your best friend. Plus you get to feel all l33t when you grok them. lol) Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Memory problem
Hi, I need to read a large amount of data into a list. So I am trying to see if I'll have any memory problem. When I do x=range(2700*2700*3) I got the following message: Traceback (most recent call last): File stdin, line 1, in ? MemoryError Any way to get around this problem? I have a machine of 4G memory. The total number of data points (float) that I need to read is in the order of 200-300 millions. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'module' object is not callable (newby question)
In [EMAIL PROTECTED], Charles Russell wrote: Why does this work from the python prompt, but fail from a script? How does one make it work from a script? #! /usr/bin/python import glob # following line works from python prompt; why not in script? files=glob.glob('*.py') print files Traceback (most recent call last): File ./glob.py, line 2, in ? import glob File /home/cdr/python/glob.py, line 5, in ? files=glob.glob('*.py') TypeError: 'module' object is not callable Don't call your file `glob.py` because then you import this module and not the `glob` module from the standard library. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python
[EMAIL PROTECTED] wrote: Hi All, What do you find the best IDE for creating web applications in Python is? Preferably FOS IDE. WingIDE appears to be the best, especially if you are an Emacs user and are used to its niceties. It is however, not free. PyScripter is pretty good too -- light weight, lots of features. Satya -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Which KDE IDE for Python?
Diez B. Roggisch napisał(a): As a side note, Eric3 has no KDE integration because it's pure PyQt application. Not fully true. While it certainly doesn't aim to be a fully integrated ide, it has some kde-support. Which you can disable using the --nokde argument, btw. It will then use kde color-dialogs, file-dialogs and the like. I wouldn't call this integration (like using kio, dcop, kparts, etc.), but you are right, it may use some elements of KDE desktop. Anyway, I think OP's wish for integration was closer to my understanding of integration with desktop environment. ;) Which doesn't change situation, that currently there's no KDE-based (nor even fully integrated with KDE) IDE for Python. -- Jarek Zgoda http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
tkinter, livewires: slow moving on Canvas
Hi, I have two similar programs- one in Livewires and one in Tkinter. Just moving the player on a canvas. Why is that one in Tkinter so slow? What did I miss? Livewires is based on Tkinter, so it should be the same. I looked at the code of Livewires, tried something, but no success. Maybe its because of sleeping part in event handler in Tkinter, that is somehow (how?) bypassed in Livewires by magic tkinter.dooneevent(tkinter.DONT_WAIT). Neither this worked with me. Could anyone help? Both programs attached. livewires: http://www.livewires.org.uk/python/lwpackage.html -- geon Pavel Kosina from livewires import * from random import randint def makePlayer(): global player_body, player_x, player_y player_x=randint(0,640) player_y=randint(0,480) player_body=circle(player_x, player_y,5, filled=1) def movePlayer(): global finito, player_body, player_x, player_y keys=keys_pressed() if '2' in keys: player_y=player_y-krok if '4' in keys: player_x=player_x-krok if '6' in keys: player_x=player_x+krok if '8' in keys: player_y=player_y+krok if 'q' in keys: finito=1 move_to(player_body, player_x, player_y) begin_graphics() allow_moveables() makePlayer() finito=0 krok=0.1 while not finito: movePlayer() end_graphics() from Tkinter import * import random def makeCanvas(): global canvas, root root=Tk() canvas=Canvas(root, width=640, height=480, bg=white) canvas.pack() def makePlayer(): global player x1,y1=random.randint(0,640), random.randint(0,480) x2,y2=x1+10, y1+10 player=canvas.create_oval(x1,y1,x2,y2, fill=blue) root.bind(Key, movePlayer) def movePlayer(event): if event.char==8: # nahoru dx,dy= 0,-step elif event.char==6: # vpravo dx,dy= step, 0 elif event.char==2: # dolu dx,dy= 0, step elif event.char==4: # vlevo dx,dy= -step,0 else: return canvas.move(player, dx, dy) # --- root program step=1 makeCanvas() makePlayer() mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Simon Forman wrote: It's simple, short, and to-the-point. The equivalent python script would be much longer, for no appreciable gain. I write most of my tiny little helper scripts in python, but in this case, bash is the clear winnar. (And on *nix. man pages are your best friend. Plus you get to feel all l33t when you grok them. lol) Thanks for the info! I might grudgingly decide to use a bash script in this case. :) And yes, it seems every time I ask a Linux question, everyone points me to a man page. Sometimes I find them difficult to decipher, but they are still a great help. -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'module' object is not callable (newby question)
Charles Russell wrote: Why does this work from the python prompt, but fail from a script? How does one make it work from a script? #! /usr/bin/python import glob # following line works from python prompt; why not in script? files=glob.glob('*.py') print files Traceback (most recent call last): File ./glob.py, line 2, in ? import glob File /home/cdr/python/glob.py, line 5, in ? files=glob.glob('*.py') TypeError: 'module' object is not callable Short answer: Change the name of your script file. Long answer: humour It is attempting to emulate the mythical ooloo bird, which is allegedly capable of evading would-be predators by vanishing up its own fundamental orifice. This topological exploit won't be available in Python until the as yet still mythical Python 3000. /humour Contemplate the following: C:\junktype glob.py if __name__ == __main__: print *** Being run as a script ... import glob print glob was imported from, glob.__file__ print glob.glob is, type(glob.glob) print glob.glob was imported from, glob.glob.__file__ print (glob.glob is glob) is, glob.glob is glob print --- end of script else: print *** Aarrgghh!! I'm being imported as, __name__ import glob print glob was imported from, glob.__file__ print glob.glob is, type(glob.glob) print glob.glob was imported from, glob.glob.__file__ print (glob.glob is glob) is, glob.glob is glob print --- end of import C:\junkglob.py *** Being run as a script ... *** Aarrgghh!! I'm being imported as glob glob was imported from C:\junk\glob.pyc glob.glob is type 'module' glob.glob was imported from C:\junk\glob.pyc (glob.glob is glob) is True --- end of import glob was imported from C:\junk\glob.pyc glob.glob is type 'module' glob.glob was imported from C:\junk\glob.pyc (glob.glob is glob) is True --- end of script HTH, John C:\junk -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
John Salerno wrote: Simon Forman wrote: It's simple, short, and to-the-point. The equivalent python script would be much longer, for no appreciable gain. I write most of my tiny little helper scripts in python, but in this case, bash is the clear winnar. (And on *nix. man pages are your best friend. Plus you get to feel all l33t when you grok them. lol) Thanks for the info! I might grudgingly decide to use a bash script in this case. :) You're welcome. lol :) And yes, it seems every time I ask a Linux question, everyone points me to a man page. Sometimes I find them difficult to decipher, but they are still a great help. Yup. When I started with Linux, man pages were one of those things I resisted... until I started actually reading them. Then I kicked myself for not starting sooner. :) Neat trick: man -k search term Shows you man pages matching your search term (I think it's the same thing as the apropos command.) It searches the command names and summary lines. Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list