Questions tagged [built-in]

Built-in functions, modules and classes are standard parts of a programming language or framework.

Built-in functions, modules and classes are standard parts of a programming language or framework.

Generally, all parts of a programming language or framework that don't require the installation of additional components are considered built-in.

1177 questions
28
votes
5 answers

Java ScriptEngine supported languages

Java has a ScriptEngine system that allows you to run/evaluate statements in a different language. I know for a fact that JavaScript is supported, but I couldn't find any other languages to work with it. Is, for example, Ruby implemented?
user1241335
27
votes
3 answers

Is it OK to raise a built-in exception, but with a different message, in Python?

Is it OK to raise a built-in exception with a custom text? or to raise a built-in warning also with custom text? The documentation reads: exception ValueError: Raised when a built-in operation or function receives an argument (…) Is it implied…
Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
26
votes
3 answers

Python: Why should I use next() and not obj.next()?

Python 2.6 introduced a next function. Why was this necessary? One could always type obj.next() instead of next(obj). Is the latter more pythonic?
Dave Halter
  • 15,556
  • 13
  • 76
  • 103
25
votes
8 answers

What's "better" the reverse method or the reversed built-in function?

What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
25
votes
5 answers

Extending Math object through prototype doesn't work

I try to extend JavaScript Math. But one thing surprised me. When I tried to extend it by prototype Math.prototype.randomBetween = function (a, b) { return Math.floor(Math.random() * (b - a + 1) + a); }; In console I have error 'Cannot set…
LJ Wadowski
  • 6,424
  • 11
  • 43
  • 76
25
votes
2 answers

What is Python's coerce() used for?

What are common uses for Python's built-in coerce function? I can see applying it if I do not know the type of a numeric value as per the documentation, but do other common usages exist? I would guess that coerce() is also called when performing…
Jzl5325
  • 3,898
  • 8
  • 42
  • 62
24
votes
5 answers

Python: Can a subclass of float take extra arguments in its constructor?

In Python 3.4, I'd like to create a subclass of float -- something that can be used in math and boolean operations like a float, but has other custom functionality and can receive an argument at initialization that controls that functionality.…
Shimon Rura
  • 439
  • 4
  • 13
24
votes
1 answer

Python filter function - single result

Is there a built in function in Python that will return a single result given a list and a validation function? For example I know I can do the following: resource = list(filter(lambda x: x.uri == uri, subject.resources))[0] The above will…
Giannis
  • 5,286
  • 15
  • 58
  • 113
24
votes
3 answers

Is there a Python method to access all non-private and non-builtin attributes of a class?

I would like to call a method to give me a dict of all of the "non-private" (I use the term "private" somewhat loosely here since it does not really exist in Python) and non-builtin attributes (i.e. those that do not begin with a single or double…
andy
  • 1,399
  • 3
  • 12
  • 32
23
votes
5 answers

How to add builtin functions?

I am new to python programming. How can I add new built-in functions and keywords to python interpreter using C or C++?
Rubia
  • 445
  • 2
  • 6
  • 17
23
votes
2 answers

__builtin_trap: when to use it?

gcc provides additional builtin functions "for optimization". One of them is void __builtin_trap (void) which essentially is here to abort the program by executing an illegal command. From the doc: __builtin_trap function causes the program to exit…
DevShark
  • 8,558
  • 9
  • 32
  • 56
23
votes
5 answers

How do I use Perl's localtime with print to get the timestamp?

I have used the following statements to get the current time. print "$query executed successfully at ",localtime; print "$query executed successfully at ",(localtime); print "$query executed successfully at ".(localtime); Output executed…
kiruthika
  • 2,155
  • 7
  • 26
  • 33
22
votes
4 answers

How to hint to GCC that a line should be unreachable at compile time?

It's common for compilers to provide a switch to warn when code is unreachable. I've also seen macros for some libraries, that provide assertions for unreachable code. Is there a hint, such as through a pragma, or builtin that I can pass to GCC (or…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
22
votes
1 answer

why __builtins__ is both module and dict

I am using the built-in module to insert a few instances, so they can be accessed globally for debugging purposes. The problem with the __builtins__ module is that it is a module in a main script and is a dict in modules, but as my script depending…
Anurag Uniyal
  • 85,954
  • 40
  • 175
  • 219
22
votes
1 answer

When __builtin_memcpy is replaced with libc's memcpy

There is a version of C99/posix memcpy function in GCC: __builtin_memcpy. Sometimes it can be replaced by GCC to inline version of memcpy and in other cases it is replaced by call to libc's memcpy. E.g. it was noted here: Finally, on a compiler…
osgx
  • 90,338
  • 53
  • 357
  • 513