Questions about this topic? Sign up to ask in the talk tab.

Classes/Logs/2012/September/17/01-02

From NetSec
Revision as of 02:56, 18 September 2012 by Chantal21I (Talk | contribs) (moved Classes/Logs/2012/09/17/01-02 to Classes/Logs/2012/September/17/01-02)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
01:19 <@zzzzzZZZZzzz[m3n]> I've never taught, or taught a programming language in any capacity before, but I think the 
                           classic methodology is to start with the hello world example.
01:19 <@zzzzzZZZZzzz[m3n]> So
01:20 <@zzzzzZZZZzzz[m3n]> http://pastebin.com/Ucw0MHaH
01:20 <@zzzzzZZZZzzz[m3n]> The classic hello world in python
01:20 < lighthouse> when explaining how things work its good to use analogies to instead of technical terms, then 
                    afterwards apply the technical terms to the different parts of the analogy
01:21 <@zzzzzZZZZzzz[m3n]> Fair
01:21 <+foo> hatter: http://pastebin.com/ZxhqH16C
01:22 <@zzzzzZZZZzzz[m3n]> Well I am assuming slight theoretical knowledge mind
01:22 <@zzzzzZZZZzzz[m3n]> So
01:22 <@zzzzzZZZZzzz[m3n]> Line by line then
01:22 <~hatter> ty foo 
01:24 <@zzzzzZZZZzzz[m3n]> Line one of course is commonly known as the "shebang", it tells the shell to use the python 
                           interpreter to execute this program, this is common for many interpreted languages.
01:26 <@zzzzzZZZZzzz[m3n]> Line four imports the sys module, what this means is that we want to draw in all the 
                           functionality of the sys module to the context of the module, or more simply the file, we 
                           ourselves are working on.
01:27 < Atlas> Did I just miss a class?
01:27 < corvus> http://pastebin.com/Qn6wnrSU Atlas
01:27 <@zzzzzZZZZzzz[m3n]> From that sentence one should infer that a file and a module in python are the same.
01:27 < Atlas> Are we back to 00:00 and 12:00 UTC?
01:28 <@zzzzzZZZZzzz[m3n]> However it is more complex than that, just know that for now.
01:28 < Atlas> Thanks corvus
01:28 <+foo> Atlas: http://blackhatlibrary.net/Current:Classes
01:29 <@zzzzzZZZZzzz[m3n]> Moving on to line seven: Here we define a function (oh joy, some meat) which is named main()
01:30 <@zzzzzZZZZzzz[m3n]> the line therafter uses the python keyword "print" to print a line of text to the terminal
01:31 <@zzzzzZZZZzzz[m3n]> The string which it prints is a concatenation of the string literal 'Hello there' and the 
                           string variable sys.argv[1]
01:32 <@zzzzzZZZZzzz[m3n]> A string literal is textual data written out in the file in place of using a variable
01:33 <@zzzzzZZZZzzz[m3n]> A string variable is a variable containing the type of data as the string literal, but that 
                           van be referred to repeatedly by name
01:33 < lighthouse> basically a literal is always the same thing?
01:34 <@zzzzzZZZZzzz[m3n]> Of course then a variable is a named placeholder for data
01:34 <@zzzzzZZZZzzz[m3n]> Yes
01:34 <@zzzzzZZZZzzz[m3n]> It is not referable anywhere else than it's definition. 
01:34 <@zzzzzZZZZzzz[m3n]> meaning it can only be used once in the code at all. 
01:34 < lighthouse> so its a specific value created by the user
01:34 <@zzzzzZZZZzzz[m3n]> In the source code I should say
01:34 < lighthouse> gotcha
01:35 < lighthouse> just trying to make sure I understand the terms correctly
01:35 <@zzzzzZZZZzzz[m3n]> For instance 
01:35 <@zzzzzZZZZzzz[m3n]> Yes of course
01:35 <@zzzzzZZZZzzz[m3n]> say : lol = "something" lol is a variable being filled with the value of a string literal, 
01:35 <@zzzzzZZZZzzz[m3n]> Now we can do 
01:35 <@zzzzzZZZZzzz[m3n]> lol = "something" 
01:36 <@zzzzzZZZZzzz[m3n]> lol="somethingelse"
01:36 <@zzzzzZZZZzzz[m3n]> but there is no way to refer to what is in the quotes again without going through the variable
01:36 <@zzzzzZZZZzzz[m3n]> their purpose becomes more clear when we talk about function.
01:37 <@zzzzzZZZZzzz[m3n]> Which is soon ;p
01:37 <@zzzzzZZZZzzz[m3n]> sys.argv is a global variable and part of the python sys module
01:38 <@zzzzzZZZZzzz[m3n]> we will talk more about it soon as well
01:38 <@zzzzzZZZZzzz[m3n]> line 14 is introduces anothe global variable '__name__'
01:39 -!- lighthouse [[email protected]] has quit [Ping timeout]
01:39 <@zzzzzZZZZzzz[m3n]> this variable is always avaliable for reference in your code even if it is the only thing 
                           referenced 
01:39 <@zzzzzZZZZzzz[m3n]> I'll wait for him, he was actually listening a-a
01:40 <@zzzzzZZZZzzz[m3n]> in the meantime, anyone else with questions is golden'
01:40 <@zzzzzZZZZzzz[m3n]> or comments/critiques 
01:40 < corvus> very nice gentle introduction
01:41 <@zzzzzZZZZzzz[m3n]> :3
01:42 <@zzzzzZZZZzzz[m3n]> hope he back soon
01:35 <@zzzzzZZZZzzz[m3n]> I guess I can give him logs...
01:36 <@zzzzzZZZZzzz[m3n]> So
01:36 -!- bx2bk [[email protected]] has joined #CSIII
01:37 <+foo> questions for Mr. Z about Python?
01:37 <~hatter> foo: I think he's about to paste another bin :D
01:37 <+foo> whoop. 
01:37 -!- lighthouse [[email protected]] has joined #CSIII
01:38 < lighthouse> got disconnected
01:38 <@zzzzzZZZZzzz[m3n]> __name__ is used to notify a python module of how it is being executed 
01:38 <@zzzzzZZZZzzz[m3n]> In otherwords 
01:39 <@zzzzzZZZZzzz[m3n]> 'Am I being imported, or am I being executed?
01:39 <@zzzzzZZZZzzz[m3n]> '
01:39 -!- Irssi: Pasting 5 lines to #csiii. Press Ctrl-K if you wish to do this or Ctrl-C to cancel.
01:39 <@zzzzzZZZZzzz[m3n]> It can tell us more than that but that is a bit out of scope.
01:39 <+foo> 01:38 <@zzzzzZZZZzzz[m3n]> we will talk more about it soon as well
01:39 <+foo> 01:38 <@zzzzzZZZZzzz[m3n]> line 14 is introduces anothe global variable '__name__'
01:39 <+foo> 01:39 -!- lighthouse [[email protected]] has quit [Ping timeout]
01:39 <+foo> 01:39 <@zzzzzZZZZzzz[m3n]> this variable is always avaliable for reference in your code even if it is the 
             only thing referenced
01:39 <+foo> lighthouse: z waited for you. 
01:41 <@zzzzzZZZZzzz[m3n]> The last line in the file "main()" is what's known as a function call, this tells the python 
                           interpreter: Execute the 'main' function we defined earlier with no parameters (parameters fo 
                           between the parentheses.
01:41 <@zzzzzZZZZzzz[m3n]> So
01:41 <@zzzzzZZZZzzz[m3n]> Since a python file is always 'executed'
01:41 <@zzzzzZZZZzzz[m3n]> from the top
01:41 <@zzzzzZZZZzzz[m3n]> even when imported
01:41 <@zzzzzZZZZzzz[m3n]> What this code actually does is
01:42 <@zzzzzZZZZzzz[m3n]> Firstly it imports the sys module, which is a standard python module (comes with your python 
                           install) 
01:42 <@zzzzzZZZZzzz[m3n]> the sys module basically contains functionality for interacting with the o/s 
01:43 <@zzzzzZZZZzzz[m3n]> for instance sys.argv which contains the parameters the python program was called with on the 
                           command line
01:43 <@zzzzzZZZZzzz[m3n]> It then moves to the if statement on line 14
01:44 <@zzzzzZZZZzzz[m3n]> an if statement makes a decision 
01:44 <@zzzzzZZZZzzz[m3n]> to execute the code in the code block below it, or not
01:44 <@zzzzzZZZZzzz[m3n]> So line 14 says
01:45 <@zzzzzZZZZzzz[m3n]> if the variable __name__ contains the value __main__ then execute the code block below (which 
                           contains our call to main() )
01:45 <@zzzzzZZZZzzz[m3n]> the value '__main_', excuse me
01:45 <@zzzzzZZZZzzz[m3n]> that is a string
01:46 <@zzzzzZZZZzzz[m3n]> The string '__main__' in the variable __name__ signifies we are being executed, not imported 
01:46 <@zzzzzZZZZzzz[m3n]> So
01:47 <@zzzzzZZZZzzz[m3n]> If we are being executed: Run the main function
01:47 <@zzzzzZZZZzzz[m3n]> Following?
01:47 < corvus> so is __name__ a module defined reference or is it user defined, meaning that '__main__ 'is a user chosen 
                reference, or is it automatically there due to the use of import sys ? or am I over complicating it? 
                sorry did not want to interrupt you again.
01:47 <@zzzzzZZZZzzz[m3n]> I will get into more detail on strings and lists soon (sys.argv is a list)
01:48 <@zzzzzZZZZzzz[m3n]> They are both python constructs.
01:48 < corvus> thank you
01:49 <@zzzzzZZZZzzz[m3n]> Shortly: __name__ is a global python set (before your code executes) variable, and '__main__' 
                           is one of several signals it can send you.
01:49 <@zzzzzZZZZzzz[m3n]> values it can contain
01:49 <@zzzzzZZZZzzz[m3n]> w/e
01:50 <@zzzzzZZZZzzz[m3n]> On code blocks in python:
01:50 <@zzzzzZZZZzzz[m3n]> A code block in python is defined using white space, in many other languages a set of { curly 
                           braces } are used.
01:51 <@zzzzzZZZZzzz[m3n]> In python (for example in our if statement)
01:51 <@zzzzzZZZZzzz[m3n]> We go to the next line
01:52 <@zzzzzZZZZzzz[m3n]> and ad whitespace until the new line begins to the left of the beginning of the first line.
01:52 <@zzzzzZZZZzzz[m3n]> This begins the code block
01:52 <@zzzzzZZZZzzz[m3n]> the code block ends
01:52 <@zzzzzZZZZzzz[m3n]> when the begin a line either before, or after the beginning of the previous line.
01:52 <@zzzzzZZZZzzz[m3n]> beginning
01:52 <@zzzzzZZZZzzz[m3n]> of
01:52 <@zzzzzZZZZzzz[m3n]> >>
01:53 <@zzzzzZZZZzzz[m3n]> So
01:53 <@zzzzzZZZZzzz[m3n]> Functions...
01:54 <@zzzzzZZZZzzz[m3n]> Let me edit ._.\
01:56 <@zzzzzZZZZzzz[m3n]> Actually, my bad, it concatenates those two strings and adds a space, the "," is part of the 
                           print statement... for clarity.
01:59 <@zzzzzZZZZzzz[m3n]> http://pastebin.com/3dG6iygw
01:59 <@zzzzzZZZZzzz[m3n]> Have a look here
01:59 <@zzzzzZZZZzzz[m3n]> We've given our main function some parameters
01:59 <@zzzzzZZZZzzz[m3n]> and we've exposed the greater use fullness of our string literals 
02:00 <@zzzzzZZZZzzz[m3n]> well
02:00 <@zzzzzZZZZzzz[m3n]> I typod the ordering sec, lol
02:00 <@zzzzzZZZZzzz[m3n]> I'm told to wrap up so ummm