tags:

views:

95

answers:

2

I have a block of code that basically intializes several classes, but they are placed in a sequential order, as later ones reference early ones.

For some reason the last one initializes before the first one...it seems to me there is some sort of threading going on. What I need to know is how can I stop it from doing this?

Is there some way to make a class init do something similar to sending a return value?

Or maybe I could use the class in an if statement of some sort to check if the class has already been initialized?

I'm a bit new to Python and am migrating from C, so I'm still getting used to the little differences like naming conventions.

A: 

Python upto 3.0 has a global lock, so everything is running in a single thread and in sequence.

My guess is that some side effect initializes the last class from a different place than you expect. Throw an exception in __init__ of that last class to see where it gets called.

Aaron Digulla
Py3k doesn't remove GIL AFAIK.
muhuk
A: 

Spaces vs. Tabs issue...ugh. >.>

Well, atleast it works now. I admit that I kind of miss the braces from C instead of forced-indentation. It's quite handy as a prototyping language though. Maybe I'll grow to love it more when I get a better grasp of it.

Stephen Belanger
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.Four shall be the number of spaces thou shalt indent, and the number of thyindenting shall be four. Eight shalt thou not indent, nor either indent thoutwo, excepting that thou then proceed to four. Tabs are right out.
JV
Every Python newbie has this issue. Just use it for a week and you'll get used to it; what's more, you'll start to see how much more simple it will make your life. That said, get an editor which fixes the indentation for you.
Aaron Digulla
Soon you'll find that the indentation requirement is a blessing, not a curse. I have seen a lot of unreadable C code with braces hidden in the most obscure ways.Never saw anything like this in Python.You just tell your Editor not to use TAB.
Ber
All good code is indented. Well-written C, C#, VB and Java is all indented. Python is no different.
S.Lott
I agree that good code is all indented, but it's a bit confusing at first when it's handled automatically by a computer that isn't actually smart enough to know how much to indent each line and seems to interchangeably use tabs and spaces. On that note; any better IDEs for Python than IDLE?
Stephen Belanger
Yes. Definitely. IDLE is horrible.Firstly, you may want to replace IDLE's interactive shell with ipython.As for an actual IDE, if you are willing to spend money ($70 to $150 afaik), try WingIDE. It's really very good. Personally, I use a mixture of (well configured) Vim, geany and gedit on ubuntu.
Dan
I'm trying out Komodo Edit at the moment (I'm too broke right now. ;_;), and it's been quite good so far. It'd be nice if I could figure out how to execute .py scripts though...I tried $(python) "%F", but it doesn't seem to work in Vista. Keeps trying to run "C:\Program", even with the quotes.
Stephen Belanger
I suggest that you split these last comments into new questions :) Then you'd get more answers!
Aaron Digulla