Python Forum
creating a variable in a method and using in another method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating a variable in a method and using in another method
#5
Thanks everyone for your comments....Please bear with me as I am new to this....I am experimenting with some of the comments above, in particular

class test:
	t = visa.ResourceManager()
	
	def __init__(self):
			self.k = visa.ResourceManager()
			m = visa.ResourceManager()
I have a file sandbox.py....I import sandbox....
I can see t by using sandbox.test.t (please jump in and correct me if I go awry)...By not using the parentheses after test (ie sandbox.test() implies I have NOT created an instance, is this correct?)

Now to see k I must do something like j = sandbox.test(); j.k....Is this correct? (seems to work)

I ALSO notice here that j.t works too...guessing that is because the instance is a subset of the class so all is good

How do I access m? Does it have to live outside the instance creation (__init__)? Seems it could live anywhere assuming you don't put self tag on it....

Last question: can I declare 'self' attributes in methods other than __init__ ? and are they accessible by external and internal?

thanks again for all the help out there! Everyone is very responsive....this is a great forum
Reply


Messages In This Thread
RE: creating a variable in a method and using in another method - by ridgerunnersjw - Oct-04-2019, 03:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Method returning None husksedgier 2 284 May-04-2024, 06:38 PM
Last Post: husksedgier
  Int.From_Bytes Method - Conversion of Non-Escaped Bytes Objects new_coder_231013 2 479 Apr-06-2024, 04:24 PM
Last Post: new_coder_231013
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 327 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  class definition and problem with a method HerrAyas 2 323 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() and order of running method in class inheritance akbarza 7 852 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  problem usage of static method akbarza 5 605 Feb-03-2024, 07:43 AM
Last Post: paul18fr
  Building a DoublyLinkedList in Python - - append method Drone4four 2 474 Jan-08-2024, 01:27 PM
Last Post: Drone4four
Information Best distribution method inovermyhead100 0 599 Jul-19-2023, 07:39 AM
Last Post: inovermyhead100
  method call help sollarriiii 6 1,245 Feb-21-2023, 03:19 AM
Last Post: noisefloor
  That compression method is not supported tester_V 9 3,730 Jan-31-2023, 07:05 PM
Last Post: tester_V

Forum Jump:

User Panel Messages

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