ImportError in python 2.5 in C API DLL
Hi, We are upgrading from Python 2.3 to verion 2.5 and when we recompile we get ImportError. To test we took the spam example from the web documentation and compiled it with Py23 and it imports without a problem. Changing the libs in visual studio 2008 to point to Py25 and we get: >>> import spam Traceback (most recent call last): File "", line 1, in ImportError: No module named spam >>> Would really appreciate any assistance. H -- #include "stdafx.h" #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } #ifdef _MANAGED #pragma managed(pop) #endif static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts; if (!PyArg_ParseTuple(args, "s", &command)) return NULL; sts = system(command); return Py_BuildValue("i", sts); } static PyMethodDef PyBSMethods[] = { {"spam", (PyCFunction) spam_system, METH_VARARGS|METH_KEYWORDS, "Hi"}, {NULL, NULL, 0, NULL}/* Sentinel */ }; extern "C" { __declspec(dllexport) void initspam(void) { PyObject* module = Py_InitModule("spam", PyBSMethods); PyObject* d = PyModule_GetDict(module); } } -- -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError in python 2.5 in C API DLL
On Oct 17, 1:05 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > Would really appreciate any assistance. > > You should change your project to create a .pyd file instead of a .dll > file. > > Regards, > Martin Ha-ha! Just rename the DLL to .pyd H -- http://mail.python.org/mailman/listinfo/python-list
dict: keys() and values() order guaranteed to be same?
Hi group, I have a question of which I'm unsure if the specification guarantees it. With an arbitrary dictionaty d, are d.keys() and d.values() guaraneed to be in the same order? I.e. what I mean is: # For all dictionaries d: assert({ list(d.keys())[i]: list(d.values())[i] for i in range(len(d)) } == d) I'm curious if it's allowed because in a special case it would make for a nice shortcut and clean code. I think however that the implementation may chose not to have them in the same order necessarily -- then I'd obviously avoid relying on it. Best regards, Joe -- http://mail.python.org/mailman/listinfo/python-list
Re: dict: keys() and values() order guaranteed to be same?
On 23.07.2012 13:40, Philipp Hagemeister wrote: > On 07/23/2012 01:23 PM, Henrik Faber wrote: >> With an arbitrary dictionaty d, are d.keys() and d.values() >> guaraneed to be in the same order? > > Yes. From the documentation[1]: > > If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() > are called with no intervening modifications to the dictionary, the > lists will directly correspond. Ah, nice! > In most cases, you should simply use items() though. Can you elaborate > on the use case for needing both keys() and values(), where items() is > not applicable? I need to parse and modify the keys of the dict and pass the keys as a compound object to a function, which expects the values to be passed as an argument list (weird, but can't change that). The order of arguments is arbitrary (as the iteration over a dict is), but there has to be a 1-to-1 relation bewtween the compound object's key order and the argument list's value order. Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rï¾â¢.......ï¾
On 23.07.2012 14:55, Roy Smith wrote: > In article <500d0632$0$1504$c3e8da3$76491...@news.astraweb.com>, > Steven D'Aprano wrote: > >> Technically, no, it's a SyntaxError, because the Original Poster has used >> some sort of "Smart Quotes" characters rââ¬â¢Ã¢â¬Ë instead of good old fashioned >> typewriter-style quotes r'' or r"". >> >> If you're going to ask programming questions using an email client that >> changes what you type, including smart quotes, special hyphens or other >> characters, you're going to have a bad time. > > Some day, we're going to have programming languages that take advantage > of the full unicode character set. Right now, we're working in ASCII > and creating silly digrams/trigrams like r'' for raw strings (and > triple-quotes for multi-line > strings). Not to mention <=, >=, ==, !=. And in languages other than > python, things like ->, => (arrows for structure membership), and so on. I disagree. Firstly, Python could already support the different types of strings even with the ASCII character set. For example, the choice could have made to treat the apostophe string 'foo' differently from the double quote string "foo". Then, the backtick could have been used `foo`. Bash for example uses all three and all three have very different meanings. Python is different: explicit is better than implicit, and I'd rather have the "r" the signifies what weird magic is going on instead of having some weird language rules. It would not be different with some UTF-8 "rawstring" magic backticks. Secondly, there's a reason that >=, <= and friends are in use. Every keyboard has a > key and every keyboard has a = key. I don't know any that would have >=, <= or != as UTF-8. It is useful to use only a limited set of characters. And if I think of PHP's latest fiasco that happened with unicode characters, it makes me shudder to think you'd want that stuff in Python. If I remember correctly, it was the Turkish locale that they stuggled with: Turkey apparently does not have a capital "I", so some weird PHP magic code broke with the Turkish locale in effect. Having to keep crap like that in mind is just plain horrible. I'm very happy with the way Python does it. Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rï¾â¢.......ï¾
On 23.07.2012 14:55, Roy Smith wrote: > Some day, we're going to have programming languages that take advantage > of the full unicode character set. Plus, if I may add this: It's *your* newsreader that broke the correctly declared ISO-8859-7 encoded subject of the OP. What a bitter irony that demonstrates nicely that even in the 2010s complete and ultimate Unicode support is far from here. Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rï¾â¢.......ï¾
On 23.07.2012 15:35, Chris Angelico wrote: > That said, though, there's good argument in allowing full Unicode in > *identifiers*. If I'm allowed to name something "foo", then a German > should be allowed to name something "foö". And since identifiers are > case sensitive (at least, they are in all good languages...), there > should be no issues with not having particular letters. To you have a "ö" key on your keyboard? I have one. It wouldn't be a problem for me. Most English layouts probably don't. It would be annoying. If you allow for UTF-8 identifiers you'll have to be horribly careful what to include and what to exclude. Is the non-breaking space a valid character for a identifier? Technically it's a different character than the normal space, so why shouldn't it be? What an awesome idea! What about à vs x? Or à vs à vs à vs à vs Ĩ vs Ī vs Ä« vs Ĭ vs Ä vs Ä® vs į vs I vs İ? Do you think if you need to maintain such code you'll immediately know the difference between the 13 (!) different "I"s I just happened to pull out randomly you need to chose and how to get it? What about È vs È? Or È¢ vs È£? Or ȸ vs ȹ? Or d vs Ô vs Ô vs Ô vs Ô? Or Ö vs g? Or Õ½ vs u? I've not even mentioned the different punctuation marks and already it's hell of a mess, although I just happened to look into a few pages. Having UTF-8 in identifiers is a horrible idea. It makes perfect sense to support it within strings (as Python3 does), but I would hate for Python to include them into identifiers. Then again, I'm pretty sure this is not planned anytime soon. Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rï¾â¢.......ï¾
On 23.07.2012 15:52, Henrik Faber wrote: > but I would hate for > Python to include them into identifiers. Then again, I'm pretty sure > this is not planned anytime soon. Dear Lord. Python 3.2 (r32:88445, Dec 8 2011, 15:26:58) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> fööbär = 3 >>> fööbär 3 I didn't know this. How awful. Regards, Johannes -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rï¾â¢.......ï¾
On 23.07.2012 15:55, Henrik Faber wrote: > Dear Lord. > > Python 3.2 (r32:88445, Dec 8 2011, 15:26:58) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> fööbär = 3 >>>> fööbär > 3 > > I didn't know this. How awful. Apparently, not all characters are fine with Python. Why can I not have domino tiles are identifier characters? >>> ð» = 9 File "", line 1 ð» = 9 ^ SyntaxError: invalid character in identifier I think there needs to be a PEP for that. Regads, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rユ.......ï¾
On 23.07.2012 16:19, Chris Angelico wrote: > On Mon, Jul 23, 2012 at 11:52 PM, Henrik Faber wrote: >> What about × vs x? Or Ì vs Í vs Î vs Ï vs Ĩ vs Ī vs ī vs Ĭ vs ĭ vs Į vs >> į vs I vs İ? Do you think if you need to maintain such code you'll >> immediately know the difference between the 13 (!) different "I"s I just >> happened to pull out randomly you need to chose and how to get it? What >> about Ȝ vs ȝ? Or Ȣ vs ȣ? Or ȸ vs ȹ? Or d vs Ԁ vs ԁ vs ԃ vs Ԃ? Or ց vs g? >> Or ս vs u? > > If they're different characters, they're different. It's not unlike > the confusion you can already get between uppercase I and lowercase l, > or between uppercase and lowercase of the same letter, or between rn > and m, or between any other of myriad confusingly-similar pairs that > can be found just in ASCII. But your reasoning is flawed: bascially you're saying some things are already confusing, so it's just fine to add more confusion. It is not in my opinion. And that the computer can differentiate different characters is also perfectly clear to me. The interpreter can also tell the difference between a non-breaking space and a regular space. Yet the non breaking space is not valid for a identifying character. This is because readability counts. People write and maintain code, not machines. Confusion should be kept to the miminum if possible. > Of course, SOMEBODY is going to make use of those to improve upon this > sort of code: > > http://thedailywtf.com/Articles/Uppity.aspx If that was written by my coworkers, I'd strangle them. Regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rユ.......ï¾
On 23.07.2012 16:10, Devin Jeanpierre wrote: > On Mon, Jul 23, 2012 at 9:52 AM, Henrik Faber wrote: >> If you allow for UTF-8 identifiers you'll have to be horribly careful >> what to include and what to exclude. Is the non-breaking space a valid >> character for a identifier? Technically it's a different character than >> the normal space, so why shouldn't it be? What an awesome idea! >> >> What about × vs x? Or Ì vs Í vs Î vs Ï vs Ĩ vs Ī vs ī vs Ĭ vs ĭ vs Į vs >> į vs I vs İ? Do you think if you need to maintain such code you'll >> immediately know the difference between the 13 (!) different "I"s I just >> happened to pull out randomly you need to chose and how to get it? What >> about Ȝ vs ȝ? Or Ȣ vs ȣ? Or ȸ vs ȹ? Or d vs Ԁ vs ԁ vs ԃ vs Ԃ? Or ց vs g? >> Or ս vs u? > > Yes, as soon as we add unicode to anything everyone will go insane and > write gibberish. No, you misunderstood me. I didn't say people are going to write gibberish. What I'm saying is that as a foreigner (who doesn't know most of these characters), it can be hard to accurately choose which one is the correct one. This is especially true if the appropriate keys are not available on your keyboard. So it makes maintenance of other people's code much more difficult if they didn't on their own chose to limit themselves to ASCII. Regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: the meaning of rï¾â¢.......ï¾
On 23.07.2012 16:43, Mark Lawrence wrote: >> Apparently, not all characters are fine with Python. Why can I not have >> domino tiles are identifier characters? >> >>>>> ð» = 9 >>File "", line 1 >> ð» = 9 >> ^ >> SyntaxError: invalid character in identifier >> >> I think there needs to be a PEP for that. > > well get writing then as there's nothing to stop you. I might wait until April 1st next year with that ;-) Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. C++11
On 15.02.2012 08:18, Tim Roberts wrote: > sturlamolden wrote: >> >> There are bigsimilarities between Python and the new C++ standard. Now >> we can actually use our experience as Python programmers to write >> fantastic C++ :-) > > This is more true than you might think. For quite a few years now, I've > been able to do an almost line-for-line translation of my Python programs > to C++ programs. (Microsoft has had a "for each" extension for a while > that made this easier.) I disagree. Unicode support comes for free with Python3+ while C++ it still is a piece of crap (or something that you'll have to pass to external libraries). The C++ standard library is nowhere nearly as densely packed with features than Python's. For every little thing you need some external dependencies. Language semantics aren't enough to translate one language into another. Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux)
What is also useful to know, is that I'm observing this on a legacy RHEL 6 system *with a customized kernel* part of the Scyld ClusterWare (https://www.penguincomputing.com/products/software/scyld-clusterware/) that *cannot* be updated: $ uname -a Linux n6 2.6.32-504.12.2.el6.664g.x86_64 #1 SMP Wed Mar 11 14:20:51 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux I appreciate any suggestions to further troubleshoot this and ideally resolve it. The reason for this being an important issue is that `find_library()` of ctypes.util performs the above stalling `Popen(['/sbin/ldconfig', '-p'])` call that was introduced in Python (>= 2.7.13). This happens for instance whenever we try to create a new virtual environment using `virtualenv`. In other words, the solution is *not* really to change the code to use, say, the shell=True approach. Thanks, Henrik PS. This is my first post to this list - please let me know if I should send to another forum instead. -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux)
Ok, thanks. I've just created https://bugs.python.org/issue35305. /Henrik On Fri, Nov 23, 2018 at 6:47 PM INADA Naoki wrote: > > Thank you for a very informative report. > > > PS. This is my first post to this list - please let me know if I > > should send to another forum instead. > > Would you send this report to the issue tracker? > https://bugs.python.org/ > > -- > INADA Naoki -- https://mail.python.org/mailman/listinfo/python-list
Re: Why Python don't accept 03 as a number?
A comment from the sideline: one could imagine extending the Python syntax with a (optional) 0d prefix that allows for explicit specification of decimal values. They would "complete" the family: * 0b: binary number * 0o: octal number * 0d: decimal number * 0x: hexadecimal number I understand that changing the syntax/parser is a major move. I wouldn't be surprised if others brought up 0d before. My $.02 Henrik On Fri, Dec 7, 2018, 21:12 Cameron Simpson On 07Dec2018 20:24, Jach Fong wrote: > >Ian at 2018/12/8 UTC+8 AM11:28:34 wrote: > >> What is it exactly that you're trying to accomplish with this? Perhaps > >> there's a better way than using eval. > > > >This problem comes from solving a word puzzle, > >ab + aa + cd == ce > >Each character will be translate to a digit and evaluate the correctness, > >03 + 00 + 15 == 18 > > Then you should be evaluating the digits and assembling values from > them. Not trying to shoehorn a string through something that _might_ > accept this string and do what you want. In Python 2 it will accept your > string and not do what you want; at least in Python 3 it doesn't accept > your string. > > My point here is that the structure of your puzzle doesn't map directly > into a naive python statement, and you shouldn't be pretending it might. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Fwd: Uninstall was succesful - but actually nothing happened
Hey, I noticed that the uninstaller says that the installation completed, but actually nothing really happened and all of my Python 3.6.8 installation was still completely installed on my machine and all files were located inside Python/Python36 folder still. See the picture attached. My computer is Windows 10, version 1909, build 10.0.18363. -- https://mail.python.org/mailman/listinfo/python-list
Iteration over two sequences
I am just starting to learn Python, mostly by going through the examples in Dive Into Python and by playing around. Quite frequently, I find the need to iterate over two sequences at the same time, and I have a bit of a hard time finding a way to do this in a "pythonic" fashion. One example is a dot product. The straight-ahead C-like way of doing it would be: def dotproduct(a, b): psum = 0 for i in range(len(a)): psum += a[i]*b[i] return psum However, the range(len(a)) term is awfully un-pythonic :) The built-in function map() gives me a way of "transposing" the a list and the b list, and now I can handle it with a list comprehension: def dotproduct(a, b): return sum([x*y for x, y in map(None, a, b)]) My concern is one of efficiency: it seems to me that I have two loops there: first one implied with map(...) and then the for loop -- which seems like a waste since I feel I should be able to do the multiplication via an argument to map. So far I have come up with an alternative via defining a separate function: def dotproduct(a, b): def prod(x,y): return x*y return sum(map(prod, a, b)) I suppose I could also use a lambda here -- but is there a different, efficient, and obvious solution that I'm overlooking? Thanks, Henrik -- "On some great and glorious day the plain folks of the land will reach in their heart's desire at last and the White House will be adorned by a downright moron." -H.L. Mencken (1880-1956) American Writer -- http://mail.python.org/mailman/listinfo/python-list
Re: Iteration over two sequences
Richard Brodie <[EMAIL PROTECTED]> wrote: > "Henrik Holm" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > I suppose I could also use a lambda here -- but is there a different, > > efficient, and obvious solution that I'm overlooking? > > Check the itertools recipes in the library documentation. Thanks, the itertools seem to contain several useful functions. -- "On some great and glorious day the plain folks of the land will reach in their heart's desire at last and the White House will be adorned by a downright moron." -H.L. Mencken (1880-1956) American Writer -- http://mail.python.org/mailman/listinfo/python-list
Re: Iteration over two sequences
John Lenton <[EMAIL PROTECTED]> wrote: > > def dotproduct(a, b): > >psum = 0 > >for i in range(len(a)): > >psum += a[i]*b[i] > >return psum > > for this particular example, the most pythonic way is to do nothing at > all, or, if you must call it dotproduct, > >>> from Numeric import dot as dotproduct Downloading, installing, and getting to know numerical modules for Python is mext on my list :). However, I was under the impression that Numarray is preferred to Numeric -- is that correct? Are these two competing packages? (Hopefully this is not flame war bait...) -- "On some great and glorious day the plain folks of the land will reach in their heart's desire at last and the White House will be adorned by a downright moron." -H.L. Mencken (1880-1956) American Writer -- http://mail.python.org/mailman/listinfo/python-list
Closing files
I have recently started playing around with Python. Some of the things I have done have involved reading files. The way I do this is along the lines of f = file('file.txt') lines = f.readlines() f.close() I have noticed that it is possible to do this in one line: lines = file('file.txt').readlines() My question is: does the file get closed if I do the reading in this manner? Similarly, for reading the output from other programs or system commands, I would do: o = popen('executable') lines = o.readlines() o.close() Is it OK to do this with a one-liner as well, with lines = popen('executable').readlines() without closing the file object? Thanks, Henrik Holm -- http://mail.python.org/mailman/listinfo/python-list
Operator commutativity
Hi there, when I have a python class X which overloads an operator, I can use that operator to do any operation for example with an integer y = X() + 123 however, say I want the "+" operator to be commutative. Then y = 123 + X() should have the same result. However, since it does not call __add__ on an instance of X, but on the int 123, this fails: TypeError: unsupported operand type(s) for +: 'int' and 'X' How can I make this commutative? Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Operator commutativity
On 19.09.2011 13:23, Paul Rudin wrote: > Henrik Faber writes: > >> How can I make this commutative? > > Incidentally - this isn't really about commutativity at all - the > question is how can you define both left and right versions of add, > irrespective of whether they yield the same result. Right. The operator+ in my case just happens to be commutative and I wanted a language way to express this. > I think __radd__ is what you're after. It is, thank you very much - I knew there was some way to get this done nicely. Perfect! :-) Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On 07.11.2011 23:06, Chris Angelico wrote: > On Tue, Nov 8, 2011 at 8:46 AM, david vierra wrote: >> But, you didn't write an all() function. You wrote a more specialized >> allBoolean() function. I think this comparison is more fair to the >> builtin all(): > > So really, it's not "all() is slow" but "function calls are slow". > Maybe it'd be worthwhile making an all-factory: PLEASE say you're joking. If I saw code like that on any of our project, this would definitely qualify for a DailyWTF. Regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple threads
On 16.11.2011 14:48, Eduardo Oliva wrote: > I need my script to run 2 separated threads, and then when the first has > finished, starts the next onebut no more than 2 threads. > I know that Semaphores would help with that. > But the problem here is to know when the thread has finished its job, to > release the semaphore and start another thread. Absolute standard request, has nothing to do with Python. The way to go (in Cish pseudocode) is: thread() { /* do work */ [...] /* finished! */ semaphore++; } semaphore = 2 while (jobs) { semaphore--;// will block if pool exhausted thread(); } // in the end, collect remaining two workers semaphore -= 2 // will block until all are finished Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Confusion about decorators
Hi group, I'm a bit confused regarding decorators. Recently started playing with them with Python3 and wanted (as an excercise) to implement a simple type checker first: I know there are lots of them out there, this is actually one of the reasons I chose that particular function (to compare my solution against other, proven solutions). Starting with a blank slate, I did something along the lines of: class _TypeCheckedFunction(): def __init__(self, decoratedfunction): self._decoratedfunction = decoratedfunction def __call__(self, *args, **kwargs): [...] Actual checking def typecheck(wrappedfunction): checkfunction = _TypeCheckedFunction(wrappedfunction) functools.update_wrapper(checkfunction, wrappedfunction) return checkfunction And decorate my methods like @typecheck def setbar(self, bar: str): This works somewhat. The problem is, however, when the method is actually called. This is what happens: 1. The decorator is called upon import of the decorated class. It creates a _TypeCheckedFunction(setbar) object. 2. When setbar is actually called (blubb.setbar("fooobar")), the __call__ method of the previously created _TypeCheckedFunction is invoked. 3. When trying to call self._decoratedfunction from within that object, this fails: "self" is missing! self._decoratedfunction is only the *function*, not the bound function of the object that contains setbar(). Therefore I cannot proceed here. Solutions that I have seen working usually consist of two functions wrapped in each other, but I do not know why the additional introduction of a class makes everything fail. Can someone please enlighten me? Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Confusion about decorators
On 12.12.2011 14:37, Andrea Crotti wrote: > On 12/12/2011 01:27 PM, Henrik Faber wrote: >> Hi group, >> >> I'm a bit confused regarding decorators. Recently started playing with >> them with Python3 and wanted (as an excercise) to implement a simple >> type checker first: I know there are lots of them out there, this is >> actually one of the reasons I chose that particular function (to compare >> my solution against other, proven solutions). > > Not sure how that could work in general, what does "bar: str" should do? > Is that a dictionary? No. It's PEP 3107 function annotations. > Anyway there is already an implementation if you're interested for type > checking: > http://oakwinter.com/code/typecheck/ *sigh* no, not really -- this is exactly why I wrote "I know there are lots of them out there". I've actually seen and run http://code.activestate.com/recipes/577299-method-signature-type-checking-decorator-for-pytho/ However, this doesn't do it for me -- I want to know why my solution fails, not just use some other solution without really understanding it. I really would like to understand what's going on. I'm especially puzzled about the fact that in my solution, __call__ is called with only the method's arguments (i.e. "fooobar") in my example instead of two arguments (self, "fooobar"). Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Confusion about decorators
On 12.12.2011 14:45, Arnaud Delobelle wrote: >> Can someone please enlighten me? > > You can (need to?) use the descriptor protocol to deal with methods. > > from functools import partial [...] >def __get__(self, obj, objtype): >return partial(self, obj) Whoa. This is absolutely fantastic, it now works as expected (I get a reference to "self"). I am very amazed -- I've been programming Python for about 5 years now and have never even come close to something as a "descriptor protocol". Python never ceases to amaze me. Do you have any beginners guide how this works? The Pydoc ("Data Model") is comprehensive, but I really don't know where to start to look. Still amazed! Best regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Confusion about decorators
On 12.12.2011 15:01, Arnaud Delobelle wrote: >> I am very amazed -- I've been programming Python for about 5 years now >> and have never even come close to something as a "descriptor protocol". >> Python never ceases to amaze me. Do you have any beginners guide how >> this works? The Pydoc ("Data Model") is comprehensive, but I really >> don't know where to start to look. > > Well, I've been using Python for 10 years :) The best reference I know is: > > http://users.rcn.com/python/download/Descriptor.htm Everyone starts out as a Padawan and I am no exception :-) Maybe five years from now I'll also have made my way to be a Python Jedi and also shake the ins and outs of descriptors out of my sleeve :-) But I can only repeat myself: Python is such an exceptional language, the more and more I know about it, the more I fall in love! Fantastic. I wish we had these types of language when I was a kid! Best regards and thanks again, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Signature-preserving decorators
Hi group, when decorating a method in Python3, by use of the functools.update_wrapper function, it can be achieved that the docstring and name of the original function is preseverved. However, the prototype is lost: When looking into the Python help, I have lots of entries that look like: getfoo(*args, **kwargs) -> int setbar(*args, **kwargs) As you can imagine, this is really not very self-explanatory. I've seen a solution which constructs a wrapper's wrapper function using inspection and eval -- this looks really dirty to me, however. Then there's the "decorator" external module -- but I'd like to do it with on-board tools. Is this possible in Python3 with too much of a hassle? Best regards, Joe -- http://mail.python.org/mailman/listinfo/python-list
Face Recognition
Hi there! Has anyone made effort to try to create a python binding to a facial recognition software [1]? For those of you with some experience - would this be very hard? [1] An example: http://www.cs.colostate.edu/evalfacerec/ -- http://mail.python.org/mailman/listinfo/python-list
Starting an external, independent process from a script
Hi there! I'm trying to create a video uploading service (just to learn). The system is mostly based on Django, but the question I'm looking an answer for is more related to Python. So, the user gets to upload a video file. This can either be a mpg, avi or mp4-file. When the file is saved to its location, I want to convert it to FLA (Flash Video). I'm currently using Mplayers Mencoder, and this works great. The Mencoder is retrieved through running os.system("mencoder variables here") The problem with this is that the user has to wait until the movie is done encoding until he can go around with his business. I don't look upon this as ideal. So - I want to spawn a new system process. I need some good pointers on how to do this right. Any input? :-) Thanks a lot in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Starting an external, independent process from a script
I've tried os.spawnv and os.spawn, but these give no error and no result. Henrik Lied skreiv: > Hi there! > > I'm trying to create a video uploading service (just to learn). The > system is mostly based on Django, but the question I'm looking an > answer for is more related to Python. > > So, the user gets to upload a video file. This can either be a mpg, > avi or mp4-file. When the file is saved to its location, I want to > convert it to FLA (Flash Video). I'm currently using Mplayers > Mencoder, and this works great. The Mencoder is retrieved through > running os.system("mencoder variables here") > > The problem with this is that the user has to wait until the movie is > done encoding until he can go around with his business. I don't look > upon this as ideal. > > So - I want to spawn a new system process. I need some good pointers > on how to do this right. > > Any input? :-) > > Thanks a lot in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Starting an external, independent process from a script
Unfortunately, that didn't work either. The output is empty, I don't get a message, and I definitely don't get a converted file. 2007/3/13, rishi pathak <[EMAIL PROTECTED]>: You can do something like this: pid = os.fork() if pid != 0: os.execl("mencoder variables here and its arguments") else: continue exec will replace the current child process with the given command and as we are doing fork the command will get executed in a child process.You can also use os.system there On 12 Mar 2007 16:13:51 -0700, Henrik Lied <[EMAIL PROTECTED] > wrote: > > Hi there! > > I'm trying to create a video uploading service (just to learn). The > system is mostly based on Django, but the question I'm looking an > answer for is more related to Python. > > So, the user gets to upload a video file. This can either be a mpg, > avi or mp4-file. When the file is saved to its location, I want to > convert it to FLA (Flash Video). I'm currently using Mplayers > Mencoder, and this works great. The Mencoder is retrieved through > running os.system("mencoder variables here") > > The problem with this is that the user has to wait until the movie is > done encoding until he can go around with his business. I don't look > upon this as ideal. > > So - I want to spawn a new system process. I need some good pointers > on how to do this right. > > Any input? :-) > > Thanks a lot in advance! > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards-- Rishi Pathak National PARAM Supercomputing Facility Center for Development of Advanced Computing(C-DAC) Pune University Campus,Ganesh Khind Road Pune-Maharastra -- Med vennlig hilsen, Henrik Lied -- http://mail.python.org/mailman/listinfo/python-list
Problems with os.spawnv
Hi there! I'm trying to convert a video in a background process. The scenario I'm after: 1. The user uploads a video 2. The video is saved in my media directory, and the database is populated with the references 3. The video gets converted to FLV - but the user shouldn't have to wait around for this to happen So, I thought to myself that spawnv would be a good fit for this. The problem is that it doesn't fire of the command. Here's my test script: http://dpaste.com/hold/7981/ Why won't this work? The while-loop is printed, but the os command isn't executed. I've also tried to specify the whole path to mencoder (/opt/local/bin/mencoder), but to no use. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with os.spawnv
On Apr 5, 11:33 pm, [EMAIL PROTECTED] wrote: > On Apr 5, 4:19 pm, "Henrik Lied" <[EMAIL PROTECTED]> wrote: > > > > > Hi there! > > > I'm trying to convert a video in a background process. > > The scenario I'm after: > > 1. The user uploads a video > > 2. The video is saved in my media directory, and the database is > > populated with the references > > 3. The video gets converted to FLV - but the user shouldn't have to > > wait around for this to happen > > > So, I thought to myself that spawnv would be a good fit for this. The > > problem is that it doesn't fire of the command. > > > Here's my test script:http://dpaste.com/hold/7981/ > > > Why won't this work? The while-loop is printed, but the os command > > isn't executed. I've also tried to specify the whole path to mencoder > > (/opt/local/bin/mencoder), but to no use. > > I don't know what the deal is. Maybe you should try the subprocess > module since it replaces the os.spawn* modules and do a > subprocess.Popen instead? Or don't assign the result to a variable > since you told it not to wait. You may need to do a combination of the > subprocess module and one of the Threading modules. > > Mike Thanks for the quick reply, Mike! I've taken a look at the Subprocess module, but it's all a bit new to me, if you know what I mean. You wouldn't be able to supply me with an example, would you? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with os.spawnv
On Apr 5, 11:39 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 05 Apr 2007 18:19:56 -0300, Henrik Lied <[EMAIL PROTECTED]> > escribió: > > > So, I thought to myself that spawnv would be a good fit for this. The > > problem is that it doesn't fire of the command. > > > Here's my test script:http://dpaste.com/hold/7981/ > > > Why won't this work? The while-loop is printed, but the os command > > isn't executed. I've also tried to specify the whole path to mencoder > > (/opt/local/bin/mencoder), but to no use. > > You are using: > v = os.spawnv(os.P_NOWAIT, "mencoder", "/Users/henriklied/test.mov > -ofps 25 -o test.flv ...") > > Read the docs about the spawnv function: > http://docs.python.org/lib/os-process.html#l2h-2749 > > In particular "...The "v" variants are good when the number of parameters > is variable, with the arguments being passed in a list or tuple as the > args parameter. In either case, the arguments to the child process must > start with the name of the command being run." > > So, for spawnv, you should build a list with each argument as an item, > being "mencoder" the first item. > But in your case it's a lot easier to use spawnl: > > v = os.spawnl(os.P_NOWAIT, "mencoder", "mencoder", > "/Users/henriklied/test.mov", "-ofps", "25", "-o", "...") > > -- > Gabriel Genellina Hi Gabriel, Thanks for your reply - but I'm afraid to tell you that spawnl didn't do the trick either. Here's the full command I used: http://dpaste.com/hold/7982/ I'd still love to get a working example of my problem using the Subprocess module. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with os.spawnv
On Apr 6, 12:09 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 05 Apr 2007 18:53:04 -0300, Henrik Lied <[EMAIL PROTECTED]> > escribió: > > > On Apr 5, 11:39 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > > wrote: > >> v = os.spawnl(os.P_NOWAIT, "mencoder", "mencoder", > >> "/Users/henriklied/test.mov", "-ofps", "25", "-o", "...") > > > Thanks for your reply - but I'm afraid to tell you that spawnl didn't > > do the trick either. > > Here's the full command I used:http://dpaste.com/hold/7982/ > > What means "didnt do the trick"? Do you get an exception? what's the > returned value? > Does the command work OK from the console? > Try from the python interpreter, using P_WAIT, and inspect the returned > value. That's what I've done. P_WAIT returned a the PID 127 - but there's still no sign of the FLV-file, I'm afraid. > > > I'd still love to get a working example of my problem using the > > Subprocess module. :-) > > The same thing: > p = subprocess.Popen(["mencoder", "/users/...", "-ofps", ...]) > That example looked great at first, but on a closer look it didn't quite end up to be what I wanted. In a real environment the user still had to wait for the command to finish. > -- > Gabriel Genellina I'm not sure what to do. I'm thinking of simply creating a crontab which checks the database every five minutes or so, and converts the videos that aren't converted. But if anyone has a good and easy solution in Python, I'd rather have that. I dare to think that people here will understand that. -- http://mail.python.org/mailman/listinfo/python-list
"No backend servers available" using httplib
Hi there! I'm using a recipe found on ASPN [1] to upload some data to an external server. The request fails, and all I get in response is "No backend servers available". So I'm wondering: Is this a known exception-message in httplib, or could it be an error in the requested external resource? [1]: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 - Thanks, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: "No backend servers available" using httplib
On Sep 27, 11:56 am, Bruno Desthuilliers wrote: > Henrik Lied a écrit : > > > Hi there! > > > I'm using a recipe found on ASPN [1] to upload some data to an > > external server. > > > The request fails, and all I get in response is "No backend servers > > available". > > > So I'm wondering: Is this a known exception-message in httplib, > > If it was, you should have a full traceback then. > > > or > > could it be an error in the requested external resource? > > [1]:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 > > From the recipe's code and the message, looks like you're connecting to > (or via) a proxy which fails to relay to the real server. Hello Bruno, The actual reason was quite a bit simpler: The receiving server required a certain keyword to be first in the request - which I was not aware of. So now it works - but it's not perfect: Is there a way to stream the file content over the connection? The way it works now, the whole file is loaded into memory, right? -- http://mail.python.org/mailman/listinfo/python-list
NameError: name 'execfile' is not defined
Newbie issue: I downloaded http://www.python.org/download/releases/3.0.1/ (windows insaller), opened the interpreter, wrote a print "Hello World" program in helloworld.py, and in the interpreter typed execfile("helloworld.py") Got back NameError: name 'execfile' is not defined (following tutorial in David Beazley's Python Essential Reference). Is execfile not supported in 3? Thanks, - Henrik -- http://mail.python.org/mailman/listinfo/python-list
Invalid syntax with print "Hello World"
obviously total mewbiew: My first program in Python Windows print "Hello World" I select Run/Run Module and get an error: Syntax error, with the closing quote highlighted. Tried with single quotes as well. Same problem. Can someone explain my mistake? Thanks, - Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Invalid syntax with print "Hello World"
On Mar 12, 7:45 am, Dotan Cohen wrote: > > Welcome to the list. As a newbie myself, I ran into the Python3 vrs > > 2.6 issue. May I suggest starting with 2.6? There is many more books > > and internet stuff you can learn with in 2.6 - and the examples will > > work. As Garry wrote, once you understand 2.6, 3.0 will not be a > > challenge. > > I do not think that is the best way to go about learning Python. Why > learn an arguably depreciating version when the new version is > available. I agree that there are not many tutorial written for Python > 3 however there are enough to get going: most of the Python 2 > tutorials are redundant. Sticking to Python 3 tutorials will give him > a higher signal-to-noise ratio in the tutorials that he finds. > > -- > Dotan Cohen > > http://what-is-what.comhttp://gibberish.co.il > > א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת > ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه-و-ي > А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я > а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я > ä-ö-ü-ß-Ä-Ö-Ü Thanks everyone! Now that I know what the issue is (2 vs 3), I'll be able to resolve those kinds of issues in the future. Thanks again! - Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: NameError: name 'execfile' is not defined
On Mar 12, 3:15 am, Gary Herron wrote: > Henrik Bechmann wrote: > > Newbie issue: > > > I downloadedhttp://www.python.org/download/releases/3.0.1/(windows > > insaller), opened the interpreter, wrote a print "Hello World" program > > in helloworld.py, and in the interpreter typed > > > execfile("helloworld.py") > > > Got back > > > NameError: name 'execfile' is not defined > > > (following tutorial in David Beazley's Python Essential Reference). > > > Is execfile not supported in 3? > > That's correct. > > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.0.htmlyou can find this > line: > > Removed execfile(). Instead of execfile(fn) use exec(open(fn).read()). > > Gary Herron > > > Thanks, > > > - Henrik > > -- > >http://mail.python.org/mailman/listinfo/python-list Excellent. Thanks very much! - Henrik -- http://mail.python.org/mailman/listinfo/python-list
Sentiment analysis using Python
Hi there, An experiment I'm currently involved with requires some form of texual analysis to figure out the "mood" of sentences (ergo, if the sentence in any way seem negative or positive). Do any of you have experience with something equivalent, and perhaps some pointers on where I should go forward? I've had some experience with Naive Bayes in the past, but I assume the training would be colossal (I've got texts in the thousands to examine). Any tips appreciated! -- Henrik L. -- http://mail.python.org/mailman/listinfo/python-list
Help with SOAPpy and WSDL.
I have a problem with SOAPpy and WSDL. It is explained here: http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 Many regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with SOAPpy and WSDL.
I'll try to explain it here then: A small example on SOAPpy and WSDL. My code: from SOAPpy import WSDL wsdlFile = 'http://www.webservicex.net/country.asmx?wsdl' server = WSDL.Proxy(wsdlFile) server.GetCurrencyByCountry('Zimbabwe') returns: Traceback (most recent call last): File "pythonwsdl.py", line 4, in server.GetCurrencyByCountry('Zimbabwe') File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 470, in __call__ return self.__r_call(*args, **kw) File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 492, in __r_call self.__hd, self.__ma) File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 406, in __call raise p SOAPpy.Types.faultType: System.Data.SqlClient.SqlException: Procedure or function 'GetCurrencyByCountry' expects parameter '@name', which was not supplied. at WebServicex.country.GetCurrencyByCountry(String CountryName) --- End of inner exception stack trace ---: > It is as if it doesn't get the name "Zimbabwe". On Mon, 2009-11-02 at 12:58 +, Simon Brunning wrote: > 2009/11/2 Henrik Aagaard Sørensen : > > I have a problem with SOAPpy and WSDL. It is explained here: > > http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 > > Why not explain it here? > > In any case, I imagine the advice is going to be to try Suds - > <https://fedorahosted.org/suds/>. > -- http://mail.python.org/mailman/listinfo/python-list
Re: join a samba domain
Toff wrote: d = c.Win32_ComputerSystem d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom") Shouldn't r"admin\\mydom" be "admin\\mydom" or r"admin\mydom". Or maybe just "admin" /Jens Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: flock seems very unsafe, python fcntl bug?
Your problem is that open(...,'w') is not locked. Use something like: lockf = open('aaa', 'a') fnctl.flock(lockf,fnctl.LOCK_EX) file = open('aaa', 'w') file.write('asdf') file.close() lockf.close() [EMAIL PROTECTED] wrote: I ran following 2 programs (lock1, lock2) at almost same time, to write either "123456", or "222" to file "aaa" at the same time. But I often just got "222456" in "aaa" . Is this a bug of python fcntl module ? See 2 programs I ran: #!/usr/bin/env python import fcntl, time file = open('aaa', "w") fcntl.flock(file, fcntl.LOCK_EX) file.write('123456') time.sleep(10) file.close() #!/usr/bin/env python import fcntl, time file = open('aaa', "w") fcntl.flock(file, fcntl.LOCK_EX) file.write('222') time.sleep(10) file.close() -- http://mail.python.org/mailman/listinfo/python-list