[cse491] HW #4

C. Titus Brown ctb at msu.edu
Wed Sep 24 07:32:06 PDT 2008


Hi, Andrew -- order doesn't matter, and good practice is to do something
like

if __name__ == '__main__':
   import sys
   host, port = sys.argv[1:3]
   port = int(port)
   serve(host, port)

i.e. all basic argument processing in the part that's only written as a
script, followed by the function call that Does Stuff.

As a side bonus, if you do it this way, you will have done the first
part of HW #5.

Actually, let me say: a big part of HW #5 is re-arranging your code into
specific functions with specific names, and you can do a lot of that as
part of HW #4.  So if you make a 'serve', a 'handle_connection', and a
'delegate' function as part of HW #4, you will have done HW #4 correctly
*and* be half done with HW #5...

cheers,
--t

p.s. good questions!

On Tue, Sep 23, 2008 at 10:13:00PM -0400, Andrew Hanlon wrote:
-> I finished homework4, but was unsure of a few components, such as,
-> whether or not the order of the keys and their values, when returned,
-> should correspond to the order that they appear in the url.  For
-> example:
-> 
-> http://localhost/some/random/url?name=test&name=test2&blah=foo
-> 
-> returns
-> 
-> hello, /some/random/url; key=blah; value=foo; key=name; value=test;
-> key=name; value=test2
-> 
-> the blah and foo are at the end of the url, but show up first when I
-> return them, I think this is parse_qs(url)'s fault though.  And you also
-> mention something about using a main function.  Do you mean for our
-> main() code to start with:
-> 
-> if __name__ == '__main__':
-> 
-> or
-> 
-> def main():
-> 
-> or what?
-> 
-> -Drew Hanlon
-> 

-- 
C. Titus Brown, ctb at msu.edu



More information about the cse491-fall-2008 mailing list