Re: Picture in Excel issue
Jim Chiang wrote: > I’m trying to very simply insert a picture from a file into an excel > spreadsheet. I know how to do this in VBA and it works fine, however > when I try this from python I get an error. Doing a search on this > turned up nothing. > > The code I’m using is: > > from win32com.client.dynamic import Dispatch > > xl = Dispatch( 'Excel.Application' ) > > xl.Visible=1 > > xl.Workbooks.Add() > > xl.ActiveSheet.Pictures.Insert("C:\a.jpg") > > > > Traceback (most recent call last): > > File "", line 1, in > > xl.ActiveSheet.Pictures.Insert("C:\a.jpg") > > AttributeError: 'function' object has no attribute 'Insert' > > > > I’m not sure why I get this issue since > ‘ActiveSheet.Pictures.Insert("C:\a.jpg")’ works fine from within Excel. > Several internet posts from my searches also suggest to use this method. > > > > I’ve tried this on both Python 2.1 and 2.5 with the same results. > > Any idea what the problem is or how I can insert the picture?? > > > > TIA, > > Jim > > > I suspect that Pictures is a function that returns a collection - try ActiveSheet.Pictures().Insert("C:\a.jpg") Remember that VBA uses implied function calls, you have to be explicit in Python. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: strange append
E.Nurminski wrote: > Hello to all good people > > I am new to the great Py so am quite puzzled by the following code > > --- > > res = [] > x = [ 1, 1 ] > for i in xrange(0,5): > res.append(x) > x[1] = x[1] + 1 > print "x = ", x > print "res = ", res > > --- > > Looks like it puts smth like reference to 'x' into 'res' list, instead of > value. But if I want a value should I use a different method or what ? > > Evgeni > > P.S. Could not easily find the issue in the manual/tutorial can you point > me out to smth relevant ? > It's best, in Python, to consider *everything* to be a reference to an object. Most actions will work with a reference to an existing object, and creating a new reference to an object will almost never create a copy of the object. If you *do* want to create an object, you may consider using the copy module: http://docs.python.org/lib/module-copy.html (But I must point out, that in 12 years of programming Python, I've hardly ever used that module.) Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: PATCH: Speed up direct string concatenation by 20+%!
Larry Hastings wrote: > There are some improvements in this version. Specifically: > > * Python will no longer crash if you do ten million prepends > ( x = 'a' + x ). Since the problem was blowing the stack > with an incredibly deep render, I now limit the depth of > the string concatenation objects (currently set at 16384). > Note that string prepending is now *immensely* faster, as > prepending in the existing implementation is a worst-case. You really should look up something called "ropes". You should also benchmark this against code that uses the ordinary append/join pattern. (you've posted conflicting benchmarks for 2.5, but if I'm trusting the benchmarks that looks more reasonable, the standard implementation pattern is still around 10 times faster than your approach). > Perhaps; I've never been to PyCon, but it might be fun to give a > presentation there. That said, it would be way more relevant if the > patch got accepted, don'tcha think? It's rather unlikely that something like this will ever be added to the 2.X series. It's pretty unlikely for 3.X as well (GvR used a rope-like structure for ABC, and it was no fun for anyone), but it'll most likely be a lot easier to provide this as an option for 3.X. -- http://mail.python.org/mailman/listinfo/python-list
Re: strange append
E.Nurminski wrote: > Hello to all good people > > I am new to the great Py so am quite puzzled by the following code > > --- > > res = [] > x = [ 1, 1 ] > for i in xrange(0,5): > res.append(x) > x[1] = x[1] + 1 > print "x = ", x > print "res = ", res > > --- > > Looks like it puts smth like reference to 'x' into 'res' list, instead of > value. But if I want a value should I use a different method or what ? > > Evgeni > > P.S. Could not easily find the issue in the manual/tutorial can you point > me out to smth relevant ? > Yes the same reference gets added every time. res = [] x = [1, 1] for i in xrange(0,5): newx = x[:] # copy the x res.append(newx)# append the copy newx[1] += 1# shorthand print "newx = %s" % newx# basic formatting print "res = %s" % res # should be what you expect James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
strange append
Hello to all good people I am new to the great Py so am quite puzzled by the following code --- res = [] x = [ 1, 1 ] for i in xrange(0,5): res.append(x) x[1] = x[1] + 1 print "x = ", x print "res = ", res --- Looks like it puts smth like reference to 'x' into 'res' list, instead of value. But if I want a value should I use a different method or what ? Evgeni P.S. Could not easily find the issue in the manual/tutorial can you point me out to smth relevant ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with .next() method adding junk characters.
John Machin wrote: > Rainy wrote: > > Hi, > > > > I tried searching for this and did not find this issue. I only looked > > at about dozen hits, I apologize if this is covered somewhere and I > > missed it. Without much further ado, here's the thing (Win, Py2.5): > > > > >>> f = open('test', 'w') > > >>> f.fileno() > > 4 > > >>> f.write('1\n') > > >>> f.write('2\n3\n4\n') > > >>> f.next() > > > > Traceback (most recent call last): > > File "", line 1, in > > f.next() > > IOError: [Errno 9] Bad file descriptor > > This *should* complain that the file is not open for reading. What you > see is an accidental error. message. When I tried it, I got no error, > but it printed a few hundred bytes of garbage. > In both your case and mine, it has also written a load of junk to the > file! > > > >>> f.close() > > >>> f = open('test') > > >>> f.next() > > '1\n' > > >>> f.next() > > '2\n' > > >>> f.next() > > '3\n' > > >>> f.next() > > '4\n' > > >>> f.next() > > '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > > ...many more lines of junk...' > > Junk was written to the file earlier. > > > > > I understand that you're not > > supposed to call .next on a file open for writing. > > Indeed. However if you mess up, Python is supposed to give you a > meaningful error message and not write gibberish to your file. > > Please report it as a bug. > > Cheers, > John Thanks for the reply, I reported it.. -Rainy -- http://mail.python.org/mailman/listinfo/python-list
Re: windev vs python SOS
stéphane bard wrote: > hello, my boss ask me to prefer windev to python. > I have to argue > > any idea for a strong argument ? * WinDev is a virtual unknown outside France. I tried asking a bunch of colleagues about WinDev just now. Nobody has even heard about it. Prior to doing Java I was doing Windows development for years--never a single time I heard about this thing. This can be much more significant than you think--there's a huge difference between developing something in a language that has a lot of websites, books, forum, etc. dedicated to it, and a proprietary IDE. I developed using a proprietary product I won't name here for about 2 years... the support was horrible, and the product SUCKS big time. * Python is known world-wide, there are already many books written by very, very intelligent people--you can "borrow" their brains anytime through their books. There are many online resources at your fingertips if you come across a problem. This group is also chock full of very smart people, some of whom contribute code to Python itself. Wonder how much do you have to pay WinDev for support? (If your boss really doesn't like Python, you might as well use Visual Basic, since it has a lot of free resources, Microsoft newsgroups, and so on.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with .next() method adding junk characters.
Rainy wrote: > Hi, > > I tried searching for this and did not find this issue. I only looked > at about dozen hits, I apologize if this is covered somewhere and I > missed it. Without much further ado, here's the thing (Win, Py2.5): > > >>> f = open('test', 'w') > >>> f.fileno() > 4 > >>> f.write('1\n') > >>> f.write('2\n3\n4\n') > >>> f.next() > > Traceback (most recent call last): > File "", line 1, in > f.next() > IOError: [Errno 9] Bad file descriptor This *should* complain that the file is not open for reading. What you see is an accidental error. message. When I tried it, I got no error, but it printed a few hundred bytes of garbage. In both your case and mine, it has also written a load of junk to the file! > >>> f.close() > >>> f = open('test') > >>> f.next() > '1\n' > >>> f.next() > '2\n' > >>> f.next() > '3\n' > >>> f.next() > '4\n' > >>> f.next() > '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > ...many more lines of junk...' Junk was written to the file earlier. > > I understand that you're not > supposed to call .next on a file open for writing. Indeed. However if you mess up, Python is supposed to give you a meaningful error message and not write gibberish to your file. Please report it as a bug. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
ANN: Urwid 0.9.7 - Console UI Library
Announcing Urwid 0.9.7 -- Urwid home page: http://excess.org/urwid/ Tarball: http://excess.org/urwid/urwid-0.9.7.tar.gz About this release: === This release adds a new BigText widget for banners and text that needs to stand out on the screen. A new example program demonstrating BigText usage and a number of fonts are included. This widget is a fixed widget, a new alternative to flow widgets and a box widgets. Fixed widgets may be displayed within Overlay or Padding widgets to handle changing screen sizes. New in this release: - Added initial support for fixed widgets - widgets that have a fixed size on screen. Fixed widgets expect a size parameter equal to (). Fixed widgets must implement the pack(..) function to return their size. - New BigText class that draws text with fonts made of grids of character cells. BigText is a fixed widget and doesn't do any alignment or wrapping. It is intended for banners and number readouts that need to stand out on the screen. Fonts: Thin3x3Font, Thin4x3Font, Thin6x6Font (full ascii) UTF-8 only fonts: HalfBlock5x4Font, HalfBlock6x5Font, HalfBlockHeavy6x5Font, HalfBlock7x7Font (full ascii) New function get_all_fonts() may be used to get a list of the available fonts. - New example program bigtext.py demonstrates use of BigText. - Padding class now has a clipping mode that pads or clips fixed widgets to make them behave as flow widgets. - Overlay class can now accept a fixed widget as the widget to display "on top". - New Canvas functions: pad_trim(..) and pad_trim_left_right(..). - Fixed a bug in Filler.get_cursor_coords(..) that causes a crash if the contained widget's get_cursor_coords(..) function returns None. - Fixed a bug in Text.pack(..) that caused an infinite loop when the text contained a newline. This function is not currently used by Urwid. - Edit.__init__(..) now calls set_edit_text(..) to initialize its text. - Overlay.calculate_padding_filler(..) and Padding.padding_values(..) now include focus parameters. About Urwid === Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. -- http://mail.python.org/mailman/listinfo/python-list
Re: PATCH: Speed up direct string concatenation by 20+%!
An update: I have submitted this as a patch on SourceForge. It's request ID #1569040. http://sourceforge.net/tracker/?group_id=5470&atid=305470 I invite everyone to take it for a spin! There are some improvements in this version. Specifically: * Python will no longer crash if you do ten million prepends ( x = 'a' + x ). Since the problem was blowing the stack with an incredibly deep render, I now limit the depth of the string concatenation objects (currently set at 16384). Note that string prepending is now *immensely* faster, as prepending in the existing implementation is a worst-case. * I figured out why my zero-length strings were occasionally not zero terminated. It had to do with subclassing a string and storing an attribute in the object, which meant storing a dict, and where specifically the interpreter chose to store that. The solution was essentially to ensure there's always space in the object for the trailing zero. When running regrtest.py, my patched version produces identical output to a non-patched build on Windows. Steve Holden wrote: > Does a comparison also force it to render? Yes. Any attempt to examine the string causes it to render. > It does sound like memory usage > might go through the roof with this technique under certain > circumstances, so the more extensive your tests are the more likely you > are to see the change actually used (I'm not convinced you'll persuade > the developers to include this). Yeah, I expect memory usage to be higher too, but not by a fantastic amount. Once you render the concatenation, it drops all the references to the child objects held in the tree, and what's left is a string object with some extra space on the end. > I think your project might make a very > interesting PyCon paper for people who were thinking about joining the > development effort but hadn't yet started. Perhaps; I've never been to PyCon, but it might be fun to give a presentation there. That said, it would be way more relevant if the patch got accepted, don'tcha think? Cheers, /larry/ p.s. Thanks for the sentiment, Colin W.! -- http://mail.python.org/mailman/listinfo/python-list
Problem with .next() method adding junk characters.
Hi, I tried searching for this and did not find this issue. I only looked at about dozen hits, I apologize if this is covered somewhere and I missed it. Without much further ado, here's the thing (Win, Py2.5): >>> f = open('test', 'w') >>> f.fileno() 4 >>> f.write('1\n') >>> f.write('2\n3\n4\n') >>> f.next() Traceback (most recent call last): File "", line 1, in f.next() IOError: [Errno 9] Bad file descriptor >>> f.close() >>> f = open('test') >>> f.next() '1\n' >>> f.next() '2\n' >>> f.next() '3\n' >>> f.next() '4\n' >>> f.next() '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 ...many more lines of junk...' I'm not actually trying to do something particular, I'm making snippets of example code for all functions in LibRef and I ran into this, and I'm just curious as to what's happening. I understand that you're not supposed to call .next on a file open for writing. But I don't know why and how it does what happened here; besides, I've seen the same thing happen before when I was doing something else with file open/write/close, but I don't remember the specifics. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple but fast 2D lib for drawing pixels
Peter Mexbacher wrote: > Hello, > > we want to teach absolute programming newbies > a first language, so they can start programming > simple scientific models. > > We thought Python would make a good choice for > a first language; but where pretty stumped when > we found out that there is no simple way to draw > pixels to a screen. (This is needed for fractals, > agent-based models etc -> like Conways Game of Life) > > Our requirements: > > -) easy to learn (newbs!) > -) not too slow (after all, the models should simulate something) > -) python :-) > > Any ideas? > > Best Regards, > Peter Did you look at the turtle module included in the standard distribution? It's very simple, made for beginners, and fast enough for simple plots (just turn off the tracer). If you intend to introduce the class to GUI's at some point I believe turtle is built on the Tkinter canvas widget, which may be suitable as well. However, if you're teaching scientific programming to more technically advanced users you might be better off using matplotlib/ipython. That will get you a matlab-like enviroment with many advanced capabilities. -- David -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple but fast 2D lib for drawing pixels
Peter Mexbacher wrote: > We thought Python would make a good choice for > a first language; but where pretty stumped when > we found out that there is no simple way to draw > pixels to a screen. (This is needed for fractals, > agent-based models etc -> like Conways Game of Life) > [snip] > -) easy to learn (newbs!) > -) not too slow (after all, the models should simulate something) > -) python :-) http://www.pygame.org/ - it's not just for games :) It'll do what you want (put pixels on the screen) easily. It'll even let you work with numeric arrays and then put those arrays on screen. Sign up to the pygame users list to ask more questions - they're always a helpful, friendly bunch. Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python world tries to be polite [formerly offensive to another language]
MonkeeSage wrote: > Ant wrote: > > Don't think so, I followed the thread along a little, and it seems to > > be correct. In addition, they seem to have the ¥ character as the Perl > > 6 equivalent of zip(). Those crazy guys. > > Yup, I don't think it was a joke either; there are several other > "hyper" operators already in pugs: > http://svn.openfoundry.org/pugs/src/Pugs/Parser/Operator.hs (see tests: > http://svn.openfoundry.org/pugs/t/operators/hyper.t ). If it weren't Perl I would think of this as an April Fool's joke. Good thing by the time Perl 6 comes out nobody'll care enough about it to use it (in fact even if it comes out tomorrow, does anybody still care?). So it's quite unlikely for us to encounter it in the real world... or so I hope. > > Regards, > Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: changing a file's permissions
James <[EMAIL PROTECTED]> writes: > I'm writing a script in linux to excercise my python skills and have > encountered a minor issue. Writing the script and creating an ouput > file was simple enough and didn't take too long. However, I don't > have permissions to execute the file by default. This is an attribute of the file (an object in the filesystem) which is checked by the kernel before allowing the file to be executed. Python has nothing to do with this; if the attributes allow execution, you can execute it as a program; if not, you can't. > Now, I could simply chmod 755 the sucker and have done with it That (or some equivalent filesystem operation to change the attributes of the file) is the only solution to the problem you present. This is by design. > but I want to apply the permissions within the python script if I can. Since the permissions are used by the operating system kernel to determine if you have permission execute the file at all, the program isn't even executing when the decision is made. Change the permission attributes of the program file (using 'chmod' or something else that operates on the filesystem object's attributes), then you'll be able to run it as a program. Incidentally, if the program is intended to be run from a command line, it's best to name the file with no '.py' extension. The fact that a command is implemented in Python is irrelevant to the person running that command; it also means you can implement it in some other language later on without changing everything that uses that command. -- \ "Facts are meaningless. You could use facts to prove anything | `\ that's even remotely true!" -- Homer, _The Simpsons_ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: XSLT speed comparisons
Jordan wrote: > If your using python 2.4.3 or essentially any of the 2.3, 2.4 series, > i'd test out PyScripter as an IDE, it's one of the best that I've used. > Unfortunately, they have yet to fully accomedate 2.5 code (you can > still write 2.5 code with almost no problems, but you won't be able to > use a 2.5 interactive interpeter). An unofficial update supporting Python 2.5 is available at pyscripter.googlepages.com and an offical release is coming real soon. -- http://mail.python.org/mailman/listinfo/python-list
Re: changing numbers to spellings
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > [EMAIL PROTECTED] wrote: >> Hey, >> >> Sorry to bother everybody again, but this group seems to have quite a >> few knowledgeable people perusing it. >> >> Here's my most recent problem: For a small project I am doing, I need >> to change numbers into letters, for example, a person typing in the >> number '3', and getting the output 'Three'. So far, I have an interface >> that only collects numbers (or letters), and displays them in a text >> variable label (as you can see below). Heres the code I have: >> >> ++---+ >> >> var=StringVar() >> >> def collect(): >> var.set(entrybox.get()) >> >> spelledentry=Label(root, textvariable=var) >> spelledentry.grid(row=5, column=1) >> >> filler1=Label(root, text="") >> filler1.grid(row=0, column=0) >> >> titletext=Label(root, text="NumberSpeller2") >> titletext.grid(row=0, column=1) >> >> filler2=Label(root, text="") >> filler2.grid(row=0, column=2) >> >> filler3=Label(root, text="\n") >> filler3.grid(row=1, column=0) >> >> entrybox=Entry(root) >> entrybox.grid(row=1, column=1, sticky=N) >> >> enterbutton=Button(root, text="Spell!", command=collect) >> enterbutton.grid(row=3, column=1, sticky=N) >> >> filler4=Label(root, text="") >> filler4.grid(row=4, column=1) >> >> filler5=Label(root, text="") >> filler5.grid(row=6, column=1) >> >> website=Label(root, text="Visit the NS2 Website") >> website.grid(row=7, column=1, sticky=S) >> >> +-++ >> >> Like I explained a little before, I need to keep users from entering >> any letters, and I need to have the numbers they typed in translated to >> text. >> >> Can someone explain how I could go across doing this? >> > You should get some clue about the number conversion (not to menion a > bunch of code you can lift :) from > > http://www.python.org/pycon/dc2004/papers/42/ex1-C/num2eng.py > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenweb http://holdenweb.blogspot.com > Recent Ramblings http://del.icio.us/steve.holden > ... and pyparsing has an example that goes from words back to numbers! http://pyparsing.wikispaces.com/space/showimage/wordsToNum.py -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Trying to find a elements Xpath and store it as a attribute
Hi all, I've been struggling with this for a while so I'm hoping that someone could point me in the right direction. Here's my problem: I'm trying to get the XPath for a given node in my document and then store that XPath as an attribute of the element itself. If anyone has a recommendation I'd be happy to hear it. Thanks, Provo For instance, I would take this XML ###before An XSLT Programmer Hello, World! ###after An XSLT Programmer Hello, World! ### import sets import amara from amara import binderytools doc = amara.parse('hello.xml') elems = {} for e in doc.xml_xpath('//*'): paths = elems.setdefault((e.namespaceURI, e.localName), sets.Set()) path = u'/'.join([n.nodeName for n in e.xml_xpath(u'ancestor::*')]) paths.add(u'/' + path) for name in elems: doc.name.km = elems[name] -- http://mail.python.org/mailman/listinfo/python-list
changing a file's permissions
I'm writing a script in linux to excercise my python skills and have encountered a minor issue.Writing the script and creating an ouput file was simple enough and didn't take too long. However, I don't have permissions to execute the file by default. Now, I could simply chmod 755 the sucker and have done with it, but I want to apply the permissions within the python script if I can. So my question is: how does one change a file's permissions inside of python?James -- http://mail.python.org/mailman/listinfo/python-list
Picture in Excel issue
I’m trying to very simply insert a picture from a file into an excel spreadsheet. I know how to do this in VBA and it works fine, however when I try this from python I get an error. Doing a search on this turned up nothing. The code I’m using is: from win32com.client.dynamic import Dispatch xl = Dispatch( 'Excel.Application' ) xl.Visible=1 xl.Workbooks.Add() xl.ActiveSheet.Pictures.Insert("C:\a.jpg") Traceback (most recent call last): File "", line 1, in xl.ActiveSheet.Pictures.Insert("C:\a.jpg") AttributeError: 'function' object has no attribute 'Insert' I’m not sure why I get this issue since ‘ActiveSheet.Pictures.Insert("C:\a.jpg")’ works fine from within Excel. Several internet posts from my searches also suggest to use this method. I’ve tried this on both Python 2.1 and 2.5 with the same results. Any idea what the problem is or how I can insert the picture?? TIA, Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: changing numbers to spellings
Tim Williams wrote: > my_nums = { 1 : 'One' , 2 : 'Two' , 3 : 'Three' , 4 : 'Four' } # etc etc > print my_nums[x] That's what I suggested, but since a list is already zero indexed I used that rather than a dictionary. And Paul Rubin posted a very nice solution that handles numbers larger than 9. I think the OP wants us to write their GUI code for them or something... Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin regular expressions?
Max M wrote: > When I used to program in Perl I used regex' for lots of stuff. In > python I probably use them once every half year. I sinply do not need them. I think you can pretty much do it either way without any big benefits / losses. There are edge-cases that will break a praser just like there are ones that will break a regexp. In perl5 you can slice strings ( my $s="Cat in a tree"; ${s:0:3} == 'Cat' ) and other things like that, but I seldom see those used except for very trivial cases (i.e., the seeming reverse of the python practice). But this hasn't caused some kind of huge epidemic of non-working programs / libraries in the perl world. If you understand how to use regexps and they are easier for you, there is no reason not to use them. On the other hand, if they make it harder for you, don't use them. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: windev vs python SOS
Scott David Daniels <[EMAIL PROTECTED]> writes: > While these statements do mean something to experienced programmers, > they seem to contradict everything a power-point wielding IT executive > who understands everything "from a 5000 foot point of view" knows to > be true. I really wish I knew how to explain these things politically. If you find it out don't forget sharing with us. :-) -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple but fast 2D lib for drawing pixels
On Oct 1, 2006, at 6:28 PM, Peter Mexbacher wrote: > Hello, > > we want to teach absolute programming newbies > a first language, so they can start programming > simple scientific models. > > We thought Python would make a good choice for > a first language; but where pretty stumped when > we found out that there is no simple way to draw > pixels to a screen. (This is needed for fractals, > agent-based models etc -> like Conways Game of Life) > > Our requirements: > > -) easy to learn (newbs!) > -) not too slow (after all, the models should simulate something) > -) python :-) > > Any ideas? > > Best Regards, > Peter You might check out John Zelle's Python book - he uses a simple graphics library on top of Tk (which Python comes with). You can find information on his book and the graphics.py file he uses at: http://mcsp.wartburg.edu/zelle/python/ It certainly meets your easy to learn and Python requirements - and of course speed is subjective so it may or may not be fast enough for you. Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: how to reuse class deinitions?
> What I do: > > For each new major version of python, in .../site-packages I make a > directory "sdd" (my initials). In it I put an empty file named > "__init__.py". When I have things I want to reuse, I put them in > files named things like ".../site-packages/sdd/goodidea.py", and > I get use of them in python programs like: > > from sdd.goodidea import File > ... > > ... > > or (actually my current style): > from sdd import goodidea > ... > > ... > this is basically what i was trying to do. i just tried it again, with a class_defs.py file in a folder i appended to the system path, itself containing the class definition for File. then: from class_defs import File works fine. nice to know i was on the right lines. thanks for the pointer! -- http://mail.python.org/mailman/listinfo/python-list
Re: preemptive OOP?
* Kent Johnson wrote (on 9/30/2006 2:04 PM): > John Salerno wrote: >> So my question in general is, is it a good idea to default to an OOP >> design like my second example when you aren't even sure you will need >> it? I know it won't hurt, and is probably smart to do sometimes, but >> maybe it also just adds unnecessary code to the program. > > In general, no. I'm a strong believer in You Aren't Going to Need It > (YAGNI): > http://c2.com/xp/YouArentGonnaNeedIt.html > > because it *does* hurt > - you have to write the code in the first place > - every time you see a reference to MyNotebook you have to remind > yourself that it's just a wx.Notebook > - anyone else looking at the code has to figure out that MyNotebook is > just wx.Notebook, and then wonder if they are missing something subtle > because you must have had a reason to create a new class... > > and so on...Putting in extra complexity because you think you will need > it later leads to code bloat. It's usually a bad idea. > > Possible exceptions are > - If you are really, really, really sure you are going to need it > really, really soon and it would be much, much easier to add it now then > after the next three features go in, then you might consider adding it > now. But are you really that good at predicting the future? > - When you are working in a domain that you are very familiar with and > the last six times you did this job, you needed this code, and you have > no reason to think this time is any different. > > You struck a nerve here, I have seen so clearly at work the difference > between projects that practice YAGNI and those that are designed to meet > any possible contingency. It's the difference between running with > running shoes on or wet, muddy boots. > > Kent I have only caught the tail of this thread so far so I may have missed some important info. However, Kent's response is, I think, a bit of an oversimplification. The answer to the original question, as quoted above, is ... it depends. On several things, actually. If this is a 'one-shot' program or simple library to accomplish a limited goal then the added complexity of OO is probably overkill. Many scripts fall into this category. You can go to a lot of trouble to generate an OO solution to a simple problem and not get much payoff for your effort. Simple problems are often solved best with simple solutions. However, when an application (or library) is designed to provide a more 'general purpose' solution to one or more problems and is likely to have a lifetime beyond the 'short term' (whatever that may mean to you), then OO can start to pay off. In these kinds of applications you see the need for future maintenance and a likely need to expand on the existing solution to add new features or cover new ground. This is made easier when the mechanism for this expansion is planned for in advance. Without this prior planning, any expansion (not to mention bug fixing) becomes more difficult and makes the resulting code more brittle. While not all planning for the future requires OO, this is one mechanism that can be employed effectively *because* it is generally well understood and can be readily grasped *if* it is planned and documented well. There is certainly a *lot* of 'Gratuitous OOP' (GOOP?) out there. This isn't a good thing. However, that doesn't mean that the use of OOP in any given project is bad. It may be inappropriate. OO is a simply a way of dealing with complexity in SW development. If a problem is complex then the solution will have to deal with that complexity. If OO can be used to make a complex solution less complex then it is appropriate. If the use of OO makes a simple solution *more* complex then it is being used inappropriately. It is not only necessary to have the correct tools for the job but, also, to be skilled in their use. Part of the skill of a SW developer is in picking the correct tool for the job - and then using it correctly. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: how to reuse class deinitions?
sam wrote: > hello all, > > pretty straightforward question here, i think. i'm experimenting with > classes and have written a File class that looks like it's worth > keeping for future use. however, i cannot work out where to put it for > this purpose or how to get it in. > > i figured i'd try a bit of (un)inspired guesswork by putting it in my > module folder, appending sys.path to tell the interpreter where this > was, and importing it like a module. probably don't need to tell you > that that didn't work, but i'm drawing a blank in the tutorial and not > getting any luck in the archives here. maybe i'm just not searching > with the right words. it's late here and my brain's switching off... > > cutting and pasting it into the interpreter is a bit of a bore. any > help? > > much appreciated in advance, > > sam > > PS i've just reached first base with classes, and i think i'm starting > to see what the big deal is about OOP. it's like someone's turned a > light on. > Here's how I do it. This seems to work pretty well for me. More seasoned programmers may have better ways. 1. Develop modules (packages) in a folder called something like "~/Code". 2. Name the directory the same name as the module or package. 3. See this for packages and modules how-to: http://docs.python.org/tut/node8.html You basically will want to think in terms of packages if you use my method. 4. Now, set up your $PYTHONPATH environment variable to point at the "~/Code" directory. Here's how you do it in UNIX (ask a DOS guru for how to do it DOS). This if for your ~/.tcshrc file or ~/.cshrc file (whichever you use): setenv PYTHONPATH /path/to/Code This is for a ~/.bashrc file: PYTHONPATH=/path/to/Code export PYTHONPATH If you have already set $PYTHONPATH somewhere else, then you probably don't need me to tell you how to include "/path/to/Code" in it. 5. Open a new shell so the $PYTHONPATH gets set correctly for your rc file. 6. Now, start python in that shell and import your packages. Congratulations! You have now setup an environment where all the code you write becomes packages and re-usable. Why a similar recipe isn't in every tutorial or beginning python book, I haven't a clue because it saves hella time figuring out exactly what you have asked here. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python world tries to be polite [formerly offensive to another language]
Ant wrote: > Don't think so, I followed the thread along a little, and it seems to > be correct. In addition, they seem to have the ¥ character as the Perl > 6 equivalent of zip(). Those crazy guys. Yup, I don't think it was a joke either; there are several other "hyper" operators already in pugs: http://svn.openfoundry.org/pugs/src/Pugs/Parser/Operator.hs (see tests: http://svn.openfoundry.org/pugs/t/operators/hyper.t ). Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python world tries to be polite [formerly offensive to another language]
Ant wrote: > Don't think so, I followed the thread along a little, and it seems to > be correct. In addition, they seem to have the ¥ character as the Perl > 6 equivalent of zip(). Those crazy guys. Yup, I don't think it was a joke either; there are several other "hyper" operators already in pugs: http://svn.openfoundry.org/pugs/src/Pugs/Parser/Operator.hs (see tests: http://svn.openfoundry.org/pugs/t/operators/hyper.t ). Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: how to reuse class deinitions?
sam wrote: > pretty straightforward question here, i think. i'm experimenting with > classes and have written a File class that looks like it's worth > keeping for future use. however, i cannot work out where to put it for > this purpose or how to get it in. What I do: For each new major version of python, in .../site-packages I make a directory "sdd" (my initials). In it I put an empty file named "__init__.py". When I have things I want to reuse, I put them in files named things like ".../site-packages/sdd/goodidea.py", and I get use of them in python programs like: from sdd.goodidea import File ... ... or (actually my current style): from sdd import goodidea ... ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Simple but fast 2D lib for drawing pixels
Hello, we want to teach absolute programming newbies a first language, so they can start programming simple scientific models. We thought Python would make a good choice for a first language; but where pretty stumped when we found out that there is no simple way to draw pixels to a screen. (This is needed for fractals, agent-based models etc -> like Conways Game of Life) Our requirements: -) easy to learn (newbs!) -) not too slow (after all, the models should simulate something) -) python :-) Any ideas? Best Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: how to reuse class deinitions?
should read 'definitions', of course. i hate stupid typos. -- http://mail.python.org/mailman/listinfo/python-list
how to reuse class deinitions?
hello all, pretty straightforward question here, i think. i'm experimenting with classes and have written a File class that looks like it's worth keeping for future use. however, i cannot work out where to put it for this purpose or how to get it in. i figured i'd try a bit of (un)inspired guesswork by putting it in my module folder, appending sys.path to tell the interpreter where this was, and importing it like a module. probably don't need to tell you that that didn't work, but i'm drawing a blank in the tutorial and not getting any luck in the archives here. maybe i'm just not searching with the right words. it's late here and my brain's switching off... cutting and pasting it into the interpreter is a bit of a bore. any help? much appreciated in advance, sam PS i've just reached first base with classes, and i think i'm starting to see what the big deal is about OOP. it's like someone's turned a light on. -- http://mail.python.org/mailman/listinfo/python-list
Re: changing numbers to spellings
On 1 Oct 2006 14:08:24 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I guess I'm just looking for a small code sample hooked up to the code > I gave, that would collect the input, compare it to code such as: > > if x==5 > print "Five" > elif x==6 > print "Six" > elif x==7 > print "Seven" > > Something along those lines. That was actually like the code I used for > something else a while ago. > > My only problem is, I want it to be printed to a textvariable for use > in the label. You can replace the above snippet with: my_nums = { 1 : 'One' , 2 : 'Two' , 3 : 'Three' , 4 : 'Four' } # etc etc print my_nums[x] so... >>> x = 2 >>> print my_nums[x] 'Two' >>> x = 4 >>> print my_nums[x] 'Four' and my_nums[x] is a "variable" for you to use. HTH :) -- http://mail.python.org/mailman/listinfo/python-list
Re: a different question: can you earn a living with *just* python?
[EMAIL PROTECTED] wrote: > Paul Rubin wrote: >> Very interesting post and list. I think I'd add at least one assembly >> language. > > Yes, definitely. I'd propose DEK's MMIX assembly language if you go for only one (or two) -- learn modern machine architectural directions at the same time as you learn an assembly language. You can still execute it (plenty of simulators are available for free), and you can get an idea of kinds of efficiency without having to learn five or six architectures. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
trouble connecting to KFNX radio station for Mark Lutz interview
Is anyone else having trouble? It worked for me last night, but now it's saying: C00D11BD: Cannot play the file Windows Media Player cannot play the file because the specified protocol is not supported. If you encountered this error by typing a Uniform Resource Locator (URL) in the Open URL dialog box, try using a different transport protocol (for example, "mms:") to open the file. If you encountered this error by clicking a link on a Web page, the link might not be valid. Error ID = 0xC00D11BD, Condition ID = 0x Hopefully I can hear this interview, if not now then later somehow. -- http://mail.python.org/mailman/listinfo/python-list
Re: changing numbers to spellings
I guess I'm just looking for a small code sample hooked up to the code I gave, that would collect the input, compare it to code such as: if x==5 print "Five" elif x==6 print "Six" elif x==7 print "Seven" Something along those lines. That was actually like the code I used for something else a while ago. My only problem is, I want it to be printed to a textvariable for use in the label. Thanks again for all your help! Tanner -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
[Charlie Strauss] >>> level0: newly created objects >>> level1: objects that survived 1 round of garbage collection >>> level2: objects that survivied 2+ rounds of gargbage collection >>> >>> Since all of my numerous objects are level2 objects, and none of >>> them are every deallocated, then I should never trip the GC for >>> these. [Fredrik Lundh] >> your understanding of generational GC is a bit fuzzy, it seems. >> that an object is promoted to a higher level means that it's >> not inspected quite as often as lower-level objects, not that it's >> never inspected at all. [Charlie] > As I understand it, level2 (and level1) objects only undergo gc when > more than 10 of them is deallocated. Since I never deallocate, this > should not be tripped right? No. Cyclic gc is triggered by an excess of allocations over deallocations. > In any case regarding your other comments: >>> Could you clarify that for me. GC really has three components >>> two it: 1) finding and freeing unrefernced memory by refer >>> refer counts 2) cycle removal and 3) defragementing the >>> storage stack. If I turn off GC, don't I lose all of these? >> CPython always does (1), only does (2) if cycle-breaking GC isn't >> disabled, and never does (3). > Never does 3? Correct. > then how does it compact it's memory allocation area? It doesn't. > Surely it does not rely on the OS to manage every small object as a > separate memory allocation. It doesn't do that either. Python has its own small-object allocator, carving up 256KB chunks obtained from the system malloc(). It's based on size-segregated "pools" with extremely low bookkeeping overhead, and external fragmentation in small-object memory is essentially non-existent because of that (although it's possible to concoct pathological programs that exhibit it). > And just to be clear: are you saying that when I do a gc.disable this > only turns off 2 and not 1? Right. Refcounting (#1) can never be disabled, and cyclic GC (#2) is used only for trash objects that can't be reclaimed by #1 (meaning container objects in cycles). -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
[charlie strauss] > Steve, digging into the gc docs a bit more, I think the behaviour I am seeing > is still > not expected. Namely, the program I offered has no obvious place where > objects > are deallocated. The way GC is supposed to work is thate there are three > levels of > objects > > level0: newly created objects > level1: objects that survived 1 round of garbage collection > level2: objects that survivied 2+ rounds of gargbage collection Yes. > Since all of my numerous objects are level2 objects, No. All newly created objects start in level0. Over time, most (but never all) of your objects end up in level 2. > and none of them are every deallocated, then I should never trip the GC for > these. Cyclic gc scans /all/ container objects at or under level N, whenever cyclic gc runs. N varies from run to run of cyclic gc, according to the scheme described in the docs for the gc.set_threshold() function. N=2 is certainly a possible value. There is never a time when a live container object becomes exempt from all future runs of cyclic gc. If a live container object survives two rounds of cyclic gc, it ends up lin level2. That doesn't mean it's never looked at again, it just means it's not looked at during level0 or level1 (N=0 or N=1) runs of cyclic gc. It will still be looked at during all level2 (N=2) runs of cyclic gc. > Your explanation would require this to be tripped so I can't explain it. For > your > explanation to be correct then there as to be some non-obvious step in the > program > that is deallocating level2 items in sufficient numbers to trip the GC. Deallocations never trigger cyclic gc. As the docs say, cyclic gc is triggered by an /excess/ of allocations /over/ deallocations. So, e.g., if you delete container objects just as fast as you create them, cyclic gc will never run. But that's not what you're doing. Instead you're allocating new objects but never deallocating them. That makes cyclic gc run as frequently as it's possible for it to run. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
[charlie strauss] > I want to clarify that, on my computer, the first instance of the gap occurs > way > before the memory if filled. (at about 20% of physical ram). Additionally the > process monitor shows no page faults. Python has no idea of how much RAM you have, or even of how much RAM it's using. See the `gc` module docs, function set_threshold(), for a description of when Python decides to run a cyclic gc pass. That's all about the current excess (if any) of the number of container allocations over the number of container deallocations since the last time cyclic gc ran. > ... > (note that the array if filled as [1]*10, so there is actually only one > "integer", > but 10 array elements refering to it, per foo class.) Nevertheless cyclic gc has to examine all 10 array elements each time the list is scanned. > ... > For example when I write > > me.memory = [1]*nfoo > > perhaps internally, python is allocating an array of size foo and then > __copying__ it > into me.memory??? No. Assignments in Python never copy anything. > Since there is no reference to the intermediate it would then marked for > future > garbage collection. Nothing in Python is "marked for future garbage collection". From time to time /all/ container objects are scanned to determine whether any have become cyclic trash. This takes time proportional to the total number of containees across all container objects. ... > foo was an election ballot holding 10 outcomes, and bar was a set of 100 > ballots > from 100 voting machines, and the total array was holding the ballot sets > from a few > thousand voting machines. > > Almost any inventory program is likely to have such a simmilar set of nested > array, > so it hardly seems unusual. For memory-consumption reasons alone, a serious such program is likely to use array.array objects at leaf level instead. array.array objects hold raw bits, not Python objects. Since they don't hold Python objects, they can't possibly be part of a cycle, so cyclic gc doesn't need to scan array.array contents either. -- http://mail.python.org/mailman/listinfo/python-list
python threading and timing
hello I'm writing a Python application for live music performance/improivsation, using csound as the synthesis engine, and Python for compositional algorithms, GUI and control. I creating several threads: one for GUI one for csound, one for a timed queue (timed automation events), one for communication with a tcp based sensor interface. My threads do not share data, I use threads merely to enable several processes to run in paralell. I think I do not need to use locks to control threads in this case, but I'm not sure (?) Also, I wonder what method I should be using to get a precise timing in my automation thread (acting as a sequencer). I've attached two simple examples of different ways I could implement threads. The only task in these examples is to generate timed counters, but the general procedure would be the same for more complex timed tasks. One example uses time.sleep() to release a thread's interpreter lock, and at the same time provide the time interval until the next iteration. The other example uses a thread event wait() call. It seems that the example using wait() does not provide the same precision as time.sleep() does (the counters does not sync, e.g. a counter with a time interval of 0.1 does not count 10 times as fast as a counter with a time interval of 1 second. Any insights on how to do this the best way (thread safety and time precision) would be greatly appreciated. best Oeyvind Brandtsegg # test of threading routines for calling functions periodically import threading import time class CounterTest(threading.Thread): def __init__(self, res, name): self.name = name self.counter = 0 self.keepRunning = 1 self.res = res threading.Thread.__init__(self) def run(self): while self.keepRunning: print self.name, self.counter self.counter += 1 time.sleep(self.res) def stopme(self): self.keepRunning = 0 c1 = CounterTest(1,'one') c2 = CounterTest(0.1,'two') print 'starting threads' c1.start() c2.start() #allow threads to run for a while time.sleep(5) c1.stopme() c2.stopme() print 'threads stopped'# test of threading routines for calling functions periodically import threading import time class CounterTest(threading.Thread): def __init__(self, res, name): self.name = name self.counter = 0 self._stopevent = threading.Event() self._sleepperiod = res threading.Thread.__init__(self) def run(self): while not self._stopevent.isSet(): print self.name, self.counter self.counter += 1 self._stopevent.wait(self._sleepperiod) def stopme(self): self._stopevent.set() c1 = CounterTest(1,'one') c2 = CounterTest(0.1,'two') print 'starting threads' c1.start() c2.start() #allow threads to run for a while time.sleep(5) c1.stopme() c2.stopme() print 'threads stopped'-- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
[Steve Holden, "pins the blame" for pauses on periodic cyclic gc] > ... > So basically what you have here is a pathological example of why it's > sometimes wise to disable garbage collection. Tim, did I miss anything? Nope! -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
[charlie strauss] >>> Below is a simple program that will cause python to intermittently >>> stop executing for a few seconds. it's 100% reproducible on my >>> machine. [Giovanni Bajo] >> Confirmed with Python 2.4.2 on Windows. [Jorgen Grahn] > And Python 2.3.5 on Linux, amd64. In fact, it causes heavy swapping so it > will disrupt other processes, too. > > I didn't read the code, stupid as I am, but I trust that the behavior > doesn't match what the code actually tries to do. No, that's what it does: as it goes on, it creates an ever-increasing and unbounded number of immortal objects and lists. The "time burps" merely reflect that the more live containers and objects you have, the longer it takes for cyclic gc to determine that they're not trash. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
[charlie strauss] > Below is a simple program that will cause python to intermittently > stop executing for a few seconds. it's 100% reproducible on my machine. Any program that creates a great many long-lived container objects will behave similarly during the creation phase. Others have explained why. Here's a simpler example: from time import time xs = [] i = 0 while 1: i += 1 s = time() xs.append([[1, 2] for dummy in xrange(1000)]) f = time() if f-s > 0.25: print "time", f-s, "on try", i if i % 100 == 0: print "xs made:", i -- http://mail.python.org/mailman/listinfo/python-list
Re: Auto color selection PIL
Leif K-Brooks wrote: > Gabriel Genellina wrote: >> Try this. It first chooses 0, 1/2, then 1/4, 3/4, then */8... >> It's the best I could make if you don't know the number of colors >> beforehand. If you *do* know how many colors, your previous response >> is OK. I've no better suggestion than either of you, _but_ note that in choosing colors for keys it is generally considered better ergonomics to vary more than simply the hue if you don't want to penalize the colorblind. Consider varying the other two parameters simultaneously (perhaps in restricted ranges and varying orders); the contrast may be more substantial even to a viewer with full color vision. -- --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: windev vs python SOS
stéphane bard wrote: > hello, my boss ask me to prefer windev to python. > I have to argue > > - python work on multiple platform (linux, mac, windows) > A good point but it didn't interest him. Because > we want to choose a language for prototyping. > So multi platform is not enough. > > - python and windev are fast to develop > > - windev as a good IDE, python? boa-constructor is ok with wxpython > > - python is open source (that's not an argument for my boss, sorry > it's a boss ...) > > any idea for a strong argument ? Well, this seems to me like a "Is it faster to New York, or by train" kind of question. "WinDev" is not a language, Python is. "WinDev" is a tool which includes a language. At least make sure you are comparing similar things ("Python and the WinDev language" or "Komodo and WinDev" or "Idle and WinDev"). Note, I have never been successful with explaining this to any of my employers that didn't just trust me on these decisions. I have a nasty habit of saying things like: "'Visual Basic' is not a language; 'Visual Basic 5.0' is a language with a vague similarity to the language 'Visual Basic 6.0'." and: "SQL is not a language; it is (at best) a family of languages." While these statements do mean something to experienced programmers, they seem to contradict everything a power-point wielding IT executive who understands everything "from a 5000 foot point of view" knows to be true. I really wish I knew how to explain these things politically. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python world tries to be polite [formerly offensive to another language]
Mirco Wahab wrote: > Thus spoke A.M. Kuchling (on 2006-09-30 19:26): > > On Sat, 30 Sep 2006 09:10:14 +0100, > > Steve Holden <[EMAIL PROTECTED]> wrote: > Thats it. What is the fuzz all about? I consider 'hyper fatarrow' > (you did't the »=>« get right) just a joke of LW > (he does so sometimes ;-). Don't think so, I followed the thread along a little, and it seems to be correct. In addition, they seem to have the ¥ character as the Perl 6 equivalent of zip(). Those crazy guys. Actually this post cracked me up (Subject: My first functional perl6 program): http://www.nntp.perl.org/group/perl.perl6.language/25953 Either the poster has posted a binary file, or the Perl 6 syntax is crazier than anyone could have imagined! ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: a query on sorting
Scott David Daniels wrote: >> map(tuple,map(reversed,list(enumerate(a > > Doesn't the following read more easily? > > [tuple(reversed(x)) for x in enumerate(a)] that involves two extra name lookups for each item in the sequence, though, so it doesn't execute more easily. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to change menu text with Tkinter?
Phil Schmidt wrote: > Eric Brunel wrote: >> But Marc's answer still applies: it's a lot of work for something that >> will usually be configured once. So requiring to restart the tool when the >> UI language changes should be acceptable. > > Thanks for the example, that helps. > > I agree with you and Marc regarding the language configuration method. > The requirements aren't mine however - my customer wants the language > selectable at runtime, so I'm kind of stuck with that. You might also explain to the customer that of any menu elements are ordered alphabetically, the result of changing the language will be jarring to the user, as well as expensive to implement. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: a query on sorting
Paul McGuire wrote: > In the interests of beating a dead horse into the ground >(metaphor-mixing?), > I looked at using map to one-line the OP's request, and found an interesting > inconsistency. > > I tried using map(reversed, list(enumerate(a))), but got back a list of > iterators. To create the list of tuples, I have to call the tuple > constructor on each one, as in: > > map(tuple,map(reversed,list(enumerate(a Doesn't the following read more easily? [tuple(reversed(x)) for x in enumerate(a)] > However, sorted returns a list, not a listsortediterator. Why the > difference in these two builtins? "sorted" (esp. Timsort) _must_ have the materialized list in memory at some point in order to sort. The only alternative would be to provide a much less efficient heap-based solution that would still need everything in memory before emitting the first result. If you always have to build the list in memory, returning the list gives the recipient more chances to be efficient. "reversed" has some great special cases related to "xrange" that can be accomplished without ever converting the arg to "reversed" to a list. While "sorted" could be special cased for those cases, the chances of real useful code containing, "sorted(xrange(a, b, c))" are pretty slim. If you don't have to build the list in memory, returning a list can make a program that could be very memory efficient suddenly _much_ less so. -- --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: does anybody earn a living programming in python?
<[EMAIL PROTECTED]> wrote: > Since then, feedback from students in industry is that it is being used > more and more, day in and day out by top world class shops (games, > effects, etc). BUT It's still Java, C++, PHP, SQL that have the > marketing demands... Absolutely. But note that SQL (like Javascript, but even more so) DOES have an absolutely good, perfectly strong reason to exist within the compass of competence of any strong programmer, no matter what language[s] he or she uses for _general-purpose_ stuff. Even when using a higher-level abstraction (an ORM rather than SQL, or one of those doodads which compile some Java code into Javascript so it runs in the user's browser), which may or may not be a good choice for a certain specific use, you really still need good understanding and practice of the underlying SQL (or Javascript) in order to get solid results, good performance, debugging of any problem that may arise, etc etc ("Spolsky's Law of Leaky Abstractions" applies strongly here;-). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Battlefield Weapon Popularity Trend
Gabriel Genellina wrote: > At Wednesday 27/9/2006 07:30, Mirco Wahab wrote: > >> >> When the Samurai of medieval Japan were confronted >> >> with new 'battlefield language', e.g. early Shotguns, >> >> they resisted because one could push any peasant >> > >> > shouldn't this be "they [the Samurai] did not resist"? >> >> The "resisted" believing all the buzz, >> e.g.: "armies made of dudes with guns" ... > > From the name I guess Ramon speaks Spanish; "resistir" in Spanish has a > similar meaning, but not exactly the same, as "to resist" As we all know, a "resistir" has a reactance that doesn't vary with frequency, unlike an "inductir". --Scott David Daniels (who couldn't resist) [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating unique row ID ints.
The primary key is usually there to uniquely identify each row. There are a couple of ways to generate them: One is to always create a new integer id (sequentially or random) when you insert a new row. This means that if you insert the same data again, the row will always be duplicated. Usually you don't want this. Then the primary key integer must somehow 'represent' the whole data row. So you would want for the key to be a function of the whole data row, such that when the data is the same the row ID is the same and when the data is different the row ID is different. The answer to your problem is to use a message digest (actually a message authentication code function). For example if your data row is in the tuple 'row' then you can do: hex_digest_key=md5.new("|".join(row)).hexdigest(), you would have to import the md5 module before doing this. What that will do is your row will be contcatenated into one string with each field separated by "|" then the md5 hash of that string will be taken and the result returned to you in hexadecimal form. You'll get back something like hex_digest_key='5d41402abc4b2a76b9719d911017c592'. Then you can turn that into an integer by doing int(hex_digest_key,16) -- and you can use that integer as your primary key. But since one of the problems you want to solve is the user's ability to predict the next key, you cannot just use a simple message digest function. If the user finally figures out that you are running an MD5 algorithm, the user can also run the same algorithm and generate the same message digest -- If that is a problem, then use a MAC (Message Authentication Code) function. It works almost like a message digest except you concatenate a secret key to the input so MD5 is run on the row_as_text+secret_key. Unless the user knows your secret key, they could not generate a primary key from a given row even if they know you used MD5 and even if the know the data content of your row. NOTE: When using a message digest (and friends) it is important to realize that there will be some collision between the keys if the number of all possible digests (as limited by the digest algoritm) is smaller than the number of the possible messages. In practice if you have large enough integers (64) you shouldn't see any collisions occur, but it is still good to be aware of them... Hope this helps, -Nick Vatamaniuc Simon Wittber wrote: > I'm building a web application using sqlalchemy in my db layer. > > Some of the tables require single integer primary keys which might be > exposed in some parts of the web interface. If users can guess the next > key in a sequence, it might be possible for them to 'game' or > manipulate the system in unexpected ways. I want to avoid this by > generating a random key for each row ID, and have decided to use the > same approach for all my single key tables. > > Are there any best practices for implementing this? > > If the random module is suitable, does anyone have any good ideas on > how this could be implemented? > > Some questions which came to mind are: > Would I need to save and restore the random module state when > generating id's for each table? > What would be an appropriate seed? > How many random integers can I generate before a repeat becomes > probable? > > I've got my own ideas for implementing this, but am interested to see > how/if anyone else has tackled the same problem. > > > -Sw. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Steve Holden wrote: > I think you'll find that most programs that eat through memory in this > way will exhibit pretty much the same behaviour. If you *know* your > program isn't creating data cycles, just turn the GC off and rely on > reference counting. That won't save you from paging when you > eventually exhaust physical memory. Nothing can. Even better, if you know that you're *creating* tons of objects without creating many *discardable* cycles at the same, it's better to turn off GC collection during loading, and only do a single pass (gc.collect()) when you are done with the allocations. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: question about scope
Steve Holden wrote: > John Salerno wrote: >> James Stroud wrote: >> >> >>> This is because that list is an attribute of the class. Instances have a >>> reference of this class attribute, but it can be replaced by an >>> attribute of the instance with self (self is a reference to the instance >>> and not the class. This example might help: >> >> Ah, I see! So within my create_menubar() method, would it better to >> refer to menu_items as DataAccessFrame.menu_items? Or does it not matter >> in this case, since I'm not reassigning it per instance? > > I'd prefer to use a self-relative reference, though either works in your > example. That way the code will work for subclasses with different menus > too. Perhaps not relevant in your case, but a general point. > > regards > Steve Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I correct an error in an old post?
[EMAIL PROTECTED] wrote: > Hi. > I was searching for some information regarding a problem and found an > interesting post that includes an answer to the problem; thought the > post is very helpful it is based on a wrong assumption and thus the > solution it suggests is incorrect. It took me some time to understand > that the suggested solution is wrong and to find the correct solution > and I wish to add my findings to the post, to prevent others from > taking the wrong path. > When I tried to replay to the post I received a reject message stating > that it is impossible to replay to the topic since it is old and was > closed by a manager. > The question is how can I add this correction? > Thanks. Start a new thread and include the old post with your corrections. Yes, this means the erroneous post is still out there, and does not link directly to yours, but that's the fault of people who "close" threads, for they are among the stupidest people on the net. But if, as you did, someone else searches for the information, the old post will come up in the search results, and yours will too, because it contains the old post. So anyone who bothers to look at both will figure out what happened. --Blair -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Roel Schroeven wrote: > AFAIK Python always does reference counting, and the garbage collector > is used only for more difficult cases. As the gc module docs say: > "Since the collector supplements the reference counting already used in > Python, you can disable the collector if you are sure your program does > not create reference cycles." > > I don't know if that's only true for CPython or also for the other > implementations. CPython always uses reference counting, but that's not guaranteed by the language specification: "Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. An implementation is allowed to postpone garbage collection or omit it altogether -- it is a matter of implementation quality how garbage collection is implemented, as long as no objects are collected that are still reachable." http://pyref.infogami.com/objects -- http://mail.python.org/mailman/listinfo/python-list
How can I correct an error in an old post?
Hi. I was searching for some information regarding a problem and found an interesting post that includes an answer to the problem; thought the post is very helpful it is based on a wrong assumption and thus the solution it suggests is incorrect. It took me some time to understand that the suggested solution is wrong and to find the correct solution and I wish to add my findings to the post, to prevent others from taking the wrong path. When I tried to replay to the post I received a reject message stating that it is impossible to replay to the topic since it is old and was closed by a manager. The question is how can I add this correction? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Roel Schroeven wrote: > Charlie Strauss schreef: > >>On Oct 1, 2006, at 9:48 AM, Fredrik Lundh wrote: >> >>>charlie strauss wrote: >>> Could you clarify that for me. GC really has three components two it: 1) finding and freeing unrefernced memory by refer refer counts 2) cycle removal and 3) defragementing the storage stack. If I turn off GC, don't I lose all of these? >>> >>>CPython always does (1), only does (2) if cycle-breaking GC isn't >>>disabled, and never does (3). >> > [snip] > >>And just to be clear: are you saying that when I do a gc.disable this >>only turns off 2 and not 1? The docs don't say that as far as I can >>tell. > > > AFAIK Python always does reference counting, and the garbage collector > is used only for more difficult cases. As the gc module docs say: > "Since the collector supplements the reference counting already used in > Python, you can disable the collector if you are sure your program does > not create reference cycles." > > I don't know if that's only true for CPython or also for the other > implementations. > Read the documentation: the garbage collector is called regularly in CPython. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: question about scope
John Salerno wrote: > James Stroud wrote: > > >>This is because that list is an attribute of the class. Instances have a >>reference of this class attribute, but it can be replaced by an >>attribute of the instance with self (self is a reference to the instance >>and not the class. This example might help: > > > Ah, I see! So within my create_menubar() method, would it better to > refer to menu_items as DataAccessFrame.menu_items? Or does it not matter > in this case, since I'm not reassigning it per instance? I'd prefer to use a self-relative reference, though either works in your example. That way the code will work for subclasses with different menus too. Perhaps not relevant in your case, but a general point. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Charlie Strauss schreef: > On Oct 1, 2006, at 9:48 AM, Fredrik Lundh wrote: >> charlie strauss wrote: >>> Could you clarify that for me. GC really has three components >>> two it: 1) finding and freeing unrefernced memory by refer >>> refer counts 2) cycle removal and 3) defragementing the >>> storage stack. If I turn off GC, don't I lose all of these? >>> >> CPython always does (1), only does (2) if cycle-breaking GC isn't >> disabled, and never does (3). > [snip] > And just to be clear: are you saying that when I do a gc.disable this > only turns off 2 and not 1? The docs don't say that as far as I can > tell. AFAIK Python always does reference counting, and the garbage collector is used only for more difficult cases. As the gc module docs say: "Since the collector supplements the reference counting already used in Python, you can disable the collector if you are sure your program does not create reference cycles." I don't know if that's only true for CPython or also for the other implementations. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: question about scope
James Stroud wrote: > This is because that list is an attribute of the class. Instances have a > reference of this class attribute, but it can be replaced by an > attribute of the instance with self (self is a reference to the instance > and not the class. This example might help: Ah, I see! So within my create_menubar() method, would it better to refer to menu_items as DataAccessFrame.menu_items? Or does it not matter in this case, since I'm not reassigning it per instance? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Charlie Strauss wrote: > Sorry to be slow but I don't know what "looking at the status > message" means. did you add import gc gc.set_debug(gc.DEBUG_STATS) to the top of the program? (you need to run it to see the status messages, of course) -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
On Oct 1, 2006, at 9:48 AM, Fredrik Lundh wrote: > charlie strauss wrote: > >> level0: newly created objects >> level1: objects that survived 1 round of garbage collection >> level2: objects that survivied 2+ rounds of gargbage collection >> >> Since all of my numerous objects are level2 objects, and none of >> them are every deallocated, then I should never trip the GC for >> these. > > your understanding of generational GC is a bit fuzzy, it seems. > that an > object is promoted to a higher level means that it's not inspected > quite > as often as lower-level objects, not that it's never inspected at all. As I understand it, level2 (and level1) objects only undergo gc when more than 10 of them is deallocated. Since I never deallocate, this should not be tripped right? In any case regarding your other comments: >> Could you clarify that for me. GC really has three components >> two it: 1) finding and freeing unrefernced memory by refer >> refer counts 2) cycle removal and 3) defragementing the >> storage stack. If I turn off GC, don't I lose all of these? >> > > CPython always does (1), only does (2) if cycle-breaking GC isn't > disabled, and never does (3). Never does 3? then how does it compact it's memory allocation area? Surely it does not rely on the OS to manage every small object as a separate memory allocation. And just to be clear: are you saying that when I do a gc.disable this only turns off 2 and not 1? The docs don't say that as far as I can tell. > in your case, it's (2) that takes more and more time, simply because > you're creating tons of non-trivial objects. to see what's going > on in > there, add > > import gc > gc.set_debug(gc.DEBUG_STATS) > > to the top of your program, and look at the status messages that > appear > just before each "Big Gap" message. Could you be a bit more explicit. I'm new to the gc module. Sorry to be slow but I don't know what "looking at the status message" means. > > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
charlie strauss wrote: > Steve, digging into the gc docs a bit more, I think the behaviour I am seeing > is still not expected. Namely, the program I offered has no obvious place > where objects are deallocated. The way GC is supposed to work is thate there > are three levels of objects > > level0: newly created objects > level1: objects that survived 1 round of garbage collection > level2: objects that survivied 2+ rounds of gargbage collection > > Since all of my numerous objects are level2 objects, and none of them are > every deallocated, then I should never trip the GC for these. > > Your explanation would require this to be tripped so I can't explain it. For > your explanation to be correct then there as to be some non-obvious step in > the program that is deallocating level2 items in sufficient numbers to trip > the GC. > So perhaps you can explain why switching garbage collection off changes program behaviour? If you read the documentation more carefully you will see that the collector merely scans generations 1 and 2 less frequently that generation 0. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin regular expressions?
Jorgen Grahn skrev: > On Sat, 30 Sep 2006 20:01:57 +0100, Thorsten Kampe <[EMAIL PROTECTED]> wrote: >> And the simple reason why Regular Expressions are not a part of the >> core Python language is that Regular Expressions are overrated. > > It seems to me they are currently /underrated/ in the Python community. Or, > I suspect, everybody disrespects them in public but secretly use them when > they're hacking ;-) When I used to program in Perl I used regex' for lots of stuff. In python I probably use them once every half year. I sinply do not need them. Max M -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating unique row ID ints.
"Simon Wittber" <[EMAIL PROTECTED]> writes: > Some of the tables require single integer primary keys which might be > exposed in some parts of the web interface. If users can guess the next > key in a sequence, it might be possible for them to 'game' or > manipulate the system in unexpected ways. I want to avoid this by > generating a random key for each row ID, and have decided to use the > same approach for all my single key tables. Normally primary keys are sequential but only live inside the system. Users are not supposed to enter them. > If the random module is suitable, does anyone have any good ideas on > how this could be implemented? The random module does not aim to be secure against knowledgeable attackers trying to guess the output (i.e. it's not cryptographic randomness). Use os.urandom instead. > I've got my own ideas for implementing this, but am interested to see > how/if anyone else has tackled the same problem. The simplest thing to do is generate random strings, e.g. key = os.urandom(16) for a 16-byte binary string. You can of course encode it as printing characters with your favorite binascii function. 16-byte strings like that should be unguessable and collision-free until you have an enormous number of them (on the order of 2**64). -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
charlie strauss wrote: > level0: newly created objects > level1: objects that survived 1 round of garbage collection > level2: objects that survivied 2+ rounds of gargbage collection > > Since all of my numerous objects are level2 objects, and none of > them are every deallocated, then I should never trip the GC for > these. your understanding of generational GC is a bit fuzzy, it seems. that an object is promoted to a higher level means that it's not inspected quite as often as lower-level objects, not that it's never inspected at all. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
charlie strauss wrote: > Could you clarify that for me. GC really has three components > two it: 1) finding and freeing unrefernced memory by refer > refer counts 2) cycle removal and 3) defragementing the > storage stack. If I turn off GC, don't I lose all of these? CPython always does (1), only does (2) if cycle-breaking GC isn't disabled, and never does (3). in your case, it's (2) that takes more and more time, simply because you're creating tons of non-trivial objects. to see what's going on in there, add import gc gc.set_debug(gc.DEBUG_STATS) to the top of your program, and look at the status messages that appear just before each "Big Gap" message. -- http://mail.python.org/mailman/listinfo/python-list
Generating unique row ID ints.
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can guess the next key in a sequence, it might be possible for them to 'game' or manipulate the system in unexpected ways. I want to avoid this by generating a random key for each row ID, and have decided to use the same approach for all my single key tables. Are there any best practices for implementing this? If the random module is suitable, does anyone have any good ideas on how this could be implemented? Some questions which came to mind are: Would I need to save and restore the random module state when generating id's for each table? What would be an appropriate seed? How many random integers can I generate before a repeat becomes probable? I've got my own ideas for implementing this, but am interested to see how/if anyone else has tackled the same problem. -Sw. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Steve, digging into the gc docs a bit more, I think the behaviour I am seeing is still not expected. Namely, the program I offered has no obvious place where objects are deallocated. The way GC is supposed to work is thate there are three levels of objects level0: newly created objects level1: objects that survived 1 round of garbage collection level2: objects that survivied 2+ rounds of gargbage collection Since all of my numerous objects are level2 objects, and none of them are every deallocated, then I should never trip the GC for these. Your explanation would require this to be tripped so I can't explain it. For your explanation to be correct then there as to be some non-obvious step in the program that is deallocating level2 items in sufficient numbers to trip the GC. -- http://mail.python.org/mailman/listinfo/python-list
Re: AN Intorduction to Tkinter
[EMAIL PROTECTED] wrote: > Sorry about that. > > As far as I can tell, its not anything to do with your code. I think > its something with tkinter modules. Sorry about misleading you. > > Thanks for the help, I'm sure you'll hear from me soon again. In > fact... Unless you post the following, no-one is able to help you : * Which examples you have a problem with * What code you actually ran (and how you ran it - inside IDLE, at the command line) * What went wrong, or the full traceback of the error For what it's worth, I've found the following resources useful for Tkinter : http://www.ferg.org/thinking_in_tkinter/index.html http://www.python.org/doc/life-preserver/ http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://tkinter.unpythonic.net/wiki/ http://www.3dartist.com/WP/python/tknotes.htm All the best, Fuzzyman http://www.voidspace.org.uk > > FlyingIsFun1217 -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
>> >I think the point you are missing is that the garbage collector is >triggered from time to time to ensure that no cyclical garbage remains >uncollected, IIRC. The more data that's been allocated, the longer it >takes the collector to scan all of memory to do its job. > >If you can find a way to avoid the behaviour I'm sure the development >team would be interested to hear it :-) > >I think you'll find that most programs that eat through memory in this >way will exhibit pretty much the same behaviour. If you *know* your >program isn't creating data cycles, just turn the GC off and rely on >reference counting. That won't save you from paging when you eventually >exhaust physical memory. Nothing can. Could you clarify that for me. GC really has three components two it: 1) finding and freeing unrefernced memory by refer counts 2) cycle removal and 3) defragementing the storage stack. If I turn off GC, don't I lose all of these? >From a user perspective, turning off GC and then managing it yourself is >unappealing. What would be preferrable would be to be able to simply turn >down it's threshold. That is, what I really want is to tell GC it can hold >off and checks other than reference counts until X% of the memory is filled. >At some point I want it to kick in, and I don't want to have to >programatically manage that, but simply specify a simple tolerance. Even better , I'd like to keep 1 and 3 and turn off just 2 and just use weak reference in the few cases I really need them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
charlie strauss wrote: > Steve and other good folks who replied: > > I want to clarify that, on my computer, the first instance of the gap occurs > way before the memory if filled. (at about 20% of physical ram). > Additionally the process monitor shows no page faults. > > Yes if you let the as-written demo program run to completetion (all 20,000 > iterations) then on many computers it would not be surprising that your > computer eventually goes into forced page swapping at some point. That would > be expected and is not the issue than the one I am concerned with. > > in my case starts glicthing at around iteration 1000. > > 1000(bars) x 100(foos)x(10 integers in array) > > is nominally > 100,000 class objects and > 1,000,000 array elements. > > (note that the array if filled as [1]*10, so there is actually only one > "integer", but 10 array elements refering to it, per foo class.) > > > However steve may have put his finger on the reason why the duration grows > with time. Here is my current hypothesis. The design of the program does > not have and points where significant amounts of memory are released: all > objects have held references till the end. But prehaps there are some > implicitly created objects of the same size created along the way??? For > example when I write > > me.memory = [1]*nfoo > > perhaps internally, python is allocating an array of size foo and then > __copying__ it into me.memory??? Since there is no reference to the > intermediate it would then marked for future garbage collection. > > If that were true then the memory would have interleaved entities of things > to GC and things with references held in me.memory. > > Then to remove these would require GC to scan the entire set of existing > objects, which is growing. > > Turning off GC would prevent this. > > > In any case I don't think what I'm doing is very unusual. The original > program that trigger my investigation of the bug was doing this: > > foo was an election ballot holding 10 outcomes, and bar was a set of 100 > ballots from 100 voting machines, and the total array was holding the ballot > sets from a few thousand voting machines. > > Almost any inventory program is likely to have such a simmilar set of nested > array, so it hardly seems unusual. > > > > > I think the point you are missing is that the garbage collector is triggered from time to time to ensure that no cyclical garbage remains uncollected, IIRC. The more data that's been allocated, the longer it takes the collector to scan all of memory to do its job. If you can find a way to avoid the behaviour I'm sure the development team would be interested to hear it :-) I think you'll find that most programs that eat through memory in this way will exhibit pretty much the same behaviour. If you *know* your program isn't creating data cycles, just turn the GC off and rely on reference counting. That won't save you from paging when you eventually exhaust physical memory. Nothing can. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
By the way if you are on a fast computer, and an OS whose time.time() function can resolve less than 0.5 seconds then you can see this problem on your machine at lower memory utilizations by changing the value of the default "allowed_gap" in the gtime class from 0.5 seconds down to say 0.1 second. This is the threshold for which the computer program flags the time it takes to create a "foo" object. on a fast computer it should take much less than 0.1 sec. -Original Message- >From: charlie strauss <[EMAIL PROTECTED]> >Sent: Oct 1, 2006 10:33 AM >To: Steve Holden <[EMAIL PROTECTED]>, python-list@python.org >Subject: Re: Is this a bug? Python intermittently stops dead for seconds > >Steve and other good folks who replied: > >I want to clarify that, on my computer, the first instance of the gap occurs >way before the memory if filled. (at about 20% of physical ram). Additionally >the process monitor shows no page faults. > > Yes if you let the as-written demo program run to completetion (all 20,000 > iterations) then on many computers it would not be surprising that your > computer eventually goes into forced page swapping at some point. That would > be expected and is not the issue than the one I am concerned with. > >in my case starts glicthing at around iteration 1000. > >1000(bars) x 100(foos)x(10 integers in array) > >is nominally >100,000 class objects and >1,000,000 array elements. > >(note that the array if filled as [1]*10, so there is actually only one >"integer", but 10 array elements refering to it, per foo class.) > > >However steve may have put his finger on the reason why the duration grows >with time. Here is my current hypothesis. The design of the program does not >have and points where significant amounts of memory are released: all objects >have held references till the end. But prehaps there are some implicitly >created objects of the same size created along the way??? For example when I >write > >me.memory = [1]*nfoo > >perhaps internally, python is allocating an array of size foo and then >__copying__ it into me.memory??? Since there is no reference to the >intermediate it would then marked for future garbage collection. > >If that were true then the memory would have interleaved entities of things to >GC and things with references held in me.memory. > >Then to remove these would require GC to scan the entire set of existing >objects, which is growing. > >Turning off GC would prevent this. > > >In any case I don't think what I'm doing is very unusual. The original >program that trigger my investigation of the bug was doing this: > >foo was an election ballot holding 10 outcomes, and bar was a set of 100 >ballots from 100 voting machines, and the total array was holding the ballot >sets from a few thousand voting machines. > >Almost any inventory program is likely to have such a simmilar set of nested >array, so it hardly seems unusual. > > > > > >-- >http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
[ANN] InformixDB-2.3 released
I am pleased to announce a new release of InformixDB, the DB-API 2.0 module for connecting to IBM Informix database engines. Changes since version 2.2: - Allow parameter list for executemany() to be arbitrary iterable objects. - .prepare() method and .command attribute for explicitly prepared statements - Python 2.5 compatibility - Bug fixes: * Rare crashes caused by missing error check in DESCRIBE step. * Inconsistent UDT input binding caused SQLCODE -1820 in bulk insert (executemany) if UDT contents went back and forth across 32K size boundary or between null and non-null. * EXECUTE PROCEDURE erroneously attempted to open a results cursor for procedures that don't return results. * Date columns were read incorrectly on 64 bit platforms due to mixup of int4 versus long. Downloads and info at http://informixdb.sourceforge.net Best regards, Carsten Haese -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Steve and other good folks who replied: I want to clarify that, on my computer, the first instance of the gap occurs way before the memory if filled. (at about 20% of physical ram). Additionally the process monitor shows no page faults. Yes if you let the as-written demo program run to completetion (all 20,000 iterations) then on many computers it would not be surprising that your computer eventually goes into forced page swapping at some point. That would be expected and is not the issue than the one I am concerned with. in my case starts glicthing at around iteration 1000. 1000(bars) x 100(foos)x(10 integers in array) is nominally 100,000 class objects and 1,000,000 array elements. (note that the array if filled as [1]*10, so there is actually only one "integer", but 10 array elements refering to it, per foo class.) However steve may have put his finger on the reason why the duration grows with time. Here is my current hypothesis. The design of the program does not have and points where significant amounts of memory are released: all objects have held references till the end. But prehaps there are some implicitly created objects of the same size created along the way??? For example when I write me.memory = [1]*nfoo perhaps internally, python is allocating an array of size foo and then __copying__ it into me.memory??? Since there is no reference to the intermediate it would then marked for future garbage collection. If that were true then the memory would have interleaved entities of things to GC and things with references held in me.memory. Then to remove these would require GC to scan the entire set of existing objects, which is growing. Turning off GC would prevent this. In any case I don't think what I'm doing is very unusual. The original program that trigger my investigation of the bug was doing this: foo was an election ballot holding 10 outcomes, and bar was a set of 100 ballots from 100 voting machines, and the total array was holding the ballot sets from a few thousand voting machines. Almost any inventory program is likely to have such a simmilar set of nested array, so it hardly seems unusual. -- http://mail.python.org/mailman/listinfo/python-list
SHTOOM
Hello, I am a new shtoom user,but I have one problem.I was download last shtoom source and when I write example: >>> from shtoom.app.phone import Phone Traceback (most recent call last): File "", line 1, in -toplevel- from shtoom.app.phone import Phone ImportError: No module named app.phone ..I think I need file app.py,where to I find that file??? If you have that file please send me: [EMAIL PROTECTED] THANKS -- http://mail.python.org/mailman/listinfo/python-list
Re: windev vs python SOS
Wolfgang Keller wrote: >>Links abour Windev for those who like facts : >> >>http://www.windev.com/pcsoft/testimonials/index.html >>http://www.pcsoft.fr/annonce10/photos.html >>http://www.pcsoft.fr/pcsoft/120pages/index.html > > > Well, it _could_ be that all the readers in comp.lang.python are utterly > braindead morons with entirely dysfunctional sense organs so that they can't > distinguish between 100% subject-matter-free sales promotion cheaptalk and > objective information about "facts" from independent and competent third > parties. > > It _could_ be. > > Anyway, if I were "PDG" of PC Soft, I would immediately fire their > advertising staff - judging from the "content" of those "facts" they're > totally incapable to produce anything that would actually convince anyone > with an IQ higher than that of an average housefly. > > EOD. > Fortunately, or unfortunately, depending how you look at it, there are plenty of people who can be convinced to buy software based on completely specious "arguments" and "facts". It's well known that to succeed in business you need superior marketing first: superior technology isn't even on the list of essentials, though as Google clearly demonstrates it can help a lot when used by intelligent people. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: PATCH: Speed up direct string concatenation by 20+%!
Congratulations on the clear way in which you have set out your proposal. I hope that it will make its way to PEPdom. Colin W. Larry Hastings wrote: > This is such a long posting that I've broken it out into sections. > Note that while developing this patch I discovered a Subtle Bug > in CPython, which I have discussed in its own section below. > > > THE OVERVIEW > > I don't remember where I picked it up, but I remember reading years > ago that the simple, obvious Python approach for string concatenation: > x = "a" + "b" > is slow. Obviously it's fine for the simple case above, but if you're > adding together twenty-five things: > x = a + b + c + d + ... + y > the performance is terrible, as the interpreter creates temporary > objects > for each intermediate result. (a + b, then (a + b) + c, > then ((a + b) + c) + d, and so on.) > > The suggested idiom for fast string concatenation was this: > x = "".join([a, b, c, d, ... y]) > This works fine. But I don't like this approach, not only because it's > kind of ugly and inobvious, but because it violates the "one obvious > way > to do it" principle. > > I mentioned all this to a friend of mine (Mike Thornburgh), and told > him matter-of-factly that I'd like to fix this, but the design of > Python > simply precluded it. He said "no it doesn't!" and proceeded to > describe > in great detail an approach to permit fast string concatenation using > +. > I have implemented what he suggested--with only slight changes--and > present it to you below. I only had to touch four files, and only did > major surgery on one. The resulting Python passes the test suite as > well > as my unmodified locally-built Python 2.5. (I didn't install the > external > source trees for stuff like SQLite, so it fails those tests.) > > Note that times have changed; using Python 2.5, a + b + c isn't *that* > much slower than "".join([]). But is is still slower. Or, was--with > my > patch, a + b + c becomes *the fastest method* for string concatenation. > Hooray! > > (It didn't pay off as *much* as I'd hoped, but it's still an > improvement.) > > _ > THE PATCH > > The core concept: adding two strings together no longer returns a pure > "string" object. Instead, it returns a "string concatenation" object > which holds references to the two strings but does not actually > concatenate > them... yet. The strings are concatenated only when someone requests > the > string's value, at which point it allocates all the space it needs and > renders the concatenated string all at once. > > More to the point, if you add multiple strings together (a + b + c), > it *doesn't* compute the intermediate strings (a + b). > > Upsides to this approach: > > * String concatenation using + is now the fastest way to > concatenate > strings (that I know of). > > * Throw off the shackles of "".join([]), you don't need it > anymore. > > * Did I mention it was faster? > > Downsides to this approach: > > * Changes how PyStringObjects are stored internally; ob_sval is > no > longer a char[1], but a char *. This makes each StringObject > four bytes larger. > > * Adds another memory dereference in order to get the value of > a string, which is a teensy-weensy slowdown. > > * Would force a recompile of all C modules that deal directly > with string objects (which I imagine is most of them). > > * Also, *requires* that C modules use the PyString_AS_STRING() > macro, rather than casting the object and grabbing ob_sval > directly. (I was pleased to see that the Python source > was very good about using this macro; if all Python C > modules are this well-behaved, this point is happily moot.) > > * On a related note, the file Mac/Modules/MacOS.c implies > that there are Mac-specific Python scripts that peer > directly into string objects. These would have to be > changed to understand the new semantics. > > * String concatenation objects are 36 bytes larger than > string objects, and this space will often go unreclaimed > after the string is rendered. > > * When rendered, string concatenation objects storing long > strings will allocate a second buffer from the heap to > store the string. So this adds some minor allocation > overhead (though this is offset by the speed gain from > the approach overall). > > * Will definitely need some heavy review before it could > go in, in particular I worry I got the semantics surrounding > "interned" strings wrong. > > > Internally, a "string concatenation" object is the same as a "string" > object with two extra fields: an array of references to string objects > (and string concatenation objects), and a count. Also, ob_ssta
Re: AN Intorduction to Tkinter
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > >>As far as I can tell, its not anything to do with your code. I think >>its something with tkinter modules. > > > as in ? > > you've posted five posts to this thread, but you still haven't provided > us with more clues than "I noticed they didn't work" and "I think it's > something with some module". don't you think it would be easier to help > you if you actually explained what you did, what you expected to happen, > and what happened instead ? > > > Can the effbot really have been taken in by a troll? Or does the troll not realise it's a troll? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
charlie strauss wrote: Below is a simple program that will cause python to intermittently stop executing for a few seconds. it's 100% reproducible on my machine. I'd be tempted to say this is a nasty garbage collection performance issue except that there is no major memory to be garbage collected in this script. I'd be tempted to say it was a unix virtual memory issue except this is occuring at around 1/5th of my physical memory size. So something else unexplained is going on Class Foo instances create and hold a list of size nfoo of integers. (nfoo =10) Class Bar instances create and hold a list of size nbar of Foo objects. (nbar =100) When the code runs it starts creating and storing Bar objects in a list while watching for real-time glitches in how long it takes to create the next Foo object. If this is longer than 1/2 of a second then it reports it. On my computer after creating 1500 Bar objects, the rate of creation of new Foo suddenly has a periodic glitch. This glitch re- occurs about every 300 Bar Objects, and the duration of the glitch keeps getting longer--growing to many seconds Platform: 800Mhz powermac g 4 1Gb of memory python: python 2.4.2 Note: since I an using absolute time threshold for reporting the glitches, the first one may take more iterations before it occurs on a fast computer. You may need to increase nbar or nfoo. import sys from time import time class Foo(object): def __init__(me,nfoo): me.memory = [1]*nfoo class Bar(object): def __init__(me,nbar,nfoo): tgx.set_tag("Bar") # timer b = [None]*nbar for i in xrange(nbar): b[i]=Foo(nfoo) # make a foo, add it to list tgx.jump("Bar"+`i`) #timer me.b = b #store the list in my instance memory # just a utility class to time things. class gtime: def __init__(me,f=sys.stderr): me.last = time() me.f=f me.tag = "" me.ticks = 0 def set_tag(me,tag): me.tag = tag me.ticks = 0 def reset(me): me.ticks = 0 def jump(me,tag="NONE",allowed_gap=0.5): me.t = time() me.ticks +=1 if me.t-me.last>allowed_gap: print >>me.f,"Big Gap:",me.t-me.last,"seconds ",me.tag,tag,me.ticks me.last = time() tgx = gtime() # instance of the timer # main loop nbar = 100 nfoo = 10 ad_nauseum = 2 final = [None]*ad_nauseum for i in xrange(ad_nauseum ): if i%100 == 0 :print >>sys.stderr,"Bars Made: ",i final[i] = Bar(nbar,nfoo) I'm not the Timbot, but the behaviour of the program seems reasonably comprehensible to me. You create a list of 20,000 elements and proceed to populate it with Bar objects, each of which contains a thousand-element list pointing to a ten-element list. So despite the fact that all list elements are (references to) the integer 1, there are a lot of references, which take up a lot of memory. Each time you report on the number of Bars you've created 100,000 references to 1. So it's hardly surprising that at some point the garbage collector cuts in and starts looking for free memory, which takes a certain amount of time. It's also unsurprising that the garbage collector takes longer the more stuff you have in memory, because it has to sweep all those structures to make sure that there aren't any collectible cycles. As I run the program I see virtual memory usage climbing steadily - hardly surprising given the nature of the program. At some point the working set of the program is going to exceed the amount of physical memory that the operating system can allocate it. At that point paging will start to occur, and garbage collection (which has to access more or less all of memory) is now triggering disk activity, making it slower by a significant margin. This didn't happen on my machine with your initial settings as I have plenty of memory, but when I increased the foo size to 100, by the time I'd allocated 13,000 bars I was seeing big big gaps and little big gaps, the big ones apparently being required by the need to page something else out to allocate additional space for the task: Bars Made: 12900 Big Gap: 3.78899979591 seconds Bar Bar95 96 Bars Made: 13000 Big Gap: 0.50027521 seconds Bar Bar89 90 Bars Made: 13100 Bars Made: 13200 Big Gap: 3.7234959 seconds Bar Bar65 66 Bars Made: 13300 Big Gap: 0.50027521 seconds Bar Bar72 73 Bars Made: 13400 Bars Made: 13500 Big Gap: 3.83699989319 seconds Bar Bar35 36 Bars Made: 13600 Bars Made: 13700 Big Gap: 0.50027521 seconds Bar Bar65 66 Bars Made: 13800 Big Gap: 3.90399980545 seconds Bar Bar4 5 Bars Made: 13900 Bars Made: 14000 Bars Made: 14100 Big Gap: 3.95200014114 seconds Bar Bar75 76 Bars Made: 14200 Big Gap: 0.50027521 seconds Bar Bar38 39 Bars Made: 14300 I trust readers will excuse me for attaching a small PNG graphic that clearly show
Re: "Wiki in 10 minutes"
Michiel Sikma <[EMAIL PROTECTED]> wrote: > lost my bookmarks. I once bookmarked this video tutorial which > allegedly showed how to make a wiki in 10 minutes with some Python > network framework. Does anybody know which one it might have been? If you add another ten minutes, this would be http://www.turbogears.org/ Cheers, --Jan Niklas -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin regular expressions?
Steve Holden wrote: > Fine. Just because you fail to see the benefit, however, that doesn't > mean there isn't one. the real reason is of course, as Richard Feynman famously observed, that in Python, "everything is made of objects". -- http://mail.python.org/mailman/listinfo/python-list
Re: does anybody earn a living programming in python?
Alex Martelli wrote: > Magnus Lycka <[EMAIL PROTECTED]> wrote: >... > > stuff in the world, so my standard extrapolation technique would yield > > 3 python programmers globally. > > I think this estimate is low, based on three piece of data I know (but, > sorry, are all confidential;-) and thus one I can infer: > -- I know how many copies of "Python in a Nutshell" Google buys; > -- I know how many Python programmers work at Google; > -- I know how many copies the Nutshell sells worldwide; > > Assuming the willingness to buy "Python in a Nutshell" is constant > across the population of Python programmers (and I don't believe my > working there influences anything -- Google had the Nutshell in the > standard set of books engineers use, well before I got hired there), I > can project a worldwide number of Python programmers that's several > times higher than that. > > Or perhaps not, depending on the definition of "Python programmer". > Most of Google's software developers who know Python also know one or > more (generally several) of C, C++, Java, SQL, HTML, Javascript, &c, > though they may or may not use any one or more of them often on the job; > many Googlers who program only in Python do not _just_ program -- they > are also working on other jobs besides software development (hardware > design, testing, management, administrative assistance, system > administration, network operations, whatever...). Hey, by a > sufficiently strict definition _I_ don't count as a "Python programmer", > since I also do substantial amounts of management, not to mention a > little bit of C++, some C, SQL, HTML, and so forth...;-) > > > Alex A few points: Personnally, I've never heard_of a Python_only programmer... When I chose Python for web dev programming class, no one knew why I was using a (second_rate) handy-crafty language, instead of ASP-PHP_whateverP language that was in the mainstream. Because of academic freedom, I was allowed to show it as a *different* type of language. Most mainstream job boards here in Montreal had never posted ANY (not that I could find) jobs (5 years ago) NONE so it went that it Python would just be a *educational* add-on for the students. Since then, feedback from students in industry is that it is being used more and more, day in and day out by top world class shops (games, effects, etc). BUT It's still Java, C++, PHP, SQL that have the marketing demands... Finally, also (personnal interpretation) because of the BUG2000 Scare, shops had boosted the staff with just about anyone they could get there hands on prior to this event, with the son, mom and great-grand uncle who could do a database of contacts in MSAccess (and this is NOT demeaning MSAccess), so now companies are NOT posting for the jobs in this *language* oriented fashion outside the mainstream (Java, C++,etc). Finally, most programmers and programmers-wannabe-students just don't hope to be top-tier in their trade - They just want a job, so they can marry, play, pay rent, go home - Sorry, most are not interested in technology, and since most managers I have seen, in a 15 year career in dev before taking a teaching job, don't CARE about technology, you have a perfect match for Java, PHP advertisement... My two cents, rooting for Python (and Ruby and Lua and OCaml, and ... you get the point!) Jean-Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin regular expressions?
Antoine De Groote wrote: > Hello, > > Can anybody tell me the reason(s) why regular expressions are not built > into Python like it is the case with Ruby and I believe Perl? Like for > example in the following Ruby code > > line = 'some string' > > case line >when /title=(.*)/ > puts "Title is #$1" >when /track=(.*)/ > puts "Track is #$1" >when /artist=(.*)/ > puts "Artist is #$1" > end > > I'm sure there are good reasons, but I just don't see them. > I'd say that Ruby took a lot of its early design clues from Perl. If you want to attract Perl programmers then they expect such things. Python has an emphasis on clarity/readability and on maintainability. It has other string methods that are much easier to read and maintain than regular expressions. There is of course a class of problem well suited to regular expressions but it is easy for people coming to Python from Perl or AWK to rely too heavily on RE's. Personally, my problem with REs is that their is inadequate debug capabilites for them. The best way I have found is to shove some example text into Kodos and incrementally refine my RE by viewing the RE's results on the example text. RE's also tend to look like line noise, even when you use the x switch and use whitesspace+comments. > Python Culture says: 'Explicit is better than implicit'. May it be > related to this? Well, by putting RE's into the language I presume you also mean doing the equivalent of setting group variables? That would be a 'magic' side effect unless you explicitly assigned them, e.g: person, craving = r"My\s(\S+)likes\s(\S+)" ~~ text # using ~~ for an RE match operator The more readable I try and make it though, the more I appreciate the Python way of doing things. - Pad. -- http://mail.python.org/mailman/listinfo/python-list
Re: question about scope
John Salerno wrote: > Steve Holden wrote: > > >>The methods do indeed look in their enclosing class, but only for >>self-relative references. These are sought first in the instance, then >>in the instance's class, then in the instance's class's superclass, and >>so on up to the ultimate superclass. In other words, all attribute >>lookup uses the method resolution order ... > > > So what I did is correct? It does work, but why don't I have to define > the list as self.menu_items as well? The first point is that the name "self" isn't in scope at the point you make the assignment: it's a local variable (strictly, it's a parameter, but they are treated the same as locals) to each method, and when the method is called it's a reference to the specific instance whose method was called (technically, the instance o which the method is bound). You could assign self.menu_items in the __init__() method, but it wouldn't really have any advantages given that names in class scope are reachable via the name resolution mechanism. Note that the def statement is also executed in class scope, which is why the method names are class-relative. Python has a special method binding feature that changes a call like instance.method(a1, a2) into (instance.__class__).method(instance, a1, a2) This is where the reference to self "magically" appears from in method calls. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me use my Dual Core CPU!
Paul Rubin wrote: > Michael <[EMAIL PROTECTED]> writes: >> > But ordinary programmers write real-world applications with shared data >> > all the time, namely database apps. >> >> I don't call that shared data because access to the shared data is >> arbitrated by a third party - namely the database. I mean where 2 or >> more people[*] hold a lock on an object and share it - specifically >> the kind of thing you reference above as turning into a mess. > > Ehhh, I don't see a big difference between having the shared data > arbitrated by an external process with cumbersome message passing, > or having it arbitrated by an in-process subroutine or even by support > built into the language. If you can go for that, I think we agree on > most other points. The difference from my perspective is that there are two (not mutually exclusive) options: A Have something arbitrate access and provide useful abstractions designed to simplify things for the user. B Use a lower level abstraction (eg built into the language, direct calling etc) I don't see these as mutually exclusive, except the former is aimed at helping the programmer, whereas the latter can be aimed at better performance. In which case you're back to the same sort of argument regarding assembler, compiled or dymanic languages are a good idea, and I'd always respond with "depends on the problem in hand". As for why you don't see much difference I can see why you think that, but I personally believe that with A) you can shared best practice [1], whereas B) means you need to be able to implement best practice. [1] Which is always an opinion :) (after all, once upon a time people thought goto was a good idea :) >> > This is just silly, and wasteful of the >> > efforts of the hardworking chip designers > >> Aside from the fact it's enabled millions of programmers to deal with >> shared data by communicating with a database? > > Well, sure, but like spreadsheets, its usefulness is that it lets > people get non-computationally-demanding tasks (of which there are a > lot) done with relatively little effort. More demanding tasks aren't > so well served by spreadsheets, and lots of them are using databases > running on massively powerful and expensive computers when they could > get by with lighter weight communications mechanisms and thereby get > the needed performance from much cheaper hardware. That in turn would > let normal folks run applications that are right now only feasible for > relatively complex businesses. If you want, I can go into why this is > important far beyond the nerdy realm of software geekery. I'd personally be interested to hear why you think that. I can think of reasons myself, but would be curious to hear yours. >> For generator based components we collapse inboxes into outboxes >> which means all that's happening when someone puts a piece of data >> into an outbox, they're simply saying "I'm no longer going to use >> this", and the recipient can use it straight away. > > But either you're copying stuff between processes, or you're running > in-process without multiprocessor concurrency, right? For generator components, that's in-process and not multiprocessor concurrency, yes. For threaded components we use Queue.Queues, which means essentially the reference is copied for most real world data, not the data itself. One step at a time I suppose really :-) One option for interprocess sharing we're considering (since POSH looks unsupported, alpha, and untested on recent pythons), is to use memory mapped files. Thing is that means serialising everything which could be icky, so it'll have to be something we come back to later. (Much of our day to day work on Kamaelia is focussed on solving specific problems for work which rolls back into fleshing out the toolkit. It would be extremely nice to spend time on solving a particular issue that would benefit from optimising interprocess comms). If we can make kamaelia benefit from the work the hardware people have done for shared memory, that's great. However it's interesting to see things like the CELL don't tend to use shared memory, and use this style of communications approach. What approach will be most useful going forward? Dunno :-) I'm only claiming we find it useful :) >> This is traditional-lock free, > >> > Lately I've been reading about "software transactional memory" (STM), > >> I've been hearing about it as well, but not digged into it >> If you do dig out those STM references, I'd be interested :-) > > They're in the post you responded to: Sorry, brain fart on my part. Thanks :-) Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: windev vs python SOS
> Links abour Windev for those who like facts : > > http://www.windev.com/pcsoft/testimonials/index.html > http://www.pcsoft.fr/annonce10/photos.html > http://www.pcsoft.fr/pcsoft/120pages/index.html Well, it _could_ be that all the readers in comp.lang.python are utterly braindead morons with entirely dysfunctional sense organs so that they can't distinguish between 100% subject-matter-free sales promotion cheaptalk and objective information about "facts" from independent and competent third parties. It _could_ be. Anyway, if I were "PDG" of PC Soft, I would immediately fire their advertising staff - judging from the "content" of those "facts" they're totally incapable to produce anything that would actually convince anyone with an IQ higher than that of an average housefly. EOD. -- My email-address is correct. Do NOT remove ".nospam" to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin regular expressions?
Jorgen Grahn: > However, there is a set of common problems which would be hell to solve > without regexes. I agree, and I think no one is thinking about dropping REs from Python stdlib. Here people are mostly talking about what's better between having them in the stdlibs instead of inside the core language, and about their syntax. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/UNO/OpenOffice?
John Machin enlightened us with: > Hi, Sybren. I tried folloing your recipe on Windows with OOo 2.0 ... > > Minor problem: the executable is called soffice, not ooffice. > > Major problem: it crashed right at the start, somewhere in the maze > of dlls. That's not nice. > Has anyone managed to get further than this on Windows (XP Pro, SP > 2)? Not me - I'm not using Windows. If anyone knows more about this, please post here or post a comment at http://www.stuvel.eu/archive/31/article-about-openofficeorg-and-python so that I can improve the article. Sybren -- Sybren Stüvel Stüvel IT - http://www.stuvel.eu/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me use my Dual Core CPU!
Michael <[EMAIL PROTECTED]> writes: > > But ordinary programmers write real-world applications with shared data > > all the time, namely database apps. > > I don't call that shared data because access to the shared data is > arbitrated by a third party - namely the database. I mean where 2 or > more people[*] hold a lock on an object and share it - specifically > the kind of thing you reference above as turning into a mess. Ehhh, I don't see a big difference between having the shared data arbitrated by an external process with cumbersome message passing, or having it arbitrated by an in-process subroutine or even by support built into the language. If you can go for that, I think we agree on most other points. > > This is just silly, and wasteful of the > > efforts of the hardworking chip designers > Aside from the fact it's enabled millions of programmers to deal with > shared data by communicating with a database? Well, sure, but like spreadsheets, its usefulness is that it lets people get non-computationally-demanding tasks (of which there are a lot) done with relatively little effort. More demanding tasks aren't so well served by spreadsheets, and lots of them are using databases running on massively powerful and expensive computers when they could get by with lighter weight communications mechanisms and thereby get the needed performance from much cheaper hardware. That in turn would let normal folks run applications that are right now only feasible for relatively complex businesses. If you want, I can go into why this is important far beyond the nerdy realm of software geekery. > For generator based components we collapse inboxes into outboxes > which means all that's happening when someone puts a piece of data > into an outbox, they're simply saying "I'm no longer going to use > this", and the recipient can use it straight away. But either you're copying stuff between processes, or you're running in-process without multiprocessor concurrency, right? > This is traditional-lock free, > > Lately I've been reading about "software transactional memory" (STM), > I've been hearing about it as well, but not digged into it > If you do dig out those STM references, I'd be interested :-) They're in the post you responded to: http://lambda-the-ultimate.org/node/463 http://research.microsoft.com/users/simonpj/papers/stm/ In particular, the one about the GHCI implementation is here: http://research.microsoft.com/users/simonpj/papers/stm/lock-free-flops06.pdf The Wikipedia article is also informative: http://en.wikipedia.org/wiki/Transactional_memory -- http://mail.python.org/mailman/listinfo/python-list
[ANNOUNCE] Kamaelia 0.5.0 Released - now enhanced by Summer of Code :-)
Hi! Kamaelia 0.5.0 marks a major stepping point for the Kamaelia project. It means we officially have coverage over almost all the core areas we want in version 1.0, with some substantial and useful subsystems in the form of network delivery (tcp, udp, multicast servers), and interactive capabilties (tk, pygame, opengl integration), and video (eg Freeview, DVB-T, Dirac) along with a visual tool for bolting these systems together visually, whilst making it more /natural/ to work with concurrency. It also marks the first release where the number of external contributors to the release outweighs developers from inside the BBC, meaning this release really does belong to the Google Summer of Code students who also worked on it. They've done some really cool interesting stuff, and that's really the focus of this release, and written their own announcement, so in Ryan's words from his blog, (http://tinyurl.com/o9te3): """ Kamaelia 0.5.0 Released! Kamaelia is an intuitive way to structure applications -- essentially as a network of components which talk to each other. This model gives natural concurrency (each component can run separately) and makes building software very visual. It's an open-source BBC Research project, originally designed for rapid development of server software. If you've used Unix pipes, Kamaelia is like those implemented in Python. If you want to know more about the theory read the one-page introduction [2] on the Kamaelia website. [2] http://kamaelia.sourceforge.net/Introduction.html Here's a taster of what a Kamaelia application looks like: (built with the GUI) [ Screenshot: http://photos1.blogger.com/blogger2/7070/3507/1600/composer-filedownloader.png ] And here's some equivalent Python code: Pipeline( ConsoleReader(eol=""), SimpleHTTPClient(), SimpleFileWriter("downloadedfile.txt"), ).run() Those 5 lines of Python give you a console-based HTTP downloading program (like wget or curl but with less options) using existing components. The ConsoleReader sends lines of text (URLs) the user enters to the HTTP client, which fetches the associated page. It then forwards on its contents to the file writer. It's as simple as that. You can also write your own components from scratch and use them with the existing ones. Version 0.5.0 is a major release - lots of functionality has been added from Google Summer of Code 2006. Key highlights of this release: * BitTorrent support (using the official BitTorrent client) - includes preliminary 'streaming over BitTorrent' support, can be used as a P2P backend in your own Kamaelia applications. [ screenshot in blog entry ] * HTTP client and nascent seaside-style pure-python webserver * OpenGL (e.g. the checkers/draughts board on the right) http://photos1.blogger.com/blogger2/7070/3507/400/thfcheckers.0.png {{{ http://kamaelia.sourceforge.net/t/Dirac3D.png }}} * Strong DVB (freeview TV) support on Linux - including the foundations of a PVR. {{{cf http://kamaelia.sourceforge.net/KamaeliaMacro.html}}} * Collaborative whiteboarding with audio (speex encoded) - draw and talk together over the internet. {{{To be featured in next month's Linux Format}}} * Enhanced visual composition of Kamaelia systems - create and link components on screen, see the code produced (the screenshot near the top of the article) For more information see the Kamaelia[3] website. You can get a copy of Kamaelia and Axon from Sourceforge, together with most of the dependencies[4] in the mega bundle. If you have any problems or questions, just pop along to #kamaelia on irc.freenode.net. [3] http://kamaelia.sourceforge.net/Home [4] http://sourceforge.net/project/showfiles.php?group_id=122494&package_id=183774&release_id=451251Hi! Kamaelia 0.5.0 marks a major stepping point for the Kamaelia project. It means we officially have coverage over almost all the core areas we want in version 1.0, with some substantial and useful subsystems in the form of network delivery (tcp, udp, multicast servers), and interactive capabilties (tk, pygame, opengl integration), and video (eg Freeview, DVB-T, Dirac) along with a visual tool for bolting these systems together visually, whilst making it more /natural/ to work with concurrency. This release is massively enhanced by the work produced by Google Summmer of Code students who worked with us over the summer. They've done some really cool interesting stuff, and that's really the focus of this release, and written their own announcement, so in Ryan's words from his blog, (http://tinyurl.com/o9te3): """ Kamaelia 0.5.0 Released! Kamaelia is an intuitive way to structure applications -- essentially as a network of components which talk to each other. This model gives natural concurrency (each component can run separately) and makes building software very visual. It's an open-source BBC Research project, originally designed for rapid development of s
Re: builtin regular expressions?
Mirco Wahab wrote: > Therefore, I'd like to have a usable and understandable > example of Regex-object juggling, that shows clearly > what its real benefit is (or gives an idea of - ). Here are some benefits: DRY - You can assign a regexp to a variable and pass it around or call specific instance methods on it. Thus... Overhead - You don't need to keep compiling the same expression if you need to use it several times, you can just assign it to a variable and reference that. Clarity - named methods are clearer than operators. ( .match vs. =~ ). Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python world tries to be polite [formerly offensive to another language]
Thus spoke A.M. Kuchling (on 2006-09-30 19:26): > On Sat, 30 Sep 2006 09:10:14 +0100, > Steve Holden <[EMAIL PROTECTED]> wrote: >> My God, Perl 6 is going to be even less comprehensible that Perl 5, >> which was at least usable. Is »=>« really a Perl6 operator? That's too >> funny! > > While we poor Python people have to cope with writing: > d = dict(zip(k, v)) > instead of Perl 6's > %h = @k >>=><< @v; > > But at least the Perl solution is 4 non-whitespace characters shorter... Didn't I get the joke? The Perl version would be a hash slice initialization on %dict: @dict{ @k } = @v; Thats it. What is the fuzz all about? I consider 'hyper fatarrow' (you did't the »=>« get right) just a joke of LW (he does so sometimes ;-). Regards Mirco -- http://mail.python.org/mailman/listinfo/python-list
Re: why logging re-raise my exception and can't be caught?
Steve Holden <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > [...] > > A 'try ... except' statement is not an exception handler. [...] > > Just as a matter of interest, what would your definition of an > exception handler be, then? Specifically, what's the "except" clause > for? It seems my understanding was wrong. The 'except' clause *is* an exception handler. (I was thinking that the "default exception handler" was the only thing that could be called an "exception handler".) It's explained better here: http://docs.python.org/ref/try.html> > The docs for looging.except should make it explicit that the > exception will be re-raised. Yes, I agree; it wasn't very clear on reading the description of 'logging.exception()' what would actually happen. > Of course it might be possible to do something hackish like > > try: > ... > except: > try: > logging.exception(...) > except: > pass > > which (although untested) should theoretically allow the catching > (for a second time) of teh exception reraised by > logging.exception(). It does seem rather a side effect, and an unexpected (and undocumented) one at that. -- \"If it ain't bust don't fix it is a very sound principle and | `\ remains so despite the fact that I have slavishly ignored it | _o__) all my life." -- Douglas Adams | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin regular expressions?
Thus spoke Steve Holden (on 2006-09-30 23:58): > Mirco Wahab wrote: >> Thus spoke MRAB (on 2006-09-30 20:54): >>>One of the differences between the Python way and the Perl way is that >>>the Perl way has a side-effect: ... >> I fail to see the benefit of a re-object, I consider these to >> be just there because regexes aren't in the core language. >> > Fine. Just because you fail to see the benefit, however, that doesn't > mean there isn't one. Maybe we just aren't explaining it in terms you > can appreciate? OK, maybe my communication style is bad or somehow 'Perl newsgroup-hardened' ;-) Of course, I'd like to really understand these things (as they were intended), probably modifying my look onto programming concepts then. Therefore, I'd like to have a usable and understandable example of Regex-object juggling, that shows clearly what its real benefit is (or gives an idea of - ). Afterwards, I'll surely try to deconstruct your assumptions hidden there in order to *get a better understanding* for myself ;-) Regards and thanks Mirco -- http://mail.python.org/mailman/listinfo/python-list
Re: Escapeism
Hendrik van Rooyen wrote: > dumb question - is the backslash as escape character fixed yes. > seems to me that would help help with what? > or if you could turn the behaviour off - don't know how though... eh? if you don't want to use repr(), you don't have to. -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin regular expressions?
Antoine De Groote wrote: > Hello, > > Can anybody tell me the reason(s) why regular expressions are not built > into Python like it is the case with Ruby and I believe Perl? Like for > example in the following Ruby code > > line = 'some string' > > case line >when /title=(.*)/ > puts "Title is #$1" >when /track=(.*)/ > puts "Track is #$1" >when /artist=(.*)/ > puts "Artist is #$1" > end > > I'm sure there are good reasons, but I just don't see them. > > Python Culture says: 'Explicit is better than implicit'. May it be > related to this? > > Regards, > antoine I notice two issues here. Only one has anything to do with regular expressions. The other one with 'explicit is better than implicit': the many implicit passing operations of Rubys case statement. Using pseudo-Python notation this could be refactored into a more explicit and not far less concise style: if line.match( "title=(.*)" ) as m: print "Title is %s"%m.group(1) elif line.match( "track=(.*)" ) as m: print "Track is %s"%m.group(1) elif line.match( "artist=(.*)" ) as m: print "Artist is %s"%m.group(1) Here the result of the test line.match( ) is assigned to the local variable m if bool(line.match( )) == True. Later m can be used in the subsequent block. Moreover match becomes a string method. No need for extra importing re and applying re.compile(). Both can be done in str.match() if necessary. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: the actual C code - Re: Scoping bugs in an embedded Python interpreter - Wizards please
FOUND IT! http://mail.python.org/pipermail/python-list/1999-June/005833.html So I'm supposed to only have ONE dictionary, 'glb', and forget the 'loc' for locals. Just call PyRun(...glb,glb) Seeing as this was a topic of discussion 7 years ago, maybe it ought to be in the "extending and embedding" manual ... well thanks everyone who read this. -- http://mail.python.org/mailman/listinfo/python-list