Re: FYI: Micro Python running on kickstarter pyBoard project, now shipping
I guess the RPi has no ADC and has a fixed system architecture, not willing to include a co-processor running as watchdog or ADC, which is mandatory for industrial control. However if you run RESTful embedded controllers as limited functionality end devices, the RPi may act as main controller, if you manage a high MTBF. regardsG. Am Samstag, 8. November 2014 20:41:41 UTC+1 schrieb John Pinner: > 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: SyntaxError on progress module
Hi Chris, Chris Angelico wrote: [] >> Python 3.0 removed the 'u' for unicode in front of strings but due to >> popular demand to ease porting it was reinstated in 3.3. Strip it away and >> you should be fine to go. > > Or upgrade to 3.3 or better; is there anything holding you on 3.2? > Building CPython from source is pretty easy on Debian, and of course > upgrading to Jessie will correspondingly upgrade you to a more recent > Python (3.4, to be precise). I moved recently from squeeze to wheezy in my production environment, I've nothing really holding me back on my current configuration... I'll give it a try in the coming days. Thanks for the prompt answer, Al -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
Hi Mark, Mark Lawrence wrote: [] >>File >> "/home/debian/repos/2418_IASI-NG/Documents/Tools/tex_tool/venv/local/lib/python3.2/site-packages/progress/bar.py", >> line 48 >> empty_fill = u'∙' >>^ >> SyntaxError: invalid syntax >> [] > > Python 3.0 removed the 'u' for unicode in front of strings but due to > popular demand to ease porting it was reinstated in 3.3. Strip it away > and you should be fine to go. I'm not particularly comfortable in fiddling with the library source, even if the change seems really minor, therefore I guess that I'll upgrade to a more recent version of Python/Debian. But here I have another question, as a python novice is there really any reason for me to use any particular version of Python? Should I start directly with the newest? What about 2.7? Al -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
Chris Angelico : > Using some other name in place of "self" should definitely remain > *possible*, but not commonly done. You are effectively making the argument that Python has made a mistake by not giving "self" a special, language-level status. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
2015-05-27 9:30 GMT+02:00 alb : > Hi Mark, > Mark Lawrence wrote: > [] >>>File >>> "/home/debian/repos/2418_IASI-NG/Documents/Tools/tex_tool/venv/local/lib/python3.2/site-packages/progress/bar.py", >>> line 48 >>> empty_fill = u'∙' >>>^ >>> SyntaxError: invalid syntax >>> > [] >> >> Python 3.0 removed the 'u' for unicode in front of strings but due to >> popular demand to ease porting it was reinstated in 3.3. Strip it away >> and you should be fine to go. > > I'm not particularly comfortable in fiddling with the library source, > even if the change seems really minor, therefore I guess that I'll > upgrade to a more recent version of Python/Debian. > > But here I have another question, as a python novice is there really any > reason for me to use any particular version of Python? > > Should I start directly with the newest? What about 2.7? > > Al > -- > https://mail.python.org/mailman/listinfo/python-list Hi, I would recommend to start with a 3.x Python. Perhaps 3.3 or 3.4? If the version provided by your OS is older, you can always use a virtual environment. Ask if you don't know about it. Best -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
On Wed, May 27, 2015 at 5:39 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> Using some other name in place of "self" should definitely remain >> *possible*, but not commonly done. > > You are effectively making the argument that Python has made a mistake > by not giving "self" a special, language-level status. Uhh... no I'm not. I'm saying it should be possible to use some other name instead of "self", which means that Python got it right by not making it special. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
On Wed, May 27, 2015 at 5:30 PM, alb wrote: > But here I have another question, as a python novice is there really any > reason for me to use any particular version of Python? > > Should I start directly with the newest? What about 2.7? > Start with the newest that's conveniently available. With Debian Jessie, Python 3.4.2 is a simple apt-get away, so that's pretty convenient. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
Op Wednesday 27 May 2015 09:30 CEST schreef alb: > But here I have another question, as a python novice is there really > any reason for me to use any particular version of Python? > > Should I start directly with the newest? What about 2.7? In principal you should use the ‘latest’ 3. The only problem is that a lot of libraries are not converted to 3 yet. If you need one of those, then you have ‘no choice’ and have to use 2.7. But I would recommend to use ‘from __future__' to make the 2.7 code as much as possible 3 compliant. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list
Fwd: Lossless bulletproof conversion to unicode (backslashing)
Hi. This was labelled offtopic in python-ideas, so I edited and forwarded it here. Please CC as I am not subscribed. In short. I need is a bulletproof way to convert from anything to unicode. This requires some kind of escaping to go forward and back. Some helper function like u2b() (unicode to binary) and b2u() (that also removes escaping). So far I can't find any code that does just that. Background story. I need to print SCons graph. SCons is a build tool, so it has a graph of nodes - what depends on what. I have no idea what a node object could be. I know only that it can have human readable representation. Sometimes node is a filename in some encoding that is not utf-8, and without knowing the encoding, converting it to unicode is not possible without loosing the information about that filename. So, here is what Python proposes: https://docs.python.org/2.7/library/functions.html?highlight=unicode#unicode unicode() type constructor that doesn't allow you to do conversion without losing the data. It offers only two basic strategies - crash or corrupt: 1. ignore - meaning skip and corrupt the data 2. replace - just corrupt the data 3. strict - just crash Python design leaves the decision how to implement safe interoperability to you, and that's basically the reason why Python 3 fails. Without a safe approach (get my binary data back frum that unicode) people just can't wrap their heads around that. Python design assumes that people know the encoding of data they are processing, but that's not true in many cases. The data may also be just broken or invalid. So, the real world coding assumptions are: 1. external data encoding is unknown or varies 2. external data has binary chunks that are invalid for conversion to unicode In real world UnicodeDecode crashes is not an option for deal with unknown or broken and invalid input (such as when I need to print human representation of Node to the screen). In many (most?) situations lossless garbage is more welcome than crash or dataloss and that should be a default behaviour. The solution is to have filter preprocess the binary string to escape all non-unicode symbols so that the following lossless transformation becomes possible: binary -> escaped utf-8 string -> unicode -> binary I want to know if that's real? I need to accomplish that with Python 2.x, but the use case is probably valid for Python 3 as well. This stuff is critical to port SCons to Python 3.x and I expect for other similar tools that have to deal with unknown ascii-binary strings too. -- anatoly t. -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
Steven D'Aprano writes: > On Wednesday 27 May 2015 14:39, Ben Finney wrote: > > > That kind of homophobic slur is inappropriate from anyone in this > > community. Kindly cut it out altogether. > > I look forward to the day when people would read the earlier insult > and be perplexed as to why it is a slur at all. In the same way as > "your mother wears army boots" has become a joke slur, not taken > seriously. Yes, let's all work toward an end to the use of gender, sexuality, ethnicity, and other inborn traits as the punchline of insults or jokes. Until that happy day, let's work to improve the lot of those who are made the butt of such slurs. Part of that work must be to call foul when someone invokes an entire class of people as an insult. -- \ “Pinky, are you pondering what I'm pondering?” “I think so, | `\Brain, but why would anyone want to see Snow White and the | _o__) Seven Samurai?” —_Pinky and The Brain_ | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
I am missing something. Why do you need unicode at all? Why can you not just keep your binary data as binary data? I feel like I must be missing something obvious here ... Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
On Wed, May 27, 2015 at 2:35 PM, Laura Creighton wrote: > I am missing something. Why do you need unicode at all? Why can you > not just keep your binary data as binary data? Good question. From the SCons code I see that we need unicode, because we switched to io.StringIO which is advertised as the future (and Python 3 way of doing things, because Python 3 doesn't have non-unicode StringIO). A really deep and exhaustive answer. advertisement (first link on StringIO vs io.StringIO): http://stackoverflow.com/questions/3410309/what-is-the-difference-between-stringio-and-io-stringio-in-python2-7 peaceful details https://bitbucket.org/scons/scons/commits/05d5af305a5d gory consequences https://bitbucket.org/scons/scons/pull-request/235/fix-tree-all-print-when-build-tree > I feel like I must be missing something obvious here ... Not that obvious as it appears. -- anatoly t. -- https://mail.python.org/mailman/listinfo/python-list
Accessing DataSocket Server with Python
Dear Python Team, currently I am working on a research project for my bachelor degree. A LabVIEW application is used for current and power measurements, whereas the measured data are sent to DataSocket Server, a technology by National Instruments used for data exchange between computers and applications. DataSocket is based on TCP/IP and thus requesting data from DataSocket should be similar to an internet request. I know with the socket library in Python it is possible with to establish sockets, send internet requests and communicate between clients and servers. Is there a possibility to access NI DataSocket and get measurement data with Python on the same computer where Python is installed and the codes are executed? Can you maybe send me an example code where such a connection with DataSocket is established? If you got any queries, please do not hesitate to contact me. Thank you very much for your efforts. Kind regards, *Corrado Garrone* DH-Student Fachrichtung Elektrotechnik / Co-op Student B.Eng. Electrical Engineering Roche Diagnostics GmbH DFGHMV8Y6164 Sandhofer Strasse 116 68305 Mannheim / Germany Phone: apprentice mailto:corrado.garr...@roche.com *Roche Diagnostics GmbH* Sandhofer Straße 116; D‑68305 Mannheim; Telefon +49‑621‑759‑0; Telefax +49‑621‑759‑2890 Sitz der Gesellschaft: Mannheim - Registergericht: AG Mannheim HRB 3962 - Geschäftsführung: Dr. Ursula Redeker, Sprecherin; Edgar Vieth - Aufsichtsratsvorsitzender: Dr. Severin Schwan *Confidentiality Note* This message is intended only for the use of the named recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient, please contact the sender and delete the message. Any unauthorized use of the information contained in this message is prohibited. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
On Wed, May 27, 2015 at 2:47 PM, anatoly techtonik wrote: > On Wed, May 27, 2015 at 2:35 PM, Laura Creighton wrote: >> I am missing something. Why do you need unicode at all? Why can you >> not just keep your binary data as binary data? > > Good question. From the SCons code I see that we need unicode, because > we switched to io.StringIO which is advertised as the future (and Python 3 > way of doing things, because Python 3 doesn't have non-unicode StringIO). > > A really deep and exhaustive answer. > advertisement (first link on StringIO vs io.StringIO): > http://stackoverflow.com/questions/3410309/what-is-the-difference-between-stringio-and-io-stringio-in-python2-7 > peaceful details > https://bitbucket.org/scons/scons/commits/05d5af305a5d > gory consequences > https://bitbucket.org/scons/scons/pull-request/235/fix-tree-all-print-when-build-tree > >> I feel like I must be missing something obvious here ... > > Not that obvious as it appears. And the short answer is that we need unicode because we are printing this information to the stdout, and stdout is opened in text mode at least on Windows, and without explicit conversion, Python will try to decode stuff as being `ascii` and fail anyway. -- anatoly t. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
On Wed, May 27, 2015 at 9:52 PM, anatoly techtonik wrote: > And the short answer is that we need unicode because we are printing this > information to the stdout, and stdout is opened in text mode at least on > Windows, and without explicit conversion, Python will try to decode stuff > as being `ascii` and fail anyway. So you're working with text. That means you HAVE to decode it somehow; you fundamentally cannot print bytes to the console. Lossless concealment of arbitrary bytes won't help you. If you can't adequately decode everything, either backslash-escape the rest, or use a replacement character; you can't print out those bytes. And no, I will not cc you. Subscribe to the list if you're going to ask a question. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
On Wed, May 27, 2015, at 07:15, anatoly techtonik wrote: > The solution is to have filter preprocess the binary string to escape all > non-unicode symbols so that the following lossless transformation > becomes possible: > >binary -> escaped utf-8 string -> unicode -> binary > > I want to know if that's real? I need to accomplish that with > Python 2.x, but the use case is probably valid for Python 3 as well. In Python 3, you could *in principle* use surrogateescape (this would be more of a binary -> escaped unicode workflow), but see below. It is worth noting that when you *read* posix filenames in unicode form (e.g. listdir with a unicode argument), they are decoded with surrogateescape, and can be returned to bytes format with fn.encode(sys.getfilesystemencoding(), errors='surrogateescape'). However keep in mind that on *windows*, the native filename format is a sequence of 16-bit WCHAR values, not a sequence of bytes. > This stuff is critical to port SCons to Python 3.x and I expect for other > similar tools that have to deal with unknown ascii-binary strings too. Even if your filename *is* valid UTF-8 (or whatever other encoding), it might contain invisible control characters that make it difficult to read. You'd probably be better off simply working directly with the binary representation, iterating over it and replacing all non-*ascii*-printable bytes with an escaped representation. As it happens, the repr() function should work well for doing exactly this. (note: repr on a *unicode* string in python 3 will pass non-ascii characters, but ideally you're working with byte strings.) There's no real need to go beyond this unless you're working in a problem domain where filenames are likely to legitimately include non-ascii characters (e.g. user documents of non-technical users who use languages other than English). -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
On Wednesday, May 27, 2015 at 6:30:16 AM UTC-5, Ben Finney wrote: > Steven D'Aprano writes: > > > On Wednesday 27 May 2015 14:39, Ben Finney wrote: > > > > > That kind of homophobic slur is inappropriate from anyone in this > > > community. Kindly cut it out altogether. > > > > I look forward to the day when people would read the earlier insult > > and be perplexed as to why it is a slur at all. In the same way as > > "your mother wears army boots" has become a joke slur, not taken > > seriously. > > Yes, let's all work toward an end to the use of gender, sexuality, > ethnicity, and other inborn traits as the punchline of insults or jokes. Oh God, you people are being idiots. It's poop. And shall we all so look forward to the day, when people who eat poop are also welcome into the circle of humanity? Everyday, you let atrocity happen, and you're fighting for oppressed feltchers? If so, you dumbasses don't deserve much of a future. Mark -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
On Wed, May 27, 2015, at 07:47, anatoly techtonik wrote: > because Python 3 doesn't have non-unicode StringIO That's actually not true - the non-unicode equivalent is BytesIO. However, it's probably not actually what you want, if the point is to display the filenames to the user. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
On Wed, 27 May 2015 09:15 pm, anatoly techtonik wrote: > Hi. > > This was labelled offtopic in python-ideas, so I edited and forwarded > it here. Please CC as I am not subscribed. > > > In short. I need is a bulletproof way to convert from anything to > unicode. This requires some kind of escaping to go forward and back. Why do you need to go back? Just keep the node, and use that. > Some helper function like u2b() (unicode to binary) and b2u() (that > also removes escaping). So far I can't find any code that does just > that. def bytes2unicode(bytes): # Converts bytes to Unicode, allowing garbage (moji-bake). return bytes.decode('latin1') def unicode2bytes(unicode): # Convert unicode containing garbage (moji-bake) to bytes. return unicode.encode('latin1') It correctly does the round trip from any sequence of bytes to unicode and back to bytes, losslessly: py> import random py> node = bytes([random.randrange(0, 256) for _ in range(10)]) py> uni = bytes2unicode(node) py> b = unicode2bytes(uni) py> b == node True But take careful note that you can't start with Unicode and still expect to round-trip losslessly. Many perfectly readable Unicode strings do *not* convert to bytes: py> unicode2bytes(u'ДЙ') # two Cyrillic letters Traceback (most recent call last): File "", line 1, in File "", line 3, in unicode2bytes UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256) That means that if you take a correctly encoded string, it will round-trip, but it will also display as garbage: py> s = u'ДЙ' py> node = s.encode('utf-8') py> print(node) # Correctly encoded UTF-8 b'\xd0\x94\xd0\x99' py> node == unicode2bytes(bytes2unicode(node)) # round trips okay True py> print(repr(bytes2unicode(node))) # but prints as crap 'Ð\x94Ð\x99' > Background story. I need to print SCons graph. SCons is a build tool, > so it has a graph of nodes - what depends on what. I have no idea > what a node object could be. I know only that it can have human > readable representation. Sometimes node is a filename in some > encoding that is not utf-8, and without knowing the encoding, > converting it to unicode is not possible without loosing the information > about that filename. py> filename = "My Russian ДЙ name" # Unicode py> b = filename.encode('koi8-r') # Oops, not UTF-8! py> b.decode("utf-8") # Fails Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 11: invalid continuation byte py> b.decode("utf-8", errors="replace") # lossy, but works 'My Russian �� name' py> s = b.decode("utf-8", errors="surrogateescape") # magic! py> s 'My Russian \udce4\udcea name' It round-trips as well: py> s.encode("utf-8", errors="surrogateescape") == b True Converting this back to Python 2.7 is left as an exercise for the reader. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)
Chris Angelico apparantly has a problem with cc'd people who aren't on the list. python-list is very quiet these days, so if you subscribe it won't be drinking from the firehose. And you can always turn off delivery when you are done. Or you can just go read the archives: https://mail.python.org/pipermail/python-list/2015-May/thread.html Laura --- Forwarded Message Return-Path: Received: from mail.python.org (mail.python.org [82.94.164.166]) by theraft.openend.se (8.14.4/8.14.4/Debian-4) with ESMTP id t4RC09ap02From: Chris Angelico Cc: "python-list@python.org" On Wed, May 27, 2015 at 9:52 PM, anatoly techtonik wrote: > And the short answer is that we need unicode because we are printing this > information to the stdout, and stdout is opened in text mode at least on > Windows, and without explicit conversion, Python will try to decode stuff > as being `ascii` and fail anyway. So you're working with text. That means you HAVE to decode it somehow; you fundamentally cannot print bytes to the console. Lossless concealment of arbitrary bytes won't help you. If you can't adequately decode everything, either backslash-escape the rest, or use a replacement character; you can't print out those bytes. And no, I will not cc you. Subscribe to the list if you're going to ask a question. ChrisA - -- https://mail.python.org/mailman/listinfo/python-list --- End of Forwarded Message -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
On Wed, May 27, 2015 at 2:40 PM, zipher wrote: > On Wednesday, May 27, 2015 at 6:30:16 AM UTC-5, Ben Finney wrote: > > Steven D'Aprano writes: > > > > > On Wednesday 27 May 2015 14:39, Ben Finney wrote: > > > > > > > That kind of homophobic slur is inappropriate from anyone in this > > > > community. Kindly cut it out altogether. > > > > > > I look forward to the day when people would read the earlier insult > > > and be perplexed as to why it is a slur at all. In the same way as > > > "your mother wears army boots" has become a joke slur, not taken > > > seriously. > > > > Yes, let's all work toward an end to the use of gender, sexuality, > > ethnicity, and other inborn traits as the punchline of insults or jokes. > > Oh God, you people are being idiots. It's poop. And shall we all so look > forward to the day, when people who eat poop are also welcome into the > circle of humanity? > > Everyday, you let atrocity happen, and you're fighting for oppressed > feltchers? > > If so, you dumbasses don't deserve much of a future. > If your goal is to get people to stop calling you a troll, you are going about it the wrong way. If it isn't, why are you even here? Please remember the first rule of holes: if you find yourself in a hole, stop digging. -- https://mail.python.org/mailman/listinfo/python-list
Re: a more precise distance algorithm
A minor point is that if you just need to compare distances you don't need to compute the hypotenuse, its square will do so no subtractions etc etc. -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
On 27/05/2015 09:42, Cecil Westerhof wrote: Op Wednesday 27 May 2015 09:30 CEST schreef alb: But here I have another question, as a python novice is there really any reason for me to use any particular version of Python? Should I start directly with the newest? What about 2.7? In principal you should use the ‘latest’ 3. The only problem is that a lot of libraries are not converted to 3 yet. If you need one of those, then you have ‘no choice’ and have to use 2.7. But I would recommend to use ‘from __future__' to make the 2.7 code as much as possible 3 compliant. Please define "a lot" whilst bearing in mind green against red here https://python3wos.appspot.com/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
On 2015-05-27, Todd wrote: > On Wed, May 27, 2015 at 2:40 PM, zipher wrote: > >> [some stupid crap] > > If your goal is to get people to stop calling you a troll, you are > going about it the wrong way. If it isn't, why are you even here? > Please remember the first rule of holes: if you find yourself in a > hole, stop digging. And thanks to everybody who keeps replying to zipher's posts so that those of use who's newsreaders are configured to filter him out get to see them anyway. -- Grant Edwards grant.b.edwardsYow! I need to discuss at BUY-BACK PROVISIONS gmail.comwith at least six studio SLEAZEBALLS!! -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
Op Wednesday 27 May 2015 15:44 CEST schreef Mark Lawrence: > On 27/05/2015 09:42, Cecil Westerhof wrote: >> Op Wednesday 27 May 2015 09:30 CEST schreef alb: >> >>> But here I have another question, as a python novice is there >>> really any reason for me to use any particular version of Python? >>> >>> Should I start directly with the newest? What about 2.7? >> >> In principal you should use the ‘latest’ 3. The only problem is >> that a lot of libraries are not converted to 3 yet. If you need one >> of those, then you have ‘no choice’ and have to use 2.7. But I >> would recommend to use ‘from __future__' to make the 2.7 code as >> much as possible 3 compliant. >> > > Please define "a lot" whilst bearing in mind green against red here > https://python3wos.appspot.com/ I just started using Python again and the first ‘real’ program I wrote I had to write with Python 2 because the needed library (libturpial, that is not listed on your link) works only with Python 2. A short search about which of the two to use gives similar answers to mine. And as far as I can see in my neighbourhood Python 2 is almost exclusively used because used libraries are only available in Python 2. This is not a scientifically substantiated argument, but for me good enough to use a lot. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
On 27/05/2015 15:11, Cecil Westerhof wrote: Op Wednesday 27 May 2015 15:44 CEST schreef Mark Lawrence: On 27/05/2015 09:42, Cecil Westerhof wrote: Op Wednesday 27 May 2015 09:30 CEST schreef alb: But here I have another question, as a python novice is there really any reason for me to use any particular version of Python? Should I start directly with the newest? What about 2.7? In principal you should use the ‘latest’ 3. The only problem is that a lot of libraries are not converted to 3 yet. If you need one of those, then you have ‘no choice’ and have to use 2.7. But I would recommend to use ‘from __future__' to make the 2.7 code as much as possible 3 compliant. Please define "a lot" whilst bearing in mind green against red here https://python3wos.appspot.com/ I just started using Python again and the first ‘real’ program I wrote I had to write with Python 2 because the needed library (libturpial, that is not listed on your link) works only with Python 2. A short search about which of the two to use gives similar answers to mine. And as far as I can see in my neighbourhood Python 2 is almost exclusively used because used libraries are only available in Python 2. This is not a scientifically substantiated argument, but for me good enough to use a lot. Have you actaully tried running libturpial with Python 3 or have you simply taken somebody or something's word for it? I've taken code in the past that was "only Python 2", run it thought the 2to3 fixer and job done. Perhaps you could do the same. Perhaps you've already tried. Again, you're the only person who actually knows. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
Op Wednesday 27 May 2015 16:51 CEST schreef Mark Lawrence: > On 27/05/2015 15:11, Cecil Westerhof wrote: >> Op Wednesday 27 May 2015 15:44 CEST schreef Mark Lawrence: >> >>> On 27/05/2015 09:42, Cecil Westerhof wrote: Op Wednesday 27 May 2015 09:30 CEST schreef alb: > But here I have another question, as a python novice is there > really any reason for me to use any particular version of > Python? > > Should I start directly with the newest? What about 2.7? In principal you should use the ‘latest’ 3. The only problem is that a lot of libraries are not converted to 3 yet. If you need one of those, then you have ‘no choice’ and have to use 2.7. But I would recommend to use ‘from __future__' to make the 2.7 code as much as possible 3 compliant. >>> >>> Please define "a lot" whilst bearing in mind green against red >>> here https://python3wos.appspot.com/ >> >> I just started using Python again and the first ‘real’ program I >> wrote I had to write with Python 2 because the needed library >> (libturpial, that is not listed on your link) works only with >> Python 2. A short search about which of the two to use gives >> similar answers to mine. And as far as I can see in my >> neighbourhood Python 2 is almost exclusively used because used >> libraries are only available in Python 2. >> >> This is not a scientifically substantiated argument, but for me >> good enough to use a lot. >> > > Have you actaully tried running libturpial with Python 3 or have you > simply taken somebody or something's word for it? I've taken code in > the past that was "only Python 2", run it thought the 2to3 fixer and > job done. Perhaps you could do the same. Perhaps you've already > tried. Again, you're the only person who actually knows. Of-course I tried: that is why I used “had to”. The library itself and libraries it depends on are only existing in a 2 version (at the moment). I write code that should work in 2 and 3 both as long as 2 is still a significant part. I call programs with python3 (even while it is 10 to 20 percent slower) and only when that is not possible I use Python 2. (Except to test if code also works with Python 2.) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list
Re: a more precise distance algorithm
On Mon, May 25, 2015 at 11:11 PM, Steven D'Aprano wrote: > > Let's compare three methods. > > def naive(a, b): > return math.sqrt(a**2 + b**2) > > def alternate(a, b): > a, b = min(a, b), max(a, b) > if a == 0: return b > if b == 0: return a > return a * math.sqrt(1 + b**2 / a**2) > d1 = naive(a, b) > d2 = alternate(a, b) > d3 = math.hypot(a, b) > > which shows that: > > (1) It's not hard to find mismatches; > (2) It's not obvious which of the three methods is more accurate. > Bottom line: they all suck. :) I ran the program you posted, and, like you, got the following two examples: for fun in [naive, alternate, math.hypot]: print '%.20f' % fun(222.44802484683657,680.255801504161) 715.70320611153294976248 715.70320611153283607564 715.70320611153283607564 and for fun in [naive, alternate, math.hypot]: print '%.20f' % fun(376.47153302262484,943.1877995550265) 1015.54617837194291496417 1015.54617837194280127733 1015.54617837194291496417 but when comparing to Wolfram Alpha, which calculates these out many more decimal places, we have for the two cases: 715.7032061115328768204988784125331443593766145937358347357252... 715.70320611153294976248 715.70320611153283607564 715.70320611153283607564 1015.546178371942943007625196455666280385821355370154991424749... 1015.54617837194291496417 1015.54617837194280127733 1015.54617837194291496417 where all of the methods deviate at the 13/14 decimal place. bb -- - bbl...@gmail.com http://web.bryant.edu/~bblais -- https://mail.python.org/mailman/listinfo/python-list
Python 3.5 crashes on wrong %PYTHONHOME
I just installed the 32-bit Python 3.5b4 via the Web-installer. First, I was a bit annoyed by the fact it installed under 'f:\ProgramFiler-x86\Python35' instead of 'f:\ProgramFiler\Python35' as I customided for. But I guess this is a WOW64 thing. I'm on Win-8.1 (64-bit). But then I noticed the whole thing crashes when calling python35!Py_FatalError. On a simple 'python -v' command. Presumably because my env-var: PYTHONHOME=f:\Programfiler\Python27 (and not 'PYTHONHOME=f:\Programfiler\Python35'). Reading the message on this list, gave me the impression Python 2.7 and Python 3.5 can co-exist with no problem. Doesn't look the case so far. Is there another 'PYTHONxx' env-var to override 'PYTHONHOME' in this case? Or what should I do to keep on using both 27 and 35? For reference, the call-stack: ucrtbase!abort+0x4b python35!Py_FatalError+0xbc python35!Py_InitializeEx_Private+0x45b python35!Py_Main+0x72c python+0x11df KERNEL32!BaseThreadInitThunk+0x24 ntdll!__RtlUserThreadStart+0x2f ntdll!_RtlUserThreadStart+0x1b And some of the modules shown in WinDbg: ModLoad: 1c47 1c47c000 F:\ProgramFiler\Python35\python.exe ModLoad: 7772 7788e000 C:\Windows\SYSTEM32\ntdll.dll ModLoad: 7750 7764 C:\Windows\SYSTEM32\KERNEL32.DLL ModLoad: 76e2 76ef7000 C:\Windows\SYSTEM32\KERNELBASE.dll ModLoad: 6cd5 6d057000 F:\ProgramFiler\Python35\python35.dll ModLoad: 6e7e 6e7f5000 C:\Windows\SYSTEM32\VCRUNTIME140.dll (the new universal CRT from MS) -- --gv -- https://mail.python.org/mailman/listinfo/python-list
Re: different types of inheritence...
On Tuesday, May 26, 2015 at 3:53:25 PM UTC-5, Michael Torrie wrote: > On 05/26/2015 08:57 AM, zipher wrote: > > Comprende? I'm not trying to be cryptic here. This is a bit of OOP > > theory to be discussed. > > No, sorry. Maybe an actual example (with use case) would spur discussion. In the first example, super_dict changes the behavior of *for the user*, expanding the API, but keeping all the prior method behaviors the same. In the second example, specialized_dict changes the behavior in the machine -- the API stays the same so the user of the code just gets new benefits from whatever the specialized_dict is improving internally *without changing his/her code*. It's a drop-in replacement. In other words, the second class changes the INTERNALS of . While the first class changes the *externals* of . Yet they both use the same class definition, but semantically are completely different. It's TWO different definition of IS-A relationship. Two definitions of the word "is". m -- https://mail.python.org/mailman/listinfo/python-list
Embedded Python. Debug Version and _ctypes
Hi! I'm trying to use embedding of Python in my program. Simple C-program, compiled in Debug, that uses py-script that just imports "ctypes" gives me an error about "no module named "_ctypes". How to compile python lib in Visual Studio statically with ctypes support? Or how to use shared ctypes lib in debug mode? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.5 crashes on wrong %PYTHONHOME
On Wed, May 27, 2015 at 1:13 PM, Gisle Vanem wrote: > I just installed the 32-bit Python 3.5b4 via the Web-installer. > First, I was a bit annoyed by the fact it installed under > 'f:\ProgramFiler-x86\Python35' instead of > 'f:\ProgramFiler\Python35' as I customided for. But I guess > this is a WOW64 thing. I'm on Win-8.1 (64-bit). > > But then I noticed the whole thing crashes when calling > python35!Py_FatalError. On a simple 'python -v' command. > > Presumably because my env-var: > PYTHONHOME=f:\Programfiler\Python27 > > (and not 'PYTHONHOME=f:\Programfiler\Python35'). > > Reading the message on this list, gave me the impression > Python 2.7 and Python 3.5 can co-exist with no problem. > Doesn't look the case so far. Is there another 'PYTHONxx' > env-var to override 'PYTHONHOME' in this case? Or what should > I do to keep on using both 27 and 35? Is there any particular reason you're setting PYTHONHOME in the first place? It shouldn't be necessary unless you're doing something abnormal. I'd try unsetting it entirely and see if things just work. -- Zach -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.5 crashes on wrong %PYTHONHOME
Zachary Ware wrote: Is there any particular reason you're setting PYTHONHOME in the first place? I have several GNU Makefiles that picks up this variable (to find Python.h, python*.lib etc.). But using Python 27 and 35 w/o having a %PYTHONHOME set, seems to work fine. I have to revise those Makefiles. -- --gv -- https://mail.python.org/mailman/listinfo/python-list
PUDB Traceback
Hi, I'm facing traceback when using pudb python debugger to debug. Any help to resolve it. # python -m pudb file.py main() File "/usr/local/lib/python2.7/dist-packages/pudb/run.py", line 30, in main steal_output=options.steal_output) File "/usr/local/lib/python2.7/dist-packages/pudb/__init__.py", line 84, in runscript dbg.interaction(None, sys.exc_info()) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 338, in interaction show_exc_dialog=show_exc_dialog) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2020, in call_with_ui return f(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2212, in interaction self.show_exception_dialog(exc_tuple) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 1966, in show_exception_dialog ("Save traceback", "save"), File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 1939, in dialog return self.event_loop(w)[0] File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2185, in event_loop keys = self.screen.get_input() File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 324, in get_input keys, raw = self.parse_input(None, None, self.get_available_raw_input()) File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 426, in get_available_raw_input codes = self._get_gpm_codes() + self._get_keyboard_codes() File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 500, in _get_keyboard_codes code = self._getch_nodelay() File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 634, in _getch_nodelay return self._getch(0) File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 544, in _getch return ord(os.read(self._term_input_file.fileno(), 1)) TypeError: ord() expected a character, but string of length 0 found Regards, ~Piyush -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
On 27/05/2015 16:18, Cecil Westerhof wrote: Op Wednesday 27 May 2015 16:51 CEST schreef Mark Lawrence: On 27/05/2015 15:11, Cecil Westerhof wrote: Op Wednesday 27 May 2015 15:44 CEST schreef Mark Lawrence: On 27/05/2015 09:42, Cecil Westerhof wrote: Op Wednesday 27 May 2015 09:30 CEST schreef alb: But here I have another question, as a python novice is there really any reason for me to use any particular version of Python? Should I start directly with the newest? What about 2.7? In principal you should use the ‘latest’ 3. The only problem is that a lot of libraries are not converted to 3 yet. If you need one of those, then you have ‘no choice’ and have to use 2.7. But I would recommend to use ‘from __future__' to make the 2.7 code as much as possible 3 compliant. Please define "a lot" whilst bearing in mind green against red here https://python3wos.appspot.com/ I just started using Python again and the first ‘real’ program I wrote I had to write with Python 2 because the needed library (libturpial, that is not listed on your link) works only with Python 2. A short search about which of the two to use gives similar answers to mine. And as far as I can see in my neighbourhood Python 2 is almost exclusively used because used libraries are only available in Python 2. This is not a scientifically substantiated argument, but for me good enough to use a lot. Have you actaully tried running libturpial with Python 3 or have you simply taken somebody or something's word for it? I've taken code in the past that was "only Python 2", run it thought the 2to3 fixer and job done. Perhaps you could do the same. Perhaps you've already tried. Again, you're the only person who actually knows. Of-course I tried: that is why I used “had to”. The library itself and libraries it depends on are only existing in a 2 version (at the moment). I write code that should work in 2 and 3 both as long as 2 is still a significant part. I call programs with python3 (even while it is 10 to 20 percent slower) and only when that is not possible I use Python 2. (Except to test if code also works with Python 2.) Did you, noting that you didn't actually answer my question, and also noting that you do ask a lot of questions yourself? So let's try again, did you or did you not run libturpial through 2to3? If yes what went wrong that stopped you porting it to Python 3? You make the statement regarding Python3 "even while it is 10 to 20 percent slower". Where is your evidence to support this statement? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.5 crashes on wrong %PYTHONHOME
On 27/05/2015 20:30, Gisle Vanem wrote: Zachary Ware wrote: Is there any particular reason you're setting PYTHONHOME in the first place? I have several GNU Makefiles that picks up this variable (to find Python.h, python*.lib etc.). But using Python 27 and 35 w/o having a %PYTHONHOME set, seems to work fine. I have to revise those Makefiles. Can you please explain precisely what you're doing, as it's not clear (at least to me) why you're installing Python 3.5 with the web installer but then mentioning GNU makefiles. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
On 5/27/2015 7:15 AM, anatoly techtonik wrote: Hi. This was labelled offtopic in python-ideas, so I edited and forwarded it here. Please CC as I am not subscribed. I am not subcribed either, but I do not need or want CCs. python-list is mirrored at news.gmane.org where you can access it as either newsgroup gmane.comp.python.idle or via their web interface. Many mail programs have embedded news readers, and there are standalone news readers. I have used both Outlook Express and now Thunderbird. I am CCing this this time, but it is a nuisance for me, so just this once. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: should "self" be changed?
On 5/27/2015 2:32 AM, Chris Angelico wrote: On Wed, May 27, 2015 at 3:23 PM, Steven D'Aprano wrote: On Wednesday 27 May 2015 06:45, Mark Lawrence wrote: Apart from breaking all the tools that rely on "self" being spelt "self" this looks like an excellent idea. Tools which rely on self being spelled "self" are already broken. It's a convention, nothing more, and there are various good reasons for breaking the convention: - metaclasses - classmethods - custom descriptors - nested classes If it truly relies on it, yes. But if I see a function that has "self" as its first parameter, I'm going to read it as a (probable) method rather than a stand-alone function, and it wouldn't surprise me if introspection and/or source code parsing made the same assumption. The Idlelib calltips function does not look at names. It leaves the signature of functions as is and removes the first name, whatever it is, of bound methods, including bound class methods. See idlelib.CallTips.get_argspec for details. To make sure there is no name assumption, test_calltips.py tests that the first name, not 'self', is the name removed. One test method, Tc.t6, has function signature "(no, self)", which makes the bound method signature "(self)". -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: a more precise distance algorithm
On 27 May 2015 at 19:00, Brian Blais wrote: > On Mon, May 25, 2015 at 11:11 PM, Steven D'Aprano wrote: >> >> Let's compare three methods. >> >> def naive(a, b): >> return math.sqrt(a**2 + b**2) >> >> def alternate(a, b): >> a, b = min(a, b), max(a, b) >> if a == 0: return b >> if b == 0: return a >> return a * math.sqrt(1 + b**2 / a**2) > > >> d1 = naive(a, b) >> d2 = alternate(a, b) >> d3 = math.hypot(a, b) >> > >> which shows that: >> >> (1) It's not hard to find mismatches; >> (2) It's not obvious which of the three methods is more accurate. >> > > Bottom line: they all suck. :) > > I ran the program you posted, and, like you, got the following two examples: > > for fun in [naive, alternate, math.hypot]: > print '%.20f' % fun(222.44802484683657,680.255801504161) > > 715.70320611153294976248 > 715.70320611153283607564 > 715.70320611153283607564 > > and > > for fun in [naive, alternate, math.hypot]: > print '%.20f' % fun(376.47153302262484,943.1877995550265) > > 1015.54617837194291496417 > 1015.54617837194280127733 > 1015.54617837194291496417 > > but when comparing to Wolfram Alpha, which calculates these out many > more decimal places, we have for the two cases: > > 715.7032061115328768204988784125331443593766145937358347357252... > 715.70320611153294976248 > 715.70320611153283607564 > 715.70320611153283607564 > > 1015.546178371942943007625196455666280385821355370154991424749... > 1015.54617837194291496417 > 1015.54617837194280127733 > 1015.54617837194291496417 > > where all of the methods deviate at the 13/14 decimal place. So they have 12/13 correct digits after the decimal point. Including the digits before the decimal point they all have 15/16 correct decimal digits. This is exactly what you should expect when using double precision floating point. Feel free to print as many digits as you like but the extra ones won't add any more accuracy. The difference between the answers you showed are just 1 ULP: >>> a = 715.70320611153283607564 >>> b = 715.70320611153294976248 >>> a 715.7032061115328 >>> a + 5e-14 715.7032061115328 >>> a + 6e-14 715.703206111533 >>> a + 6e-14 == b True Since you don't show the source numbers we can't know whether the true result lies between these two or not. Oscar -- https://mail.python.org/mailman/listinfo/python-list
assertRaises() help
I am trying to add a test to pandas Int the first case I assert that I get a NaT value, in the second I what to test that I get a value error. def test_day_not_in_month_coerce_true () works I am trying to duplicate them with coerce= False which will give a ValueError but I cant get the tests to work. class TestDaysInMonth(tm.TestCase): def test_day_not_in_month_coerce_true(self): self.assertTrue(isnull(to_datetime('2015-02-29', coerce=True))) self.assertTrue(isnull(to_datetime('2015-02-29', format="%Y-%m-%d", coerce=True))) self.assertTrue(isnull(to_datetime('2015-02-32', format="%Y-%m-%d", coerce=True))) self.assertTrue(isnull(to_datetime('2015-04-31', format="%Y-%m-%d", coerce=True))) def test_day_not_in_month_coerce_false(self): self.assertRaises(ValueError, to_datetime, '2015-02-29', coerce=False) what I get is FAIL: test_day_not_in_month_coerce_false (pandas.tests.test_tseries.TestDaysInMonth) -- Traceback (most recent call last): File "/Users/vmd/GitHub/pandas_vmd/pandas/tests/test_tseries.py", line 747, in test_day_not_in_month_coerce_false self.assertRaises(ValueError, to_datetime, '2015-02-29', coerce=False) File "/Users/vmd/GitHub/pandas_vmd/pandas/util/testing.py", line 1576, in assertRaises _callable(*args, **kwargs) File "/Users/vmd/GitHub/pandas_vmd/pandas/util/testing.py", line 1640, in __exit__ raise AssertionError("{0} not raised.".format(name)) AssertionError: ValueError not raised. >From the docs maybe I should be using a "with" statement. Vincent Davis 720-301-3003 -- https://mail.python.org/mailman/listinfo/python-list
Decoding JSON file using python
I have the JSON structure shown below and the python code shown below to manipulate the JSON structure. import json json_input = { "msgType": "0", "tid": "1", "data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\"> "Timestamp": "1432703193431", "Host": "myserver.com", "Agent": "Experience", "AppName": "undefined", "AppInstance": "my_server", "Group": "UndefinedGroup" } data = json_input['data'] tdetails = data['Message'] print('json_input {} \n\ndata {} \n\n tdetails {}\n\n'.format(json_input,data,tdetails)) I am getting the error. Traceback (most recent call last): File "test_json.py", line 19, in tdetails = data['Message'] TypeError: string indices must be integers, not str The JSON structure is valid as shown by http://jsonlint.com/ I want to be able to access the different fields inside `data` such as `severity`, `subject` and also fields inside `tdetails` such as `CPUs` and `Product`. How do I do this? -- https://mail.python.org/mailman/listinfo/python-list
Re: Decoding JSON file using python
On Wed, May 27, 2015, at 18:23, Karthik Sharma wrote: > The JSON structure is valid as shown by http://jsonlint.com/ >I want to be able to access the different fields inside `data` such as >`severity`, `subject` and also fields inside `tdetails` such as `CPUs` >and `Product`. How do I do this? your data object is a string, it doesn't have anything inside it. if you want it to be a json object you'll need to actually use the json parser on it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Decoding JSON file using python
On 2015-05-27 23:23, Karthik Sharma wrote: I have the JSON structure shown below and the python code shown below to manipulate the JSON structure. import json json_input = { "msgType": "0", "tid": "1", "data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\"> "Timestamp": "1432703193431", "Host": "myserver.com", "Agent": "Experience", "AppName": "undefined", "AppInstance": "my_server", "Group": "UndefinedGroup" } data = json_input['data'] tdetails = data['Message'] print('json_input {} \n\ndata {} \n\n tdetails {}\n\n'.format(json_input,data,tdetails)) I am getting the error. Traceback (most recent call last): File "test_json.py", line 19, in tdetails = data['Message'] TypeError: string indices must be integers, not str The JSON structure is valid as shown by http://jsonlint.com/ I want to be able to access the different fields inside `data` such as `severity`, `subject` and also fields inside `tdetails` such as `CPUs` and `Product`. How do I do this? json_input['Message'] is a string, not a dict. -- https://mail.python.org/mailman/listinfo/python-list
Re: PUDB Traceback
On 2015-05-27 21:01, Piyush Verma wrote: Hi, I'm facing traceback when using pudb python debugger to debug. Any help to resolve it. # python -m pudb file.py main() File "/usr/local/lib/python2.7/dist-packages/pudb/run.py", line 30, in main steal_output=options.steal_output) File "/usr/local/lib/python2.7/dist-packages/pudb/__init__.py", line 84, in runscript dbg.interaction(None, sys.exc_info()) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 338, in interaction show_exc_dialog=show_exc_dialog) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2020, in call_with_ui return f(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2212, in interaction self.show_exception_dialog(exc_tuple) File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 1966, in show_exception_dialog ("Save traceback", "save"), File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 1939, in dialog return self.event_loop(w)[0] File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2185, in event_loop keys = self.screen.get_input() File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 324, in get_input keys, raw = self.parse_input(None, None, self.get_available_raw_input()) File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 426, in get_available_raw_input codes = self._get_gpm_codes() + self._get_keyboard_codes() File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 500, in _get_keyboard_codes code = self._getch_nodelay() File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 634, in _getch_nodelay return self._getch(0) File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 544, in _getch return ord(os.read(self._term_input_file.fileno(), 1)) TypeError: ord() expected a character, but string of length 0 found Regards, ~Piyush At a guess I'd say it has reached the end of the input, so os.read(...) is returning an empty string. -- https://mail.python.org/mailman/listinfo/python-list
Re: Decoding JSON file using python
On 27May2015 15:23, Karthik Sharma wrote: I have the JSON structure shown below and the python code shown below to manipulate the JSON structure. import json json_input = { "msgType": "0", "tid": "1", "data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\"> "Timestamp": "1432703193431", "Host": "myserver.com", "Agent": "Experience", "AppName": "undefined", "AppInstance": "my_server", "Group": "UndefinedGroup" } data = json_input['data'] tdetails = data['Message'] print('json_input {} \n\ndata {} \n\n tdetails {}\n\n'.format(json_input,data,tdetails)) I am getting the error. Traceback (most recent call last): File "test_json.py", line 19, in tdetails = data['Message'] TypeError: string indices must be integers, not str That will be because of this line: tdetails = data['Message'] because "data" is just the string from your dict. The JSON structure is valid as shown by http://jsonlint.com/ I want to be able to access the different fields inside `data` such as `severity`, `subject` and also fields inside `tdetails` such as `CPUs` and `Product`. How do I do this? Then you need to decode "data". Example (untested): data_decoded = json.loads(data) and then access: data_decoded['Message'] Cheers, Cameron Simpson Here's a great .sig I wrote, so good it doesn't rhyme. Jon Benger -- https://mail.python.org/mailman/listinfo/python-list
Re: assertRaises() help
On 27May2015 16:09, Vincent Davis wrote: I am trying to add a test to pandas Int the first case I assert that I get a NaT value, in the second I what to test that I get a value error. def test_day_not_in_month_coerce_true () works I am trying to duplicate them with coerce= False which will give a ValueError but I cant get the tests to work. class TestDaysInMonth(tm.TestCase): def test_day_not_in_month_coerce_true(self): self.assertTrue(isnull(to_datetime('2015-02-29', coerce=True))) self.assertTrue(isnull(to_datetime('2015-02-29', format="%Y-%m-%d", coerce=True))) self.assertTrue(isnull(to_datetime('2015-02-32', format="%Y-%m-%d", coerce=True))) self.assertTrue(isnull(to_datetime('2015-04-31', format="%Y-%m-%d", coerce=True))) def test_day_not_in_month_coerce_false(self): self.assertRaises(ValueError, to_datetime, '2015-02-29', coerce=False) what I get is FAIL: test_day_not_in_month_coerce_false (pandas.tests.test_tseries.TestDaysInMonth) -- [...] AssertionError: ValueError not raised. From the docs maybe I should be using a "with" statement. Unlikely. First, test your test by hand running: to_datetime('2015-02-29', coerce=False) _Does_ it raise ValueError? Cheers, Cameron Simpson Q: How many user support people does it take to change a light bulb? A: We have an exact copy of the light bulb here and it seems to be working fine. Can you tell me what kind of system you have? -- https://mail.python.org/mailman/listinfo/python-list
Re: assertRaises() help
On Wed, May 27, 2015 at 4:55 PM, Cameron Simpson wrote: > First, test your test by hand running: > > to_datetime('2015-02-29', coerce=False) > > _Does_ it raise ValueError? > Well that was not expected. Thanks Vincent Davis -- https://mail.python.org/mailman/listinfo/python-list
Re: OpenCV with Python (cv or cv2)
Hi Laura, On 26-05-2015 11:21, Laura Creighton wrote: In a message of Tue, 26 May 2015 10:24:30 -0300, Markos writes: Hi, I want to use OpenCV with Python. I installed version 2.4.9 (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/) in debian Squeeze running Python 2.6.6. Using the tutorial: http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/ (I tried to install versions 2.4.11 and 2.4.10 (in Squeeze with python 2.2.6) but I couldn't.) You mean python 2.6.6, right? and this package: https://packages.debian.org/source/squeeze/opencv which is 2.1.0-3 is too old for you? I installed this package (python-opencv) but I thought this package would be only some API for python to use the opencv library and I imagined that I would still have to install the opencv library from source. What do you mean that you tried to install versions 2.4.11 and 2.4.10 but couldn't? What error messages did you get? For example when trying to install the 2.4.11 version after running cmake: cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. (Output of cmake at the end of message.) and make -j2 to compile, but an error occurred after compiling 55%: [ 55%] Building CXX object modules/legacy/CMakeFiles/opencv_legacy.dir/src/facedetection.cpp.o Linking CXX shared library ../../lib/libopencv_legacy.so [ 55%] Built target opencv_legacy make: ** [all] Erro 2 I lost some time trying to load the module cv2: Import cv2.cv the cv s/the/as/ ? import cv2.cv as cv Traceback (most recent call last): File "", line 1, in> ImportError: No module named cv2.cv After a while I realized I could use the cv module. (import cv) But still I do not understand the differences between the modules cv and cv2. Do you suggest any good tutorial about the differences between cv and cv2? I will have to make many changes in python programs using cv to reuse the code later with cv2? Thanks, Markos -- https://mail.python.org/mailman/listinfo/python-list post the output you got from cmake At the end of message. It will probably complain that it is missing some headers, so couldn't make libcv2.so If you haven't installed python-dev (not just python) and numpy I guarantee it will not find needed headers; if you have but it is still not being made we will have to look harder at what is going wrong. I installed the following packages: apt-get install cmake apt-get install build-essential apt-get install pkg-config apt-get install libgtk2.0-dev apt-get install python-opencv python-dev python-numpy apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 zlib1g-dbg zlib1g zlib1g-dev pngtools libjasper-dev libjasper-runtime libjasper1 libjpeg8 libjpeg8-dbg libjpeg62 libjpeg62-dev libjpeg-progs libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev libswscale0 libswscale-dev openexr libopenexr6 libopenexr-dev apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libucil2 libucil2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils libv4l-0 libv4l-dev apt-get install libqt4-dev If it made a libcv.so for you, did it put it in a place you can see with your PYTHONPATH? Laura >>> import sys >>> print sys.path ['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode'] import cv works fine but I didn't find libcv.so in my system. I suppose that cv had already been installed by the package python-opencv, and the compilation of the opencv didn't install cv2. Thanks for your attention, Markos Return of cmake -- Linker flags (Release): -- Linker flags (Debug): -- Precompiled headers: YES -- -- OpenCV modules: -- To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab -- Disabled:world -- Disabled by dependency: - -- Unavailable: androidcamera dynamicuda java python viz -- -- GUI: -- QT 4.x: YES (ver 4.6.3 EDITION = OpenSource) -- QT OpenGL support: YES (/usr/lib/libQtO
Re: Decoding JSON file using python
I tried modifying the program as follows as per your suggestion.Doesn't seem to work. import simplejson as json import cjson json_input = { "msgType": "0", "tid": "1", "data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\"> "Timestamp": "1432703193431", "Host": "myserver.com", "Agent": "Experience", "AppName": "undefined", "AppInstance": "my_server", "Group": "UndefinedGroup" } print('json input original {} \n\n'.format(json_input)) data = json_input['data'] print('data {} \n\n'.format(data)) message = json.loads(data) print('message {} \n\n'.format(message['Message'])) I get the following error. Traceback (most recent call last): File "test_json.py", line 23, in print('message {} \n\n'.format(message['Message'])) TypeError: list indices must be integers, not str karthik.sharma@aukksharma2:~$ vim test_json.py On Thursday, 28 May 2015 11:14:44 UTC+12, Cameron Simpson wrote: > On 27May2015 15:23, Karthik Sharma wrote: > >I have the JSON structure shown below and the python code shown below to > >manipulate the JSON structure. > > > >import json > > > >json_input = { > >"msgType": "0", > >"tid": "1", > >"data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting > > \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\"> > >"Timestamp": "1432703193431", > >"Host": "myserver.com", > >"Agent": "Experience", > >"AppName": "undefined", > >"AppInstance": "my_server", > >"Group": "UndefinedGroup" > >} > > > > > >data = json_input['data'] > >tdetails = data['Message'] > >print('json_input {} \n\ndata {} \n\n tdetails > > {}\n\n'.format(json_input,data,tdetails)) > > > >I am getting the error. > > > >Traceback (most recent call last): > > File "test_json.py", line 19, in > >tdetails = data['Message'] > >TypeError: string indices must be integers, not str > > That will be because of this line: > > tdetails = data['Message'] > > because "data" is just the string from your dict. > > >The JSON structure is valid as shown by http://jsonlint.com/ > > I want to be able to access the different fields inside `data` such as > > `severity`, `subject` and also fields inside `tdetails` such as `CPUs` and > > `Product`. How do I do this? > > Then you need to decode "data". Example (untested): > > data_decoded = json.loads(data) > > and then access: > > data_decoded['Message'] > > Cheers, > Cameron Simpson > > Here's a great .sig I wrote, so good it doesn't rhyme. > Jon Benger -- https://mail.python.org/mailman/listinfo/python-list
Re: assertRaises() help
On 27May2015 17:13, Vincent Davis wrote: On Wed, May 27, 2015 at 4:55 PM, Cameron Simpson wrote: First, test your test by hand running: to_datetime('2015-02-29', coerce=False) _Does_ it raise ValueError? Well that was not expected. Thanks See? If you'd just believed your unit test... :-) Welcome to test driven development! Cheers, Cameron Simpson Acceptance Testing: Dropping your mods straight into the production environment to see if the users will accept them. -- https://mail.python.org/mailman/listinfo/python-list
Re: Decoding JSON file using python
On 2015-05-27, Karthik Sharma wrote: > I tried modifying the program as follows as per your > suggestion.Doesn't seem to work. That's because you didn't modify the program as per their suggestion, you made completely different changes that bore no relation to what they said. > import cjson What do you think 'import json' (or 'import cjson', or whatever) does? Hint: it doesn't cause Python to henceforth treat all strings as if they might contain JSON and to interpret them as such just in case. As Cameron already said, you have to actually *call* the JSON decoder to convert the data from its JSON string representation into Python objects. -- https://mail.python.org/mailman/listinfo/python-list
Re: assertRaises() help
On Thu, 28 May 2015 08:09 am, Vincent Davis wrote: > I am trying to add a test to pandas Int the first case I assert that I get > a NaT value, in the second I what to test that I get a value error. Your sentence has just enough typos to lead me to doubt I understand you. What do you mean, add a test "to pandas Int the first case..." ? What's a NaT value? > def > test_day_not_in_month_coerce_true > () works If it works, why is it relevant to your question? > I am trying to duplicate them with coerce= > False which > will give a ValueError but I cant get the tests to work. [...] > def test_day_not_in_month_coerce_false(self): > self.assertRaises(ValueError, to_datetime, '2015-02-29', > coerce=False) What leads you to believe that to_datetime('2015-02-29', coerce=False) will raise ValueError? > what I get is > > FAIL: test_day_not_in_month_coerce_false > (pandas.tests.test_tseries.TestDaysInMonth) This failure clearly shows that to_datetime(...) does not raise ValueError. I don't see anything obviously wrong in your use of the assertRaises method, *assuming* that it is the assertRaises method from the standard library unittest module. If it is some custom method written by you, or part of pandas, then I have no idea if you are doing something wrong. But I expect that the real problem is that you are mistaken to believe that to_datetime('2015-02-29', coerce=False) raises ValueError. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError on progress module
On Thu, 28 May 2015 06:03 am, Mark Lawrence wrote: > You make the statement regarding Python3 "even while it is 10 to 20 > percent slower". Where is your evidence to support this statement? Its well known that Python 3 is generally slower than Python 2. Cecil's claim shouldn't be controversial, any more than "Python is generally about 10 to 100 times slower than C" should be controversial. But for what it's worth: [steve@ando ~]$ python2.7 -m timeit "i=1; L=sorted([30,20,50,10,40]); L[i+1]" 100 loops, best of 3: 1.54 usec per loop [steve@ando ~]$ python3.3 -m timeit "i=1; L=sorted([30,20,50,10,40]); L[i+1]" 100 loops, best of 3: 1.62 usec per loop which is an 8% slowdown. On the other hand: [steve@ando ~]$ python2.7 -m timeit "i='1'; L=sorted([30,20,50,10,40]); L[int(i)+1]" 10 loops, best of 3: 2.6 usec per loop [steve@ando ~]$ python3.3 -m timeit "i='1'; L=sorted([30,20,50,10,40]); L[int(i)+1]" 10 loops, best of 3: 2.29 usec per loop which is a 12% speed up. So the lesson is, micro-benchmarks are not a good guide to whole-application benchmarks. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Returning a custom file object (Python 3)
I'd like to return a custom file object, say my own subclass. I can easily subclass the file object: from io import TextIOWrapper class MyFile(TextIOWrapper): pass but how do I tell open() to use MyFile? Answers for Python 3, thanks. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Returning a custom file object (Python 3)
Steven D'Aprano writes: > from io import TextIOWrapper > class MyFile(TextIOWrapper): > pass > > but how do I tell open() to use MyFile? I haven't used it, but does the ‘opener’ parameter do what you want? open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) -> file object […] A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling *opener* with (*file*, *flags*). *opener* must return an open file descriptor (passing os.open as *opener* results in functionality similar to passing None). -- \ “Our products just aren't engineered for security.” —Brian | `\ Valentine, senior vice-president of Microsoft Windows | _o__) development | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Returning a custom file object (Python 3)
Ben Finney writes: > Steven D'Aprano writes: > > > but how do I tell open() to use MyFile? > > I haven't used it, but does the ‘opener’ parameter do what you want? No, it doesn't; the ‘opener’ parameter doesn't have any say in the type of object returned from ‘open’. It seems the existing ‘open’ implementation doesn't allow you to override the type of object returned. You may have to resort to monkey-patching the ‘io’ attributes to put your preferred classes there. -- \ “Science shows that belief in God is not only obsolete. It is | `\also incoherent.” —Victor J. Stenger, 2001 | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Decoding JSON file using python
On Wed, May 27, 2015, at 19:51, Karthik Sharma wrote: > I get the following error. > > Traceback (most recent call last): > File "test_json.py", line 23, in > print('message {} \n\n'.format(message['Message'])) > TypeError: list indices must be integers, not str > karthik.sharma@aukksharma2:~$ vim test_json.py The string in data appears to be a json _list_ (note the first character is a square bracket) - try message[0]['Message']. You should really be able to figure this out yourself. -- https://mail.python.org/mailman/listinfo/python-list
Re: Decoding JSON file using python
On 2015-05-28 00:51, Karthik Sharma wrote: I tried modifying the program as follows as per your suggestion.Doesn't seem to work. import simplejson as json import cjson json_input = { "msgType": "0", "tid": "1", "data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\"> "Timestamp": "1432703193431", "Host": "myserver.com", "Agent": "Experience", "AppName": "undefined", "AppInstance": "my_server", "Group": "UndefinedGroup" } print('json input original {} \n\n'.format(json_input)) data = json_input['data'] print('data {} \n\n'.format(data)) message = json.loads(data) print('message {} \n\n'.format(message['Message'])) I get the following error. Traceback (most recent call last): File "test_json.py", line 23, in print('message {} \n\n'.format(message['Message'])) TypeError: list indices must be integers, not str karthik.sharma@aukksharma2:~$ vim test_json.py You have a different error message now. It says that 'message' is a list. Have a look at the JSON data. It represents a list that contains a dict. On Thursday, 28 May 2015 11:14:44 UTC+12, Cameron Simpson wrote: On 27May2015 15:23, Karthik Sharma wrote: >I have the JSON structure shown below and the python code shown below to manipulate the JSON structure. > >import json > >json_input = { >"msgType": "0", >"tid": "1", >"data": "[{\"Severity\":\"warn\",\"Subject\":\"Reporting \",\"Message\":\"tdetails:{\\\"Product\\\":\\\"Gecko\\\",\\\"CPUs\\\":8,\\\"Language\\\":\\\"en-GB\\\",\\\"isEvent\\\":\\\"> >"Timestamp": "1432703193431", >"Host": "myserver.com", >"Agent": "Experience", >"AppName": "undefined", >"AppInstance": "my_server", >"Group": "UndefinedGroup" >} > > >data = json_input['data'] >tdetails = data['Message'] >print('json_input {} \n\ndata {} \n\n tdetails {}\n\n'.format(json_input,data,tdetails)) > >I am getting the error. > >Traceback (most recent call last): > File "test_json.py", line 19, in >tdetails = data['Message'] >TypeError: string indices must be integers, not str That will be because of this line: tdetails = data['Message'] because "data" is just the string from your dict. >The JSON structure is valid as shown by http://jsonlint.com/ > I want to be able to access the different fields inside `data` such as `severity`, `subject` and also fields inside `tdetails` such as `CPUs` and `Product`. How do I do this? Then you need to decode "data". Example (untested): data_decoded = json.loads(data) and then access: data_decoded['Message'] -- https://mail.python.org/mailman/listinfo/python-list
Re: Decoding JSON file using python
On 28May2015 01:38, Jon Ribbens wrote: On 2015-05-27, Karthik Sharma wrote: I tried modifying the program as follows as per your suggestion.Doesn't seem to work. That's because you didn't modify the program as per their suggestion, you made completely different changes that bore no relation to what they said. Actually, his changes looked good to me. He does print from data first, but only for debugging. Then he goes: message = json.loads(data) and tried to access message['Message']. However I am having trouble reproducing his issue because his quoted code is incorrect. I've tried to fix it, as listed below, but I don't know what is really meant to be in the 'data" string. Hint: Karthik, use raw strings (r'foo') for complicated strings - it avoids a lot of backslashing etc, and thus avoids errors in backslashing. Karthik, please correct the code below. Currently I do not get your exception, I get an exception from the JSON module parsing the "data" string. Code below, Cameron Simpson import json json_input = { "msgType": "0", "tid": "1", "data": r'[{"Severity":"warn","Subject":"Reporting ","Message":"tdetails": {"Product":"Gecko","CPUs":8,"Language":"en-GB","isEven t":">}]', "Timestamp": "1432703193431", "Host": "myserver.com", "Agent": "Experience", "AppName": "undefined", "AppInstance": "my_server", "Group": "UndefinedGroup" } print('json input original {} \n\n'.format(json_input)) data = json_input['data'] print('data {} \n\n'.format(data)) message = json.loads(data) print('message {} \n\n'.format(message['Message'])) -- https://mail.python.org/mailman/listinfo/python-list
Re: OpenCV with Python (cv or cv2)
Your cmake output doesn't mention that it tried to build libcv.so so, I guess the reason you cannot find it is that it never tried to make it. You may already have fixed your problem by just installing the relevant debian package. If not, it may be that you need to install this one https://packages.debian.org/squeeze/libcv-dev to get libcv. You have another problem. Squeeze is _very_ old. According to http://stackoverflow.com/questions/5212728/libcxcore-so-2-missing-in-opencv the opencv project renamed a bunch of libraries, so if at all possible you should upgrade your debian distribution. You may have all sorts of mismatches between the source you just built and the libraries you need -- which you will only find by trial and error. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Returning a custom file object (Python 3)
Ben Finney : > It seems the existing ‘open’ implementation doesn't allow you to > override the type of object returned. The question is, can you assign to the builtin namespace. I'm guessing you can't. Within a module, you can simply do: open = MyFile Also, in other modules, you can: from myfile import open Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Returning a custom file object (Python 3)
On Thu, May 28, 2015 at 3:29 PM, Marko Rauhamaa wrote: > Ben Finney : > >> It seems the existing ‘open’ implementation doesn't allow you to >> override the type of object returned. > > The question is, can you assign to the builtin namespace. I'm guessing > you can't. > > Within a module, you can simply do: > >open = MyFile > > Also, in other modules, you can: > >from myfile import open Well, you can... >>> import builtins >>> builtins.open >>> builtins.open = "not your grandfather's open() function" >>> open "not your grandfather's open() function" ... but I don't think replacing all of open() is what Steven has in mind; it's a function that does a lot of work, most of which is what's wanted. Depending on how brutal you want to be, though, you _could_ hack around it. >>> from io import TextIOWrapper >>> class MyFile(TextIOWrapper): ... def demo(self): print("Hello, world!") ... >>> f = open("/tmp/dummy", "w", encoding="utf-8") >>> f <_io.TextIOWrapper name='/tmp/dummy' mode='w' encoding='utf-8'> >>> f.__class__ >>> f.__class__ = MyFile >>> f.demo() Hello, world! This does appear to work. Whether or not it's a good idea is a separate question. And of course, you could replace open() with something like this: >>> _orig_open = open >>> def open(*args, **kw): ... cls = kw.pop("use_class", None) ... f = _orig_open(*args, **kw) ... if cls is not None: f.__class__ = cls ... return f ... >>> f = open("/tmp/dummy", "w", encoding="utf-8", use_class=MyFile) >>> f <_io.TextIOWrapper name='/tmp/dummy' mode='w' encoding='utf-8'> >>> f.demo() Hello, world! But again, I'm really not sure this is a good way to do things. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Returning a custom file object (Python 3)
On 05/27/2015 10:29 PM, Marko Rauhamaa wrote: Ben Finney : It seems the existing ‘open’ implementation doesn't allow you to override the type of object returned. The question is, can you assign to the builtin namespace. I'm guessing you can't. Of course you can. Python2: >>> __builtins__.open = "whatever" >>> Python3: >>> import builtins >>> builtins.open = "whatever" >>> Of course doing so is like shooting yourself in the foot: Any subsequent pain is your own fault and probably well deserved. Gary Herron Within a module, you can simply do: open = MyFile Also, in other modules, you can: from myfile import open Marko -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Re: Returning a custom file object (Python 3)
On Thursday 28 May 2015 15:56, Gary Herron wrote: > On 05/27/2015 10:29 PM, Marko Rauhamaa wrote: >> Ben Finney : >> >>> It seems the existing ‘open’ implementation doesn't allow you to >>> override the type of object returned. >> The question is, can you assign to the builtin namespace. I'm guessing >> you can't. > > Of course you can. > > Python2: > >>> __builtins__.open = "whatever" Don't use __builtins__ with an "s". That's an implementation of CPython and may not exist in the future, and doesn't exist in other implementations. Instead, you should import __builtin__ with no "s". Confusing? It certainly is, which is why Python 3 renamed __builtin__ to builtins. -- Steve -- https://mail.python.org/mailman/listinfo/python-list