Re: Pass and return
On Thu, 20 Dec 2012 21:23:58 -0800, iMath wrote: > Pass and return > Are these two functions the same ? They are neither functions, nor are they the same. Check if they are functions: - can you pass them arguments? - can you assign their result to a target? No. py> pass(23) File "", line 1 pass(23) ^ SyntaxError: invalid syntax py> x = return File "", line 1 x = return ^ SyntaxError: invalid syntax Are they the same? Try it with these two functions: def test_pass(): for i in range(100): pass print i def test_return(): for i in range(100): return print i py> test_pass() 99 py> test_return() py> So what are they? They are *statements*, not functions. You cannot pass them arguments, nor do they assign a result to a target on the left hand side of = equals sign. "pass" is a do-nothing statement. It literally does nothing. "return" exits a function and sets the return result. It is only legal inside functions and generators, while "pass" is legal almost anywhere. Normally you say "return some_value", but you can leave out the result and Python will "return None". If functions get all the way to the bottom without a return statement, they will return None. The example you give: > def test(): > return The body of the function immediately returns None. But functions return None by default, so you could leave the "return" statement out. If you do that, you will get a SyntaxError because there is nothing in the body: py> def test(): ... ... File "", line 3 ^ IndentationError: expected an indented block So if you put a "pass" statement in, just to satisfy the compiler, you get the same result: > def test(): > pass Also a function which immediately exists and return None. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On 12/20/2012 04:37 AM, Pierre Quentel wrote: To create an element, for instance an HTML anchor : doc <= A('Python',href="http://www.python.org";) To me, that is a awful choice and I urge you to change it. '<=' is not just an operator, it is a comparison operator. It normally return False or True. Numpy array comparison returns arrays of booleans, so the meaning is extended, not completely changed. People will often be using it with its normal mean in conditionals elsewhere, so this usage creates strong cognitive dissonance. Also, using an expression as a statement is allowed, but except in the interactive interpreter, it only makes sense with an expression that obviously has side-effects or could have side-effects (like the expression 'mylist.sort()'. It just looks wrong to an experienced Python programmer like me. It also is unnecessary. Use '+=' or '|='. The former means just what you want the statement to do and the latter is at least somewhat related (bit or-addition) and is rarely used and is very unlikely to be used in code intended for a browser. I'm afraid I am going to disagree. The document is a tree structure, and today Python doesn't have a syntax for easily manipulating trees. To add a child to a node, using an operator instead of a function call saves a lot of typing ; <= looks like a left arrow, which is a visual indication of the meaning "receive as child". |= doesn't have this arrow shape += is supported by Brython, but it means something different. <= means "add child" ; the addition operator + means "add brother" Although I'm not really in favor of using an operator for this sort of thing either way, I can't help but notice the discussion seems to be limited to Python's operators. If you're implementing Python yourself, can't you define a new operator that is unambiguous? -- http://mail.python.org/mailman/listinfo/python-list
Python USB control on Windows 7?
In this year's Christmas Raffle at work I won a 'party-in-a-box' including USB fairy lights. They sit boringly on all the time, so does anyone know if I can toggle the power easily from a script? My work PC is running Win7. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pass and return
Mitya Sirenef wrote: > On 12/21/2012 12:23 AM, iMath wrote: >> Pass and return >> Are these two functions the same ? >> >> def test(): >> return >> >> def test(): >> pass > > > From the point of style, of course, the latter is > much better because that's the idiomatic way > to define a no-op function. With a return, it > looks like you might have forgotten to add the > value to return or deleted it by mistake. > I would say it is *an* idiomatic way to define a no-op function. Another idiomatic way is to use a doc-string as the only body, that way you can also explain why you feel the need for an empty function. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On 12/21/2012 3:31 AM, Rouslan Korneychuk wrote: Although I'm not really in favor of using an operator for this sort of thing either way, I can't help but notice the discussion seems to be limited to Python's operators. If you're implementing Python yourself, can't you define a new operator that is unambiguous? Then the result is not exactly Python. The Python 3.3 Reference defines the Python 3.3 language. Supporting only a subset (as Brython does) is okay as long as the implementation only claims support for a subset (as Brython does). -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Oracle E-Business Suite Techno Functional Consultant Required for UAE
VAM SYSTEMS is a Business Consulting, IT Solutions and Services company with operations in UAE, Qatar, Bahrain, USA, Australia, Singapore & India. VAM SYSTEMS is currently looking for Oracle E-Business Suite Techno Functional Consultant for our UAE operations with the following skill set and terms and conditions: Skills Required • Strong Techno functional experience in Oracle E- Business Suite. • Should have experience in Supply chain and marketing Experience Required: Minimum 4+Years. Terms and conditions: Joining time frame: 2 weeks (Maximum 1 Month). The selected candidates shall join VAMSYSTEMS- UAE and shall be deputed to one of the leading Organizations in UAE. Should you be interested in this opportunity, please send your latest resume in MS Word format at the earliest at ambili.krish...@vamsystems.com or call us +91 476 2681150. -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
Pierre Quentel, 20.12.2012 10:42: > Le jeudi 20 décembre 2012 01:54:44 UTC+1, Ian a écrit : >> On Wed, Dec 19, 2012 at 5:07 PM, Terry Reedy wrote: To create an element, for instance an HTML anchor : doc <= A('Python',href="http://www.python.org";) >>> >>> To me, that is a awful choice and I urge you to change it. +1 >> +1. The DOM already has a well-established API. [...] >> >> link = document.createElement('a') >> link.setAttribute("href", "http://www.python.org/";) >> link.appendChild(document.createTextNode('Python')) >> document.body.appendChild(link) > > We don't have the same point of view. Mine is to offer an alternative to > Javascript, with the simplicity and elegance of the Python syntax, for a > programer who wants to develop a web application and doesn't know Javascript. > Ultimately this means that the whole DOM API would be described without any > mention of Javascript, only with the Python API If that's your intention, then instead of coming up with something totally new, unpythonic and ugly, why not take the normal Python route and implement a subset of the ElementTree API? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: compile python 3.3 with bz2 support on RedHat 5.5
On Friday, 21 December 2012 12:05:57 UTC+5:30, Isml wrote: > hi, everyone: > I want to compile python 3.3 with bz2 support on RedHat 5.5 but fail to > do that. Here is how I do it: > 1、download bzip2 and compile it(make、make -f Makefile_libbz2_so、make > install) > 2、chang to python 3.3 source directory : ./configure > --with-bz2=/usr/local/include > 3、make > 4、make install > > after installation complete, I test it: > [root@localhost Python-3.3.0]# python3 -c "import bz2" > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python3.3/bz2.py", line 21, in > from _bz2 import BZ2Compressor, BZ2Decompressor > ImportError: No module named '_bz2' > > By the way, RedHat 5.5 has a built-in python 2.4.3. Would it be a problem? Are the bzip headers in /usr/local/include/ ? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to detect the encoding used for a specific text data ?
On 20 December 2012 11:57, iMath wrote: > how to detect the encoding used for a specific text data ? Normally encoding is given in some way by the context of the data. Otherwise no general solution is possible. On a related note: how to answer question with no context on mailing list? -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
> If that's your intention, then instead of coming up with something totally > new, unpythonic and ugly, why not take the normal Python route and > implement a subset of the ElementTree API? > > Stefan Because the tree implementation in ElementTree or other tree modules in Python require a lot of typing and parenthesis To produce the HTML code hello world these modules require writing something like div = Tag('DIV') div.appendChild(TextNode('hello ')) b = Tag('B') b.appendChild(TextNode('world')) div.appendChild(b) doc.appendChild(div) With the tree syntax proposed in Brython it would just be doc <= DIV('hello '+B('world')) If "pythonic" means concise and readable, which one is more pythonic ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Fri, Dec 21, 2012 at 11:38 PM, Pierre Quentel wrote: > With the tree syntax proposed in Brython it would just be > > doc <= DIV('hello '+B('world')) > > If "pythonic" means concise and readable, which one is more pythonic ? Pythonic also means: If the implementation is hard to explain, it's a bad idea. What, exactly, does the sum of a string and a bolded string produce? Can you explain that easily and clearly? Don't forget that humans, as well as machines, will expect to be able to parse what's inside the parentheses without looking outside them. The DOM structure is, undeniably, quite verbose. But you could go for something with the same tree structure while a lot less wordy by simply returning self from lots of methods, thus allowing method chaining - something like this: https://github.com/Rosuav/Gypsum/blob/master/window.pike#L247 Note how the tree structure is defined by the parentheses, with ->add(...) calls creating children. (That's Pike, not Python, as I don't have a good Python example handy. The -> operator does more or less what Python's . does.) Now, I can conceive of a kind of API - an ideal API, the creature of my fancy, you know - which would be totally unobjectionable. An API, for instance, which would abolish taxes and make everything cheap, except gondolas... oh wait, wrong mailing list. To produce the HTML code hello world you might use: doc.add(Tag('DIV').add('hello ').add(Tag('B').add('world'))) And you can easily wrap that to suit, since it's surrounded by parentheses: doc.add( Tag('DIV') .add('hello ') .add(Tag('B').add('world')) ) There's no magic with operators, just simple method chaining. It's a bit more verbose than your proposed tree syntax, but not nearly as bad as the JS version; and it's not magical. Reject the idea if you will, but do at least please consider it :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
Pierre Quentel wrote: >> If that's your intention, then instead of coming up with something >> totally new, unpythonic and ugly, why not take the normal Python >> route and implement a subset of the ElementTree API? >> >> Stefan > Because the tree implementation in ElementTree or other tree modules > in Python require a lot of typing and parenthesis > > To produce the HTML code > >hello world > > these modules require writing something like > > div = Tag('DIV') > div.appendChild(TextNode('hello ')) > b = Tag('B') > b.appendChild(TextNode('world')) > div.appendChild(b) > doc.appendChild(div) Or you can do something like this: >>> from lxml.html.builder import * >>> snippet = DIV("Hello ", B("world")) >>> etree.tostring(snippet) 'Hello world' > > With the tree syntax proposed in Brython it would just be > > doc <= DIV('hello '+B('world')) > > If "pythonic" means concise and readable, which one is more pythonic ? > The one that doesn't do unexpected things with operators. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
Duncan Booth, 21.12.2012 14:14: > Pierre Quentel wrote: >>> If that's your intention, then instead of coming up with something >>> totally new, unpythonic and ugly, why not take the normal Python >>> route and implement a subset of the ElementTree API? >> >> Because the tree implementation in ElementTree or other tree modules >> in Python require a lot of typing and parenthesis >> >> To produce the HTML code >> >> hello world >> >> these modules require writing something like >> >> div = Tag('DIV') >> div.appendChild(TextNode('hello ')) >> b = Tag('B') >> b.appendChild(TextNode('world')) >> div.appendChild(b) >> doc.appendChild(div) > > Or you can do something like this: > > >>> from lxml.html.builder import * > >>> snippet = DIV("Hello ", B("world")) > >>> etree.tostring(snippet) > 'Hello world' For which there even happens to be an ElementTree implementation available: http://svn.effbot.org/public/stuff/sandbox/elementlib/builder.py (It's not like I made this up ...) Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: redirect standard output problem
On 21/12/12 06:23:18, iMath wrote: > redirect standard output problem > > why the result only print A but leave out 888 ? > > import sys > class RedirectStdoutTo: > > def __init__(self, out_new): > self.out_new = out_new > def __enter__(self): > sys.stdout = self.out_new > def __exit__(self, *args): > sys.stdout = sys.__stdout__ > > > print('A') > with open('out.log', mode='w', encoding='utf-8') as a_file, > RedirectStdoutTo(a_file): > > print('B') > print('C') > > print(888) On my machine it works as you'd expect. If it doesn't work on your system, it might help to flush sys.stdout in a few strategic places: class RedirectStdoutTo: def __init__(self, out_new): self.out_new = out_new def __enter__(self): sys.stdout.flush() sys.stdout = self.out_new def __exit__(self, *args): sys.stdout.flush() sys.stdout = sys.__stdout__ print('A') with open('out.log', mode='w', encoding='utf-8') as a_file, RedirectStdoutTo(a_file): print('B') print('C') print(888) sys.stdout.flush() Hope this helps, -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: compile python 3.3 with bz2 support on RedHat 5.5
On Fri, Dec 21, 2012 at 5:35 PM, Isml <76069...@qq.com> wrote: > By the way, RedHat 5.5 has a built-in python 2.4.3. Would it be a problem? You may want to consider using 'make altinstall' rather than 'make install'. That way, you don't stomp all over the system Python (so system scripts that expect 2.4 will still work), but you can type 'python3' to invoke your newly-built one. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: how to detect the encoding used for a specific text data ?
On 12/21/2012 07:38 AM, Oscar Benjamin wrote: > > On a related note: how to answer question with no context on mailing > list? Depends on how you're reading/responding. I'll assume you're using an email client like Thunderbird, and that you do NOT subscribe in digest form. Most general way is to use Reply-All, and remove any recipients you don't want there, but make sure you keep the python-list recipient. Alternatively, if you're using Thunderbird or another with similar capability, use Reply-list, which is smart enough to only keep the list entry. Or, what I used to do, reply, then add the python-list@python.org to the list of recipients. That's error prone. I hope this answers your question. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: redirect standard output problem
On 12/21/2012 12:23 AM, iMath wrote: > redirect standard output problem > > why the result only print A but leave out 888 ? > > import sys > class RedirectStdoutTo: > > def __init__(self, out_new): > self.out_new = out_new > def __enter__(self): > sys.stdout = self.out_new > def __exit__(self, *args): > sys.stdout = sys.__stdout__ Just a comment. It'd be better to save and restore the stdout value, rather than restoring it to what it was at begin of process. Quoting from http://docs.python.org/3.3/library/sys.html?highlight=__stdout__#sys.__stdout__ It can also be used to restore the actual files to known working file objects in case they have been overwritten with a broken object. However, the preferred way to do this is to explicitly save the previous stream before replacing it, and restore the saved object. My reasoning is that some function further up the stack may also be using a similar (or identical) redirection technique. Anyway, instead of using __stdout__, I'd use a saved value inside your object. def __init__(self, out_new): self.out_new = out_new def __enter__(self): self.savedstate = sys.stdout sys.stdout = self.out_new def __exit__(self, *args): sys.stdout = self.savedstate This may or may not solve your problem (I'd suspect that flush() is the right answer), but I still think it's worth doing. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Build and runtime dependencies
? 2012?12?21? 06:11, Jack Silver ??: I have two Linux From Scratch machine. On the first one (the server), I want to build install python 3.3.0 in a shared filesystem and access it from the second one (the client). These machines are fairly minimal in term of the number of software installed. I just want to install python on this filesystem and anything else. I would like to know what are the build and runtime dependencies that are needed on both machine. My understanding is that the core CPython interpreter only needs a C compiler to be built. For the extension modules, I think that only the development headers of some additional libraries are needed on the server machine. Hence, I do not need to install all those libraries on the client machine. Right ? I'm somewhat confused by this server-client-python thing. Do you mean that you want all python related pkgs to be installed on server and you clients only contain your own python projects? I would like to build as much module I can, so I have a complete python installation. Here is the list of dependecies I think I need to install on the server machine : expat bzip2 gdbm openssl libffi zlib tk sqlite valgrind bluez Four your information, here's a list of packages needed to build python2.7. bzip2 db gdbm openssl readline sqlite3 zlib anything ? Is there anything I need to install on the client too ? If you can access server via ssh, why is anything needed to be installed on client? If you want your python projects to reside on your client and to run them on server, or vice versa, try an nfs mount. Thanks Jack -- http://mail.python.org/mailman/listinfo/python-list
HTML - WEB FORM running PYTHON SCRIPT
Hi there, i would like to ask.. i need to create an html webpage and bring that live on the internet via my host service, and i would also like a conversion calculator being showed on this website. Concersion tool such as Cels. to Kelvin. I have the calculation formula and i would like to script it in python and embed the conversion form in it. For example http://www.sciencegateway.org/tools/fwcal.htm . So im asking... how could i do that? I do not want the guest to download the program from this webpage. What i need is the form to be showed online and then the calculations being made from guest computer. Not server. Im newbie to java thats why this is not good option to me. After lots of searching i think ironpython may be somehow helpfull to me but... im asking you too. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML - WEB FORM running PYTHON SCRIPT
On Sat, Dec 22, 2012 at 2:00 AM, Dimitrios Xenakis wrote: > Hi there, i would like to ask.. i need to create an html webpage and bring > that live on the internet via my host service, and i would also like a > conversion calculator being showed on this website. Concersion tool such as > Cels. to Kelvin. I have the calculation formula and i would like to script it > in python and embed the conversion form in it. For example > http://www.sciencegateway.org/tools/fwcal.htm . > > So im asking... how could i do that? I do not want the guest to download the > program from this webpage. What i need is the form to be showed online and > then the calculations being made from guest computer. Not server. Im newbie > to java thats why this is not good option to me. There have been a few attempts at making it possible to program a web browser using Python. In fact, one is being discussed and developed right now - search the list archives for Brython. But normally, the way to script a user's browser is to use JavaScript. I'm not sure how IronPython fits into your picture; it's an implementation of Python that uses the .NET framework. Unless you have a very good reason for wanting to use Python (eg you want to share code with another Python project), I strongly recommend learning JavaScript. What you're looking to do is fairly simple, and not worth downloading to the user's browser a massive language engine - because that's how systems like Brython work. Keep it simple, learn a few languages, and you'll become a better programmer for it :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
> Pythonic also means: > If the implementation is hard to explain, it's a bad idea. > What, exactly, does the sum of a string and a bolded string produce? Can you > explain that easily and clearly? Yes : a+b returns the string a+str(b) It is exactly what you get in CPython with >>> class B: ... def __init__(self,value): ... self.value = value ... def __radd__(self,other): ... return '%s%s' %(other,self.value) ... >>> 'hello '+B('world') 'hello world' > The DOM structure is, undeniably, quite verbose. But you could go for > something with the same tree structure while a lot less wordy by > simply returning self from lots of methods, thus allowing method > chaining - something like this: > > https://github.com/Rosuav/Gypsum/blob/master/window.pike#L247 > Hang me if I understand what this code is supposed to do ;-) > > To produce the HTML code > > hello world > > you might use: > > doc.add(Tag('DIV').add('hello ').add(Tag('B').add('world'))) > No, with this syntax, the result of Tag('B').add('world') is below 'hello' in the tree structure, not at the same level (just below Tag('DIV')) as it should be In this case it's not a real problem, but it's obvious if you want to produce onetwo : you would need 2 different 'add' top = Tag('UL') top.add(Tag('LI').add('one')) top.add(Tag('LI').add('two')) With the syntax used in Brython : UL(LI('one')+LI('two')) > > Reject the idea if you will, but do at least please consider it :) > I did in fact consider many options before proposing this one. I have done a lot of web programming, including a web framework, and I faced the problem of generating HTML code from Python. I started with a syntax with nested parenthesis and chained methods returning self, only ending in ugly, unreadable code. Once I started using <= for "add child" and "+" for "add brother" (I first proposed it in the Python Cookbook recipe #366000, the HTMLTags module) - and I've used it on fairly large projects - the result was a much cleaner code -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Sat, Dec 22, 2012 at 2:36 AM, Pierre Quentel wrote: >> doc.add(Tag('DIV').add('hello ').add(Tag('B').add('world'))) >> > No, with this syntax, the result of Tag('B').add('world') is below 'hello' in > the tree structure, not at the same level (just below Tag('DIV')) as it > should be No; look at the expanded form for a more readable (but syntactically identical) version: doc.add( Tag('DIV') .add('hello ') .add(Tag('B').add('world')) ) 'world' is below Tag('B') - look at the parentheses - but Tag('DIV').add('hello ') returns the DIV, not the hello, so B and hello are peers. > In this case it's not a real problem, but it's obvious if you want to produce > onetwo : you would need 2 different 'add' > top = Tag('UL') > top.add(Tag('LI').add('one')) > top.add(Tag('LI').add('two')) > > With the syntax used in Brython : UL(LI('one')+LI('two')) They can be directly combined, because Tag.add(self,other) returns self, not other. > Yes : a+b returns the string a+str(b) > 'hello '+B('world') > 'hello world' Hmm. So when that gets added into a DIV, it has to get parsed for tags? How does this work? This seems very odd. I would have expected it to remain as DOM objects. What happens if I do, for instance: 'blah blah x'+s+'' rather than any sort of class. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange effect with import
Hans Mulder wrote: > Maybe something like this: > class ReqHandler(SocketServer.BaseRequestHandler): > def __init__(self, request, client_address, server, ham, spam) > super(SocketServer, self).__init__( > self, request, client_address, server) > self.ham = ham > self.spam = spam > The only thing I had to change about this was to assign the additional class variables before calling super() because in the __init__() method of the base class my overloaded handle() method is already called which needs those extra variables. > And later: > import functools > server = SocketServer.TCPServer((192.168.1.10, 12345), >functools.partial(ReqHandler, ham="hello", spam=42)) Thanks a lot, that's now all working perfectly well and I got rid of those pesky global variables;-) Probably the guys that wrote the SocketServer module indeed didn't expect people as dense as me to use their module and thus didn't mention that passing additional information to a handler object can be done this way... Best regards, Jens -- \ Jens Thoms Toerring ___ j...@toerring.de \__ http://toerring.de -- http://mail.python.org/mailman/listinfo/python-list
Second try: non-blocking subprocess pipe and Tkinter in 2.7
Yesterday I posted a question about keeping a Tkinter GUI during a long-running process, i.e. reading data from a pipe via the subprocess module. I think that question did not quite get at the heart of the issue because it assumed that Python, like Tcl which underlies Tkinter, supports non-blocking, asynchronous reading out of the box. Apparently it does not. So, my question is hereby revised as such: how can I implement a non-blocking read of a subprocess pipe that can write data to the Tkinter text widget in an manner that does not cause the GUI to lock up? --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Build and runtime dependencies
On Fri, Dec 21, 2012 at 9:11 AM, Jack Silver wrote: > On the first one (the server), I want to build install python 3.3.0 in a > shared filesystem and access it from the second one (the client). Correct me if I'm wrong, but my understanding of your description is this: System #1 ("server"): Full development environment, C compiler, etc, etc. System #2 ("client"): Run-time only, uses the Python built on System #1. System #3->N: Identical to System 2. This is definitely a viable setup, but you need to make sure the server and clients are running "broadly similar" systems - for instance, they should both be the same architecture (eg amd64), and for convenience, probably should be similar Linux kernel versions and file system layouts, so you don't have to worry about pathing messes and so on. On the server, you'll need all the development tools, all the dev packages for your libraries, and so on (as Hans said, Debian has packages like libbz2-1.0 and libbz2-dev); on the clients, you need only the run-times. The easiest way, I've found, is an iterative process of build, see what didn't work, grab another package (in my case, "apt-get install"), rinse and repeat; in this case, you'll want to do this exercise on the server, grabbing -dev packages, and then repeat it on the client, referring to your list of libraries as a "will likely need this" hint set. (But you might not; chances are you have some of the runtimes already.) One thing to beware of. You say you're planning to use a shared filesystem; that may cause some hassles when you come to do a recompile. I would recommend, at the very least, running some kind of separate "install" step after building, copying the necessary files onto the shared filesystem - that way, if you upgrade to a new version of Python and it doesn't build for some reason (back to needing more packages, perhaps, or maybe you like to live on the edge and you picked up the very latest and it happened to not work), you haven't toasted all your clients. But this might not be an issue for you. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
> <= is a comparison expression operator, which is completely different. > It is just wrong for this usage. I am 99.9% sure you will come to regret > it eventually. Better to make the change now than in Brython2 or Brython3. I am 99.99% sure of the contrary, having used this syntax for more than 3 years now, as the users of the Karrigell framework with the HTMLTags module Another point why there is no possible confusion is that when <= is a comparison operator, it is never used in an standalone expression like "a <= b", with the left term of the comparison starting the line ; it is always used in an expression like "if x <= 10", "while x <= 5", "assert x <= 0", "return foo <= bar" etc. So when you see a line like doc <= DIV('hello') it should be obvious that you are not *comparing* doc and DIV('hello'), because if it was the case, the line would do nothing -- http://mail.python.org/mailman/listinfo/python-list
Re: Second try: non-blocking subprocess pipe and Tkinter in 2.7
Kevin Walzer wrote: > Yesterday I posted a question about keeping a Tkinter GUI during a > long-running process, i.e. reading data from a pipe via the subprocess > module. I think that question did not quite get at the heart of the > issue because it assumed that Python, like Tcl which underlies Tkinter, > supports non-blocking, asynchronous reading out of the box. Apparently > it does not. > > So, my question is hereby revised as such: how can I implement a > non-blocking read of a subprocess pipe that can write data to the > Tkinter text widget in an manner that does not cause the GUI to lock up? You could do blocking reads in a separate thread and use a queue to communicate with the GUI in the main thread: http://effbot.org/zone/tkinter-threads.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
> Hmm. So when that gets added into a DIV, it has to get parsed for > tags? How does this work? This seems very odd. I would have expected > it to remain as DOM objects. In DIV(child) : - if child is a string, integer or float, a text node is added (addChild) to the DIV element, with the string value of child - if child is another DOM element (as in DIV(B('foo'))) then this element is added to the DIV element The code is in module py_dom.js, class $TagClass > > What happens if I do, for instance: > 'blah blah x You can test this code in the console on the Brython site (http://brython.info/tests/console_fr.html) : doc <= 'blah blah xhttp://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
Pierre Quentel, 21.12.2012 17:16: > So when you see a line like > > doc <= DIV('hello') > > it should be obvious that you are not *comparing* doc and DIV('hello'), > because if it was the case, the line would do nothing Yep, that's one of the main concerns - it looks like useless code, which is totally different from what it does. So it basically uses magic side-effects as part of the design, which is never a good thing. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Pass and return
On 12/21/2012 03:52 AM, Duncan Booth wrote: Mitya Sirenef wrote: On 12/21/2012 12:23 AM, iMath wrote: Pass and return Are these two functions the same ? def test(): return def test(): pass From the point of style, of course, the latter is much better because that's the idiomatic way to define a no-op function. With a return, it looks like you might have forgotten to add the value to return or deleted it by mistake. I would say it is *an* idiomatic way to define a no-op function. Another idiomatic way is to use a doc-string as the only body, that way you can also explain why you feel the need for an empty function. That's true, a docstring is preferable in many cases. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ -- http://mail.python.org/mailman/listinfo/python-list
Re: help with making my code more efficient
On Thursday, December 20, 2012 8:31:18 PM UTC-7, Dave Angel wrote: > On 12/20/2012 08:46 PM, larry.mart...@gmail.com wrote: > > > On Thursday, December 20, 2012 6:17:04 PM UTC-7, Dave Angel wrote: > > >> > > > Of course it's a fragment - it's part of a large program and I was just > > showing the relevant parts. > > But it seems these are methods in a class, or something, so we're > missing context. And you use self without it being an argument to the > function. Like it's a global. I didn't show the entire method, only what I thought was relevant to my issue. The method is declared as: def generate_data(self): > > > > > > Yes, the code works. I end up with just the rows I want. > > >> Are you only concerned about speed, not fixing features? > > > Don't know what you mean by 'fixing features'. The code does what I want, > > it just takes too long. > > > > > >> As far as I can tell, the logic that includes the time comparison is > >> bogus. > > > Not at all. > > > > > >> You don't do anything there to worry about the value of tup[2], just > >> whether some > > >> item has a nearby time. Of course, I could misunderstand the spec. > > > The data comes from a database. tup[2] is a datetime column. tdiff comes > > from a datetime.timedelta() > > I thought that tup[1] was the datetime. In any case, the loop makes no > sense to me, so I can't really optimize it, just make suggestions. Yes, tup[1] is the datetime. I mistyped last night. > >> Are you making a global called 'self' ? That name is by convention only > > >> used in methods to designate the instance object. What's the attribute > > >> self? > > > Yes, self is my instance object. self.message contains the string of > > interest that I need to look for. > > > > > >> Can cdata have duplicates, and are they significant? > > > No, it will not have duplicates. > > > > > >> Is the list sorted in any way? > > > Yes, the list is sorted by tool and datetime. > > > > > >> Chances are your performance bottleneck is the doubly-nested loop. You > > >> have a list comprehension at top-level code, and inside it calls a > > >> function that also loops over the 600,000 items. So the inner loop gets > > >> executed 360 billion times. You can cut this down drastically by some > > >> judicious sorting, as well as by having a map of lists, where the map is > > >> keyed by the tool. > > > Thanks. I will try that. > > > > So in your first loop, you could simply split the list into separate > lists, one per tup[0] value, and the lists as dictionary items, keyed by > that tool string. > > Then inside the determine() function, make a local ref to the particular > > list for the tool. > >recs = messageTimes[tup[0]] I made that change ant went from taking over 2 hours to 54 minutes. A dramatic improvement, but still not adequate for my app. > Instead of a for loop over recs, use a binary search to identify the > first item that's >= date_time-tdiff. Then if it's less than > date_time+tdiff, return True, otherwise False. Check out the bisect > module. Function bisect_left() should do what you want in a sorted list. Didn't know about bisect. Thanks. I thought it would be my savior for sure. But unfortunaly when I added that, it blows up with out of memory. This was the code I had: times = messageTimes[tup[0]] le = bisect.bisect_right(times, tup[1]) ge = bisect.bisect_left(times, tup[1]) return (le and tup[1]-times[le-1] <= tdiff) or (ge != len(times) and times[ge]-tup[1] <= tdiff) > >>> cdata[:] = [tup for tup in cdata if determine(tup)] > > >> As the code exists, there's no need to copy the list. Just do a simple > >> bind. > > > This statement is to remove the items from cdata that I don't want. I don't > > know what you mean by bind. I'm not familiar with that python function. > > Every "assignment" to a simple name is really a rebinding of that name. > cdata = [tup for tup in cdata if determine(tup)] > > will rebind the name to the new object, much quicker than copying. If > this is indeed a top-level line, it should be equivalent. But if in > fact this is inside some other function, it may violate some other > assumptions. In particular, if there are other names for the same > object, then you're probably stuck with modifying it in place, using > slice notation. The slice notation was left over when when cdata was a tuple. Now that it's a list I don't need that any more. > BTW, a set is generally much more memory efficient than a dict, when you > don't use the "value". But since I think you'll be better off with a > dict of lists, it's a moot point. I'm going back to square 1 and try and do all from SQL. -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Fri, Dec 21, 2012 at 9:16 AM, Pierre Quentel wrote: >> <= is a comparison expression operator, which is completely different. >> It is just wrong for this usage. I am 99.9% sure you will come to regret >> it eventually. Better to make the change now than in Brython2 or Brython3. > > I am 99.99% sure of the contrary, having used this syntax for more than 3 > years now, as the users of the Karrigell framework with the HTMLTags module > > Another point why there is no possible confusion is that when <= is a > comparison operator, it is never used in an standalone expression like "a <= > b", with the left term of the comparison starting the line ; it is always > used in an expression like "if x <= 10", "while x <= 5", "assert x <= 0", > "return foo <= bar" etc. > > So when you see a line like > > doc <= DIV('hello') > > it should be obvious that you are not *comparing* doc and DIV('hello'), > because if it was the case, the line would do nothing The interpreter, though, will be more than happy to treat that as a comparison if the LHS is not the type that you think it is. For example, maybe you've added it to a string at some point, and now it's a string instead of an element. I guess that since doc is made a keyword, that probably couldn't happen in this example, but it could happen when trying to add child nodes to other nodes. By the way, what is Brython actually doing when you append a child to the document itself like that? Usually I would expect a div to be appended to the body or to another div. The above looks like it would attach the new div as a sibling of the html element. Or is it just calling document.write()? -- http://mail.python.org/mailman/listinfo/python-list
RE: Question regarding mod_python and a script for web.
Hi Ion thanks a bunch, for responding. The problem we seem to be running into is that When we change the forms to a post instead of a get I cannot pick up the post values using cgi: page_info = cgi.FieldStorage() is this a limitation of mod_python? Thanks. john Date: Thu, 20 Dec 2012 17:59:42 -0800 Subject: Re: Question regarding mod_python and a script for web. From: ian.doug...@iandouglas.com To: johnp...@hotmail.com CC: python-list@python.org Short answer: Use the POST method on the form instead of GET. Depending how you process the form you might need to make a few changes to the script that answers the request. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with making my code more efficient
On Friday, December 21, 2012 10:57:19 AM UTC-7, larry@gmail.com wrote: > On Thursday, December 20, 2012 8:31:18 PM UTC-7, Dave Angel wrote: > > On 12/20/2012 08:46 PM, larry.mart...@gmail.com wrote: > > > On Thursday, December 20, 2012 6:17:04 PM UTC-7, Dave Angel wrote: > > >> > > > Of course it's a fragment - it's part of a large program and I was just > > > showing the relevant parts. > > But it seems these are methods in a class, or something, so we're > > missing context. And you use self without it being an argument to the > > function. Like it's a global. > I didn't show the entire method, only what I thought was relevant to my > issue. The method is declared as: > > def generate_data(self): > > > > > > Yes, the code works. I end up with just the rows I want. > > >> Are you only concerned about speed, not fixing features? > > > Don't know what you mean by 'fixing features'. The code does what I want, > > > it just takes too long. > > >> As far as I can tell, the logic that includes the time comparison is > > >> bogus. > > > Not at all. > > >> You don't do anything there to worry about the value of tup[2], just > > >> whether some > > >> item has a nearby time. Of course, I could misunderstand the spec. > > > The data comes from a database. tup[2] is a datetime column. tdiff comes > > > from a datetime.timedelta() > > I thought that tup[1] was the datetime. In any case, the loop makes no > > sense to me, so I can't really optimize it, just make suggestions. > Yes, tup[1] is the datetime. I mistyped last night. > > >> Are you making a global called 'self' ? That name is by convention only > > >> used in methods to designate the instance object. What's the attribute > > >> self? > > > Yes, self is my instance object. self.message contains the string of > > > interest that I need to look for. > > >> Can cdata have duplicates, and are they significant? > > > No, it will not have duplicates. > > >> Is the list sorted in any way? > > > Yes, the list is sorted by tool and datetime. > > >> Chances are your performance bottleneck is the doubly-nested loop. You > > >> have a list comprehension at top-level code, and inside it calls a > > >> function that also loops over the 600,000 items. So the inner loop gets > > >> executed 360 billion times. You can cut this down drastically by some > > >> judicious sorting, as well as by having a map of lists, where the map is > > >> keyed by the tool. > > > Thanks. I will try that. > > So in your first loop, you could simply split the list into separate > > lists, one per tup[0] value, and the lists as dictionary items, keyed by > > that tool string. > > Then inside the determine() function, make a local ref to the particular > > list for the tool. > >recs = messageTimes[tup[0]] > I made that change ant went from taking over 2 hours to 54 minutes. A > dramatic improvement, but still not adequate for my app. > > Instead of a for loop over recs, use a binary search to identify the > > first item that's >= date_time-tdiff. Then if it's less than > > date_time+tdiff, return True, otherwise False. Check out the bisect > > module. Function bisect_left() should do what you want in a sorted list. > Didn't know about bisect. Thanks. I thought it would be my savior for sure. > But unfortunaly when I added that, it blows up with out of memory. The out of memory error had nothing to do with using bisect. I had introduced a typo that I really though would have caused a variable referenced before assignment error. But it did not do that, and instead somehow caused all the memory in my machine to get used up. When I fixed that, it worked really well with bisect. The code that was taking 2 hours was down to 20 minutes, and even better, a query that was taking 40 minutes was down to 8 seconds. Thanks very much for all your help. > This was the code I had: > > times = messageTimes[tup[0]] > > le = bisect.bisect_right(times, tup[1]) > > ge = bisect.bisect_left(times, tup[1]) > > return (le and tup[1]-times[le-1] <= tdiff) or (ge != len(times) and > times[ge]-tup[1] <= tdiff) > > > > > >>> cdata[:] = [tup for tup in cdata if determine(tup)] > > > > > > >> As the code exists, there's no need to copy the list. Just do a simple > > > >> bind. > > > > > > > This statement is to remove the items from cdata that I don't want. I > > > don't know what you mean by bind. I'm not familiar with that python > > > function. > > > > > > Every "assignment" to a simple name is really a rebinding of that name. > > > cdata = [tup for tup in cdata if determine(tup)] > > > > > > will rebind the name to the new object, much quicker than copying. If > > > this is indeed a top-level line, it should be equivalent. But if in > > > fact this is inside some other function, it may violate some other > > > assumptions. In particular, if there are other names for the same > >
Re: Brython - Python in the browser
> The interpreter, though, will be more than happy to treat that as a > comparison if the LHS is not the type that you think it is. For > example, maybe you've added it to a string at some point, and now it's > a string instead of an element. I guess that since doc is made a > keyword, that probably couldn't happen in this example, but it could > happen when trying to add child nodes to other nodes. Unsurprisingly, the translation engine in Brython transforms x <= y into x.__le__(y) If x is a string, then __le__ means of course "lesser or equal" so y can only be a string, otherwise an exception is raised ; this is similar to trying to add a child node to a text node in the DOM > By the way, what is Brython actually doing when you append a child to > the document itself like that? Usually I would expect a div to be > appended to the body or to another div. The above looks like it would > attach the new div as a sibling of the html element. Or is it just > calling document.write()? dom_elt <= obj actually adds one or several DOM nodes (it depends of the class of obj) to the DOM node represented by dom_elt. It's difficult to explain all the cases here, you would have to take a look at the code in py_dom.js, but <= and + work on the DOM tree, there is no document.write anywhere -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Fri, Dec 21, 2012 at 1:59 PM, Pierre Quentel wrote: >> By the way, what is Brython actually doing when you append a child to >> the document itself like that? Usually I would expect a div to be >> appended to the body or to another div. The above looks like it would >> attach the new div as a sibling of the html element. Or is it just >> calling document.write()? > > dom_elt <= obj actually adds one or several DOM nodes (it depends of the > class of obj) to the DOM node represented by dom_elt. It's difficult to > explain all the cases here, you would have to take a look at the code in > py_dom.js, but <= and + work on the DOM tree, there is no document.write > anywhere Thanks, I found my answer in the source: doc <= element basically calls document.body.appendChild(element) -- http://mail.python.org/mailman/listinfo/python-list
Scrapy/XPath help
Hello all. I'm new to Python, but have been playing around with it for a few weeks now, following tutorials, etc. I've spun off on my own and am trying to do some basic web scraping. I've used Firebug/View XPath in Firefox for some help with the XPaths, however, I still am receiving errors when I try to run this script. If you could help, it would be greatly appreciated! from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from cbb_info.items import CbbInfoItem, Field class GameInfoSpider(BaseSpider): name = "game_info" allowed_domains = ["www.sbrforum.com"] start_urls = [ 'http://www.sbrforum.com/betting-odds/ncaa-basketball/', ] def parse(self, response): hxs = HtmlXPathSelector(response) toplevels = hxs.select("//div[@class='eventLine-value']") items = [] for toplevels in toplevels: item = CbbInfoItem() item ["teams"] = toplevels.select("/span[@class='team-name'/text()").extract() item ["lines"] = toplevels.select("/div[@rel='19']").extract() item.append(item) return items -- http://mail.python.org/mailman/listinfo/python-list
Re: Scrapy/XPath help
You might have better luck if you share the python make, version, os, error message, and some unit tests demonstrating what you expect. On Fri, Dec 21, 2012 at 3:21 PM, Always Learning wrote: > Hello all. I'm new to Python, but have been playing around with it for a few > weeks now, following tutorials, etc. I've spun off on my own and am trying to > do some basic web scraping. I've used Firebug/View XPath in Firefox for some > help with the XPaths, however, I still am receiving errors when I try to run > this script. If you could help, it would be greatly appreciated! > > from scrapy.spider import BaseSpider > from scrapy.selector import HtmlXPathSelector > from cbb_info.items import CbbInfoItem, Field > > class GameInfoSpider(BaseSpider): > name = "game_info" > allowed_domains = ["www.sbrforum.com"] > start_urls = [ > 'http://www.sbrforum.com/betting-odds/ncaa-basketball/', > ] > > def parse(self, response): > hxs = HtmlXPathSelector(response) > toplevels = hxs.select("//div[@class='eventLine-value']") > items = [] > for toplevels in toplevels: > item = CbbInfoItem() > item ["teams"] = > toplevels.select("/span[@class='team-name'/text()").extract() > item ["lines"] = toplevels.select("/div[@rel='19']").extract() > item.append(item) > return items > -- > http://mail.python.org/mailman/listinfo/python-list -- Grant Rettke | ACM, AMA, COG, IEEE gret...@acm.org | http://www.wisdomandwonder.com/ Wisdom begins in wonder. ((λ (x) (x x)) (λ (x) (x x))) -- http://mail.python.org/mailman/listinfo/python-list
Re: Scrapy/XPath help
Sorry about that. I'm using Python 2.7.3, 32 bit one Windows 7. The errors I get are >>File >>"C:\python27\lib\site-packages\scrapy-0.16.3-py2.7.egg\scrapy\selector\lxmlsel.py", >> line 47, in select >>raise ValueError("Invalid XPath: %s" % xpath) >>exceptions.ValueError: Invalid XPath: /span[@class='team-name'/text() Ultimaly, I expect it to gather the team name in text, and then the odds in one of the columns in text as well, so I can then put it into a .csv -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Sat, Dec 22, 2012 at 3:36 AM, Pierre Quentel wrote: > >> Hmm. So when that gets added into a DIV, it has to get parsed for >> tags? How does this work? This seems very odd. I would have expected >> it to remain as DOM objects. > > In DIV(child) : > - if child is a string, integer or float, a text node is added (addChild) to > the DIV element, with the string value of child > - if child is another DOM element (as in DIV(B('foo'))) then this element is > added to the DIV element Meaning that: doc <= ' will add literal text, not a paragraph object, right? That's definitely what I would expect. > doc <= 'blah blah x > It will add a text node to the document, with the string 'blah blah x followed by 'True!' in bold characters This is where it's getting confusing. My expectation of this is that it adds a text node with the literal text, followed by a bold node with its child text. This operation should never involve the parsing of HTML tags, as the document structure is all there in the code. So it ought to be a DOM object, not a text string, that gets <='d onto doc (is <= a verb now?). That means the result of the addition has to be a DOM object, not a text string; but you said that adding a string to a B object converts the object to a string and concatenates the strings. Do you see now what I mean about the API being difficult to explain? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Fri, Dec 21, 2012 at 3:52 PM, Chris Angelico wrote: > On Sat, Dec 22, 2012 at 3:36 AM, Pierre Quentel > wrote: >> >>> Hmm. So when that gets added into a DIV, it has to get parsed for >>> tags? How does this work? This seems very odd. I would have expected >>> it to remain as DOM objects. >> >> In DIV(child) : >> - if child is a string, integer or float, a text node is added (addChild) to >> the DIV element, with the string value of child >> - if child is another DOM element (as in DIV(B('foo'))) then this element is >> added to the DIV element > > Meaning that: > doc <= ' > will add literal text, not a paragraph object, right? That's > definitely what I would expect. > >> doc <= 'blah blah x> >> It will add a text node to the document, with the string 'blah blah x> followed by 'True!' in bold characters > > This is where it's getting confusing. My expectation of this is that > it adds a text node with the literal text, followed by a bold node > with its child text. This operation should never involve the parsing > of HTML tags, as the document structure is all there in the code. So > it ought to be a DOM object, not a text string, that gets <='d onto > doc (is <= a verb now?). That means the result of the addition has to > be a DOM object, not a text string; but you said that adding a string > to a B object converts the object to a string and concatenates the > strings. > > Do you see now what I mean about the API being difficult to explain? In my playing around with it just now, the addition doesn't seem to actually return a string. I typed this script into the test console: log('hello ' + B('world')) and clicked Run, and the result was: [object Object] whereas if I just try to log a plain string literal, it actually prints out the string. Somewhat disturbingly, this also gives the [object Object] result: log(str('hello ' + B('world'))) In Brython, the str builtin does not return strings? -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
Héllo, > > doc <= 'blah blah x I will surely backlog latter or some crytologist from the futur will do and he will surely agree about the fact something strange happened around december 2012. Sorry for that, that's me trying to be funny. Last time I checked DOM manipulation is not the primary way for js devs to do DOM manipulation anymore, or is it ? Javascript template engines do DOM manipulation but this is almost invisible for the user so whatever the API, I expect this will be minor, if not completly overlooked by users of Brython. I could even argue more that for cross-language knowledge sharing the low level API should be the same but no. Brython is a very good idea. I failed at something similar except I took the pyjs route and focused on classes (functions being callable class objects) and "bindings" which is IMO more interessant than list comprehensions, operator-overloading and plain functions. The idea was that bindings will be even more important than in CPython because most of the hard work for browser compatibility was already done and optimised by the JS community. I may completly be off beat but the vision was that Python would be for framework and application developpement and not for utility libraries that would replace jQuery, SocketIO, Mediator.js History.js or any template engine hence the focus on classes and meta-programming. What is the plan regarding this issues in Brython ? Regards, Amirouche -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Fri, Dec 21, 2012 at 4:45 PM, Ian Kelly wrote: > In Brython, the str builtin does not return strings? Oh, and repr is just a synonym of str, which makes it useless. -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Fri, Dec 21, 2012 at 4:45 PM, Ian Kelly wrote: > In my playing around with it just now, the addition doesn't seem to > actually return a string. >From the code, it appears that adding two nodes together *actually* returns a $AbstractTag object, which seems to be just a container for a list of child nodes with no parent, that automagically gets removed from the hierarchy when appended to another node. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pigeon Computer 0.1 Initial (BETA) release
Héllo, 2012/12/22 Simon Forman > Pigeon Computer 0.1 Initial (BETA) release > > Summary > > > The Pigeon Computer is a simple but sophisticated system for learning > and exploring the fundamentals of computers and programming. > > It is written to support a course or class (as yet pending) to learn > programming from the bit to the compiler. > > There is a DRAFT manual and a Pigeon User Interface that includes: > > * An assembler for the ATmega328P micro-controller. > * A polymorphic meta-compiler. > * Forth-like firmware in assembly. > * Simple high-level language for assembly control structures. > * A virtual computer that illustrates Functional Programming. > > Source code is released under the GPL (v3) and is hosted on Github: > https://github.com/PhoenixBureau/PigeonComputer > > The manual is online in HTML form here: > http://phoenixbureau.github.com/PigeonComputer/ > > Mailing list: > https://groups.google.com/d/forum/pigeoncomputer > > It has been tested on Linux with Python 2.7, YMMV. > > I'm releasing it now because it's basically done even though it needs > polish and I'm just too excited about it. Happy End of the World Day! > > This sound fun! Could you elaborate a bit in simple words what it is and what's the common way to interact with the system ? What do you mean by « Forth-like firmware in assembly » ? Is there a GUI ? Does it feels like being a hipster like in the '50s or before and breaking the 1 billion dollar thing ? Of course the little tutorial I stripped and read a bit gives some of the responses. Thanks Amirouche > - - - > > Whew! If you are still reading, thank you. There is a lot more to be > done and I am hoping to form classes in early January 2013. If you > are interested please email me at forman.si...@gmail.com > > You can also participate on Github and join the mailing list. > * https://github.com/PhoenixBureau/PigeonComputer > * https://groups.google.com/d/forum/pigeoncomputer > > Warm regards, > ~Simon P. Forman > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Sat, Dec 22, 2012 at 10:57 AM, Ian Kelly wrote: > From the code, it appears that adding two nodes together *actually* > returns a $AbstractTag object, which seems to be just a container for > a list of child nodes with no parent, that automagically gets removed > from the hierarchy when appended to another node. That actually makes good sense. The sum of two nodes is an ordered pair of peers, which will be added sequentially to the same parent. For this to work, *every* situation needs to be able to handle (with equal ease) a string, an $AbstractTag, or a node. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Sat, Dec 22, 2012 at 10:50 AM, Amirouche Boubekki wrote: > Last time I checked DOM > manipulation is not the primary way for js devs to do DOM manipulation > anymore, or is it ? Javascript template engines do DOM manipulation but this > is almost invisible for the user... Not sure how most of the world works, but I write using the DOM. There's little point using jquery etc when what you're doing is really simple - which, for me, it is. So I'm probably not representative. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Brython - Python in the browser
On Fri, 21 Dec 2012 12:25:01 +0100, Stefan Behnel wrote: > If that's your intention, then instead of coming up with something > totally new, unpythonic and ugly, why not take the normal Python route > and implement a subset of the ElementTree API? Yo mean something old, unpythonic and ugly? :-P -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Second try: non-blocking subprocess pipe and Tkinter in 2.7
On 12/21/2012 10:52 AM, Kevin Walzer wrote: Yesterday I posted a question about keeping a Tkinter GUI during a long-running process, i.e. reading data from a pipe via the subprocess module. I think that question did not quite get at the heart of the issue because it assumed that Python, like Tcl which underlies Tkinter, supports non-blocking, asynchronous reading out of the box. Apparently it does not. There is currently the asyncore module, but I don't know that anyone really likes it. So, my question is hereby revised as such: how can I implement a non-blocking read of a subprocess pipe that can write data to the Tkinter text widget in an manner that does not cause the GUI to lock up? Interesting question. Guido is currently, with help from many others with async experience, working on a replacement for asyncore. PEP 3156 - Asynchronous IO Support Rebooted http://python.org/dev/peps/pep-3156/ You can read the pep if you want, but it includes a generalized event loop interface. The prototype (partial) implementation includes (or will) a default event loop. However, the intention is that it can be replaced by (or maybe work with) adapters for existing event loops, including that of gui frameworks. Being able write a tk loop adapter and easily add io events and handlers to work along side with tk key and mouse events and write to a widjet should be an interesting test of the new framework. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Scrapy/XPath help
On 12/21/2012 04:58 PM, Always Learning wrote: > Sorry about that. I'm using Python 2.7.3, 32 bit one Windows 7. > > The errors I get are > >>> File >>> "C:\python27\lib\site-packages\scrapy-0.16.3-py2.7.egg\scrapy\selector\lxmlsel.py", >>> line 47, in select >>> raise ValueError("Invalid XPath: %s" % xpath) >>> exceptions.ValueError: Invalid XPath: /span[@class='team-name'/text() > Ultimaly, I expect it to gather the team name in text, and then the odds in > one of the columns in text as well, so I can then put it into a .csv Why are you displaying only the last 3 lines of the error message? Unless your source code is lxmlsel.py, there are other stack levels above this one. (I can't help, but I'm trying to save some time for someone who can) -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: help with making my code more efficient
On 12/21/2012 03:36 PM, larry.mart...@gmail.com wrote: > On Friday, December 21, 2012 10:57:19 AM UTC-7, larry@gmail.com wrote: >> >> Didn't know about bisect. Thanks. I thought it would be my savior for sure. >> But unfortunaly when I added that, it blows up with out of memory. > The out of memory error had nothing to do with using bisect. I had introduced > a typo that I really though would have caused a variable referenced before > assignment error. But it did not do that, and instead somehow caused all the > memory in my machine to get used up. When I fixed that, it worked really well > with bisect. The code that was taking 2 hours was down to 20 minutes, and > even better, a query that was taking 40 minutes was down to 8 seconds. > > Thanks very much for all your help. > > Congratulations. But you're not done. A fourfold improvement isn't nearly as much as I'd expect. When you go from a n-squared algorithm to an n-log-n, for n of 600k, I'd be disappointed in less than a 100 fold improvement. Assuming we're talking just about time spent in the cdata = list-comprehension list. It's also probably possible to simplify, and get some speedup from other parts of the code other than that one loop. For example, if the bisect is really working right, it's probably unnecessary to even copy the original cdata. You said it was sorted. So bisect it directly, and skip the messageTimes intermediate data structure. It may not help, but i suspect it will. > >> This was the code I had: >> >> times = messageTimes[tup[0]] >> >> le = bisect.bisect_right(times, tup[1]) >> >> ge = bisect.bisect_left(times, tup[1]) >> >> return (le and tup[1]-times[le-1] <= tdiff) or (ge != len(times) and >> times[ge]-tup[1] <= tdiff) I'm stymied making further suggestions to this fragment. Without seeing the changes you apparently made to messageTimes, I can't even be sure this is equivalent. And I wonder if even looking up tup[1] is worthwhile, since your caller already knows the index in cdata. If you used cdata directly, you might not need a sort at all. I wish you could post some sample data, and identify which records are intended to be True. Obviously you could simplify, and just use ints where it's using datetimes here. But if your rule is simply accept all records that come in a cluster with no delta more than a threshold, then you don't even need any search at all. Just pass the index in, and compare the datetime with its predecessor and successor. Could we see the whole fragment as you originally had it, but with the optimizations you've done so far? The more I look at that determine() function, the more futile it seems. I just don't understand what the criteria are supposed to be. Your list-comp loops through all of cdata, and for each item, passes that item to determine(). determine() loops through a copy of cdata, checking to see if any of them is within tdiff of tup. But won't that always return True, since you'll encounter the record and compare it to itself? -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: help with making my code more efficient
On Friday, December 21, 2012 8:19:37 PM UTC-7, Dave Angel wrote: > On 12/21/2012 03:36 PM, larry.mart...@gmail.com wrote: > > > On Friday, December 21, 2012 10:57:19 AM UTC-7, larry@gmail.com wrote: > > >> > > >> Didn't know about bisect. Thanks. I thought it would be my savior for > >> sure. But unfortunaly when I added that, it blows up with out of memory. > > > The out of memory error had nothing to do with using bisect. I had > > introduced a typo that I really though would have caused a variable > > referenced before assignment error. But it did not do that, and instead > > somehow caused all the memory in my machine to get used up. When I fixed > > that, it worked really well with bisect. The code that was taking 2 hours > > was down to 20 minutes, and even better, a query that was taking 40 minutes > > was down to 8 seconds. > > > > > > Thanks very much for all your help. > > Congratulations. But you're not done. A fourfold improvement isn't > nearly as much as I'd expect. When you go from a n-squared algorithm to > an n-log-n, for n of 600k, I'd be disappointed in less than a 100 fold > improvement. Assuming we're talking just about time spent in the cdata > = list-comprehension list. > > It's also probably possible to simplify, and get some speedup from other > parts of the code other than that one loop. For example, if the bisect > is really working right, it's probably unnecessary to even copy the > original cdata. You said it was sorted. So bisect it directly, and > skip the messageTimes intermediate data structure. It may not help, but > i suspect it will. > > > > >> This was the code I had: > >> > >> times = messageTimes[tup[0]] > > >> > > >> le = bisect.bisect_right(times, tup[1]) > >> ge = bisect.bisect_left(times, tup[1]) > >> return (le and tup[1]-times[le-1] <= tdiff) or (ge != len(times) and > >> times[ge]-tup[1] <= tdiff) > > > > I'm stymied making further suggestions to this fragment. Without seeing > the changes you apparently made to messageTimes, I can't even be sure > this is equivalent. And I wonder if even looking up tup[1] is > worthwhile, since your caller already knows the index in cdata. If you > used cdata directly, you might not need a sort at all. > > I wish you could post some sample data, and identify which records are > intended to be True. Obviously you could simplify, and just use ints > where it's using datetimes here. But if your rule is simply accept all > records that come in a cluster with no delta more than a threshold, then > you don't even need any search at all. Just pass the index in, and > compare the datetime with its predecessor and successor. > > Could we see the whole fragment as you originally had it, but with the > optimizations you've done so far? The more I look at that determine() > function, the more futile it seems. I just don't understand what the > criteria are supposed to be. Your list-comp loops through all of cdata, > and for each item, passes that item to determine(). determine() loops > through a copy of cdata, checking to see if any of them is within tdiff > of tup. But won't that always return True, since you'll encounter the > record and compare it to itself? I think you're misunderstanding what I need to do. I have a set of rows from the database with tool, time, and message. The user has specified a string and a time threshold. From that set of rows I need to return all the rows that contain the user's string and all the other rows that match the tool from the matched rows and have a time within the threshold. cdata has all the rows. messageTimes has the times of all the matched messages, keyed by tool. In determine() I don't look though cdata - it gets one element from cdata and I see if that should be selected because it either matches the user's message, or it's within the threshold of one that did match. Here's my original code: # record time for each message matching the specified message for each tool messageTimes = {} for row in cdata: # tool, time, message if self.message in row[2]: messageTimes[row[0], row[1]] = 1 # now pull out each message that is within the time diff for each matched message # as well as the matched messages themselves def determine(tup): if self.message in tup[2]: return True # matched message for (tool, date_time) in messageTimes: if tool == tup[0]: if abs(date_time-tup[1]) <= tdiff: return True return False cdata[:] = [tup for tup in cdata if determine(tup)] Here's the code now: # Parse data and make a list of the time for each message matching the specified message for each tool messageTimes = defaultdict(list)# a dict with sorted lists for row in cdata: # tool, time, message if self.message in row[2]: messageTimes[row[0]].append(row[1]) # now pull out each message tha
Re: help with making my code more efficient
On 12/21/2012 11:47 PM, larry.mart...@gmail.com wrote: > On Friday, December 21, 2012 8:19:37 PM UTC-7, Dave Angel wrote: >> On 12/21/2012 03:36 PM, larry.mart...@gmail.com wrote: >> > I think you're misunderstanding what I need to do. I have a set of rows from > the database with tool, time, and message. The user has specified a string > and a time threshold. From that set of rows I need to return all the rows > that contain the user's string and all the other rows that match the tool > from the matched rows and have a time within the threshold. > > cdata has all the rows. messageTimes has the times of all the matched > messages, keyed by tool. In determine() I don't look though cdata - it gets > one element from cdata and I see if that should be selected because it either > matches the user's message, or it's within the threshold of one that did > match. > > Here's my original code: > > # record time for each message matching the specified message for each tool > messageTimes = {} > for row in cdata: # tool, time, message > if self.message in row[2]: > messageTimes[row[0], row[1]] = 1 > > # now pull out each message that is within the time diff for each matched > message > # as well as the matched messages themselves > > def determine(tup): > if self.message in tup[2]: return True # matched message > > for (tool, date_time) in messageTimes: > if tool == tup[0]: > if abs(date_time-tup[1]) <= tdiff: >return True > > return False > > cdata[:] = [tup for tup in cdata if determine(tup)] > > Here's the code now: > > ># Parse data and make a list of the time for each message matching the > specified message for each tool > messageTimes = defaultdict(list)# a dict with sorted lists > > for row in cdata: # tool, time, message > if self.message in row[2]: > messageTimes[row[0]].append(row[1]) > > # now pull out each message that is within the time context for each > matched message > # as well as the matched messages themselves > > # return true is we should keep this message > def determine(tup): > if self.message in tup[2]: return True # matched message > if seconds == 0: return False# no time context > specified > > times = messageTimes[tup[0]] # get the list of > matched messages for this tool > > le = bisect.bisect_right(times, tup[1]) # find time less than > or equal to tup[1] > ge = bisect.bisect_left(times, tup[1])# find time greater > then to equal to tup[1] > return (le and tup[1]-times[le-1] <= tdiff) or (ge != len(times) > and times[ge]-tup[1] <= tdiff) > > cdata = [tup for tup in cdata if determine(tup)] > > In my test case, cdata started with 600k rows, 30k matched the users string, > and a total of 110k needed to be returned (which is what cdata ended up with) > - the 30k that matched the string, and 80k that were within the time > threshold. > > I think the point you may have missed is the tool - I only return a row if > it's the same tool as a matched message and within the threshold. > > I hope I've explained this better. Thanks again. That is better, and the point I missed noticing before is that messageTimes is substantially smaller than cdata; it's already been filtered down by looking for self.message in its row[2]. The code was there, but I didn't relate. Remember I was bothered that you didn't look at tup[2] when you were comparing for time-similarity. Well, you did that implicitly, since messageTimes was already filtered. Sorry about that. That also lowers my expectations for improvement ratio, since instead of 600,000 * 600,000, we're talking "only" 600,000 * 30,000, 5% as much. So now my expectations are only 4:1 to 10:1. Still, there's room for improvement. (1) You should only need one bisect in determine, and (2) if you remember the last result for each tool, you could speed that one up some. (1) Instead of getting both and le and a ge, get just one, by searching for tup[1]-tdiff. Then by comparing that row's value against tup[1]+tdiff, you can return immediately the boolean, the expression being about half of the one you've now got. (2) Make a dict of ints, keyed by the tool, and initialized to zero. Call that dict "found." Each time you do a bisect, specify a range starting at found[tool]. Similarly, store the result of the bisect in found[tool]. This should gradually restrict the range searched by bisect, which COULD save some time. It works because everything's sorted. Naturally, make these changes independently, and time the changes. In particular, it's possible that #2 will degrade performance instead of improving it. But #1 should double performance, pretty close. I hope these were clear enough. I don't want to write the cha