[Tutor] [Python2.7] Convert (2,188,1) into (188,1)

2017-06-28 Thread Allan Tanaka via Tutor
Hi. I have array shape like: (2,188,1). I want to make it like this: (188,1). I 
try that using .reshape(188,1) but throws an error: total size of an array must 
be unchanged
Thank you for the help!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Choosing between dictionary or external file

2017-06-28 Thread Henrique C. S. Junior
Dear colleagues, how are you?
I'm a scientist that is just starting with Python. I've decided to write a
small software to generate inputs used in a Quantum Chemistry package.
basically, we have to choose from several lists of options. Right now, I'm
using dictionaries to store information. Here is an example:


basis_sets = {
"Pople-style basis sets": {
"3-21G": "Pople 3-21G (H-Cs)",
"STO-3G": "Minimal basis set(H-I)",
"3-21GSP": "Buenker 3-21GSP (H-Ar)",
"4-22GSP": "Buenker 4-22GSP (H-Ar)",
"6-31G": "Pople 6-31G and its modifications (H-Zn)",
"m6-31G": "Modified 6-31G for 3d transition metals (Sc-Cu)",
"6-311G": "Pople 6-311G and its modifications (H-Br)"},

"The def2 basis sets of the Karlsruhe group": {
"def2-SVP": "Valence double-zeta basis set with 'new' polarization
functions",
"def2-SV(P)": "The above with slightly reduced polarization",
"def2-TZVP": "Valence triple-zeta basis set with 'new' polarization
"
 "functions. Note that this is quite similar to the
older ('def') TZVPP "
 "for the main group elements and TZVP for hydrogen.",
"def2-TZVP(-f)": "TZVP with f polarization removed from main group
elements",
"def2-TZVPP": "TZVPP basis set with 'new' polarization functions",
"def2-QZVPP": "Accurate polarized quadruple-zeta basis"},


My question is: is this the correct approach? The dictionaries, after
finished, probably will not have to be changed for a long time and my idea
is to import them in the main code.
A second question is regarding the creation os a GUI, what are your
recommendations (keeping in mind that I'm not an experienced programmer)
Glade, PyQt + QT Designer, Tkinter or something else (to run on Linux, Mac
and Windows)?
.
Thank you for any suggestions

-- 
*Henrique C. S. Junior*
Industrial Chemist - UFRRJ
M. Sc. Inorganic Chemistry - UFRRJ
Data Processing Center - PMP
Visite o Mundo Químico 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Program to check Python 2 syntaxes incompatible to Python 3?

2017-06-28 Thread STF
Hi,

After reading some articles about Python 2 vs Python 3 issues and web pages
like:
https://docs.python.org/3/whatsnew/3.0.html
https://wiki.python.org/moin/Python2orPython3

I'm wondering if there's any program/tool to list out incompatible syntaxes
in a Python 2 source file.

I know the 2to3 tool exists, but I'm more interested to do some manual
change to source code if possible.

Thanks in advance.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choosing between dictionary or external file

2017-06-28 Thread Alan Gauld via Tutor
On 28/06/17 17:44, Henrique C. S. Junior wrote:

> using dictionaries to store information. Here is an example:
> 
> 
> basis_sets = {
> "Pople-style basis sets": {
> "3-21G": "Pople 3-21G (H-Cs)",
> "STO-3G": "Minimal basis set(H-I)",
> "3-21GSP": "Buenker 3-21GSP (H-Ar)",
> "4-22GSP": "Buenker 4-22GSP (H-Ar)",
> "6-31G": "Pople 6-31G and its modifications (H-Zn)",
> "m6-31G": "Modified 6-31G for 3d transition metals (Sc-Cu)",
> "6-311G": "Pople 6-311G and its modifications (H-Br)"},
> 
> "The def2 basis sets of the Karlsruhe group": {
> "def2-SVP": "Valence double-zeta basis set with 'new' polarization
> 
> 
> My question is: is this the correct approach? The dictionaries, after
> finished, probably will not have to be changed for a long time and my idea
> is to import them in the main code.

Using dictionaries is ok, but your keys are inordinately long.
I'd probably define the strings as a set of variables(consts)
that can then be used in the dictionaries and in your code.

Otherwise you are likely to wind up with horrible looking code like:

if "beunker" in lower(basic_sets["Pople-style basis sets"]["3-21GSP"]):
.

Which is verbose at the very least and likely to be
error prone too. Whereas if you define something like

POPLE = "Pople-style basis sets"
...
basic_sets = {POPLE: {}}

The code becomes

if "beunker" in lower(basic_sets[POPLE]["3-21GSP"]):
   ...

Which, I think, is slightly easier on the eye. (And
you can still use the longhand version if you think
you need it)

> A second question is regarding the creation os a GUI, what are your
> recommendations (keeping in mind that I'm not an experienced programmer)
> Glade, PyQt + QT Designer, Tkinter or something else (to run on Linux, Mac
> and Windows)?

For easy to learn wrapping of a CLI I'd suggest Tkinter but
if you want to distribute the code to others then Qt probably
looks nicer and has more features. But a steeper learning
curve.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Query regarding Regular Expression

2017-06-28 Thread cookiestar227 - Cookie Productions
I am using Python version 3.6.0 and am learning Python as my very first
programming language.

Right now I am studying Regular Expressions.  We are finding all of the
matched substrings in a string using the "findall" method with the
following syntax:

re.findall(pattern, string[, flags])

Here is a link to the page tutorial I am using:

http://www.python-course.eu/python3_re_advanced.php

 So far have understood everything except for the following example:

>>>  t = "A fat cat doesn't eat oat but a rat eats bats."
>>>  mo = re.findall("[force]at", t)
>>>  print(mo)
['fat', 'cat', 'eat', 'oat', 'rat', 'eat']

What I don't understand is the [force] part of the Regular Expression.  I
cannot find anywhere online where there is an explanation of what [force]
means or what is does.  Why does it match to 'eat' from 'eats'? But not
'bat' from 'bats'?

I would prefer to use the following RE as it achieves my desired result:

>>> mo = re.findall("[A-Za-z]at", t)
>>> print(mo)
['fat', 'cat', 'eat', 'oat', 'rat', 'eat',  'bat']

Can anyone tell me what the [force] means and why it was used?

Thanks!

Kelly
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Query regarding Regular Expression

2017-06-28 Thread Alan Gauld via Tutor
On 28/06/17 21:27, cookiestar227 - Cookie Productions wrote:

>  So far have understood everything except for the following example:
> 
  t = "A fat cat doesn't eat oat but a rat eats bats."
  mo = re.findall("[force]at", t)

> What I don't understand is the [force] part of the Regular Expression.  

A sequence of characters inside square brackets means match any one of
the characters. So [force]at matches:

fat, oat, rat, cat, eat

It does not ,atch bat because there is no b inside the brackets.

The fact that force spells a real word is misleading, it could just as
well be written

[ocfre]at

and it would do the same.

> I would prefer to use the following RE as it achieves my desired result:
> 
 mo = re.findall("[A-Za-z]at", t)
 print(mo)
> ['fat', 'cat', 'eat', 'oat', 'rat', 'eat',  'bat']
Fine, but it does a different job, as you discovered.

The problem with regex is that very minor changes in
pattern can have big differences in output. Or, as
you've shown a big difference in pattern can make
a very subtle difference in output.

That's what makes regex so powerful and so very difficult
to get right.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor