two newbie questions ... "date from string"

Daan Hoogland hoogland at astron.nl
Tue May 13 06:20:20 EDT 2003


Thanks,  got it

Any idea on the datetime_from_string parsing question, anyone? Or do I have to
write one myself?

I can't find a function to convert a date string back to a datetime object. The
date i have is returned by postgresql in the (well known) format "YYYY-MM-DD
hh:mm:ss:mmmmmm". Am i missing something in the help? Or is there an extended
Date package that does this?


On Tue, 13 May 2003, you wrote:
> Daan Hoogland <hoogland at astron.nl> wrote in
> news:mailman.1052808978.12235.python-list at python.org: 
> 
> > Now I want to have these lines in three files. so adding some
> > import statements seemed the obvious. It failed for equally obvious
> > reasons: 
> > 
> > ImportError: cannot import name A                                     
> >          
> > 
> ><file name="A.py">
> > from B import B;
> >  
> > class A:
> >   def __init__(self):
> >     self.b = B();
> ></file>
> > 
> ><file name="B.py">
> > from A import A;
> >  
> 
> This is one of many reasons why you should avoid using the 'from module 
> import name' form of the import statement. If you simply import the module 
> then the problem (almost) goes away:
> 
> --- A.py ---
> import B
> 
> class A:
>     def __init__(self):
>         self.b = B.B()
> 
> --- B.py ---
> import A
> 
> class B:
>   def delegate(self, a):
>     a = A.A();
> 
> --------------
> Say you import A first, then the import B starts executing B.py, that calls 
> import A which succeeds immediately, even though the class A.A doesn't yet 
> exist. class B gets defined and the original import of B can complete 
> letting class A get defined.
> 
> If you imported B first then the code in A.py gets executed by the import A 
> after which the code in B.py can complete. Either way, so long as you don't 
> try to use the classes until all the imports have completed it should all 
> hang together.
> 
> Of course, if you actually try to instantiate class A in A.py it will still 
> break if B was imported first.
> 
> -- 
> Duncan Booth                                             duncan at rcp.co.uk
> int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
> "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
> -- 
> http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list