Random questions again = one tho.

Hi, 1st of all, I know this isnt c++ or c… But why doesnt python use code {}? It seem more work friendly to me. Like so,

If (bla bla == bla bla)
   {do this}
else if (bla bla == bla bla)
   {do this}

It work seem more easier then just having to make sure everything is space right. Cus doing def. seem kinda of hard when there is no {} to go with, or I could be wrong… trying to get things to work with in my code.

#-----------------------start------------------------------
    def loading():
		f = open("networking/Users/Mradr.txt","r")
		lineList = f.readlines()
		f.close()
		print repr(lineList[2]) 
		town = lineList[2].strip()
		#Load the first environment model town.egg 
		environ = loader.loadModel("towns/a")
		environ.reparentTo(render) 
		environ.setScale(0.15,0.15,0.15) 
		environ.setPos(0,0,0)

		#waterpiller = loader.loadModel("towns/water")
		#waterpiller.reparentTo(render)
		#waterpiller.setScale(0.15,0.15,0.15)
		#waterpiller.setPos(-1000,-100000,-64)
		#watershader = Shader.load("shaders/water.sha")
		#waterpiller.setShader(watershader)
#----------------------end-------------------------------
#----------------------start-------------------------------
    def controlroom():
	#environ.destroy()
	loader.unloadModel("towns/controlroom")
	#Load the first environment model town.egg
	environ = loader.loadModel("towns/controlroom")  
	environ.reparentTo(render) 
	environ.setScale(0.15,0.15,0.15) 
	environ.setPos(0,0,0)
#----------------------end-------------------------------

	loading()

The Def above the loading command is also being added to the def controlroom(). And if I try to space them so they dont add the loading() I get a error IndentationError: unindent does not match any outer indentation level. Make no secne to me… I move the def controlroom() over so it wont be in line with it…>.>;

You can get braces in python but you have to import them form a special module called future where all the experimental features live.

from __future__ import braces

I for one love the indentation you would have to do indentation any ways in order to do be good style why just not do it in the first place? You also never have any problem matching braces. I think your frustration with spaces is due to the editor you use i recommend pyDev or komodo edit. There you just high light a block you want to indent press [tab] or [shift-tab] to unindent.

Your error of:
“IndentationError: unindent does not match any outer indentation level”
is probably due to the mixture of spaces and tab. You need to tell your editor to always use spaces and only use 4 spaces for indent level. Every one goes though this little hazing phase when learning python.

another issue is with your def controlroom()'ish line.

this line starts with a space sign - thats why python thinks, it is intended.

also the other commands belonging to def controlroom() need intendation. Otherwise python thinks that the “def” block ends after the “def…” line.

but then Python would argue again… you can’t def a empty function (it needs at least a “pass” command so that any command is issued).

The braces thing is something that (imho) works very much against the idea of “sanity-based” programming.

Whenever you see, that you have five apples and you know you need at least 4 for guests, you can choose to eat one.

if apples >4:
  eat one
else:
   if your_money not > 0:
      leave them alone
   else:
      buy new ones
      eat one

You don’t think in braces, do you? :wink:

Regards, Bigfoot29

Basically Braces and “;” at the end of the lines could be seen as
artefact from older compiler…

Just imagine , for a 10 000 Lines of code , you get 10 000 “;” that dont give
any single bit of information, just waste keyboard keys and programmer wrist…

For an average programmer at 60WPM(300 letters / minute)
=>You lose 30 minutes of your life !

Ok that was my silly rant about oldies in languages

True, this idea would work best with out the {}:

if apples >4: 
  eat one 
else: 
   if your_money not > 0: 
      leave them alone 
   else: 
      buy new ones 
      eat one

but if you think about everything being a if (sorta like I do)
def = if

    if loading(): [color=darkred]{
      f = open("networking/Users/Mradr.txt","r") 
      lineList = f.readlines() 
      f.close() 
      print repr(lineList[2]) 
      town = lineList[2].strip() 
      #Load the first environment model town.egg 
      environ = loader.loadModel("towns/a") 
      environ.reparentTo(render) 
      environ.setScale(0.15,0.15,0.15) 
      environ.setPos(0,0,0) [color=darkred]}


#---lets say this wasnt to be in the code---
      #waterpiller = loader.loadModel("towns/water") 
      #waterpiller.reparentTo(render) 
      #waterpiller.setScale(0.15,0.15,0.15) 
      #waterpiller.setPos(-1000,-100000,-64) 
      #watershader = Shader.load("shaders/water.sha") 
      #waterpiller.setShader(watershader)

The last half wouldnt be added now if we use {} as shown in red it wouldnt add them…Now I do understand the not need of ; anymore, that was a wast of space for the most part.

Anyways thanks so far answering my questions.

I wonder whats the usage if you use spaces to inline your code still…

Its two more signs that could cause trouble (eg. if you don’t close them…)

Maybe I am too stupid to find the point of interest, but: what would change if you just remove the {}?

It would help to keep programming habits, you have get used to in the past, through, but other than that? scratches itchie

Basically the rule is:
{ : start putting a tab or several " " signs in front of your code as its highly recommened coding style anyway
} : Stop using another tab or several " " signs in front of your code as its highly recommened coding style anyway

So basically your code using {} doesn’t follow the recommened coding style… (makes it hard to read because you can easily oversee the “}” especcially here in the bbstyle-elements.

Its nice that treeform could help - and I will shut up as well - its just something that doesn’t make sense to -> me <- :wink:

Regards, Bigfoot29

Regards, Bigfoot29

Please dont get me wrong Bigfoot29, I see what your saying, its just to me using {} would be a little nicer then just using the space them selfs. Thanks for your input too tho ^.^; I’ll shut up too lol.

In fact, Python had support for block notation from it’s begining:

if foo: #{
     foo1();
     foo2();
     foo3();
#}

Inspired by Larry Wall (Perl), Guido also made sure that the ending delimiter could be written in various other ways, such as #end if. Anything to empower the newbies, you know. But real Python programmers tend to omit both semicolons and curly braces, of course.

Hmm… maybe a more technical explanation of this undocumented feature:

Python Block Delimited Notation Parsing Explained

Python incorporates a sophisticated parser and advanced notation for recognizing block delimiters from almost any computer language. The foreign language notations of C, Ada Pascal, TCL, and Perl will work in most situations. The Python parser only requires two minor modifications to the block notation rules of the foreign language’s grammar rules in order to be Python compliant.

The first change is the addition of a rule which states that indentation of code is not simply a stylistic suggestion like it is in other languages. It is mandatory in Python. The use of indentation is considered good coding practice in all these languages and Python takes this a step further by making it required by the language grammar. In Python the meaning of a code block which is not properly indent is not defined. Experienced Python programmers find this rule to be very helpful in making everyone’s code more readable. An added benefit is that language sensitive editors, such as Xemacs, can assist in writing code since they are able to automate the indentation of code blocks.

The second change to to the grammar rules of foreign languages is that all symbols used to indicate the beginning or end of a block must be prefixed with the ‘#’ character. If you are a former Pascal or Ada programmer this will change your usual notation to:

	if x: #BEGIN
		x = x + 1
	#END

If you are more familiar with C and C++ then you will be comfortable with either:

	if x: #{
		x = x + 1
	#}

or:

	if x:
		x = x + 1

or even:

	if x: x = x + 1

C programmers will be happy to hear that the Python parser will do the right thing even if curly braces are not included when two trailing statements are present:

	if x:
		x = x + 1
		y = 3 + x

This last feature will fix a common source of bugs in C, C++, and Java programs.

Python’s parser is also sophisticated enough to recognize mixed notations, and it will even catch missing beginning or end delimiters and correct the program for the user. This allows the following to be recognized as legal Python:

	if x: #BEGIN
		x = x + 1
	#}

or even:

	if x: #{
		x = x + 1

Now as you can see from this series of examples, Python has advanced the state of the art of parser technology and code recognition capabilities well beyond that of the legacy languages. It has done this in a manner which carefully balances good coding style with the need for older programmers to feel comfortable with look of the language syntax.

(quoted from the Python humor page :slight_smile:
enn0x

i think my

joke was funnier but no one got it :frowning: ehhh

>>> from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance
>>>

I love Python :slight_smile:

hey, I am outing myself as a NUB there - but I thought it would be possible… :stuck_out_tongue:

But well, the result is funneh :smiley:

hey ennox… wasn’t the “#” “operator” meant to show that following code is just a comment? :stuck_out_tongue:

But yeh… I am a noob… I surely got that wrong XD

Regards, Bigfoot29