2017-04-15 3 views
-1

저는 파이썬에서 새롭고이 문제가 있습니다. 내 스크립트를 실행하면이 오류를 보여줍니다ImportError : 'inf'라는 이름을 가져올 수 없습니다.

Traceback (most recent call last): 
    File "./message", line 2, in <module> 
    from src.graph_lib import * 
    File "/export/home/xsymersk/TGR/src/graph_lib.py", line 2, in <module> 
    from math import inf 
ImportError: cannot import name 'inf' 

내 코드는이 수입 구조가 있습니다

graph_lyb.py :

from src.dfs_lib import * 
from math import inf 
from collections import Counter 
from operator import itemgetter 

dfs_lib.py :

from enum import Enum 

을 message.py :

from src.graph_lib import * 
from sys import stdin 

forest.py :

from src.graph_lib import * 
from sys import stdin 

race.py :

from src.graph_lib import * 
from sys import stdin 

코드 inf 수입없이 실행됩니다.

+1

'math.inf' 파이썬 3.5에서 추가되었다 스스로를 추가 할 수 있습니다. – vaultah

답변

0

수학 모듈에서 inf을 가져올 필요가 없습니다. math.isinf 함수가 있지만 무한 값을 정의하려면 float('inf')을 사용할 수 있습니다.

1

어떤 python 버전을 사용하십니까? 당신은 당신이 사용하는 파이썬의 버전을 확인해야합니다

: (https://docs.python.org/3/library/math.html#math.inf 관련 링크) math 패키지

inf 상수는 파이썬 3.5

에서 구현됩니다.

+0

아, 저 버전이 있는데, inf로 뭔가 있습니까? –

+0

나는 그것을 가지고, float ("inf") –

1

앞서 언급 한 것처럼 math.inf은 python 3.5에서 새로 도입되었습니다. inf은 항상 float('inf')으로, math.inf은 정말 편리합니다. 당신이 math.inf를 사용하여 좋아하는 경우에, 당신은 지원되는 버전

import sys 
if sys.version_info < (3,5): 
    raise ImportError('{} requires python version 3.5 or later'.format(__name__)) 

에 코드를 제한 할 수 있습니다 또는 당신은 단지

import sys 
import math 
if sys.version_info < (3,5): 
    math.inf = float('inf') 
    math.nan = float('nan') 
    math.tau = math.pi * 2. 
관련 문제