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 psycopg2 for python
3.5. Is it something 3.5 has different scenario for django? I couldn't find
anyway to complete my setup so I'm going to downgrade to 3.4 as I found
psycopg2 for 3.4 only. 

 

If you have any idea about it then please let me know.

 

 

 

Regards,

Dhaval Parekh

Project Coordinator,

NCrypted Technologies Pvt. Ltd.
  http://www.ncrypted.com

 

An ISO 9001:2008 Certified Company | BID International Quality Crown (2012)
 Award Winner

IDC: 2nd floor, Shivalik 5, Gondal Road, Rajkot (Gujarat), India | +91 (281)
237 8880, 391 8880

Disclaimer & Privilege Notice: This e-Mail may contain proprietary,
privileged and confidential information and is sent for the intended
recipient(s) only. If, by an addressing or transmission error, this mail has
been misdirected to you, you are requested to notify us immediately by
return email message and delete this mail and its attachments. You are also
hereby notified that any use, any form of reproduction, dissemination,
copying, disclosure, modification, distribution and/or publication of this
e-mail message, contents or its attachment(s) other than by its intended
recipient(s) is strictly prohibited. Any opinions expressed in this email
are those of the individual and may not necessarily represent those of
NCrypted Technologies Pvt. Ltd. Before opening attachment(s), please scan
for viruses.

NCrypted is a registered trademark of NCrypted Technologies Pvt. Ltd. in
India and other countries.

 

-- 
https://mail.python.org/mailman/listinfo/python-list


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:
>> > 
>> > sampler =
>> > pymc.MCMC([alpha,betax,betay,eps,model,tau,z_obs,x_true,y_true])
>> > 
>> > 
>> > I want to know the detail of pymc.MCMC, then I get help content of it
>> > with:
>> > 
>> > /
>> > help(pymc.MCMC)
>> > Help on class MCMC in module pymc.MCMC:
>> > 
>> > class MCMC(pymc.Model.Sampler)
>> >  |  This class fits probability models using Markov Chain Monte Carlo.
>> >  |  Each stochastic variable is assigned a StepMethod object, which
>> >  |  makes it take a single MCMC step conditional on the rest of the
>> >  |  model. These step methods are called in turn.
>> >  |  
>> >  |>>> A = MCMC(input, db, verbose=0)
>> >  |  
>> > \\
>> > 
>> > 
>> > help('pymc.Model.Sampler')
>> > no Python documentation found for 'pymc.Model.Sampler'
>> > 
>> > 
>> > help('pymc.Model')
>> > Help on class Model in pymc:
>> > 
>> > pymc.Model = class Model(pymc.Container.ObjectContainer)
>> >  |  The base class for all objects that fit probability models. Model
>> >  |  is initialized with:
>> >  |  
>> >  |>>> A = Model(input, verbose=0)
>> >  |  
>> >  |:Parameters:
>> >  |  - input : module, list, tuple, dictionary, set, object or
>> >  |  nothing.
>> >  |  Model definition, in terms of Stochastics, Deterministics,
>> >  |  Potentials and Containers. If nothing, all nodes are
>> >  |  collected from the base namespace.
>> >  |  
>> >  |  Attributes:
>> >  |- deterministics
>> >  |- stochastics (with observed=False)
>> >  |- data (stochastic variables with observed=True)
>> >  |- variables
>> >  |- potentials
>> >  |- containers
>> >  |- nodes
>> >  |- all_objects
>> >  |- status: Not useful for the Model base class, but may be used by
>> >  |subclasses.
>> >  |  
>> >  |  The following attributes only exist after the appropriate method is
>> >  |  called:
>> >  |- moral_neighbors: The edges of the moralized graph. A
>> >  |dictionary, keyed by stochastic variable,
>> >  |  whose values are sets of stochastic variables. Edges exist
>> >  |  between the key variable and all variables in the value.
>> >  |  Created by method _moralize.
>> >  |- extended_children: The extended children of self's stochastic
>> >  |variables. See the docstring of
>> >  |  extend_children. This is a dictionary keyed by stochastic
>> >  |  variable.
>> >  |- generations: A list of sets of stochastic variables. The
>> >  |members of each element only have parents in
>> >  |  previous elements. Created by method find_generations.
>> >  |  
>> >  |  Methods:
>> >  | - sample_model_likelihood(iter): Generate and return iter
>> >  | samples of p(data and potentials|model).
>> >  |   Can be used to generate Bayes' factors.
>> >  |  
>> >  |  :SeeAlso: Sampler, MAP, NormalApproximation, weight, Container,
>> >  |  :graph.
>> >  |  
>> >  |  Method resolution order:
>> >  |  Model
>> >  |  pymc.Container.ObjectContainer
>> >  |  pymc.six.NewBase
>> >  |  pymc.Node.ContainerBase
>> >  |  __builtin__.object
>> >  |  
>> >  |  Methods defined here:
>> >  |  
>> >  |  __init__(self, input=None, name=None, verbose=-1)
>> >  |  Initialize a Model instance.
>> >  |  
>> >  |  :Parameters:
>> >  |- input : module, list, tuple, dictionary, set, object or
>> >  |nothing.
>> >  |Model definition, in terms of Stochastics,
>> >  |Deterministics, Potentials and Containers. If nothing,
>> >  |all nodes are collected from the base namespace.
>> >  |  
>> >  |  draw_from_prior(self)
>> >  |  Sets all variables to random values drawn from joint 'prior',
>> >  |  meaning contributions of data and potentials to the joint
>> >  |  distribution are not considered.
>> >  |  
>> >  |  get_node(self, node_name)
>> >  |  Retrieve node with passed name
>> >  |  
>> >  |  seed(self)
>> >  |  Seed new initial values for the stochastics.
>> >  |  
>> >  |  
--
>> >  |  Data descriptors defined here:
>> >  |  
>> >  |  generations
>> >  |  
>> >  |  
--
>> >  |  Data and other attributes defined here:
>> >  |  
>> >  |  __slotnames__ = []
>> >  |  
>> >  |  register = False
>> >  |  
>> >  |  
--
>> >  |  Methods inherited from pymc.Container.ObjectContainer:
>> >  |  
>> >  |  replace(self, item, new_container, key)
>> >  |  
>> >  |  
--
>> >  |  Data 

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 any errors you got from the installation, and we'll see what's
wrong. There were some changes to install locations and such in 3.5 so
it's possible that something isn't working with those binaries. But I
have fair confidence in them.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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, 0x20, 0x12, 0x01]


Use python 3.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


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:\python\fexit.spec
47 INFO: UPX is not available.
47 INFO: Extending PYTHONPATH with S:\python
47 INFO: checking Analysis
920 INFO: checking PYZ
1014 INFO: checking PKG
1092 INFO: Building because S:\python\build\fexit\fexit.exe.manifest changed
1092 INFO: Building PKG (CArchive) out00-PKG.pkg
1497 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 
30729, 4940)
5366 INFO: Bootloader 
c:\python27\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
5366 INFO: checking EXE
5444 INFO: Building because out00-EXE.toc is bad
5475 INFO: Building EXE from out00-EXE.toc
5522 INFO: SRCPATH [('fex.ico', None)]
5522 INFO: Updating icons from ['fex.ico'] to 
c:\users\admin\appdata\local\temp\tmpoingb4
5522 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
5522 INFO: Writing RT_ICON 1 resource with 18488 bytes
5538 INFO: Appending archive to EXE S:\python\dist\fexit.exe


http://fex.rus.uni-stuttgart.de/fop/SsmdcBLk/X-20151214111803.png

Where is the error?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: [email protected]
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


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 (in my case psycopg2-2.6.1) works just 
fine and smoothly (even for python-3.5!).

If you've got postgresql through a pre-compiled package it is (maybe) necessary 
to *show* where to find 'pg_config' by editing the setup.cfg-file in the 
psycopg2-source-folder.

Have you visited this site?
http://initd.org/psycopg/

regards
Michael

* Dhaval Parekh - NCrypted  [2015-12-14 09:29]:
> 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 psycopg2 for python
> 3.5. Is it something 3.5 has different scenario for django? I couldn't find
> anyway to complete my setup so I'm going to downgrade to 3.4 as I found
> psycopg2 for 3.4 only. 
> 
>  
> 
> If you have any idea about it then please let me know.
> 
>  
> 
>  
> 
>  
> 
> Regards,
> 
> Dhaval Parekh
> 
> Project Coordinator,
> 
> NCrypted Technologies Pvt. Ltd.
>   http://www.ncrypted.com
> 
>  
> 
> An ISO 9001:2008 Certified Company | BID International Quality Crown (2012)
>  Award Winner
> 
> IDC: 2nd floor, Shivalik 5, Gondal Road, Rajkot (Gujarat), India | +91 (281)
> 237 8880, 391 8880
> 
> Disclaimer & Privilege Notice: This e-Mail may contain proprietary,
> privileged and confidential information and is sent for the intended
> recipient(s) only. If, by an addressing or transmission error, this mail has
> been misdirected to you, you are requested to notify us immediately by
> return email message and delete this mail and its attachments. You are also
> hereby notified that any use, any form of reproduction, dissemination,
> copying, disclosure, modification, distribution and/or publication of this
> e-mail message, contents or its attachment(s) other than by its intended
> recipient(s) is strictly prohibited. Any opinions expressed in this email
> are those of the individual and may not necessarily represent those of
> NCrypted Technologies Pvt. Ltd. Before opening attachment(s), please scan
> for viruses.
> 
> NCrypted is a registered trademark of NCrypted Technologies Pvt. Ltd. in
> India and other countries.
> 
>  
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.4.3, on linux mint 17 (qiana)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


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 returns a
byte string regardless of whether you open it in text mode or binary mode.
That part is true, but there are other differences between text files and
binary files (opened in the correct mode): binary mode is guaranteed to
return the actual bytes in the file, but opening it in text mode may
perform some platform-specific processing:

(1) \r or \r\n may be converted to \n

(2) Ctrl-Z may be interpreted as end-of-file

There may be other changes made as well.


 
>> ['\x10', '\x20', '\x12', '\x01']
> 
> If a 'binary' file yields strings, you must be using 2.x.
> 
>> How can I receive this instead?
>> [0x10, 0x20, 0x12, 0x01]
> 
> Use python 3.

True, except by default integers display in decimal, not hex:

py> [0x10, 0x20, 0x12, 0x01]
[16, 32, 18, 1]



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


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 or directories into this window.")
  system('explorer "%s"' % HOME)
  file = get_paste()
  if not(os.path.exists(file)): die('"%s" does not exist' % file)


def get_paste():
  import msvcrt
  while True:
c = msvcrt.getch()
if c == '\t': return ''
if c == '\003' or c == '\004': return None
if not (c == '\n' or c == '\r'): break
  paste = c
  while msvcrt.kbhit():
c = msvcrt.getch()
if c == '\n' or c == '\r': break
paste += c
  if match(r'\s',paste): paste = subst('^"(.+)"$',r'\1',paste)
  return paste


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: [email protected]
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


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://www.varesano.net/blog/fabio/capturing%20screen%20image%20python%20and%20pil%20windows

Thanks!

Albert-Jan
  
-- 
https://mail.python.org/mailman/listinfo/python-list


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' clause.

I agree, those all seem like bad ideas.  But 'continue' has been singled
out for a SyntaxError.  Rumor has it that continue was difficult to make
work at all, while the other keywords, while ill-advised, were at least
possible.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


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 fixed in 3.x by making unicode the core text class, 
replacing the implementation of unicode, and performing further work 
with the new implementation.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


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 an exception-handler's
'finally' clause.


I agree, those all seem like bad ideas.  But 'continue' has been singled
out for a SyntaxError.  Rumor has it that continue was difficult to make
work at all, while the other keywords, while ill-advised, were at least
possible.

--Ned.



Part of the rumour mill 
http://www.gossamer-threads.com/lists/python/dev/484210?  This was 
referenced from the stackoverflow question that Ben Finney referred to 
yesterday.


--
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: 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. Microsoft's getwch function
isn't designed to handle the variety of ways the console host
(conhost.exe) encodes Unicode keyboard events. Their implementation
calls ReadConsoleInput and looks for a KEY_EVENT. If bKeyDown is set
it grabs the UnicodeChar field.

In an ideal world it would be that simple. However, the console
literally supports the alt+numpad sequences that allow entering
characters by code. So the input event sequence, for example, could be
+VK_MENU, +VK_NUMPAD7, -VK_NUMPAD7, +VK_NUMPAD6, -VK_NUMPAD6,
-VK_MENU, which is an "L". (Denoting "+" as key down and "-" as key
up.) This may just be the closest approximation in the system locale's
codepage (ANSI). That doesn't matter because the actual Unicode
codepoint is set in the last event's UnicodeChar field.

Try using the pyreadline module. IIRC, it does a better job decoding
the events from ReadConsoleInput.
-- 
https://mail.python.org/mailman/listinfo/python-list


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) filenames or use current 3.x.  This is one of the (known) 
>unicode problems fixed in 3.x by making unicode the core text class, 
>replacing the implementation of unicode, and performing further work 
>with the new implementation.
>
>-- 
>Terry Jan Reedy
>
>-- 
>https://mail.python.org/mailman/listinfo/python-list

Given that Ulli is in Germany, latin-1 is likely to work fine for him.  And
you do it like this:

# -*- coding: latin-1 -*-
from Tkinter import *
root = Tk()
s = 'Välkommen till Göteborg'  # Welcome to Gothenburg (where I live)
u = unicode(s, 'iso8859-1')
Label(root, text=u).pack()

root.mainloop()

Laura



-- 
https://mail.python.org/mailman/listinfo/python-list


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.  From the below, it appears that what you want is to have a 
literally up-to-date screenshot taken automatically during the doc build.


This requires that one be able to automate getting the application into 
the exact display state one wants to capture.  You can probably do that 
with a tkinter app if you write it with that possibility in mind.  In 
particular, you must keep a Python reference to every widget you want to 
manipulate, even if not needed for normal program operation.


There is also an issue with grabbing the whole screen versus only a 
program-specific window.


> This looks ok:

https://pypi.python.org/pypi/sphinxcontrib-programscreenshot


This (automatically) takes 'screenshots' on a no-screen (headless) *nix 
system (during doc build) by redirecting X-windows output to a 
pseudo-screen program.  Rather clever, and system-specific.



BUT I need something that works on Windows (Python 2.7).

> Can any recommend an approach? I thought about using PIL:

Get the pillow fork/upgrade on pypi.


http://www.varesano.net/blog/fabio/capturing%20screen%20image%20python%20and%20pil%20windows


Or look into Windows screen grabber programs, of which there are many.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


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älkommen till Göteborg'  # Welcome to Gothenburg (where I live)
> u = unicode(s, 'iso8859-1')
> Label(root, text=u).pack()

The problem is the input of these filenames.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: [email protected]
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


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 msvcrt?

I would use curses for user input, but:

,-
,-
| 
| No one has made a Windows port of the curses module. On a Windows 
| platform, try the Console module written by Fredrik Lundh. The Console 
| module provides cursor-addressable text output, plus full support for 
| mouse and keyboard input, and is available from 
| http://effbot.org/zone/console-index.htm.

So you should try that instead.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


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 AttributeError:
pass
handle.write("\n")

The specific use case I noticed this was
https://github.com/biopython/biopython/blob/master/Bio/AlignIO/EmbossIO.py#L38

Vincent Davis
-- 
https://mail.python.org/mailman/listinfo/python-list


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/mailman/listinfo/python-list


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 more directly, but hasattr() is shorter. However, consider this: 
I would write your example:



   try:
   handle.write("# Report_file: %s\n" % handle.name)
   except AttributeError:
   pass
   handle.write("\n")


as:

 try:
   write = handle.write
 except AttributeError:
   pass# or complain
 else:
   write("# Report_file: %s\n" % handle.name)
   write("\n")

Two things:

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 silently 
caught.


Second, notice that as a side effect of the:

 write = handle.write

line we now have the attribute value. If it were an if:

 if hasattr(handle, 'write'):
   write = handle.write
   ... write messages now ...

which is two steps to test and get the attribute. Feels... clunky. Perhaps 
partly because of the scope of a spelling error between the "'write'" string 
and the "handle.write" use below it, but clunky anyway.


Which to use depends on how you weigh readability and directness. But try to 
get decide how mugh of your "if" preference is personal uncomfortableness with 
try/except (for whatever reasons), and then how much those reasons may be 
generally applicable or a personal foible.


But it is your code, your call. What reads better to your eye?

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


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 “easier to ask forgiveness than
permission” (EAFP), and tends to prefer the latter.

http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#eafp-vs-lbyl>

“It is easier to ask forgiveness than permission” is attributed to
computer programming legend Rear Admiral Grace Hopper (she who
documented the first actual computer bug — a large moth in the wires).

Alex Martelli explores when LBYL and EAFP are each appropriate in Python
http://pyvideo.org/video/1338/permission-or-forgiveness-0>.

-- 
 \   “The optimist thinks this is the best of all possible worlds. |
  `\   The pessimist fears it is true.” —J. Robert Oppenheimer |
_o__)  |
Ben Finney

-- 
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 silently caught.
>

​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.

So then possibly this based on your suggestion:
try:
write = handel.write
except AttributeError:
raise
try:
name = handel.name
write("# Report_file: %s\n" % name)
except AttributeError:
pass
write("\n")


Vincent Davis
720-301-3003
-- 
https://mail.python.org/mailman/listinfo/python-list


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 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 might also emit AttributeError, and should
>> probably not be silently caught.
>>
>
> 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.
>
> So then possibly this based on your suggestion:
> try:
> write = handel.write
> except AttributeError:
> raise

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)
-- 
https://mail.python.org/mailman/listinfo/python-list


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
alt-numpad sequences that get queued for non-ASCII characters, just
like mvcrt.getwch. If you decide to roll your own getwch via ctypes or
PyWin32, I suggest starting a new topic on the ctypes list or Windows
list.
-- 
https://mail.python.org/mailman/listinfo/python-list


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:
>
>,-
>,-
>| 
>| No one has made a Windows port of the curses module. On a Windows 
>| platform, try the Console module written by Fredrik Lundh. The Console 
>| module provides cursor-addressable text output, plus full support for 
>| mouse and keyboard input, and is available from 
>| http://effbot.org/zone/console-index.htm.
>
>So you should try that instead.

If going for curses, I'd try this instead:
http://pdcurses.sourceforge.net/

Laura

-- 
https://mail.python.org/mailman/listinfo/python-list


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 it to no
>avail. When dropping a file path into the console it ignores the
>alt-numpad sequences that get queued for non-ASCII characters, just
>like mvcrt.getwch. If you decide to roll your own getwch via ctypes or
>PyWin32, I suggest starting a new topic on the ctypes list or Windows
>list.
>-- 
>https://mail.python.org/mailman/listinfo/python-list

PyPy wrote its own pyreadline.
You can get it here. https://bitbucket.org/pypy/pyrepl
And see if it works any better.

Laura
-- 
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: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 be silly.

Thanks​ everyone for the education.
-- 
https://mail.python.org/mailman/listinfo/python-list


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 your toes? How about your
> > tongue?
>
> Drive a car with my tongue? Perhaps not, but I could drive a car with my
> mouth if it were equipped with a sufficiently powerful interface.
>
> "Driver, please take me to the airport."

Sorry Steven, but that command will not be executed. First
you must say: "Ok Google". ;-)

Even google is not insane enough to write software that
attempts interpretation of every spoken within ear-shot of
it. But your interface has an even greater problem: since
software cannot yet read minds, and since most metropolitan
areas contain more than one airport, you may want to be more
specific than "take me to the airport". Heck, why not follow
that one with "take me shopping". ;-)

Not only have you demonstrated that your "mock interface" is
un-intuitive, your commands are so implicit that the banter
between human<->software is likely to descend into a sad
parody of Abbott and Costello!

> > Sure, even the most atrocious interface can be "learned", but what i
> > cannot understand, except in the case of you being a contrarian, is why
> > you would argue *AGAINST* intuitive interfaces? And believe it or not,
> > *SYNTAX* is an interface! As are paradigms!
>
> I do believe that you are arguing against a strawman. I don't think that
> anyone here has argued *against* "intuitiveness", all else being equal. But
> you are glossing over a whole lot of real complexity:
>
> - what makes you think all else actually is equal?
>
> - who decides what is intuitive and what isn't? why should we take
>   your word over what's intuitive and what isn't?
>
> - intuitive for who? my dad, who has never used a computer? my mum,
>   who has used a computer but only for word processing and web
>   browsing? a ten year old maths prodigy? a thirty year veteran
>   of C programming? a beginner to programming with a month's
>   experience in PHP?
>
> - what level of power are we willing to forgo in order to keep
>   the language "intuitive"?
>
> - what the hell does "intuitive" mean anyway?

Who's needs Abbott! Listen Steven, the litmus test for
intuitiveness is simple: if the overwhelming majority of the
users find it to be intuitive during the learning process,
then your interface is intuitive. That's it.

> I know what the definition of the word is, but it doesn't apply to
> programming language interfaces. As has been pointed out many times, the
> only truly intuitive interface is the nipple. Everything else has to be
> learned.

And what experience do *YOU* have with breast feeding that
would in any way qualify *YOU* to make such an assertion?

> In practice, "intuitive interface" gets bandied about in two ways:
>
> (1) Some people use it as a thought-terminating cliche. What they really
> mean is that they want this interface feature, for reasons of their own,
> and by calling it 'intuitive', they hope to bamboozle or intimidate others
> into backing down and accepting the feature. Who could possibly be
> against "intuitive" interfaces? That's like being against "usefulness",
> or "flexibility".
>
> When people start protesting about others being "against intuitive
> interfaces" (especially if they SHOUT the word "against", that's an good
> sign that they're using it as a thought-terminating cliche. To these
> people, "intuitive" is like "New And Improved!!!" to advertisers.
>
> (2) Others use it to mean an interface which is:
>
> * predictable;
> * consistent;
> * easy to explore and learn;
> * and "easy to use" in some vague sense.

This last comparison looks an awful lot like a straw-man
Steven. Nice. Extra points for painting me as a bully, and
then using my exact definition of intuitiveness but applying
it to the "friendly challenger". Your sleight of hand is
impressive my friend.

> [...]
>
> And most importantly, they recognize that programmers are beginners for
> perhaps 1% of their programming life: you might be completely new to
> programming for three months out of a 30 year span of programming. Why
> optimize the language for something that you will use for less than 1% of
> your productive lifespan? Apart from intentional beginner's languages like
> Scratch, for most languages it makes sense to add power even if it
> increases the learning curve.

I can assure you that complexity is not sacrificed when we
design interfaces to be intuitive. And to illustrate, we
need look no further than the automobile for a fine example.
The interface for driving a car is not only intuitive, it is
consistent!

  It is intuitive because it exposes a small number of high
  level operator components: the steering wheel, the brake
  petal, and the accelerator petal.

  And it is consistent because no matter what brand 

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=alpha, b=beta):
"""theta = logit^{-1}(a+b)"""
return pymc.invlogit(a+b*x)

d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\
observed=True)

import pymc
import mymodel

S = pymc.MCMC(mymodel, db='pickle')
S.sample(iter=1, burn=5000, thin=2)
pymc.Matplot.plot(S)



I find that the figures are shown after these two lines by myself:
*
import matplotlib.pyplot as plt
plt.show()

I have searched around and have not found some explanation about it.
The plot function here is different from Matlab's. Is there better ways than
my last two lines? (I am not confident whether my last two lines is the 
only choice.

Thanks,
-- 
https://mail.python.org/mailman/listinfo/python-list


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:
>>
>>,-
>>,-
>>|
>>| No one has made a Windows port of the curses module. On a Windows
>>| platform, try the Console module written by Fredrik Lundh. The Console
>>| module provides cursor-addressable text output, plus full support for
>>| mouse and keyboard input, and is available from
>>| http://effbot.org/zone/console-index.htm.
>>
>>So you should try that instead.
>
> If going for curses, I'd try this instead:
> http://pdcurses.sourceforge.net/

Christoph Gohlke has an extension module based on PDCurses [1]. The
good news for Python 3 users is that it uses the [W]ide-character
console API, such as ReadConsoleInputW. Also, its _get_key_count [2]
function is designed to support the alt numpad event sequences that
the system creates for the input filepath when dragging a file into
the console. In my limited testing, dragging filepaths from Explorer
worked without a hitch using a random Latin-1 name "¨°¸ÀÈÐØàèðø" and a
Latin Extended-B name "ƠƨưƸǀLjǐǘǠǨǰǸ".

Unfortunately the Python 2.7 version is linked against the [A]NSI API,
which maps each Unicode character to either the closest matching
character in the console's codepage or "?". Moreover the PDCurses code
has a bug in narrow builds in that it returns the UnicodeChar from the
KEY_EVENT_RECORD [3] instead of the AsciiChar (the name is a
misnomer). In this case the high byte is junk. You can mask it out
using a bitwise & with 0xFF.

That said, IIRC, the OP wants to avoid using any frameworks such as
curses or a GUI toolkit.

[1]: http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses
[2]: https://github.com/wmcbrine/PDCurses/blob/PDCurses_3_4/win32/pdckbd.c#L259
[3]: https://msdn.microsoft.com/en-us/library/ms684166
-- 
https://mail.python.org/mailman/listinfo/python-list


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 AttributeError, and should
probably not be silently caught.



​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.


I have to say that this was not at all evident to me. I think that also argues 
for putting the smallest possible bit of code inside the try/except.



So then possibly this based on your suggestion:
try:
   write = handel.write
except AttributeError:
   raise


Someone has already suggested dropping the try/except altogether for this.


try:
   name = handel.name
   write("# Report_file: %s\n" % name)
except AttributeError:
   pass


Again, I would minimise the stuff in the try/except, so:

 try:
   name = handle.name
 except AttributeError:
   pass
 else:
   write("# Report_file: %s\n" % name)

But in this case, in my code, I do two things:

Firstly, things needing names always get one:

 class Foo:
   def __init__(self, blah, name=None):
 if name is None:
   name = "Foo-%s" % (id(self),)
 self.name = name

Secondly, for your use case "print the name if it has one" I _would_ use 
hasattr:


 if hasattr(handle, name):
   write("# Report_file: %s\n" % name)

The logic feels far clearer to my eye.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


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 one" I _would_ use 
hasattr:


if hasattr(handle, name):
  write("# Report_file: %s\n" % name)


On reflection, there's also this:

 name = getattr(handle, 'name', repr(handle))
 write("# Report_file: %s\n" % name)

i.e. _always_ identfy the handle, even if it has no nice name.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list