Python Articles

Page 850 of 854

How to execute Python CGI Script on Apache Server?

Arnab Chakraborty
Arnab Chakraborty
Updated on 30-Jul-2019 598 Views

in apache server normally python script will not run. SO you have to go httpd.conf file in apache server, inside that you will find some .php, .asp etc in a property called AddHandler, you have to put there .py. save the file and restart the server. then run your python CGI script, it will run properly 

Read More

How will you explain Python Operator Overloading?

Jayashree
Jayashree
Updated on 30-Jul-2019 312 Views

Every class in Python, whether built-in or user defined is inherited from object class. The object class has a number of properties whose name is preceded and followed by double underscores (__). Each of these properties is a wrapper around a method of same name. Such methods are called special or magic methods.The magic methods __lt__(), __gt__(), __eq__(), __ne__(), etc. are overridden in a class to overload == and != operators respectively.

Read More

How can I preserve Python tuples with JSON?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 462 Views

There is no concept of a tuple in the JSON format. Python's JSON module converts Python tuples to JSON lists because that's the closest thing in JSON to a tuple. Immutability will not be preserved. If you want to preserve them, use a utility like a pickle or write your own encoders and decoders.If you're using pickle, it won't store the Python temples in JSON files but in pkl files. This isn't useful if you're sending data across the web. The best way is to use your own encoders and decoders that will differentiate between lists and tuples depending on ...

Read More

Do you think a Python dictionary is thread safe?

George John
George John
Updated on 30-Jul-2019 2K+ Views

Yes, a Python dictionary is thread safe. Actually, all built-ins in python are thread safe. You can read moreabout this in the documentation: https://docs.python.org/3/glossary.html#term-global-interpreter-lock

Read More

How to optimize Python Dictionary for performance?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 809 Views

dicts in python are heavily optimized. Creating a dict from N keys or key/value pairs is O(N), fetching is O(1), putting is amortized O(1), and so forth. You don't need to optimize them explicitly. You can be sure of this as python under the hood implements its own classes using dicts.Don't compare lists/tuples to dicts/sets though as they solve different problems.

Read More

How to split Python dictionary into multiple keys, dividing the values equally?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 967 Views

Very use case specific: https://stackoverflow.com/questions/30447708/split-python-dictionary-into-multiple-keys-dividing-the-values-equally

Read More

How to change the look of Python operators?

Sai Subramanyam
Sai Subramanyam
Updated on 30-Jul-2019 205 Views

Python and most mainstream languages do not allow changing how operators look. If you're trying to replace something like a == b with a equals b, you can't do that. In Python the restriction is quite intentional — an expression such as a equals b would look ungrammatical to any reader familiar with Python.

Read More

Can we change operator precedence in Python?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 550 Views

No this cannot be done. It's part of the Python language itself. That's how the language parses the expressions and builds parse and syntax trees. From the documentation:When performing mathematical operations with mixed operators, it is important to note that Python determines which operations to perform first, based on a pre-determined precedence. This precedence follows a similar precedence to most programming languages.

Read More

How can we speed up Python "in" operator?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 633 Views

The python operator performs very badly in a list, O(n), because it traverses the whole list. You can use something like a set or a dict(hashed data structures that have very fast lookups) to get the same result in ~O(1) time!But this also depends on the type of data structure you're looking at. This is because while lookups in sets/dicts are fast, insertion may take more time than list. So this speedup really depends on the type.

Read More

What is operator binding in Python?

Ankitha Reddy
Ankitha Reddy
Updated on 30-Jul-2019 593 Views

For expressions like − a == b first the python interpreter looks up the __eq__() method on the object a. If it finds that, then executes that with b as argument, ie, a.__eq__(b). If this method returns a NotImplemented, then it tries doind just the reverse, ie, it tries to call, b.__eq__(a)

Read More
Showing 8491–8500 of 8,532 articles
« Prev 1 848 849 850 851 852 854 Next »
Advertisements