Swamppifi Posted July 29, 2014 Share Posted July 29, 2014 Hi All I have a little problem... I have been brushing up on my python coding. I am the first to admitt it not up to scratch, so I have been working my way along a video series of tut, now I am half way along the intermidiate level and now into classes. I have been trying the following code class MyClass: name = "noname"def Main(): me = MyClass() me.name = "mr ed" print "name: " + me.nameif __name__ == '__Main__': Main()print "test" Now in Windows using python 2.7.8 , it will print "test", but not 'print "name: " + me.name' in linux it prints both, but comes up an error saying 'me' is not defined can anyone point out where I am making a mistake. Thank you Quote Link to comment Share on other sites More sharing options...
Swamppifi Posted July 29, 2014 Author Share Posted July 29, 2014 (edited) Ah ..found it the space in the line 'me.name = "mr ed" ' delete the space and it worked , can anyone explain why Edited July 29, 2014 by Swamppifi Quote Link to comment Share on other sites More sharing options...
Sitwon Posted July 29, 2014 Share Posted July 29, 2014 If I had to guess, the problem likely had to do with leading whitespace being inconsistent. When programming in Python you should always use an editor that visualizes whitespace so that you can distinguish a tab from the equivalent width of spaces. Visually they may look the same, but to the Python interpreter they will look very different.I generally prefer to use Vim. The following lines added to your .vimrc will help you out: set listchars=tab:>-,trail:- set list On Windows, I will sometimes use Notepad++. Look for the button with the Paragraph icon. (It looks like a backwards P with two vertical lines.) Quote Link to comment Share on other sites More sharing options...
Swamppifi Posted July 31, 2014 Author Share Posted July 31, 2014 Thanks for the tip sitwon I am using notepad++ already, but thanks for the info on spacing Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.