Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a general question
#1
I have the following code, the first method, SendCommandV1, was given to me. My question is do I have to pass ser as an argument when I call SendCommand? Since ser is defined globally, I do not see any reason to pass ser through the argument.
Would the second method, SendCommandV2 be just as good?


ser = serial.serial('COM3', '9600')

def SendCommandV1(ser, command_string):
   ser.write(command_string)

def SendCommandV2(command_string):
   ser.write(command_string)

SendCommandV1('ser, Hello World')
SendCommandV2('Hello World')  #is this OK?
Reply


Messages In This Thread
a general question - by barryjo - Feb-01-2022, 06:04 PM
RE: a general question - by deanhystad - Feb-01-2022, 07:54 PM
RE: a general question - by Gribouillis - Feb-01-2022, 08:20 PM
RE: a general question - by DeaD_EyE - Feb-01-2022, 08:59 PM
RE: a general question - by barryjo - Feb-01-2022, 09:05 PM
RE: a general question - by Gribouillis - Feb-01-2022, 10:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python can - general question caslor 0 1,139 Jul-14-2022, 05:21 PM
Last Post: caslor
  General Programming Question with Dictionary giddyhead 12 2,818 Jan-10-2022, 10:12 AM
Last Post: Pedroski55
Big Grin General programming question (input string)[ jamie_01 2 1,640 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Question about formula implementation in general format Alienspecimen 0 1,682 Mar-01-2021, 08:39 PM
Last Post: Alienspecimen
  General list size question to solve problem Milfredo 3 2,392 Sep-27-2020, 08:42 AM
Last Post: Milfredo
  General Listbox question. Milfredo 4 2,210 Sep-06-2020, 07:36 PM
Last Post: Milfredo
  General question about serialization/deserialization in python local 1 1,871 Jan-28-2020, 04:35 AM
Last Post: Larz60+
  General Programming Question Qui_Ten 1 2,214 Jan-14-2019, 11:15 AM
Last Post: steve_shambles

Forum Jump:

User Panel Messages

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