Found 10784 Articles for Python

Is it possible to use Python modules in Octave?

Rajendra Dharmkar
Updated on 30-Jul-2019 22:30:20

180 Views

There is no straightforward way to do this. But it is possible to run a Python program and parse the output. You can execute any shell command using the function system (cmd, flag). The second argument is optional. If it is present, the output of the command is returned by system as a string. If it is not supplied, any output from the command is printed, with the standard output filtered through the pager. For example,output = system ("python /path/to/your/python/script.py", 1)

How we can copy Python modules from one system to another?

Rajendra Dharmkar
Updated on 01-Oct-2019 10:50:57

4K+ Views

If you have your own Python modules you want to copy, you can simply copy them and run on other systems with Python installed. If you want to copy installed modules, the best way is to install the same version of Python on the second system. Then run$ pip freeze > installed_modules.txton the first system to get a list of the installed modules in the installed_modules.txt file. Now copy this file over to second system. Now use pip to install these modules using:$ pip install -r installed_modules.txtThis will install all modules that were installed on the first system. It is ... Read More

How we can import Python modules without installing?

Rajendra Dharmkar
Updated on 01-Oct-2019 10:51:33

4K+ Views

Yes there are ways to import Python modules without installing. If you are not able to install modules on a machine(due to not having enough permissions), you could use either virtualenv or save the module files in another directory and use the following code to allow Python to search for modules in the given module:>>> import os, sys >>> file_path = 'AdditionalModules/' >>> sys.path.append(os.path.dirname(file_path)) >>> # Now python also searches AdditionalModules folder for importing modules as we have set it on the PYTHONPATH.You can also use virtualenv to create an isolated local Python environment. The basic problem being addressed is ... Read More

How does variable scopes work in Python Modules?

Pranathi M
Updated on 16-Sep-2022 07:34:35

1K+ Views

The scope of the Python object determines its accessibility. The scope must be specified in order to access the particular variable in the code because it cannot be accessible from anywhere in the program. The term "scope" describes the precise coding region where variables are shown. It is possible to limit the visibility of variables so that only certain people can see them. Scope confirms which variable can be "Seen". The scope determines the rules that regulate how and where a variable can be searched. The variable is searched either to assign a value or to retrieve one. The namespace ... Read More

How to use Python modules over Paramiko (SSH)?

Rajendra Dharmkar
Updated on 30-Jul-2019 22:30:20

423 Views

You connect and use a python module on the remote computer over SSH, as SSH only provides limited functionality so calling the module isn't possible.You can call a script on the remote server and run that as a way of getting around this problem. To get a result from the script, you can look at it by reading the lines from stdout if you're logging your result. Alternatively, you can write the result to a file and then read the file once the result has been generated and written to the file.If you want to do this over the network ... Read More

Which one is the Python module to obfuscate javascript?

Rajendra Dharmkar
Updated on 12-Sep-2019 07:26:07

716 Views

You can use the jsmin module to minimize/obfuscate javascript code using Python. Install jsmin using:$ pip install jsminTo use jsmin in your python project to minimize a js file, say hello.js, you can use it as follows:>>> from jsmin import jsmin >>> with open('hello.js') as js_file: ...     minified = jsmin(js_file.read()) >>> print minifiedYou'll get the minified JS code printed to your shell. You can also use jsmin as a command line tool:$ python -m jsmin hello.jsYou can read more about jsmin on pypi docs: https://pypi.python.org/pypi/jsmin

How to disable logging from imported modules in Python?

Sarika Singh
Updated on 14-Nov-2022 08:02:06

19K+ Views

Applications can use the logging module to configure various log handlers and to route log messages to these handlers. This enables a very flexible design that can handle a wide range of use cases. A caller must first request a named logger in order to produce a log message. The program can set up various rules for various loggers using the name. The program can then utilise this logger to produce plain-text messages at various log levels (DEBUG, INFO, ERROR, etc.), allowing it to handle messages with a higher priority differently from those with a lower priority.Following is an example ... Read More

How do I disable log messages from the Requests Python module?

Rajendra Dharmkar
Updated on 11-Dec-2019 09:57:29

766 Views

You can disable logging from the requests module using the logging module.ExampleYou can configure it to not log messages unless they are at least warnings using the following code:import logging logging.getLogger("requests").setLevel(logging.WARNING)If you want to go a level higher and only want to log messages when they are errors or critical, you can do replace logging.WARNING with logging.ERROR and logging.CRITICAL respectively.

What are common practices for modifying Python modules?

Rajendra Dharmkar
Updated on 11-Dec-2019 09:59:06

195 Views

If you are modifying a module and want to test it in the interpreter without having to restart the shell everytime you save that module, you can use the reload(moduleName) function. reload(moduleName) reloads a previously loaded module (assuming you loaded it with the syntax "import moduleName". It is intended for conversational use, where you have edited the source file for a module and want to test it without leaving Python and starting it again.For example>>> import mymodule >>> # Edited mymodule and want to reload it in this script >>> reload(mymodule)Note that the moduleName is the actual name of the ... Read More

How we can import Python modules in Jython?

Rajendra Dharmkar
Updated on 30-Jul-2019 22:30:20

1K+ Views

You can use pure python modules from jython. You can't use modules that are implemented in C. To use modules from your pip installs, you need to add the sys.path of python to that of Jython as Jython does not automatically pick up the PYTHONPATH informationJython 2.5 introduced the JYTHONPATH environmental variable as Jython-equivalent of PYTHONPATH, so setting both to the same value should do the trick for most use cases (unless you're working in a setup with incompatible Python an Jython versions).Now you can import python modules installed locally directly using 'import' in Jython.

Advertisements