module

Rails ENV variable inside Module

How can I read ENV variable module MyModule def self.current_ip request.env['REMOTE_ADDR'] end end MyModule::current_ip How to? ...

How do I dynamically change the Perl module path?

I have two different versions of a Perl module. Currently, the crucial script uses the version of the module specified by an environment variable and the system relied on different tasks being run by different users. The user's environment would determine which version of the Perl module was used. Now I would like to change this to th...

Dynamic loading and symbols sharing

Hi, I'm trying to load a module library via dl in such way, that the module can access globals from the main application. How is that possible to do? I get an error message from dlopen saying library/name.so: undefined symbol: .... The only flag used is: RTLD_NOW. The module itself is build with libtool with -module -avoid-version. ...

Dynamically import a callable given the full module path?

>>> import_path('os.path.join') <function join at 0x22d4050> What is the simplest way to write import_path (in Python 2.6 and above)? Assume that the last component is always a callable in a module/package. ...

Writing Python packages with multiple C modules

Hello, I am writing a Python C extension which uses the pygame C API. So far so good. Now I wonder how I organize my source code so that I can have multiple submodules in the package. All the tutorials out there focus on one .c file extensions. I tried looking at some projects setup.py files but they blew my mind with complexity, and I ...

Parent App access vs Events in Flex Modules

Inspired by this Flex question, is it seen as better practice to dispatch an event back to the parent app, as opposed to calling a method on the instance of the parent app, from within a module? To me it seems that the module shouldn't know what methods are available at the parent, as such approach leads to tight coupling. Thoughts? ...

Making a module global?

I would like to know why >>> def func2(): ... global time ... import time ... >>> time Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'time' is not defined >>> func2() >>> time <module 'time' (built-in)> >>> works, but >>> def func(): ... global module ... module="time" .....

Script to find if a similar question exists

G'day, I'm creating an FAQ system, and the user needs to be able to see if a similar question has been asked. Just wondering if anyone knows of an scripts (php or javascript preferably, or possibly actionscript) that has some kind of AI that will do this? I've noticed on stackoverflow as a question is typed, related questions are given ...

Launching code for Javascript modules

Most of the javascript I work with is UI code - code that attaches additional functionality to the HTML framework of my pages and interacts with various HTML elements. Overall, I'm in favor of breaking UI code into into modules. For example, if I have code that attaches handlers to back/next buttons that implements carousel behavior, i...

Importing globally and locally

I created a module which is going to be used in several python scripts. The structure is as follows: Main file: import numpy as np from mymodule import newfunction f = np.arange(100,200,1) a = np.zeros(np.shape(f)) c = newfunction(f) mymodule.py: def newfunction(f): import numpy as np b = np.zeros(np.shape(f)) return b ...

How bad is it to override a method from a third-party module?

How bad is it to redefine a class method from another, third-party module, in Python? In fact, users can create NumPy matrices that contain numbers with uncertainty; ideally, I would like their code to run unmodified (compared to when the code manipulates float matrices); in particular, it would be great if the inverse of matrix m could...

Where would I import urllib2 for a class?

I have a class that needs access to urllib2, the trivial example for me is: class foo(object): myStringHTML = urllib2.urlopen("http://www.google.com").read() How should I structure my code to include urllib2? In general, I want to store foo in a utility module with a number of other classes, and be able to import foo by itself fr...

F# code organization: types & modules

How do you decide between writing a function inside a module or as a static member of some type? For example, in the source code of F#, there are lots of types that are defined along with a equally named module, as follows: type MyType = // ... [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] module MyType = ...

Pylons: Webhelpers: missing secure_form module

I installed Pylons 0.9.7 using the go-pylons.py script. I have a line of python: from webhelpers.html.secure_form import secure_form When I try to serve my application I get the error: no module secure_form. I've tried writing import webhelpers.html.tags and other modules from webhelpers and those work. I'm wondering why I don't ha...

Independent instances of 'random'

The below code attempts to illustrate what I want. I basically want two instances of "random" that operate independently of each other. I want to seed "random" within one class without affecting "random" in another class. How can I do that? class RandomSeeded: def __init__(self, seed): import random as r1 self.random...

[KO3] Remember the session with Auth module ?

I'm trying to make the Auth module to 'remember' the user session with a checkbox on the login page. What happens is that no cookie is created, only session as usually. I've noticed the user_tokens table, but don't see any use of user_token model's methods at all. I do pass (bool) TRUE as a third parameter to login() method, but there's ...

How to show the outcome of joomla menu item type as a module?

I am not sure how to put it ... but I am using certain modules in my joomla site which can be shown only using a menu item e.g. Phoca gallery, hwdvideoshare etc. These modules can not be displayed on any specific position, instead a menu item has to be created which links to these modules and shows them according to the configuration par...

Is there a way to set a Module to behave like a static class?

This questions is for VBers, it's irrelevant in C#. In VB, when you create a module, all it's fucntions and members are available in the scope without need to type the module name, just like all the VB functions (Rnd, Mid, IIf etc.). I want to create a module but I should have to explicitly write it's name to access it's members, i.e. ...

How do you extend class level methods to a separate module in Rails?

Given a situation such as: module Extension def self.included(recipient) recipient.extend(ModelClassMethods) end module ModelClassMethods def self.msg puts 'Hi from module' end end end class B include Extension end Why is B.msg not available? >> B.msg NoMethodError: undefined method `msg' for B:Class ...

Rails cache do inside module

Hot can I use cache do command inside module? Example module MyModule def self.some_method(str) cache str do ... some code ... end end end Thx! ...