TypeError: 'module' object is not callable

2011-08-11 Thread Forafo San
I wrote a class, Univariate, that resides in a directory that is in my 
PYTHONPATH. I'm able to import that class into a *.py file. However when I try 
to instantiate an object with that class like:

x = Univariate(a) # a is a list that is expected by the Univariate 
class

python raises the TypeError: 'module' object is not callable.  If I embed the 
code of the Univariate class in my *.py file, there is no problem.  Also, when 
the class is imported and I do a

print dir(Univariate)

it does not print all the methods that are in the class, while if the class 
code appears in my *.py file, all the methods are available and a list with the 
correct methods are printed.

What gives?

Thanks in advance.
==
FreeBSD 7.2 machine with python version 2.5.6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: 'module' object is not callable

2011-08-11 Thread Forafo San
On Thursday, August 11, 2011 8:22:20 PM UTC-4, MRAB wrote:
> On 11/08/2011 23:43, Forafo San wrote:
> > I wrote a class, Univariate, that resides in a directory that is in my 
> > PYTHONPATH. I'm able to import that class into a *.py file. However when I 
> > try to instantiate an object with that class like:
> >
> > x = Univariate(a) # a is a list that is expected by the 
> > Univariate class
> >
> > python raises the TypeError: 'module' object is not callable.  If I embed 
> > the code of the Univariate class in my *.py file, there is no problem.  
> > Also, when the class is imported and I do a
> >
> > print dir(Univariate)
> >
> > it does not print all the methods that are in the class, while if the class 
> > code appears in my *.py file, all the methods are available and a list with 
> > the correct methods are printed.
> >
> > What gives?
> >
> I think you mat be confusing the class with the module.
> 
> When you write:
> 
>  import Univariate
> 
> you're importing the module.
> 
> If the module is called "Univariate" and the class within the module is
> called "Univariate" then you should either write:
> 
>  import Univariate
>  x = Univariate.Univariate(a) # the class Univariate in the module 
> Univariate
> 
> or:
> 
>  from Univariate import Univariate
>  x = Univariate(a)
> 
> Incidentally, it's recommended that module names use lowercase, so that
> would be:
> 
>  import univariate
>  x = univariate.Univariate(a)
> 
> or:
> 
>  from univariate import Univariate

Thank you all for your replies. When I do a

from Univariate import Univariate

the TypeError disappears and everything is fine.  Clearly this was an error 
that a newbie such as myself is likely to make because of little experience 
with Python. However, this isn't something I'm likely to forget.

I will also adopt the style recommendations.  Thanks, again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Replacement for the shelve module?

2011-08-19 Thread Forafo San
Folks,
What might be a good replacement for the shelve module, but one that
can handle a few gigs of data. I'm doing some calculations on daily
stock prices and the result is a nested list like:

[[date_1, floating result 1],
 [date_2, floating result 2],
...
 [date_n, floating result n]]

However, there are about 5,000 lists like that, one for each stock
symbol. Using the shelve module I could easily save them to a file
( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the
data. But shelve is deprecated AND when a lot of data is written
shelve was acting weird (refusing to write, filesizes reported with an
"ls" did not make sense, etc.).

Thanks in advance for your suggestions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacement for the shelve module?

2011-08-19 Thread Forafo San
On Aug 19, 11:54 am, Thomas Jollans  wrote:
> On 19/08/11 17:31, Forafo San wrote:
>
>
>
>
>
>
>
>
>
> > Folks,
> > What might be a good replacement for the shelve module, but one that
> > can handle a few gigs of data. I'm doing some calculations on daily
> > stock prices and the result is a nested list like:
>
> > [[date_1, floating result 1],
> >  [date_2, floating result 2],
> > ...
> >  [date_n, floating result n]]
>
> > However, there are about 5,000 lists like that, one for each stock
> > symbol. Using the shelve module I could easily save them to a file
> > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the
> > data. But shelve is deprecated AND when a lot of data is written
> > shelve was acting weird (refusing to write, filesizes reported with an
> > "ls" did not make sense, etc.).
>
> > Thanks in advance for your suggestions.
>
> Firstly, since when is shelve deprecated? Shouldn't there be a
> deprecation warning onhttp://docs.python.org/dev/library/shelve.html?
>
> If you want to keep your current approach of having an object containing
> all the data for each symbol, you will have to think about how to
> serialise the data, as well as how to store the documents/objects
> individually. For the serialisation, you can use pickle (as shelve does)
> or JSON (probably better because it's easier to edit directly, and
> therefore easier to debug).
> To store these documents, you could use a huge pickle'd Python
> dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2;
> this is what shelve uses), or simple the file system: one file per
> serialised object.
>
> Looking at your use case, however, I think what you really should use is
> a SQL database. SQLite is part of Python and will do the job nicely.
> Just use a single table with three columns: symbol, date, value.
>
> Thomas

Sorry. There is no indication that shelve is deprecated. I was using
it on a FreeBSD system and it turns out that the bsddb module is
deprecated and confused it with the shelve module.

Thanks Ken and Thomas for your suggestions -- I will play around with
both and pick one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Weird python behavior

2013-04-24 Thread Forafo San
Hello All,
I'm running Python version 2.7.3_6 on a FreeBSD system. The following session 
in a Python interpreter throws a mysterious TypeError:

--
[ppvora@snowfall ~/xbrl]$ python 
Python 2.7.3 (default, Apr 22 2013, 18:42:18) 
[GCC 4.2.1 20070719  [FreeBSD]] on freebsd8
Type "help", "copyright", "credits" or "license" for more information.
>>> import glob
Traceback (most recent call last):
  File "", line 1, in 
  File "glob.py", line 14, in 
myl = glob.glob('data/*.xml')
TypeError: 'module' object is not callable
--
The file glob.py that the error refers to was run under another screen session. 
It's a mystery why even that program threw an error. Regardless, why should 
that session throw an import error in this session? Weird. Any help is 
appreciated. Thanks,
-Premal 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Weird python behavior

2013-04-24 Thread Forafo San
On Wednesday, April 24, 2013 3:08:27 PM UTC-4, Neil Cerutti wrote:
> On 2013-04-24, Forafo San  wrote:
> 
> > Hello All,
> 
> > I'm running Python version 2.7.3_6 on a FreeBSD system. The following 
> > session in a Python interpreter throws a mysterious TypeError:
> 
> >
> 
> > --
> 
> > [ppvora@snowfall ~/xbrl]$ python 
> 
> > Python 2.7.3 (default, Apr 22 2013, 18:42:18) 
> 
> > [GCC 4.2.1 20070719  [FreeBSD]] on freebsd8
> 
> > Type "help", "copyright", "credits" or "license" for more information.
> 
> >>>> import glob
> 
> > Traceback (most recent call last):
> 
> >   File "", line 1, in 
> 
> >   File "glob.py", line 14, in 
> 
> > myl = glob.glob('data/*.xml')
> 
> > TypeError: 'module' object is not callable
> 
> > --
> 
> > The file glob.py that the error refers to was run under another
> 
> > screen session. It's a mystery why even that program threw an
> 
> > error. Regardless, why should that session throw an import
> 
> > error in this session? Weird. Any help is appreciated. Thanks,
> 
> 
> 
> 'Cause Python's import statement looks in the current directory
> 
> first for files to import. So you're importing your own
> 
> error-riddled and mortal glob.py, rather than Python's pristine
> 
> and Olympian glob.py.
> 
> 
> 
> -- 
> 
> Neil Cerutti
> 
>   "This room is an illusion and is a trap devisut by Satan.  Go
> 
> ahead and dauntlessly!  Make rapid progres!"
> 
>   --Ghosts 'n Goblins

OK, lesson learned: Take care not to have module names that conflict with 
python's built ins. Sorry for being so obtuse.
-- 
http://mail.python.org/mailman/listinfo/python-list