pygtk help
[x-posted to PyGTk mailing list as well] Hello! I'm trying to figure out how to use PYGTK to implement a rudimentary UI: I want to have an Image as the background, and then be able to put buttons (eventually icons, but buttons for now) The PyGTK FAQ (pygtk.org) has some suggestions, but they have failed to clear up the issue. Using their suggestions as a starting point, I've arrived at the below. However, it fails in that I can't seem to place the image behind the button. There is a FAQ entry specifically on this at PyGTK.org, but that fails to show the pixmap (it is obscured completely when we place a button in the Fixed widget), and fails to allow the pixmap to be scrolled. Can anyone show a minimal example of how I might achieve having the pixmap as the background of the Fixed widget? Thanks Johan def __init__(self): # create the main window, and attach delete_event signal to terminating # the application window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.connect("delete_event", self.close_application) window.connect("destroy", self.close_application) window.set_border_width(0) hbox= gtk.HBox() window.add(hbox) hbox.show() swin1 = gtk.ScrolledWindow() swin1.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_ALWAYS) swin1.set_size_request(600, 600) hbox.add(swin1) swin1.show() fbox1 = gtk.Fixed() swin1.add_with_viewport(fbox1) fbox1.show() ebox1 = gtk.EventBox() fbox1.put(ebox1,0,0) ebox1.show() image1 = gtk.Image() image1.set_from_file("/home/johan/bg.jpg") ebox1.add(image1) image1.show() widgetinfo( image1) b = gtk.Button("FOO") fbox1.put(b, 200,200) b.show() widgetinfo(b) ebox1.set_events(gtk.gdk.BUTTON_PRESS_MASK) ebox1.connect("button_press_event", self.button_clicked) window.show() -- http://mail.python.org/mailman/listinfo/python-list
some problems with mod_python
Hi I have installed and tested this on centos, fedora and freebsd all give the same problem so I guess I missed some steps. I have compiled bot apache (2.2.4) and mod_python (3.3.1) according to the docs and no problem with this. But when I have made everything about testing mod_python an browse to http://server/test and there expecting to see "Hello world" I instead get an index of contents in this directory. If I go to http://server/test/mptest.py it works. No errors in any log either. What Have I missed? This I added to httpd.conf AllowOverride All AddHandler mod_python .py PythonHandler mptest PythonDebug On this is my mptest.py: from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Hello World!") return apache.OK /johan -- http://mail.python.org/mailman/listinfo/python-list
Re: some problems with mod_python
On Aug 27, 10:29 pm, "Greg Donald" <[EMAIL PROTECTED]> wrote: > This is the syntax I have working locally: > > # mod_python > > AddHandler python-program .py > PythonHandler test > PythonDebug On > > > In particular my AddHandler directive is different from yours. > If I did understand the docs about the difference between python- program and mod_python is that the later is the new way, while using python-program still works. It does not matter which I use, same result. /johan -- http://mail.python.org/mailman/listinfo/python-list
Re: some problems with mod_python
On Aug 24, 3:39 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Your problem is with Apache configuration, not with mod_python. The > AddHandler directive maps /*.py to your handler. So you have to > call .py to trigger the desired behaviour. If you want > *any* url under to be handled by mptest, you need to use > SetHandler, not AddHandler. Yes, this is what I missed. Using SetHandler instead solved my problem. Many thanks to the people on the list that pointed that out for me. (and will use mod_python mailing list in the future as suggested) /johan -- http://mail.python.org/mailman/listinfo/python-list
Using dicts and lists as default arguments of functions
Dear all, Considering this test program: def tst(a={}): print 1, a a['1'] = 1 print 2, a del a def tstb(a=[]): print 1, a a.append(1) print 2, a del a tst() tst() tstb() tstb() With output: t...@tnjx:~/tst> python tt.py 1 {} 2 {'1': 1} 1 {'1': 1} 2 {'1': 1} 1 [] 2 [1] 1 [1] 2 [1, 1] Would there be a way to ensure that the results does not depend on the previous call of the function. The desired output is: 1 {} 2 {'1': 1} 1 {} 2 {'1': 1} 1 [] 2 [1] 1 [] 2 [1] I know that tst({}) and tstb([]) will work, but is there any way to still use tst(), tstb()? Thanks in advance, Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Execute script from ipython
Hi all, I have a script "myscript.py" located in "/usr/local/bin" on my linux box. I can execute it in ipython with run /usr/local/bin/myscript.py but not with run myscript.py even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. What should I do to correct this? Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute script from ipython
Thanks Chris! I tried using "!" instead of "run". It works but with a significant performance penalty. Best regards, Johan On Fri, Aug 19, 2011 at 5:11 PM, Chris Rebert wrote: > On Fri, Aug 19, 2011 at 6:00 AM, Johan Ekh wrote: > > Hi all, > > I have a script "myscript.py" located in "/usr/local/bin" on my linux > box. > > I can execute it in ipython with > > > > run /usr/local/bin/myscript.py > > > > but not with > > > > run myscript.py > > > > even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. > > > > What should I do to correct this? > > Given that %run takes a filename and not a module name, I doubt > PYTHONPATH matters. ipython's docs for %run don't seem to indicate > that a search of any kind is performed. So, I'd say you have to either > pass a valid absolute or relative path to myscript.py, or run > myscript.py from bash instead of ipython. > > Changing your script's shebang line to ipython might also work > (haven't tried it myself). Or you could try patching ipython's run() > function to add this search feature you desire. > > Cheers, > Chris > -- > http://rebertia.com > -- http://mail.python.org/mailman/listinfo/python-list
"pickle" vs. f.write()
Hi, I have a class with attributes that are string, integer and list. eg. class person: name ="" age = 0 friends=[] comment="""""" me = person() I want to save a whole bunch of instances to a file, a classic "records" file I/O. To write the file, I can do f.write(str([me.name, me.age, me.friends, me.comment]) + "\n" This works nicely for writing, but when reading, I cannot convert the string easily to a list: list(f.readline()) is not the same as [me.name, me.age, me.friends, me.comment] I was wondering whether pickle might make this easier - an example would be much appreciated. Otherwise, what is the best "Python" way to write and read this data structure? Thanks in advance... Johan __ Yes, I do feel stupid asking this, but time's-a-runnin' out.. -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/ Please find our disclaimer at http://www.ukzn.ac.za/disclaimer <<<>>> -- http://mail.python.org/mailman/listinfo/python-list
Re: "pickle" vs. f.write()
Thanks... works like a charm :-) On Wed, 26 Jan 2005 12:55:38 +0100, Peter Maas <[EMAIL PROTECTED]> wrote: Johan Kohler schrieb: class person: name ="" age = 0 friends=[] comment="""""" me = person() Otherwise, what is the best "Python" way to write and read this data structure? import pickle class person: name ="" age = 0 friends=[] comment="""""" me = person() # store pf = file('/tmp/pickletest', 'w') pickle.dump(me, pf) pf.close() # load pf = file('/tmp/pickletest', 'r') me2 = pickle.load(pf) pf.close() This is sequential access. If you want to have random access, look for shelve. -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/ Please find our disclaimer at http://www.ukzn.ac.za/disclaimer <<<>>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Office COM automatisation - calling python from VBA
Hi. > > If you are new to Python and want to use it with COM, definitely get > > yourself a copy of _Python Programming on Win32_ by Mark Hammond and > > Andy Robinson. > > ...or at least read the chapter available online: > http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html Also, check out the following tutorials: http://www.reportlab.com/ftp/talks/PythonWindowsTutorial.doc http://starship.python.net/crew/pirx/spam7/COMtut.PPT ...and if you're visiting EuroPython make sure to show up for Guy Dalbertos tutorial on Python+ Excel. If you're not, download his presentation and example code from: http://www.python-in-business.org/ep2005/talk.chtml?talk=2626&track=690 HTH Johan Lindberg [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: finding sublist
Hello. > my target is implement a function controlla(string - a binary string-) > that check if there is in a string two equal not overlapping > subsequences at least of length limitem: > > my code: > [snip] > I may have misunderstood it, but does your function work the way you want it to? >>>controlla("testeststest") no I can't get it to print anything other than "no". But then again, I'm reading and posting via Google and I guess all those break statements shouldn't be on the same indent-level. > the question is: Is there a faster way doing that? I don't know, > changing string into list or array, using map, or module, using > different loop, regular expression,funcional programming , list > comprehensions , sets, different looping techniques, i dont > know...(!) Since you're using nested for loops when searching the string you should make sure not to perform more iterations than neccessary. The function below returns a list of all, non-overlapping, substrings in text where len(substring)>= minLength. The outer loop is limited to about half of the length of the text which is where most of the speed comes from but I'm sure it can be tweaked for more. def foo(text, minLength): result= [] for length in range(minLength, len(text)/ 2+ 1): for start in range(len(text)): end= start+ length if end< len(text): part= text[start:end] if text.find(part, end)!= -1: if part not in result: result.append(part) return result >>>foo("testeststest", 4) ['test', 'stes', 'stest'] >>>foo("testeststest", 3) ['tes', 'est', 'ste', 'test', 'stes', 'stest'] HTH Johan Lindberg [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: finding sublist
> thanks everyone. only a question. there is a way to advantage of binary > sequences? I doubt you'll find any way to optimize the code that somehow only applies to binary sequences. You still have to find each possible subsequence of minimum length within the sequence and compare it to all other possible subsequences and that's what's going to take most of the time. If you haven't already, check out psyco (http://psyco.sourceforge.net/). It will most definitely make your code run faster. BR Johan Lindberg [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Speeding up CGIHTTPServer
Hi, I'm using CGIHTTPServer (via its test() method) to test some CGI on my Windoze 98 box. I find that the execution is very slow. Is there anything I can do to make sure I'm getting the best performance out of CGIHTTPServer? Thanks in advance, Johan Please find our disclaimer at http://www.ukzn.ac.za/disclaimer <<<>>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Speeding up CGIHTTPServer (Tim Roberts)
On Tue, 8 Mar 2005 10:25:46 +0100 (CET), <[EMAIL PROTECTED]> wrote: I'm using CGIHTTPServer (via its test() method) to test some CGI on my Windoze 98 box. I find that the execution is very slow. Is there anything I can do to make sure I'm getting the best performance out of CGIHTTPServer? Compared to what, and on what hardware? CGI is not a rip-roaring performance demon on any platform, but CGIHTTPServer is designed to be convenient more than fast. It isn't going to do as well as a native server. The key question you need ask is this: is it fast enough? If you're doing a web page for internal use that is only going to get a hundred hits a day, who cares if each page takes 5 seconds to render? If you're doing 10,000 hits a day, you need to choose something other than Windows 98. Fair enough. Pretend my question said "compared to apache, but also to CGIHTTPServer on linux". The Windows box has modest specs Celeron 2.8GHz, 256MB, but it takes 30-60s render pages. I was using it to test my cgi locally, ie. no network, one user Windows bashing is fun :-) but unfortunately I don't think that is the issue here. The answer I was looking for was something like - "yes, change config file so-and-so in such-and-such a way" or simply "no." If there is no way to improve performance, could anyone tell my _why_ it's running so slowly? Presumably spawning a process takes some time. The code I'm running as CGI is not hectic at all. Thanks in advance, Johan -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/ Please find our disclaimer at http://www.ukzn.ac.za/disclaimer <<<>>> -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle and py2exe
> Im trying to compile a script with py2exe. The pickle module is causing the > program to give an error. > > Traceback (most recent call last): > File "SETIstat.pyw", line 330, in ? > File "SETIstat.pyw", line 84, in start_up > File "SETIstat.pyw", line 79, in config_load > File "pickle.pyc", line 1390, in load > File "pickle.pyc", line 872, in load > File "pickle.pyc", line 985, in load_string > LookupError: unknown encoding: string-escape > > the data in the pickled file is a dictionary containing a couple strings. The > strings do contain \n and \t charaters but no other special characters or > anything. > > Does anyone have any suggestions to what I can try to get around this? The > pickle module works fine when the .pyw file is run. Its only when I compile > this is there an issue. > > Thanks for any help, > > Justin Have you included string-escape encoding in your setup.py? My guess is that you can fix the problem with something similar to: from distutils.core import setup import py2exe opts = { "py2exe": { "packages": ["encodings"], } } setup(windows= ["spam.py"], options= opts) in your setup.py. Hope it helps /Johan Lindberg -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle and py2exe
>>> Im trying to compile a script with py2exe. The pickle module is causing the >>> program to give an error. >>> >>> Traceback (most recent call last): >>> File "SETIstat.pyw", line 330, in ? >>> File "SETIstat.pyw", line 84, in start_up >>> File "SETIstat.pyw", line 79, in config_load >>> File "pickle.pyc", line 1390, in load >>> File "pickle.pyc", line 872, in load >>> File "pickle.pyc", line 985, in load_string >>> LookupError: unknown encoding: string-escape >>> >>> the data in the pickled file is a dictionary containing a couple >>> strings. The >>> strings do contain \n and \t charaters but no other special characters or >>> anything. >>> >>> Does anyone have any suggestions to what I can try to get around this? The >>> pickle module works fine when the .pyw file is run. Its only when I compile >>> this is there an issue. >>> >>> Thanks for any help, >>> >>> Justin >>Have you included string-escape encoding in your setup.py? >>My guess is that you can fix the problem with something similar to: >> >> from distutils.core import setup >> import py2exe >> opts = { "py2exe": { "packages": ["encodings"], } } >> setup(windows= ["spam.py"], options= opts) >> >>in your setup.py. >> >>Hope it helps >>/Johan Lindberg > Thanks Johan, but unfortunately the same traceback is given in the log. > I should have mentioned in my previous post that Im using win2000, if it > matters any. > Hi Justin. I'm assuming that your library.zip now has several encoding-files in it? And more specifically that you have a file called "string_escape.pyc" in path "encodings". Right? I don't think it's got anything to do with your windows version but it might be helpful to know your python and py2exe versions. Unfortunately I haven't been able to reproduce the error on either of my windows machines (using python 2.3.4 and py2exe 0.5.3 on both, one is win2k and the other XP). Line 985 in pickle.py says: self.append(rep.decode("string-escape")) so that's why you need the encoding, even though you "don't use it". Will the same lookup error show up in a smallest possible program, such as: # encoding= iso-8859-1 spam= "Det här är svenska" print spam.decode("string-escape") What happens when you compile that script to an exe using the above setup.py? (don't forget to change windows= ["spam.py"] to console= ["spam.py"]) Also you might want to try the py2exe-users list (see http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/py2exe-users). BR /Johan Lindberg -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython bug
> [...] > What to do? Open up wxProject.py and fix the problem. The traceback is pretty clear: On line 137 in wxProject.py, the method GetFirstChild expects 2 arguments, but was given 3. Unfortunately the wx documentation is not very clear about the GetFirstChild method. It only says: wxPython note: In wxPython the returned wxTreeItemId and the new cookie value are both returned as a tuple containing the two values. It should also mention that it (GetFirstChild) only takes one parameter (item) For future reference: keep the wxPython api docs (http://www.wxpython.org/docs/api/) close. /Johan Lindberg -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question: starting external application(win)?
>The module popen2 is your friend. Or the os.spawn* methods in module os. Another (simpler IMO) way to do it is to use os.startfile. To start Notepad: >>> import os >>> os.startfile("notepad.exe") also, you can start an application from an associated file. Start MS Word with: >>> os.startfile("MyDocument.doc") /Johan Lindberg -- http://mail.python.org/mailman/listinfo/python-list
Re: Confirm: compiled re(gexps) are thread safe?
Skip Montanaro wrote: Johan> Subject says it all, really. Yes, searching using a compiled regular expression is thread-safe. Skip Great. Thanks -- http://mail.python.org/mailman/listinfo/python-list
list.count() with no arguments
Wouldn't it be nice if list.count, called without any arguments, returned a dict with the list's unique items as keys and their frequency of occurance as values? >>> [1,2,1,'a'].count() {'a': 1, 1: 2, 2: 1} >>> 'hello world'.count() {' ': 1, 'e': 1, 'd': 1, 'h': 1, 'l': 3, 'o': 2, 'r': 1, 'w': 1} ...johahn -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML editor component?
You could try the (very) simple HTML editor I use for my CM project. It can only handle B, I, U and A, but then again, it was never meant to do more. It's written in wxPython, based on Scintilla and can probably be extended to fit your needs. You can find it here: http://sourceforge.net/project/showfiles.php?group_id=72786&package_id=138707 BR /Johan Lindberg -- http://mail.python.org/mailman/listinfo/python-list
multiprocessing in a while loop?
hi, I am struggling to understand how to leverage python's multiprocessing module in a while loop. the examples I have found seem to assume it is known ahead of time how many items need to be processed. specifically, I am reading from an external queue. I currently process items one at a time until the queue is empty. I wrote a wrapper function to handle connecting to the queue, pulling the next message, and deleting it when I am done. ideally, I'd like to modify this wrapper function to take an additional argument (processes) to specify the number of messages to process simultaneously. I've attached a script that captures what I am doing now. unfortunately, the external queue object is not publicly accessible and I'm not quite sure how to set up a local object that would support testing. any suggestions would be most welcome. thanks, Johan #!/usr/bin/env python import boto import logging LOG_FMT = '%(asctime)s - %(levelname)s - %(module)s.%(funcName)s - %(message)s' QUEUE = 'my-queue' logger = logging.getLogger(__name__) # read from an external queue; items may be added during processing def consume_queue(queue_name): conn = boto.connect_sqs() q = conn.get_queue(queue_name) m = q.read() while m is not None: yield m q.delete_message(m) logger.debug('message deleted') m = q.read() # high variability in message processing times (seconds - hours) def handle_message(message) s = message.get_body() logger.info(s) def main(): for message in consume_queue(QUEUE): handle_message(message) if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG, format=LOG_FMT) main() -- https://mail.python.org/mailman/listinfo/python-list
Problem compiling Postgresql-7.3.4 + Python
Hi All, I am trying to compile Postgresql-7.3.4 with the following flags: ../configure --prefix=$(E4LDIR) --with-pgport=5433 --with-python --with-includes=$(E4LDIR)/include/python2.3-e4l --with-libra ries=$(E4LDIR)/lib/python2.3-e4l && \ $(MAKE) This gives me the following compilation error: Anyone any clues? Thanks for any reply! Grz. Johan Barelds - /usr/bin/ld: /usr/local/lib/python2.3/config/libpython2.3.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/python2.3/config/libpython2.3.a: could not read symbols: Bad value collect2: ld returned 1 exit status apxs:Error: Command failed with rc=65536 . make[1]: *** [mod_python.so] Error 1 make[1]: Leaving directory `/root/mod_python-3.1.4/src' make: *** [do_dso] Error 2 - -- http://mail.python.org/mailman/listinfo/python-list
Re: for: else: - any practical uses for the else clause?
On 29 Sep 2006 11:26:10 -0700, Klaas <[EMAIL PROTECTED]> wrote: else: does not trigger when there is no data on which to iterate, butwhen the loop terminated normally (ie., wasn't break-ed out). It is meaningless without break. The else clause *is* executed when there is no data on which to iterate. Your example even demonstrates that clearly: >>> for x in []:... print 'nothing'... else:... print 'done' ...done The else clause is executed because the loop still terminates normally with an empty list - albeit without having looped at all. I agree that it is meaningless without a break statement, but I still find it useful when I want to determine whether I looped over the whole list or not. For example, if I want to see whether or not a list contains an odd number: for i in list: if i % 2 == 1: print "Found an odd number." break else: print "No odd number found." Without the else clause I would need to use an extra variable as a "flag" and check its value outside the loop: found = False for i in list: if i % 2 == 1: print "Found an odd number." found = True break if not found: print "No odd number found." OK, so using "else" only saves me 2 lines and a variable - not much to write home about, but I still like it. Johan. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK Notebook button_press_event connection
> > > notebook = gtk.Notebook() > ... > child = gtk.Frame() > ... > label = gtk.Label('Any text') > label.connect('button_press_event', a_function) > ... > notebook.append_page(child, label) > > > > But the button_press_event event is not intercepted (nothing happens > when I click on the tab label). A gtk.Label does not have a gdk window (as in the windowing system of gtk+), so it cannot listen to events. A workaround is to put it in an eventbox: eventbox = gtk.EventBox() eventbox.set_events(gtk.gdk.BUTTON_PRESS_MASK) eventbox.connect('button-press-event', callback) label = gtk.Label() eventbox.add(label) notebook.append_page(..., eventbox) Perhaps you should subscribe to the PyGTK mailing list[1] though, where this kind of question is more appropriately asked [1]: http://www.daa.com.au/mailman/listinfo/pygtk Johan Dahlin -- http://mail.python.org/mailman/listinfo/python-list
Re: sending keystrokes to gtk window
sven wrote: > hi list, > i'd like to send keystrokes to a (terminal) window. > the windowmanager is gnome (ubuntu). > what i want to do is to control dvgrab which can be > started in interactive mode. > thx in advance, This is not entirely trivial to do. The best way to do that would be to use the wnck bindings which can be found in the python-gnome2-extras, which unfortunately is broken on ubuntu/breezy. There is a separate list for the gtk python bindings: http://www.daa.com.au/mailman/listinfo/pygtk Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Conventions
Iain King skrev: > How do you gain access to the system tray? Use wx.TaskBarIcon. See http://wiki.wxpython.org/index.cgi/FlashingTaskbarIcon for snippets. /Johan -- http://mail.python.org/mailman/listinfo/python-list
optparse with numpy.array?
Hi all, I'm trying to use optparse to process command line parameters given to my program. It works as I expect for the types supported by optparse, i.e. int, float, string etc. but how can I pass a numpy.array or a list to my program? I have been searching for it but cannot find a good solution. By the way, I am a Python newbie so please be gentle... Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse with numpy.array?
Thank you Robert, but what if I just want to create an array interactively, e.g. like m = array([1.0, 2.0, 3.0]), and pass it to my program? I tried extending optparse with a new type as explained in the link you gave me but I was not able to get it to work. Is it really neccessary follow that route just to pass an array? Lot's of people must have done this before! Best regards, Johan On Tue, Jan 27, 2009 at 1:00 AM, Robert Kern wrote: > On 2009-01-26 17:44, Johan Ekh wrote: > >> Hi all, >> I'm trying to use optparse to process command line parameters given to >> my program. >> It works as I expect for the types supported by optparse, i.e. int, >> float, string etc. but how can I >> pass a numpy.array or a list to my program? >> > > http://docs.python.org/library/optparse#optparse-extending-optparse > > Figure out the text format you want your users to type the value on the > command line, write a function that will take that text and convert it to an > array or list, then customize OptionParser to use that parser as given in > the link above. Keep in mind that your user probably won't want to need to > use whitespace or any kind of brackets. Commas are nice, though. > > You may also want to consider taking a filename and parsing that file > instead. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse with numpy.array?
Thank you James, but I just can't optparse to accept an array, only integers, floats ans strings. My code looks like this from optparse import OptionParser parser = OptionParser() parser.add_option('-t', '--dt', action='store', type='float', dest='dt_i', default=0.1, help='time increment where lsoda saves results') parser.add_option('-T', '--tstop', action='store', type='float', dest='tstop_i', default=1.0, help='duration of the solution') parser.add_option('-m', '--mass_vector', action='store', type='float', dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') op, args = parser.parse_args(sys.argv[1:]) I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse complains that m_i is not a float. Best regards, Johan On Tue, Jan 27, 2009 at 6:53 AM, James Mills wrote: > On Tue, Jan 27, 2009 at 3:45 PM, Johan Ekh wrote: > > Thank you Robert, > > but what if I just want to create an array interactively, e.g. like m = > > array([1.0, 2.0, 3.0]), and pass it > > to my program? I tried extending optparse with a new type as explained in > > the link you gave me > > but I was not able to get it to work. Is it really neccessary follow that > > route just to pass an array? > > Lot's of people must have done this before! > > Normally command line applications accept > a number of arguments which are available > in sys.argv > > cheers > James > -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse with numpy.array?
Thanks, James I will try your suggestion! Robert, what mean with "interactively" is that i would like to create an array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or by reading a file with values etc., and then execute my program with "myprog -m m_i" and thus pass the array "m_i" to my program. This is just an example. I would like to pass several arrays. My program will be wrapped inside a loop and the arrays are updated in each loop. I have never heard of the "argparse" library. Do you think that it would be better to use that in my case? Best regards, Johan On Tue, Jan 27, 2009 at 7:12 AM, Robert Kern wrote: > On 2009-01-27 00:01, Johan Ekh wrote: > >> Thank you James, >> but I just can't optparse to accept an array, only integers, floats ans >> strings. >> >> My code looks like this >> >> from optparse import OptionParser >> parser = OptionParser() >> parser.add_option('-t', '--dt', action='store', type='float', >> dest='dt_i', default=0.1, help='time increment where lsoda saves results') >> parser.add_option('-T', '--tstop', action='store', type='float', >> dest='tstop_i', default=1.0, help='duration of the solution') >> parser.add_option('-m', '--mass_vector', action='store', type='float', >> dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') >> op, args = parser.parse_args(sys.argv[1:]) >> >> I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse >> complains that m_i is not a float. >> > > Well, yes, because you declared that --mass_vector was type='float'. You > will need to subclass OptionParser in order to parse something that is not > one of the included types. Yes, it is a bit cumbersome; it's one of the > reasons I usually use the third-party argparse library instead. You only > need to supply a parsing function rather than subclass. > > I'm afraid I don't really understand what you want when you say that you > want to create an array interactively. Can you show me an example command > line that you want to parse? Keep in mind that in many shells, ()[] > characters are specially handled by the shell and are not convenient for > users. > > BTW, I am subscribed to the list. You do not need to Cc me. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: please include python26_d.lib in the installer
On Sat, Mar 28, 2009 at 1:17 AM, Mark Hammond wrote: >> Please note: I want to build my own code in Debug mode for debugging. >> I don't want to build or use the debug version of Python. I also can't > > Python does this on purpose so you don't accidentally mix different versions > of the C runtime library. This would happen ff you defined DEBUG in your > code but use Python built without DEBUG - Python using a different name for > its lib prevents this. > > Note that just shipping the _d.lib wouldn't help - you would need the _d.dll > itself, plus *all* extension modules you use - *all* .pyd/.dll etc files > have the trailing _d, and a debug version of Python refuses to load the > release versions without the _d. > > I'd recommend leaving DEBUG etc disbled, but enable debug information and > disable optimizations while debugging. If Python doesn't include the _d.lib file, then why does the header file reference it? I would prefer manual control over which lib file to use. (And I don't want to disable _DEBUG for other reasons). Could the header file be changed so it alwas uses the release lib? In most cases it's actually ok to mix different versions of the CRT in one application. See the following blog post about this issue: http://www.davidlenihan.com/2008/01/choosing_the_correct_cc_runtim.html The goal is to use one runtime library throughout your entire application. That is nearly impossible since you typically don't have control of which runtime library other libraries use. It turns out is is OK to mix runtime libraries *except* in certain cases. A well written library should avoid these cases and then it doesn't matter if the runtime libraries match. Libraries that cannot avoid these cases should ship with 4 versions of their libraries that match the 4 versions of the runtime libraries. P.S. If pyconfig.h really wanted to use the correct CRT, then it would need to reference different lib files for both VS2005 and 2008. Johan. -- http://mail.python.org/mailman/listinfo/python-list
standard library audio/image support
Hi there! I spent the afternoon making a simple graphics-to-audio converter.. I was surprised to find that the AIFF parser/writer is in the standard library, but that I had to go to some external library for opening and manipulating a JPG file. How come audio is deemed more important for the standard library than imaging? Regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Multiple python installations on opensuse?
Hi all, I use the finite element package ABAQUS that is partly built around python 2.4.3. ABAQUS ships with its own version of python 2.4.3 but it comes without third party libraries, e.g. numpy and scipy. In order to load these modules into ABAQUS python I must install python 2.4.3. on my opensuse laptop. How can I do this without interference with my python 2.6 installation that I use for all my non-ABAQUS python work? Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: pylab/matplotlib large plot memory management - bug? or tuning parameter needed?
bdb112 skrev: Summary: It is not straightforward to avoid memory leaks/consumption in pylab. If we define x = arange(1e6) # adjust size to make the increment visible, yet fast enough to plot # then repetition of plot(x,hold=0) # consumes increasing memory according to ubuntu system monitor [...] I do not know what closing the window does, but in my programs, running on debian and opensuse, I found that explicitly calling close() solved my memory leaks with matplotlib. 3/ Are there python/matplotlib memory management tuning parameters I can tweak? You could try to import gc, and then call gc.collect() after each call to close(). docs at: http://docs.python.org/library/gc.html Hope it helps / johan -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know locals of script without running it
Nadav Chernin skrev: Is there a way to know locals of the script without running it? As I interpret the question, I believe there is. I think Pylint does what you want. I have no idea how it does it, or how certain it can be to find all locals, but it may give you a place to start looking. Pylint homepage: <http://www.logilab.org/857/> / johan -- http://mail.python.org/mailman/listinfo/python-list
Re: python as pen and paper substitute
Manuel Graune skrev: To clarify, I just start an editor, write a file that might look something like this: -snip- code=""" a = 1 b = 2 c = 3 result = a + b """ exec(code) print(code) print("result =\t", result) print("result + c =\t", result + c) -snip-- and feed this to python. I do not understand your use-case, but as one way of performing the same task as the above code, without sacrificing syntax-highlighting, I would suggest: - from __future__ import with_statement import sys def print_source(): print sys.argv with open(sys.argv[0]) as file: for line in file: print line, a = 1 b = 2 c = 3 result = a + b print_source() print("result =\t", result) print("result + c =\t", result + c) ---- Does that help towards a solution of your problem? / johan -- http://mail.python.org/mailman/listinfo/python-list
Re: python as pen and paper substitute
Manuel Graune skrev: Thanks for your reply. The output should 1) show manually selected python code and comments (whatever I think is important), 2) show selected results (final and intermediate) and 3) *not* show python code that for someone only interested in the calculation and the results (and probably not knowing python) would just be "noise" (e. g. "import"-statements, actual "print()"-functions, etc.). Here is my second attempt. This version introduces what I might optimistically call a very simple markup language in the code. Printing of source can selectively be turned on and off by inserting lines beginning with "## Ignore" or "## Show" into the source file. -- ## Ignore from __future__ import with_statement import sys def print_selected_source(): is_printing = True with open(sys.argv[0]) as file: for line in file: if line.startswith("## Ignore"): is_printing = False elif line.startswith("## Show"): is_printing = True elif is_printing: print line, ## Show a = 1 b = 2 c = 3 result = a + b ## Ignore print_selected_source() print("result =\t", result) print("result + c =\t", result + c) -- Is this getting closer? / johan -- http://mail.python.org/mailman/listinfo/python-list
Re: python as pen and paper substitute
Manuel Graune skrev: Manuel Graune writes: Just as an additional example, let's assume I'd want to add the area of to circles. [...] which can be explained to anyone who knows basic math and is not at all interested in python. Third attempt. The markup now includes tagging of different parts of the code, and printing parts of the source based on a tag. (Sorry about the mixture of python 2.X and python 3.X print statements, I use 2.5) - ## Ignore from __future__ import with_statement import sys def print_selected_source(tag = ""): is_printing = True with open(sys.argv[0]) as file: for line in file: if line.startswith("## Ignore"): is_printing = False elif line.startswith("## Show") and tag in line: is_printing = True elif is_printing: print line, from math import pi as PI ## Show Code1 d1= 3.0 A1= d1**2 * PI / 4.0 ## Ignore print_selected_source(tag = "Code1") print ("Area of Circle 1:\t", A1) ## Show Code2 d2= 5.0 A2= d2**2 * PI / 4.0 ## Ignore print_selected_source(tag = "Code2") print ("Area of Circle 2:\t", A2) Sum_Of_Areas= A1 + A2 print ("Sum of areas:\t", Sum_Of_Areas) - / johan -- http://mail.python.org/mailman/listinfo/python-list
Re: open(False) in python3
On Tue, 11 May 2010 19:27:37 -0300, Gabriel Genellina wrote: > so open(False) is the same as open(0), and 0 is the file descriptor > associated to standard input. The program isn't hung, it's just waiting > for you to type some text That's interesting. Are there any more numbered pseudofiles? I suppose its mainly an excellent way to confuse people when you open(0).read(), but it would be interesting to know. Johan Förberg -- http://mail.python.org/mailman/listinfo/python-list
tkinter function outout to text widget
Hi I'm totally new on python and I'm doing an assignement where I'm doing a class that manipulates a text. The program is also supposed to have a GUI, for which I have used tkinter. So far I have entry widgets for file names and buttons, its all working like I want it to. What is missing is a way to output the changes to the text. I was thinking that a text-widget would be suitable. Is there a reasonably easy way to do this? I tried inserting a string to the textwidget and letting the class method change this string, but the inserted string isn't updated in the text-widget. Would be very happy for any hints. -- http://mail.python.org/mailman/listinfo/python-list
Re: Plot problem.. ?? No sign at all
2010-07-06 19:18, Ritchy lelis skrev: On 6 jul, 17:29, Alan G Isaac wrote: Unfortunately I cannot make sense of the code you posted. Provide a detailed description in words (or psuedocode) of what you are trying to accomplish. Be very careful and detailed is you want a useful response. Alan Isaac hummm... ok, i will try to make that detailed description. I can tell you why I do not understand from your posted code what you are trying to do. Firstly, I do not understand if you are trying to plot a surface, a set of curves, or a curve, or just a set of points? In your posted code, the plot command is part of the else clause, and my guess is that you never intend the else-clause to be executed at all. In your code snippet you loop over two arrays (Vi and Vref), compute a scalar value V0, and all plot-commands you issue are of the form plot(V0). This will probably draw a line of one point (for each value in Vi and Vref), which may not be what you want, and if it draws anything at all, then all points will be drawn at the same x-value, which is also probably not what you want. Secondly, how are the Vi and Vref related to your axes? I assume you want to plot all values you compute for V0, but as a function of what? When I use the plot command, I usually give it (at least) two arguments, where the first is the x-axis, and the second is the y-axis. After I have understood those things, the next question would be about the maths relating the Vi and Vref values to the V0 values, but I do not think I will understand those until after the above points are explained clearer. I definitely think your english is not a problem here. Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Plot problem.. ?? No sign at all
2010-07-11 02:12, Ritchy lelis skrev: On 7 jul, 08:38, Johan Grönqvist wrote: About the plot draw it's a curve that it's a set of points wich it's the result of the comput of the Vref and Vi together. I don't know if i had to make a break instruction (like in other's languages) after the "If" instructions if i want the else-condition to be executed? ... (do you have some sujestions?) I would have expected a code structure similar to this: (NOTE: This is a very inefficient solution, and not the one suggested earlier, but it is closer to the code snippet you posted originally, and it does produce a plot.) -- import numpy as np import matplotlib.pyplot as plt Vref = np.linspace(1,20, 100) Vi = np.linspace(1,10,100) for ref in Vref: # Loop over Vref and Vi for i in Vi: if i > ref/4: # Compute V0 V0 = 2*i-ref elif (-ref/4) <= ref and ref <= ref/4: V0 = 2*i elif i < -ref/4: V0 = 2*i+ref plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 plt.show() # Display the plot in a window -- Anyway i have a picture of a tuturial that i found but in this forum i can't post it. That pic would show what a really want... Can you give a link? Relatively to the axis, the Vi takes the x-axis and the Vref takes the y-axis. To me this sound like you want to make a 3D-plot, as there is the x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? As i said, i have a good 2 pic of a doc that has the information about this ADC that i'm developing. I looked on wikipedia <http://en.wikipedia.org/wiki/Analog-to-digital_converter>, and saw some figures. Is any of those similar to what you look for? I see that they have (Vi - Vref) on the x-axis, and the computed value on the y-axis. Regards Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: how to install all python plugins
2010-07-15 18:18, Daniel Fetchinson skrev: If you mean all python packages that are available through the package manager of ubuntu, then you'll need to search the entire list of available packages using ubuntu's package manager, pick out the ones that have 'python' in their names (presumably, this is how it works on fedora) and install them using the above mentioned package manager software. To install all packages whose names start with "python-" in ubuntu: "apt-get install python-*" (as root, or prepended with sudo) / johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Plot problem.. ?? No sign at all
Hi Ritchy, This is the first time I am doing this, but it's a standard response given on lists like this. 2010-07-13 18:17, Ritchy lelis skrev: This is how looks like the flash residue transference function that i was talking about... http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif I'm suposed to obtain a figure like that in my plot. From the hints you have been given, and your answers to those hints, my conclusion is that the issue is not with the programming, but with your understanding of the problem. I get the feeling you do not understand what you are trying to do, and therefore our programming hints do not help you. Based on the "we will not do your homework"-principle, I will therefore not read up on your theory, and therefore not produce your plot for you. That will not change until you show better understanding for the plot you are trying to generate. Regards Johan -- http://mail.python.org/mailman/listinfo/python-list
Creating a local variable scope.
Hi All, I find several places in my code where I would like to have a variable scope that is smaller than the enclosing function/class/module definition. One representative example would look like: -- spam = { ... } eggs = { ... } ham = (a[eggs], b[spam]) -- The essence is that for readability, I want spam and eggs in separate definitions, but for clarity, I would like to express the fact that they are "local to the definition of ham", i.e., they are not used outside of the definition of ham. The language reference at <http://docs.python.org/reference/executionmodel.html> says that "The following are blocks: a module, a function body, and a class definition." (all other cases seem to refer to dynamic execution using eval() or similar). Python 3 and 2.6 seem to have identical scope rules. In the other languages I have used I can either use braces (C and descendants) or use let-bindings (SML, Haskell etc.) to form local scopes. Are there suggestions or conventions to maximize readability for these cases in python? (Execution time is not important in the cases I currently consider.) Regards Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Shebang line problems and python
Blaine skrev: I'm not sure if there is a Ctrl+Z in here... but, here's the output: bla...@attila ~/tmp $ hexdump shebang-test 000 2123 752f 7273 622f 6e69 702f 7479 6f68 010 0a6e 6d69 6f70 7472 7320 7379 730a 7379 020 732e 6474 756f 2e74 7277 7469 2865 4822 030 6c65 6f6c 202c 6f77 6c72 2e64 6e5c 2922 040 000a 041 You can perhaps use "hexdump -c shebang-test" to get characters instead of hexadecimals. / johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a local variable scope.
Thanks for all replies. First, two general comments, and then my conclusions: I did not intend to ask for new features, but my interest was in writing readable code that works in python 2.5, although I may upgrade to 2.6 soon. Also, what I gave was intended as a minimal example, and not a complete use case. Summarizing the answers, it seems that I will try to follow three suggestions: 1) In general, try to restructure the code into smaller modules and smaller functions. 2) When using many local variables bindings to create one larger object, define an inner function that hides those bindings. 3) If I define a few values intended to be used very locally, delete those after use. Thanks again, Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a local variable scope.
Gabriel Genellina skrev: En Fri, 18 Sep 2009 10:55:47 -0300, Johan Grönqvist escribió: Summarizing the answers, it seems that I will try to follow three suggestions: 3) If I define a few values intended to be used very locally, delete those after use. Why bother? Unless they're big objects and you want to ensure they get deleted as soon as possible. To ease debugging. Perhaps the problem only appears because I use longer functions than recommended for python, but I have functions containing 2 to 4 loops, with several if-clause each, where the different parts use very similar variable names, like x, y, z, dr, dr_2, dr_3 etc. None of the code fragments uses all of the names, but every fragment uses some of them. I have had typos that incorrectly reused values from a previous fragment. In those cases, it would have been much easier to debug a raised exception due to using an undefined name, than to debug a slightly incorrect result due to some if-clause of some loop computing with an incorrect value. Regards Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a local variable scope.
Sean DiZazzo skrev: I would do something like this: class Namespace(object): ... pass ... n = Namespace() n.f = 2 n.g = 4 print f Traceback (most recent call last): File "", line 1, in ? NameError: name 'f' is not defined print n.f 2 I like this solution. This also minimizes the extra code if I would want to explicitly delete the bindings, as I would only need one line to delete the Namespace object. Thanks! Johan -- http://mail.python.org/mailman/listinfo/python-list
Installing Python 3.2.3 on Win 7
Hi I installed Python 3.2.3 successfully on my work laptop (XP) but cannot seem to do it on my home PC (Win7) I click the button to install and the window just disappears o the screen. So how do I in fact install Python 3.2.3 on Win 7? -- Johan van Zyl PMB - Box 21673, Mayors Walk, 3208 Pretoria - Box 2667, Brooklyn Square, 0075 FAX: 086 622 9554 The answer my friend is blowin in the wind... If you forward messages, Please use the BCC area, and Please REMOVE all email addresses and all the useless info at the bottom of the message, before you send it on. ONLY send out CLEAN and TIDY emails. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python 3.2.3 on Win 7
Python 32 bit on Win 7 32 bit. Thx! On 16 August 2012 12:32, Tommi Helander wrote: > Hi Johan, > > -Are you trying to install 32 or 64-bit Python? > -Is your Win7 32 or 64-bits? > -Have you tried running the Python installer from the command line to see if > it generates any helpful output? > > -Tommi Helander > >> Date: Thu, 16 Aug 2012 09:17:43 +0200 >> Subject: Installing Python 3.2.3 on Win 7 >> From: jo...@jvz.co.za >> To: python-list@python.org > >> >> Hi >> >> I installed Python 3.2.3 successfully on my work laptop (XP) but >> cannot seem to do it on my home PC (Win7) >> I click the button to install and the window just disappears o the screen. >> So how do I in fact install Python 3.2.3 on Win 7? >> >> -- >> Johan van Zyl >> PMB - Box 21673, Mayors Walk, 3208 >> Pretoria - Box 2667, Brooklyn Square, 0075 >> FAX: 086 622 9554 >> The answer my friend is blowin in the wind... >> If you forward messages, Please use the BCC area, and Please REMOVE >> all email addresses and all the useless info at the bottom of the >> message, before you send it on. ONLY send out CLEAN and TIDY emails. >> Thank you. >> -- >> http://mail.python.org/mailman/listinfo/python-list -- Johan van Zyl PMB - Box 21673, Mayors Walk, 3208 Pretoria - Box 2667, Brooklyn Square, 0075 FAX: 086 622 9554 The answer my friend is blowin in the wind... If you forward messages, Please use the BCC area, and Please REMOVE all email addresses and all the useless info at the bottom of the message, before you send it on. ONLY send out CLEAN and TIDY emails. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: A question on Encoding and Decoding.
[EMAIL PROTECTED] wrote: > Hello, > I think this remark is more to the point. In my experience, the general > problem is that python operates with the default encoding "ascii" as in > sys.getdefaultencoding(). It is possible to set the defaultencoding in > sitecustomize.py, with sys.setdefaultencoding('latin1'). I have placed > sitecustomize.py in Lib/site-packages. It is not possible to set the > encoding once python has started. Setting the encoding only works if > you can bind yourself to this one encoding and is therefore no general > fix. > The only reasonable way to work is to get your strings into unicode > (and sometimes back out again). > If for instance you type: > s = "äÄöÖüÜß" and then try > us = unicode(s) you will get a traceback identical to yours. I missed the beginning of this thread, but why not write s = u"äÄöÖüÜß" Is there ever a reason _not_ to exclusively use the unicode stringtype throughout your Python program? (of course you may need to encode/decode when interfacing with the world outside your program) /johan -- http://mail.python.org/mailman/listinfo/python-list
Re: os.lisdir, gets unicode, returns unicode... USUALLY?!?!?
Laurent Pointal wrote: > gabor a écrit : >> hi, >> >> from the documentation (http://docs.python.org/lib/os-file-dir.html) for >> os.listdir: >> >> "On Windows NT/2k/XP and Unix, if path is a Unicode object, the result >> will be a list of Unicode objects." > > Maybe, for each filename, you can test if it is an unicode string, and > if not, convert it to unicode using the encoding indicated by > sys.getfilesystemencoding(). > > Have a try. > > A+ > > Laurent. Strange coincident, as I was wrestling with this problem only yesterday. I found this most illuminating discussion on the topic with contributions from Mr Lövis and others: http://www.thescripts.com/forum/thread41954.html /johan -- http://mail.python.org/mailman/listinfo/python-list
Difference between CPython, Python for .NET and IronPython?
What is the difference between CPython, Python for .NET, and IronPython? For example, if I'm running IronPython, can I access modules such as Numeric and numarray? As I understand it, interoperability with C# and .NET works in both directions with IronPython, but CPython modules cannot be imported, or? With Python for .NET I can import the .NET Framework and continue using CPython modules, or? What is the roadmap for IronPython, will it be possible to import CPython modules in the near future? One last question, is IronPython cross-platform. That is, can I use IronPython with Mono? Carl -- http://mail.python.org/mailman/listinfo/python-list
Mouseclick
Hello. I have been trying desperately for a while to make Python push the left mousebutton. I have been able to let Python push a button in a box: def click(hwnd): win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, 0, 0) win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, 0) optDialog = findTopWindow(wantedText="Options") def findAButtonCalledOK(hwnd, windowText, windowClass): return windowClass == "Button" and windowText == "OK" okButton = findControl(optDialog, findAButtonCalledOK) click(okButton) As described here, http://tinyurl.com/cwjls. But, that is not what I am looking for. I would like to specify some coordinates such as windll.user32.SetCursorPos(450, 370) and thereafter click the left mousebutton at that place. I know that the sollution lies somewhere with Microsoft (http://www.6URL.com/FED), but cannot understand how to make Python click the button regardless of how much I try. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Py2Exe security
Hello. We have created some programs in Python that are to be distributed around. The programs will be made into .exe files by py2exe. However, in the source there are certain webadresses, logins and passwords that the programs use, that we would like to keep away from the end users. They will use them thru the program, but we would like them not to be extracted and used separately for other purposes. Is the compiling by py2exe enough? I have opened all the files in the directory py2exe has made, and have not found anything I could read in clear text. However, that does not mean that others can not. Is it possible to extract these passwords, adresses and logins from the sourcecode? If py2exe is not enough, is there some other simple tools we can use to hide the source from the endusers? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Py2Exe security
Simon Brunning wrote: > On 3 May 2005 05:03:00 -0700, Terje Johan Abrahamsen <[EMAIL PROTECTED]> wrote: > > We have created some programs in Python that are to be distributed > > around. The programs will be made into .exe files by py2exe. However, > > in the source there are certain webadresses, logins and passwords that > > the programs use, that we would like to keep away from the end users. > > They will use them thru the program, but we would like them not to be > > extracted and used separately for other purposes. > > If your program can access these details, then a suficiently > determined attacker can access them too, regardless of what you do. Yes, I assume so. Luckily it is not national secrets we are trying to hide. But, how does py2exe compare with for example a program written in a compiled language like C++? Is it easier to find the info in a py2exe .exe than a c++ compiled c++? -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Files
Dan wrote: > On Wed, 04 May 2005 10:24:23 +0200, bruno modulix <[EMAIL PROTECTED]> > wrote: > > >As in any other language I know : just open it in write mode !-) > > Easy when you know how. > > Thanks e = file('c:/file.txt', 'w') By the way, check out the Python tutor service... http://mail.python.org/mailman/listinfo/tutor -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression tools?
This is what you are looking for. http://kodos.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
ICFP Programming Contest 2007
Want to show off your programming skills? Your favorite programming language? Your best programming tools? Join the ICFP Programming Contest 2007! The 10th ICFP Programming Contest celebrates a decade of contests. This is one of the world's most advanced and prestiguous programming contest you can enter. For free! Book July 20 - 23, 2007. Check out http://www.icfpcontest.org/. -- http://mail.python.org/mailman/listinfo/python-list
numpy performance and random numbers
Dear friends, I plan to port a Monte Carlo engine from Matlab to Python. However, when I timed randn(N1, N2) in Python and compared it with Matlab's randn, Matlab came out as a clear winner with a speedup of 3-4 times. This was truly disappointing. I ran tthis test on a Win32 machine and without the Atlas library. Why is there such a large difference in speed and how can I improve the speed of randn in Python! Any help with this matter is truly appreciated since I really would like to get away from Matlab and move over to Python instead. Yours Carl -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On Dec 19, 12:29 pm, Steven D'Aprano wrote: > On Sat, 19 Dec 2009 02:05:17 -0800, Carl Johan Rehn wrote: > > Dear friends, > > > I plan to port a Monte Carlo engine from Matlab to Python. However, when > > I timed randn(N1, N2) in Python and compared it with Matlab's randn, > > What's randn? I don't know that function. I know the randint, random, and > randrange functions, but not randn. Where does it come from? > > > Matlab came out as a clear winner with a speedup of 3-4 times. This was > > truly disappointing. I ran tthis test on a Win32 machine and without the > > Atlas library. > > > Why is there such a large difference in speed and how can I improve the > > speed of randn in Python! Any help with this matter is truly appreciated > > since I really would like to get away from Matlab and move over to > > Python instead. > > Could be many reasons. Python could be generally slower than Matlab. Your > timing code might have been faulty and you weren't comparing equal > amounts of work (if your Python code was doing four times as much work as > the Matlab code, then naturally it will be four times slower). Perhaps > the Matlab random number generator is a low-quality generator which is > fast but not very random. Python uses a very high quality RNG which is > not cheap. > > But does it really matter if the RNG is slower? Your Monte Carlo engine > is a lot more than just a RNG. What matters is whether the engine as a > whole is faster or slower, not whether one small component is slower. > > -- > Steven randn is given by >> import numpy >>> numpy.random.randn(2,3) array([[-2.66435181, -0.32486419, 0.12742156], [-0.2387061 , -0.55894044, 1.20750493]]) Generally, at least in my MC application, I need a large number of random numbers. Usually I execute, for example, r = randn(100, 1) sequentially a relatively large number of times until sufficient accuracy has been reached. Thus, randn is in my case a mission critical component for obtaining an acceptable overall run time. Matlab and numpy have (by chance?) the exact names for the same functionality, so I was very happy with numpy's implementation until I timed it. So the basioc question is, how can I speed up random number generation? Carl -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On Dec 19, 2:49 pm, sturlamolden wrote: > On 19 Des, 11:05, Carl Johan Rehn wrote: > > > I plan to port a Monte Carlo engine from Matlab to Python. However, > > when I timed randn(N1, N2) in Python and compared it with Matlab's > > randn, Matlab came out as a clear winner with a speedup of 3-4 times. > > This was truly disappointing. I ran tthis test on a Win32 machine and > > without the Atlas library. > > This is due to the algorithm. Matlab is using Marsaglia's ziggurat > method. Is is the fastest there is for normal and gamma random > variates. NumPy uses the Mersenne Twister to produce uniform random > deviates, and then applies trancendental functions to transform to the > normal distribution. Marsaglia's C code for ziggurat is freely > available, so you can compile it yourself and call from ctypes, Cython > or f2py. > > The PRNG does not use BLAS/ATLAS. Thank you, this was very informative. I know about the Mersenne Twister, but had no idea about Marsaglia's ziggurat method. I will definitely try f2py or cython. Well, I guess I knew that random numbers were not handled by BLAS/ ATLAS, but wasn't 100% sure. Carl -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On Dec 19, 3:16 pm, sturlamolden wrote: > On 19 Des, 14:06, Carl Johan Rehn wrote: > > > Matlab and numpy have (by chance?) the exact names for the same > > functionality, > > Common ancenstry, NumPy and Matlab borrowed the name from IDL. > > LabView, Octave and SciLab uses the name randn as well. > > > So the basioc question is, how can I speed up random number > > generation? > > The obvious thing would be to compile ziggurat yourself, and turn on > optimization flags for your hardware.http://www.jstatsoft.org/v05/i08/ > > P.S. Be careful if you consider using more than one processor. > Multithreading is a very difficult issue with PRNGs, becuase it is > difficult to guarrantee they are truely independent. But you can use a > producer-consumer pattern, though: one thread constantly producing > random numbers (writing into a buffer or pipe) and another thread(s) > consuming them. How about mulit-core or (perhaps more exciting) GPU and CUDA? I must admit that I am extremely interested in trying the CUDA-alternative. Obviously, cuBLAS is not an option here, so what is the safest route for a novice parallel-programmer? Carl Carl -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On Dec 19, 4:47 pm, sturlamolden wrote: > On 19 Des, 16:20, Carl Johan Rehn wrote: > > > How about mulit-core or (perhaps more exciting) GPU and CUDA? I must > > admit that I am extremely interested in trying the CUDA-alternative. > > > Obviously, cuBLAS is not an option here, so what is the safest route > > for a novice parallel-programmer? > > The problem with PRNG is that they are iterative in nature, and > maintain global states. They are therefore very hard to vectorize. A > GPU will not help. The GPU has hundreds of computational cores that > can run kernels, but you only get to utilize one. > > Parallel PRNGs are an unsolved problem in computer science. >>>How did you time it? Well, in Matlab I used "tic; for i = 1:1000, randn(100, 1), end; toc" and in IPython i used a similar construct but with "time" instead of tic/(toc. >>> Parallel PRNGs are an unsolved problem in computer science. Thanks again for sharing your knowledge. I had no idea. This means that if I want to speed up my application I have to go for the fastest random generator and focus on other parts of my code that can be vectorized. Carl -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On 19 Dec, 23:09, sturlamolden wrote: > On 19 Des, 22:58, sturlamolden wrote: > > > If you pick two random states (using any PRNG), you need error- > > checking that states are always unique, i.e. that each PRNG never > > reaches the starting state of the other(s). > > Another note on this: > > Ideally, we would e.g. know how to find (analytically) MT states that > are very far apart. But to my knowledge no such equation has been > derived. > > But often in Monte Carlo simulations, the PRNG is not the dominant > computational bottleneck. So we can simply start N PRNGs from N > consequtive states, and for each PRNG only use every N-th pseudorandom > deviate. Thank you for pointing me to the short-period MT reference and especially the reference on the CUDA-version of parallel MT (even though I would have wished the author had included a benchmark comparison in the report). This is a very interesting topic. I agree that it may work to start PRNGs at distinct and different states, but that bookkeeping may slow down the algorithm so that it is not worth the effort. However, the CUDA-version sounds interesting and should be easy enough to use in a practical application. Carl -- http://mail.python.org/mailman/listinfo/python-list
NumPy and vectorize
I'm having problem with the return values of NumPy's vectorize function. When I pass an array of strings in the following simple example, vectorize truncates the strings in the returned list. Any clues of what to do? Yours, Carl import numpy as np def __f(x): return x f = vectorize(__f) s = '2010-04-28' y1 = f(s) y2 = f(np.array([s, s, s, s])) In [62]: y1 Out[62]: array('2010-04-28', dtype='|S10') In [63]: y2 Out[63]: array(['2010-04-', '2010-04-', '2010-04-', '2010-04-'], dtype='|S8') -- http://mail.python.org/mailman/listinfo/python-list
Bug report - Python 3.10 from Microsoft Store - IDLE won't start
Hello, IDLE won't start if ver. 3.10 is installed from Microsoft Store. 3.9 works just fine. Thanks in advance! Johan Gunnarsson Lunds universitet Medicinska fakulteten Bibliotek & IKT Box 118, 221 00 Lund<https://webmail.lu.se/owa/> Besöksadress: Sölvegatan 19, 221 84 Lund<https://webmail.lu.se/owa/> Telefon: +46 46 222 18 23 www.medicin.lu.se<http://www.medicin.lu.se/> -- https://mail.python.org/mailman/listinfo/python-list
XML + SOAP + Webservices
I'm put on building a system in Python and I haven't used either webservices, SOAP or Python so I'm a bit lost. This system will require callback functions, should I use Python thru Apache for this or build my own listening daemon? Use module for Apache or do I make some kind of CGI script in Python? Where do I start? What lib do I use for XML? SOAP? Webservices? Is there any nice project/tutorial for this so I can give it a taste and try to estimate how much time I need and stuff. Help needed. =) Thanks. signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: XML + SOAP + Webservices
On 2005-06-09 13:21 +0200 or thereabouts, Johan Segernäs wrote: > I'm put on building a system in Python and I haven't used either webservices, > SOAP or Python so I'm a bit lost. Addon: I will speak to .NET-stuff in the other end, does this create problems? signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: XML + SOAP + Webservices
On 2005-06-09 14:20 +0200 or thereabouts, Diez B. Roggisch wrote: > a way to pass a server the necessary callback information. It basically > consists of the url to talk to. That by the way is no limitation of But of course, a little slip in my thoughts. > Sooo - concluding remarks could be: > - soap and python - not so good > - if you can, use some other RPC to interface .NET - like IPython, or > win32, or even corba if you can. Basically, don't write the implementation to talk to the SOAP/WDSL-services in Python, find something else and this 'something else' produces an XML file which I then parse with Python? win32 isn't an option, we only have *nix-boxes around and we plan to stay that way. Very good answer btw, thanks alot. signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list