python newbie



New to python, programming in 15 or so langs for 24 years.

Couple of questions the tuts I've looked at don't explain:

1) global vars - python sets scope to the block a var is declared (1st set), I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, or, when 1st set in a function where it is listed as a global, does that then declare the necessary global.

2) Everything is an object. So then, why the distinction between functions/variables and fields/methods. If a module is an object, would not every function be a method of that module and every variable be a field of that module?

I'm sure I will have other questions, but, I have a specific task that I am coding in python, and having a better understanding of the language will keep me from writing crap based on other language bias.

TIA,
Jim
.



Relevant Pages

  • Re: python newbie
    ... global vars - python sets scope to the block a var is ... to global vars in a function, what I'm not clear on is does ... If x is referenced, but not assigned to, then Python does not ... global statement to declare your intation. ...
    (comp.lang.python)
  • Re: python newbie
    ... are implicitly declared via the first assignment. ... It isn't at all, Python has dynamic typing. ... function which opens a file. ... Traditionally, I would declare the ...
    (comp.lang.python)
  • Re: Bug in Python class static variable?
    ... When I run "python w.py", ... statement executes: the first 'from a import *' will load and execute ... just imports names defined in the main script *before* a was ... exist until the lines which declare them have been executed. ...
    (comp.lang.python)
  • Re: What are modules really for?
    ... So, a static method is just a global method declared withing a class, which just serves as a namespace for it. ... about anything else compromise encapsulation? ... Anyway, in Python, classes know always too much from each other, don't they?, as there are no access modifiers for class attributes. ... If I want to do something, I don't declare a class that knows how to do it, then create it and invoke the right method, I just put the code to do what I want to do. ...
    (comp.lang.python)
  • Re: Function declarations - why are they needed?
    ... >> For example in Python functions are defined once and never declared ... The same holds in Fortran where you need not declare ... Fortran is typically used for large MLOC programs and there is *no* ... else) which require the called routine to have an 'explicit interface' ...
    (comp.lang.c)