QijingZheng / pyband

band plot using python matplotlib
155 stars 93 forks source link

An error caused by the difference between python2 and python3 #3

Closed Ionizing closed 6 years ago

Ionizing commented 6 years ago

Hello Mr. Zheng

I ran into an error like

Traceback (most recent call last):
  File "../pyband", line 434, in <module>
    kpath, bands, efermi, kpt_bounds = get_bandInfo(opts.filename)
  File "../pyband", line 108, in get_bandInfo
    for ii in range(Nseg):
TypeError: 'float' object cannot be interpreted as an integer

when I testing pyband with the examples listed in this repo.

And I guess this issue was caused by the difference of division operator / in py2 and py3. The MWE below confirmed it:

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 3 / 2
1

while in python3:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 3 / 2
1.5

So I provide a fix to it: in this line, substitute / with // and everything would go well (both python2 and python3 could perform // in same behavior.

QijingZheng commented 6 years ago

Hi

When I wrote this script, I was using python2 and did not take into account the difference of the '/' operator between python2 and python3. Anyway, thank you for you fix, I will add this to the script.

Best Qijing

Ionizing commented 6 years ago

Okay, I think I can close this issue with pleasure😀

Ionizing commented 6 years ago

Hi

The same issue occurs in pydos at L46 and L47, just substitute / with // and problem related to compatibility will be solved... for now(Another problem is the syntax difference between print in python2 and print() in python3).

Best Radiation

QijingZheng commented 6 years ago

Solved. Thank you...

Qijing

On Wed, May 23, 2018 at 3:18 PM, Ionizing Radiation < notifications@github.com> wrote:

Hi

The same issue occurs in pydos in L46 https://github.com/QijingZheng/pyband/blob/master/pydos#L46 and L47 https://github.com/QijingZheng/pyband/blob/master/pydos#L47, just substitute / with // and problem related to compatibility will be solved.

Best Radiation

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/QijingZheng/pyband/issues/3#issuecomment-391245834, or mute the thread https://github.com/notifications/unsubscribe-auth/AIINPtYNWiJ72UcDzglXzvTHCTNO_Ax5ks5t1Q1fgaJpZM4TrSLh .