Re: [Tutor] user agent
On Wed, Sep 24, 2008 at 6:55 PM, jeremiah <[EMAIL PROTECTED]> wrote: > I'm trying to force the user agent in a python login script... My > question is what are the possible user agents I can specify Here is a rather long list: http://www.user-agents.org/ but presumably there is a particular browser you want to emulate? > and how do I > print the user agent at the end of the script so I know that it was > accurately saved. I don't understand where you want to save the user agent. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] user agent
On Wed, Sep 24, 2008 at 7:55 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > "jeremiah" <[EMAIL PROTECTED]> wrote >> >> I'm trying to force the user agent in a python login script... > > Might I ask why? > It should never be necessary and is extremely user hostile. > Especially given that many modern browsers are capable of emulating the > troublesome ones - ie IE! And future versions might change the rules and you > then have a huge maintenance overhead of keeping your list of browsers > updated. Alan, I think you might have this backwards. I think jeremiah wants to specify the user agent on the client side of the connection. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] user agent
"jeremiah" <[EMAIL PROTECTED]> wrote I'm trying to force the user agent in a python login script... Might I ask why? It should never be necessary and is extremely user hostile. Especially given that many modern browsers are capable of emulating the troublesome ones - ie IE! And future versions might change the rules and you then have a huge maintenance overhead of keeping your list of browsers updated. If at all possible it's better to put the effort into making your code browser neutral. Which mainly meams avoiding unusual HTML constructs, using ECMAscript rather than any vendor specific variant of JavaScript and not trying to control layout and style too closely (that's what PDF is for!) question is what are the possible user agents I can specify Thats a changing question because the number of browsers and what they report to the server is changing constantly. Its usually more common to simply specify a small subset of the most common ones and anyone with the audacity to prefer an alternative hgets a more or less rude message telling them to pick another browser print the user agent at the end of the script so I know that it was accurately saved. Here is the first bit of my code. Its stored in an environment variable. How you access that will depend on your server/framework but as a last resort os.getenv() should work. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] user agent
I'm trying to force the user agent in a python login script... My question is what are the possible user agents I can specify and how do I print the user agent at the end of the script so I know that it was accurately saved. Here is the first bit of my code. Any suggestions? thx, JJ == #!/usr/bin/python import cookielib, urllib2 import urllib cookie_jar = cookielib.CookieJar() opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(cookie_jar) ) """ User Agent Setting - change ua_value to modify user agent options are: 'Mozilla/5.0', 'ie5' """ ua_value="ie5" opener.addheaders = [('User-agent', ua_value)] Disclaimer: The information contained in this transmission, including any attachments, may contain confidential information of Panasonic Avionics Corporation. This transmission is intended only for the use of the addressee(s) listed above. Unauthorized review, dissemination or other use of the information contained in this transmission is strictly prohibited. If you have received this transmission in error or have reason to believe you are not authorized to receive it, please notify the sender by return email and promptly delete the transmission. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please explain this error
Hello Herold! I have three ideas what you could do: - Try to run the script on the server. Maybe even take NFS down while running the script. Or as a variation, run the script in a directory which is on the local disk. It seems the script is confused by some specific behavior of NFS. (There is at least some hope that the script once worked for its author.) - Email the script's author about the bug and ask him for advice. Put an error report into the script's Bugzilla if one exists. - Try to understand the script and fix it. Kind regards, Eike. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where Does the DOS Window Come From?
"Wayne Watson" <[EMAIL PROTECTED]> wrote When it's executed the expected GUI appears along with a DOS window. Occasionally, I think, I've seen something put in the DOS window. The DOS window is the XP Command prompt execution environment as used by the python interpreter,. Its where the stdin, stdout and stderr streams appear by default. Thus any print statements will appear there and any raw_input requests will be read from there. You should eliminate print or raw_input statements from a GUI if you want to eliminate the DOS window. How do I stop it from appearing and how do I find why it's used? To stop it appearing you need to run pythonw instead of python and the easiest way to do that is change the extension from .py to .pyw OTOH you may find it convenient for debugging to keep the DOS window until everything is working as a place for debug/test print statements to appear. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where Does the DOS Window Come From?
Title: Signature.html Well, the responses above pretty well clear that up. As far as I can tell, the program uses print exactly once. At this point, I have no idea why. It looks like it's bring to the attention of the user that something has gone wrong finding a centroid. However, the message is so non-descript, it looks useless. if total == 0: print "Count: %d Total: %d" % (count,total) return 361,244,0,0 Possibly it was left behind by mistake. I'll likely know in a few weeks when I tackle the program more fully. In over two years of use, I maybe have seen the message twice. It runs every day for about 10 hours per day. I don't think the program stopped when it was issued. Kent Johnson wrote: On Wed, Sep 24, 2008 at 11:36 AM, Wayne Watson <[EMAIL PROTECTED]> wrote: I'm looking at a GUI application that I hope to modify in the next few weeks. When it's executed the expected GUI appears along with a DOS window. Occasionally, I think, I've seen something put in the DOS window. How do I stop it from appearing and how do I find why it's used? To stop the DOS window from appearing, run the program using pythonw instead of python. See the section "Running GUI Applications" here: http://oreilly.com/catalog/pythonwin32/chapter/ch20.html Kent -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Truth is mighty and will prevail. There is nothing wrong with this, except that it ain't so." -- Mark Twain Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where Does the DOS Window Come From?
> > I'm looking at a GUI application that I hope to modify in the next few >> weeks. When it's executed the expected GUI appears along with a DOS window. >> Occasionally, I think, I've seen something put in the DOS window. How do I >> stop it from appearing and how do I find why it's used? >> > > If you don't want the DOS window, you can change the extension of the file > to .pyw instead of .py, but in this case you will not see the messages > printed by the print statement. > Not to be pedantic, but that's NOT a DOS window, it's a Python terminal. (It just happens to be black-and-white, 80x25 character mode, the same as DOS - but that's just because DOS was originally designed to use the same monitor as an IBM terminal.) You'd get the same thing under Linux or OS X. But yes, to amplify what others have said - you can invoke the script with "pythonw script.py", or just change its extension to ".pyw" and it will automatically be opened with pythonw (assuming that your file associations have been set correctly, which it sounds like they have.) -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where Does the DOS Window Come From?
On Wed, Sep 24, 2008 at 11:36 AM, Wayne Watson <[EMAIL PROTECTED]> wrote: > I'm looking at a GUI application that I hope to modify in the next few > weeks. When it's executed the expected GUI appears along with a DOS window. > Occasionally, I think, I've seen something put in the DOS window. How do I > stop it from appearing and how do I find why it's used? To stop the DOS window from appearing, run the program using pythonw instead of python. See the section "Running GUI Applications" here: http://oreilly.com/catalog/pythonwin32/chapter/ch20.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where Does the DOS Window Come From?
Wayne Watson ha scritto: I'm looking at a GUI application that I hope to modify in the next few weeks. When it's executed the expected GUI appears along with a DOS window. Occasionally, I think, I've seen something put in the DOS window. How do I stop it from appearing and how do I find why it's used? If you don't want the DOS window, you can change the extension of the file to .pyw instead of .py, but in this case you will not see the messages printed by the print statement. -- Simone Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where Does the DOS Window Come From?
On Wed, Sep 24, 2008 at 10:36 AM, Wayne Watson <[EMAIL PROTECTED] > wrote: > I'm looking at a GUI application that I hope to modify in the next few > weeks. When it's executed the expected GUI appears along with a DOS window. > Occasionally, I think, I've seen something put in the DOS window. How do I > stop it from appearing and how do I find why it's used? > My guess, though I'm not on windows ATM to test: any time the "print" command is used, it outputs to the command line. And in windows, more often than not that probably means "create". So look through and find any "print" commands and comment those out, and my guess it it should silence the window... but I don't know for sure. HTH, Wayne -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Where Does the DOS Window Come From?
Title: Signature.html I'm looking at a GUI application that I hope to modify in the next few weeks. When it's executed the expected GUI appears along with a DOS window. Occasionally, I think, I've seen something put in the DOS window. How do I stop it from appearing and how do I find why it's used? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Truth is mighty and will prevail. There is nothing wrong with this, except that it ain't so." -- Mark Twain Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please explain this error
Steve, Thanks for your reply. Yes. The python program is or was keeping the file open.. This is failing at the commit stage of the program, in checking in the svn data. So how do I go about fixing this? Any help and insight is appreciated. Herold Anadigics Herold Kroh [EMAIL PROTECTED] 141 Mt Bethel Rd Warren NJ, 07059 US tel: 908-668-5000 ext 6151 mobile: 570-510-2611 AIM: hekroh Skype ID:hekroh -Original Message- From: Steve Willoughby [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 23, 2008 6:45 PM To: Herold Kroh Cc: [EMAIL PROTECTED]; tutor@python.org Subject: Re: [Tutor] please explain this error On Tue, Sep 23, 2008 at 06:13:31PM -0400, Herold Kroh wrote: > libsvn._core.SubversionException: ("Can't remove > 'SVN_skill/db/transactions/0-1.txn': Directory not empty", 39) > > I go to the offending directory and I see a .nfs file. When I > touch the file, it disappears. The problem here is with NFS, really. The .nfs files are how the NFS system handles the case where files are deleted on the fileserver but still open on a client. (Under Unix, a file can still be open and all its data accessed even if deleted from the filesystem... it won't *really* go away until it's closed, too. But NFS doesn't represent that case well so a temporary filename is used.) Unless your Python program is what's holding the offending file(s) open... any idea what's keeping the file in use? -- Steve Willoughby| Using billion-dollar satellites [EMAIL PROTECTED] | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting Dictionary of Dictionary by certain Value
> -Original Message- > Hi Pythonistas, > > I have a large dictionary of dictionary (50,000+ keys) which > has a structure as follows: > DoD = { > 'flintstones' : { > 'husband' : "fred", > 'pal' : "barney", > 'income': 500, > }, > 'jetsons' : { > 'husband' : "george", > 'wife' : "jane", > 'his boy' : "elroy", > 'income': 700, > }, > 'simpsons' : { > 'husband' : "homer", > 'wife' : "marge", > 'kid' : "bart", > 'income': 600, > }, > }; > > I want to sort the dictionary by 'income' > Is there an efficient way to do the same. > Thanks in advance. > > - Jo > This sounds like it'd be a good job for a database...perhaps SQLite? Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Subject: header intact.
-- Forwarded message -- From: <[EMAIL PROTECTED]> Date: Wed, Sep 24, 2008 at 4:14 PM Subject: The results of your email commands To: [EMAIL PROTECTED] The results of your email command are provided below. Attached is your original message. - Results: Ignoring non-text/plain MIME parts - Unprocessed: From: <[EMAIL PROTECTED]<[EMAIL PROTECTED]> <[EMAIL PROTECTED]<[EMAIL PROTECTED]> > > Date: Wed, Sep 24, 2008 at 3:14 PM Subject: Your confirmation is required to join the Tutor mailing list To: [EMAIL PROTECTED] Mailing list subscription confirmation notice for mailing list Tutor We have received a request for subscription of your email address, "[EMAIL PROTECTED]", to the tutor@python.org mailing list. To confirm that you want to be added to this mailing list, simply reply to this message, keeping the Subject: header intact. Or visit this web page: http://mail.python.org/mailman/confirm/tutor/e29d3177873143be8813dc62cf452fcb191d9528 Or include the following line -- and only the following line -- in a message to [EMAIL PROTECTED]: confirm e29d3177873143be8813dc62cf452fcb191d9528 - Ignored: Note that simply sending a `reply' to this message should work from most mail readers, since that usually leaves the Subject: line in the right form (additional "Re:" text in the Subject: is okay). If you do not wish to be subscribed to this list, please simply disregard this message. If you think you are being maliciously subscribed to the list, or have any other questions, send them to [EMAIL PROTECTED] - Done. -- Forwarded message -- From: "sudhir sahu" <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Date: Wed, 24 Sep 2008 16:13:39 +0530 Subject: Fwd: Your confirmation is required to join the Tutor mailing list -- Forwarded message -- From: <[EMAIL PROTECTED]<[EMAIL PROTECTED]> > Date: Wed, Sep 24, 2008 at 3:14 PM Subject: Your confirmation is required to join the Tutor mailing list To: [EMAIL PROTECTED] Mailing list subscription confirmation notice for mailing list Tutor We have received a request for subscription of your email address, "[EMAIL PROTECTED]", to the tutor@python.org mailing list. To confirm that you want to be added to this mailing list, simply reply to this message, keeping the Subject: header intact. Or visit this web page: http://mail.python.org/mailman/confirm/tutor/e29d3177873143be8813dc62cf452fcb191d9528 Or include the following line -- and only the following line -- in a message to [EMAIL PROTECTED]: confirm e29d3177873143be8813dc62cf452fcb191d9528 Note that simply sending a `reply' to this message should work from most mail readers, since that usually leaves the Subject: line in the right form (additional "Re:" text in the Subject: is okay). If you do not wish to be subscribed to this list, please simply disregard this message. If you think you are being maliciously subscribed to the list, or have any other questions, send them to [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] WHAT IS THE DIFFERENCE BETWEEN FILTER AND REDUCE FUNCTION
Warning: this is going to look *a lot* better if you view it in a fixed-width font so things line up properly. Both functions apply a function to a list of values, but they do so in different ways. filter() applies a function to each element of a list in turn, returning a new list containing only those elements from the original list for which the function returned True (when given the element as the function argument). In effect, it "filters" a list, like a physical filter would allow some particles to pass and catch others. Only those elements meeting a certain criteria pass through the filter. def is_odd(i): return i%2 != 0 a = [1, 2, 3, 4] b = filter(is_odd, a) b now contains [1, 3] The same thing could be done using lambda instead of defining a named function, of course: a = [1, 2, 3, 4] b = filter(lambda i: i%2!=0, a) The reduce() function does something quite different. It reduces a list of values to a single result by repeatedly applying the result of the transformation to the next one, adding a new element each time. This way you get a cumulative effect. The most obvious example of such a function (to me, anyway) is a factorial function. n! = 1*2*3*4*...*n So you could implement the factorial function in Python using iteration, like this: def factorial(n): result = 0 for i in range(1,n+1): result *= i return result But we could also do this with reduce(), given a list of integers to multiply: def product(x, y): return x * y a = [1, 2, 3, 4, 5, 6] b = reduce(product, a) b is now 720. What this will do is to start with the first two elements of a, and pass them to the product() function, then pass the result of that operation along with the next element to the product() function again, and so on until it has reduced the list to a single result: a =[1, 2, 3, 4, 5, 6] product(1, 2) | | | | -> 2 product(2, 3) | | | -> 6 product(6, 4) | | -> 24 product(24, 5) | -> 120 product(120, 6) -> 720 or in other words, this computes (1*2)*3)*4)*5)*6) = 720 So our factorial function could have been implemented like this using reduce: def factorial(n): return reduce(lambda x,y: x*y, range(1,n+1)) HTH HAND steve ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor