import problem

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

import problem

scott macri
Hello,
I'm having a strange issue and have already spent an hour trying to
figure it out.

I created a python app called mn.  Then I setup all my models and
stuff to work under mn.hcp.  Everything has been working fine until I
tried to use date time in a py file in the hcp directory.

I've imported datetime, with import date time at the top of my py
file.  Then within the file I have a class with an internal method
trying to use some date functions.

datetime.date(2003,11,11)

For some reason I am getting a NameError on the datetime object.  I
don't understand why this is happening after I've imported datetime.
Any help would be appreciated.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

DrBloodmoney
On Wed, Feb 15, 2012 at 10:48 PM, Scott <[hidden email]> wrote:

> Hello,
> I'm having a strange issue and have already spent an hour trying to
> figure it out.
>
> I created a python app called mn.  Then I setup all my models and
> stuff to work under mn.hcp.  Everything has been working fine until I
> tried to use date time in a py file in the hcp directory.
>
> I've imported datetime, with import date time at the top of my py
> file.  Then within the file I have a class with an internal method
> trying to use some date functions.
>
> datetime.date(2003,11,11)
>
> For some reason I am getting a NameError on the datetime object.  I
> don't understand why this is happening after I've imported datetime.
> Any help would be appreciated.  Thanks.

You probably have some sort of namespace collision. Look for circular
imports or import modules with the same name etc.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

Furbee-2
In reply to this post by scott macri
Can you reply with the actual NameError Exception? Like: NameError: global name 'datetime' is not defined, or whatever it is. From the module that is throwing this error are you importing anything else that is importing an overridden date method or datetime object?

You can also try this (instead of "import datetime"):

from datetime import date

On Wed, Feb 15, 2012 at 7:48 PM, Scott <[hidden email]> wrote:
Hello,
I'm having a strange issue and have already spent an hour trying to
figure it out.

I created a python app called mn.  Then I setup all my models and
stuff to work under mn.hcp.  Everything has been working fine until I
tried to use date time in a py file in the hcp directory.

I've imported datetime, with import date time at the top of my py
file.  Then within the file I have a class with an internal method
trying to use some date functions.

datetime.date(2003,11,11)

For some reason I am getting a NameError on the datetime object.  I
don't understand why this is happening after I've imported datetime.
Any help would be appreciated.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: import problem

Scott Macri-2
DrBloodmoney I not sure what you mean by circular imports.  datetime
is the only import I have in this file.

Yes Furbeenator it is a 'datetime' is not defined error.

I'll post the entire error message tonight when I get home.

My website directory is mn and my app directory is hcp.  I'm trying to
do the import on a file in the hcp app directory.  The imports of my
classes (ie from mn.hcp import something) work just fine.  The issue
seems to be with python specific imports.

Thanks.

On Wed, Feb 15, 2012 at 11:11 PM, Furbee <[hidden email]> wrote:

> Can you reply with the actual NameError Exception? Like: NameError: global
> name 'datetime' is not defined, or whatever it is. From the module that is
> throwing this error are you importing anything else that is importing an
> overridden date method or datetime object?
>
> You can also try this (instead of "import datetime"):
>
> from datetime import date
>
> On Wed, Feb 15, 2012 at 7:48 PM, Scott <[hidden email]> wrote:
>>
>> Hello,
>> I'm having a strange issue and have already spent an hour trying to
>> figure it out.
>>
>> I created a python app called mn.  Then I setup all my models and
>> stuff to work under mn.hcp.  Everything has been working fine until I
>> tried to use date time in a py file in the hcp directory.
>>
>> I've imported datetime, with import date time at the top of my py
>> file.  Then within the file I have a class with an internal method
>> trying to use some date functions.
>>
>> datetime.date(2003,11,11)
>>
>> For some reason I am getting a NameError on the datetime object.  I
>> don't understand why this is happening after I've imported datetime.
>> Any help would be appreciated.  Thanks.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [hidden email].
>> To unsubscribe from this group, send email to
>> [hidden email].
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.



--
Scott A. Macri
www.ScottMacri.com
(571) 234-1581

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

Scott Macri-2
Oh, the other thing is that if I run the exact same code in my idle
shell within the hcp app all the imports work fine.

On Thu, Feb 16, 2012 at 9:20 AM, Scott Macri <[hidden email]> wrote:

> DrBloodmoney I not sure what you mean by circular imports.  datetime
> is the only import I have in this file.
>
> Yes Furbeenator it is a 'datetime' is not defined error.
>
> I'll post the entire error message tonight when I get home.
>
> My website directory is mn and my app directory is hcp.  I'm trying to
> do the import on a file in the hcp app directory.  The imports of my
> classes (ie from mn.hcp import something) work just fine.  The issue
> seems to be with python specific imports.
>
> Thanks.
>
> On Wed, Feb 15, 2012 at 11:11 PM, Furbee <[hidden email]> wrote:
>> Can you reply with the actual NameError Exception? Like: NameError: global
>> name 'datetime' is not defined, or whatever it is. From the module that is
>> throwing this error are you importing anything else that is importing an
>> overridden date method or datetime object?
>>
>> You can also try this (instead of "import datetime"):
>>
>> from datetime import date
>>
>> On Wed, Feb 15, 2012 at 7:48 PM, Scott <[hidden email]> wrote:
>>>
>>> Hello,
>>> I'm having a strange issue and have already spent an hour trying to
>>> figure it out.
>>>
>>> I created a python app called mn.  Then I setup all my models and
>>> stuff to work under mn.hcp.  Everything has been working fine until I
>>> tried to use date time in a py file in the hcp directory.
>>>
>>> I've imported datetime, with import date time at the top of my py
>>> file.  Then within the file I have a class with an internal method
>>> trying to use some date functions.
>>>
>>> datetime.date(2003,11,11)
>>>
>>> For some reason I am getting a NameError on the datetime object.  I
>>> don't understand why this is happening after I've imported datetime.
>>> Any help would be appreciated.  Thanks.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to [hidden email].
>>> To unsubscribe from this group, send email to
>>> [hidden email].
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [hidden email].
>> To unsubscribe from this group, send email to
>> [hidden email].
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>
>
>
> --
> Scott A. Macri
> www.ScottMacri.com
> (571) 234-1581



--
Scott A. Macri
www.ScottMacri.com
(571) 234-1581

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

scott macri
In reply to this post by Furbee-2
DrBloodmoney I not sure what you mean by circular imports.  datetime
is the only import I have in this file.

Yes Furbeenator it is a 'datetime' is not defined error.

I'll post the entire error message tonight when I get home.

My website directory is mn and my app directory is hcp.  I'm trying to
do the import on a file in the hcp app directory.  The imports of my
classes (ie from mn.hcp import something) work just fine.  The issue
seems to be with python specific imports.

Thanks.

Oh, the other thing is that if I run the exact same code in my idle
shell within the hcp app all the imports work fine.

On Wed, Feb 15, 2012 at 11:11 PM, Furbee <[hidden email]> wrote:

> Can you reply with the actual NameError Exception? Like: NameError: global
> name 'datetime' is not defined, or whatever it is. From the module that is
> throwing this error are you importing anything else that is importing an
> overridden date method or datetime object?
>
> You can also try this (instead of "import datetime"):
>
> from datetime import date
>
> On Wed, Feb 15, 2012 at 7:48 PM, Scott <[hidden email]> wrote:
>>
>> Hello,
>> I'm having a strange issue and have already spent an hour trying to
>> figure it out.
>>
>> I created a python app called mn.  Then I setup all my models and
>> stuff to work under mn.hcp.  Everything has been working fine until I
>> tried to use date time in a py file in the hcp directory.
>>
>> I've imported datetime, with import date time at the top of my py
>> file.  Then within the file I have a class with an internal method
>> trying to use some date functions.
>>
>> datetime.date(2003,11,11)
>>
>> For some reason I am getting a NameError on the datetime object.  I
>> don't understand why this is happening after I've imported datetime.
>> Any help would be appreciated.  Thanks.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [hidden email].
>> To unsubscribe from this group, send email to
>> [hidden email].
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

DrBloodmoney
In reply to this post by Scott Macri-2
On Thu, Feb 16, 2012 at 9:20 AM, Scott Macri <[hidden email]> wrote:
> DrBloodmoney I not sure what you mean by circular imports.  datetime
> is the only import I have in this file.

Here are examples of circular import problems [1][2]

I am forever getting bitten by them, so it's become one of the first
things that I think about when weird things/bugs happen in Python.

[1] http://effbot.org/zone/import-confusion.htm#circular-imports
[2] http://stackoverflow.com/questions/1556387/circular-import-dependency-in-python

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

Scott Macri-2
I don't believe I have any circular imports in my code.  I have a
simple file dosomething.py, with a simple class containing a simple
function.
dosomething.py
def somefunction(some_date)

At the tope of dosomething I have:
import datetime

in the somefunction def I have:
start_date = datetime.date(int(some_date[0:4]),int(some_date[5:7]),int(some_date[8:10]))

As soon as the code gets to the line containing start_date it fails.

On Thu, Feb 16, 2012 at 11:38 AM, DrBloodmoney <[hidden email]> wrote:

> On Thu, Feb 16, 2012 at 9:20 AM, Scott Macri <[hidden email]> wrote:
>> DrBloodmoney I not sure what you mean by circular imports.  datetime
>> is the only import I have in this file.
>
> Here are examples of circular import problems [1][2]
>
> I am forever getting bitten by them, so it's become one of the first
> things that I think about when weird things/bugs happen in Python.
>
> [1] http://effbot.org/zone/import-confusion.htm#circular-imports
> [2] http://stackoverflow.com/questions/1556387/circular-import-dependency-in-python
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to [hidden email].
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>



--
Scott A. Macri
www.ScottMacri.com
(571) 234-1581

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

Furbee-2
He said he would do that later tonight.

Furbee

On Thu, Feb 16, 2012 at 2:04 PM, Dennis Lee Bieber <[hidden email]> wrote:
On Thu, 16 Feb 2012 13:41:32 -0500, Scott Macri <[hidden email]>
wrote:

>I don't believe I have any circular imports in my code.  I have a
>simple file dosomething.py, with a simple class containing a simple
>function.

       You have yet to show (at least, in the history I've seen) the exact
traceback of the error.

--
       Wulfraed                 Dennis Lee Bieber         AF6VN
       [hidden email]    HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: import problem

Scott Macri-2
WEIRD.  There must have been something messed up in my environment.  I
closed IDLE, deleted the dosomething.pyc file and reran the code.  It
seems to be working now.  I didn't make any code changes so maybe
something was in memory, who knows.  I tried deleting the pyc file
before and it didn't do anything.

Do I need to close IDLE every time I modify one of my object classes
being accessed?  I've just been recreating the object in IDLE and not
closing the window.  Any thoughts on this?  Thanks.

On Thu, Feb 16, 2012 at 5:12 PM, Furbee <[hidden email]> wrote:

> He said he would do that later tonight.
>
> Furbee
>
>
> On Thu, Feb 16, 2012 at 2:04 PM, Dennis Lee Bieber <[hidden email]>
> wrote:
>>
>> On Thu, 16 Feb 2012 13:41:32 -0500, Scott Macri <[hidden email]>
>> wrote:
>>
>> >I don't believe I have any circular imports in my code.  I have a
>> >simple file dosomething.py, with a simple class containing a simple
>> >function.
>>
>>        You have yet to show (at least, in the history I've seen) the exact
>> traceback of the error.
>>
>> --
>>        Wulfraed                 Dennis Lee Bieber         AF6VN
>>        [hidden email]    HTTP://wlfraed.home.netcom.com/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [hidden email].
>> To unsubscribe from this group, send email to
>> [hidden email].
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.



--
Scott A. Macri
www.ScottMacri.com
(571) 234-1581

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: import problem

Furbee-2
Good point, Dennis. I use Apache2, and any time I modify .py files, I need to restart the Apache2 daemon. I wish I didn't have to, but the environment needs to be flushed. Luckily, it doesn't kill the sessions or anything like, say ColdFusion when it restarts. I was wondering if there was something with your environment that was using an old copy of the file without the import, because your syntax sounded perfect. Anyway, I'm glad you got it figured out!

Furbee

On Thu, Feb 16, 2012 at 6:33 PM, Dennis Lee Bieber <[hidden email]> wrote:
On Thu, 16 Feb 2012 21:00:40 -0500, Scott Macri <[hidden email]>
wrote:


>Do I need to close IDLE every time I modify one of my object classes
>being accessed?  I've just been recreating the object in IDLE and not
>closing the window.  Any thoughts on this?  Thanks.

       If the file needs to be imported -- doing edit file/save file/
"import file", won't affect anything that has references to the previous
edition of the file. Heck, just "import file" on the second import won't
do anything -- Python will find that "file" has already been imported
and reference that module. You have to use a reload operation to get
changed modules to import a second time. But even this only replaces
stuff for NEW references; any other references won't see the new
version.

       This is especially true if you are testing in the interactive shell.
You need to spawn a totally new process to ensure a clean environment
(which is why some of us keep a command line open next to the
environment we use for editing [PythonWin, in my case -- I never could
get comfortable with IDLE]. We edit the file in the IDE, save it, and
switch to the command shell to run the program cleanly.
--
       Wulfraed                 Dennis Lee Bieber         AF6VN
       [hidden email]    HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.