Re: Accessing variables in __init__.py
On Tuesday, October 16, 2012 3:41:55 PM UTC+5:30, Marco Nawijn wrote: > On Tuesday, October 16, 2012 10:48:17 AM UTC+2, Gaudha wrote: > > > my_package/ > > > > > > __init__.py > > > > > > my_module1.py > > > > > > my_module2.py > > > > > > variables.py > > > > > > > > > > > > I want to define common variables in __init__.py and use the namespace in > > my_module1.py or my_module2.py. Defining it is not a problem. How can call > > it from my modules? > > > > > > > > > > > > If I define them in a module (say, variables.py), I can call them by > > importing variables.py in other modules. How can it be done if I define it > > in __init__.py? > > > > > > > > > > > > It may be a silly query as I am newbie in Python. But, I would be grateful > > to get help. > > > > Hi, > > > > If you store the variables in __init__.py, you can import them from the > package. So in your case suppose __init__.py contains: > > a = 10 > > b = {1 :"Hello", 2: "World" } > > > > Than if you import my_package, you can access the variables as follows > (interactive IPython session): > > > > In [1]: import my_package > > > > In [2]: my_pack > > my_package my_package/ > > > > In [2]: my_package. > > my_package.a my_package.b > > > > In [2]: my_package.a > > Out[2]: 10 > > > > In [3]: my_package.b > > Out[3]: {1: 'Hello', 2: 'World'} > > > > In [4]: Yea. I got it. It was a new information for me. A module in a package can import its own mother package to call the variables in __init__. Is it funny or an extraordinary feature? Anyway. I felt it as something weird. Guido should have done it something like how 'self' behaves in classes. -- http://mail.python.org/mailman/listinfo/python-list
Accessing variables in __init__.py
my_package/ __init__.py my_module1.py my_module2.py variables.py I want to define common variables in __init__.py and use the namespace in my_module1.py or my_module2.py. Defining it is not a problem. How can call it from my modules? If I define them in a module (say, variables.py), I can call them by importing variables.py in other modules. How can it be done if I define it in __init__.py? It may be a silly query as I am newbie in Python. But, I would be grateful to get help. -- http://mail.python.org/mailman/listinfo/python-list
Re: to use unicode strings only
On Jun 27, 9:44 pm, Benjamin Peterson wrote: > Gaudha gmail.com> writes: > > > And Peter, I tried importing the __future__ module. It's also not > > working... > > How so? Sorry guys, __future__ module is working excellent :-). I had some bad coding somewhere else, just fixed it. Anyway, thank you for all... -- http://mail.python.org/mailman/listinfo/python-list
Re: to use unicode strings only
On Jun 27, 4:54 pm, Peter Otten <__pete...@web.de> wrote: > MRAB wrote: > > Gaudha wrote: > >> I wanna make all the strings in my code unicode strings. How to do it > >> without giving unicode switch 'u' before every string? > > > Use Python 3.1 instead. > > or use > > from __future__ import unicode_literals > > in Python 2.6. I know about Python 3.1 have the capability. But, unfortunately the community for which I'm working do not prefer Python 3.*... And Peter, I tried importing the __future__ module. It's also not working... -- http://mail.python.org/mailman/listinfo/python-list
to use unicode strings only
Hey gentlemen, I wanna make all the strings in my code unicode strings. How to do it without giving unicode switch 'u' before every string? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop a function execution like...
On Jun 16, 4:45 pm, "Diez B. Roggisch" wrote: > Gaudha wrote: > > Is there any built-in function to stop execution of a function similar > > to stop the program execution by sys.exit? > > In the example below, I want to skip statement 2... if the 'if' > > condition is satisfied. > > Don't advice me to put statement 2 in 'else' block. That's not my > > intention. > > Why not? It's from all you tell us perfectly the right thing to do. > > > May be this a simple task. Sorry to say I'm novice in Python, > > gentlemen... > > > def funct : > > if (.) : statement 1 > > statement 2 > > def funct(): > if ...: > statement 1 > return > statement 2 > > would also work. But it is not really "better" than using else. > > Diez I considered 'return' as meant only for returning any value. Thank you sir... -- http://mail.python.org/mailman/listinfo/python-list
how to stop a function execution like...
Is there any built-in function to stop execution of a function similar to stop the program execution by sys.exit? In the example below, I want to skip statement 2... if the 'if' condition is satisfied. Don't advice me to put statement 2 in 'else' block. That's not my intention. May be this a simple task. Sorry to say I'm novice in Python, gentlemen... def funct : if (.) : statement 1 statement 2 -- http://mail.python.org/mailman/listinfo/python-list
openhook
Can anybody tell me what is meant by 'openhook' ? -- http://mail.python.org/mailman/listinfo/python-list
help needed on loop controls
Hi Pythons I have got some problems with exiting and continuing nested loops. Some solving ideas found somewhere like http://offog.org/ideas/python-loop-exit.html. I searched in depth of the Official Python Documentation and couldn't find any like that. Did that ideas implemented as it is or in some better way? If so, please give me information about that. If not, please advice me any tricks to make it possible... -- http://mail.python.org/mailman/listinfo/python-list