Help needed - function apparently global cannot be called.

Ian hobson42 at gmaiil.com
Tue Sep 7 17:50:24 EDT 2010


  Hi Rami, Stefan, Bruno.

First a big thanks for your replies.

On 07/09/2010 20:54, Rami Chowdhury wrote:
> Hi Ian,
>
> I think I see where you're going wrong -- this bit me too when I was 
> learning Python, having come from PHP. Unlike PHP, when you import a 
> module in Python it does *not* inherit the importing module's 
> namespace. So the "log" function you're accessing in DelNotePrinter.py 
> is not the one you defined above the import statement.
>
Hmm. My php background shows that much. Huh? :)  I guess so.
>
>>
>>     http://docs.python.org/reference/executionmodel.html#naming-and-binding
>>
>>
>     Thanks for the pointer. What a truly execrable piece of writing -
>     full of over-long sentences and multiple subordinate clauses. It
>     routinely uses terms before definition, and sometimes without
>     definition.  It is astonishingly bad.
>
>
> Perhaps you could help rewrite it? I'm sure the maintainers would be 
> very happy to get a documentation patch.
I would be happy to re-write it but I do need to understand the subject 
better before that can happen. Clear and wrong will not help anyone. :)

>
>      Do I really have to move a 4 line function into its own file and
>     import it again and again and again?
>
>
> The short answer is yes. If you have this and similar functions that 
> you call from various modules, then it's ideal to put them in a 
> utility module of their own. However, as imported modules are cached 
> in Python, this isn't as expensive as you might think if you are more 
> used to other languages.
>
OK. Now I understand the need, the solution is easy.

My first exploration of the wonders of writing windows services has had 
five things wrong with it:
    1) Its windows - spit, crash, complicated, can't start a command 
line with elevated permissions, nash teeth, rip hair out.
    2) Its services - so no stdout, or stderr,  errors not reported, no 
"current directory" - burn and crash programming all over again. Deep joy!
    3) pythonservice.exe - so module not called __main__ and 
initialisation not performed (unseen - see 2) - More fun.
    4) multi-threading   - I got really confused from this example
http://docs.python.org/library/multiprocessing.html#exchanging-objects-between-processes
  becasue I got the wrong sort of Queue, so it stalled when it failed to 
call task_done()  (there isn't such a method - but no error  reported 
see 2).
    5) Names pipes. The latest is that writing - yes writing - to the 
named pipe causes the reader to fail with
     (232, 'ConnectNamedPipe', 'The pipe is being closed.')  if I write 
using php - yet I can write with python no trouble.

There are down sides to "batteries included". When there are so many 
batteries, it can be hard to know if what you have is "good enough" or 
should you search for a more suitable one.  Logging would have helped me 
a lot (assuming it would work in service environment with the 
permissions it would have had - a serious assumption). If it failed, it 
would have failed and hidden the problem.

Oh to get on to proper GUI programming with python and PyQt! The next 
project. Wey Hey!

Thanks again

Ian




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100907/b4085f72/attachment-0001.html>


More information about the Python-list mailing list