exec, import and isinstance
Hi all, I'm playing with python internals and I'm discovering a strange behavior of isinstance. Considering the following test case: test/bar.py test/b.py test/a/__init__.py test/a/foo.py -- __init__.py - empty --- foo.py: class foo: pass c = foo --- b.py def ret(): d = {} #s = import sys;sys.path.append('a');import foo ## this cause the problem s = import sys;from a import foo exec s in d return d[foo].c --- bar.py import a.foo import b c1 = a.foo.foo c2 = b.ret() print c1, c2 print isinstance(c2(), c1) --- Executing bar.py, I receive: a.foo.foo a.foo.foo True But, if I replace the indicated line, python doesn't recognize anymore the instance and I receive: a.foo.foo foo.foo False Why? I don't understand how python see the instance. Or better, does it see only the path? The classes (and the instances) are the same! Thanks for all that help me to turn the light on... Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Computer Music Toolkit (CMT) ?
Terry Reedy wrote: On 1/10/2010 4:15 AM, Peter Billam wrote: Greetings. Is there a way to get at the Computer Music Toolkit (CMT) http://www.ladspa.org/cmt/ functionality from Python (Python3 in my case) ? You can access compiled C shared libraries most easily via the ctypes module. so if you do develop a ctypes wrapping, consider contributing it. Since I'm interested to do it for a my new project, if the OP are interested, please contact me directly. Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL and Python
catafest wrote: I don't extract data from jpegs. I wanna put some data in this (copyright of my site) ... My wrap for freeimage, called freeimagepy :) can't, as now, wrote exif information on the image, but since freeimage can do it, I think that it's not so difficult to add this type of feature. If you have some time for investigate and create a patch, I'll be happy to include it into the mainline! Contact me directly if you want to talk of need some help on how do it. Michele -- http://mail.python.org/mailman/listinfo/python-list
python 3 and stringio.seek
Hi list, I'm trying to port a my library to python 3, but I have a problem with a the stringio.seek: the method not accept anymore a value like pos=-6 mode=1, but the old (2.X) version yes... The error: File /home/devel/Py3/lib/python3.0/io.py, line 2031, in seek return self._seek(pos, whence) IOError: Can't do nonzero cur-relative seeks How solve this? Thanks, MIchele -- http://mail.python.org/mailman/listinfo/python-list
Re: try except inside exec
Emile van Sebille wrote: Write the string out to a .py file and import it? I don't think that it's possible. I want to create an env that are accessible only from that peace of code and not from the code that execute the third-party one. Emile Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: try except inside exec
David Stanek wrote: Is the thirdparty function the entire STR or just the a_funct part? Just the a_funct. Only for try and for see if it's possible to catch all the (possible) exception(s), I add the try/except clause that include the a_funct external code. Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: try except inside exec
Aaron Brady wrote: Exceptions are only caught when raised in a 'try' statement. If you don't raise the exception in a try statement, it won't be caught. The function you posted will raise an exception. If you are making the call yourself, that is, if only the definition is foreign, then simply catch exceptions when so. Seeing my code and reading you post I found that... yes, are a my fault! I'm catching only an exception in a code/function definition, no its execution! Just modified my code to catch the exception *inside* the def and not before and... now work! Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and PPID
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Michele Petrazzo wrote: I have a code that execute into a Popen a command (ssh). I need that, if the python process die, the parent pid (PPID) of the child don't become 1 (like I can seen on /proc/$pid$/status ), but it has to die, following it's parent It's possible in linux and with subprocess? There is a Linux-specific system call that says it does this (haven't tried). See the prctl(2) man page. Just seen. It can be, bust since I cannot modify the child process and this syscall must be called from the child, I cannot use it. Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and PPID
[EMAIL PROTECTED] wrote: It's possible in linux and with subprocess? AFAIK, there is no easy way to do this. If the parent python process is doing a controlled exit, just kill the child via close() on Popen() handle. Like I do ;) If the parent is doing a uncontrolled exit (say via a SIGKILL signal), you can't really do anything. The only thing that I thought it's to use an external resource, like a .pid file where I save the child pid(s) and, on the next parent startup control the file and kill the process, if any To reliably have the child exit when the parent exits, you would have to poll for the parent from the child and do a exit when the child detects that the parent has gone away. Like said, I haven't the control of the sources, so I can't. Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
subprocess and PPID
Hi all, I believe that this is a *nix question, but since I'm developing in python, I'm here. I have a code that execute into a Popen a command (ssh). I need that, if the python process die, the parent pid (PPID) of the child don't become 1 (like I can seen on /proc/$pid$/status ), but it has to die, following it's parent It's possible in linux and with subprocess? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and PPID
Jorgen Grahn wrote: On Wed, 5 Nov 2008 08:19:34 -0800 (PST), [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Nov 5, 5:12 pm, Michele Petrazzo [EMAIL PROTECTED] wrote: Hi all, I believe that this is a *nix question, but since I'm developing in python, I'm here. I have a code that execute into a Popen a command (ssh). I need that, What's 'a Popen'? Is it os.popen or one of its variants? Popen is the default python Popen: from subprocess import Popen, PIPE cmd = ssh -C -N -i keys/id_rsa_key -L remote:ip:local [EMAIL PROTECTED] cmd_p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE) Do you read from it or write to it? If you do both, you should use something like the third-party module pexpect instead. Nothing. I do only a tunnel To reliably have the child exit when the parent exits, you would have to poll for the parent from the child and do a exit when the child detects that the parent has gone away. But in the special case where he's feeding data into ssh somewhere somecmd or pulling data from it, a crash of the parent should make somecmd exit because it sees EOF, and thus make the ssh process end. Sounds relatively risk-free -- but it depends on somecmd. Interesting. So, how I have to modify my code (if I can)? Add an stdin? /Jorgen Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
overwrite set behavior
Hi all, I want to modify the method that set use for see if there is already an object inside its obj-list. Something like this: class foo: pass bar1 = foo() bar1.attr = 1 bar2 = foo() bar2.attr = 1 set( (bar1, bar2), key=lambda o: o.attr) and, of course, set has only one value. It's possible? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: overwrite set behavior
Marco Bizzarri wrote: looking at the source, maybe you could create a subclass of Set redefining the __contains__ method? Made some tries, but __contains__ are never called class foo(set): ... def __contains__(self, value): ... print value ... a = foo((1,2)) Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Python multimap
brad wrote: Recently had a need to us a multimap container in C++. I now need to write equivalent Python code. How does Python handle this? k['1'] = 'Tom' k['1'] = 'Bob' k['1'] = 'Joe' Same key, but different values. No overwrites either They all must be inserted into the container Subclassing the builtin dict? class d(dict): def __setitem__(self, item, value): if not item in self: super(d, self).__setitem__(item, []) self[item].append(value) D = d() D[1] = Hello D[1] = World! D[1] ['Hello', 'World!'] Thanks, Brad Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: annoying dictionary problem, non-existing keys
bvidinli wrote: i use dictionaries to hold some config data, such as: conf={'key1':'value1','key2':'value2'} and so on... when i try to process conf, i have to code every time like: if conf.has_key('key1'): if conf['key1']'': other commands this is very annoying. in php, i was able to code only like: if conf['key1']=='someth' in python, this fails, because, if key1 does not exists, it raises an exception. That is one of python rules: import this (cut) Explicit is better than implicit. (cut) php hide some thing that python expose. MY question: is there a way to directly get value of an array/tuple/dict item by key, as in php above, even if key may not exist, i should not check if key exist, i should only use it, if it does not exist, it may return only empty, just as in php i hope you understand my question... You can simple modify the dict behavior: class my_dict(dict): ... def __getitem__(self, item): ... if item in self: ...return super(my_dict, self).__getitem__(item) ... else: ...return '' ... d = my_dict() d[a] '' d[a] = 5 d[a] 5 Michele -- http://mail.python.org/mailman/listinfo/python-list
C to python conversion
Hi all, I'm trying to translate a simple C code into a python + ctypes (where need), but I have some problems on char conversion. The code have to work on Linux and talk with the serial port. I think that the problem is that I don't translate correctly the strings. C code: #define START 0x33 #define RETURN_START 0x22 #define ADDR 0x01 #define WRITE_CMD 0x03 #define ALL_CMD 0xFF ... char buf[10]; char buf_ret[10]; buf[0]=0; buf[0]=START; buf[1]=ADDR; buf[2]=WRITE_CMD; write(_fd, buf, 6); read(_fd,buf_ret,6); It works python: START = 0x33 RETURN_START = 0x22 ADDR = 0x01 WRITE_CMD = 0x03 ALL_CMD = 0xFF lib = C.CDLL('libc.so.6') items = [START, ADDR, WRITE_CMD] buf = C.c_char * 10 buffer_rec = buf() buffer_send = buf(*items) (Here I receive: TypeError: one character string expected) If I do: chr(int()) of every value, it work, but: lib.write(fd, buffer_send, 6) lib.read(fd, buffer_rec, 6) I stay there and block the program execution, until a CTRL+C What can I do? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Strange problems with subprocess
Hi all. I have a simple ping tester program that, every 1 minute (execute by linux crontab), create, with subprocess, a ping -c 1 my_addrs. All work, but sometime (about 1/2 times at a day), I receive this error message: File /exports/srv-wipex/net_test/ping_tester.py, line 88, in pyPing cmd_p = Popen(cmd, stdout=PIPE, stderr=PIPE) File subprocess.py, line 543, in __init__ errread, errwrite) File subprocess.py, line 970, in _execute_child data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB What can be that raise this? Python 2.4 in deb etch Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange problems with subprocess
[EMAIL PROTECTED] wrote: This doesn't look like a complete traceback. It doesn't give what the error was. Forgot a line, sorry! exceptions.OSError: [Errno 4] Interrupted system call Mike Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning to use wxPython
KDawg44 wrote: Hi, Hi, I downloaded the wxPython demo and did an emerge wxpython (gentoo) to install. When I run the demo, I am getting this error: # python demo.py Traceback (most recent call last): File /usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/ _misc.py, line 1286, in Notify From here, I read that you are using the wx version 2.6 and the demo that you are tring are for the 2.8.3! (the last as now). So: 1) install the new 2.8 2) download the demo for the 2.6! :) Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Making GIF image twice the size - in memory
Miki wrote: Hello All, Heelo, I get an image from a web page (via urlopen), and like to make it twice the size. -cut- However I don't get a valid GIF image. Your code work well here! Why you said that the string are invalid? --code: test_image_double.py from urllib import urlopen import Image from ImageFile import Parser def double(image_data): image_parser = Parser() image_parser.feed(image_data) im = image_parser.close() new_size = tuple(map(lambda x: 2 * x, im.size)) new = im.resize(new_size) return new.tostring(gif, P), new, new_size url = http://www.google.com/intl/en_ALL/images/logo.gif; image_data = urlopen(url).read() image_data, img, new_size = double(image_data) img_new = Image.fromstring(P, new_size, image_data, gif) img_new.save(./out1.gif) img.save(./out2.gif) print PIL version:, Image.VERSION -- test michele:~/tmp$ python test_image_double.py file out1.gif file out2.gif (552, 220) 49554 PIL version: 1.1.5 out1.gif: GIF image data, version 87a, 552 x 220 out2.gif: GIF image data, version 87a, 552 x 220 michele:~/tmp$ Any ideas? Forgot to specify that the data aren't in raw format, but to decode it with the gif encoder? Thanks, Ciao, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: failed to install PIL in fedora core 6
Frank Potter wrote: I use python setup.py install to install PIL in fedora with python 2.4, But I got these errors: -cut some errors- error: Python.h: No such file or directory In file included from libImaging/Imaging.h:14, from _imaging.c:78: So you don't have the python-dev package. What should I do if I want to successfully have pil installed? Try to search into the Fedora repos for the PIL (or python-imaging). If not, install the python-dev and compile! Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: beep or sound playing under linux
hg wrote: Hi, Is there a way to do that ? I can do it, into my debian, with a: michele:~$ echo -e \007 /dev/tty It's very simple to reproduce it with python and os.system or subprocess. Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: wxWindows off-screen?
Ivan Voras wrote: Is it possible to draw a widget or a window in an off-screen buffer? (Assuming that you are on linux.) wxWigets (wxWindows is the old name) or better, since if you are on a python ng, wxPython :), can't be used if you are on a not-X machine: michele:~$ env | grep DIS DISPLAY=:0.0 michele:~$ export DISPLAY= michele:~$ env | grep DIS DISPLAY= michele:~$ python Python 2.4.4 (#2, Oct 20 2006, 00:23:25) [GCC 4.1.2 20061015 (prerelease) (Debian 4.1.1-16.1)] on linux2 Type help, copyright, credits or license for more information. import wx a = wx.PySimpleApp() Unable to access the X Display, is $DISPLAY set properly? michele:~$ echo $? 1 michele:~$ What I'm trying to do is capture rendered HTML to a bitmap (in other words, something like html2bitmap) by using wxWindows' HTML widget. If anyone has a different way of doing it, I'd be glad to hear it... For me you have some solutions: - open an X server (only X, you don't need gdm, kdm other), set the right DISPLAY env variable and use wx. Ok, you need (a lot of) memory, that in my tests are about 16 M for Xorg and 24 for python with wx, a wxFrame, wxPanel and some controls. Can be a good/the right solution for me. - If I remember correctly, there are a project that emulate an X server (so the same that the X solution, but with less memory), but I don't know its name... Try to search on internet. - Always with an X server, use a browser and with its api (pyxpcom for mozilla based, or dcop and pykde for konqueror and so on...), using the print on a file feature, so print a ps and convert it on an image. Good try :), and not forgot to tell us your results! Hope this help, Michele -- http://mail.python.org/mailman/listinfo/python-list
optparser question
I'm trying optparse and I see a strange (for me) behavior: def store_value(option, opt_str, value, parser): setattr(parser.values, option.dest, value) parser = optparse.OptionParser() parser.add_option(-f, --foo, action=callback, callback=store_value, type=int, dest=foo) args = [-f, 1] (options, args) = parser.parse_args(args) print options, args {'foo': 1} [] # with the type {'foo': None} ['1'] #without it If I not specify the type in add_options, the value aren't passed to the store_value (into value variable), but it's understood as args! If I specify it, it Is this normal? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: optparser question
Steven Bethard wrote: You can try using argparse_, which doesn't make these weird inferences, and generally assumes that your action will take a single argument unless you specify otherwise:: -cut- Not sure exactly what your callback was trying to do though -- it seems like you're just duplicating the 'store' action (which is the default anyway). I made only a copy from the python docs for show the problem. Ok, I have not understand the trickle for transform the action=callback and provide a callback to a new action. I believe, however, that the doc has to be more explicit about this strange behavior, because a not so expert dev (like me :) ), can don't understand at the first time, it. STeVe Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: FreeImagePy creating thumbnails from TIFF
[EMAIL PROTECTED] wrote: I a trying to create a series of thumbnail images from a multpage TIFF file. The sample code is below. When it executes, we get the following error; FreeImagePy.constants.FreeImagePy_ColorWrong: 'Wrong color 1 in function: FreeImage_MakeThumbnail. I can use: (8, 24, 32)' Any suggestions? Found a bug! Change, into the funct_list, at line 119, ('FreeImage_MakeThumbnail', '@12', (CO.COL_8, CO.COL_24, CO.COL_32) ), to ('FreeImage_MakeThumbnail', '@12', CO.COL_1TO32 ), and it'll work. Or update to the new svn version (r21), that adds the __iter__ method for the Image class. Now you can do this: fname = 01-PJ2306.tif img = FIPY.Image(fname) for bmp in img: new_img = bmp.thumbnail(300) Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Execute external code and get return value
Hi, I want to execute an external code, that become from a text file (pe), call a function inside it and get its return value: # ext_code.txt def funct2Call(): return True # test.py sourcecode = open(ex_code.txt).read() comp_code = compile(sourcecode, My_test, exec) #do something like this return_value = comp_code.funct2Call() But I can't... I find this: http://tinyurl.com/nwbpk but here, it call from the external code a function inside my code. I want the opposite! Is there a solution for do this? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute external code and get return value
Michele Petrazzo wrote: Auto reply: I find this: http://tinyurl.com/nwbpk Following this link, here is my solution: code = def funct2Call(): return It work! object.method(funct2Call) class Object(object): def method(self, value): self._callable = value def __call__(self): return self._callable() # populate the namespace namespace = { object: Object() } # execute the code exec code in namespace namespace[object]() Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute external code and get return value
Peter Otten wrote: Michele Petrazzo wrote: I want to execute an external code, that become from a text file (pe), call a function inside it and get its return value: namespace = {} execfile(ext_code.txt, namespace) print namespace[funct2Call]() Sorry, I forgot to say that ext_code.txt isn't a real file, but a text become from a db, so or I create a temp file where I save the code and pass its path to execfile, or use my post. Peter Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Decoding group4 tiff with PIL
Filipe wrote: Is decoding group4 tiff possible with Python Imaging Library? Not natively: http://mail.python.org/pipermail/image-sig/2003-July/002354.html [1] http://effbot.python-hosting.com/file/stuff/sandbox/pil/libtiff.py [2] http://www.haynold.com/software_projects/2004/pytiff/ Any thoughts? [1] Seem to work. You need only some dlls (http://gnuwin32.sourceforge.net/packages/tiff.htm) [3] FreeImagePy Cheers, Filipe Bye, MIchele -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL cannot open TIFF image in Windows
Rob Williscroft wrote: I downloaded some test images from: url:http://www.remotesensing.org/libtiff/images.html I do the same and modified your code for try FreeImagePy and the results are: ok: 41 error: 20 total: 61 Better than PIL, but a lot of problems with lower-rgb-planar- 8 and flower-rgb-contig- 8 IrfanView seem that can load all the images... Rob. Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe: cannot identify image file
Daniel Mark wrote: Hello all: It seems that function 'Image.open' cannot read image file under EXE application. What should I do for this problem? google and pil py2exe, the first reply: http://starship.python.net/crew/theller/moin.cgi/PIL_20and_20py2exe Thank you -Daniel Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for EXIF-info-additions ?
Bror Johansson wrote: Is there somewhere some Python-module that can be used for adding EXIF-info to JPEG files? (Modules for extraction of EXIF-data are easily found, but lacks - as I see it - capacity to add new tags.) Hi, this is a feature that I want to add to FreeImagePy. It's not so difficult, but now I haven't time to do it. If you want to spend some hours for make enjoying yourself and all the python community, email me! :) /BJ Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for EXIF-info-additions ?
Bruno Dilly wrote: I think you can find what do you need into this repository, it's a creative commons tool: https://svn.berlios.de/svnroot/repos/cctools/publisher/branches/flickr-storage-branch/ take a look in the follow directory: ccpublisher/jpeg/ I'm not sure if it's what you want, let me know. This is more and more times harder than I need! This code add the exif tags to the image by itself, but I need only to wrap and add some python code for make freeimagepy talk with the tags freeimage's functions. Only this! All the tags code for add/remove/modify them are already inside freeimage! See you, Dilly Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
look for a module without import it
Hi list, I have to know if a module are present on the system, but I don't want to import it. Only know if it is present. I think that a loop on the site-packages directory can do the work, but is there another solution? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: look for a module without import it
Fredrik Lundh wrote: more module.py print I'M MODULE! python import imp imp.find_module(os) It was! Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: string replace
[EMAIL PROTECTED] wrote: Check out the .translate method and the string.maketrans documentation. You can use it to delete a list of characters all in one line: Yes. This is, more or less, what I were looking for. P.s. Sure, if replace could accept a tuple... :) Thanks to all, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: python for windows internet filter / firewall
[EMAIL PROTECTED] wrote: Greetings, I'm interested in a simple content-based internet firewall/filter, similar to dansguardian (http://dansguardian.org/), Firewall and filter are two things totally separated! - If you want to do something like a page filtering, like dansguard and squidguard, you can simple do it with python, because you have to act like a proxy that leave of not visit a page. - If you have to do a firewall... I think you can't, especially if you are on win. Take a look at wipfw (wipfw.sf.net) that do what you want but written in python, Of course :) and for windows. Why? All that work with networking (and not only that) work better with *nix OS! I assumed such a project would already exist, Firewall I don't think, and the same for the filtering (I know only something like a plugin for squid, so for *nix platform). but my searches on freshmeat, and google turned up empty. I would be interested in starting my own project if necessary, so I have two questions: 1) Does any one no of such a project? 2) Is this even reasonable in python and how might I get started? (e.g. win32 COM?) win32COM for do what? You can do it in not so difficult manner: Take twisted and its proxy class, make some outline code (for filter the pages) and enjoy! (work also on win) Thanks much -- matthew P.s. Don't forgot to share your code, when it'll work :) Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Way for see if dict has a key
Hi ng, what the preferred way for see if the dict has a key? We have a lot of solutions: key in dict key in dict.keys() dict.has_key(key) ... but what the better or the more pythonic? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Way for see if dict has a key
Fredrik Lundh wrote: Michele Petrazzo wrote: what the preferred way for see if the dict has a key? We have a lot of solutions: key in dict new syntax (2.3 and later). So, following it, it can be used for the operations like len? len(dict) - len(dict.keys()) ? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Way for see if dict has a key
Bruno Desthuilliers wrote: but what the better Depends on the context. If know only one context: see if the key are into the dict... What other context do you know? Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Way for see if dict has a key
Fredrik Lundh wrote: Michele Petrazzo wrote: key in dict new syntax (2.3 and later). So, following it, it can be used for the operations like len? what's it in this sentence? It, is the thought that the new 2.3 introduce. Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: delete first line in a file
Juergen Huber wrote: but...how can i say python, delete the first line?! thats my problem! You can open the file, read its lines with readlines function ( that return a list), so make your modifies and save to another file. Now, do you know how to work with lists? http://python.org/doc/2.4.2/tut/node5.html#SECTION00514 and now you have only to wrote it http://python.org/doc/2.4.2/tut/node9.html#SECTION00920 Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Way for see if dict has a key
André wrote: Michele Petrazzo wrote: Bruno Desthuilliers wrote: but what the better Depends on the context. If know only one context: see if the key are into the dict... What other context do you know? Michele Perhaps Bruno meant this: try: ... my_dict[key] ... except: Yes I see :) when we expect that the key will most often be in my_dict so that exception will be raised rarely I didn't thought this because if I think that a key aren't in a dict, I use dict.get(key, default) otherwise use if key in dict André Thanks to all, Michele -- http://mail.python.org/mailman/listinfo/python-list
string replace
Hi, a lot of times I need to replace more than one char into a string, so I have to do something like value = test chars = e for c in chars: value = value.replace(c, ) A solution could be that replace accept a tuple/list of chars, like that was add into the new 2.5 for startswith. I don't know, but can be this feature included into a future python release? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: python for windows internet filter / firewall
[EMAIL PROTECTED] wrote: Thanks for a detailed reply. I thing that now we are becoming OT... :) because is restricts traffic on a port based on content, but you're correct, they aren't the same thing at all. So, what you want to do? Open and close a destination IP (domain), following what the user see, with a firewall? It's so hard to do, and it doesnt' sound like a good think. This is the work of a proxy, not of a firewall. win32COM for do what? My knowledge of COM is miniscule, but I assumed it has a low level interface for packet filtering. Yes, but you have to create a dll that work at low level and has an low level features... Something like that wipfw do: create a .sys/.vxd (if I remember correctly) that in your case are the dll and after with an exe (that are the python program) that teach the rules... Very bas idea, for me! You can do it in not so difficult manner: Take twisted and its proxy class, make some outline code (for filter the pages) and enjoy! (work also on win) Proxy would be an easy way, but I wanted to do it at a lower level. But you _can't_ with python. How you create a .sys/.vxd file? Also that has only few kb program? And don't such more than few kb memory? Keep the proxy way or switch to another language :) Thanks again. --matthew Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem on win xp and run time error
Chris Lambacher wrote: On Sat, Jun 17, 2006 at 07:32:34AM +, Michele Petrazzo wrote: Chris Lambacher wrote: On Fri, Jun 16, 2006 at 06:11:53PM +, Michele Petrazzo wrote: Hi list, just found in this moment that my applications stop to work with win xp and receive this error: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. (Note that the same application [python source code + py2exe] with python 2.3.x work well!) Don't use the single file executatble option with py2exe and the problem will go away. I'm not using that option! (that has also problems on win9x with python+wx) Do you get the problem when you are not using py2exe? That will be your real clue about what the culprit is. No, but... I'm not using any of the bundle_files options, but only: zipfile = lib/libraries.zip Try setting that to the default value for the moment and see if it gets you anywhere. You might also want to try an older version of py2exe. I would blame an interaction between py2exe and some extension you are using, unless you can get it to happen without py2exe. Was, I think, a win problem because after the last windows update all now work! Thanks for the support, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem on win xp and run time error
Chris Lambacher wrote: On Fri, Jun 16, 2006 at 06:11:53PM +, Michele Petrazzo wrote: Hi list, just found in this moment that my applications stop to work with win xp and receive this error: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. (Note that the same application [python source code + py2exe] with python 2.3.x work well!) Don't use the single file executatble option with py2exe and the problem will go away. I'm not using that option! (that has also problems on win9x with python+wx) I'm not using any of the bundle_files options, but only: zipfile = lib/libraries.zip -Chris Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem on win xp and run time error
Fredrik Lundh wrote: I see that the page says: This problem may occur when you use the /GR and the /MD compiler switches hint 1: the use of may in that sentence is intentional. This is the only, real, answer/solution that I found on internet, so I thought that was the problem. This also convince me because the page said that this happen only on win xp sp2, that is the platform where the problem happens! All work on win2k! hint 2: python 2.4 wasn't built with Visual C++ 6.0 (but python 2.3 was) But, I have problems only on with 2.4! With 2.3, and the *same* code, all work! hint 3: on Windows, this message is displayed when the abort function is called (including when an assert fails): http://msdn2.microsoft.com/en-us/library/k089yyh0.aspx the python interpreter will call abort() when it stumbles upon a fatal error (Py_FatalError), or when an internal assertion fails. when this happens, the program will print a Fatal Python error message to both stderr and the debug console before it calls abort. Normally py2exe catch that messages and show them when the program are closed, but in this case, I don't see any message :( Is it possible that some, but I don't know what, can be modified from py2.3 to py2.4 and now my program wont work? Is there some tried that I can do for try to solve my issue? /F Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Problem on win xp and run time error
Hi list, just found in this moment that my applications stop to work with win xp and receive this error: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. (Note that the same application [python source code + py2exe] with python 2.3.x work well!) With a little google search I found that this is a win xp sp2 problem *without* apparently solution :( http://support.microsoft.com/kb/884538/en-us I see that the page says: This problem may occur when you use the /GR and the /MD compiler switches so my question are: python are compiled with that switches? If yes, can someone try to compile it without that switches, if it can of course, and publish the new installer? I'm can't work until microsoft solve that issue! :( Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: FreeImagePy and PIL
David Isaac wrote: I am just starting to think about image processing. What are the overlaps and differences in intended functionality between FreeImagePy and PIL? Thanks, Alan Isaac http://tinyurl.com/m5kal For any other questions, I'm here :) Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to get FreeImagePy to work.
Fredrik Lundh wrote: So you *need* to invert it to work correctly with PIL! PIL has no problem reading min-is-white TIFF images. it would be nice if you stopped posting bogus support information for other libraries. Sorry if my posts make to seem that other libraries has problems! Sure that *my* wrap has problems, like I have problem with something that I don't know so well, like Image world (like I always said). I'm only suggesting some, bad, trick for do the work that Iain wants. I tried, but without success, to make the convertToPil function work with 1, 8, 16 bpp... Seem that only 24/32 work, but I don't know why. I know that PIL doesn't have problems! /F Hope that this can explain better the situation. Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to get FreeImagePy to work.
Iain King wrote: I'll try out FIPY's resizing tomorrow too. OTOH, I have functions to convert between PIL and wxPython, and functions to convert betweem PIL and FIPY, but I don't see a function to convert FIPY to wxPython? Image at: http://www.snakebomb.com/misc/example.tif Iain Yes it's min-is-white:: michele:~$ tiffinfo example.tif TIFFReadDirectory: Warning, example.tif: unknown field with tag 37680 (0x9330) encountered. TIFF Directory at offset 0x1520 (5408) Subfile Type: (0 = 0x0) Image Width: 1696 Image Length: 1162 Resolution: 200, 200 pixels/inch Bits/Sample: 1 Compression Scheme: CCITT Group 4 Photometric Interpretation: min-is-white# -- FillOrder: msb-to-lsb Samples/Pixel: 1 Rows/Strip: 1162 Planar Configuration: single image plane ImageDescription: DS michele:~$ So you *need* to invert it to work correctly with PIL! P.s. Added the convertToWx function, that return a wx.Image, to the Image class. Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes pointers and SendMessage
Metalone wrote: I would like to call windll.user32.SendMessageA(hwnd, win32con.WM_COMMAND, wParam, lParam) where lParam represents a pointer to an object. and the others? And also convert this pointer back to an object reference inside of wnd_proc def wnd_proc(hwnd, msg, wParam, lParam): So something like this: class X(Structure): def __init__(self, x): self.v = x What am I doing wrong? I don't know if you want to create a real C structure. If yes this is the wrong method: class X(Structure): ... _fields_ = [(x, c_int), ] ... x1 = X(1) x1.x 1 http://starship.python.net/crew/theller/ctypes/tutorial.html - Structures and Unions Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to get FreeImagePy to work.
Iain King wrote: Michele Petrazzo wrote: Iain King wrote: Michele Petrazzo wrote: I downloaded and installed 0.9.9.3, and it now works. Thanks! I advice you to don't use that ctypes version... Better is to use the newest one and update freeimagepy! Iain Michele OK, Ive installed the latest versions I can find, which are FreeImagePy 1.2.4 and ctypes 0.9.9.6, and I'm back to the error I had earlier. Do you know what's wrong? Iain Can you download the last svn version from sf.net? Otherwise I'll send you the last sources privately. Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to get FreeImagePy to work.
Iain King wrote: Can you download the last svn version from sf.net? Otherwise I'll send you the last sources privately. Bye, Michele I got the TortoiseSVN client though, and checked out your newest build, copied it over the top of site-packages/freeimagepy, updated my ctypes back to 0.9.9.6 (I'd regressed again), ran my program, and it worked. Thanks! This is a good news! Next question (and what I'm using FreeImagePy for): I'm loading a pile of TIF's as thumbnails into a wx list control. I load the image with FIPY, convert it to PIL, use PIL's antialiasing thumbnail function, then load it from there into wx. Why use PIL for it and not FIPY directly? You can use the image.size or the other methods for resize the image However, when I'm do the fipy.convertToPil(), it inverts the image? No, it not invert the image... It only return the image as is. I've inserted a fipy.invert() before the conversion as a temporary fix, but is there a reason for this? If you are have a min-is-white image (fax ?) that isn't the standard, you will have an inverted image, because PIl expect a min-is-black image! relevant code: def getHeaders(files): thumbs = [] for f in files: print Adding %s % f fi = FIPY.Image(f) fi.setCurrentPage(0) fi.invert() #temp fix thumb = fi.convertToPil() thumb.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS) thumbs.append((os.path.basename(f), pilToBitmap(thumb))) thumbs.sort() return thumbs Just a question, why thumbs.sort ? Inside this list you have only images! P.s. you can use also fi.currentPage = 0 rather then fi.setCurrentPage(0). Is think it look like better :) Iain p.s. thanks again :) Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to get FreeImagePy to work.
Iain King wrote: I've installed ctypes and FreeImagePy. When I do this: import FreeImagePy f = FreeImagePy.Image() I put a 'print self._name' in the ctypes __init__ file, just before line 296 - it's printing out the 'find' just before the error. So, in what specific way have I screwed up the install? What's your ctypes version? Is 0.9.9.6? If yes, can you download the last svn version, that solve that problem (I hope) and add some functions? If you can't I'll release a new version (1.2.5) Iain Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to get FreeImagePy to work.
Iain King wrote: Michele Petrazzo wrote: I downloaded and installed 0.9.9.3, and it now works. Thanks! I advice you to don't use that ctypes version... Better is to use the newest one and update freeimagepy! Iain Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Starting/launching eric3
Byte wrote: OK, now I've managed to get it working, but when I run it the eric3 splash screen pops up, and then it says (in terminal): [EMAIL PROTECTED]:~$ eric3 Traceback (most recent call last): File /usr/lib/site-python/eric3/eric3.py, line 147, in ? main() File /usr/lib/site-python/eric3/eric3.py, line 132, in main mw = UserInterface(loc, splash) File /usr/lib/site-python/eric3/UI/UserInterface.py, line 265, in __init__ self.sbv = SBVviewer(dbs, self.sbvDock, 1) File /usr/lib/site-python/eric3/UI/SBVviewer.py, line 75, in __init__ self.stackComboBox.sizePolicy().hasHeightForWidth())) TypeError: argument 1 of QSizePolicy() has an invalid type Segmentation fault [EMAIL PROTECTED]:~$ Its not ment to do that... how to make it work right?? Just happen on my costumer ubuntu (and an old eric3 release). I have solve it downloading the last (3.9.x if I remember correctly) from eric3 home and overwrite the site-packages/eric directory. Now all work great. -- /usr/bin/byte Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Python memory deallocate
Heiko Wundram wrote: As was said before: as long as you keep a reference to an object, the object's storage _will not be_ reused by Python for any other objects (which is sensible, or would you like your object to be overwritten by other objects before you're done with them?). Besides, even if Python did free the memory that was used, the operating system wouldn't pick it up (in the general case) anyway (because of fragmentation issues), so Python keeping the memory in an internal free-list for new objects is a sensible choice the Python developers took here. This isn't true. Just tried with python 2.5a2 and: d:\python25\python.exe a = range(1000 * 100 *100) # 173 MB del a # 122MB So now, like you saied, if I try to allocate another memory chunk, python'll re-use it... But this isn't true: b = range(100 * 100 * 100) # 126 MB del b # 122MB exit() # :) d:\python25\python.exe b = range(100 * 100 * 100) # 19 MB Do why python don't reuse the freed memory and re-allocate 4 MB (126 - 122)? For me it's a problem... --- Heiko. Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: python 2.5a2, gcc 4.1 and memory problems
[EMAIL PROTECTED] wrote: Michele Petrazzo wrote: I haven't tried to recompile py 2.4 myself with gcc 4.1 because it is already compiled with it (4.0.3), so I think (only think) that is a py 2.5 problem. I'm right? or I have to compile it with something other switches? Sounds like a gcc problem to me. Try adding --with-pydebug in the configure options. My guess is that it will work. This option enables asserts, but more importantly disables optimization. Yes, with this option it work, but has very bad performances. My guess is that this is an optimization problem with gcc. I assume -fno-strict-aliasing is one of the gcc flags. It should be as this is required for building python. Yes, I specify that flag for compiling, but still the same... Always problems. Also tried with --without-pymalloc and no changes. Cheers, n I think that I'll wait for the firsts debian packages, or compile it with gcc 3.3. Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
python 2.5a2, gcc 4.1 and memory problems
Hi list, I'm doing some tests on my debian testing and I see a very strange memory problem with py 2.5a2 (just downloaded) and compiled with gcc 4.1.0, but not with the gcc 3.3.5: My test are: #--test.py import sys if sys.version.startswith(2.3): from sets import Set as set b=set(range(500)) a=set(range(10)) c = b-a for i in 3 4 5; do echo python 2.$i time python2.$i test.py; done My configure args for compile py 2.5a2 are: michele:~/Python-2.5a2$ export CC=gcc-4.1 michele:~/Python-2.5a2$ export CXX=g++-4.1 michele:~/Python-2.5a2$ ./configure --prefix=/usr --enable-shared michele:~/Python-2.5a2$ make michele:~/Python-2.5a2$ make install michele:~/Python-2.5a2$ export CC=gcc-3.3 michele:~/Python-2.5a2$ export CXX=g++-3.3 michele:~/Python-2.5a2$ ./configure --prefix=/usr --enable-shared michele:~/Python-2.5a2$ make michele:~/Python-2.5a2$ make install Then I execute my test. The memory usage of 2.5a2 and gcc 3.3 that I see with top, is the same (about VIRT: 260 MB and RES: 250MB ) that with the py 2.3 and 2.4, but then I recompile with 4.1 and execute the same test, my system stop to work... with top I can see that it use VIRT: 2440 MB and RES: 640MB RAM (I think all that I have into my pc) I haven't tried to recompile py 2.4 myself with gcc 4.1 because it is already compiled with it (4.0.3), so I think (only think) that is a py 2.5 problem. I'm right? or I have to compile it with something other switches? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python?
Saurabh Sardeshpande wrote: Pardon if this is already discussed extensively. But what is the best IDE for Python for a newbie? I have experience in C++ and Java and this is the first time I am learning a scripting language. Thanks in advance Try all the you find! However on linux I find eric3(4) very useful. Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: OpenOffice UNO export PDF help needed
Sells, Fred wrote: I've geen googling for 3 days now, and cannot find out how to do this. I'm trying to use OpenOffice 2.0 and UNO to generate PDF documents. I'm using windows, but will have to make it work under Linux for production. I've been able to set the parameters and call the exportToPdf method, but the exported file is not PDF but an .odt document, Have you tried the ooextract.py found on: http://udk.openoffice.org/python/python-bridge.html Here work well and generate a pdf file. See also this for more info about generate pdf: http://mithrandr.moria.org/blog/447.html Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: pytiff for windows
Iain King wrote: -cut pytiff- (or alternatively tell me how to get PIL to save a multipage tiff). PIL can't. If you need to work with multi-page images (tiff and others), you can use freeimagepy (freeimagepy.sf.net) import FreeImagePy as FIPY lst_names = (/tmp/f1.png, /tmp/f2.jpg) F = FIPY.freeimage() F.convertToMultiPage(lst_names, out.tif, FIPY.FIF_TIFF) (0, 'All ok!! File saved on out.tif') Iain Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: pytiff for windows
Michele Petrazzo wrote: import FreeImagePy as FIPY lst_names = (/tmp/f1.png, /tmp/f2.jpg) F = FIPY.freeimage() F.convertToMultiPage(lst_names, out.tif, FIPY.FIF_TIFF) (0, 'All ok!! File saved on out.tif') Sorry for this bad copy/paste/thunderbird :) import FreeImagePy as FIPY lst_names = (/tmp/f1.png,/tmp/f2.jpg) F = FIPY.freeimage() F.convertToMultiPage(lst_names, out.tif, FIPY.FIF_TIFF) Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython warnings
Philippe Martin wrote: I had a similar but simple problem (the file was missing) and had to check by hand before calling wxPython. Can you check the tag by hand before calling wxPython ? Philippe Hi, also I have the same problem with g3/g4 images. My solution was convert that image *before* to .png before... Very bad hack, but work. I think that is an internal wxWidgets message (warning), passed to the wxPython subsystem. Have you tried to wrote to the wxpython ml? Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: GRIB to images
Sheldon wrote: Hi, I am interesseted on reading some GRIB files using python and then converting the fields to gif images. Does anyone know if this is possible or have a program that does this? Yes of course with PIL. http://www.pythonware.com/products/pil/ http://effbot.org/imagingbook/format-grib.htm /Sheldon Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Module for Determining CPU Freq. and Memory?
Tim Golden wrote: [efrat] |I'd like to determine at runtime the computer's CPU frequency and | memory. | | (Please note: I'm interested in hardware stuff, like how much | memory the | machine has; not how much free memory is available.) I don't know if there's a cross-platform solution for this. For Windows, you could use WMI. Something like this: -cut- For linux (and also for other *nix?) something like this os.system(cat /proc/cpuinfo | grep cpu) cpu family : 6 cpu MHz : 1922.308 or: open(/proc/cpuinfo).readlines() ['processor\t: 0\n', 'vendor_id\t: AuthenticAMD\n' Michele -- http://mail.python.org/mailman/listinfo/python-list
shelve and .bak .dat .dir files
Hi, I'm trying a script on a debian 3.1 that has problems on shelve library. The same script work well on a fedora 2 and I don't know why it create this problem on debian: #extract from my code import shelve class XX: def __init__(self): self._data = shelve.open(/tmp/myfile) # do the work def onClose(self): self._data.close() Now I see that shelve create not my file, but three files that has the name that I want (/tmp/myfile) and also the extensions: .bak .dat .dir Of course, before say to shelve to open, I delete the previous file, and I have all the rights to do what I want into the directory. How solve it? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: How to work with directories and files with spaces
[EMAIL PROTECTED] wrote: hi I am working in unix and i have some directories names with spaces eg ABC DEF A how can i work effectively with spaces in directory/file names in python? Like you can do with unix: michele:~$ echo Michele my\ name michele:~$ python Python 2.3.5 (#2, May 4 2005, 08:51:39) [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2 Type help, copyright, credits or license for more information. open(my name) open file 'my name', mode 'r' at 0x401e3ba0 import os os.system(cat my\ name) Michele 0 os.system(cat 'my name') Michele 0 Bye, Michele :) -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve and .bak .dat .dir files
Sion Arrowsmith wrote: This is a documented behaviour of shelve: Sorry, I had read only the: Open a persistent dictionary. The filename specified is the base filename ... :) I guess this depends on what dbm shelve is built on the documentation implies it goes through anydbm. I'm not seeing this behaviour on my Debian 3.1 In my tries, I see that if I use a simple script that open, use and save the shelve data, it work without problems, but if I use shelve into my application, I has this behaviour. (and I fail to understand why it is a problem). Because: 1) I pass a name that, after, I'll pass to another program and if shelve change the name, the latter can't read it (it doesn't exists!) 2) I can't read those files with shelve! If I try... : shelve.open(test.dat) Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.3/shelve.py, line 231, in open return DbfilenameShelf(filename, flag, protocol, writeback, binary) File /usr/lib/python2.3/shelve.py, line 212, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary) File /usr/lib/python2.3/anydbm.py, line 80, in open raise error, db type could not be determined anydbm.error: db type could not be determined And this with all the three types. Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
base64 memory question
Hi ng, I see that after en encoding with base64, the memory used for the variable that I use for store the encoded data, after deleted, python keep a part of that memory: #ls -lh on /tmp/test_zero #-rw-r--r-- 1 michele michele 9,8M 2006-03-31 18:32 /tmp/test_zero michele:~$ python2.4 Python 2.4.2 (#2, Nov 20 2005, 17:04:48) [GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2 Type help, copyright, credits or license for more information. import base64 # Now top say me: 6217 michele 15 0 4412 2536 3336 S 0.0 0.3 0:00.01 python2.4 b = base64.encodestring(open(/tmp/test_zero, rb).read()) #top: 6217 michele 15 0 39156 36m 3376 S 19.6 4.8 0:00.60 python2.4 del base64, b #top 6217 michele 15 0 25644 23m 3376 S 0.0 3.1 0:00.61 python2.4 So like I can read from the top, python forgot to free that part of memory. Is this normal? Is there a solution for free that memory? P.s. The same happen on my win2k machine with py 2.4.2 Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
String split
Hello ng, I don't understand why split (string split) doesn't work with the same method if I can't pass values or if I pass a whitespace value: .split() [] .split( ) [''] But into the doc I see: If sep is not specified or is None, any whitespace string is a separator. In this two cases, split would to return the _same_ result? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: String split
Peter Otten wrote: The documentation for Python 2.4 has a better explanation. -cut- Quoted after http://docs.python.org/lib/string-methods.html#l2h-202. Peter Thanks, I haven't see it. Just a question about that different algorithm, because it force the developer to do other work for make the split result more logically compatible: S = # this can become from an external source like config parser for s n S.split(): do the work... # don't go inside that isn't compatible, so python split it into two different methods the string, with: for s n S.split(','): do the work... # run one time into this Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception not raised - May be the end
Sion Arrowsmith wrote: Michele Petrazzo [EMAIL PROTECTED] wrote: some days ago I posted here and say that python forgot to raise an exception, but my code was too long for make some tries possible. But now I can reproduce the problem into another, little, project: www.unipex.it/vario/wxFrameSchedule.py www.unipex.it/vario/metamenus.py [ ... ] It looks like a wx sandwich issue to me Yes! Now I think the same Robin gave a full explanation to someone else having similar problems on wxPython-users a couple of days ago, but I'm having trouble finding that. Yes, I had read it, but I didn't think that was I similar problem! This is the message http://aspn.activestate.com/ASPN/Mail/Message/wxpython-users/3034524 I hope that, like Robin says, this will be changed into 2.7! Thanks a lot for the tip! Michele -- http://mail.python.org/mailman/listinfo/python-list
Exception not raised - May be the end
Hi group, some days ago I posted here and say that python forgot to raise an exception, but my code was too long for make some tries possible. But now I can reproduce the problem into another, little, project: (Need wx 2.6) Here is the code: www.unipex.it/vario/wxFrameSchedule.py www.unipex.it/vario/metamenus.py.py Execute the wxFrameSchedule.py into a terminal (or where you want) and select on menu bar: Show - Only work hour The program print and forgot to raise an exception: 12 #e number before the call that must, but don't raise the exception type 'dict' False # variable type and if the value are inside the keys # (str in dict) #Here the program don't raise the KeyError exception. Le lines are: - 44 in wxFrameSchedule (self._mb.GetMenuState(ShowOnlyworkhour)) - 802 in metamenus (this = self.MBStrings[_prefixMB + menu_string]) Hope that someone can reproduce this error. I see it on win2k (terminal usage) and debian (terminal and eric3 )... py 2.3.5 and wx 2.6 Thanks a lot, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple System Tray Icon
3c273 wrote: Hello, I have a short looping script that runs in the background (Windows 2000) and I want to have a tray icon so I know that it is running. I have looked at wxTaskBarIcon and the examples on the web and in the demo, but it seems pretty complex and I haven't had any success even getting one to show up. wxTaskBarIcon is very, very simple! Into the demo, inside 80 line, you can find all the taskbar work, the menu connected with the rclick and its image change... Where do you find this complex? Try to make the windows taskbar with the win32 api ... :) Can someone point me to a simple example that just shows an icon? I don't need it to anything but show up. Any help is appreciated. Copy and paste that lines into your code and remove the lines that you don't need. I think that with 15/20 lines you will your taskbar work! Louis Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception not raised
Diez B. Roggisch wrote: This code are inside a method into class that have no try/except. And called from a method inside a wx.Frame derivate. The other strange thing is that if I try the same code just before the caller to that method, it raise an exception: So maybe the C-layer of wx in-between doesn't propagate the exception for whatever reason? Can be, but only that exception aren't raised, all the other, in the same point of code, yes. Fact is: pythons exception-handling is core part of the language and an error in there _extremely_ improbable . I think the same, and this is one of the reason that push me to use python. So I suggest you cut down your example until it is self-contained with only a few dozen lines and still produces your observed behavior. Otherwise no one will be able to help you. Into my 100 line code, that exception (and all the others) are raised! I don't able, into all my tries, to reproduce that error on a small code... I can publish my code, if someone has one hour of spare time and a postgresql where test the code. I'm make some instruction to reproduce it. Diez Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Exception not raised
Hi list, I have a strange error on my software on win 2k/xp and debian 3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython: python, on a piece of code doesn't raise a KeyError on a dict (that don't have that key), but the strange thing is that the try/except code see that exception. Other strange thing is that other exceptions are raised! Simple example extract from my code: #code def test(): print type(t_fields), 11 in t_fields print t_fields[11] print I'm here print ok test() print ok #end code Output: ok type 'dict' False Here I see only one ok and not the I'm here. The interpreter stop to run here, but the application continue to work! Other try: #code def test(): try: print type(t_fields), 11 in t_fields print t_fields[11] except KeyError, ex: print Error, ex #end code Output: ok type 'dict' False Error 11 ok Here the output is ok, so python see that exception inside the try/except and print it. Last try: #code def test() print type(t_fields), 11 in t_fields print dont_exist print t_fields[11] #end code Output: ok type 'dict' False File conn.py, line 231, in test print dont_exist NameError: global name 'dont_exist' is not defined So all the exception are raised except the KeyError outside the try/except! I don't know what can be. Thanks to all that can help me. Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception not raised
Diez B. Roggisch wrote: Not here: t_fields = {} #code def test(): print type(t_fields), 11 in t_fields print t_fields[11] print I'm here print ok test() print ok #end code Gives me KeyError: 11 Also on my environ when I try this 4 line code. My project, where that strangeness happen has 500/600 + K of code. So - whatever you do, there must be some other code capturing that exception. This code are inside a method into class that have no try/except. And called from a method inside a wx.Frame derivate. The other strange thing is that if I try the same code just before the caller to that method, it raise an exception: #code extract alway from the big project: class errorHappen(object): def methodError(self, t_fields): print type(t_fields), 11 in t_fields print t_fields[11] print I'm here def myF(wx.Frame): init self._e = errorHappen() def caller(self): d = dict(dictionary with 50/100 keys) #if here I try d[11], I'll KeyError self._e.methodError(d) #here I don't see the exeception Maybe you don't use dict, but a subclass of it? All my dict are created as d = dict() and populate by: d.update(other_dict) or for k, val in iter: d[k] = val Diez Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception not raised
Michele Petrazzo wrote: Hi list, I have a strange error on my software on win 2k/xp and debian 3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython: Just for give evidence to my _failed_ tests, my a debugger (eric3), it see the exception, so it break with a KeyError! And the same code, no! Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception not raised
Michele Petrazzo wrote: Michele Petrazzo wrote: Hi list, I have a strange error on my software on win 2k/xp and debian 3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython: Opss, I forgot some words :) Just for give evidence to my _failed_ tests, my a debugger (eric3), it with a debugger (not my a debugger) see the exception, so it break with a KeyError! And the same code, no! And the same code, exceute inside a terminal, no... -- http://mail.python.org/mailman/listinfo/python-list
Re: PyUNO with different Python
Stefan Behnel wrote: M�ta-MCI schrieb: The second way don't run: Traceback (most recent call last): File C:\Program Files\OpenOffice.org 2.0\program\hello_world.py, line 1, in? import uno File C:\Program Files\OpenOffice.org 2.0\program\uno.py, line 37, in ? import pyuno ImportError: Module use of python23.dll conflicts with this version of Python. Sounds like you might want to switch back to Python 2.3 ... Yes and no. I have both 2.3 and 2.4 on my debian system and with both, the program at: http://udk.openoffice.org/python/samples/ooextract.py work well with a modify: before the first line import uno, add: import sys sys.path.append(/opt/openoffice.org2.0/program/) Now, save the program, move it where you want, and go: michele:~$ python2.3 tmp/ooextract.py --pdf test.odt michele:~$ python2.4 tmp/ooextract.py --pdf test.odt Both create the test.pdf file! P.s. Before execute the script, execute OOo: soffice -accept=socket,host=localhost,port=2002;urp; Stefan Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: PyUNO with different Python
Katja Suess wrote: Thanks. What I have in mind is to write a Python script to generate PDFs from a set of ODTs. Pay attention that you have a OOo program running somewhere that accept the connection from your zope server (I don't think that you have a X server running on it.) This script has to run in Zope which brings its own Python. My problem is the setup of PyUNO with this Python which is not the OO included one. Try with the little modify that I wrote and the other post and let us know. Hope to find a Mac user who made/solved similar experience... Regards, Katja Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: PyUNO with different Python
� wrote: Hi! maybe somebody can give me an hint to my problem setting up PyUNO on my Mac to work with my Python not the Python delivered with OpenOffice. As said in installation instructions I've set OPENOFFICE_PATH=/usr/lib/openoffice/program export PYTHONPATH=$OPENOFFICE_PATH export LD_LIBRARY_PATH=$OPENOFFICE_PATH according to my environment. importing uno gives me this error: import uno Traceback (most recent call last): File stdin, line 1, in ? File /Applications/OpenOffice.org 2.0.app/Contents/openoffice.org2.0/program/uno.py, line 37, in ? import pyuno ImportError: No module named pyuno which means python finds uno but not pyuno (pyuno.dylib). Do you want to use system python inside OOo (inside a macro, or...), or system python outside OOo? For the first, follow this: http://udk.openoffice.org/python/python-bridge.html#replacing for the second: http://udk.openoffice.org/python/python-bridge.html#modes Any hints? Regards, Katja Michele -- http://mail.python.org/mailman/listinfo/python-list
ANN: FreeImagePy 1.2.2
FreeImagePy 1.2.2 is available at freeimagepy.sf.net What is? It' a python wrapper for FreeImage, Open Source library for developers who would like to support popular graphics image formats. How work? It use a binary freeimage library present on the system and ctypes. Major changes from 1.2.0: New convertToPil function: i = FreeImagePy.Image(myImage.ext) pil = i.convetToPil() Some bugs solved Michele Petrazzo -- http://mail.python.org/mailman/listinfo/python-list
Re: Visual Report Editor
Pawel wrote: Hello, Hi Pawel, I plan to make Visual Reporting Editior, a new product for corporate-class systems. Data will be in XML and in my application, designer should be able to make fascinating templates of reports. I will use Python and MSVS 2005 Pro. What are MSVS 2005 Pro ? My question is, which libaries will be useful in my job. I plan to buy Qt and make visual layer of application using Qt. I'm making businessplan soI have to decide which tool will be useful. Is Qt best choice, maybe I should buy something different? Qt has a strange license for a graphical toolkit, it is release under GPL/commercial license, so if you want to include your new Reporting Editior into a commercial product, you have to pay a license for it. Different thing is if you use wx or gtk, that has other, more permissive licenses. I (my company), for our project, has create a Reporting Editior based on wx, following the pySketch tool, but now has about all the code rewrite. It has some little problems with the auto-resizeable objects (text only for now), that, into the engine that should compose the page, not are displayed correctly. On the other hand has a lot of worker functions, like: - model-view framework - object-like develop, so it's simple to add new drawing objects - xml read and save - multi-page size (A4, A3, etc...) - multi-block (head, title, text [more that one], food, end) - align-resize object - infinite undo-redo - image support - multi-layer (9 layers) - text block wrap, align right/left/center vertically/horrizontally - more other... Now I haven't the mind and the time for solve the problems, but if you want to complete it, or help me to do it, I'll send you the code, so after we'll a new -open source (do you like wxWidgets license? [LGPL] )- *Visual Reporting Editior* Pawel Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: FreeImagePy 1.2.2
Claudio Grondi wrote: Knowing some details about PIL and as good as no details about FreeImage, I would like in this context to become enlightened by the answer to the question, when does it make sense to use FreeImage instead of PIL? Into some little environments, like tiff with G3/G4 compressions and multi-page files. From what I know up to now I can't see any use for FreeImage :-( . Like I say to freeimagepy site, I start to wrote it *only* because I needed a simple python library for manipulate fax images (G3/G4) that PIL can't. I need it into my python fax client [hylapex] that it's connect to hylafax server. Of course, It wouldn't be a PIl replacement ;)! Claudio Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: using the Filters DLL (image filters)
Dieter Vanderelst wrote: Hello, I'm trying to access the Filters-Dll provided by the filters-project (http://filters.sourceforge.net/index.htm). Nice project :) Following the advice I got from the Python list -thank you for that-, I do this using ctypes (http://starship.python.net/crew/theller/ctypes/index.html). Good choose! I can seem to access the image filters now provided by the Dll. But reading and writing of images is still a problem. What are the problems? Please specify it. Furthermore, the project is not very well documented. So, I was wondering whether there are people on this list that have some experience in using the filters Dll. Maybe they could sent me some examples of the use of the Dll with Python? There are a lot of python projects that use ctypes for use libraries (.dll/.so). You can see them for study and copy that code (like all do :P ). Start at wnd.sf.net and freeimagepy.sf.net Kind regards, Dieter Bye, Michele -- http://mail.python.org/mailman/listinfo/python-list
ANN: FreeImagePy 1.2.0
FreeImagePy 1.2.0 is available at freeimagepy.sf.net What is? It' a python wrapper for FreeImage, Open Source library for developers who would like to support popular graphics image formats. How work? It use a binary freeimage library present on the system and ctypes. Major changes from 1.1.0: Start the port to a more pythonic interface. See Image class documentation (or the examples) A bug in *nix mode that cause a problem when getStatus are called Michele Petrazzo -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython import error
[EMAIL PROTECTED] ha scritto: I have tried several times to install wxPython on Fedora Core 2. The installation seems to go fine (from sources), but when I try to import the wx module I keep getting the following error: -cut- Any help or explanation would be greatly appreciated. For a my customer I had tried a lot of time, but without success to compile and install wx 2.6.x But luckily there is a precompiled package on wxpython.org. Have you try it? Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: sort problem
Kent Johnson wrote: or learn about decorate-sort-undecorate: lst = [ ...whatever ] lst = [ x[3], i, x for i, x in enumerate(lst) ] I think that here the code must be changed (for the future): lst = [ (x[3], i, x) for i, x in enumerate(lst) ] lst.sort() lst = [ x for _, _, x in lst ] Wow, this work with my py 2.3! Kent Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
sort problem
I have a list of lists (a grid table) that can have about 15000 - 2 rows and 10 cols, so: 1 [ [ 'aaa', 'vv', 'cc', 23, ... ], 2 [ 'aav', 'vv', 'cc', 45, ... ], ... 15000 [ 'sad', 'ad', 'es', 123, ... ], ] I need to sort this list, but I need to specify two things: the column and its type (string or int), so for example in this list, I want to sort the fourth column that has int values. The type because that I want that 1, 2, 12 will be sort in this order, not 1, 12, 2 like strings. I have already tried to modify some code found on aspn, but the results are always too slow for me, about 30-40 sec. Can someone has some code or some point where can I start for speedup my code? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: sort problem
Lasse Vågsæther Karlsen wrote: How about: list.sort(key=lambda x: x[3]) Does that work? Yes, on my linux-test-box it work, but I my developer pc I don't have the 2.4 yet. I think that this is a good reason for update :) Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: epydoc, variables and encoding
Kenneth Pronovici wrote: I found a problem on epydoc. If I specify an encoding, epydoc not find my global variables, and if I remove it, it work well. -cut- No, it's not normal, and I'm fairly sure it's a bug. -cut- Otherwise, you can try applying the following patch: -cut- Maybe Edward won't like this patch, but since he seems to be unreachable for the last six months sigh, you'll have to settle for my less-than-educated guess at a fix. :) I don't know why Edward won't like this parch :), in any case it work well for my source. KEN Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: python image library TIFF
bryan rasmussen wrote: Hi does anyone have any experience using the Python Image library to determine if a Tiff is in the G4 or G3 codec? PIL don't support G3/G4 encoding. You can use freeimagepy that is another python graphic package. Michele (freeimagepy developer :) ) -- http://mail.python.org/mailman/listinfo/python-list
epydoc, variables and encoding
I found a problem on epydoc. If I specify an encoding, epydoc not find my global variables, and if I remove it, it work well. code.py: #!/usr/bin/env python # -*- coding: utf-8 -*- MY_VAR = None class foo(object): def __init__(self, foo): Some text @param foo: Pass me what you want @type foo: A type @return: The object return foo This not work (MY_VAR is silently skipped), but if I remove: # -*- coding: utf-8 -*- it see MY_VAR and put it to my html file. Is it normal? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapper module for Linux shared lib
Ernesto wrote: What's the best resource for finding out how to write a wrapper module for a shared library file *.so* in Linux? If you have only the .so file, not the source, you can use ctypes. I work always with it without problems. Michele -- http://mail.python.org/mailman/listinfo/python-list
distutils problem
I create a setup script for distribute my application, but I have a problems with the exe package. When I create the package with: python setup.py win bdist_wininst and execute if after, it'll copy the data file specified by data_files directive into the C:\python23\python23\lib\site-package\my_lib, so not on the right site-package directory (python23 + python23). Otherwise if I use the same script from the source (python setup.py install) it work well, so it copy on C:\python23\lib\site-package\my_lib or /usr/lib/python23/site-package/ on linux. (this for python 2.3, of course :) ) My script: dataToCopy = glob.glob(FreeImagePy/data/*.*) if sys.platform == 'win32': prefix = os.path.join(sys.prefix, Lib/site-packages/FreeImagePy) else: prefix = os.path.join(sys.exec_prefix, lib/python%s % sys.version[:3], site-packages/FreeImagePy) setup( packages=['FreeImagePy', 'FreeImagePy.test', 'FreeImagePy.tools'], data_files=[ (prefix, dataToCopy),], ) How can I modify my script, for make it work with exe package? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list