Python Forum
iPython tab completion of method variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iPython tab completion of method variable
#1
is there any way to get iPython to recognize the type of "each" in B.printBarList().  for example I want to use tab-complete in iPython so I type "each." but it doesn't know the type.  

# A.py
class A:
    
    def __init__(self):
        self._foo = "FOO"

    def getFoo(self):
        return self._foo
# B.py
from A import A
class B:

    def createBarList(self):
        '''create 10 instances of A in barList'''
        barList = []
        for i in range(10):
            barList.append(A())
        return barList

    def printBarList(self, barList):
        '''
        Itter over each A in barList and print each
        ***MY QUESTION*** the "each" in the loop below
        '''
        for each in barList:
            print(each.foo)

if __name__ == "__main__":

    b = b()
    barList = b.createBarList()
    b.printBarList()
Moderator Larz60+: Changed icode tags to Python tags (see help, BBCODE)
Reply
#2
I found my answer.  as of python 3.5 


import typing

def foo(bar: int) --> int:
    return bar**2

in ipython when you enter,  "foo()" it wll prompt with "bar: int returns int". this also works with class types.

class Baz:
    def __init__(self):
        pass

def foo(bar: Baz) --> None:
    pass
Moderator Larz60+: Added Python tags. Please do this in the future (see help, BBCODE) second notice
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code Completion in Visual Studio for External Libraries mjakov 0 645 Aug-25-2024, 02:48 PM
Last Post: mjakov
  IPython errors for numpy array min/max methods muelaner 1 1,591 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Can a program execute code in iPython shell and get result? deanhystad 3 2,853 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  IPython console vs Spyder script losc 3 3,780 Apr-30-2020, 04:57 AM
Last Post: deanhystad
  How can I create a multiline input in ipython? DataMower 3 5,816 Oct-28-2019, 08:50 PM
Last Post: DataMower
  creating a variable in a method and using in another method ridgerunnersjw 5 4,133 Oct-04-2019, 04:03 PM
Last Post: buran
  ipython autocomplete broke indentation! Exsul 6 6,124 Aug-20-2019, 01:29 AM
Last Post: Exsul
  Multiprocessing Module Running An Infinite Child Process Even After Completion hsikora 0 5,186 Dec-19-2018, 08:01 AM
Last Post: hsikora
  How to clear IPython console in Spyder? Vai 7 63,055 Aug-20-2018, 09:43 PM
Last Post: james_balcomb
  Stopwatch in Python/IPython shell suvadip 3 5,416 Jul-06-2018, 01:51 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020