gdesklets __import__ problem
Hi, I'm writing a gdesklets control, that dynamicly uses __import__ and getattr to get the right classes based on userinput. The problem is, that my control is somehow being run from somewhere unknown. This means that __import__ can't find the modules. I tried putting an os.chdir("~/.gdesklets/Controls/1136298021.06/...") just before the __import__ call, and that worked, but ofcource isn't very smart in the run. Is there any way to find out where the control is put on the disk, so that I can change to the correct folder? Or is there some hack, that allows me to import the modules without knowing there location? -- Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to read and interpret the "scripture" of this age. -- http://mail.python.org/mailman/listinfo/python-list
Getting module location
Is it possible for an imported module to find its own location? -- Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to read and interpret the "scripture" of this age. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting module location
Den Thu, 05 Jan 2006 14:53:40 +0800. skrev limodou: > 2006/1/5, Thomas Dybdahl Ahle <[EMAIL PROTECTED]>: >> Is it possible for an imported module to find its own location? > > you can access __file__(missing for built-in modules) or __path__(used > for a package) attribute to find a module's location. Super, what I needed seems to be os.chdir(os.path.dirname(__file__)). Works flawlessly. Thank you. -- Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to read and interpret the "scripture" of this age. -- http://mail.python.org/mailman/listinfo/python-list
Python daemon process
Hi, I'm writing a program, using popen4(gnuchess), The problem is, that gnuchess keeps running after program exit. I know about the atexit module, but in java, you could make a process a daemon process, and it would only run as long as the real processes ran. I think this is a better way to stop gnuchess, as you are 100% sure, that it'll stop. Can you do this with popen? -- Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python daemon process
I might not have made myself very clear, since you both got me wrong. What I need, is not a method to terminate a process, but a way to terminate a process when the main process dies. >From the atexit module info: Note: the functions registered via this module are not called when the program is killed by a signal, when a Python fatal internal error is detected, or when os._exit() is called. I belive that there is noway you can be sure to get a piece of code run, if the program crashes or something like that, therefor I ask for a way to run gnuchess as a kind of subprocess, that can only run when the parrentprocess is still running. I know this is called a daemon thread in java. > 2006/8/26, Thomas Dybdahl Ahle <[EMAIL PROTECTED]>: >> Hi, I'm writing a program, using popen4(gnuchess), >> The problem is, that gnuchess keeps running after program exit. >> >> I know about the atexit module, but in java, you could make a process a >> daemon process, and it would only run as long as the real processes ran. I >> think this is a better way to stop gnuchess, as you are 100% sure, that >> it'll stop. >> >> Can you do this with popen? >> >> -- >> Thomas >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > You could send the quit (or close or wahtever) command to gnuchess > when you want it to terminate. Supposing that gnuchess needs to do > some stuff on exit, this is a better solution. > > PAolo -- Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to read and interpret the "scripture" of this age. -- http://mail.python.org/mailman/listinfo/python-list
subprocess leaves child living
Hi, When I do a small program like from subprocess import Popen popen = Popen(["ping", "google.com"]) from time import sleep sleep(100) start it and kill it, the ping process lives on. Is there a way to ensure that the ping process is always killed when the python process is? I can't use atexit, as ping then isn't killed when python is killed "in the hard way" -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess leaves child living
Den Tue, 05 Jun 2007 14:07:44 +0200 skrev Stefan Sonnenberg-Carstens: > Thomas Dybdahl Ahle schrieb: >> Hi, When I do a small program like >> >> from subprocess import Popen >> popen = Popen(["ping", "google.com"]) from time import sleep >> sleep(100) >> >> start it and kill it, the ping process lives on. Is there a way to >> ensure that the ping process is always killed when the python process >> is? >> I can't use atexit, as ping then isn't killed when python is killed "in >> the hard way" >> > Calling popen.close() perhaps ? > You basically open a pipe, which spawns a shell and the command is then > started in there. > So, if your program quits, the spawned shell is still alive, only the > pipe is dead. Problem is - I can't do that when I get killed. Isn't it possible to open processes in such a way like terminals? If I kill the terminal, everything open in it will die too. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess leaves child living
Den Tue, 05 Jun 2007 07:06:15 -0700 skrev Rob Wolfe: > Thomas Dybdahl Ahle wrote: > >> Problem is - I can't do that when I get killed. Isn't it possible to >> open processes in such a way like terminals? If I kill the terminal, >> everything open in it will die too. > > On POSIX platform you can use signals and ``os.kill`` function. Fo > example: > > > import os, signal > from subprocess import Popen > from time import sleep > > def handler(signum, frame): > print 'Signal handler called' > raise KeyboardInterrupt > > signal.signal(signal.SIGTERM, handler) > > try: > popen = Popen(["ping", "google.com"]) try: > sleep(100) > except KeyboardInterrupt: > pass > finally: > if popen.poll() is None: > print "killing process: %d" % popen.pid os.kill(popen.pid, > signal.SIGTERM) > But you can't ever catch sigkill. Isn't there a way to make sure the os kills the childprocess when the parrent dies? -- http://mail.python.org/mailman/listinfo/python-list
Strange errors on exit
When I close my (gtk) program, I get errors like the below. It seams that when the interpreter shuts down, it sets every variable to None, but continues running the threads, (seems only in cases where they've just been asleep) I don't think this would be intended behavior? Exception in thread Thread-4 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap File "/home/thomas/Programmering/python/skak/0.7/lib/pychess/System/ ThreadPool.py", line 49, in run File "/usr/lib/python2.4/Queue.py", line 89, in put File "/usr/lib/python2.4/threading.py", line 237, in notify exceptions.TypeError: exceptions must be classes, instances, or strings (deprecated), not NoneType Unhandled exception in thread started by Error in sys.excepthook: Original exception was: -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess leaves child living
Den Tue, 05 Jun 2007 22:01:44 +0200 skrev Rob Wolfe: > Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: > >> But you can't ever catch sigkill. > > There is no protection against sigkill. > >> Isn't there a way to make sure the os kills the childprocess when the >> parrent dies? > > If the parent dies suddenly without any notification childprocesses > become zombies and there is no way to avoid that. If I call "kill -9 pythonpid" on the python code you posted earlier, the terminal running the script will continue pinging forever. If it was a harder program like a chessengine or such, it would continue consuming 100% cpu time. Zombies would be fine to me. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess leaves child living
Den Tue, 05 Jun 2007 15:46:39 -0500 skrev Michael Bentley: > But actually *that* is an orphan process. When a parent process dies > and the child continues to run, the child becomes an orphan and is > adopted by init. Orphan processes can be cleaned up on most Unices with > 'init q' (or something very similar). Is it not possible to tell python that this process should not be adopted by init, but die with its parrent? Just like terminals seem to do it.. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess leaves child living
Den Tue, 05 Jun 2007 17:41:47 -0500 skrev Michael Bentley: > On Jun 5, 2007, at 5:13 PM, Michael Bentley wrote: > > >> On Jun 5, 2007, at 4:17 PM, Thomas Dybdahl Ahle wrote: >> >>> Den Tue, 05 Jun 2007 15:46:39 -0500 skrev Michael Bentley: >>> >>>> But actually *that* is an orphan process. When a parent process dies >>>> and the child continues to run, the child becomes an orphan and is >>>> adopted by init. Orphan processes can be cleaned up on most Unices >>>> with >>>> 'init q' (or something very similar). >>> >>> Is it not possible to tell python that this process should not be >>> adopted >>> by init, but die with its parrent? >>> Just like terminals seem to do it.. >> >> Well, the way you posed the original question: >> >>> from subprocess import Popen >>> popen = Popen(["ping", "google.com"]) from time import sleep >>> sleep(100) >> >> is really what adoption by init is designed to handle. Here you've >> created a child but have not waited for its return value. Like a good >> adoptive parent, init will wait(2) for the child. >> >> I think if you really looked into it you'd find that the terminal had >> called wait(2) before it was killed. Similarly, if you start a long- >> running subprocess in python and wait for it to return -- killing the >> parent will slaughter the child as well. > > I guess I should have verified my suspicions before speaking up -- I was > worng -- even if you are waiting for a return code, the child will > persist as a child of init. Bugger. I know that if you use forkpty, the child get slaughtered, but using the subprocess module just seems much easier than forking. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess leaves child living
Den Thu, 07 Jun 2007 07:00:53 + skrev reed: > On Jun 5, 7:58 am, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: >> Hi, When I do a small program like >> >> from subprocess import Popen >> popen = Popen(["ping", "google.com"]) from time import sleep >> sleep(100) >> >> start it and kill it, the ping process lives on. Is there a way to >> ensure that the ping process is always killed when the python process >> is? >> I can't use atexit, as ping then isn't killed when python is killed "in >> the hard way" > > > > pid = popen.pid > pidfile = open('/usr/local/var/somefile.pid', 'w') pidfile.write('pid') > pidfile.close() > then you can check if it is still running when your ?program? restarts > and can kill it. If it restarts yeah. > maybe not the perfect answer, but it answers an imperfect question. Any details you need? -- http://mail.python.org/mailman/listinfo/python-list
Sort with extra variables
I have a sort function in a python chess program. Currently it looks like this: def sortMoves (board, table, ply, moves): f = lambda move: getMoveValue (board, table, ply, move) moves.sort(key=f, reverse=True) return moves However I'd really like not to use the lambda, as it slows down the code. I've thought about saving the extra variables in the global space, but it really feals ugly. Do you have any ideas how I can sort these moves the fastest? -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort with extra variables
Den Fri, 02 Mar 2007 21:13:02 +0100 skrev Bjoern Schliessmann: > Thomas Dybdahl Ahle wrote: > >> However I'd really like not to use the lambda, as it slows down the >> code. > > Did you check how much the slowdown is? Yes, the lambda adds 50% -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort with extra variables
Den Fri, 02 Mar 2007 11:44:27 -0800 skrev Paul Rubin: > Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: >> Do you have any ideas how I can sort these moves the fastest? > > One idea: if you're using alpha-beta pruning, maybe you can use > something like heapq instead of sorting, since a lot of the time you > only have to look at the first few moves (ordered best-first). Do you mean that I add my moves something like this? from heapq import heappush, heappop heap = [] for move in genAll(): heappush(heap, (-getMoveValue (board, table, ply, move), move)) And then use heappop(heap) in the alphabeta loop? I don't know much of heap queues, but it actually looks very smart. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort with extra variables
Den Fri, 02 Mar 2007 20:33:45 +0100 skrev Diez B. Roggisch: > Thomas Dybdahl Ahle schrieb: >> I have a sort function in a python chess program. Currently it looks >> like this: >> >> def sortMoves (board, table, ply, moves): >> f = lambda move: getMoveValue (board, table, ply, move) >> moves.sort(key=f, reverse=True) >> return moves >> >> However I'd really like not to use the lambda, as it slows down the >> code. >> >> I've thought about saving the extra variables in the global space, but >> it really feals ugly. >> >> Do you have any ideas how I can sort these moves the fastest? > > First of all, in your case it is somewhat strange to use > f = lambda ... > because then you could as well use > def f(move): > Wouldn't that be just as slow? > But that is just a general remark. Regarding the question: I don't see > how that could possibly become faster without much more insight into > what you are doing in getMoveValue. As it seems, it is dependend of a > lot of factors that change often, so caching it isn't a real option. And > I hope you are aware that the key-method is invoked only _once_ per > list-item! Yeah, key is a nice thing. My only problem is that I need these other objects to generate the value, and I don't want to create a new function each time.. In my profiling the functions with the lambda line says 860 cumtime and getMoveValue says 580. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort with extra variables
Den Fri, 02 Mar 2007 15:20:33 -0800 skrev MonkeeSage: > On Mar 2, 5:11 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: >> Wouldn't that be just as slow? > > Well, I'm not sure about speed, but with the lambda you're creating a > new callable for f every time you call sortMoves. Intuitively, that > seems like it would be more of a hit than just doing a lookup for a > predefined function. Mabye not though...you could time it and see. I guess the thing is that I'd have to create a new callable no matter how, as it is the only way to bring the extra variables into the getValue function when called by sort. -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and functions
Den Fri, 02 Mar 2007 19:26:08 -0300 skrev Silver Rock: > Friends, > > I don´t see why using classes.. functions does everything already. I > read the Rossum tutotial and two other already. > > Maybe this is because I am only writing small scripts, or some more > serious misunderstandings of the language. > > Please give me a light. I guess you are fimiliar with the string methods. You can do stuff like "hi hi".split(" ") or " hi".strip(). This is because a string is a class. The same functionality could be done by functions: split("hi hi", " ") and strip(" hi") but it feals more inituitive to put the dot after the variable. It also makes it easier to know where to look for functions related to the object. And yes, I'm sure you will see the light, when doing larger programs :) Don't worry. -- http://mail.python.org/mailman/listinfo/python-list
Re: How *extract* data from XHTML Transitional web pages? got xml.dom.minidom troubles..
Den Fri, 02 Mar 2007 15:32:58 -0800 skrev [EMAIL PROTECTED]: > I'm trying to extract some data from an XHTML Transitional web page. > xml.dom.minidom.parseString("text of web page") gives errors about it > not being well formed XML. > Do I just need to add something like or what? As many HTML Transitional pages are very bad formed, you can't really create a dom of them. I've written multiple grabbers, which grab tv data from html pages, and parses it into xml. Basicly there are three ways to get the info: # Use find(): If you are only searching for a few data pieces, you might be able to find some html code always appearing before the data you need. # Use regular expressions: This can very quickly get all data from a table or so into a nice list. Only problem is regular expressions having a little steep learing curve. # Use a SAX parser: This will iterate through all html items, not carring if they validate or not. You will define a method to be called each time it finds a tag, a piece of text etc. > What is best way to do this? In the beginning I mostly did the SAX way, but it really generates a lot of code, which is not necessaryly more readable than the regular expressions. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort with extra variables
Den Fri, 02 Mar 2007 16:27:47 -0800 skrev MonkeeSage: > On Mar 2, 5:51 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: >> I guess the thing is that I'd have to create a new callable no matter >> how, as it is the only way to bring the extra variables into the >> getValue function when called by sort. > > Yes, but you don't have to create it every time you call sortMoves... > > def sortKey(move): > return getMoveValue(board, table, ply, move) > > def sortMoves(board, table, ply, moves): > moves.sort(key=sortKey, reverse=True) return moves Well, you'd have to define the function inside the sortMoves function, as it is where the variables exists. def sortMoves(board, table, ply, moves): def sortKey(move): return getMoveValue(board, table, ply, move) moves.sort(key=sortKey, reverse=True) return moves Wouldn't that make it create the callable at each call? -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort with extra variables
Den Fri, 02 Mar 2007 16:46:05 -0800 skrev Paul Rubin: > Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: >> Do you mean that I add my moves something like this? >> >> from heapq import heappush, heappop >> heap = [] >> for move in genAll(): >> heappush(heap, (-getMoveValue (board, table, ply, move), move)) >> >> And then use heappop(heap) in the alphabeta loop? > > Yes, something like that. If you want to get, say, the five smallest > values in a list, heapq lets you do that without having to sort the > whole list. Yeah, I use this now. The only think I don't really like, is the need of creating a ton of tupples, but it doesn't show me too much it seams. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort with extra variables
Den Sat, 03 Mar 2007 11:26:08 +0100 skrev Diez B. Roggisch: >> Well, you'd have to define the function inside the sortMoves function, >> as it is where the variables exists. >> >> def sortMoves(board, table, ply, moves): >> def sortKey(move): >> return getMoveValue(board, table, ply, move) >> moves.sort(key=sortKey, reverse=True) return moves >> >> Wouldn't that make it create the callable at each call? > > Yes, it does. But it's only created _once_ per sortMoves-call, and > afterwards doesn't affect performance. Sure, but I'm having a LOT of sortMove calls ;) > And no, it's not slower than you lambda version - they _should_ be > equally fast, if not it's neglible. Sure, but the lambda version was too slow also. > And also doesn't affect sorting-performance. I know, but the sorting itself is really not the problem, as the lists only contain 5-30 items. -- http://mail.python.org/mailman/listinfo/python-list
Exception passing
Hi, I have a function, which looks like the following: connecting = False def func (): global connecting connecting = True try: # Do lot of network stuff except Exception, e: connecting = False raise e This works quite good, but it is a hell to debug. Instead of getting a log message to the line which originally raised the exception. Is there anyway to reraise an exception, but preserve the log? -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception passing
Den Fri, 23 Mar 2007 07:38:47 -0700 skrev Alex Martelli: > Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: >> This works quite good, but it is a hell to debug. Instead of getting a >> log message to the line which originally raised the exception. > As you see, the traceback is "maintained" when you just "raise", though > it's altered when you "raise e". Thanks a lot :D -- http://mail.python.org/mailman/listinfo/python-list
Sending ECHO_REQUEST (pinging) with python
Hi, I've writing a python application in which I'd like to have a small "ping label", to always tell the current ping time to the server. It seems however that I have to be root to send those imcp packages, but I guess there must be a workaround since I can easily use the "ping" command as ordinary user. Do anybody know how to do this in python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Sending ECHO_REQUEST (pinging) with python
Den Mon, 26 Mar 2007 11:24:34 +0200 skrev Michal 'vorner' Vaner: > On Mon, Mar 26, 2007 at 08:30:16AM +0200, Thomas Dybdahl Ahle wrote: >> Do anybody know how to do this in python? > You need root for that and the ping command is allowed to have them by > suid bit. You can execute ping from inside python and use ping as is, if > you need. Yeah, I could execute ping, but it would lock me harder to the platform. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sending ECHO_REQUEST (pinging) with python
Den Mon, 26 Mar 2007 06:30:04 -0500 skrev Nick Craig-Wood: > Michael Bentley <[EMAIL PROTECTED]> wrote: >> On Mar 26, 2007, at 1:30 AM, Thomas Dybdahl Ahle wrote: >> > It seems however that I have to be root to send those imcp packages, >> > but I guess there must be a workaround since I can easily use the >> > "ping" command as ordinary user. >> >> The workaround your ping command is using btw, is probably running >> suid root. > > Under linux the only priviledge you need is CAP_NET_RAW. It is possible > to give this to a process - a bit of searching with google will show you > how! How, I did google, but I wasn't able to find any way to do this in python.. -- http://mail.python.org/mailman/listinfo/python-list
Kill thread or at least socket.getaddrinfo
Hi, I'm writing an application that connects to the internet. Something like this: for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.sock = socket.socket(af, socktype, proto) Now if the user press the cancel button, I'd like the connection to imidiatly stop. I run self.sock.shutdown(socket.SHUT_RDWR) self.sock.close() Dunno if they are both nessesary. I normaly use only the first, but it makes no difference to use both. If python is at the actual connection in socket.socket( this work fine, but if python is at calling socket.getaddrinfo(, it doesn't stop. I also can't kill the thread, as it is afaik not a possibility in python. Is there any other way to do this? -- http://mail.python.org/mailman/listinfo/python-list
Compare regular expressions
Hi, I'm writing a program with a large data stream to which modules can connect using regular expressions. Now I'd like to not have to test all expressions every time I get a line, as most of the time, one of them having a match means none of the others can have so. But ofcource there are also cases where a regular expression can "contain" another expression, like in: "^strange line (\w+) and (\w+)$" and "^strange line (\w+) (?:.*?)$" in which case I'd like to first test the seccond and only if it mathces test the seccond. Do anybody know if such a test is possible? if exp0.contains(exp1): ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Compare regular expressions
Den Mon, 16 Apr 2007 11:50:40 +0200 skrev Thomas Dybdahl Ahle: > Hi, I'm writing a program with a large data stream to which modules can > connect using regular expressions. > > Now I'd like to not have to test all expressions every time I get a > line, as most of the time, one of them having a match means none of the > others can have so. > > But ofcource there are also cases where a regular expression can > "contain" another expression, like in: "^strange line (\w+) and (\w+)$" > and "^strange line (\w+) (?:.*?)$" in which case I'd like to first test > the seccond and only if it mathces test the seccond. > > Do anybody know if such a test is possible? if exp0.contains(exp1): ... I found this link: http://terpstra.ca/compare.html which seams to compare expressions. Not python expressions though. Sadly it writes nothing about the way it does the thing, and if it will always work. -- http://mail.python.org/mailman/listinfo/python-list
Re: Compare regular expressions
Den Tue, 17 Apr 2007 11:59:15 -0700 skrev Paddy: > On Apr 17, 9:17 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Paddy schrieb: >> > you could OR all the individual RE's test them all at once then find >> > out which matched. >> >> > big_re = "|".join( r"(?P<__match_%i__>%s)" % (i, r) >> >for i,r in enumerate(regexps) ) >> >> This doesn't answer the question if two of the sub-expressions matched. Hm, if I were to OR them all the time, then I wouldn't get any boost from compiling. I'll probably just stick with a try them all solution, and then change it if I run into something that does the right thing. I believe it can make the code something like 7 or 10 times faster. -- http://mail.python.org/mailman/listinfo/python-list
Re: Binary file output using python
Den Tue, 17 Apr 2007 11:07:38 -0700 skrev kyosohma: > On Apr 17, 12:41 pm, Chi Yin Cheung <[EMAIL PROTECTED]> wrote: >> Hi, >> Is there a way in python to output binary files? I need to python to >> write out a stream of 5 million floating point numbers, separated by >> some separator, but it seems that all python supports natively is >> string information output, which is extremely space inefficient. I don't understand. To me it seams like there is no space difference: [EMAIL PROTECTED] ~]$ python Python 2.4.4 (#1, Oct 23 2006, 13:58:00) [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f = open("test2", "w") >>> f.write(str(range(10**7))) >>> f.close() >>> f = open("test", "wb") >>> f.write(str(range(10**7))) >>> f.close() >>> [EMAIL PROTECTED] ~]$ ls -l test test2 -rw-rw-r-- 1 thomas thomas 8890 17 apr 22:28 test -rw-rw-r-- 1 thomas thomas 8890 17 apr 22:27 test2 [EMAIL PROTECTED] ~]$ -- http://mail.python.org/mailman/listinfo/python-list
distutils install-data-hook
Hey I have this pythonapp I'm trying to pack, and I've read in the Gnome specifications that I should run "update-icon-cache" after install, in order to get the menus and stuff correctly updated. Is there a way to specify a (list of) commands to be run after installation? -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: > yadin wrote: > >> if i were up to make a GUI chich are the advantages of choosing python >> over matlab or java? >> > The best is Delphi, > second is VB, That sounds mostly like a personal preference :) I would certainly suggest Python very much for any kind of gui. -- http://mail.python.org/mailman/listinfo/python-list
Untrusted python code
Hi, I have an application for which I want users to be able to make themes. I've planed a rather advanced model (in xml), which gives themes the option to redefine various drawing methods. Now I don't want those themes to be able to take over the current user, but I'd still like the scripts to be able to import stuff like math. Is there a way to ensure no IO and other dangerous stuff is done? -- http://mail.python.org/mailman/listinfo/python-list
Decrypt DES by password
Hi, I've got some DES encrypted data, for which I know the password. The problem is that I have to generate an 8byte key from the password. I use python-crypto-2.0.1. I also know, that the C# way to do the decryption is: PasswordDeriveBytes bytes1 = new PasswordDeriveBytes("passwordString", null); byte[] array1 = new byte[8]; byte[] array2 = bytes1.CryptDeriveKey("DES", "MD5", 0, array1); DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider(); FileStream fs = new FileStream("fileNameString", FileMode.Open, FileAccess.Read); CryptoStream cs = new CryptoStream(fs, provider1.CreateEncryptor(array2, array1), CryptoStreamMode.Read); Anybody know how to do this in python? -- Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to read and interpret the "scripture" of this age. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decrypt DES by password
Den Mon, 15 May 2006 11:32:47 -0700. skrev Paul Rubin: > Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: >> byte[] array2 = bytes1.CryptDeriveKey("DES", "MD5", 0, array1); >> > Anybody know how to do this in python? > > I'm not aware of a standard that says how CryptDeriveKey is supposed > to work. Or rather, there are multiple possible standard ways to do > it. If you can find an exact specification, or C# source code that > does it, it will probably be straightforward to reimplement in Python. I tried to find out how the monofolks did it, but also they didn't know the algorithms. Maybe I should find a windows computer with .net, create the key and base64 encode it, so that I could take it to the python program... But thanks for the excample anyways. Maybe I can use it, if I need to encrypt something myself, another time. -- Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to read and interpret the "scripture" of this age. -- http://mail.python.org/mailman/listinfo/python-list
Bit Scan Forward and Reverse
Hi, I'm writing an app in python, and I'm storing some a lot of data in bitmaps. I need a way to find the first or latest set bit in a 64bit number, and for that I've implemented a small routine. Thing is that this routine is not as fast as I'd wish. I know most processors implement BSF and BSR calls to do this efficiently. Is there anyway to access those calls from python? I'd still have my routine as a fallback on nonsupporting architectures. -- Med venlig hilsen, Best regards, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python GUI toolkit
On Sun, 2008-02-03 at 15:18 +, [EMAIL PROTECTED] wrote: > what would be the best python GUI toolkit, it must be cross platform. > > i have tried gtk, but it interface are real bad and its coding was difficult > so i dropped it, I came from Sving to Gtk, so for me also it was a real brainbreak. However I must say I got used to it. I have a good list of links if you still have some corruage. > the only remaining are qt4 and wx, i would like to know if one of these or > any other toolkit is capable of creating good-looking GUI's, like in other > apps, for e.g, .net apps. Well, I've always hated wx apps. It might be a good toolkit for writing, but I've never seen a good-looking app written in it. For Qt there is also distance between the good looking apps. However with qt4 I've started to see some. They still don't fit good into gnome of cource, but it's not as bad as it used to. I also think the toolkit is nice for writing. Another toolkit you might look into is Tkinter. I think it is something like the "official" toolkit for python. I also think it is an adapter for other toolkits, so it will use gtk widgets on gnome, qt widgets on kde and some other strange widgets on windows. > i m a noob, and willing to learn, so difficulty is no problem In that case I think you should give gtk another try. The way it is build is very much based on GObject, which is also used in a number of other gnome libraries + stuff like Clutter. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does anyone else use this little idiom?
On Sat, 2008-02-02 at 18:03 -0800, [EMAIL PROTECTED] wrote: > for _ in xrange (1,n): >some code I'd always use i for loop variables I don't know what to call. It stands for iterator or something. In a nested loop the next variable would simply be called j and so on. I also tend to use _, but in cases like: _, _, something, _ = somecall() where I only need one variable from a tupple. I only use this if I'm sure the other values will probably never be of any use for the code. However a large problem with _ is, that it is also the standard name of the translate function of e.g. gettext. In gui code you'll often find widget.setText(_("Save")). If you have renamed _ this will give you problems. > An alternative way of indicating that you don't care about the loop > index would be > > for dummy in xrange (1,n): >some code I don't like dummy, as it is too long. I generelly spend more times looking into long variable than short ones. Regards, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Project naming suggestions?
On Sun, 2008-02-03 at 10:17 -0800, [EMAIL PROTECTED] wrote: > I'm considering writing a little interpreter for a python-like > language and I'm looking for name suggestions. :-) > > Basically, I don't want to change a whole lot about Python. In fact, > I see myself starting with the compiler module from Python 2.5 and > building from there. > > This language would be more or less "Python modulo a few > (incompatible) changes, but it'd be recognizable by Python > programmers. I'm talking about stuff like "allowing the character '?' > in identifier names," and "a better way to express 'for dummy in > xrange (n):' when the index isn't needed." I'd also like to > implement most of the planned Python 3000 changes. Are you really thinking about creating an entire language, simply because you don't like 'for dummy in xrange (n):'? I hope you know what an extreamly large work that is, and how little we need more languages in this category. > Any suggestions? I'm thinking "Ophidian," for the snake connection, > or, possibly, "Circus," from "Monty Python's Flying Circus." > > Thanks :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Speed of light [was Re: Why not a Python compiler?]
On Sat, 2008-02-09 at 14:56 +0100, Martin P. Hellwig wrote: > > Propagate, travel, what's the difference? > > > Unfortunately, I didn't study any of this but I sure do remember the > answer one drunk physic said to me in a bar when I ask him the question: > "Does light travel or propagate?" > He answered: "Depends on how you see light." > He must have studied philosophy too :-) Quantum mechanics are closely related to philosophy. -- Best Regards, Med Venlig Hilsen, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Adding more warnings
I tend to make a lot of mistakes of misspelled variable names. Is it possible to make python warn me about those at "compile time"? Very few times I use dynamic variable initialization. I can live with getting a warning for those as well. -- Best Regards, Med Venlig Hilsen, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python behave so? (removing list items)
On Wed, 2008-03-26 at 23:04 +0100, Michał Bentkowski wrote: > Why does python create a reference here, not just copy the variable? Python, like most other oo languages, will always make references for =, unless you work on native types (numbers and strings). Instead use one of: k = j[:] or k = [i for i in j] or from copy import copy k = copy(j) or k = range(6) -- Best Regards, Med Venlig Hilsen, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Rounding a number to nearest even
On Fri, 2008-04-11 at 03:14 -0700, bdsatish wrote: > The built-in function round( ) will always "round up", that is 1.5 is > rounded to 2.0 and 2.5 is rounded to 3.0. > > If I want to round to the nearest even, that is > > my_round(1.5) = 2# As expected > my_round(2.5) = 2# Not 3, which is an odd num > > I'm interested in rounding numbers of the form "x.5" depending upon > whether x is odd or even. Any idea about how to implement it ? This seams to work fine: evenRound = lambda f: round(f/2.)*2 >>> [(f*.5, evenRound(f*.5)) for f in xrange(0,20)] [(0.0, 0.0),(0.5, 0.0), (1.0, 2.0), (1.5, 2.0), (2.0, 2.0), (2.5, 2.0), (3.0, 4.0), (3.5, 4.0), (4.0, 4.0), (4.5, 4.0), (5.0, 6.0), (5.5, 6.0), (6.0, 6.0), (6.5, 6.0), (7.0, 8.0), (7.5, 8.0), (8.0, 8.0), (8.5, 8.0), (9.0, 10.0), (9.5, 10.0)] -- Best Regards, Med Venlig Hilsen, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature suggestion: sum() ought to use a compensated summation algorithm
On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote: > On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote: > > > Arnaud Delobelle wrote: > >> > >> sum() works for any sequence of objects with an __add__ method, not > >> just floats! Your algorithm is specific to floats. > > > > This occurred to me also, but then I tried > > > > sum(['abc', 'efg'], '') > > Interesting, I always thought that sum is like shortcut of > reduce(operator.add, ...), but I was mistaken. > > reduce() is more forgiving: > reduce(operator.add, ['abc', 'efg'], '' ) # it works > 'abcefg' Hm, it works for lists: sum(([1], [2]), []) [1, 2] However I find the seccond argument hack ugly. Does the sum way have any performance advantages over the reduce way? -- Best Regards, Med Venlig Hilsen, Thomas -- http://mail.python.org/mailman/listinfo/python-list