Re: what is the keyword "is" for?
"Dan Bishop" <[EMAIL PROTECTED]> wrote: | Sybren Stuvel wrote [on the difference between is and ==]: | > Obviously "a is b" implies "a == b", | | Not necessarily. | | >>> a = b = 1e1000 / 1e1000 | >>> a is b | True | >>> a == b | False Huh? - wtf is this - I find this deeply disturbing - Sybren's explanation kind of was congruent with my own understanding, and this is just weird - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Small Troll on notation of variables over time
Hi there, I can write: s = 'some string' then print s[1] will be the string 'o' and a while later I can write: s = 'other some string' then print s[1] will be the string 't' and then: s = [1,2,3,4] then print s[1] will be the number 2 and still later: s = {1:'boo',2:'foo',3:'shoo'} when print s[1] will yield the string 'boo' Now how about introducing an index that works over time, such that s{0} (the default so as to not break any existing code) implies the current object bound to the name s, with s{1} being the previous one, and so on... This will mean that s{2}[1] is the string 't' and s{3}[1] is the string 'o' while s{4} should be None... It should be easy to implement this, as all that needs to be done is to change the "pointer" (or whatever) to the object with a stack of them at the time the binding or rebinding is done... I first thought of using s{-1} for the previous "value" but that suffers from the regrettable disadvantage that it implies the existence of an s{1} - i.e. a future value - and I could not think of a way to achieve this - so the minus sign adds no information and should therefore be left out... What do you guys think? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Small Troll on notation of variables over time
"John Machin" <[EMAIL PROTECTED]> wrote: | | Hendrik van Rooyen wrote: | [snip] | > What do you guys think? | | The subject said it all. You should find some other way of entertaining | yourself on the weekends :-) This is the right answer... *grin* - well - at least you *were* warned... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter btn visual state with tkMessageBox
<[EMAIL PROTECTED]> wrote: To: | why is the button sunken when called through a bind method, and not | with the command attribute? | Thank you! | | | ## Cut'nPaste example | from Tkinter import * | import tkMessageBox | | class Vue(object): | def __init__(self): | self.root=Tk() | self.root.title("test button visual state") | self.b1=Button(self.root,text="tkMessageBox.showinfo with bind | :-(") #,command=self.showMsg) | self.b1.bind("",self.showMsg) 8<--- change this to : self.b1.bind("",self.showMsg) Problem is that a button "sinks in" when you press it and "springs back" when you release it... and the "Button" leaves it sunken - because when you release, the control is no longer there - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter btn visual state with tkMessageBox
<[EMAIL PROTECTED]> Wrote: | | Hendrik van Rooyen wrote: | > <[EMAIL PROTECTED]> wrote: | > | > To: | > | > | > | why is the button sunken when called through a bind method, and not | > | with the command attribute? | > | Thank you! | > | | > | | > | ## Cut'nPaste example | > | from Tkinter import * | > | import tkMessageBox | > | | > | class Vue(object): | > | def __init__(self): | > | self.root=Tk() | > | self.root.title("test button visual state") | > | self.b1=Button(self.root,text="tkMessageBox.showinfo with bind | > | :-(") #,command=self.showMsg) | > | self.b1.bind("",self.showMsg) | > | > 8<--- | > | > change this to : | > | >self.b1.bind("",self.showMsg) | > | > Problem is that a button "sinks in" when you press it and "springs back" when | > you release it... | > | > and the "Button" leaves it sunken - because when you release, the control is | > no longer there | > | > - Hendrik | Thanks Hendrik - is the command attribute connected to the bindable | events? | jm I don't have a clue - you are either asking about advanced magic here, or I don't understand your question - I believe the lower level routines are common, but I don't *Know* this - so its a pity that some people who shall be nameless have beaten their brains out in a thread about a directory name here.. You may have noticed that there is another subtle bug with what I have suggested to you - when you press the offending button, then move the mouse to move the cursor off the screen button, - the button "springs back" as expected - but then when you release the mouse button, off the screen button, the call back is done anyway, instead of being cancelled when the cursor moves off the screen button. - for the command case, the sequence is different, and the call back is done only if the release is done on the screen button... - But this may just be my setup - does yours do the same? I don't know how to fix that - you could look at sequences of events - button push followed by release - But I doubt whether this will help, as its doing something like that anyway (haven't tried it) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Input from the same file as the script
"Dennis Lee Bieber" <[EMAIL PROTECTED]> Wrote: | On 20 Aug 2006 11:02:25 -0700, [EMAIL PROTECTED] declaimed the | following in comp.lang.python: | | > Can the input to the python script be given from the same file as the | > script itself. e.g., when we execute a python script with the command | > 'python | Redirecting? Ugh... | | Off-hand, I'd say NO | | There is no way to tell the python interpreter where the program | ends and the "run data" begins. You *could* jump through a hoop like this one: ListOfInput = ['first input', 'second input', ...'last input'] and then read the elements of the list one by one... You will probably have to make the list global to get it to work... But I kind of agree with Dennis - I would not do it that way either - reading the inputs from the stdin console is easy enough, or if there are just a few of them, getting them as command line arguments is arguably even easier - and if its a whole bunch of stuff that is painstaking to type in every time - put it in a text file and read it line by line. - Hendrik - -- http://mail.python.org/mailman/listinfo/python-list
Re: Small Troll on notation of variables over time
"Piet van Oostrum" <[EMAIL PROTECTED]> Wrote: | You are about 7 months early. | -- Am I? - Early for what - a seven months premature baby is small indeed... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Small Troll on notation of variables over time
"Jeremy Sanders" <[EMAIL PROTECTED]> wrote: | Hendrik van Rooyen wrote: | | > What do you guys think? | | You could get something similar using an object, such as | | class Hist(object): | | def __init__(self): | self.vals = [None] | | def __call__(self, index=-1): | return self.vals[index] | | def set(self, val): | self.vals.append(val) | | a = Hist() | | a.set(5) | print a() | | a.set('hi there') | print a() | print a(-2) | | Which prints | 5 | hi there | 5 - Sneaky! - I like this - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you want in a new web framework?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: | Alex Martelli wrote: | | > Indeed, it has been truthfully observed that Python's the only language | > with more web frameworks than keywords. | | recent research indicates that it has more web frameworks than comments | in the source code. | | Argh! -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you want in a new web framework?
"Alex Martelli" <[EMAIL PROTECTED]> | Tim Roberts <[EMAIL PROTECTED]> wrote: |... | > themselves. However, in the case of web frameworks, I believe Marc is | > fundamentally correct: the web framework proliferation in Python is | > actually doing the language a huge disservice. | | Indeed, it has been truthfully observed that Python's the only language | with more web frameworks than keywords. | | I have already suggested to the BDFL that he can remedy this situation | in Py3k: all he has to do, of course, is to add a LOT more keywords. | | | Alex *groan* -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
"jojoba" <[EMAIL PROTECTED]> Wrote: | > At the risk of stating the obvious, why don't you simply add a parameter | > for the title in the invocation of the tree editor? I.e. instead of | > invoke_tree_editor(somedict) | > do | > invoke_tree_editor(somedict, "somedict") | > HTH, | > Carsten. | | | Thanks Carsten. | This would indeed allow me to assign a title for my dicitonaries, but i | am looking for something more general.. | specfically: | given any dictionary, get a name for it. | | But yeah, your way would totally work! | Thanks, | jojoba | At the risk of asking the even more obvious - "given any dictionary" - How is it given - just print whatever it is that causes you to believe that you are dealing with a dictionary.. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
"Eric Brunel" <[EMAIL PROTECTED]> wrote: > On Wed, 04 Oct 2006 10:33:55 +0200, Hendrik van Rooyen > <[EMAIL PROTECTED]> wrote: > > > Hi, > > > > I get the following: > > > > [EMAIL PROTECTED]:~/Controller/lib> python display.py > > UpdateStringProc should not be invoked for type font > > Aborted > > > > and I am back at the bash prompt - this is most frustrating, as there is > > no > > friendly traceback to help me guess where its coming from. > > > > And what is worse, the script runs for a varying time before it simply > > exits > > like this. > > > > What can I do to dig deeper to try to find a clue? - I don't even know > > if its > > Python, Tkinter or Linux... > > Neither of them: it's a tcl problem. The message you get is in the file > generic/tclObj.c in the tcl source directory. > > I know the problem happens sometimes on one of my Tkinter applications, > but I never succeeded in reproducing it systematically. I've browsed the > tcl bugs, but didn't find anything. Maybe you'll be luckier than I... If > you are, I'm interested in any hint you can find. Ouch! - this is a bit the wrong answer... What I have seen, in mucking about today, is that it seems to be related to threading - I have a silly sort of thread that runs, updating my meters, more or less continuously, to simulate data from the field - it just adds some values to the seven display variables and calls the update methods that delete and redraw the arcs representing the analogue style meters, deleting and replacing the text objects that show the values, and then it sleeps for a while, and does it all again. At the same time, one other thread (other than the main thread), can be created to move a component on the canvas around by calling its delete and draw methods. - but this is also done more or less continuously, as a new thread is created as soon as the previous one dies to move the next object around. Now these two things are asynchronous with each other, so that given enough time, they are bound to make calls to Tkinter in a re-entrant fashion, and I suspect that it is this that is causing the problem - my "evidence" for this is that I implemented a boolean as a sort of "lock" and had the Meter updating back down in favour of the other animation to try and avoid any sort of re - entrancy to the Tkinter canvas object's delete and draw methods... Now the Jury is still out on this - it seems to have helped, as the thing has been running for some hours now without crashing - but maybe I have just applied a band aid to sword cut - I don't know - if it runs through the night I will feel much better... Will update again as soon as I have more data... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
"Russell E. Owen" <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > > >Hi, > > > >I get the following: > > > >[EMAIL PROTECTED]:~/Controller/lib> python display.py > >UpdateStringProc should not be invoked for type font > >Aborted > >... > >Everything seems to work fine. - there is a thread that runs to move the meter > >values around continuously, and this has been stable for some time now, and I > >can get the various "machine" parts to move around the screen by pushing the > >buttons... > > You mention threads several times in your posting. Do you have multiple > threads talking to Tkinter? If so, try recoding to avoid this (e.g. by > having the background threads communicate with the main thread via > Queues). > > -- Russell I am not sure how to do this - once I have called the Tkinter mainloop - that main thread is essentially event driven - and figuring out how to get it to poll a queue for content is not obvious - I suppose I could arrange some external wake up event that I could activate to make it look at the queue - must read up on this... Thanks it is a good idea as it will make the interface cleaner, and as I have to sort out inter process communication anyway it will make sense to also use a queueing mechanism between the threads in this display process. There is already one queue defined - but its a hack as I use it to pass the main threads id to get around the problem of referring to a class before its defined... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
"Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Eric Brunel" <[EMAIL PROTECTED]> wrote: > > > > On Wed, 04 Oct 2006 10:33:55 +0200, Hendrik van Rooyen > > <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > > I get the following: > > > > > > [EMAIL PROTECTED]:~/Controller/lib> python display.py > > > UpdateStringProc should not be invoked for type font > > > Aborted > > > > > > and I am back at the bash prompt - this is most frustrating, as there is > > > no > > > friendly traceback to help me guess where its coming from. > > > > > > And what is worse, the script runs for a varying time before it simply > > > exits > > > like this. > > > > > > What can I do to dig deeper to try to find a clue? - I don't even know > > > if its > > > Python, Tkinter or Linux... > > > > Neither of them: it's a tcl problem. The message you get is in the file > > generic/tclObj.c in the tcl source directory. > > > > I know the problem happens sometimes on one of my Tkinter applications, > > but I never succeeded in reproducing it systematically. I've browsed the > > tcl bugs, but didn't find anything. Maybe you'll be luckier than I... If > > you are, I'm interested in any hint you can find. > > Ouch! - this is a bit the wrong answer... > > What I have seen, in mucking about today, is that it seems to be related to > threading - I have a silly sort of thread that runs, updating my meters, more or > less continuously, to simulate data from the field - it just adds some values to > the seven display variables and calls the update methods that delete and redraw > the arcs representing the analogue style meters, deleting and replacing the text > objects that show the values, and then it sleeps for a while, and does it all > again. > > At the same time, one other thread (other than the main thread), can be created > to move a component on the canvas around by calling its delete and draw > methods. - but this is also done more or less continuously, as a new thread is > created as soon as the previous one dies to move the next object around. > > Now these two things are asynchronous with each other, so that given enough > time, they are bound to make calls to Tkinter in a re-entrant fashion, and I > suspect that it is this that is causing the problem - my "evidence" for this is > that I implemented a boolean as a sort of "lock" and had the Meter updating back > down in favour of the other animation to try and avoid any sort of re - entrancy > to the Tkinter canvas object's delete and draw methods... > > Now the Jury is still out on this - it seems to have helped, as the thing has > been running for some hours now without crashing - but maybe I have just applied > a band aid to sword cut - I don't know - if it runs through the night I will > feel much better... > > Will update again as soon as I have more data... OK - It has run through the night and as I type it is still running, so the band aid has helped a bit... Eric - if you are interested and contact me, then I will comment out the "fix" and email you the bits that you need to run this horror - if you need a reliably failing thingy to study the problem with :-) It was your post yesterday or so in another thread here that prompted me to try this style of fix... Thank you. BTW - I am curious - in your app that exhibits the same crash - what did you do to work around the problem ? - Is it also running a thread and calling methods that are normally event driven commands in the main thread? Or two other threads like me? It would be interesting to try to spot any similarities... Is it even allowed to asynchronously call a main thread method from another thread? - it seems to work - but I am not sure why it does - what is the main thread's mainloop doing while this is going on? - your other comment in the other thread here implies that it is a strict no - no... Is it safe to call invoke from another thread? - what is the difference between calling invoke and calling the bound method directly? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Eric Brunel wrote: > > > AFAIK, Tkinter is not thread safe. Using some kind of lock to serialize > > the calls from different threads may seem to work (I never tested it > > actually), but the safest way I found to use threads with Tkinter was to > > call it only from the thread where the main loop executes. > > the Tkinter binding contains some code that attempts to deal with re- > entrant calls, but I don't know/remember to what extent it's actually > supposed to work (in other words, if the observed problems are bugs or > just limitations). > > (maybe Martin's memory is better?) > > anyway, I usually play it safe and make sure to use a single thread to > deal with the UI. > > I must be dense - After I have called mainloop, if I have not started another thread to respond to events that are not generated by the user on the screen (in this case values of variables to display from the field generated by different processes - there is other hardware out there), how do I get control back to do the necessary updating? - I suppose I can use the call back after some time thingy to implement a polling loop - possibly as Russel Owen suggested - by polling a queue - but queues are for between threads - and I have seen here somewhere that sockets also want to be the main thread - so that leaves a pipe - and I have had bad experiences with pipes that are unblocked, and if I don't unblock it, then the gui will grind to a haltso I need a thread for the pipe between processes, and a queue between threads, and a time out based polling loop to read the queue, it seems - is it even safe to change a main loop variable from another thread? , or should I do it all via commands through a queue, implementing a whole goddam serial protocol just between threads? and If I don't have another thread to do the timing for the animation bits, then I must base that on a timed callback too, and somehow keep state between callbacks... now is it ok to call widget command methods from a callback in the same thread, or do I have to use invoke? My head is beginning to hurt... - what was a nice simple threaded implementation is turning into a spaghetti monster of timed callbacks - you thought gotos was bad? - you aint seen nothing yet... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
"Paul Rubin" <http://[EMAIL PROTECTED]> wrote: > "Hendrik van Rooyen" <[EMAIL PROTECTED]> writes: > > I am not sure how to do this - once I have called the Tkinter > > mainloop - that main thread is essentially event driven - and > > figuring out how to get it to poll a queue for content is not > > obvious - I suppose I could arrange some external wake up event that > > I could activate to make it look at the queue - must read up on > > this... > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 > Thank you Paul - this shows how nicely! - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter newsgroup or mailing list
"Franz Steinhaeusler" <[EMAIL PROTECTED]> wrote: > Hello NG, > > I'm asking this, (although I know a mailing list on gmane > gmane.comp.python.tkinter and there is so little traffic > compared to the mailing list of wxPython also mirrored > on gmane gmane.comp.python.wxpython. > > I cannot imagine, that there is no more interest > in exchanging opinions, or is this really the case? > > Is tkinter so simple, that no more questions appear? > Or is it simply so uninteresting? :) > > -- > Franz Steinhaeusler It is neither uninteresting, nor simple - see my very recent posts here... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
"Steve Holden" <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen wrote: > > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > > > >>Eric Brunel wrote: > >> > >> > >>>AFAIK, Tkinter is not thread safe. Using some kind of lock to serialize > >>>the calls from different threads may seem to work (I never tested it > >>>actually), but the safest way I found to use threads with Tkinter was to > >>>call it only from the thread where the main loop executes. > >> > >>the Tkinter binding contains some code that attempts to deal with re- > >>entrant calls, but I don't know/remember to what extent it's actually > >>supposed to work (in other words, if the observed problems are bugs or > >>just limitations). > >> > >>(maybe Martin's memory is better?) > >> > >>anyway, I usually play it safe and make sure to use a single thread to > >>deal with the UI. > >> > >> > > > > > > I must be dense - After I have called mainloop, if I have not started another > > thread to respond to events that are not generated by the user on the screen (in > > this case values of variables to display from the field generated by different > > processes - there is other hardware out there), how do I get control back to do > > the necessary updating? - I suppose I can use the call back after some time > > thingy to implement a polling loop - possibly as Russel Owen suggested - by > > polling a queue - but queues are for between threads - and I have seen here > > somewhere that sockets also want to be the main thread - so that leaves a > > pipe - and I have had bad experiences with pipes that are unblocked, and if I > > don't unblock it, then the gui will grind to a haltso I need a thread for > > the pipe between processes, and a queue between threads, and a time out based > > polling loop to read the queue, it seems - is it even safe to change a main loop > > variable from another thread? , or should I do it all via commands through a > > queue, implementing a whole goddam serial protocol just between threads? and If > > I don't have another thread to do the timing for the animation bits, then I must > > base that on a timed callback too, and somehow keep state between callbacks... > > now is it ok to call widget command methods from a callback in the same thread, > > or do I have to use invoke? > > > > My head is beginning to hurt... - what was a nice simple threaded implementation > > is turning into a spaghetti monster of timed callbacks - you thought gotos was > > bad? - you aint seen nothing yet... > > > See if this helps: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 > > It's Jacob Hallen's description of how he solved the problem. > > regards > Steve Thanks Steve - It is the same one Paul Rubin pointed me to and it describes nicely how to get the "worker" thread going, and the queue between it and the GUI thread. In my case, I will have a thread for input, as well as one for output to send commands away. The bit I was complaining about above is the replacement of a thread to do the animation timing with a "stutter" machine inside the gui thread, where the timing is handled by callbacks. A piece of feedback - the stutter machine animation timing is much smoother than the timing based on threaded sleep calls - less jittery - looks much better... So I am kind of glad the thing fell over because this implementation is going to be much better. Thank You All. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do this?
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote: > On Thu, 5 Oct 2006 11:28:08 +0100, "Matthew Warren" > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > > > > Now, I started programming when I was 8 with BBC Basic. > > > Remember what the acronym BASIC stands for? 8<--- yes - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Dumping the state of a deadlocked process
<[EMAIL PROTECTED]> wrote: > Hi all > > I'm currently having some issues with a process getting deadlocked. The > problem is that the only way I can seem to find information about where > it deadlocks is by making a wild guess, insert a pdb.set_trace() before > this point, and then step until it locks up, hoping that I've guessed > right. > > The frustrating part is that most of the time my guesses are wrong. Welcome to the wonderful world of crash and burn > > It would be really nice if I could send the python process some signal > which would cause it to print the current stacktrace and exit > immediately. That way I would quickly be able to pinpoint where in the > code the deadlock happens. Java has a somewhat similar feature where > you can send a running VM process a SIGQUIT, to which it will respond > by dumping all current threads and lots of other information on stdout. > > Is this possible somehow? Have you tried to sprinkle your code with print statements of the "We get here No: 7" kind - you can get quite a good idea of what is going on if you do, and if there are threads running - the results are often surprisingly insightful... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. AndySingleton
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: 8<--- > ... - I don't wanna get > into the details of my underwear :P > > Diez Why not? - what are you hiding? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary containing a list
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Steve Holden wrote: > > > One of the fascinating things about c.l.py is that sometimes a questin > > will be posted that makes almost no sense to me, and somebody else will > > casually read the OP's mind, home in on the issue and provide a useful > > and relevant answer. > > if the assertions made by some about the documentation's unsuit- > ability for some are in fact true, that's probably some kind of > natural selection in action. > > LOL - Whining about documentation is what programmers do - its driven by the "fact" that the docs and the implementation are "never" in sync, except on something that is either trivial, or as old as the hills... And it does not matter if the software is free and open source, or bought at great expense - there are always these differences - sometimes niggly, and often major - it sometimes looks as if the docs were a statement of intent, with the implementation taking a left turn at the first crossroads. - Hendrik - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: People's names (was Re: sqlite3 error)
"Lawrence D'Oliveiro" <[EMAIL PROTECTED]> wrote: 8< > I wonder if we need another "middle" field for holding the "bin/binte" part > (could also hold, e.g. "Van" for those names that use this). NO! - I think of my surname as "van Rooyen" - its only a string with a space in it - and its peculiar in that the first letter is not capitalised And I am sure that the people called "von Kardorff" would not agree either... - Hendrik van Rooyen -- http://mail.python.org/mailman/listinfo/python-list
Re: Names changed to protect the guilty
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > On Fri, 06 Oct 2006 18:29:34 -0700, John Machin wrote: > > MonkeeSage wrote: > >> On Oct 6, 8:02 pm, "MonkeeSage" <[EMAIL PROTECTED]> wrote: > >> > it is clearer to you to make the condition explicit ("blah not False"), > >> > >> "blah not False" -> "blah is False" > > > > Whichever way your team wants to interpret it, d00d. > > > > Please consider whether you should be writing "(blah is False) is > > True", that would be more explicit. > > Puh-lease! Get it right! > > It should be "((blah is False) is True) is True". I once saw a baking powder tin with a picture of a baking powder tin with a picture of a baking powder tin... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: People's names (was Re: sqlite3 error)
"Dennis Lee Bieber" <[EMAIL PROTECTED]>wrote: 8<-- > In the days of paper filing (I actually took Shorthand, and a > Business Machines & Filing course in High School to avoid Phys.Ed.) the > training for things like oriental names was to choose one for "surname". > This is where the real papers would be stored. However, one was also > taught to create cross-reference entries under the other names -- > basically single cards of the form: > > sort, name > see name, sort > > I'll concede I doubt if any common database system is designed to > include that concept This sort of thing reminds me of a parts inventory system that I worked on - many moons ago - it had a replacement list consisting of- and you had to follow these links through to the bitter end, as it could happen multiple times, avoiding infinite loops as you go - on a "mainframe" with 64 kilobytes of core memory - not a job for recursion... But luckily we had disks - I would hate to have to do this on a tape drive only machine... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: People's names (was Re: sqlite3 error)
"Lawrence D'Oliveiro" <[EMAIL PROTECTED]> wrote: > In message <[EMAIL PROTECTED]>, Hendrik van > Rooyen wrote: > > > "Lawrence D'Oliveiro" <[EMAIL PROTECTED]> wrote: > > > > 8< > > > >> I wonder if we need another "middle" field for holding the "bin/binte" > >> part (could also hold, e.g. "Van" for those names that use this). > > > > NO! - I think of my surname as "van Rooyen" - its only a string with a > > space in it - and its peculiar in that the first letter is not > > capitalised > > > > And I am sure that the people called "von Kardorff" would not agree > > either... > > So do the Dutch phone books have a lot of entries under V, then? > > It just seems less efficient to me, that's all. Don't know about what happens in Holland - my ancestors came over here to South Africa a long time ago - a mixed up kid I am - Dutch and French from the time of the revocation of the edict of Nantes... And yes, here the phone books are sorted that way - the "van Rensburg"s precede the "van Rooyen"s. And what is worse, there are a lot of "van der"s too - two spaces in the string like "van der Merwe" who are preceded by "van der Bank" - "van" basically means "from" - like the German "von" - but in Germany its an appellation applied to the nobility - and in my name it makes no sense as "Rooyen" is not a place - its a strange archaic derivative of the colour red - "rooij' in Dutch, spelt "rooi" in Afrikaans - and the "der" is an archaic form of "the" - (and modern "the" in German, if yer male) ... And that lot completely ignores other animals like the "Janse van Rensburg"s, who go in amongst the "J"s... HTH - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Everything is a distributed object
"Martin Drautzburg" <[EMAIL PROTECTED]> wrote: > Hello all, > > I've seen various attempts to add distributed computing capabilities on top > of an existing language. For a true distributed system I would expect it to > be possible to instantiate objects of a remote class or to subclass a > remote class and other stuff like this. My impression is that those things > are difficult when built on top of an existing language. > > Since the paradigm "everything is an object" pays so well, I thought it > might be less painful to implement a distributed system from ground up, > starting with the paradigm: "everything is a distributed object". > > Do you know if such a thing has been attempted with python, i.e. by hacking > the python core and add new capabilities to "object". Or do you think that > this is really a silly idea ? Google for pyro - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python component model
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Nick Vatamaniuc wrote: > > > At the same time one could claim that Python already has certain > > policies that makes it seem as if it has a component model. 8< > implementing this using existing mechanisms is trivial (as the endless > stream of interface/component/adapter/trait implementations have shown > us); coming up with a good-enough-to-be-useful-for-enough-people > vocabulary is a lot harder. not sure if its trivial - but agree about the generality - my meat is your poison effect operating here - and also - standards are not per se a *Good Thing* - they stifle both inventiveness and diversity... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Sarcasm and irony
"Steve Holden" <[EMAIL PROTECTED]> wrote: 8< > ... It's well-known among Brits that Americans don't > understand irony. They can be pretty oblique when it come to sarcasms > too, for that matter. *ducks to avoid the nuclear fall out* You should not do that Steve - they have no Sense of Humour either - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Wing IDE 2.1.3 released
"Wingware Announce" <[EMAIL PROTECTED]> wrote: 8<--- > * Professional quality code editor > * Visual Studio, VI/Vim, Emacs, and Brief key bindings Can I copy paste columns as in Brief? Do the Brief Macros work? 100% ? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread termination
"Teja" <[EMAIL PROTECTED]>wrote: > Hi all, > > Does any one know how to terminate or kill a thread that is started > with "start_new_thread()" in the middle of its execution? > > Any pointers? > > Thanks in advance > > Teja. can't be done from outside without co operation of thread in question. google this newsgroup - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the defaultargument value?
"Antoon Pardon" <[EMAIL PROTECTED]> wrote: 8<- > If we somehow want to seperate parameters in those that > can be used with a keyword and those that don't it has > to be something different than providing a default value > to that parameter. This makes sense - before reading this thread I was under the impression that giving a variable a default value makes it a keyword variable - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Starting out.
<[EMAIL PROTECTED]> wrote: 8< > Well, I'm on vacation this week, so 5 pm means nothing to me: > > teetertotter > > from the Consolidated Word List from puzzlers.org. > > Yes, it's also spelled with a hyphen or a space, but as long as this > is a valid spelling, it counts. > > I would recommend NOT looking this up, just take my word for it. > You may be offended at what you find. did not need to look it up - I know that teetertotter is a complicated word for "see-saw". - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread termination
"Nick Craig-Wood" <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > > can't be done from outside without co operation of thread in question. > > google this newsgroup > > Hopefully google will discover also the thread where the above statement is > proved to be false ;-) > > This might be a useful thing to search for... > > ctypes.pythonapi.PyThreadState_SetAsyncExc > Where were you when we needed you some week or two ago? I *could* argue that using ctypes is cheating - But I wont... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Can I set up a timed callback without Tkinter or twisted or something?
Hi, I want to do the equivalent of the after thingy in tkinter - setting up in effect a timed call back. My use case is as a "supervisory" timer - I want to set up an alarm, which I want to cancel if the expected occurrence occurs - but its not a GUI app. My googling gets a lot of stuff pointing to optparse... Does the standard lib have anything like this? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I set up a timed callback without Tkinter or twisted orsomething?
"Scott David Daniels" <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen wrote: > > I want to do the equivalent of the after thingy in tkinter - setting up in > > effect a timed call back. > > > > My use case is as a "supervisory" timer - I want to set up an alarm, which I > > want to cancel if the expected occurrence occurs - but its not a GUI app. > > Use a thread that uses something like: >def action(): >sleep(50) >if not canceled: >callback(foo) > as its action. > > The callback ill be in another thread, but Look up threading for > more details. Thanks - I was hoping that I did not have to do it myself - the Tkinter thingy works nicely - I was hoping that the interpreter could handle something like this... What I don't like too much about the sleep based solution is that yer blind and deaf while sleeping - at least in that thread - and I am trying for fairly fine grained timing resolution... is there not something based on signals? - I seem to recall some such thing here in another thread.. ( I am running Linux) -Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I set up a timed callback without Tkinter or twisted orsomething?
"hg" <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen wrote: > > Hi, > > > > I want to do the equivalent of the after thingy in tkinter - setting up in > > effect a timed call back. > > > > My use case is as a "supervisory" timer - I want to set up an alarm, which I > > want to cancel if the expected occurrence occurs - but its not a GUI app. > > > > My googling gets a lot of stuff pointing to optparse... > > > > Does the standard lib have anything like this? > > > > - Hendrik > > > > http://python.active-venture.com/lib/timer-objects.html > Thanks - will check it out - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I set up a timed callback without Tkinter or twisted orsomething?
<[EMAIL PROTECTED]> wrote: > > Hendrik> is there not something based on signals? - I seem to recall > Hendrik> some such thing here in another thread.. ( I am running Linux) > > Have you tried: > > import signal > help(signal) > > at the interpreter prompt? > > Skip *blush* - actually, no - I was looking for signals... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: A friendlier, sugarier lambda -- a proposal for Ruby-like blocksin python
"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote: > Kay Schluehr wrote: > > Bruno Desthuilliers wrote: > > > >> Just for the record : Ruby's code-blocks (closures, really) come from > >> Smalltalk, which is still the OneTrueObjectLanguage(tm). > > > > IsTheOneTrueObjectLanguage(tm)ReallyCamelCased? > > > ThatsAGoodQuestion. > > DoYouMeanIsTheIdentifierTheOneTrueObjectLanguage(tm)CamelCasedOrIsTheObjectObjec tBoundToIdentifierTheOneTrueObjectLanguage(tm)CamelCasedOrYetSomethingElse? IAmGladToSeeThisSterlingAttemptAtMinimisingTheEncodingSpaceAsTheSpaceCharacterNe verImpartedAnyInformationAnywayHendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: People's names (was Re: sqlite3 error)
"Florian Diesch" <[EMAIL PROTECTED]>wrote: 8<-- >In Germany "von" is just a part of the name since 1919 when the nobility >was abolished by law. Thanks - was not aware of this - 1919 - just after the Great War, 1914-1918... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: invert or reverse a string... warning this is a rant
"Fredrik Lundh" <[EMAIL PROTECTED]>wrote: 8<--- > 'a man a plan a canal panama' is not a palindrome > > ? not if spaces count - able was I ere I saw elba - is one - but its a tougher test... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting existing module/objects to threads
<[EMAIL PROTECTED]> wrote: > I have inheirted some existing code, that i will explain in a moment, > have needed to extend and ultimately should be able to run in threads. > I've done a bunch of work with python but very little with threads and > am looking for some pointers on how to implement, and if the lower > level modules/objects need to be rewritten to use threading.local for > all local variables. > > I have a module that communicates with a hardware device, which reads > data off of sensors, that can only talk with one controller at a time. > The controller (my module) needs to (in its simplest form) init, > configure the device, request data, and write out xml, sleep, repeat. > > The new request is that the device needs to be queried until a > condition is true, and then start requesting data. So an instance of a > controller needs to be deadicated to a hardware device forever, or > until the program endswhich ever comes first. > > This currently works in a non-threaded version, but only for one device > at a time, there is a need to create a single windows(yeach) service > that talks to many of these devices at once. I don't need worker > threads that handle seperate portions of the entire job, i need a > single application to spawn multiple processes to run through the > entire communication from configure to report, sleep until the next > interval time and run again. The communication could last from 1 > minute to 10 minutes before it ends. 8<-- not sure if I understand this correctly - but I would in this position spawn new threads, and use a global list of queues to interface between the new threads and the old comms module, still talking to one device at a time, but now time sliced. - in the comms module: for q in list_of_queues: see if anything to ask: continue if not ask it and put answer on reply queue but then I am a Philistine coder, interested only in getting the job done... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: invert or reverse a string... warning this is a rant
"Brad" <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > > Gah!!! That's *awful* in so many ways. > > Thanks... I'm used to hearing encouragement like that. After a while you > begin to believe that everything you do will be awful, so why even > bother trying? > > > > It has been my experience that Python has discouraging forums with > someone always calling someone else an idiot or telling them they are > awful in some way. I love Python, but the community is way too negative, > uptight and generally down on users who do not have PhD's in CS or Math. > > Do you have children? How would your child feel if he brought you > something he had made and you then told him it was awful in *sooo* many > ways. How does that reflect on you and the community you represent? > > Cut people who don't think like you some slack, OK? > > 8<- This is kind of sad to see - what seems not be appreciated here is the genuine effort that was put in by Stephen to critique the piece of code - not just a one liner putdown, but a reasoned exposition, taking time... and yes - it hurts at first to have your ego bruised - but look past that - and see the genuine attempt to help. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Arrays? (Or lists if you prefer)
From: <[EMAIL PROTECTED]> wrote: 8<--- > So: > Way to do SIMPLE array, either internally or externally, with Python, > please. to help you see it - here is a simple 3 row by 3 column list: myarray = [[1,2,3],[4,5,6],[7,8,9]] the first "row" is myarray[0] - ie the list [1,2,3] the middle element is myarray[1][1] - ie 5 - row 1, col 1. the last element in the first row is myarray[0][2] - ie 3 play with it at the interactive prompt... HTH - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 ; Effbot console ; thank ; pb release.
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: Méta-MCI wrote: > For the professional developments, it is a major risk. some days, I ask myself why I shouldn't just use GPL for everything I do, and ship it as source code only. because then you would deny your work to thousands of ungrateful, unmotivated lazy buggers like me... seriously, though- the OP's problem was that he was fixing something that was not broken - by upgrading, for some incomprehensible reason - and then expecting that the whole world would follow, and ease his pain by intuiting what he was using, and upgrading it for him, to make his chosen add ons compatible with his upgrade... I wonder what else his upgrade broke? - you obviously have a major task on your hands as you are expected to fix that too... Why are you surprised at ingratitude, BTW? Keep up the good work. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Rabbit Modules - Dynamic C - Python
"Picio" <[EMAIL PROTECTED]> wrote: > Hello, > I would wonder if anyone knows something about programming with > Python, Rabbit Core Modules, that normally were programmed with Dynamic > C. > > I mean either: > - something like using python to create code in dynamic suitable for > the rabbit core > - writing machine code for the rabbit core using a python API. > > Sorry if I'm not using the rights technicals words. > > Picio if I remember correctly, the rabbit is a modified z180, which is a modified z80, which is a descendant of the 8080... so it should be possible - however, the average ram memory in a rabbit module will probably not support Python - it is unlikely that there will be enough for the Object Orientation that Python brings - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter question
Sorin Schwimmer wrote: Hi All, Is it possible to have a widget id while it is created? Something like this: Button(root, text='...', command= lambda v=: fn(v)).grid() and then the function: def fn(v): v['bg']='BLUE' # or maybe nametowidget(v)['bg']='BLUE' Thanks, Sorin - just give the thing a name when you make it: MyFirstButton = Button(. or possibly if its in a class: self.MyFirstButton = Button(. then use self.MyFirstButton.configure('bg' = 'blue', 'text' = 'new description on the button') HTH Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter question
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Eric Brunel wrote: > > > But Hendrik's solution is better, since it avoids the use of lambda, which > > is often difficult to understand. > > storing the button reference in a variable doesn't help if you want to use the > same callback for multiple buttons, though... > > I can't see how to use it for that - on the other hand, it enables you to use the same button for different things at different times by re configuring the command binding... This can be used as a sort of "state machine" to keep track of what the user is doing - changing button text, colour and command binding from "On", "green" and onOn to "Off", "red" and onOff... In my current project this style has developed to a point where onOn would change the colour,etc, as well as setting up a deferred callback to onOnTimeout, and firing off a message to the hardware in the field. A response from the successful completion is then used to call onOnEnd, which cancels the timed callback. onOnTimeout does emergency stuff because something did not work, as onOnEnd was not called... It is a bit more complex than the above - as there are intermediate "grey out" states - but the above illustrates the principle simply. It seems to work quite robustly, and I am also developing a Simple Distributed Control Language - SDCL (tm) , to do the work on the small micros in the field, tying everything together. - It was fun and almost indecently easy to write a one pass "compiler" resolving forward references on the fly in Python - more of an assembler, really - and no trace of lexx or yacc or bison - just a few lines of Python code - but I digress... And yes I know what SDLC is... *WEG* - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: question about True values
"Robert Kern" <[EMAIL PROTECTED]> wrote: 8<-- > It's a bit of an abuse on the English language, but what isn't in software? jumps used not to be - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: basic questions on cmp, < and sort
"Ben Finney" <[EMAIL PROTECTED]> wrote: To: Sent: Thursday, October 26, 2006 4:44 AM Subject: Re: basic questions on cmp, < and sort Schüle Daniel <[EMAIL PROTECTED]> writes: 8<--- > third question > > sort([[1,2,3],["ABC"],['Z','A'], X(), 4) >>> sort([[1,2,3],["ABC"],['Z','A'], X(), 4) File "", line 1 sort([[1,2,3],["ABC"],['Z','A'], X(), 4) ^ SyntaxError: invalid syntax needs a closing ']' to make the list a list. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: cleaner way to write this?
"John Salerno" <[EMAIL PROTECTED]> wrote: 8<- > > LOL. Guess I'm doing things right, then? ;) > you can NEVER be sure - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: displaying \n-less prompts in a pythonic way
"Steve Holden" <[EMAIL PROTECTED]> wrote: 8<--- > >>> mystr = raw_input("Who is this? ") > Who is this? Steve how did you know how to answer that? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: wxPython 2.7.1.3
"Johann C. Rocholl" <[EMAIL PROTECTED]>wrote: 8<-- > Oh, it's fun to be a speling fanatic! :-) six munce ago I could not even spell 'fatanic' - and now I are one... I wander what a speling fanatic is? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Listbox string formatting question - how to kill a dancing snake ?
I am populating a listbox from a directory that looks like this: variable_dict = {"funny_long_or_short_variable_name_as_key": (2,45),.. the tuple represents a "card, line" pair. medf is a font object and a forward reference here. I write: for x in variable_dict: txt = x while medf.measure(txt) < 350: txt = txt + ' ' txt = txt + str(variable_dict[x]) and I use the txt string to populate the list box. At first glance, it seems to work, as the names are on the left, and the tuples are in a column... But if you scroll the listbox, the inherent error makes it appear as if the tuple column is a snake doing the twist. I tried using a tab but got a backslash - t in the text, and simply counting spaces is worse than useless. Is there a way to format this so it will line up with *any* font ? I would prefer not to give up and use a fixed width font - it looks so teletypish... A blank char of one pixel width would sort this nicely - but as the hilbilly said when he first saw a rhinoceros: " There aint no such animal! " - or is there? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python windows interactive.
"notejam" <[EMAIL PROTECTED]> Top posted: > Thanks everyone for the help. I got a simple two line program to work > from a text file. > Can not figure out how to write more than one line in interpreter mode. > Is that all interpreter is good for, testing one liners? I have it > run the program everytime I hit return, and can not figure out how to > enter multiple lines of code. I can do multiple lines in text file, so > no problem, but I am jsut wondering can a program with 2 or more lines > be wrote from the interpreter mode? the interactive interpreter remembers the stuff you type. so you can assign values to variables, and refer to them later. you can define functions and call them later that is enough to start with. try it - you will like it... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Listbox string formatting question - how to kill a dancingsnake ?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > instead of trying to force the listbox to behave like a multicolumn > widget, maybe you could switch to another widget? some alternatives include > > a Text widget (you have to roll your own selection logic) I _really_ don't feel strong enough for this, or for sticking them loose on a canvas... > bwidgets multicolumn ListBox: > http://tkinter.unpythonic.net/bwidget/ > tktable: > http://tktable.sourceforge.net/ > something based on the wck (that's what I'd would use myself): > http://effbot.org/zone/wck-4.htm > and perhaps there's something in Pmw: > http://pmw.sourceforge.net > Thanks I will check these out... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Listbox string formatting question - how to kill adancingsnake ?
"Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > > > instead of trying to force the listbox to behave like a multicolumn > > widget, maybe you could switch to another widget? some alternatives include > > > > a Text widget (you have to roll your own selection logic) > > I _really_ don't feel strong enough for this, or for sticking them loose on a > canvas... 8< sorry - thought has just occurred to me - my basic problem is text formatting, as variable width fonts make it difficult to get two things to line up under one another by using spaces as padding - so how would the Text widget have helped me with this ? or - Luxury ! - can I set a tab stop in pixels ? - maybe I can catch a general clue here... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: report progress from C function
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Michael S wrote: > > > I downloaded Pyrex and ran it through their own > > example. The code looks quite messy, and I even saw a > > few "goto"s. > > looked at the assembler output from your C compiler lately? > > LOL! - is it even possible to code an if else without conditional jumps? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Listbox string formatting question - how to kill a dancingsnake ?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: In the meantime, I have produced this evil hack, that takes advantage of the difference in pixel widths between the space, and either the fullstop or the single quote... It will only work if you have quite a lot of space to waste between columns, and I have only tested it for two sizes of Lucida and Helvetica - and for a fixed font like courier it seems to do no harm other than the cpu time it wastes... If the difference in width is one pixel, it lines up the next thing to be added to the string exactly, else it almost gets it right... I find the few (up to one less than there are pixels in a space) characters it adds into the line less visually disturbing than the dancing snake column caused by the full space width variation. anyway for what its worth, here it is: # this does some text padding to try to line variable font stuff up def pad_text(txt,pixlen,fontp): """This does padding up to a pixel value exploiting differences between space, fullstop or single quote widths. txt is a text string pixlen is an int - the number of pixels to "tab" to fontp is the font parameter """ a = fontp.measure(txt) diff = pixlen - a if diff < 0: return "string too long too fit in pixels" spsize = fontp.measure(' ') fssize = fontp.measure('.') sqsize = fontp.measure("'") repchr = ' ' rpsize = spsize numr = 0 rpdiff = 0 if spsize != fssize: repchr = '.' rpsize = fssize rpdiff = abs(fssize - spsize) elif spsize != sqsize: repchr = "'" rpsize = sqsize rpdiff = abs(spsize - sqsize) numspace, rem = divmod(diff,spsize) if rem == 0: numr = 0 else: if spsize < rpsize: numspace -= rem/rpdiff numr = rem/rpdiff elif spsize > rpsize: numr = (spsize - rem)/rpdiff numspace = numspace - numr + 1 numspace -= 2 txt = txt + ' ' while numr > 0: txt = txt + repchr numr -= 1 while numspace > 0: txt = txt + ' ' numspace -= 1 return txt Feel free to play the critic... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Is there a way to define a true global across modules?
I am struggling with this - I want to define a "system-wide" flag for use as a semaphore. It looks to me as if the only way to do it is to import all the modules that need to access it into the main namespace using the " from whatever import * " form. Is there a way to have one global object known to the main module as well as say two imported modules by using the global statement in the three places, while using the normal "import modname " form? It looks as if the global statement just makes the name global to the module where it is defined, and if I use the "import modname" form I end up with a "local global" for each module, as well as one for the main module... Can they be "merged' into one without sticking everything into the same namespace? I can think of ways to work around this, but it gets a bit obfuscatory - it would be nicer to have one name, one thing in all three places... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to define a true global across modules?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen wrote: > > > I am struggling with this - I want to define a "system-wide" flag for use as a > > semaphore. > > http://www.effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm > > Thanks - just like COBOL's data division *grin* - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to define a true global across modules?
"robert" <[EMAIL PROTECTED]> wrote: > Fredrik Lundh wrote: > > Hendrik van Rooyen wrote: > > > >> I am struggling with this - I want to define a "system-wide" flag for > >> use as a > >> semaphore. > > > > http://www.effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm > > > > Or worse style - if you are too lazy to create a extra global variables module (ab)use the __main__ module als "global": > > > import __main__ > > __main__.mysemphore += 1 > > > -robert Thanks - how could you possibly have guessed that I am lazy - does it show that much? *WEG* - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Having trouble with file modes
"erikcw" <[EMAIL PROTECTED]> wrote: 8< > #loop through patterns list and find/replace data > for o, r in patterns: > data = data.replace(o, r) > print "Replaced %s with %s" % (o, r) > f.write(data) > f.close() > > This results in an empty file. All of the modes I've tried either > produce an empty file or append the data onto the end of the file. How I would take a hard look at what the find and replace does - it acts as if you are replacing *everything* with *nothing* - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Language that is Spreadsheet/Table Based
"James Stroud" <[EMAIL PROTECTED]> wrote: > Gerard Flanagan wrote: 8<-- > Thank you, this is very good stuff to think about. > > James I can't really add to the above train of thought... And I don't know if this will help - but if you want to think, here is a skewed, simple view: If I were to try and do something like this, I would start by defining a spread sheet like dict to keep everything in, using (column,row) tuples as keys, and build on top of that. This would give you the ability to keep *anything* in a cell, and the database like structures you are thinking of would live on top of this underlying access structure, with the (column,row) being a direct *pointer* to an element in one fast step. I would then also use other dicts to describe what is kept in the "columns" - something simple like: header_dict = {0:['name of person','Name','Enter your name'],1:['age of person since birth','Age','Enter your birthday'], ... } where the first item in the list is a help string, the second a column header for printing, the third the string to use as prompt for a GUI, etc... - you could even keep and enforce type if you wanted to - must be int, must be date, column width for printing, validation data and rules, - whatever. In a sense this is a sort of inverted way of looking at a file - instead of having an underlying dict with (column, row) keys, you could alternatively have "loose" column dicts only to keep the data in ( note that I have been writing (column, row) consistently, instead of the more conventional (row,column).) - this would make adding or deleting columns almost trivial. You *could* also have references to Python functions or class methods living alongside the data in the cells, and then things can get hairy - for an age entry, for instance, the cell can look like: Data[(column,row)] = # (or Age[row] in the alternative approach) [(1947,01,24),self.BirthdayChecker,self.PresentChooser,self.LetterWriter, ...] where the first entry, the tuple, represents the data (could have been a list or dict, of course ) and the rest are methods or functions to use, in this particular instance. You could instead have these function references in the age column's header dict entry, for those of them that have applicability across all rows of the column, just like the idea of type enforcement or validation above. For a kind of row, or row type, you need then simply keep a list of column numbers that are required for this "record", with a different list defining a different record type - Gold members need these column entries filled in, while Silver members need only those... simple, but then you need a record type column... This sort of thing organises the stuff, but the code to use it becomes a bit impenetrable, as you have to write a kind of crawling process to access the structure to do what is required, but it is all "table driven" and can be very flexible. Its not a weekend project though, and when you are finished its a kind of super relational database... HTH - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: tips requested for a log-processing script
"Jaap" <[EMAIL PROTECTED]> wrote: > Python ers, > As a relatively new user of Python I would like to ask your advice on > the following script I want to create. > > I have a logfile which contains records. All records have the same > layout, and are stored in a CSV-format. Each record is (non-uniquely) > identified by a date and a itemID. Each itemID can occur 0 or more times > per month. The item contains a figure/amount which I need to sum per > month and per itemID. I have already managed to separate the individual > parts of each logfile-record by using the csv-module from Python 2.5. > very simple indeed. > > Apart from this I have a configuration file, which contains the list of > itemID's i need to focus on per month. Not all itemID's are relevant for > each month, but for example only every second or third month. All > records in the logfile with other itemID's can be ignored. I have yet to > define the format of this configuration file, but am thinking about a 0 > or 1 for each month, and then the itemID, like: > "1 0 0 1 0 0 1 0 0 1 0 0 123456" for a itemID 123456 which only needs > consideration at first month of each quarter. > > My question to this forum is: which data structure would you propose? > The logfile is not very big (about 200k max, average 200k) so I assume I > can store in internal memory/list? > > How would you propose I tackle the filtering of relevant/non-relevant > items from logfile? Would you propose I use a filter(func, list) for > this task or is another thing better? > > In the end I want to mail the outcome of my process, but this seems > straitforward from the documentation I have found, although I must > connect to an external SMTP-server. > > Any tips, views, advice is highly appreciated! > > > Jaap > > PS: when I load the logfile in a spreadsheet I can create a pivot table > which does about the same ;-] but that is not what I want; the > processing must be automated in the end with a periodic script which > e-mails the summary of the keyfigure every month. I would do something like this: (obviously untested) for line in readlines(open(logfile,r,1)): (code to get hold of item, date, amount) if item not in item_dict: item_dict[item] = [(date,amount)] else: item_dict[item].append(date,amount) this will give you, for each unique item, a direct ref to wherever its been used. I would then work through the config file, and extract the items of interest for the run date... HTH - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to define a true global across modules?
"alex23" <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen wrote: > > "robert" <[EMAIL PROTECTED]> wrote: > > > Fredrik Lundh wrote: > > > > http://www.effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm > > > > Or worse style - if you are too lazy to create a extra global variables module > > > (ab)use the __main__ module als "global": > > > import __main__ > > > __main__.mysemphore += 1 > > > Thanks - how could you possibly have guessed that I am lazy - does it show that > > much? *WEG* > > You could merge the two approaches and bind a more explicit name to > __main__: > > import __main__ as config > > config.mysemaphore = 0 > > It's a little clearer what you're subverting __main__ for here :) > > - alex23 Thanks - clever and clear! - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode/ascii encoding nightmare
"John Machin" <[EMAIL PROTECTED]> wrote: 8<--- > I strongly suggest that you read the docs *FIRST*, and don't "tinker" > at all. > > HTH, > John This is *good* advice - its unlikely to be followed though, as the OP is prolly just like most of us - you unpack the stuff out of the box and start assembling it, and only towards the end, when it wont fit together, do you read the manual to see where you went wrong... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: [DLC] ChiPy Monthly Meeting, Thursday 7:00 pm.
"Steve Holden" <[EMAIL PROTECTED]> wrote: > I don't suppose there's any chance that someone might be passing > Schaumberg on their way to this meeting? I'm teaching there, and a ride > would avoid me having to rent a car (and hence increase the probability > I'd make it). Where in the whole wide world is Schaumberg - "foam mountain" - is it near Koekenaap? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: [DLC] ChiPy Monthly Meeting, Thursday 7:00 pm.
"Steve Holden" <[EMAIL PROTECTED]> > Hendrik van Rooyen wrote: > > "Steve Holden" <[EMAIL PROTECTED]> wrote: > > > > > >>I don't suppose there's any chance that someone might be passing > >>Schaumberg on their way to this meeting? I'm teaching there, and a ride > >>would avoid me having to rent a car (and hence increase the probability > >>I'd make it). > > > > > > Where in the whole wide world is Schaumberg - "foam mountain" - is it near > > Koekenaap? > > > It appears to be about twenty miles West and slightly North of the > meeting venue. Zip code 60173, I believe, if that helps. > > regards > Steve That puts you on the North American continent - nowhere near Koekenaap - I am amazed that you are brave enough to be there, after implying that the locals do not understand irony... Anyway - a word of unwanted advice - avoid prominently high buildings, and beware of low flying aircraft.. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: substring search without using built in utils
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: 8<-- > Given a source list, find the offset of a target sub-list within the > source list, in other words, find for lists. > > i.e. search(source, target) returns n if source[n:n+len(target)] == target > for any sequence type. > > Yes, I know I'm changing the constraints of the problem. Now for a real > challenge, change the search from a one-dimensional data structure to two. > > (The solution is left as an exercise for the class.) do you mean like a cross word puzzle - find for fit both across and down, and possibly reversed too, in both dimensions? - sounds like a lot of nested loops to me... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Multithreaded C API Python questions
"Svein Seldal" <"svein at seldal dot com">wrote: 8<--- > I am dependent upon the ability to have to threads executing in python > land at the same time. How can this be done? call time.sleep(0.001) in each, as well as the main thread, to politely give the rest a chance Fiddle with the sleep times in your setup to get the best performance - and don't be misled into thinking that faster is better - its not always true - there comes a point where the overhead of swapping a thread consumes the total resource of the process, and no work gets done. - HTH - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K idea: why not drop the colon?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: 8<--- > >>> color = "blue" > >>> if color == "red" or "green" or "yellow": > ... print color, "is red or green or yellow" > ... > blue is red or green or yellow *grin* - this can be construed as a weakness in Python - Even COBOL compilers in the sixties would "add in" the implied "if color = " after each 'or', instead of bloody - mindedly thinking: ok the first condition is not true the second "condition" 's string is not empty, so take the true path... BUT - the other way leads naturally to abominations like: if color not equal to 'red' or 'green' or 'yellow' where 'green' and 'yellow' takes the "wrong" path, as neither is equal to red, when what you wanted was: if color not equal to 'red' and 'green' and 'yellow'... Long live de Morgan! In this Python simply requires you to be specific in what you want, which is in a sense a GoodThing, seen as a BadThing by lazy programmers. And as for the colon : colon schmolon - its irrelevant either way, but if the interpreter requires it, you have no choice but to type it... Programming is basically about guessing what was in the mind of the compiler writer. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K idea: why not drop the colon?
"Dan Lenski" <[EMAIL PROTECTED]> wrote: > Hendrik van Rooyen wrote: > > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > > > > 8<--- > > > >>> color = "blue" > > > >>> if color == "red" or "green" or "yellow": > > > ... print color, "is red or green or yellow" > > > ... > > > blue is red or green or yellow > > > > *grin* - this can be construed as a weakness in Python - > > > > Even COBOL compilers in the sixties would "add in" the implied > > "if color = " after each 'or', instead of bloody - mindedly thinking: > > How the heck could this be considered a weakness in Python? I *like* > the fact that Python does not do anything "automagical" and rewrite > expressions, thinking it's smarter than the programmer. That's one > reason I got sick of Perl. > > There are plenty of cases where I might want to use an expression like > "color == red or foo or bar" with the semantics it actually implies in > Python. Making an exception for literal strings specifically seems > reallly dubious given the fact that Python already has an easy way to > do what you want with the "color in (red, green, blue)" construct. > This supposedly lacking feature would only be desired by people who > have been brain-damaged by programming languages like BASIC and > COBOL... or newbies who haven't programmed enough to really "get" > Boolean logic. > > Dan I am amazed by the reaction my grin and weakness comment has drawn - it looks as if both you and the effbot did not bother to read and try to understand the rest of that post, which gave an example of why the python way is in fact good... I apologise if my example is meaningless to people whose brains have not been damaged by experience yet. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: explicit self revisited
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote: > Especially since there is a comefrom *breaks into song* : "Oh Susannah, now don't you cry for me..." -- http://mail.python.org/mailman/listinfo/python-list
Re: Random image text generation?
From: "Leif K-Brooks" <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > For a text only solution, consider putting up a natural language question > > such as: > > > > What is the third letter of 'national'? > > What is four plus two? > > How many eggs in a dozen? > > Fill in the blank: Mary had a little its fleece was white as snow. > > Cat, Dog, Apple, Bird. One of those words is a fruit. Which one? > > That wouldn't work as a true CAPTCHA (Completely Automated *Public* > Turing test to tell Computers and Humans Apart), since making the list > of questions and answers public would defeat its purpose. you could consider keeping these answers secret - the spammers would then be stymied... -- http://mail.python.org/mailman/listinfo/python-list
Re: Data structure for ordered sequence
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > > unless this is homework because the pil people will not let > > you distribute pils. > > I'm not sure I can parse this sentence fragment. What do you mean? oh come on! - you of all people should know that "pils" means mushroom... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python development time is faster.
"Chris Brat" <[EMAIL PROTECTED]> wrote: > I've seen a few posts, columns and articles which state that one of the > advantages of Python is that code can be developed x times faster than > languages such as <>. > > Does anyone have any comments on that statement from personal > experience? > How is this comparison measured? I don't think it can be, objectively - comparing two teams, one using language "a", and the other python, to do a task, is simply comparing the skill levels of the two teams - and using the same team to do the same task in two different languages is also misleading, because of the experience gained in the first iteration. Python is actually astonishing - it seems to "fit the brain" of a large number of people - it is very easy to get started with, and is rich enough to keep surprising you - even after considerable time hacking around with it. It can do OO, but you can also write procedures in it, and you can even mix the two in the same module, and most of the time it "just works" - and when it doesn't, it is normally very easy to teach yourself what you are doing wrong by playing at the interactive interpreter prompt. This makes for productivity, as you can write quite complex things in a day or so, from scratch, such as: A single pass "assembler" for a virtual machine with 33 instructions - from nothing to running, fully debugged, in two days. A simple sliding window protocol - coded up from nothing in four days - mostly spent staring into space, imagining problems, instead of coding... so the "design" time is included... but its not working yet, as I have to write the other side in assembler on a very small machine, which would normally have taken me almost a month, but that will now probably take about two weeks, as I have the Python code to translate... And I am not a guru on this group, and I have just idly mucked around with Python for about a year in real time, not doing it full time, or making any real effort to study the language formally beyond lurking here - there are other people here on this group who, I am sure, could beat the hell out of these times, both for the design and the coding. So to sum up my personal perspective - it is very worth while to know a little python, even if you just use it as a prototyping language - it gets you going rapidly... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K idea: why not drop the colon?
"Simon Brunning" <[EMAIL PROTECTED]> Wrote: > On 11/11/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > Hendrik van Rooyen wrote: > > > > >> blue is red or green or yellow > > > > > > *grin* - this can be construed as a weakness in Python - > > > > it's boolean logic, and it's incompatible with human use of the same > > terms in all contexts, not just Python. > > Indeed. > > The other day, I way showing my eight year old, Freja, what a program > looks like: > > your_name = raw_input("What's your name? ") > if your_name.lower() == "freja": > print "You're very stinky,", your_name > else: > print "You smell lovely, ", your_name > > After running it a couple of times, she dove in and changed the 2nd line to: > > if your_name.lower() == "daddy or ella": > > (Ella is my other daughter's name.) That's pretty close to correct, > I'd say - but you don't get anything for being close in a programming > language. This is true - and it is actually also an intractable problem - if you look at what your daughter wrote, you get the feeling that you should be able to write an interpreter that can implement what she meant, because it is quite clear to you - until you try to write the specs... Your daughter, btw, will go far if she already has the guts to do that... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K idea: why not drop the colon?
"Robert Kern" <[EMAIL PROTECTED]> wrote: > Michael Hobbs wrote: > > True enough. Although, I have to ask how many times you define a new > > function only to have Python spit a syntax error out at you saying that > > you forgot a colon. It happens to me all the time. (Usually after an > > "else") If you'd never notice that the colon was missing if the compiler > > didn't point it out, is it really that readable? For me, I tend to get > > annoyed at language "features" that I'm constantly tripping over. > > Never. I confess I find myself in the position of a Yorkshire Youngster - I don't believe you! - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K idea: why not drop the colon?
"Dan Lenski" <[EMAIL PROTECTED]> wrote: > I think part of learning to think like a computer is learning to stop > associating computer logic too strongly with the natural language > meanings of "and", "or", and "not". This is true - and you have left out "but" - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python v PHP: fair comparison?
Olexandr Melnyk wrote: > PHP has a lower barrier to entry I don't think so. Python has more intuitive syntax for beginners and is one of the best choices for the first programming language to pick up. I second this - before discovering Python (in a GSM module's guts) - I was being steered in the direction of PHP by a friend - and I resisted, kicking and screaming, as I found the syntax weird - I believe its not called Personal Home Page for nothing... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
"Fredrik Tolf" <[EMAIL PROTECTED]> wrote: > I was thinking that maybe it could be possible to load and run untrusted > Python code, simply by loading it in a module with a modified version of > __builtins__. Without any reachable function that do unsafe operations, > code running from there shouldn't be able to do evil things. google for "sandbox" - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal() instead of float?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > .. and seriously, under- > standing the various aspects of floats and decimals is utterly trivial > compared to all the nearly-magical things you need to understand to be > able to do geographical calculations at a sub-millimeter scale. heck, > even sub-kilometer stuff is pretty hard to get right ;-) This is true - have you looked at that thing they call a geode? - horrible... I can never understand why people grab for floats at the first opportunity. To my simple mind, it seems better to work with a sub unit, and to stick to integer arithmetic - if, as Steve said, there is a speed penalty for changing from floats to decimal. then you can make even a cripple processor look good by sticking to integers - unless you run out of precision... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal() instead of float?
"John Salerno" <[EMAIL PROTECTED]> wrote: > John Machin wrote: > > > Here in Austraila, (I expect this is common to most countries), there > > are people who are utterly clueless about elementary data model rules, > > like identification "numbers" should be kept as strings. > > Do you mean that ID numbers that serve as a primary key in a database > should also be strings? Nothing wrong with doing that - its not as if you are going to arithmetic with them - adding my id to yours is generally not very useful... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K idea: why not drop the colon?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > have anyone counted the number of colons used in this way by the OP, > in his first few posts ? (if there isn't a name for the law that > states that the number for a "let's remove the colons" proposal is > always greater than zero, someone should come up with one...) You just have - how do you want it to be immortalised? The effbot's law of colonic inevitability? - Badger (for Steve) -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
"Stephan Kuhagen" <[EMAIL PROTECTED]> wrote: > The problem with linux kernel limits are, that they won't work really good > on MacOSX and Windows... OTOH the idea is the right one, but the effect can > be achieved inside of Python. Since Python does byte compile the code and > the interpreter evaluates each byte code token in one evaluation step. The > interpreter could be extended for such usecases to count and limit the > number of evaluation steps allowed for untrusted script or methods in > untrusted script as well as to limit the recursion depth or memory to be > allocated. All those limits are managed by the interpreter for script code > and hence can be limited for untrusted code by the interpreter. This also > does not really make DoS impossible (what about C extensions? - maybe > restricting "import"?). - As I said before in this thread, making a sandbox > really secure is a hard job, and may need some serious changes in the > Python interpreter, but AFAIK from Tcl, it is possible - and would be nice > to have. I seem to recall previous discussion on this group about a thing called the bastion module, and that it was deprecated. Not sure if it has any relevance. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
"Stephan Kuhagen" <[EMAIL PROTECTED]> wrote: > The problem with linux kernel limits are, that they won't work really good > on MacOSX and Windows... OTOH the idea is the right one, but the effect can > be achieved inside of Python. Since Python does byte compile the code and > the interpreter evaluates each byte code token in one evaluation step. The > interpreter could be extended for such usecases to count and limit the > number of evaluation steps allowed for untrusted script or methods in > untrusted script as well as to limit the recursion depth or memory to be > allocated. All those limits are managed by the interpreter for script code > and hence can be limited for untrusted code by the interpreter. This also > does not really make DoS impossible (what about C extensions? - maybe > restricting "import"?). - As I said before in this thread, making a sandbox > really secure is a hard job, and may need some serious changes in the > Python interpreter, but AFAIK from Tcl, it is possible - and would be nice > to have. I seem to recall previous discussion on this group about a thing called the bastion module, and that it was deprecated. Not sure if it has any relevance. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
"Stephan Kuhagen" <[EMAIL PROTECTED]> wrote: > The problem with linux kernel limits are, that they won't work really good > on MacOSX and Windows... OTOH the idea is the right one, but the effect can > be achieved inside of Python. Since Python does byte compile the code and > the interpreter evaluates each byte code token in one evaluation step. The > interpreter could be extended for such usecases to count and limit the > number of evaluation steps allowed for untrusted script or methods in > untrusted script as well as to limit the recursion depth or memory to be > allocated. All those limits are managed by the interpreter for script code > and hence can be limited for untrusted code by the interpreter. This also > does not really make DoS impossible (what about C extensions? - maybe > restricting "import"?). - As I said before in this thread, making a sandbox > really secure is a hard job, and may need some serious changes in the > Python interpreter, but AFAIK from Tcl, it is possible - and would be nice > to have. I seem to recall previous discussion on this group about a thing called the bastion module, and that it was deprecated. Not sure if it has any relevance. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
"Stephan Kuhagen" <[EMAIL PROTECTED]> wrote: > The problem with linux kernel limits are, that they won't work really good > on MacOSX and Windows... OTOH the idea is the right one, but the effect can > be achieved inside of Python. Since Python does byte compile the code and > the interpreter evaluates each byte code token in one evaluation step. The > interpreter could be extended for such usecases to count and limit the > number of evaluation steps allowed for untrusted script or methods in > untrusted script as well as to limit the recursion depth or memory to be > allocated. All those limits are managed by the interpreter for script code > and hence can be limited for untrusted code by the interpreter. This also > does not really make DoS impossible (what about C extensions? - maybe > restricting "import"?). - As I said before in this thread, making a sandbox > really secure is a hard job, and may need some serious changes in the > Python interpreter, but AFAIK from Tcl, it is possible - and would be nice > to have. I seem to recall previous discussion on this group about a thing called the bastion module, and that it was deprecated. Not sure if it has any relevance. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
"Fredrik Lundh" <[EMAIL PROTECTED]> Wrote: 8< | (I still think a "join" built-in would be nice, though. but anyone who | argues that "join" should support numbers too will be whacked with a | great big halibut.) | | Strange this - you don't *LOOK* like a Gaulish Blacksmith... -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a good idea or a waste of time?
"Simon Forman" <[EMAIL PROTECTED]> wrote: 8<- | BTW, speaking of "strictness", "more stricter" is invalid English, | just "stricter" is the "correct" form. ;-) or alternatively the construct "more strict" is also acceptable - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Consistency in Python
Hi, for S where S is a Standard Python type: The slice notation S[n] returns either: The n'th element of S, or The value of the dictionary entry whose key is n. This is beautiful because as a programmer you don't have to worry what S is... (and as an aside - This consistency has already saved my butt when I thought I was working with a string that turned out to be a tuple instead - and still worked perfectly as expected...) Now consider what you have to do to add an element to S... (where "add" is used in its meaning of increasing the size of a set, and not 1 + 1 = 2) There seems to be no common methods such as- "prepend" - for adding something to the beginning "append" - for adding something to the end "insert[j]" - for adding something somewhere in the middle Or have I missed something ? Is there a reason for this lack - or is it simply that the language has "just growed" ? Are there any plans afoot to do this kind of tidying up in the places where it makes sense? BTW - I understand that some things are immutable - but that is an implementation detail, not a language issue. - the fact that you get the name S bound to a new object is irrelevant to a discussion about how you tell the interpreter to do something... Any other thoughts - such as making a kind of opposite to del instead ? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Fw: Is this a good idea or a waste of time?
"Simon Forman" <[EMAIL PROTECTED]> wrote: 8<- | BTW, speaking of "strictness", "more stricter" is invalid English, | just "stricter" is the "correct" form. ;-) or alternatively the construct "more strict" is also acceptable - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Fw: Is this a good idea or a waste of time?
"Simon Forman" <[EMAIL PROTECTED]> Wrote: | Hendrik van Rooyen wrote: | > "Simon Forman" <[EMAIL PROTECTED]> wrote: | > | > 8<- | > | > | BTW, speaking of "strictness", "more stricter" is invalid English, | > | just "stricter" is the "correct" form. ;-) | > | > or alternatively the construct "more strict" is also acceptable - Hendrik | | It is, but technically it's not. English is more bizarrer that that.. LOL! | It depends or the number of syllables in the word: one or two, add | '-er'; three or more (or if the two-syllable-er word "sounds lame"), | use "more"... | | English, the perl of natural languages.. lol (Apparently Dutch is | pretty weird too..) | | Peace, | ~Simon *grin* my Dutch is Dangerous - its actually Afrikaans - a highly simplified variant that is poison to good Dutch... I like the rule about the syllables - would never remember it in the heat of battle though... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Consistency in Python
"Paul Boddie" <[EMAIL PROTECTED]> Wrote: | Hendrik van Rooyen wrote: | > | > There seems to be no common methods such as- | > "prepend" - for adding something to the beginning | > "append" - for adding something to the end | > "insert[j]" - for adding something somewhere in the middle | > | > Or have I missed something ? | | [...] | | > BTW - I understand that some things are immutable - but that is an | > implementation detail, not a language issue. - the fact that you get the name S | > bound to a new object is irrelevant to a discussion about how you tell the | > interpreter to do something... | | You haven't missed one of the principal reasons exactly, but you | underestimate its importance. There aren't such methods as append or | insert on strings or tuples precisely because those objects are | immutable, whilst such methods on lists and other mutable objects | change the contents of such objects. Moreover, append and insert return | no result because the change occurs within an existing object - if you | were to return a reference to the changed object, it would be the same | reference as the one you already had. | | # Append on lists: | l.append(something) # returns nothing (you'll get None) | | Now, you could argue that insert and append should always return a | reference to some object, and that for lists (and other mutable | objects) it should return the same reference (to the changed object), | whereas for strings (and other immutable objects) it should return a | different reference (to an object which has the changed contents of the | original object). | | # Fictional append on strings: | s2 = s.append(sometext) # s would be the same, s2 different | # Fictional append variant on lists: | l2 = l.append(something) # l and l2 would be the same Lovely - this is exactly what I am thinking about... | | However, there's a sort of unwritten guarantee - although it could be | in the documentation - that the append and insert methods specifically | mutate objects and that they therefore have no place in immutable | objects. Certainly, the behaviour illustrated above could be surprising | in some kinds of programs because the append method on strings would be | more like a factory or a copy constructor rather than a "mutator". | | Now, you could argue that the name involved could be hacked in some | magical way, thus preserving the illusions that strings are mutable, | but what happens when a name is not involved? | | s.append(sometext) # s gets replaced | (text + moretext).append(sometext) # what gets replaced? nothing really - this thing standing on its own is kind of "outside" the language - If I do not have a name for you, I can't order you about - and the same is true here - the result is just a string that is used wherever its needed, as a literal would be : "this is a string" + " Here is some more" ("is" being used in the sense of "should be" - we are talking hypothetics here and not how stuff actually "is") | | Mutability is more than a mere implementation detail: in imperative | languages, it's probably one of the most underrated mechanisms | influencing the correct behaviour of programs. | | Paul This could be true - its just that, as an assembler type person - the notion that some parts of memory is "cast in concrete" is kind of strange to me... I understand that when you do something like giving a dict a key and tie a value to the key - its dangerous to change the key - it would be a very smart implementation indeed that can track the changes to such a key - but I can see no value in solving the problem by making the key "Immutable" - it is a natural consequence (at least in my mind) that when you store something in one way, you have to use exactly the same way to retrieve it - but I don't think it should be a language rule to try to protect a programmer from his own stupidity in such cases - so if I do something like: PaulsName = "Paul Buddie" and I use that as a key in my telephone directory, and then I see the error, and I do PaulsName = "Paul Boddie" and I try to get at the information I have stored earlier, using the same symbolic name - it aint gonna work... And I accept this - its not what I am on about - I still think it would be nicer if there were these commands to do the prepend insert append job, instead of doing it laboriously using slicing. (Aside: note that in the above the "value" tied to the symbolic name "PaulsName" has actually changed - so what is immutable about it from this perspective? if I can do this - why bother with immutability? ) Think for instance of the hoops you have to jump through to calculate the checksum on an Intel hex, or Motorola s file, and to make a string that you can write to a file or send to a serial port... Thanks for the reasoned reply, btw - I appreciate it! - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Consistency in Python
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote, oder schrieb, of het geskryf: | Hendrik van Rooyen schrieb: | > Hi, | > | > for S where S is a Standard Python type: | > The slice notation S[n] returns either: | > The n'th element of S, or | > The value of the dictionary entry whose key is n. | > | > This is beautiful because as a programmer you don't have to worry what S is... | > (and as an aside - This consistency has already saved my butt when I thought I | > was working with a string that turned out to be a tuple instead - and still | > worked perfectly as expected...) | > | > Now consider what you have to do to add an element to S... | > (where "add" is used in its meaning of increasing the size of a set, and not 1 + | > 1 = 2) | > | > There seems to be no common methods such as- | > "prepend" - for adding something to the beginning | > "append" - for adding something to the end | > "insert[j]" - for adding something somewhere in the middle | > | > Or have I missed something ? | | Yes, the nature of collections. dictionaries have no notion of | "somewhere in the middle". Most of the time they are unordered. If they | are ordered, they can be ordered by insertion time, key or value value. | And they always need key, value | | So - all these three methods only make sense on sequences which imply a | key (the index), and are mutable of course - which is why they are | available on lists only. | | Diez I understand that dicts are actually a bit special - Its very simple to add something to a dict - you just do it - but the in the other cases what I have in mind is more in line with some of what Paul Boddie wrote... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: How to let a loop run for a while before checking for break condition?
"Claudio Grondi" <[EMAIL PROTECTED]> Wrote: | Fredrik Lundh wrote: | > Diez B. Roggisch wrote: | > | >> A while loop has a condition. period. The only thing to change that is | >> to introduce a uncoditioned loop, and use self-modifying code to make | >> it a while-loop after that timer interrupt of yours. | > | > | > or use a timer interrupt to interrupt the loop: | > | > import signal, time | > | > def func1(timeout): | > | > def callback(signum, frame): | > raise EOFError # could use a custom exception instead | > signal.signal(signal.SIGALRM, callback) | > signal.alarm(timeout) | > | > count = 0 | > try: | > while 1: | > count += 1 | > except EOFError: | > for i in range(10): | > count += 1 | > print count | > | > for an utterly trivial task like the one in that example, the alarm | > version runs about five times faster than a polling version, on my test | > machine (ymmv): | > | > def func2(timeout): | > | > gettime = time.time | > t_limit = gettime() + timeout | > | > count = 0 | > while gettime() < t_limit: | > count += 1 | > for i in range(10): | > count += 1 | > print count | > | > | > | | This above is exactly what I am looking for, except it does not work in | Microsoft Windows where the signal.alarm() function is not available. | | So now the only thing I would like to know is how to achieve the same | functionality when running Python on a Microsoft Windows box. | | Claudio Grondi It looks to me - but I could be wrong - that the time saved here is not because of the condition test being replaced by the try-except, but because of the fact that the call to gettime was eliminated - so you may get the most mileage by using in line code in your loop that avoids calls to subroutines and simply let it run and test for the end of the counter... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: How to let a loop run for a while before checking for breakcondition?
"Claudio Grondi" <[EMAIL PROTECTED]> wrote: | Diez B. Roggisch wrote: | > Claudio Grondi schrieb: | > | >> | >> Sometimes it is known in advance, that the time spent in a loop will | >> be in order of minutes or even hours, so it makes sense to optimize | >> each element in the loop to make it run faster. | >> One of instructions which can sure be optimized away is the check for | >> the break condition, at least within the time where it is known that | >> the loop will not reach it. | >> | >> Any idea how to write such a loop? | >> | >> e.g. | >> | >> counter = 2*64 | >> | >> while counter(BUT DON'T CHECK IT THE FIRST ONE HOUR LONG): | > | > | > now = time.time() | > while time.time() - now < 3600.0 or some_other_condition: | >... | > | > | > The short circuiting of the or will prevent the execution of | > some_other_condition. | > | >> ... do something ... # and decrease the counter | >> | >> Thanks for any hint, but in particular if related to timers on the | >> Windows 2000/XP system I am mainly working with. | >> | >> What do you think about this idea? Does it make sense? | > | > What idea? | This one you haven't probably got from what I have written. | I thought, that the introductory text gives enough context to be able to | see what I mean, but I was apparently wrong. | | The idea is to speed up a loop by using a timer interrupt interfering | with the loop, so that only after the timer interrupt would occur, the | loop will start to check its break condition in each iteration. | No checking of any kind in the loop should happen up to that time to | minimize the number of operations in each iteration within the loop | itself (i.e. the loop more or less won't know, that there is a timer on | its way to change the loops behavior at a later time). | | I hope this above helps to understand what I would like to achieve. | | Claudio Grondi I don't think this is usefully possible in python - the problem is that you will simply replace one check - The expiry of the counter - with another - to see if the interrupt has occurred already - That said - the way I would do it would be to do something like this (in horrible pseudo code): loop_start: do_something() jump loop_start if counter > end_value: break jump loop_start loop_end: Interrupt_routine: replace the first jump to loop_start with a bunch of no - ops return I don't think you can do this in python - it involves altering the running loop - but hey maybe I can learn something here... This example sort of exposes the break for what it is - a jump statement in disguise - "look you cant recognise me - I am wearing dark glasses" - and "continue" is exactly like that too - the only difference is that the one jumps to the end, and the other to the beginning of the loop... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: time.clock() going backwards??
"Grant Edwards" <[EMAIL PROTECTED]> Wrote: | On 2006-08-28, Grant Edwards <[EMAIL PROTECTED]> wrote: | | >>> For processors that run at (say) 2GHz, several million (say 10 | >>> million) represents a difference of 10e6/2e9 = 0.005 seconds | >>> between when the processors were sufficiently powered up to | >>> start counting cycles. | > | >> If it were so, than why can't the delta of time between the | >> processors be set to exact zero? | > | > This is | | Oops. Hit the wrong key. I meant to say: Thank god! - I know you are not an idiot - and for some minutes you had me guessing - I was beginning to think that my brain had finally been destroyed by drink - trying to figure out this enigmatic post... :-) - Hendrik 8<- -- http://mail.python.org/mailman/listinfo/python-list
Re: How to let a loop run for a while before checking for break condition?
"Claudio Grondi" <[EMAIL PROTECTED]> wrote: 8<- | The test of the counter is what actually slows the loop down. Probably | the test of time slows the loop even more down. Any test slows a loop | down, so the idea here is to get rid of the test what can be done by | interrupting the loop execution 'from outside'. | Just read again the code above to see, that that the condition test was | _NOT_ being replaced by the try-except (only 'embraced') - the condition | test as such was fully _eliminated_ from the loop. | | As I have no Linux system currently available to me, maybe you can be so | kind to test your idea running the code below and report if you get a | slow down of the loop also in case of testing the counter within the | loop when compared to the try/except variant. Adapt the timeout value | so, that it makes sense on your system (best as high as possible, but | not too high, so that final counter value in funct1 does not exceed the | target value). | | | import signal, time | | def func1(timeout): | | def callback(signum, frame): | raise EOFError # could use a custom exception instead | signal.signal(signal.SIGALRM, callback) | signal.alarm(timeout) | | count = 0 | try: | while 1: | count += 1 | except EOFError: | while True: | count += 1 | if count < 0x500: | break | print hex(count) | | def func2(): | | count = 0 | while True: | count += 1 | if count < 0x500: | break | print hex(count) | | print | startTime = time.clock() | funct1(10) | print time.clock() - startTime | | print | print | startTime = time.clock() | funct2() | print time.clock() - startTime | | | | Claudio Grondi OK - copied this stuff over to my Linux box as a file junk.py in directory junk: ran it, and I got: > ls junk.py > python junk.py Traceback (most recent call last): File "junk.py", line 32, in ? funct1(10) NameError: name 'funct1' is not defined TUT - TUT! so fixed the names, ran it, and I got: > python junk.py 0x1c142af 5.41 0x1 0.0 > Not very helpful - so I changed the time.clock to time.time, ran it, and I got: > python junk.py 0x1aa21ea 10.0033490658 0x1 0.000311851501465 then I actually read the code and changed the less thans to greater thans... > python junk.py 0x501 66.8134140968 0x501 76.9292650223 so yup, it makes a difference so then I messed with the timeout, setting it to 40 secs: > python junk.py 0x5ecd34a 40.0047910213 0x501 89.4619050026 so it helps (it seems) to let it run longer before starting to test - but comparing one run against the other is not very illuminating - this was slower, as shown by the unchanged second loop's timing, and yet the first one did more in 40 secs than in the previous run time of 66 secs... Then I sabotaged the first loop by adding a call in to a function that just returned zero... > python junk.py 0x501 160.986829996 0x501 75.8728411198 the call is more expensive than the add... so the more you do, the longer it takes (TradeMark)... Here is the code as it is now: import signal, time def func1(timeout): def callback(signum, frame): raise EOFError # could use a custom exception instead signal.signal(signal.SIGALRM, callback) signal.alarm(timeout) count = 0 try: while 1: count += 1 error = func3() except EOFError: while True: count += 1 error = func3() if count > 0x500: break print hex(count) def func2(): count = 0 while True: count += 1 if count > 0x500: break print hex(count) def func3(): return 0 print startTime = time.time() func1(40) print time.time() - startTime print print startTime = time.time() func2() print time.time() - startTime HTH - Hendrik -- http://mail.python.org/mailman/listinfo/python-list