Re: FYI: Micro Python running on kickstarter pyBoard project, now shipping
On Thursday, 23 October 2014 22:12:10 UTC+1, sohca...@gmail.com wrote: On Thursday, October 23, 2014 10:07:26 AM UTC-7, jkn wrote: Hi all I haven't heard in mentioned here, but since I saw one of the boards today thought I'd pass on the news: The Kickstarter 'MicroPython' project, which has a tiny 'pyboard' (only a couple of sq.inches in size) with a processor running 'a complete re-write of the Python (version 3.4) programming language so that it fits and runs on a microcontroller' is now shipping. https://micropython.org/ Looks nice; I have no connection but will be getting one myself to play with... Cheers J^n Is there any particular reason to get one of these when I can get a Raspberry Pi which is faster, has more memory, and a bundle of other features? I mean, the idea seems cool and all, but I'm trying to understand why I would want to spend the ~$45 on something like that when a ~$35 Raspberry Pi will do everything and more, and do it faster. They are quite different devices: * The Raspberry Pi is a low-power general purpose computer designed specifically for education purposes. It just so happens that it's ideal for geek experimentation as well... * MicroPython is an optimised version of Python 3 running on a micro-controller board, designed specifically for controlling 'things' (eg robots). Doing what it is designed for, it will run far faster and use far less power than a Pi, but cannot do any of the general computing things a Pi can do, for example it has no means of editing programs for MicroPython, you have to do this on, say, your PC and download them to the MicroPython board. It won't do *any* of the other things you can do with a Pi - watch videos, browse the net, etc etc, but what it can do it will do faster and better. If you want a low-power, cheap, computer to play with and learn from, get a Pi. If you want a nifty micro-controller you can program in Python, buy a MicroPython board. John -- -- https://mail.python.org/mailman/listinfo/python-list
Re: PyEval_EvalCodeEx return value
On Sep 20, 11:34 am, Mateusz Loskot mate...@loskot.net wrote: Hi, I'm trying to dig out details about what exactly is the return value the of PyEval_EvalCodeEx function in Python 3.x The documentation is sparse, unfortunately. Perhaps I'm looking at wrong function. My aim is simple, I need to execute Python code using Python interpreter embedded in my C++ application. The Python code is a simple script that always returns single value. For example: #! /usr/bin/env python def foo(a, b): return a + b f = foo(2, 3) But, f can be of different type for different script: one returns numeric value, another returns a sequence, so the type is not possible to be determined in advance. I know how to capture Python stdout/stderr. I also know how to access the f attribute using PyObject_GetAttrString and then I can convert f value to C++ type depending on PyObject type. However, I guess there shall be a way to access f value directly from PyEval_EvalCode return object: PyObject* evalRet = ::PyEval_EvalCode(...); But, I can't find any details what the evalRet actually is. I assume that you have read the documentation at http://docs.python.org/c-api/veryhigh.html, and I agree that it's sparse, but the entry for the next entry, PyEval_EvalCodeEx, tells you a little more, as does that for PyEval_EvalFrameEx. Obviously, it's returning a pointer to a PyObject, and Looking at the source code, that may be NULL, to throw an exception, or an execution frame, or a generator,etc, etc, depending on the code it's been given. I guess that you should be able to inspect the PyObject to see what it is. What I'm wondering is, why are you eval-ing code ? A favourite device of C programmers coming to Python (and mea culpa in the past), it's fraught with potential problems and even security risks, and is difficult to debug, and maybe you should be using introspection instead. And maybe you should be working in Python, and not C++ at this point, do the dynamic stuff in the language best suited, and then return to C+ + when needed. Best wishes, John -- Any pointers would be helpful. Best regards, -- Mateusz Loskot,http://mateusz.loskot.net Charter Member of OSGeo,http://osgeo.org Member of ACCU,http://accu.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Syntactic sugar for assignment statements: one value to multiple targets?
On Aug 3, 2:45 am, gc gc1...@gmail.com wrote: Hi everyone! Longtime lurker, hardly an expert, but I've been using Python for various projects since 2007 and love it. I'm looking for either (A) suggestions on how to do a very common operation elegantly and Pythonically, or (B) input on whether my proposal is PEP-able, assuming there's no answer to A. (The proposal is sort of like the inverse of PEP 3132; I don't think it has been proposed before, sorry if I missed it.) Anyway, I frequently need to initialize several variables to the same value, as I'm sure many do. Sometimes the value is a constant, often zero; sometimes it's more particular, such as defaultdict(list). I use dict() below. Target lists using comma separation are great, but they don't work very well for this task. What I want is something like a,b,c,d,e = *dict() where * in this context means something like assign separately to all. I'm not sure that * would the best sugar for this, but the normal meaning of * doesn't seem as if it would ever be valid in this case, and it somehow feels right (to me, anyway). Statements fitting the form above would get expanded during parsing to a sequence of separate assignments (a = dict(); b = dict(); c = dict() and so forth.) That's all there is to it. Compared to the patterns below, it's svelte, less copy-paste-y (so it removes an opportunity for inconsistency, where I remember to change a-d to defaultdict(list) but forget with e), and it doesn't require me to keep count of the number of variables I'm initializing. This would update section 6.2 of the language reference and require a small grammar expansion. But: Is there already a good way to do this that I just don't know? Below, I compare four obvious patterns, three of which are correct but annoying and one of which is incorrect in a way which used to surprise me when I was starting out. # Option 1 (separate lines) # Verbose and annoying, particularly when the varnames are long and of irregular length a = dict() b = dict() c = dict() d = dict() e = dict() # Option 2 (one line) # More concise but still pretty annoying, and hard to read (alternates variables and assignments) a = dict(); b = dict(); c = dict(); d = dict(); e = dict() # Option 3 (multiple target list: this seems the most Pythonic, and is normally what I use) # Concise, separates variables from assignments, but somewhat annoying; have to change individually and track numbers on both sides. a,b,c,d,e = dict(),dict(),dict(),dict(),dict() # Option 4 (iterable multiplication) # Looks better, and if the dict() should be something else, you only have to change it once, but the extra brackets are ugly and you still have to keep count of the targets... a,b,c,d,e = [dict()] * 5 # and it will bite you... a[1] = 1 b {1: 1} id(a) == id(b) True # Gotcha! # Other forms of 4 also have this behavior: a,b,c,d,e = ({},) * 5 a[1] = 1 b {1: 1} Alternatively, is there a version of iterable multiplication that creates new objects rather than just copying the reference? That would solve part of the problem, though it would still look clunky and you'd still have to keep count. Any thoughts? Thanks! I hesitate to put this forward, as it smells and is probably considered bad practice, but heh! for char in 'abcdefg' : globals()[ char ] = dict() does what you wanted. Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Docstrings and class Attributes
On Aug 9, 1:36 am, Ben Finney ben+pyt...@benfinney.id.au wrote: Ethan Furman et...@stoneleaf.us writes: So if property docstrings are so hard to get to, what's the point in having them? Why would you expect there be a special point to them? Men, like all primates of any sex, have nipples. Properties, like any function in Python, have docstrings. So are you saying that men's nipples are pointless? You could be correct, except in cold weather maybe. John -- They're an accident of the history that led to their implementation, and of the pre-existing parts that they're built from. There doesn't need to be a point to them (though they might be useful for reasons incidental for the reasons they exist). -- \ “I filled my humidifier with wax. Now my room is all shiny.” | `\ —Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: De-tupleizing a list
On Apr 26, 4:28 am, Gnarlodious gnarlodi...@gmail.com wrote: I have an SQLite query that returns a list of tuples: [('0A',), ('1B',), ('2C',), ('3D',),... What is the most Pythonic way to loop through the list returning a list like this?: ['0A', '1B', '2C', '3D',... -- Gnarlie If you want to handle a list of tuples where each tuple could have *more* than one element, one solution would be: L = [(1, 2), (2, 3, 4), (5,), (6, 7, 8, 9, 0)] tuple([ x for t in L for x in t ]) (1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 0) John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: What do I need to know in order to write a web application in python?
On Mar 5, 7:42 pm, geremy condra debat...@gmail.com wrote: On Sat, Mar 5, 2011 at 3:49 AM, ErichCart ErichCart erichc...@gmail.com wrote: Visual Python seems to be exactly what I want. But it doesn't seem very popular. Perhaps it means that there are not many people who will be able to help if I have problems with it. Also judging by the amount of ads at visualpython.org, it also doesn't seem very serious. I looked into pyGTK, and I found something called Glade, which seems to be something similar to visual python. The latest version of Glade was released just this month, so it seems to be actively developed. Regarding Boa constructor, it is very old, isn't it? The latest news from this project date to the end of 2006. I don't expect it to support python 3 any time soon. So, Glade, is this what everybody uses? I mean programmers don't just use text editors to make GUI applications, do they? Yes, they do. It isn't that bad once you get used to it, Agreed. and it beats the snot out of trying to maintain the insensible gibberish that some of the autogen tools put out. I have a lot of experience with Qt Designer, I don't know about any of the other tools: 1. Qt Designer produces sensible well-formed XML, not gibberish. 2. The whole point of the tool is that you should _never_ have to edit the code it produces - if you need to extend ui designs, you do this by sub- classing. On a side note, you should check out pygui[0]- very, very nice GUI toolkit. Yay, looks good. Thanks, Greg. John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to gain root privileges
On Feb 17, 3:32 pm, GSO gso...@yahoo.co.uk wrote: I'm having a awfully hard time figuring out why a home CCTV application might need privilege at all. Are you sure you really need privilege? It sounds to me like there may be some larger design issues mandating the need for privilege when it's not really necessary. A user login should only able to view the footage. It's important that a user login cannot delete any images/video. This much can be done with ACL - but having said that a user login would still be able to copy the images/video, so ACL would work but is not ideal - I could prevent copying with raised privileges. If I were to allow a user to archive footage without using an admin login then that would require ACL with write access, which is out of the question. Uour origianl questions was: I'm sure this question is as old as time, but what is the best way to gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk v2.18.9, on RHEL6.) To which I would say, redesign the app so that you do not need root privileges. There has been plentiful advice in this thread already, but I would add: Now that you've said what the requirement is, why don't you work with the OS instead of against it? Linux and, to a lesser extent, Unix have the ability to set 'setuid', 'setgid' and 'sticky' bits on a directory's permissions, so if, for example the setgid bit is set, then all files created in that directory will belong to the group owning the directory. The sticky bit ensures that only the super user or the file owner may delete a file in the directory. See the chmod manual entry - man chmod - for details. You would need to be root to set this up initially. I think that using this mechanism, together with an appropriate umask or mode setting, should satisfy your requirements, without potential security breakages. Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Which is the best book to learn python
On Jan 25, 8:56 am, Mark Summerfield l...@qtrac.plus.com wrote: On Jan 24, 5:09 pm, santosh hs santosh.tron...@gmail.com wrote: Hi All, i am beginner to python please tell me which is the best available reference for beginner to start from novice If you want to learn Python 3 and have some prior programming experience (in any modern procedural or object oriented language), you might find Programming in Python 3 (http://www.qtrac.eu/py3book.html) to be a good choice. (I'm biased though since I wrote it;-) You may be biased, but you're right :-) Nice book. John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: getdefaultencoding - how to change this?
On Jan 20, 4:46 pm, Robert Kern robert.k...@gmail.com wrote: snips Instead, you want to use an encoding declaration in each file: http://docs.python.org/reference/lexical_analysis.html#encoding-decla... All that this does is tell the interpreter how the source file is encoded, it does not affect default encodings etc. John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: getdefaultencoding - how to change this?
To answer the OP's original question: On Jan 20, 2:31 pm, Helmut Jarausch jarau...@skynet.be wrote: Hi, I've searched the net but didn't find the information I need. Using Python-2.7.1, I know, I can't modify defaultencoding at run time. I think you can. There is a function setdefaultencoding in the sys module, but at startup when site.py runs the function gets deleted after it has been used, because as others have said it is a *bad* idea to change the default encoding (although I *think* changing it to utf8 should cause no harm). so if you reload sys, setdefaultencoding() becomes available again, and you can use it, with all the caveats mentioned: import sys reload(sys) sys.setdefaultencoding( 'utf-8' ) This works on a Unicode build of Python only. As has been said, you can change the default encoding in site.py, but this means that it gets changed for everyone/every Python program on the system, using setdefaultencoding() as above only changes it for the running program, and hopefully the change will have been made by someone who knows what they are doing and is aware of the possible consequences. Python even ignores export PYTHONIOENCODING=ISO8859-1 locale.getdefaultlocale()[1] returns 'ISO8859-1' still sys.stdout is using the ascii codec. How can I recompile Python (itself) to change this to iso8859-1 ? You don't need to, nor should you. (My favourite editor cannot be told to use unicode.) Maybe you need a new editor. scite works well with Python, and is cross-platform. John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: __pycache__, one more good reason to stck with Python 2?
Hi You have disturbe my slumber, Steven ;-) On Jan 19, 2:42 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Tue, 18 Jan 2011 00:58:14 -0800, jmfauth wrote: It is now practically impossible to launch a Python application via a .pyc file. When has that ever been possible? .pyc files are Python byte-code. You can't run them directly using Python (except via the import machinery), you can't run them as a script, they're not machine code. Unless you write a wrapper to import the file as a module, you can't directly execute .pyc files. Not true. 'python myprog.pyc' has worked for as long as I have been using Python. Whether or not it is a good idea is another matter. Probably it would be best to check what you're saying before posting such a bald assertion, even though you were 110% sure of what you were saying. I've been there, done that, bought the tee-shirt. Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: how to scrutch a dict()
On Oct 21, 5:40 am, Paul Rubin no.em...@nospam.invalid wrote: Phlip phlip2...@gmail.com writes: def _scrunch(**dict): result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says throw away every item in a dict if the Value is None. Are there any tighter or smarmier ways to do that? Python does so often manage maps better than that... As James has suggested, you can 'clean the dict in place (as it's mutable), you don't have to return a whole new object. Untested: def _scrunch(**kwargs): return dict(k,v for k,v in kwargs.iteritems() if v is not None) Note: it's best not to use dict as a parameter name, Yes, likewise with any other builtin; if you use pychecker and/or pylint routinely, they would warn you about this. since it is a built in function (dictionary constructor). I don't think so: type(dict) type 'type' So you're not running a function, but creating an instance of a dict. Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: System idle time under Linux
On Sep 29, 7:36 pm, Hugo Léveillé hu...@fastmail.net wrote: Good point One I am looking for, is time since last user mouse or keyboard action. So I guess I am looking for the exact same thing a screensaver is looking for The command who -Hu). will give you idle time for each logged-in user ( H - print headers; u - list users ) and you could run this command via subprocess, then read and parse its output. Alternatively you could parse the same file(s) as who - I think it reads /var/run/utmp - but that would be a lot more work, as it is a binary file (run man utmp to see its format, use the struct module to decode) Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Macros's Not the Power in OOo they should be ?
On Sep 23, 10:12 am, Boris Borcic bbor...@gmail.com wrote: Lawrence D'Oliveiro wrote: flebber wrote: Has anyone had much success with python macro's. Or developing powerful macro's in an language? I did an application for my own use recently, involving automatically generating invoices in editable OOWriter format from my billing database. I gave up on all the PyUNO stuff, and used ODFPY instead—so much easier to generate ODF directly, without having to go through OpenOffice code. And OpenOffice has been able to open the results for final tweaking just fine. A nice package to manipulate Ooo text documents with python is the pod module of the appy framework. It uses the same approach with a twist. One of our guys, David Chan, has done something you may find useful, 'OpenDocMill': http://www.troi.org/opendoc-mill.html We use it to produce some quite complicated documents, for example Engineering Reports, Invoices, Certificates. Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Using String Methods In Jump Tables
On Aug 20, 12:27 am, Tim Daneliuk tun...@tundraware.com wrote: Problem: Given tuples in the form (key, string), use 'key' to determine what string method to apply to the string: key operation --- l lower() u upper() t title() ... Commentary: Easy, right? Well ... except that I would really, really like to avoid cascading ifs or eval based solutions. I'd like to implement this as a jump table dictionary: jt = { 'l' : lower_function reference, 'u' : upper_function reference, ... } So I could then do this: string = jt[key](string) But There's A Problem: I tried to do this: jt = {'l', .lower, 'u', .upper, ... } You can get away with this because all string objects appear to point to common method objects. That is,: id(a.lower) == id(b.lower) HOWEVER, you cannot then do this: string = jt[key](string) Why? Because the methods of a string, while common to all strings *do not accept an arg*. They are implemented to know about the string instance they belong to (that contains them). (Forgive me here, I am probably not using some of the OO arcana properly...) I realize that the string module has many of the same functions that are found as methods on strings. But it doesn't have all of them - the .title() method is notably absent. If this were not the case, I could happily do things like 'l' : string.lower and my approach would work fine. Even if I could use the string module, I'd still be curious though: How do you get a reference to a method found in one object instance, but actually apply it to another instance of the same class? I'm guessing this may involve fiddling with some of the internal __ variables, but I'm not quite sure where to go next. As I said, I know I could do this as a set of cascading ifs or even as an eval, but I'm loathe to use such approaches. I like jump tables as a structural construct because they are easy to understand and maintain. I also realize that what I'm asking may be violating some deeply held notion of OO purity, but, well, now I'm just curious if there is a way to do this I think the solution to what you are asking for is to use getattr(), eg: ops={'u':'upper','l':'lower'} s='hello world' getattr( s, ops['u'] )() 'HELLO WORLD' For info on getattr() see: http://docs.python.org/library/functions.html#getattr or http://effbot.org/zone/python-getattr.htm Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: deprecated string module issue
On Jun 25, 11:14 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Fri, 25 Jun 2010 16:31:17 -0500, GrayShark wrote: Why the rudness Terry Jan Reedy? Get up on the wrong side of the bed? Or worse luck, no one on the other side to create a wrong side? I see only one person being rude here, and that's you. True. Terry made the very reasonable observation that you would serve the community, and thank us, by posting a bug report to pylint, rather than just ignoring it, and you respond with a totally bogus accusation of rudeness followed by comments about what you imagine Terry's personal life is like. Except that it is not a bug, but a configuration issue: pylint's behaviour is governed by its config file, pylintrc. In the [IMPORTS] section, there is a line: deprecated-modules=regsub,string,TERMIOS,Bastion,rexec So if you edit this line to remove string, the warning will not be made. Although I find that most of the default pylint settings are eminently sensible, and wouldn't remove string from the deprecated modules myself. I find pylint (and pychecker) to be invaluable. Thanks to our friends at Logilab for pylint, and to Neal Norwitz for pychecker! As for your guess as to why pylint haven't fixed the ticket similar to this issue: As to your comment about Logilab's pylint. I've seen a ticket similar to this from three months back. I assume they're not fixing it because if you review 'string' via pydoc you'd read this: [...] Or possibly the ticket has just been missed, and all it needs is a comment made saying This has bitten me too and somebody will attend to it. Or not -- who knows? But making *assumptions* that a pylint bug won't be fixed because of the docstring in the string module is foolish. Unless the bug is marked as Won't fix, the safe assumption is that it hasn't been worked on YET. Like I said, it isn't a bug... Best wishes, John -- EuroPython is coming! http://europython.eu 17th-24th July 2010, Birmingham, UK. -- http://mail.python.org/mailman/listinfo/python-list
Re: Docstrings considered too complicated
On Feb 24, 8:23 pm, Andreas Waldenburger use...@geekmail.invalid wrote: Hi all, a company that works with my company writes a lot of of their code in Python (lucky jerks). I've seen their code and it basically looks like this: Function that does stuff def doStuff(): while not wise(up): yield scorn Now my question is this: How do I kill these people without the authorities thinking they didn't deserve it? A good way to control Python contractors is (given that firstly there are functional specifications to comply with, and tests to pass) is to impose the following condition: that all code delivered must reach a score of (say) 9.5 or more when checked by pylint and pylint could be the way to demonstrate the problems to the 'authorities'. If payment depends on such a measure, things will change quite quickly. John -- /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
What happened to pyjamas?
It appears that, in trying to cut down spm, somone chahnged a DNS entry and screwed it up : it shouldbe back before long. John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: [pyconuk] pyweek is happening august 02 - august 09
Hello All, On 04/08/07, Laura Creighton [EMAIL PROTECTED] wrote: 00:00 UTC 2007-09-02 to 00:00 UTC 2007-09-09 exactly. See www.pyweek.org PyconUK is happening. http://www.pyconuk.org/ 8th and 9th September. This means that those of us who generally do not see each other but are going to PyconUK could put together an entry and then sprint together on it before PyCon UK. There would be this terrible torment -- do I attend the con or get my game to work -- but it is still the best chance some of us have to work together yet. Talk to me if you are interested in maybe making a PyconUK pygame team. I think that this could be a lot of fun. Sign up on www.pyweek.org if you think so, as well. But mail me. John -- assuming we want to meet up _before_ PyConUK -- can that work? Yes, we'd really like to see you at PyCon UK, and the games! We have sprint facilities available for two days before and two days after PyCon UK. They are at 95 Broad Street, about ten minutes walk from the Conference venue. There is a fat pipe internet connection. There are three rooms available, one has 10 high spec workstations which can be pre-installed with the o/s of your choice, for the other rooms you'd need your own laptops. There are places nearby to buy cheap food (a local supermarket and the usual fast food and sandwich shops). Can you point us at a cheap hostel for a few days? Looking at http://www.pyconuk.org/accommodation.html : The budget buys are the Etap (conference hotel) and Birmingham Backpackers, they are also furthest from the sprint location, say 25 and 30 minutes walk respectively (I haven't timed these). Basically, you can stay at either of these for less than £20 if you share. Also worth considering are the Comfort Zone serviced apartments, the ones in Townsend Street are about ten minutes walk from the sprint venue, less to the conference. The nearest hotel is the Novotel (where we're holding the conference dinner) at 70 Broad Street, 2 minutes from the sprint and 10 from the Conference. You should be able to get an online deal for about £69 for a double room. Just behind the Novotel is the Premier Travel Inn, slightly less at say £65 for a double. There are two Travel Inns in the area, sprinters would want the Birmingham Broad Street (Brindley Place) one. A good compromise between cost and convenience for the sprinters would be the Travelodge, just across the road from the sprint at 230 Broad Street, where you can get a family room (sleeps 3 adults plus one child, 4 adults at a push) for £66. One of the PyCon UK delegates has been finding cheap accommodation in the area, and I'll ask him to contact you directly, Laura. Best wishes, John -- -- http://mail.python.org/mailman/listinfo/python-list