How to write a warning to my log file?
Hi All, A small newbie Q. I have made a nice log function in me program. The program writes some data to me mysql database. When I write to the database I get som warnings back. Have do I write these to me log file? I know I have to use the the warnings api. But I can not figure out how to use it. Is there anyone take might give me a small example. THX all :-) -- http://mail.python.org/mailman/listinfo/python-list
How to do python and RESTful
Hi all, I want to make a web service application in python and keywords are RESTful, python and nice urls(urls mapped to python objects). I don't want a big framework but a nice small one, that can just do the things I want. I have be looking at quixote, but is this uptodate? "plain" mod_python, can this make url to http put,get,delete and post? Can some one here point me some where I can read about python and RESTful or have some experiences with other? Any help is apricieted. Regards Marc -- http://mail.python.org/mailman/listinfo/python-list
Newbie packages Q
Hi All, I do not understand the packages system in python. I have read this http://docs.python.org/tut/node8.html a 100 times and I can not get it to work. I make a test app like this: *** Test/ __init__.py (a empty file) apack/ __init__.py (a empty file) atest.py bpack/ __init__.py (a empty file) btest.py *** atest.py: from Test.bpack import btest def printA(): print "This is Atest from Apack" def printbtest(): print btest.printB() print printA() print printbtest() *** btest.py: from Test.apack import atest def printB(): print "This is Btest from Bpack" def printatest(): print atest.printA() print printatest() *** All I get is an import error: ImportError: cannot import name x I can remove the import statements an use the Test package quit normal but when I try to make intra-pacage references I get the import error. I must be missing something, could any one point me at what. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 2:16 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Would it hep to observe that the atest and btest submodules attemot to > import each other? > > There is no reason I can see for apack and bpack to be subpackages. Why > not just rename atest.py as apack.py at the same level as the Test > package's __init__.py, and in the same way make btest.py bpack.py. > > Then the __init__.py can do: > > from apack import printA > from bpack import printB > > and your main program can do > > import Test > Test.printA(...) This is away of doing it, but not a very "Package" way. The situation is I want to make a package split up in sub dir's. And each sub dir need to call the other. And I cant see why it will not work, the way i do it. And the atest and btest, shouldn't they be able to import each other?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 4:24 pm, Bruno Desthuilliers wrote: > MarkyMarc a écrit : > (snip) > > > And the atest and btest, shouldn't they be able to import each > > other?? > > import is a statement. It's executed, like any other top-level code, > when the module is imported (or the script loaded into the interpreter > if it's called directly). So if A.py imports B.py and B.py imports A.py, > you do have a circular reference that can't be solved. > > Anyway, circular dependencies are Bad(tm), so you *don't* want such a > situation. Yes it is bad and I would not do it in production. But shouldn't I be able to call one module from another module inside a package? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 5:22 pm, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > MarkyMarc wrote: > > On Oct 7, 4:24 pm, Bruno Desthuilliers > [EMAIL PROTECTED]> wrote: > >> MarkyMarc a écrit : > >> import is a statement. It's executed, like any other top-level code, > >> when the module is imported (or the script loaded into the interpreter > >> if it's called directly). So if A.py imports B.py and B.py imports A.py, > >> you do have a circular reference that can't be solved. > > >> Anyway, circular dependencies are Bad(tm), so you *don't* want such a > >> situation. > > > Yes it is bad and I would not do it in production. But shouldn't I be > > able to call one module from another module inside a package? > > Thats not the point. Intra-package references are (of course) perfectly > possible, the problem here are *circular* references (as Bruno explained). > > Secondly, if you have such circular dependencies, I would argue that > your package design might need a little reconsideration. Why do 2 > seperate modules need *each other*? To me that sounds like 2 modules > begging to be combined. > > /W It was simply to make a point. But then lets say the to files looks like this: *** atest.py: def printA(): print "This is Atest from Apack" *** btest.py: from Test.apack import atest def printB(): print "This is Btest from Bpack" def printatest(): print atest.printA() print printB() print printatest() *** Now only one of them imports the other, and this most be the simplest way of illustrating the intra-package references. But how do I get this to work? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 5:49 pm, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > MarkyMarc wrote: > > *** > > atest.py: > > > def printA(): > > print "This is Atest from Apack" > > *** > > btest.py: > > from Test.apack import atest > > > def printB(): > > print "This is Btest from Bpack" > > > def printatest(): > > print atest.printA() > > > print printB() > > print printatest() > > *** > > > Now only one of them imports the other, and this most be the simplest > > way of illustrating the intra-package references. > > But how do I get this to work? > > This doesn't work? What error do you get? > I've never done too complicated packaging stuff, and can't raelly > testdrive your example right now. Maybe you have to look into sys.path > if Test can be found at all. Or maybe you have to play with the import > statement (from apack import atest?). I'm just guessing here; importing > continues to remain going on being a mystery to me. > > /W I get "no module name Test.apack." But if I print the sys.path just before importing the Test.apack, I have this: /python/Test/bpack So "Test" is in my path. But it seems like it will not look up the path but only down. And there by do not read the __init__.py files. But I might be wrong. Anyone that can explain me how this import and packaging in python works?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 6:04 pm, Bruno Desthuilliers wrote: > MarkyMarc a écrit : > (snip) > > > It was simply to make a point. But then lets say the to files looks > > like this: > > > *** > > atest.py: > > > def printA(): > > print "This is Atest from Apack" > > *** > > btest.py: > > from Test.apack import atest > > FWIW, better to stick to all_lower names for packages and modules. > > > > > def printB(): > > print "This is Btest from Bpack" > > > def printatest(): > > print atest.printA() > > > print printB() > > print printatest() > > *** > > > Now only one of them imports the other, and this most be the simplest > > way of illustrating the intra-package references. > > > But how do I get this to work? > > You failed to specify how your files are organized, and what is "not > working". > > But anyway, if > - atest.py is in /Test/apack, > - both Test and apack have a __init__.py > - is in the sys.path, > > then this should just work AFAICT. If you se me first post you will see have me files are organized. But like this: Test/ __init__.py (a empty file) apack/ __init__.py (a empty file) atest.py bpack/ __init__.py (a empty file) btest.py And also in me first post(and others), all I get is an import error: ImportError: cannot import name apack. And sys.path is /python/Test/bpack -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 8:00 pm, Bruno Desthuilliers wrote: > > > And sys.path is /python/Test/bpack > > And you do wonder why you can't import ? Please reread with attention > the first and third points listed above (following the 'But anyway'). > The 'Test' package is *not* in your sys.path. I can say yes to the first: The atest.py is in the right dir/package. And the third. If it is not good enough that this /python/Test/bpack is in the path. Then I can not understand the package thing. I also tried to put /python/ and /python/Test in the sys.path same result. What am I missing in the intra-package references. Can anyone provide at working example? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 10:05 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > MarkyMarc <[EMAIL PROTECTED]> wrote: > >... > > > > > And sys.path is /python/Test/bpack > > sys.path must be a LIST. Are you saying you set yours to NOT be a list, > but, e.g., a STRING?! (It's hard to tell, as you show no quotes there). > > > > The 'Test' package is *not* in your sys.path. > > > I can say yes to the first: > > The atest.py is in the right dir/package. > > And the third. If it is not good enough that this /python/Test/bpack > > is in the path. > > Then I can not understand the package thing. > > > I also tried to put /python/ and /python/Test in the sys.path same > > result. > > If the only ITEM in the list that is sys.path is the string '/python', > then any Python code you execute will be able to import Test.apack (as > well as Test.bpack, or just Test). > Of course I have more than just the /python string in the sys.path. I have a list of paths, depending on which system the code run on. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie packages Q
On Oct 7, 10:31 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > MarkyMarc <[EMAIL PROTECTED]> wrote: > >... > > > > > > > And sys.path is /python/Test/bpack > > > > sys.path must be a LIST. Are you saying you set yours to NOT be a list, > > > but, e.g., a STRING?! (It's hard to tell, as you show no quotes there). >... > > > > I also tried to put /python/ and /python/Test in the sys.path same > > > > result. > > > > If the only ITEM in the list that is sys.path is the string '/python', > > > then any Python code you execute will be able to import Test.apack (as > > > well as Test.bpack, or just Test). > > > Of course I have more than just the /python string in the sys.path. > > I have a list of paths, depending on which system the code run on. > > As long as '/python' comes in the list before any other directory that > might interfere (by dint of having a Test.py or Test/__init__.py), and > in particular in the non-pathological case where there are no such > possible interferences, my assertion here quoted still holds. > > If you're having problems in this case, run with python -v to get > information about all that's being imported, print sys.path and > sys.modules just before the import statement that you think is failing, > and copy and paste all the output here, incuding the traceback from said > failing import. > > Alex OK thank you, with some help from the -v option and debugging I found a test package in some package. I now renamed it and load it with sys.path.append. And now the btest.py works. BUT does this mean I have to set the path too the package in every __init__.py class? Or have do I tell a subpackage that it is part of a big package ? -- http://mail.python.org/mailman/listinfo/python-list