Python Forum
NameError:name'build' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError:name'build' is not defined
#1
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.
Reply
#2
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.
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm getting a NameError: ...not defined. vonArre 2 151 Mar-24-2024, 10:25 PM
Last Post: vonArre
  Getting NameError for a function that is defined JonWayn 2 1,055 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,771 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 3,198 Sep-01-2022, 07:41 PM
Last Post: deanhystad
  NameError: name ‘app_ctrl’ is not defined 3lnyn0 0 1,456 Jul-04-2022, 08:08 PM
Last Post: 3lnyn0
  NameError: name 'hash_value_x_t' is not defined Anldra12 5 1,863 May-13-2022, 03:37 PM
Last Post: deanhystad
  NameError: name 'cross_validation' is not defined tmhsa 6 13,179 Jan-17-2022, 09:53 PM
Last Post: TropicalHeat
  NameError: name “x” is not defined ... even though x is defined campjaybellson 7 14,667 Oct-20-2021, 05:39 PM
Last Post: deanhystad
  NameError: name 'Particle' is not defined in Pygame drunkenneo 4 3,298 Aug-15-2021, 06:12 PM
Last Post: bowlofred
  NameError: name 'u1' is not defined (on parser code Python) Melcu54 1 2,843 Jul-26-2021, 04:36 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020