NameError:name'build' is not defined - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: NameError:name'build' is not defined (/thread-1911.html) |
NameError:name'build' is not defined - hsunteik - Feb-04-2017 class information(object): #version 1 build=1 majorVersion=0 minorVersion=1 bugFixes=0 optimization=0 versionId=str(majorVersion)+'.'+str(minorVersion)+'.'+str(bugFixes)+'.'+str(optimization) changelogs='1)infinite procedural generation added\n2)new blocks:dirt,grass,coal ore,iron ore,diamond,ore,gold ore,etc' versionName='World is here' print("version:"+information.versionId) print('\n') print('changelogs:') print(information.changelogs) print('\n') print('version name:'+information.versionName) print('\n') print(build) but,there is one error note:the code,output and error above is edited a little(not the original)Nevermind,my mistake,found the problem and fixed it. RE: NameError:name'build' is not defined - micseydel - Feb-04-2017 It should be information.build, you should access it the same way as as you access the other ones that are assigned in the same way. RE: NameError:name'build' is not defined - snippsat - Feb-04-2017 (Feb-04-2017, 04:50 AM)hsunteik Wrote: Nevermind,my mistake,found the problem and fixed it.Some pointer,there are a style issues and none stander way of doing this stuff. So here we go: Indentation is always 4 space,object make no sense in Python 3.x,and class should have capital letter. PEP 396 Module Version Numbers: Quote:3) When a module (or package) includes a version number, the version SHOULD be available in the __version__ attribute.Eg: class Information: __version__ = '1.0'Use it: >>> Information.__version__ '1.0' >>> obj = Information() >>> obj.__version__ '1.0' Quote:str(majorVersion)+'.'+str(minorVersion)Drop str() and + Python has string formatting.>>> majorVersion = 1.0 >>> minorVersion = 0.98 >>> print('majorVersion is: {}\nminorVersion is: {}'.format(majorVersion, minorVersion)) majorVersion is: 1.0 minorVersion is: 0.98In 3.6 there is also f-string. >>> majorVersion = 1.0 >>> minorVersion = 0.98 >>> print(f'majorVersion is: {majorVersion}\nminorVersion is: {minorVersion}') majorVersion is: 1.0 minorVersion is: 0.98 |