[issue36207] robotsparser deny all with some rules
Nico added the comment: Had same problem today for my website (https://www.bonus4casino.fr/), following for a fix -- nosy: +nico.bonefato ___ Python tracker <https://bugs.python.org/issue36207> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43786] slice(None) is slice(None) is False
Nico Schlömer added the comment: Thanks very much, Steven, for the feedback and the suggestion. -- ___ Python tracker <https://bugs.python.org/issue43786> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43786] slice(None) is slice(None) is False
New submission from Nico Schlömer : I stumbled upon this when dealing with NumPy arrays: ``` slice(None) is slice(None) ``` ``` False ``` This came up when trying to check if a variable `a` equals `slice(None)`. The comparison ``` a = slice(None) a == slice(None) ``` ``` True ``` works, but doesn't return a single Boolean if a is a NumPy array, for example. Perhaps there's another way of finding out if a variable is exactly `slice(None)`, but the failure of `is` seems like a bug. -- messages: 390598 nosy: nschloe priority: normal severity: normal status: open title: slice(None) is slice(None) is False ___ Python tracker <https://bugs.python.org/issue43786> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41386] Popen.wait does not account for negative return codes
Nico added the comment: Yeah I see the point. To me it does make no sense because even in the windows API they seam to not know whether to use a ulong or a uint nor does this reflect the actual depiction within the program. However it is probably not worth implementing a flag for that nor to change the behavior entirely. This will create more problems than it would fix ambiguity. Thanks for taking the time and sorry for the inconvenience. -- stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue41386> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41386] Popen.wait does not account for negative return codes
Nico added the comment: We apparently need a flag to ensure compatibility with the windows return codes == FAIL: test_disable_windows_exc_handler (test.test_faulthandler.FaultHandlerTests) -- Traceback (most recent call last): File "D:\a\cpython\cpython\lib\test\test_faulthandler.py", line 825, in test_disable_windows_exc_handler self.assertEqual(exitcode, 0xC005) AssertionError: -1073741819 != 3221225477 -- ___ Python tracker <https://bugs.python.org/issue41386> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41386] Popen.wait does not account for negative return codes
Nico added the comment: I don't know if it should be a good idea to add a flag to turn off the negative conversation? -- ___ Python tracker <https://bugs.python.org/issue41386> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41386] Popen.wait does not account for negative return codes
Change by Nico : -- versions: -Python 3.8 ___ Python tracker <https://bugs.python.org/issue41386> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41386] Popen.wait does not account for negative return codes
Change by Nico : -- components: +Library (Lib) -Windows ___ Python tracker <https://bugs.python.org/issue41386> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41386] Popen.wait does not account for negative return codes
Nico added the comment: I suggest implementing a singed conversation into _wait -- keywords: +patch message_count: 1.0 -> 2.0 pull_requests: +20749 stage: -> patch review pull_request: https://github.com/python/cpython/pull/21607 ___ Python tracker <https://bugs.python.org/issue41386> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41386] Popen.wait does not account for negative return codes
New submission from Nico : Following problem occurred. A C style program can have negative return codes. However this is not correctly implemented in the Windows API. Therefore it is being returned as unsigned long by the API hence it leads to ambiguity while comparing return codes. For reference regarding this topic see: https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?redirectedfrom=MSDN=vs-2019 https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess I suggest a -- components: Windows messages: 374194 nosy: MrTroble, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: Popen.wait does not account for negative return codes type: behavior versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue41386> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31415] Add -X option to show import time
Nico Schlömer added the comment: I just updated tuna [1] to support import time profiles as well. Install with ``` pip install tuna ``` and use with ``` python -X importprofile yourfile.py 2> import.log tuna import.log ``` See screenshot for example output. Cheers, Nico [1] https://github.com/nschloe/tuna -- nosy: +nschloe Added file: https://bugs.python.org/file47663/sc.png ___ Python tracker <https://bugs.python.org/issue31415> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: cProfile, timed call tree
Thanks, Dieter, for the concise answer. Cheers, Nico On Sat, May 26, 2018 at 7:42 AM dieter <die...@handshake.de> wrote: > Nico Schlömer <nico.schloe...@gmail.com> writes: > > > From what I understand about the Python profilers, the type of > information > > you get from a stats object is > > > > * How much time was spent in function X, > > * what the callers and callees of function X are, and > > * and bunch of meta info about function X. > > > > With the program > > ``` > > def prime(n): > > # compute the n-th prime number, takes longer for larger n > > return 2 > > > > def a(): > > return prime(1) > > > > def b(): > > return prime(4000) > > > > a() > > b() > > ``` > > I would be able to find that `prime` took a lot of time, but not that it > > took more time when called from `b()`. In other words: I cannot construct > > the call tree with times from Stats. > > You will see that "prime" was called both from "a" and "b" - and > *in this particular case*, you will see that the execution times > of "b" and "prime" are almost identical and derive that the "prime" > call of b was the expensive one. > > But, in general, you are right: you cannot reconstruct complete > call trees. The reason is quite simple: maintaining information > for the complete caller ancestry (rather than just the immediate > caller) is expensive (both in terms of runtime and storage). > Profiling usually is used as a preparation for optimization. > Optimization has the greatest effects if applied to inner loops. > And for the analysis of inner loops, complete call tree information > is not necessary. > > > Is this correct? If not, how to get a timed call tree from Stats? Perhaps > > that's not the right think to work with? > > You will need to write your own profiler - one that keeps track > not only about the immediate caller of a function call but > of the whole caller ancestry (maybe recursion reduced). > > You can see an example of a custom profiler > in "Products.ZopeProfiler" (--> PyPI). > It does not take into account the whole caller ancestry. > Instead it records additional information concerning higher level > Zope (a Web application framework) calls. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
cProfile, timed call tree
Hi everyone, >From what I understand about the Python profilers, the type of information you get from a stats object is * How much time was spent in function X, * what the callers and callees of function X are, and * and bunch of meta info about function X. With the program ``` def prime(n): # compute the n-th prime number, takes longer for larger n return 2 def a(): return prime(1) def b(): return prime(4000) a() b() ``` I would be able to find that `prime` took a lot of time, but not that it took more time when called from `b()`. In other words: I cannot construct the call tree with times from Stats. Is this correct? If not, how to get a timed call tree from Stats? Perhaps that's not the right think to work with? Cheers, Nico -- https://mail.python.org/mailman/listinfo/python-list
[issue29282] Fused multiply-add: proposal to add math.fma()
Nico Schlömer <nico.schloe...@gmail.com> added the comment: Okay, thanks for the info. As a stop-gap measure, I've created pyfma [1, 2]. Install with ``` pip install pyfma ``` and use with ``` pyfma.fma(3.0, 2.0, 1.0) ``` Only works on Unix reliable then, but that's all I care about. :) Cheers, Nico [1] https://github.com/nschloe/pyfma [2] https://pypi.python.org/pypi/pyfma -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue29282> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29282] Fused multiply-add: proposal to add math.fma()
Nico Schlömer <nico.schloe...@gmail.com> added the comment: > Existing libm implementations don't work, Okay. Is this because of the inf/NaN discrimination hiccups mentioned above or are there any other pitfalls? -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue29282> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29282] Fused multiply-add: proposal to add math.fma()
Nico Schlömer <nico.schloe...@gmail.com> added the comment: Do I read this thread correctly assuming that this hasn't been implemented yet? If not, I would probably make my own little library for this -- I really need the feature for the precision. -- nosy: +nschloe ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue29282> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: GUI user input to function
Am Donnerstag, 28. Dezember 2017 14:00:14 UTC+1 schrieb Chris Angelico: > On Thu, Dec 28, 2017 at 11:06 PM, Nico Vogeli <nicco.9...@gmail.com> wrote: > > Am Donnerstag, 28. Dezember 2017 12:59:24 UTC+1 schrieb Chris Angelico: > >> On Thu, Dec 28, 2017 at 8:38 PM, Nico Vogeli <nicco.9...@gmail.com> wrote: > >> > Withs test, this return a correct value for the two x functions: > >> > > >> > from sympy import symbols > >> > > >> > x = symbols('x') > >> > f1 = eval(input('function 1 ')) > >> > f2 = eval(input('function 2 ')) > >> > > >> > >> What are you typing as input? It's hard to grok your code without knowing > >> that. > >> > >> ChrisA > > > > I'm sorry! User input would look like this for example: x**2 + 3*x or x**3 > > > > Cool. That's an expression, but it isn't a function. To make that into > a function, you need to prefix it with the lambda keyword. > > So you should be able to construct functions like this: > > f1 = eval("lambda x: " + input("function 1: ")) > > Then, when you type "x**3", Python evaluates "lambda x: x**3", which > is a function. > > ChrisA Thank you very much! It now works perfectly fine now!! Thank you! Nicco -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI user input to function
Am Donnerstag, 28. Dezember 2017 12:59:24 UTC+1 schrieb Chris Angelico: > On Thu, Dec 28, 2017 at 8:38 PM, Nico Vogeli <nicco.9...@gmail.com> wrote: > > Withs test, this return a correct value for the two x functions: > > > > from sympy import symbols > > > > x = symbols('x') > > f1 = eval(input('function 1 ')) > > f2 = eval(input('function 2 ')) > > > > What are you typing as input? It's hard to grok your code without knowing > that. > > ChrisA I'm sorry! User input would look like this for example: x**2 + 3*x or x**3 Regards Nicco -- https://mail.python.org/mailman/listinfo/python-list
GUI user input to function
Hello again I think my question got lost in all the others raised, so here I am again :P So, I tried my best, was looking into the eval and exec function, but still no succsess.. Maybe it helps when I provide the code I want to implement: def newton_verfahren(self): if self.cB_1.currentText() == 'Newton': x0 = self.newton_x.text() f1 = self.func_1.text() f2 = self.func_2.text() tol = self.newton_tol.text() n = self.newton_n.text() k = Numerik_Funktionen.newton(int(x0), eval(f1), eval(f2), int(tol), int(n)) k1 = str(k[0]) k2 = str(k[1]) k3 = str(k[2]) self.ausgabe.setText('Startwert -> x0: '+ k1 + "\n" + 'Anzahl Iterationen: ' + k2 +"\n" + 'f(x~): ' + k3) Notice that cB_1 is a combobox, newton_x, func_1, func_2, newton_tol and newton_n are all QLineEdits. The code above doesn't work, so I've opend a 'test' file to just play around with the functions. Withs test, this return a correct value for the two x functions: from sympy import symbols x = symbols('x') f1 = eval(input('function 1 ')) f2 = eval(input('function 2 ')) But now I get and error from the imported module in the line where the abs(f(x)) > tol. It states that the 'Pow' object is not callable. And now I don't know how to proceed, I can't figure out a way to make the call to the imported module: x = symbols('x') def newton(x0, f, fx, tol, n = 2): ''' Näherung zur lösung einer Gleichung mit dem Newton-Verfahren x0 = Startwert f = zu lösende Funktion fx = Ableitung der Funktion ''' x = x0 k = 0 while n > k and abs(f(x)) > tol: k += 1 x = x - f(x)/fx(x) print('x', k, '\n', x) print('Startwert -> x0', '\n', x0) print('Anzahl Iterationen', '\n', k) print('f(x~)', '\n', f(x)) print('Näherungswert -> x~', '\n', x) return x0, k, f(x), x Regards Nicco -- https://mail.python.org/mailman/listinfo/python-list
Re: user input string to function
Am Montag, 25. Dezember 2017 16:56:19 UTC+1 schrieb Chris Angelico: > On Tue, Dec 26, 2017 at 2:04 AM, Nico Vogeli <nicco.9...@gmail.com> wrote: > > Am Montag, 25. Dezember 2017 15:58:26 UTC+1 schrieb Chris Angelico: > >> On Tue, Dec 26, 2017 at 1:48 AM, Nico Vogeli <nicco.9...@gmail.com> wrote: > >> > Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: > >> >> On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli <nicco.9...@gmail.com> > >> >> wrote: > >> >> > Hi everybody. First ad foremost, happy Christmas! > >> >> > >> >> Same to you! > >> >> > >> >> > I want to let the use input a function (like x**2) and parse it after > >> >> > that through code (for my numeric class) > >> >> > > >> >> > def newton(x0, s, s2, tol, n = 2): > >> >> > ''' > >> >> > Näherung zur lösung einer Gleichung mit dem Newton-Verfahren > >> >> > x0 = Startwert > >> >> > f = zu lösende Funktion > >> >> > fx = Ableitung der Funktion > >> >> > > >> >> > ''' > >> >> > def f(a): > >> >> > y = s > >> >> > return y > >> >> > > >> >> > def fx(a): > >> >> > y = s2 > >> >> > return y > >> >> > >> >> > >> >> > newton(2, 3*x**2, 6*x, 0.1, 2) > >> >> > > >> >> > I notice that the x is not converted to an integer, because of the x > >> >> > = symplos('x') > >> >> > But I don't know how I could possibli change the code to work... > >> >> > >> >> The easiest way is to pass a *function* to newton(). It'd look like > >> >> this: > >> >> > >> >> def newton(x0, f, fx, tol, n=2): > >> >> ... as before, but without the nested functions > >> >> > >> >> newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) > >> >> > >> >> At least, I think that's how you're doing things. Inside the nested > >> >> functions, you use 'a', but outside, you use 'x'. Are those > >> >> representing the same concept? If so, the lambda functions given here > >> >> will have the same effect. > >> >> > >> >> Hope that helps! > >> >> > >> >> ChrisA > >> > > >> > Hi Chris > >> > > >> > Thanks very much for your quick response! > >> > I was in a bit of a rush, so I confused the variables (don't worry, I > >> > just messed arround to try different things, the original code was al > >> > tidy with the variable). > >> > > >> > I tried your input, but now I get another error: > >> > > >> > > >> > File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, > >> > in newton > >> > b = x - f(x)/fx(x) > >> > > >> > TypeError: unsupported operand type(s) for /: 'function' and 'function' > >> > > >> > This did not occure befor I tried to implement the user input.. > >> > >> Did you remove the nested functions? The lambda functions completely > >> replace your "def f(a)" and "def fx(a)" functions. > >> > >> ChrisA > > > > I am so so sorry!! I just did not know what you meant by sested functions.. > > :P > > No need to apologize! That's why we have two-directional communication > - I can ask you to clarify, you can ask me to clarify, and we get to a > solution. > > The concept of passing functions around does take some getting used > to, so there's no shame in not instantly understanding it. > > > Thank you so much for helping me! You're great! > > > > Cheers and all the best! > > My pleasure! Have yourself an awesome holiday season. > > ChrisA Hello again So, I tried my best, was looking into the eval and exec function, but still no succsess.. Maybe it helps when I provide the code I want to implement: def newton_verfahren(self): if self.cB_1.currentText() == 'Newton': x0 = self.newton_x.text() f1 = self.func_1.text() f2 = self.func_2.text() tol = self.newton_tol.text() n = self.newton_n.text() k
Re: user input string to function
Am Montag, 25. Dezember 2017 15:58:26 UTC+1 schrieb Chris Angelico: > On Tue, Dec 26, 2017 at 1:48 AM, Nico Vogeli <nicco.9...@gmail.com> wrote: > > Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: > >> On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli <nicco.9...@gmail.com> wrote: > >> > Hi everybody. First ad foremost, happy Christmas! > >> > >> Same to you! > >> > >> > I want to let the use input a function (like x**2) and parse it after > >> > that through code (for my numeric class) > >> > > >> > def newton(x0, s, s2, tol, n = 2): > >> > ''' > >> > Näherung zur lösung einer Gleichung mit dem Newton-Verfahren > >> > x0 = Startwert > >> > f = zu lösende Funktion > >> > fx = Ableitung der Funktion > >> > > >> > ''' > >> > def f(a): > >> > y = s > >> > return y > >> > > >> > def fx(a): > >> > y = s2 > >> > return y > >> > >> > >> > newton(2, 3*x**2, 6*x, 0.1, 2) > >> > > >> > I notice that the x is not converted to an integer, because of the x = > >> > symplos('x') > >> > But I don't know how I could possibli change the code to work... > >> > >> The easiest way is to pass a *function* to newton(). It'd look like this: > >> > >> def newton(x0, f, fx, tol, n=2): > >> ... as before, but without the nested functions > >> > >> newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) > >> > >> At least, I think that's how you're doing things. Inside the nested > >> functions, you use 'a', but outside, you use 'x'. Are those > >> representing the same concept? If so, the lambda functions given here > >> will have the same effect. > >> > >> Hope that helps! > >> > >> ChrisA > > > > Hi Chris > > > > Thanks very much for your quick response! > > I was in a bit of a rush, so I confused the variables (don't worry, I just > > messed arround to try different things, the original code was al tidy with > > the variable). > > > > I tried your input, but now I get another error: > > > > > > File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, in > > newton > > b = x - f(x)/fx(x) > > > > TypeError: unsupported operand type(s) for /: 'function' and 'function' > > > > This did not occure befor I tried to implement the user input.. > > Did you remove the nested functions? The lambda functions completely > replace your "def f(a)" and "def fx(a)" functions. > > ChrisA I am so so sorry!! I just did not know what you meant by sested functions.. :P Thank you so much for helping me! You're great! Cheers and all the best! Nicco -- https://mail.python.org/mailman/listinfo/python-list
Re: user input string to function
Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: > On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli <nicco.9...@gmail.com> wrote: > > Hi everybody. First ad foremost, happy Christmas! > > Same to you! > > > I want to let the use input a function (like x**2) and parse it after that > > through code (for my numeric class) > > > > def newton(x0, s, s2, tol, n = 2): > > ''' > > Näherung zur lösung einer Gleichung mit dem Newton-Verfahren > > x0 = Startwert > > f = zu lösende Funktion > > fx = Ableitung der Funktion > > > > ''' > > def f(a): > > y = s > > return y > > > > def fx(a): > > y = s2 > > return y > > > > newton(2, 3*x**2, 6*x, 0.1, 2) > > > > I notice that the x is not converted to an integer, because of the x = > > symplos('x') > > But I don't know how I could possibli change the code to work... > > The easiest way is to pass a *function* to newton(). It'd look like this: > > def newton(x0, f, fx, tol, n=2): > ... as before, but without the nested functions > > newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) > > At least, I think that's how you're doing things. Inside the nested > functions, you use 'a', but outside, you use 'x'. Are those > representing the same concept? If so, the lambda functions given here > will have the same effect. > > Hope that helps! > > ChrisA Hi Chris Thanks very much for your quick response! I was in a bit of a rush, so I confused the variables (don't worry, I just messed arround to try different things, the original code was al tidy with the variable). I tried your input, but now I get another error: File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, in newton b = x - f(x)/fx(x) TypeError: unsupported operand type(s) for /: 'function' and 'function' This did not occure befor I tried to implement the user input.. Thank you very much! Nicco -- https://mail.python.org/mailman/listinfo/python-list
user input string to function
Hi everybody. First ad foremost, happy Christmas! I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) import numpy as np import matplotlib.pyplot as plt import scipy.linalg from sympy.abc import o, h import sympy from sympy import symbols from scitools.StringFunction import StringFunction from sympy.plotting import plot x = symbols('x') def newton(x0, s, s2, tol, n = 2): ''' Näherung zur lösung einer Gleichung mit dem Newton-Verfahren x0 = Startwert f = zu lösende Funktion fx = Ableitung der Funktion ''' def f(a): y = s return y def fx(a): y = s2 return y a = x0 k = 0 while n > k: k += 1 b = a - f(a)/fx(a) print('x', k, '\n',b) print('Startwert -> x0', '\n', x0) print('Anzahl Iterationen', '\n', k) print('f(x~)', '\n', f(x)) print('Näherungswert -> x~', '\n', b) return x0, k, f(x), x (Please ignore all the input, they are used latter) Now the output looks like this: newton(2, 3*x**2, 6*x, 0.1, 2) x 1 -x/2 + 2 x 2 -x/2 + 2 Startwert -> x0 2 Anzahl Iterationen 2 f(x~) 3*x**2 Näherungswert -> x~ -x/2 + 2 Out[166]: (2, 2, 3*x**2, x) I notice that the x is not converted to an integer, because of the x = symplos('x') But I don't know how I could possibli change the code to work... Regards Nicco -- https://mail.python.org/mailman/listinfo/python-list
[issue29522] PyLong_AsDouble Behaviour is Weird
New submission from nico: I'm using the pre-installed version of Python 2.7.12 on Ubuntu 16.04. Pretty straight forward error the following code: PyObject * intobj = PyInt_FromLong(10); double d1 = (double)PyLong_AsLong(intobj); double d2 = PyLong_AsDouble(intobj); printf("Should be the same: %f vs %f", d1, d2); Does not display the same number for both double since `PyLong_AsDouble` raises the error, SystemError: ../Objects/longobject.c:2336: bad argument to internal function and returns -1.0 instead of 10.0. -- components: Build messages: 287486 nosy: nico priority: normal severity: normal status: open title: PyLong_AsDouble Behaviour is Weird versions: Python 2.7 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29522> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9720] zipfile writes incorrect local file header for large files in zip64
Nico Möller added the comment: I most definitely need a patch for 2.7.3 Would be awesome if you could provide a patch for that version. -- nosy: +Nico.Möller ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9720 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: PIL: The _imaging C module is not installed
I had this happening to me as well someday. I recall that first installing it (python setup.py install), and then rerunning selftest, solved that error. I tried that as well. Here is the summary of the install process: build/temp.linux-x86_64-2.4/libImaging/ZipEncode.o -L/usr/local/lib -L/usr/lib -ljpeg -lz -o build/lib.linux-x86_64-2.4/_imaging.so /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc building '_imagingft' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c _imagingft.c -o build/temp.linux-x86_64-2.4/_imagingft.o gcc -pthread -shared build/temp.linux-x86_64-2.4/_imagingft.o -L/usr/local/lib -L/usr/lib -lfreetype -o build/lib.linux-x86_64-2.4/_imagingft.so /usr/bin/ld: skipping incompatible /usr/lib/libfreetype.so when searching for -lfreetype /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc building '_imagingmath' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c _imagingmath.c -o build/temp.linux-x86_64-2.4/_imagingmath.o gcc -pthread -shared build/temp.linux-x86_64-2.4/_imagingmath.o -L/usr/local/lib -L/usr/lib -o build/lib.linux-x86_64-2.4/_imagingmath.so /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc PIL 1.1.7 SETUP SUMMARY version 1.1.7 platform linux2 2.4.6 (#1, Mar 16 2011, 11:33:33) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the setup.py script. To check the build, run the selftest.py script. running build_scripts creating build/scripts-2.4 copying Scripts/pilfont.py - build/scripts-2.4 copying and adjusting Scripts/pilconvert.py - build/scripts-2.4 copying and adjusting Scripts/pilfile.py - build/scripts-2.4 copying and adjusting Scripts/pilprint.py - build/scripts-2.4 copying and adjusting Scripts/pildriver.py - build/scripts-2.4 changing mode of build/scripts-2.4/pilfont.py from 644 to 755 changing mode of build/scripts-2.4/pilconvert.py from 644 to 755 changing mode of build/scripts-2.4/pilfile.py from 644 to 755 changing mode of build/scripts-2.4/pilprint.py from 644 to 755 changing mode of build/scripts-2.4/pildriver.py from 644 to 755 running install_lib copying build/lib.linux-x86_64-2.4/_imagingft.so - /usr/local/lib/python2.4/site-packages/PIL copying build/lib.linux-x86_64-2.4/_imagingmath.so - /usr/local/lib/python2.4/site-packages/PIL copying build/lib.linux-x86_64-2.4/_imaging.so - /usr/local/lib/python2.4/site-packages/PIL running install_scripts copying build/scripts-2.4/pilconvert.py - /usr/local/bin copying build/scripts-2.4/pilfile.py - /usr/local/bin copying build/scripts-2.4/pilprint.py - /usr/local/bin copying build/scripts-2.4/pildriver.py - /usr/local/bin changing mode of /usr/local/bin/pilfont.py to 755 changing mode of /usr/local/bin/pilconvert.py to 755 changing mode of /usr/local/bin/pilfile.py to 755 changing mode of /usr/local/bin/pilprint.py to 755 changing mode of /usr/local/bin/pildriver.py to 755 creating /usr/local/lib/python2.4/site-packages/PIL.pth $ python selftest.py *** The _imaging C module is not installed Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 92, Issue 40
PIL will compile and install if you don't have some development libraries and then simply not work or not work up to full steam when used. To avoid this, you need to install the appropriate libraries, among which are: libjpeg-devel freetype-devel libpng-devel Dear Albert Thank you for your reply. I did install all these libraries. Testing it with yum shows: $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version $ yum install libjpeg-devel Package libjpeg-devel-6b-37.x86_64 already installed and latest version Package libjpeg-devel-6b-37.i386 already installed and latest version $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version Re-Compiling PIL shows: $ python setup.py build_ext -i *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available However, running the selftest still fails: $ python selftest.py *** The _imaging C module is not installed Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL: The _imaging C module is not installed
PIL will compile and install if you don't have some development libraries and then simply not work or not work up to full steam when used. To avoid this, you need to install the appropriate libraries, among which are: libjpeg-devel freetype-devel libpng-devel Dear Albert Thank you for your reply. I did install all these libraries. Testing it with yum shows: $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version $ yum install libjpeg-devel Package libjpeg-devel-6b-37.x86_64 already installed and latest version Package libjpeg-devel-6b-37.i386 already installed and latest version $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version Re-Compiling PIL shows: $ python setup.py build_ext -i *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available However, running the selftest still fails: $ python selftest.py *** The _imaging C module is not installed Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
PIL: The _imaging C module is not installed
Hi there I am having trouble to install PIL 1.1.7 on CentOS. I read and followed the instructions from http://effbot.org/zone/pil-imaging-not-installed.htm However, I still get the The _imaging C module is not installed error if I run the selftest: $ python selftest.py *** The _imaging C module is not installed Here is what I have tested so far: 1.) $ python -v ... import Image ... dlopen(/usr/local/lib/python2.4/site-packages/PIL/_imaging.so, 2); import _imaging # dynamically loaded from /usr/local/lib/python2.4/site-packages/PIL/_imaging.so ... 2.) $ python ... import _imaging ...success imported! Any idea what might be wrong? Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Build unordered list in HTML from a python list
Dear list members I have this python list that represets a sitemap: tree = [{'indent': 1, 'title':'Item 1', 'hassubfolder':False}, {'indent': 1, 'title':'Item 2', 'hassubfolder':False}, {'indent': 1, 'title':'Folder 1', 'hassubfolder':True}, {'indent': 2, 'title':'Sub Item 1.1', 'hassubfolder':False}, {'indent': 2, 'title':'Sub Item 1.2', 'hassubfolder':False}, {'indent': 1, 'title':'Item 3', 'hassubfolder':False}, {'indent': 1, 'title':'Folder 2', 'hassubfolder':True}, {'indent': 2, 'title':'Sub Item 2.1', 'hassubfolder':False}, {'indent': 2, 'title':'Folder 2.1', 'hassubfolder':True}, {'indent': 3, 'title':'Sub Item 2.1.1', 'hassubfolder':False}, {'indent': 3, 'title':'Sub Item 2.1.2', 'hassubfolder':False}, ] From that list I want to create the following HTML code: ul id=tree liItem 1/li liItem 2/li liFolder 1 ul liSub Item 1.1/li liSub Item 1.2/li /ul /li liItem 3/li liFolder 2 ul liSub Item 2.1/li liFolder 2.1 ul liSub Item 2.1.1/li liSub Item 2.1.2/li /ul /li /ul /li /ul If an item of the list has 'True' for the 'hassubfolder' key than a new ulli must be created instead of /li after its title. (See Folder 2 node in the HTML code above. My problem is: How do I keep track of the closing tags while iterating over the python list? Any help is much appreciated. Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Build unordered list in HTML from a python list
Use a stack? Whenever you start a new list, push the corresponding closing tag onto a stack. Whenever your indent level decreases, pop the stack and write out the closing tag you get. It's straightforward to use a python list as a stack. Thanks for the tip, Kushal. Do you have a short code example for me? Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
itertools: problem with nested groupby, list()
Hi, I ran into a bit of an unexpected issue here with itertools, and I need to say that I discovered itertools only recently, so maybe my way of approaching the problem is not what I want to do. Anyway, the problem is the following: I have a list of dictionaries, something like [ { a: 1, b: 1, c: 3 }, { a: 1, b: 1, c: 4 }, ... ] and I'd like to iterate through all items with, e.g., a:1. What I do is sort and then groupby, my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) and then just very simply iterate over my_list_grouped, for my_item in my_list_grouped: # do something with my_item[0], my_item[1] Now, inside this loop I'd like to again iterate over all items with the same 'b'-value -- no problem, just do the above inside the loop: for my_item in my_list_grouped: # group by keyword b my_list2 = list( my_item[1] ) my_list2.sort( key=operator.itemgetter('b') ) my_list_grouped = itertools.groupby( my_list2, operator.itemgetter('b') ) for e in my_list_grouped: # do something with e[0], e[1] That seems to work all right. Now, the problem occurs when this all is wrapped into an outer loop, such as for k in [ 'first pass', 'second pass' ]: for my_item in my_list_grouped: # bla, the above To be able to iterate more than once through my_list_grouped, I have to convert it into a list first, so outside all loops, I go like my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) my_list_grouped = list( my_list_grouped ) This, however, makes it impossible to do the inner sort and groupby-operation; you just get the very first element, and that's it. An example file is attached. Hints, anyone? Cheers, Nico #! /usr/bin/env python # -*- coding: utf-8 -*- import operator, itertools my_list = [ { a: 1, b: 1, c: 3 }, { a: 1, b: 1, c: 4 }, { a: 1, b: 11, c: 3 }, { a: 1, b: 11, c: 4 }, { a: 2, b: 1, c: 3 }, { a: 2, b: 1, c: 4 }, { a: 2, b: 11, c: 3 }, { a: 2, b: 11, c: 4 } ] # group my_list by a my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) my_list_grouped = list( my_list_grouped ) for k in [ 'first pass', 'second pass' ]: print k for my_item in my_list_grouped: print \t + str( my_item[0] ) # group by keyword b; need to get list first to be able to use 'sort' my_list2 = list( my_item[1] ) my_list2.sort( key=operator.itemgetter('b') ) my_list_grouped = itertools.groupby( my_list2, operator.itemgetter('b') ) for e in my_list_grouped: print \t\t + str( e[0] ) lll = list( e[1] ) for ee in lll: print \t\t\t + str( ee )-- http://mail.python.org/mailman/listinfo/python-list
Re: itertools: problem with nested groupby, list()
Does this example help at all? Thanks, that clarified things a lot! To make it easier, let's just look at 'a' and 'b': my_list.sort( key=itemgetter('a','b','c') ) for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a for b, b_iter in groupby(a_iter, itemgetter('b')): print '\t', 'New B', b for b_data in b_iter: print '\t'*3, a, b, b_data print '\t', 'End B', b print 'End A', a That works well, and I can wrap the outer loop in another loop without problems. What's *not* working, though, is having more than one pass on the inner loop, as in === *snip* === my_list.sort( key=itemgetter('a','b','c') ) for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a for pass in ['first pass', 'second pass']: for b, b_iter in groupby(a_iter, itemgetter('b')): print '\t', 'New B', b for b_data in b_iter: print '\t'*3, a, b, b_data print '\t', 'End B', b print 'End A', a === *snap* === I tried working around this by === *snip* === my_list.sort( key=itemgetter('a','b','c') ) for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a inner_list = list( groupby(a_iter, itemgetter('b')) ) for pass in ['first pass', 'second pass']: for b, b_iter in inner_list: print '\t', 'New B', b for b_data in b_iter: print '\t'*3, a, b, b_data print '\t', 'End B', b print 'End A', a === *snap* === which don't work either, and I don't understand why. -- I'll look at Uli's comments. Cheers, Nico On Tue, May 4, 2010 at 1:08 PM, Jon Clements jon...@googlemail.com wrote: On 4 May, 11:10, Nico Schlömer nico.schloe...@gmail.com wrote: Hi, I ran into a bit of an unexpected issue here with itertools, and I need to say that I discovered itertools only recently, so maybe my way of approaching the problem is not what I want to do. Anyway, the problem is the following: I have a list of dictionaries, something like [ { a: 1, b: 1, c: 3 }, { a: 1, b: 1, c: 4 }, ... ] and I'd like to iterate through all items with, e.g., a:1. What I do is sort and then groupby, my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) and then just very simply iterate over my_list_grouped, for my_item in my_list_grouped: # do something with my_item[0], my_item[1] Now, inside this loop I'd like to again iterate over all items with the same 'b'-value -- no problem, just do the above inside the loop: for my_item in my_list_grouped: # group by keyword b my_list2 = list( my_item[1] ) my_list2.sort( key=operator.itemgetter('b') ) my_list_grouped = itertools.groupby( my_list2, operator.itemgetter('b') ) for e in my_list_grouped: # do something with e[0], e[1] That seems to work all right. Now, the problem occurs when this all is wrapped into an outer loop, such as for k in [ 'first pass', 'second pass' ]: for my_item in my_list_grouped: # bla, the above To be able to iterate more than once through my_list_grouped, I have to convert it into a list first, so outside all loops, I go like my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) my_list_grouped = list( my_list_grouped ) This, however, makes it impossible to do the inner sort and groupby-operation; you just get the very first element, and that's it. An example file is attached. Hints, anyone? Cheers, Nico Does this example help at all? my_list.sort( key=itemgetter('a','b','c') ) for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a for b, b_iter in groupby(a_iter, itemgetter('b')): print '\t', 'New B', b for c, c_iter in groupby(b_iter, itemgetter('c')): print '\t'*2, 'New C', c for c_data in c_iter: print '\t'*3, a, b, c, c_data print '\t'*2, 'End C', c print '\t', 'End B', b print 'End A', a Jon. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: itertools: problem with nested groupby, list()
I'd try to avoid copying the list and instead just iterate over it: def iterate_by_key(l, key): for d in l: try: yield l[key] except: continue Hm, that won't work for me b/c I don't know all the keys beforehand. I could certainly do a unique(list.keys()) or something like that beforehand, but I guess this does away with the speed advantage. Since your operation not only iterates over a list but first sorts it, it requires a modification which must not happen while iterating. You work around this by copying the list first. So when I go like for item in list: item[1].sort() I actually modify *list*? I didn't realize that; I thought it'd just be a copy of it. Anyway, I could just try for item in list: newitem = sorted( item[1] ) in that case. which is a no-no. Create a custom iterator function (IIRC they are called generators) and you should be fine. I'll look into this, thanks for the hint. Cheers, Nico On Tue, May 4, 2010 at 12:46 PM, Ulrich Eckhardt eckha...@satorlaser.com wrote: Nico Schlömer wrote: I ran into a bit of an unexpected issue here with itertools, and I need to say that I discovered itertools only recently, so maybe my way of approaching the problem is not what I want to do. Anyway, the problem is the following: I have a list of dictionaries, something like [ { a: 1, b: 1, c: 3 }, { a: 1, b: 1, c: 4 }, ... ] and I'd like to iterate through all items with, e.g., a:1. What I do is sort and then groupby, my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) and then just very simply iterate over my_list_grouped, for my_item in my_list_grouped: # do something with my_item[0], my_item[1] I'd try to avoid copying the list and instead just iterate over it: def iterate_by_key(l, key): for d in l: try: yield l[key] except: continue Note that you could also ask the dictionary first if it has the key, but I'm told this way is even faster since it only requires a single lookup attempt. Now, inside this loop I'd like to again iterate over all items with the same 'b'-value -- no problem, just do the above inside the loop: for my_item in my_list_grouped: # group by keyword b my_list2 = list( my_item[1] ) my_list2.sort( key=operator.itemgetter('b') ) my_list_grouped = itertools.groupby( my_list2, operator.itemgetter('b') ) for e in my_list_grouped: # do something with e[0], e[1] That seems to work all right. Since your operation not only iterates over a list but first sorts it, it requires a modification which must not happen while iterating. You work around this by copying the list first. Now, the problem occurs when this all is wrapped into an outer loop, such as for k in [ 'first pass', 'second pass' ]: for my_item in my_list_grouped: # bla, the above To be able to iterate more than once through my_list_grouped, I have to convert it into a list first, so outside all loops, I go like my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) my_list_grouped = list( my_list_grouped ) This, however, makes it impossible to do the inner sort and groupby-operation; you just get the very first element, and that's it. I believe that you are doing a modifying operation inside the the iteration, which is a no-no. Create a custom iterator function (IIRC they are called generators) and you should be fine. Note that this should also perform better since copying and sorting are not exactly for free, though you may not notice that with small numbers of objects. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: itertools: problem with nested groupby, list()
Are you basically after this, then? for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a for b, b_iter in groupby(a_iter, itemgetter('b')): b_list = list(b_iter) for p in ['first', 'second']: for b_data in b_list: #whatever... Yes. Moving the 'first', 'second' operation to the innermost loop works all right, and I guess that's what I'll do. Cos that looks like it could be simplified to (untested) for (a, b), data_iter in groupby(my_list, itemgetter('a','b')): data = list(data) # take copy for pass_ in ['first', 'second']: # do something with data Potentially yes, but for now I actually need to do something at print 'New A', a, so I can't just skip this. Anyway, the above suggestion works well for now. Thanks! --Nico On Tue, May 4, 2010 at 1:52 PM, Jon Clements jon...@googlemail.com wrote: On 4 May, 12:36, Nico Schlömer nico.schloe...@gmail.com wrote: Does this example help at all? Thanks, that clarified things a lot! To make it easier, let's just look at 'a' and 'b': my_list.sort( key=itemgetter('a','b','c') ) for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a for b, b_iter in groupby(a_iter, itemgetter('b')): print '\t', 'New B', b for b_data in b_iter: print '\t'*3, a, b, b_data print '\t', 'End B', b print 'End A', a That works well, and I can wrap the outer loop in another loop without problems. What's *not* working, though, is having more than one pass on the inner loop, as in === *snip* === my_list.sort( key=itemgetter('a','b','c') ) for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a for pass in ['first pass', 'second pass']: for b, b_iter in groupby(a_iter, itemgetter('b')): print '\t', 'New B', b for b_data in b_iter: print '\t'*3, a, b, b_data print '\t', 'End B', b print 'End A', a === *snap* === I tried working around this by === *snip* === my_list.sort( key=itemgetter('a','b','c') ) for a, a_iter in groupby(my_list, itemgetter('a')): print 'New A', a inner_list = list( groupby(a_iter, itemgetter('b')) ) for pass in ['first pass', 'second pass']: for b, b_iter in inner_list: print '\t', 'New B', b for b_data in b_iter: print '\t'*3, a, b, b_data print '\t', 'End B', b print 'End A', a === *snap* === which don't work either, and I don't understand why. -- I'll look at Uli's comments. Cheers, Nico On Tue, May 4, 2010 at 1:08 PM, Jon Clements jon...@googlemail.com wrote: On 4 May, 11:10, Nico Schlömer nico.schloe...@gmail.com wrote: Hi, I ran into a bit of an unexpected issue here with itertools, and I need to say that I discovered itertools only recently, so maybe my way of approaching the problem is not what I want to do. Anyway, the problem is the following: I have a list of dictionaries, something like [ { a: 1, b: 1, c: 3 }, { a: 1, b: 1, c: 4 }, ... ] and I'd like to iterate through all items with, e.g., a:1. What I do is sort and then groupby, my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) and then just very simply iterate over my_list_grouped, for my_item in my_list_grouped: # do something with my_item[0], my_item[1] Now, inside this loop I'd like to again iterate over all items with the same 'b'-value -- no problem, just do the above inside the loop: for my_item in my_list_grouped: # group by keyword b my_list2 = list( my_item[1] ) my_list2.sort( key=operator.itemgetter('b') ) my_list_grouped = itertools.groupby( my_list2, operator.itemgetter('b') ) for e in my_list_grouped: # do something with e[0], e[1] That seems to work all right. Now, the problem occurs when this all is wrapped into an outer loop, such as for k in [ 'first pass', 'second pass' ]: for my_item in my_list_grouped: # bla, the above To be able to iterate more than once through my_list_grouped, I have to convert it into a list first, so outside all loops, I go like my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) my_list_grouped = list( my_list_grouped ) This, however, makes it impossible to do the inner sort and groupby-operation; you just get the very first element, and that's it. An example file is attached. Hints, anyone? Cheers, Nico Does this example help at all? my_list.sort( key=itemgetter('a','b','c
[issue8609] itertools: problem with nested groupby, list()
New submission from Nico nico.schloe...@gmail.com: Hi, I ran into a bit of an unexpected issue here with itertools. I need to say that I discovered itertools only recently, and that maybe my way of approaching the problem is not what I want to do. If you think this may be the case, please let me know. Anyway, the problem is the following: I have a list of dictionaries, something like [ { a: 1, b: 1, c: 3 }, { a: 1, b: 1, c: 4 }, ... ] and I'd like to iterate through all items with, e.g., a:1. What I do is sort and then groupby, my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) and then just very simply iterate over my_list_grouped, for my_item in my_list_grouped: # do something with my_item[0], my_item[1] Now, inside this loop I'd like to again iterate over all items with the same 'b'-value -- no problem, just do the above inside the loop: for my_item in my_list_grouped: # group by keyword b my_list2 = list( my_item[1] ) my_list2.sort( key=operator.itemgetter('b') ) my_list_grouped = itertools.groupby( my_list2, operator.itemgetter('b') ) for e in my_list_grouped: # do something with e[0], e[1] That seems to work all right. Now, the problem occurs when this all is wrapped into an outer loop, such as for k in [ 'first pass', 'second pass' ]: for my_item in my_list_grouped: # bla, the above To be able to iterate more than once through my_list_grouped, I have to convert it into a list first, so outside all loops, I go like my_list.sort( key=operator.itemgetter('a') ) my_list_grouped = itertools.groupby( my_list, operator.itemgetter('a') ) my_list_grouped = list( my_list_grouped ) This, however, makes it impossible to do the inner sort and groupby-operation; you just get the very first element, and that's it. An example file is attached. Is there anything that I can do to debug? Cheers, Nico -- components: None files: iterator-test.py messages: 104917 nosy: nicki priority: normal severity: normal status: open title: itertools: problem with nested groupby, list() versions: Python 2.6 Added file: http://bugs.python.org/file17198/iterator-test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8609] itertools: problem with nested groupby, list()
Nico nico.schloe...@gmail.com added the comment: Okay, thanks for the hint. Closing as invalid. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Sort list of dictionaries by key (case insensitive)
Hi there I have the following list 'mylist' that contains some dictionaries: mylist = [{'title':'the Fog', 'id':1}, {'title':'The Storm', 'id':2}, {'title':'the bible', 'id':3}, {'title':'The thunder', 'id':4} ] How I can sort (case insensitive) the list by the dictioary's 'title' key? The result should be this list: [{'title':'the bible', 'id':3}, {'title':'the Fog', 'id':1}, {'title':'The Storm', 'id':2}, {'title':'The thunder', 'id':4} ] I am using Python 2.4. Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort list of dictionaries by key (case insensitive)
Er, that should have been mylist.sort(key = lambda d: d['title'].lower()) of course. Thanks a lot for the tip, chris. Unfortunately, I only have Python 2.3.5 installed and can't upgrade to 2.4 due to an underliying application server. In python 2.3 the 'sort()' function does not excepts any keywords arguments (TypeError: sort() takes no keyword arguments), so is there a workaround? Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort list of dictionaries by key (case insensitive)
Thanks a lot Stefan Peter. I'm almost there (except sorting of umlauts does not work yet). import locale def sorted(items, key): decorated = [(key(item), index, item) for index, item in enumerate(items)] decorated.sort() return [item[2] for item in decorated] items = [{'title':'the Ähnlich', 'id':1}, {'title':'The Storm', 'id':2}, {'title':'the bible','id':3}, {'title':'The thunder', 'id':4}] print sorted(items, key=lambda d: locale.strxfrm(d.get('title'))) - [{'id': 2, 'title': 'The Storm'}, {'id': 4, 'title': 'The thunder'}, {'id': 3, 'title': 'the bible'}, {'id': 1, 'title': 'the \xc4hnlich'}] The entry with the umlaut is the last item in but according to german umlaut rules it should be the first item in the result. Do I have to set anything with the locale module? Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort list of dictionaries by key (case insensitive)
http://wiki.python.org/moin/HowTo/Sorting#Topicstobecovered Works fine. Thanks a lot for your help, Stefan. Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: ftplib timeout in Python 2.4
Try the timelimited function from this recipe http://code.activestate.com/recipes/576780/ Works perfect! Thanks a lot, Jean! -- http://mail.python.org/mailman/listinfo/python-list
ftplib timeout in Python 2.4
Hi there, The ftplib has a timeout parameter in Python 2.6 and above. Is there a way to set a timeout in Python 2.4? Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: ftplib timeout in Python 2.4
I don't know of one so you may need a workaround. What platforms do you need to support? Suse Linux Enterprise 10, 64 Bit with Python 2.4.4. I need the Python 2.4.4 for a running application Server (Zope). -- http://mail.python.org/mailman/listinfo/python-list
Re: List of paths
Here's a tricky case that doesn't show up in your example: In each case above, the directory names are distinct. how about: ['/desk', '/desk/ethanallen', '/desk/ikea', '/desktop', /desktop/pc', '/desktop/mac'] Should the answer be ['/desk'] or ['/desk', '/desktop'] ? Hi Scott good point. It should be: ['/desk', '/desktop'] -- http://mail.python.org/mailman/listinfo/python-list
List of paths
Dear Python developers I have the following (sorted) list. ['/notebook', '/notebook/mac', '/notebook/mac/macbook', '/notebook/mac/macbookpro', '/notebook/pc', '/notebook/pc/lenovo', '/notebook/pc/hp', '/notebook/pc/sony', '/desktop', '/desktop/pc/dell', '/desktop/mac/imac', '/server/hp/proliant', '/server/hp/proliant/385', '/server/hp/proliant/585' ] I want to remove all paths x from the list if there is a path y in the list which is part of x so y.startswith(x) is true. The list I want to have is: ['/notebook', '/desktop', '/server/hp/proliant'] Any idea how I can do this in Python? Thanks in advance Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: List of paths
May be not so much pythonic, but works for i in range(len(q)): for x in q[i:]: if x.startswith(q[i]) and x!=q[i]: q.remove(x) ...but works fine. Thanks, Eugene. Also thanks to Andrew. Your example works fine, too. Thanks to remind me of the 'yield' statement! ;-) Regards Nico -- http://mail.python.org/mailman/listinfo/python-list
Rebuild list of objects with redundancies on objects' attribute
Hi there I have a list of dummy objects which have the attributes 'location', 'name', 'gender'. Now I want to rebuild this list in order to avoid redundancies on objects with the same 'location'. Example: #-- class Dummy: pass a = Dummy() a.location = 'tokio' a.name = 'john' a.gender = 'm' b = Dummy() b.location = 'tokio' b.name = 'peter' b.gender = 'm' c = Dummy() c.location = 'madrid' c.name = 'susan' c.gender = 'f' d = Dummy() d.location = 'london' d.name = 'alex' d.gender = 'm' persons = [a, b, c, d] print loc name gender print - for obj in persons: print %s - %s - %s % (obj.location, obj.name, obj.gender) #-- The output reads like this: loc name gender - tokio john m tokio peter m madrid susan f london alex m I want to create this list (where name and gender are lists): loc name gender - tokio[john, peter] [m] madrid [susan] [f] london [alex][m] How can I do this? Thanks in advance. Nico -- http://mail.python.org/mailman/listinfo/python-list
Unicode string formating
Hi, I need to do a lot of string formating, and I have strings and/or unicode strings and when I do the following: %s %s % (u'Salut', 'H\xe4llo'), I get an exception : UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal not in range(128) How can I insure I don't get an exception? Thanks, Nicolas -- http://mail.python.org/mailman/listinfo/python-list
Find Replace hyperlinks in a string
Hi there, I have a string containing some hyperlinks. I'd like to replace every hyperlink with a HTML style link. Example: Replace 'http://www.foo.com/any_url' with 'a href=http://www.foo.com/any_url;http://www.foo.com/any_url/a' What's the best way to do this if I have a few hundret strings to check? Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
How can I have one element list or tuple?
The following example returns a string type, but I need a tuple... var = (Hello) print type(var) type 'str' I need that for a method parameter. Thx -- http://mail.python.org/mailman/listinfo/python-list
Problems with threading in embedded Python
Hi all, I hope this hasn't been brought up before, but if it did i missed it, so bear with me please :) anyway, i'm trying to embed Python into a C program. A sample python syript i want to run is as follows: ---SNIP--- import time import threading go_on = 1 t = 0 def ProcessMessage(): print ... ProcessMessage def Main(): global go_on print ... Main while go_on: ProcessMessage () print ... ... , time.sleep (0.2) def Setup(): global t print ... Setup t = threading.Thread (None, Main) t.start () # t.join (0) # print t.isAlive() def Shutdown(): global go_on, t go_on = 0 t.join () print ... Shutdown ---SNIP--- I call Setup from C, which should create a new thread which should enter the loop in Main. well, it doesn't :) It prints ... Setup and does nothing. when i call Shutdown from C, it prints ... Main , followed by ... Shutdown, and exits... So it seems to me the python interpreter wants to run the seperate thread, but doesn't get time from the scheduler (is that the thing about 100 opcodes?) How can i handle this problem? Do I need to wrap all the Py_Stuff() into its own thread? do i need artificial python code that only serves the purpose of piling up enough opcodes so that the Main() thread gets eventually called? I hope you can help me, if you need more code (f.ex. the C-code ), i will post more :) (basically I modified the run_func.cc file from the docs, added PyEval_InitThreads() and monkeyed around with GIL and Acquire/ReleaseLock, but so far i had no luck :) Cheers, Nico -- http://mail.python.org/mailman/listinfo/python-list
How to use unix_md5_crypt from Perl in Python?
Dear list members, I have a Perl script which crypts a password using a clearteaxt password and a username. Example: username = '[EMAIL PROTECTED]' password = 'root' The crypted password is: 'roK20XGbWEsSM' The crypted password always starts with the first 2 characters of the username (here: 'ro' from '[EMAIL PROTECTED]'). The Perl script contains this code and I am wondering how I can do this in Python: # my $CryptedPw = ''; # md5 pw if ($Self-{ConfigObject}-Get('AuthModule::DB::CryptType') $Self-{ConfigObject}-Get('AuthModule::DB::CryptType') eq 'md5') { $CryptedPw = unix_md5_crypt($Pw, $Param{UserLogin}); } # crypt pw else { # crypt given pw (unfortunately there is a mod_perl2 bug # on RH8 - check if # crypt() is working correctly) :-/ if (crypt('root', '[EMAIL PROTECTED]') eq 'roK20XGbWEsSM') { $CryptedPw = crypt($Pw, $Param{UserLogin}); } else { $Self-{LogObject}-Log( Priority = 'notice', Message = The crypt() of your mod_perl(2) is not working correctly! Update mod_perl!, ); my $TempUser = quotemeta($Param{UserLogin}); my $TempPw = quotemeta($Pw); my $CMD = perl -e \print crypt('$TempPw', '$TempUser');\; open (IO, $CMD | ) || print STDERR Can't open $CMD: $!; while (IO) { $CryptedPw .= $_; } close (IO); chomp $CryptedPw; } } # What do I have to do in Python to create the crypted password 'roK20XGbWEsSM' by using '[EMAIL PROTECTED]' for username and 'root' for password? I tried: username = '[EMAIL PROTECTED]' password = 'root' import crypt crypt.crypt(username, password) 'roowueH.vq6VM' This creates 'roowueH.vq6VM' but not 'roK20XGbWEsSM'. :-( Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Python's email module - problem with umlauts in some email clients
Hi there, I wrote a short python script that sends an email using python's email module and I am using Python 2.3.5. The problem is, that umlauts are not displayed properly in some email clients: + On a windows machine running thunderbird 1.0.2 umlauts are displayed properly. The email header contains Content-type: text/plain; charset=utf-8 so the email client's character encoding automatically switches to Unicode (UTF-8) + On a solaris machine running thunderbird 1.5.0.8 and on a macintosh machine running eudora umlauts are *not* displayed properly. The email header does not contain any Content-type. If I manually switch the email client's character encoding to Unicode (UTF-8), the umlauts are displayed properly. Therefore, I guess it has something to do with the missing Content-type: text/plain; charset=utf-8 information in the email header. Any idea why the Content-type: text/plain; charset=utf-8 is missing? Here is my script: #-- # send email from email.Header import Header import email.Message import email.Utils import mimetypes from smtplib import SMTP host = 'mail.example.com' mFrom = '[EMAIL PROTECTED]' mTo = '[EMAIL PROTECTED]' mSubj = u'f\xfcr' mBody = u'f\xfcr foo bar' mBody = mBody.encode('UTF-8') mainMsg = email.Message.Message() mainMsg['From'] = mFrom mainMsg['To'] = mTo mainMsg['Subject'] = mSubj mainMsg.set_payload(mBody) mainMsg['Date'] = email.Utils.formatdate(localtime=1) mainMsg['Message-ID'] = email.Utils.make_msgid() mainMsg['Mime-version'] = '1.0' mainMsg['Content-type'] = 'text/plain; charset=utf-8' mainMsg['Content-transfer-encoding'] = '8bit' # 'quoted-printable' does not work either # mainMsg['Content-Transfer-Encoding'] = 'quoted-printable' s = SMTP(host) s.sendmail(mFrom, [mTo], mainMsg.as_string()) s.close() #-- Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
ldapsearch example in python-ldap?
Hi there, on a linux machine I am running this ldapsearch from the command line: ldapsearch -x -h myldaphost.mydomain.com \ -D CN=ldapuser,CN=Users,DC=mydomain,DC=com -w secret \ -b CN=ANYCOMPUTER,CN=Computers,DC=mydomain,DC=com How can I do this with python-ldap? Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
PIL on Python 2.4 - ImportError: No module named _imagingft
Dear list members, I have installed Python 2.4.3. and PIL 1.1.5. on a Suse Linux 10 64 Bit machine. If I try import _imagingft I get this error: ImportError: No module named _imagingft Did I miss something? On my 32 But Linux with Python 2.3.5. everything works fine. Kind regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL on Python 2.4 - ImportError: No module named _imagingft [Solved]
If I try import _imagingft I get this error: ImportError: No module named _imagingft Did I miss something? Yes, I did. Somehow, there was no _imagingft.so in the PIL directory. -- http://mail.python.org/mailman/listinfo/python-list
Convert binary image to JPEG with 72 dpi
Dear list members,I have the binary content of an image file and it's filename.I neither know the resolution nor the dpi of the image.No I need to convert this binary content into a 72 dpi jpeg image. Furthermore I have to resize the image so neither the width nor the height is bigger than 250 pixels. I'd like to use PIL for this job. Any tips how to do it?Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python on a 64-Bit OS
Several changes have been made to Python 2.4 and 2.5 to support AMD64-Linux better, and not all of these changes have been incorporated into Python 2.3, as this software is no longer maintained. As others have said: you should really try to use the python 2.4 that comes with the operating system. Can you share the reason why you have to use Python 2.3? I actually should use the Python 2.3.5 for an application server called Zope and a Zope product that officially does not support the latest Zope version yet. The latest stable Zope version requires Python 2.4.2 so I'll installed Python 2.4.3. and I am trying to get it running. Thanks for the tips. Nico -- http://mail.python.org/mailman/listinfo/python-list
Installing Python on a 64-Bit OS
Hi there, I'd like to install Python 2.3.5. on a 64-Bit OS (Suse Linux Enterprise Server 10) on an AMD Opteron 64-Bit machine. I have to use Python 2.3.5. Do I need a special source archive or can I use Python-2.3.5.tgz from http://www.python.org/ftp/python/2.3.5/Python-2.3.5.tgz ? Is there anything special I have to care about or is installing Python on a 64 Bit OS just as easy as installing it on a 32-Bit OS? Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching a string and extract all occurancies of a substring
is this XML, or just something that looks a little like XML ? Unfortunately, something that looks a little XML so I can't use a XML parser. But the HTML parser does the job. -- http://mail.python.org/mailman/listinfo/python-list
Searching a string and extract all occurancies of a substring
Hi there, in a text with no carriage returns I need to look for all occurancies of this string: source id=boxparameter key=path.../parameter/source The ... can contain different values. I need to extract the string between source id=boxparameter key=path and /parameter/source. Example text: This is a test. link url=/www/folder target=_self title= A test. source id=boxparameter key=path/www/mydoc1/parameter/source And I need to extraxt /www/mydoc1 and /www/mydoc2 from this text. source id=boxparameter key=path/foo/bar/doc/parameter/source From this text I need to get a list with this: [/www/mydoc1, /foo/bar/doc] What's the best way to do this? I'll need to use Python: 2.3.5 Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching a string and extract all occurancies of a substring
Try Beautiful Soup, or if your input is simple enough, the re module. Hi Gabriel, I first tried HTMLParser and wrote this short script: from HTMLParser import HTMLParser from htmlentitydefs import entitydefs class MyDocParser(HTMLParser): def __init__(self): self.paths = [] self.readingpaths = 0 # flag HTMLParser.__init__(self) def handle_starttag(self, tag, attrs): if tag == 'parameter': self.readingpaths = 1 def handle_endtag(self, tag): if tag == 'parameter': self.readingpaths = 0 def handle_data(self, data): if self.readingpaths: self.paths.append(data) def handle_entityref(self, name): handle values like 'Home amp; Products' if entitydefs.has_key(name): self.handle_data(entitydefs[name]) else: self.handle_data('' + name + ';') def handle_charref(self, name): handle values like 'Home amp; Products#174;' Ignores invalid character references try: charnum = int(name) except ValueError: return if charnum 1 or charnum 255: return def get_paths(self): return self.paths def parse_content(content): parse parser = MyDocParser() parser.feed(content) paths = parser.get_paths() return paths # /end This works as long as there are no other paramter Tags in the content that I parse. Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching a string and extract all occurancies of a substring
This works as long as there are no other paramter Tags in the content that I parse. Got it. I forgot to handle the 'attrs' parameter in handle_starttag(). Changed it to: def handle_starttag(self, tag, attrs): if tag == 'parameter': if attrs == [('key', 'infobox_path')]: self.readingpaths = 1 This works so far. -- http://mail.python.org/mailman/listinfo/python-list
How to change the path for python binary?
Hi there, I have installed Python 2.3.5 on Suse Linux 10. If I enter python in the shell, the Python 2.3.5 interpreter is called. After I installed Python 2.4.3. the Python 2.4.3 interpreter is called which is the default behaviour I guess. which python brings me /usr/local/bin/python which calls the Python 2.4.3 interpreter. My question now is: What do I have to do in order to get the Python 2.3.5 interpreter each time I enter python in the shell? Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Search substring in a string and get index of all occurances
Hi there, I would like to search for a substring in a string and get the index of all occurances. mystring = 'John has a really nice powerbook.' substr = ' ' # space I would like to get this list: [4, 8, 10, 17, 22] How can I do that without using for i in mystring which might be expensive for large strings? Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: os.popen3() - how to close cmd window automatically?
replace console=[... by windows=[... in your setup.py Works perfect. Thank you, Rony! -- http://mail.python.org/mailman/listinfo/python-list
os.popen3() - how to close cmd window automatically?
Dear Python developers, I use a short python script in order to run an external application plus to open a browser displaying a default page. My Setup: Python 2.4.3. / Windows2000 # -- # Script shortcut.py import os import webbrowser import win32api # open default web browser and display webbpage page = 'C:\\Temp\\Welcome.html' webbrowser.open(page) # path to application that is opened path = C:\\Program Files\\ExternalApplication.exe # get short name shortpath = win32api.GetShortPathName(path) # open external application stdin, stdout, stderr = os.popen3(shortpath) output = stdout.read() errors = stderr.read() stdin.close() stdout.close() stderr.close() print output print errors # -- In order to make this Script available on other Windows2000 machines where no Python installation is present, I made this script executable using py2exe (http://www.py2exe.org/). This creates a shortcut.exe file. If I run shortcut.exe everything works fine but a black empty cmd window opens and its kept open until I close the application ExternalApplication.exe. How can I close that black empty window automatically? Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open https Site and pass request?
That depends on your OS. In Windows, I believe you would have to recompile Python from source. On Linux, you could probably just get a package. From Debian, I know that it's python-ssl. I'm sure most the others would have one as well. Hi Jerry, thank you for your reply. I use Linux and installed the package python-openssl which allows me to import the module OpenSSL (import OpenSSL) but I think installing this package has nothing to do with the SSL support of my python installation. Is that true? Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find out a date/time difference
I use datetime class in my program and now I have two fields that have the datetime format like this datetime.datetime(2006, 5, 24, 16, 1, 26) How can I find out the date/time difference ( in days) of such two fields? Hi Lad, you could do this: a = datetime.datetime(2006, 5, 24, 16, 1, 26) b = datetime.datetime(2006, 5, 20, 12, 1, 26) a-b datetime.timedelta(4) # 4 days b = datetime.datetime(2006, 5, 20, 12, 1, 26) x = a-b x datetime.timedelta(4, 14400) str(x) '4 days, 4:00:00' Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
How to open https Site and pass request?
Hi there, I am trying to open an https site and pass a request to it in order to simulate the submit of an HTML form on a https site that sets an authentication cookie for a tomcat application, so the the URL I am trying to open points to a web form provided by the tomcat webserver. I tried (Python 2.3.5): import urllib import urllib2 the_url = https://myserver/application/login.do; user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = { 'User-Agent' : user_agent } values = { 'username' : 'myuser', 'password' : 'mypasswd' } data = urllib.urlencode(values) req = urllib2.Request(the_url, data) handle = urllib2.urlopen(req) This raises the following exception: Traceback (most recent call last): File stdin, line 1, in ? File /usr/local/lib/python2.3/urllib2.py, line 129, in urlopen return _opener.open(url, data) File /usr/local/lib/python2.3/urllib2.py, line 331, in open 'unknown_open', req) File /usr/local/lib/python2.3/urllib2.py, line 306, in _call_chain result = func(*args) File /usr/local/lib/python2.3/urllib2.py, line 914, in unknown_open raise URLError('unknown url type: %s' % type) urllib2.URLError: urlopen error unknown url type: https Any idea, what I did wrong? Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open https Site and pass request?
import urllib import urllib2 the_url = https://myserver/application/login.do; user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = { 'User-Agent' : user_agent } values = { 'username' : 'myuser', 'password' : 'mypasswd' } data = urllib.urlencode(values) req = urllib2.Request(the_url, data) handle = urllib2.urlopen(req) urllib2.URLError: urlopen error unknown url type: https To answer my question myself: My python installation does not have SSL support (from socket import ssl failed). I tested the same code on another machine and it's working. However, I am wondering how I can additionally enable SSL support for my python installation ? Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Zope Guru...
In doing some research into Workflow apps regarding document management, I came across Zope. Given that it's Python Based, I figured I'd shout to the group here... If you want to develop an application with Zope+Python from scratch, there are a few Zope products out there that handle workflow (DCWorkflow, Openflow). If you look for an existing Zope based DMS, you might want to look at the Document Library application which has been released yesterday by infrae. http://www.infrae.com/download/documentlibrary Another existing Zope based application for document management including workflow is Plone. http://www.plone.org If you plan to start using Zope 3, you might want to take a look at http://www.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/Zope3Workflow Regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Sorting a list of dictionaries by dictionary key
Hi there, I am looking for a way to sort a list containing dictionaries. This is my example list: [{'Title': 'ABC', 'from_datetime': DateTime('2006/04/25 12:45:00 GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18 12:45:00 GMT+2')}, {'Title': 'GHI', 'from_datetime': DateTime('2006/03/10 12:45:00 GMT+2')}] I want to sort the list by dictionary's key 'from_datetime' so the sorted list should be: [{'Title': 'GHI', 'from_datetime': DateTime('2006/03/10 12:45:00 GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18 12:45:00 GMT+2')}, {'Title': 'ABC', 'from_datetime': DateTime('2006/04/25 12:45:00 GMT+2')}] Any idea how I can sort this list? Thank you very much in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting a list of dictionaries by dictionary key
assuming that DateTime returns something that compares correctly, you can do something like: def sortkey(item): return item.get(from_datetime) data.sort(key=sortkey) (assuming Python 2.4 or later) Thank you very much, Frederik. Unfortunately, I can only use Python 2.3.5. -- http://mail.python.org/mailman/listinfo/python-list
Problem with spawning an external process
I want to execute a command (in this case, and it seems to be significant, a Java program) in a thread in Python. When I execute the java binary in the main python thread, everything runs correctly. But when I try and execute java in a thread, java segfaults. I am using Python 2.3.3 and trying to run the java binary from the 1.4.2 SDK from Sun. I have tried executing some arbitrary C program that I wrote, and it works fine in the main thread and the started thread. The problem seems to be specific to the Java binary. Here is the example code: --- START CODE --- import os import popen2 import time import select import threading # Change these to suit your system PATH = '/home/nico/j2sdk1.4.2/bin/java' #PATH = '/home/nico/j2sdk1.4.2/bin/java -invalid_arg' def get_ret(status): signal = status 0xff if signal == 0: retcode = status 8 else: retcode = 0 return signal,retcode print In main thread # Using spawn pid = os.spawnl(os.P_NOWAIT,PATH,PATH) ret = os.waitpid(pid,0) print PID: %i signal: %i return code: %i % (ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1]) class TestThread(threading.Thread): def run(self): # Using spawn pid = os.spawnl(os.P_NOWAIT,PATH,PATH) ret = os.waitpid(pid,0) print PID: %i signal: %i return code: %i % (ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1]) print In Thread TestThread().start() print Waiting... time.sleep(2) print ...Finished END CODE Here is the output that I get on my machine: [nico@ script]$ python testcrash2.py In main thread JAVA USAGE INFO STRIPPED PID: 32107 signal: 0 return code: 1 In Thread PID: 32116 signal: 11 return code: 0 You will notice that in the main thread, the program executes correctly (return code 1, signal 0). When the command is executed in the thread, it segfaults (signal 11). The second PATH= line calls Java with an invalid argument. In this case, it does not crash in the thread. I have tried a fork() and then os.execv in the thread as well, and get the same behaviour. I would appreciate it if someone with both Java and Python could try and run this sample and report back. Any suggestions would be welcome, as this is quite the showstopper for me at the moment. I am sure I am missing something totally obvious... Thanks in advance, Nico. -- NetSys International (Pty) Ltd. Tel : +27 12 349 2056 Fax : +27 12 349 2757 Web : http://www.netsys.co.za P.O. Box 35798, Menlo Park, 0102, South Africa The information contained in this communication is confidential and may be legally privileged. It is solely for use of the individual or entity to whom is addressed and others authorised to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this information is strictly prohibited and may be unlawful. This Message has been scanned for viruses and dangerous content by the NetSys International Mail Scanner and is believed to be clean. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with spawning an external process
Apologies, this is on a Fedora Core 2 system. On Wed, 2006-04-12 at 11:27, Nico Kruger wrote: I want to execute a command (in this case, and it seems to be significant, a Java program) in a thread in Python. When I execute the java binary in the main python thread, everything runs correctly. But when I try and execute java in a thread, java segfaults. I am using Python 2.3.3 and trying to run the java binary from the 1.4.2 SDK from Sun. I have tried executing some arbitrary C program that I wrote, and it works fine in the main thread and the started thread. The problem seems to be specific to the Java binary. Here is the example code: --- START CODE --- import os import popen2 import time import select import threading # Change these to suit your system PATH = '/home/nico/j2sdk1.4.2/bin/java' #PATH = '/home/nico/j2sdk1.4.2/bin/java -invalid_arg' def get_ret(status): signal = status 0xff if signal == 0: retcode = status 8 else: retcode = 0 return signal,retcode print In main thread # Using spawn pid = os.spawnl(os.P_NOWAIT,PATH,PATH) ret = os.waitpid(pid,0) print PID: %i signal: %i return code: %i % (ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1]) class TestThread(threading.Thread): def run(self): # Using spawn pid = os.spawnl(os.P_NOWAIT,PATH,PATH) ret = os.waitpid(pid,0) print PID: %i signal: %i return code: %i % (ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1]) print In Thread TestThread().start() print Waiting... time.sleep(2) print ...Finished END CODE Here is the output that I get on my machine: [nico@ script]$ python testcrash2.py In main thread JAVA USAGE INFO STRIPPED PID: 32107 signal: 0 return code: 1 In Thread PID: 32116 signal: 11 return code: 0 You will notice that in the main thread, the program executes correctly (return code 1, signal 0). When the command is executed in the thread, it segfaults (signal 11). The second PATH= line calls Java with an invalid argument. In this case, it does not crash in the thread. I have tried a fork() and then os.execv in the thread as well, and get the same behaviour. I would appreciate it if someone with both Java and Python could try and run this sample and report back. Any suggestions would be welcome, as this is quite the showstopper for me at the moment. I am sure I am missing something totally obvious... Thanks in advance, Nico. -- NetSys International (Pty) Ltd. Tel : +27 12 349 2056 Fax : +27 12 349 2757 Web : http://www.netsys.co.za P.O. Box 35798, Menlo Park, 0102, South Africa The information contained in this communication is confidential and may be legally privileged. It is solely for use of the individual or entity to whom is addressed and others authorised to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this information is strictly prohibited and may be unlawful. This Message has been scanned for viruses and dangerous content by the NetSys International Mail Scanner and is believed to be clean. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with spawning an external process
Daniel, you are correct, it is not that good news for me :) But anyway, thanks to your responses, I installed Python 2.4.3 and it is working on my machine now as well. We were overdue for an upgrade to our Python environment anyways, so I think this is the final incentive to upgrade. Although, I will download 2.3.5 now and get back to you with the status. Would be interesting to know when exactly this problem was fixed, maybe it would help to know what is causing the problem? It really is a strange one. Again, thanks for your effort! On Wed, 2006-04-12 at 12:41, Daniel Nogradi wrote: Daniel, thanks for your input. What version of the JDK/JRE and Python are you using? So the previous test was on python 2.4, java 1.4.2, suse 9.3 but now I ran it on python 2.3.5, java 1.4.2, gentoo 1.4.16 and your code still does what it supposed to do. I'm not sure if that is good new for you though :) -- NetSys International (Pty) Ltd. Tel : +27 12 349 2056 Fax : +27 12 349 2757 Web : http://www.netsys.co.za P.O. Box 35798, Menlo Park, 0102, South Africa The information contained in this communication is confidential and may be legally privileged. It is solely for use of the individual or entity to whom is addressed and others authorised to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this information is strictly prohibited and may be unlawful. This Message has been scanned for viruses and dangerous content by the NetSys International Mail Scanner and is believed to be clean. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with spawning an external process
Not working with Python 2.3.5 here on Fedora Core 2 :(. Oh well, at least it's working on 2.4. Must be specific to something in the combination of Fedora Core 2 and Python 2.3.x, that is all I can think of. On Wed, 2006-04-12 at 12:55, Nico Kruger wrote: Daniel, you are correct, it is not that good news for me :) But anyway, thanks to your responses, I installed Python 2.4.3 and it is working on my machine now as well. We were overdue for an upgrade to our Python environment anyways, so I think this is the final incentive to upgrade. Although, I will download 2.3.5 now and get back to you with the status. Would be interesting to know when exactly this problem was fixed, maybe it would help to know what is causing the problem? It really is a strange one. Again, thanks for your effort! -- NetSys International (Pty) Ltd. Tel : +27 12 349 2056 Fax : +27 12 349 2757 Web : http://www.netsys.co.za P.O. Box 35798, Menlo Park, 0102, South Africa The information contained in this communication is confidential and may be legally privileged. It is solely for use of the individual or entity to whom is addressed and others authorised to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this information is strictly prohibited and may be unlawful. This Message has been scanned for viruses and dangerous content by the NetSys International Mail Scanner and is believed to be clean. -- http://mail.python.org/mailman/listinfo/python-list
Splitting a string
Dear Python users, I'd like to split a string where 'and', 'or', 'and not' occurs. Example string: s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green' I need to split s in order to get this list: ['Smith, R.', 'White', 'Blue, T.', 'Back', 'Red', 'Green'] Any idea, how I can split a string where 'and', 'or', 'and not' occurs? Thank you very much in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: python-soappy
can anybody point me to a tutorial, howto or example code of python-soappy...? google did not have really useful results about... This might be helpful: http://www-128.ibm.com/developerworks/library/ws-pyth5/ http://users.skynet.be/pascalbotte/rcx-ws-doc/python.htm Nico -- http://mail.python.org/mailman/listinfo/python-list
String question - find all possible versions of a person's firstname
Hi there, I have a string 'Michèle' that represents the firstname of a person. What's the best way to get all possible versions of this name if I consider to use these characters: e, è, é, ê I'd like to have a function that returns a list of the following names when passing 'Michèle' as parameter to it: 'Michele' 'Michelè' 'Michelé' 'Michelê' 'Michêle' 'Michêlè' 'Michêlé' 'Michêlê' 'Michèle' 'Michèlè' 'Michèlé' 'Michèlê' 'Michéle' 'Michélè' 'Michélé' 'Michélê' Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: String question - find all possible versions of a person's firstname
This sounds like a homework problem. You might try splitting the name at the e's, check the length of the resulting list and do that many nested loops. This was my idea too but I am wondering if there are any scripts for tasks like this. Nico -- http://mail.python.org/mailman/listinfo/python-list
How to ping in Python?
Hi there, I could not find any ping Class or Handler in python (2.3.5) to ping a machine. I just need to ping a machine to see if its answering. What's the best way to do it? Kind regards, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: ftplib question - ftp.dir() returns something and ftp.nlst() does not
add ftp.set_debuglevel(3) so you can see what the goes on the wire (without that information, it's hard to tell if it's a bug in the library or a glitch in your server). /F Hello Fredrik , thank you for your reply. I did a ftp.set_debuglevel(3) and ftp.nlst() now prints: ftp.nlst() *cmd* 'TYPE A' *put* 'TYPE A\r\n' *get* '200 Type set to I.\r\n' *resp* '200 Type set to I.' *cmd* 'PORT 10,30,1,31,128,129' *put* 'PORT 10,30,1,31,128,129\r\n' *get* '200 PORT command Ok.\r\n' *resp* '200 PORT command Ok.' *cmd* 'NLST' *put* 'NLST\r\n' *get* '150 About to open data connection.\r\n' *resp* '150 About to open data connection.' *retr* '' *get* '226 Transfer complete.\r\n' *resp* '226 Transfer complete.' [] Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: ftplib question - ftp.dir() returns something and ftp.nlst() does not
it's not obvious how Python could translate '' to anything other than an empty list, so it sure looks like a server issue. (or is a problem with running in passive mode? can you test with- out using passive mode on the same server?) I thought using ftp.set_pasv(0) sets active mode so I can use ftp.anyMethod() wihtout using passive mode? I tried: ftp.set_pasv(0) ftp.nlst() *cmd* 'TYPE A' *put* 'TYPE A\r\n' *get* '200 Type set to I.\r\n' *resp* '200 Type set to I.' *cmd* 'PORT 10,30,1,31,128,19' *put* 'PORT 10,30,1,31,128,19\r\n' *get* '200 PORT command Ok.\r\n' *resp* '200 PORT command Ok.' *cmd* 'NLST' *put* 'NLST\r\n' *get* '150 About to open data connection.\r\n' *resp* '150 About to open data connection.' *retr* '' *get* '226 Transfer complete.\r\n' *resp* '226 Transfer complete.' [] ftp.dir() -r--r--r-- 1 ownergroup 121984 Nov 24 12:13 member.dat -r--r--r-- 1 ownergroup 115 Nov 24 15:53 status.dat -r--r--r-- 1 ownergroup 339 Nov 24 15:53 debug.txt Nico -- http://mail.python.org/mailman/listinfo/python-list
ftplib question - ftp.dir() returns something and ftp.nlst() does not
Hi there, I am using the ftplib library to connect to a ftp server. After I got connected, I can see a list of file in the current directory using ftp.dir() or ftp.retrlines('LIST'). But using ftp.nlst() returns an empty list which seems somehow strange to me. Here is, what I did: from ftplib import FTP HOST = 'my.server' USER = 'myuser' PASSWD = 'mypass' ftp = FTP(HOST, USER, PASSWD) ftp.set_pasv(0) # set active mode ftp.dir() -r--r--r-- 1 ownergroup 121984 Nov 24 12:13 member.dat -r--r--r-- 1 ownergroup 115 Nov 24 15:53 status.dat -r--r--r-- 1 ownergroup 339 Nov 24 15:53 debug.txt ftp.retrlines('LIST') -r--r--r-- 1 ownergroup 121984 Nov 24 12:13 member.dat -r--r--r-- 1 ownergroup 115 Nov 24 15:53 status.dat -r--r--r-- 1 ownergroup 339 Nov 24 15:53 debug.txt '226 Transfer complete.' ftp.nlst() [] I thought ftp.nlst() would return the list ['member.dat', 'status.dat', 'debug.txt']. Any idea, what is going wrong here? Nico -- http://mail.python.org/mailman/listinfo/python-list
Question about parsing a string
Hi there, I would like to parse a string in Python. If the string is e.g. '[url=http://www.whatever.org][/url]' I would like to generate this string: 'a href=http://www.whatever.org;http://www.whatever.org/a' If the string is e.g. '[url=http://www.whatever.org]My link[/url]' I would like to generate this string: 'a href=http://www.whatever.org;My link/a' Any idea how I can do this? Maybe with regular expressions? Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
How to use a timer in Python?
Hi there, on a Linux machine running Python 2.3.5. I want to create a file 'newfile' in a directory '/tmp' only if there is no file 'transfer.lock' in '/temp'. A cronjob creates a file 'transfer.lock' in '/temp' directory every 15 minutes while the cronjob is doing something. This job takes around 30 seconds. During these 30 seconds the 'transfer.lock' file is present in the '/temp' directory and I must not create 'newfile'. After the cronjob has been finished, the 'transfer.lock' file is deleted from '/temp' and I can create 'newfile'. How can I use a timer that waits e.g. 10 seconds if 'transfer.lock' is present and then checks again if 'transfer.lock' is still there? I want to do something like this: import os if 'transfer.lock' in os.listdir('/temp'): # ...wait 10 seconds and then check again if # 'transfer.lock' is in os.listdir('/temp') else: # create 'newfile' Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use a timer in Python?
Hi Sybren and Wolfram, thank you very much for the time.sleep() tip. My program reads like this now. import os import time WINDOWS_SHARE = 'C:\\Temp' while 'transfer.lock' in os.listdir( WINDOWS_SHARE ): print Busy, please wait... time.sleep(10) f = open(WINDOWS_SHARE + '/myfile', 'w') f.write(test 123) f.close() print Done! Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use a timer in Python?
That all sounds very race-y to me! The cron-job and the other process need to take the same lock, otherwise the cron-job will start 1ms after the other process checks for transfer.lock and before it has a chance to create newfile and there will be trouble. Using files as locks isn't brilliant because the operations read to see if the lock is there and create the file isn't aren't atomic. Ie someone can get in there after you read the directory but before you create the file. However creating a directory is atomic, so you can take the lock by os.mkdir(/tmp/lock). If that succeeded you got the lock, if it failed (threw OSError) then you didn't. If it failed then just time.sleep(1) and try again. This kind of locking works cross platform too. You can use it in shell too, eg mkdir /tmp/lock || exit 1 in your cronjob. There is no cronjob anymore now. I just need to check if there is a lock file. How would you modify my short program to avoid the situation Ie someone can get in there after you read the directory but before you create the file.? Nico -- http://mail.python.org/mailman/listinfo/python-list
How to use writelines to append new lines to an existing file
Hi there, I would like to open an existing file that contains some lines of text in order to append a new line at the end of the content. My first try was: f = open('/tmp/myfile', 'w') #create new file for writing f.writelines('123') #write first line f.close() f = open('/tmp/myfile', 'w') #open existing file to append new line f.writelines('456') f.close() f = open('/tmp/myfile', 'r') # open file for reading f.read() '456' I supposed to have: f.read() '123\n456\n' Does f = open('/tmp/myfile', 'w') overwrite the existing file or does f.writelines('456') replace the first line in the existing file? Nico -- http://mail.python.org/mailman/listinfo/python-list
How to copy a file from one machine to another machine
Hi there, I would like to copy a file from one machine (machine #01) to another (machine #02). machine #01: Suse Linux 9.2, Samba 3, Python 2.3.5 machine #02: Windows Machine, Destination Dir: Share\temp\files\ Both machines are in one network so they can communicate each other. In order to be able to write a file in the directory on Machine #02 I need to be the user myadmin. In a short Python program I create the source file on Machine #01 like this: filecontent = 'This is just a test...' # my own helper method to generate a unique filename filename = createUniqueFilename() f = open('/var/files/' + filename, 'w') f.write(filecontent) f.close() Every time a new source file has been created it needs to be copied or moved from machine #01 to machine #02. Are there Python modules which help me doing this job? Any examples how to do that would be very helpful. Kind regards and many thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: How to copy a file from one machine to another machine
This isn't really a Python question, as this problem would exist irrespective of the language you are using. One possibility would be to run Samba (www.smaba.org) on the Linux machine so it offered a share to the Windows machine. Then you could just write to a UNC path (\\server\path\to\file) from Windows and have the file appear on the Linux machine. Another way would be to use CIFS client on Linux to access the share from the Windows machine. There are many other file sharing solutions, and you can of course also consider using FTP to send the file to the Linux server. Hello Steve, Samba is already installed and configured on the Linux machine. Can I just use file=open(path_to_my_windows_share,'w') in Python to mount the windows share and create the file? By the way, your book Python Web Programming is one of the best python books I have read! Really good work! Nico -- http://mail.python.org/mailman/listinfo/python-list
Embedded python
Hi, Does anyone have embedded a python interpreter on a proprietary hardware ? I have a home made hardware running a home made OS. C is used as programming language. I'd like to add a python interpreter to my system. Any guidelines ? Nicolas -- http://mail.python.org/mailman/listinfo/python-list
OT: Survey facing design patterns and communication
Hello everybody! We are a group of students at Freie Universitaet Berlin. As part of our computer science studies we are going to do a survey facing the use of design patterns in communication. Examples of design patterns are Abstract Factory, Singleton, Composite, Iterator and Listener. If you know what we are talking about, you are welcome to take part in our survey. It takes about 5 minutes to fill out the form. Just jump to: http://study.beatdepot.de If you agree, we will send you the results of our survey. Thanks in advance for your participation! And sorry for the interruption of your discussion. -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda a plusieurs arguments
Bonjour, [EMAIL PROTECTED] seems to be a good place to post questions related to Python if you intend to use french. - http://www.aful.org/wws/arc/python/ (( des questions rédigées en français sont plus à leur place sur des liste de diffusions nationales ... )) Désolé, je me suis trompé de groupe en postant... :( -- nico -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda a plusieurs arguments
Jp Calderone wrote: On Fri, 27 May 2005 19:38:33 +0200, nico [EMAIL PROTECTED] wrote: Bonjour, Comment faire une fonction lambda a plusieurs arguments ? (lambda a:a+1)(2) 3 f=(lambda (a,b):a+b) f(5,6) Traceback (most recent call last): File stdin, line 1, in ? TypeError: lambda() takes exactly 1 argument (2 given) f((5.6)) ^--- , f((5, 6)) 11 Aussi, f = lambda a, b: a + b f(5, 6) 11 Jp Ok, merci. -- nico -- http://mail.python.org/mailman/listinfo/python-list
lambda a plusieurs arguments
Bonjour, Comment faire une fonction lambda a plusieurs arguments ? (lambda a:a+1)(2) 3 f=(lambda (a,b):a+b) f(5,6) Traceback (most recent call last): File stdin, line 1, in ? TypeError: lambda() takes exactly 1 argument (2 given) f((5.6)) Traceback (most recent call last): File stdin, line 1, in ? File stdin, line 1, in lambda TypeError: unpack non-sequence pourquoi ca ne marche pas ? je ne comprends pas le message d'erreur ! Merci. -- nico -- http://mail.python.org/mailman/listinfo/python-list
Remove HTML tags (except anchor tag) from a string using regular expressions
Hello, I want to remove all html tags from a string content except a ...xxx/a. My script reads like this: ### import re content = re.sub('([^!]([^]|\n)*)', '', content) ### It works fine. It removes all html tags from content. Unfortunately, this also removes a ...xxx/a occurancies. Any idea, how to modify this to remove all html tags except a ...xxx/a? Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list