w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

import python module/packge into remote machine
I am not in any way associated with the tool I am going to suggest. I have used Vagrant with VirtualBox and it has worked fine for me. The code is in a folder which is accessible from both Virtual as well as Base machine.

Categories : Python

moving python lxml module to a remote directory
Because the lxml use the c extension (they are dll files on windows or .so files on unix/linux after compiled), you can not make it works just copy the files which builded on the windows to the server simplely. And you can download the source code of lxml in lxml, And the run python setup install under the lxml root dir in the server. Or maybe you can build local and then upload the builded files to the server, just run python setup.py build under the lxml root dir in the local, and then copy the ./build/*/lxml to the server! But it may not works as it is platform related!

Categories : Python

python on linux - use 'pwd' module to read passwd file of remote machine
The pwd module will only work for the current machine. It uses the C library functions defined in <pwd.h>, which do not provide any parameters for a remote machine. However, this does not prevent you from using ssh tools to run a script on the remote machine.

Categories : Python

Import python module over the internet/multiple protocols or dynamically create module
In principle, yes, but all of the tools built-in which kinda support this go through the filesystem. To do this, you're going to have to load the source from wherever, compile it with compile, and exec it with the __dict__ of a new module. See below. I have left the actually grabbing text from the internet, and parsing uris etc as an exercise for the reader (for beginners: I suggest using requests) In pep 302 terms, this would be the implementation behind a loader.load_module function (the parameters are different). See that document for details on how to integrate this with the import statement. import imp modulesource = 'a=1;b=2' #load from internet or wherever def makemodule(modulesource,sourcestr='http://some/url/or/whatever',modname=None): #if loading from the internet, you'd

Categories : Python

why is python argparse giving the help for imported module rather than current module?
Your tone module defines an argument parser at the module level and prints the help message as it parses your command line arguments If you only want the parsing to take place if tone is being run as a script, move the parser.parse_args() call to your __main__ test block: if __name__ == '__main__': # run as a script, not imported as a module args = parser.parse_args()

Categories : Python

call ejb remote interface from another ejb module
Solved adding lookup to EJB annotation: @EJB(lookup = "java:global/MyAppTestEJB/CountryFacade!net.myapp.ejb.CountryFacadeRemote") @Singleton public class NewBean { @EJB(lookup = "java:global/MyAppTestEJB/CountryFacade!net.myapp.ejb.CountryFacadeRemote") private CountryFacadeRemote countryFacade; @Schedule(hour = "*", minute = "*") public void businessMethod() { System.out.println("NumCountries:" + countryFacade.count()); } } Is there a more elegant way to do this?

Categories : Java

python c api not able to import any module into the newly created module
Resolved this in a different way : The problem is that the __dict__ attribute of a module is read-only. I am using the python/c api for 2.7.5. After using PyModule_New there was no provisioning to execute any code into the __dict__ for imports in the api. So I used a different approach. I created a module using python code rather than the python/c api. Which has the provision to to execute some code into a modules dictionary exec 'import sys' in mymod.__dict__. The sys import provides the newly created module to have access to sys.modules which has all the available modules. So when I do another import, the program knows where to look up the path for the import. Here is the code. PyRun_SimpleString("import types,sys"); //create the new module in python PyRun_SimpleString("mymod = t

Categories : Python

python module imports itself instead of dist module
Use: from __future__ import absolute_import in your libx.something.mimetypes module, or give it a different name. See PEP 328 - Imports: Multi-Line and Absolute/Relative for the nitty gritty details. In Python 2, imports are first resolved relative to the current module, before searching the modules path; with the above statement imports are always absolute unless you use the new relative import syntax (from . import mimetypes, etc.). The statement switches import behaviour per module; adding it to your libx.something.mimetypes module will not alter behaviour of importing in other modules.

Categories : Python

How to load some data into $rootScope from remote server before the module's controller is loaded?
The $http service is implemented using promises. The code you write in your success handler will run when the promise is resolved. Due to the asynchronous nature of promises, it is unknown when this happens. It can be 1 second later or 10 seconds later. Meanwhile, your other code continues to run and your controller is probably getting loaded before the promise is resolved. The best way to tackle this problem is to think in 'asynchronous' terms, not force some kind of synchronous behavior. Here are a few valid options: You could move the code to your controller and move your logic to the success handler like this: myModule.controller('SomeCtrl', function($rootScope, $http, $location) { $http.get("http://mydomain/load_user/"). success(function(respData) { // Perform any l

Categories : Angularjs

Python : how to import module in other module
Take a minute to look at what you're trying to achieve: you want to import the module abc.py which is a part of the package lib, so in order to import it correctly you need to specify in which package it is: from lib import abc or import lib.abc as my_import On a side note, have a look at the Python Tutorial chapter on modules. Given what @Noelkd commented, I forgot to tell you about PYTHONPATH which is an environment variable that contains the folder where Python will look for the module (like the Java CLASSPATH). You need to put your root folder inside the PYTHONPATH to avoid doing some fiddling with sys.path.append. In Bash: export PYTHONPATH=<abs. path to outdir> For example, I've put outdir in my Desktop: export PYTHONPATH=~/Desktop/outdir And the import works lik

Categories : Python

How can I run a python program in Komodo IDE like in IDLE(Python GUI) using Run Module feature?
Is Python on your PATH? That is, if you open a command prompt and type python by itself, does it run? In Komodo, look under Edit/Preferences/Languages/Python3 and check the configuration. If python.exe is not on your PATH you can provide the full path to it there

Categories : Python

working in python console while executing a boost::python module
You have two options: start python with the -i flag, that will cause to drop it to the interactive interperter instead of exiting from the main thread start an interactive session manually: import code code.interact() The second option is particularily useful if you want to run the interactive session in it's own thread, as some libraries (like PyQt/PySide) don't like it when they arn't started from the main thread: from code import interact from threading import Thread Thread(target=interact, kwargs={'local': globals()}).start() ... # start some mainloop which will block the main thread Passing local=globals() to interact is necessary so that you have access to the scope of the module, otherwise the interpreter session would only have access to the content of the thread's scope.

Categories : Python

python ast module fails in pydev, succeeds in cmdline python
It seems the ast you have imported in PyDev is not the ast module in the standard library, but a package. I guess: There is a __init__.py file in the same directory as your test1.py. You selected "Add project directory to the PYTHONPATH" during the project creation. These two combined, results in that error. The ast module in the standard library is shadowed by this ast package. In cmdline python, this ast package is not in the search path, thus the ast module is imported. If you change test1.py to import ast if __name__ == '__main__': print ast.__file__ I guess the output in PyDev would be C: esearchastast\__init__.pyc

Categories : Python

Is there a way to import an embedded python script into IronPython as a python module?
It is possible. You just need to add search paths to ScriptEngine object like this: var paths = engine.GetSearchPaths(); paths.Add(yourLibsPath); // add directory to search or engine.SetSearchPaths(paths); Then you could use any module in directories, which you add: import pyFileName # without extension .py Update OK. If you want to use embedded resource strings like module, you may use this code: var scope = engine.CreateScope(); // Create ScriptScope to use it like a module engine.Execute("import clr " + "clr.AddReference("System.Windows.Forms") " + "import System.Windows.Forms " + "def Hello(): " + " System.Windows.Forms.MessageBox.Show("Hello World!")", scope); // Execute code from string in scope. Now you ha

Categories : C#

Install python module to non default version of python using .sh
You should run your scripts in a virtualenv created for your app's environment. This creates an isolated environment that uses the Python interpreter you created the virtualenv with, but with its own set of libraries. # create the virtualenv folder: M2Crypto-venv python2.7 virtualenv.py --distribute M2Crypto-venv # activate the virtualenv, changing environment variables to use its Python interpreter . M2Crypto-venv/bin/activate # see how the current python has changed which python # should be M2Crypto-venv/bin/python python --version # should be 2.7 # after activating, run your install scripts If you're using mod_wsgi or something similar to serve content, you'll want to modify your WSGI file to activate the virtualenv before doing anything else (adapted from mod_wsgi instr

Categories : Python

How can I specify the version of Python that Perl's Inline::Python module is using?
You link with desired version during the installation of the module. See Makefile.PL: #============================================================================ # What python are we going to try? #============================================================================ my @pythons; my $sep = $^O eq 'MSWin32' ? ";" : ":"; for $p (split /$sep/, $ENV{PATH}) { $p =~ s/^~/$ENV{HOME}/; $p .= "/python"; push @pythons, { path => $p } if -f $p && -x $p; } # Keep them in PATH order. #@pythons = sort { $a->{path} cmp $b->{path} } @pythons; my $num = 1; print "Found these python executables on your PATH: "; print $num++ . ". " . $_->{path} . " " for @pythons; my $sel = prompt("Use which?", '1'); $sel = $pythons[$sel-1] if $sel =~ /^d+$/; $sel = { path => $

Categories : Python

Python module import : what about modules imported in the imported module
Your experiment can be conducted very easily from the shell: ╭─phillip@phillip-laptop ~ ‹ruby-1.9.3@global› ‹pandas› ╰─$ echo "import module1" > test.py ╭─phillip@phillip-laptop ~ ‹ruby-1.9.3@global› ‹pandas› ╰─$ touch module1.py ╭─phillip@phillip-laptop ~ ‹ruby-1.9.3@global› ‹pandas› ╰─$ py Python 2.7.5 (default, May 17 2013, 07:55:04) [GCC 4.8.0 20130502 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import test >>> test.module1 <module 'module1' from 'module1.py'> >>> from test import * >>> module1 <module 'module1' from 'module1.py'>

Categories : Python

Can I bring a Python 2.6 module (fractions) to Python 2.5?
Use the source! Just download the source and modify it as needed for 2.5 I also some this: http://answers.yahoo.com/question/index?qid=20090610101000AAerKHj Or you could use SymPy: Pure Python rational numbers module for 2.5

Categories : Python

module works for /usr/bin/python but not /opt/local/bin/python
Was having this issue myself this week. The solution with thanks to [1] is to build it yourself from the git sources [2]. git clone https://github.com/Kitware/VTK.git VTK mkdir VTK-build && cd VTK-build ccmake ../VTK Press 't' for advanced mode. Ensure you've set "VTK_WRAP_PYTHON: ON". Press 'c' to run the first configure. Set PYTHON_EXECUTABLE: /to/your/python (for Macports: /opt/local/bin/python) Set PYTHON_INCLUDE_DIR: /to/your/Python.framework/Headers (for Macports: /opt/local/Library/Frameworks/Python.framework/Headers) Set PYTHON_LIBRARY: /to/your/Python.framework/libpythonx.x.dylib (for Macports: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib) Press 'c' to run final configure Press 'g' to generate make files make [sudo] make install

Categories : Python

Python - Trying to use the value of a name from one module in a different module
If I understand you correctly: from remainder import xy def GCD(x,y): #gives the Greatest Common Divisor of two values. while y != 0: r = xy(x,y) x = y y = r print x and def xy(x, y): #Gives the remainder of the division of x by y. Outputs as r. while x >= y: x -= y return x

Categories : Python

Explicitly accessing module var from module function in revealing module pattern
I want the function sayOhai to say "ohai" using the defined var. Assumed i do not want to change the parameter name of sayOhai, how can i access foo's value within sayOhai? You simply can't. The var foo is shadowed by the inner function parameter with the same name.

Categories : Javascript

Python - Detect if remote computer is on
It seems like what you're looking for is a network/host monitoring tool, or just a simple heart beat monitor. Depending on the specifics (like number of hosts to monitor), something like Nagios, Munin or Heartbeat might help.

Categories : Python

Python, Using Remote Managers and Multiprocessing
Iterating over a queue is the same as doing: while True: elem = queue.get() #queue empty -> it blocks!!! An elegant way to "iterate" over a queue and block your worker process when there are no more jobs to execute is to use None(or something else) as a sentinel and use iter(callable, sentinel): for job in iter(queue.get, None): # execute the calculation output_queue.put(result) #shutdown the worker process Which is equivalent to: while True: job = queue.get() if job is None: break #execute the calculation output_queue.put(result) #shutdown the worker process Note that you have to insert in the queu a sentinel for each worker subprocess, otherwise there will be subprocesses waiting for it. Regarding your second question, I don't understand

Categories : Python

How do I reboot the remote system via python script?
If you want to reboot remote systems without password, you need to configure the SSH key for the remote systems. First, you need to create a SSH key on the system you run your python script.By using $ ssh-keygen -t rsa -P "" Then, you change the name of your SSH key file $ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys Now, you can copy you SSH key to the remote systems.The path is ~/.ssh/ $ scp ~/.ssh/authorized_keys user@remote_ip:~/.ssh/ Job is done, Now you can login remote systems without password, so is your python script.

Categories : Python

Creating a remote a file over serial using python
As a workaround, could you use a heredoc ? ser.write("cat > file.txt << END_OF_FILE ") ser.write([contents I need to add to the file]) ser.write(" END_OF_FILE "); For a more robust solution, you should probably have to look at some file transfer protocol over serial line, like Kermit.

Categories : Python

Restart remote servers with a Python script
This article explains in detail how to configure remote shutdown for Windows: http://www.howtogeek.com/109655/how-to-remotely-shut-down-or-restart-windows-pcs/ Note that you will need Samba to get a net command which you can run from Linux. If that is no available, then the workaround is to write a small server in Python which you install on a Windows box which accepts the "restart everything" command from the Pi (use a plain socket server but implement some kind of password protection).

Categories : Python

re module in Python
You don't need regex here: >>> strs = "#define FULL_CHIP /* Turn on for chip level design */" >>> if strs.startswith('#define FULL_CHIP'): strs = '//' + strs >>> strs '//#define FULL_CHIP /* Turn on for chip level design */' If you still want to use a regex then use () to capture a group: >>> strs = "#define FULL_CHIP /* Turn on for chip level design */" >>> re.sub(r'(#define FULL_CHIP)',r'//1', strs) '//#define FULL_CHIP /* Turn on for chip level design */' The above regex will replace all #define FULL_CHIP present anywhere in the string. To replace #define FULL_CHIP that is at the start of the string use ^: >>> re.sub(r'^(#define FULL_CHIP)',r'//1', strs)

Categories : Python

Send commands to a remote machine application with Python
you can do the following: child = pexpect.spawn('telnet 192.168.0.1') child.expect('[Ll]ogin') #you use the expected output, here will match either Login or login child.sendline('username') child.expect('[Pp]assword') child.sendline('password') child.expect('your remote prompt') child.sendline('command') you can install pexpect using pip You can also have a list of expect: index = child.expect['[Ll]ogin', '[Pp]assword'] if index == 0: child.sendline('username') else index == 1: child.sendline('password')

Categories : Python

In python, how to print the docstrings of all functions defined in an imported module, without the functions that the imported module itself imported?
Functions have a __module__ attribute storing the name of the module they were defined in. You can check if that matches the module you're inspecting. Note that this will frequently miss functions that actually are part of a module's API, but were defined in a different module. For example, heapq.heappush.__module__ == '_heapq', because the function is actually defined in a C module _heapq and import *ed into the Python module heapq.

Categories : Python

get the path of a module in python
import os import your_module # Get directory of your module print os.path.dirname(your_module.__file__) Demo: import os import re print os.path.dirname(re.__file__) Output: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7

Categories : Python

Python xlrd module
row_values returns a list of cell values with appropriate data types. Data type of each item in the list depends on the cell type in the source excel file. There could be items with only string, float and int data types, see this mapping table (find there docs for Cell) for more info. u just means that this is a unicode string. Documentation explains it pretty well. Hope that helps.

Categories : Python

Python module and __all__
Listing names in __all__ does not, by itself, import items into a module. All it does is list names to import from that module if you used from database import * syntax. Import session into database/__init__.py: from .engine import session

Categories : Python

Python global in module
The key is here: 135 for __func_name in __always_supported: 136 # try them all, some may not work due to the OpenSSL 137 # version not supporting that algorithm. 138 try: 139 globals()[__func_name] = __get_hash(__func_name) The __get_hash function maps to either __get_builtin_constructor or __get_openssl_constructor depending on the availability of openssl. Let's assume openssl is not available. This is how it would look... The for __func_name line would iterate the keys of __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') And would add a reference to each in the module scope (globals()). When you call hashlib.md5(), first it uses 66 def __get_builtin_constructor(name): To define a callable which is returned. In t

Categories : Python

Python's "re" module not working?
re module is not broken. What you are likely encountering is the fact that not all HTML cannot be easily matched with simple regexps. Instead, try parsing your HTML with an actual HTML parser like BeautifulSoup: from BeautifulSoup import BeautifulSoup from requests import get request = get("http://www.allmusic.com/album/warning-mw0000106792") soup = BeautifulSoup(request.content) print soup.findAll('hgroup') Or alternatively, with pyquery: from pyquery import PyQuery as pq d = pq(url='http://www.allmusic.com/album/warning-mw0000106792') print d('hgroup')

Categories : Python

Python -- class vs module
I'm just a novice python developer, but if I understood your question correctly then you need to code something like this: import re class MathOperations: def id(_self, lst): #returns modulus 2 (1,0,0,1,1,....) for input lists return [int(lst[i])%2 for i in range(len(lst))] and then you can use the class: obj = MathOperations() obj.id([1, 2])

Categories : Python

Python Module Imports
Because you imported the CheckerBoardModule module object, not the CheckerBoard class. If you want to use just CheckerBoard, import that: from Boards.CheckerBoardModule import CheckerBoard All that importing does, apart from executing the module if that hasn't already happened, is bind the imported name in your own namespace. from foo import bar binds bar to whatever bar was bound to from foo. from foo import bar as baz lets you specify a new name.

Categories : Python

Python reload module
Manually deleting the module from the sys.modules dictionary seems to work for me. import sys import unittest import myModule class MyTest( unittest.TestCase ): def setUp( self ): global myModule myModule = __import__( 'path.to.myModule', globals(), locals(), [''], -1 ) return def tearDown( self ): global myModule del sys.modules[myModule.__name__] return

Categories : Python

passing a value to another python module
You got confused. You are running test.py, not test1.py. Run test1.py to have it call test.main(). Because you are running test.py it's __main__ block is running and branch_name is an empty string. Your code is otherwise working Just Fine: $ python test1.py ab_mr1 /private/tmp BranchName ab_mr1 Before running test1 ('In test.py, the value is: {0}', 'ab_mr1') After running test1

Categories : Python

how to add path with module to python?
Obviously, the module gyp.py is not in the search path of modules (sys.path). sys.path is an array variable in sys module which contains all known paths of the modules. You can add the directory containing the module gyp.py manually by either of these methods: set via PYTHONPATH environment variable (see http://docs.python.org/3/using/cmdline.html?highlight=path#envvar-PYTHONPATH) Add the path manually within your python script prior to importing gyp. For example, if the directory containing this module is /home/you/gyp: import os, sys sys.path.append('/home/you/gyp') import gyp #--------- That's it ------------ You can check if this path already exists using the debug lines import sys print(sys.path) # version python 3.2 or print sys.path # version python 2.7

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.