def get_par(filename_or_pard):
# automatically search for the path
Path = GetPathOsmosisPth()
f = open(Path,'r')
TheLines = f.readlines()
Path = TheLines[0][0:-1] + '/osmosis/'
f.close()
# Get the name of the path to the data
ThePath = locate_dir('GeneralParameters',Path)
Thepdata = ThePath.split('GeneralParameters')[0] #(line 216 - This line gives error)
# check if we do not have provided an external data path
DataDir = CheckInputDataDirectory()
#DataDir = 'Data_CS'
if DataDir is None:
pdata = Thepdata
else:
pdata = os.path.join(Path,DataDir)
# search for the file
if isstring(filename_or_pard):
# myprintv("isstring: ", filename_or_pard)
# creating the dictionary
ThePath = locate(filename_or_pard,pdata)
f = ThePath + os.path.sep + filename_or_pard
pard = create_par_structure(f)
# creating the class par_struct
par = par_struct(pard)
# store the filename with the parameters in the par structure
par.TheFilename = filename_or_pard
else:
# myprint2v("not isstring: ", filename_or_pard, type(filename_or_pard))
# the dictionary is provided as input
pard = filename_or_pard
# creating the class par_struct
if isdict(pard):
par = par_struct(pard)
par._FromStringToTrueType()
else:
par = pard
# if parameters.txt, set the path_data
if hasattr(par,'path_data'):
par.path_data = pdata
par.root_path = Path
# myprintv("pdata: ", par.path_data)
if hasattr(par,'path_packages'):
par.path_packages = os.path.join(Path,par.path_packages)
# returning the result
return par
私のプログラムを実行すると、上記の両方の分割方法でエラーが発生します。私は、私は信じている 'NoneType' オブジェクトが属性 'スプリット' を持っていない"AttributeError: 'NoneType'オブジェクトに 'split'属性がありません。"
:表示されたエラーがget_par Thepdata = ThePath.split( 'GeneralParameters'、パス)で
ライン216、[0] はAttributeErrorです小さなエラーを作りますが、私は知りません、ちょうどプログラミングを始めます。事前にNone
を返しlocate_dir
「locate_dir」はどこに定義されていますか? – bernie
'locate_dir()'は 'None'を返しました。あなたの質問にその機能を追加してください。 –
あなたの質問にコードを追加し、正しくフォーマットしてください!あなたは偶然、「見つけて警告:ディレクトリが見つかりません!」というメッセージを受け取っていますか?何も返さない場合は、エラーを発生させる必要がありますが、呼び出しコードでは何かが必要であることに注意してください。 – MisterMiyagi