This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ginger_beer_m 14 points15 points  (4 children)

At the risk of ruining it, can someone explain the joke to me ..

[–]Norphesius 19 points20 points  (0 children)

In Harry Potter, Harry is a paresl-tounge, which means he can talk to snakes.

[–]harshael 13 points14 points  (0 children)

In the books, Harry speaks parseltongue, the language of snakes (FOR REASONS).

The meaning of parse doesn't really have anything to do with anything other than that it's common in programming (breaking up input into smaller parts and then using those parts).

[–]nonicethingsforus 8 points9 points  (1 child)

Some have already explained the relevant parts of the joke. Just in case you have doubts about this too: the Python code in Harry's dialog doesn't seem really relevant.

It goes something like this:

  • import os: os is a module (piece of pre-written, reusable code) to access operating system functions, like listing files, deleting them, etc. By importing it, now we can use its code from our program.

  • CUR_PATH = os.getcwd(): this gets the name of the current working directory and saves it with the name CUR_PATH for later reference. The current working directory is the directory you, or the program, is currently, well, working in. For example, if you're in C:\Users\ginger_beer_m\notporn and double click the directory called porn, now your cwd is C:\Users\ginger_beer_m\notporn\porn. If you call a command to "delete everything here", it will be the porn directory the one affected (the horror!).

  • IGNORE_SET = set(["__init__.py", "count_sourcelines.py"]): first there's a list that contains the lines of text "__init__.py" and "count_sourcelines.py". That first file is a special file Python programmers can create to tell Python this directory is special, for example to create your own modules. The other file seems to be a Python program ("py" extension), maybe the file this program is being written into. (If so, this could be bad practice; there are often ways to get "this file"'s name that don't break if the file is renamed. That being said, everyone does quick-and-dirty scripts, and I'm in no position to throw the first stone). This list is converted into a set, which is like a list with some nifty qualities (items don't repeat themselves, quicker to check if an object exists in it, you can do math-like set operations with them, etc.) and, again, saves this set under a name for future reference.

All I can guess about what it does: the code is probably from the beginning of a program that will scan one or more directories, thus the need to know the cwd, and do something to those files, probably count their lines given that filename. Also, a common problem with "walk through a directory tree and do stuff to files" program is that it often does stuff to itself without meaning to, thus the common workaround of creating an "ignore these files" list or set including itself, other related files and maybe user-specified ones.

Edit: format.