python-module

Python - problem in importing new module - libgmail

Hi all, I downloaded Python module libgmail from sourceforge and extracted all the files in the archive. The archive had setup.py, so I went to that directory in command prompt and did setup.py install I am getting the following error message I:\libgmail-0.1.11>setup.py install Traceback (most recent call last): File "I:\libgmail...

Prevent Python from caching the imported modules

While developing a largeish project (split in several files and folders) in Python with IPython, I run into the trouble of cached imported modules. The problem is that instructions import module only reads the module once, even if that module has changed! So each time I change something in my package, I have to quit and restart IPython....

Python: what modules have been imported in my process?

How can I get a list of the modules that have been imported into my process? ...

Recompiling Python to fix arrow keys in interactive mode issue

I am working in python 2.6 (installed alongside Python2.4.3 required for CentOS) and I am having issues with the arrow keys and backspace etc. I compiled from source and I imagine the solution is to recompile after installing readline-devel as outlined in: http://stackoverflow.com/questions/893053/python-shell-arrow-keys-do-not-work-on...

Getting Python's nltk.wordnet module working for Jython.

Hello, I've read through the FAQ for Jython and this post http://stackoverflow.com/questions/471000/jython-and-python-modules but am not sure how I can determine if a module is written purely in C or Python. The problem I'm facing is mentioned here http://old.nabble.com/using-NLTK-in-Jython-td28520926.html Can anyone that has done thi...

How to use named parameters and global vars with same name in Python?

Example code from a module: somevar = "a" def myfunc(somevar = None): # need to access both somevars ??? # ... if somevar was specified print it or use the global value pass if __name__ == '__main__': somevar = "b" # this is just for fun here myfunc("c") myfunc() # should print "a" (the value of global variable...

Using built-in type(,,) function to create a dynamic module

I'm trying to use the type(,,) function to dynamically build a module. The module creates classes representing templates, and I need a new class for every .tex file that lives in a particular folder. For instance, if I have a a4-page-template.tex file, I need to create a class called A4PageTemplate. I can create the type easily enough u...

Python Class in module not loading in one computer, but the other.

So I have two files: File 1 has this method in it: import MyGlobals global old_function def init(): import ModuleB global old_function MyGlobals.SomeNumber = 0 old_function = ModuleB.someClass.function ModuleB.someClass.function = someNewFunction File 2 has a class "someClass" and a class "someOtherClass". That be...

Extending python with C module

So I have a C program to interface with an i2c device. I need to interface to that device from python. I'm just wondering if it's worth porting the program into a python module or if the amount of effort involved in porting won't outweigh just executing the program using subprocess. I know I'm sure it's different for every application, b...

Mapping module imports in Python for easy refactoring

I have a bunch of Python modules I want to clean up, reorganize and refactor (there's some duplicate code, some unused code ...), and I'm wondering if there's a tool to make a map of which module uses which other module. Ideally, I'd like a map like this: main.py -> task_runner.py -> task_utils.py -> deserialization.py -> file_...

How can I get 'urlpatterns = __import__(<string_name>)' to work like a normal import statement?

I'm trying to create an import statement that's pluggable with other projects. This statement is located in urls.py So this works: from forum.urls import urlpatterns # Base Class: <type 'list'> But this doesn't work: from settings import ROOT_URLCONF as project_urls urlpatterns = __import__(project_urls) # Base Class: <type ...

Python: 'Private' module in a package

I have a package mypack with modules mod_a and mod_b in it. I intend the first two to be imported freely: import mypack import mypack.mod_a However, I'd like to keep mod_b for the exclusive use of mypack. That's because it exists merely to organize the latter's internal code. My first question is, is this -- 'private' modules -- an ...

How to properly use relative or absolute imports in Python modules?

Usage of relative imports in Python has one drawback, you will not be able to run the modules as standalones anymore because you will get an exception: ValueError: Attempted relative import in non-package # /test.py: just a sample file importing foo module import foo ... # /foo/foo.py: from . import bar ... if __name__ == "__main__": ...

How To Make Eclipse Pydev Plugin Recognize Newly Installed Python Modules?

So I just installed SubnetTree (http://www.icir.org/robin/pysubnettree/) and if I open the Python interactive interpreter I can successfully import it without any error messages. I use it in one of my programs and can successfully run it without a hitch. However, Eclipse marks the import as an error, and this is a problem as I use Eclips...

Is there a way to run a python script that is inside a zip file from bash?

I know there is a way to import modules which are in a zip file with python. I created kind of custom python package library in a zip file. I would like to put as well my "task" script in this package, those are using the library. Then, with bash, I would like to call the desired script in the zip file without extracting the zip. The ...

What's wrong with importing a python module without the full package name?

At http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Imports, it suggests: Even if the module is in the same package, do not directly import the module without the full package name. This might cause the package to be imported twice (with unintended side effects) when the "main" module that is used to start an applicatio...

html 1.13 package installation

I downloaded html 1.13 package from Python site and as per instructions I doubleclicked on install.bat and installed it. I also added the directory C:\Python26\HTML.py-0.04 to PYTHONPATH. But when I try to import the module with >>> from html import HTML I still get ImportError: No module named html Can someone help me understand w...

Is it possible to list all functions in a module?

I defined a .py file in this format: foo.py def foo1(): pass def foo2(): pass def foo3(): pass I import it from another file: main.py from foo import * # or import foo Is it possible list all functions name, e.g. ["foo1", "foo2", "foo3"]? Thanks for your help, I made a class for what I want, pls comment if you have suggestion...