Python Articles

Page 853 of 854

When are python objects candidates for garbage collection?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 290 Views

A python object or variable will be eligible for garbage collection as soon as all references to it go out of scope or are manually deleted (del x). We would have to presume there were no references to the object anywhere else for it to be garbage collected.

Read More

How to exit from a Python if clause?

Malhar Lathkar
Malhar Lathkar
Updated on 30-Jul-2019 570 Views

It is not possible to exit from an if block of Python code. The break keyword does appear in if block but it has to inside a loop. It is however possible to exit from entire program from inside if block by sys.exit()

Read More

What is the difference between the != and <> operators in Python?

Malhar Lathkar
Malhar Lathkar
Updated on 30-Jul-2019 333 Views

In Python 2.x, both != and operators are available to check if two operands are not equal. Both return true if operands are not equal and false if they are equal.In Python 3.x, operator has been deprecated.

Read More

Why there is not do...while loop in Python?

Pythonista
Pythonista
Updated on 30-Jul-2019 1K+ Views

PEP 315 (Python Enhancement Proposal) to include do..while statement has been rejected because it doen't fit in the general format of indented block statement: indented block used by every other Python compound statement. In words of Guido Van Rossum -  "Please reject the PEP. More variations along these lines won't make the language more elegant or easier to learn. They'd just save a few hasty folks some typing while making others who have to read/maintain their code wonder what it means".

Read More

What is the max length of a Python string?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 4K+ Views

With a 64-bit Python installation, and 64 GB of memory, a Python 2 string of around 63 GB should be quite feasible. If you can upgrade your memory much beyond that, your maximum feasible strings should get proportionally longer. But this comes with a hit to the runtimes.With a typical 32-bit Python installation, of course, the total memory you can use in your application is limited to something like 2 or 3 GB (depending on OS and configuration), so the longest strings you can use will be much smaller than in 64-bit installations with very high amounts of RAM.

Read More

Where can I find good reference document on python exceptions?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 128 Views

The following link is a  good reference document on python exceptionshttps://docs.python.org/2/library/exceptions.html

Read More

Is it possible to use Python modules in Octave?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 367 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)

Read More

How to use Python modules over Paramiko (SSH)?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 656 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

How to prohibit a Python module from calling other modules?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 293 Views

You can use "Sandboxed Python". A "Sandboxed Python" would let you permit or forbid modules, limit execution slices, permit or deny network traffic, constrain filesystem access to a particular directory (floated as "/"), and so on. It is also referred to as RestrictedExecution. There are many ways to implement sandboxing on Python. You could Modify the CPython Runtime, Use Another Runtime, Use Operating System Support, etc to implement such a sandbox. You can read more about sandboxing at: https://wiki.python.org/moin/SandboxedPythonPypi has a package called RestrictedPython(https://pypi.python.org/pypi/RestrictedPython) that is a defined subset of the Python language which allows to provide a program input ...

Read More

Do recursive functions in Python create a new namespace each time the function calls itself?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 234 Views

Yes, a function call (any function call, not just recursive ones) creates a new namespace. BUT, when given as parameters, OBJECTS are passed by reference.So, the new namespace get its own copy of this reference but it still refers to the same object as in the calling function, and if you change the content of that object, you will notice the change in the calling function.To be more specific, Whenever the Interpreter encounters a call to a function, its creates a frame object, which is pushed to a frame stack. Each time a frame is created, that frame is given ...

Read More
Showing 8521–8530 of 8,532 articles
Advertisements