avoid the use of globals #4

닫힘
" coolaj862018-09-30 01:16:15 +00:00을 오픈" · 3개의 코멘트

Right now you have a lot of global variables. A generally accepted better way to program (and part of The Zen of Python) is to use parameters

so instead of

def encrypt():

you would have

def encrypt(str, shift):
Right now you have a lot of global variables. A generally accepted better way to program (and part of [The Zen of Python](https://www.python.org/dev/peps/pep-0020/)) is to use parameters so instead of ```py def encrypt(): ``` you would have ```py def encrypt(str, shift): ```
소유자

Macej was saying that it was better not to use global variables. I just hadn't figured out how to do it better yet.

Macej was saying that it was better not to use global variables. I just hadn't figured out how to do it better yet.
Author

The technical term "variables" refers to free-standing references to values.

x = 1

The technical term "arguments" refers to references to values which are "received" by a function

def foo(x, y)
  x = 1

The technical term "parameters" refers to the definition of "arguments" in the function definition itself

def foo(x, y)

When you read the command line values into a local variable you can then pass it into the function as an argument.

cmd = sys.argv[1]
msg = sys.argv[2]
shift = sys.argv[3]

if "enable" == cmd:
  encrypt(msg, shift)

(not sure if that's real python, but I think it looks something like that)

The technical term "variables" refers to free-standing references to values. ```py x = 1 ``` The technical term "arguments" refers to references to values which are "received" by a function ```py def foo(x, y) x = 1 ``` The technical term "parameters" refers to the definition of "arguments" in the function definition itself ```py def foo(x, y) ``` When you read the command line values into a local variable you can then pass it into the function as an argument. ```py cmd = sys.argv[1] msg = sys.argv[2] shift = sys.argv[3] if "enable" == cmd: encrypt(msg, shift) ``` (not sure if that's real python, but I think it looks something like that)
소유자

Thank you. Fixed in 024c033ac2

Thank you. Fixed in https://git.coolaj86.com/josh/python-hard-way/commit/024c033ac2a56097c7b2dbddbd75a233100da96f
josh closed this issue 2018-10-06 17:12:14 +00:00
"로그인하여 이 대화에 참여"
레이블 없음
참여자 2명
알림
마감일
마감일이 설정되지 않았습니다.
의존성

No dependencies set.

Reference: josh/python-hard-way#4
No description provided.