Re: Try: rather than if :

2015-12-14 Thread Cameron Simpson
On 15Dec2015 17:11, Cameron Simpson wrote: On 14Dec2015 16:48, Vincent Davis wrote: [...] ​I think the intent of the original code was to check if handle had the attribute "name", I don't think the attribute "write" was the issue. [...] Secondly, for your use case "print the name if it has o

Re: Try: rather than if :

2015-12-14 Thread Cameron Simpson
On 14Dec2015 16:48, Vincent Davis wrote: On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson wrote: First, notice that the code inside the try/except _only_ fetches the attribute. Your version calls the "write" attribute, and also accesses handle.name. Either of those might also emit AttributeE

Re: cannot open file with non-ASCII filename

2015-12-14 Thread eryk sun
On Mon, Dec 14, 2015 at 6:07 PM, Laura Creighton wrote: > In a message of Mon, 14 Dec 2015 23:41:21 +0100, "Thomas 'PointedEars' Lahn" > wr > ites: > >>Why do you have to use msvcrt? >> >>I would use curses for user input, but: >> >>,-

Question about figure plot

2015-12-14 Thread Robert
Hi, When I run the following code, there is no figure shown in the end. // import pymc import numpy as np n = 5*np.ones(4,dtype=int) x = np.array([-.86,-.3,-.05,.73]) alpha = pymc.Normal('alpha',mu=0,tau=.01) beta = pymc.Normal('beta',mu=0,tau=.01) @pymc.deterministic def theta(a=alph

Re: Is vars() the most useless Python built-in ever?

2015-12-14 Thread Rick Johnson
On Friday, December 11, 2015 at 10:45:02 PM UTC-6, Steven D'Aprano wrote: > On Sat, 12 Dec 2015 09:13 am, Rick Johnson wrote: > > > Intuitiveness and productivity have a > > synergy like peas and carrots! One cannot be productive if one is fighting > > an unintuitive interface. Could you drive with

Re: Try: rather than if :

2015-12-14 Thread Vincent Davis
On Mon, Dec 14, 2015 at 4:53 PM, Ian Kelly wrote: > > Except that catching an exception just to immediately re-raise it is > silly. This would be better: > > try: > name = handle.name > except AttributeError: > pass > else: > handle.write("# Report_file: %s\n" % name) ​Ya that would

Re: cannot open file with non-ASCII filename

2015-12-14 Thread Laura Creighton
In a message of Mon, 14 Dec 2015 17:55:04 -0600, eryk sun writes: >On Mon, Dec 14, 2015 at 4:17 PM, Ulli Horlacher > wrote: >> >> ImportError: No module named pyreadline >> >> Is it a python 3.x module? >> >> I am limited to Python 2.7 > >pyreadline is available for 2.7-3.5 on PyPI. Anyway, I tried

Re: cannot open file with non-ASCII filename

2015-12-14 Thread Laura Creighton
In a message of Mon, 14 Dec 2015 23:41:21 +0100, "Thomas 'PointedEars' Lahn" wr ites: >Why do you have to use msvcrt? > >I would use curses for user input, but: > >,- >,-

Re: cannot open file with non-ASCII filename

2015-12-14 Thread eryk sun
On Mon, Dec 14, 2015 at 4:17 PM, Ulli Horlacher wrote: > > ImportError: No module named pyreadline > > Is it a python 3.x module? > > I am limited to Python 2.7 pyreadline is available for 2.7-3.5 on PyPI. Anyway, I tried it to no avail. When dropping a file path into the console it ignores the a

Re: Try: rather than if :

2015-12-14 Thread Ian Kelly
On Mon, Dec 14, 2015 at 4:48 PM, Vincent Davis wrote: > On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson wrote: > >> First, notice that the code inside the try/except _only_ fetches the >> attribute. Your version calls the "write" attribute, and also accesses >> handle.name. Either of those migh

Re: Try: rather than if :

2015-12-14 Thread Chris Angelico
On Tue, Dec 15, 2015 at 10:48 AM, Vincent Davis wrote: > try: > write = handel.write > except AttributeError: > raise Just "write = handel.write" :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Try: rather than if :

2015-12-14 Thread Vincent Davis
On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson wrote: > First, notice that the code inside the try/except _only_ fetches the > attribute. Your version calls the "write" attribute, and also accesses > handle.name. Either of those might also emit AttributeError, and should > probably not be sile

EAFP and LBYL (was: Try: rather than if :)

2015-12-14 Thread Ben Finney
Vincent Davis writes: > In the code below try is used to check if handle has the attribute name. It > seems an if statement could be used. Is there reason one way would be > better than another? The Python community refers to the difference by contrasting “look before you leap” (LBYL) versus “ea

Re: Try: rather than if :

2015-12-14 Thread Cameron Simpson
On 14Dec2015 15:38, Vincent Davis wrote: In the code below try is used to check if handle has the attribute name. It seems an if statement could be used. Only by using hasattr(), which IIRC does a try/except internally. Is there reason one way would be better than another? try/except is mo

Re: Try: rather than if :

2015-12-14 Thread Ian Kelly
On Mon, Dec 14, 2015 at 3:38 PM, Vincent Davis wrote: > In the code below try is used to check if handle has the attribute name. It > seems an if statement could be used. Is there reason one way would be > better than another? http://www.oranlooney.com/lbyl-vs-eafp/ -- https://mail.python.org/ma

Try: rather than if :

2015-12-14 Thread Vincent Davis
In the code below try is used to check if handle has the attribute name. It seems an if statement could be used. Is there reason one way would be better than another? def write_header(self): handle = self.handle try: handle.write("# Report_file: %s\n" % handle.name) except Attr

Re: cannot open file with non-ASCII filename

2015-12-14 Thread Thomas 'PointedEars' Lahn
Ulli Horlacher wrote: > Laura Creighton wrote: >> Given that Ulli is in Germany, latin-1 is likely to work fine for him. > > For me, but not for my users. We have people from about 100 nations at our > university. > […] > The problem is the input of these filenames. Why do you have to use msvcr

Re: cannot open file with non-ASCII filename

2015-12-14 Thread Ulli Horlacher
Laura Creighton wrote: > Given that Ulli is in Germany, latin-1 is likely to work fine for him. For me, but not for my users. We have people from about 100 nations at our university. > And you do it like this: > > # -*- coding: latin-1 -*- > from Tkinter import * > root = Tk() > s = 'Välkom

Re: Screenshots in Sphinx docs

2015-12-14 Thread Terry Reedy
On 12/14/2015 11:31 AM, Albert-Jan Roskam wrote: I'd like to include up-to-date screenshots (of a tkinter app) > into my Sphinx documentation. If you manually take screenshots with *any* screen grabber and save in an appropriate format, this is apparently trivial -- use the ..image directive

Re: cannot open file with non-ASCII filename

2015-12-14 Thread Laura Creighton
In a message of Mon, 14 Dec 2015 13:34:56 -0500, Terry Reedy writes: >On 12/14/2015 11:24 AM, Ulli Horlacher wrote: >> With Python 2.7.11 on Windows 7 my users cannot open/read files with >> non-ASCII filenames. > >Right. They should either restrict themselves to ascii (or possibly >latin-1) file

Re: cannot open file with non-ASCII filename

2015-12-14 Thread eryk sun
On Mon, Dec 14, 2015 at 10:24 AM, Ulli Horlacher wrote: > With Python 2.7.11 on Windows 7 my users cannot open/read files with > non-ASCII filenames. [...] > c = msvcrt.getch() This isn't an issue with Python per se, and the same problem exists in Python 3, using either getch or getwch. Micro

Re: Why is break allowed in finally, but continue is not?

2015-12-14 Thread Mark Lawrence
On 14/12/2015 17:37, Ned Batchelder wrote: On Sunday, December 13, 2015 at 5:28:44 PM UTC-5, Ben Finney wrote: Ned Batchelder writes: So why treat 'continue' specially? I am inclined to agree, but in the opposite direction: a case should be made for allowing *any* flow-control statement in a

Re: cannot open file with non-ASCII filename

2015-12-14 Thread Terry Reedy
On 12/14/2015 11:24 AM, Ulli Horlacher wrote: With Python 2.7.11 on Windows 7 my users cannot open/read files with non-ASCII filenames. Right. They should either restrict themselves to ascii (or possibly latin-1) filenames or use current 3.x. This is one of the (known) unicode problems fixe

Re: Why is break allowed in finally, but continue is not?

2015-12-14 Thread Ned Batchelder
On Sunday, December 13, 2015 at 5:28:44 PM UTC-5, Ben Finney wrote: > Ned Batchelder writes: > > So why treat 'continue' specially? > > I am inclined to agree, but in the opposite direction: a case should be > made for allowing *any* flow-control statement in an exception-handler's > 'finally' cl

Screenshots in Sphinx docs

2015-12-14 Thread Albert-Jan Roskam
Hello, I'd like to include up-to-date screenshots (of a tkinter app) into my Sphinx documentation. This looks ok: https://pypi.python.org/pypi/sphinxcontrib-programscreenshot BUT I need something that works on Windows (Python 2.7). Can any recommend an approach? I thought about using PIL: http:

cannot open file with non-ASCII filename

2015-12-14 Thread Ulli Horlacher
With Python 2.7.11 on Windows 7 my users cannot open/read files with non-ASCII filenames. They use the Windows explorer to drag&drop files into a console window running the Python program. os.path.exists() does not detect such a file and an open() fails, too. My code: print("\nDrag&drop files

Re: List of integers

2015-12-14 Thread Steven D'Aprano
On Mon, 14 Dec 2015 08:56 pm, Terry Reedy wrote: > On 12/13/2015 7:24 PM, KP wrote: >> >> >> data = list(f.read(4)) >> print data >> >> from a binary file might give > > In 2.x, a binary file and a text file are not distinguished. I think what you mean is that, in Python 2, reading from a file r

Re: Can't find way to install psycopg2 in 3.5

2015-12-14 Thread Michael Poeltl
hi, I'm used to compile postgresql from source (last time it was postgresql-9.4.4 with ./configure --prefix=/usr --enable-thread-safety --docdir=/usr/share/doc/postgresql-9.4.4 --with-tcl --with-openssl --enable-nls=de --with-libxml on my linuxmint17-box) and then the installation of psycopg2 (

pyinstaller ignores icon

2015-12-14 Thread Ulli Horlacher
pyinstaller ignores a specified icon file: the resulting executable shows the default icon on the desktop. I compile with: S:\python>pyinstaller.exe --onefile --icon=fex.ico fexit.py 31 INFO: PyInstaller: 3.0 31 INFO: Python: 2.7.11 31 INFO: Platform: Windows-7-6.1.7601-SP1 31 INFO: wrote S:\pyth

Re: List of integers

2015-12-14 Thread Terry Reedy
On 12/13/2015 7:24 PM, KP wrote: data = list(f.read(4)) print data from a binary file might give In 2.x, a binary file and a text file are not distinguished. ['\x10', '\x20', '\x12', '\x01'] If a 'binary' file yields strings, you must be using 2.x. How can I receive this instead? [0x10

Re: Can't find way to install psycopg2 in 3.5

2015-12-14 Thread Chris Angelico
On Mon, Dec 14, 2015 at 5:20 PM, Dhaval Parekh - NCrypted wrote: > I've digged a lot but I couldn't find psycopg2 for python 3.5. Here's where I'd get a psycopg2 binary: http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg If you've tried that and still can't get Python to talk to Postgres, post

Re: Help on class understanding in pymc code

2015-12-14 Thread Peter Otten
Robert wrote: > On Sunday, December 13, 2015 at 8:10:25 PM UTC-5, Peter Otten wrote: >> Robert wrote: >> >> > Hi, >> > >> > I follow code example at link: >> > >> > https://users.obs.carnegiescience.edu/cburns/ipynbs/PyMC.html >> > >> > >> > There is the following code line: >> > >> > sample

Can't find way to install psycopg2 in 3.5

2015-12-14 Thread Dhaval Parekh - NCrypted
Hello, I'm newbie in using python. I've installed python 3.5 and django 1.9 to develop web application. I wanted to set postgresql as a DBMS but I couldn't complete the setup as it was continuously throwing me an error that psycopg2 module not found. I've digged a lot but I couldn't find psycop