Python Forum

Full Version: NameError:name'build' is not defined
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
Output:
version:0.0.1.0 changelogs: 1)infinite procedural generation added 2)new blocks:dirt,grass,coal ore,iron ore,diamond,ore,gold ore,etc version name:World is here
but,
there is one error
Error:
Traceback (most recent call last):      File "information.py", line 22, in <module>           print (build) NameError: name 'build' is not defined
note:the code,output and error above is edited a little(not the original)

Nevermind,my mistake,found the problem and fixed it.
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.
(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.
5) The __version__ attribute's value SHOULD be a string.
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.98
In 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