Re: Slices time complexity
On May 18, 2015 9:26 PM, "Mario Figueiredo" wrote: > > I'd like to understand what I'm being told about slices in > https://wiki.python.org/moin/TimeComplexity > > Particularly, what's a 'del slice' and a 'set slice' and whether this > information pertains to both CPython 2.7 and 3.4. > > From the above link it seems slices work in linear time on all cases. > And this really has a big impact on certain operations. For instance, > the code below may surprise some people when they realize it doesn't > run in linear time on 3.4: > > def minimum(values): > if len(values) == 1: > return values[0] > else: > m = minimum(values[1:]) > return m if m < values[0] else values[0] > > Other languages implement slices. I'm currently being faced with a Go > snippet that mirrors the exact code above and it does run in linear > time. > > Is there any reason why Python 3.4 implementation of slices cannot be > a near constant operation? In this case you are copying the items (or rather pointers to the items) from the list to a new list. This is inherently a O(k) operation. There are other ways to implement it. I recall the was talk of a way to get views of sequences, although this would involve keeping the original list in memory and any changes to the new list would be passed to the original (this is how numpy works) . It is also possible to do copy-on-write, which avoids altering the original list but has the same memory problems while still involving a O(k) copy operation if you want to change the list, and it is more complex to implement (this is how MATLAB works) . But to have a new list that can be edited independently requires coping something, and that will be a O(k) operation, unless you use a radically different data structure with its own limitations. -- https://mail.python.org/mailman/listinfo/python-list
Re: Slices time complexity
On May 18, 2015 9:56 PM, "Fabien" wrote: > > On 05/18/2015 09:49 PM, Ian Kelly wrote: >> >> It may be possible that lists in CPython could be made to share their >> internal arrays with other lists on a copy-on-write basis, which could >> allow slicing to be O(1) as long as neither list is modified while the >> array is being shared. I expect this would be a substantial piece of >> work, and I don't know if it's something that anybody has looked into. > > > Isn't Numpy doing this (not sure, not a python nor a numpy expert): > > >>> import numpy as np > >>> a = np.array([1,2,3,4]) > >>> b = a[1:] > >>> b[0] = 9 > >>> a > array([1, 9, 3, 4]) > > > Fabien Numpy arrays use views. Matlab arrays use copy-on-write. But as discussed in the recent thread about string views, these approaches have a memory penalty since they require keeping the original array in memory. And the copy-on-write approach still has a O(k) complexity if you try to make any changes. -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
On Wed, May 27, 2015 at 2:40 PM, zipher wrote: > On Wednesday, May 27, 2015 at 6:30:16 AM UTC-5, Ben Finney wrote: > > Steven D'Aprano writes: > > > > > On Wednesday 27 May 2015 14:39, Ben Finney wrote: > > > > > > > That kind of homophobic slur is inappropriate from anyone in this > > > > community. Kindly cut it out altogether. > > > > > > I look forward to the day when people would read the earlier insult > > > and be perplexed as to why it is a slur at all. In the same way as > > > "your mother wears army boots" has become a joke slur, not taken > > > seriously. > > > > Yes, let's all work toward an end to the use of gender, sexuality, > > ethnicity, and other inborn traits as the punchline of insults or jokes. > > Oh God, you people are being idiots. It's poop. And shall we all so look > forward to the day, when people who eat poop are also welcome into the > circle of humanity? > > Everyday, you let atrocity happen, and you're fighting for oppressed > feltchers? > > If so, you dumbasses don't deserve much of a future. > If your goal is to get people to stop calling you a troll, you are going about it the wrong way. If it isn't, why are you even here? Please remember the first rule of holes: if you find yourself in a hole, stop digging. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question About Image Processing in Python
On Thu, May 28, 2015 at 1:05 PM, Terry Reedy wrote: > On 5/28/2015 6:34 AM, Serge Christian Ibala wrote: > > > I want to use the following package >> >> “numpy, matplotib, mahotas, ipython OpenCV and SciPy" >> > > opencv seems to be the only one not available for 3.x. > > OpenCV 3 (which is in RC1 now) supports Python 3.x. -- https://mail.python.org/mailman/listinfo/python-list
Re: What is considered an "advanced" topic in Python?
On Fri, May 29, 2015 at 7:02 PM, Todd wrote: > On Fri, May 29, 2015 at 6:01 PM, Mike Driscoll wrote: > >> Hi, >> >> I've been asked on several occasions to write about intermediate or >> advanced topics in Python and I was wondering what the community considers >> to be "intermediate" or "advanced". I realize we're all growing in our >> abilities with the language, so this is going to be very subjective, but I >> am still curious what my fellow Python developers think about this topic. >> >> Thanks, >> Mike >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > The ast module and AST hacking > The dist module and understanding the interpreter. > Code objects > Sorry, miss-typed. I meant the "dis" module, not the "dist" module. -- https://mail.python.org/mailman/listinfo/python-list
Re: What is considered an "advanced" topic in Python?
On Fri, May 29, 2015 at 6:01 PM, Mike Driscoll wrote: > Hi, > > I've been asked on several occasions to write about intermediate or > advanced topics in Python and I was wondering what the community considers > to be "intermediate" or "advanced". I realize we're all growing in our > abilities with the language, so this is going to be very subjective, but I > am still curious what my fellow Python developers think about this topic. > > Thanks, > Mike > -- > https://mail.python.org/mailman/listinfo/python-list > The ast module and AST hacking The dist module and understanding the interpreter. Code objects -- https://mail.python.org/mailman/listinfo/python-list
Re: for...else
I think there is essentially zero chance of that. My understanding is that Guido regrets having "else" to begin with. But this should work broken = True for x in it: if complicated_calculation_1(): break complicated_calculation_2() if complicated_calculation_3(): break else: broken = False if broken: cleanup() On Tue, Jun 2, 2015 at 1:26 PM, acdr wrote: > Hi, > > Currently, in various places in my code, I have the equivalent of: > > for x in it: > if complicated_calculation_1(): > cleanup() > break > complicated_calculation_2() > if complicated_calculation_3(): > cleanup() > break > > Obviously, I'm repeating myself by having two separate calls to > cleanup(). I can't really see a nicer way to do this. (Though I see > plenty of non-nice ways to do this, such as adding "broken = True" in > front of every "break", and then after the loop is done, have an "if > broken" section.) Other solutions that I'm not particularly fond of > can be found on stackexchange, where someone else is trying to do the > same thing: > http://stackoverflow.com/questions/3296044/opposite-of-python-for-else > > I'm wondering if there is a demand for expanding the "for...else" > functionality to be expanded also have a block of code that only gets > called if the loop is broken out of. I.e.: > > for x in it: > ... > then: > # "break" was called > ... > else: > # "break was not called > ... > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: So what's happening here?
On Fri, Jun 5, 2015 at 2:46 PM, Paul Appleby wrote: > I saw somewhere on the net that you can copy a list with slicing. So > what's happening when I try it with a numpy array? > > >>> a = numpy.array([1,2,3]) > >>> b = a[:] > >>> a is b > False > >>> b[1] = 9 > >>> a > array([1, 9, 3]) > > Numpy arrays are not lists, they are numpy arrays. They are two different data types with different behaviors. In lists, slicing is a copy. In numpy arrays, it is a view (a data structure representing some part of another data structure). You need to explicitly copy the numpy array using the "copy" method to get a copy rather than a view: >>> a = numpy.array([1,2,3]) >>> b = a.copy() >>> a is b False >>> b[1] = 9 >>> a array([1, 2, 3]) Here is how it works with lists: >>> a = [1,2,3] >>> b = a[:] >>> a is b False >>> b[1] = 9 >>> a [1, 2, 3] -- https://mail.python.org/mailman/listinfo/python-list
Re: So what's happening here?
On Fri, Jun 5, 2015 at 3:11 PM, Paul Appleby wrote: > On Fri, 05 Jun 2015 14:55:11 +0200, Todd wrote: > > > Numpy arrays are not lists, they are numpy arrays. They are two > > different data types with different behaviors. In lists, slicing is a > > copy. In numpy arrays, it is a view (a data structure representing some > > part of another data structure). You need to explicitly copy the numpy > > array using the "copy" method to get a copy rather than a view: > > OK, thanks. I see. > > (I'd have thought that id(a[1]) and id(b[1]) would be the same if they > were the same element via different "views", but the id's seem to change > according to rules that I can't fathom.) > > a[1] and b[1] are NOT views. Slices are views, single elements are not. They are numpy scalars, which are immutable, so returning a view wouldn't make sense in such a case since you can't modify it anyway. Taking a slice creates a new view. It is looking at the same underlying data, but it is a new object. So "a[1:] is b[1:]" is False, as is "a[:] is b". -- https://mail.python.org/mailman/listinfo/python-list
Re: So what's happening here?
On Fri, Jun 5, 2015 at 3:23 PM, Gary Herron wrote: > On 06/05/2015 06:11 AM, Paul Appleby wrote: > >> On Fri, 05 Jun 2015 14:55:11 +0200, Todd wrote: >> >> Numpy arrays are not lists, they are numpy arrays. They are two >>> different data types with different behaviors. In lists, slicing is a >>> copy. In numpy arrays, it is a view (a data structure representing some >>> part of another data structure). You need to explicitly copy the numpy >>> array using the "copy" method to get a copy rather than a view: >>> >> OK, thanks. I see. >> >> (I'd have thought that id(a[1]) and id(b[1]) would be the same if they >> were the same element via different "views", but the id's seem to change >> according to rules that I can't fathom.) >> > Nope. It's odder than that. a[1] is still a view into the inderlying > numpy array, and your id is the id of that view. Each such index produces a > new such view object. Check this out: > > >>> import numpy > >>> a = numpy.array([1,2,3]) > >>> id(a[1]) > 28392768 > >>> id(a[1]) > 28409872 > > This produces two different view of the same underlying object. > a[1] and b[1] are not views: >>> a[1].flags['OWNDATA'] True >>> b[1].flags['OWNDATA'] True >>> a[1:2].flags['OWNDATA'] False -- https://mail.python.org/mailman/listinfo/python-list
Re: Classic OOP in Python
On Thu, Jun 18, 2015 at 1:03 PM, Fabien wrote: > On 06/17/2015 11:16 PM, sohcahto...@gmail.com wrote: > >> You don't need interfaces with Python. Duck typing makes that all >> possible. >> > > Yes, but I also like interfaces (or in python: mimicked interfaces with > NotImplementedError) for their clarity and documentation purposes. > > Would you consider the following kind of program "unpythonic"? > > class MovingObject(object): > """Great doc about what a moving object is""" > > def move(self): > """Great doc about move""" > raise NotImplementedError() > > class Dog(MovingObject): > def move(self): > print "Dog is moving" > > class Car(MovingObject): > def move(self): > print "Car is moving" > > (Disclaimer: I learned OOP with Java) > > I think this is what abstract base classes are for in Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: thinking with laziness
On Thu, Jun 18, 2015 at 6:15 PM, Mark Lawrence wrote: > On 18/06/2015 14:53, Steven D'Aprano wrote: > >> On Thu, 18 Jun 2015 11:10 pm, Neal Becker wrote: >> >> http://begriffs.com/posts/2015-06-17-thinking-with-laziness.html >>> >> >> I wanted to think about that post, but I'm too lazy to read it. >> >> >> My-apologies-I-couldn't-resist-it-ly y'rs, >> >> > Reminds me of last night's AGM of the Apathy Society, which was an > outstanding success as nobody turned up. > I thought about it, but couldn't be bothered to find the address. -- https://mail.python.org/mailman/listinfo/python-list
Re: Bug in floating point multiplication
The loop runs to completion for me on openSUSE Tumbleweed and both Python 2.7 64bits and Python 3.4 64bits. On Thu, Jul 2, 2015 at 4:52 PM, Steven D'Aprano wrote: > Despite the title, this is not one of the usual "Why can't Python do > maths?" "bug" reports. > > Can anyone reproduce this behaviour? If so, please reply with the version > of > Python and your operating system. Printing sys.version will probably do. > > > x = 1 - 1/2**53 > assert x == 0. > for i in range(1, 100): > if int(i*x) == i: > print(i); break > > > Using Jython and IronPython, the loop runs to completion. That is the > correct behaviour, or so I am lead to believe. Using Python 2.6, 2.7 and > 3.3 on Centos and Debian, it prints 2049 and breaks. That should not > happen. If you can reproduce that (for any value of i, not necessarily > 2049), please reply. > > See also http://bugs.python.org/issue24546 for more details. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Bug in floating point multiplication
On Thu, Jul 2, 2015 at 5:29 PM, Robin Becker wrote: > > > $ uname -a > Linux everest 4.0.6-1-ARCH #1 SMP PREEMPT Tue Jun 23 14:40:31 CEST 2015 > i686 GNU/Linux > I am wondering if this is a 32bit vs. 64bit thing. Has anyone gotten this problem to work on a 64bit python? -- https://mail.python.org/mailman/listinfo/python-list
Re: str.index() and str.find() versus only list.index()
On Tue, Jul 14, 2015 at 7:13 AM, Chris Angelico wrote: > On Tue, Jul 14, 2015 at 2:58 PM, Steven D'Aprano > wrote: > > On Tuesday 14 July 2015 14:07, Ian Kelly wrote: > > > >> On Mon, Jul 13, 2015 at 9:23 PM, Steven D'Aprano > >> wrote: > >>> Correct. But rather than removing it, it would be better to take a leaf > >>> out of re.match's book and return None as the sentinel. That would > >>> eliminate the "using -1 as a valid index" bug. > >> > >> Better IMO to just have the one non-redundant method that raises an > >> exception rather than returning anything that could possibly be > >> interpreted as a string index. > > > > > > Well, maybe, but if you got rid of str.find, the first thing people > would do > > is recreate it: > > > > def find(*args): > > try: > > return str.index(*args) > > except ValueError: > > return -1 > > > > > > Having a version of str.index that returns a sentinel is just too damn > > handy. > > Same as dictionaries have [] and .get(), although find doesn't allow > you to change the sentinel. > > Maybe that is the solution? Add a keyword-only argument to find to change the sentinel? -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to install ALL Python packages?
On Tue, Jul 21, 2015 at 2:10 PM, tjohnson wrote: > On 7/20/2015 10:57 PM, ryguy7272 wrote: > >> I'd like to install ALL Python packages on my machine. Even if it takes >> up 4-5GB, or more, I'd like to get everything, and then use it when I need >> it. Now, I'd like to import packages, like numpy and pandas, but nothing >> will install. I figure, if I can just install everything, I can simply use >> it when I need it, and if I don't need it, then I just won't use it. >> >> I know R offers this as an option. I figure Python must allow it too. >> >> Any idea how to grab everything? >> >> Thanks all. >> >> As others have stated, this is not practical with Python. If you were to > install every single package from PyPI, you'd end up with packages like > funny 0.1 or Barun_Heehaw, which is described as "A sample junk project." > (No, I'm not joking.) > The latter being, literally, a "Hello world" project and nothing else. -- https://mail.python.org/mailman/listinfo/python-list
Re: Which GUI?
On Sun, Jul 26, 2015 at 7:19 PM, Paulo da Silva < p_s_d_a_s_i_l_v_a...@netcabo.pt> wrote: > On 26-07-2015 05:47, blue wrote: > > Hi . > > I tested all. Now I think the PySide can more. > > No python3! > Besides ... any differences to pyqt4? > Thanks > pyside has supported python 3 for a long time now. As for differences, the main difference is the license. -- https://mail.python.org/mailman/listinfo/python-list
Re: Run Python Script; Nothing Happens
On Wed, Jul 29, 2015 at 3:19 PM, ryguy7272 wrote: > I am using Spyder Python 2.7. I'm running this sample code. > import numpy as np > import numpy.random as npr > import matplotlib.pyplot as plt > S0 = 100 > r = 0.05 > sigma = 0.25 > T = 30 / 365. > I = 1 > ST = S0 * np.exp((r - 0.5 * sigma ** 2) * T + sigma * np.sqrt(T) * > npr.standard_normal(I)) > R_gbm = np.sort(ST - S0) > plt.hist(R_gbm, bins=50) > plt.xlabel('absolute return') > plt.ylabel('frequency') > plt.grid(True) > > I found it in a book, and I'm trying to run various samples of code, in an > effort to learn Python. So, I click the debug button, and this is what I > get. > > c:\users\rshuell001\untitled12.py(1)() > -> import numpy as np > (Pdb) > > It seems like it doesn't really do anything. So, I click the exit debug > button and then click the run button and nothing happens. I get nothing at > all. In the book, the author got a graph. I get nothing. I think, and I > could be totally wrong, Python is sending something to a Console, but I > can't tell where it goes. I opened every Console I could find, and I still > see nothing happening whatsoever. > > Any idea what's wrong here? > > First, you need to call plt.show() at the end in order to see anything. Second, when you run the debugger it immediately waits for you to tell it what to do. So you need to tell it continue running. But normally you wouldn't run it in the debugger. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 May Become Relevant Now
On Aug 3, 2015 17:46, "Rick Johnson" wrote: > > On Sunday, August 2, 2015 at 9:45:51 PM UTC-5, Chris Angelico wrote: > > How do you know it was written today, if you didn't click it? > > Because i possess skills you can hardly fathom. There are always > loopholes; back doors; knot holes; key holes; cracks; crevices; > tells; Freudian slips; little white lies; and yes, even arthropods > creeping and crawling in dark corners fitted with multiple visual > sensors -- all one need do is discover them, and then *EXPLOIT* them! > -- That sounds like a lot more work than simply clicking a link. -- https://mail.python.org/mailman/listinfo/python-list
Re: python-matplotlib changes very often?
On Aug 8, 2015 10:46, "Cecil Westerhof" wrote: > > On openSUSE I see python-matplotlib updated very often. Sometimes more > as once a week. It is also not very small (almost 40 MB). Is there a > reason for this, or is there a problem at SUSE? I assume you are using tumbleweed and/or devel:languages:python? matplotlib has quite a few dependencies, and many of those have dependencies of their own. Whenever a dependency of a package is updated the open build service openSUSE uses for packaging the package is also updated. So it isn't really matplotlib getting updates, but rather the packages it depends on (or packages they depend on, and so on). And none of those are updated very often, there are just a lot if them. -- https://mail.python.org/mailman/listinfo/python-list
Re: Idiosyncratic python
Using list indexing with booleans in place of a ternary operator. a = False b = [var2, var1][a] Instead of: b = var1 if a else var2 On Sep 24, 2015 8:06 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > I was looking at an in-house code base today, and the author seems to have > a > rather idiosyncratic approach to Python. For example: > > > for k, v in mydict.items(): > del(k) > ... > > > instead of the more obvious > > for v in mydict.values(): > ... > > > > What are your favorite not-wrong-just-weird Python moments? > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Idiosyncratic python
On Sep 24, 2015 18:59, "Chris Angelico" wrote: > > On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > > Using list indexing with booleans in place of a ternary operator. > > > > a = False > > b = [var2, var1][a] > > > > Instead of: > > > > b = var1 if a else var2 > > Be careful - these are not semantically identical. The first one > evaluates both var1 and var2, while the second will evaluate only the > one it needs. This might be significant if they're not simple names. True, but the code I saw doing this was just choosing between simple float literals. -- https://mail.python.org/mailman/listinfo/python-list
Re: Strong typing implementation for Python
On Oct 13, 2015 2:11 AM, "Steven D'Aprano" wrote: > > On Tue, 13 Oct 2015 04:20 am, Marko Rauhamaa wrote: > > > As for managing complexity, many people believe static typing is a > > crucial tool. I disagree. Static typing adds vast amounts of noise to > > the code. > > Only if you are stuck in the 1970s. And even then, it is not always noise, > type declarations or annotations often make useful documentation. > > Consider the following piece of code: > > def addone(x): > return x + 1 > > > The human programmer reading that can trivially infer that x must be a > number (or at least something which supports numeric addition). So can the > compiler. In a strongly typed language with no numeric promotion, the > compiler can infer that x must be an int. In a language with numeric > promotion, it can infer that x must be an int or float. Or a decimal, complex number, numpy array, any one of a dozen or so pandas classes, any one of the dozen or so units classes, sympy variable, etc... -- https://mail.python.org/mailman/listinfo/python-list
Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)
On Nov 19, 2015 20:48, "Chris Angelico" wrote: > > On Fri, Nov 20, 2015 at 5:42 AM, Ian Kelly wrote: > > BartC on the other hand is just complaining about an aspect of Python > > that is legitimately controversial. > > IMO it's controversial mainly because there's an easy and obvious > syntax for early binding, but late binding doesn't have syntactic > support, and all the options are imperfect. Consider: > > def late1(x=None): > """Terse but buggy""" > do_stuff_with(x or []) > > def late2(x=None): > """Not bad but has an extra line for each default. Also, can't take None.""" > if x is None: x = [] > do_stuff_with(x) > > _SENTINEL = object() > def late3(x=_SENTINEL): > """Has the same global-pollution problem you get when you > try to construct early binding from late; you can share the > sentinel among multiple args, even multiple funcs, though""" > if x is _SENTINEL: x = [] > do_stuff_with(x) > > def late4(x=object()): > """Depends on its own name remaining bound in its scope, > and will break if you change argument order""" > if x is late4.__defaults__[0]: x = [] > do_stuff_with(x) > > And there might be other techniques, too. They all share one important > flaw, too: When you ask for help about the function, you can't see > what the default really is. All you see is: > > late1(x=None) > late3(x=) > > In the first two cases, it's not too bad; you can specify a timeout as > either a number or as None, and if it's None (the default), the > timeout is three times the currently estimated round trip time. No > problem. But how would you implement something like next() in pure > Python? If you provide _any second argument at all_, it returns that > instead of raising StopIteration. The ONLY way that I can think of is > to use *args notation: > > def next(iterator, *default): > try: > return iterator.__next__() > except StopIteration: > if default: return default[0] > raise > > And while that isn't TOO bad for just one argument, it scales poorly: > > def foo(fixed_arg, *args): > """Foo the fixed_arg against the spam mapping, the > ham sequence, and the jam file.""" > args.reverse() > spam = args.pop() if args else {} > ham = args.pop() if args else [] > jam = args.pop() if args else open("jam.txt") > > Suppose, instead, that Python had a syntax like this: > > def foo(fixed_arg, spam=>{}, ham=>[], jam=>open("jam.txt")): > """Foo the fixed_arg against the spam mapping, the > ham sequence, and the jam file.""" > > The expressions would be evaluated as closures, using the same scope > that the function's own definition used. (This won't keep things alive > unnecessarily, as the function's body will be nested within that same > scope anyway.) Bikeshed the syntax all you like, but this would be > something to point people to: "here's how to get late-binding > semantics". For the purposes of documentation, the exact text of the > parameter definition could be retained, and like docstrings, they > could be discarded in -OO mode. > > Would this satisfy the people who get confused about "=[]"? > > ChrisA Rather than a dedicated syntax, might this be something that could be handled by a built-in decorator? Maybe something like: @late_binding def myfunc(x, y=[]): @late_binding('z') def myfunc(x, y=expensive(), z=[]): M = 5 @late_binding('z', vars_early=True) def myfunc(x, y=expensive(), z=list(range(n))): The big advantage, as shown in the last example, is that it could be possible to specify early our late binding for variables as well. -- https://mail.python.org/mailman/listinfo/python-list
call static function from extension module - syntaxerror
Hi, I'm working right from the example here to make a basic extenstion module. http://docs.python.org/ext/intro.html http://www.dalkescientific.com/writings/diary/archive/2005/04/26/extending_python.html I can load my module into python and dir shows my function. But I get a syntax error if I try to access it. >>> ast_man.exec File "", line 1 ast_man.exec ^ SyntaxError: invalid syntax However, I can get at it using getattr. I tried compiling myself and using setup. My method is defined as static PyMethodDef ast_man_methods[] = { {"exec",exec,METH_VARARGS,"Execute Asterisk commands."}, {NULL,NULL,0,NULL} }; What might be my problem?? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't this work--Extending Python--?
jeremito wrote: > I have written a simple C++ program in my efforts to learn how to > extend Python. It is shown below. Everything compiles and installs > correctly, but I get strange answers. I know the function "Pi" is > correct because when I call it from a C++ code it gives the correct > answers. This is what I get when I run it in Python: > 27 int Particles; > 28 int Pie; > 29 if (!PyArg_ParseTuple(args, "i", &Particles)) > > 30 return NULL; > > 31 Pie = Pi(Particles); > > 32 return Py_BuildValue("d", Pie); Just scanning over this, looks like what you want is double Pie. You have int. The compiler probably gave a warning. http://www.signalsguru.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Quickest way to make py script Web accessible
[EMAIL PROTECTED] wrote: > What is the quickiest and easiest way to make a py script run on a Web > server? I have access to an Apache Web server running on Linux. > > I'm often asked to run some of my scripts on behalf of others. My hope > is to make a simple Web-based interface where people could run the > scripts themselves whenever they like... instead of asking me. > > I'd rather not rewrite the scripts with PHP. Any tips on a fast, easy > way of doing this? > > Thanks! I haven't tried it myself, but have you looked into http://www.modpython.org/? -- -Todd http://www.signalsguru.net -- http://mail.python.org/mailman/listinfo/python-list
python mysteriously halts
Hello everyone, I ran a python script last night which connects to a matlab automation server via DCOM (using win32com). I expected to see the results when I came in this morning. But apparently, not long after I left, python stopped. I hit enter in the console, and it started again. I scoured the handful of lines of code to see if there was any kind of input statement put there by accident but couldn't find one. Furthermore, I've run this code many times without it pausing. It's still possible I've done something boneheaded, but I'm wondering if there is another reason (e.g. a pause in the win32com module, some kind of timeout feature if the system is idle, etc.). thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: python mysteriously halts
On Jul 7, 10:17 am, Tim Golden <[EMAIL PROTECTED]> wrote: > Todd wrote: > > I ran a python script last night which connects to a matlab automation > > server via DCOM (using win32com). I expected to see the results when > > I came in this morning. But apparently, not long after I left, python > > stopped. I hit enter in the console, and it started again. > > Symptomatically, at least, this can be caused by someone starting to > select (with the mouse) an area of the screen: the process will pause > until is pressed, which copies the area to the clipboard. This > only happens with a console window, but it sounds like that's what > you had running. > > TJG That might be it, although I don't recall doing that. Fortunately/ unfortunately, it happened a few times, but it seems to have stopped now. -- http://mail.python.org/mailman/listinfo/python-list
Re: efficiency of range() and xrange() in for loops
Steve R. Hastings wrote: > When you compile the expression > > for i in range(1000): > pass > > does Python make an iterator for range(), and then generate the values > on the fly? Or does Python actually allocate the list [0, 1, 2, ..., 999] > and then step through it? I ran an experiment on this a while back. I thought it generated a list. But the results turned out to be surprising. Take this with a grain of salt. I'm not completely sure I did what I meant to do. But it looks like however you do it, it works out about the same. http://www.signalsguru.net/articles/pyloops/pyloops.html -- http://mail.python.org/mailman/listinfo/python-list
confusing behaviour of os.system
I'm trying to run the following in python. os.system('/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file \"test.c\")"') This connects to xemacs with gnuclient and runs htmlize. If I run it from a shell, xemacs gives me an error, but it generates the html file just fine. If I run the same statement in python, I get the exact same behaviour, but there's no file. I'm not sure what the issue is. I thought maybe it's putting it in another directory or there might be some permissions problem. Any ideas? If you want to try it, just make sure to run "M-x gnuserve-start" first. -- http://mail.python.org/mailman/listinfo/python-list
Re: confusing behaviour of os.system
Ben Cartwright wrote: > Todd wrote: > > I'm trying to run the following in python. > > > > os.system('/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file > > \"test.c\")"') > > Python is interpreting the \"s as "s before it's being passed to > os.system. Try doubling the backslashes. > > >>> print '/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> > >>> \"test.c\")"' > /usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> "test.c")" > >>> print '/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> > >>> \\"test.c\\")"' > /usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \"test.c\")" > > --Ben Thanks! Yay multiple layers of string interpretation. -- http://mail.python.org/mailman/listinfo/python-list
Search and replace text in XML file?
I'm looking to search an entire XML file for specific text and replace that text, while maintaining the structure of the XML file. The text occurs within multiple nodes throughout the file. I basically need to replace every occurrence C:\Program Files with C:\Program Files (x86), regardless of location. For example, that text appears within: C:\Program Files\\Map Data\Road_Centerlines.shp and also within: C:\Program Files\Templates\RoadNetwork.rtx ...among others. I've tried some non-python methods and they all ruined the XML structure. I've been Google searching all day and can only seem to find solutions that look for a specific node and replace the whole string between the tags. I've been looking at using minidom to achieve this but I just can't seem to figure out the right method. My end goal, once I have working code, is to compile an exe that can work on machines without python, allowing a user can click in order to perform the XML modification. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Komodo 7 release (Python development tools)
Hello, My name is Todd. I'm the lead developer for Komodo IDE (Interactive Development Environment) and Komodo Edit (a free, open-source editor) at ActiveState. I wanted to announce that the newest version, Komodo 7, has been released: http://www.activestate.com/komodo-ide Python has long been one of the main languages supported by Komodo, so we're always getting useful feedback and suggestions. For Komodo 7, we've incorporated a lot of this feedback into enhancing our Python features. * Python Code Profiling (IDE only) Users have asked if there is a way to find out why their programs are taking so long to run. Komodo IDE 7 can show a graph of the methods and calls made by your program, so that you can detect where your CPU is being taken up. * Sophisticated Syntax Checking Choose between multiple syntax checkers like PyLint, PyFlakes and PyChecker. Provides language-specific syntax checking for CSS/JavaScript/Django inside HTML template languages like Django. * Code Collaboration (IDE only) We wanted to make pair programming easier. With the collaboration feature, multiple users can edit a document at the same time. It's kind of like Google Docs, but for code editing! * Speed With Komodo 7 you'll notice a lot snappier Komodo start-up time, lower CPU utilization - particularly when idle, and lower memory usage for large projects. * Even more... There are way more features in Komodo 7 than I can outline in a single post, so check out the online web pages for more Komodo 7 enhancements: http://www.activestate.com/komodo-ide/python-editor Again, note that Komodo comes in two different flavours: 1) Komodo Edit - completely free and fully open-source editor, offering smart code completions, syntax checking, code colorizing, sophisticated editing and more. 2) Komodo IDE - a full featured IDE, offering advanced debugging, interactive shells, code browsing, source code control, database integration, unit testing, regular expression tools and more. Try out Komodo 7 and let me know what you think. We really appreciate the support and feedback! Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Komodo 7 release (Python development tools)
On 12-02-08 01:52 PM, Terry Reedy wrote: On 2/8/2012 3:14 PM, Todd Whiteman wrote: My name is Todd. I'm the lead developer for Komodo IDE (Interactive Development Environment) and Komodo Edit (a free, open-source editor) at ActiveState. I wanted to announce that the newest version, Komodo 7, has been released: http://www.activestate.com/komodo-ide/python-editor It would seem that the Professional Python Editor is the same as Komodo Edit, but it is unclear why only Python editing would be featured for Komodo IDE. http://www.activestate.com/komodo-edit is the page with the link people need to download just the editor. The above page covers features from both Edit and IDE - some will only apply to the IDE version. For a full comparison of features you can check out: http://www.activestate.com/komodo-edit/compare-with-komodo-ide Does K.Edit let me run a program with one key, like F5 in IDLE? If so, does it leave me in interactive mode (python -i) as IDLE does? Komodo Edit does not offer a quick run (F5) command by default, you could create your own Python command [1] in the Komodo toolbox and assign it the F5 key binding to serve such a purpose. [1] The short command for running a Python script is: "%(python) %F", which uses Komodo's interpolation shortcuts: http://docs.activestate.com/komodo/7.0/shortcuts.html#shortcuts_top Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
RPM Modules
Is there any documentation that shows how to use the RPM API for Python. I have found one example but it's dated 2000 and I haven't been able to get it to work :(. Thanks ~Todd -- http://mail.python.org/mailman/listinfo/python-list
working with VERY large 'float' and 'complex' types
Greetings Python'ers: I'm just an amature who occasionally uses Python for complex mathematical models. The current model I'm working with occasionally generates really large numbers that are either "float" or "complex" types. These numbers are so large that I either get an overflow error, or some funky code like #INF or 1.#INDj. However I really need these numbers to be calculated (although precision isn't key). Is there a way to get python to increase the size limit of float and complex numbers? I should mention that I'm using a lot of pre-made modules and functions like math.exp() and scipy.special.erf() that don't seem to be able to use available types like "Decimal" or "FixedPoint" (especially since these don't seem to handle complex numbers). Since I learn best by example, how could one solve the following problem: from math import exp >>>x=1000. >>>z=exp(x) so that z returns an actual value Thanks in advance for any advice! Todd -- http://mail.python.org/mailman/listinfo/python-list
Can't run BLT program more than once?
I'm running activestate Python 2.4 for windows, and the latest BLT, under XP. I'm using pythonWin as my environment. When I run my plotting program the first time, it works just fine. If I exit out (normally), and then run it again from PythonWin, I get the following error. It's as if something isn't getting properly re-initialized. If I quit out of PythonWin, and relaunch it, I can run the program again, once. Any ideas? Error: 1 TclError Exception in Tk callback Function: > (type: ) Args: () Traceback (innermost last): File "C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBase.py", line 1747, in __call__ None File "C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py", line 89, in doOpenTrace self.doPlotTrace() # go plot the thing File "C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py", line 117, in doPlotTrace self.graph = Pmw.Blt.Graph(tkRoot) # make a new graph area File "C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBlt.py", line 260, in __init__ None File "C:\Python24\lib\lib-tk\Tkinter.py", line 1861, in __init__ self.tk.call( TclError: invalid command name "::blt::graph" -- http://mail.python.org/mailman/listinfo/python-list
Can'r run BLT twice?
I'm running PythonWin on XP. When I run my plotter program the first time, it works fine. The second time I run it, I get the following error. If I exit PythonWin, and restart, I can again run it once. Any ideas? Error: 1 TclError Exception in Tk callback Function: > (type: ) Args: () Traceback (innermost last): File "C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBase.py", line 1747, in __call__ None File "C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py", line 89, in doOpenTrace self.doPlotTrace() # go plot the thing File "C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py", line 117, in doPlotTrace self.graph = Pmw.Blt.Graph(tkRoot) # make a new graph area File "C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBlt.py", line 260, in __init__ None File "C:\Python24\lib\lib-tk\Tkinter.py", line 1861, in __init__ self.tk.call( TclError: invalid command name "::blt::graph" -- http://mail.python.org/mailman/listinfo/python-list
Re: class attribute
On 28/01/16 13:15, ast wrote: hello Here is a class from django framework from django.db import models class Article(models.Model): titre = models.CharField(max_length=100) auteur = models.CharField(max_length=42) contenu = models.TextField(null=True) date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Date de parution") def __str__(self): return self.titre From a Python point of view, what are titre, auteur, contenu and date ? Are they class attributes, so common to all instance of Article ? It seems so to me. But if i do in a django shell (run with py manage.py shell) Article.titre it doesnt work, AttributeError: type object 'Article' has no attribute 'titre' why ? if I test on a small class class MyClass: i=0 MyClass.i 0 works When we create an object of class Article article = Article(titre="Bonjour", auteur="Maxime") article.contenu = "Les crêpes bretonnes sont trop bonnes !" we use the same names titre, auteur, contenu, which should be instance attribute this time. This is confusing to me thx Django Model classes are very different from a basic Python classes. It is worth having a look inside django/db/models/base.py for more information. But in summary, see below. The Model class has a metaclass of ModelBase which on __new__() returns a class constructed from the attributes which you have defined in your Model class (Article in this example). All the information is retained, it is just filed away neatly for other purposes. Have a look in the Article._meta attribute. You can find the fields you provided through Article._meta.fields. When you create Article (as above) you run the __init__() which reaches into the ._meta attribute of the class in order to create an object, which is then stored within the 'database'. This is done because you don't want to access the attributes on the Model, so they are removed when the Model is created. What you actually want to do is access them on the objects within the Model. Writing Article.objects.first().titre in Django Models is mostly equivalent to Article.titre from Python classes. Todd -- https://mail.python.org/mailman/listinfo/python-list
Re: Jython from bathc file?
On 5/8/2015 7:36 PM, vjp2...@at.biostrategist.dot.dot.com wrote: How do I do this in a .bat file? Do I include the Jython or pipe it? % CLASSPATH=$CLASSPATH:$RDBASE/Code/JavaWrappers/gmwrapper/org.RDKit.jar; jython -Djava.library.path=$RDBASE/Code/JavaWrappers/gmwrapper Jython 2.2.1 on java1.6.0_20 Type "copyright", "credits" or "license" for more information. from org.RDKit import * from java import lang lang.System.loadLibrary('GraphMolWrap') m = RWMol.MolFromSmiles('c1c1') m.getNumAtoms() This does not do that but for those who don't know Jython it can help. @echo off set "x=thequickbrownfoxjumpsoverthelazydog" set "x1=%x:~11,1%%x:~1,1%%x:~29,1%%x:~0,1%" set "x2= %x:~32,2%%x:~2,1%%x:~20,1%" set "x3= %x:~5,1%%x:~0,1% %x:~32,2%" echo %x1%%x2%%x3%? pause>nul -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) -- https://mail.python.org/mailman/listinfo/python-list
Re: SMPP implementation in python
SMPP, are you referring to the Short Message Peer to Peer protocol? If so, I implemented this in python some 4 years ago for SMPP v3.4, I have the source code, which I might release LGPL if interested. Cheers, Todd Alvin A. Delagon wrote: > Greetings! > > Does anyone know a good reference on how to implement SMPP in python. I > can't find any besides NET::SMPP in perl and I don't want to get my > hands for that. Thanks in advance! > -- http://mail.python.org/mailman/listinfo/python-list
Re: a more precise re for email addys
OMG, that is so ugly :D Jim wrote: > There is a precise one in a Perl module, I believe. > http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html > Can you swipe that? > > Jim > > -- http://mail.python.org/mailman/listinfo/python-list
Re: wing ide vs. komodo (python IDE comparison)?
Check the following links, somebody has already done the hard work for you :) http://wiki.python.org/moin/IntegratedDevelopmentEnvironments http://spyced.blogspot.com/2006/02/pycon-python-ide-review.html http://spyced.blogspot.com/2005/09/review-of-6-python-ides.html http://www.straw-dogs.co.uk/blog/python-ide-review Cheers, Todd John Salerno wrote: > Just curious what users of the two big commercial IDEs think of them > compared to one another (if you've used both). > > Wing IDE looks a lot nicer and fuller featured in the screenshots, but a > glance at the feature list shows that the "personal" version doesn't > even support code folding! That's a little ridiculous and makes me have > doubts about it. > > Komodo, on the other hand, seems to have more of the features that the > personal version of Wing IDE lacks (call tips, class browser, etc.) but > the look of it seems very sparse for some reason. > -- http://mail.python.org/mailman/listinfo/python-list
Re: Komodo
SpreadTooThin wrote: > Why is it that (On MAC OS X) in Komodo 3.5 Professional, if I try to > find something in my script, > I am unable to change the text it is searching for? > > I am not sure, especially given the limited amount of context, you will likely get a better response by posting a message at: http://support.activestate.com/products/Komodo And giving more details on your exact problem also helps (Mac type: PPC, Intel, Script type, etc...). Best regards, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some help here
"Kareem840" <[EMAIL PROTECTED]> writes: > Hello. Unfortunately, I am in need of money to pay my credit card > bills. If you could spare just $1, I would be grateful. I have a Paypal > account. [EMAIL PROTECTED] I swear this will go to my card > balances. Thank you. If you have a story of unusual personal hardship that led to the balances, share it--you may get more response. If you're just a usual idiot without the discipline to live within their their means, get a job, or if you have one, get a better one and dig yourself out of the whole you've created for yourself. Otherwise, we'd all just be enabling you to be an idiot again, we'd all be a dollar poorer, and you'd be no wiser--just with a better credit score for a time. If you're just seeing how many folks will give you money without any good reason (i.e. not a scam, just an internet beggar), hey, enjoy. If you're a clever sociology graduate student doing a pootentially interesting thesis on various responses to an anonymous plea for money on the internet, kudos. I bet it'd be an interesting study. Best Regards, -- Todd H. http://www.toddh.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb, lots of columns and newb-ness
Andrew Sackville-West wrote: > > I can successfully connect to mysql and do stuff to my tables my > specific problem is how to efficiently put those 132 fields into the > thing. All I have been able to figure out is really ugly stuff like: > build the mysql statement out of various pieces with appropriate > commas and quote included. stuff like (not tested) > I just started looking into Python myself, so someone can probably clean this up or suggest a better way, but this may work: import MySQLdb fields = ["field1\r\n","field2\r\n","field3\r\n"] def escapeAndQuote(x): return "\"%s\"" % MySQLdb.escape_string(x) values = ", ".join([escapeAndQuote(f[:-2]) for f in fields]) q = "insert into daily values(%s)" % values In testing I got: >>> fields = ["field1\r\n","field2\r\n","field3\r\n"] >>> values = ", ".join([escapeAndQuote(f[:-2]) for f in fields]) >>> values '"field1", "field2", "field3"' >>> q = "insert into daily values(%s)" % values 'insert into daily values("field1", "field2", "field3")' Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: list1.append(list2) returns None
Pyenos wrote: > def enlargetable(table,col): > return table.append(col) > > def removecolfromtable(table,col): > return table.remove(col) > > print enlargetable([[1],[2],[3]],[4]) # returns None > > Why does it return None instead of [[1],[2],[3],[4]] which I expected? append modifies the list and then returns None: >>> print a [1, 2, 3] >>> print a.append(4) None >>> print a [1, 2, 3, 4] The reasoning given at http://www.python.org/doc/faq/general.html#why-doesn-t-list-sort-return-the-sorted-list is so you wont do something like this: a = [1,2,3] b = a.append(4) and assume that a is still [1,2,3] More discussion on this topic is available at http://groups.google.com/group/comp.lang.python/browse_thread/thread/8ab2e67550123b92 Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: %SystemDrive%
Another hack: drive = os.popen("echo %SYSTEMDRIVE%").readline().strip() rtilley wrote: > Is there a proper way to get this variable from Windows? I know it's in > the registry, but I'd rather not go there. I could not find a CSIDL > shell constant for it either. I've been doing this: > > os.chdir('/') > sys_drive = os.getcwd() > print sys_drive > C:\ > > This seems too much of a hack and maybe not 100% right all of the time. > How could it be done better? > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in the Mozilla world
Eric S. Johansson wrote: > this morning I was looking at Python and XUL. I was impressed by the very > interesting projects that were happening around 2005 but it seems like they > have > all died. Integrating Python at the Mozilla was also very intriguing as it > held > the promise of eliminating JavaScript for extension development (yaaa). But > that seems to have died as well. In fact, it looks like that almost all of > the > alternative languages for browsers have died for lack of interest or > something. > I was really looking forward to pyax Not quite true. Mark Hammond has been working on integrating Python into Mozilla to work as a JavaScript near equivalent for use with XUL. This is currently integrated into the mozilla trunk and expected to be ready/included for Firefox 3. I have seen this in action, so it is not just hype. Check PyDom info for a brief overview: http://developer.mozilla.org/en/docs/PyDOM There are also a few projects that make use of PyXPCOM in the current mozilla/firefox/xulrunner builds, such as Democracy and Komodo. Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Building a Python app with Mozilla
Thorsten Kampe wrote: > Hi, > > I've already sent this to the Komodo mailing list (which seemed to me > the more appropriate place) but unfortunately I got no response. Hi Thorsten, I'm sorry that we (Komodo team) missed it, but I did not see such a message on the Komodo mailing list. > > I'd like to build a Python GUI app. Neither Tkinter nor Wxpython nor > PyQT are actually what I want (because the lack of GUI builders and > they don't really look good on Windows and Linux). > > Komodo itself is an excellent example of a - at least Python driven - > application that looks superb and has superior functionality so it > seems natural to use the Komodo approach for me. > > Some questions > > * Is there a simple How-To how to build a very simple (Python) app > with the Mozilla framework? Kind of "Hello world"...? > Just to detail how Komodo works, as there seems to be some confusion on this: * Komodo is based on top of Mozilla (like Firefox, Thunderbird, Democracy, etc... ) * Komodo includes PyXPCOM (XPCOM bindings to the Python language), which enables JavaScript and C++ components to easily interact with python objects inside an embedded Python. * The Komodo UI is written using XUL/JavaScript and most of the backend services are written using Python code. To enable the use of Python from within the Mozilla framework you'll need to build mozilla with the python xpcom extension enabled. For a simple overview of building and making use of PyXPCOM, see these links: * http://developer.mozilla.org/en/docs/PyXPCOM * http://developer.mozilla.org/en/docs/Building_PyXPCOM * http://developer.mozilla.org/en/docs/Creating_a_Python_XPCOM_component > * Is is reasonable to think that building a GUI with Mozilla is easier > than using Python frameworks because Mozilla does most of the GUI > work? > I would not recommend this for a small project, as there are many build related issues (especially since you'll need to build a separate Mozilla/XulRunner application for every platform you support) and a steeper learning curve for getting an application like this to work, packaged and installable. Yes, it is definitely a lot easier to build the UI using XUL and it does look consistently better across multiple platforms. Using Mozilla you'll gain access to a wealth of components with which you can take advantage of within your application. Note also that for the Firefox 3 codebase, it is expected that Python will become usable in the XUL UI, so instead of writing JavaScript you'll be able to write Python code that accesses and manipulates the user interface and the DOM. Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: I am giving up perl because of assholes on clpm -- switching to Python
On Jul 22, 2:20 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] a écrit : > > > Python is a better language, with php support, > > Python has php support ? My, I'm a professional web developper using > both, and I didn't knew this. > As an aside, perl DOES support PHP: http://search.cpan.org/~gschloss/PHP-Interpreter/ trwww -- http://mail.python.org/mailman/listinfo/python-list
Unsupported operator for Decimal: + (or -)
This seems to have come up earlier... http://mail.python.org/pipermail/python-list/2007-July/451187.html but no resolution. We're seeing the same thing. We're using Django's DecimalField type and when we try to add or subtract values--which should be decimal.Decimal objects--we occasionally get an error about the operator not being supported. It doesn't always happen and we can't seem to reproduce it when we try to. Has anybody else seen this or is it just the original poster and me? Todd -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Pulling data from a .asps site
-- Forwarded message -- From: Todd O'Bryan <[EMAIL PROTECTED]> Date: Nov 27, 2007 1:48 PM Subject: Re: Pulling data from a .asps site To: [EMAIL PROTECTED] Check out Selenium Remote Control! It's very easy to use. On Nov 27, 2007 1:37 PM, <[EMAIL PROTECTED]> wrote: > There's a government website which shows public data for banks. We'd > like to pull the data down programmatically but the data is "hidden" > behind .aspx... > > Is there anyway in Python to hook in directly to a browser (firefox or > IE) to do the following... > > 1) Fill the search criteria > 2) Press the "Search" button > 3) Press another button (the CSV button) on the resulting page > 4) Then grab the data out of the notepad file that pops up > > If this is a wild good chase, let me know... (or if there's a better > way besides Python... I may have to explore writing a firefox plug-in > or something)... > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Push to Make (Single Pole) Button running a loop
Happy holidays all! I'm developing an application and, as a relative newbie to Python, have come across a stumbling block with Tkinter. I'd like to have a button that when pressed executes a loop (this could be a thread) and then stops execution when it's released (Push to Make - Single Pole in electronics terms). I've tried the regular way of associating the procedure with a callback and tried using and bindings but am getting nowhere fast (in the latter case the button release event seems to occur anyhows). So my question is: Is there a neat way of doing this? And would it necessarily involve creating a custom widget? ... Also, while I'm here, what's the state of play regarding non-ASCII in Tkinter widgets. I've been trying to get our currency symbol, £, to display but didn't have much luck even playing with the coding: settings. TIA jon -- http://mail.python.org/mailman/listinfo/python-list
Re: Paramiko SFTP autologon using id_dsa.pub
Mike Hjorleifsson wrote: > I wrote a lil module using paramiko's module to send a file via > sftp.. it works great using the username and password. > I would prefer to use id_dsa.pub to have an autologon and not save > the > password anywhere on the disk.. I cant find a good example of this. > Can anyone help ? Hi Mike, If you download the Paramiko zip archive: http://www.lag.net/paramiko/download/paramiko-1.7.2.zip You can find examples of loading and using public/private keys for automated logins in the code under the "demos" sub folder. Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Best GUI toolkit with Table support
deech wrote: Hi all, I am making a cross-platform frontend to a sqlite3 database. Which python GUI toolkit has the best table support? Tkinter doesn't seem to support them (without additional package installation). The issue is that the application must run off a flash drive with a vanilla Python install on both Windows and Linux. Or if there is a way to store additional packages on the flash drive and call them in some portable way, this would work too. If you don't need custom sqlite functionality, you could use an existing sqlite manager app, such as SQLiteManager, which runs cross-platform as a Firefox extension, or can use XULRunner as a standalone (so it could run off a flash drive): http://code.google.com/p/sqlite-manager/wiki/ScreenShots Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Komodo Edit newbie Q
John Dann wrote: I'm learning Python using the Komodo Edit freeware code editor. One thing I'm finding a little confusing is that the code completion lists (what I would call Intellisense coming from a .Net background) are often very incomplete, especially with imported classes like wx. It's like KE can't look far enough into these classes to offer a comprehensive list of method etc options. I presume that I haven't possibly omitted some KE setup step that would give more detail to the code completion? Hi John, There are some Komodo forum posts that help out when dealing with wx completions in Komodo, this link below may be particularly helpful: <http://community.activestate.com/forum-topic/calltip-and-autocomplete-wxpython-differs-between-komodo-and-pythonwin> If not then maybe this is just a limitation of the KE freeware (because it's free?). Does anyone know if say Komodo IDE offers more in the way of code completion (I know that it offers more things in the way of debugging etc, but it's code completion specifically that I'm asking about here). Or is one of the other Python IDEs maybe more capable when it comes to code completion? Komodo Edit and Komodo IDE both use the exact same code intelligence system, so what occurs in Edit occurs in the IDE version. Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Gecko 1.9
Joe P. Cool wrote: > In 2005 I heard of plans to add Python as a second language to the > Gecko engine. Is this still true? Or has this plan been abandoned? > You can use Python inside of Mozilla (Gecko) based applications now, such as Firefox/Thunderbird/Komodo Edit/XulRunner which communicate through the Mozilla XPCOM architecture. There are builds of PyXPCOM (Python XPCOM) that can be downloaded and easily installed through the xpi extension mechanism, see: http://pyxpcomext.mozdev.org/ The Mozilla 1.9 branch (Gecko 1.9) also contains the hooks necessary to be able to use Python as a script handler, instead of having to use JavaScript. This is commonly referred to as PyDOM. To get and use PyXPCOM (Mozilla 1.8 and Mozilla 1.9): * install the above extension * or make your own build of the Mozilla application To get and use PyDOM (Mozilla 1.9): * you'll need to make your own build of the Mozilla application I'm the one working on the PyXPCOM extension, which I am hoping will eventually contain the PyDOM module as well (once I get around to making new Mozilla builds with this enabled). Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Python plugin for Firefox
zelegolas wrote: > Hi, > > It's may be a stupid question but do you if someone tried to create a > python plugin for firefox? > If you know an Open Source project let me know... > > Thanks This was asked just recently on the list (included responses below): Joe P. Cool wrote: > > In 2005 I heard of plans to add Python as a second language to the > > Gecko engine. Is this still true? Or has this plan been abandoned? > > You can use Python inside of Mozilla (Gecko) based applications now, such as Firefox/Thunderbird/Komodo Edit/XulRunner which communicate through the Mozilla XPCOM architecture. There are builds of PyXPCOM (Python XPCOM) that can be downloaded and easily installed through the xpi extension mechanism, see: http://pyxpcomext.mozdev.org/ The Mozilla 1.9 branch (Gecko 1.9) also contains the hooks necessary to be able to use Python as a script handler, instead of having to use JavaScript. This is commonly referred to as PyDOM. To get and use PyXPCOM (Mozilla 1.8 and Mozilla 1.9): * install the above extension * or make your own build of the Mozilla application To get and use PyDOM (Mozilla 1.9): * you'll need to make your own build of the Mozilla application I'm the one working on the PyXPCOM extension, which I am hoping will eventually contain the PyDOM module as well (once I get around to making new Mozilla builds with this enabled). Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: SSL through python. possible ?
TkNeo wrote: ok i have tried around a lot but no luck. I think M2Crypto is my best option except it requires a minimum of python 2.4 which i don't have. What i am trying to do is to do an FTP transfer that uses SSL (username, password authentication) and not a certificate file. The few example i have found of the Openssl module use a certificate for authentication unlike what i want to do. Komodo uses ssl to provide FTPS support (FTP over SSL), using the Python ssl socket library. From memory, I think there were problems trying to get FTPS to work on earlier versions of python (earlier than Python 2.4) and also a few problems working with Python 2.4 itself. This code might provide some help (you can search for FTPS): http://svn.openkomodo.com/openkomodo/view/openkomodo/trunk/src/components/koFTP.py Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGUI as a standard GUI API for Python?
M.-A. Lemburg wrote: A long time ago, there was a Python plugin for Netscape which allowed you to run Python straight in the browser. Perhaps it's time to revive such an idea... but then you're still missing out on the GUI part, since you're still stuck with what the browser has to offer in terms of widget support. There is still a plugin (extension) for Mozilla based products, that enables use of Python in products like Firefox: http://pyxpcomext.mozdev.org/ Mark Hammond's Python/Mozilla work has enabled products like Komodo, Miro (Democracy) and the OLPC project to use Python as a major driver for consistent cross-platform GUI applications. Personally, I believe XULRunner has a lot to offer for Python GUI development, I'm currently finishing up some documentation steps to show off how to use it specifically for Python (I'll post it to this list when it's finished). Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGUI as a standard GUI API for Python?
Todd Whiteman wrote: Mark Hammond's Python/Mozilla work has enabled products like Komodo, Miro (Democracy) and the OLPC project to use Python as a major driver for consistent cross-platform GUI applications. Personally, I believe XULRunner has a lot to offer for Python GUI development, I'm currently finishing up some documentation steps to show off how to use it specifically for Python (I'll post it to this list when it's finished). Here is the tutorial I've started in order to show off building a Python/XULRunner GUI application. http://pyxpcomext.mozdev.org/no_wrap/tutorials/pyxulrunner/python_xulrunner_about.html The details in this tutorial mostly targets a Windows/Linux platform (MacOSX is possible with a few deviations, I have tried to cover these deviations where applicable). Feedback is welcome. Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python GUI development using XULRunner
I've put together a tutorial that shows off how to build a GUI application using XULRunner (same architectural components as Firefox uses) that can be used in conjunction with the Python programming language. The tutorial covers how to build a Python/XULRunner GUI application: http://pyxpcomext.mozdev.org/no_wrap/tutorials/pyxulrunner/python_xulrunner_about.html The details in this tutorial covers the initial setup to full packaging/deployment, mostly targeting a Windows/Linux platform (MacOSX is possible with a few deviations, I have tried to cover these deviations where applicable). Feedback is welcome. Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python GUI development using XULRunner
Don Spaulding wrote: On Sep 16, 8:29 pm, Todd Whiteman <[EMAIL PROTECTED]> wrote: I've put together a tutorial that shows off how to build a GUI application using XULRunner (same architectural components as Firefox uses) that can be used in conjunction with the Python programming language. The tutorial covers how to build a Python/XULRunner GUI application:http://pyxpcomext.mozdev.org/no_wrap/tutorials/pyxulrunner/python_xul... I get to the "Running" step and run into "Couldn't load XPCOM." Does this work on x86_64? Or have I made a rookie mistake? Hi Don, A good question. Mozilla only provide 32-bit XulRunner applications by default, you you'll need to install the necessary 32-bit compatability libraries on your Linux machine, i.e. for Ubuntu it's something like: sudo apt-get install ia32-libs ia32-libs-gtk Then you should be able to run the example. You can check the dependencies using something the following commands, there should be no missing dependencies: $ cd pyxpcom_gui_app/xulrunner $ LD_LIBRARY_PATH=. ldd ./xulrunner-bin It is possible to use a 64-bit version, but you'll need to compile this yourself (or find somewhere that provides these x86_64 versions). Note that the PythonExt project does not offer Python bindings for x86_64 either (it's on my todo list), you can compile the PythonExt part yourself as well if you need a 64-bit version. Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python GUI development using XULRunner
[EMAIL PROTECTED] wrote: On Sep 17, 1:21 pm, Todd Whiteman <[EMAIL PROTECTED]> wrote: Don Spaulding wrote: On Sep 16, 8:29 pm, Todd Whiteman <[EMAIL PROTECTED]> wrote: I've put together a tutorial that shows off how to build a GUI application using XULRunner (same architectural components as Firefox uses) that can be used in conjunction with the Python programming language. The tutorial covers how to build a Python/XULRunner GUI application:http://pyxpcomext.mozdev.org/no_wrap/tutorials/pyxulrunner/python_xul... I get to the "Running" step and run into "Couldn't load XPCOM." Does this work on x86_64? Or have I made a rookie mistake? Hi Don, A good question. Mozilla only provide 32-bit XulRunner applications by default, you you'll need to install the necessary 32-bit compatability libraries on your Linux machine, i.e. for Ubuntu it's something like: sudo apt-get install ia32-libs ia32-libs-gtk Then you should be able to run the example. You can check the dependencies using something the following commands, there should be no missing dependencies: $ cd pyxpcom_gui_app/xulrunner $ LD_LIBRARY_PATH=. ldd ./xulrunner-bin It is possible to use a 64-bit version, but you'll need to compile this yourself (or find somewhere that provides these x86_64 versions). Note that the PythonExt project does not offer Python bindings for x86_64 either (it's on my todo list), you can compile the PythonExt part yourself as well if you need a 64-bit version. Cheers, Todd Interesting, I'm running Ubuntu Intrepid here, and have both ia32-libs and ia32-libs-gtk installed. ldd shows that I'm missing the following libs, even though the proper packages are installed, and the files show up in /usr/lib. libxcb-render-util.so.0 => not found libxcb-render.so.0 => not found There's also /usr/lib/libxcb-render.so.0.0.0 and the same for render- util, so I wonder if that could be part of the problem? Don Hi Don, I'm thinking there may be additional 32-bit packages necessary then (I'm not sure which package). Not sure about Ubuntu 8.10 (it's still alpha). I'm using a Ubuntu 8.04 x86_64 machine and my dependencies list the following for the latest 32-bit build of XulRunner: $ LD_LIBRARY_PATH=. ldd ./xulrunner-bin | grep libxcb libxcb-xlib.so.0 => /usr/lib32/libxcb-xlib.so.0 (0xf6493000) libxcb.so.1 => /usr/lib32/libxcb.so.1 (0xf647b000) Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: decent interactive python shell on MS Windows?
[EMAIL PROTECTED] wrote: Hi everyone, After having used Python on Linux for some time, I now have to do Python coding on Windows. I am big fan of the interactive Python shell to test, eg, regexps. Is there an interactive Python shell on Windows that supports: - easy copy-pasting to/from an editor? (as opposed to the cumbersome "mark", "copy" and then "paste" sequence that any terminal on Windows seems forced to adopt) - readline-like command history (up/down for previous/next command, Ctr-R for searching, etc) ? I have tried the python.org shell (difficult copy-pasting), ActiveState's (no readline command history) and iPython (difficult copy-pasting). Do you know of any decent interactive python shell on Windows that comes close to the friendliness of the standard one on Linux? Hi James, It sounds like a decent Editor/IDE would also fit this problem. Most modern Python IDE's can provide a Python interactive shell session as part of the editor with nice readline, copy/paste support: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments Komodo IDE for example, comes with a nice regex helper tool for testing regular expressions... so there isn't as much of a need for the interactive shell when creating/testing regular expressions: http://docs.activestate.com/komodo/4.4/tutorial/tourlet_rx.html#rx_top Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
Re: Stopping a Thread with Time Slicing
Steve wrote: Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always sitting in the sleep command and not able to be interrupted. When the time came to set the semaphore flag to false (stopping the thread), my program would have to wait up to the entire sleep time to break out of the loop. I have finally found a very workable solution to break out of the sleep loop by using a time slicing loop to divide the overall sleep time into small pieces (slices) giving the loop more opportunities to be interrupted. A better approach for this is to use a Python Event or Condition object: http://docs.python.org/library/threading.html#id5 Example code: import threading my_stop_event = threading.Event() # Sleep Loop : #for current_loop in range(0, self.time_slice) : # time.sleep(self.sleep_time / self.time_slice) event.wait(self.sleep_time) if not self.running:# check the flag break # break out of the sleep loop # From another thread, you can notify the above sleeping thread using: my_stop_event.set() Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
python 3.1.1 and --libdir option broken.
I've been trying to install Python 3.1.1 into /usr/lib64 via the configure script option --libdir, but it is ignored and Python 3.1.1 is installed in /usr/lib. Has anyone ran into this problem and solved it? Looking at the Makefile is seems as thought /lib in hard coded into the file. Any suggestions to fix this? Todd :-) -- http://mail.python.org/mailman/listinfo/python-list
Komodo IDE 6 released
Hello all, We are pleased to tell you that Komodo 6.0 has been released. With this release Komodo adds full support for Python 3 (Python 2 already supported) - with syntax coloring, error reporting, automatic code completions, debugging, code browsing and interactive Python shell. The new features of Komodo 6 include: * Python 3 support * Places - a smarter file system and project viewer * Publishing - to synchronize local and remote file systems (IDE) * Database Explorer - visualize database tables, run SQL queries (IDE) * Toolbox - refactored tool layout and a new invoke-tool helper * HTML5 and CSS3 - updated for the latest web technologies * Faster - common actions are now even faster than Komodo 5, wow! * Rx Toolkit - language-specific matching for Python, PHP, JS (IDE) For a detailed overview of the new Komodo 6 features, check out these feature pages: http://www.activestate.com/komodo-ide/whats-new http://community.activestate.com/komodo-60-features Enjoy, Todd -- http://mail.python.org/mailman/listinfo/python-list
socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello, When transmitting via UDP to a PLC, I run into a strange problem where socket.sendto returns double the number of characters sent in the datagram. I thought this was an error and used Wireshark to sniff the connection and discovered that it did, in fact, include two copies of the string I am transmitting in the same packet. The only thing differentiating this string from prior commands is its length. The functional ones are between 5 & 7 bytes (with 16 byte responses received successfully) but transmitting a 66-byte message actually results in 132 bytes being sent! I am running 2.6.6 on Windows XP, which I understand has a default minimum buffersize of 576 bytes which I would think is sufficient. Apologies if this is somewhat incoherent, I'm cross-eyed from staring at this! - - Todd - -- code -- def PLC_Functions(command, argument): """ Command is one of: GetTray, Status, SetText Argument is one of: tray number (as string), None, message (as string) The PC transmits and receives on socket 2260 (pcSocket) The PLC transmits and receives on socket 2002 The protocol used is UDP """ MegaMatPLC = (config.get('megamat','plcip'),int(config.get('megamat','targetport'))) # at some point it will be necessary to wrap these in TRY/EXCEPT to handle the socket errors # create UDP socket pcSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # bind it pcSocket.bind((config.get('megamat','pcip'),int(config.get('megamat','sourceport' # make them blocking (i/o is 'fire-and-forget' to a PLC that may or may not respond in a given time.) # non-blocking fails and raises windows exceptions for some reason (20-Oct-2010) pcSocket.setblocking(True) if command == 'CallTray': # frame 1 (see docs for frame sequence) print 'Received call tray command for tray %s' %(argument) getReadyMsg = '0145\r' totalsent = 0 while totalsent < len(getReadyMsg): sent = pcSocket.sendto(getReadyMsg[totalsent:],MegaMatPLC) if sent == 0: raise RunTimeError('Transmission failure. Please confirm MegaMat settings in megapy.ini') totalsent = totalsent + sent # Frame 2 response = '' while response.find('\r') < 0: response = pcSocket.recv(17) if response == '': raise RunTimeError('PLC did not respond') #this should be changed. The MIF software will wait until it receives a response or timeout, not ABEND print response if response[0:4] == '0135': print 'Drive ready received.' #Frame 3 getReadyMsg2 = '016040\r' totalsent = 0 while totalsent < len(getReadyMsg2): sent = pcSocket.sendto(getReadyMsg2[totalsent:],MegaMatPLC) if sent == 0: raise RunTimeError('Transmission failure. Please confirm MegaMat settings in megapy.ini') totalsent = totalsent + sent # Frame 4 response = '' while response.find('\r') < 0: response = pcSocket.recv(16) if response == '': raise RunTimeError('PLC did not respond') #this should be changed. The MIF software will wait until it receives a response or timeout, not ABEND print response if response[0:4] == '0130': # Frame 5 # Transmit tray request if int(argument) < 10: shelfPrefix = '' else: shelfPrefix = '000' shelf = shelfPrefix + argument unit = '001' stack = '01' """ There is a 10 digit number plus 40 blanks spaces after the shelf description built above. It is possible this is for storing shelf descriptions and barcodes on the PLC. We will follow the example of the MIF software and put a phony b/c and blank description. X is a field terminator and \r is the end of transmission (EoT.) """ fakeBarcode = '1234567890' fortySpacesField = ' '*40 + 'X\r' getShelfMsg = '0105' + shelf + unit + stack + fakeBarcode + fortySpacesField
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 00:07:58 +0100 MRAB wrote: > > > [snip] > > The docs for 'sendto' say: > > """The socket should not be connected to a remote socket, since > the destination socket is specified by address.""" > > Could your problem be caused by you binding the socket to a source > port, so it's going out both to the bound port _and_ the one given the > binding? > > Have you tried using two sockets, one outgoing and the other incoming? > > BTW, your code for handling the response doesn't cope with it coming > in a bit at a time. It loops discard any previous data from the > previous iteration. > > Also, it's more Pythonic to say: > > while '\r' not in response: > ... I haven't bound the socket to a remote port, as I read it; it's bound to a source port (192.168.10.2:2260, the local machine) and just transmits to an address with a port glommed on (192.168.10.1:2002, the PLC). Unfortunately I cannot alter the PLC's logic; it was provided by the vendor without source (and I'm not entirely sure i have the appropriate software to deal with it anyway as we're an Omron/A-B shop). I based this code on the actual conversation on the wire from the utility GUI that came with the storage unit. It ping pongs back and forth on just those two ports, likely because the old controller used a RS232 half-duplex interface. That being said, I don't know for a fact that the PLC cares about the source port -- they are usually pretty "dumb" and only care about the input but you never know what's been hard-coded. I will have to test this. I am primarily interested in the '\r'; it serves as the EOT (ie., 'over' not 'out') I know the response packet size is fixed and it only gets sent once in full. No re-transmission or fragmentation (this is likely by design - full stack isn't really necessary on this kind of PLC.) I'll change my loops to be more pythonic; it reads better. Thanks for your help, - - Todd -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzAVPAACgkQwnknPuQqPIPevgCdGHTXUiJLvyVOgcV12weBRDuV h0AAn0spYoMaxSuyoQi0EwEKXIk+rG20 =sgL9 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 17:03:58 +0100 MRAB wrote: > On 21/10/2010 15:57, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 00:07:58 +0100 > > MRAB wrote: > > > >>> > >> [snip] > >> > >> The docs for 'sendto' say: > >> > >> """The socket should not be connected to a remote socket, > >> since the destination socket is specified by address.""" > >> > >> Could your problem be caused by you binding the socket to a source > >> port, so it's going out both to the bound port _and_ the one given > >> the binding? > >> > >> Have you tried using two sockets, one outgoing and the other > >> incoming? > >> > >> BTW, your code for handling the response doesn't cope with it > >> coming in a bit at a time. It loops discard any previous data from > >> the previous iteration. > >> > >> Also, it's more Pythonic to say: > >> > >> while '\r' not in response: > >> ... > > I haven't bound the socket to a remote port, as I read it; it's > > bound to a source port (192.168.10.2:2260, the local machine) and > > just transmits to an address with a port glommed on > > (192.168.10.1:2002, the PLC). > [snip] > What I meant was that you're using 'pcSocket' for both directions and > using .bind on it. > > Try creating two sockets, 'pcInSocket' and 'pcOutSocket', and bind > only pcOutSocket. Ah, I comprehend now. Thanks! - - Todd -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzAb14ACgkQwnknPuQqPIOYEwCeNQNjGSQ/fwy2kLn862lY4fIk OosAn0WplhDaFE3gVVmyLHrFwfwjfLFm =j9fb -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 21 Oct 2010 17:03:58 +0100 MRAB wrote: > On 21/10/2010 15:57, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 00:07:58 +0100 > > MRAB wrote: > > > >>> > >> [snip] > >> > >> The docs for 'sendto' say: > >> > >> """The socket should not be connected to a remote socket, > >> since the destination socket is specified by address.""" > >> > >> Could your problem be caused by you binding the socket to a source > >> port, so it's going out both to the bound port _and_ the one given > >> the binding? > >> > >> Have you tried using two sockets, one outgoing and the other > >> incoming? > >> > >> BTW, your code for handling the response doesn't cope with it > >> coming in a bit at a time. It loops discard any previous data from > >> the previous iteration. > >> > >> Also, it's more Pythonic to say: > >> > >> while '\r' not in response: > >> ... > > I haven't bound the socket to a remote port, as I read it; it'sp > > bound to a source port (192.168.10.2:2260, the local machine) and > > just transmits to an address with a port glommed onu sn > > (192.168.10.1:2002, the PLC). > [snip] > What I meant was that you're using 'pcSocket' for both directions and > using .bind on it. > > Try creating two sockets, 'pcInSocket' and 'pcOutSocket', and bind > only pcOutSocket. As it turns out, Windows will throw a 10022 if you try and .recvfrom on an unbound port so I went back to the old way as it didn't seem to be related to my problem. I re-captured the packets from the utility again and I noticed that my text string is getting s p a c e d o u t in the datagram whereas the primary utility sends a nice cohesive "spacedout". My early transmissions work this way, successfully, as well and I think it is because either Python or Windows is treating my text strings differently than my numerical strings; more clearly when I send "1234" it goes out "1234" and when I send "Todd" it goes out as "T o d d ". This will obviously overflow the PLC and cause a reset. Any ideas? Regards, - - Todd -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzAnQUACgkQwnknPuQqPIOx6QCgjNP/S/dODwO/c7xk8xKZk1A7 IMQAniGKd5yaqRo3nAmHJJsrkEP6iL/j =aH+4 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Fri, 22 Oct 2010 00:00:03 +0100 MRAB wrote: > On 21/10/2010 21:05, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 17:03:58 +0100 > > MRAB wrote: > > > >> On 21/10/2010 15:57, Todd Walter wrote: > >>> -BEGIN PGP SIGNED MESSAGE- > >>> Hash: SHA1 > >>> > >>> On Thu, 21 Oct 2010 00:07:58 +0100 > >>> MRAB wrote: > >>> > >>>>> > >>>> [snip] > >>>> > >>>> The docs for 'sendto' say: > >>>> > >>>>"""The socket should not be connected to a remote socket, > >>>> since the destination socket is specified by address.""" > >>>> > >>>> Could your problem be caused by you binding the socket to a > >>>> source port, so it's going out both to the bound port _and_ the > >>>> one given the binding? > >>>> > >>>> Have you tried using two sockets, one outgoing and the other > >>>> incoming? > >>>> > >>>> BTW, your code for handling the response doesn't cope with it > >>>> coming in a bit at a time. It loops discard any previous data > >>>> from the previous iteration. > >>>> > >>>> Also, it's more Pythonic to say: > >>>> > >>>>while '\r' not in response: > >>>>... > >>> I haven't bound the socket to a remote port, as I read it; it'sp > >>> bound to a source port (192.168.10.2:2260, the local machine) and > >>> just transmits to an address with a port glommed onu sn > >>> (192.168.10.1:2002, the PLC). > >> [snip] > >> What I meant was that you're using 'pcSocket' for both directions > >> and using .bind on it. > >> > >> Try creating two sockets, 'pcInSocket' and 'pcOutSocket', and bind > >> only pcOutSocket. > > > > As it turns out, Windows will throw a 10022 if you try > > and .recvfrom on an unbound port so I went back to the old way as > > it didn't seem to be related to my problem. > > > Oops! I should've said "bind only pcInSocket". Sorry! :-( > | > > I re-captured the packets from the utility again and I noticed > > that my text string is getting s p a c e d o u t in the datagram > > whereas the primary utility sends a nice cohesive "spacedout". My > > early transmissions work this way, successfully, as well and I > > think it is because either Python or Windows is treating my text > > strings differently than my numerical strings; more clearly when I > > send "1234" it goes out "1234" and when I send "Todd" it goes out > > as "T o d d ". This will obviously overflow the PLC and cause a > > reset. > > > > Any ideas? > > > If they're all bytestrings then the contents shouldn't matter. Try > printing their repr just to check. No problem. I will keep trying until I get it! :) -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzBfuEACgkQwnknPuQqPIM0RACbBIqd8Ajf0APavZP4GkjeXSG0 DL4An07ZH+N5MVq8rru/OmsOpoR1CmnN =QFwU -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Fri, 22 Oct 2010 00:00:03 +0100 MRAB wrote: > On 21/10/2010 21:05, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 17:03:58 +0100 > > MRAB wrote: > > > >> On 21/10/2010 15:57, Todd Walter wrote: > >>> -BEGIN PGP SIGNED MESSAGE- > >>> Hash: SHA1 > >>> > >>> On Thu, 21 Oct 2010 00:07:58 +0100 > >>> MRAB wrote: > >>> > >>>>> > >>>> [snip] > >>>> > >>>> The docs for 'sendto' say: > >>>> > >>>>"""The socket should not be connected to a remote socket, > >>>> since the destination socket is specified by address.""" > >>>> > >>>> Could your problem be caused by you binding the socket to a > >>>> source port, so it's going out both to the bound port _and_ the > >>>> one given the binding? > >>>> > >>>> Have you tried using two sockets, one outgoing and the other > >>>> incoming? > >>>> > >>>> BTW, your code for handling the response doesn't cope with it > >>>> coming in a bit at a time. It loops discard any previous data > >>>> from the previous iteration. > >>>> > >>>> Also, it's more Pythonic to say: > >>>> > >>>>while '\r' not in response: > >>>>... > >>> I haven't bound the socket to a remote port, as I read it; it'sp > >>> bound to a source port (192.168.10.2:2260, the local machine) and > >>> just transmits to an address with a port glommed onu sn > >>> (192.168.10.1:2002, the PLC). > >> [snip] > >> What I meant was that you're using 'pcSocket' for both directions > >> and using .bind on it. > >> > >> Try creating two sockets, 'pcInSocket' and 'pcOutSocket', and bind > >> only pcOutSocket. > > > > As it turns out, Windows will throw a 10022 if you try > > and .recvfrom on an unbound port so I went back to the old way as > > it didn't seem to be related to my problem. > > > Oops! I should've said "bind only pcInSocket". Sorry! :-( > | > > I re-captured the packets from the utility again and I noticed > > that my text string is getting s p a c e d o u t in the datagram > > whereas the primary utility sends a nice cohesive "spacedout". My > > early transmissions work this way, successfully, as well and I > > think it is because either Python or Windows is treating my text > > strings differently than my numerical strings; more clearly when I > > send "1234" it goes out "1234" and when I send "Todd" it goes out > > as "T o d d ". This will obviously overflow the PLC and cause a > > reset. > > > > Any ideas? > > > If they're all bytestrings then the contents shouldn't matter. Try > printing their repr just to check. Printing the repr() results in the exact string I built. I infer this to mean that the cause is lower down; either in the socket module or the Windows stack. XP SP2 was known to do buggy things with UDP sockets; I wonder if that is what is causing me grief. I'm going to extract this part of the code and try it on my Linux laptop and see if I can get different results. Thanks for your help, - - Todd -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzBhKcACgkQwnknPuQqPIOf6wCfe8xouwHBJGnC2eHbKo+Eyvjo tw4AnjbSd9gnoAigJsDfowQQ1vM+rkFv =/GQV -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Fri, 22 Oct 2010 00:00:03 +0100 MRAB wrote: > On 21/10/2010 21:05, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 17:03:58 +0100 > > MRAB wrote: > > > >> On 21/10/2010 15:57, Todd Walter wrote: > >>> -BEGIN PGP SIGNED MESSAGE- > >>> Hash: SHA1 > >>> > >>> On Thu, 21 Oct 2010 00:07:58 +0100 > >>> MRAB wrote: > >>> > >>>>> > >>>> [snip] > >>>> > >>>> The docs for 'sendto' say: > >>>> > >>>>"""The socket should not be connected to a remote socket, > >>>> since the destination socket is specified by address.""" > >>>> > >>>> Could your problem be caused by you binding the socket to a > >>>> source port, so it's going out both to the bound port _and_ the > >>>> one given the binding? > >>>> > >>>> Have you tried using two sockets, one outgoing and the other > >>>> incoming?, > >>>> > >>>> BTW, your code for handling the response doesn't cope with it > >>>> coming in a bit at a time. It loops discard any previous data > >>>> from the previous iteration. > >>>> > >>>> Also, it's more Pythonic to say: > >>>> > >>>>while '\r' not in respo > >>>>... > >>> I haven't bound the socket to a remote port, as I read it; it'sp > >>> bound to a source port (192.168.10.2:2260, the local machine) and > >>> just transmits to an address with a port glommed onu sn > >>> (192.168.10.1:2002, the PLC). > >> [snip] > >> What I meant was that you're using 'pcSocket' for both directions > >> and using .bind on it. > >> > >> Try creating two sockets, 'pcInSocket' and 'pcOutSocket', and bind > >> only pcOutSocket. As it turns out, I must use only one socket. I have to use a fixed source port as the PLC will respond to that port. If I transmit using .sendto with an unbound socket the source port is picked at random making listening for the response impossible. It was my understanding that there could be a many-to-one relationship between sockets and ports but an attempt to recv without a bind throws an error and an attempt to bind to an already bound port throws an error. I thought the socket operations worked on the buffer so why does multiplexing fail? It shouldn't care how many listeners there are, it should just read the information off the wire and throw it somewhere everyone can read it. Is there a way to specify the source port for a transmission without first binding to it? - - Todd -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzBkV0ACgkQwnknPuQqPIM/4ACeKDGYAUJPdBjyGV2Iu6l/5bA1 X/MAoIWDOvnMhdA0NHXLo2Mv1Nm8kkZZ =4t/0 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Fri, 22 Oct 2010 10:53:45 -0400 Tom Pacheco wrote: > On 10/21/2010 4:05 PM, Todd Walter wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > On Thu, 21 Oct 2010 17:03:58 +0100 > > MRAB wrote: > > > >> On 21/10/2010 15:57, Todd Walter wrote: > >>> -BEGIN PGP SIGNED MESSAGE- > >>> Hash: SHA1 > >>> > >>> On Thu, 21 Oct 2010 00:07:58 +0100 > >>> MRAB wrote: > >>> > >>>> [snip] > >>>> > >>>> The docs for 'sendto' say: > >>>> > >>>>"""The socket should not be connected to a remote socket, > >>>> since the destination socket is specified by address.""" > >>>> > >>>> Could your problem be caused by you binding the socket to a > >>>> source port, so it's going out both to the bound port _and_ the > >>>> one given the binding? > >>>> > >>>> Have you tried using two sockets, one outgoing and the other > >>>> incoming? > >>>> > >>>> BTW, your code for handling the response doesn't cope with it > >>>> coming in a bit at a time. It loops discard any previous data > >>>> from the previous iteration. > >>>> > >>>> Also, it's more Pythonic to say: > >>>> > >>>>while '\r' not in response: > >>>>... > >>> I haven't bound the socket to a remote port, as I read it; it'sp > >>> bound to a source port (192.168.10.2:2260, the local machine) and > >>> just transmits to an address with a port glommed onu sn > >>> (192.168.10.1:2002, the PLC). > >> [snip] > >> What I meant was that you're using 'pcSocket' for both directions > >> and using .bind on it. > >> > >> Try creating two sockets, 'pcInSocket' and 'pcOutSocket', and bind > >> only pcOutSocket. > > As it turns out, Windows will throw a 10022 if you try and .recvfrom > > on an unbound port so I went back to the old way as it didn't seem > > to be related to my problem. I re-captured the packets from the > > utility again and I noticed that my text string is getting s p a c > > e d o u t in the datagram whereas the primary utility sends a nice > > cohesive "spacedout". My early transmissions work this way, > > successfully, as well and I think it is because either Python or > > Windows is treating my text strings differently than my numerical > > strings; more clearly when I send "1234" it goes out "1234" and > > when I send "Todd" it goes out as "T o d d ". This will obviously > > overflow the PLC and cause a reset. > > > > Any ideas? > > > > Regards, > > > > - - Todd > > -BEGIN PGP SIGNATURE- > > Version: GnuPG v2.0.16 (GNU/Linux) > > > > iEYEARECAAYFAkzAnQUACgkQwnknPuQqPIOx6QCgjNP/S/dODwO/c7xk8xKZk1A7 > > IMQAniGKd5yaqRo3nAmHJJsrkEP6iL/j > > =aH+4 > > -END PGP SIGNATURE- > > > what version of python are you using? > It sounds like you might be using python 3 which uses unicode for > strings. you would need to switch to bytes like b"Todd" > > - tom > > Python 2.6.6. That being said, there used to be an installation of 3.1 on the system that I removed. Would it be possible for stale .DLLs to interact with the 2.6.6 interpreter? Thanks for your help, - - Todd. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzBqxoACgkQwnknPuQqPIO0SQCfcxdLqZevWEzWnwzJ8iHxNNLo fIcAniDEHDVGEQhptrvJ/Bd2wqwVezt6 =n8Rx -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Thank you all for your help, I now have a functioning interface. As it turns out, trying to do things the "correct" way was wrong. The timing was so tight that doing anything (such as traversing the while-loop once) instead of a read immediately after transmission meant we missed the PLC's response. And, for whatever reason, I had to wrap the outgoing text in bytes() (this is still a mystery, but obviously it thinks strings going to the socket module are unicode.) The shorter, numeric, messages were able to complete sufficiently quickly that catching the response worked within a while loop but not the larger, 66-byte, message. Again, thanks all for your assistance. Cheers, Todd - The functional code --- def PLC_Functions(command, argument): """ Command is one of: GetTray, Status, SetText Argument is one of: tray number (as string), None, message (as string) The PC (arbitrarily) transmits / receives on socket 2260 (pcSocket) The PLC receives on socket 2002 and responds to whatever port it sees in the header The protocol used is UDP """ pcSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # bind it pcSocket.bind((config.get('megamat','pcip'),int(config.get('megamat','sourceport' # make them blocking (i/o is 'fire-and-forget' to a PLC that may or may not respond in a given time.) # non-blocking fails and raises windows exceptions for some reason (20-Oct-2010) pcSocket.settimeout(1.0) # 1ms? PLC will respond in ~0.10ms if command == 'CallTray': # frame 1 (see docs for frame sequence) print 'Received call tray command for tray %s' %(argument) getReadyMsg = '0145\r' totalsent = 0 while totalsent < len(getReadyMsg): sent = pcSocket.sendto(bytes(getReadyMsg[totalsent:]),MegaMatPLC) response, address = pcSocket.recvfrom(17) if sent == 0: raise RunTimeError('Transmission failure. Please confirm MegaMat settings in megapy.ini') totalsent = totalsent + sent # Frame 2 ''' response = '' while '\r' not in response: response, address = pcSocket.recvfrom(17) if response == '': raise RunTimeError('PLC did not respond') #this should be changed. The MIF software will wait until it receives a response or timeout, not ABEND ''' print response, address if response[0:4] == '0135': print 'Drive ready received.' # Frame 5 # Transmit tray request if int(argument) < 10: shelfPrefix = '' else: shelfPrefix = '000' shelf = shelfPrefix + argument unit = '001' stack = '01' """ There is a 10 digit number plus 40 blanks spaces after the shelf description built above. It is possible this is for storing shelf descriptions and barcodes on the PLC. We will follow the example of the MIF software and put a phony b/c and blank description. X is a field terminator and \r is the end of transmission (EoT.) """ fakeBarcode = '1234567890' fortySpacesField = '' + 'Todd Was Here' + ' ' + 'X\r' #fortySpacesField = ' '*40 + 'X\r' getShelfMsg = '0105' + shelf + unit + stack + fakeBarcode + fortySpacesField print 'Transmitting shelf request as follows: \n' + getShelfMsg sent = pcSocket.sendto(bytes(getShelfMsg),MegaMatPLC) response, address = pcSocket.recvfrom(132) print sent print response, address #Frame 6 ''' response = '' while '\r' not in response: response, address = pcSocket.recvfrom(16) if response == '': raise RunTimeError('PLC did not respond') #this should be changed. The MIF software will wait until it receives a response or timeout, not ABEND ''' print response, address pcSocket.close() -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzBzN0ACgkQwnknPuQqPINgfQCeN4hm8jDCnwU2niC0dOHkJO8F +MAAn1/kECizBDEY4doQj1+3+Si9Zyjg =SvAW -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
cheese shop registration error
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Python-list - I'd like to publish to PyPI. I'm assuming that this is open to anyone. So here's my repro case for trying to register for an account: REPRO: - - open cheeseshop reg form http://cheeseshop.python.org/pypi?%3Aaction=register_form - - fill out registration form as follows: Username: tgreenwood Password: some password Confirm: some password (same as above) Email Address: [EMAIL PROTECTED] PGP Key ID: (see below) - - i don't have a lot of experience with pgp, so i installed kpgp, a gui frontend to gnupg. i created a pgp key as follows: - -- install kpgp - -- create a new key pair for me : Todd Greenwood-Geer, [EMAIL PROTECTED], etc. - -- publish the key to hkp://subkeys.pgp.net - -- dblclick the new key in kpgp to get the properties dialog, copy down the key id, and paste that into the web field for PGP Key ID (above) - - submit form Error... There's been a problem with your request smtplib.SMTPRecipientsRefused: {u'tgreenwoodgeer.yahoo.com': (550, ': Recipient address rejected: User unknown in local recipient table')} Q: Do I have to be a member of some sort of secret society in order to be listed in the 'local recipient table'? - -Todd -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDi3ewz6uXX4lQc/URAvqrAKCjeUpJE6qWXeBSZO2kAG8v4IJ1BACeO+IA qERmUIqjKwmk3ipJSkKPUPE= =xPKQ -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: os.starfile() linux
On Mon, Nov 30, 2009 at 05:35:31PM +, joao abrantes wrote: > to open a new shell and to put the output of the new python program > there.. The subprocess module is probably what you want. -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks" -- http://mail.python.org/mailman/listinfo/python-list
Re: Invalid syntax error
On Sun, Dec 20, 2009 at 08:40:05AM -0500, Ray Holt wrote: > Why am I getting an invalid syntax error on the following: > os.chdir(c:\\Python_Modules). The error message says the colon after c You need to pass either a string literal or a variable. If you're passing a string, like you are trying to do, then you need to quote it. Also, you may want to use os.path.join() to make sure you're passing a portable pathname. -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks" -- http://mail.python.org/mailman/listinfo/python-list