Configuring the REPL's tab completion
I have absolutely no idea how to do this or even where to go looking,
so I'd appreciate a starting pointer :)
When you're in the Python REPL (just the basic core one, not IDLE or
anything), you can tab-complete global and built-in names, attributes
of known objects, etc. But quoted strings work kinda weirdly - they
try to tab-complete a global or keyword:
Python 3.8.0a0 (heads/master:8b9c33ea9c, Nov 20 2018, 02:18:50)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> "in
in input( int(
>>> "input("
'input('
I typed "in and hit tab twice, then typed p and hit tab, enter. It
filled in the function name *input*, added an open parenthesis... and
then closed the quote. Which doesn't make a lot of sense, but then,
tab completing globals and keywords inside a text string doesn't make
that much sense either.
What would be more useful would be tab-completing file names from the
current directory.
open("Foo
to fill in the name of a file. Sure, not every quoted string is a file
name (in fact, very few are), but I don't know of anything else that
would feel natural. (Also, Pike's REPL behaves this way, so presumably
it's of use to more people than me.)
Where would I start looking to try to make this happen? Doesn't
necessarily have to be pushed upstream as a core Python feature; I'm
guessing this can probably be done in sitecustomize.py. Anyone have
tutorials on messing with tab completion? There's not a lot of info in
the rlcompleter module docs.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Help!!! How to apply my created function to another function
Please see the last line When I put vectorMagnitude(A), it returns perfectly corrected that means my function create right. But when I try to put vectorMagnitude(B) which I was thinking to put new list from buildRandomVector(A),it returns an error. I have been attempting to import buildRandomVector(A) to a list, but I can not understand why the list can not apply to vectorMagnitude(B). Can you assist me in figuring the problem? Thank you!! A = [ 4, 5, 1] #TASK0 def displayVector(v) : print(v) displayVector(A) #TASK1 def buildVector(v) : print(v[0],v[1],v[2]) buildVector(A) #TASK2 import random def buildRandomVector(v) : Z = [] for i in range(len(v)): x = (random.randint(0, 9)) Z.append(x) print(Z) buildRandomVector(A) #TASK3 import math B = buildRandomVector(A) def vectorMagnitude(v) : tsum = 0 for i in v: tsum = tsum + i**2 x = math.sqrt(tsum) print(x) vectorMagnitude(B) == this is problem -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!!! How to apply my created function to another function
Dear Joyce, On 11/03/19 7:30 AM, [email protected] wrote: ... A = [ 4, 5, 1] #TASK0 def displayVector(v) : print(v) displayVector(A) ... B = buildRandomVector(A) def vectorMagnitude(v) : tsum = 0 for i in v: tsum = tsum + i**2 x = math.sqrt(tsum) print(x) vectorMagnitude(B) == this is problem Perhaps "this..." is not, but is merely where you *notice* a problem? After defining B, and before assessing its magnitude, try displaying that vector. Does it contain what you expect? -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!!! How to apply my created function to another function
On 10-3-2019 19:30, [email protected] wrote: Please see the last line When reading above, i was thinking about this joke: Q: how will you be able to keep a blonde busy for hours? A: get a paper and write see other side on both sides of the paper When I put vectorMagnitude(A), it returns perfectly corrected that means my function create right. But when I try to put vectorMagnitude(B) which I was thinking to put new list from buildRandomVector(A),it returns an error. I have been attempting to import buildRandomVector(A) to a list, but I can not understand why the list can not apply to vectorMagnitude(B). vectorMagnitude(B) == this is problem Luckily the text 'Please see first line' is missing ;) -- Luuk -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!!! How to apply my created function to another function
Luuk, On 11/03/19 8:02 AM, Luuk wrote: On 10-3-2019 19:30, [email protected] wrote: Please see the last line When reading above, i was thinking about this joke: ...> ;) Yes, I had a similar reaction to the wording: why not put *it* first. Having lived and worked in many countries/cultures, I try not to demand high degrees of English spelling or grammatical competence - and ask that natives of such places expect (only) similarly of me, in their language! OTOH... One of the disadvantages of an interpreted language is that 'things' must be defined before they can be 'used' (except in certain specific cases). So, it is not possible to execute func( args ) until 'the last line' - or more accurately, until *after* the def func( params ): etc definition. [insert discussion about "single-pass" and "multi-pass" interpreters here] I often think how much more preferable it would be to begin my programs with the 'mainline' and leave the 'compiler' to integrate the mentioned functions, classes, modules... 'later'/as-needed - instead of having if __name__ == "__main__" : towards the "last line", and having to find/scroll the editor to start reading. [yes, much web-based code has a 'director' as its mainline/.wsgi file; and imports routines as (page) handlers!] When you think about it, Python often says 'see later'/'see the last line'. Maybe the 'joke' is on us? -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Help!!! How to apply my created function to another function
[email protected] wrote: def buildVector(v) : print(v[0],v[1],v[2]) If you want to be able to use the result of this function in another computation, you need to return it, not print it: def buildVector(v) : return (v[0],v[1],v[2]) Similarly with buildRandomVector and vectorMagnitude. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
