Re: Captcha identify
On 15/08/2014 5:43 AM, Eric S. Johansson wrote: On 8/14/2014 2:37 PM, Peter Pearson wrote: "Which of the following eight sentences are sarcastic in tone?" and responses on this list alone show problems with detecting sarcasm (or snark). It can be especially difficult for people on the autism spectrum. Something to consider when advocating changes to a system that disadvantages you is to not pass the problem on to others. -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote: On further inspection, it seems that strptime() in 2.7 doesn't handle %z at all. In 3.2, it ignores the value it gets, because there's no practical way to select the "right" tz string from the offset. For example, a dictionary of offset minutes to tzstrings looks something like this: { -720: ['BIT'], -660: ['NUT', 'SST'], -600: ['CKT', 'HAST', 'HST', 'TAHT'], -570: ['MART', 'MIT'], -540: ['AKST', 'GAMT', 'GIT', 'HADT'], -480: ['AKDT', 'CIST', 'PST'], -420: ['MST', 'PDT'], -360: ['CST', 'EAST', 'GALT', 'MDT'], -300: ['CDT', 'COT', 'CST', 'EASST', 'ECT', 'EST', 'PET'], -270: ['VET'], -240: ['AMT', 'AST', 'BOT', 'CDT', 'CLT', 'COST', 'ECT', 'EDT', 'FKT', 'GYT', 'PYT'], -210: ['NST', 'NT'], -180: ['ADT', 'AMST', 'ART', 'BRT', 'CLST', 'FKST', 'FKST', 'GFT', 'PMST', 'PYST', 'ROTT', 'SRT', 'UYT'], -150: ['NDT'], -120: ['FNT', 'GST', 'PMDT', 'UYST'], -60: ['AZOST', 'CVT', 'EGT'], 0: ['GMT', 'UCT', 'UTC', 'WET', 'Z', 'EGST'], 60: ['BST', 'CET', 'DFT', 'IST', 'MET', 'WAT', 'WEDT', 'WEST'], 120: ['CAT', 'CEDT', 'CEST', 'EET', 'HAEC', 'IST', 'MEST', 'SAST', 'WAST'], 180: ['AST', 'EAT', 'EEDT', 'EEST', 'FET', 'IDT', 'IOT', 'SYOT'], 210: ['IRST'], 240: ['AMT', 'AZT', 'GET', 'GST', 'MSK', 'MUT', 'RET', 'SAMT', 'SCT', 'VOLT'], 270: ['AFT', 'IRDT'], 300: ['AMST', 'HMT', 'MAWT', 'MVT', 'ORAT', 'PKT', 'TFT', 'TJT', 'TMT', 'UZT'], 330: ['IST', 'SLST'], 345: ['NPT'], 360: ['BIOT', 'BST', 'BTT', 'KGT', 'VOST', 'YEKT'], 390: ['CCT', 'MMT', 'MST'], 420: ['CXT', 'DAVT', 'HOVT', 'ICT', 'KRAT', 'OMST', 'THA', 'WIT'], 480: ['ACT', 'AWST', 'BDT', 'CHOT', 'CIT', 'CST', 'CT', 'HKT', 'MST', 'MYT', 'PST', 'SGT', 'SST', 'ULAT', 'WST'], 525: ['CWST'], 540: ['AWDT', 'EIT', 'IRKT', 'JST', 'KST', 'TLT'], 570: ['ACST', 'CST'], 600: ['AEST', 'CHUT', 'DDUT', 'EST', 'PGT', 'VLAT', 'YAKT'], 630: ['ACDT', 'CST', 'LHST'], 660: ['AEDT', 'KOST', 'LHST', 'MIST', 'NCT', 'PONT', 'SAKT', 'SBT', 'VUT'], 690: ['NFT'], 720: ['FJT', 'GILT', 'MAGT', 'MHT', 'NZST', 'PETT', 'TVT', 'WAKT'], 765: ['CHAST'] 780: ['NZDT', 'PHOT', 'TKT', 'TOT'], 825: ['CHADT'], 840: ['LINT'], } I've patched my 2.7 to set a tz string of "UTC[+-]" from the [+-] %z value. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On 15Aug2014 13:59, Chris Angelico wrote: On Fri, Aug 15, 2014 at 1:51 PM, Denis McMahon wrote: AttributeError: 'module' object has no attribute 'timezone' Both fail as you describe in 2.7, but in 3.4/3.5ish (my 'python3' is a bit of a mess, but it's something between those two I think), both work as per the OP's description. You both need to be clearer about version numbers, I think :) The OP did have a link to docs with 3.4 in the name, although that isn't proof necessarily. At least one of the OP's posts showed 3.4.0 as the Python version. On some flavour of Windows I believe. Cheers, Cameron Simpson Our friend Trefayne is really most intuitive; you may trust that anything he says is absolutely true.- Aylebourne -- https://mail.python.org/mailman/listinfo/python-list
Re: get the min date from a list
On 15/08/2014 01:56, Dan Stromberg wrote: On Thu, Aug 14, 2014 at 5:44 PM, Mark Lawrence wrote: I really don't understand why people here are spoon feeding you when you still insist on top posting. Ever heard the term "manners"? Oh what a stupid comment, obviously not. *plonk* Getting people to stop top-posting is a losing battle. No it isn't a losing battle. The rules here are quite clear, don't top post. If you can't be bothered to adhere to the rules, don't post. Particularly when all of your questions could be answered by reading the £$%^ing docs. Aren't there more important things to worry about? Like the NSA overstepping or the Fergeson, Missouri police? Who or what are the NSA? Missouri, never heard of it, some tiny little hamlet on one of the Scottish islands? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Captcha identify
On 15/08/2014 08:03, alex23 wrote: On 15/08/2014 5:43 AM, Eric S. Johansson wrote: On 8/14/2014 2:37 PM, Peter Pearson wrote: "Which of the following eight sentences are sarcastic in tone?" and responses on this list alone show problems with detecting sarcasm (or snark). It can be especially difficult for people on the autism spectrum. Something to consider when advocating changes to a system that disadvantages you is to not pass the problem on to others. Something I fully understand. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: get the min date from a list
Mark Lawrence : > The rules here are quite clear, don't top post. If you can't be > bothered to adhere to the rules, don't post. Top-posting is bad, but I find nagging worse. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On Fri, 15 Aug 2014 07:39:23 +, Denis McMahon wrote: > I've patched my 2.7 to set a tz string of "UTC[+-]" from the > [+-] %z value. ... but that doesn't do much, because time.struct_time in 2.7 doesn't recognise anything that strptime passes in as a tz at all, as it expects the dst flag in that position and seems to have no concept of tz at all. So in 2.7 you can probably forget any question of reading in tz info with datetime.strptime(). See another reply to the OP regarding Python 3.2 -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
python small task
i have this piece of code file1 = open('text.txt, w) try: text = file1.read() finally: file1.close() i wish to manage an office task using this small code , how can i implemetn it to function. how can i pars it in a webpage ? -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote: > problem : > > t1 is GMT time 2014 00:36:46 t2 is GMT time 2014 14:36:46 > > datetime.datetime.strptime do not give me the right answer. As far as I can tell from running the following, it all seems to work as expected in python 3.2 (and hence I expect in 3.4). If the expected output doesn't match yours, it would be interesting to see what your output is. If the expected output does match yours, and you think it's wrong, it would be interesting to know which bits you think are wrong and why you think they are wrong, because having a fair bit of the night looking at this, it all looks good to me. #!/usr/bin/python3 from datetime import tzinfo, timedelta, datetime, timezone # define timedelta based timezones UTCm7 = timezone(timedelta(0,-7*3600),"UTC-07:00") UTCp7 = timezone(timedelta(0,+7*3600),"UTC+07:00") UTC = timezone(timedelta(0),"UTC+00:00") # some timestrings t1 = 'Sat, 09 Aug 2014 07:36:46 -0700' t2 = 'Sat, 09 Aug 2014 07:36:46 +0700' t3 = 'Sat, 09 Aug 2014 07:36:46 +' # make some datetime objects # these are both utc -7 a1 = datetime.strptime(t1,"%a, %d %b %Y %H:%M:%S %z") b1 = datetime(2014, 8, 9, 7, 36, 46, tzinfo = UTCm7) # these are both utc +7 a2 = datetime.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") b2 = datetime(2014, 8, 9, 7, 36, 46, tzinfo = UTCp7) # these are both utc a3 = datetime.strptime(t3,"%a, %d %b %Y %H:%M:%S %z") b3 = datetime(2014, 8, 9, 7, 36, 46, tzinfo = UTC) # print them out as stored print( "UTC -7:" ) print( t1 ) print( a1 ) print( b1 ) print( "UTC +7:" ) print( t2 ) print( a2 ) print( b2 ) print( "UTC:" ) print( t3 ) print( a3 ) print( b3 ) # print them out converted to UTC print( "UTC -7 as UTC:" ) print( a1.astimezone( UTC ) ) print( b1.astimezone( UTC ) ) print( "UTC +7 as UTC:" ) print( a2.astimezone( UTC ) ) print( b2.astimezone( UTC ) ) print( "UTC as UTC:" ) print( a3.astimezone( UTC ) ) print( b3.astimezone( UTC ) ) # expected output """ UTC -7: Sat, 09 Aug 2014 07:36:46 -0700 2014-08-09 07:36:46-07:00 2014-08-09 07:36:46-07:00 UTC +7: Sat, 09 Aug 2014 07:36:46 +0700 2014-08-09 07:36:46+07:00 2014-08-09 07:36:46+07:00 UTC: Sat, 09 Aug 2014 07:36:46 + 2014-08-09 07:36:46+00:00 2014-08-09 07:36:46+00:00 UTC -7 as UTC: 2014-08-09 14:36:46+00:00 2014-08-09 14:36:46+00:00 UTC +7 as UTC: 2014-08-09 00:36:46+00:00 2014-08-09 00:36:46+00:00 UTC as UTC: 2014-08-09 07:36:46+00:00 2014-08-09 07:36:46+00:00 """ -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Matplotlib Contour Plots
On Thursday, August 14, 2014 5:53:09 PM UTC+1, Steven D'Aprano wrote: > Jamie Mitchell wrote: > > > > > Hello all, > > > > > > I want to contour a scatter plot but I don't know how. > > > > > > Can anyone help me out? > > > > Certainly. Which way did you come in? > > > > :-) > > > > Sorry, I couldn't resist. > > > > It took me literally 20 seconds to find this by googling for "matplotlib > > contour plot", and it only took that long because I misspelled "contour" > > the first time. > > > > http://matplotlib.org/examples/pylab_examples/contour_demo.html > > > > > > Does this help? If not, please explain what experience you have with > > matplotlib, what you have tried, what you expected it to do, and what it > > did instead. > > > > > > > > -- > > Steven Yep I've seen that thanks but I can't get it to work. I don't have much experience with matplotlib or programming in general. I just want to get a contour plot of two numpy arrays. When I call plt.contour on my data I get "input must be a 2D array" An example of one of my arrays: array([ 2.0886, 2.29400015, 2.00400019, 1.8811, 2.0480001 , 2.16800022, 2.0480001 , 1.8829, 1.9586, 2.0029, 2.02800012, 1.8124, 1.9505, 1.96200013, 1.95200014, 1.99800014, 2.0717, 1.8829, 1.9849, 2.1346, 2.1148, 1.8945, 2.0519, 2.0198, 2.03400016, 2.16600013, 2.0099, 1.86200011, 2.19800019, 2.0128], dtype=float32) How do I get the above array in to the right format for a contour plot? Thanks, Jamie -- https://mail.python.org/mailman/listinfo/python-list
Re: python small task
On 15.08.2014 11:18, ngangsia akumbo wrote: > i have this piece of code > > file1 = open('text.txt, w) > try: > text = file1.read() > finally: > file1.close() > > i wish to manage an office task using this small code , how can i implemetn > it to function. import random import troll import socket t = troll.GenericTroll(maxiq = 75) try: t.connect("comp.lang.python") t.spout(random.randdrivel()) except socket.error: print("so good try. many wow. fail sad") finally: t.close() > how can i pars it in a webpage ? t.pars_in_a_webpage() Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa -- https://mail.python.org/mailman/listinfo/python-list
Re: Matplotlib Contour Plots
Jamie Mitchell wrote: [...] > I just want to get a contour plot of two numpy arrays. > When I call plt.contour on my data I get "input must be a 2D array" You are providing a 1D array, or possibly a 3D array. So the question you really want to ask is not "How do I do contour plots" but "how do I make a 2D array?" > An example of one of my arrays: > > array([ 2.0886, 2.29400015, 2.00400019, 1.8811, 2.0480001 , > 2.16800022, 2.0480001 , 1.8829, 1.9586, 2.0029, > 2.02800012, 1.8124, 1.9505, 1.96200013, 1.95200014, > 1.99800014, 2.0717, 1.8829, 1.9849, 2.1346, > 2.1148, 1.8945, 2.0519, 2.0198, 2.03400016, > 2.16600013, 2.0099, 1.86200011, 2.19800019, 2.0128], > dtype=float32) > > How do I get the above array in to the right format for a contour plot? Here's an example of making a 2D array: py> import numpy py> a = numpy.array([1.2, 2.5, 3.7, 4.8]) # One dimensional array py> a array([ 1.2, 2.5, 3.7, 4.8]) py> b = numpy.array([ [1.2, 2.5, 3.7, 4.8], ... [9.5, 8.1, 7.0, 6.2] ]) # Two dimensional array py> b array([[ 1.2, 2.5, 3.7, 4.8], [ 9.5, 8.1, 7. , 6.2]]) One dimensional arrays are made from a single list of numbers: [...] Two dimensional arrays are made from a list of lists: [ [...], [...] ] -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: how to change the time string into number?
On Thu, 14 Aug 2014 14:52:17 +0800, luofeiyu wrote: > in the manual https://docs.python.org/3.4/library/time.html > > %zTime zone offset indicating a positive or negative time difference > from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour > digits and M represents decimal minute digits [-23:59, +23:59]. > %ZTime zone name (no characters if no time zone exists). > > > t1='Sat, 09 Aug 2014 07:36:46 ' > time.strptime(t1,"%a, %d %b %Y %H:%M:%S ") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, > tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) > > >>> t2='Sat, 09 Aug 2014 07:36:46 -0700' time.strptime(t2,"%a, %d %b > >>> %Y %H:%M:%S %z") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, > tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) > > t1 and t2 is different time ,the timezone in t2 is -0700 ,why we get the > same result? > > >>> t3='Sat, 09 Aug 2014 07:36:46 +0400' time.strptime(t3,"%a, %d %b > >>> %Y %H:%M:%S %z") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, > tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1) > > > The Directive %z has no any effect here,what is the matter? Please learn to use usenet properly. Comments go below the text they refer to. What version of python are you using? I know what version of the documentation you are looking at, but as I explained inj an earlier post, the implementation varies between different python versions, and for example python 2.7 strptime seems to completely ignore the %z in the format string, so again, what version of python are you using? To check your python version: $ python >>> import sys >>> sys.version will output something like: '2.7.3 (default, Feb 27 2014, 19:58:35) \n[GCC 4.6.3]' for Python 2.7 or: '3.2.3 (default, Feb 27 2014, 21:31:18) \n[GCC 4.6.3]' for Python 3.2. Again, I stress, we need to know what version of python you are using to help you! Did you run the code I posted? Did you get the same output as me? If you didn't, what was different. If you did get the same output, what do you think is wrong with it? -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Matplotlib Contour Plots
On Friday, August 15, 2014 2:23:25 PM UTC+1, Steven D'Aprano wrote: > Jamie Mitchell wrote: > > > > [...] > > > I just want to get a contour plot of two numpy arrays. > > > When I call plt.contour on my data I get "input must be a 2D array" > > > > You are providing a 1D array, or possibly a 3D array. So the question you > > really want to ask is not "How do I do contour plots" but "how do I make a > > 2D array?" > > > > > > > An example of one of my arrays: > > > > > > array([ 2.0886, 2.29400015, 2.00400019, 1.8811, 2.0480001 , > > > 2.16800022, 2.0480001 , 1.8829, 1.9586, 2.0029, > > > 2.02800012, 1.8124, 1.9505, 1.96200013, 1.95200014, > > > 1.99800014, 2.0717, 1.8829, 1.9849, 2.1346, > > > 2.1148, 1.8945, 2.0519, 2.0198, 2.03400016, > > > 2.16600013, 2.0099, 1.86200011, 2.19800019, 2.0128], > > > dtype=float32) > > > > > > How do I get the above array in to the right format for a contour plot? > > > > Here's an example of making a 2D array: > > > > py> import numpy > > py> a = numpy.array([1.2, 2.5, 3.7, 4.8]) # One dimensional array > > py> a > > array([ 1.2, 2.5, 3.7, 4.8]) > > py> b = numpy.array([ [1.2, 2.5, 3.7, 4.8], > > ... [9.5, 8.1, 7.0, 6.2] ]) # Two dimensional array > > py> b > > array([[ 1.2, 2.5, 3.7, 4.8], > >[ 9.5, 8.1, 7. , 6.2]]) > > > > One dimensional arrays are made from a single list of numbers: [...] > > > > Two dimensional arrays are made from a list of lists: [ [...], [...] ] > > > > > > > > -- > > Steven Thank you Steven. I created the 2D array which read as: array([[[ 2.0886, 2.29400015, 2.00400019, 1.8811, 2.0480001 , 2.16800022, 2.0480001 , 1.8829, 1.9586, 2.0029, 2.02800012, 1.8124, 1.9505, 1.96200013, 1.95200014, 1.99800014, 2.0717, 1.8829, 1.9849, 2.1346, 2.1148, 1.8945, 2.0519, 2.0198, 2.03400016, 2.16600013, 2.0099, 1.86200011, 2.19800019, 2.0128]], [[ 8.515 , 8.8811, 8.5519, 7.9481, 8.6066, 8.515 , 8.8019, 8.1311, 8.6858, 8.7254, 8.4754, 8.25 , 8.4085, 8.4358, 8.3839, 8.3566, 8.6339, 8.5123, 8.3689, 8.6981, 8.5273, 8.1339, 8.3689, 8.4208, 8.5547, 8.7254, 9.0915, 8.1858, 8.7623, 8.5396]]], dtype=float32) Unfortunately when I called plt.contour on this, it said again "Input must be a 2D array". Is there something I have missed? Thanks, Jamie -- https://mail.python.org/mailman/listinfo/python-list
Re: python small task
CAN U BE VERY DETAILED PLEASEE -- https://mail.python.org/mailman/listinfo/python-list
Re: Matplotlib Contour Plots
Jamie Mitchell wrote: > I created the 2D array which read as: That's not a 2D array. When the amount of data you have is too big to clearly see what it happening, replace it with something smaller. Instead of 30 items per sub-array, try it with 5 items per sub-array. Instead of eight decimal places, try it with single-digit integers. Anything to make it small enough to see clearly. When I do that with your data, instead of this: > array([[[ 2.0886, 2.29400015, 2.00400019, 1.8811, 2.0480001 , > 2.16800022, 2.0480001 , 1.8829, 1.9586, 2.0029, > 2.02800012, 1.8124, 1.9505, 1.96200013, 1.95200014, > 1.99800014, 2.0717, 1.8829, 1.9849, 2.1346, > 2.1148, 1.8945, 2.0519, 2.0198, 2.03400016, > 2.16600013, 2.0099, 1.86200011, 2.19800019, > 2.0128]], > >[[ 8.515 , 8.8811, 8.5519, 7.9481, 8.6066, > 8.515 , 8.8019, 8.1311, 8.6858, 8.7254, > 8.4754, 8.25 , 8.4085, 8.4358, 8.3839, > 8.3566, 8.6339, 8.5123, 8.3689, 8.6981, > 8.5273, 8.1339, 8.3689, 8.4208, 8.5547, > 8.7254, 9.0915, 8.1858, 8.7623, > 8.5396]]], dtype=float32) I get this: array([[[ 2, 2, 2, 1, 2]], [[ 8, 8, 8, 7, 8]]], dtype=float32) which is much easier to work with. See the difference between that smaller example, and my earlier explanation of the difference between a 1D and 2D array? One dimensional arrays are made from a single list of numbers: [...] Two dimensional arrays are made from a list of lists: [ [...], [...] ] *Three* dimensional arrays are made from a list of lists of lists: [ [ [...], [...] ] ] *Four* dimensional arrays are made from a list of lists of lists of lists: [ [ [ [...], [...] ] ] ] and so on. You have a 3D array, with dimensions 2 x 1 x 30. You can check the dimensions by storing the array into a variable like this: py> a = numpy.array([[[ 2, 2, 2, 1, 2]], [[ 8, 8, 8, 7, 8]]]) py> a.shape (2, 1, 5) -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Captcha identify
On 08/13/2014 02:18 PM, Ian Kelly wrote: > On Wed, Aug 13, 2014 at 2:01 PM, Tim Chase > wrote: >> On 2014-08-13 12:24, Chris Kaynor wrote: >>> Many of the better captchas also include options for an audio cue in >>> addition to the default visual one. >> >> Have you actually tried to use the audio cue? They're atrocious. I >> got more intelligible words out of my old 8-bit SoundBlaster or a >> de-tuned radio station. I'm all for just ditching them (and avoiding >> sites that employ them). > > Just like the images, if they were easy to understand then they would > be easily defeated by a spambot with a speech recognition module. > I think the effort to make captcha systems more accessible is laudable, > if perhaps misguided. Well we seem to be at an impasse then. But the worst of it is that captchas aren't effective anymore. There are thousands of folks (at least) willing to solve captchas to create various accounts for nefarious purposes for money. This happens to gmail all the time, for example. Maybe the internet landscape is one giant example of the tragedy of the commons, with or without captchas. -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On Fri, Aug 15, 2014 at 1:39 AM, Denis McMahon wrote: > On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote: > > On further inspection, it seems that strptime() in 2.7 doesn't handle %z > at all. In 3.2, it ignores the value it gets, because there's no > practical way to select the "right" tz string from the offset. I'm not sure when %z was added, but it's worth noting that it doesn't seem to be documented earlier than 3.3. -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On 15/08/2014 16:23, Ian Kelly wrote: On Fri, Aug 15, 2014 at 1:39 AM, Denis McMahon wrote: On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote: On further inspection, it seems that strptime() in 2.7 doesn't handle %z at all. In 3.2, it ignores the value it gets, because there's no practical way to select the "right" tz string from the offset. I'm not sure when %z was added, but it's worth noting that it doesn't seem to be documented earlier than 3.3. Looks like this http://bugs.python.org/issue16667 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Captcha identify
On 8/14/2014 7:19 PM, Denis McMahon wrote: On Wed, 13 Aug 2014 07:39:20 -0400, Eric S. Johansson wrote: you are clear but also missing a really good reason to break captchas. handicapped accessibility. Captchas are a huge barrier to access and in many cases push disabled users away from using a service with captchas. That's as may be, but bozo is not trying to improve handicapped accessibility, he's trying to write a spambot. not necessary. you are probably right but he never described the application. Please don't use the accessibility concerns surrounding captcha to justify writing spambot software. It doesn't help the accessibility argument to be seen to be pro spambot, in fact if anything it may damage it. I agree that there are more reasons not to use captcha these days than there are to use them, however I still don't advocate helping spambot bastards defeat them. not what I said or advocated. pointing out that breaking captchas is good for accessibility issues it not the same as being pro spambot. it may have that effect but it is not the same thing. fwiw, making software accessible means making it possible to make your own interface via an application api. the current scrape-a-gui model fails the -what-the-user-needs test. at the same time, notice the huge security risk an D(ability)A(ccessibility) api opens up. does not mean we shouldn't use the DA api model, just that we also need to fix the security problem at the same time. -- https://mail.python.org/mailman/listinfo/python-list
Re: problem on top-post
In Ben Finney writes: > "Bottom-post" usually refers to the inferior practice of quoting a > message (entirely or large amounts) and then indiscriminately responding > to all of it below all of the quoted text. I was unaware of that meaning. -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list
Re: Captcha identify
On Sat, Aug 16, 2014 at 3:18 AM, Eric S. Johansson wrote: > not what I said or advocated. pointing out that breaking captchas is good > for accessibility issues it not the same as being pro spambot. it may have > that effect but it is not the same thing. I don't care, frankly. I'm still not going to help anyone to break CAPTCHAs automatically. If you're unable to solve CAPTCHAs, it's equivalent to being unable to run VBScript or unable to download music over a proprietary streaming protocol: it's a problem to be solved by getting the server admin to change policy, *not* by trying to script around it. Scripting around the problem just forces everyone to make it harder to script around the problem. You're joining the arms race, and on the wrong side. Breaking CAPTCHAs is *not* good for any issue. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On Fri, 15 Aug 2014 09:23:02 -0600, Ian Kelly wrote: > On Fri, Aug 15, 2014 at 1:39 AM, Denis McMahon > wrote: >> On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote: >> >> On further inspection, it seems that strptime() in 2.7 doesn't handle >> %z at all. In 3.2, it ignores the value it gets, because there's no >> practical way to select the "right" tz string from the offset. > > I'm not sure when %z was added, but it's worth noting that it doesn't > seem to be documented earlier than 3.3. There may be some confusion because %z is in the table of strftime and strptime format chars on the 2.7.8 docs at https://docs.python.org/2/library/datetime.html#strftime-and-strptime- behavior but I suspect it's only applicable to strftime in that release. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: timedelta problem
On Fri, Aug 15, 2014 at 11:43 AM, Denis McMahon wrote: > On Fri, 15 Aug 2014 09:23:02 -0600, Ian Kelly wrote: > >> On Fri, Aug 15, 2014 at 1:39 AM, Denis McMahon >> wrote: >>> On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote: >>> >>> On further inspection, it seems that strptime() in 2.7 doesn't handle >>> %z at all. In 3.2, it ignores the value it gets, because there's no >>> practical way to select the "right" tz string from the offset. >> >> I'm not sure when %z was added, but it's worth noting that it doesn't >> seem to be documented earlier than 3.3. > > There may be some confusion because %z is in the table of strftime and > strptime format chars on the 2.7.8 docs at > > https://docs.python.org/2/library/datetime.html#strftime-and-strptime- > behavior > > but I suspect it's only applicable to strftime in that release. Ah, interesting. I was looking at the time.strptime docs. I incorrectly assumed that since help(datetime.strptime) defers to help(time.strptime), the docs would also. I note it says that "datetime.strptime(date_string, format) is equivalent to datetime(*(time.strptime(date_string, format)[0:6]))", but clearly that's not the case when the format includes %z. -- https://mail.python.org/mailman/listinfo/python-list
Re: get the min date from a list
On Thu, 14 Aug 2014 22:10:36 +0800, luofeiyu wrote: > I finished it ,but how to make it into more pythonic way such as min > (dates, key = converter) 1. If you don't learn to post properly, I'm going to stop trying to help you. 2. To user strptime, you need to have all the time strings in the same format. Your time strings are not all in the same format. 3. Consider the following code which works on python 3.2: #!/usr/bin/python3 from datetime import tzinfo, timedelta, datetime, timezone times=[ 'Sat, 09 Aug 2014 07:36:46 -0700', # rest of array here 'Tue, 05 Aug 2014 01:55:24 +', ] realtimes = [ datetime.strptime( x, "%a, %d %b %Y %H:%M:%S %z" ) for x in times ] realtimes.sort() utctimes = [ x.astimezone(timezone(timedelta(0))) for x in realtimes ] for i in range( len( realtimes ) ): print( realtimes[i], "==", utctimes[i] ) Output is a sorted list of the actual times and the UTC equivalents of all the times in the original list. Note that I had to edit several strings in your times list to ensure they were all in identical format: I added leading 0s to numeric values in some strings, deleted extra spaces in some strings, deleted extraneous information after the tz offset in some strings. When feeding strings to a parsing function such as strptime () it is critically important that the format specifier matches the input data. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Unicode in cgi-script with apache2
Hi, I've got a little script: #!/usr/bin/env python3 print("Content-Type: text/html") print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past print("") f = open("/var/www/cgi-data/index.html", "r") for line in f: print(line,end='') If I run the script in the terminal, it nicely prints the webpage 'index.html'. If access the script through a webbrowser, apache gives an error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1791: ordinal not in range(128) I've done a hole afternoon of reading on fora and blogs, I don't have a solution. Can anyone help me? Greetings, Dominique. -- https://mail.python.org/mailman/listinfo/python-list
Re: Unicode in cgi-script with apache2
On Fri, 15 Aug 2014 20:10:25 +0200, Dominique Ramaekers wrote: > Hi, > > I've got a little script: > > #!/usr/bin/env python3 print("Content-Type: text/html") > print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 > print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past > print("") > f = open("/var/www/cgi-data/index.html", "r") > for line in f: > print(line,end='') > > If I run the script in the terminal, it nicely prints the webpage > 'index.html'. > > If access the script through a webbrowser, apache gives an error: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position > 1791: ordinal not in range(128) > > I've done a hole afternoon of reading on fora and blogs, I don't have a > solution. > > Can anyone help me? > > Greetings, > > Dominique. 1) this is not the way to get python to generate a web page, if you dont want to use an existing framework (for example if you are doing this ans an educational exercise) i suggest to google SWGI 2) you need to encode your output strings into a format apache/html protocols can support - UTF8 is probably best here. change your pint function to print(line.encode('utf'),end='') 3) Ignore any subsequent advice from JMF even when he is trying to help he is invariable wrong. -- Freedom's just another word for nothing left to lose. -- Kris Kristofferson, "Me and Bobby McGee" -- https://mail.python.org/mailman/listinfo/python-list
Re: Unicode in cgi-script with apache2
In Dominique Ramaekers writes: > #!/usr/bin/env python3 > print("Content-Type: text/html") > print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 > print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past > print("") > f = open("/var/www/cgi-data/index.html", "r") > for line in f: > print(line,end='') > If access the script through a webbrowser, apache gives an error: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position > 1791: ordinal not in range(128) The error traceback should display exactly where the error occurs within the script. Which line is it? -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list
Re: get the min date from a list
On 15/08/2014 19:21, Denis McMahon wrote: On Thu, 14 Aug 2014 22:10:36 +0800, luofeiyu wrote: I finished it ,but how to make it into more pythonic way such as min (dates, key = converter) 1. If you don't learn to post properly, I'm going to stop trying to help you. I say old bean do be careful, I've been suffering nightmares having been accused of nagging, I wouldn't want you to suffer the same fate. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: PyMatch Tool.
Am 14.08.14 21:50, schrieb rafinha.u...@gmail.com: Hello, I created this tool to help me develop on formatting text using regular expressions. Any questions, I am available. Thank you. Tool -> https://github.com/rfunix/PyMatch I expected something like visual regexp: http://laurent.riesterer.free.fr/regexp/ Since RegExp-Syntax is very similar across tools, yours is almost identical to grep. Is it not? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: get the min date from a list
On Fri, Aug 15, 2014 at 12:21 PM, Denis McMahon wrote: > Output is a sorted list of the actual times and the UTC equivalents of > all the times in the original list. Note that I had to edit several > strings in your times list to ensure they were all in identical format: I > added leading 0s to numeric values in some strings, deleted extra spaces > in some strings, deleted extraneous information after the tz offset in > some strings. When feeding strings to a parsing function such as strptime > () it is critically important that the format specifier matches the input > data. >>> datetime.strptime("Mon, 9\t\t\tAug\n2014\r7:36:46\f-0700", "%a, %d %b %Y >>> %H:%M:%S %z") datetime.datetime(2014, 8, 9, 7, 36, 46, tzinfo=datetime.timezone(datetime.timedelta(-1, 61200))) strptime doesn't seem to care about variations in whitespace as long as some is present, or missing leading zeroes (although it does throw an error if the time zone offset is only 3 digits). -- https://mail.python.org/mailman/listinfo/python-list
Logging multiple formats to the same file
So I've got my program log going to a RotatingFileHandler (actually a subclass that ensmartens the umask, but I digress). I'd like to be able to provide information to the logger that is formatted two different ways, primarily just so that I can provide a Program Started message into the log. What I've got going right now works, but boy it feels like I had to butcher the intent of the logging module to pull it off. Does anyone have any better ideas than... class BannerFormatter(logging.Formatter): """ Uses the assigned formatting, unless the name of the logger is 'BANNER', in which case we use the special alternate banner format. """ def __init__(self, *args, **kwargs): self.normal = logging.Formatter(*args, **kwargs) self.banner = logging.Formatter( '\n\n%(asctime)s - ** %(message)s **' ) def format(self, record): if record.name == 'BANNER': return self.banner.format(record) else: return self.normal.format(record) ... logging.getLogger('BANNER').critical('Starting program.') -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. -- https://mail.python.org/mailman/listinfo/python-list
string encoding regex problem
Hello, I have defined a function with: def URLReader(url) : try : f = urllib2.urlopen(url) data = f.read() f.close() except Exception, e : raise MyError.StopError(e) return data which get the HTML source code from an URL. I use this to get a part of a HTML document without any HTML parsing, so I call (I would like to get the download link of the boost library): found = re.search( "href=\"/projects/boost/files/latest/download\?source=files\" title=\"/boost/(.*)", Utilities.URLReader("http://sourceforge.net/projects/boost/files/boost/";) ) if found == None : raise MyError.StopError("Boost Download URL not found") But found is always None, so I cannot get the correct match. I didn't find the error in my code. Thanks for help Phil-- https://mail.python.org/mailman/listinfo/python-list
Re: string encoding regex problem
In article , Philipp Kraus wrote: > found = re.search( " href=\"/projects/boost/files/latest/download\?source=files\" > title=\"/boost/(.*)", > Utilities.URLReader("http://sourceforge.net/projects/boost/files/boost/";) > ) > if found == None : > raise MyError.StopError("Boost Download URL not found") > > But found is always None, so I cannot get the correct match. I didn't > find the error in my code. I would start by breaking this down into pieces. Something like: > data = > Utilities.URLReader("http://sourceforge.net/projects/boost/files/boost/";) > ) > print data > found = re.search( " href=\"/projects/boost/files/latest/download\?source=files\" > title=\"/boost/(.*)", > data) > if found == None : > raise MyError.StopError("Boost Download URL not found") Now at least you get to look at what URLReader() returned. Did it return what you expected? If not, then there might be something wrong in your URLReader() function. If it is what you expected, then I would start looking at the pattern to see if it's correct. Either way, you've managed to halve the size of the problem. -- https://mail.python.org/mailman/listinfo/python-list
Re: string encoding regex problem
On 2014-08-16 00:48:46 +, Roy Smith said: In article , Philipp Kraus wrote: found = re.search( "http://sourceforge.net/projects/boost/files/boost/";) ) if found == None : raise MyError.StopError("Boost Download URL not found") But found is always None, so I cannot get the correct match. I didn't find the error in my code. I would start by breaking this down into pieces. Something like: data = Utilities.URLReader("http://sourceforge.net/projects/boost/files/boost/";) ) print data found = re.search( " Now at least you get to look at what URLReader() returned. Did it return what you expected? If not, then there might be something wrong in your URLReader() function. I have check the result of the (sorry, I forgot this information on my first post). The URLReader returns the HTML code of the URL, so this seems to work correctly If it is what you expected, then I would start looking at the pattern to see if it's correct. Either way, you've managed to halve the size of the problem. The code works till last week correctly, I don't change the pattern. My question is, can it be a problem with string encoding? Did I mask the question mark and quotes correctly? Phil -- https://mail.python.org/mailman/listinfo/python-list
Re: string encoding regex problem
In article , Philipp Kraus wrote: > The code works till last week correctly, I don't change the pattern. OK, so what did you change? Can you go back to last week's code and compare it to what you have now to see what changed? > My question is, can it be a problem with string encoding? Did I mask > the question mark and quotes correctly? The best thing to do with regular expressions is to use raw strings, i.e. r'this is a string'. The nice thing about that is backslashes are not special. It makes it about 1000% easier to write complicated regular expressions. Simple ones are only 500% easier. -- https://mail.python.org/mailman/listinfo/python-list
redirect stderr to syslog?
We are using the syslog module for logging, and would like to redirect stderr to our log. Is there a practical way to do it? I realize the logging module supports this and has a syslog writer, so that's a fallback. But we were hoping to use the syslog module for performance. -- Russell -- https://mail.python.org/mailman/listinfo/python-list
Re: string encoding regex problem
Philipp Kraus wrote: > The code works till last week correctly, I don't change the pattern. My > question is, can it be > a problem with string encoding? Did I mask the question mark and quotes > correctly? If you didn't change the code, how could the *exact same code* not mask the question mark last week, but this week suddenly start masking it, despite not changing? There are three things that can cause a change in behaviour: - the re module has changed; - the pattern has changed; - the text you are searching has changed. Have you removed the re module and replaced it with a different one? Did you update Python to a new version? Have you changed the regex search pattern? Has the text you are searching changed? Websites upgrade their HTML quite frequently. Perhaps the Boost website has changed enough to break your regex. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: redirect stderr to syslog?
Russell E. Owen wrote: > I realize the logging module supports this and has a syslog writer, so > that's a fallback. But we were hoping to use the syslog module for > performance. Have you benchmarked your code and discovered that using the logging module makes a noticeable difference to performance? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
timezone argument %z and %Z
I feel it is necessary to start a new post to go on the discussion about timezone. In my system : win7+ python3.4 . related official material. https://docs.python.org/3.4/library/datetime.html#strftime-and-strptime %z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive). (empty), +, -0400, +1030 (6) %Z Time zone name (empty string if the object is naive). (empty), UTC, EST, CST 1.%z (lowercase) import datetime t1='Sat, 09 Aug 2014 07:36:46 -0700' # - is after backword t2='Sat, 09 Aug 2014 07:36:46 +0700'#+ is before foreward dt1=datetime.datetime.strptime(t1,"%a, %d %b %Y %H:%M:%S %z") dt2=datetime.datetime.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") dt1.astimezone(datetime.timezone.utc) datetime.datetime(2014, 8, 9, 14, 36, 46, tzinfo=datetime.timezone.utc) dt2.astimezone(datetime.timezone.utc) datetime.datetime(2014, 8, 9, 0, 36, 46, tzinfo=datetime.timezone.utc) %z is sovled by our community. 2.%Z (uppercase) Time zone name problem 1: There are 24 time zone in the world, does any time zone has the time zone name such as EST,CST ? Are there 24 time zone abbreviations in python ?what are other 22 except for EST ,CST ? problem 2: t3='Sat, 09 Aug 2014 07:36:46 EST' dt3=datetime.datetime.strptime(t3,"%a, %d %b %Y %H:%M:%S %Z") Traceback (most recent call last): File "", line 1, in File "D:\Python34\lib\_strptime.py", line 500, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "D:\Python34\lib\_strptime.py", line 337, in _strptime (data_string, format)) ValueError: time data 'Sat, 09 Aug 2014 07:36:46 EST' does not match format '%a, %d %b %Y %H:%M:%S %Z' does %Z remain problem?is it a bug in python datetime module? -- https://mail.python.org/mailman/listinfo/python-list
Re: timezone argument %z and %Z
luofeiyu writes: > In my system : win7+ python3.4 . AFAIK, Microsoft's Windows OS does not provide correct standard timezones for programmers. They provide only proprietary data, which do not match the international standard time zones. You will need to install timezone support specifically for Python, with the ‘pytz’ library I directed you to earlier. > problem 1: > There are 24 time zone in the world, does any time zone has the time > zone name such as EST,CST ? > Are there 24 time zone abbreviations in python ?what are other 22 > except for EST ,CST ? There are *many* time zones in the world, much more than 24. Please read up on time zones, you should already have plenty of pointers instead of asking here all the time. -- \ “Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.” —Anthony Taylor | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list