Re: Returning a custom file object (Python 3)

2015-05-27 Thread Steven D'Aprano
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 guess

Re: Returning a custom file object (Python 3)

2015-05-27 Thread Gary Herron
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__.op

Re: Returning a custom file object (Python 3)

2015-05-27 Thread Chris Angelico
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

Re: Returning a custom file object (Python 3)

2015-05-27 Thread Marko Rauhamaa
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: fr

Re: OpenCV with Python (cv or cv2)

2015-05-27 Thread Laura Creighton
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://packag

Re: Decoding JSON file using python

2015-05-27 Thread Cameron Simpson
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

Re: Decoding JSON file using python

2015-05-27 Thread MRAB
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\":

Re: Decoding JSON file using python

2015-05-27 Thread random832
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@aukksharm

Re: Returning a custom file object (Python 3)

2015-05-27 Thread Ben Finney
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 ‘ope

Re: Returning a custom file object (Python 3)

2015-05-27 Thread Ben Finney
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, newli

Returning a custom file object (Python 3)

2015-05-27 Thread Steven D'Aprano
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/lis

Re: SyntaxError on progress module

2015-05-27 Thread Steven D'Aprano
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,

Re: assertRaises() help

2015-05-27 Thread Steven D'Aprano
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 t

Re: Decoding JSON file using python

2015-05-27 Thread Jon Ribbens
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

Re: assertRaises() help

2015-05-27 Thread Cameron Simpson
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... :-

Re: Decoding JSON file using python

2015-05-27 Thread Karthik Sharma
I tried modifying the program as follows as per your suggestion.Doesn't seem to work. import simplejson as json import cjson json_inpu

Re: OpenCV with Python (cv or cv2)

2015-05-27 Thread Markos
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

Re: assertRaises() help

2015-05-27 Thread Vincent Davis
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: assertRaises() help

2015-05-27 Thread Cameron Simpson
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

Re: Decoding JSON file using python

2015-05-27 Thread Cameron Simpson
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 \",\"Me

Re: PUDB Traceback

2015-05-27 Thread MRAB
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) Fil

Re: Decoding JSON file using python

2015-05-27 Thread MRAB
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\":\"Reportin

Re: Decoding JSON file using python

2015-05-27 Thread random832
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 d

Decoding JSON file using python

2015-05-27 Thread Karthik Sharma
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\\\"

assertRaises() help

2015-05-27 Thread Vincent Davis
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 wor

Re: a more precise distance algorithm

2015-05-27 Thread Oscar Benjamin
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

Re: should "self" be changed?

2015-05-27 Thread Terry Reedy
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

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread Terry Reedy
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 ei

Re: Python 3.5 crashes on wrong %PYTHONHOME

2015-05-27 Thread Mark Lawrence
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, seem

Re: SyntaxError on progress module

2015-05-27 Thread Mark Lawrence
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 schre

PUDB Traceback

2015-05-27 Thread Piyush Verma
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/

Re: Python 3.5 crashes on wrong %PYTHONHOME

2015-05-27 Thread Gisle Vanem
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 Ma

Re: Python 3.5 crashes on wrong %PYTHONHOME

2015-05-27 Thread Zachary Ware
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

Embedded Python. Debug Version and _ctypes

2015-05-27 Thread Uladzimir Kryvian
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 l

Re: different types of inheritence...

2015-05-27 Thread zipher
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 fi

Python 3.5 crashes on wrong %PYTHONHOME

2015-05-27 Thread Gisle Vanem
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 th

Re: a more precise distance algorithm

2015-05-27 Thread Brian Blais
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 /

Re: SyntaxError on progress module

2015-05-27 Thread Cecil Westerhof
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

Re: SyntaxError on progress module

2015-05-27 Thread 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 an

Re: SyntaxError on progress module

2015-05-27 Thread Cecil Westerhof
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? >>

Re: should "self" be changed?

2015-05-27 Thread Grant Edwards
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 yo

Re: SyntaxError on progress module

2015-05-27 Thread 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 y

Re: a more precise distance algorithm

2015-05-27 Thread Robin Becker
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: should "self" be changed?

2015-05-27 Thread Todd
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 > > > > commu

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-27 Thread Laura Creighton
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.or

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread Steven D'Aprano
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 escap

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread random832
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.

Re: should "self" be changed?

2015-05-27 Thread zipher
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

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread random832
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 kno

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread Chris Angelico
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 `a

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread anatoly techtonik
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

Accessing DataSocket Server with Python

2015-05-27 Thread Garrone, Corrado
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 applic

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread anatoly techtonik
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

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread Laura Creighton
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: should "self" be changed?

2015-05-27 Thread Ben Finney
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

Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread anatoly techtonik
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

Re: SyntaxError on progress module

2015-05-27 Thread Cecil Westerhof
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 pr

Re: SyntaxError on progress module

2015-05-27 Thread Chris Angelico
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

Re: should "self" be changed?

2015-05-27 Thread Chris Angelico
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, langua

Re: SyntaxError on progress module

2015-05-27 Thread David Palao
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 s

Re: should "self" be changed?

2015-05-27 Thread Marko Rauhamaa
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/listi

Re: SyntaxError on progress module

2015-05-27 Thread 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'

Re: SyntaxError on progress module

2015-05-27 Thread alb
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? > Buildin

Re: FYI: Micro Python running on kickstarter pyBoard project, now shipping

2015-05-27 Thread radler63
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, i